]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Pass subarray arg explicitly to ->update_subarray.
authorNeilBrown <neilb@suse.de>
Mon, 22 Nov 2010 09:24:50 +0000 (20:24 +1100)
committerNeilBrown <neilb@suse.de>
Mon, 22 Nov 2010 09:24:50 +0000 (20:24 +1100)
This is better than hiding it in the supertype structure
where we are never quite sure who needs it.

Signed-off-by: NeilBrown <neilb@suse.de>
Manage.c
mdadm.h
super-intel.c
util.c

index 1ce4aa63521c7935cab8182c6d023110b12d49bd..0a4472595f36cc84700ec1e883e7cb154b5c5f5b 100644 (file)
--- a/Manage.c
+++ b/Manage.c
@@ -1054,7 +1054,7 @@ int Update_subarray(char *dev, char *subarray, char *update, mddev_ident_t ident
        if (mdmon_running(st->devnum))
                st->update_tail = &st->updates;
 
-       rv = st->ss->update_subarray(st, update, ident);
+       rv = st->ss->update_subarray(st, subarray, update, ident);
 
        if (rv) {
                if (!quiet)
diff --git a/mdadm.h b/mdadm.h
index d46139ce2ae335da8e7d3541799af393c539fdba..25bc6230eadf8273af0da36bc69bc5ab7e30eae8 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -629,7 +629,8 @@ extern struct superswitch {
        /* Permit subarray's to be deleted from inactive containers */
        int (*kill_subarray)(struct supertype *st); /* optional */
        /* Permit subarray's to be modified */
-       int (*update_subarray)(struct supertype *st, char *update, mddev_ident_t ident); /* optional */
+       int (*update_subarray)(struct supertype *st, char *subarray,
+                              char *update, mddev_ident_t ident); /* optional */
 
 /* for mdmon */
        int (*open_new)(struct supertype *c, struct active_array *a,
index f64731b6cf34f56edadd46b955fcf64dadd62e33..03c214f9357bcf32a0a9c864d55df313b9de4d0e 100644 (file)
@@ -4229,19 +4229,19 @@ static int kill_subarray_imsm(struct supertype *st)
        return 0;
 }
 
-static int update_subarray_imsm(struct supertype *st, char *update, mddev_ident_t ident)
+static int update_subarray_imsm(struct supertype *st, char *subarray,
+                               char *update, mddev_ident_t ident)
 {
        /* update the subarray currently referenced by ->current_vol */
        struct intel_super *super = st->sb;
        struct imsm_super *mpb = super->anchor;
 
-       if (super->current_vol < 0)
-               return 2;
-
        if (strcmp(update, "name") == 0) {
                char *name = ident->name;
+               char *ep;
+               int vol;
 
-               if (is_subarray_active(st->subarray, st->devname)) {
+               if (is_subarray_active(subarray, st->devname)) {
                        fprintf(stderr,
                                Name ": Unable to update name of active subarray\n");
                        return 2;
@@ -4250,20 +4250,24 @@ static int update_subarray_imsm(struct supertype *st, char *update, mddev_ident_
                if (!check_name(super, name, 0))
                        return 2;
 
+               vol = strtoul(subarray, &ep, 10);
+               if (*ep != '\0' || vol >= super->anchor->num_raid_devs)
+                       return 2;
+
                if (st->update_tail) {
                        struct imsm_update_rename_array *u = malloc(sizeof(*u));
 
                        if (!u)
                                return 2;
                        u->type = update_rename_array;
-                       u->dev_idx = super->current_vol;
+                       u->dev_idx = vol;
                        snprintf((char *) u->name, MAX_RAID_SERIAL_LEN, "%s", name);
                        append_metadata_update(st, u, sizeof(*u));
                } else {
                        struct imsm_dev *dev;
                        int i;
 
-                       dev = get_imsm_dev(super, super->current_vol);
+                       dev = get_imsm_dev(super, vol);
                        snprintf((char *) dev->volume, MAX_RAID_SERIAL_LEN, "%s", name);
                        for (i = 0; i < mpb->num_raid_devs; i++) {
                                dev = get_imsm_dev(super, i);
diff --git a/util.c b/util.c
index 66c7f0b9d6ddfa5f26ccc3bc77d13a481c72fbac..83a972e79c16032f296d93409b64dee712bc7d29 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1446,6 +1446,7 @@ int is_container_active(char *container)
 int open_subarray(char *dev, char *subarray, struct supertype *st, int quiet)
 {
        struct mdinfo *mdi;
+       struct mdinfo *info;
        int fd, err = 1;
 
        fd = open(dev, O_RDWR|O_EXCL);
@@ -1495,12 +1496,10 @@ int open_subarray(char *dev, char *subarray, struct supertype *st, int quiet)
                goto free_sysfs;
        }
 
-       strncpy(st->subarray, subarray, sizeof(st->subarray)-1);
-
        if (st->ss->load_super(st, fd, NULL)) {
                if (!quiet)
-                       fprintf(stderr, Name ": Failed to find subarray-%s in %s\n",
-                               st->subarray, dev);
+                       fprintf(stderr, Name ": Failed to load metadata for %s\n",
+                               dev);
                goto free_name;
        }
 
@@ -1510,6 +1509,15 @@ int open_subarray(char *dev, char *subarray, struct supertype *st, int quiet)
                goto free_super;
        }
 
+       info = st->ss->container_content(st, subarray);
+       if (!info) {
+               if (!quiet)
+                       fprintf(stderr, Name ": Failed to find subarray-%s in %s\n",
+                               subarray, dev);
+               goto free_super;
+       }
+       free(info);
+
        err = 0;
 
  free_super: