Skip to content

Commit 38692fd

Browse files
hreineckedwsuse
authored andcommitted
Use argument structure for nvme_set_property() and nvme_get_property()
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 8e376cb commit 38692fd

2 files changed

Lines changed: 45 additions & 18 deletions

File tree

src/nvme/ioctl.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,37 +1417,40 @@ int nvme_lockdown(struct nvme_lockdown_args *args)
14171417
return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
14181418
}
14191419

1420-
int nvme_set_property(int fd, int offset, __u64 value,
1421-
__u32 timeout, __u32 *result)
1420+
int nvme_set_property(struct nvme_set_property_args *args)
14221421
{
1423-
__u32 cdw10 = nvme_is_64bit_reg(offset);
1422+
__u32 cdw10 = nvme_is_64bit_reg(args->offset);
14241423

14251424
struct nvme_passthru_cmd cmd = {
14261425
.opcode = nvme_admin_fabrics,
14271426
.nsid = nvme_fabrics_type_property_set,
14281427
.cdw10 = cdw10,
1429-
.cdw11 = offset,
1430-
.cdw12 = value & 0xffffffff,
1431-
.cdw13 = value >> 32,
1432-
.timeout_ms = timeout,
1428+
.cdw11 = args->offset,
1429+
.cdw12 = args->value & 0xffffffff,
1430+
.cdw13 = args->value >> 32,
1431+
.timeout_ms = args->timeout,
14331432
};
14341433

1435-
return nvme_submit_admin_passthru(fd, &cmd, result);
1434+
if (args->args_size < sizeof(*args))
1435+
return -EINVAL;
1436+
return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
14361437
}
14371438

1438-
int nvme_get_property(int fd, int offset, __u64 *value, __u32 timeout)
1439+
int nvme_get_property(struct nvme_get_property_args *args)
14391440
{
1440-
__u32 cdw10 = nvme_is_64bit_reg(offset);
1441+
__u32 cdw10 = nvme_is_64bit_reg(args->offset);
14411442

14421443
struct nvme_passthru_cmd64 cmd = {
14431444
.opcode = nvme_admin_fabrics,
14441445
.nsid = nvme_fabrics_type_property_get,
14451446
.cdw10 = cdw10,
1446-
.cdw11 = offset,
1447-
.timeout_ms = timeout,
1447+
.cdw11 = args->offset,
1448+
.timeout_ms = args->timeout,
14481449
};
14491450

1450-
return nvme_submit_admin_passthru64(fd, &cmd, value);
1451+
if (args->args_size < sizeof(*args))
1452+
return -EINVAL;
1453+
return nvme_submit_admin_passthru64(args->fd, &cmd, args->value);
14511454
}
14521455

14531456
int nvme_sanitize_nvm(int fd, enum nvme_sanitize_sanact sanact, bool ause,

src/nvme/ioctl.h

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3381,36 +3381,60 @@ struct nvme_lockdown_args {
33813381
int nvme_lockdown(struct nvme_lockdown_args *args);
33823382

33833383
/**
3384-
* nvme_set_property() - Set controller property
3384+
* nvme_set_property_args - Arguments for NVMe Set Property command
33853385
* @fd: File descriptor of nvme device
33863386
* @offset: Property offset from the base to set
33873387
* @value: The value to set the property
33883388
* @timeout: Timeout in ms
33893389
* @result: The command completion result from CQE dword0
3390+
*/
3391+
struct nvme_set_property_args {
3392+
int args_size;
3393+
int fd;
3394+
int offset;
3395+
__u64 value;
3396+
__u32 timeout;
3397+
__u32 *result;
3398+
};
3399+
3400+
/**
3401+
* nvme_set_property() - Set controller property
3402+
* @args: &struct nvme_set_property_args argument structure
33903403
*
33913404
* This is an NVMe-over-Fabrics specific command, not applicable to PCIe. These
33923405
* properties align to the PCI MMIO controller registers.
33933406
*
33943407
* Return: The nvme command status if a response was received (see
33953408
* &enum nvme_status_field) or -1 with errno set otherwise.
33963409
*/
3397-
int nvme_set_property(int fd, int offset, __u64 value,
3398-
__u32 timeout, __u32 *result);
3410+
int nvme_set_property(struct nvme_set_property_args *args);
33993411

34003412
/**
3401-
* nvme_get_property() - Get a controller property
3413+
* nvme_get_property_args - Arguments for NVMe Get Property command
34023414
* @fd: File descriptor of nvme device
34033415
* @offset: Property offset from the base to retrieve
34043416
* @value: Where the property's value will be stored on success
34053417
* @timeout: Timeout in ms
3418+
*/
3419+
struct nvme_get_property_args {
3420+
int args_size;
3421+
int fd;
3422+
int offset;
3423+
__u64 *value;
3424+
__u32 timeout;
3425+
};
3426+
3427+
/**
3428+
* nvme_get_property() - Get a controller property
3429+
* @args: &struct nvme_get_propert_args argument structure
34063430
*
34073431
* This is an NVMe-over-Fabrics specific command, not applicable to PCIe. These
34083432
* properties align to the PCI MMIO controller registers.
34093433
*
34103434
* Return: The nvme command status if a response was received (see
34113435
* &enum nvme_status_field) or -1 with errno set otherwise.
34123436
*/
3413-
int nvme_get_property(int fd, int offset, __u64 *value, __u32 timeout);
3437+
int nvme_get_property(struct nvme_get_property_args *args);
34143438

34153439
/**
34163440
* nvme_sanitize_nvm() - Start a sanitize operation

0 commit comments

Comments
 (0)