From b3d3195538e315b3863235731112eee7398d4340 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sat, 25 Oct 2008 18:20:49 +1100 Subject: Allow WRITEMOSTLY to be cleared on --readd using --readwrite. Previously it was possible to set the WRITEMOSTLY flag when adding a device to an array, but not to clear the flag when re-adding. This is now possible with --readwrite. Signed-off-by: NeilBrown --- Build.c | 2 +- ChangeLog | 4 ++++ Create.c | 2 +- Manage.c | 8 +++++--- mdadm.8 | 11 +++++++++++ mdadm.c | 21 ++++++--------------- mdadm.h | 2 +- 7 files changed, 29 insertions(+), 21 deletions(-) diff --git a/Build.c b/Build.c index d6e20fb8..1e213ce4 100644 --- a/Build.c +++ b/Build.c @@ -183,7 +183,7 @@ int Build(char *mddev, int mdfd, int chunk, int level, int layout, disk.number = i; disk.raid_disk = i; disk.state = (1<writemostly) + if (dv->writemostly == 1) disk.state |= 1<writemostly) + if (dv->writemostly == 1) info.disk.state |= (1<writemostly) + if (dv->writemostly == 1) disc.state |= 1 << MD_DISK_WRITEMOSTLY; + if (dv->writemostly == 2) + disc.state &= ~(1 << MD_DISK_WRITEMOSTLY); if (ioctl(fd, ADD_NEW_DISK, &disc) == 0) { if (verbose >= 0) fprintf(stderr, Name ": re-added %s\n", dv->devname); @@ -452,7 +454,7 @@ int Manage_subdevs(char *devname, int fd, disc.number =j; disc.state = 0; if (array.not_persistent==0) { - if (dv->writemostly) + if (dv->writemostly == 1) disc.state |= 1 << MD_DISK_WRITEMOSTLY; tst->ss->add_to_super(tst, &disc); if (tst->ss->write_init_super(tst, &disc, @@ -487,7 +489,7 @@ int Manage_subdevs(char *devname, int fd, break; } } - if (dv->writemostly) + if (dv->writemostly == 1) disc.state |= (1 << MD_DISK_WRITEMOSTLY); if (ioctl(fd,ADD_NEW_DISK, &disc)) { fprintf(stderr, Name ": add new device failed for %s as %d: %s\n", diff --git a/mdadm.8 b/mdadm.8 index d26da800..054addae 100644 --- a/mdadm.8 +++ b/mdadm.8 @@ -905,6 +905,17 @@ the system to be marked as failed. It can then be removed. same as .BR \-\-fail . +.TP +.BR \-\-write\-mostly +Subsequent devices that are added or re-added will have the 'write-mostly' +flag set. This is only valid for RAID! and means that the 'md' driver +will avoid reading from these devices if possible. +.TP +.BR \-\-readwrite +Subsequent devices that are added or re-added will have the 'write-mostly' +flag cleared. + + .P Each of these options require that the first device listed is the array to be acted upon, and the remainder are component devices to be added, diff --git a/mdadm.c b/mdadm.c index 3aa3b132..af9627d5 100644 --- a/mdadm.c +++ b/mdadm.c @@ -360,6 +360,12 @@ int main(int argc, char *argv[]) writemostly = 1; continue; + case O(MANAGE,'w'): + /* clear write-mostly for following devices */ + writemostly = 2; + continue; + + case O(GROW,'z'): case O(CREATE,'z'): /* size */ if (size >= 0) { @@ -745,21 +751,6 @@ int main(int argc, char *argv[]) runstop = -1; continue; - case O(MANAGE,'o'): - if (readonly < 0) { - fprintf(stderr, Name ": Cannot have both readonly and readwrite\n"); - exit(2); - } - readonly = 1; - continue; - case O(MANAGE,'w'): - if (readonly > 0) { - fprintf(stderr, Name ": Cannot have both readwrite and readonly.\n"); - exit(2); - } - readonly = -1; - continue; - case O(MISC,'Q'): case O(MISC,'D'): case O(MISC,'E'): diff --git a/mdadm.h b/mdadm.h index 174ea395..bc4b38e7 100644 --- a/mdadm.h +++ b/mdadm.h @@ -232,7 +232,7 @@ typedef struct mddev_dev_s { char disposition; /* 'a' for add, 'r' for remove, 'f' for fail. * Not set for names read from .config */ - char writemostly; + char writemostly; /* 1 for 'set writemostly', 2 for 'clear writemostly' */ char re_add; char used; /* set when used */ struct mddev_dev_s *next; -- cgit v1.2.3