Linux-Fsdevel Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] When writeback cache is enabled, same file in two different directory maybe inconsistent
@ 2021-01-28 10:07 Fengnan Chang
0 siblings, 0 replies; only message in thread
From: Fengnan Chang @ 2021-01-28 10:07 UTC (permalink / raw)
To: miklos; +Cc: linux-fsdevel, changfengnan
From: changfengnan <changfengnan@vivo.com>
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.
We have a solution, add a judgment condition to check whether to use the
info in the cache according to mtime.
Signed-off-by: changfengnan <changfengnan@vivo.com>
---
fs/fuse/inode.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index b0e18b470e91..e63984bfac48 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -182,7 +182,10 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
inode->i_atime.tv_sec = attr->atime;
inode->i_atime.tv_nsec = attr->atimensec;
/* mtime from server may be stale due to local buffered write */
- if (!fc->writeback_cache || !S_ISREG(inode->i_mode)) {
+ if (!fc->writeback_cache || !S_ISREG(inode->i_mode)
+ || (attr->mtime >= inode->i_mtime.tv_sec)
+ || ((attr->mtime == inode->i_mtime.tv_sec)
+ && (attr->mtimensec >= inode->i_mtime.tv_nsec))) {
inode->i_mtime.tv_sec = attr->mtime;
inode->i_mtime.tv_nsec = attr->mtimensec;
inode->i_ctime.tv_sec = attr->ctime;
@@ -241,8 +244,12 @@ 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->mtime >= inode->i_mtime.tv_sec)
+ || ((attr->mtime == inode->i_mtime.tv_sec)
+ && (attr->mtimensec >= inode->i_mtime.tv_nsec))) {
i_size_write(inode, attr->size);
+ }
spin_unlock(&fi->lock);
if (!is_wb && S_ISREG(inode->i_mode)) {
--
2.29.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2021-01-28 10:17 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-28 10:07 [PATCH] When writeback cache is enabled, same file in two different directory maybe inconsistent Fengnan Chang
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).