]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
allow add_to_super to return errors
authorDan Williams <dan.j.williams@intel.com>
Wed, 26 Nov 2008 22:39:51 +0000 (15:39 -0700)
committerNeilBrown <neilb@suse.de>
Thu, 27 Nov 2008 04:30:39 +0000 (15:30 +1100)
Prepare add_to_super to validate disks against the platform capabilities

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Create.c
Manage.c
mdadm.h
super-ddf.c
super-intel.c
super0.c
super1.c

index 783ab09f974bff2c5721bbdc29c227f0597a7b63..424be12c5ce958270c44ebb14aa8cc892b12d616 100644 (file)
--- a/Create.c
+++ b/Create.c
@@ -705,8 +705,12 @@ int Create(struct supertype *st, char *mddev,
                                inf->disk.minor = minor(stb.st_rdev);
 
                                remove_partitions(fd);
                                inf->disk.minor = minor(stb.st_rdev);
 
                                remove_partitions(fd);
-                               st->ss->add_to_super(st, &inf->disk,
-                                                    fd, dv->devname);
+                               if (st->ss->add_to_super(st, &inf->disk,
+                                                        fd, dv->devname)) {
+                                       fprintf(stderr, Name ": failed to add %s\n",
+                                               dv->devname);
+                                       goto abort;
+                               }
                                st->ss->getinfo_super(st, inf);
                                safe_mode_delay = inf->safe_mode_delay;
 
                                st->ss->getinfo_super(st, inf);
                                safe_mode_delay = inf->safe_mode_delay;
 
index ccc13c4aebe6c45ca5af61ceee0d31fa03809ece..4998c9477aa924e9786d222e78657d7841fee423 100644 (file)
--- a/Manage.c
+++ b/Manage.c
@@ -624,8 +624,13 @@ int Manage_subdevs(char *devname, int fd,
                                if (dv->writemostly == 1)
                                        disc.state |= 1 << MD_DISK_WRITEMOSTLY;
                                dfd = open(dv->devname, O_RDWR | O_EXCL|O_DIRECT);
                                if (dv->writemostly == 1)
                                        disc.state |= 1 << MD_DISK_WRITEMOSTLY;
                                dfd = open(dv->devname, O_RDWR | O_EXCL|O_DIRECT);
-                               tst->ss->add_to_super(tst, &disc, dfd,
-                                                     dv->devname);
+                               if (tst->ss->add_to_super(tst, &disc, dfd,
+                                                         dv->devname)) {
+                                       fprintf(stderr, Name ": failed to add %s\n",
+                                               dv->devname);
+                                       close(dfd);
+                                       return 1;
+                               }
                                /* write_init_super will close 'dfd' */
                                if (tst->ss->external)
                                        /* mdmon will write the metadata */
                                /* write_init_super will close 'dfd' */
                                if (tst->ss->external)
                                        /* mdmon will write the metadata */
diff --git a/mdadm.h b/mdadm.h
index f7fd53e5cde6be193733c8e39a0a86aa709e1d69..05b79bafa9497843a59b308a3b227bd7a3f7ba1e 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -503,7 +503,7 @@ extern struct superswitch {
        /* update the metadata to include new device, either at create or
         * when hot-adding a spare.
         */
        /* update the metadata to include new device, either at create or
         * when hot-adding a spare.
         */
-       void (*add_to_super)(struct supertype *st, mdu_disk_info_t *dinfo,
+       int (*add_to_super)(struct supertype *st, mdu_disk_info_t *dinfo,
                             int fd, char *devname);
 
        /* Write metadata to one device when fixing problems or adding
                             int fd, char *devname);
 
        /* Write metadata to one device when fixing problems or adding
index 3e78ffca10a914960214d09f028833a8e7a288a0..3c97bb678b70161ca34eebc5228b0d4e80677058 100644 (file)
@@ -2050,7 +2050,7 @@ static void add_to_super_ddf_bvd(struct supertype *st,
 /* add a device to a container, either while creating it or while
  * expanding a pre-existing container
  */
 /* add a device to a container, either while creating it or while
  * expanding a pre-existing container
  */
-static void add_to_super_ddf(struct supertype *st,
+static int add_to_super_ddf(struct supertype *st,
                             mdu_disk_info_t *dk, int fd, char *devname)
 {
        struct ddf_super *ddf = st->sb;
                             mdu_disk_info_t *dk, int fd, char *devname)
 {
        struct ddf_super *ddf = st->sb;
@@ -2064,7 +2064,7 @@ static void add_to_super_ddf(struct supertype *st,
 
        if (ddf->currentconf) {
                add_to_super_ddf_bvd(st, dk, fd, devname);
 
        if (ddf->currentconf) {
                add_to_super_ddf_bvd(st, dk, fd, devname);
-               return;
+               return 0;
        }
 
        /* This is device numbered dk->number.  We need to create
        }
 
        /* This is device numbered dk->number.  We need to create
@@ -2076,7 +2076,7 @@ static void add_to_super_ddf(struct supertype *st,
                fprintf(stderr, Name
                        ": %s could allocate buffer for new disk, aborting\n",
                        __func__);
                fprintf(stderr, Name
                        ": %s could allocate buffer for new disk, aborting\n",
                        __func__);
-               abort();
+               return 1;
        }
        dd->major = major(stb.st_rdev);
        dd->minor = minor(stb.st_rdev);
        }
        dd->major = major(stb.st_rdev);
        dd->minor = minor(stb.st_rdev);
@@ -2147,6 +2147,8 @@ static void add_to_super_ddf(struct supertype *st,
                ddf->dlist = dd;
                ddf->updates_pending = 1;
        }
                ddf->dlist = dd;
                ddf->updates_pending = 1;
        }
+
+       return 0;
 }
 
 /*
 }
 
 /*
index 433fa464ce9e1fbf1fb99f23a6e12f57ae52b7fb..d39b88ca622e173598711510b50f668f0af9630f 100644 (file)
@@ -1911,7 +1911,7 @@ static int init_super_imsm(struct supertype *st, mdu_array_info_t *info,
 }
 
 #ifndef MDASSEMBLE
 }
 
 #ifndef MDASSEMBLE
-static void add_to_super_imsm_volume(struct supertype *st, mdu_disk_info_t *dk,
+static int add_to_super_imsm_volume(struct supertype *st, mdu_disk_info_t *dk,
                                     int fd, char *devname)
 {
        struct intel_super *super = st->sb;
                                     int fd, char *devname)
 {
        struct intel_super *super = st->sb;
@@ -1929,7 +1929,7 @@ static void add_to_super_imsm_volume(struct supertype *st, mdu_disk_info_t *dk,
                        break;
 
        if (!dl || ! (dk->state & (1<<MD_DISK_SYNC)))
                        break;
 
        if (!dl || ! (dk->state & (1<<MD_DISK_SYNC)))
-               return;
+               return 1;
 
        /* add a pristine spare to the metadata */
        if (dl->index < 0) {
 
        /* add a pristine spare to the metadata */
        if (dl->index < 0) {
@@ -1950,9 +1950,11 @@ static void add_to_super_imsm_volume(struct supertype *st, mdu_disk_info_t *dk,
                sum = __gen_imsm_checksum(mpb);
                mpb->family_num = __cpu_to_le32(sum);
        }
                sum = __gen_imsm_checksum(mpb);
                mpb->family_num = __cpu_to_le32(sum);
        }
+
+       return 0;
 }
 
 }
 
-static void add_to_super_imsm(struct supertype *st, mdu_disk_info_t *dk,
+static int add_to_super_imsm(struct supertype *st, mdu_disk_info_t *dk,
                              int fd, char *devname)
 {
        struct intel_super *super = st->sb;
                              int fd, char *devname)
 {
        struct intel_super *super = st->sb;
@@ -1962,17 +1964,15 @@ static void add_to_super_imsm(struct supertype *st, mdu_disk_info_t *dk,
        int rv;
        struct stat stb;
 
        int rv;
        struct stat stb;
 
-       if (super->current_vol >= 0) {
-               add_to_super_imsm_volume(st, dk, fd, devname);
-               return;
-       }
+       if (super->current_vol >= 0)
+               return add_to_super_imsm_volume(st, dk, fd, devname);
 
        fstat(fd, &stb);
        dd = malloc(sizeof(*dd));
        if (!dd) {
                fprintf(stderr,
                        Name ": malloc failed %s:%d.\n", __func__, __LINE__);
 
        fstat(fd, &stb);
        dd = malloc(sizeof(*dd));
        if (!dd) {
                fprintf(stderr,
                        Name ": malloc failed %s:%d.\n", __func__, __LINE__);
-               abort();
+               return 1;
        }
        memset(dd, 0, sizeof(*dd));
        dd->major = major(stb.st_rdev);
        }
        memset(dd, 0, sizeof(*dd));
        dd->major = major(stb.st_rdev);
@@ -2005,6 +2005,8 @@ static void add_to_super_imsm(struct supertype *st, mdu_disk_info_t *dk,
                dd->next = super->disks;
                super->disks = dd;
        }
                dd->next = super->disks;
                super->disks = dd;
        }
+
+       return 0;
 }
 
 static int store_imsm_mpb(int fd, struct intel_super *super);
 }
 
 static int store_imsm_mpb(int fd, struct intel_super *super);
index 92255c23cbec0f9f7e1776377bce2db03021a0d2..ab4232b0b5b34d10624e33060a28434e0f68db67 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -627,7 +627,7 @@ struct devinfo {
 
 #ifndef MDASSEMBLE
 /* Add a device to the superblock being created */
 
 #ifndef MDASSEMBLE
 /* Add a device to the superblock being created */
-static void add_to_super0(struct supertype *st, mdu_disk_info_t *dinfo,
+static int add_to_super0(struct supertype *st, mdu_disk_info_t *dinfo,
                          int fd, char *devname)
 {
        mdp_super_t *sb = st->sb;
                          int fd, char *devname)
 {
        mdp_super_t *sb = st->sb;
@@ -652,6 +652,8 @@ static void add_to_super0(struct supertype *st, mdu_disk_info_t *dinfo,
        di->disk = *dinfo;
        di->next = NULL;
        *dip = di;
        di->disk = *dinfo;
        di->next = NULL;
        *dip = di;
+
+       return 0;
 }
 #endif
 
 }
 #endif
 
index 3d392cb05c996dc96f0156c11dd0103707e10be6..9446948ab3cde218f0e3b487a8db599aae03fd26 100644 (file)
--- a/super1.c
+++ b/super1.c
@@ -796,7 +796,7 @@ struct devinfo {
 };
 #ifndef MDASSEMBLE
 /* Add a device to the superblock being created */
 };
 #ifndef MDASSEMBLE
 /* Add a device to the superblock being created */
-static void add_to_super1(struct supertype *st, mdu_disk_info_t *dk,
+static int add_to_super1(struct supertype *st, mdu_disk_info_t *dk,
                          int fd, char *devname)
 {
        struct mdp_superblock_1 *sb = st->sb;
                          int fd, char *devname)
 {
        struct mdp_superblock_1 *sb = st->sb;
@@ -822,6 +822,8 @@ static void add_to_super1(struct supertype *st, mdu_disk_info_t *dk,
        di->disk = *dk;
        di->next = NULL;
        *dip = di;
        di->disk = *dk;
        di->next = NULL;
        *dip = di;
+
+       return 0;
 }
 #endif
 
 }
 #endif