From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A396C48BDF for ; Thu, 24 Jun 2021 07:42:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F39E1613EB for ; Thu, 24 Jun 2021 07:42:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231589AbhFXHov (ORCPT ); Thu, 24 Jun 2021 03:44:51 -0400 Received: from mail-m121144.qiye.163.com ([115.236.121.144]:55732 "EHLO mail-m121144.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231503AbhFXHor (ORCPT ); Thu, 24 Jun 2021 03:44:47 -0400 DKIM-Signature: a=rsa-sha256; b=HHLlNLp8+LCAGC0d2nGF2McFyQuUCGpClwhxBGeYPc1WPbhB89sWO/Fxc3SymqpkMezfWTjjhkKfTMQUMIT7LygFAL0o1gjCAjtWPJywxLZ2J0zk0M0sLf0tePylPBG4uMEtpPEF2htl+8i+gN1j6ySjizkSRU2MskBNX/5SwxI=; c=relaxed/relaxed; s=default; d=vivo.com; v=1; bh=vVNPe8htp5VSe9hMK7ur2f19b0dC71+2ZozOaB//Uo4=; h=date:mime-version:subject:message-id:from; Received: from [172.25.44.145] (unknown [58.251.74.232]) by mail-m121144.qiye.163.com (Hmail) with ESMTPA id DEFC0AC037E; Thu, 24 Jun 2021 15:42:24 +0800 (CST) Subject: Re: [PATCH v2] fuse: use newer inode info when writeback cache is enabled To: Miklos Szeredi Cc: linux-fsdevel@vger.kernel.org References: <20210130085003.1392-1-changfengnan@vivo.com> <3e740389-9734-a959-a88a-3b1d54b59e22@vivo.com> From: Fengnan Chang Message-ID: <29a3623f-fb4d-2a2b-af28-26f9ef0b0764@vivo.com> Date: Thu, 24 Jun 2021 15:42:24 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgYFAkeWUFZS1VLWVdZKFlBSE83V1ktWUFJV1kPCR oVCBIfWUFZGk0aT1YfGkIZSkMaSU1IQkJVEwETFhoSFyQUDg9ZV1kWGg8SFR0UWUFZT0tIVUpKS0 hKTFVLWQY+ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6ND46GCo*Nz8DNjNRH0MwKEIq QglPFBxVSlVKTUlPTklLTk9OT0xCVTMWGhIXVRgTGhUcHR4VHBUaFTsNEg0UVRgUFkVZV1kSC1lB WU5DVUlOSlVMT1VJSElZV1kIAVlBT0hDQzcG X-HM-Tid: 0a7a3cf852d8b039kuuudefc0ac037e Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Hi Miklos: Thank you for the information, I have been able to reproduce the problem. The new version of the patch as below. Previous fsx test is pass now. Need do more test, Can you help to test new patch? or send me your test case, I will test this. Here is my test case, and is the problem this patch is trying to solve. Case A: mkdir /tmp/test passthrough_ll -ocache=always,writeback /mnt/test/ echo "11111" > /tmp/test/fsx ls -l /mnt/test/tmp/test/ echo "2222" >> /tmp/test/fsx ls -l /mnt/test/tmp/test/ Case B: mkdir /tmp/test passthrough_ll -ocache=always,writeback /mnt/test/ passthrough_ll -ocache=always,writeback /mnt/test2/ echo "11111" > /tmp/test/fsx ls -l /mnt/test/tmp/test/ ls -l /mnt/test2/tmp/test/ echo "222" >> /mnt/test/tmp/test/fsx ls -l /mnt/test/tmp/test/ ls -l /mnt/test2/tmp/test/ diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index b9beb39a4a18..8e22a31b55c4 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -60,6 +60,10 @@ MODULE_PARM_DESC(max_user_congthresh, /** Congestion starts at 75% of maximum */ #define FUSE_DEFAULT_CONGESTION_THRESHOLD (FUSE_DEFAULT_MAX_BACKGROUND * 3 / 4) +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)); +} #ifdef CONFIG_BLOCK static struct file_system_type fuseblk_fs_type; #endif @@ -241,8 +245,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)) { On 2021/6/22 23:19, Miklos Szeredi wrote: > On Tue, 22 Jun 2021 at 14:25, Fengnan Chang wrote: >> >> Unh, it seems i_writecount not work. >> If we modify file through lowerfs, i_writecount won't change, but the >> size already changed. >> For example: >> echo "111" > /lowerfs/test >> ls -l /upper/test >> echo "2222" >> /lowerfs/test >> ls -l /upper/test >> >> So, can you describe your test enviroment? including kernel version and >> fsx parameters, I will check it. > > linux-5.13-rc5 + patch > mkdir /tmp/test > libfuse/example/passthrough_ll -ocache=always,writeback /mnt/fuse/ > fsx-linux -N 1000000 /mnt/fuse/tmp/test/fsx > > Thanks, > Miklos >