Skip to content

Commit b57ff52

Browse files
hreineckedwsuse
authored andcommitted
Use argument structure for NVMe reservation commands
Use an argument structure for NVMe reservation commands like nvme_resv_acquire() or nvme_resv_release() 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 4571032 commit b57ff52

2 files changed

Lines changed: 119 additions & 50 deletions

File tree

src/nvme/ioctl.c

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,78 +1629,90 @@ int nvme_copy(struct nvme_copy_args *args)
16291629
return nvme_submit_io_passthru(args->fd, &cmd, args->result);
16301630
}
16311631

1632-
int nvme_resv_acquire(int fd, __u32 nsid, enum nvme_resv_rtype rtype,
1633-
enum nvme_resv_racqa racqa, bool iekey,
1634-
__u64 crkey, __u64 nrkey, __u32 timeout, __u32 *result)
1632+
int nvme_resv_acquire(struct nvme_resv_acquire_args *args)
16351633
{
1636-
__le64 payload[2] = { cpu_to_le64(crkey), cpu_to_le64(nrkey) };
1637-
__u32 cdw10 = (racqa & 0x7) | (iekey ? 1 << 3 : 0) | rtype << 8;
1634+
__le64 payload[2] = {
1635+
cpu_to_le64(args->crkey),
1636+
cpu_to_le64(args->nrkey)
1637+
};
1638+
__u32 cdw10 = (args->racqa & 0x7) |
1639+
(args->iekey ? 1 << 3 : 0) |
1640+
(args->rtype << 8);
16381641

16391642
struct nvme_passthru_cmd cmd = {
16401643
.opcode = nvme_cmd_resv_acquire,
1641-
.nsid = nsid,
1644+
.nsid = args->nsid,
16421645
.cdw10 = cdw10,
16431646
.data_len = sizeof(payload),
16441647
.addr = (__u64)(uintptr_t)(payload),
1645-
.timeout_ms = timeout,
1648+
.timeout_ms = args->timeout,
16461649
};
16471650

1648-
return nvme_submit_io_passthru(fd, &cmd, result);
1651+
if (args->args_size < sizeof(*args))
1652+
return -EINVAL;
1653+
return nvme_submit_io_passthru(args->fd, &cmd, args->result);
16491654
}
16501655

1651-
int nvme_resv_register(int fd, __u32 nsid, enum nvme_resv_rrega rrega,
1652-
enum nvme_resv_cptpl cptpl, bool iekey,
1653-
__u64 crkey, __u64 nrkey, __u32 timeout, __u32 *result)
1656+
int nvme_resv_register(struct nvme_resv_register_args *args)
16541657
{
1655-
__le64 payload[2] = { cpu_to_le64(crkey), cpu_to_le64(nrkey) };
1656-
__u32 cdw10 = (rrega & 0x7) | (iekey ? 1 << 3 : 0) | cptpl << 30;
1658+
__le64 payload[2] = {
1659+
cpu_to_le64(args->crkey),
1660+
cpu_to_le64(args->nrkey)
1661+
};
1662+
__u32 cdw10 = (args->rrega & 0x7) |
1663+
(args->iekey ? 1 << 3 : 0) |
1664+
(args->cptpl << 30);
16571665

16581666
struct nvme_passthru_cmd cmd = {
16591667
.opcode = nvme_cmd_resv_register,
1660-
.nsid = nsid,
1668+
.nsid = args->nsid,
16611669
.cdw10 = cdw10,
16621670
.data_len = sizeof(payload),
16631671
.addr = (__u64)(uintptr_t)(payload),
1664-
.timeout_ms = timeout,
1672+
.timeout_ms = args->timeout,
16651673
};
16661674

1667-
return nvme_submit_io_passthru(fd, &cmd, result);
1675+
if (args->args_size < sizeof(*args))
1676+
return -EINVAL;
1677+
return nvme_submit_io_passthru(args->fd, &cmd, args->result);
16681678
}
16691679

1670-
int nvme_resv_release(int fd, __u32 nsid, enum nvme_resv_rtype rtype,
1671-
enum nvme_resv_rrela rrela, bool iekey,
1672-
__u64 crkey, __u32 timeout, __u32 *result)
1680+
int nvme_resv_release(struct nvme_resv_release_args *args)
16731681
{
1674-
__le64 payload[1] = { cpu_to_le64(crkey) };
1675-
__u32 cdw10 = (rrela & 0x7) | (iekey ? 1 << 3 : 0) | rtype << 8;
1682+
__le64 payload[1] = { cpu_to_le64(args->crkey) };
1683+
__u32 cdw10 = (args->rrela & 0x7) |
1684+
(args->iekey ? 1 << 3 : 0) |
1685+
(args->rtype << 8);
16761686

16771687
struct nvme_passthru_cmd cmd = {
16781688
.opcode = nvme_cmd_resv_release,
1679-
.nsid = nsid,
1689+
.nsid = args->nsid,
16801690
.cdw10 = cdw10,
16811691
.addr = (__u64)(uintptr_t)(payload),
16821692
.data_len = sizeof(payload),
1683-
.timeout_ms = timeout,
1693+
.timeout_ms = args->timeout,
16841694
};
16851695

1686-
return nvme_submit_io_passthru(fd, &cmd, result);
1696+
if (args->args_size < sizeof(*args))
1697+
return -EINVAL;
1698+
return nvme_submit_io_passthru(args->fd, &cmd, args->result);
16871699
}
16881700

