]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Create.c
Create: user container_dev rather than subarray for some tests.
[thirdparty/mdadm.git] / Create.c
index 8a73799c4448c727308228dc51c34049093ebe65..337040c22d9c48d184a5d06f37e5458ca0df5312 100644 (file)
--- a/Create.c
+++ b/Create.c
@@ -43,7 +43,7 @@ static int default_layout(struct supertype *st, int level, int verbose)
                        layout = 0x102; /* near=2, far=1 */
                        if (verbose > 0)
                                fprintf(stderr,
-                                       Name ": layout defaults to n1\n");
+                                       Name ": layout defaults to n2\n");
                        break;
                case 5:
                case 6:
@@ -195,7 +195,7 @@ int Create(struct supertype *st, char *mddev,
        if (st && st->ss->external && sparedisks) {
                fprintf(stderr,
                        Name ": This metadata type does not support "
-                       "spare disks are create time\n");
+                       "spare disks at create time\n");
                return 1;
        }
        if (subdevs > raiddisks+sparedisks) {
@@ -234,8 +234,19 @@ int Create(struct supertype *st, char *mddev,
        case 10:
        case 6:
        case 0:
-       case LEVEL_LINEAR: /* linear */
                if (chunk == 0) {
+                       if (st && st->ss->default_chunk)
+                               chunk = st->ss->default_chunk(st);
+
+                       chunk = chunk ? : 512;
+
+                       if (verbose > 0)
+                               fprintf(stderr, Name ": chunk size defaults to %dK\n", chunk);
+               }
+               break;
+       case LEVEL_LINEAR:
+               /* a chunksize of zero 0s perfectly valid (and preferred) since 2.6.16 */
+               if (get_linux_version() < 2006016 && chunk == 0) {
                        chunk = 64;
                        if (verbose > 0)
                                fprintf(stderr, Name ": chunk size defaults to 64K\n");
@@ -325,7 +336,7 @@ int Create(struct supertype *st, char *mddev,
                                                       raiddisks,
                                                       chunk, size*2, dname,
                                                       &freesize,
-                                                      verbose > 0)) {
+                                                      verbose >= 0)) {
 
                                fprintf(stderr,
                                        Name ": %s is not suitable for "
@@ -368,6 +379,28 @@ int Create(struct supertype *st, char *mddev,
                        warn |= check_ext2(fd, dname);
                        warn |= check_reiser(fd, dname);
                        warn |= check_raid(fd, dname);
+                       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 & 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 '/boot' on this device please ensure that\n"
+                                       "    your boot-loader understands md/v1.x metadata, or use\n"
+                                       "    --metadata=0.90\n");
+                       }
                        close(fd);
                }
        }
@@ -509,7 +542,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;
@@ -581,7 +614,7 @@ int Create(struct supertype *st, char *mddev,
 
        total_slots = info.array.nr_disks;
        sysfs_init(&info, mdfd, 0);
-       st->ss->getinfo_super(st, &info);
+       st->ss->getinfo_super(st, &info, NULL);
 
        if (did_default && verbose >= 0) {
                if (is_subarray(info.text_version)) {
@@ -622,6 +655,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)) {
@@ -634,7 +672,7 @@ int Create(struct supertype *st, char *mddev,
 
        sysfs_init(&info, mdfd, 0);
 
-       if (st->ss->external && st->subarray[0]) {
+       if (st->ss->external && st->container_dev != NoMdDev) {
                /* member */
 
                /* When creating a member, we need to be careful
@@ -737,7 +775,8 @@ int Create(struct supertype *st, char *mddev,
                                if (have_container)
                                        fd = -1;
                                else {
-                                       if (st->ss->external && st->subarray[0])
+                                       if (st->ss->external &&
+                                           st->container_dev != NoMdDev)
                                                fd = open(dv->devname, O_RDWR);
                                        else
                                                fd = open(dv->devname, O_RDWR|O_EXCL);
@@ -755,9 +794,11 @@ 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);
+                               }
+                               st->ss->getinfo_super(st, inf, NULL);
                                safe_mode_delay = inf->safe_mode_delay;
 
                                if (have_container && verbose > 0)
@@ -792,7 +833,39 @@ int Create(struct supertype *st, char *mddev,
                            dv == moved_disk && dnum != insert_point) break;
                }
                if (pass == 1) {
+                       struct mdinfo info_new;
+                       struct map_ent *me = NULL;
+
+                       /* check to see if the uuid has changed due to these
+                        * metadata changes, and if so update the member array
+                        * and container uuid.  Note ->write_init_super clears
+                        * the subarray cursor such that ->getinfo_super once
+                        * again returns container info.
+                        */
+                       map_lock(&map);
+                       st->ss->getinfo_super(st, &info_new, NULL);
+                       if (st->ss->external && level != LEVEL_CONTAINER &&
+                           !same_uuid(info_new.uuid, info.uuid, 0)) {
+                               map_update(&map, fd2devnum(mdfd),
+                                          info_new.text_version,
+                                          info_new.uuid, chosen_name);
+                               me = map_by_devnum(&map, st->container_dev);
+                       }
+
                        st->ss->write_init_super(st);
+
+                       /* update parent container uuid */
+                       if (me) {
+                               char *path = strdup(me->path);
+
+                               st->ss->getinfo_super(st, &info_new, NULL);
+                               map_update(&map, st->container_dev,
+                                          info_new.text_version,
+                                          info_new.uuid, path);
+                               free(path);
+                       }
+                       map_unlock(&map);
+
                        flush_metadata_updates(st);
                }
        }
@@ -828,13 +901,13 @@ 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;
                        }
                }
                if (verbose >= 0)
                        fprintf(stderr, Name ": array %s started.\n", mddev);
-               if (st->ss->external && st->subarray[0]) {
+               if (st->ss->external && st->container_dev != NoMdDev) {
                        if (need_mdmon)
                                start_mdmon(st->container_dev);
 
@@ -849,6 +922,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;