]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Create.c
DDF: write_init_super_ddf: don't zero superblocks for subarrays
[thirdparty/mdadm.git] / Create.c
index 4dd27040ec739c1b0b018e883528996b3bcc6084..ac22f77c92d3e5205bcb7773b8958ae6d88eb3a4 100644 (file)
--- a/Create.c
+++ b/Create.c
@@ -1,7 +1,7 @@
 /*
  * mdadm - manage Linux "md" devices aka RAID arrays.
  *
- * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
+ * Copyright (C) 2001-2012 Neil Brown <neilb@suse.de>
  *
  *
  *    This program is free software; you can redistribute it and/or modify
@@ -22,7 +22,7 @@
  *    Email: <neilb@suse.de>
  */
 
-#include "mdadm.h"
+#include       "mdadm.h"
 #include       "md_u.h"
 #include       "md_p.h"
 #include       <ctype.h>
@@ -61,12 +61,11 @@ static int default_layout(struct supertype *st, int level, int verbose)
        return layout;
 }
 
-
 int Create(struct supertype *st, char *mddev,
           char *name, int *uuid,
           int subdevs, struct mddev_dev *devlist,
           struct shape *s,
-          struct context *c)
+          struct context *c, unsigned long long data_offset)
 {
        /*
         * Create a new raid array.
@@ -198,7 +197,6 @@ int Create(struct supertype *st, char *mddev,
 
        /* now set some defaults */
 
-
        if (s->layout == UnSet) {
                do_default_layout = 1;
                s->layout = default_layout(st, s->level, c->verbose);
@@ -253,7 +251,9 @@ int Create(struct supertype *st, char *mddev,
                s->size &= ~(unsigned long long)(s->chunk - 1);
        newsize = s->size * 2;
        if (st && ! st->ss->validate_geometry(st, s->level, s->layout, s->raiddisks,
-                                             &s->chunk, s->size*2, NULL, &newsize, c->verbose>=0))
+                                             &s->chunk, s->size*2,
+                                             data_offset, NULL,
+                                             &newsize, c->verbose>=0))
                return 1;
 
        if (s->chunk && s->chunk != UnSet) {
@@ -289,6 +289,7 @@ int Create(struct supertype *st, char *mddev,
                char *dname = dv->devname;
                unsigned long long freesize;
                int dfd;
+               char *doff;
 
                if (strcasecmp(dname, "missing")==0) {
                        if (first_missing > dnum)
@@ -298,6 +299,16 @@ int Create(struct supertype *st, char *mddev,
                        missing_disks ++;
                        continue;
                }
+               if (data_offset == VARIABLE_OFFSET) {
+                       doff = strchr(dname, ':');
+                       if (doff) {
+                               *doff++ = 0;
+                               dv->data_offset = parse_size(doff);
+                       } else
+                               dv->data_offset = INVALID_SECTORS;
+               } else
+                       dv->data_offset = data_offset;
+
                dfd = open(dname, O_RDONLY);
                if (dfd < 0) {
                        pr_err("cannot open %s: %s\n",
@@ -334,8 +345,9 @@ int Create(struct supertype *st, char *mddev,
                                        s->layout = default_layout(st, s->level, c->verbose);
                                switch (st->ss->validate_geometry(
                                                st, s->level, s->layout, s->raiddisks,
-                                               &s->chunk, s->size*2, dname, &freesize,
-                                               c->verbose > 0)) {
+                                               &s->chunk, s->size*2,
+                                               dv->data_offset, dname,
+                                               &freesize, c->verbose > 0)) {
                                case -1: /* Not valid, message printed, and not
                                          * worth checking any further */
                                        exit(2);
@@ -370,8 +382,9 @@ int Create(struct supertype *st, char *mddev,
                                s->layout = default_layout(st, s->level, 0);
                        if (!st->ss->validate_geometry(st, s->level, s->layout,
                                                       s->raiddisks,
-                                                      &s->chunk, s->size*2, dname,
-                                                      &freesize,
+                                                      &s->chunk, s->size*2,
+                                                      dv->data_offset,
+                                                      dname, &freesize,
                                                       c->verbose >= 0)) {
 
                                pr_err("%s is not suitable for "
@@ -395,6 +408,11 @@ int Create(struct supertype *st, char *mddev,
                                do_default_chunk = 0;
                        }
                }
+               if (!freesize) {
+                       pr_err("no free space left on %s\n", dname);
+                       fail = 1;
+                       continue;
+               }
 
                if (s->size && freesize < s->size) {
                        pr_err("%s is smaller than given size."
@@ -472,6 +490,7 @@ int Create(struct supertype *st, char *mddev,
                        if (!st->ss->validate_geometry(st, s->level, s->layout,
                                                       s->raiddisks,
                                                       &s->chunk, minsize*2,
+                                                      data_offset,
                                                       NULL, NULL, 0)) {
                                pr_err("devices too large for RAID level %d\n", s->level);
                                return 1;
@@ -487,6 +506,17 @@ int Create(struct supertype *st, char *mddev,
                                pr_err("size set to %lluK\n", s->size);
                }
        }
+
+       if (!s->bitmap_file &&
+           s->level >= 1 &&
+           (s->write_behind || s->size > 100*1024*1024ULL)) {
+               if (c->verbose > 0)
+                       pr_err("automatically enabling write-intent bitmap on large array\n");
+               s->bitmap_file = "internal";
+       }
+       if (s->bitmap_file && strcmp(s->bitmap_file, "none") == 0)
+               s->bitmap_file = NULL;
+
        if (!have_container && s->level > 0 && ((maxsize-s->size)*100 > maxsize)) {
                if (c->runstop != 1 || c->verbose >= 0)
                        pr_err("largest drive (%s) exceeds size (%lluK) by more than 1%%\n",
@@ -494,7 +524,7 @@ int Create(struct supertype *st, char *mddev,
                warn = 1;
        }
 
-       if (st->ss->detail_platform && st->ss->detail_platform(0, 1) != 0) {
+       if (st->ss->detail_platform && st->ss->detail_platform(0, 1, NULL) != 0) {
                if (c->runstop != 1 || c->verbose >= 0)
                        pr_err("%s unable to enumerate platform support\n"
                                "    array may not be compatible with hardware/firmware\n",
@@ -641,7 +671,7 @@ int Create(struct supertype *st, char *mddev,
         *          including spares
         * failed_disks is the number of disks marked failed
         *
-         * Ideally, the kernel would keep these (except raid_disks)
+        * Ideally, the kernel would keep these (except raid_disks)
         * up-to-date as we ADD_NEW_DISK, but it doesn't (yet).
         * So for now, we assume that all raid and spare
         * devices will be given.
@@ -657,6 +687,7 @@ int Create(struct supertype *st, char *mddev,
                /* base name on mddev */
                /*  /dev/md0 -> 0
                 *  /dev/md_d0 -> d0
+                *  /dev/md_foo -> foo
                 *  /dev/md/1 -> 1
                 *  /dev/md/d1 -> d1
                 *  /dev/md/home -> home
@@ -666,9 +697,8 @@ int Create(struct supertype *st, char *mddev,
                name = strrchr(mddev, '/');
                if (name) {
                        name++;
-                       if (strncmp(name, "md_d", 4)==0 &&
-                           strlen(name) > 4 &&
-                           isdigit(name[4]) &&
+                       if (strncmp(name, "md_", 3)==0 &&
+                           strlen(name) > 3 &&
                            (name-mddev) == 5 /* /dev/ */)
                                name += 3;
                        else if (strncmp(name, "md", 2)==0 &&
@@ -678,36 +708,37 @@ int Create(struct supertype *st, char *mddev,
                                name += 2;
                }
        }
-       if (!st->ss->init_super(st, &info.array, s->size, name, c->homehost, uuid))
+       if (!st->ss->init_super(st, &info.array, s->size, name, c->homehost, uuid,
+                               data_offset))
                goto abort_locked;
 
        total_slots = info.array.nr_disks;
        st->ss->getinfo_super(st, &info, NULL);
-       sysfs_init(&info, mdfd, 0);
+       sysfs_init(&info, mdfd, NULL);
 
        if (did_default && c->verbose >= 0) {
                if (is_subarray(info.text_version)) {
-                       int dnum = devname2devnum(info.text_version+1);
-                       char *path;
-                       int mdp = get_mdp_major();
+                       char devnm[32];
+                       char *ep;
                        struct mdinfo *mdi;
-                       if (dnum > 0)
-                               path = map_dev(MD_MAJOR, dnum, 1);
-                       else
-                               path = map_dev(mdp, (-1-dnum)<< 6, 1);
 
-                       mdi = sysfs_read(-1, dnum, GET_VERSION);
+                       strncpy(devnm, info.text_version+1, 32);
+                       devnm[31] = 0;
+                       ep = strchr(devnm, '/');
+                       if (ep)
+                               *ep = 0;
 
-                       pr_err("Creating array inside "
-                               "%s container %s\n", 
-                               mdi?mdi->text_version:"managed", path);
+                       mdi = sysfs_read(-1, devnm, GET_VERSION);
+
+                       pr_err("Creating array inside %s container %s\n",
+                               mdi?mdi->text_version:"managed", devnm);
                        sysfs_free(mdi);
                } else
                        pr_err("Defaulting to version"
                                " %s metadata\n", info.text_version);
        }
 
-       map_update(&map, fd2devnum(mdfd), info.text_version,
+       map_update(&map, fd2devnm(mdfd), info.text_version,
                   info.uuid, chosen_name);
        map_unlock(&map);
 
@@ -738,10 +769,9 @@ int Create(struct supertype *st, char *mddev,
                s->bitmap_file = NULL;
        }
 
+       sysfs_init(&info, mdfd, NULL);
 
-       sysfs_init(&info, mdfd, 0);
-
-       if (st->ss->external && st->container_dev != NoMdDev) {
+       if (st->ss->external && st->container_devnm[0]) {
                /* member */
 
                /* When creating a member, we need to be careful
@@ -756,17 +786,17 @@ int Create(struct supertype *st, char *mddev,
                 *
                 * For now, fail if it is already running.
                 */
-               container_fd = open_dev_excl(st->container_dev);
+               container_fd = open_dev_excl(st->container_devnm);
                if (container_fd < 0) {
                        pr_err("Cannot get exclusive "
                                "open on container - weird.\n");
                        goto abort;
                }
-               if (mdmon_running(st->container_dev)) {
+               if (mdmon_running(st->container_devnm)) {
                        if (c->verbose)
                                pr_err("reusing mdmon "
                                        "for %s.\n",
-                                       devnum2devname(st->container_dev));
+                                       st->container_devnm);
                        st->update_tail = &st->updates;
                } else
                        need_mdmon = 1;
@@ -802,7 +832,7 @@ int Create(struct supertype *st, char *mddev,
        }
 
        infos = xmalloc(sizeof(*infos) * total_slots);
-
+       enable_fds(total_slots);
        for (pass=1; pass <=2 ; pass++) {
                struct mddev_dev *moved_disk = NULL; /* the disk that was moved out of the insert point */
 
@@ -845,7 +875,7 @@ int Create(struct supertype *st, char *mddev,
                                        fd = -1;
                                else {
                                        if (st->ss->external &&
-                                           st->container_dev != NoMdDev)
+                                           st->container_devnm[0])
                                                fd = open(dv->devname, O_RDWR);
                                        else
                                                fd = open(dv->devname, O_RDWR|O_EXCL);
@@ -863,7 +893,8 @@ 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,
+                                                        dv->data_offset)) {
                                        ioctl(mdfd, STOP_ARRAY, NULL);
                                        goto abort;
                                }
@@ -912,10 +943,10 @@ int Create(struct supertype *st, char *mddev,
                        st->ss->getinfo_super(st, &info_new, NULL);
                        if (st->ss->external && s->level != LEVEL_CONTAINER &&
                            !same_uuid(info_new.uuid, info.uuid, 0)) {
-                               map_update(&map, fd2devnum(mdfd),
+                               map_update(&map, fd2devnm(mdfd),
                                           info_new.text_version,
                                           info_new.uuid, chosen_name);
-                               me = map_by_devnum(&map, st->container_dev);
+                               me = map_by_devnm(&map, st->container_devnm);
                        }
 
                        if (st->ss->write_init_super(st)) {
@@ -928,7 +959,7 @@ int Create(struct supertype *st, char *mddev,
                                char *path = xstrdup(me->path);
 
                                st->ss->getinfo_super(st, &info_new, NULL);
-                               map_update(&map, st->container_dev,
+                               map_update(&map, st->container_devnm,
                                           info_new.text_version,
                                           info_new.uuid, path);
                                free(path);
@@ -996,14 +1027,19 @@ int Create(struct supertype *st, char *mddev,
                                ioctl(mdfd, STOP_ARRAY, NULL);
                                goto abort;
                        }
+                       /* if start_ro module parameter is set, array is
+                        * auto-read-only, which is bad as the resync won't
+                        * start.  So lets make it read-write now.
+                        */
+                       ioctl(mdfd, RESTART_ARRAY_RW, NULL);
                }
                if (c->verbose >= 0)
                        pr_err("array %s started.\n", mddev);
-               if (st->ss->external && st->container_dev != NoMdDev) {
+               if (st->ss->external && st->container_devnm[0]) {
                        if (need_mdmon)
-                               start_mdmon(st->container_dev);
+                               start_mdmon(st->container_devnm);
 
-                       ping_monitor_by_id(st->container_dev);
+                       ping_monitor(st->container_devnm);
                        close(container_fd);
                }
                wait_for(chosen_name, mdfd);
@@ -1016,7 +1052,7 @@ int Create(struct supertype *st, char *mddev,
  abort:
        map_lock(&map);
  abort_locked:
-       map_remove(&map, fd2devnum(mdfd));
+       map_remove(&map, fd2devnm(mdfd));
        map_unlock(&map);
 
        if (mdfd >= 0)