Skip to contentSkip to conversation

ublk: zoned: support REQ_OP_ZONE_RESET_ALL

PATCH Applied Ming Lei 3 participants 9 messages Aug 10, 2023 – Aug 21, 2023

Subsystems (2)
lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH v2 1/1 ublk: zoned: support REQ_OP_ZONE_RESET_ALL

There isn't any reason to not support REQ_OP_ZONE_RESET_ALL given everything is actually handled in userspace, not mention it is pretty easy to support RESET_ALL.

So enable REQ_OP_ZONE_RESET_ALL and let userspace handle it.

Verified by 'tools/zbc_reset_zone -all /dev/ublkb0' in libzbc[1] with libublk-rs based ublk-zoned target prototype[2], follows command line for creating ublk-zoned:

	cargo run --example zoned -- add -1 1024	# add $dev_id $DEV_SIZE

[1] https://github.com/westerndigitalcorporation/libzbc
[2] https://github.com/ming1/libublk-rs/tree/zoned.v2

Cc Niklas Cassel <[email protected]>
Cc Damien Le Moal <[email protected]>
Cc Andreas Hindborg <[email protected]>

---
V2:
- update comment as reported by Niklas

 drivers/block/ublk_drv.c      | 7 +++++--
 include/uapi/linux/ublk_cmd.h | 1 +
 2 files changed, 6 insertions(+), 2 deletions(-)
drivers/block/ublk_drv.c +5 -2
index b60394fe7be6..3650ef209344 100644
@@ -251,6 +251,7 @@ static int ublk_dev_param_zoned_apply(struct ublk_device *ub)
 	const struct ublk_param_zoned *p = &ub->params.zoned;
 
 	disk_set_zoned(ub->ub_disk, BLK_ZONED_HM);
+	blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, ub->ub_disk->queue);
 	blk_queue_required_elevator_features(ub->ub_disk->queue,
 					     ELEVATOR_F_ZBD_SEQ_WRITE);
 	disk_set_max_active_zones(ub->ub_disk, p->max_active_zones);
