Skip to content

Commit 4a4a3a8

Browse files
committed
ioctl: rework nvme_virtual_mgmt command
Replace the struct args approach by providing init function for initializing the passthru commands. This reduces the dependency between callside and library. Signed-off-by: Daniel Wagner <wagi@kernel.org>
1 parent b2eee6e commit 4a4a3a8

File tree

5 files changed

+38
-70
lines changed

5 files changed

+38
-70
lines changed

src/libnvme.map

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ LIBNVME_2_0 {
293293
nvme_uuid_from_string;
294294
nvme_uuid_random;
295295
nvme_uuid_to_string;
296-
nvme_virtual_mgmt;
297296
nvme_zns_append;
298297
nvme_zns_mgmt_recv;
299298
nvme_zns_mgmt_send;

src/nvme/api-types.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,6 @@ struct nvme_global_ctx *nvme_create_global_ctx(FILE *fp, int log_level);
3838
*/
3939
void nvme_free_global_ctx(struct nvme_global_ctx *ctx);
4040

41-
/**
42-
* struct nvme_virtual_mgmt_args - Arguments for the NVMe Virtualization
43-
* resource management command
44-
* @args_size: Size of &struct nvme_virtual_mgmt_args
45-
* @result: If successful, the CQE dword0
46-
* @timeout: Timeout in ms
47-
* @act: Virtual resource action, see &enum nvme_virt_mgmt_act
48-
* @rt: Resource type to modify, see &enum nvme_virt_mgmt_rt
49-
* @cntlid: Controller id for which resources are bing modified
50-
* @nr: Number of resources being allocated or assigned
51-
*/
52-
struct nvme_virtual_mgmt_args {
53-
__u32 *result;
54-
int args_size;
55-
__u32 timeout;
56-
enum nvme_virt_mgmt_act act;
57-
enum nvme_virt_mgmt_rt rt;
58-
__u16 cntlid;
59-
__u16 nr;
60-
};
61-
6241
/**
6342
* struct nvme_io_args - Arguments for NVMe I/O commands
6443
* @slba: Starting logical block

src/nvme/ioctl.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -621,26 +621,6 @@ int nvme_get_ana_log_atomic(struct nvme_transport_handle *hdl, bool rae, bool rg
621621
return -EAGAIN;
622622
}
623623

624-
int nvme_virtual_mgmt(struct nvme_transport_handle *hdl, struct nvme_virtual_mgmt_args *args)
625-
{
626-
__u32 cdw10 = NVME_SET(args->act, VIRT_MGMT_CDW10_ACT) |
627-
NVME_SET(args->rt, VIRT_MGMT_CDW10_RT) |
628-
NVME_SET(args->cntlid, VIRT_MGMT_CDW10_CNTLID);
629-
__u32 cdw11 = NVME_SET(args->nr, VIRT_MGMT_CDW11_NR);
630-
631-
struct nvme_passthru_cmd cmd = {
632-
.opcode = nvme_admin_virtual_mgmt,
633-
.cdw10 = cdw10,
634-
.cdw11 = cdw11,
635-
.timeout_ms = args->timeout,
636-
};
637-
638-
if (args->args_size < sizeof(*args))
639-
return -EINVAL;
640-
641-
return nvme_submit_admin_passthru(hdl, &cmd, args->result);
642-
}
643-
644624
int nvme_submit_io_passthru64(struct nvme_transport_handle *hdl, struct nvme_passthru_cmd64 *cmd,
645625
__u64 *result)
646626
{

src/nvme/ioctl.h

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4197,22 +4197,37 @@ nvme_init_dev_self_test(struct nvme_passthru_cmd *cmd, __u32 nsid,
41974197
}
41984198

41994199
/**
4200-
* nvme_virtual_mgmt() - Virtualization resource management
4201-
* @hdl: Transport handle
4202-
* @args: &struct nvme_virtual_mgmt_args argument structure
4203-
*
4204-
* The Virtualization Management command is supported by primary controllers
4205-
* that support the Virtualization Enhancements capability. This command is
4206-
* used for several functions:
4207-
*
4208-
* - Modifying Flexible Resource allocation for the primary controller
4209-
* - Assigning Flexible Resources for secondary controllers
4210-
* - Setting the Online and Offline state for secondary controllers
4200+
* nvme_init_virtual_mgmt() - Initialize passthru command for
4201+
* Virtualization Resource Management
4202+
* @cmd: Passthru command to use
4203+
* @act: Virtual resource action, see &enum nvme_virt_mgmt_act
4204+
* @rt: Resource type to modify, see &enum nvme_virt_mgmt_rt
4205+
* @cntlid: Controller id for which resources are bing modified
4206+
* @nr: Number of resources being allocated or assigned
42114207
*
4212-
* Return: 0 on success, the nvme command status if a response was
4213-
* received (see &enum nvme_status_field) or a negative error otherwise.
4208+
* Initializes the passthru command buffer for the Virtualization
4209+
* Management command.
42144210
*/
4215-
int nvme_virtual_mgmt(struct nvme_transport_handle *hdl, struct nvme_virtual_mgmt_args *args);
4211+
static inline void
4212+
nvme_init_virtual_mgmt(struct nvme_passthru_cmd *cmd,
4213+
enum nvme_virt_mgmt_act act, enum nvme_virt_mgmt_rt rt,
4214+
__u16 cntlid, __u16 nr)
4215+
{
4216+
memset(cmd, 0, sizeof(*cmd));
4217+
cmd->opcode = nvme_admin_virtual_mgmt;
4218+
cmd->cdw10 = NVME_FIELD_ENCODE(act,
4219+
NVME_VIRT_MGMT_CDW10_ACT_SHIFT,
4220+
NVME_VIRT_MGMT_CDW10_ACT_MASK) |
4221+
NVME_FIELD_ENCODE(rt,
4222+
NVME_VIRT_MGMT_CDW10_RT_SHIFT,
4223+
NVME_VIRT_MGMT_CDW10_RT_MASK) |
4224+
NVME_FIELD_ENCODE(cntlid,
4225+
NVME_VIRT_MGMT_CDW10_CNTLID_SHIFT,
4226+
NVME_VIRT_MGMT_CDW10_CNTLID_MASK);
4227+
cmd->cdw11 = NVME_FIELD_ENCODE(nr,
4228+
NVME_VIRT_MGMT_CDW11_NR_SHIFT,
4229+
NVME_VIRT_MGMT_CDW11_NR_MASK);
4230+
}
42164231

42174232
/**
42184233
* nvme_flush() - Send an nvme flush command

test/ioctl/misc.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -726,28 +726,23 @@ static void test_dev_self_test(void)
726726

727727
static void test_virtual_mgmt(void)
728728
{
729+
enum nvme_virt_mgmt_act act = NVME_VIRT_MGMT_ACT_ASSIGN_SEC_CTRL;
730+
enum nvme_virt_mgmt_rt rt = NVME_VIRT_MGMT_RT_VI_RESOURCE;
729731
__u32 expected_result = 0x45, result = 0;
730-
731-
struct nvme_virtual_mgmt_args args = {
732-
.result = &result,
733-
.args_size = sizeof(args),
734-
.act = NVME_VIRT_MGMT_ACT_ASSIGN_SEC_CTRL,
735-
.rt = NVME_VIRT_MGMT_RT_VI_RESOURCE,
736-
.cntlid = 0x0,
737-
.nr = 0xff,
738-
};
739-
732+
__u16 cntlid = 0x0;
733+
__u16 nr = 0xff;
740734
struct mock_cmd mock_admin_cmd = {
741735
.opcode = nvme_admin_virtual_mgmt,
742-
.cdw10 = args.act | (args.rt << 8) | (args.cntlid << 16),
743-
.cdw11 = args.nr,
736+
.cdw10 = act | (rt << 8) | (cntlid << 16),
737+
.cdw11 = nr,
744738
.result = expected_result,
745739
};
746-
740+
struct nvme_passthru_cmd cmd;
747741
int err;
748742

749743
set_mock_admin_cmds(&mock_admin_cmd, 1);
750-
err = nvme_virtual_mgmt(test_hdl, &args);
744+
nvme_init_virtual_mgmt(&cmd, act, rt, cntlid, nr);
745+
err = nvme_submit_admin_passthru(test_hdl, &cmd, &result);
751746
end_mock_cmds();
752747
check(err == 0, "returned error %d", err);
753748
check(result == expected_result, "wrong result");

0 commit comments

Comments
 (0)