]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Create.c
Create: cleanup after failed create in duplicated array member case
[thirdparty/mdadm.git] / Create.c
index 5b01b63d61cea1f7a9d67bf0c27a65c2d5737d9c..b04388f5e338205c3136e7ef6ec9a14ea7063a8a 100644 (file)
--- a/Create.c
+++ b/Create.c
@@ -375,16 +375,27 @@ int Create(struct supertype *st, char *mddev,
                        warn |= check_ext2(fd, dname);
                        warn |= check_reiser(fd, dname);
                        warn |= check_raid(fd, dname);
-                       if (st && strcmp(st->ss->name, "1.x") == 0 &&
+                       if (strcmp(st->ss->name, "1.x") == 0 &&
+                           st->minor_version >= 1)
+                               /* metadata at front */
+                               warn |= check_partitions(fd, dname, 0);
+                       else if (level == 1 || level == LEVEL_CONTAINER)
+                               /* partitions could be meaningful */
+                               warn |= check_partitions(fd, dname, freesize*2);
+                       else
+                               /* partitions cannot be meaningful */
+                               warn |= check_partitions(fd, dname, 0);
+                       if (strcmp(st->ss->name, "1.x") == 0 &&
                            st->minor_version >= 1 &&
                            did_default &&
-                           level == 1) {
-                               warn = 1;
+                           level == 1 &&
+                           (warn & 1024) == 0) {
+                               warn |= 1024;
                                fprintf(stderr, Name ": Note: this array has metadata at the start and\n"
                                        "    may not be suitable as a boot device.  If you plan to\n"
-                                       "    store '/' or '/boot' on this device please ensure that\n"
+                                       "    store '/boot' on this device please ensure that\n"
                                        "    your boot-loader understands md/v1.x metadata, or use\n"
-                                       "    --metadata=1.0\n");
+                                       "    --metadata=0.90\n");
                        }
                        close(fd);
                }
@@ -527,7 +538,7 @@ int Create(struct supertype *st, char *mddev,
             assume_clean
                ) {
                info.array.state = 1; /* clean, but one+ drive will be missing*/
-               info.resync_start = ~0ULL;
+               info.resync_start = MaxSector;
        } else {
                info.array.state = 0; /* not clean, but no errors */
                info.resync_start = 0;
@@ -640,6 +651,11 @@ int Create(struct supertype *st, char *mddev,
                        fprintf(stderr, Name ": internal bitmaps not supported by this kernel.\n");
                        goto abort;
                }
+               if (!st->ss->add_internal_bitmap) {
+                       fprintf(stderr, Name ": internal bitmaps not supported with %s metadata\n",
+                               st->ss->name);
+                       goto abort;
+               }
                if (!st->ss->add_internal_bitmap(st, &bitmap_chunk,
                                                 delay, write_behind,
                                                 bitmapsize, 1, major_num)) {
@@ -773,8 +789,10 @@ int Create(struct supertype *st, char *mddev,
                                if (fd >= 0)
                                        remove_partitions(fd);
                                if (st->ss->add_to_super(st, &inf->disk,
-                                                        fd, dv->devname))
+                                                        fd, dv->devname)) {
+                                       ioctl(mdfd, STOP_ARRAY, NULL);
                                        goto abort;
+                               }
                                st->ss->getinfo_super(st, inf);
                                safe_mode_delay = inf->safe_mode_delay;
 
@@ -878,7 +896,7 @@ int Create(struct supertype *st, char *mddev,
                        if (ioctl(mdfd, RUN_ARRAY, &param)) {
                                fprintf(stderr, Name ": RUN_ARRAY failed: %s\n",
                                        strerror(errno));
-                               Manage_runstop(mddev, mdfd, -1, 0);
+                               ioctl(mdfd, STOP_ARRAY, NULL);
                                goto abort;
                        }
                }
@@ -899,6 +917,10 @@ int Create(struct supertype *st, char *mddev,
        return 0;
 
  abort:
+       map_lock(&map);
+       map_remove(&map, fd2devnum(mdfd));
+       map_unlock(&map);
+
        if (mdfd >= 0)
                close(mdfd);
        return 1;