Skip to content

Commit f081393

Browse files
hreineckedwsuse
authored andcommitted
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 <[email protected]>
1 parent b57ff52 commit f081393

3 files changed

Lines changed: 91 additions & 64 deletions

File tree

src/nvme/ioctl.c

Lines changed: 27 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,74 +1715,54 @@ int nvme_resv_report(struct nvme_resv_report_args *args)
17151715
return nvme_submit_io_passthru(args->fd, &cmd, args->result);
17161716
}
17171717

1718-
int nvme_zns_mgmt_send(int fd, __u32 nsid, __u64 slba,
1719-
enum nvme_zns_send_action zsa, bool select_all,
1720-
__u8 zsaso, __u32 data_len,
1721-
void *data, __u32 timeout, __u32 *result)
1718+
int nvme_zns_mgmt_send(struct nvme_zns_mgmt_send_args *args)
17221719
{
1723-
__u32 cdw10 = slba & 0xffffffff;
1724-
__u32 cdw11 = slba >> 32;
1725-
__u32 cdw13 = NVME_SET(zsaso, ZNS_MGMT_SEND_ZSASO) |
1726-
NVME_SET(!!select_all, ZNS_MGMT_SEND_SEL) |
1727-
NVME_SET(zsa, ZNS_MGMT_SEND_ZSA);
1720+
__u32 cdw10 = args->slba & 0xffffffff;
1721+
__u32 cdw11 = args->slba >> 32;
1722+
__u32 cdw13 = NVME_SET(args->zsaso, ZNS_MGMT_SEND_ZSASO) |
1723+
NVME_SET(!!args->select_all, ZNS_MGMT_SEND_SEL) |
1724+
NVME_SET(args->zsa, ZNS_MGMT_SEND_ZSA);
17281725

17291726
struct nvme_passthru_cmd cmd = {
17301727
.opcode = nvme_zns_cmd_mgmt_send,
1731-
.nsid = nsid,
1728+
.nsid = args->nsid,
17321729
.cdw10 = cdw10,
17331730
.cdw11 = cdw11,
17341731
.cdw13 = cdw13,
1735-
.addr = (__u64)(uintptr_t)data,
1736-
.data_len = data_len,
1737-
.timeout_ms = timeout,
1732+
.addr = (__u64)(uintptr_t)args->data,
1733+
.data_len = args->data_len,
1734+
.timeout_ms = args->timeout,
17381735
};
17391736

1740-
return nvme_submit_io_passthru(fd, &cmd, result);
1737+
if (args->args_size < sizeof(*args))
1738+
return -EINVAL;
1739+
return nvme_submit_io_passthru(args->fd, &cmd, args->result);
17411740
}
17421741

