From: Ming Lei <ming.lei@redhat.com>
To: Jared Holzman <jholzman@nvidia.com>
Cc: "linux-block@vger.kernel.org" <linux-block@vger.kernel.org>
Subject: Re: [PATCH] ublk: Add UBLK_U_CMD_SET_SIZE
Date: Sat, 5 Apr 2025 10:51:09 +0800 [thread overview]
Message-ID: <Z_Cana4Ibs8zN_wA@fedora> (raw)
In-Reply-To: <SJ1PR12MB63639AFCE9BC8C1EC4D28795B1AE2@SJ1PR12MB6363.namprd12.prod.outlook.com>
Hello Jared,
On Thu, Apr 03, 2025 at 12:37:11PM +0000, Jared Holzman wrote:
> Apologies if this is a dup, but I am not seeing the original mail on the mailing list archive.
I guess it is because the patch is sent as html, instead of plain test,
please follow the patch submission guide:
https://www.kernel.org/doc/Documentation/process/submitting-patches.rst
>
> ________________________________
> From: Jared Holzman <jholzman@nvidia.com>
> Sent: Monday, 31 March 2025 4:54 PM
> To: linux-block@vger.kernel.org <linux-block@vger.kernel.org>
> Cc: ming.lei@redhat.com <ming.lei@redhat.com>; Omri Mann <omri@nvidia.com>; Ofer Oshri <ofer@nvidia.com>; Omri Levi <omril@nvidia.com>; Jared Holzman <jholzman@nvidia.com>
> Subject: [PATCH] ublk: Add UBLK_U_CMD_SET_SIZE
>
> From: Omri Mann <omri@nvidia.com>
>
> Currently ublk only allows the size of the ublkb block device to be
> set via UBLK_CMD_SET_PARAMS before UBLK_CMD_START_DEV is triggered.
>
> This does not provide support for extendable user-space block devices
> without having to stop and restart the underlying ublkb block device
> causing IO interruption.
The requirement is reasonable.
>
> This patch adds a new ublk command UBLK_U_CMD_SET_SIZE to allow the
> ublk block device to be resized on-the-fly.
Looks CMD_SET_SIZE is not generic enough, maybe UBLK_CMD_UPDATE_PARAMS
can be added for support any parameter update by allowing to do it
when device is in LIVE state.
>
> Signed-off-by: Omri Mann <omri@nvidia.com>
> ---
> Documentation/block/ublk.rst | 5 +++++
> drivers/block/ublk_drv.c | 26 +++++++++++++++++++++++++-
> include/uapi/linux/ublk_cmd.h | 7 +++++++
> 3 files changed, 37 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/block/ublk.rst b/Documentation/block/ublk.rst
> index 1e0e7358e14a..7eca87a66b9c 100644
> --- a/Documentation/block/ublk.rst
> +++ b/Documentation/block/ublk.rst
> @@ -139,6 +139,11 @@ managing and controlling ublk devices with help of several control commands:
> set up the per-queue context efficiently, such as bind affine CPUs with IO
> pthread and try to allocate buffers in IO thread context.
>
> +- ``UBLK_F_SET_SIZE``
> +
> + Allows changing the size of the block device after it has started. Useful for
> + userspace implementations that allow extending the underlying block device.
> +
> - ``UBLK_CMD_GET_DEV_INFO``
>
> For retrieving device info via ``ublksrv_ctrl_dev_info``. It is the server's
> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> index c060da409ed8..ab6364475b9c 100644
> --- a/drivers/block/ublk_drv.c
> +++ b/drivers/block/ublk_drv.c
> @@ -64,7 +64,8 @@
> | UBLK_F_CMD_IOCTL_ENCODE \
> | UBLK_F_USER_COPY \
> | UBLK_F_ZONED \
> - | UBLK_F_USER_RECOVERY_FAIL_IO)
> + | UBLK_F_USER_RECOVERY_FAIL_IO \
> + | UBLK_F_SET_SIZE)
>
> #define UBLK_F_ALL_RECOVERY_FLAGS (UBLK_F_USER_RECOVERY \
> | UBLK_F_USER_RECOVERY_REISSUE \
> @@ -2917,6 +2918,25 @@ static int ublk_ctrl_get_features(struct io_uring_cmd *cmd)
> return 0;
> }
>
> +static int ublk_ctrl_set_size(struct ublk_device *ub,
> + struct io_uring_cmd *cmd)
> +{
> + const struct ublksrv_ctrl_cmd *header = io_uring_sqe_cmd(cmd->sqe);
> + struct ublk_param_basic *p = &ub->params.basic;
> + size_t new_size = (int)header->data[0];
> + int ret = 0;
> + unsigned int memflags;
> +
> + p->dev_sectors = new_size;
> +
> + memflags = blk_mq_freeze_queue(ub->ub_disk->queue);
> + mutex_lock(&ub->mutex);
> + set_capacity_and_notify(ub->ub_disk, p->dev_sectors);
> + mutex_unlock(&ub->mutex);
> + blk_mq_unfreeze_queue(ub->ub_disk->queue, memflags);
Actually if it is just for updating device size, queue freeze isn't needed,
because bio_check_eod() is called without grabbing ->q_usage_counter, but
for updating other parameters, freezing queue is often needed.
Thanks,
Ming
next parent reply other threads:[~2025-04-05 2:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20250331135449.3371818-1-jholzman@nvidia.com>
[not found] ` <SJ1PR12MB63639AFCE9BC8C1EC4D28795B1AE2@SJ1PR12MB6363.namprd12.prod.outlook.com>
2025-04-05 2:51 ` Ming Lei [this message]
2025-04-06 20:17 ` [PATCH] ublk: Add UBLK_U_CMD_SET_SIZE Jared Holzman
2025-04-07 3:14 ` Ming Lei
2025-04-07 3:32 ` Ming Lei
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=Z_Cana4Ibs8zN_wA@fedora \
--to=ming.lei@redhat.com \
--cc=jholzman@nvidia.com \
--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;
as well as URLs for NNTP newsgroup(s).