diff mbox series

[RFC,v3,03/10] ovl: implement ->writepages operation

Message ID 20201108140307.1385745-4-cgxu519@mykernel.net (mailing list archive)
State New, archived
Headers show
Series implement containerized syncfs for overlayfs | expand

Commit Message

Chengguang Xu Nov. 8, 2020, 2:03 p.m. UTC
Implement overlayfs' ->writepages operation so that
we can sync dirty data/metadata to upper filesystem.
If writeback mode is sync_mode we add overlayfs inode
to extra syncfs wait list so that we can wait completion
in ->syncfs.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
 fs/overlayfs/inode.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
diff mbox series

Patch

diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
index b584dca845ba..1f5cbbc60b28 100644
--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -11,6 +11,7 @@ 
 #include <linux/posix_acl.h>
 #include <linux/ratelimit.h>
 #include <linux/fiemap.h>
+#include <linux/writeback.h>
 #include "overlayfs.h"
 
 
@@ -516,7 +517,30 @@  static const struct inode_operations ovl_special_inode_operations = {
 	.update_time	= ovl_update_time,
 };
 
+static int ovl_writepages(struct address_space *mapping,
+			  struct writeback_control *wbc)
+{
+	struct inode *inode = mapping->host;
+	struct ovl_fs *ofs = inode->i_sb->s_fs_info;
+	struct inode *upper = ovl_inode_upper(inode);
+	int ret;
+
+	if (!ovl_should_sync(ofs))
+		return 0;
+	ret = sync_inode(upper, wbc);
+	if (!ret && wbc->for_sync == 1) {
+		spin_lock(&ofs->syncfs_wait_list_lock);
+		if (list_empty(&OVL_I(inode)->wait_list))
+			list_add_tail(&OVL_I(inode)->wait_list,
+				      &ofs->syncfs_wait_list);
+		spin_unlock(&ofs->syncfs_wait_list_lock);
+	}
+
+	return ret;
+}
+
 static const struct address_space_operations ovl_aops = {
+	.writepages		= ovl_writepages,
 	/* For O_DIRECT dentry_open() checks f_mapping->a_ops->direct_IO */
 	.direct_IO		= noop_direct_IO,
 };