mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: Miklos Szeredi <miklos@szeredi.hu>,
	Amir Goldstein <amir73il@gmail.com>,
	 Christian Brauner <brauner@kernel.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
	 Christoph Hellwig <hch@infradead.org>,
	Chris Mason <mason@kernel.org>,
	 Chengguang Xu <cgxu519@mykernel.net>,
	linux-unionfs@vger.kernel.org,  linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org,  Josef Bacik <josef@toxicpanda.com>
Subject: [PATCH v7 4/7] fs: add write_inode_for_sync()
Date: Wed, 18 Nov 2026 17:03:27 +0000	[thread overview]
Message-ID: <20261118-b4-ovl-containerized-sync-v7-4-54f45743fe55@toxicpanda.com> (raw)
In-Reply-To: <20261118-b4-ovl-containerized-sync-v7-0-54f45743fe55@toxicpanda.com>

sync_inodes_sb() has the flusher write every dirty inode of a superblock
with WB_SYNC_ALL and for_sync set.  That writes the pages without waiting
for them, hands over the timestamps that lazytime has deferred while it
holds I_SYNC, and calls ->write_inode() in a way that tells the filesystem
that ->sync_fs() follows, so ext4 does not commit a transaction for every
inode.

overlayfs is about to sync some of the inodes of its upper filesystem, and
none of the exported functions does that for one inode.  write_inode_now()
and sync_inode_metadata() either do not wait for somebody else who is
writing the inode and leave deferred timestamps alone, or they wait for the
pages, clear the error flags of the mapping and make ext4 commit.

Add a function that writes one inode the way a sync does.

Nothing calls it yet.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/fs-writeback.c       | 36 ++++++++++++++++++++++++++++++++++++
 include/linux/pagemap.h |  1 +
 2 files changed, 37 insertions(+)

diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 15260cf2a29b..d265466f12a8 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -3103,6 +3103,42 @@ int write_inode_now(struct inode *inode, int sync)
 }
 EXPORT_SYMBOL(write_inode_now);
 
+/**
+ * write_inode_for_sync - write an inode like a sync of its filesystem does
+ * @inode: inode to write to disk
+ *
+ * This does for one inode what sync_inodes_sb() has the flusher do for every
+ * dirty inode of a superblock.  It writes all dirty pages, the timestamps that
+ * lazytime has deferred and the inode.  It waits for somebody else who is
+ * writing the inode, but not for the pages it writes, and it does not ask the
+ * filesystem to commit anything.
+ *
+ * This is for a caller that syncs some of the inodes of a filesystem.  It has
+ * to wait for the pages with filemap_fdatawait_keep_errors(), like
+ * wait_sb_inodes() does, and to call sync_fs_and_bdev() in the end.
+ *
+ * The caller must have a ref on the inode.
+ *
+ * Return: 0 on success, a negative error code otherwise.
+ */
+int write_inode_for_sync(struct inode *inode)
+{
+	struct writeback_control wbc = {
+		.nr_to_write = LONG_MAX,
+		.sync_mode = WB_SYNC_ALL,
+		.range_start = 0,
+		.range_end = LLONG_MAX,
+		.for_sync = 1,
+	};
+
+	if (!mapping_can_writeback(inode->i_mapping))
+		wbc.nr_to_write = 0;
+
+	might_sleep();
+	return writeback_single_inode(inode, &wbc);
+}
+EXPORT_SYMBOL_GPL(write_inode_for_sync);
+
 /**
  * sync_inode_metadata - write an inode to disk
  * @inode: the inode to sync
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 73af18a37367..172c0fe0453f 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -35,6 +35,7 @@ int filemap_invalidate_pages(struct address_space *mapping,
 			     loff_t pos, loff_t end, bool nowait);
 
 int write_inode_now(struct inode *, int sync);
+int write_inode_for_sync(struct inode *inode);
 int filemap_fdatawrite(struct address_space *);
 int filemap_flush(struct address_space *);
 int filemap_flush_nr(struct address_space *mapping, long *nr_to_write);

-- 
2.55.0


  parent reply	other threads:[~2026-11-18 17:03 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 17:03 [PATCH v7 0/7] ovl: only sync what was written through the overlay Josef Bacik
2026-11-18 17:03 ` [PATCH v7 1/7] ovl: expand fsync mount options Josef Bacik
2026-11-18 17:03 ` [PATCH v7 2/7] ovl: no fsync=relaxed without data integrity Josef Bacik
2026-11-18 18:00   ` Amir Goldstein
2026-11-18 17:03 ` [PATCH v7 3/7] fs: add sync_fs_and_bdev() Josef Bacik
2026-11-19  8:55   ` Jan Kara
2026-11-18 17:03 ` Josef Bacik [this message]
2026-11-19  9:14   ` [PATCH v7 4/7] fs: add write_inode_for_sync() Jan Kara
2026-11-19  9:47     ` OGAWA Hirofumi
2026-11-18 17:03 ` [PATCH v7 5/7] ovl: add a set of the inodes that a sync has to write Josef Bacik
2026-11-18 17:03 ` [PATCH v7 6/7] ovl: track an inode when it is modified Josef Bacik
2026-11-18 17:03 ` [PATCH v7 7/7] ovl: implement containerized syncfs for overlayfs Josef Bacik
2026-11-18 18:09   ` Amir Goldstein
2026-11-18 18:14 ` [PATCH v7 0/7] ovl: only sync what was written through the overlay Amir Goldstein

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=20261118-b4-ovl-containerized-sync-v7-4-54f45743fe55@toxicpanda.com \
    --to=josef@toxicpanda.com \
    --cc=amir73il@gmail.com \
    --cc=brauner@kernel.org \
    --cc=cgxu519@mykernel.net \
    --cc=hch@infradead.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=mason@kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®