]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Factor out path_policy functon.
authorNeilBrown <neilb@suse.de>
Thu, 2 Sep 2010 00:04:26 +0000 (10:04 +1000)
committerNeilBrown <neilb@suse.de>
Mon, 6 Sep 2010 01:26:28 +0000 (11:26 +1000)
Allow disk-policy to be computed given the path and
disk type explicitly.  This can be used when hunting through
/dev/disk/by-path for something interesting.

Signed-off-by: NeilBrown <neilb@suse.de>
mdadm.h
policy.c

diff --git a/mdadm.h b/mdadm.h
index 08e454404bccb3494bc8789d1f9d3f97c42c767a..c513c723c98e5f9f677b8198d04c6630472ef0db 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -788,6 +788,7 @@ extern char type_part[], type_disk[];
 extern void policyline(char *line, char *type);
 extern void policy_free(void);
 
+extern struct dev_policy *path_policy(char *path, char *type);
 extern struct dev_policy *disk_policy(struct mdinfo *disk);
 extern void dev_policy_free(struct dev_policy *p);
 
index 0e343b989748ee77a7913a985bc7a449508dc06a..8aa4cc8eb3a8116617edcd9cb588961fa5993402 100644 (file)
--- a/policy.c
+++ b/policy.c
@@ -333,23 +333,16 @@ static int config_rules_has_path = 0;
 /*
  * most policy comes from a set policy rules that are
  * read from the config file.
- * disk_policy() gathers policy information for the
- * disk described in the given mdinfo (disk.{major,minor}).
+ * path_policy() gathers policy information for the
+ * disk described in the given a 'path' and a 'type'.
  */
-struct dev_policy *disk_policy(struct mdinfo *disk)
+struct dev_policy *path_policy(char *path, char *type)
 {
-       char *path = NULL;
-       char *type = disk_type(disk);
        struct pol_rule *rules;
        struct dev_policy *pol = NULL;
 
        if (!type)
                return NULL;
-       if (config_rules_has_path) {
-               path = disk_path(disk);
-               if (!path)
-                       return NULL;
-       }
 
        rules = config_rules;
 
@@ -369,6 +362,29 @@ struct dev_policy *disk_policy(struct mdinfo *disk)
        }
        pol_sort(&pol);
        pol_dedup(pol);
+       return pol;
+}
+
+/*
+ * disk_policy() gathers policy information for the
+ * disk described in the given mdinfo (disk.{major,minor}).
+ */
+struct dev_policy *disk_policy(struct mdinfo *disk)
+{
+       char *path = NULL;
+       char *type = disk_type(disk);
+       struct dev_policy *pol = NULL;
+
+       if (!type)
+               return NULL;
+       if (config_rules_has_path) {
+               path = disk_path(disk);
+               if (!path)
+                       return NULL;
+       }
+
+       pol = path_policy(path, type);
+
        free(path);
        return pol;
 }