aboutsummaryrefslogtreecommitdiffstats
path: root/block/ioctl.c
diff options
context:
space:
mode:
authorMing Lei <ming.lei@canonical.com>2015-05-06 00:26:27 -0400
committerJens Axboe <axboe@fb.com>2015-05-20 11:05:45 -0400
commitb04a5636a665f5529fdf69ee7e5512156196f31c (patch)
tree4a75e8a779f2fe0032d67ed15a8a7df9484ce984 /block/ioctl.c
parentbe32417796c2b8a83fe4cbece83bea96ab9e378f (diff)
block: replace trylock with mutex_lock in blkdev_reread_part()
The only possible problem of using mutex_lock() instead of trylock is about deadlock. If there aren't any locks held before calling blkdev_reread_part(), deadlock can't be caused by this conversion. If there are locks held before calling blkdev_reread_part(), and if these locks arn't required in open, close handler and I/O path, deadlock shouldn't be caused too. Both user space's ioctl(BLKRRPART) and md_setup_drive() from init/do_mounts_md.c belongs to the 1st case, so the conversion is safe for the two cases. For loop, the previous patches in this pathset has fixed the ABBA lock dependency, so the conversion is OK. For nbd, tx_lock is held when calling the function: - both open and release won't hold the lock - when blkdev_reread_part() is run, I/O thread has been stopped already, so tx_lock won't be acquired in I/O path at that time. - so the conversion won't cause deadlock for nbd For dasd, both dasd_open(), dasd_release() and request function don't acquire any mutex/semphone, so the conversion should be safe. Reviewed-by: Christoph Hellwig <hch@lst.de> Tested-by: Jarod Wilson <jarod@redhat.com> Acked-by: Jarod Wilson <jarod@redhat.com> Signed-off-by: Ming Lei <ming.lei@canonical.com> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'block/ioctl.c')
-rw-r--r--block/ioctl.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/block/ioctl.c b/block/ioctl.c
index 203cb4aeea8b..8061eba42887 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -174,13 +174,18 @@ EXPORT_SYMBOL(__blkdev_reread_part);
174 * This is an exported API for the block driver, and will 174 * This is an exported API for the block driver, and will
175 * try to acquire bd_mutex. If bd_mutex has been held already 175 * try to acquire bd_mutex. If bd_mutex has been held already
176 * in current context, please call __blkdev_reread_part(). 176 * in current context, please call __blkdev_reread_part().
177 *
178 * Make sure the held locks in current context aren't required
179 * in open()/close() handler and I/O path for avoiding ABBA deadlock:
180 * - bd_mutex is held before calling block driver's open/close
181 * handler
182 * - reading partition table may submit I/O to the block device
177 */ 183 */
178int blkdev_reread_part(struct block_device *bdev) 184int blkdev_reread_part(struct block_device *bdev)
179{ 185{
180 int res; 186 int res;
181 187
182 if (!mutex_trylock(&bdev->bd_mutex)) 188 mutex_lock(&bdev->bd_mutex);
183 return -EBUSY;
184 res = __blkdev_reread_part(bdev); 189 res = __blkdev_reread_part(bdev);
185 mutex_unlock(&bdev->bd_mutex); 190 mutex_unlock(&bdev->bd_mutex);
186 191