]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Manage.c
imsm: allow drives in a container regardless of sector size
[thirdparty/mdadm.git] / Manage.c
index 9e6913208ad28c690dc22cb9daba2a52f49f847b..14276b709d1cfbfedd1c852da4a29eef060647e1 100644 (file)
--- a/Manage.c
+++ b/Manage.c
@@ -40,13 +40,9 @@ int Manage_ro(char *devname, int fd, int readonly)
         * use RESTART_ARRAY_RW or STOP_ARRAY_RO
         *
         */
-       mdu_array_info_t array;
-#ifndef MDASSEMBLE
        struct mdinfo *mdi;
-#endif
        int rv = 0;
 
-#ifndef MDASSEMBLE
        /* If this is an externally-managed array, we need to modify the
         * metadata_version so that mdmon doesn't undo our change.
         */
@@ -90,10 +86,9 @@ int Manage_ro(char *devname, int fd, int readonly)
                }
                goto out;
        }
-#endif
-       if (md_get_array_info(fd, &array)) {
-               pr_err("%s does not appear to be active.\n",
-                       devname);
+
+       if (!md_array_active(fd)) {
+               pr_err("%s does not appear to be active.\n", devname);
                rv = 1;
                goto out;
        }
@@ -114,14 +109,10 @@ int Manage_ro(char *devname, int fd, int readonly)
                }
        }
 out:
-#ifndef MDASSEMBLE
        sysfs_free(mdi);
-#endif
        return rv;
 }
 
-#ifndef MDASSEMBLE
-
 static void remove_devices(char *devnm, char *path)
 {
        /*
@@ -936,7 +927,7 @@ int Manage_add(int fd, int tfd, struct mddev_dev *dv,
                        return -1;
                }
 
-               if (strncmp(mdp->sysfs_array_state, "readonly", 8) != 0) {
+               if (mdp->array_state != ARRAY_READONLY) {
                        sysfs_free(mdp);
                        pr_err("%s is not readonly, cannot add journal.\n", devname);
                        return -1;
@@ -1519,24 +1510,16 @@ int Manage_subdevs(char *devname, int fd,
                         */
                        rdev = makedev(mj, mn);
                } else {
-                       struct stat stb;
                        tfd = dev_open(dv->devname, O_RDONLY);
                        if (tfd >= 0) {
-                               fstat(tfd, &stb);
+                               fstat_is_blkdev(tfd, dv->devname, &rdev);
                                close(tfd);
                        } else {
                                int open_err = errno;
-                               if (stat(dv->devname, &stb) != 0) {
-                                       pr_err("Cannot find %s: %s\n",
-                                              dv->devname, strerror(errno));
-                                       goto abort;
-                               }
-                               if ((stb.st_mode & S_IFMT) != S_IFBLK) {
+                               if (!stat_is_blkdev(dv->devname, &rdev)) {
                                        if (dv->disposition == 'M')
                                                /* non-fatal. Also improbable */
                                                continue;
-                                       pr_err("%s is not a block device.\n",
-                                              dv->devname);
                                        goto abort;
                                }
                                if (dv->disposition == 'r')
@@ -1553,7 +1536,6 @@ int Manage_subdevs(char *devname, int fd,
                                        goto abort;
                                }
                        }
-                       rdev = stb.st_rdev;
                }
                switch(dv->disposition){
                default:
@@ -1802,4 +1784,3 @@ int move_spare(char *from_devname, char *to_devname, dev_t devid)
        close(fd2);
        return 0;
 }
-#endif