X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=Detail.c;h=f633d9365cc392d0d0f91284c6364cedcf1292d7;hb=db428d7a2460b92773b565a0b9d27733f36ba1c9;hp=94156288a19fc50be64fd1c881cf6371c64bfdb7;hpb=5f7e44b29fe3fd9bf77c27e375c92046bf00d0c4;p=thirdparty%2Fmdadm.git diff --git a/Detail.c b/Detail.c index 94156288..f633d936 100644 --- a/Detail.c +++ b/Detail.c @@ -1,7 +1,7 @@ /* * mdadm - manage Linux "md" devices aka RAID arrays. * - * Copyright (C) 2001-2009 Neil Brown + * Copyright (C) 2001-2012 Neil Brown * * * This program is free software; you can redistribute it and/or modify @@ -27,7 +27,7 @@ #include "md_u.h" #include -int Detail(char *dev, int brief, int export, int test, char *homehost) +int Detail(char *dev, struct context *c) { /* * Print out details for an md array by using @@ -41,7 +41,7 @@ int Detail(char *dev, int brief, int export, int test, char *homehost) int next; int d; time_t atime; - char *c; + char *str; char *devices = NULL; int spares = 0; struct stat stb; @@ -56,34 +56,34 @@ int Detail(char *dev, int brief, int export, int test, char *homehost) char *member = NULL; char *container = NULL; - int rv = test ? 4 : 1; + int rv = c->test ? 4 : 1; int avail_disks = 0; - char *avail; + char *avail = NULL; if (fd < 0) { - fprintf(stderr, Name ": cannot open %s: %s\n", + pr_err("cannot open %s: %s\n", dev, strerror(errno)); return rv; } vers = md_get_version(fd); if (vers < 0) { - fprintf(stderr, Name ": %s does not appear to be an md device\n", + pr_err("%s does not appear to be an md device\n", dev); close(fd); return rv; } if (vers < 9000) { - fprintf(stderr, Name ": cannot get detail for md device %s: driver version too old.\n", + pr_err("cannot get detail for md device %s: driver version too old.\n", dev); close(fd); return rv; } if (ioctl(fd, GET_ARRAY_INFO, &array)<0) { if (errno == ENODEV) - fprintf(stderr, Name ": md device %s does not appear to be active.\n", + pr_err("md device %s does not appear to be active.\n", dev); else - fprintf(stderr, Name ": cannot get array detail for %s: %s\n", + pr_err("cannot get array detail for %s: %s\n", dev, strerror(errno)); close(fd); return rv; @@ -105,7 +105,7 @@ int Detail(char *dev, int brief, int export, int test, char *homehost) int dn = st->container_dev; member = subarray; - container = map_dev(dev2major(dn), dev2minor(dn), 1); + container = map_dev_preferred(dev2major(dn), dev2minor(dn), 1, c->prefer); } /* try to load a superblock */ @@ -146,7 +146,7 @@ int Detail(char *dev, int brief, int export, int test, char *homehost) if (subarray) info = st->ss->container_content(st, subarray); else { - info = malloc(sizeof(*info)); + info = xmalloc(sizeof(*info)); st->ss->getinfo_super(st, info, NULL); } if (!info) @@ -159,16 +159,16 @@ int Detail(char *dev, int brief, int export, int test, char *homehost) continue; } /* some formats (imsm) have free-floating-spares - * with a uuid of uuid_match_any, they don't + * with a uuid of uuid_zero, they don't * have very good info about the rest of the * container, so keep searching when * encountering such a device. Otherwise, stop * after the first successful call to * ->load_super. */ - if (memcmp(uuid_match_any, + if (memcmp(uuid_zero, info->uuid, - sizeof(uuid_match_any)) == 0) { + sizeof(uuid_zero)) == 0) { st->ss->free_super(st); continue; } @@ -176,12 +176,12 @@ int Detail(char *dev, int brief, int export, int test, char *homehost) } /* Ok, we have some info to print... */ - c = map_num(pers, array.level); + str = map_num(pers, array.level); - if (export) { + if (c->export) { if (array.raid_disks) { - if (c) - printf("MD_LEVEL=%s\n", c); + if (str) + printf("MD_LEVEL=%s\n", str); printf("MD_DEVICES=%d\n", array.raid_disks); } else { printf("MD_LEVEL=container\n"); @@ -197,7 +197,7 @@ int Detail(char *dev, int brief, int export, int test, char *homehost) printf("MD_METADATA=%d.%d\n", array.major_version, array.minor_version); } - + if (st && st->sb && info) { char nbuf[64]; struct map_ent *mp, *map = NULL; @@ -226,20 +226,20 @@ int Detail(char *dev, int brief, int export, int test, char *homehost) goto out; } - disks = malloc(max_disks * sizeof(mdu_disk_info_t)); - for (d=0; dbrief) { mdu_bitmap_file_t bmf; printf("ARRAY %s", dev); - if (brief > 1) { + if (c->brief > 1) { if (array.raid_disks) printf(" level=%s num-devices=%d", - c?c:"-unknown-", + str?str:"-unknown-", array.raid_disks ); else printf(" level=container num-devices=%d", @@ -321,10 +321,12 @@ int Detail(char *dev, int brief, int export, int test, char *homehost) atime = array.ctime; if (atime) printf(" Creation Time : %.24s\n", ctime(&atime)); - if (array.raid_disks == 0) c = "container"; - printf(" Raid Level : %s\n", c?c:"-unknown-"); + if (array.raid_disks == 0) + str = "container"; + printf(" Raid Level : %s\n", str?str:"-unknown-"); if (larray_size) - printf(" Array Size : %llu%s\n", (larray_size>>10), human_size(larray_size)); + printf(" Array Size : %llu%s\n", (larray_size>>10), + human_size(larray_size)); if (array.level >= 1) { if (array.major_version != 0 && (larray_size >= 0xFFFFFFFFULL|| array.size == 0)) { @@ -342,7 +344,7 @@ int Detail(char *dev, int brief, int export, int test, char *homehost) if (array.raid_disks) printf(" Raid Devices : %d\n", array.raid_disks); printf(" Total Devices : %d\n", array.nr_disks); - if (!container && + if (!container && ((sra == NULL && array.major_version == 0) || (sra && sra->array.major_version == 0))) printf("Preferred Minor : %d\n", array.md_minor); @@ -362,21 +364,25 @@ int Detail(char *dev, int brief, int export, int test, char *homehost) if (atime) printf(" Update Time : %.24s\n", ctime(&atime)); if (array.raid_disks) { - static char *sync_action[] = {", recovering",", resyncing",", reshaping",", checking"}; + static char *sync_action[] = { + ", recovering", ", resyncing", + ", reshaping", ", checking" }; char *st; if (avail_disks == array.raid_disks) st = ""; else if (!enough(array.level, array.raid_disks, - array.layout, 1, avail, avail_disks)) + array.layout, 1, avail)) st = ", FAILED"; else st = ", degraded"; - printf(" State : %s%s%s%s\n", - (array.state&(1<percent < 0) ? "" : sync_action[e->resync], - larray_size ? "": ", Not Started"); + printf(" State : %s%s%s%s%s%s \n", + (array.state&(1<percent < 0 && e->percent != RESYNC_PENDING && + e->percent != RESYNC_DELAYED)) ? "" : sync_action[e->resync], + larray_size ? "": ", Not Started", + e->percent == RESYNC_DELAYED ? " (DELAYED)": "", + e->percent == RESYNC_PENDING ? " (PENDING)": ""); } if (array.raid_disks) printf(" Active Devices : %d\n", array.active_disks); @@ -387,12 +393,12 @@ int Detail(char *dev, int brief, int export, int test, char *homehost) } printf("\n"); if (array.level == 5) { - c = map_num(r5layout, array.layout); - printf(" Layout : %s\n", c?c:"-unknown-"); + str = map_num(r5layout, array.layout); + printf(" Layout : %s\n", str?str:"-unknown-"); } if (array.level == 6) { - c = map_num(r6layout, array.layout); - printf(" Layout : %s\n", c?c:"-unknown-"); + str = map_num(r6layout, array.layout); + printf(" Layout : %s\n", str?str:"-unknown-"); } if (array.level == 10) { printf(" Layout :"); @@ -416,41 +422,40 @@ int Detail(char *dev, int brief, int export, int test, char *homehost) } if (e && e->percent >= 0) { - printf(" Re%s Status : %d%% complete\n", - (st && st->sb && info->reshape_active)? - "shape":"build", - e->percent); + static char *sync_action[] = { + "Rebuild", "Resync", + "Reshape", "Check"}; + printf(" %7s Status : %d%% complete\n", sync_action[e->resync], e->percent); is_rebuilding = 1; } free_mdstat(ms); - if (st->sb && info->reshape_active) { + if ((st && st->sb) && (info && info->reshape_active)) { #if 0 This is pretty boring printf(" Reshape pos'n : %llu%s\n", (unsigned long long) info->reshape_progress<<9, human_size((unsigned long long)info->reshape_progress<<9)); #endif - if (info->delta_disks > 0) - printf(" Delta Devices : %d, (%d->%d)\n", - info->delta_disks, array.raid_disks - info->delta_disks, array.raid_disks); - if (info->delta_disks < 0) + if (info->delta_disks != 0) printf(" Delta Devices : %d, (%d->%d)\n", - info->delta_disks, array.raid_disks, array.raid_disks + info->delta_disks); + info->delta_disks, + array.raid_disks - info->delta_disks, + array.raid_disks); if (info->new_level != array.level) { - char *c = map_num(pers, info->new_level); - printf(" New Level : %s\n", c?c:"-unknown-"); + str = map_num(pers, info->new_level); + printf(" New Level : %s\n", str?str:"-unknown-"); } if (info->new_level != array.level || info->new_layout != array.layout) { if (info->new_level == 5) { - char *c = map_num(r5layout, info->new_layout); + str = map_num(r5layout, info->new_layout); printf(" New Layout : %s\n", - c?c:"-unknown-"); + str?str:"-unknown-"); } if (info->new_level == 6) { - char *c = map_num(r6layout, info->new_layout); + str = map_num(r6layout, info->new_layout); printf(" New Layout : %s\n", - c?c:"-unknown-"); + str?str:"-unknown-"); } if (info->new_level == 10) { printf(" New Layout : near=%d, %s=%d\n", @@ -465,7 +470,7 @@ This is pretty boring } else if (e && e->percent >= 0) printf("\n"); if (st && st->sb) - st->ss->detail_super(st, homehost); + st->ss->detail_super(st, c->homehost); if (array.raid_disks == 0 && sra && sra->array.major_version == -1 && sra->array.minor_version == -2 && sra->text_version[0] != '/') { @@ -489,13 +494,14 @@ This is pretty boring if (load_sys(path, vbuf) < 0) continue; if (strncmp(vbuf, "external:", 9) != 0 || - !is_subarray(sra->sys_name+9) || + !is_subarray(vbuf+9) || strncmp(vbuf+10, sra->sys_name, nlen) != 0 || vbuf[10+nlen] != '/') continue; dn = devname2devnum(de->d_name); - printf(" %s", map_dev(dev2major(dn), - dev2minor(dn), 1)); + printf(" %s", map_dev_preferred( + dev2major(dn), + dev2minor(dn), 1, c->prefer)); } if (dir) closedir(dir); @@ -517,7 +523,7 @@ This is pretty boring disk.major == 0 && disk.minor == 0) continue; - if (!brief) { + if (!c->brief) { if (d == array.raid_disks) printf("\n"); if (disk.raid_disk < 0) printf(" %5d %5d %5d - ", @@ -526,7 +532,7 @@ This is pretty boring printf(" %5d %5d %5d %5d ", disk.number, disk.major, disk.minor, disk.raid_disk); } - if (!brief && array.raid_disks) { + if (!c->brief && array.raid_disks) { if (disk.state & (1<> 8) & 0xff; + int copies = nc*fc; + if (array.raid_disks % copies == 0 && copies <= 26) { + /* We can divide the devices into 'sets' */ + int set = disk.raid_disk % copies; + printf(" set-%c", set + 'A'); + } + } + } if (disk.state & (1<test && d < array.raid_disks && !(disk.state & (1<prefer); + if (dv != NULL) { + if (c->brief) { if (devices) { - devices = realloc(devices, + devices = xrealloc(devices, strlen(devices)+1+strlen(dv)+1); strcat(strcat(devices,","),dv); } else - devices = strdup(dv); + devices = xstrdup(dv); } else printf(" %s", dv); } - if (!brief) printf("\n"); + if (!c->brief) printf("\n"); } - if (spares && brief && array.raid_disks) printf(" spares=%d", spares); - if (brief && st && st->sb) + if (spares && c->brief && array.raid_disks) printf(" spares=%d", spares); + if (c->brief && st && st->sb) st->ss->brief_detail_super(st); - st->ss->free_super(st); + if (st) + st->ss->free_super(st); - if (brief > 1 && devices) printf("\n devices=%s", devices); - if (brief) printf("\n"); - if (test && + if (c->brief > 1 && devices) printf("\n devices=%s", devices); + if (c->brief) + printf("\n"); + if (c->test && !enough(array.level, array.raid_disks, array.layout, - 1, avail, avail_disks)) + 1, avail)) rv = 2; free(disks); out: close(fd); free(subarray); + free(avail); + sysfs_free(sra); return rv; } @@ -604,12 +627,12 @@ int Detail_Platform(struct superswitch *ss, int scan, int verbose) if (ss && ss->detail_platform) err = ss->detail_platform(verbose, 0); else if (ss) { - if (verbose) - fprintf(stderr, Name ": %s metadata is platform independent\n", + if (verbose > 0) + pr_err("%s metadata is platform independent\n", ss->name ? : "[no name]"); } else if (!scan) { - if (verbose) - fprintf(stderr, Name ": specify a metadata type or --scan\n"); + if (verbose > 0) + pr_err("specify a metadata type or --scan\n"); } if (!scan) @@ -620,12 +643,12 @@ int Detail_Platform(struct superswitch *ss, int scan, int verbose) if (meta == ss) continue; - if (verbose) - fprintf(stderr, Name ": checking metadata %s\n", + if (verbose > 0) + pr_err("checking metadata %s\n", meta->name ? : "[no name]"); if (!meta->detail_platform) { - if (verbose) - fprintf(stderr, Name ": %s metadata is platform independent\n", + if (verbose > 0) + pr_err("%s metadata is platform independent\n", meta->name ? : "[no name]"); } else err |= meta->detail_platform(verbose, 0);