]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Incremental.c
FIX: Detect error and rollback metadata
[thirdparty/mdadm.git] / Incremental.c
index c2a89c0b8c75dc5857b8484488739ec5b9f9840a..a61f45336aa58c7b59309ca55fd3fe8ab27f921e 100644 (file)
@@ -259,8 +259,7 @@ int Incremental(char *devname, int verbose, int runstop,
 
        name_to_use = info.name;
        if (name_to_use[0] == 0 &&
-           info.array.level == LEVEL_CONTAINER &&
-           trustworthy == LOCAL) {
+           info.array.level == LEVEL_CONTAINER) {
                name_to_use = info.text_version;
                trustworthy = METADATA;
        }
@@ -326,7 +325,6 @@ int Incremental(char *devname, int verbose, int runstop,
                        fprintf(stderr, Name
                      ": You have an old buggy kernel which cannot support\n"
                                "      --incremental reliably.  Aborting.\n");
-                       sysfs_free(sra);
                        rv = 2;
                        goto out_unlock;
                }
@@ -386,6 +384,12 @@ int Incremental(char *devname, int verbose, int runstop,
                        sprintf(dn, "%d:%d", sra->devs->disk.major,
                                sra->devs->disk.minor);
                        dfd2 = dev_open(dn, O_RDONLY);
+                       if (dfd2 < 0) {
+                               fprintf(stderr, Name
+                                       ": unable to open %s\n", devname);
+                               rv = 2;
+                               goto out_unlock;
+                       }
                        st2 = dup_super(st);
                        if (st2->ss->load_super(st2, dfd2, NULL) ||
                            st->ss->compare_super(st, st2) != 0) {
@@ -410,19 +414,19 @@ int Incremental(char *devname, int verbose, int runstop,
                                goto out_unlock;
                        }
                }
-               info2.disk.major = major(stb.st_rdev);
-               info2.disk.minor = minor(stb.st_rdev);
+               info.disk.major = major(stb.st_rdev);
+               info.disk.minor = minor(stb.st_rdev);
                /* add disk needs to know about containers */
                if (st->ss->external)
                        sra->array.level = LEVEL_CONTAINER;
-               err = add_disk(mdfd, st, sra, &info2);
+               err = add_disk(mdfd, st, sra, &info);
                if (err < 0 && errno == EBUSY) {
                        /* could be another device present with the same
                         * disk.number. Find and reject any such
                         */
                        find_reject(mdfd, st, sra, info.disk.number,
                                    info.events, verbose, chosen_name);
-                       err = add_disk(mdfd, st, sra, &info2);
+                       err = add_disk(mdfd, st, sra, &info);
                }
                if (err < 0) {
                        fprintf(stderr, Name ": failed to add %s to %s: %s.\n",
@@ -441,10 +445,12 @@ int Incremental(char *devname, int verbose, int runstop,
        if (info.array.level == LEVEL_CONTAINER) {
                int devnum = devnum; /* defined and used iff ->external */
                /* Try to assemble within the container */
+               sysfs_uevent(sra, "change");
                if (verbose >= 0)
                        fprintf(stderr, Name
-                               ": container %s now has %d devices\n",
-                               chosen_name, info.array.working_disks);
+                               ": container %s now has %d device%s\n",
+                               chosen_name, info.array.working_disks,
+                               info.array.working_disks==1?"":"s");
                wait_for(chosen_name, mdfd);
                if (st->ss->external)
                        devnum = fd2devnum(mdfd);
@@ -479,7 +485,7 @@ int Incremental(char *devname, int verbose, int runstop,
        active_disks = count_active(st, sra, mdfd, &avail, &info);
        if (enough(info.array.level, info.array.raid_disks,
                   info.array.layout, info.array.state & 1,
-                  avail, active_disks) == 0) {
+                  avail) == 0) {
                if (verbose >= 0)
                        fprintf(stderr, Name
                             ": %s attached to %s, not enough to start (%d).\n",
@@ -878,7 +884,7 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                         * to obtain minimum spare size */
                        struct supertype *st3 = dup_super(st2);
                        int mdfd = open_dev(mp->devnum);
-                       if (!mdfd) {
+                       if (mdfd < 0) {
                                free(st3);
                                goto next;
                        }
@@ -1323,6 +1329,7 @@ int IncrementalScan(int verbose)
                                        strerror(errno));
                                rv = 1;
                        }
+                       sysfs_free(sra);
                }
        }
        return rv;
@@ -1404,9 +1411,6 @@ static int Incremental_container(struct supertype *st, char *devname,
        /* when nothing to activate - quit */
        if (list == NULL)
                return 0;
-       if (map_lock(&map))
-               fprintf(stderr, Name ": failed to get exclusive lock on "
-                       "mapfile\n");
        for (ra = list ; ra ; ra = ra->next) {
                int mdfd;
                char chosen_name[1024];
@@ -1501,10 +1505,8 @@ static int Incremental_container(struct supertype *st, char *devname,
 
        /* don't move spares to container with volume being activated
           when all volumes are blocked */
-       if (ra_all == ra_blocked) {
-               map_unlock(&map);
+       if (ra_all == ra_blocked)
                return 0;
-       }
 
        /* Now move all suitable spares from spare container */
        domains = domain_from_array(list, st->ss->name);