1689-
int nvme_resv_report(int fd, __u32 nsid, bool eds, __u32 len,
1690-
struct nvme_resv_status *report, __u32 timeout,
1691-
__u32 *result)
1701+
int nvme_resv_report(struct nvme_resv_report_args *args)
16921702
{
16931703
struct nvme_passthru_cmd cmd = {
16941704
.opcode = nvme_cmd_resv_report,
1695-
.nsid = nsid,
1696-
.cdw10 = (len >> 2) - 1,
1697-
.cdw11 = eds ? 1 : 0,
1698-
.addr = (__u64)(uintptr_t)report,
1699-
.data_len = len,
1700-
.timeout_ms = timeout,
1705+
.nsid = args->nsid,
1706+
.cdw10 = (args->len >> 2) - 1,
1707+
.cdw11 = args->eds ? 1 : 0,
1708+
.addr = (__u64)(uintptr_t)args->report,
1709+
.data_len = args->len,
1710+
.timeout_ms = args->timeout,
17011711
};
17021712

1703-
return nvme_submit_io_passthru(fd, &cmd, result);
1713+
if (args->args_size < sizeof(*args))
1714+
return -EINVAL;
1715+
return nvme_submit_io_passthru(args->fd, &cmd, args->result);
17041716
}
17051717

17061718
int nvme_zns_mgmt_send(int fd, __u32 nsid, __u64 slba,

src/nvme/ioctl.h

Lines changed: 73 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3799,7 +3799,7 @@ struct nvme_copy_args {
37993799
int nvme_copy(struct nvme_copy_args *args);
38003800

38013801
/**
3802-
* nvme_resv_acquire() - Send an nvme reservation acquire
3802+
* nvme_resv_acquire_args - Arguments for the NVMe Reservation Acquire Comand
38033803
* @fd: File descriptor of nvme device
38043804
* @nsid: Namespace identifier
38053805
* @rtype: The type of reservation to be create, see &enum nvme_resv_rtype
@@ -3810,6 +3810,23 @@ int nvme_copy(struct nvme_copy_args *args);
38103810
* the action is preempt
38113811
* @timeout: Timeout in ms
38123812
* @result: The command completion result from CQE dword0
3813+
*/
3814+
struct nvme_resv_acquire_args {
3815+
int args_size;
3816+
int fd;
3817+
__u32 nsid;
3818+
enum nvme_resv_rtype rtype;
3819+
enum nvme_resv_racqa racqa;
3820+
bool iekey;
3821+
__u64 crkey;
3822+
__u64 nrkey;
3823+
__u32 timeout;
3824+
__u32 *result;
3825+
};
3826+
3827+
/**
3828+
* nvme_resv_acquire() - Send an nvme reservation acquire
3829+
* @args: &struct nvme_resv_acquire argument structure
38133830
*
38143831
* The Reservation Acquire command acquires a reservation on a namespace,
38153832
* preempt a reservation held on a namespace, and abort a reservation held on a
@@ -3818,12 +3835,10 @@ int nvme_copy(struct nvme_copy_args *args);
38183835
* Return: The nvme command status if a response was received (see
38193836
* &enum nvme_status_field) or -1 with errno set otherwise.
38203837
*/
3821-
int nvme_resv_acquire(int fd, __u32 nsid, enum nvme_resv_rtype rtype,
3822-
enum nvme_resv_racqa racqa, bool iekey,
3823-
__u64 crkey, __u64 nrkey, __u32 timeout, __u32 *result);
3838+
int nvme_resv_acquire(struct nvme_resv_acquire_args *args);
38243839

38253840
/**
3826-
* nvme_resv_register() - Send an nvme reservation register
3841+
* nvme_resv_register_args - Arguments for the NVMe Reservation Register command
38273842
* @fd: File descriptor of nvme device
38283843
* @nsid: Namespace identifier
38293844
* @rrega: The registration action, see &enum nvme_resv_rrega
@@ -3833,19 +3848,34 @@ int nvme_resv_acquire(int fd, __u32 nsid, enum nvme_resv_rtype rtype,
38333848
* @nrkey: The new reservation key to be register if action is register or
38343849
* replace
38353850
* @timeout: Timeout in ms
3851+
*/
3852+
struct nvme_resv_register_args {
3853+
int args_size;
3854+
int fd;
3855+
__u32 nsid;
3856+
enum nvme_resv_rrega rrega;
3857+
enum nvme_resv_cptpl cptpl;
3858+
bool iekey;
3859+
__u64 crkey;
3860+
__u64 nrkey;
3861+
__u32 timeout;
3862+
__u32 *result;
3863+
};
3864+
3865+
/**
3866+
* nvme_resv_register() - Send an nvme reservation register
3867+
* @args: &struct nvme_resv_register_args argument structure
38363868
*
38373869
* The Reservation Register command registers, unregisters, or replaces a
38383870
* reservation key.
38393871
*
38403872
* Return: The nvme command status if a response was received (see
38413873
* &enum nvme_status_field) or -1 with errno set otherwise.
38423874
*/
3843-
int nvme_resv_register(int fd, __u32 nsid, enum nvme_resv_rrega rrega,
3844-
enum nvme_resv_cptpl cptpl, bool iekey,
3845-
__u64 crkey, __u64 nrkey, __u32 timeout, __u32 *result);
3875+
int nvme_resv_register(struct nvme_resv_register_args *args);
38463876

38473877
/**
3848-
* nvme_resv_release() - Send an nvme reservation release
3878+
* nvme_resv_release_args - Arguments for the NVMe Reservation Release Command
38493879
* @fd: File descriptor of nvme device
38503880
* @nsid: Namespace identifier
38513881
* @rtype: The type of reservation to be create, see &enum nvme_resv_rtype
@@ -3854,16 +3884,30 @@ int nvme_resv_register(int fd, __u32 nsid, enum nvme_resv_rrega rrega,
38543884
* @crkey: The current reservation key to release
38553885
* @timeout: Timeout in ms
38563886
* @result: The command completion result from CQE dword0
3887+
*/
3888+
struct nvme_resv_release_args {
3889+
int args_size;
3890+
int fd;
3891+
__u32 nsid;
3892+
enum nvme_resv_rtype rtype;
3893+
enum nvme_resv_rrela rrela;
3894+
bool iekey;
3895+
__u64 crkey;
3896+
__u32 timeout;
3897+
__u32 *result;
3898+
};
3899+
3900+
/**
3901+
* nvme_resv_release() - Send an nvme reservation release
3902+
* @args: &struct nvme_resv_release_args argument structure
38573903
*
38583904
* Return: The nvme command status if a response was received (see
38593905
* &enum nvme_status_field) or -1 with errno set otherwise.
38603906
*/
3861-
int nvme_resv_release(int fd, __u32 nsid, enum nvme_resv_rtype rtype,
3862-
enum nvme_resv_rrela rrela, bool iekey,
3863-
__u64 crkey, __u32 timeout, __u32 *result);
3907+
int nvme_resv_release(struct nvme_resv_release_args *args);
38643908

38653909
/**
3866-
* nvme_resv_report() - Send an nvme reservation report
3910+
* nvme_resv_report_args - Arguments for the NVMe Reservation Report command
38673911
* @fd: File descriptor of nvme device
38683912
* @nsid: Namespace identifier
38693913
* @eds: Request extended Data Structure
@@ -3872,6 +3916,21 @@ int nvme_resv_release(int fd, __u32 nsid, enum nvme_resv_rtype rtype,
38723916
* report
38733917
* @timeout: Timeout in ms
38743918
* @result: The command completion result from CQE dword0
3919+
*/
3920+
struct nvme_resv_report_args {
3921+
int args_size;
3922+
int fd;
3923+
__u32 nsid;
3924+
bool eds;
3925+
__u32 len;
3926+
struct nvme_resv_status *report;
3927+
__u32 timeout;
3928+
__u32 *result;
3929+
};
3930+
3931+
/**
3932+
* nvme_resv_report() - Send an nvme reservation report
3933+
* @args: struct nvme_resv_report_args argument structure
38753934
*
38763935
* Returns a Reservation Status data structure to memory that describes the
38773936
* registration and reservation status of a namespace. See the defintion for
@@ -3880,9 +3939,7 @@ int nvme_resv_release(int fd, __u32 nsid, enum nvme_resv_rtype rtype,
38803939
* Return: The nvme command status if a response was received (see
38813940
* &enum nvme_status_field) or -1 with errno set otherwise.
38823941
*/
3883-
int nvme_resv_report(int fd, __u32 nsid, bool eds, __u32 len,
3884-
struct nvme_resv_status *report,
3885-
__u32 timeout, __u32 *result);
3942+
int nvme_resv_report(struct nvme_resv_report_args *args);
38863943

38873944
/**
38883945
* nvme_zns_mgmt_send() -

0 commit comments

Comments
 (0)