Skip to content

Commit 7459192

Browse files
hreineckedwsuse
authored andcommitted
Use argument structure for nvme_directive_send() and nvme_directive_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 d1eee6a commit 7459192

2 files changed

Lines changed: 200 additions & 126 deletions

File tree

src/nvme/ioctl.c

Lines changed: 40 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,29 +1312,27 @@ int nvme_get_lba_status(struct nvme_get_lba_status_args *args)
13121312
return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
13131313
}
13141314

1315-
int nvme_directive_send(int fd, __u32 nsid, __u16 dspec,
1316-
enum nvme_directive_send_doper doper,
1317-
enum nvme_directive_dtype dtype, __u32 cdw12,
1318-
__u32 data_len, void *data, __u32 timeout,
1319-
__u32 *result)
1315+
int nvme_directive_send(struct nvme_directive_send_args *args)
13201316
{
1321-
__u32 cdw10 = data_len ? (data_len >> 2) - 1 : 0;
1322-
__u32 cdw11 = NVME_SET(doper, DIRECTIVE_CDW11_DOPER) |
1323-
NVME_SET(dtype, DIRECTIVE_CDW11_DTYPE) |
1324-
NVME_SET(dspec, DIRECTIVE_CDW11_DPSEC);
1317+
__u32 cdw10 = args->data_len ? (args->data_len >> 2) - 1 : 0;
1318+
__u32 cdw11 = NVME_SET(args->doper, DIRECTIVE_CDW11_DOPER) |
1319+
NVME_SET(args->dtype, DIRECTIVE_CDW11_DTYPE) |
1320+
NVME_SET(args->dspec, DIRECTIVE_CDW11_DPSEC);
13251321

13261322
struct nvme_passthru_cmd cmd = {
13271323
.opcode = nvme_admin_directive_send,
1328-
.nsid = nsid,
1324+
.nsid = args->nsid,
13291325
.cdw10 = cdw10,
13301326
.cdw11 = cdw11,
1331-
.cdw12 = cdw12,
1332-
.data_len = data_len,
1333-
.addr = (__u64)(uintptr_t)data,
1334-
.timeout_ms = timeout,
1327+
.cdw12 = args->cdw12,
1328+
.data_len = args->data_len,
1329+
.addr = (__u64)(uintptr_t)args->data,
1330+
.timeout_ms = args->timeout,
13351331
};
13361332

1337-
return nvme_submit_admin_passthru(fd, &cmd, result);
1333+
if (args->args_size < sizeof(*args))
1334+
return -EINVAL;
1335+
return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
13381336
}
13391337

13401338
int nvme_directive_send_id_endir(int fd, __u32 nsid, bool endir,
@@ -1343,102 +1341,44 @@ int nvme_directive_send_id_endir(int fd, __u32 nsid, bool endir,
13431341
{
13441342
__u32 cdw12 = NVME_SET(dtype, DIRECTIVE_SEND_IDENTIFY_CDW12_DTYPE) |
13451343
NVME_SET(endir, DIRECTIVE_SEND_IDENTIFY_CDW12_ENDIR);
1344+
struct nvme_directive_send_args args = {
1345+
.args_size = sizeof(args),
1346+
.fd = fd,
1347+
.nsid = nsid,
1348+
.dspec = 0,
1349+
.dtype = NVME_DIRECTIVE_DTYPE_IDENTIFY,
1350+
.doper = NVME_DIRECTIVE_SEND_IDENTIFY_DOPER_ENDIR,
1351+
.cdw12 = cdw12,
1352+
.data_len = sizeof(*id),
1353+
.data = id,
1354+
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
1355+
.result = NULL,
1356+
};
13461357

1347-
return nvme_directive_send(fd, nsid, 0, NVME_DIRECTIVE_DTYPE_IDENTIFY,
1348-
NVME_DIRECTIVE_SEND_IDENTIFY_DOPER_ENDIR,
1349-
cdw12, sizeof(*id), id,
1350-
NVME_DEFAULT_IOCTL_TIMEOUT, NULL);
1351-
}
1352-
1353-
int nvme_directive_send_stream_release_identifier(int fd, __u32 nsid,
1354-
__u16 stream_id)
1355-
{
1356-
enum nvme_directive_dtype dtype =
1357-
NVME_DIRECTIVE_SEND_STREAMS_DOPER_RELEASE_IDENTIFIER;
1358-
1359-
return nvme_directive_send(fd, nsid, stream_id,
1360-
NVME_DIRECTIVE_DTYPE_STREAMS,
1361-
dtype, 0, 0, NULL,
1362-
NVME_DEFAULT_IOCTL_TIMEOUT, NULL);
1363-
}
1364-
1365-
int nvme_directive_send_stream_release_resource(int fd, __u32 nsid)
1366-
{
1367-
enum nvme_directive_dtype dtype =
1368-
NVME_DIRECTIVE_SEND_STREAMS_DOPER_RELEASE_RESOURCE;
1369-
1370-
return nvme_directive_send(fd, nsid, 0, NVME_DIRECTIVE_DTYPE_STREAMS,
1371-
dtype, 0, 0, NULL,
1372-
NVME_DEFAULT_IOCTL_TIMEOUT, NULL);
1358+
return nvme_directive_send(&args);
13731359
}
13741360

1375-
int nvme_directive_recv(int fd, __u32 nsid, __u16 dspec,
1376-
enum nvme_directive_receive_doper doper,
1377-
enum nvme_directive_dtype dtype, __u32 cdw12,
1378-
__u32 data_len, void *data, __u32 timeout,
1379-
__u32 *result)
1361+
int nvme_directive_recv(struct nvme_directive_recv_args *args)
13801362
{
1381-
__u32 cdw10 = data_len ? (data_len >> 2) - 1 : 0;
1382-
__u32 cdw11 = NVME_SET(doper, DIRECTIVE_CDW11_DOPER) |
1383-
NVME_SET(dtype, DIRECTIVE_CDW11_DTYPE) |
1384-
NVME_SET(dspec, DIRECTIVE_CDW11_DPSEC);
1363+
__u32 cdw10 = args->data_len ? (args->data_len >> 2) - 1 : 0;
1364+
__u32 cdw11 = NVME_SET(args->doper, DIRECTIVE_CDW11_DOPER) |
1365+
NVME_SET(args->dtype, DIRECTIVE_CDW11_DTYPE) |
1366+
NVME_SET(args->dspec, DIRECTIVE_CDW11_DPSEC);
13851367

13861368
struct nvme_passthru_cmd cmd = {
13871369
.opcode = nvme_admin_directive_recv,
1388-
.nsid = nsid,
1370+
.nsid = args->nsid,
13891371
.cdw10 = cdw10,
13901372
.cdw11 = cdw11,
1391-
.cdw12 = cdw12,
1392-
.data_len = data_len,
1393-
.addr = (__u64)(uintptr_t)data,
1394-
.timeout_ms = timeout,
1373+
.cdw12 = args->cdw12,
1374+
.data_len = args->data_len,
1375+
.addr = (__u64)(uintptr_t)args->data,
1376+
.timeout_ms = args->timeout,
13951377
};
13961378

1397-
return nvme_submit_admin_passthru(fd, &cmd, result);
1398-
}
1399-
1400-
int nvme_directive_recv_identify_parameters(int fd, __u32 nsid,
1401-
struct nvme_id_directives *id)
1402-
{
1403-
enum nvme_directive_dtype dtype =
1404-
NVME_DIRECTIVE_RECEIVE_IDENTIFY_DOPER_PARAM;
1405-
1406-
return nvme_directive_recv(fd, nsid, 0, NVME_DIRECTIVE_DTYPE_IDENTIFY,
1407-
dtype, 0, sizeof(*id), id,
1408-
NVME_DEFAULT_IOCTL_TIMEOUT, NULL);
1409-
}
1410-
1411-
int nvme_directive_recv_stream_parameters(int fd, __u32 nsid,
1412-
struct nvme_streams_directive_params *parms)
1413-
{
1414-
enum nvme_directive_dtype dtype =
1415-
NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_PARAM;
1416-
1417-
return nvme_directive_recv(fd, nsid, 0, NVME_DIRECTIVE_DTYPE_STREAMS,
1418-
dtype, 0, sizeof(*parms), parms,
1419-
NVME_DEFAULT_IOCTL_TIMEOUT, NULL);
1420-
}
1421-
1422-
int nvme_directive_recv_stream_status(int fd, __u32 nsid, unsigned nr_entries,
1423-
struct nvme_streams_directive_status *id)
1424-
{
1425-
enum nvme_directive_dtype dtype =
1426-
NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_STATUS;
1427-
1428-
return nvme_directive_recv(fd, nsid, 0, NVME_DIRECTIVE_DTYPE_STREAMS,
1429-
dtype, 0, sizeof(*id), id,
1430-
NVME_DEFAULT_IOCTL_TIMEOUT, NULL);
1431-
}
1432-
1433-
int nvme_directive_recv_stream_allocate(int fd, __u32 nsid, __u16 nsr,
1434-
__u32 *result)
1435-
{
1436-
enum nvme_directive_dtype dtype =
1437-
NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_RESOURCE;
1438-
1439-
return nvme_directive_recv(fd, nsid, 0, NVME_DIRECTIVE_DTYPE_STREAMS,
1440-
dtype, nsr, 0, NULL,
1441-
NVME_DEFAULT_IOCTL_TIMEOUT, result);
1379+
if (args->args_size < sizeof(*args))
1380+
return -EINVAL;
1381+
return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
14421382
}
14431383

14441384
int nvme_capacity_mgmt(int fd, __u8 op, __u16 element_id,

0 commit comments

Comments
 (0)