1743-
int nvme_zns_mgmt_recv(int fd, __u32 nsid, __u64 slba,
1744-
enum nvme_zns_recv_action zra, __u16 zrasf,
1745-
bool zras_feat, __u32 data_len, void *data,
1746-
__u32 timeout, __u32 *result)
1742+
int nvme_zns_mgmt_recv(struct nvme_zns_mgmt_recv_args *args)
17471743
{
1748-
__u32 cdw10 = slba & 0xffffffff;
1749-
__u32 cdw11 = slba >> 32;
1750-
__u32 cdw12 = (data_len >> 2) - 1;
1751-
__u32 cdw13 = NVME_SET(zra, ZNS_MGMT_RECV_ZRA) |
1752-
NVME_SET(zrasf, ZNS_MGMT_RECV_ZRASF) |
1753-
NVME_SET(zras_feat, ZNS_MGMT_RECV_ZRAS_FEAT);
1744+
__u32 cdw10 = args->slba & 0xffffffff;
1745+
__u32 cdw11 = args->slba >> 32;
1746+
__u32 cdw12 = (args->data_len >> 2) - 1;
1747+
__u32 cdw13 = NVME_SET(args->zra, ZNS_MGMT_RECV_ZRA) |
1748+
NVME_SET(args->zrasf, ZNS_MGMT_RECV_ZRASF) |
1749+
NVME_SET(args->zras_feat, ZNS_MGMT_RECV_ZRAS_FEAT);
17541750

17551751
struct nvme_passthru_cmd cmd = {
17561752
.opcode = nvme_zns_cmd_mgmt_recv,
1757-
.nsid = nsid,
1753+
.nsid = args->nsid,
17581754
.cdw10 = cdw10,
17591755
.cdw11 = cdw11,
17601756
.cdw12 = cdw12,
17611757
.cdw13 = cdw13,
1762-
.addr = (__u64)(uintptr_t)data,
1763-
.data_len = data_len,
1764-
.timeout_ms = timeout,
1758+
.addr = (__u64)(uintptr_t)args->data,
1759+
.data_len = args->data_len,
1760+
.timeout_ms = args->timeout,
17651761
};
17661762

1767-
return nvme_submit_io_passthru(fd, &cmd, result);
1768-
}
1769-
1770-
int nvme_zns_report_zones(int fd, __u32 nsid, __u64 slba,
1771-
enum nvme_zns_report_options opts,
1772-
bool extended, bool partial,
1773-
__u32 data_len, void *data,
1774-
__u32 timeout, __u32 *result)
1775-
{
1776-
BUILD_ASSERT(sizeof(struct nvme_zns_desc) == 64);
1777-
enum nvme_zns_recv_action zra;
1778-
1779-
if (extended)
1780-
zra = NVME_ZNS_ZRA_EXTENDED_REPORT_ZONES;
1781-
else
1782-
zra = NVME_ZNS_ZRA_REPORT_ZONES;
1783-
1784-
return nvme_zns_mgmt_recv(fd, nsid, slba, zra, opts, partial,
1785-
data_len, data, timeout, result);
1763+
if (args->args_size < sizeof(*args))
1764+
return -EINVAL;
1765+
return nvme_submit_io_passthru(args->fd, &cmd, args->result);
17861766
}
17871767

