[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230726102603.155522-7-hao.xu@linux.dev>
Date: Wed, 26 Jul 2023 18:26:02 +0800
From: Hao Xu <hao.xu@...ux.dev>
To: io-uring@...r.kernel.org, Jens Axboe <axboe@...nel.dk>
Cc: Dominique Martinet <asmadeus@...ewreck.org>,
Pavel Begunkov <asml.silence@...il.com>,
Christian Brauner <brauner@...nel.org>,
Alexander Viro <viro@...iv.linux.org.uk>,
Stefan Roesch <shr@...com>, Clay Harris <bugs@...ycon.org>,
Dave Chinner <david@...morbit.com>,
"Darrick J . Wong" <djwong@...nel.org>,
linux-fsdevel@...r.kernel.org, linux-xfs@...r.kernel.org,
linux-ext4@...r.kernel.org, Wanpeng Li <wanpengli@...cent.com>
Subject: [PATCH 6/7] add vfs_lseek_nowait()
From: Hao Xu <howeyxu@...cent.com>
Add a new vfs wrapper for io_uring lseek usage. The reason is the
current vfs_lseek() calls llseek() but what we need is llseek_nowait().
Signed-off-by: Hao Xu <howeyxu@...cent.com>
---
fs/read_write.c | 18 ++++++++++++++++++
include/linux/fs.h | 3 +++
2 files changed, 21 insertions(+)
diff --git a/fs/read_write.c b/fs/read_write.c
index b07de77ef126..b4c3bcf706e2 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -290,6 +290,24 @@ loff_t vfs_llseek(struct file *file, loff_t offset, int whence)
}
EXPORT_SYMBOL(vfs_llseek);
+loff_t vfs_lseek_nowait(struct file *file, off_t offset,
+ int whence, bool nowait)
+{
+ if (!(file->f_mode & FMODE_LSEEK))
+ return -ESPIPE;
+ /*
+ * This function is only used by io_uring, thus
+ * returning -ENOTSUPP is not proper since doing
+ * nonblock lseek as the first try is asked internally
+ * by io_uring not by users. Return -ENOTSUPP to users
+ * is not sane.
+ */
+ if (!file->f_op->llseek_nowait)
+ return -EAGAIN;
+ return file->f_op->llseek_nowait(file, offset, whence, nowait);
+}
+EXPORT_SYMBOL(vfs_lseek_nowait);
+
static off_t ksys_lseek(unsigned int fd, off_t offset, unsigned int whence)
{
off_t retval;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index d37290da2d7e..cb804d1f1650 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2654,6 +2654,9 @@ extern loff_t default_llseek(struct file *file, loff_t offset, int whence);
extern loff_t vfs_llseek(struct file *file, loff_t offset, int whence);
+extern loff_t vfs_lseek_nowait(struct file *file, off_t offset,
+ int whence, bool nowait);
+
extern int inode_init_always(struct super_block *, struct inode *);
extern void inode_init_once(struct inode *);
extern void address_space_init_once(struct address_space *mapping);
--
2.25.1
Powered by blists - more mailing lists