Skip to content

Commit 987a088

Browse files
committed
ioctl: drop timeout arguments
Introduce a timeout variable to nvme_link that can be adjusted by the user. If the timeout value of the command to be submitted matches the default value, it is overwritten with the nvme_link specific timeout. Signed-off-by: Dennis Maisenbacher <[email protected]>
1 parent f148243 commit 987a088

File tree

8 files changed

+37
-41
lines changed

8 files changed

+37
-41
lines changed

src/nvme/fabrics.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,6 @@ int nvmf_get_discovery_log(nvme_ctrl_t c, struct nvmf_discovery_log **logp,
12251225
struct nvme_get_discovery_args args = {
12261226
.c = c,
12271227
.max_retries = max_retries,
1228-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
12291228
.lsp = NVMF_LOG_DISC_LSP_NONE,
12301229
};
12311230

@@ -1604,7 +1603,6 @@ static int nvmf_dim(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u8 trtype,
16041603
struct nvme_dim_args args = {
16051604
.args_size = sizeof(args),
16061605
.result = result,
1607-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
16081606
.tas = tas
16091607
};
16101608

src/nvme/ioctl.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "util.h"
3131
#include "log.h"
3232
#include "private.h"
33+
#include "linux.h"
3334

3435
static int nvme_verify_chr(nvme_link_t l)
3536
{
@@ -97,6 +98,9 @@ int nvme_submit_passthru64(nvme_link_t l, unsigned long ioctl_cmd,
9798
struct nvme_passthru_cmd64 *cmd,
9899
__u64 *result)
99100
{
101+
if (cmd->timeout_ms == NVME_DEFAULT_IOCTL_TIMEOUT)
102+
cmd->timeout_ms = nvme_link_get_timeout(l);
103+
100104
int err = ioctl(l->fd, ioctl_cmd, cmd);
101105

102106
if (err >= 0 && result)
@@ -110,6 +114,9 @@ __attribute__((weak))
110114
int nvme_submit_passthru(nvme_link_t l, unsigned long ioctl_cmd,
111115
struct nvme_passthru_cmd *cmd, __u32 *result)
112116
{
117+
if (cmd->timeout_ms == NVME_DEFAULT_IOCTL_TIMEOUT)
118+
cmd->timeout_ms = nvme_link_get_timeout(l);
119+
113120
int err = ioctl(l->fd, ioctl_cmd, cmd);
114121

115122
if (err >= 0 && result)
@@ -670,7 +677,6 @@ static int __nvme_get_features(nvme_link_t l, enum nvme_features_id fid,
670677
.uuidx = NVME_UUID_NONE,
671678
.data_len = 0,
672679
.data = NULL,
673-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
674680
.result = result,
675681
};
676682

@@ -701,7 +707,6 @@ int nvme_get_features_lba_range(nvme_link_t l, enum nvme_get_features_sel sel,
701707
.uuidx = NVME_UUID_NONE,
702708
.data = data,
703709
.data_len = sizeof(*data),
704-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
705710
.result = result,
706711
};
707712

@@ -720,7 +725,6 @@ int nvme_get_features_temp_thresh(nvme_link_t l, enum nvme_get_features_sel sel,
720725
.uuidx = NVME_UUID_NONE,
721726
.data_len = 0,
722727
.data = NULL,
723-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
724728
.result = result,
725729
};
726730

@@ -737,7 +741,6 @@ int nvme_get_features_err_recovery(nvme_link_t l, enum nvme_get_features_sel sel
737741
.nsid = nsid,
738742
.sel = sel,
739743
.uuidx = NVME_UUID_NONE,
740-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
741744
.result = result,
742745
};
743746

@@ -775,7 +778,6 @@ int nvme_get_features_irq_config(nvme_link_t l, enum nvme_get_features_sel sel,
775778
.uuidx = NVME_UUID_NONE,
776779
.data_len = 0,
777780
.data = NULL,
778-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
779781
.result = result,
780782
};
781783

@@ -807,7 +809,6 @@ int nvme_get_features_auto_pst(nvme_link_t l, enum nvme_get_features_sel sel,
807809
.uuidx = NVME_UUID_NONE,
808810
.data_len = sizeof(*apst),
809811
.data = apst,
810-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
811812
.result = result,
812813
};
813814

@@ -826,7 +827,6 @@ int nvme_get_features_host_mem_buf(nvme_link_t l, enum nvme_get_features_sel sel
826827
.uuidx = NVME_UUID_NONE,
827828
.data = attrs,
828829
.data_len = sizeof(*attrs),
829-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
830830
.result = result,
831831
};
832832

@@ -845,7 +845,6 @@ int nvme_get_features_timestamp(nvme_link_t l, enum nvme_get_features_sel sel,
845845
.uuidx = NVME_UUID_NONE,
846846
.data_len = sizeof(*ts),
847847
.data = ts,
848-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
849848
.result = NULL,
850849
};
851850

@@ -885,7 +884,6 @@ int nvme_get_features_plm_config(nvme_link_t l, enum nvme_get_features_sel sel,
885884
.uuidx = NVME_UUID_NONE,
886885
.data_len = sizeof(*data),
887886
.data = data,
888-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
889887
.result = result,
890888
};
891889

@@ -904,7 +902,6 @@ int nvme_get_features_plm_window(nvme_link_t l, enum nvme_get_features_sel sel,
904902
.uuidx = NVME_UUID_NONE,
905903
.data_len = 0,
906904
.data = NULL,
907-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
908905
.result = result,
909906
};
910907

@@ -931,7 +928,6 @@ int nvme_get_features_host_behavior(nvme_link_t l, enum nvme_get_features_sel se
931928
.uuidx = NVME_UUID_NONE,
932929
.data_len = sizeof(*data),
933930
.data = data,
934-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
935931
.result = result,
936932
};
937933

@@ -956,7 +952,6 @@ int nvme_get_features_endurance_event_cfg(nvme_link_t l, enum nvme_get_features_
956952
.uuidx = NVME_UUID_NONE,
957953
.data_len = 0,
958954
.data = NULL,
959-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
960955
.result = result,
961956
};
962957

@@ -981,7 +976,6 @@ int nvme_get_features_host_id(nvme_link_t l, enum nvme_get_features_sel sel,
981976
.uuidx = NVME_UUID_NONE,
982977
.data_len = len,
983978
.data = hostid,
984-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
985979
.result = NULL,
986980
};
987981

@@ -997,7 +991,6 @@ int nvme_get_features_resv_mask(nvme_link_t l, enum nvme_get_features_sel sel,
997991
.nsid = nsid,
998992
.sel = sel,
999993
.uuidx = NVME_UUID_NONE,
1000-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
1001994
.result = result,
1002995
};
1003996

@@ -1013,7 +1006,6 @@ int nvme_get_features_resv_persist(nvme_link_t l, enum nvme_get_features_sel sel
10131006
.nsid = nsid,
10141007
.sel = sel,
10151008
.uuidx = NVME_UUID_NONE,
1016-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
10171009
.result = result,
10181010
};
10191011

@@ -1033,7 +1025,6 @@ int nvme_get_features_write_protect(nvme_link_t l, __u32 nsid,
10331025
.uuidx = NVME_UUID_NONE,
10341026
.data_len = 0,
10351027
.data = NULL,
1036-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
10371028
.result = result,
10381029
};
10391030

@@ -1135,7 +1126,6 @@ int nvme_directive_send_id_endir(nvme_link_t l, __u32 nsid, bool endir,
11351126
.cdw12 = cdw12,
11361127
.data_len = sizeof(*id),
11371128
.data = id,
1138-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
11391129
.result = NULL,
11401130
};
11411131

@@ -1887,7 +1877,6 @@ int nvme_lm_get_features_ctrl_data_queue(nvme_link_t l, __u16 cdqid,
18871877
.cdw11 = cdqid,
18881878
.data = data,
18891879
.data_len = sizeof(*data),
1890-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
18911880
.result = result,
18921881
};
18931882

src/nvme/ioctl.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,8 +2245,6 @@ static inline int nvme_set_features(nvme_link_t l, void *data, __u32 nsid,
22452245
.cdw13 = cdw13,
22462246
.cdw14 = cdw14,
22472247
.cdw15 = cdw15,
2248-
//TODO: This should be set via the link object
2249-
.timeout_ms = NVME_DEFAULT_IOCTL_TIMEOUT,
22502248
};
22512249

22522250
return nvme_submit_admin_passthru(l, &cmd, result);
@@ -2871,7 +2869,6 @@ static inline int nvme_get_features_data(nvme_link_t l, enum nvme_features_id fi
28712869
.result = result,
28722870
.data = data,
28732871
.args_size = sizeof(args),
2874-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
28752872
.nsid = nsid,
28762873
.sel = NVME_GET_FEATURES_SEL_CURRENT,
28772874
.cdw11 = 0,
@@ -3652,7 +3649,6 @@ static inline int nvme_directive_send_stream_release_identifier(nvme_link_t l,
36523649
.result = NULL,
36533650
.data = NULL,
36543651
.args_size = sizeof(args),
3655-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
36563652
.nsid = nsid,
36573653
.doper = NVME_DIRECTIVE_SEND_STREAMS_DOPER_RELEASE_IDENTIFIER,
36583654
.dtype = NVME_DIRECTIVE_DTYPE_STREAMS,
@@ -3678,7 +3674,6 @@ static inline int nvme_directive_send_stream_release_resource(nvme_link_t l, __u
36783674
.result = NULL,
36793675
.data = NULL,
36803676
.args_size = sizeof(args),
3681-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
36823677
.nsid = nsid,
36833678
.doper = NVME_DIRECTIVE_SEND_STREAMS_DOPER_RELEASE_RESOURCE,
36843679
.dtype = NVME_DIRECTIVE_DTYPE_STREAMS,
@@ -3716,7 +3711,6 @@ static inline int nvme_directive_recv_identify_parameters(nvme_link_t l, __u32 n
37163711
.result = NULL,
37173712
.data = id,
37183713
.args_size = sizeof(args),
3719-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
37203714
.nsid = nsid,
37213715
.doper = NVME_DIRECTIVE_RECEIVE_IDENTIFY_DOPER_PARAM,
37223716
.dtype = NVME_DIRECTIVE_DTYPE_IDENTIFY,
@@ -3744,7 +3738,6 @@ static inline int nvme_directive_recv_stream_parameters(nvme_link_t l, __u32 nsi
37443738
.result = NULL,
37453739
.data = parms,
37463740
.args_size = sizeof(args),
3747-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
37483741
.nsid = nsid,
37493742
.doper = NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_PARAM,
37503743
.dtype = NVME_DIRECTIVE_DTYPE_STREAMS,
@@ -3779,7 +3772,6 @@ static inline int nvme_directive_recv_stream_status(nvme_link_t l, __u32 nsid,
37793772
.result = NULL,
37803773
.data = id,
37813774
.args_size = sizeof(args),
3782-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
37833775
.nsid = nsid,
37843776
.doper = NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_STATUS,
37853777
.dtype = NVME_DIRECTIVE_DTYPE_STREAMS,
@@ -3808,7 +3800,6 @@ static inline int nvme_directive_recv_stream_allocate(nvme_link_t l, __u32 nsid,
38083800
.result = result,
38093801
.data = NULL,
38103802
.args_size = sizeof(args),
3811-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
38123803
.nsid = nsid,
38133804
.doper = NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_RESOURCE,
38143805
.dtype = NVME_DIRECTIVE_DTYPE_STREAMS,
@@ -4154,7 +4145,6 @@ static inline int nvme_fdp_reclaim_unit_handle_status(nvme_link_t l, __u32 nsid,
41544145
.args_size = sizeof(args),
41554146
.nsid = nsid,
41564147
.data_len = data_len,
4157-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
41584148
.mos = 0,
41594149
.mo = NVME_IO_MGMT_RECV_RUH_STATUS,
41604150
};
@@ -4190,7 +4180,6 @@ static inline int nvme_fdp_reclaim_unit_handle_update(nvme_link_t l, __u32 nsid,
41904180
.args_size = sizeof(args),
41914181
.nsid = nsid,
41924182
.data_len = (__u32)(npids * sizeof(__u16)),
4193-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
41944183
.mos = (__u16)(npids - 1),
41954184
.mo = NVME_IO_MGMT_SEND_RUH_UPDATE,
41964185
};
@@ -4229,7 +4218,6 @@ int nvme_zns_mgmt_recv(nvme_link_t l, struct nvme_zns_mgmt_recv_args *args);
42294218
* @partial: Partial report requested
42304219
* @data_len: Length of the data buffer
42314220
* @data: Userspace address of the report zones data
4232-
* @timeout: timeout in ms
42334221
* @result: The command completion result from CQE dword0
42344222
*
42354223
* Return: 0 on success, the nvme command status if a response was
@@ -4238,15 +4226,13 @@ int nvme_zns_mgmt_recv(nvme_link_t l, struct nvme_zns_mgmt_recv_args *args);
42384226
static inline int nvme_zns_report_zones(nvme_link_t l, __u32 nsid, __u64 slba,
42394227
enum nvme_zns_report_options opts,
42404228
bool extended, bool partial,
4241-
__u32 data_len, void *data,
4242-
__u32 timeout, __u32 *result)
4229+
__u32 data_len, void *data, __u32 *result)
42434230
{
42444231
struct nvme_zns_mgmt_recv_args args = {
42454232
.slba = slba,
42464233
.result = result,
42474234
.data = data,
42484235
.args_size = sizeof(args),
4249-
.timeout = timeout,
42504236
.nsid = nsid,
42514237
.zra = extended ? NVME_ZNS_ZRA_EXTENDED_REPORT_ZONES :
42524238
NVME_ZNS_ZRA_REPORT_ZONES,

src/nvme/linux.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ nvme_link_t __nvme_create_link(nvme_root_t r)
9494
return NULL;
9595

9696
l->root = r;
97+
l->timeout = NVME_DEFAULT_IOCTL_TIMEOUT;
9798

9899
return l;
99100
}
@@ -184,6 +185,16 @@ const char *nvme_link_get_name(nvme_link_t l)
184185
return l->name;
185186
}
186187

188+
__u32 nvme_link_get_timeout(nvme_link_t l)
189+
{
190+
return l->timeout;
191+
}
192+
193+
void nvme_link_set_timeout(nvme_link_t l, __u32 timeout)
194+
{
195+
l->timeout = timeout;
196+
}
197+
187198
int nvme_fw_download_seq(nvme_link_t l, __u32 size, __u32 xfer, __u32 offset,
188199
void *buf)
189200
{
@@ -363,7 +374,6 @@ int nvme_get_lba_status_log(nvme_link_t l, bool rae, struct nvme_lba_status_log
363374
.lsp = NVME_LOG_LSP_NONE,
364375
.lsi = NVME_LOG_LSI_NONE,
365376
.uuidx = NVME_UUID_NONE,
366-
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
367377
.result = NULL,
368378
.csi = NVME_CSI_NVM,
369379
.rae = rae,

src/nvme/linux.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,21 @@ bool nvme_link_is_mi(nvme_link_t l);
251251
*/
252252
const char *nvme_link_get_name(nvme_link_t l);
253253

254+
/**
255+
* nvme_link_get_timeout - Return the command timeout of the device link handle
256+
* @l: Link handle
257+
*
258+
* Return: Command timeout [ms]
259+
*/
260+
__u32 nvme_link_get_timeout(nvme_link_t l);
261+
262+
/**
263+
* nvme_link_set_timeout - Set the command timeout of the device link handle
264+
* @l: Link handle
265+
* @timeout: Timeout in ms
266+
*/
267+
void nvme_link_set_timeout(nvme_link_t l, __u32 timeout);
268+
254269
/**
255270
* enum nvme_hmac_alg - HMAC algorithm
256271
* @NVME_HMAC_ALG_NONE: No HMAC algorithm

src/nvme/private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct nvme_link {
5252
struct list_node ep_entry;
5353

5454
struct nvme_log *log;
55+
__u32 timeout;
5556
};
5657

5758
struct nvme_path {

test/ioctl/zns.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ static void test_zns_report_zones(void)
6060
{
6161
__u8 expected_data[8], data[8] = {};
6262
__u32 result = 0;
63-
uint32_t timeout = 1234;
6463
bool extended = true;
6564
bool partial = true;
6665
enum nvme_zns_report_options opts = NVME_ZNS_ZRAS_REPORT_CLOSED;
@@ -75,7 +74,6 @@ static void test_zns_report_zones(void)
7574
(!!partial << 16),
7675
.data_len = sizeof(expected_data),
7776
.out_data = &expected_data,
78-
.timeout_ms = timeout,
7977
};
8078

8179
int err;
@@ -84,7 +82,7 @@ static void test_zns_report_zones(void)
8482
set_mock_io_cmds(&mock_io_cmd, 1);
8583
err = nvme_zns_report_zones(test_link, TEST_NSID, TEST_SLBA, opts,
8684
extended, partial, sizeof(data), &data,
87-
timeout, &result);
85+
&result);
8886
end_mock_cmds();
8987
check(err == 0, "returned error %d", err);
9088
check(result == 0, "returned result %u", result);

test/zns.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ static void show_zns_properties(nvme_ns_t n)
4848

4949
if (nvme_zns_report_zones(nvme_ns_get_link(n), nvme_ns_get_nsid(n), 0,
5050
NVME_ZNS_ZRAS_REPORT_ALL, false,
51-
true, 0x1000, (void *)zr,
52-
NVME_DEFAULT_IOCTL_TIMEOUT, &result)) {
51+
true, 0x1000, (void *)zr, &result)) {
5352
fprintf(stderr, "failed to report zones, result %x\n",
5453
le32_to_cpu(result));
5554
free(zr);

0 commit comments

Comments
 (0)