3 Support adding a spare to a live md array with external metadata.
5 i.e. extend the 'md/dev-XXX/slot' attribute so that you can
6 tell a device to fill an vacant slot in an and md array.
9 Signed-off-by: Neil Brown <neilb@suse.de>
12 ./drivers/md/md.c | 44 ++++++++++++++++++++++++++++++++++++++++----
13 ./drivers/md/multipath.c | 7 ++++++-
14 ./drivers/md/raid1.c | 7 ++++++-
15 ./drivers/md/raid10.c | 10 ++++++++--
16 ./drivers/md/raid5.c | 10 ++++++++--
17 5 files changed, 68 insertions(+), 10 deletions(-)
19 diff .prev/drivers/md/md.c ./drivers/md/md.c
20 --- .prev/drivers/md/md.c 2008-06-05 09:19:56.000000000 +1000
21 +++ ./drivers/md/md.c 2008-06-10 10:41:21.000000000 +1000
22 @@ -1932,7 +1932,7 @@ slot_store(mdk_rdev_t *rdev, const char
24 else if (e==buf || (*e && *e!= '\n'))
26 - if (rdev->mddev->pers) {
27 + if (rdev->mddev->pers && slot == -1) {
28 /* Setting 'slot' on an active array requires also
29 * updating the 'rd%d' link, and communicating
30 * with the personality with ->hot_*_disk.
31 @@ -1940,8 +1940,6 @@ slot_store(mdk_rdev_t *rdev, const char
32 * failed/spare devices. This normally happens automatically,
33 * but not when the metadata is externally managed.
37 if (rdev->raid_disk == -1)
39 /* personality does all needed checks */
40 @@ -1955,6 +1953,44 @@ slot_store(mdk_rdev_t *rdev, const char
41 sysfs_remove_link(&rdev->mddev->kobj, nm);
42 set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery);
43 md_wakeup_thread(rdev->mddev->thread);
44 + } else if (rdev->mddev->pers) {
46 + struct list_head *tmp;
47 + /* Activating a spare .. or possibly reactivating
48 + * if we every get bitmaps working here.
51 + if (rdev->raid_disk != -1)
54 + if (rdev->mddev->pers->hot_add_disk == NULL)
57 + rdev_for_each(rdev2, tmp, rdev->mddev)
58 + if (rdev2->raid_disk == slot)
61 + rdev->raid_disk = slot;
62 + if (test_bit(In_sync, &rdev->flags))
63 + rdev->saved_raid_disk = slot;
65 + rdev->saved_raid_disk = -1;
66 + err = rdev->mddev->pers->
67 + hot_add_disk(rdev->mddev, rdev);
69 + rdev->raid_disk = -1;
74 + sprintf(nm, "rd%d", rdev->raid_disk);
75 + if (sysfs_create_link(&rdev->mddev->kobj, &rdev->kobj, nm))
77 + "md: cannot register "
79 + nm, mdname(rdev->mddev));
81 + /* don't wakeup anyone, leave that to userspace. */
83 if (slot >= rdev->mddev->raid_disks)
85 @@ -4205,7 +4241,7 @@ static int add_new_disk(mddev_t * mddev,
86 super_types[mddev->major_version].
87 validate_super(mddev, rdev);
88 err = mddev->pers->hot_add_disk(mddev, rdev);
91 unbind_rdev_from_array(rdev);
95 diff .prev/drivers/md/multipath.c ./drivers/md/multipath.c
96 --- .prev/drivers/md/multipath.c 2008-05-30 14:49:31.000000000 +1000
97 +++ ./drivers/md/multipath.c 2008-06-10 10:35:03.000000000 +1000
98 @@ -284,10 +284,15 @@ static int multipath_add_disk(mddev_t *m
101 struct multipath_info *p;
103 + int last = mddev->raid_disks - 1;
105 + if (rdev->raid_disk >= 0)
106 + first = last = rdev->raid_disk;
108 print_multipath_conf(conf);
110 - for (path=0; path<mddev->raid_disks; path++)
111 + for (path = first; path <= last; path++)
112 if ((p=conf->multipaths+path)->rdev == NULL) {
113 q = rdev->bdev->bd_disk->queue;
114 blk_queue_stack_limits(mddev->queue, q);
116 diff .prev/drivers/md/raid10.c ./drivers/md/raid10.c
117 --- .prev/drivers/md/raid10.c 2008-05-30 14:49:31.000000000 +1000
118 +++ ./drivers/md/raid10.c 2008-06-10 10:28:53.000000000 +1000
119 @@ -1116,6 +1116,8 @@ static int raid10_add_disk(mddev_t *mdde
124 + int last = mddev->raid_disks - 1;
126 if (mddev->recovery_cp < MaxSector)
127 /* only hot-add to in-sync arrays, as recovery is
128 @@ -1125,12 +1127,16 @@ static int raid10_add_disk(mddev_t *mdde
132 + if (rdev->raid_disk)
133 + first = last = rdev->raid_disk;
135 if (rdev->saved_raid_disk >= 0 &&
136 + rdev->saved_raid_disk >= first &&
137 conf->mirrors[rdev->saved_raid_disk].rdev == NULL)
138 mirror = rdev->saved_raid_disk;
141 - for ( ; mirror < mddev->raid_disks; mirror++)
143 + for ( ; mirror <= last ; mirror++)
144 if ( !(p=conf->mirrors+mirror)->rdev) {
146 blk_queue_stack_limits(mddev->queue,
148 diff .prev/drivers/md/raid1.c ./drivers/md/raid1.c
149 --- .prev/drivers/md/raid1.c 2008-05-30 14:49:31.000000000 +1000
150 +++ ./drivers/md/raid1.c 2008-06-10 10:41:00.000000000 +1000
151 @@ -1103,8 +1103,13 @@ static int raid1_add_disk(mddev_t *mddev
156 + int last = mddev->raid_disks - 1;
158 - for (mirror=0; mirror < mddev->raid_disks; mirror++)
159 + if (rdev->raid_disk >= 0)
160 + first = last = rdev->raid_disk;
162 + for (mirror = first; mirror <= last; mirror++)
163 if ( !(p=conf->mirrors+mirror)->rdev) {
165 blk_queue_stack_limits(mddev->queue,
167 diff .prev/drivers/md/raid5.c ./drivers/md/raid5.c
168 --- .prev/drivers/md/raid5.c 2008-05-30 14:49:35.000000000 +1000
169 +++ ./drivers/md/raid5.c 2008-06-10 10:27:51.000000000 +1000
170 @@ -4399,21 +4399,27 @@ static int raid5_add_disk(mddev_t *mddev
175 + int last = conf->raid_disks - 1;
177 if (mddev->degraded > conf->max_degraded)
178 /* no point adding a device */
181 + if (rdev->raid_disk >= 0)
182 + first = last = rdev->raid_disk;
185 * find the disk ... but prefer rdev->saved_raid_disk
188 if (rdev->saved_raid_disk >= 0 &&
189 + rdev->saved_raid_disk >= first &&
190 conf->disks[rdev->saved_raid_disk].rdev == NULL)
191 disk = rdev->saved_raid_disk;
194 - for ( ; disk < conf->raid_disks; disk++)
196 + for ( ; disk <= last ; disk++)
197 if ((p=conf->disks + disk)->rdev == NULL) {
198 clear_bit(In_sync, &rdev->flags);
199 rdev->raid_disk = disk;