@@ -393,6 +394,9 @@ static blk_status_t ublk_setup_iod_zoned(struct ublk_queue *ubq,
 	case REQ_OP_ZONE_APPEND:
 		ublk_op = UBLK_IO_OP_ZONE_APPEND;
 		break;
+	case REQ_OP_ZONE_RESET_ALL:
+		ublk_op = UBLK_IO_OP_ZONE_RESET_ALL;
+		break;
 	case REQ_OP_DRV_IN:
 		ublk_op = pdu->operation;
 		switch (ublk_op) {
@@ -404,9 +408,8 @@ static blk_status_t ublk_setup_iod_zoned(struct ublk_queue *ubq,
 		default:
 			return BLK_STS_IOERR;
 		}
-	case REQ_OP_ZONE_RESET_ALL:
 	case REQ_OP_DRV_OUT:
-		/* We do not support reset_all and drv_out */
+		/* We do not support drv_out */
 		return BLK_STS_NOTSUPP;
 	default:
 		return BLK_STS_IOERR;
include/uapi/linux/ublk_cmd.h +1 -0
index 2685e53e4752..b9cfc5c96268 100644
@@ -245,6 +245,7 @@ struct ublksrv_ctrl_dev_info {
 #define		UBLK_IO_OP_ZONE_CLOSE		11
 #define		UBLK_IO_OP_ZONE_FINISH		12
 #define		UBLK_IO_OP_ZONE_APPEND		13
+#define		UBLK_IO_OP_ZONE_RESET_ALL	14
 #define		UBLK_IO_OP_ZONE_RESET		15
 /*
  * Construct a zone report. The report request is carried in `struct
Signature · 1 line
2.40.1
#1 lore raw
Quoted 65 lines · Ming Lei

There isn't any reason to not support REQ_OP_ZONE_RESET_ALL given everything is actually handled in userspace, not mention it is pretty easy to support RESET_ALL.

So enable REQ_OP_ZONE_RESET_ALL and let userspace handle it.

Verified by 'tools/zbc_reset_zone -all /dev/ublkb0' in libzbc[1] with libublk-rs based ublk-zoned target prototype[2], follows command line for creating ublk-zoned:

	cargo run --example zoned -- add -1 1024	# add $dev_id $DEV_SIZE

[1] https://github.com/westerndigitalcorporation/libzbc
[2] https://github.com/ming1/libublk-rs/tree/zoned.v2

Cc Niklas Cassel <[email protected]>
Cc Damien Le Moal <[email protected]>
Cc Andreas Hindborg <[email protected]>

---
V2:
- update comment as reported by Niklas

 drivers/block/ublk_drv.c      | 7 +++++--
 include/uapi/linux/ublk_cmd.h | 1 +
 2 files changed, 6 insertions(+), 2 deletions(-)
drivers/block/ublk_drv.c +5 -2
index b60394fe7be6..3650ef209344 100644
@@ -251,6 +251,7 @@ static int ublk_dev_param_zoned_apply(struct ublk_device *ub)
 	const struct ublk_param_zoned *p = &ub->params.zoned;
 
 	disk_set_zoned(ub->ub_disk, BLK_ZONED_HM);
+	blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, ub->ub_disk->queue);
 	blk_queue_required_elevator_features(ub->ub_disk->queue,
 					     ELEVATOR_F_ZBD_SEQ_WRITE);
 	disk_set_max_active_zones(ub->ub_disk, p->max_active_zones);
@@ -393,6 +394,9 @@ static blk_status_t ublk_setup_iod_zoned(struct ublk_queue *ubq,
 	case REQ_OP_ZONE_APPEND:
 		ublk_op = UBLK_IO_OP_ZONE_APPEND;
 		break;
+	case REQ_OP_ZONE_RESET_ALL:
+		ublk_op = UBLK_IO_OP_ZONE_RESET_ALL;
+		break;
 	case REQ_OP_DRV_IN:
 		ublk_op = pdu->operation;
 		switch (ublk_op) {
@@ -404,9 +408,8 @@ static blk_status_t ublk_setup_iod_zoned(struct ublk_queue *ubq,
 		default:
 			return BLK_STS_IOERR;
 		}
-	case REQ_OP_ZONE_RESET_ALL:
 	case REQ_OP_DRV_OUT:
-		/* We do not support reset_all and drv_out */
+		/* We do not support drv_out */
 		return BLK_STS_NOTSUPP;
 	default:
 		return BLK_STS_IOERR;
include/uapi/linux/ublk_cmd.h +0 -0
index 2685e53e4752..b9cfc5c96268 100644

include/uapi/linux/ublk_cmd.h struct ublksrv_ctrl_dev_info { · line 248

Quoted 4 lines
include/uapi/linux/ublk_cmd.h +1 -0
@@ -245,6 +245,7 @@ struct ublksrv_ctrl_dev_info {
 #define		UBLK_IO_OP_ZONE_CLOSE		11
 #define		UBLK_IO_OP_ZONE_FINISH		12
 #define		UBLK_IO_OP_ZONE_APPEND		13
+#define		UBLK_IO_OP_ZONE_RESET_ALL	14

For some reason, it seems like the UBLK_IO_OP_ZONE_* values are identical to the REQ_OP_ZONE_* values in enum req_op:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/blk_types.h?h=v6.5-rc5#n371

I don't see any obvious advantage of keeping them the same, but if you want to keep this pattern, then perhaps you want to define UBLK_IO_OP_ZONE_RESET_ALL to 17.

Kind regards,
Niklas

author
#2 lore raw
Quoted 65 lines · Niklas Cassel
Quoted 64 lines · Ming Lei

There isn't any reason to not support REQ_OP_ZONE_RESET_ALL given everything is actually handled in userspace, not mention it is pretty easy to support RESET_ALL.

So enable REQ_OP_ZONE_RESET_ALL and let userspace handle it.

Verified by 'tools/zbc_reset_zone -all /dev/ublkb0' in libzbc[1] with libublk-rs based ublk-zoned target prototype[2], follows command line for creating ublk-zoned:

	cargo run --example zoned -- add -1 1024	# add $dev_id $DEV_SIZE

[1] https://github.com/westerndigitalcorporation/libzbc
[2] https://github.com/ming1/libublk-rs/tree/zoned.v2

Cc Niklas Cassel <[email protected]>
Cc Damien Le Moal <[email protected]>
Cc Andreas Hindborg <[email protected]>

---
V2:
- update comment as reported by Niklas

 drivers/block/ublk_drv.c      | 7 +++++--
 include/uapi/linux/ublk_cmd.h | 1 +
 2 files changed, 6 insertions(+), 2 deletions(-)
drivers/block/ublk_drv.c +5 -2
index b60394fe7be6..3650ef209344 100644
@@ -251,6 +251,7 @@ static int ublk_dev_param_zoned_apply(struct ublk_device *ub)
 	const struct ublk_param_zoned *p = &ub->params.zoned;
 
 	disk_set_zoned(ub->ub_disk, BLK_ZONED_HM);
+	blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, ub->ub_disk->queue);
 	blk_queue_required_elevator_features(ub->ub_disk->queue,
 					     ELEVATOR_F_ZBD_SEQ_WRITE);
 	disk_set_max_active_zones(ub->ub_disk, p->max_active_zones);
@@ -393,6 +394,9 @@ static blk_status_t ublk_setup_iod_zoned(struct ublk_queue *ubq,
 	case REQ_OP_ZONE_APPEND:
 		ublk_op = UBLK_IO_OP_ZONE_APPEND;
 		break;
+	case REQ_OP_ZONE_RESET_ALL:
+		ublk_op = UBLK_IO_OP_ZONE_RESET_ALL;
+		break;
 	case REQ_OP_DRV_IN:
 		ublk_op = pdu->operation;
 		switch (ublk_op) {
@@ -404,9 +408,8 @@ static blk_status_t ublk_setup_iod_zoned(struct ublk_queue *ubq,
 		default:
 			return BLK_STS_IOERR;
 		}
-	case REQ_OP_ZONE_RESET_ALL:
 	case REQ_OP_DRV_OUT:
-		/* We do not support reset_all and drv_out */
+		/* We do not support drv_out */
 		return BLK_STS_NOTSUPP;
 	default:
 		return BLK_STS_IOERR;
include/uapi/linux/ublk_cmd.h +0 -0
index 2685e53e4752..b9cfc5c96268 100644
Quoted 8 lines

include/uapi/linux/ublk_cmd.h struct ublksrv_ctrl_dev_info { · line 248

Quoted 5 lines
include/uapi/linux/ublk_cmd.h +1 -0
@@ -245,6 +245,7 @@ struct ublksrv_ctrl_dev_info {
 #define		UBLK_IO_OP_ZONE_CLOSE		11
 #define		UBLK_IO_OP_ZONE_FINISH		12
 #define		UBLK_IO_OP_ZONE_APPEND		13
+#define		UBLK_IO_OP_ZONE_RESET_ALL	14

For some reason, it seems like the UBLK_IO_OP_ZONE_* values are identical to the REQ_OP_ZONE_* values in enum req_op:

Yeah.

I think that is zoned interface abstraction, which should be generic enough to use linux's definition for ublk's UAPI in 1:1.

The same mapping can be found in virtio-blk zoned spec.

Quoted 3 lines

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/blk_types.h?h=v6.5-rc5#n371

I don't see any obvious advantage of keeping them the same,

Not sure I follow your idea, and can you share your exact suggestion?

UBLK_IO_OP_ZONE_* is part of ublk UAPI, but REQ_OP_ZONE_* is just kernel internal definition which may be changed time by time, so we can't use REQ_OP_ZONE_* directly.

Here you can think of UBLK_IO_OP_ZONE_* as interface between driver and hardware, so UBLK_IO_OP_ZONE_* has to be defined independently.

Quoted 2 lines

but if you want to keep this pattern, then perhaps you want to define UBLK_IO_OP_ZONE_RESET_ALL to 17.

Why do you think that 17 is better than 14?

I'd rather use 14 to fill the hole, meantime the two ZONE_RESET OPs can be kept together.

Thanks,
Ming

#3 lore raw
Quoted 2 lines · Ming Lei
Quoted 1 line · Niklas Cassel

On Thu, Aug 10, 2023 at 08:43:26PM +0800, Ming Lei wrote:

(snip)

Quoted 11 lines

UBLK_IO_OP_ZONE_* is part of ublk UAPI, but REQ_OP_ZONE_* is just kernel internal definition which may be changed time by time, so we can't use REQ_OP_ZONE_* directly.

Here you can think of UBLK_IO_OP_ZONE_* as interface between driver and hardware, so UBLK_IO_OP_ZONE_* has to be defined independently.

Quoted 2 lines

but if you want to keep this pattern, then perhaps you want to define UBLK_IO_OP_ZONE_RESET_ALL to 17.

Why do you think that 17 is better than 14?

I never said that it was better :)
I even said: "I don't see any obvious advantage of keeping them the same" :)

Just that it would follow the existing pattern of keeping UBLK_IO_OP_ZONE_* in sync with REQ_OP_ZONE_*.

Quoted 3 lines

I'd rather use 14 to fill the hole, meantime the two ZONE_RESET OPs can be kept together.

Ok, but then, considering that UBLK_IO_OP_ZONE_* is not part of any official kernel release, and that the highest UBLK_IO_OP is currently defined as 5:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/ublk_cmd.h?h=v6.5-rc5#n237

why not define:
+#define UBLK_IO_OP_ZONE_OPEN 6
+#define UBLK_IO_OP_ZONE_CLOSE 7
+#define UBLK_IO_OP_ZONE_FINISH 8
+#define UBLK_IO_OP_ZONE_APPEND 9
+#define UBLK_IO_OP_ZONE_RESET 10
+#define UBLK_IO_OP_ZONE_RESET_ALL 11

instead of, like it currently is in linux-block/for-next (this patch included):

+#define UBLK_IO_OP_ZONE_OPEN 10
+#define UBLK_IO_OP_ZONE_CLOSE 11
+#define UBLK_IO_OP_ZONE_FINISH 12
+#define UBLK_IO_OP_ZONE_APPEND 13
+#define UBLK_IO_OP_ZONE_RESET_ALL 14
+#define UBLK_IO_OP_ZONE_RESET 15

Because, even after this patch, you would still have a hole between UBLK_IO_OP_ value 5 and 10.

Kind regards,
Niklas

author
#4 lore raw
Quoted 13 lines · Niklas Cassel
Quoted 2 lines · Ming Lei
Quoted 1 line · Niklas Cassel

On Thu, Aug 10, 2023 at 08:43:26PM +0800, Ming Lei wrote:

(snip)

Quoted 7 lines

UBLK_IO_OP_ZONE_* is part of ublk UAPI, but REQ_OP_ZONE_* is just kernel internal definition which may be changed time by time, so we can't use REQ_OP_ZONE_* directly.

Here you can think of UBLK_IO_OP_ZONE_* as interface between driver and hardware, so UBLK_IO_OP_ZONE_* has to be defined independently.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

but if you want to keep this pattern, then perhaps you want to define UBLK_IO_OP_ZONE_RESET_ALL to 17.

Why do you think that 17 is better than 14?

I never said that it was better :)
I even said: "I don't see any obvious advantage of keeping them the same" :)

OK, maybe I misunderstood your point.

Quoted 3 lines

Just that it would follow the existing pattern of keeping UBLK_IO_OP_ZONE_* in sync with REQ_OP_ZONE_*.

No matter 14 or 17, it does sync with REQ_OP_ZONE_*, even though it isn't necessary to do so.

Then your all comment on this patch should be addressed, right?

Quoted 8 lines
Quoted 5 lines

I'd rather use 14 to fill the hole, meantime the two ZONE_RESET OPs can be kept together.

Ok, but then, considering that UBLK_IO_OP_ZONE_* is not part of any official kernel release, and that the highest UBLK_IO_OP is currently defined as 5:

I don't think it is necessary, see below.

Quoted 19 lines

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/ublk_cmd.h?h=v6.5-rc5#n237

why not define:

(quoted diff) +6 -0
+#define		UBLK_IO_OP_ZONE_OPEN		6
+#define		UBLK_IO_OP_ZONE_CLOSE		7
+#define		UBLK_IO_OP_ZONE_FINISH		8
+#define		UBLK_IO_OP_ZONE_APPEND		9
+#define		UBLK_IO_OP_ZONE_RESET		10
+#define		UBLK_IO_OP_ZONE_RESET_ALL	11

instead of, like it currently is in linux-block/for-next (this patch included):

(quoted diff) +6 -0
+#define		UBLK_IO_OP_ZONE_OPEN		10
+#define		UBLK_IO_OP_ZONE_CLOSE		11
+#define		UBLK_IO_OP_ZONE_FINISH		12
+#define		UBLK_IO_OP_ZONE_APPEND		13
+#define		UBLK_IO_OP_ZONE_RESET_ALL	14
+#define		UBLK_IO_OP_ZONE_RESET		15
Quoted 2 lines

Because, even after this patch, you would still have a hole between UBLK_IO_OP_ value 5 and 10.

(5, 10) can be reserved for some more generic normal IOs, maybe new kind of READ/WRITE, or whatever.

We have 256 OP available, which is big enough for future extend, and OP code can be used from any offset, but still more readable to group them according to their category. And it isn't big deal to use which number for which command, what matters is that we can extend, and keep compatible.

Thanks,
Ming

#5 lore raw
Quoted 10 lines · Ming Lei
Quoted 3 lines · Niklas Cassel
Quoted 2 lines · Ming Lei
Quoted 1 line · Niklas Cassel

On Thu, Aug 10, 2023 at 08:43:26PM +0800, Ming Lei wrote:

We have 256 OP available, which is big enough for future extend, and OP code can be used from any offset, but still more readable to group them according to their category. And it isn't big deal to use which number for which command, what matters is that we can extend, and keep compatible.

I see your point, cheers!

Kind regards,
Niklas

author
#6 lore raw
In reply to Ming Lei
Quoted 15 lines · Ming Lei

There isn't any reason to not support REQ_OP_ZONE_RESET_ALL given everything is actually handled in userspace, not mention it is pretty easy to support RESET_ALL.

So enable REQ_OP_ZONE_RESET_ALL and let userspace handle it.

Verified by 'tools/zbc_reset_zone -all /dev/ublkb0' in libzbc[1] with libublk-rs based ublk-zoned target prototype[2], follows command line for creating ublk-zoned:

	cargo run --example zoned -- add -1 1024	# add $dev_id $DEV_SIZE

[1] https://github.com/westerndigitalcorporation/libzbc
[2] https://github.com/ming1/libublk-rs/tree/zoned.v2

Quoted 7 lines
Cc Niklas Cassel <[email protected]>
Cc Damien Le Moal <[email protected]>
Cc Andreas Hindborg <[email protected]>

---
V2:
- update comment as reported by Niklas

Hello Jens,

Can you merge this one since V2 addresses Niklas's concern.

Thanks,
Ming

author
#7 lore raw
Quoted 24 lines · Ming Lei
Quoted 15 lines · Ming Lei

There isn't any reason to not support REQ_OP_ZONE_RESET_ALL given everything is actually handled in userspace, not mention it is pretty easy to support RESET_ALL.

So enable REQ_OP_ZONE_RESET_ALL and let userspace handle it.

Verified by 'tools/zbc_reset_zone -all /dev/ublkb0' in libzbc[1] with libublk-rs based ublk-zoned target prototype[2], follows command line for creating ublk-zoned:

	cargo run --example zoned -- add -1 1024	# add $dev_id $DEV_SIZE

[1] https://github.com/westerndigitalcorporation/libzbc
[2] https://github.com/ming1/libublk-rs/tree/zoned.v2

Quoted 7 lines
Cc Niklas Cassel <[email protected]>
Cc Damien Le Moal <[email protected]>
Cc Andreas Hindborg <[email protected]>

---
V2:
- update comment as reported by Niklas

Quoted 3 lines

Hello Jens,

Can you merge this one since V2 addresses Niklas's concern.

Ping...

Thanks,
Ming

maintainer Applied
#8 lore raw
In reply to Ming Lei
Quoted 11 lines · Ming Lei

There isn't any reason to not support REQ_OP_ZONE_RESET_ALL given everything is actually handled in userspace, not mention it is pretty easy to support RESET_ALL.

So enable REQ_OP_ZONE_RESET_ALL and let userspace handle it.

Verified by 'tools/zbc_reset_zone -all /dev/ublkb0' in libzbc[1] with libublk-rs based ublk-zoned target prototype[2], follows command line for creating ublk-zoned:

[...]

Applied, thanks!

[1/1] ublk: zoned: support REQ_OP_ZONE_RESET_ALL

      commit: 851e06297f20bbd85c93bbf09469f2150d1db218

Best regards,

Signature · 1 line
Jens Axboe