[PATCH 6/7] add vfs_lseek_nowait()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Hao Xu <howeyxu@xxxxxxxxxxx>

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@xxxxxxxxxxx>
---
 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




[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux