All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] fuse: use newer inode info when writeback cache is enabled
@ 2021-06-29 13:03 Fengnan Chang
  2021-07-21  8:07 ` Fengnan Chang
  0 siblings, 1 reply; 2+ messages in thread
From: Fengnan Chang @ 2021-06-29 13:03 UTC (permalink / raw)
  To: miklos, linux-fsdevel; +Cc: Fengnan Chang

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@vivo.com>
---
 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)) {
-- 
2.29.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] fuse: use newer inode info when writeback cache is enabled
  2021-06-29 13:03 [PATCH v3] fuse: use newer inode info when writeback cache is enabled Fengnan Chang
@ 2021-07-21  8:07 ` Fengnan Chang
  0 siblings, 0 replies; 2+ messages in thread
From: Fengnan Chang @ 2021-07-21  8:07 UTC (permalink / raw)
  To: miklos, linux-fsdevel

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@vivo.com>
> ---
>   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)) {
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-21  8:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-29 13:03 [PATCH v3] fuse: use newer inode info when writeback cache is enabled Fengnan Chang
2021-07-21  8:07 ` Fengnan Chang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.