From 128083ec42f5cab5a107142b3c34b5103c9cdfd8 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Tue, 22 Mar 2022 15:24:29 -0700 Subject: [PATCH] spdk_dd: If both input and output are block devices, use IORING_SETUP_IOPOLL Change-Id: Ie1ab8ab896ce0d2e41290645bf3ee275e1a5c578 Signed-off-by: Ben Walker Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12022 Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Tested-by: SPDK CI Jenkins --- app/spdk_dd/spdk_dd.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/app/spdk_dd/spdk_dd.c b/app/spdk_dd/spdk_dd.c index 7fce247e2..22678eb61 100644 --- a/app/spdk_dd/spdk_dd.c +++ b/app/spdk_dd/spdk_dd.c @@ -724,6 +724,20 @@ parse_flags(char *file_flags) return flags; } +#ifdef SPDK_CONFIG_URING +static bool +dd_is_blk(int fd) +{ + struct stat st; + + if (fstat(fd, &st) != 0) { + return false; + } + + return S_ISBLK(st.st_mode); +} +#endif + static void dd_run(void *arg1) { @@ -840,8 +854,17 @@ dd_run(void *arg1) if (g_opts.input_file || g_opts.output_file) { #ifdef SPDK_CONFIG_URING if (g_opts.aio == false) { + unsigned int io_uring_flags = IORING_SETUP_SQPOLL; + int flags = parse_flags(g_opts.input_file_flags) & parse_flags(g_opts.output_file_flags); + + if ((flags & O_DIRECT) != 0 && + dd_is_blk(g_job.input.u.uring.fd) && + dd_is_blk(g_job.output.u.uring.fd)) { + io_uring_flags = IORING_SETUP_IOPOLL; + } + g_job.u.uring.poller = spdk_poller_register(dd_uring_poll, NULL, 0); - rc = io_uring_queue_init(g_opts.queue_depth * 2, &g_job.u.uring.ring, IORING_SETUP_SQPOLL); + rc = io_uring_queue_init(g_opts.queue_depth * 2, &g_job.u.uring.ring, io_uring_flags); if (rc) { SPDK_ERRLOG("Failed to create io_uring: %d (%s)\n", rc, spdk_strerror(-rc)); dd_exit(rc);