17881768
int nvme_zns_append(int fd, __u32 nsid, __u64 zslba, __u16 nlb, __u16 control,

src/nvme/ioctl.h

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3942,7 +3942,7 @@ struct nvme_resv_report_args {
39423942
int nvme_resv_report(struct nvme_resv_report_args *args);
39433943

39443944
/**
3945-
* nvme_zns_mgmt_send() -
3945+
* nvme_zns_mgmt_send_args - Arguments for the NVMe ZNS Management Send command
39463946
* @fd: File descriptor of nvme device
39473947
* @nsid: Namespace ID
39483948
* @slba: Starting logical block address
@@ -3953,18 +3953,33 @@ int nvme_resv_report(struct nvme_resv_report_args *args);
39533953
* @data: Userspace address of the data
39543954
* @timeout: timeout in ms
39553955
* @result: The command completion result from CQE dword0
3956+
*/
3957+
struct nvme_zns_mgmt_send_args {
3958+
int args_size;
3959+
int fd;
3960+
__u32 nsid;
3961+
__u64 slba;
3962+
enum nvme_zns_send_action zsa;
3963+
bool select_all;
3964+
__u8 zsaso;
3965+
__u32 data_len;
3966+
void *data;
3967+
__u32 timeout;
3968+
__u32 *result;
3969+
};
3970+
3971+
/**
3972+
* nvme_zns_mgmt_send() -
3973+
* @args: &struct nvme_zns_mgmt_send_args argument structure
39563974
*
39573975
* Return: The nvme command status if a response was received (see
39583976
* &enum nvme_status_field) or -1 with errno set otherwise.
39593977
*/
3960-
int nvme_zns_mgmt_send(int fd, __u32 nsid, __u64 slba,
3961-
enum nvme_zns_send_action zsa, bool select_all, __u8 zsaso,
3962-
__u32 data_len, void *data,
3963-
__u32 timeout, __u32 *result);
3978+
int nvme_zns_mgmt_send(struct nvme_zns_mgmt_send_args *args);
39643979

39653980

39663981
/**
3967-
* nvme_zns_mgmt_recv() -
3982+
* nvme_zns_mgmt_recv_args - Arguments for the NVMe ZNS Management Receive command
39683983
* @fd: File descriptor of nvme device
39693984
* @nsid: Namespace ID
39703985
* @slba: Starting logical block address
@@ -3975,14 +3990,29 @@ int nvme_zns_mgmt_send(int fd, __u32 nsid, __u64 slba,
39753990
* @data: Userspace address of the data
39763991
* @timeout: timeout in ms
39773992
* @result: The command completion result from CQE dword0
3993+
*/
3994+
struct nvme_zns_mgmt_recv_args {
3995+
int args_size;
3996+
int fd;
3997+
__u32 nsid;
3998+
__u64 slba;
3999+
enum nvme_zns_recv_action zra;
4000+
__u16 zrasf;
4001+
bool zras_feat;
4002+
__u32 data_len;
4003+
void *data;
4004+
__u32 timeout;
4005+
__u32 *result;
4006+
};
4007+
4008+
/**
4009+
* nvme_zns_mgmt_recv() -
4010+
* @args: &struct nvme_zns_mgmt_recv_args argument structure
39784011
*
39794012
* Return: The nvme command status if a response was received (see
39804013
* &enum nvme_status_field) or -1 with errno set otherwise.
39814014
*/
3982-
int nvme_zns_mgmt_recv(int fd, __u32 nsid, __u64 slba,
3983-
enum nvme_zns_recv_action zra, __u16 zrasf,
3984-
bool zras_feat, __u32 data_len, void *data,
3985-
__u32 timeout, __u32 *result);
4015+
int nvme_zns_mgmt_recv(struct nvme_zns_mgmt_recv_args *args);
39864016

39874017
/**
39884018
* nvme_zns_report_zones() - Return the list of zones
@@ -4000,11 +4030,29 @@ int nvme_zns_mgmt_recv(int fd, __u32 nsid, __u64 slba,
40004030
* Return: The nvme command status if a response was received (see
40014031
* &enum nvme_status_field) or -1 with errno set otherwise.
40024032
*/
4003-
int nvme_zns_report_zones(int fd, __u32 nsid, __u64 slba,
4033+
static inline int nvme_zns_report_zones(int fd, __u32 nsid, __u64 slba,
40044034
enum nvme_zns_report_options opts,
40054035
bool extended, bool partial,
40064036
__u32 data_len, void *data,
4007-
__u32 timeout, __u32 *result);
4037+
__u32 timeout, __u32 *result)
4038+
{
4039+
struct nvme_zns_mgmt_recv_args args = {
4040+
.args_size = sizeof(args),
4041+
.fd = fd,
4042+
.nsid = nsid,
4043+
.slba = slba,
4044+
.zra = extended ? NVME_ZNS_ZRA_EXTENDED_REPORT_ZONES :
4045+
NVME_ZNS_ZRA_REPORT_ZONES,
4046+
.zrasf = opts,
4047+
.zras_feat = partial,
4048+
.data_len = data_len,
4049+
.data = data,
4050+
.timeout = timeout,
4051+
.result = result,
4052+
};
4053+
4054+
return nvme_zns_mgmt_recv(&args);
4055+
}
40084056

40094057
/**
40104058
* nvme_zns_append() - Append data to a zone

test/zns.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ static void show_zns_properties(nvme_ns_t n)
4545

4646
printf("zasl:%u\n", zns_ctrl.zasl);
4747

48-
if (nvme_zns_mgmt_recv(nvme_ns_get_fd(n), nvme_ns_get_nsid(n), 0,
49-
NVME_ZNS_ZRA_REPORT_ZONES,
50-
NVME_ZNS_ZRAS_REPORT_ALL,
51-
true, 0x1000, (void *)zr,
52-
NVME_DEFAULT_IOCTL_TIMEOUT, &result)) {
48+
if (nvme_zns_report_zones(nvme_ns_get_fd(n), nvme_ns_get_nsid(n), 0,
49+
NVME_ZNS_ZRAS_REPORT_ALL, false,
50+
true, 0x1000, (void *)zr,
51+
NVME_DEFAULT_IOCTL_TIMEOUT, &result)) {
5352
fprintf(stderr, "failed to report zones, result %x\n",
5453
le32_to_cpu(result));
5554
return;

0 commit comments

Comments
 (0)