]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Create.c
Improve partition table code.
[thirdparty/mdadm.git] / Create.c
index d33f891421795a3a00561fdb333df3a19ffda25b..909ac5da5fcba1fad615e402a4d9da503edee9bd 100644 (file)
--- a/Create.c
+++ b/Create.c
@@ -1,7 +1,7 @@
 /*
  * mdadm - manage Linux "md" devices aka RAID arrays.
  *
- * Copyright (C) 2001-2006 Neil Brown <neilb@suse.de>
+ * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
  *
  *
  *    This program is free software; you can redistribute it and/or modify
  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  *    Author: Neil Brown
- *    Email: <neilb@cse.unsw.edu.au>
- *    Paper: Neil Brown
- *           School of Computer Science and Engineering
- *           The University of New South Wales
- *           Sydney, 2052
- *           Australia
+ *    Email: <neilb@suse.de>
  */
 
 #include "mdadm.h"
@@ -200,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) {
@@ -239,8 +234,15 @@ int Create(struct supertype *st, char *mddev,
        case 10:
        case 6:
        case 0:
-       case LEVEL_LINEAR: /* linear */
                if (chunk == 0) {
+                       chunk = 512;
+                       if (verbose > 0)
+                               fprintf(stderr, Name ": chunk size defaults to 512K\n");
+               }
+               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");
@@ -261,6 +263,8 @@ int Create(struct supertype *st, char *mddev,
                return 1;
        }
        
+       if (size && chunk)
+               size &= ~(unsigned long long)(chunk - 1);
        newsize = size * 2;
        if (st && ! st->ss->validate_geometry(st, level, layout, raiddisks,
                                              chunk, size*2, NULL, &newsize, verbose>=0))
@@ -328,7 +332,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 "
@@ -371,6 +375,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);
                }
        }
@@ -512,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;
@@ -795,7 +821,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);
+                       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);
+                               map_update(&map, st->container_dev,
+                                          info_new.text_version,
+                                          info_new.uuid, path);
+                               free(path);
+                       }
+                       map_unlock(&map);
+
                        flush_metadata_updates(st);
                }
        }
@@ -808,7 +866,7 @@ int Create(struct supertype *st, char *mddev,
                sysfs_uevent(&info, "change");
                if (verbose >= 0)
                        fprintf(stderr, Name ": container %s prepared.\n", mddev);
-               wait_for(chosen_name);
+               wait_for(chosen_name, mdfd);
        } else if (runstop == 1 || subdevs >= raiddisks) {
                if (st->ss->external) {
                        switch(level) {
@@ -844,7 +902,7 @@ int Create(struct supertype *st, char *mddev,
                        ping_monitor(devnum2devname(st->container_dev));
                        close(container_fd);
                }
-               wait_for(chosen_name);
+               wait_for(chosen_name, mdfd);
        } else {
                fprintf(stderr, Name ": not starting array - not enough devices.\n");
        }