Hi miklos:
Have you test this version? Is there any problem ?
Thanks.
On 2021/6/29 21:03, Fengnan Chang wrote:
When writeback cache is enabled, the inode information in cached is
considered new by default, and the inode information of lowerfs is
stale.
When a lower fs is mount in a different directory through different
connection, for example PATHA and PATHB, since writeback cache is
enabled by default, when the file is modified through PATHA, viewing the
same file from the PATHB, PATHB will think that cached inode is newer
than lowerfs, resulting in file size and time from under PATHA and PATHB
is inconsistent.
Add a judgment condition to check whether to use the info in the cache
according to mtime.
Signed-off-by: Fengnan Chang <changfengnan@xxxxxxxx>
---
fs/fuse/fuse_i.h | 6 ++++++
fs/fuse/inode.c | 4 +++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 07829ce78695..98fc2ba91a03 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -909,6 +909,12 @@ static inline void fuse_page_descs_length_init(struct fuse_page_desc *descs,
for (i = index; i < index + nr_pages; i++)
descs[i].length = PAGE_SIZE - descs[i].offset;
}
+static inline bool attr_newer_than_local(struct fuse_attr *attr, struct inode *inode)
+{
+ return (attr->mtime > inode->i_mtime.tv_sec) ||
+ ((attr->mtime == inode->i_mtime.tv_sec) &&
+ (attr->mtimensec > inode->i_mtime.tv_nsec));
+}
/** Device operations */
extern const struct file_operations fuse_dev_operations;
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index b9beb39a4a18..32545f488274 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -241,8 +241,10 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
* extend local i_size without keeping userspace server in sync. So,
* attr->size coming from server can be stale. We cannot trust it.
*/
- if (!is_wb || !S_ISREG(inode->i_mode))
+ if (!is_wb || !S_ISREG(inode->i_mode)
+ || (attr_newer_than_local(attr, inode) && !inode_is_open_for_write(inode))) {
i_size_write(inode, attr->size);
+ }
spin_unlock(&fi->lock);
if (!is_wb && S_ISREG(inode->i_mode)) {