提交 9218b108 编写于 作者: J Jan Kara 提交者: Greg Kroah-Hartman

loop: Push loop_ctl_mutex down to loop_set_fd()

commit 757ecf40b7e029529768eb5f9562d5eeb3002106 upstream.

Push lo_ctl_mutex down to loop_set_fd(). We will need this to be able to
call loop_reread_partitions() without lo_ctl_mutex.
Signed-off-by: NJan Kara <jack@suse.cz>
Signed-off-by: NJens Axboe <axboe@kernel.dk>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 90386ad7
...@@ -919,13 +919,17 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, ...@@ -919,13 +919,17 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
if (!file) if (!file)
goto out; goto out;
error = mutex_lock_killable_nested(&loop_ctl_mutex, 1);
if (error)
goto out_putf;
error = -EBUSY; error = -EBUSY;
if (lo->lo_state != Lo_unbound) if (lo->lo_state != Lo_unbound)
goto out_putf; goto out_unlock;
error = loop_validate_file(file, bdev); error = loop_validate_file(file, bdev);
if (error) if (error)
goto out_putf; goto out_unlock;
mapping = file->f_mapping; mapping = file->f_mapping;
inode = mapping->host; inode = mapping->host;
...@@ -937,10 +941,10 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, ...@@ -937,10 +941,10 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
error = -EFBIG; error = -EFBIG;
size = get_loop_size(lo, file); size = get_loop_size(lo, file);
if ((loff_t)(sector_t)size != size) if ((loff_t)(sector_t)size != size)
goto out_putf; goto out_unlock;
error = loop_prepare_queue(lo); error = loop_prepare_queue(lo);
if (error) if (error)
goto out_putf; goto out_unlock;
error = 0; error = 0;
...@@ -979,11 +983,14 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, ...@@ -979,11 +983,14 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
* put /dev/loopXX inode. Later in __loop_clr_fd() we bdput(bdev). * put /dev/loopXX inode. Later in __loop_clr_fd() we bdput(bdev).
*/ */
bdgrab(bdev); bdgrab(bdev);
mutex_unlock(&loop_ctl_mutex);
return 0; return 0;
out_putf: out_unlock:
mutex_unlock(&loop_ctl_mutex);
out_putf:
fput(file); fput(file);
out: out:
/* This is safe: open() is still holding a reference. */ /* This is safe: open() is still holding a reference. */
module_put(THIS_MODULE); module_put(THIS_MODULE);
return error; return error;
...@@ -1461,12 +1468,7 @@ static int lo_ioctl(struct block_device *bdev, fmode_t mode, ...@@ -1461,12 +1468,7 @@ static int lo_ioctl(struct block_device *bdev, fmode_t mode,
switch (cmd) { switch (cmd) {
case LOOP_SET_FD: case LOOP_SET_FD:
err = mutex_lock_killable_nested(&loop_ctl_mutex, 1); return loop_set_fd(lo, mode, bdev, arg);
if (err)
return err;
err = loop_set_fd(lo, mode, bdev, arg);
mutex_unlock(&loop_ctl_mutex);
break;
case LOOP_CHANGE_FD: case LOOP_CHANGE_FD:
err = mutex_lock_killable_nested(&loop_ctl_mutex, 1); err = mutex_lock_killable_nested(&loop_ctl_mutex, 1);
if (err) if (err)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册