aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2009-03-17 21:10:40 -0400
committerDan Williams <dan.j.williams@intel.com>2009-03-30 23:57:49 -0400
commit80c3a6ce4ba4470379b9e6a4d9bcd9d2ee26ae03 (patch)
treede88622f05a7e681ac7bff7714e8f2d8953b66ac
parent93ed05e2a56b5ee06c0100a169433b11c4aa5d0b (diff)
md: add 'size' as a personality method
In preparation for giving userspace control over ->array_sectors we need to be able to retrieve the 'default' size, and the 'anticipated' size when a reshape is requested. For personalities that do not reshape emit a warning if anything but the default size is requested. In the raid5 case we need to update ->previous_raid_disks to make the new 'default' size available. Reviewed-by: Andre Noll <maan@systemlinux.org> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
-rw-r--r--drivers/md/faulty.c14
-rw-r--r--drivers/md/linear.c15
-rw-r--r--drivers/md/md.h1
-rw-r--r--drivers/md/multipath.c11
-rw-r--r--drivers/md/raid0.c20
-rw-r--r--drivers/md/raid1.c13
-rw-r--r--drivers/md/raid10.c24
-rw-r--r--drivers/md/raid5.c35
8 files changed, 111 insertions, 22 deletions
diff --git a/drivers/md/faulty.c b/drivers/md/faulty.c
index 18793c137278..d76c87f2a831 100644
--- a/drivers/md/faulty.c
+++ b/drivers/md/faulty.c
@@ -283,6 +283,17 @@ static int reconfig(mddev_t *mddev, int layout, int chunk_size)
283 return 0; 283 return 0;
284} 284}
285 285
286static sector_t faulty_size(mddev_t *mddev, sector_t sectors, int raid_disks)
287{
288 WARN_ONCE(raid_disks,
289 "%s does not support generic reshape\n", __func__);
290
291 if (sectors == 0)
292 return mddev->dev_sectors;
293
294 return sectors;
295}
296
286static int run(mddev_t *mddev) 297static int run(mddev_t *mddev)
287{ 298{
288 mdk_rdev_t *rdev; 299 mdk_rdev_t *rdev;
@@ -301,7 +312,7 @@ static int run(mddev_t *mddev)
301 list_for_each_entry(rdev, &mddev->disks, same_set) 312 list_for_each_entry(rdev, &mddev->disks, same_set)
302 conf->rdev = rdev; 313 conf->rdev = rdev;
303 314
304 mddev->array_sectors = mddev->dev_sectors; 315 mddev->array_sectors = faulty_size(mddev, 0, 0);
305 mddev->private = conf; 316 mddev->private = conf;
306 317
307 reconfig(mddev, mddev->layout, -1); 318 reconfig(mddev, mddev->layout, -1);
@@ -328,6 +339,7 @@ static struct mdk_personality faulty_personality =
328 .stop = stop, 339 .stop = stop,
329 .status = status, 340 .status = status,
330 .reconfig = reconfig, 341 .reconfig = reconfig,
342 .size = faulty_size,
331}; 343};
332 344
333static int __init raid_init(void) 345static int __init raid_init(void)
diff --git a/drivers/md/linear.c b/drivers/md/linear.c
index d5d99290041a..b6bb976123da 100644
--- a/drivers/md/linear.c
+++ b/drivers/md/linear.c
@@ -101,6 +101,16 @@ static int linear_congested(void *data, int bits)
101 return ret; 101 return ret;
102} 102}
103 103
104static sector_t linear_size(mddev_t *mddev, sector_t sectors, int raid_disks)
105{
106 linear_conf_t *conf = mddev_to_conf(mddev);
107
108 WARN_ONCE(sectors || raid_disks,
109 "%s does not support generic reshape\n", __func__);
110
111 return conf->array_sectors;
112}
113
104static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks) 114static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
105{ 115{
106 linear_conf_t *conf; 116 linear_conf_t *conf;
@@ -253,7 +263,7 @@ static int linear_run (mddev_t *mddev)
253 if (!conf) 263 if (!conf)
254 return 1; 264 return 1;
255 mddev->private = conf; 265 mddev->private = conf;
256 mddev->array_sectors = conf->array_sectors; 266 mddev->array_sectors = linear_size(mddev, 0, 0);
257 267
258 blk_queue_merge_bvec(mddev->queue, linear_mergeable_bvec); 268 blk_queue_merge_bvec(mddev->queue, linear_mergeable_bvec);
259 mddev->queue->unplug_fn = linear_unplug; 269 mddev->queue->unplug_fn = linear_unplug;
@@ -287,7 +297,7 @@ static int linear_add(mddev_t *mddev, mdk_rdev_t *rdev)
287 newconf->prev = mddev_to_conf(mddev); 297 newconf->prev = mddev_to_conf(mddev);
288 mddev->private = newconf; 298 mddev->private = newconf;
289 mddev->raid_disks++; 299 mddev->raid_disks++;
290 mddev->array_sectors = newconf->array_sectors; 300 mddev->array_sectors = linear_size(mddev, 0, 0);
291 set_capacity(mddev->gendisk, mddev->array_sectors); 301 set_capacity(mddev->gendisk, mddev->array_sectors);
292 return 0; 302 return 0;
293} 303}
@@ -385,6 +395,7 @@ static struct mdk_personality linear_personality =
385 .stop = linear_stop, 395 .stop = linear_stop,
386 .status = linear_status, 396 .status = linear_status,
387 .hot_add_disk = linear_add, 397 .hot_add_disk = linear_add,
398 .size = linear_size,
388}; 399};
389 400
390static int __init linear_init (void) 401static int __init linear_init (void)
diff --git a/drivers/md/md.h b/drivers/md/md.h
index 8034f62a9d28..d2c50da1ae7f 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -312,6 +312,7 @@ struct mdk_personality
312 int (*spare_active) (mddev_t *mddev); 312 int (*spare_active) (mddev_t *mddev);
313 sector_t (*sync_request)(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster); 313 sector_t (*sync_request)(mddev_t *mddev, sector_t sector_nr, int *skipped, int go_faster);
314 int (*resize) (mddev_t *mddev, sector_t sectors); 314 int (*resize) (mddev_t *mddev, sector_t sectors);
315 sector_t (*size) (mddev_t *mddev, sector_t sectors, int raid_disks);
315 int (*check_reshape) (mddev_t *mddev); 316 int (*check_reshape) (mddev_t *mddev);
316 int (*start_reshape) (mddev_t *mddev); 317 int (*start_reshape) (mddev_t *mddev);
317 int (*reconfig) (mddev_t *mddev, int layout, int chunk_size); 318 int (*reconfig) (mddev_t *mddev, int layout, int chunk_size);
diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index 87accf74e4b4..a3f6d8668bb3 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -406,6 +406,14 @@ static void multipathd (mddev_t *mddev)
406 spin_unlock_irqrestore(&conf->device_lock, flags); 406 spin_unlock_irqrestore(&conf->device_lock, flags);
407} 407}
408 408
409static sector_t multipath_size(mddev_t *mddev, sector_t sectors, int raid_disks)
410{
411 WARN_ONCE(sectors || raid_disks,
412 "%s does not support generic reshape\n", __func__);
413
414 return mddev->dev_sectors;
415}
416
409static int multipath_run (mddev_t *mddev) 417static int multipath_run (mddev_t *mddev)
410{ 418{
411 multipath_conf_t *conf; 419 multipath_conf_t *conf;
@@ -502,7 +510,7 @@ static int multipath_run (mddev_t *mddev)
502 /* 510 /*
503 * Ok, everything is just fine now 511 * Ok, everything is just fine now
504 */ 512 */
505 mddev->array_sectors = mddev->dev_sectors; 513 mddev->array_sectors = multipath_size(mddev, 0, 0);
506 514
507 mddev->queue->unplug_fn = multipath_unplug; 515 mddev->queue->unplug_fn = multipath_unplug;
508 mddev->queue->backing_dev_info.congested_fn = multipath_congested; 516 mddev->queue->backing_dev_info.congested_fn = multipath_congested;
@@ -547,6 +555,7 @@ static struct mdk_personality multipath_personality =
547 .error_handler = multipath_error, 555 .error_handler = multipath_error,
548 .hot_add_disk = multipath_add_disk, 556 .hot_add_disk = multipath_add_disk,
549 .hot_remove_disk= multipath_remove_disk, 557 .hot_remove_disk= multipath_remove_disk,
558 .size = multipath_size,
550}; 559};
551 560
552static int __init multipath_init (void) 561static int __init multipath_init (void)
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 9aebb4c93b60..bb0df6a18443 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -263,12 +263,25 @@ static int raid0_mergeable_bvec(struct request_queue *q,
263 return max; 263 return max;
264} 264}
265 265
266static sector_t raid0_size(mddev_t *mddev, sector_t sectors, int raid_disks)
267{
268 sector_t array_sectors = 0;
269 mdk_rdev_t *rdev;
270
271 WARN_ONCE(sectors || raid_disks,
272 "%s does not support generic reshape\n", __func__);
273
274 list_for_each_entry(rdev, &mddev->disks, same_set)
275 array_sectors += rdev->sectors;
276
277 return array_sectors;
278}
279
266static int raid0_run (mddev_t *mddev) 280static int raid0_run (mddev_t *mddev)
267{ 281{
268 unsigned cur=0, i=0, nb_zone; 282 unsigned cur=0, i=0, nb_zone;
269 s64 sectors; 283 s64 sectors;
270 raid0_conf_t *conf; 284 raid0_conf_t *conf;
271 mdk_rdev_t *rdev;
272 285
273 if (mddev->chunk_size == 0) { 286 if (mddev->chunk_size == 0) {
274 printk(KERN_ERR "md/raid0: non-zero chunk size required.\n"); 287 printk(KERN_ERR "md/raid0: non-zero chunk size required.\n");
@@ -293,9 +306,7 @@ static int raid0_run (mddev_t *mddev)
293 goto out_free_conf; 306 goto out_free_conf;
294 307
295 /* calculate array device size */ 308 /* calculate array device size */
296 mddev->array_sectors = 0; 309 mddev->array_sectors = raid0_size(mddev, 0, 0);
297 list_for_each_entry(rdev, &mddev->disks, same_set)
298 mddev->array_sectors += rdev->sectors;
299 310
300 printk(KERN_INFO "raid0 : md_size is %llu sectors.\n", 311 printk(KERN_INFO "raid0 : md_size is %llu sectors.\n",
301 (unsigned long long)mddev->array_sectors); 312 (unsigned long long)mddev->array_sectors);
@@ -511,6 +522,7 @@ static struct mdk_personality raid0_personality=
511 .run = raid0_run, 522 .run = raid0_run,
512 .stop = raid0_stop, 523 .stop = raid0_stop,
513 .status = raid0_status, 524 .status = raid0_status,
525 .size = raid0_size,
514}; 526};
515 527
516static int __init raid0_init (void) 528static int __init raid0_init (void)
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 7eaca3209364..a2a83b0d5a95 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1922,6 +1922,14 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1922 return nr_sectors; 1922 return nr_sectors;
1923} 1923}
1924 1924
1925static sector_t raid1_size(mddev_t *mddev, sector_t sectors, int raid_disks)
1926{
1927 if (sectors)
1928 return sectors;
1929
1930 return mddev->dev_sectors;
1931}
1932
1925static int run(mddev_t *mddev) 1933static int run(mddev_t *mddev)
1926{ 1934{
1927 conf_t *conf; 1935 conf_t *conf;
@@ -2051,7 +2059,7 @@ static int run(mddev_t *mddev)
2051 /* 2059 /*
2052 * Ok, everything is just fine now 2060 * Ok, everything is just fine now
2053 */ 2061 */
2054 mddev->array_sectors = mddev->dev_sectors; 2062 mddev->array_sectors = raid1_size(mddev, 0, 0);
2055 2063
2056 mddev->queue->unplug_fn = raid1_unplug; 2064 mddev->queue->unplug_fn = raid1_unplug;
2057 mddev->queue->backing_dev_info.congested_fn = raid1_congested; 2065 mddev->queue->backing_dev_info.congested_fn = raid1_congested;
@@ -2116,7 +2124,7 @@ static int raid1_resize(mddev_t *mddev, sector_t sectors)
2116 * any io in the removed space completes, but it hardly seems 2124 * any io in the removed space completes, but it hardly seems
2117 * worth it. 2125 * worth it.
2118 */ 2126 */
2119 mddev->array_sectors = sectors; 2127 mddev->array_sectors = raid1_size(mddev, sectors, 0);
2120 set_capacity(mddev->gendisk, mddev->array_sectors); 2128 set_capacity(mddev->gendisk, mddev->array_sectors);
2121 mddev->changed = 1; 2129 mddev->changed = 1;
2122 if (mddev->array_sectors > mddev->dev_sectors && 2130 if (mddev->array_sectors > mddev->dev_sectors &&
@@ -2270,6 +2278,7 @@ static struct mdk_personality raid1_personality =
2270 .spare_active = raid1_spare_active, 2278 .spare_active = raid1_spare_active,
2271 .sync_request = sync_request, 2279 .sync_request = sync_request,
2272 .resize = raid1_resize, 2280 .resize = raid1_resize,
2281 .size = raid1_size,
2273 .check_reshape = raid1_reshape, 2282 .check_reshape = raid1_reshape,
2274 .quiesce = raid1_quiesce, 2283 .quiesce = raid1_quiesce,
2275}; 2284};
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index c2059e25d03f..5bf1b24ae802 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -2023,6 +2023,25 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
2023 goto skipped; 2023 goto skipped;
2024} 2024}
2025 2025
2026static sector_t
2027raid10_size(mddev_t *mddev, sector_t sectors, int raid_disks)
2028{
2029 sector_t size;
2030 conf_t *conf = mddev_to_conf(mddev);
2031
2032 if (!raid_disks)
2033 raid_disks = mddev->raid_disks;
2034 if (!sectors)
2035 sectors = mddev->dev_sectors;
2036
2037 size = sectors >> conf->chunk_shift;
2038 sector_div(size, conf->far_copies);
2039 size = size * raid_disks;
2040 sector_div(size, conf->near_copies);
2041
2042 return size << conf->chunk_shift;
2043}
2044
2026static int run(mddev_t *mddev) 2045static int run(mddev_t *mddev)
2027{ 2046{
2028 conf_t *conf; 2047 conf_t *conf;
@@ -2174,8 +2193,8 @@ static int run(mddev_t *mddev)
2174 /* 2193 /*
2175 * Ok, everything is just fine now 2194 * Ok, everything is just fine now
2176 */ 2195 */
2177 mddev->array_sectors = size << conf->chunk_shift; 2196 mddev->array_sectors = raid10_size(mddev, 0, 0);
2178 mddev->resync_max_sectors = size << conf->chunk_shift; 2197 mddev->resync_max_sectors = mddev->array_sectors;
2179 2198
2180 mddev->queue->unplug_fn = raid10_unplug; 2199 mddev->queue->unplug_fn = raid10_unplug;
2181 mddev->queue->backing_dev_info.congested_fn = raid10_congested; 2200 mddev->queue->backing_dev_info.congested_fn = raid10_congested;
@@ -2261,6 +2280,7 @@ static struct mdk_personality raid10_personality =
2261 .spare_active = raid10_spare_active, 2280 .spare_active = raid10_spare_active,
2262 .sync_request = sync_request, 2281 .sync_request = sync_request,
2263 .quiesce = raid10_quiesce, 2282 .quiesce = raid10_quiesce,
2283 .size = raid10_size,
2264}; 2284};
2265 2285
2266static int __init raid_init(void) 2286static int __init raid_init(void)
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 70b50af2bcd7..2cd619ff0761 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -4166,6 +4166,20 @@ static struct attribute_group raid5_attrs_group = {
4166 .attrs = raid5_attrs, 4166 .attrs = raid5_attrs,
4167}; 4167};
4168 4168
4169static sector_t
4170raid5_size(mddev_t *mddev, sector_t sectors, int raid_disks)
4171{
4172 raid5_conf_t *conf = mddev_to_conf(mddev);
4173
4174 if (!sectors)
4175 sectors = mddev->dev_sectors;
4176 if (!raid_disks)
4177 raid_disks = conf->previous_raid_disks;
4178
4179 sectors &= ~((sector_t)mddev->chunk_size/512 - 1);
4180 return sectors * (raid_disks - conf->max_degraded);
4181}
4182
4169static raid5_conf_t *setup_conf(mddev_t *mddev) 4183static raid5_conf_t *setup_conf(mddev_t *mddev)
4170{ 4184{
4171 raid5_conf_t *conf; 4185 raid5_conf_t *conf;
@@ -4460,8 +4474,7 @@ static int run(mddev_t *mddev)
4460 mddev->queue->backing_dev_info.congested_data = mddev; 4474 mddev->queue->backing_dev_info.congested_data = mddev;
4461 mddev->queue->backing_dev_info.congested_fn = raid5_congested; 4475 mddev->queue->backing_dev_info.congested_fn = raid5_congested;
4462 4476
4463 mddev->array_sectors = mddev->dev_sectors * 4477 mddev->array_sectors = raid5_size(mddev, 0, 0);
4464 (conf->previous_raid_disks - conf->max_degraded);
4465 4478
4466 blk_queue_merge_bvec(mddev->queue, raid5_mergeable_bvec); 4479 blk_queue_merge_bvec(mddev->queue, raid5_mergeable_bvec);
4467 4480
@@ -4684,11 +4697,8 @@ static int raid5_resize(mddev_t *mddev, sector_t sectors)
4684 * any io in the removed space completes, but it hardly seems 4697 * any io in the removed space completes, but it hardly seems
4685 * worth it. 4698 * worth it.
4686 */ 4699 */
4687 raid5_conf_t *conf = mddev_to_conf(mddev);
4688
4689 sectors &= ~((sector_t)mddev->chunk_size/512 - 1); 4700 sectors &= ~((sector_t)mddev->chunk_size/512 - 1);
4690 mddev->array_sectors = sectors * (mddev->raid_disks 4701 mddev->array_sectors = raid5_size(mddev, sectors, mddev->raid_disks);
4691 - conf->max_degraded);
4692 set_capacity(mddev->gendisk, mddev->array_sectors); 4702 set_capacity(mddev->gendisk, mddev->array_sectors);
4693 mddev->changed = 1; 4703 mddev->changed = 1;
4694 if (sectors > mddev->dev_sectors && mddev->recovery_cp == MaxSector) { 4704 if (sectors > mddev->dev_sectors && mddev->recovery_cp == MaxSector) {
@@ -4824,10 +4834,12 @@ static void end_reshape(raid5_conf_t *conf)
4824 struct block_device *bdev; 4834 struct block_device *bdev;
4825 4835
4826 if (!test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) { 4836 if (!test_bit(MD_RECOVERY_INTR, &conf->mddev->recovery)) {
4827 conf->mddev->array_sectors = conf->mddev->dev_sectors * 4837 mddev_t *mddev = conf->mddev;
4828 (conf->raid_disks - conf->max_degraded); 4838
4829 set_capacity(conf->mddev->gendisk, conf->mddev->array_sectors); 4839 mddev->array_sectors = raid5_size(mddev, 0, conf->raid_disks);
4830 conf->mddev->changed = 1; 4840 set_capacity(mddev->gendisk, mddev->array_sectors);
4841 mddev->changed = 1;
4842 conf->previous_raid_disks = conf->raid_disks;
4831 4843
4832 bdev = bdget_disk(conf->mddev->gendisk, 0); 4844 bdev = bdget_disk(conf->mddev->gendisk, 0);
4833 if (bdev) { 4845 if (bdev) {
@@ -5076,6 +5088,7 @@ static struct mdk_personality raid6_personality =
5076 .spare_active = raid5_spare_active, 5088 .spare_active = raid5_spare_active,
5077 .sync_request = sync_request, 5089 .sync_request = sync_request,
5078 .resize = raid5_resize, 5090 .resize = raid5_resize,
5091 .size = raid5_size,
5079#ifdef CONFIG_MD_RAID5_RESHAPE 5092#ifdef CONFIG_MD_RAID5_RESHAPE
5080 .check_reshape = raid5_check_reshape, 5093 .check_reshape = raid5_check_reshape,
5081 .start_reshape = raid5_start_reshape, 5094 .start_reshape = raid5_start_reshape,
@@ -5098,6 +5111,7 @@ static struct mdk_personality raid5_personality =
5098 .spare_active = raid5_spare_active, 5111 .spare_active = raid5_spare_active,
5099 .sync_request = sync_request, 5112 .sync_request = sync_request,
5100 .resize = raid5_resize, 5113 .resize = raid5_resize,
5114 .size = raid5_size,
5101#ifdef CONFIG_MD_RAID5_RESHAPE 5115#ifdef CONFIG_MD_RAID5_RESHAPE
5102 .check_reshape = raid5_check_reshape, 5116 .check_reshape = raid5_check_reshape,
5103 .start_reshape = raid5_start_reshape, 5117 .start_reshape = raid5_start_reshape,
@@ -5122,6 +5136,7 @@ static struct mdk_personality raid4_personality =
5122 .spare_active = raid5_spare_active, 5136 .spare_active = raid5_spare_active,
5123 .sync_request = sync_request, 5137 .sync_request = sync_request,
5124 .resize = raid5_resize, 5138 .resize = raid5_resize,
5139 .size = raid5_size,
5125#ifdef CONFIG_MD_RAID5_RESHAPE 5140#ifdef CONFIG_MD_RAID5_RESHAPE
5126 .check_reshape = raid5_check_reshape, 5141 .check_reshape = raid5_check_reshape,
5127 .start_reshape = raid5_start_reshape, 5142 .start_reshape = raid5_start_reshape,