@@ -351,6 +351,19 @@ static int parse_args(int argc, char *argv[], const char *desc,
351351 return 0 ;
352352}
353353
354+ static void setup_transport_handle (struct libnvme_global_ctx * ctx ,
355+ struct libnvme_transport_handle * hdl ,
356+ struct argconfig_commandline_options * opts )
357+ {
358+ libnvme_transport_handle_set_submit_entry (hdl , nvme_submit_entry );
359+ libnvme_transport_handle_set_submit_exit (hdl , nvme_submit_exit );
360+ libnvme_transport_handle_set_decide_retry (hdl , nvme_decide_retry );
361+ libnvme_set_dry_run (ctx , argconfig_parse_seen (opts , "dry-run" ));
362+ if (nvme_args .timeout != NVME_DEFAULT_IOCTL_TIMEOUT ||
363+ argconfig_parse_seen (opts , "timeout" ))
364+ libnvme_transport_handle_set_timeout (hdl , nvme_args .timeout );
365+ }
366+
354367int parse_and_open (struct libnvme_global_ctx * * ctx ,
355368 struct libnvme_transport_handle * * hdl , int argc , char * * argv ,
356369 const char * desc , struct argconfig_commandline_options * opts )
@@ -377,22 +390,18 @@ int parse_and_open(struct libnvme_global_ctx **ctx,
377390 return - ENXIO ;
378391 }
379392
380- libnvme_transport_handle_set_submit_entry (hdl_new , nvme_submit_entry );
381- libnvme_transport_handle_set_submit_exit (hdl_new , nvme_submit_exit );
382- libnvme_transport_handle_set_decide_retry (hdl_new , nvme_decide_retry );
383- 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 );
393+ setup_transport_handle (ctx_new , hdl_new , opts );
387394
388395 * ctx = ctx_new ;
389396 * hdl = hdl_new ;
397+
390398 return 0 ;
391399}
392400
393401int open_exclusive (struct libnvme_global_ctx * * ctx ,
394402 struct libnvme_transport_handle * * hdl , int argc , char * * argv ,
395- int ignore_exclusive )
403+ int ignore_exclusive ,
404+ struct argconfig_commandline_options * opts )
396405{
397406 struct libnvme_transport_handle * hdl_new ;
398407 struct libnvme_global_ctx * ctx_new ;
@@ -412,8 +421,11 @@ int open_exclusive(struct libnvme_global_ctx **ctx,
412421 return - ENXIO ;
413422 }
414423
424+ setup_transport_handle (ctx_new , hdl_new , opts );
425+
415426 * ctx = ctx_new ;
416427 * hdl = hdl_new ;
428+
417429 return 0 ;
418430}
419431
@@ -6606,7 +6618,6 @@ static int format_cmd(int argc, char **argv, struct command *acmd, struct plugin
66066618 __cleanup_free struct nvme_id_ns * ns = NULL ;
66076619 nvme_print_flags_t flags = NORMAL ;
66086620 struct libnvme_passthru_cmd cmd ;
6609- __u32 timeout_ms = 600000 ;
66106621 __u8 prev_lbaf = 0 ;
66116622 int block_size ;
66126623 int err , i ;
@@ -6637,9 +6648,6 @@ static int format_cmd(int argc, char **argv, struct command *acmd, struct plugin
66376648 .bs = 0 ,
66386649 };
66396650
6640- if (nvme_args .timeout != NVME_DEFAULT_IOCTL_TIMEOUT )
6641- timeout_ms = nvme_args .timeout ;
6642-
66436651 NVME_ARGS (opts ,
66446652 OPT_FLAG ("ish" , 'I' , & cfg .ish , ish ),
66456653 OPT_UINT ("namespace-id" , 'n' , & cfg .namespace_id , namespace_id_desired ),
@@ -6652,11 +6660,14 @@ static int format_cmd(int argc, char **argv, struct command *acmd, struct plugin
66526660 OPT_FLAG ("force" , 0 , & cfg .force , force ),
66536661 OPT_SUFFIX ("block-size" , 'b' , & cfg .bs , bs ));
66546662
6663+ /* set default timeout for format to 60 seconds */
6664+ nvme_args .timeout = 600000 ;
6665+
66556666 err = parse_args (argc , argv , desc , opts );
66566667 if (err )
66576668 return err ;
66586669
6659- err = open_exclusive (& ctx , & hdl , argc , argv , cfg .force );
6670+ err = open_exclusive (& ctx , & hdl , argc , argv , cfg .force , opts );
66606671 if (err ) {
66616672 if (- err == EBUSY ) {
66626673 fprintf (stderr , "Failed to open %s.\n" , basename (argv [optind ]));
@@ -6796,7 +6807,6 @@ static int format_cmd(int argc, char **argv, struct command *acmd, struct plugin
67966807
67976808 nvme_init_format_nvm (& cmd , cfg .namespace_id , cfg .lbaf , cfg .mset ,
67986809 cfg .pi , cfg .pil , cfg .ses );
6799- cmd .timeout_ms = timeout_ms ;
68006810 if (cfg .ish ) {
68016811 if (libnvme_transport_handle_is_mi (hdl ))
68026812 nvme_init_mi_cmd_flags (& cmd , ish );
@@ -8434,7 +8444,7 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char
84348444 err = parse_args (argc , argv , desc , opts );
84358445 if (err )
84368446 return err ;
8437- err = open_exclusive (& ctx , & hdl , argc , argv , cfg .force );
8447+ err = open_exclusive (& ctx , & hdl , argc , argv , cfg .force , opts );
84388448 if (err ) {
84398449 if (err == - EBUSY ) {
84408450 fprintf (stderr , "Failed to open %s.\n" , basename (argv [optind ]));
0 commit comments