Skip to content

Commit 3a72d66

Browse files
committed
linux: add possibility to disable IOCTL probing
blktests nvme/039 is assuming that the first ioctl issued is the expected IO passthru. Though the recent introduce ioctl probing breaks the tests. One could argue that the test should be made more robust but it's probably a good idea to have a way to disable this feature anyway. The obvious to way to implement this feature is to add a flag argument to nvme_open. This works for all nvme commands but not for the nvmf because under the hood new transport handles are created when necessary. Since this is a global flag anyway, add it to the global context. Signed-off-by: Daniel Wagner <[email protected]>
1 parent bf3c146 commit 3a72d66

7 files changed

Lines changed: 34 additions & 5 deletions

File tree

libnvme/src/libnvme.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ LIBNVME_2_0 {
229229
nvme_set_application;
230230
nvme_set_dry_run;
231231
nvme_set_etdas;
232+
nvme_set_ioctl_probing;
232233
nvme_set_keyring;
233234
nvme_set_property;
234235
nvme_set_root;

libnvme/src/nvme/linux.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ void nvme_set_dry_run(struct nvme_global_ctx *ctx, bool enable)
4646
ctx->dry_run = enable;
4747
}
4848

49+
void nvme_set_ioctl_probing(struct nvme_global_ctx *ctx, bool enable)
50+
{
51+
ctx->ioctl_probing = enable;
52+
}
53+
4954
void nvme_transport_handle_set_submit_entry(struct nvme_transport_handle *hdl,
5055
void *(*submit_entry)(struct nvme_transport_handle *hdl,
5156
struct nvme_passthru_cmd *cmd))
@@ -108,9 +113,11 @@ static int __nvme_transport_handle_open_direct(struct nvme_transport_handle *hdl
108113
return -EINVAL;
109114
}
110115

111-
ret = ioctl(hdl->fd, NVME_IOCTL_ADMIN64_CMD, &dummy);
112-
if (ret > 0)
113-
hdl->ioctl64 = true;
116+
if (hdl->ctx->ioctl_probing) {
117+
ret = ioctl(hdl->fd, NVME_IOCTL_ADMIN64_CMD, &dummy);
118+
if (ret > 0)
119+
hdl->ioctl64 = true;
120+
}
114121

115122
return 0;
116123
}

libnvme/src/nvme/linux.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,4 +742,16 @@ int nvme_import_tls_key_versioned(struct nvme_global_ctx *ctx,
742742
*/
743743
void nvme_set_dry_run(struct nvme_global_ctx *ctx, bool enable);
744744

745+
/**
746+
* nvme_set_ioctl_probing() - Enable/disable 64-bit IOCTL probing
747+
* @ctx: struct nvme_global_ctx object
748+
* @enable: Enable/disable 64-bit IOCTL probing
749+
*
750+
* When IOCTL probing is enabled, a 64-bit IOCTL command is issued to
751+
* figure out if the passthru interface supports it.
752+
*
753+
* IOCTL probing is enabled per default.
754+
*/
755+
void nvme_set_ioctl_probing(struct nvme_global_ctx *ctx, bool enable);
756+
745757
#endif /* _LIBNVME_LINUX_H */

libnvme/src/nvme/private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ struct nvme_global_ctx {
272272
struct list_head hosts;
273273
struct nvme_log log;
274274
bool mi_probe_enabled;
275+
bool ioctl_probing;
275276
bool create_only;
276277
bool dry_run;
277278
struct nvme_fabric_options *options;

libnvme/src/nvme/tree.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ struct nvme_global_ctx *nvme_create_global_ctx(FILE *fp, int log_level)
335335
int fd;
336336

337337
ctx = calloc(1, sizeof(*ctx));
338-
if (!ctx)
338+
if (!ctx)
339339
return NULL;
340340

341341
if (fp) {
@@ -353,6 +353,8 @@ struct nvme_global_ctx *nvme_create_global_ctx(FILE *fp, int log_level)
353353
list_head_init(&ctx->hosts);
354354
list_head_init(&ctx->endpoints);
355355

356+
ctx->ioctl_probing = true;
357+
356358
return ctx;
357359
}
358360

nvme.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@ int parse_and_open(struct nvme_global_ctx **ctx,
396396
if (!ctx_new)
397397
return -ENOMEM;
398398

399+
nvme_set_ioctl_probing(ctx_new,
400+
!argconfig_parse_seen(opts, "no-ioctl-probing"));
401+
399402
ret = get_transport_handle(ctx_new, argc, argv, O_RDONLY, &hdl_new);
400403
if (ret) {
401404
nvme_free_global_ctx(ctx_new);

nvme.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct nvme_config {
5858
__u32 timeout;
5959
bool dry_run;
6060
bool no_retries;
61+
bool no_ioctl_probing;
6162
unsigned int output_format_ver;
6263
};
6364

@@ -73,7 +74,9 @@ struct nvme_config {
7374
OPT_UINT("timeout", 't', &nvme_cfg.timeout, timeout), \
7475
OPT_FLAG("dry-run", 0, &nvme_cfg.dry_run, dry_run), \
7576
OPT_FLAG("no-retries", 0, &nvme_cfg.no_retries, \
76-
"disable retry logic on errors\n"), \
77+
"disable retry logic on errors"), \
78+
OPT_FLAG("no-ioctl-probing", 0, &nvme_cfg.no_ioctl_probing, \
79+
"disable 64-bit IOCTL support probing"), \
7780
OPT_UINT("output-format-version", 0, &nvme_cfg.output_format_ver, \
7881
"output format version: 1|2"), \
7982
OPT_END() \

0 commit comments

Comments
 (0)