From: Jens Axboe <[email protected]>
To: [email protected]
Cc: [email protected], [email protected],
Jens Axboe <[email protected]>
Subject: [PATCH 1/3] io_uring: add IORING_OP_FADVISE
Date: Fri, 10 Jan 2020 08:47:37 -0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
This adds support for doing fadvise through io_uring. We assume that
WILLNEED doesn't block, but that DONTNEED may block.
Signed-off-by: Jens Axboe <[email protected]>
---
fs/io_uring.c | 53 +++++++++++++++++++++++++++++++++++
include/uapi/linux/io_uring.h | 2 ++
2 files changed, 55 insertions(+)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 62459a79a61f..0b200a7d4ae0 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -72,6 +72,7 @@
#include <linux/highmem.h>
#include <linux/namei.h>
#include <linux/fsnotify.h>
+#include <linux/fadvise.h>
#define CREATE_TRACE_POINTS
#include <trace/events/io_uring.h>
@@ -400,6 +401,13 @@ struct io_files_update {
u32 offset;
};
+struct io_fadvise {
+ struct file *file;
+ u64 offset;
+ u32 len;
+ u32 advice;
+};
+
struct io_async_connect {
struct sockaddr_storage address;
};
@@ -452,6 +460,7 @@ struct io_kiocb {
struct io_open open;
struct io_close close;
struct io_files_update files_update;
+ struct io_fadvise fadvise;
};
struct io_async_ctx *io;
@@ -669,6 +678,10 @@ static const struct io_op_def io_op_defs[] = {
.needs_file = 1,
.unbound_nonreg_file = 1,
},
+ {
+ /* IORING_OP_FADVISE */
+ .needs_file = 1,
+ },
};
static void io_wq_submit_work(struct io_wq_work **workptr);
@@ -2435,6 +2448,35 @@ static int io_openat(struct io_kiocb *req, struct io_kiocb **nxt,
return 0;
}
+static int io_fadvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
+{
+ if (sqe->ioprio || sqe->buf_index || sqe->addr)
+ return -EINVAL;
+
+ req->fadvise.offset = READ_ONCE(sqe->off);
+ req->fadvise.len = READ_ONCE(sqe->len);
+ req->fadvise.advice = READ_ONCE(sqe->fadvise_advice);
+ return 0;
+}
+
+static int io_fadvise(struct io_kiocb *req, struct io_kiocb **nxt,
+ bool force_nonblock)
+{
+ struct io_fadvise *fa = &req->fadvise;
+ int ret;
+
+ /* DONTNEED may block, others _should_ not */
+ if (fa->advice == POSIX_FADV_DONTNEED && force_nonblock)
+ return -EAGAIN;
+
+ ret = vfs_fadvise(req->file, fa->offset, fa->len, fa->advice);
+ if (ret < 0)
+ req_set_fail_links(req);
+ io_cqring_add_event(req, ret);
+ io_put_req_find_next(req, nxt);
+ return 0;
+}
+
static int io_statx_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
{
unsigned lookup_flags;
@@ -3724,6 +3766,9 @@ static int io_req_defer_prep(struct io_kiocb *req,
case IORING_OP_STATX:
ret = io_statx_prep(req, sqe);
break;
+ case IORING_OP_FADVISE:
+ ret = io_fadvise_prep(req, sqe);
+ break;
default:
printk_once(KERN_WARNING "io_uring: unhandled opcode %d\n",
req->opcode);
@@ -3920,6 +3965,14 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,
}
ret = io_statx(req, nxt, force_nonblock);
break;
+ case IORING_OP_FADVISE:
+ if (sqe) {
+ ret = io_fadvise_prep(req, sqe);
+ if (ret)
+ break;
+ }
+ ret = io_fadvise(req, nxt, force_nonblock);
+ break;
default:
ret = -EINVAL;
break;
diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
index 80f892628e66..f87d8fb42916 100644
--- a/include/uapi/linux/io_uring.h
+++ b/include/uapi/linux/io_uring.h
@@ -36,6 +36,7 @@ struct io_uring_sqe {
__u32 cancel_flags;
__u32 open_flags;
__u32 statx_flags;
+ __u32 fadvise_advice;
};
__u64 user_data; /* data to be passed back at completion time */
union {
@@ -86,6 +87,7 @@ enum {
IORING_OP_STATX,
IORING_OP_READ,
IORING_OP_WRITE,
+ IORING_OP_FADVISE,
/* this goes last, obviously */
IORING_OP_LAST,
--
2.24.1
next prev parent reply other threads:[~2020-01-10 15:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-10 15:47 [PATCHSET 0/3] io_uring: add support for madvise/fadvise Jens Axboe
2020-01-10 15:47 ` Jens Axboe [this message]
2020-01-10 15:47 ` [PATCH 2/3] mm: make do_madvise() available internally Jens Axboe
2020-01-10 15:47 ` [PATCH 3/3] io_uring: add IORING_OP_MADVISE Jens Axboe
2020-01-11 23:10 ` Kirill A. Shutemov
2020-01-12 2:16 ` Jens Axboe
2020-01-12 21:39 ` Pavel Begunkov
2020-01-13 16:58 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox