diff options
author | Omar Sandoval <osandov@fb.com> | 2018-03-27 00:39:11 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2018-03-27 16:21:11 -0400 |
commit | 2d1d4c1e591fd40bd7dafd868a249d7d00e215d5 (patch) | |
tree | 4d4c72ede037788ddc62d5dab7227bb6f4a3b24b /drivers/block/loop.c | |
parent | bc56e2cafa3f80954a278d74bd18349ac3cb8fa5 (diff) |
loop: don't call into filesystem while holding lo_ctl_mutex
We hit an issue where a loop device on NFS was stuck in
loop_get_status() doing vfs_getattr() after the NFS server died, which
caused a pile-up of uninterruptible processes waiting on lo_ctl_mutex.
There's no reason to hold this lock while we wait on the filesystem;
let's drop it so that other processes can do their thing. We need to
grab a reference on lo_backing_file while we use it, and we can get rid
of the check on lo_device, which has been unnecessary since commit
a34c0ae9ebd6 ("[PATCH] loop: remove the bio remapping capability") in
the linux-history tree.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'drivers/block/loop.c')
-rw-r--r-- | drivers/block/loop.c | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 7952ed5c607b..c633b68b69ff 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c | |||
@@ -1167,21 +1167,17 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info) | |||
1167 | static int | 1167 | static int |
1168 | loop_get_status(struct loop_device *lo, struct loop_info64 *info) | 1168 | loop_get_status(struct loop_device *lo, struct loop_info64 *info) |
1169 | { | 1169 | { |
1170 | struct file *file = lo->lo_backing_file; | 1170 | struct file *file; |
1171 | struct kstat stat; | 1171 | struct kstat stat; |
1172 | int error; | 1172 | int ret; |
1173 | 1173 | ||
1174 | if (lo->lo_state != Lo_bound) | 1174 | if (lo->lo_state != Lo_bound) { |
1175 | mutex_unlock(&lo->lo_ctl_mutex); | ||
1175 | return -ENXIO; | 1176 | return -ENXIO; |
1176 | error = vfs_getattr(&file->f_path, &stat, | 1177 | } |
1177 | STATX_INO, AT_STATX_SYNC_AS_STAT); | 1178 | |
1178 | if (error) | ||
1179 | return error; | ||
1180 | memset(info, 0, sizeof(*info)); | 1179 | memset(info, 0, sizeof(*info)); |
1181 | info->lo_number = lo->lo_number; | 1180 | info->lo_number = lo->lo_number; |
1182 | info->lo_device = huge_encode_dev(stat.dev); | ||
1183 | info->lo_inode = stat.ino; | ||
1184 | info->lo_rdevice = huge_encode_dev(lo->lo_device ? stat.rdev : stat.dev); | ||
1185 | info->lo_offset = lo->lo_offset; | 1181 | info->lo_offset = lo->lo_offset; |
1186 | info->lo_sizelimit = lo->lo_sizelimit; | 1182 | info->lo_sizelimit = lo->lo_sizelimit; |
1187 | info->lo_flags = lo->lo_flags; | 1183 | info->lo_flags = lo->lo_flags; |
@@ -1194,7 +1190,19 @@ loop_get_status(struct loop_device *lo, struct loop_info64 *info) | |||
1194 | memcpy(info->lo_encrypt_key, lo->lo_encrypt_key, | 1190 | memcpy(info->lo_encrypt_key, lo->lo_encrypt_key, |
1195 | lo->lo_encrypt_key_size); | 1191 | lo->lo_encrypt_key_size); |
1196 | } | 1192 | } |
1197 | return 0; | 1193 | |
1194 | /* Drop lo_ctl_mutex while we call into the filesystem. */ | ||
1195 | file = get_file(lo->lo_backing_file); | ||
1196 | mutex_unlock(&lo->lo_ctl_mutex); | ||
1197 | ret = vfs_getattr(&file->f_path, &stat, STATX_INO, | ||
1198 | AT_STATX_SYNC_AS_STAT); | ||
1199 | if (!ret) { | ||
1200 | info->lo_device = huge_encode_dev(stat.dev); | ||
1201 | info->lo_inode = stat.ino; | ||
1202 | info->lo_rdevice = huge_encode_dev(stat.rdev); | ||
1203 | } | ||
1204 | fput(file); | ||
1205 | return ret; | ||
1198 | } | 1206 | } |
1199 | 1207 | ||
1200 | static void | 1208 | static void |
@@ -1374,7 +1382,8 @@ static int lo_ioctl(struct block_device *bdev, fmode_t mode, | |||
1374 | break; | 1382 | break; |
1375 | case LOOP_GET_STATUS: | 1383 | case LOOP_GET_STATUS: |
1376 | err = loop_get_status_old(lo, (struct loop_info __user *) arg); | 1384 | err = loop_get_status_old(lo, (struct loop_info __user *) arg); |
1377 | break; | 1385 | /* loop_get_status() unlocks lo_ctl_mutex */ |
1386 | goto out_unlocked; | ||
1378 | case LOOP_SET_STATUS64: | 1387 | case LOOP_SET_STATUS64: |
1379 | err = -EPERM; | 1388 | err = -EPERM; |
1380 | if ((mode & FMODE_WRITE) || capable(CAP_SYS_ADMIN)) | 1389 | if ((mode & FMODE_WRITE) || capable(CAP_SYS_ADMIN)) |
@@ -1383,7 +1392,8 @@ static int lo_ioctl(struct block_device *bdev, fmode_t mode, | |||
1383 | break; | 1392 | break; |
1384 | case LOOP_GET_STATUS64: | 1393 | case LOOP_GET_STATUS64: |
1385 | err = loop_get_status64(lo, (struct loop_info64 __user *) arg); | 1394 | err = loop_get_status64(lo, (struct loop_info64 __user *) arg); |
1386 | break; | 1395 | /* loop_get_status() unlocks lo_ctl_mutex */ |
1396 | goto out_unlocked; | ||
1387 | case LOOP_SET_CAPACITY: | 1397 | case LOOP_SET_CAPACITY: |
1388 | err = -EPERM; | 1398 | err = -EPERM; |
1389 | if ((mode & FMODE_WRITE) || capable(CAP_SYS_ADMIN)) | 1399 | if ((mode & FMODE_WRITE) || capable(CAP_SYS_ADMIN)) |
@@ -1544,7 +1554,7 @@ static int lo_compat_ioctl(struct block_device *bdev, fmode_t mode, | |||
1544 | mutex_lock(&lo->lo_ctl_mutex); | 1554 | mutex_lock(&lo->lo_ctl_mutex); |
1545 | err = loop_get_status_compat( | 1555 | err = loop_get_status_compat( |
1546 | lo, (struct compat_loop_info __user *) arg); | 1556 | lo, (struct compat_loop_info __user *) arg); |
1547 | mutex_unlock(&lo->lo_ctl_mutex); | 1557 | /* loop_get_status() unlocks lo_ctl_mutex */ |
1548 | break; | 1558 | break; |
1549 | case LOOP_SET_CAPACITY: | 1559 | case LOOP_SET_CAPACITY: |
1550 | case LOOP_CLR_FD: | 1560 | case LOOP_CLR_FD: |