Detail: deterministic ordering in --brief --verbose
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> Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
parent
0ddc35beed
commit
41a663b267
33
Detail.c
33
Detail.c
|
@ -27,6 +27,11 @@
|
||||||
#include "md_u.h"
|
#include "md_u.h"
|
||||||
#include <dirent.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)
|
int Detail(char *dev, struct context *c)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -42,7 +47,8 @@ int Detail(char *dev, struct context *c)
|
||||||
int d;
|
int d;
|
||||||
time_t atime;
|
time_t atime;
|
||||||
char *str;
|
char *str;
|
||||||
char *devices = NULL;
|
char **devices = NULL;
|
||||||
|
int max_devices = 0, n_devices = 0;
|
||||||
int spares = 0;
|
int spares = 0;
|
||||||
struct stat stb;
|
struct stat stb;
|
||||||
int is_26 = get_linux_version() >= 2006000;
|
int is_26 = get_linux_version() >= 2006000;
|
||||||
|
@ -655,12 +661,15 @@ This is pretty boring
|
||||||
dv=map_dev_preferred(disk.major, disk.minor, 0, c->prefer);
|
dv=map_dev_preferred(disk.major, disk.minor, 0, c->prefer);
|
||||||
if (dv != NULL) {
|
if (dv != NULL) {
|
||||||
if (c->brief) {
|
if (c->brief) {
|
||||||
if (devices) {
|
if (n_devices + 1 >= max_devices) {
|
||||||
devices = xrealloc(devices,
|
max_devices += 16;
|
||||||
strlen(devices)+1+strlen(dv)+1);
|
devices = xrealloc(devices, max_devices
|
||||||
strcat(strcat(devices,","),dv);
|
*sizeof(*devices));
|
||||||
} else
|
if (!devices)
|
||||||
devices = xstrdup(dv);
|
goto out;
|
||||||
|
};
|
||||||
|
devices[n_devices] = xstrdup(dv);
|
||||||
|
n_devices++;
|
||||||
} else
|
} else
|
||||||
printf(" %s", dv);
|
printf(" %s", dv);
|
||||||
}
|
}
|
||||||
|
@ -672,7 +681,12 @@ This is pretty boring
|
||||||
if (st)
|
if (st)
|
||||||
st->ss->free_super(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)
|
if (c->brief)
|
||||||
printf("\n");
|
printf("\n");
|
||||||
if (c->test &&
|
if (c->test &&
|
||||||
|
@ -685,6 +699,9 @@ out:
|
||||||
close(fd);
|
close(fd);
|
||||||
free(subarray);
|
free(subarray);
|
||||||
free(avail);
|
free(avail);
|
||||||
|
for (d = 0; d < n_devices; d++)
|
||||||
|
free(devices[d]);
|
||||||
|
free(devices);
|
||||||
sysfs_free(sra);
|
sysfs_free(sra);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue