Skip to content

Commit d1eee6a

Browse files
hreineckedwsuse
authored andcommitted
Use argument structure for nvme_get_lba_status()
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 0b5a6b8 commit d1eee6a

2 files changed

Lines changed: 31 additions & 16 deletions

File tree

src/nvme/ioctl.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,28 +1288,28 @@ int nvme_security_receive(struct nvme_security_receive_args *args)
12881288
return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
12891289
}
12901290

1291-
int nvme_get_lba_status(int fd, __u32 nsid, __u64 slba, __u32 mndw, __u16 rl,
1292-
enum nvme_lba_status_atype atype, __u32 timeout,
1293-
struct nvme_lba_status *lbas, __u32 *result)
1291+
int nvme_get_lba_status(struct nvme_get_lba_status_args *args)
12941292
{
1295-
__u32 cdw10 = slba & 0xffffffff;
1296-
__u32 cdw11 = slba >> 32;
1297-
__u32 cdw12 = mndw;
1298-
__u32 cdw13 = NVME_SET(rl, GET_LBA_STATUS_CDW13_RL) |
1299-
NVME_SET(atype, GET_LBA_STATUS_CDW13_ATYPE);
1293+
__u32 cdw10 = args->slba & 0xffffffff;
1294+
__u32 cdw11 = args->slba >> 32;
1295+
__u32 cdw12 = args->mndw;
1296+
__u32 cdw13 = NVME_SET(args->rl, GET_LBA_STATUS_CDW13_RL) |
1297+
NVME_SET(args->atype, GET_LBA_STATUS_CDW13_ATYPE);
13001298

13011299
struct nvme_passthru_cmd cmd = {
13021300
.opcode = nvme_admin_get_lba_status,
1303-
.nsid = nsid,
1304-
.addr = (__u64)(uintptr_t)lbas,
1301+
.nsid = args->nsid,
1302+
.addr = (__u64)(uintptr_t)args->lbas,
13051303
.cdw10 = cdw10,
13061304
.cdw11 = cdw11,
13071305
.cdw12 = cdw12,
13081306
.cdw13 = cdw13,
1309-
.timeout_ms = timeout,
1307+
.timeout_ms = args->timeout,
13101308
};
13111309

1312-
return nvme_submit_admin_passthru(fd, &cmd, result);
1310+
if (args->args_size < sizeof(*args))
1311+
return -EINVAL;
1312+
return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
13131313
}
13141314

13151315
int nvme_directive_send(int fd, __u32 nsid, __u16 dspec,

src/nvme/ioctl.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3018,7 +3018,7 @@ struct nvme_security_receive_args {
30183018
int nvme_security_receive(struct nvme_security_receive_args *args);
30193019

30203020
/**
3021-
* nvme_get_lba_status() - Retrieve information on possibly unrecoverable LBAs
3021+
* nvme_get_lba_status_args - Arguments for the NVMe Get LBA Status command
30223022
* @fd: File descriptor of nvme device
30233023
* @nsid: Namespace ID to retrieve LBA status
30243024
* @slba: Starting logical block address to check statuses
@@ -3029,16 +3029,31 @@ int nvme_security_receive(struct nvme_security_receive_args *args);
30293029
* @timeout: Timeout in ms
30303030
* @lbas: Data payload to return status descriptors
30313031
* @result: The command completion result from CQE dword0
3032+
*/
3033+
struct nvme_get_lba_status_args {
3034+
int args_size;
3035+
int fd;
3036+
__u32 nsid;
3037+
__u64 slba;
3038+
__u32 mndw;
3039+
__u16 rl;
3040+
enum nvme_lba_status_atype atype;
3041+
__u32 timeout;
3042+
struct nvme_lba_status *lbas;
3043+
__u32 *result;
3044+
};
3045+
3046+
/**
3047+
* nvme_get_lba_status() - Retrieve information on possibly unrecoverable LBAs
3048+
* @args: &struct nvme_get_lba_status_args argument structure
30323049
*
30333050
* The Get LBA Status command requests information about Potentially
30343051
* Unrecoverable LBAs. Refer to the specification for action type descriptions.
30353052
*
30363053
* Return: The nvme command status if a response was received (see
30373054
* &enum nvme_status_field) or -1 with errno set otherwise.
30383055
*/
3039-
int nvme_get_lba_status(int fd, __u32 nsid, __u64 slba, __u32 mndw, __u16 rl,
3040-
enum nvme_lba_status_atype atype, __u32 timeout,
3041-
struct nvme_lba_status *lbas, __u32 *result);
3056+
int nvme_get_lba_status(struct nvme_get_lba_status_args *args);
30423057

30433058
/**
30443059
* nvme_directive_send() - Send directive command

0 commit comments

Comments
 (0)