From: "Ritesh Harjani (IBM)" <ritesh.list@gmail.com>
To: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org
Cc: Jan Kara <jack@suse.cz>, Christoph Hellwig <hch@infradead.org>,
"Darrick J . Wong" <djwong@kernel.org>,
Ojaswin Mujoo <ojaswin@linux.ibm.com>,
"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>
Subject: [RFCv2 2/8] libfs: Add __generic_file_fsync_nolock implementation
Date: Tue, 11 Apr 2023 10:51:50 +0530 [thread overview]
Message-ID: <6fad2ec25bccbbb9b3effbd18c2d6d6965b9a33c.1681188927.git.ritesh.list@gmail.com> (raw)
In-Reply-To: <cover.1681188927.git.ritesh.list@gmail.com>
Some of the higher layers like iomap takes inode_lock() when calling
generic_write_sync().
Also writeback already happens from other paths without inode lock,
so it's difficult to say that we really need sync_mapping_buffers() to
take any inode locking here. Having said that, let's add a _nolock
variant of this function in libfs for now so that filesystems like
ext2 and ext4's nojournal mode can use it.
Ext4 when got converted to iomap for direct-io already copied it's own
variant of __generic_file_fsync() without lock. Hence let's add a helper
API and use it both in ext2 and ext4.
Later we can review other filesystems as well to see if we can make
_nolock as the default path if inode_lock() is not necessary here.
Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
---
fs/libfs.c | 43 +++++++++++++++++++++++++++++++++++++++++++
include/linux/fs.h | 1 +
2 files changed, 44 insertions(+)
diff --git a/fs/libfs.c b/fs/libfs.c
index 4eda519c3002..d2dfb72e3cf8 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -1110,6 +1110,49 @@ struct dentry *generic_fh_to_parent(struct super_block *sb, struct fid *fid,
}
EXPORT_SYMBOL_GPL(generic_fh_to_parent);
+/**
+ * __generic_file_fsync_nolock - generic fsync implementation for simple
+ * filesystems with no inode lock
+ *
+ * @file: file to synchronize
+ * @start: start offset in bytes
+ * @end: end offset in bytes (inclusive)
+ * @datasync: only synchronize essential metadata if true
+ *
+ * This is a generic implementation of the fsync method for simple
+ * filesystems which track all non-inode metadata in the buffers list
+ * hanging off the address_space structure.
+ */
+int __generic_file_fsync_nolock(struct file *file, loff_t start, loff_t end,
+ int datasync)
+{
+ struct inode *inode = file->f_mapping->host;
+ int err;
+ int ret;
+
+ err = file_write_and_wait_range(file, start, end);
+ if (err)
+ return err;
+
+ ret = sync_mapping_buffers(inode->i_mapping);
+ if (!(inode->i_state & I_DIRTY_ALL))
+ goto out;
+ if (datasync && !(inode->i_state & I_DIRTY_DATASYNC))
+ goto out;
+
+ err = sync_inode_metadata(inode, 1);
+ if (ret == 0)
+ ret = err;
+
+out:
+ /* check and advance again to catch errors after syncing out buffers */
+ err = file_check_and_advance_wb_err(file);
+ if (ret == 0)
+ ret = err;
+ return ret;
+}
+EXPORT_SYMBOL(__generic_file_fsync_nolock);
+
/**
* __generic_file_fsync - generic fsync implementation for simple filesystems
*
diff --git a/include/linux/fs.h b/include/linux/fs.h
index c85916e9f7db..21d2b5670308 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2935,6 +2935,7 @@ extern ssize_t simple_read_from_buffer(void __user *to, size_t count,
extern ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos,
const void __user *from, size_t count);
+extern int __generic_file_fsync_nolock(struct file *, loff_t, loff_t, int);
extern int __generic_file_fsync(struct file *, loff_t, loff_t, int);
extern int generic_file_fsync(struct file *, loff_t, loff_t, int);
--
2.39.2
next prev parent reply other threads:[~2023-04-11 5:22 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-11 5:21 [RFCv2 0/8] ext2: DIO to use iomap Ritesh Harjani (IBM)
2023-04-11 5:21 ` [RFCv2 1/8] ext2/dax: Fix ext2_setsize when len is page aligned Ritesh Harjani (IBM)
2023-04-11 14:29 ` Darrick J. Wong
2023-04-11 5:21 ` Ritesh Harjani (IBM) [this message]
2023-04-11 5:27 ` [RFCv2 2/8] libfs: Add __generic_file_fsync_nolock implementation Christoph Hellwig
2023-04-11 12:33 ` Matthew Wilcox
2023-04-11 15:12 ` Ritesh Harjani
2023-04-12 11:43 ` Christoph Hellwig
2023-04-12 14:02 ` Ritesh Harjani
2023-04-13 9:51 ` Christian Brauner
2023-04-11 5:21 ` [RFCv2 3/8] ext4: Use " Ritesh Harjani (IBM)
2023-04-11 5:21 ` [RFCv2 4/8] ext2: " Ritesh Harjani (IBM)
2023-04-11 5:21 ` [RFCv2 5/8] ext2: Move direct-io to use iomap Ritesh Harjani (IBM)
2023-04-11 5:46 ` Christoph Hellwig
2023-04-11 15:21 ` Ritesh Harjani
2023-04-12 11:43 ` Christoph Hellwig
2023-04-12 14:03 ` Ritesh Harjani
2023-04-11 5:21 ` [RFCv2 6/8] iomap: Remove IOMAP_DIO_NOSYNC unused dio flag Ritesh Harjani (IBM)
2023-04-11 5:27 ` Christoph Hellwig
2023-04-11 5:21 ` [RFCv2 7/8] fs.h: Add IOCB_STRINGS for use in trace points Ritesh Harjani (IBM)
2023-04-11 5:38 ` Christoph Hellwig
2023-04-11 5:21 ` [RFCv2 8/8] ext2: Add direct-io " Ritesh Harjani (IBM)
2023-04-11 5:38 ` Christoph Hellwig
2023-04-11 14:34 ` Darrick J. Wong
2023-04-11 15:11 ` Ritesh Harjani
2023-04-12 11:44 ` Christoph Hellwig
2023-04-12 14:07 ` Ritesh Harjani
2023-04-12 11:45 ` [RFCv2 0/8] ext2: DIO to use iomap Jan Kara
2023-04-12 14:10 ` Ritesh Harjani
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 \
--in-reply-to=6fad2ec25bccbbb9b3effbd18c2d6d6965b9a33c.1681188927.git.ritesh.list@gmail.com \
--to=ritesh.list@gmail.com \
--cc=djwong@kernel.org \
--cc=hch@infradead.org \
--cc=jack@suse.cz \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=ojaswin@linux.ibm.com \
/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;
as well as URLs for NNTP newsgroup(s).