]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Build.c
mdadm: improve the dlm locking mechanism for clustered raid
[thirdparty/mdadm.git] / Build.c
diff --git a/Build.c b/Build.c
index 665d9067b8d6c34ccb0abb9e7e2bf5f46281e4e0..962c2e3776b91ccb15135b9c0cff91f322a8c9fe 100644 (file)
--- a/Build.c
+++ b/Build.c
 
 #include "mdadm.h"
 
-#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)
 {
@@ -41,7 +37,7 @@ int Build(char *mddev, struct mddev_dev *devlist,
         * cc = chunk size factor: 0==4k, 1==8k etc.
         */
        int i;
-       struct stat stb;
+       dev_t rdev;
        int subdevs = 0, missing_disks = 0;
        struct mddev_dev *dv;
        int bitmap_fd;
@@ -64,16 +60,8 @@ int Build(char *mddev, struct mddev_dev *devlist,
                        missing_disks++;
                        continue;
                }
-               if (stat(dv->devname, &stb)) {
-                       pr_err("Cannot find %s: %s\n",
-                               dv->devname, strerror(errno));
-                       return 1;
-               }
-               if ((stb.st_mode & S_IFMT) != S_IFBLK) {
-                       pr_err("%s is not a block device.\n",
-                               dv->devname);
+               if (!stat_is_blkdev(dv->devname, NULL))
                        return 1;
-               }
        }
 
        if (s->raiddisks != subdevs) {
@@ -126,8 +114,8 @@ int Build(char *mddev, struct mddev_dev *devlist,
        array.nr_disks = s->raiddisks;
        array.raid_disks = s->raiddisks;
        array.md_minor = 0;
-       if (fstat(mdfd, &stb) == 0)
-               array.md_minor = minor(stb.st_rdev);
+       if (fstat_is_blkdev(mdfd, mddev, &rdev))
+               array.md_minor = minor(rdev);
        array.not_persistent = 1;
        array.state = 0; /* not clean, but no errors */
        if (s->assume_clean)
@@ -161,16 +149,8 @@ int Build(char *mddev, struct mddev_dev *devlist,
 
                if (strcmp("missing", dv->devname) == 0)
                        continue;
-               if (stat(dv->devname, &stb)) {
-                       pr_err("Weird: %s has disappeared.\n",
-                               dv->devname);
-                       goto abort;
-               }
-               if ((stb.st_mode & S_IFMT)!= S_IFBLK) {
-                       pr_err("Weird: %s is no longer a block device.\n",
-                               dv->devname);
+               if (!stat_is_blkdev(dv->devname, &rdev))
                        goto abort;
-               }
                fd = open(dv->devname, O_RDONLY|O_EXCL);
                if (fd < 0) {
                        pr_err("Cannot open %s: %s\n",
@@ -186,8 +166,8 @@ int Build(char *mddev, struct mddev_dev *devlist,
                disk.state = (1<<MD_DISK_SYNC) | (1<<MD_DISK_ACTIVE);
                if (dv->writemostly == FlagSet)
                        disk.state |= 1<<MD_DISK_WRITEMOSTLY;
-               disk.major = major(stb.st_rdev);
-               disk.minor = minor(stb.st_rdev);
+               disk.major = major(rdev);
+               disk.minor = minor(rdev);
                if (ioctl(mdfd, ADD_NEW_DISK, &disk)) {
                        pr_err("ADD_NEW_DISK failed for %s: %s\n",
                               dv->devname, strerror(errno));
@@ -201,7 +181,7 @@ int Build(char *mddev, struct mddev_dev *devlist,
                        int major = BITMAP_MAJOR_HI;
 #if 0
                        if (s->bitmap_chunk == UnSet) {
-                               pr_err("%s cannot be openned.", s->bitmap_file);
+                               pr_err("%s cannot be opened.\n", s->bitmap_file);
                                goto abort;
                        }
 #endif
@@ -213,7 +193,7 @@ int Build(char *mddev, struct mddev_dev *devlist,
                        }
                        bitmap_fd = open(s->bitmap_file, O_RDWR);
                        if (bitmap_fd < 0) {
-                               pr_err("%s cannot be openned.", s->bitmap_file);
+                               pr_err("%s cannot be opened.\n", s->bitmap_file);
                                goto abort;
                        }
                }