diff options
author | NeilBrown <neilb@suse.com> | 2016-11-29 23:02:11 +0100 |
---|---|---|
committer | Jes Sorensen <Jes.Sorensen@redhat.com> | 2016-11-29 23:12:13 +0100 |
commit | e22fe3ae15901d723aa6a0d319cd18564156c50b (patch) | |
tree | 7311d646a0a6dc72571b6816fb10669c0f3bc2b5 | |
parent | mdmon: bad block support for external metadata - clear bad blocks (diff) | |
download | mdadm-e22fe3ae15901d723aa6a0d319cd18564156c50b.tar.xz mdadm-e22fe3ae15901d723aa6a0d319cd18564156c50b.zip |
Introduce enum flag_mode for setting and clearing flags.
We currently use '1' to indicate that a flag (writemostly or failfast)
needs to be set, and '2' to indicate that it needs to be cleared.
Using magic number like this is not a best-practice.
So replaced them with values from a enum.
No functional change.
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
-rw-r--r-- | Build.c | 2 | ||||
-rw-r--r-- | Create.c | 4 | ||||
-rw-r--r-- | Incremental.c | 4 | ||||
-rw-r--r-- | Manage.c | 32 | ||||
-rw-r--r-- | mdadm.c | 12 | ||||
-rw-r--r-- | mdadm.h | 8 |
6 files changed, 33 insertions, 29 deletions
@@ -192,7 +192,7 @@ int Build(char *mddev, struct mddev_dev *devlist, disk.number = i; disk.raid_disk = i; disk.state = (1<<MD_DISK_SYNC) | (1<<MD_DISK_ACTIVE); - if (dv->writemostly == 1) + if (dv->writemostly == FlagSet) disk.state |= 1<<MD_DISK_WRITEMOSTLY; disk.major = major(stb.st_rdev); disk.minor = minor(stb.st_rdev); @@ -888,9 +888,9 @@ int Create(struct supertype *st, char *mddev, else inf->disk.state = 0; - if (dv->writemostly == 1) + if (dv->writemostly == FlagSet) inf->disk.state |= (1<<MD_DISK_WRITEMOSTLY); - if (dv->failfast == 1) + if (dv->failfast == FlagSet) inf->disk.state |= (1<<MD_DISK_FAILFAST); if (have_container) diff --git a/Incremental.c b/Incremental.c index 75d95ccc..0f507bb3 100644 --- a/Incremental.c +++ b/Incremental.c @@ -1034,8 +1034,8 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol, char chosen_devname[24]; // 2*11 for int (including signs) + colon + null devlist.next = NULL; devlist.used = 0; - devlist.writemostly = 0; - devlist.failfast = 0; + devlist.writemostly = FlagDefault; + devlist.failfast = FlagDefault; devlist.devname = chosen_devname; sprintf(chosen_devname, "%d:%d", major(stb.st_rdev), minor(stb.st_rdev)); @@ -679,17 +679,17 @@ int attempt_re_add(int fd, int tfd, struct mddev_dev *dv, else disc.state |= (1 << MD_DISK_CLUSTER_ADD); } - if (dv->writemostly == 1) + if (dv->writemostly == FlagSet) disc.state |= 1 << MD_DISK_WRITEMOSTLY; - if (dv->writemostly == 2) + if (dv->writemostly == FlagClear) disc.state &= ~(1 << MD_DISK_WRITEMOSTLY); - if (dv->failfast == 1) + if (dv->failfast == FlagSet) disc.state |= 1 << MD_DISK_FAILFAST; - if (dv->failfast == 2) + if (dv->failfast == FlagClear) disc.state &= ~(1 << MD_DISK_FAILFAST); remove_partitions(tfd); - if (update || dv->writemostly > 0 - || dv->failfast > 0) { + if (update || dv->writemostly != FlagDefault + || dv->failfast != FlagDefault) { int rv = -1; tfd = dev_open(dv->devname, O_RDWR); if (tfd < 0) { @@ -697,19 +697,19 @@ int attempt_re_add(int fd, int tfd, struct mddev_dev *dv, return -1; } - if (dv->writemostly == 1) + if (dv->writemostly == FlagSet) rv = dev_st->ss->update_super( dev_st, NULL, "writemostly", devname, verbose, 0, NULL); - if (dv->writemostly == 2) + if (dv->writemostly == FlagClear) rv = dev_st->ss->update_super( dev_st, NULL, "readwrite", devname, verbose, 0, NULL); - if (dv->failfast == 1) + if (dv->failfast == FlagSet) rv = dev_st->ss->update_super( dev_st, NULL, "failfast", devname, verbose, 0, NULL); - if (dv->failfast == 2) + if (dv->failfast == FlagClear) rv = dev_st->ss->update_super( dev_st, NULL, "nofailfast", devname, verbose, 0, NULL); @@ -975,9 +975,9 @@ int Manage_add(int fd, int tfd, struct mddev_dev *dv, int dfd; if (dv->disposition == 'j') disc.state |= (1 << MD_DISK_JOURNAL) | (1 << MD_DISK_SYNC); - if (dv->writemostly == 1) + if (dv->writemostly == FlagSet) disc.state |= 1 << MD_DISK_WRITEMOSTLY; - if (dv->failfast == 1) + if (dv->failfast == FlagSet) disc.state |= 1 << MD_DISK_FAILFAST; dfd = dev_open(dv->devname, O_RDWR | O_EXCL|O_DIRECT); if (tst->ss->add_to_super(tst, &disc, dfd, @@ -1022,9 +1022,9 @@ int Manage_add(int fd, int tfd, struct mddev_dev *dv, disc.state |= (1 << MD_DISK_CLUSTER_ADD); } - if (dv->writemostly == 1) + if (dv->writemostly == FlagSet) disc.state |= (1 << MD_DISK_WRITEMOSTLY); - if (dv->failfast == 1) + if (dv->failfast == FlagSet) disc.state |= (1 << MD_DISK_FAILFAST); if (tst->ss->external) { /* add a disk @@ -1801,8 +1801,8 @@ int move_spare(char *from_devname, char *to_devname, dev_t devid) devlist.next = NULL; devlist.used = 0; - devlist.writemostly = 0; - devlist.failfast = 0; + devlist.writemostly = FlagDefault; + devlist.failfast = FlagDefault; devlist.devname = devname; sprintf(devname, "%d:%d", major(devid), minor(devid)); @@ -89,8 +89,8 @@ int main(int argc, char *argv[]) int oneshot = 0; int spare_sharing = 1; struct supertype *ss = NULL; - int writemostly = 0; - int failfast = 0; + enum flag_mode writemostly = FlagDefault; + enum flag_mode failfast = FlagDefault; char *shortopt = short_options; int dosyslog = 0; int rebuild_map = 0; @@ -412,20 +412,20 @@ int main(int argc, char *argv[]) case O(CREATE,'W'): case O(CREATE,WriteMostly): /* set write-mostly for following devices */ - writemostly = 1; + writemostly = FlagSet; continue; case O(MANAGE,'w'): /* clear write-mostly for following devices */ - writemostly = 2; + writemostly = FlagClear; continue; case O(MANAGE,FailFast): case O(CREATE,FailFast): - failfast = 1; + failfast = FlagSet; continue; case O(MANAGE,NoFailFast): - failfast = 2; + failfast = FlagClear; continue; case O(GROW,'z'): @@ -439,6 +439,10 @@ enum bitmap_update { NodeNumUpdate, }; +enum flag_mode { + FlagDefault, FlagSet, FlagClear, +}; + /* structures read from config file */ /* List of mddevice names and identifiers * Identifiers can be: @@ -532,8 +536,8 @@ struct mddev_dev { * 'A' for re_add. * Not set for names read from .config */ - char writemostly; /* 1 for 'set writemostly', 2 for 'clear writemostly' */ - char failfast; /* Ditto but for 'failfast' flag */ + enum flag_mode writemostly; + enum flag_mode failfast; int used; /* set when used */ long long data_offset; struct mddev_dev *next; |