Message ID | 20201113065555.147276-7-cgxu519@mykernel.net (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | implement containerized syncfs for overlayfs | expand |
On Fri, Nov 13, 2020 at 7:57 AM Chengguang Xu <cgxu519@mykernel.net> wrote: > > Implement overlayfs' ->write_inode to sync dirty data > and redirty overlayfs' inode if necessary. > > Signed-off-by: Chengguang Xu <cgxu519@mykernel.net> > --- > fs/overlayfs/super.c | 30 ++++++++++++++++++++++++++++++ > 1 file changed, 30 insertions(+) > > diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c > index 883172ac8a12..82e001b97f38 100644 > --- a/fs/overlayfs/super.c > +++ b/fs/overlayfs/super.c > @@ -390,6 +390,35 @@ static int ovl_remount(struct super_block *sb, int *flags, char *data) > return ret; > } > > +static int ovl_write_inode(struct inode *inode, > + struct writeback_control *wbc) > +{ > + struct ovl_fs *ofs = inode->i_sb->s_fs_info; > + struct inode *upper = ovl_inode_upper(inode); > + unsigned long iflag = 0; > + int ret = 0; > + > + if (!upper) > + return 0; > + > + if (!ovl_should_sync(ofs)) > + return 0; > + > + if (upper->i_sb->s_op->write_inode) > + ret = upper->i_sb->s_op->write_inode(inode, wbc); > + > + if (mapping_writably_mapped(upper->i_mapping) || > + mapping_tagged(upper->i_mapping, PAGECACHE_TAG_WRITEBACK)) > + iflag |= I_DIRTY_PAGES; > + > + iflag |= upper->i_state & I_DIRTY_ALL; How is I_DIRTY_SYNC added/removed from the overlay inode? Thanks, Miklos
---- 在 星期五, 2021-04-09 21:49:07 Miklos Szeredi <miklos@szeredi.hu> 撰写 ---- > On Fri, Nov 13, 2020 at 7:57 AM Chengguang Xu <cgxu519@mykernel.net> wrote: > > > > Implement overlayfs' ->write_inode to sync dirty data > > and redirty overlayfs' inode if necessary. > > > > Signed-off-by: Chengguang Xu <cgxu519@mykernel.net> > > --- > > fs/overlayfs/super.c | 30 ++++++++++++++++++++++++++++++ > > 1 file changed, 30 insertions(+) > > > > diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c > > index 883172ac8a12..82e001b97f38 100644 > > --- a/fs/overlayfs/super.c > > +++ b/fs/overlayfs/super.c > > @@ -390,6 +390,35 @@ static int ovl_remount(struct super_block *sb, int *flags, char *data) > > return ret; > > } > > > > +static int ovl_write_inode(struct inode *inode, > > + struct writeback_control *wbc) > > +{ > > + struct ovl_fs *ofs = inode->i_sb->s_fs_info; > > + struct inode *upper = ovl_inode_upper(inode); > > + unsigned long iflag = 0; > > + int ret = 0; > > + > > + if (!upper) > > + return 0; > > + > > + if (!ovl_should_sync(ofs)) > > + return 0; > > + > > + if (upper->i_sb->s_op->write_inode) > > + ret = upper->i_sb->s_op->write_inode(inode, wbc); > > + > > + if (mapping_writably_mapped(upper->i_mapping) || > > + mapping_tagged(upper->i_mapping, PAGECACHE_TAG_WRITEBACK)) > > + iflag |= I_DIRTY_PAGES; > > + > > + iflag |= upper->i_state & I_DIRTY_ALL; > > How is I_DIRTY_SYNC added/removed from the overlay inode? > generally, I_DIRTY_SYNC is added to overlay inode when the operation dirties upper inode, I'll check all those places and call ovl_mark_inode_dirty() to do it. After writeback if upper inode becomes clean status, we will remove I_DIRTY_SYNC from overlay inode. One exception is mmaped file, it will always keep I_DIRTY_SYNC until to be evicted. Thanks, Chengguang
diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index 883172ac8a12..82e001b97f38 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -390,6 +390,35 @@ static int ovl_remount(struct super_block *sb, int *flags, char *data) return ret; } +static int ovl_write_inode(struct inode *inode, + struct writeback_control *wbc) +{ + struct ovl_fs *ofs = inode->i_sb->s_fs_info; + struct inode *upper = ovl_inode_upper(inode); + unsigned long iflag = 0; + int ret = 0; + + if (!upper) + return 0; + + if (!ovl_should_sync(ofs)) + return 0; + + if (upper->i_sb->s_op->write_inode) + ret = upper->i_sb->s_op->write_inode(inode, wbc); + + if (mapping_writably_mapped(upper->i_mapping) || + mapping_tagged(upper->i_mapping, PAGECACHE_TAG_WRITEBACK)) + iflag |= I_DIRTY_PAGES; + + iflag |= upper->i_state & I_DIRTY_ALL; + + if (iflag) + ovl_mark_inode_dirty(inode); + + return ret; +} + static void ovl_evict_inode(struct inode *inode) { inode->i_state &= ~I_DIRTY_ALL; @@ -402,6 +431,7 @@ static const struct super_operations ovl_super_operations = { .destroy_inode = ovl_destroy_inode, .drop_inode = generic_delete_inode, .evict_inode = ovl_evict_inode, + .write_inode = ovl_write_inode, .put_super = ovl_put_super, .sync_fs = ovl_sync_fs, .statfs = ovl_statfs,
Implement overlayfs' ->write_inode to sync dirty data and redirty overlayfs' inode if necessary. Signed-off-by: Chengguang Xu <cgxu519@mykernel.net> --- fs/overlayfs/super.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)