Skip to content

Commit 3fe7c82

Browse files
darkfiberiruclaude
authored andcommitted
nvme: apply user-specified timeout via transport handle
The --timeout / -t flag is parsed into nvme_args.timeout but was only honored by format-nvm and admin-passthru. All other commands left cmd.timeout_ms at 0 (set by nvme_init_*() helpers), silently falling back to the kernel's admin_timeout (60s). Signed-off-by: Nick Wolff <[email protected]> Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent bed896f commit 3fe7c82

6 files changed

Lines changed: 32 additions & 0 deletions

File tree

libnvme/src/libnvme.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ LIBNVME_3 {
188188
libnvme_transport_handle_set_decide_retry;
189189
libnvme_transport_handle_set_submit_entry;
190190
libnvme_transport_handle_set_submit_exit;
191+
libnvme_transport_handle_set_timeout;
191192
libnvme_unlink_ctrl;
192193
libnvme_update_block_size;
193194
libnvme_update_key;

libnvme/src/nvme/ioctl.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ static int libnvme_submit_passthru64(struct libnvme_transport_handle *hdl,
193193
__public int libnvme_submit_io_passthru(struct libnvme_transport_handle *hdl,
194194
struct libnvme_passthru_cmd *cmd)
195195
{
196+
if (!cmd->timeout_ms && hdl->timeout)
197+
cmd->timeout_ms = hdl->timeout;
198+
196199
if (hdl->ioctl_io64)
197200
return libnvme_submit_passthru64(hdl,
198201
LIBNVME_IOCTL_IO64_CMD, cmd);
@@ -202,6 +205,9 @@ __public int libnvme_submit_io_passthru(struct libnvme_transport_handle *hdl,
202205
__public int libnvme_submit_admin_passthru(struct libnvme_transport_handle *hdl,
203206
struct libnvme_passthru_cmd *cmd)
204207
{
208+
if (!cmd->timeout_ms && hdl->timeout)
209+
cmd->timeout_ms = hdl->timeout;
210+
205211
switch (hdl->type) {
206212
case LIBNVME_TRANSPORT_HANDLE_TYPE_DIRECT:
207213
if (hdl->ioctl_admin64)

libnvme/src/nvme/lib.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ __public void libnvme_transport_handle_set_decide_retry(struct libnvme_transport
137137
hdl->decide_retry = __libnvme_decide_retry;
138138
}
139139

140+
__public void libnvme_transport_handle_set_timeout(
141+
struct libnvme_transport_handle *hdl, __u32 timeout_ms)
142+
{
143+
hdl->timeout = timeout_ms;
144+
}
145+
140146
static int __nvme_transport_handle_open_direct(
141147
struct libnvme_transport_handle *hdl, const char *devname)
142148
{

libnvme/src/nvme/lib.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,19 @@ void libnvme_transport_handle_set_decide_retry(
216216
bool (*decide_retry)(struct libnvme_transport_handle *hdl,
217217
struct libnvme_passthru_cmd *cmd, int err));
218218

219+
/**
220+
* libnvme_transport_handle_set_timeout() - Set the default command timeout
221+
* @hdl: Transport handle to configure
222+
* @timeout_ms: Timeout in milliseconds. A value of 0 means use the kernel
223+
* default (NVME_DEFAULT_IOCTL_TIMEOUT).
224+
*
225+
* Sets a default timeout that is applied to every passthrough command
226+
* submitted through @hdl when the command's own timeout_ms field is 0.
227+
* Commands that set a non-zero timeout_ms override this default.
228+
*/
229+
void libnvme_transport_handle_set_timeout(struct libnvme_transport_handle *hdl,
230+
__u32 timeout_ms);
231+
219232
/**
220233
* libnvme_set_probe_enabled() - enable/disable the probe for new MI endpoints
221234
* @ctx: &struct libnvme_global_ctx object

libnvme/src/nvme/private.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ struct libnvme_transport_handle {
150150
bool (*decide_retry)(struct libnvme_transport_handle *hdl,
151151
struct libnvme_passthru_cmd *cmd, int err);
152152

153+
/* global command timeout */
154+
__u32 timeout;
155+
153156
/* direct */
154157
int fd;
155158
struct stat stat;

nvme.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,9 @@ int parse_and_open(struct libnvme_global_ctx **ctx,
381381
libnvme_transport_handle_set_submit_exit(hdl_new , nvme_submit_exit);
382382
libnvme_transport_handle_set_decide_retry(hdl_new, nvme_decide_retry);
383383
libnvme_set_dry_run(ctx_new, argconfig_parse_seen(opts, "dry-run"));
384+
if (argconfig_parse_seen(opts, "timeout"))
385+
libnvme_transport_handle_set_timeout(hdl_new,
386+
nvme_args.timeout);
384387

385388
*ctx = ctx_new;
386389
*hdl = hdl_new;

0 commit comments

Comments
 (0)