History

ublk: add new batch command UBLK_U_IO_PREP_IO_CMDS & UBLK_U_IO_COMMIT_IO_CMDS

Add new command UBLK_U_IO_PREP_IO_CMDS, which is the batch version of UBLK_IO_FETCH_REQ. Add new command UBLK_U_IO_COMMIT_IO_CMDS, which is for committing io command result only, still the batch version. The new command header type is `struct ublk_batch_io`. This patch doesn't actually implement these commands yet, just validates the SQE fields.

Ming Lei committed 10 months ago

Commit e86f89a1 parent 7ba62f52 files · +135 −1Browse files

Unified · Split

2 files
  1. drivers/block/ublk_drv.c +86 −1
  2. include/uapi/linux/ublk_cmd.h +49 −0
drivers/block/ublk_drv.c+86−1
@@ -91,6 +91,11 @@ · 90 unmodified lines
9191 UBLK_PARAM_TYPE_DMA_ALIGN | UBLK_PARAM_TYPE_SEGMENT | \
9292 UBLK_PARAM_TYPE_INTEGRITY)
9393
94+#define UBLK_BATCH_F_ALL \
95+ (UBLK_BATCH_F_HAS_ZONE_LBA | \
96+ UBLK_BATCH_F_HAS_BUF_ADDR | \
97+ UBLK_BATCH_F_AUTO_BUF_REG_FALLBACK)
98+
9499 struct ublk_uring_cmd_pdu {
95100 /*
96101 * Store requests in same batch temporarily for queuing them to
@@ -114,6 +119,13 @@ struct ublk_uring_cmd_pdu { · 17 unmodified lines
114119 u16 tag;
115120 };
116121
122+struct ublk_batch_io_data {
123+ struct ublk_device *ub;
124+ struct io_uring_cmd *cmd;
125+ struct ublk_batch_io header;
126+ unsigned int issue_flags;
127+};
128+
117129 /*
118130 * io command is active: sqe cmd is received, and its cqe isn't done
119131 *
@@ -2687,10 +2699,83 @@ static int ublk_ch_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags) · 2567 unmodified lines
26872699 return ublk_ch_uring_cmd_local(cmd, issue_flags);
26882700 }
26892701
2702+static int ublk_check_batch_cmd_flags(const struct ublk_batch_io *uc)
2703+{
2704+ unsigned elem_bytes = sizeof(struct ublk_elem_header);
2705+
2706+ if (uc->flags & ~UBLK_BATCH_F_ALL)
2707+ return -EINVAL;
2708+
2709+ /* UBLK_BATCH_F_AUTO_BUF_REG_FALLBACK requires buffer index */
2710+ if ((uc->flags & UBLK_BATCH_F_AUTO_BUF_REG_FALLBACK) &&
2711+ (uc->flags & UBLK_BATCH_F_HAS_BUF_ADDR))
2712+ return -EINVAL;
2713+
2714+ elem_bytes += (uc->flags & UBLK_BATCH_F_HAS_ZONE_LBA ? sizeof(u64) : 0) +
2715+ (uc->flags & UBLK_BATCH_F_HAS_BUF_ADDR ? sizeof(u64) : 0);
2716+ if (uc->elem_bytes != elem_bytes)
2717+ return -EINVAL;
2718+ return 0;
2719+}
2720+
2721+static int ublk_check_batch_cmd(const struct ublk_batch_io_data *data)
2722+{
2723+
2724+ const struct ublk_batch_io *uc = &data->header;
2725+
2726+ if (uc->nr_elem > data->ub->dev_info.queue_depth)
2727+ return -E2BIG;
2728+
2729+ if ((uc->flags & UBLK_BATCH_F_HAS_ZONE_LBA) &&
2730+ !ublk_dev_is_zoned(data->ub))
2731+ return -EINVAL;
2732+
2733+ if ((uc->flags & UBLK_BATCH_F_HAS_BUF_ADDR) &&
2734+ !ublk_dev_need_map_io(data->ub))
2735+ return -EINVAL;
2736+
2737+ if ((uc->flags & UBLK_BATCH_F_AUTO_BUF_REG_FALLBACK) &&
2738+ !ublk_dev_support_auto_buf_reg(data->ub))
2739+ return -EINVAL;
2740+
2741+ return ublk_check_batch_cmd_flags(uc);
2742+}
2743+
26902744 static int ublk_ch_batch_io_uring_cmd(struct io_uring_cmd *cmd,
26912745 unsigned int issue_flags)
26922746 {
2693− return -EOPNOTSUPP;
2747+ const struct ublk_batch_io *uc = io_uring_sqe_cmd(cmd->sqe);
2748+ struct ublk_device *ub = cmd->file->private_data;
2749+ struct ublk_batch_io_data data = {
2750+ .ub = ub,
2751+ .cmd = cmd,
2752+ .header = (struct ublk_batch_io) {
2753+ .q_id = READ_ONCE(uc->q_id),
2754+ .flags = READ_ONCE(uc->flags),
2755+ .nr_elem = READ_ONCE(uc->nr_elem),
2756+ .elem_bytes = READ_ONCE(uc->elem_bytes),
2757+ },
2758+ .issue_flags = issue_flags,
2759+ };
2760+ u32 cmd_op = cmd->cmd_op;
2761+ int ret = -EINVAL;
2762+
2763+ if (data.header.q_id >= ub->dev_info.nr_hw_queues)
2764+ goto out;
2765+
2766+ switch (cmd_op) {
2767+ case UBLK_U_IO_PREP_IO_CMDS:
2768+ case UBLK_U_IO_COMMIT_IO_CMDS:
2769+ ret = ublk_check_batch_cmd(&data);
2770+ if (ret)
2771+ goto out;
2772+ ret = -EOPNOTSUPP;
2773+ break;
2774+ default:
2775+ ret = -EOPNOTSUPP;
2776+ }
2777+out:
2778+ return ret;
26942779 }
26952780
26962781 static inline bool ublk_check_ubuf_dir(const struct request *req,
include/uapi/linux/ublk_cmd.h+49−0
@@ -103,6 +103,10 @@ · 102 unmodified lines
103103 _IOWR('u', 0x23, struct ublksrv_io_cmd)
104104 #define UBLK_U_IO_UNREGISTER_IO_BUF \
105105 _IOWR('u', 0x24, struct ublksrv_io_cmd)
106+#define UBLK_U_IO_PREP_IO_CMDS \
107+ _IOWR('u', 0x25, struct ublk_batch_io)
108+#define UBLK_U_IO_COMMIT_IO_CMDS \
109+ _IOWR('u', 0x26, struct ublk_batch_io)
106110
107111 /* only ABORT means that no re-fetch */
108112 #define UBLK_IO_RES_OK 0
@@ -544,6 +548,51 @@ struct ublksrv_io_cmd { · 435 unmodified lines
544548 };
545549 };
546550
551+struct ublk_elem_header {
552+ __u16 tag; /* IO tag */
553+
554+ /*
555+ * Buffer index for incoming io command, only valid iff
556+ * UBLK_F_AUTO_BUF_REG is set
557+ */
558+ __u16 buf_index;
559+ __s32 result; /* I/O completion result (commit only) */
560+};
561+
562+/*
563+ * uring_cmd buffer structure for batch commands
564+ *
565+ * buffer includes multiple elements, which number is specified by
566+ * `nr_elem`. Each element buffer is organized in the following order:
567+ *
568+ * struct ublk_elem_buffer {
569+ * // Mandatory fields (8 bytes)
570+ * struct ublk_elem_header header;
571+ *
572+ * // Optional fields (8 bytes each, included based on flags)
573+ *
574+ * // Buffer address (if UBLK_BATCH_F_HAS_BUF_ADDR) for copying data
575+ * // between ublk request and ublk server buffer
576+ * __u64 buf_addr;
577+ *
578+ * // returned Zone append LBA (if UBLK_BATCH_F_HAS_ZONE_LBA)
579+ * __u64 zone_lba;
580+ * }
581+ *
582+ * Used for `UBLK_U_IO_PREP_IO_CMDS` and `UBLK_U_IO_COMMIT_IO_CMDS`
583+ */
584+struct ublk_batch_io {
585+ __u16 q_id;
586+#define UBLK_BATCH_F_HAS_ZONE_LBA (1 << 0)
587+#define UBLK_BATCH_F_HAS_BUF_ADDR (1 << 1)
588+#define UBLK_BATCH_F_AUTO_BUF_REG_FALLBACK (1 << 2)
589+ __u16 flags;
590+ __u16 nr_elem;
591+ __u8 elem_bytes;
592+ __u8 reserved;
593+ __u64 reserved2;
594+};
595+
547596 struct ublk_param_basic {
548597 #define UBLK_ATTR_READ_ONLY (1 << 0)
549598 #define UBLK_ATTR_ROTATIONAL (1 << 1)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t