]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Detail.c
Create missing /dev files where needed.
[thirdparty/mdadm.git] / Detail.c
index 5028ae29c40346c0991c4e33a3deb1f1d04a1077..d322732c4222433092997ad45072bc3c2924f48a 100644 (file)
--- a/Detail.c
+++ b/Detail.c
@@ -41,15 +41,21 @@ int Detail(char *dev, int brief, int test)
        int fd = open(dev, O_RDONLY, 0);
        int vers;
        mdu_array_info_t array;
+       mdu_disk_info_t *disks;
+       int next;
        int d;
        time_t atime;
        char *c;
        char *devices = NULL;
        int spares = 0;
        struct stat stb;
+       int is_26 = get_linux_version() >= 2006000;
+       int is_rebuilding = 0;
+       int failed = 0;
+       struct supertype *st = NULL;
+       int max_disks = MD_SB_DISKS;
 
-       mdp_super_t super;
-       int have_super = 0;
+       void *super = NULL;
        int rv = test ? 4 : 1;
 
        if (fd < 0) {
@@ -80,20 +86,58 @@ int Detail(char *dev, int brief, int test)
                close(fd);
                return rv;
        }
+       st = super_by_version(array.major_version, array.minor_version);
+
        if (fstat(fd, &stb) != 0 && !S_ISBLK(stb.st_mode))
                stb.st_rdev = 0;
        rv = 0;
+
+       if (st) max_disks = st->max_devs;
+
+       /* try to load a superblock */
+       for (d= 0; d<max_disks; d++) {
+               mdu_disk_info_t disk;
+               char *dv;
+               disk.number = d;
+               if (ioctl(fd, GET_DISK_INFO, &disk) < 0)
+                       continue;
+               if (d >= array.raid_disks &&
+                   disk.major == 0 &&
+                   disk.minor == 0)
+                       continue;
+               if ((dv=map_dev(disk.major, disk.minor, 1))) {
+                       if (!super && (disk.state & (1<<MD_DISK_ACTIVE))) {
+                               /* try to read the superblock from this device
+                                * to get more info
+                                */
+                               int fd2 = dev_open(dv, O_RDONLY);
+                               if (fd2 >=0 && st &&
+                                   st->ss->load_super(st, fd2, &super, NULL) == 0) {
+                                       struct mdinfo info;
+                                       st->ss->getinfo_super(&info, super);
+                                       if (info.array.ctime != array.ctime ||
+                                           info.array.level != array.level) {
+                                               free(super);
+                                               super = NULL;
+                                       }
+                               }
+                               if (fd2 >= 0) close(fd2);
+                       }
+               }
+       }
+
        /* Ok, we have some info to print... */
        c = map_num(pers, array.level);
        if (brief) 
                printf("ARRAY %s level=%s num-devices=%d", dev, c?c:"-unknown-",array.raid_disks );
        else {
+               mdu_bitmap_file_t bmf;
                unsigned long array_size;
                unsigned long long larray_size;
-               struct mdstat_ent *ms = mdstat_read(0);
+               struct mdstat_ent *ms = mdstat_read(0, 0);
                struct mdstat_ent *e;
                int devnum = array.md_minor;
-               if (MAJOR(stb.st_rdev) != MD_MAJOR)
+               if (major(stb.st_rdev) != MD_MAJOR)
                        devnum = -1 - devnum;
 
                for (e=ms; e; e=e->next)
@@ -119,20 +163,36 @@ int Detail(char *dev, int brief, int test)
                printf("     Raid Level : %s\n", c?c:"-unknown-");
                if (larray_size)
                        printf("     Array Size : %llu%s\n", (larray_size>>10), human_size(larray_size));
-               if (array.level >= 1)
-                       printf("    Device Size : %d%s\n", array.size, human_size((long long)array.size<<10));
+               if (array.level >= 1) {
+                       if (array.major_version != 0 &&
+                           (larray_size >= 0xFFFFFFFFULL|| array.size == 0)) {
+                               unsigned long long dsize = get_component_size(fd);
+                               if (dsize > 0)
+                                       printf("    Device Size : %llu%s\n", dsize, human_size((long long)array.size<<10));
+                               else
+                                       printf("    Device Size : unknown\n");
+                       } else
+                               printf("    Device Size : %d%s\n", array.size, human_size((long long)array.size<<10));
+               }
                printf("   Raid Devices : %d\n", array.raid_disks);
                printf("  Total Devices : %d\n", array.nr_disks);
                printf("Preferred Minor : %d\n", array.md_minor);
                printf("    Persistence : Superblock is %spersistent\n",
                       array.not_persistent?"not ":"");
                printf("\n");
+               if (ioctl(fd, GET_BITMAP_FILE, &bmf) == 0 &&
+                       bmf.pathname[0]) {
+                       printf("  Intent Bitmap : %s\n", bmf.pathname);
+                       printf("\n");
+               } else if (array.state & (1<<MD_SB_BITMAP_PRESENT))
+                       printf("  Intent Bitmap : Internal\n\n");
                atime = array.utime;
                printf("    Update Time : %.24s\n", ctime(&atime));
                printf("          State : %s%s%s\n",
-                      (array.state&(1<<MD_SB_CLEAN))?"clean":"dirty",
+                      (array.state&(1<<MD_SB_CLEAN))?"clean":"active",
                       array.active_disks < array.raid_disks? ", degraded":"",
-                      (e && e->percent >= 0) ? ", recovering": "");
+                      (!e || e->percent < 0) ? "" :
+                       (e->resync) ? ", resyncing": ", recovering");
                printf(" Active Devices : %d\n", array.active_disks);
                printf("Working Devices : %d\n", array.working_disks);
                printf(" Failed Devices : %d\n", array.failed_disks);
