]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Report error in --update string is not recognised.
authorNeilBrown <neilb@suse.de>
Mon, 22 Nov 2010 08:35:24 +0000 (19:35 +1100)
committerNeilBrown <neilb@suse.de>
Mon, 22 Nov 2010 08:35:24 +0000 (19:35 +1100)
If an --update is requested by the relevant metadata doesn't
understand it, print a useful message rather than silently ignoring
the issue.

Signed-off-by: NeilBrown <neilb@suse.de>
Assemble.c
super-ddf.c
super-intel.c
super0.c
super1.c

index e115ecac775bca52428f1ba7820f7d0601473a4f..a25fdbe17c50303c01b7ccfba19a1b192b184277 100644 (file)
@@ -615,6 +615,7 @@ int Assemble(struct supertype *st, char *mddev,
                        /* prepare useful information in info structures */
                        struct stat stb2;
                        struct supertype *tst;
+                       int err;
                        fstat(mdfd, &stb2);
 
                        if (strcmp(update, "uuid")==0 &&
@@ -648,22 +649,33 @@ int Assemble(struct supertype *st, char *mddev,
                        strcpy(content->name, ident->name);
                        content->array.md_minor = minor(stb2.st_rdev);
 
-                       tst->ss->update_super(tst, content, update,
-                                             devname, verbose,
-                                             ident->uuid_set, homehost);
+                       if (strcmp(update, "byteorder") == 0)
+                               err = 0;
+                       else
+                               err = tst->ss->update_super(tst, content, update,
+                                                           devname, verbose,
+                                                           ident->uuid_set,
+                                                           homehost);
+                       if (err < 0) {
+                               fprintf(stderr,
+                                       Name ": --update=%s not understood"
+                                       " for %s metadata\n",
+                                       update, tst->ss->name);
+                               tst->ss->free_super(tst);
+                               free(tst);
+                               close(mdfd);
+                               close(dfd);
+                               return 1;
+                       }
                        if (strcmp(update, "uuid")==0 &&
                            !ident->uuid_set) {
                                ident->uuid_set = 1;
                                memcpy(ident->uuid, content->uuid, 16);
                        }
-                       if (dfd < 0)
-                               fprintf(stderr, Name ": Cannot open %s for superblock update\n",
-                                       devname);
-                       else if (tst->ss->store_super(tst, dfd))
+                       if (tst->ss->store_super(tst, dfd))
                                fprintf(stderr, Name ": Could not re-write superblock on %s.\n",
                                        devname);
-                       if (dfd >= 0)
-                               close(dfd);
+                       close(dfd);
 
                        if (strcmp(update, "uuid")==0 &&
                            ident->bitmap_fd >= 0 && !bitmap_done) {
index dba59703a03cc2f054e70e1c8f3a5b74677c3ee7..fca8edd742e472060f0219050731abcf399488a1 100644 (file)
@@ -1515,28 +1515,24 @@ static int update_super_ddf(struct supertype *st, struct mdinfo *info,
 
        if (strcmp(update, "grow") == 0) {
                /* FIXME */
-       }
-       if (strcmp(update, "resync") == 0) {
+       } else if (strcmp(update, "resync") == 0) {
 //             info->resync_checkpoint = 0;
-       }
-       /* We ignore UUID updates as they make even less sense
-        * with DDF
-        */
-       if (strcmp(update, "homehost") == 0) {
+       } else if (strcmp(update, "homehost") == 0) {
                /* homehost is stored in controller->vendor_data,
                 * or it is when we are the vendor
                 */
 //             if (info->vendor_is_local)
 //                     strcpy(ddf->controller.vendor_data, homehost);
-       }
-       if (strcmp(update, "name") == 0) {
+               rv = -1;
+       if (strcmp(update, "name") == 0) {
                /* name is stored in virtual_entry->name */
 //             memset(ve->name, ' ', 16);
 //             strncpy(ve->name, info->name, 16);
-       }
-       if (strcmp(update, "_reshape_progress") == 0) {
+               rv = -1;
+       if (strcmp(update, "_reshape_progress") == 0) {
                /* We don't support reshape yet */
-       }
+       } else
+               rv = -1;
 
 //     update_all_csum(ddf);
 
index f438044e82587daf40364c55b000d6de14482c34..38d0ae30550005d7e27fe375b8f622f18af28eb5 100644 (file)
@@ -1705,8 +1705,7 @@ static int update_super_imsm(struct supertype *st, struct mdinfo *info,
        mpb = super->anchor;
 
        if (strcmp(update, "uuid") == 0 && uuid_set && !info->update_private)
-               fprintf(stderr,
-                       Name ": '--uuid' not supported for imsm metadata\n");
+               rv = -1;
        else if (strcmp(update, "uuid") == 0 && uuid_set && info->update_private) {
                mpb->orig_family_num = *((__u32 *) info->update_private);
                rv = 0;
@@ -1727,9 +1726,7 @@ static int update_super_imsm(struct supertype *st, struct mdinfo *info,
        } else if (strcmp(update, "assemble") == 0)
                rv = 0;
        else
-               fprintf(stderr,
-                       Name ": '--update=%s' not supported for imsm metadata\n",
-                       update);
+               rv = -1;
 
        /* successful update? recompute checksum */
        if (rv == 0)
index ae3e8855193f9d6183776f346779b6d29ba5ef5c..a650c3e69784a05ade30624cfb8955c39c77cb66 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -419,14 +419,12 @@ static int update_super0(struct supertype *st, struct mdinfo *info,
                if (verbose >= 0)
                        fprintf (stderr, Name ": adjusting superblock of %s for 2.2/sparc compatability.\n",
                                 devname);
-       }
-       if (strcmp(update, "super-minor") ==0) {
+       } else if (strcmp(update, "super-minor") ==0) {
                sb->md_minor = info->array.md_minor;
                if (verbose > 0)
                        fprintf(stderr, Name ": updating superblock of %s with minor number %d\n",
                                devname, info->array.md_minor);
-       }
-       if (strcmp(update, "summaries") == 0) {
+       } else if (strcmp(update, "summaries") == 0) {
                unsigned int i;
                /* set nr_disks, active_disks, working_disks,
                 * failed_disks, spare_disks based on disks[]
@@ -453,8 +451,7 @@ static int update_super0(struct supertype *st, struct mdinfo *info,
                                        sb->spare_disks++;
                        } else if (i >= sb->raid_disks && sb->disks[i].number == 0)
                                sb->disks[i].state = 0;
-       }
-       if (strcmp(update, "force-one")==0) {
+       } else if (strcmp(update, "force-one")==0) {
                /* Not enough devices for a working array, so
                 * bring this one up-to-date.
                 */
@@ -464,8 +461,7 @@ static int update_super0(struct supertype *st, struct mdinfo *info,
                if (sb->events_hi != ehi ||
                    sb->events_lo != elo)
                        rv = 1;
-       }
-       if (strcmp(update, "force-array")==0) {
+       } else if (strcmp(update, "force-array")==0) {
                /* degraded array and 'force' requested, so
                 * maybe need to mark it 'clean'
                 */
@@ -475,8 +471,7 @@ static int update_super0(struct supertype *st, struct mdinfo *info,
                        sb->state |= (1 << MD_SB_CLEAN);
                        rv = 1;
                }
-       }
-       if (strcmp(update, "assemble")==0) {
+       } else if (strcmp(update, "assemble")==0) {
                int d = info->disk.number;
                int wonly = sb->disks[d].state & (1<<MD_DISK_WRITEMOSTLY);
                int mask = (1<<MD_DISK_WRITEMOSTLY);
@@ -491,8 +486,7 @@ static int update_super0(struct supertype *st, struct mdinfo *info,
                        sb->disks[d].state = info->disk.state | wonly;
                        rv = 1;
                }
-       }
-       if (strcmp(update, "linear-grow-new") == 0) {
+       } else if (strcmp(update, "linear-grow-new") == 0) {
                memset(&sb->disks[info->disk.number], 0, sizeof(sb->disks[0]));
                sb->disks[info->disk.number].number = info->disk.number;
                sb->disks[info->disk.number].major = info->disk.major;
@@ -500,8 +494,7 @@ static int update_super0(struct supertype *st, struct mdinfo *info,
                sb->disks[info->disk.number].raid_disk = info->disk.raid_disk;
                sb->disks[info->disk.number].state = info->disk.state;
                sb->this_disk = sb->disks[info->disk.number];
-       }
-       if (strcmp(update, "linear-grow-update") == 0) {
+       } else if (strcmp(update, "linear-grow-update") == 0) {
                sb->raid_disks = info->array.raid_disks;
                sb->nr_disks = info->array.nr_disks;
                sb->active_disks = info->array.active_disks;
@@ -512,20 +505,17 @@ static int update_super0(struct supertype *st, struct mdinfo *info,
                sb->disks[info->disk.number].minor = info->disk.minor;
                sb->disks[info->disk.number].raid_disk = info->disk.raid_disk;
                sb->disks[info->disk.number].state = info->disk.state;
-       }
-       if (strcmp(update, "resync") == 0) {
+       } else if (strcmp(update, "resync") == 0) {
                /* make sure resync happens */
                sb->state &= ~(1<<MD_SB_CLEAN);
                sb->recovery_cp = 0;
-       }
-       if (strcmp(update, "homehost") == 0 &&
+       } else if (strcmp(update, "homehost") == 0 &&
            homehost) {
                uuid_set = 0;
                update = "uuid";
                info->uuid[0] = sb->set_uuid0;
                info->uuid[1] = sb->set_uuid1;
-       }
-       if (strcmp(update, "uuid") == 0) {
+       } else if (strcmp(update, "uuid") == 0) {
                if (!uuid_set && homehost) {
                        char buf[20];
                        char *hash = sha1_buffer(homehost,
@@ -542,9 +532,10 @@ static int update_super0(struct supertype *st, struct mdinfo *info,
                        bm = (struct bitmap_super_s*)(sb+1);
                        uuid_from_super0(st, (int*)bm->uuid);
                }
-       }
-       if (strcmp(update, "_reshape_progress")==0)
+       } else if (strcmp(update, "_reshape_progress")==0)
                sb->reshape_position = info->reshape_progress;
+       else
+               rv = -1;
 
        sb->sb_csum = calc_sb0_csum(sb);
        return rv;
index 01473d14e68897666d0ef536df01d32ebf1aac30..24c18c0ee3ea57f55eb321db031edd662bf57710 100644 (file)
--- a/super1.c
+++ b/super1.c
@@ -656,8 +656,7 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
                if (sb->events != __cpu_to_le64(info->events))
                        rv = 1;
                sb->events = __cpu_to_le64(info->events);
-       }
-       if (strcmp(update, "force-array")==0) {
+       } else if (strcmp(update, "force-array")==0) {
                /* Degraded array and 'force' requests to
                 * maybe need to mark it 'clean'.
                 */
@@ -668,8 +667,7 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
                                rv = 1;
                        sb->resync_offset = MaxSector;
                }
-       }
-       if (strcmp(update, "assemble")==0) {
+       } else if (strcmp(update, "assemble")==0) {
                int d = info->disk.number;
                int want;
                if (info->disk.state == 6)
@@ -680,8 +678,7 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
                        sb->dev_roles[d] = want;
                        rv = 1;
                }
-       }
-       if (strcmp(update, "linear-grow-new") == 0) {
+       } else if (strcmp(update, "linear-grow-new") == 0) {
                unsigned int i;
                int rfd, fd;
                unsigned int max = __le32_to_cpu(sb->max_dev);
@@ -723,17 +720,14 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
                                        ds - __le64_to_cpu(sb->data_offset));
                        }
                }
-       }
-       if (strcmp(update, "linear-grow-update") == 0) {
+       } else if (strcmp(update, "linear-grow-update") == 0) {
                sb->raid_disks = __cpu_to_le32(info->array.raid_disks);
                sb->dev_roles[info->disk.number] =
                        __cpu_to_le16(info->disk.raid_disk);
-       }
-       if (strcmp(update, "resync") == 0) {
+       } else if (strcmp(update, "resync") == 0) {
                /* make sure resync happens */
                sb->resync_offset = 0ULL;
-       }
-       if (strcmp(update, "uuid") == 0) {
+       } else if (strcmp(update, "uuid") == 0) {
                copy_uuid(sb->set_uuid, info->uuid, super1.swapuuid);
 
                if (__le32_to_cpu(sb->feature_map)&MD_FEATURE_BITMAP_OFFSET) {
@@ -741,8 +735,7 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
                        bm = (struct bitmap_super_s*)(st->sb+1024);
                        memcpy(bm->uuid, sb->set_uuid, 16);
                }
-       }
-       if (strcmp(update, "homehost") == 0 &&
+       } else if (strcmp(update, "homehost") == 0 &&
            homehost) {
                char *c;
                update = "name";
@@ -752,8 +745,7 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
                else
                        strncpy(info->name, sb->set_name, 32);
                info->name[32] = 0;
-       }
-       if (strcmp(update, "name") == 0) {
+       } else if (strcmp(update, "name") == 0) {
                if (info->name[0] == 0)
                        sprintf(info->name, "%d", info->array.md_minor);
                memset(sb->set_name, 0, sizeof(sb->set_name));
@@ -765,8 +757,7 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
                        strcat(sb->set_name, info->name);
                } else
                        strcpy(sb->set_name, info->name);
-       }
-       if (strcmp(update, "devicesize") == 0 &&
+       } else if (strcmp(update, "devicesize") == 0 &&
            __le64_to_cpu(sb->super_offset) <
            __le64_to_cpu(sb->data_offset)) {
                /* set data_size to device size less data_offset */
@@ -778,9 +769,10 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
                        misc->device_size - __le64_to_cpu(sb->data_offset));
                printf("Size is %llu\n", (unsigned long long)
                       __le64_to_cpu(sb->data_size));
-       }
-       if (strcmp(update, "_reshape_progress")==0)
+       } else if (strcmp(update, "_reshape_progress")==0)
                sb->reshape_position = __cpu_to_le64(info->reshape_progress);
+       else
+               rv = -1;
 
        sb->sb_csum = calc_sb_1_csum(sb);
        return rv;