Skip to content

Commit dd099d4

Browse files
ikegami-tigaw
authored andcommitted
ioctl: nvme_zns_append use nvme_passthru_cmd directly
Drop struct nvme_zns_append_args. Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
1 parent d7590f2 commit dd099d4

File tree

5 files changed

+56
-106
lines changed

5 files changed

+56
-106
lines changed

src/libnvme.map

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,6 @@ LIBNVME_2_0 {
356356
nvme_uuid_random;
357357
nvme_uuid_to_string;
358358
nvme_virtual_mgmt;
359-
nvme_zns_append;
360359
nvmf_add_ctrl;
361360
nvmf_adrfam_str;
362361
nvmf_cms_str;

src/nvme/api-types.h

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -318,46 +318,6 @@ struct nvme_virtual_mgmt_args {
318318
__u16 nr;
319319
};
320320

321-
/**
322-
* struct nvme_zns_append_args - Arguments for the NVMe ZNS Append command
323-
* @zslba: Zone start logical block address
324-
* @result: The command completion result from CQE dword0
325-
* @data: Userspace address of the data
326-
* @metadata: Userspace address of the metadata
327-
* @args_size: Size of &struct nvme_zns_append_args
328-
* @timeout: Timeout in ms
329-
* @nsid: Namespace ID
330-
* @ilbrt: Initial logical block reference tag
331-
* @data_len: Length of @data
332-
* @metadata_len: Length of @metadata
333-
* @nlb: Number of logical blocks
334-
* @control:
335-
* @lbat: Logical block application tag
336-
* @lbatm: Logical block application tag mask
337-
* @rsvd1: Reserved
338-
* @ilbrt_u64: Initial logical block reference tag - 8 byte
339-
* version required for enhanced protection info
340-
*
341-
*/
342-
struct nvme_zns_append_args {
343-
__u64 zslba;
344-
__u64 *result;
345-
void *data;
346-
void *metadata;
347-
int args_size;
348-
__u32 timeout;
349-
__u32 nsid;
350-
__u32 ilbrt;
351-
__u32 data_len;
352-
__u32 metadata_len;
353-
__u16 nlb;
354-
__u16 control;
355-
__u16 lbat;
356-
__u16 lbatm;
357-
__u8 rsvd1[4];
358-
__u64 ilbrt_u64;
359-
};
360-
361321
/**
362322
* struct nvme_dim_args - Arguments for the Discovery Information Management (DIM) command
363323
* @result: Set on completion to the command's CQE DWORD 0 controller response.

src/nvme/ioctl.c

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,47 +1344,6 @@ int nvme_io_passthru(nvme_link_t l, __u8 opcode, __u8 flags, __u16 rsvd,
13441344
timeout_ms, result);
13451345
}
13461346

1347-
int nvme_zns_append(nvme_link_t l, struct nvme_zns_append_args *args)
1348-
{
1349-
const size_t size_v1 = sizeof_args(struct nvme_zns_append_args, lbatm, __u64);
1350-
const size_t size_v2 = sizeof_args(struct nvme_zns_append_args, ilbrt_u64, __u64);
1351-
__u32 cdw3, cdw10, cdw11, cdw12, cdw14, cdw15;
1352-
1353-
if (args->args_size < size_v1 || args->args_size > size_v2)
1354-
return -EINVAL;
1355-
1356-
cdw10 = args->zslba & 0xffffffff;
1357-
cdw11 = args->zslba >> 32;
1358-
cdw12 = args->nlb | (args->control << 16);
1359-
cdw15 = args->lbat | (args->lbatm << 16);
1360-
1361-
if (args->args_size == size_v1) {
1362-
cdw3 = 0;
1363-
cdw14 = args->ilbrt;
1364-
} else {
1365-
cdw3 = (args->ilbrt_u64 >> 32) & 0xffffffff;
1366-
cdw14 = args->ilbrt_u64 & 0xffffffff;
1367-
}
1368-
1369-
struct nvme_passthru_cmd64 cmd = {
1370-
.opcode = nvme_zns_cmd_append,
1371-
.nsid = args->nsid,
1372-
.cdw3 = cdw3,
1373-
.cdw10 = cdw10,
1374-
.cdw11 = cdw11,
1375-
.cdw12 = cdw12,
1376-
.cdw14 = cdw14,
1377-
.cdw15 = cdw15,
1378-
.data_len = args->data_len,
1379-
.addr = (__u64)(uintptr_t)args->data,
1380-
.metadata_len = args->metadata_len,
1381-
.metadata = (__u64)(uintptr_t)args->metadata,
1382-
.timeout_ms = args->timeout,
1383-
};
1384-
1385-
return nvme_submit_io_passthru64(l, &cmd, args->result);
1386-
}
1387-
13881347
int nvme_dim_send(nvme_link_t l, struct nvme_dim_args *args)
13891348
{
13901349
__u32 cdw10 = NVME_SET(args->tas, DIM_TAS);

src/nvme/ioctl.h

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4910,12 +4910,51 @@ static inline int nvme_zns_report_zones(nvme_link_t l, __u32 nsid, __u64 slba,
49104910
/**
49114911
* nvme_zns_append() - Append data to a zone
49124912
* @l: Link handle
4913-
* @args: &struct nvme_zns_append_args argument structure
4913+
* @nsid: Namespace ID
4914+
* @zslba: Zone start logical block address
4915+
* @nlb: Number of logical blocks
4916+
* @control:
4917+
* @lbat: Logical block application tag
4918+
* @lbatm: Logical block application tag mask
4919+
* @ilbrt_u64: Initial logical block reference tag - 8 byte
4920+
* version required for enhanced protection info
4921+
* @data: Userspace address of the data
4922+
* @data_len: Length of @data
4923+
* @metadata: Userspace address of the metadata
4924+
* @metadata_len: Length of @metadata
4925+
* @result: The command completion result from CQE dword0
49144926
*
49154927
* Return: 0 on success, the nvme command status if a response was
49164928
* received (see &enum nvme_status_field) or a negative error otherwise.
49174929
*/
4918-
int nvme_zns_append(nvme_link_t l, struct nvme_zns_append_args *args);
4930+
static inline int nvme_zns_append(nvme_link_t l, __u32 nsid, __u64 zslba, __u16 nlb, __u16 control,
4931+
__u16 lbat, __u16 lbatm, __u64 ilbrt_u64, void *data,
4932+
__u32 data_len, void *metadata, __u32 metadata_len, __u64 *result)
4933+
{
4934+
__u32 cdw3 = (ilbrt_u64 >> 32) & 0xffffffff;
4935+
__u32 cdw10 = zslba & 0xffffffff;
4936+
__u32 cdw11 = zslba >> 32;
4937+
__u32 cdw12 = nlb | (control << 16);
4938+
__u32 cdw14 = ilbrt_u64 & 0xffffffff;
4939+
__u32 cdw15 = lbat | (lbatm << 16);
4940+
4941+
struct nvme_passthru_cmd64 cmd = {
4942+
.opcode = nvme_zns_cmd_append,
4943+
.nsid = nsid,
4944+
.cdw3 = cdw3,
4945+
.metadata = (__u64)(uintptr_t)metadata,
4946+
.addr = (__u64)(uintptr_t)data,
4947+
.metadata_len = metadata_len,
4948+
.data_len = data_len,
4949+
.cdw10 = cdw10,
4950+
.cdw11 = cdw11,
4951+
.cdw12 = cdw12,
4952+
.cdw14 = cdw14,
4953+
.cdw15 = cdw15,
4954+
};
4955+
4956+
return nvme_submit_io_passthru64(l, &cmd, result);
4957+
}
49194958

49204959
/**
49214960
* nvme_dim_send - Send a Discovery Information Management (DIM) command

test/ioctl/zns.c

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,32 @@ static nvme_link_t test_link;
1717
static void test_zns_append(void)
1818
{
1919
__u8 expected_data[8], data[8] = {};
20+
__u64 zslba = TEST_SLBA;
21+
__u64 ilbrt_u64 = 0x76;
22+
__u16 control = 0xcd;
23+
__u16 lbatm = 0x98;
24+
__u16 lbat = 0xef;
25+
__u16 nlb = 0xab;
2026
__u64 result = 0;
21-
struct nvme_zns_append_args args = {
22-
.zslba = TEST_SLBA,
23-
.result = &result,
24-
.data = &data,
25-
.args_size = sizeof(args),
26-
.nsid = TEST_NSID,
27-
.data_len = sizeof(data),
28-
.nlb = 0xab,
29-
.control = 0xcd,
30-
.lbat = 0xef,
31-
.lbatm = 0x98,
32-
.ilbrt_u64 = 0x76,
33-
};
27+
int err;
3428

3529
struct mock_cmd mock_io_cmd = {
3630
.opcode = nvme_zns_cmd_append,
3731
.nsid = TEST_NSID,
38-
.cdw3 = (args.ilbrt_u64 >> 32) & 0xffffffff,
39-
.cdw10 = args.zslba & 0xffffffff,
40-
.cdw11 = args.zslba >> 32,
41-
.cdw12 = args.nlb | (args.control << 16),
42-
.cdw14 = args.ilbrt_u64 & 0xffffffff,
43-
.cdw15 = args.lbat | (args.lbatm << 16),
32+
.cdw3 = (ilbrt_u64 >> 32) & 0xffffffff,
33+
.cdw10 = zslba & 0xffffffff,
34+
.cdw11 = zslba >> 32,
35+
.cdw12 = nlb | (control << 16),
36+
.cdw14 = ilbrt_u64 & 0xffffffff,
37+
.cdw15 = lbat | (lbatm << 16),
4438
.data_len = sizeof(expected_data),
4539
.out_data = &expected_data,
4640
};
4741

48-
int err;
49-
5042
arbitrary(&expected_data, sizeof(expected_data));
5143
set_mock_io_cmds(&mock_io_cmd, 1);
52-
err = nvme_zns_append(test_link, &args);
44+
err = nvme_zns_append(test_link, TEST_NSID, zslba, nlb, control, lbat, lbatm, ilbrt_u64,
45+
&data, sizeof(data), NULL, 0, &result);
5346
end_mock_cmds();
5447
check(err == 0, "returned error %d", err);
5548
check(result == 0, "wrong result");

0 commit comments

Comments
 (0)