Commit 4af1a041 authored by NeilBrown's avatar NeilBrown

md: move GET_BITMAP_FILE ioctl out from mddev_lock.

It makes more sense to report bitmap_info->file, rather than
bitmap->file (the later is only available once the array is
active).

With that change, use mddev->lock to protect bitmap_info being
set to NULL, and we can call get_bitmap_file() without taking
the mutex.
Signed-off-by: default avatarNeilBrown <neilb@suse.de>
parent 1e594bb2
...@@ -5292,8 +5292,11 @@ static int do_md_stop(struct mddev *mddev, int mode, ...@@ -5292,8 +5292,11 @@ static int do_md_stop(struct mddev *mddev, int mode,
bitmap_destroy(mddev); bitmap_destroy(mddev);
if (mddev->bitmap_info.file) { if (mddev->bitmap_info.file) {
fput(mddev->bitmap_info.file); struct file *f = mddev->bitmap_info.file;
spin_lock(&mddev->lock);
mddev->bitmap_info.file = NULL; mddev->bitmap_info.file = NULL;
spin_unlock(&mddev->lock);
fput(f);
} }
mddev->bitmap_info.offset = 0; mddev->bitmap_info.offset = 0;
...@@ -5503,32 +5506,30 @@ static int get_bitmap_file(struct mddev *mddev, void __user * arg) ...@@ -5503,32 +5506,30 @@ static int get_bitmap_file(struct mddev *mddev, void __user * arg)
{ {
mdu_bitmap_file_t *file = NULL; /* too big for stack allocation */ mdu_bitmap_file_t *file = NULL; /* too big for stack allocation */
char *ptr; char *ptr;
int err = -ENOMEM; int err;
file = kmalloc(sizeof(*file), GFP_NOIO); file = kmalloc(sizeof(*file), GFP_NOIO);
if (!file) if (!file)
goto out; return -ENOMEM;
err = 0;
spin_lock(&mddev->lock);
/* bitmap disabled, zero the first byte and copy out */ /* bitmap disabled, zero the first byte and copy out */
if (!mddev->bitmap || !mddev->bitmap->storage.file) { if (!mddev->bitmap_info.file)
file->pathname[0] = '\0'; file->pathname[0] = '\0';
goto copy_out; else if ((ptr = d_path(&mddev->bitmap_info.file->f_path,
} file->pathname, sizeof(file->pathname))),
IS_ERR(ptr))
ptr = d_path(&mddev->bitmap->storage.file->f_path, err = PTR_ERR(ptr);
file->pathname, sizeof(file->pathname)); else
if (IS_ERR(ptr)) memmove(file->pathname, ptr,
goto out; sizeof(file->pathname)-(ptr-file->pathname));
spin_unlock(&mddev->lock);
memmove(file->pathname, ptr,
sizeof(file->pathname)-(ptr-file->pathname));
copy_out: if (err == 0 &&
err = 0; copy_to_user(arg, file, sizeof(*file)))
if (copy_to_user(arg, file, sizeof(*file)))
err = -EFAULT; err = -EFAULT;
out:
kfree(file); kfree(file);
return err; return err;
} }
...@@ -5900,9 +5901,13 @@ static int set_bitmap_file(struct mddev *mddev, int fd) ...@@ -5900,9 +5901,13 @@ static int set_bitmap_file(struct mddev *mddev, int fd)
mddev->pers->quiesce(mddev, 0); mddev->pers->quiesce(mddev, 0);
} }
if (fd < 0) { if (fd < 0) {
if (mddev->bitmap_info.file) struct file *f = mddev->bitmap_info.file;
fput(mddev->bitmap_info.file); if (f) {
mddev->bitmap_info.file = NULL; spin_lock(&mddev->lock);
mddev->bitmap_info.file = NULL;
spin_unlock(&mddev->lock);
fput(f);
}
} }
return err; return err;
...@@ -6315,6 +6320,11 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode, ...@@ -6315,6 +6320,11 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
case SET_DISK_FAULTY: case SET_DISK_FAULTY:
err = set_disk_faulty(mddev, new_decode_dev(arg)); err = set_disk_faulty(mddev, new_decode_dev(arg));
goto out; goto out;
case GET_BITMAP_FILE:
err = get_bitmap_file(mddev, argp);
goto out;
} }
if (cmd == ADD_NEW_DISK) if (cmd == ADD_NEW_DISK)
...@@ -6406,10 +6416,6 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode, ...@@ -6406,10 +6416,6 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
* Commands even a read-only array can execute: * Commands even a read-only array can execute:
*/ */
switch (cmd) { switch (cmd) {
case GET_BITMAP_FILE:
err = get_bitmap_file(mddev, argp);
goto unlock;
case RESTART_ARRAY_RW: case RESTART_ARRAY_RW:
err = restart_array(mddev); err = restart_array(mddev);
goto unlock; goto unlock;
......
...@@ -393,6 +393,7 @@ struct mddev { ...@@ -393,6 +393,7 @@ struct mddev {
* in_sync - and related safemode and MD_CHANGE changes * in_sync - and related safemode and MD_CHANGE changes
* pers (also protected by reconfig_mutex and pending IO). * pers (also protected by reconfig_mutex and pending IO).
* clearing ->bitmap * clearing ->bitmap
* clearing ->bitmap_info.file
*/ */
spinlock_t lock; spinlock_t lock;
wait_queue_head_t sb_wait; /* for waiting on superblock updates */ wait_queue_head_t sb_wait; /* for waiting on superblock updates */
......
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