diff mbox series

[21/22] aio: utilize io_event->res2 for CQ ring

Message ID 20181221192236.12866-22-axboe@kernel.dk (mailing list archive)
State New, archived
Headers show
Series [01/22] fs: add an iopoll method to struct file_operations | expand

Commit Message

Jens Axboe Dec. 21, 2018, 7:22 p.m. UTC
We don't use this at all, grab it to provide hints about the data.
The first hint we add is IORING_RES2_CACHEHIT, whether a read was
served out of the page cache, or if it hit media. This is useful
for buffered aio, O_DIRECT reads would never have this set (for
obvious reasons).

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 fs/aio.c                     | 7 +++++--
 include/uapi/linux/aio_abi.h | 6 ++++++
 2 files changed, 11 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/fs/aio.c b/fs/aio.c
index 8894c9299b39..a433503a2dc3 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1361,6 +1361,7 @@  static void aio_complete(struct aio_kiocb *iocb, long res, long res2)
 	struct kioctx *ctx = iocb->ki_ctx;
 
 	if (ctx->flags & IOCTX_FLAG_SCQRING) {
+		int nowait = test_bit(KIOCB_F_FORCE_NONBLOCK, &iocb->ki_flags);
 		unsigned long flags;
 		struct io_event *ev;
 		unsigned int tail;
@@ -1372,10 +1373,12 @@  static void aio_complete(struct aio_kiocb *iocb, long res, long res2)
 		 * see it and punt to workqueue. This is just for buffered
 		 * aio reads.
 		 */
-		if (res == -EAGAIN &&
-		    test_bit(KIOCB_F_FORCE_NONBLOCK, &iocb->ki_flags)) {
+		if (res == -EAGAIN && nowait) {
 			ctx->submit_eagain = 1;
 		} else {
+			if (nowait)
+				res2 = IOEV_RES2_CACHEHIT;
+
 			/*
 			 * If we can't get a cq entry, userspace overflowed the
 			 * submission (by quite a lot). Flag it as an overflow
diff --git a/include/uapi/linux/aio_abi.h b/include/uapi/linux/aio_abi.h
index 26173de01fee..809c6f33f5e6 100644
--- a/include/uapi/linux/aio_abi.h
+++ b/include/uapi/linux/aio_abi.h
@@ -66,6 +66,12 @@  struct io_event {
 	__s64		res2;		/* secondary result */
 };
 
+/*
+ * aio CQ ring commandeers the otherwise unused ev->res2 to provide
+ * metadata about the IO.
+ */
+#define IOEV_RES2_CACHEHIT	(1 << 0)	/* IO did not hit media */
+
 /*
  * we always use a 64bit off_t when communicating
  * with userland.  its up to libraries to do the