Commit c3d9714e authored by NeilBrown's avatar NeilBrown

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: default avatarNeilBrown <neilb@suse.de>
parent 709ae487
...@@ -1090,10 +1090,10 @@ void bitmap_daemon_work(mddev_t *mddev) ...@@ -1090,10 +1090,10 @@ void bitmap_daemon_work(mddev_t *mddev)
/* Use a mutex to guard daemon_work against /* Use a mutex to guard daemon_work against
* bitmap_destroy. * bitmap_destroy.
*/ */
mutex_lock(&mddev->bitmap_mutex); mutex_lock(&mddev->bitmap_info.mutex);
bitmap = mddev->bitmap; bitmap = mddev->bitmap;
if (bitmap == NULL) { if (bitmap == NULL) {
mutex_unlock(&mddev->bitmap_mutex); mutex_unlock(&mddev->bitmap_info.mutex);
return; return;
} }
if (time_before(jiffies, bitmap->daemon_lastrun + bitmap->daemon_sleep*HZ)) if (time_before(jiffies, bitmap->daemon_lastrun + bitmap->daemon_sleep*HZ))
...@@ -1211,7 +1211,7 @@ void bitmap_daemon_work(mddev_t *mddev) ...@@ -1211,7 +1211,7 @@ void bitmap_daemon_work(mddev_t *mddev)
done: done:
if (bitmap->allclean == 0) if (bitmap->allclean == 0)
bitmap->mddev->thread->timeout = bitmap->daemon_sleep * HZ; bitmap->mddev->thread->timeout = bitmap->daemon_sleep * HZ;
mutex_unlock(&mddev->bitmap_mutex); mutex_unlock(&mddev->bitmap_info.mutex);
} }
static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap, static bitmap_counter_t *bitmap_get_counter(struct bitmap *bitmap,
...@@ -1591,9 +1591,9 @@ void bitmap_destroy(mddev_t *mddev) ...@@ -1591,9 +1591,9 @@ void bitmap_destroy(mddev_t *mddev)
if (!bitmap) /* there was no bitmap */ if (!bitmap) /* there was no bitmap */
return; return;
mutex_lock(&mddev->bitmap_mutex); mutex_lock(&mddev->bitmap_info.mutex);
mddev->bitmap = NULL; /* disconnect from the md device */ mddev->bitmap = NULL; /* disconnect from the md device */
mutex_unlock(&mddev->bitmap_mutex); mutex_unlock(&mddev->bitmap_info.mutex);
if (mddev->thread) if (mddev->thread)
mddev->thread->timeout = MAX_SCHEDULE_TIMEOUT; mddev->thread->timeout = MAX_SCHEDULE_TIMEOUT;
...@@ -1610,16 +1610,16 @@ int bitmap_create(mddev_t *mddev) ...@@ -1610,16 +1610,16 @@ int bitmap_create(mddev_t *mddev)
sector_t blocks = mddev->resync_max_sectors; sector_t blocks = mddev->resync_max_sectors;
unsigned long chunks; unsigned long chunks;
unsigned long pages; unsigned long pages;
struct file *file = mddev->bitmap_file; struct file *file = mddev->bitmap_info.file;
int err; int err;
sector_t start; sector_t start;
BUILD_BUG_ON(sizeof(bitmap_super_t) != 256); BUILD_BUG_ON(sizeof(bitmap_super_t) != 256);
if (!file && !mddev->bitmap_offset) /* bitmap disabled, nothing to do */ if (!file && !mddev->bitmap_info.offset) /* bitmap disabled, nothing to do */
return 0; return 0;
BUG_ON(file && mddev->bitmap_offset); BUG_ON(file && mddev->bitmap_info.offset);
bitmap = kzalloc(sizeof(*bitmap), GFP_KERNEL); bitmap = kzalloc(sizeof(*bitmap), GFP_KERNEL);
if (!bitmap) if (!bitmap)
...@@ -1633,7 +1633,7 @@ int bitmap_create(mddev_t *mddev) ...@@ -1633,7 +1633,7 @@ int bitmap_create(mddev_t *mddev)
bitmap->mddev = mddev; bitmap->mddev = mddev;
bitmap->file = file; bitmap->file = file;
bitmap->offset = mddev->bitmap_offset; bitmap->offset = mddev->bitmap_info.offset;
if (file) { if (file) {
get_file(file); get_file(file);
/* As future accesses to this file will use bmap, /* As future accesses to this file will use bmap,
......
...@@ -463,7 +463,7 @@ static mddev_t * mddev_find(dev_t unit) ...@@ -463,7 +463,7 @@ static mddev_t * mddev_find(dev_t unit)
mutex_init(&new->open_mutex); mutex_init(&new->open_mutex);
mutex_init(&new->reconfig_mutex); mutex_init(&new->reconfig_mutex);
mutex_init(&new->bitmap_mutex); mutex_init(&new->bitmap_info.mutex);
INIT_LIST_HEAD(&new->disks); INIT_LIST_HEAD(&new->disks);
INIT_LIST_HEAD(&new->all_mddevs); INIT_LIST_HEAD(&new->all_mddevs);
init_timer(&new->safemode_timer); init_timer(&new->safemode_timer);
...@@ -850,7 +850,7 @@ struct super_type { ...@@ -850,7 +850,7 @@ struct super_type {
*/ */
int md_check_no_bitmap(mddev_t *mddev) int md_check_no_bitmap(mddev_t *mddev)
{ {
if (!mddev->bitmap_file && !mddev->bitmap_offset) if (!mddev->bitmap_info.file && !mddev->bitmap_info.offset)
return 0; return 0;
printk(KERN_ERR "%s: bitmaps are not supported for %s\n", printk(KERN_ERR "%s: bitmaps are not supported for %s\n",
mdname(mddev), mddev->pers->name); mdname(mddev), mddev->pers->name);
...@@ -978,8 +978,8 @@ static int super_90_validate(mddev_t *mddev, mdk_rdev_t *rdev) ...@@ -978,8 +978,8 @@ static int super_90_validate(mddev_t *mddev, mdk_rdev_t *rdev)
mddev->raid_disks = sb->raid_disks; mddev->raid_disks = sb->raid_disks;
mddev->dev_sectors = sb->size * 2; mddev->dev_sectors = sb->size * 2;
mddev->events = ev1; mddev->events = ev1;
mddev->bitmap_offset = 0; mddev->bitmap_info.offset = 0;
mddev->default_bitmap_offset = MD_SB_BYTES >> 9; mddev->bitmap_info.default_offset = MD_SB_BYTES >> 9;
if (mddev->minor_version >= 91) { if (mddev->minor_version >= 91) {
mddev->reshape_position = sb->reshape_position; mddev->reshape_position = sb->reshape_position;
...@@ -1013,8 +1013,9 @@ static int super_90_validate(mddev_t *mddev, mdk_rdev_t *rdev) ...@@ -1013,8 +1013,9 @@ static int super_90_validate(mddev_t *mddev, mdk_rdev_t *rdev)
mddev->max_disks = MD_SB_DISKS; mddev->max_disks = MD_SB_DISKS;
if (sb->state & (1<<MD_SB_BITMAP_PRESENT) && if (sb->state & (1<<MD_SB_BITMAP_PRESENT) &&
mddev->bitmap_file == NULL) mddev->bitmap_info.file == NULL)
mddev->bitmap_offset = mddev->default_bitmap_offset; mddev->bitmap_info.offset =
mddev->bitmap_info.default_offset;
} else if (mddev->pers == NULL) { } else if (mddev->pers == NULL) {
/* Insist on good event counter while assembling */ /* Insist on good event counter while assembling */
...@@ -1131,7 +1132,7 @@ static void super_90_sync(mddev_t *mddev, mdk_rdev_t *rdev) ...@@ -1131,7 +1132,7 @@ static void super_90_sync(mddev_t *mddev, mdk_rdev_t *rdev)
sb->layout = mddev->layout; sb->layout = mddev->layout;
sb->chunk_size = mddev->chunk_sectors << 9; sb->chunk_size = mddev->chunk_sectors << 9;
if (mddev->bitmap && mddev->bitmap_file == NULL) if (mddev->bitmap && mddev->bitmap_info.file == NULL)
sb->state |= (1<<MD_SB_BITMAP_PRESENT); sb->state |= (1<<MD_SB_BITMAP_PRESENT);
sb->disks[0].state = (1<<MD_DISK_REMOVED); 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,7 +1210,7 @@ super_90_rdev_size_change(mdk_rdev_t *rdev, sector_t num_sectors)
{ {
if (num_sectors && num_sectors < rdev->mddev->dev_sectors) if (num_sectors && num_sectors < rdev->mddev->dev_sectors)
return 0; /* component must fit device */ return 0; /* component must fit device */
if (rdev->mddev->bitmap_offset) if (rdev->mddev->bitmap_info.offset)
return 0; /* can't move bitmap */ return 0; /* can't move bitmap */
rdev->sb_start = calc_dev_sboffset(rdev->bdev); rdev->sb_start = calc_dev_sboffset(rdev->bdev);
if (!num_sectors || num_sectors > rdev->sb_start) 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,8 +1389,8 @@ static int super_1_validate(mddev_t *mddev, mdk_rdev_t *rdev)
mddev->raid_disks = le32_to_cpu(sb->raid_disks); mddev->raid_disks = le32_to_cpu(sb->raid_disks);
mddev->dev_sectors = le64_to_cpu(sb->size); mddev->dev_sectors = le64_to_cpu(sb->size);
mddev->events = ev1; mddev->events = ev1;
mddev->bitmap_offset = 0; mddev->bitmap_info.offset = 0;
mddev->default_bitmap_offset = 1024 >> 9; mddev->bitmap_info.default_offset = 1024 >> 9;
mddev->recovery_cp = le64_to_cpu(sb->resync_offset); mddev->recovery_cp = le64_to_cpu(sb->resync_offset);
memcpy(mddev->uuid, sb->set_uuid, 16); memcpy(mddev->uuid, sb->set_uuid, 16);
...@@ -1397,8 +1398,9 @@ static int super_1_validate(mddev_t *mddev, mdk_rdev_t *rdev) ...@@ -1397,8 +1398,9 @@ static int super_1_validate(mddev_t *mddev, mdk_rdev_t *rdev)
mddev->max_disks = (4096-256)/2; mddev->max_disks = (4096-256)/2;
if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_BITMAP_OFFSET) && if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_BITMAP_OFFSET) &&
mddev->bitmap_file == NULL ) mddev->bitmap_info.file == NULL )
mddev->bitmap_offset = (__s32)le32_to_cpu(sb->bitmap_offset); mddev->bitmap_info.offset =
(__s32)le32_to_cpu(sb->bitmap_offset);
if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE)) { if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE)) {
mddev->reshape_position = le64_to_cpu(sb->reshape_position); 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,8 +1494,8 @@ static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev)
sb->level = cpu_to_le32(mddev->level); sb->level = cpu_to_le32(mddev->level);
sb->layout = cpu_to_le32(mddev->layout); sb->layout = cpu_to_le32(mddev->layout);
if (mddev->bitmap && mddev->bitmap_file == NULL) { if (mddev->bitmap && mddev->bitmap_info.file == NULL) {
sb->bitmap_offset = cpu_to_le32((__u32)mddev->bitmap_offset); sb->bitmap_offset = cpu_to_le32((__u32)mddev->bitmap_info.offset);
sb->feature_map = cpu_to_le32(MD_FEATURE_BITMAP_OFFSET); sb->feature_map = cpu_to_le32(MD_FEATURE_BITMAP_OFFSET);
} }
...@@ -1560,7 +1562,7 @@ super_1_rdev_size_change(mdk_rdev_t *rdev, sector_t num_sectors) ...@@ -1560,7 +1562,7 @@ super_1_rdev_size_change(mdk_rdev_t *rdev, sector_t num_sectors)
max_sectors -= rdev->data_offset; max_sectors -= rdev->data_offset;
if (!num_sectors || num_sectors > max_sectors) if (!num_sectors || num_sectors > max_sectors)
num_sectors = max_sectors; num_sectors = max_sectors;
} else if (rdev->mddev->bitmap_offset) { } else if (rdev->mddev->bitmap_info.offset) {
/* minor version 0 with bitmap we can't move */ /* minor version 0 with bitmap we can't move */
return 0; return 0;
} else { } else {
...@@ -4507,12 +4509,12 @@ out: ...@@ -4507,12 +4509,12 @@ out:
printk(KERN_INFO "md: %s stopped.\n", mdname(mddev)); printk(KERN_INFO "md: %s stopped.\n", mdname(mddev));
bitmap_destroy(mddev); bitmap_destroy(mddev);
if (mddev->bitmap_file) { if (mddev->bitmap_info.file) {
restore_bitmap_write_access(mddev->bitmap_file); restore_bitmap_write_access(mddev->bitmap_info.file);
fput(mddev->bitmap_file); fput(mddev->bitmap_info.file);
mddev->bitmap_file = NULL; mddev->bitmap_info.file = NULL;
} }
mddev->bitmap_offset = 0; mddev->bitmap_info.offset = 0;
/* make sure all md_delayed_delete calls have finished */ /* make sure all md_delayed_delete calls have finished */
flush_scheduled_work(); flush_scheduled_work();
...@@ -4553,6 +4555,8 @@ out: ...@@ -4553,6 +4555,8 @@ out:
mddev->degraded = 0; mddev->degraded = 0;
mddev->barriers_work = 0; mddev->barriers_work = 0;
mddev->safemode = 0; mddev->safemode = 0;
mddev->bitmap_info.offset = 0;
mddev->bitmap_info.default_offset = 0;
kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE); kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE);
if (mddev->hold_active == UNTIL_STOP) if (mddev->hold_active == UNTIL_STOP)
mddev->hold_active = 0; mddev->hold_active = 0;
...@@ -4738,7 +4742,7 @@ static int get_array_info(mddev_t * mddev, void __user * arg) ...@@ -4738,7 +4742,7 @@ static int get_array_info(mddev_t * mddev, void __user * arg)
info.state = 0; info.state = 0;
if (mddev->in_sync) if (mddev->in_sync)
info.state = (1<<MD_SB_CLEAN); info.state = (1<<MD_SB_CLEAN);
if (mddev->bitmap && mddev->bitmap_offset) if (mddev->bitmap && mddev->bitmap_info.offset)
info.state = (1<<MD_SB_BITMAP_PRESENT); info.state = (1<<MD_SB_BITMAP_PRESENT);
info.active_disks = insync; info.active_disks = insync;
info.working_disks = working; info.working_disks = working;
...@@ -5096,23 +5100,23 @@ static int set_bitmap_file(mddev_t *mddev, int fd) ...@@ -5096,23 +5100,23 @@ static int set_bitmap_file(mddev_t *mddev, int fd)
if (fd >= 0) { if (fd >= 0) {
if (mddev->bitmap) if (mddev->bitmap)
return -EEXIST; /* cannot add when bitmap is present */ return -EEXIST; /* cannot add when bitmap is present */
mddev->bitmap_file = fget(fd); mddev->bitmap_info.file = fget(fd);
if (mddev->bitmap_file == NULL) { if (mddev->bitmap_info.file == NULL) {
printk(KERN_ERR "%s: error: failed to get bitmap file\n", printk(KERN_ERR "%s: error: failed to get bitmap file\n",
mdname(mddev)); mdname(mddev));
return -EBADF; return -EBADF;
} }
err = deny_bitmap_write_access(mddev->bitmap_file); err = deny_bitmap_write_access(mddev->bitmap_info.file);
if (err) { if (err) {
printk(KERN_ERR "%s: error: bitmap file is already in use\n", printk(KERN_ERR "%s: error: bitmap file is already in use\n",
mdname(mddev)); mdname(mddev));
fput(mddev->bitmap_file); fput(mddev->bitmap_info.file);
mddev->bitmap_file = NULL; mddev->bitmap_info.file = NULL;
return err; return err;
} }
mddev->bitmap_offset = 0; /* file overrides offset */ mddev->bitmap_info.offset = 0; /* file overrides offset */
} else if (mddev->bitmap == NULL) } else if (mddev->bitmap == NULL)
return -ENOENT; /* cannot remove what isn't there */ return -ENOENT; /* cannot remove what isn't there */
err = 0; err = 0;
...@@ -5127,11 +5131,11 @@ static int set_bitmap_file(mddev_t *mddev, int fd) ...@@ -5127,11 +5131,11 @@ static int set_bitmap_file(mddev_t *mddev, int fd)
mddev->pers->quiesce(mddev, 0); mddev->pers->quiesce(mddev, 0);
} }
if (fd < 0) { if (fd < 0) {
if (mddev->bitmap_file) { if (mddev->bitmap_info.file) {
restore_bitmap_write_access(mddev->bitmap_file); restore_bitmap_write_access(mddev->bitmap_info.file);
fput(mddev->bitmap_file); fput(mddev->bitmap_info.file);
} }
mddev->bitmap_file = NULL; mddev->bitmap_info.file = NULL;
} }
return err; return err;
...@@ -5198,8 +5202,8 @@ static int set_array_info(mddev_t * mddev, mdu_array_info_t *info) ...@@ -5198,8 +5202,8 @@ static int set_array_info(mddev_t * mddev, mdu_array_info_t *info)
mddev->flags = 0; mddev->flags = 0;
set_bit(MD_CHANGE_DEVS, &mddev->flags); set_bit(MD_CHANGE_DEVS, &mddev->flags);
mddev->default_bitmap_offset = MD_SB_BYTES >> 9; mddev->bitmap_info.default_offset = MD_SB_BYTES >> 9;
mddev->bitmap_offset = 0; mddev->bitmap_info.offset = 0;
mddev->reshape_position = MaxSector; mddev->reshape_position = MaxSector;
...@@ -5299,7 +5303,7 @@ static int update_array_info(mddev_t *mddev, mdu_array_info_t *info) ...@@ -5299,7 +5303,7 @@ static int update_array_info(mddev_t *mddev, mdu_array_info_t *info)
int state = 0; int state = 0;
/* calculate expected state,ignoring low bits */ /* calculate expected state,ignoring low bits */
if (mddev->bitmap && mddev->bitmap_offset) if (mddev->bitmap && mddev->bitmap_info.offset)
state |= (1 << MD_SB_BITMAP_PRESENT); state |= (1 << MD_SB_BITMAP_PRESENT);
if (mddev->major_version != info->major_version || 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,9 +5362,10 @@ static int update_array_info(mddev_t *mddev, mdu_array_info_t *info)
/* add the bitmap */ /* add the bitmap */
if (mddev->bitmap) if (mddev->bitmap)
return -EEXIST; return -EEXIST;
if (mddev->default_bitmap_offset == 0) if (mddev->bitmap_info.default_offset == 0)
return -EINVAL; return -EINVAL;
mddev->bitmap_offset = mddev->default_bitmap_offset; mddev->bitmap_info.offset =
mddev->bitmap_info.default_offset;
mddev->pers->quiesce(mddev, 1); mddev->pers->quiesce(mddev, 1);
rv = bitmap_create(mddev); rv = bitmap_create(mddev);
if (rv) if (rv)
...@@ -5375,7 +5380,7 @@ static int update_array_info(mddev_t *mddev, mdu_array_info_t *info) ...@@ -5375,7 +5380,7 @@ static int update_array_info(mddev_t *mddev, mdu_array_info_t *info)
mddev->pers->quiesce(mddev, 1); mddev->pers->quiesce(mddev, 1);
bitmap_destroy(mddev); bitmap_destroy(mddev);
mddev->pers->quiesce(mddev, 0); mddev->pers->quiesce(mddev, 0);
mddev->bitmap_offset = 0; mddev->bitmap_info.offset = 0;
} }
} }
md_update_sb(mddev, 1); md_update_sb(mddev, 1);
......
...@@ -280,16 +280,18 @@ struct mddev_s ...@@ -280,16 +280,18 @@ struct mddev_s
unsigned int max_write_behind; /* 0 = sync */ unsigned int max_write_behind; /* 0 = sync */
struct bitmap *bitmap; /* the bitmap for the device */ struct bitmap *bitmap; /* the bitmap for the device */
struct file *bitmap_file; /* the bitmap file */ struct {
long bitmap_offset; /* offset from superblock of struct file *file; /* the bitmap file */
* start of bitmap. May be long offset; /* offset from superblock of
* negative, but not '0' * start of bitmap. May be
*/ * negative, but not '0'
long default_bitmap_offset; /* this is the offset to use when */
* hot-adding a bitmap. It should long default_offset; /* this is the offset to use when
* eventually be settable by sysfs. * hot-adding a bitmap. It should
*/ * eventually be settable by sysfs.
struct mutex bitmap_mutex; */
struct mutex mutex;
} bitmap_info;
struct list_head all_mddevs; struct list_head all_mddevs;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment