Don't use UnSet with consistency_policy
authorArtur Paszkiewicz <artur.paszkiewicz@intel.com>
Mon, 24 Apr 2017 14:03:26 +0000 (16:03 +0200)
committerJes Sorensen <jsorensen@fb.com>
Mon, 24 Apr 2017 21:10:56 +0000 (17:10 -0400)
Use CONSISTENCY_POLICY_UNKNOWN instead. Simplify some checks because
since 5e8e35fb7e17 ("maps: Use keyvalue for null terminator to indicate
'unset' value") map_name() can return this default directly.

Suggested-by: Jes Sorensen <Jes.Sorensen@gmail.com>
Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
maps.c
mdadm.c
super-intel.c
sysfs.c

diff --git a/maps.c b/maps.c
index bb28ba6..02a0474 100644 (file)
--- a/maps.c
+++ b/maps.c
@@ -137,7 +137,7 @@ mapping_t consistency_policies[] = {
        { "bitmap", CONSISTENCY_POLICY_BITMAP},
        { "journal", CONSISTENCY_POLICY_JOURNAL},
        { "ppl", CONSISTENCY_POLICY_PPL},
-       { NULL, UnSet }
+       { NULL, CONSISTENCY_POLICY_UNKNOWN }
 };
 
 mapping_t sysfs_array_states[] = {
diff --git a/mdadm.c b/mdadm.c
index 41dae1d..b689e32 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -78,7 +78,7 @@ int main(int argc, char *argv[])
                .level          = UnSet,
                .layout         = UnSet,
                .bitmap_chunk   = UnSet,
-               .consistency_policy     = UnSet,
+               .consistency_policy     = CONSISTENCY_POLICY_UNKNOWN,
        };
 
        char sys_hostname[256];
@@ -1228,8 +1228,7 @@ int main(int argc, char *argv[])
                case O(GROW, 'k'):
                        s.consistency_policy = map_name(consistency_policies,
                                                        optarg);
-                       if (s.consistency_policy == UnSet ||
-                           s.consistency_policy < CONSISTENCY_POLICY_RESYNC) {
+                       if (s.consistency_policy < CONSISTENCY_POLICY_RESYNC) {
                                pr_err("Invalid consistency policy: %s\n",
                                       optarg);
                                exit(2);
@@ -1267,7 +1266,7 @@ int main(int argc, char *argv[])
                        pr_err("--write-journal is only supported for RAID level 4/5/6.\n");
                        exit(2);
                }
-               if (s.consistency_policy != UnSet &&
+               if (s.consistency_policy != CONSISTENCY_POLICY_UNKNOWN &&
                    s.consistency_policy != CONSISTENCY_POLICY_JOURNAL) {
                        pr_err("--write-journal is not supported with consistency policy: %s\n",
                               map_num(consistency_policies, s.consistency_policy));
@@ -1275,7 +1274,8 @@ int main(int argc, char *argv[])
                }
        }
 
-       if (mode == CREATE && s.consistency_policy != UnSet) {
+       if (mode == CREATE &&
+           s.consistency_policy != CONSISTENCY_POLICY_UNKNOWN) {
                if (s.level <= 0) {
                        pr_err("--consistency-policy not meaningful with level %s.\n",
                               map_num(pers, s.level));
@@ -1687,7 +1687,7 @@ int main(int argc, char *argv[])
                        rv = Grow_reshape(devlist->devname, mdfd,
                                          devlist->next,
                                          data_offset, &c, &s);
-               } else if (s.consistency_policy != UnSet) {
+               } else if (s.consistency_policy != CONSISTENCY_POLICY_UNKNOWN) {
                        rv = Grow_consistency_policy(devlist->devname, mdfd, &c, &s);
                } else if (array_size == 0)
                        pr_err("no changes to --grow\n");
index 0aed57c..fbff215 100644 (file)
@@ -5369,9 +5369,7 @@ static int init_super_imsm_volume(struct supertype *st, mdu_array_info_t *info,
        }
        mpb->num_raid_devs++;
 
-       if (s->consistency_policy == UnSet ||
-           s->consistency_policy == CONSISTENCY_POLICY_RESYNC ||
-           s->consistency_policy == CONSISTENCY_POLICY_NONE) {
+       if (s->consistency_policy <= CONSISTENCY_POLICY_RESYNC) {
                dev->rwh_policy = RWH_OFF;
        } else if (s->consistency_policy == CONSISTENCY_POLICY_PPL) {
                dev->rwh_policy = RWH_DISTRIBUTED;
diff --git a/sysfs.c b/sysfs.c
index 712f8b3..aa30de5 100644 (file)
--- a/sysfs.c
+++ b/sysfs.c
@@ -254,13 +254,11 @@ struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options)
 
        if (options & GET_CONSISTENCY_POLICY) {
                strcpy(base, "consistency_policy");
-               if (load_sys(fname, buf, sizeof(buf))) {
+               if (load_sys(fname, buf, sizeof(buf)))
                        sra->consistency_policy = CONSISTENCY_POLICY_UNKNOWN;
-               } else {
-                       sra->consistency_policy = map_name(consistency_policies, buf);
-                       if (sra->consistency_policy == UnSet)
-                               sra->consistency_policy = CONSISTENCY_POLICY_UNKNOWN;
-               }
+               else
+                       sra->consistency_policy = map_name(consistency_policies,
+                                                          buf);
        }
 
        if (! (options & GET_DEVS))