Skip to content

Commit 0b5a6b8

Browse files
hreineckedwsuse
authored andcommitted
Use argument structure for nvme_security_send() and nvme_security_receive()
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 e465328 commit 0b5a6b8

2 files changed

Lines changed: 68 additions & 34 deletions

File tree

src/nvme/ioctl.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,50 +1242,50 @@ int nvme_fw_commit(struct nvme_fw_commit_args *args)
12421242
return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
12431243
}
12441244

1245-
int nvme_security_send(int fd, __u32 nsid, __u8 nssf, __u8 spsp0, __u8 spsp1,
1246-
__u8 secp, __u32 tl, __u32 data_len, void *data,
1247-
__u32 timeout, __u32 *result)
1245+
int nvme_security_send(struct nvme_security_send_args *args)
12481246
{
1249-
__u32 cdw10 = NVME_SET(secp, SECURITY_SECP) |
1250-
NVME_SET(spsp0, SECURITY_SPSP0) |
1251-
NVME_SET(spsp1, SECURITY_SPSP1) |
1252-
NVME_SET(nssf, SECURITY_NSSF);
1253-
__u32 cdw11 = tl;
1247+
__u32 cdw10 = NVME_SET(args->secp, SECURITY_SECP) |
1248+
NVME_SET(args->spsp0, SECURITY_SPSP0) |
1249+
NVME_SET(args->spsp1, SECURITY_SPSP1) |
1250+
NVME_SET(args->nssf, SECURITY_NSSF);
1251+
__u32 cdw11 = args->tl;
12541252

12551253
struct nvme_passthru_cmd cmd = {
12561254
.opcode = nvme_admin_security_send,
1257-
.nsid = nsid,
1255+
.nsid = args->nsid,
12581256
.cdw10 = cdw10,
12591257
.cdw11 = cdw11,
1260-
.data_len = data_len,
1261-
.addr = (__u64)(uintptr_t)data,
1262-
.timeout_ms = timeout,
1258+
.data_len = args->data_len,
1259+
.addr = (__u64)(uintptr_t)args->data,
1260+
.timeout_ms = args->timeout,
12631261
};
12641262

1265-
return nvme_submit_admin_passthru(fd, &cmd, result);
1263+
if (args->args_size < sizeof(*args))
1264+
return -EINVAL;
1265+
return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
12661266
}
12671267

1268-
int nvme_security_receive(int fd, __u32 nsid, __u8 nssf, __u8 spsp0,
1269-
__u8 spsp1, __u8 secp, __u32 al, __u32 data_len,
1270-
void *data, __u32 timeout, __u32 *result)
1268+
int nvme_security_receive(struct nvme_security_receive_args *args)
12711269
{
1272-
__u32 cdw10 = NVME_SET(secp, SECURITY_SECP) |
1273-
NVME_SET(spsp0, SECURITY_SPSP0) |
1274-
NVME_SET(spsp1, SECURITY_SPSP1) |
1275-
NVME_SET(nssf, SECURITY_NSSF);
1276-
__u32 cdw11 = al;
1270+
__u32 cdw10 = NVME_SET(args->secp, SECURITY_SECP) |
1271+
NVME_SET(args->spsp0, SECURITY_SPSP0) |
1272+
NVME_SET(args->spsp1, SECURITY_SPSP1) |
1273+
NVME_SET(args->nssf, SECURITY_NSSF);
1274+
__u32 cdw11 = args->al;
12771275

12781276
struct nvme_passthru_cmd cmd = {
12791277
.opcode = nvme_admin_security_recv,
1280-
.nsid = nsid,
1278+
.nsid = args->nsid,
12811279
.cdw10 = cdw10,
12821280
.cdw11 = cdw11,
1283-
.data_len = data_len,
1284-
.addr = (__u64)(uintptr_t)data,
1285-
.timeout_ms = timeout,
1281+
.data_len = args->data_len,
1282+
.addr = (__u64)(uintptr_t)args->data,
1283+
.timeout_ms = args->timeout,
12861284
};
12871285

1288-
return nvme_submit_admin_passthru(fd, &cmd, result);
1286+
if (args->args_size < sizeof(*args))
1287+
return -EINVAL;
1288+
return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
12891289
}
12901290

