Skip to content

Commit 820fa2f

Browse files
darkfiberiruclaude
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). Rather than adding cmd.timeout_ms assignments at every call site, set the timeout once on the transport handle in parse_and_open() and apply it in libnvme_submit_admin_passthru() and libnvme_submit_io_passthru() when the command's own timeout_ms is 0. Commands that set a non-zero timeout_ms (e.g. format's 600s default) are unaffected. This covers all built-in commands, all vendor plugins, and all internal libnvme callers (nvme-cmds.c, tree.c, fabrics.c) without requiring per-call-site changes. libnvme changes: - Add __u32 timeout field to struct libnvme_transport_handle - Add libnvme_transport_handle_set_timeout() public API - Apply handle timeout in submit_admin_passthru/submit_io_passthru - Export new symbol in LIBNVME_4 version section Signed-off-by: Nick Wolff <[email protected]> Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 80d8492 commit 820fa2f

6 files changed

Lines changed: 35 additions & 0 deletions

File tree

libnvme/src/libnvme.ld

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,8 @@ LIBNVME_3 {
196196
local:
197197
*;
198198
};
199+
200+
LIBNVME_4 {
201+
global:
202+
libnvme_transport_handle_set_timeout;
203+
} LIBNVME_3;

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(
230+
struct libnvme_transport_handle *hdl, __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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ struct libnvme_transport_handle {
150150
bool (*decide_retry)(struct libnvme_transport_handle *hdl,
151151
struct libnvme_passthru_cmd *cmd, int err);
152152

153+
__u32 timeout;
154+
153155
/* direct */
154156
int fd;
155157
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)