]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Create.c
Support --uuid= with --create to choose your own UUID.
[thirdparty/mdadm.git] / Create.c
index fe7a3abebe5dd3f349f560ec19bf6ffb5e8a5d31..21e578b8bb0b7c4bd9860400f1635e0f5302665b 100644 (file)
--- a/Create.c
+++ b/Create.c
 #include "mdadm.h"
 #include       "md_u.h"
 #include       "md_p.h"
+#include       <ctype.h>
 
 int Create(struct supertype *st, char *mddev, int mdfd,
           int chunk, int level, int layout, unsigned long long size, int raiddisks, int sparedisks,
-          char *name,
+          char *name, char *homehost, int *uuid,
           int subdevs, mddev_dev_t devlist,
           int runstop, int verbose, int force, int assume_clean,
           char *bitmap_file, int bitmap_chunk, int write_behind, int delay)
@@ -179,7 +180,6 @@ int Create(struct supertype *st, char *mddev, int mdfd,
        dnum = 0;
        for (dv=devlist; dv; dv=dv->next, dnum++) {
                char *dname = dv->devname;
-               unsigned long dsize;
                unsigned long long ldsize, freesize;
                int fd;
                if (strcasecmp(dname, "missing")==0) {
@@ -198,21 +198,15 @@ int Create(struct supertype *st, char *mddev, int mdfd,
                        fail=1;
                        continue;
                }
-#ifdef BLKGETSIZE64
-               if (ioctl(fd, BLKGETSIZE64, &ldsize)==0)
-                       ;
-               else
-#endif
-               if (ioctl(fd, BLKGETSIZE, &dsize)) {
-                       fprintf(stderr, Name ": Cannot get size of %s: %s\n",
-                               dname, strerror(errno));
+               if (!get_dev_size(fd, dname, &ldsize)) {
                        fail = 1;
                        close(fd);
                        continue;
                }
-               else {
-                       ldsize = dsize;
-                       ldsize <<= 9;
+               if (st == NULL) {
+                       struct createinfo *ci = conf_get_create_info();
+                       if (ci)
+                               st = ci->supertype;
                }
                if (st == NULL) {
                        /* Need to choose a default metadata, which is different
@@ -357,7 +351,7 @@ int Create(struct supertype *st, char *mddev, int mdfd,
                 * which is array.size * raid_disks / ncopies;
                 * .. but convert to sectors.
                 */
-               int ncopies = (layout>>8) * (layout & 255);
+               int ncopies = ((layout>>8) & 255) * (layout & 255);
                bitmapsize = (unsigned long long)size * raiddisks / ncopies * 2;
 /*             printf("bms=%llu as=%d rd=%d nc=%d\n", bitmapsize, size, raiddisks, ncopies);*/
        } else
@@ -389,7 +383,31 @@ int Create(struct supertype *st, char *mddev, int mdfd,
        array.chunk_size = chunk*1024;
        array.major_version = st->ss->major;
 
-       if (!st->ss->init_super(st, &super, &array, size, name))
+       if (name == NULL || *name == 0) {
+               /* base name on mddev */
+               /*  /dev/md0 -> 0
+                *  /dev/md_d0 -> d0
+                *  /dev/md/1 -> 1
+                *  /dev/md/d1 -> d1
+                *  /dev/md/home -> home
+                *  /dev/mdhome -> home
+                */
+               name = strrchr(mddev, '/');
+               if (name) {
+                       name++;
+                       if (strncmp(name, "md_d", 4)==0 &&
+                           strlen(name) > 4 &&
+                           isdigit(name[4]) &&
+                           (name-mddev) == 5 /* /dev/ */)
+                               name += 3;
+                       else if (strncmp(name, "md", 2)==0 &&
+                                strlen(name) > 2 &&
+                                isdigit(name[2]) &&
+                                (name-mddev) == 5 /* /dev/ */)
+                               name += 2;
+               }
+       }
+       if (!st->ss->init_super(st, &super, &array, size, name, homehost, uuid))
                return 1;
 
        if (bitmap_file && vers < 9003) {
@@ -405,7 +423,8 @@ int Create(struct supertype *st, char *mddev, int mdfd,
                        fprintf(stderr, Name ": internal bitmaps not supported by this kernel.\n");
                        return 1;
                }
-               if (!st->ss->add_internal_bitmap(st, super, bitmap_chunk, delay, write_behind,
+               if (!st->ss->add_internal_bitmap(st, super, &bitmap_chunk,
+                                                delay, write_behind,
                                                 bitmapsize, 1, major)) {
                        fprintf(stderr, Name ": Given bitmap chunk size not supported.\n");
                        return 1;
@@ -491,6 +510,7 @@ int Create(struct supertype *st, char *mddev, int mdfd,
                                fstat(fd, &stb);
                                disk.major = major(stb.st_rdev);
                                disk.minor = minor(stb.st_rdev);
+                               remove_partitions(fd);
                                close(fd);
                        }
                        switch(pass){