]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Manage.c
mdadm: Fixup a large number of bad formatting of logical operators
[thirdparty/mdadm.git] / Manage.c
index 0ffb6c68dec2334047dc34a1040a88b90b269f96..cee5dad8600473e882efec5ac78a42dcc09e0ba0 100644 (file)
--- a/Manage.c
+++ b/Manage.c
 #include "md_p.h"
 #include <ctype.h>
 
-#define REGISTER_DEV           _IO (MD_MAJOR, 1)
-#define START_MD               _IO (MD_MAJOR, 2)
-#define STOP_MD                        _IO (MD_MAJOR, 3)
-
 int Manage_ro(char *devname, int fd, int readonly)
 {
        /* switch to readonly or rw
@@ -40,17 +36,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;
 
-       if (md_get_version(fd) < 9000) {
-               pr_err("need md driver version 0.90.0 or later\n");
-               return 1;
-       }
-#ifndef MDASSEMBLE
        /* If this is an externally-managed array, we need to modify the
         * metadata_version so that mdmon doesn't undo our change.
         */
@@ -94,10 +82,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;
        }
@@ -118,14 +105,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)
 {
        /*
@@ -176,10 +159,6 @@ int Manage_run(char *devname, int fd, struct context *c)
         */
        char nm[32], *nmp;
 
-       if (md_get_version(fd) < 9000) {
-               pr_err("need md driver version 0.90.0 or later\n");
-               return 1;
-       }
        nmp = fd2devnm(fd);
        if (!nmp) {
                pr_err("Cannot find %s in sysfs!!\n", devname);
@@ -207,14 +186,6 @@ int Manage_stop(char *devname, int fd, int verbose, int will_retry)
        if (will_retry && verbose == 0)
                verbose = -1;
 
-       if (md_get_version(fd) < 9000) {
-               if (ioctl(fd, STOP_MD, 0) == 0)
-                       return 0;
-               pr_err("stopping device %s failed: %s\n",
-                      devname, strerror(errno));
-               return 1;
-       }
-
        strcpy(devnm, fd2devnm(fd));
        /* Get EXCL access first.  If this fails, then attempting
         * to stop is probably a bad idea.
@@ -233,11 +204,9 @@ int Manage_stop(char *devname, int fd, int verbose, int will_retry)
        count = 5;
        while (((fd = ((devname[0] == '/')
                       ?open(devname, O_RDONLY|O_EXCL)
-                      :open_dev_flags(devnm, O_RDONLY|O_EXCL))) < 0
-               || strcmp(fd2devnm(fd), devnm) != 0)
-              && container[0]
-              && mdmon_running(container)
-              && count) {
+                      :open_dev_flags(devnm, O_RDONLY|O_EXCL))) < 0 ||
+               strcmp(fd2devnm(fd), devnm) != 0) && container[0] &&
+              mdmon_running(container) && count) {
                /* Can't open, so something might be wrong.  However it
                 * is a container, so we might be racing with mdmon, so
                 * retry for a bit.
@@ -273,8 +242,8 @@ int Manage_stop(char *devname, int fd, int verbose, int will_retry)
                while (count &&
                       (err = sysfs_set_str(mdi, NULL,
                                            "array_state",
-                                           "inactive")) < 0
-                      && errno == EBUSY) {
+                                           "inactive")) < 0 &&
+                      errno == EBUSY) {
                        usleep(200000);
                        count--;
                }
@@ -476,9 +445,8 @@ done:
         * so it is reasonable to retry for a while - 5 seconds.
         */
        count = 25; err = 0;
-       while (count && fd >= 0
-              && (err = ioctl(fd, STOP_ARRAY, NULL)) < 0
-              && errno == EBUSY) {
+       while (count && fd >= 0 &&
+              (err = ioctl(fd, STOP_ARRAY, NULL)) < 0 && errno == EBUSY) {
                usleep(200000);
                count --;
        }
@@ -773,9 +741,7 @@ int Manage_add(int fd, int tfd, struct mddev_dev *dv,
                       "       Adding anyway as --force was given.\n",
                       dv->devname, devname);
        }
-       if (!tst->ss->external &&
-           array->major_version == 0 &&
-           md_get_version(fd)%100 < 2) {
+       if (!tst->ss->external && array->major_version == 0) {
                if (ioctl(fd, HOT_ADD_DISK, rdev)==0) {
                        if (verbose >= 0)
                                pr_err("hot added %s\n",
@@ -826,8 +792,8 @@ int Manage_add(int fd, int tfd, struct mddev_dev *dv,
                                break;
                        }
                /* FIXME this is a bad test to be using */
-               if (!tst->sb && (dv->disposition != 'a'
-                                && dv->disposition != 'S')) {
+               if (!tst->sb && (dv->disposition != 'a' &&
+                                dv->disposition != 'S')) {
                        /* we are re-adding a device to a
                         * completely dead array - have to depend
                         * on kernel to check
@@ -954,7 +920,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;
@@ -1382,12 +1348,15 @@ int Manage_subdevs(char *devname, int fd,
        int busy = 0;
        int raid_slot = -1;
 
+       if (sysfs_init(&info, fd, NULL)) {
+               pr_err("sysfs not availabile for %s\n", devname);
+               goto abort;
+       }
+
        if (md_get_array_info(fd, &array)) {
                pr_err("Cannot get array info for %s\n", devname);
                goto abort;
        }
-       sysfs_init(&info, fd, NULL);
-
        /* array.size is only 32 bits and may be truncated.
         * So read from sysfs if possible, and record number of sectors
         */
@@ -1421,8 +1390,7 @@ int Manage_subdevs(char *devname, int fd,
 
                if (strcmp(dv->devname, "failed") == 0 ||
                    strcmp(dv->devname, "faulty") == 0) {
-                       if (dv->disposition != 'A'
-                           && dv->disposition != 'r') {
+                       if (dv->disposition != 'A' && dv->disposition != 'r') {
                                pr_err("%s only meaningful with -r or --re-add, not -%c\n",
                                        dv->devname, dv->disposition);
                                goto abort;
@@ -1527,31 +1495,24 @@ int Manage_subdevs(char *devname, int fd,
                                        goto abort;
                                }
                        }
-               } else if ((dv->disposition == 'r' || dv->disposition == 'f')
-                          && get_maj_min(dv->devname, &mj, &mn)) {
+               } else if ((dv->disposition == 'r' ||
+                           dv->disposition == 'f') &&
+                          get_maj_min(dv->devname, &mj, &mn)) {
                        /* for 'fail' and 'remove', the device might
                         * not exist.
                         */
                        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')
@@ -1568,7 +1529,6 @@ int Manage_subdevs(char *devname, int fd,
                                        goto abort;
                                }
                        }
-                       rdev = stb.st_rdev;
                }
                switch(dv->disposition){
                default:
@@ -1817,4 +1777,3 @@ int move_spare(char *from_devname, char *to_devname, dev_t devid)
        close(fd2);
        return 0;
 }
-#endif