From: Haris Iqbal <haris.iqbal@linux.dev>
To: Bart Van Assche <bvanassche@acm.org>, Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org,
Christoph Hellwig <hch@infradead.org>,
Marco Elver <elver@google.com>
Subject: Re: [PATCH 16/27] loop: Split loop_configure()
Date: Fri, 12 Jun 2026 18:16:01 +0200 [thread overview]
Message-ID: <667e352d-afad-412e-8f2a-ad5f5f8a737b@linux.dev> (raw)
In-Reply-To: <f001b652198021d586af28c4c2c27be4b1824f3d.1781042470.git.bvanassche@acm.org>
On 6/10/26 00:05, Bart Van Assche wrote:
> Prepare for adding a second __loop_configure() call.
>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
> drivers/block/loop.c | 109 ++++++++++++++++++++++---------------------
> 1 file changed, 57 insertions(+), 52 deletions(-)
>
> diff --git a/drivers/block/loop.c b/drivers/block/loop.c
> index 6fbea0af144f..80fdb0dee268 100644
> --- a/drivers/block/loop.c
> +++ b/drivers/block/loop.c
> @@ -981,61 +981,28 @@ static void loop_update_limits(struct loop_device *lo, struct queue_limits *lim,
> lim->discard_granularity = 0;
> }
>
> -static int loop_configure(struct loop_device *lo, blk_mode_t mode,
> - struct block_device *bdev,
> - const struct loop_config *config)
> +static int __loop_configure(struct loop_device *lo, blk_mode_t mode,
> + struct block_device *bdev,
> + const struct loop_config *config, struct file *file,
> + bool *partscan)
> {
I wonder if we can add "__must_hold(&lo->lo_mutex)" to this.
Same for the function __loop_change_fd()
> - struct file *file = fget(config->fd);
> struct queue_limits lim;
> - int error;
> loff_t size;
> - bool partscan;
> - bool is_loop;
> -
> - if (!file)
> - return -EBADF;
> -
> - error = loop_check_backing_file(file);
> - if (error) {
> - fput(file);
> - return error;
> - }
> -
> - is_loop = is_loop_device(file);
> -
> - /* This is safe, since we have a reference from open(). */
> - __module_get(THIS_MODULE);
> -
> - /*
> - * If we don't hold exclusive handle for the device, upgrade to it
> - * here to avoid changing device under exclusive owner.
> - */
> - if (!(mode & BLK_OPEN_EXCL)) {
> - error = bd_prepare_to_claim(bdev, loop_configure, NULL);
> - if (error)
> - goto out_putf;
> - }
> -
> - error = loop_global_lock_killable(lo, is_loop);
> - if (error)
> - goto out_bdev;
> + int error;
>
> - error = -EBUSY;
> if (lo->lo_state != Lo_unbound)
> - goto out_unlock;
> + return -EBUSY;
>
> error = loop_validate_file(file, bdev);
> if (error)
> - goto out_unlock;
> + return error;
>
> - if ((config->info.lo_flags & ~LOOP_CONFIGURE_SETTABLE_FLAGS) != 0) {
> - error = -EINVAL;
> - goto out_unlock;
> - }
> + if ((config->info.lo_flags & ~LOOP_CONFIGURE_SETTABLE_FLAGS) != 0)
> + return -EINVAL;
>
> error = loop_set_status_from_info(lo, &config->info);
> if (error)
> - goto out_unlock;
> + return error;
> lo->lo_flags = config->info.lo_flags;
>
> if (!(file->f_mode & FMODE_WRITE) || !(mode & BLK_OPEN_WRITE) ||
> @@ -1046,10 +1013,8 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
> lo->workqueue = alloc_workqueue("loop%d",
> WQ_UNBOUND | WQ_FREEZABLE,
> 0, lo->lo_number);
> - if (!lo->workqueue) {
> - error = -ENOMEM;
> - goto out_unlock;
> - }
> + if (!lo->workqueue)
> + return -ENOMEM;
> }
>
> /* suppress uevents while reconfiguring the device */
> @@ -1066,7 +1031,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
> /* No need to freeze the queue as the device isn't bound yet. */
> error = queue_limits_commit_update(lo->lo_queue, &lim);
> if (error)
> - goto out_unlock;
> + return error;
>
> /*
> * We might switch to direct I/O mode for the loop device, write back
> @@ -1087,14 +1052,56 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
> WRITE_ONCE(lo->lo_state, Lo_bound);
> if (part_shift)
> lo->lo_flags |= LO_FLAGS_PARTSCAN;
> - partscan = lo->lo_flags & LO_FLAGS_PARTSCAN;
> - if (partscan)
> + *partscan = lo->lo_flags & LO_FLAGS_PARTSCAN;
> + if (*partscan)
> clear_bit(GD_SUPPRESS_PART_SCAN, &lo->lo_disk->state);
>
> dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 0);
> kobject_uevent(&disk_to_dev(lo->lo_disk)->kobj, KOBJ_CHANGE);
>
> + return 0;
> +}
> +
> +static int loop_configure(struct loop_device *lo, blk_mode_t mode,
> + struct block_device *bdev,
> + const struct loop_config *config)
> +{
> + struct file *file = fget(config->fd);
> + int error;
> + bool partscan;
> + bool is_loop;
> +
> + if (!file)
> + return -EBADF;
> +
> + error = loop_check_backing_file(file);
> + if (error) {
> + fput(file);
> + return error;
> + }
> +
> + is_loop = is_loop_device(file);
> +
> + /* This is safe, since we have a reference from open(). */
> + __module_get(THIS_MODULE);
> +
> + /*
> + * If we don't hold exclusive handle for the device, upgrade to it
> + * here to avoid changing device under exclusive owner.
> + */
> + if (!(mode & BLK_OPEN_EXCL)) {
> + error = bd_prepare_to_claim(bdev, loop_configure, NULL);
> + if (error)
> + goto out_putf;
> + }
> +
> + error = loop_global_lock_killable(lo, is_loop);
> + if (error)
> + goto out_bdev;
> + error = __loop_configure(lo, mode, bdev, config, file, &partscan);
> loop_global_unlock(lo, is_loop);
> + if (error)
> + goto out_bdev;
> if (partscan)
> loop_reread_partitions(lo);
>
> @@ -1103,8 +1110,6 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
>
> return 0;
>
> -out_unlock:
> - loop_global_unlock(lo, is_loop);
> out_bdev:
> if (!(mode & BLK_OPEN_EXCL))
> bd_abort_claiming(bdev, loop_configure);
>
next prev parent reply other threads:[~2026-06-12 16:16 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-09 22:04 [PATCH 00/27] Enable lock context analysis in drivers/block/ Bart Van Assche
2026-06-09 22:04 ` [PATCH 01/27] aoe: Enable lock context analysis Bart Van Assche
2026-06-12 14:52 ` Haris Iqbal
2026-06-09 22:04 ` [PATCH 02/27] drbd: Remove "extern" from function declarations Bart Van Assche
2026-06-10 5:17 ` Christoph Hellwig
2026-06-09 22:04 ` [PATCH 03/27] drbd: Retain one _get_ldev_if_state() implementation Bart Van Assche
2026-06-10 5:18 ` Christoph Hellwig
2026-06-09 22:04 ` [PATCH 04/27] drbd: Remove the get_ldev_if_state() macro Bart Van Assche
2026-06-10 5:19 ` Christoph Hellwig
2026-06-09 22:04 ` [PATCH 05/27] drbd: Remove the 'local' lock context Bart Van Assche
2026-06-10 5:19 ` Christoph Hellwig
2026-06-09 22:04 ` [PATCH 06/27] drbd: Simplify the bitmap locking functions Bart Van Assche
2026-06-10 5:20 ` Christoph Hellwig
2026-06-09 22:04 ` [PATCH 07/27] drbd: Move two declarations Bart Van Assche
2026-06-10 5:20 ` Christoph Hellwig
2026-06-09 22:04 ` [PATCH 08/27] drbd: Pass 'resource' directly to complete_conflicting_writes() Bart Van Assche
2026-06-10 5:21 ` Christoph Hellwig
2026-06-09 22:04 ` [PATCH 09/27] drbd: Split drbd_nl_get_connections_dumpit() Bart Van Assche
2026-06-10 5:22 ` Christoph Hellwig
2026-06-10 16:48 ` Bart Van Assche
2026-06-09 22:04 ` [PATCH 10/27] drbd: Make a mutex_unlock() call unconditional Bart Van Assche
2026-06-10 5:22 ` Christoph Hellwig
2026-06-09 22:04 ` [PATCH 11/27] drbd: Split drbd_req_state() Bart Van Assche
2026-06-10 5:24 ` Christoph Hellwig
2026-06-10 17:05 ` Bart Van Assche
2026-06-10 17:07 ` Bart Van Assche
2026-06-09 22:04 ` [PATCH 12/27] drbd: Convert drbd_req_state() to unconditional locking Bart Van Assche
2026-06-10 5:25 ` Christoph Hellwig
2026-06-09 22:05 ` [PATCH 13/27] drbd: Annotate drbd_bm_{lock,unlock}() Bart Van Assche
2026-06-10 5:26 ` Christoph Hellwig
2026-06-09 22:05 ` [PATCH 14/27] drbd: Enable lock context analysis Bart Van Assche
2026-06-09 22:05 ` [PATCH 15/27] loop: Split loop_change_fd() Bart Van Assche
2026-06-10 5:30 ` Christoph Hellwig
2026-06-09 22:05 ` [PATCH 16/27] loop: Split loop_configure() Bart Van Assche
2026-06-12 16:16 ` Haris Iqbal [this message]
2026-06-12 17:12 ` Bart Van Assche
2026-06-09 22:05 ` [PATCH 17/27] loop: Remove the "bool global" function argument Bart Van Assche
2026-06-09 22:05 ` [PATCH 18/27] loop: Add lock context annotations Bart Van Assche
2026-06-10 9:21 ` Nilay Shroff
2026-06-10 17:13 ` Bart Van Assche
2026-06-11 5:00 ` Nilay Shroff
2026-06-09 22:05 ` [PATCH 19/27] mtip32: Enable lock context analysis Bart Van Assche
2026-06-09 22:05 ` [PATCH 20/27] nbd: " Bart Van Assche
2026-06-10 8:02 ` Nilay Shroff
2026-06-10 17:16 ` Bart Van Assche
2026-06-11 5:02 ` Nilay Shroff
2026-06-09 22:05 ` [PATCH 21/27] null_blk: " Bart Van Assche
2026-06-09 23:42 ` Damien Le Moal
2026-06-10 5:31 ` Christoph Hellwig
2026-06-10 18:01 ` Bart Van Assche
2026-06-10 7:28 ` Nilay Shroff
2026-06-09 22:05 ` [PATCH 22/27] rbd: " Bart Van Assche
2026-06-10 5:32 ` Christoph Hellwig
2026-06-09 22:05 ` [PATCH 23/27] ublk: " Bart Van Assche
2026-06-10 2:24 ` Ming Lei
2026-06-09 22:05 ` [PATCH 24/27] xen-blkback: " Bart Van Assche
2026-06-09 22:05 ` [PATCH 25/27] zram: " Bart Van Assche
2026-06-09 22:05 ` [PATCH 26/27] rnbd: " Bart Van Assche
2026-06-09 22:05 ` [PATCH 27/27] block: Enable lock context analysis for all block drivers Bart Van Assche
2026-06-10 5:34 ` [PATCH 00/27] Enable lock context analysis in drivers/block/ Christoph Hellwig
2026-06-10 7:31 ` Marco Elver
2026-06-10 11:30 ` Christoph Hellwig
2026-06-10 17:00 ` Bart Van Assche
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=667e352d-afad-412e-8f2a-ad5f5f8a737b@linux.dev \
--to=haris.iqbal@linux.dev \
--cc=axboe@kernel.dk \
--cc=bvanassche@acm.org \
--cc=elver@google.com \
--cc=hch@infradead.org \
--cc=linux-block@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox