Skip to content

Commit db91866

Browse files
hreineckedwsuse
authored andcommitted
Use argument structure for nvme_virtual_mgmt()
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. Signed-off-by: Hannes Reinecke <[email protected]>
1 parent 2bfe3d2 commit db91866

2 files changed

Lines changed: 31 additions & 15 deletions

File tree

src/nvme/ioctl.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,22 +1490,23 @@ int nvme_dev_self_test(struct nvme_dev_self_test_args *args)
14901490
return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
14911491
}
14921492

1493-
int nvme_virtual_mgmt(int fd, enum nvme_virt_mgmt_act act,
1494-
enum nvme_virt_mgmt_rt rt, __u16 cntlid, __u16 nr,
1495-
__u32 *result)
1493+
int nvme_virtual_mgmt(struct nvme_virtual_mgmt_args *args)
14961494
{
1497-
__u32 cdw10 = NVME_SET(act, VIRT_MGMT_CDW10_ACT) |
1498-
NVME_SET(rt, VIRT_MGMT_CDW10_RT) |
1499-
NVME_SET(cntlid, VIRT_MGMT_CDW10_CNTLID);
1500-
__u32 cdw11 = NVME_SET(nr, VIRT_MGMT_CDW11_NR);
1495+
__u32 cdw10 = NVME_SET(args->act, VIRT_MGMT_CDW10_ACT) |
1496+
NVME_SET(args->rt, VIRT_MGMT_CDW10_RT) |
1497+
NVME_SET(args->cntlid, VIRT_MGMT_CDW10_CNTLID);
1498+
__u32 cdw11 = NVME_SET(args->nr, VIRT_MGMT_CDW11_NR);
15011499

15021500
struct nvme_passthru_cmd cmd = {
1503-
.opcode = nvme_admin_virtual_mgmt,
1504-
.cdw10 = cdw10,
1505-
.cdw11 = cdw11,
1501+
.opcode = nvme_admin_virtual_mgmt,
1502+
.cdw10 = cdw10,
1503+
.cdw11 = cdw11,
1504+
.timeout_ms = args->timeout,
15061505
};
15071506

1508-
return nvme_submit_admin_passthru(fd, &cmd, result);
1507+
if (args->args_size < sizeof(*args))
1508+
return -EINVAL;
1509+
return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
15091510
}
15101511

15111512
int nvme_submit_io_passthru64(int fd, struct nvme_passthru_cmd64 *cmd,

src/nvme/ioctl.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3518,13 +3518,30 @@ struct nvme_dev_self_test_args {
35183518
int nvme_dev_self_test(struct nvme_dev_self_test_args *args);
35193519

35203520
/**
3521-
* nvme_virtual_mgmt() - Virtualization resource management
3521+
* nvme_virtual_mgmt_args - Arguments for the NVMe Virtualization
3522+
* resource management command
35223523
* @fd: File descriptor of nvme device
35233524
* @act: Virtual resource action, see &enum nvme_virt_mgmt_act
35243525
* @rt: Resource type to modify, see &enum nvme_virt_mgmt_rt
35253526
* @cntlid: Controller id for which resources are bing modified
35263527
* @nr: Number of resources being allocated or assigned
3528+
* @timeout: Timeout in ms
35273529
* @result: If successful, the CQE dword0
3530+
*/
3531+
struct nvme_virtual_mgmt_args {
3532+
int args_size;
3533+
int fd;
3534+
enum nvme_virt_mgmt_act act;
3535+
enum nvme_virt_mgmt_rt rt;
3536+
__u16 cntlid;
3537+
__u16 nr;
3538+
__u32 timeout;
3539+
__u32 *result;
3540+
};
3541+
3542+
/**
3543+
* nvme_virtual_mgmt() - Virtualization resource management
3544+
* @args: &struct nvme_virtual_mgmt_args argument structure
35283545
*
35293546
* The Virtualization Management command is supported by primary controllers
35303547
* that support the Virtualization Enhancements capability. This command is
@@ -3537,9 +3554,7 @@ int nvme_dev_self_test(struct nvme_dev_self_test_args *args);
35373554
* Return: The nvme command status if a response was received (see
35383555
* &enum nvme_status_field) or -1 with errno set otherwise.
35393556
*/
3540-
int nvme_virtual_mgmt(int fd, enum nvme_virt_mgmt_act act,
3541-
enum nvme_virt_mgmt_rt rt, __u16 cntlid, __u16 nr,
3542-
__u32 *result);
3557+
int nvme_virtual_mgmt(struct nvme_virtual_mgmt_args *args);
35433558

35443559
/**
35453560
* nvme_flush() - Send an nvme flush command

0 commit comments

Comments
 (0)