12911291
int nvme_get_lba_status(int fd, __u32 nsid, __u64 slba, __u32 mndw, __u16 rl,

src/nvme/ioctl.h

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2933,7 +2933,7 @@ struct nvme_fw_commit_args {
29332933
int nvme_fw_commit(struct nvme_fw_commit_args *args);
29342934

29352935
/**
2936-
* nvme_security_send() -
2936+
* nvme_security_send_args - Arguments for the NVMe Security Send command
29372937
* @fd: File descriptor of nvme device
29382938
* @nsid: Namespace ID to issue security command on
29392939
* @nssf: NVMe Security Specific field
@@ -2945,6 +2945,25 @@ int nvme_fw_commit(struct nvme_fw_commit_args *args);
29452945
* @data: Security data payload to send
29462946
* @timeout: Timeout in ms
29472947
* @result: The command completion result from CQE dword0
2948+
*/
2949+
struct nvme_security_send_args {
2950+
int args_size;
2951+
int fd;
2952+
__u32 nsid;
2953+
__u8 nssf;
2954+
__u8 spsp0;
2955+
__u8 spsp1;
2956+
__u8 secp;
2957+
__u32 tl;
2958+
__u32 data_len;
2959+
void *data;
2960+
__u32 timeout;
2961+
__u32 *result;
2962+
};
2963+
2964+
/**
2965+
* nvme_security_send() -
2966+
* @args: &struct nvme_security_send argument structure
29482967
*
29492968
* The Security Send command transfers security protocol data to the
29502969
* controller. The data structure transferred to the controller as part of this
@@ -2958,12 +2977,10 @@ int nvme_fw_commit(struct nvme_fw_commit_args *args);
29582977
* Return: The nvme command status if a response was received (see
29592978
* &enum nvme_status_field) or -1 with errno set otherwise.
29602979
*/
2961-
int nvme_security_send(int fd, __u32 nsid, __u8 nssf, __u8 spsp0, __u8 spsp1,
2962-
__u8 secp, __u32 tl, __u32 data_len, void *data,
2963-
__u32 timeout, __u32 *result);
2980+
int nvme_security_send(struct nvme_security_send_args *args);
29642981

29652982
/**
2966-
* nvme_security_receive() -
2983+
* nvme_security_receive_args - Arguments for the NVMe Security Receive command
29672984
* @fd: File descriptor of nvme device
29682985
* @nsid: Namespace ID to issue security command on
29692986
* @nssf: NVMe Security Specific field
@@ -2975,13 +2992,30 @@ int nvme_security_send(int fd, __u32 nsid, __u8 nssf, __u8 spsp0, __u8 spsp1,
29752992
* @data: Security data payload to send
29762993
* @timeout: Timeout in ms
29772994
* @result: The command completion result from CQE dword0
2995+
*/
2996+
struct nvme_security_receive_args {
2997+
int args_size;
2998+
int fd;
2999+
__u32 nsid;
3000+
__u8 nssf;
3001+
__u8 spsp0;
3002+
__u8 spsp1;
3003+
__u8 secp;
3004+
__u32 al;
3005+
__u32 data_len;
3006+
void *data;
3007+
__u32 timeout;
3008+
__u32 *result;
3009+
};
3010+
3011+
/**
3012+
* nvme_security_receive() -
3013+
* @args: &struct nvme_security_recevice argument structure
29783014
*
29793015
* Return: The nvme command status if a response was received (see
29803016
* &enum nvme_status_field) or -1 with errno set otherwise.
29813017
*/
2982-
int nvme_security_receive(int fd, __u32 nsid, __u8 nssf, __u8 spsp0,
2983-
__u8 spsp1, __u8 secp, __u32 al, __u32 data_len,
2984-
void *data, __u32 timeout, __u32 *result);
3018+
int nvme_security_receive(struct nvme_security_receive_args *args);
29853019

29863020
/**
29873021
* nvme_get_lba_status() - Retrieve information on possibly unrecoverable LBAs

0 commit comments

Comments
 (0)