linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.de>
To: mwilck@arcor.de
Cc: linux-raid@vger.kernel.org
Subject: Re: [PATCH 2/2] Detail: deterministic ordering in --brief --verbose
Date: Mon, 24 Jun 2013 16:57:04 +1000	[thread overview]
Message-ID: <20130624165704.0cf94d1e@notabene.brown> (raw)
In-Reply-To: <1371759665-5625-2-git-send-email-mwilck@arcor.de>

[-- Attachment #1: Type: text/plain, Size: 2752 bytes --]

On Thu, 20 Jun 2013 22:21:05 +0200 mwilck@arcor.de wrote:

> Have mdadm --Detail --brief --verbose print the list of devices in
> alphabetical order.
> 
> This is useful for debugging purposes. E.g. the test script
> 10ddf-create compares the output of two mdadm -Dbv calls which
> may be different if the order is not deterministic.
> 
> (I confess: I use a modified "test" script that always runs
> "mdadm --verbose" rather than "mdadm --quiet", otherwise this
> wouldn't happen in 10ddf-create).
> 
> Signed-off-by: Martin Wilck <mwilck@arcor.de>
> ---
>  Detail.c |   33 +++++++++++++++++++++++++--------
>  1 files changed, 25 insertions(+), 8 deletions(-)
> 
> diff --git a/Detail.c b/Detail.c
> index 33b3a18..031219a 100644
> --- a/Detail.c
> +++ b/Detail.c
> @@ -27,6 +27,11 @@
>  #include	"md_u.h"
>  #include	<dirent.h>
>  
> +static int cmpstringp(const void *p1, const void *p2)
> +{
> +	return strcmp(* (char * const *) p1, * (char * const *) p2);
> +}
> +
>  int Detail(char *dev, struct context *c)
>  {
>  	/*
> @@ -42,7 +47,8 @@ int Detail(char *dev, struct context *c)
>  	int d;
>  	time_t atime;
>  	char *str;
> -	char *devices = NULL;
> +	char **devices = NULL;
> +	int max_devices = 0, n_devices = 0;
>  	int spares = 0;
>  	struct stat stb;
>  	int is_26 = get_linux_version() >= 2006000;
> @@ -636,12 +642,15 @@ This is pretty boring
>  		dv=map_dev_preferred(disk.major, disk.minor, 0, c->prefer);
>  		if (dv != NULL) {
>  			if (c->brief) {
> -				if (devices) {
> -					devices = xrealloc(devices,
> -							  strlen(devices)+1+strlen(dv)+1);
> -					strcat(strcat(devices,","),dv);
> -				} else
> -					devices = xstrdup(dv);
> +				if (n_devices + 1 >= max_devices) {
> +					max_devices += 16;
> +					devices = xrealloc(devices, max_devices
> +							   *sizeof(*devices));
> +					if (!devices)
> +						goto out;
> +				};
> +				devices[n_devices] = xstrdup(dv);
> +				n_devices++;
>  			} else
>  				printf("   %s", dv);
>  		}
> @@ -653,7 +662,12 @@ This is pretty boring
>  	if (st)
>  		st->ss->free_super(st);
>  
> -	if (c->brief && c->verbose > 0 && devices) printf("\n   devices=%s", devices);
> +	if (c->brief && c->verbose > 0 && devices) {
> +		qsort(devices, n_devices, sizeof(*devices), cmpstringp);
> +		printf("\n   devices=%s", devices[0]);
> +		for (d = 1; d < n_devices; d++)
> +			printf(",%s", devices[d]);
> +	}
>  	if (c->brief)
>  		printf("\n");
>  	if (c->test &&
> @@ -666,6 +680,9 @@ out:
>  	close(fd);
>  	free(subarray);
>  	free(avail);
> +	for (d = 0; d < n_devices; d++)
> +		free(devices[d]);
> +	free(devices);
>  	sysfs_free(sra);
>  	return rv;
>  }


Applied, thanks.

NeilBrown

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

  parent reply	other threads:[~2013-06-24  6:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-20 20:21 [PATCH 1/2] select_devices: fix scanning of container members with dev list mwilck
2013-06-20 20:21 ` [PATCH 2/2] Detail: deterministic ordering in --brief --verbose mwilck
2013-06-20 20:26   ` Martin Wilck
2013-06-24  6:57   ` NeilBrown [this message]
2013-06-24  6:55 ` [PATCH 1/2] select_devices: fix scanning of container members with dev list NeilBrown
2013-06-27 18:15   ` Martin Wilck
2013-06-27 19:38     ` Martin Wilck
2013-07-02  1:20       ` NeilBrown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130624165704.0cf94d1e@notabene.brown \
    --to=neilb@suse.de \
    --cc=linux-raid@vger.kernel.org \
    --cc=mwilck@arcor.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).