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@xxxxxxxx> --- Ask, and you shall receive :-) NeilBrown Build.c | 2 +- Create.c | 4 ++-- Incremental.c | 4 ++-- Manage.c | 32 ++++++++++++++++---------------- mdadm.c | 12 ++++++------ mdadm.h | 8 ++++++-- 6 files changed, 33 insertions(+), 29 deletions(-) diff --git a/Build.c b/Build.c index 8603c710aea2..74a440e78965 100644 --- a/Build.c +++ b/Build.c @@ -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); diff --git a/Create.c b/Create.c index bd114eabafc1..2721884efabc 100644 --- a/Create.c +++ b/Create.c @@ -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 75d95ccc497a..0f507bb32c9e 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)); diff --git a/Manage.c b/Manage.c index 429d8631cd23..5c3d2b9b1a9f 100644 --- a/Manage.c +++ b/Manage.c @@ -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)); diff --git a/mdadm.c b/mdadm.c index 3c8f273c8254..c3a265b80947 100644 --- a/mdadm.c +++ b/mdadm.c @@ -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'): diff --git a/mdadm.h b/mdadm.h index d47de01f725b..a85b5ad8149d 100644 --- a/mdadm.h +++ b/mdadm.h @@ -424,6 +424,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: @@ -517,8 +521,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; -- 2.10.2
Attachment:
signature.asc
Description: PGP signature