Skip to content

Commit 7fcee0a

Browse files
calebsanderigaw
authored andcommitted
ioctl: pass data for Get/Set Features commands
Several nvme_{g,s}et_features_*() functions take a data buffer but don't provide it to the Get/Set Features commands. Fix them to pass the data buffer to nvme_{g,s}et_features(). Getting the Host Memory Buffer feature also returns a struct nvme_host_mem_buf_attrs data structure, so make a nvme_get_features_host_mem_buf2() function that takes in a data buffer to receive it. Signed-off-by: Caleb Sander <[email protected]>
1 parent 87cf460 commit 7fcee0a

3 files changed

Lines changed: 64 additions & 14 deletions

File tree

src/libnvme.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LIBNVME_1_6 {
55
nvme_ctrl_find;
66
nvme_ctrl_get_src_addr;
77
nvme_ctrl_release_fd;
8+
nvme_get_features_host_mem_buf2;
89
nvme_host_release_fds;
910
nvme_ns_release_fd;
1011
nvme_root_release_fds;

src/nvme/ioctl.c

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -665,10 +665,21 @@ int nvme_set_features_async_event(int fd, __u32 events,
665665
int nvme_set_features_auto_pst(int fd, bool apste, bool save,
666666
struct nvme_feat_auto_pst *apst, __u32 *result)
667667
{
668-
__u32 value = NVME_SET(!!apste, FEAT_APST_APSTE);
668+
struct nvme_set_features_args args = {
669+
.args_size = sizeof(args),
670+
.fd = fd,
671+
.fid = NVME_FEAT_FID_AUTO_PST,
672+
.nsid = NVME_NSID_NONE,
673+
.cdw11 = NVME_SET(!!apste, FEAT_APST_APSTE),
674+
.save = save,
675+
.uuidx = NVME_UUID_NONE,
676+
.data = apst,
677+
.data_len = sizeof(*apst),
678+
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
679+
.result = result,
680+
};
669681

670-
return __nvme_set_features(fd, NVME_FEAT_FID_AUTO_PST, value, save,
671-
result);
682+
return nvme_set_features(&args);
672683
}
673684

674685
int nvme_set_features_timestamp(int fd, bool save, __u64 timestamp)
@@ -748,8 +759,8 @@ int nvme_set_features_plm_config(int fd, bool plm, __u16 nvmsetid, bool save,
748759
.save = save,
749760
.uuidx = NVME_UUID_NONE,
750761
.cdw15 = 0,
751-
.data_len = 0,
752-
.data = NULL,
762+
.data_len = sizeof(*data),
763+
.data = data,
753764
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
754765
.result = result,
755766
};
@@ -952,8 +963,8 @@ int nvme_get_features_lba_range(int fd, enum nvme_get_features_sel sel,
952963
.sel = sel,
953964
.cdw11 = 0,
954965
.uuidx = NVME_UUID_NONE,
955-
.data_len = 0,
956-
.data = NULL,
966+
.data_len = sizeof(*data),
967+
.data = data,
957968
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
958969
.result = result,
959970
};
@@ -1037,8 +1048,8 @@ int nvme_get_features_auto_pst(int fd, enum nvme_get_features_sel sel,
10371048
.sel = sel,
10381049
.cdw11 = 0,
10391050
.uuidx = NVME_UUID_NONE,
1040-
.data_len = 0,
1041-
.data = NULL,
1051+
.data_len = sizeof(*apst),
1052+
.data = apst,
10421053
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
10431054
.result = result,
10441055
};
@@ -1052,6 +1063,26 @@ int nvme_get_features_host_mem_buf(int fd, enum nvme_get_features_sel sel,
10521063
return __nvme_get_features(fd, NVME_FEAT_FID_HOST_MEM_BUF, sel, result);
10531064
}
10541065

1066+
int nvme_get_features_host_mem_buf2(int fd, enum nvme_get_features_sel sel,
1067+
struct nvme_host_mem_buf_attrs *attrs,
1068+
__u32 *result)
1069+
{
1070+
struct nvme_get_features_args args = {
1071+
.args_size = sizeof(args),
1072+
.fd = fd,
1073+
.fid = NVME_FEAT_FID_HOST_MEM_BUF,
1074+
.nsid = NVME_NSID_NONE,
1075+
.sel = sel,
1076+
.uuidx = NVME_UUID_NONE,
1077+
.data = attrs,
1078+
.data_len = sizeof(*attrs),
1079+
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
1080+
.result = result,
1081+
};
1082+
1083+
return nvme_get_features(&args);
1084+
}
1085+
10551086
int nvme_get_features_timestamp(int fd, enum nvme_get_features_sel sel,
10561087
struct nvme_timestamp *ts)
10571088
{
@@ -1104,8 +1135,8 @@ int nvme_get_features_plm_config(int fd, enum nvme_get_features_sel sel,
11041135
.sel = sel,
11051136
.cdw11 = nvmsetid,
11061137
.uuidx = NVME_UUID_NONE,
1107-
.data_len = 0,
1108-
.data = NULL,
1138+
.data_len = sizeof(*data),
1139+
.data = data,
11091140
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
11101141
.result = result,
11111142
};
@@ -1152,8 +1183,8 @@ int nvme_get_features_host_behavior(int fd, enum nvme_get_features_sel sel,
11521183
.sel = sel,
11531184
.cdw11 = 0,
11541185
.uuidx = NVME_UUID_NONE,
1155-
.data_len = 0,
1156-
.data = NULL,
1186+
.data_len = sizeof(*data),
1187+
.data = data,
11571188
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
11581189
.result = result,
11591190
};

src/nvme/ioctl.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2758,6 +2758,10 @@ int nvme_get_features_auto_pst(int fd, enum nvme_get_features_sel sel,
27582758

27592759
/**
27602760
* nvme_get_features_host_mem_buf() - Get host memory buffer feature
2761+
*
2762+
* Deprecated: doesn't fetch the Host Memory Buffer Attributes data structure.
2763+
* Use nvme_get_features_host_mem_buf2() instead.
2764+
*
27612765
* @fd: File descriptor of nvme device
27622766
* @sel: Select which type of attribute to return, see &enum nvme_get_features_sel
27632767
* @result: The command completion result from CQE dword0
@@ -2766,7 +2770,21 @@ int nvme_get_features_auto_pst(int fd, enum nvme_get_features_sel sel,
27662770
* &enum nvme_status_field) or -1 with errno set otherwise.
27672771
*/
27682772
int nvme_get_features_host_mem_buf(int fd, enum nvme_get_features_sel sel,
2769-
__u32 *result);
2773+
__u32 *result) __attribute__((deprecated));
2774+
2775+
/**
2776+
* nvme_get_features_host_mem_buf2() - Get host memory buffer feature
2777+
* @fd: File descriptor of nvme device
2778+
* @sel: Select which type of attribute to return, see &enum nvme_get_features_sel
2779+
* @attrs: Buffer for returned Host Memory Buffer Attributes
2780+
* @result: The command completion result from CQE dword0
2781+
*
2782+
* Return: The nvme command status if a response was received (see
2783+
* &enum nvme_status_field) or -1 with errno set otherwise.
2784+
*/
2785+
int nvme_get_features_host_mem_buf2(int fd, enum nvme_get_features_sel sel,
2786+
struct nvme_host_mem_buf_attrs *attrs,
2787+
__u32 *result);
27702788

27712789
/**
27722790
* nvme_get_features_timestamp() - Get timestamp feature

0 commit comments

Comments
 (0)