Skip to content

Commit 3caa403

Browse files
committed
ioctl: introduce force xfer length configuration knob
Some controllers can't handle transfers smaller than 4k size. Introduce an environment variable which allows to force all xfers to 4k. This is not documented on purpose, as it's rather a crude hack we don't want to promote. Signed-off-by: Daniel Wagner <wagi@kernel.org>
1 parent 1dccef2 commit 3caa403

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/nvme/ioctl.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,22 @@ int nvme_get_log(struct nvme_get_log_args *args)
320320
return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
321321
}
322322

323+
static bool force_4k;
324+
325+
__attribute__((constructor))
326+
static void nvme_init_env(void)
327+
{
328+
char *val;
329+
330+
val = getenv("LIBNVME_FORCE_4K");
331+
if (!val)
332+
return;
333+
if (!strcmp(val, "1") ||
334+
!strcasecmp(val, "true") ||
335+
!strncasecmp(val, "enable", 6))
336+
force_4k = true;
337+
}
338+
323339
#ifdef CONFIG_LIBURING
324340
enum {
325341
IO_URING_NOT_AVAILABLE,
@@ -449,6 +465,9 @@ int nvme_get_log_page(int fd, __u32 xfer_len, struct nvme_get_log_args *args)
449465

450466
args->fd = fd;
451467

468+
if (force_4k)
469+
xfer_len = NVME_LOG_PAGE_PDU_SIZE;
470+
452471
#ifdef CONFIG_LIBURING
453472
int n = 0;
454473
struct io_uring ring;
@@ -469,9 +488,13 @@ int nvme_get_log_page(int fd, __u32 xfer_len, struct nvme_get_log_args *args)
469488
* avoids having to check the MDTS value of the controller.
470489
*/
471490
do {
472-
xfer = data_len - offset;
473-
if (xfer > xfer_len)
474-
xfer = xfer_len;
491+
if (!force_4k) {
492+
xfer = data_len - offset;
493+
if (xfer > xfer_len)
494+
xfer = xfer_len;
495+
} else {
496+
xfer = NVME_LOG_PAGE_PDU_SIZE;
497+
}
475498

476499
/*
477500
* Always retain regardless of the RAE parameter until the very

0 commit comments

Comments
 (0)