Skip to content

Commit 00b1ea9

Browse files
hreineckedwsuse
authored andcommitted
Use argument structure for nvme_sanize_nvm()
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 38692fd commit 00b1ea9

2 files changed

Lines changed: 30 additions & 15 deletions

File tree

src/nvme/ioctl.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,25 +1453,25 @@ int nvme_get_property(struct nvme_get_property_args *args)
14531453
return nvme_submit_admin_passthru64(args->fd, &cmd, args->value);
14541454
}
14551455

1456-
int nvme_sanitize_nvm(int fd, enum nvme_sanitize_sanact sanact, bool ause,
1457-
__u8 owpass, bool oipbp, bool nodas, __u32 ovrpat,
1458-
__u32 timeout, __u32 *result)
1456+
int nvme_sanitize_nvm(struct nvme_sanitize_nvm_args *args)
14591457
{
1460-
__u32 cdw10 = NVME_SET(sanact, SANITIZE_CDW10_SANACT) |
1461-
NVME_SET(!!ause, SANITIZE_CDW10_AUSE) |
1462-
NVME_SET(owpass, SANITIZE_CDW10_OWPASS) |
1463-
NVME_SET(!!oipbp, SANITIZE_CDW10_OIPBP) |
1464-
NVME_SET(!!nodas, SANITIZE_CDW10_NODAS);
1465-
__u32 cdw11 = ovrpat;
1458+
__u32 cdw10 = NVME_SET(args->sanact, SANITIZE_CDW10_SANACT) |
1459+
NVME_SET(!!args->ause, SANITIZE_CDW10_AUSE) |
1460+
NVME_SET(args->owpass, SANITIZE_CDW10_OWPASS) |
1461+
NVME_SET(!!args->oipbp, SANITIZE_CDW10_OIPBP) |
1462+
NVME_SET(!!args->nodas, SANITIZE_CDW10_NODAS);
1463+
__u32 cdw11 = args->ovrpat;
14661464

14671465
struct nvme_passthru_cmd cmd = {
14681466
.opcode = nvme_admin_sanitize_nvm,
14691467
.cdw10 = cdw10,
14701468
.cdw11 = cdw11,
1471-
.timeout_ms = timeout,
1469+
.timeout_ms = args->timeout,
14721470
};
14731471

1474-
return nvme_submit_admin_passthru(fd, &cmd, result);
1472+
if (args->args_size < sizeof(*args))
1473+
return -EINVAL;
1474+
return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
14751475
}
14761476

14771477
int nvme_dev_self_test(int fd, __u32 nsid, enum nvme_dst_stc stc)

src/nvme/ioctl.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3437,7 +3437,7 @@ struct nvme_get_property_args {
34373437
int nvme_get_property(struct nvme_get_property_args *args);
34383438

34393439
/**
3440-
* nvme_sanitize_nvm() - Start a sanitize operation
3440+
* nvme_sanitize_nvm_args - Arguments for the NVMe Sanitize NVM command
34413441
* @fd: File descriptor of nvme device
34423442
* @sanact: Sanitize action, see &enum nvme_sanitize_sanact
34433443
* @ause: Set to allow unrestriced sanitize exit
@@ -3447,6 +3447,23 @@ int nvme_get_property(struct nvme_get_property_args *args);
34473447
* @ovrpat: Overwrite pattern
34483448
* @timeout: Timeout in ms
34493449
* @result: The command completion result from CQE dword0
3450+
*/
3451+
struct nvme_sanitize_nvm_args {
3452+
int args_size;
3453+
int fd;
3454+
enum nvme_sanitize_sanact sanact;
3455+
bool ause;
3456+
__u8 owpass;
3457+
bool oipbp;
3458+
bool nodas;
3459+
__u32 ovrpat;
3460+
__u32 timeout;
3461+
__u32 *result;
3462+
};
3463+
3464+
/**
3465+
* nvme_sanitize_nvm() - Start a sanitize operation
3466+
* @args: &struct nvme_sanitize_nvm_args argument structure
34503467
*
34513468
* A sanitize operation alters all user data in the NVM subsystem such that
34523469
* recovery of any previous user data from any cache, the non-volatile media,
@@ -3461,9 +3478,7 @@ int nvme_get_property(struct nvme_get_property_args *args);
34613478
* Return: The nvme command status if a response was received (see
34623479
* &enum nvme_status_field) or -1 with errno set otherwise.
34633480
*/
3464-
int nvme_sanitize_nvm(int fd, enum nvme_sanitize_sanact sanact, bool ause,
3465-
__u8 owpass, bool oipbp, bool nodas, __u32 ovrpat,
3466-
__u32 timeout, __u32 *result);
3481+
int nvme_sanitize_nvm(struct nvme_sanitize_nvm_args *args);
34673482

34683483
/**
34693484
* nvme_dev_self_test() - Start or abort a self test

0 commit comments

Comments
 (0)