]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Manage.c
mdadm: Fixup more broken logical operator formatting
[thirdparty/mdadm.git] / Manage.c
index 8966e3368d1e3c7b47de9d6a19e93b5aadf46351..04b9398c2e4f1e76587de518966b0d557b9688ba 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,7 +36,6 @@ int Manage_ro(char *devname, int fd, int readonly)
         * use RESTART_ARRAY_RW or STOP_ARRAY_RO
         *
         */
-       mdu_array_info_t array;
        struct mdinfo *mdi;
        int rv = 0;
 
@@ -88,9 +83,8 @@ int Manage_ro(char *devname, int fd, int readonly)
                goto out;
        }
 
-       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;
        }
@@ -210,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.
@@ -250,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--;
                }
@@ -453,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 --;
        }
@@ -664,8 +655,8 @@ int attempt_re_add(int fd, int tfd, struct mddev_dev *dv,
                if (dv->failfast == FlagClear)
                        disc.state &= ~(1 << MD_DISK_FAILFAST);
                remove_partitions(tfd);
-               if (update || dv->writemostly != FlagDefault
-                       || dv->failfast != FlagDefault) {
+               if (update || dv->writemostly != FlagDefault ||
+                   dv->failfast != FlagDefault) {
                        int rv = -1;
                        tfd = dev_open(dv->devname, O_RDWR);
                        if (tfd < 0) {
@@ -801,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
@@ -1399,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;
@@ -1505,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')
@@ -1546,7 +1529,6 @@ int Manage_subdevs(char *devname, int fd,
                                        goto abort;
                                }
                        }
-                       rdev = stb.st_rdev;
                }
                switch(dv->disposition){
                default: