2023-08-03 14:45:09

by Andreas Hindborg

[permalink] [raw]
Subject: [PATCH v10 0/3] ublk: enable zoned storage support

From: Andreas Hindborg <[email protected]>

Hi All,

This patch set adds zoned storage support to `ublk`. The first two patches do
some house cleaning in preparation for the last patch. The last patch adds
support for report_zones and the following operations:

- REQ_OP_ZONE_OPEN
- REQ_OP_ZONE_CLOSE
- REQ_OP_ZONE_FINISH
- REQ_OP_ZONE_RESET
- REQ_OP_ZONE_APPEND

A user space component based on ubdsrv is available for testing [1] with the
"loop" target.

Read/write and zone operations are tested with zenfs [2].

The zone append path is tested with fio -> zonefs -> ublk -> null_blk.

The series is based on v6.5-rc4.

Changes for v10
- Remove IO flag UBLK_IO_FLAG_ZONE_APPEND
- Rename ublk_rq_data.nr_sectors to nr_zones
- Change UAPI by adding field `nr_zones` in union with
`ublksrv_io_desc.nr_sectors` and use zone count instead of sector count when
applicable
- Add documentation suggested Ming to UAPI `UBLK_IO_OP_REPORT_ZONES` and
`ublksrv_io_cmd`
- Updated user space component [1]

[1] https://github.com/metaspace/ubdsrv/tree/2966e5f9637b5856d4a4273ae113e31b1c53ff98
[2] https://github.com/westerndigitalcorporation/zenfs
[3] https://git.kernel.dk/linux.git

Andreas Hindborg (3):
ublk: add helper to check if device supports user copy
ublk: move check for empty address field on command submission
ublk: enable zoned storage support

drivers/block/ublk_drv.c | 353 ++++++++++++++++++++++++++++++++--
include/uapi/linux/ublk_cmd.h | 63 +++++-
2 files changed, 388 insertions(+), 28 deletions(-)


base-commit: 5d0c230f1de8c7515b6567d9afba1f196fb4e2f4
--
2.41.0



2023-08-03 14:53:26

by Andreas Hindborg

[permalink] [raw]
Subject: [PATCH v10 1/3] ublk: add helper to check if device supports user copy

From: Andreas Hindborg <[email protected]>

This will be used by ublk zoned storage support.

Signed-off-by: Andreas Hindborg <[email protected]>
Reviewed-by: Ming Lei <[email protected]>
Reviewed-by: Damien Le Moal <[email protected]>
---
drivers/block/ublk_drv.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 21d2e71c5514..db3523e281a6 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -185,6 +185,11 @@ struct ublk_params_header {
__u32 types;
};

+static inline bool ublk_dev_is_user_copy(const struct ublk_device *ub)
+{
+ return ub->dev_info.flags & UBLK_F_USER_COPY;
+}
+
static inline void __ublk_complete_rq(struct request *req);
static void ublk_complete_rq(struct kref *ref);

@@ -2038,7 +2043,7 @@ static int ublk_ctrl_add_dev(struct io_uring_cmd *cmd)
UBLK_F_URING_CMD_COMP_IN_TASK;

/* GET_DATA isn't needed any more with USER_COPY */
- if (ub->dev_info.flags & UBLK_F_USER_COPY)
+ if (ublk_dev_is_user_copy(ub))
ub->dev_info.flags &= ~UBLK_F_NEED_GET_DATA;

/* We are not ready to support zero copy */
--
2.41.0


2023-08-03 16:28:03

by Andreas Hindborg

[permalink] [raw]
Subject: [PATCH v10 2/3] ublk: move check for empty address field on command submission

From: Andreas Hindborg <[email protected]>

In preparation for zoned storage support, move the check for empty `addr`
field into the command handler case statement. Note that the check makes no
sense for `UBLK_IO_NEED_GET_DATA` because the `addr` field must always be
set for this command.

Signed-off-by: Andreas Hindborg <[email protected]>
---
drivers/block/ublk_drv.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index db3523e281a6..5a1ee17636ac 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -1419,11 +1419,6 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
^ (_IOC_NR(cmd_op) == UBLK_IO_NEED_GET_DATA))
goto out;

- if (ublk_support_user_copy(ubq) && ub_cmd->addr) {
- ret = -EINVAL;
- goto out;
- }
-
ret = ublk_check_cmd_op(cmd_op);
if (ret)
goto out;
@@ -1452,6 +1447,12 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
goto out;
}

+ /* User copy requires addr to be unset */
+ if (ublk_support_user_copy(ubq) && ub_cmd->addr) {
+ ret = -EINVAL;
+ goto out;
+ }
+
ublk_fill_io_cmd(io, cmd, ub_cmd->addr);
ublk_mark_io_ready(ub, ubq);
break;
@@ -1470,6 +1471,13 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
req_op(req) == REQ_OP_READ))
goto out;
}
+
+ /* User copy requires addr to be unset */
+ if (ublk_support_user_copy(ubq) && ub_cmd->addr) {
+ ret = -EINVAL;
+ goto out;
+ }
+
ublk_fill_io_cmd(io, cmd, ub_cmd->addr);
ublk_commit_completion(ub, ub_cmd);
break;
--
2.41.0


2023-08-04 11:11:59

by Ming Lei

[permalink] [raw]
Subject: Re: [PATCH v10 2/3] ublk: move check for empty address field on command submission

Hi Andreas,

On Thu, Aug 03, 2023 at 04:07:00PM +0200, Andreas Hindborg (Samsung) wrote:
> From: Andreas Hindborg <[email protected]>
>
> In preparation for zoned storage support, move the check for empty `addr`
> field into the command handler case statement. Note that the check makes no
> sense for `UBLK_IO_NEED_GET_DATA` because the `addr` field must always be
> set for this command.
>
> Signed-off-by: Andreas Hindborg <[email protected]>
> ---
> drivers/block/ublk_drv.c | 18 +++++++++++++-----
> 1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> index db3523e281a6..5a1ee17636ac 100644
> --- a/drivers/block/ublk_drv.c
> +++ b/drivers/block/ublk_drv.c
> @@ -1419,11 +1419,6 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
> ^ (_IOC_NR(cmd_op) == UBLK_IO_NEED_GET_DATA))
> goto out;
>
> - if (ublk_support_user_copy(ubq) && ub_cmd->addr) {
> - ret = -EINVAL;
> - goto out;
> - }
> -
> ret = ublk_check_cmd_op(cmd_op);
> if (ret)
> goto out;
> @@ -1452,6 +1447,12 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
> goto out;
> }
>
> + /* User copy requires addr to be unset */
> + if (ublk_support_user_copy(ubq) && ub_cmd->addr) {
> + ret = -EINVAL;
> + goto out;
> + }
> +

Given you have to post v11 for fixing build issue, please convert the
above two 'if' into one 'if else':

if (!ublk_support_user_copy(ubq)) {
/*
* FETCH_RQ has to provide IO buffer if NEED GET
* DATA is not enabled
*/
if (!ub_cmd->addr && !ublk_need_get_data(ubq))
goto out;
} else {
if (ub_cmd->addr) {
ret = -EINVAL;
goto out;
}
}

> ublk_fill_io_cmd(io, cmd, ub_cmd->addr);
> ublk_mark_io_ready(ub, ubq);
> break;
> @@ -1470,6 +1471,13 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
> req_op(req) == REQ_OP_READ))
> goto out;
> }
> +
> + /* User copy requires addr to be unset */
> + if (ublk_support_user_copy(ubq) && ub_cmd->addr) {
> + ret = -EINVAL;
> + goto out;
> + }
> +

Same with above.

BTW, I have verified this patchset with ublk-zoned example in
libublk-rs:

https://github.com/ming1/libublk-rs/tree/zoned.v2

cargo run --example zoned -- add -1 10240
mkfs.btrfs -O zoned /dev/ublkb0
mount & git clone linux-kernel &umount

Hope V11 can be merged.


Thanks,
Ming

2023-08-04 11:13:20

by Andreas Hindborg

[permalink] [raw]
Subject: Re: [PATCH v10 2/3] ublk: move check for empty address field on command submission


Ming Lei <[email protected]> writes:

> Hi Andreas,
>
> On Thu, Aug 03, 2023 at 04:07:00PM +0200, Andreas Hindborg (Samsung) wrote:
>> From: Andreas Hindborg <[email protected]>
>>
>> In preparation for zoned storage support, move the check for empty `addr`
>> field into the command handler case statement. Note that the check makes no
>> sense for `UBLK_IO_NEED_GET_DATA` because the `addr` field must always be
>> set for this command.
>>
>> Signed-off-by: Andreas Hindborg <[email protected]>
>> ---
>> drivers/block/ublk_drv.c | 18 +++++++++++++-----
>> 1 file changed, 13 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
>> index db3523e281a6..5a1ee17636ac 100644
>> --- a/drivers/block/ublk_drv.c
>> +++ b/drivers/block/ublk_drv.c
>> @@ -1419,11 +1419,6 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
>> ^ (_IOC_NR(cmd_op) == UBLK_IO_NEED_GET_DATA))
>> goto out;
>>
>> - if (ublk_support_user_copy(ubq) && ub_cmd->addr) {
>> - ret = -EINVAL;
>> - goto out;
>> - }
>> -
>> ret = ublk_check_cmd_op(cmd_op);
>> if (ret)
>> goto out;
>> @@ -1452,6 +1447,12 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
>> goto out;
>> }
>>
>> + /* User copy requires addr to be unset */
>> + if (ublk_support_user_copy(ubq) && ub_cmd->addr) {
>> + ret = -EINVAL;
>> + goto out;
>> + }
>> +
>
> Given you have to post v11 for fixing build issue, please convert the
> above two 'if' into one 'if else':
>
> if (!ublk_support_user_copy(ubq)) {
> /*
> * FETCH_RQ has to provide IO buffer if NEED GET
> * DATA is not enabled
> */
> if (!ub_cmd->addr && !ublk_need_get_data(ubq))
> goto out;
> } else {
> if (ub_cmd->addr) {
> ret = -EINVAL;
> goto out;
> }
> }

Alright. I was debating with myself one over the other ????

>
>> ublk_fill_io_cmd(io, cmd, ub_cmd->addr);
>> ublk_mark_io_ready(ub, ubq);
>> break;
>> @@ -1470,6 +1471,13 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
>> req_op(req) == REQ_OP_READ))
>> goto out;
>> }
>> +
>> + /* User copy requires addr to be unset */
>> + if (ublk_support_user_copy(ubq) && ub_cmd->addr) {
>> + ret = -EINVAL;
>> + goto out;
>> + }
>> +
>
> Same with above.
>
> BTW, I have verified this patchset with ublk-zoned example in
> libublk-rs:
>
> https://github.com/ming1/libublk-rs/tree/zoned.v2
>
> cargo run --example zoned -- add -1 10240
> mkfs.btrfs -O zoned /dev/ublkb0
> mount & git clone linux-kernel &umount

Thanks!

BR Andreas