Skip to content

Commit d57f337

Browse files
jankaraaxboe
authored andcommitted
loop: Move special partition reread handling in loop_clr_fd()
The call of __blkdev_reread_part() from loop_reread_partition() happens only when we need to invalidate partitions from loop_release(). Thus move a detection for this into loop_clr_fd() and simplify loop_reread_partition(). This makes loop_reread_partition() safe to use without loop_ctl_mutex because we use only lo->lo_number and lo->lo_file_name in case of error for reporting purposes (thus possibly reporting outdate information is not a big deal) and we are safe from 'lo' going away under us by elevated lo->lo_refcnt. Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent c371077 commit d57f337

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

drivers/block/loop.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -630,18 +630,7 @@ static void loop_reread_partitions(struct loop_device *lo,
630630
{
631631
int rc;
632632

633-
/*
634-
* bd_mutex has been held already in release path, so don't
635-
* acquire it if this function is called in such case.
636-
*
637-
* If the reread partition isn't from release path, lo_refcnt
638-
* must be at least one and it can only become zero when the
639-
* current holder is released.
640-
*/
641-
if (!atomic_read(&lo->lo_refcnt))
642-
rc = __blkdev_reread_part(bdev);
643-
else
644-
rc = blkdev_reread_part(bdev);
633+
rc = blkdev_reread_part(bdev);
645634
if (rc)
646635
pr_warn("%s: partition scan of loop%d (%s) failed (rc=%d)\n",
647636
__func__, lo->lo_number, lo->lo_file_name, rc);
@@ -1095,8 +1084,24 @@ static int __loop_clr_fd(struct loop_device *lo)
10951084
module_put(THIS_MODULE);
10961085
blk_mq_unfreeze_queue(lo->lo_queue);
10971086

1098-
if (lo->lo_flags & LO_FLAGS_PARTSCAN && bdev)
1099-
loop_reread_partitions(lo, bdev);
1087+
if (lo->lo_flags & LO_FLAGS_PARTSCAN && bdev) {
1088+
/*
1089+
* bd_mutex has been held already in release path, so don't
1090+
* acquire it if this function is called in such case.
1091+
*
1092+
* If the reread partition isn't from release path, lo_refcnt
1093+
* must be at least one and it can only become zero when the
1094+
* current holder is released.
1095+
*/
1096+
if (!atomic_read(&lo->lo_refcnt))
1097+
err = __blkdev_reread_part(bdev);
1098+
else
1099+
err = blkdev_reread_part(bdev);
1100+
pr_warn("%s: partition scan of loop%d failed (rc=%d)\n",
1101+
__func__, lo->lo_number, err);
1102+
/* Device is gone, no point in returning error */
1103+
err = 0;
1104+
}
11001105
lo->lo_flags = 0;
11011106
if (!part_shift)
11021107
lo->lo_disk->flags |= GENHD_FL_NO_PART_SCAN;

0 commit comments

Comments
 (0)