]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - policy.c
Fix RAID metadata check
[thirdparty/mdadm.git] / policy.c
index c3de692e79ced9e2d894e81ffa4f1240a6b685f8..064d34919ea5a750ca4394d7aa3d019392e44549 100644 (file)
--- a/policy.c
+++ b/policy.c
@@ -200,26 +200,25 @@ static char *disk_path(struct mdinfo *disk)
        int rv;
 
        by_path = opendir(symlink);
-       if (!by_path)
-               return NULL;
-       prefix_len = strlen(symlink);
-
-       while ((ent = readdir(by_path)) != NULL) {
-               if (ent->d_type != DT_LNK)
-                       continue;
-               strncpy(symlink + prefix_len,
-                       ent->d_name,
-                       sizeof(symlink) - prefix_len);
-               if (stat(symlink, &stb) < 0)
-                       continue;
-               if ((stb.st_mode & S_IFMT) != S_IFBLK)
-                       continue;
-               if (stb.st_rdev != makedev(disk->disk.major, disk->disk.minor))
-                       continue;
+       if (by_path) {
+               prefix_len = strlen(symlink);
+               while ((ent = readdir(by_path)) != NULL) {
+                       if (ent->d_type != DT_LNK)
+                               continue;
+                       strncpy(symlink + prefix_len,
+                                       ent->d_name,
+                                       sizeof(symlink) - prefix_len);
+                       if (stat(symlink, &stb) < 0)
+                               continue;
+                       if ((stb.st_mode & S_IFMT) != S_IFBLK)
+                               continue;
+                       if (stb.st_rdev != makedev(disk->disk.major, disk->disk.minor))
+                               continue;
+                       closedir(by_path);
+                       return xstrdup(ent->d_name);
+               }
                closedir(by_path);
-               return xstrdup(ent->d_name);
        }
-       closedir(by_path);
        /* A NULL path isn't really acceptable - use the devname.. */
        sprintf(symlink, "/sys/dev/block/%d:%d", disk->disk.major, disk->disk.minor);
        rv = readlink(symlink, nm, sizeof(nm)-1);
@@ -401,7 +400,6 @@ void pol_add(struct dev_policy **pol,
        pol_dedup(*pol);
 }
 
-
 /*
  * disk_policy() gathers policy information for the
  * disk described in the given mdinfo (disk.{major,minor}).
@@ -421,7 +419,7 @@ struct dev_policy *disk_policy(struct mdinfo *disk)
        return pol;
 }
 
-struct dev_policy *devnum_policy(int dev)
+struct dev_policy *devid_policy(int dev)
 {
        struct mdinfo disk;
        disk.disk.major = major(dev);
@@ -592,7 +590,6 @@ int disk_action_allows(struct mdinfo *disk, const char *metadata, enum policy_ac
        return rv;
 }
 
-
 /* Domain policy:
  * Any device can have a list of domains asserted by different policy
  * statements.
@@ -677,9 +674,9 @@ int domain_test(struct domainlist *dom, struct dev_policy *pol,
        return found_any;
 }
 
-void domainlist_add_dev(struct domainlist **dom, int devnum, const char *metadata)
+void domainlist_add_dev(struct domainlist **dom, int devid, const char *metadata)
 {
-       struct dev_policy *pol = devnum_policy(devnum);
+       struct dev_policy *pol = devid_policy(devid);
        domain_merge(dom, pol, metadata);
        dev_policy_free(pol);
 }
@@ -703,7 +700,6 @@ void domain_add(struct domainlist **domp, char *domain)
        domain_merge_one(domp, domain);
 }
 
-
 void domain_free(struct domainlist *dl)
 {
        while (dl) {
@@ -731,16 +727,14 @@ void policy_save_path(char *id_path, struct map_ent *array)
        FILE *f = NULL;
 
        if (mkdir(FAILED_SLOTS_DIR, S_IRWXU) < 0 && errno != EEXIST) {
-               pr_err("can't create file to save path "
-                       "to old disk: %s\n", strerror(errno));
+               pr_err("can't create file to save path to old disk: %s\n", strerror(errno));
                return;
        }
 
        snprintf(path, PATH_MAX, FAILED_SLOTS_DIR "/%s", id_path);
        f = fopen(path, "w");
        if (!f) {
-               pr_err("can't create file to"
-                       " save path to old disk: %s\n",
+               pr_err("can't create file to save path to old disk: %s\n",
                        strerror(errno));
                return;
        }
@@ -749,8 +743,7 @@ void policy_save_path(char *id_path, struct map_ent *array)
                    array->metadata,
                    array->uuid[0], array->uuid[1],
                    array->uuid[2], array->uuid[3]) <= 0)
-               pr_err("Failed to write to "
-                      "<id_path> cookie\n");
+               pr_err("Failed to write to <id_path> cookie\n");
 
        fclose(f);
 }
@@ -803,12 +796,12 @@ char *find_rule(struct rule *rule, char *rule_type)
 #define UDEV_RULE_FORMAT \
 "ACTION==\"add\", SUBSYSTEM==\"block\", " \
 "ENV{DEVTYPE}==\"%s\", ENV{ID_PATH}==\"%s\", " \
-"RUN+=\"/sbin/mdadm --incremental $env{DEVNAME}\"\n"
+"RUN+=\"" BINDIR "/mdadm --incremental $env{DEVNAME}\"\n"
 
 #define UDEV_RULE_FORMAT_NOTYPE \
 "ACTION==\"add\", SUBSYSTEM==\"block\", " \
 "ENV{ID_PATH}==\"%s\", " \
-"RUN+=\"/sbin/mdadm --incremental $env{DEVNAME}\"\n"
+"RUN+=\"" BINDIR "/mdadm --incremental $env{DEVNAME}\"\n"
 
 /* Write rule in the rule file. Use format from UDEV_RULE_FORMAT */
 int write_rule(struct rule *rule, int fd, int force_part)