]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Build.c
sysfs: Use the presence of /sys/block/<dev>/md as indicator of valid device
[thirdparty/mdadm.git] / Build.c
diff --git a/Build.c b/Build.c
index e3f7fb2a246d79dcc3da63b35831db93f4ffcafe..691dd6f954f5ca6b23df0644780061c60633abf3 100644 (file)
--- a/Build.c
+++ b/Build.c
@@ -24,9 +24,9 @@
 
 #include "mdadm.h"
 
-#define REGISTER_DEV           _IO (MD_MAJOR, 1)
-#define START_MD               _IO (MD_MAJOR, 2)
-#define STOP_MD                _IO (MD_MAJOR, 3)
+#define REGISTER_DEV           _IO (MD_MAJOR, 1)
+#define START_MD               _IO (MD_MAJOR, 2)
+#define STOP_MD                        _IO (MD_MAJOR, 3)
 
 int Build(char *mddev, struct mddev_dev *devlist,
          struct shape *s, struct context *c)
@@ -56,6 +56,10 @@ int Build(char *mddev, struct mddev_dev *devlist,
        int uuid[4] = {0,0,0,0};
        struct map_ent *map = NULL;
 
+       if (s->level == UnSet) {
+               pr_err("a RAID level is needed to Build an array.\n");
+               return 1;
+       }
        /* scan all devices, make sure they really are block devices */
        for (dv = devlist; dv; dv=dv->next) {
                subdevs++;
@@ -115,7 +119,7 @@ int Build(char *mddev, struct mddev_dev *devlist,
        }
        mddev = chosen_name;
 
-       map_update(&map, fd2devnum(mdfd), "none", uuid, chosen_name);
+       map_update(&map, fd2devnm(mdfd), "none", uuid, chosen_name);
        map_unlock(&map);
 
        vers = md_get_version(mdfd);
@@ -124,7 +128,9 @@ int Build(char *mddev, struct mddev_dev *devlist,
        if (vers >= 9000) {
                mdu_array_info_t array;
                array.level = s->level;
-               array.size = s->size == MAX_SIZE ? 0 : s->size;
+               if (s->size == MAX_SIZE)
+                       s->size = 0;
+               array.size = s->size;
                array.nr_disks = s->raiddisks;
                array.raid_disks = s->raiddisks;
                array.md_minor = 0;
@@ -142,8 +148,8 @@ int Build(char *mddev, struct mddev_dev *devlist,
                        s->chunk = 64;
                array.chunk_size = s->chunk*1024;
                array.layout = s->layout;
-               if (ioctl(mdfd, SET_ARRAY_INFO, &array)) {
-                       pr_err("SET_ARRAY_INFO failed for %s: %s\n",
+               if (md_set_array_info(mdfd, &array)) {
+                       pr_err("md_set_array_info() failed for %s: %s\n",
                                mddev, strerror(errno));
                        goto abort;
                }
@@ -152,6 +158,8 @@ int Build(char *mddev, struct mddev_dev *devlist,
                goto abort;
        }
 
+       if (s->bitmap_file && strcmp(s->bitmap_file, "none") == 0)
+               s->bitmap_file = NULL;
        if (s->bitmap_file && s->level <= 0) {
                pr_err("bitmaps not meaningful with level %s\n",
                        map_num(pers, s->level)?:"given");
@@ -169,7 +177,7 @@ int Build(char *mddev, struct mddev_dev *devlist,
                        goto abort;
                }
                if ((stb.st_mode & S_IFMT)!= S_IFBLK) {
-                       pr_err("Wierd: %s is no longer a block device.\n",
+                       pr_err("Weird: %s is no longer a block device.\n",
                                dv->devname);
                        goto abort;
                }
@@ -188,7 +196,7 @@ int Build(char *mddev, struct mddev_dev *devlist,
                        disk.number = i;
                        disk.raid_disk = i;
                        disk.state = (1<<MD_DISK_SYNC) | (1<<MD_DISK_ACTIVE);
-                       if (dv->writemostly == 1)
+                       if (dv->writemostly == FlagSet)
                                disk.state |= 1<<MD_DISK_WRITEMOSTLY;
                        disk.major = major(stb.st_rdev);
                        disk.minor = minor(stb.st_rdev);
@@ -250,8 +258,7 @@ int Build(char *mddev, struct mddev_dev *devlist,
                        pr_err("RUN_ARRAY failed: %s\n",
                                strerror(errno));
                        if (s->chunk & (s->chunk-1)) {
-                               cont_err("Problem may be that chunk size"
-                                        " is not a power of 2\n");
+                               cont_err("Problem may be that chunk size is not a power of 2\n");
                        }
                        goto abort;
                }