@@ -142,29 +202,45 @@ int Detail(char *dev, int brief, int test)
                        c = map_num(r5layout, array.layout);
                        printf("         Layout : %s\n", c?c:"-unknown-");
                }
+               if (array.level == 10) {
+                       printf("         Layout : near=%d, far=%d\n", 
+                              array.layout&255, (array.layout>>8)&255);
+               }
                switch (array.level) {
                case 0:
                case 4:
                case 5:
-                       printf("     Chunk Size : %dK\n", array.chunk_size/1024);
+               case 10:
+               case 6:
+                       printf("     Chunk Size : %dK\n\n", array.chunk_size/1024);
                        break;
                case -1:
-                       printf("       Rounding : %dK\n", array.chunk_size/1024);
+                       printf("       Rounding : %dK\n\n", array.chunk_size/1024);
                        break;
                default: break;
                }
        
-               printf("\n");
-
-               if (e && e->percent >= 0)
+               if (e && e->percent >= 0) {
                        printf(" Rebuild Status : %d%% complete\n\n", e->percent);
+                       is_rebuilding = 1;
+               }
                free_mdstat(ms);
 
+               if (super && st)
+                       st->ss->detail_super(super);
+
                printf("    Number   Major   Minor   RaidDevice State\n");
        }
-       for (d= 0; d<MD_SB_DISKS; d++) {
+       disks = malloc(max_disks * sizeof(mdu_disk_info_t));
+       for (d=0; d<max_disks; d++) {
+               disks[d].state = (1<<MD_DISK_REMOVED);
+               disks[d].major = disks[d].minor = 0;
+               disks[d].number = disks[d].raid_disk = d;
+       }
+
+       next = array.raid_disks;
+       for (d=0; d < max_disks; d++) {
                mdu_disk_info_t disk;
-               char *dv;
                disk.number = d;
                if (ioctl(fd, GET_DISK_INFO, &disk) < 0) {
                        if (d < array.raid_disks)
@@ -172,25 +248,66 @@ int Detail(char *dev, int brief, int test)
                                        d, strerror(errno));
                        continue;
                }
+               if (disk.major == 0 && disk.minor == 0)
+                       continue;
+               if (disk.raid_disk >= 0 && disk.raid_disk < array.raid_disks) 
+                       disks[disk.raid_disk] = disk;
+               else if (next < max_disks)
+                       disks[next++] = disk;
+       }
+
+       for (d= 0; d < max_disks; d++) {
+               char *dv;
+               mdu_disk_info_t disk = disks[d];
+
                if (d >= array.raid_disks &&
                    disk.major == 0 &&
                    disk.minor == 0)
                        continue;
                if (!brief) {
-                       printf("   %5d   %5d    %5d    %5d     ", 
-                              disk.number, disk.major, disk.minor, disk.raid_disk);
-                       if (disk.state & (1<<MD_DISK_FAULTY)) printf(" faulty");
+                       if (d == array.raid_disks) printf("\n");
+                       if (disk.raid_disk < 0)
+                               printf("   %5d   %5d    %5d        -     ", 
+                                      disk.number, disk.major, disk.minor);
+                       else
+                               printf("   %5d   %5d    %5d    %5d     ", 
+                                      disk.number, disk.major, disk.minor, disk.raid_disk);
+                       if (disk.state & (1<<MD_DISK_FAULTY)) { 
+                               printf(" faulty"); 
+                               if (disk.raid_disk < array.raid_disks &&
+                                   disk.raid_disk >= 0)
+                                       failed++;
+                       }
                        if (disk.state & (1<<MD_DISK_ACTIVE)) printf(" active");
                        if (disk.state & (1<<MD_DISK_SYNC)) printf(" sync");
                        if (disk.state & (1<<MD_DISK_REMOVED)) printf(" removed");
-                       if (disk.state == 0) { printf(" spare"); spares++; }
+                       if (disk.state & (1<<MD_DISK_WRITEMOSTLY)) printf(" writemostly");
+                       if ((disk.state &
+                            ((1<<MD_DISK_ACTIVE)|(1<<MD_DISK_SYNC)|(1<<MD_DISK_REMOVED)))
+                           == 0) {
+                               printf(" spare");
+                               if (is_26) {
+                                       if (disk.raid_disk < array.raid_disks && disk.raid_disk >= 0)
+                                               printf(" rebuilding");
+                               } else if (is_rebuilding && failed) {
+                                       /* Taking a bit of a risk here, we remove the
+                                        * device from the array, and then put it back.
+                                        * If this fails, we are rebuilding
+                                        */
+                                       int err = ioctl(fd, HOT_REMOVE_DISK, makedev(disk.major, disk.minor));
+                                       if (err == 0) ioctl(fd, HOT_ADD_DISK, makedev(disk.major, disk.minor));
+                                       if (err && errno ==  EBUSY)
+                                               printf(" rebuilding");
+                               }
+                       }
                }
+               if (disk.state == 0) spares++;
                if (test && d < array.raid_disks && disk.state & (1<<MD_DISK_FAULTY)) {
                        if ((rv & 1) && (array.level ==4 || array.level == 5))
                                rv |= 2;
                        rv |= 1;
                }
-               if ((dv=map_dev(disk.major, disk.minor))) {
+               if ((dv=map_dev(disk.major, disk.minor, 0))) {
                        if (brief) {
                                if (devices) {
                                        devices = realloc(devices,
@@ -200,34 +317,16 @@ int Detail(char *dev, int brief, int test)
                                        devices = strdup(dv);
                        } else
                                printf("   %s", dv);
-                       if (!have_super && (disk.state & (1<<MD_DISK_ACTIVE))) {
-                               /* try to read the superblock from this device
-                                * to get more info
-                                */
-                               int fd = open(dv, O_RDONLY);
-                               if (fd >=0 &&
-                                   load_super(fd, &super) ==0 &&
-                                   (unsigned long)super.ctime == (unsigned long)array.ctime &&
-                                   (unsigned int)super.level == (unsigned int)array.level)
-                                       have_super = 1;
-                       }
                }
                if (!brief) printf("\n");
        }
        if (spares && brief) printf(" spares=%d", spares);
-       if (have_super) {
-               if (brief) printf(" UUID=");
-               else printf("           UUID : ");
-               if (super.minor_version >= 90)
-                       printf("%08x:%08x:%08x:%08x", super.set_uuid0, super.set_uuid1,
-                              super.set_uuid2, super.set_uuid3);
-               else
-                       printf("%08x", super.set_uuid0);
-               if (!brief) 
-                       printf("\n         Events : %d.%d\n", super.events_hi, super.events_lo);
-       }
-       if (brief && devices) printf("\n   devices=%s", devices);
+       if (super && brief && st)
+               st->ss->brief_detail_super(super);
+
+       if (brief > 1 && devices) printf("\n   devices=%s", devices);
        if (brief) printf("\n");
        if (test && (rv&2)) rv &= ~1;
+       close(fd);
        return rv;
 }