aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2009-12-13 20:49:52 -0500
committerNeilBrown <neilb@suse.de>2009-12-13 20:51:41 -0500
commitc3d9714e88c8685cf9bc837c3241fc005f95fb82 (patch)
treedd11e16ec911983bb7452bb4fb092769ba612e3b /drivers
parent709ae4879ae33628ded276ce7da8cd5acfec476b (diff)
md: collect bitmap-specific fields into one structure.
In preparation for making bitmap fields configurable via sysfs, start tidying up by making a single structure to contain the configuration fields. Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/md/bitmap.c18
-rw-r--r--drivers/md/md.c79
-rw-r--r--drivers/md/md.h22
3 files changed, 63 insertions, 56 deletions
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index a5e5f2fbf963..c9270f2c9ecd 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -1090,10 +1090,10 @@ void bitmap_daemon_work(mddev_t *mddev)
1090 /* Use a mutex to guard daemon_work against 1090 /* Use a mutex to guard daemon_work against
1091 * bitmap_destroy. 1091 * bitmap_destroy.
1092 */ 1092 */
1093 mutex_lock(&mddev->bitmap_mutex); 1093 mutex_lock(&mddev->bitmap_info.mutex);
1094 bitmap = mddev->bitmap; 1094 bitmap = mddev->bitmap;
1095 if (bitmap == NULL) { 1095 if (bitmap == NULL) {
1096 mutex_unlock(&mddev->bitmap_mutex); 1096 mutex_unlock(&mddev->bitmap_info.mutex);
1097 return; 1097 return;
1098 } 1098 }
1099 if (time_before(jiffies, bitmap->daemon_lastrun + bitmap->daemon_sleep*HZ)) 1099 if (time_before(jiffies, bitmap->daemon_lastrun + bitmap->daemon_sleep*HZ))
@@ -1211,7 +1211,7 @@ void bitmap_daemon_work(mddev_t *mddev)
1211 done: 1211 done:
1212 if (bitmap->allclean == 0) 1212 if (bitmap->allclean == 0)
1213 bitmap->mddev->thread->timeout = bitmap->daemon_sleep * HZ; 1213 bitmap->mddev->thread->timeout = bitmap->daemon_sleep * HZ;
1214 mutex_unlock(&mddev->bitmap_mutex); 1214 mutex_unlock(&mddev->bitmap_info.mutex);
1215} 1215}
1216 1216
1217static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap, 1217static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap,
@@ -1591,9 +1591,9 @@ void bitmap_destroy(mddev_t *mddev)
1591 if (!bitmap) /* there was no bitmap */ 1591 if (!bitmap) /* there was no bitmap */
1592 return; 1592 return;
1593 1593
1594 mutex_lock(&mddev->bitmap_mutex); 1594 mutex_lock(&mddev->bitmap_info.mutex);
1595 mddev->bitmap = NULL; /* disconnect from the md device */ 1595 mddev->bitmap = NULL; /* disconnect from the md device */
1596 mutex_unlock(&mddev->bitmap_mutex); 1596 mutex_unlock(&mddev->bitmap_info.mutex);
1597 if (mddev->thread) 1597 if (mddev->thread)
1598 mddev->thread->timeout = MAX_SCHEDULE_TIMEOUT; 1598 mddev->thread->timeout = MAX_SCHEDULE_TIMEOUT;
1599 1599
@@ -1610,16 +1610,16 @@ int bitmap_create(mddev_t *mddev)
1610 sector_t blocks = mddev->resync_max_sectors; 1610 sector_t blocks = mddev->resync_max_sectors;
1611 unsigned long chunks; 1611 unsigned long chunks;
1612 unsigned long pages; 1612 unsigned long pages;
1613 struct file *file = mddev->bitmap_file; 1613 struct file *file = mddev->bitmap_info.file;
1614 int err; 1614 int err;
1615 sector_t start; 1615 sector_t start;
1616 1616
1617 BUILD_BUG_ON(sizeof(bitmap_super_t) != 256); 1617 BUILD_BUG_ON(sizeof(bitmap_super_t) != 256);
1618 1618
1619 if (!file && !mddev->bitmap_offset) /* bitmap disabled, nothing to do */ 1619 if (!file && !mddev->bitmap_info.offset) /* bitmap disabled, nothing to do */
1620 return 0; 1620 return 0;
1621 1621
1622 BUG_ON(file && mddev->bitmap_offset); 1622 BUG_ON(file && mddev->bitmap_info.offset);
1623 1623
1624 bitmap = kzalloc(sizeof(*bitmap), GFP_KERNEL); 1624 bitmap = kzalloc(sizeof(*bitmap), GFP_KERNEL);
1625 if (!bitmap) 1625 if (!bitmap)
@@ -1633,7 +1633,7 @@ int bitmap_create(mddev_t *mddev)
1633 bitmap->mddev = mddev; 1633 bitmap->mddev = mddev;
1634 1634
1635 bitmap->file = file; 1635 bitmap->file = file;
1636 bitmap->offset = mddev->bitmap_offset; 1636 bitmap->offset = mddev->bitmap_info.offset;
1637 if (file) { 1637 if (file) {
1638 get_file(file); 1638 get_file(file);
1639 /* As future accesses to this file will use bmap, 1639 /* As future accesses to this file will use bmap,
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 569f25183db6..63da0a51852d 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -463,7 +463,7 @@ static mddev_t * mddev_find(dev_t unit)
463 463
464 mutex_init(&new->open_mutex); 464 mutex_init(&new->open_mutex);
465 mutex_init(&new->reconfig_mutex); 465 mutex_init(&new->reconfig_mutex);
466 mutex_init(&new->bitmap_mutex); 466 mutex_init(&new->bitmap_info.mutex);
467 INIT_LIST_HEAD(&new->disks); 467 INIT_LIST_HEAD(&new->disks);
468 INIT_LIST_HEAD(&new->all_mddevs); 468 INIT_LIST_HEAD(&new->all_mddevs);
469 init_timer(&new->safemode_timer); 469 init_timer(&new->safemode_timer);
@@ -850,7 +850,7 @@ struct super_type {
850 */ 850 */
851int md_check_no_bitmap(mddev_t *mddev) 851int md_check_no_bitmap(mddev_t *mddev)
852{ 852{
853 if (!mddev->bitmap_file && !mddev->bitmap_offset) 853 if (!mddev->bitmap_info.file && !mddev->bitmap_info.offset)
854 return 0; 854 return 0;
855 printk(KERN_ERR "%s: bitmaps are not supported for %s\n", 855 printk(KERN_ERR "%s: bitmaps are not supported for %s\n",
856 mdname(mddev), mddev->pers->name); 856 mdname(mddev), mddev->pers->name);
@@ -978,8 +978,8 @@ static int super_90_validate(mddev_t *mddev, mdk_rdev_t *rdev)
978 mddev->raid_disks = sb->raid_disks; 978 mddev->raid_disks = sb->raid_disks;
979 mddev->dev_sectors = sb->size * 2; 979 mddev->dev_sectors = sb->size * 2;
980 mddev->events = ev1; 980 mddev->events = ev1;
981 mddev->bitmap_offset = 0; 981 mddev->bitmap_info.offset = 0;
982 mddev->default_bitmap_offset = MD_SB_BYTES >> 9; 982 mddev->bitmap_info.default_offset = MD_SB_BYTES >> 9;
983 983
984 if (mddev->minor_version >= 91) { 984 if (mddev->minor_version >= 91) {
985 mddev->reshape_position = sb->reshape_position; 985 mddev->reshape_position = sb->reshape_position;
@@ -1013,8 +1013,9 @@ static int super_90_validate(mddev_t *mddev, mdk_rdev_t *rdev)
1013 mddev->max_disks = MD_SB_DISKS; 1013 mddev->max_disks = MD_SB_DISKS;
1014 1014
1015 if (sb->state & (1<<MD_SB_BITMAP_PRESENT) && 1015 if (sb->state & (1<<MD_SB_BITMAP_PRESENT) &&
1016 mddev->bitmap_file == NULL) 1016 mddev->bitmap_info.file == NULL)
1017 mddev->bitmap_offset = mddev->default_bitmap_offset; 1017 mddev->bitmap_info.offset =
1018 mddev->bitmap_info.default_offset;
1018 1019
1019 } else if (mddev->pers == NULL) { 1020 } else if (mddev->pers == NULL) {
1020 /* Insist on good event counter while assembling */ 1021 /* Insist on good event counter while assembling */
@@ -1131,7 +1132,7 @@ static void super_90_sync(mddev_t *mddev, mdk_rdev_t *rdev)
1131 sb->layout = mddev->layout; 1132 sb->layout = mddev->layout;
1132 sb->chunk_size = mddev->chunk_sectors << 9; 1133 sb->chunk_size = mddev->chunk_sectors << 9;
1133 1134
1134 if (mddev->bitmap && mddev->bitmap_file == NULL) 1135 if (mddev->bitmap && mddev->bitmap_info.file == NULL)
1135 sb->state |= (1<<MD_SB_BITMAP_PRESENT); 1136 sb->state |= (1<<MD_SB_BITMAP_PRESENT);
1136 1137
1137 sb->disks[0].state = (1<<MD_DISK_REMOVED); 1138 sb->disks[0].state = (1<<MD_DISK_REMOVED);
@@ -1209,7 +1210,7 @@ super_90_rdev_size_change(mdk_rdev_t *rdev, sector_t num_sectors)
1209{ 1210{
1210 if (num_sectors && num_sectors < rdev->mddev->dev_sectors) 1211 if (num_sectors && num_sectors < rdev->mddev->dev_sectors)
1211 return 0; /* component must fit device */ 1212 return 0; /* component must fit device */
1212 if (rdev->mddev->bitmap_offset) 1213 if (rdev->mddev->bitmap_info.offset)
1213 return 0; /* can't move bitmap */ 1214 return 0; /* can't move bitmap */
1214 rdev->sb_start = calc_dev_sboffset(rdev->bdev); 1215 rdev->sb_start = calc_dev_sboffset(rdev->bdev);
1215 if (!num_sectors || num_sectors > rdev->sb_start) 1216 if (!num_sectors || num_sectors > rdev->sb_start)
@@ -1388,8 +1389,8 @@ static int super_1_validate(mddev_t *mddev, mdk_rdev_t *rdev)
1388 mddev->raid_disks = le32_to_cpu(sb->raid_disks); 1389 mddev->raid_disks = le32_to_cpu(sb->raid_disks);
1389 mddev->dev_sectors = le64_to_cpu(sb->size); 1390 mddev->dev_sectors = le64_to_cpu(sb->size);
1390 mddev->events = ev1; 1391 mddev->events = ev1;
1391 mddev->bitmap_offset = 0; 1392 mddev->bitmap_info.offset = 0;
1392 mddev->default_bitmap_offset = 1024 >> 9; 1393 mddev->bitmap_info.default_offset = 1024 >> 9;
1393 1394
1394 mddev->recovery_cp = le64_to_cpu(sb->resync_offset); 1395 mddev->recovery_cp = le64_to_cpu(sb->resync_offset);
1395 memcpy(mddev->uuid, sb->set_uuid, 16); 1396 memcpy(mddev->uuid, sb->set_uuid, 16);
@@ -1397,8 +1398,9 @@ static int super_1_validate(mddev_t *mddev, mdk_rdev_t *rdev)
1397 mddev->max_disks = (4096-256)/2; 1398 mddev->max_disks = (4096-256)/2;
1398 1399
1399 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_BITMAP_OFFSET) && 1400 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_BITMAP_OFFSET) &&
1400 mddev->bitmap_file == NULL ) 1401 mddev->bitmap_info.file == NULL )
1401 mddev->bitmap_offset = (__s32)le32_to_cpu(sb->bitmap_offset); 1402 mddev->bitmap_info.offset =
1403 (__s32)le32_to_cpu(sb->bitmap_offset);
1402 1404
1403 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE)) { 1405 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE)) {
1404 mddev->reshape_position = le64_to_cpu(sb->reshape_position); 1406 mddev->reshape_position = le64_to_cpu(sb->reshape_position);
@@ -1492,8 +1494,8 @@ static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev)
1492 sb->level = cpu_to_le32(mddev->level); 1494 sb->level = cpu_to_le32(mddev->level);
1493 sb->layout = cpu_to_le32(mddev->layout); 1495 sb->layout = cpu_to_le32(mddev->layout);
1494 1496
1495 if (mddev->bitmap && mddev->bitmap_file == NULL) { 1497 if (mddev->bitmap && mddev->bitmap_info.file == NULL) {
1496 sb->bitmap_offset = cpu_to_le32((__u32)mddev->bitmap_offset); 1498 sb->bitmap_offset = cpu_to_le32((__u32)mddev->bitmap_info.offset);
1497 sb->feature_map = cpu_to_le32(MD_FEATURE_BITMAP_OFFSET); 1499 sb->feature_map = cpu_to_le32(MD_FEATURE_BITMAP_OFFSET);
1498 } 1500 }
1499 1501
@@ -1560,7 +1562,7 @@ super_1_rdev_size_change(mdk_rdev_t *rdev, sector_t num_sectors)
1560 max_sectors -= rdev->data_offset; 1562 max_sectors -= rdev->data_offset;
1561 if (!num_sectors || num_sectors > max_sectors) 1563 if (!num_sectors || num_sectors > max_sectors)
1562 num_sectors = max_sectors; 1564 num_sectors = max_sectors;
1563 } else if (rdev->mddev->bitmap_offset) { 1565 } else if (rdev->mddev->bitmap_info.offset) {
1564 /* minor version 0 with bitmap we can't move */ 1566 /* minor version 0 with bitmap we can't move */
1565 return 0; 1567 return 0;
1566 } else { 1568 } else {
@@ -4507,12 +4509,12 @@ out:
4507 printk(KERN_INFO "md: %s stopped.\n", mdname(mddev)); 4509 printk(KERN_INFO "md: %s stopped.\n", mdname(mddev));
4508 4510
4509 bitmap_destroy(mddev); 4511 bitmap_destroy(mddev);
4510 if (mddev->bitmap_file) { 4512 if (mddev->bitmap_info.file) {
4511 restore_bitmap_write_access(mddev->bitmap_file); 4513 restore_bitmap_write_access(mddev->bitmap_info.file);
4512 fput(mddev->bitmap_file); 4514 fput(mddev->bitmap_info.file);
4513 mddev->bitmap_file = NULL; 4515 mddev->bitmap_info.file = NULL;
4514 } 4516 }
4515 mddev->bitmap_offset = 0; 4517 mddev->bitmap_info.offset = 0;
4516 4518
4517 /* make sure all md_delayed_delete calls have finished */ 4519 /* make sure all md_delayed_delete calls have finished */
4518 flush_scheduled_work(); 4520 flush_scheduled_work();
@@ -4553,6 +4555,8 @@ out:
4553 mddev->degraded = 0; 4555 mddev->degraded = 0;
4554 mddev->barriers_work = 0; 4556 mddev->barriers_work = 0;
4555 mddev->safemode = 0; 4557 mddev->safemode = 0;
4558 mddev->bitmap_info.offset = 0;
4559 mddev->bitmap_info.default_offset = 0;
4556 kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE); 4560 kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE);
4557 if (mddev->hold_active == UNTIL_STOP) 4561 if (mddev->hold_active == UNTIL_STOP)
4558 mddev->hold_active = 0; 4562 mddev->hold_active = 0;
@@ -4738,7 +4742,7 @@ static int get_array_info(mddev_t * mddev, void __user * arg)
4738 info.state = 0; 4742 info.state = 0;
4739 if (mddev->in_sync) 4743 if (mddev->in_sync)
4740 info.state = (1<<MD_SB_CLEAN); 4744 info.state = (1<<MD_SB_CLEAN);
4741 if (mddev->bitmap && mddev->bitmap_offset) 4745 if (mddev->bitmap && mddev->bitmap_info.offset)
4742 info.state = (1<<MD_SB_BITMAP_PRESENT); 4746 info.state = (1<<MD_SB_BITMAP_PRESENT);
4743 info.active_disks = insync; 4747 info.active_disks = insync;
4744 info.working_disks = working; 4748 info.working_disks = working;
@@ -5096,23 +5100,23 @@ static int set_bitmap_file(mddev_t *mddev, int fd)
5096 if (fd >= 0) { 5100 if (fd >= 0) {
5097 if (mddev->bitmap) 5101 if (mddev->bitmap)
5098 return -EEXIST; /* cannot add when bitmap is present */ 5102 return -EEXIST; /* cannot add when bitmap is present */
5099 mddev->bitmap_file = fget(fd); 5103 mddev->bitmap_info.file = fget(fd);
5100 5104
5101 if (mddev->bitmap_file == NULL) { 5105 if (mddev->bitmap_info.file == NULL) {
5102 printk(KERN_ERR "%s: error: failed to get bitmap file\n", 5106 printk(KERN_ERR "%s: error: failed to get bitmap file\n",
5103 mdname(mddev)); 5107 mdname(mddev));
5104 return -EBADF; 5108 return -EBADF;
5105 } 5109 }
5106 5110
5107 err = deny_bitmap_write_access(mddev->bitmap_file); 5111 err = deny_bitmap_write_access(mddev->bitmap_info.file);
5108 if (err) { 5112 if (err) {
5109 printk(KERN_ERR "%s: error: bitmap file is already in use\n", 5113 printk(KERN_ERR "%s: error: bitmap file is already in use\n",
5110 mdname(mddev)); 5114 mdname(mddev));
5111 fput(mddev->bitmap_file); 5115 fput(mddev->bitmap_info.file);
5112 mddev->bitmap_file = NULL; 5116 mddev->bitmap_info.file = NULL;
5113 return err; 5117 return err;
5114 } 5118 }
5115 mddev->bitmap_offset = 0; /* file overrides offset */ 5119 mddev->bitmap_info.offset = 0; /* file overrides offset */
5116 } else if (mddev->bitmap == NULL) 5120 } else if (mddev->bitmap == NULL)
5117 return -ENOENT; /* cannot remove what isn't there */ 5121 return -ENOENT; /* cannot remove what isn't there */
5118 err = 0; 5122 err = 0;
@@ -5127,11 +5131,11 @@ static int set_bitmap_file(mddev_t *mddev, int fd)
5127 mddev->pers->quiesce(mddev, 0); 5131 mddev->pers->quiesce(mddev, 0);
5128 } 5132 }
5129 if (fd < 0) { 5133 if (fd < 0) {
5130 if (mddev->bitmap_file) { 5134 if (mddev->bitmap_info.file) {
5131 restore_bitmap_write_access(mddev->bitmap_file); 5135 restore_bitmap_write_access(mddev->bitmap_info.file);
5132 fput(mddev->bitmap_file); 5136 fput(mddev->bitmap_info.file);
5133 } 5137 }
5134 mddev->bitmap_file = NULL; 5138 mddev->bitmap_info.file = NULL;
5135 } 5139 }
5136 5140
5137 return err; 5141 return err;
@@ -5198,8 +5202,8 @@ static int set_array_info(mddev_t * mddev, mdu_array_info_t *info)
5198 mddev->flags = 0; 5202 mddev->flags = 0;
5199 set_bit(MD_CHANGE_DEVS, &mddev->flags); 5203 set_bit(MD_CHANGE_DEVS, &mddev->flags);
5200 5204
5201 mddev->default_bitmap_offset = MD_SB_BYTES >> 9; 5205 mddev->bitmap_info.default_offset = MD_SB_BYTES >> 9;
5202 mddev->bitmap_offset = 0; 5206 mddev->bitmap_info.offset = 0;
5203 5207
5204 mddev->reshape_position = MaxSector; 5208 mddev->reshape_position = MaxSector;
5205 5209
@@ -5299,7 +5303,7 @@ static int update_array_info(mddev_t *mddev, mdu_array_info_t *info)
5299 int state = 0; 5303 int state = 0;
5300 5304
5301 /* calculate expected state,ignoring low bits */ 5305 /* calculate expected state,ignoring low bits */
5302 if (mddev->bitmap && mddev->bitmap_offset) 5306 if (mddev->bitmap && mddev->bitmap_info.offset)
5303 state |= (1 << MD_SB_BITMAP_PRESENT); 5307 state |= (1 << MD_SB_BITMAP_PRESENT);
5304 5308
5305 if (mddev->major_version != info->major_version || 5309 if (mddev->major_version != info->major_version ||
@@ -5358,9 +5362,10 @@ static int update_array_info(mddev_t *mddev, mdu_array_info_t *info)
5358 /* add the bitmap */ 5362 /* add the bitmap */
5359 if (mddev->bitmap) 5363 if (mddev->bitmap)
5360 return -EEXIST; 5364 return -EEXIST;
5361 if (mddev->default_bitmap_offset == 0) 5365 if (mddev->bitmap_info.default_offset == 0)
5362 return -EINVAL; 5366 return -EINVAL;
5363 mddev->bitmap_offset = mddev->default_bitmap_offset; 5367 mddev->bitmap_info.offset =
5368 mddev->bitmap_info.default_offset;
5364 mddev->pers->quiesce(mddev, 1); 5369 mddev->pers->quiesce(mddev, 1);
5365 rv = bitmap_create(mddev); 5370 rv = bitmap_create(mddev);
5366 if (rv) 5371 if (rv)
@@ -5375,7 +5380,7 @@ static int update_array_info(mddev_t *mddev, mdu_array_info_t *info)
5375 mddev->pers->quiesce(mddev, 1); 5380 mddev->pers->quiesce(mddev, 1);
5376 bitmap_destroy(mddev); 5381 bitmap_destroy(mddev);
5377 mddev->pers->quiesce(mddev, 0); 5382 mddev->pers->quiesce(mddev, 0);
5378 mddev->bitmap_offset = 0; 5383 mddev->bitmap_info.offset = 0;
5379 } 5384 }
5380 } 5385 }
5381 md_update_sb(mddev, 1); 5386 md_update_sb(mddev, 1);
diff --git a/drivers/md/md.h b/drivers/md/md.h
index cb036868a9e9..50e62ef32e9d 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -280,16 +280,18 @@ struct mddev_s
280 unsigned int max_write_behind; /* 0 = sync */ 280 unsigned int max_write_behind; /* 0 = sync */
281 281
282 struct bitmap *bitmap; /* the bitmap for the device */ 282 struct bitmap *bitmap; /* the bitmap for the device */
283 struct file *bitmap_file; /* the bitmap file */ 283 struct {
284 long bitmap_offset; /* offset from superblock of 284 struct file *file; /* the bitmap file */
285 * start of bitmap. May be 285 long offset; /* offset from superblock of
286 * negative, but not '0' 286 * start of bitmap. May be
287 */ 287 * negative, but not '0'
288 long default_bitmap_offset; /* this is the offset to use when 288 */
289 * hot-adding a bitmap. It should 289 long default_offset; /* this is the offset to use when
290 * eventually be settable by sysfs. 290 * hot-adding a bitmap. It should
291 */ 291 * eventually be settable by sysfs.
292 struct mutex bitmap_mutex; 292 */
293 struct mutex mutex;
294 } bitmap_info;
293 295
294 struct list_head all_mddevs; 296 struct list_head all_mddevs;
295 297