From f08139355010b7c64d49b8cd2e0ecf27d1d6632b Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Fri, 17 Dec 2021 08:03:42 +0100 Subject: [PATCH] Use argument structure for nvme_zns_mgmt_send() and nvme_zns_mgmt_recv() Use an argument structure instead of passing all arguments one by one. This allows for a future expansion of the argument list without having to change the library ABI. Also convert zns.c to use nvme_zns_report_zones() instead of calling nvme_zns_mgmt_recv() directly. Signed-off-by: Hannes Reinecke --- src/nvme/ioctl.c | 74 ++++++++++++++++++------------------------------ src/nvme/ioctl.h | 72 ++++++++++++++++++++++++++++++++++++++-------- test/zns.c | 9 +++--- 3 files changed, 91 insertions(+), 64 deletions(-) diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 9973919d..531763c2 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1715,74 +1715,54 @@ int nvme_resv_report(struct nvme_resv_report_args *args) return nvme_submit_io_passthru(args->fd, &cmd, args->result); } -int nvme_zns_mgmt_send(int fd, __u32 nsid, __u64 slba, - enum nvme_zns_send_action zsa, bool select_all, - __u8 zsaso, __u32 data_len, - void *data, __u32 timeout, __u32 *result) +int nvme_zns_mgmt_send(struct nvme_zns_mgmt_send_args *args) { - __u32 cdw10 = slba & 0xffffffff; - __u32 cdw11 = slba >> 32; - __u32 cdw13 = NVME_SET(zsaso, ZNS_MGMT_SEND_ZSASO) | - NVME_SET(!!select_all, ZNS_MGMT_SEND_SEL) | - NVME_SET(zsa, ZNS_MGMT_SEND_ZSA); + __u32 cdw10 = args->slba & 0xffffffff; + __u32 cdw11 = args->slba >> 32; + __u32 cdw13 = NVME_SET(args->zsaso, ZNS_MGMT_SEND_ZSASO) | + NVME_SET(!!args->select_all, ZNS_MGMT_SEND_SEL) | + NVME_SET(args->zsa, ZNS_MGMT_SEND_ZSA); struct nvme_passthru_cmd cmd = { .opcode = nvme_zns_cmd_mgmt_send, - .nsid = nsid, + .nsid = args->nsid, .cdw10 = cdw10, .cdw11 = cdw11, .cdw13 = cdw13, - .addr = (__u64)(uintptr_t)data, - .data_len = data_len, - .timeout_ms = timeout, + .addr = (__u64)(uintptr_t)args->data, + .data_len = args->data_len, + .timeout_ms = args->timeout, }; - return nvme_submit_io_passthru(fd, &cmd, result); + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_io_passthru(args->fd, &cmd, args->result); } -int nvme_zns_mgmt_recv(int fd, __u32 nsid, __u64 slba, - enum nvme_zns_recv_action zra, __u16 zrasf, - bool zras_feat, __u32 data_len, void *data, - __u32 timeout, __u32 *result) +int nvme_zns_mgmt_recv(struct nvme_zns_mgmt_recv_args *args) { - __u32 cdw10 = slba & 0xffffffff; - __u32 cdw11 = slba >> 32; - __u32 cdw12 = (data_len >> 2) - 1; - __u32 cdw13 = NVME_SET(zra, ZNS_MGMT_RECV_ZRA) | - NVME_SET(zrasf, ZNS_MGMT_RECV_ZRASF) | - NVME_SET(zras_feat, ZNS_MGMT_RECV_ZRAS_FEAT); + __u32 cdw10 = args->slba & 0xffffffff; + __u32 cdw11 = args->slba >> 32; + __u32 cdw12 = (args->data_len >> 2) - 1; + __u32 cdw13 = NVME_SET(args->zra, ZNS_MGMT_RECV_ZRA) | + NVME_SET(args->zrasf, ZNS_MGMT_RECV_ZRASF) | + NVME_SET(args->zras_feat, ZNS_MGMT_RECV_ZRAS_FEAT); struct nvme_passthru_cmd cmd = { .opcode = nvme_zns_cmd_mgmt_recv, - .nsid = nsid, + .nsid = args->nsid, .cdw10 = cdw10, .cdw11 = cdw11, .cdw12 = cdw12, .cdw13 = cdw13, - .addr = (__u64)(uintptr_t)data, - .data_len = data_len, - .timeout_ms = timeout, + .addr = (__u64)(uintptr_t)args->data, + .data_len = args->data_len, + .timeout_ms = args->timeout, }; - return nvme_submit_io_passthru(fd, &cmd, result); -} - -int nvme_zns_report_zones(int fd, __u32 nsid, __u64 slba, - enum nvme_zns_report_options opts, - bool extended, bool partial, - __u32 data_len, void *data, - __u32 timeout, __u32 *result) -{ - BUILD_ASSERT(sizeof(struct nvme_zns_desc) == 64); - enum nvme_zns_recv_action zra; - - if (extended) - zra = NVME_ZNS_ZRA_EXTENDED_REPORT_ZONES; - else - zra = NVME_ZNS_ZRA_REPORT_ZONES; - - return nvme_zns_mgmt_recv(fd, nsid, slba, zra, opts, partial, - data_len, data, timeout, result); + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_io_passthru(args->fd, &cmd, args->result); } int nvme_zns_append(int fd, __u32 nsid, __u64 zslba, __u16 nlb, __u16 control, diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 3f528872..42604ca9 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -3942,7 +3942,7 @@ struct nvme_resv_report_args { int nvme_resv_report(struct nvme_resv_report_args *args); /** - * nvme_zns_mgmt_send() - + * nvme_zns_mgmt_send_args - Arguments for the NVMe ZNS Management Send command * @fd: File descriptor of nvme device * @nsid: Namespace ID * @slba: Starting logical block address @@ -3953,18 +3953,33 @@ int nvme_resv_report(struct nvme_resv_report_args *args); * @data: Userspace address of the data * @timeout: timeout in ms * @result: The command completion result from CQE dword0 + */ +struct nvme_zns_mgmt_send_args { + int args_size; + int fd; + __u32 nsid; + __u64 slba; + enum nvme_zns_send_action zsa; + bool select_all; + __u8 zsaso; + __u32 data_len; + void *data; + __u32 timeout; + __u32 *result; +}; + +/** + * nvme_zns_mgmt_send() - + * @args: &struct nvme_zns_mgmt_send_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_zns_mgmt_send(int fd, __u32 nsid, __u64 slba, - enum nvme_zns_send_action zsa, bool select_all, __u8 zsaso, - __u32 data_len, void *data, - __u32 timeout, __u32 *result); +int nvme_zns_mgmt_send(struct nvme_zns_mgmt_send_args *args); /** - * nvme_zns_mgmt_recv() - + * nvme_zns_mgmt_recv_args - Arguments for the NVMe ZNS Management Receive command * @fd: File descriptor of nvme device * @nsid: Namespace ID * @slba: Starting logical block address @@ -3975,14 +3990,29 @@ int nvme_zns_mgmt_send(int fd, __u32 nsid, __u64 slba, * @data: Userspace address of the data * @timeout: timeout in ms * @result: The command completion result from CQE dword0 + */ +struct nvme_zns_mgmt_recv_args { + int args_size; + int fd; + __u32 nsid; + __u64 slba; + enum nvme_zns_recv_action zra; + __u16 zrasf; + bool zras_feat; + __u32 data_len; + void *data; + __u32 timeout; + __u32 *result; +}; + +/** + * nvme_zns_mgmt_recv() - + * @args: &struct nvme_zns_mgmt_recv_args argument structure * * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_zns_mgmt_recv(int fd, __u32 nsid, __u64 slba, - enum nvme_zns_recv_action zra, __u16 zrasf, - bool zras_feat, __u32 data_len, void *data, - __u32 timeout, __u32 *result); +int nvme_zns_mgmt_recv(struct nvme_zns_mgmt_recv_args *args); /** * nvme_zns_report_zones() - Return the list of zones @@ -4000,11 +4030,29 @@ int nvme_zns_mgmt_recv(int fd, __u32 nsid, __u64 slba, * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_zns_report_zones(int fd, __u32 nsid, __u64 slba, +static inline int nvme_zns_report_zones(int fd, __u32 nsid, __u64 slba, enum nvme_zns_report_options opts, bool extended, bool partial, __u32 data_len, void *data, - __u32 timeout, __u32 *result); + __u32 timeout, __u32 *result) +{ + struct nvme_zns_mgmt_recv_args args = { + .args_size = sizeof(args), + .fd = fd, + .nsid = nsid, + .slba = slba, + .zra = extended ? NVME_ZNS_ZRA_EXTENDED_REPORT_ZONES : + NVME_ZNS_ZRA_REPORT_ZONES, + .zrasf = opts, + .zras_feat = partial, + .data_len = data_len, + .data = data, + .timeout = timeout, + .result = result, + }; + + return nvme_zns_mgmt_recv(&args); +} /** * nvme_zns_append() - Append data to a zone diff --git a/test/zns.c b/test/zns.c index 997765b4..b6549862 100644 --- a/test/zns.c +++ b/test/zns.c @@ -45,11 +45,10 @@ static void show_zns_properties(nvme_ns_t n) printf("zasl:%u\n", zns_ctrl.zasl); - if (nvme_zns_mgmt_recv(nvme_ns_get_fd(n), nvme_ns_get_nsid(n), 0, - NVME_ZNS_ZRA_REPORT_ZONES, - NVME_ZNS_ZRAS_REPORT_ALL, - true, 0x1000, (void *)zr, - NVME_DEFAULT_IOCTL_TIMEOUT, &result)) { + if (nvme_zns_report_zones(nvme_ns_get_fd(n), nvme_ns_get_nsid(n), 0, + NVME_ZNS_ZRAS_REPORT_ALL, false, + true, 0x1000, (void *)zr, + NVME_DEFAULT_IOCTL_TIMEOUT, &result)) { fprintf(stderr, "failed to report zones, result %x\n", le32_to_cpu(result)); return; -- 2.50.1