summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.com>2016-11-29 23:02:11 +0100
committerJes Sorensen <Jes.Sorensen@redhat.com>2016-11-29 23:12:13 +0100
commite22fe3ae15901d723aa6a0d319cd18564156c50b (patch)
tree7311d646a0a6dc72571b6816fb10669c0f3bc2b5
parentmdmon: bad block support for external metadata - clear bad blocks (diff)
downloadmdadm-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.c2
-rw-r--r--Create.c4
-rw-r--r--Incremental.c4
-rw-r--r--Manage.c32
-rw-r--r--mdadm.c12
-rw-r--r--mdadm.h8
6 files changed, 33 insertions, 29 deletions
diff --git a/Build.c b/Build.c
index 8603c710..74a440e7 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 bd114eab..2721884e 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 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));
diff --git a/Manage.c b/Manage.c
index 429d8631..5c3d2b9b 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 3c8f273c..c3a265b8 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 a10964c5..71b8afb9 100644
--- a/mdadm.h
+++ b/mdadm.h
@@ -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;