From c386f64819895165472538884e6e64bc6d32eff9 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 24 Feb 2019 06:05:07 +0000 Subject: [PATCH] vdisk_fileio, async mode: Submit direct I/O with the "nowait" flag set git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7987 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/backport.h | 8 ++++++++ scst/src/dev_handlers/scst_vdisk.c | 21 ++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/scst/include/backport.h b/scst/include/backport.h index ca0d60682..8011d4921 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -434,6 +434,14 @@ static inline ssize_t call_write_iter(struct file *file, struct kiocb *kio, } #endif +/* + * See also commit b745fafaf70c ("fs: Introduce RWF_NOWAIT and + * FMODE_AIO_NOWAIT") # v4.13. + */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 13, 0) +#define IOCB_NOWAIT 0 +#endif + /* See also commit bdd1d2d3d251 ("fs: fix kernel_read prototype") # v4.14 */ #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0) static inline ssize_t diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index d208babc8..a6ed3fdf5 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -3303,13 +3303,20 @@ static enum compl_status_e fileio_exec_async(struct vdisk_cmd_params *p) .ki_complete = fileio_async_complete, }; if (virt_dev->o_direct_flag) - iocb->ki_flags |= IOCB_DIRECT; - if (dir == WRITE) { - if (virt_dev->wt_flag && !virt_dev->nv_cache) - iocb->ki_flags |= IOCB_DSYNC; - ret = call_write_iter(fd, iocb, &iter); - } else { - ret = call_read_iter(fd, iocb, &iter); + iocb->ki_flags |= IOCB_DIRECT | IOCB_NOWAIT; + if (dir == WRITE && virt_dev->wt_flag && !virt_dev->nv_cache) + iocb->ki_flags |= IOCB_DSYNC; + for (;;) { + if (dir == WRITE) + ret = call_write_iter(fd, iocb, &iter); + else + ret = call_read_iter(fd, iocb, &iter); + if (ret >= 0 || (ret != -EOPNOTSUPP && ret != -EAGAIN)) + break; + if (iocb->ki_flags & IOCB_NOWAIT) + iocb->ki_flags &= ~IOCB_NOWAIT; + else + break; } if (p->async.bvec != p->async.small_bvec) kfree(p->async.bvec);