From patchwork Tue Jul 11 04:34:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiachen Zhang X-Patchwork-Id: 118249 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp242393vqm; Mon, 10 Jul 2023 21:46:52 -0700 (PDT) X-Google-Smtp-Source: APBJJlGFXyvG4FieNY/IDDxWnIbWKyfWkJ13q06Ud4AD8/dCPecO2fDKVRcI4r+jdBnUiuOeEeZL X-Received: by 2002:a05:6402:38a:b0:51e:3558:5eb6 with SMTP id o10-20020a056402038a00b0051e35585eb6mr12265100edv.3.1689050812274; Mon, 10 Jul 2023 21:46:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689050812; cv=none; d=google.com; s=arc-20160816; b=BalXsKKYlR/4hjpu1EWq0FyCBqbXKsA3mj/vWqwsK4Eq1quif460oScYNUhKKuEbzG nhyXJgnuAM3FTrZa8xM5JLy5VGJh+MKbg1XMphqy8DDETMye03e2xSlxyqsJvpvj0M8C fwvshKWzfLYv5fOEv/CEinNV7ds3I3b214RMVA06rQYvKF4wQUAF56HIcPbQOjQ93+xP fkiU+cE5Eu6xP9M5P0FzPVvKdOXpFoLfl7GyhXOxXxoOPzsP3jnXY9TLPzuR5/jp9kVA t48dveXEPBoCdwmfpcidsVtMilobb1FKk9b05HfyACQQH10AQWxyt0tSvT7xrnDjakhr AbGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=o2fbpRc1gP3OYJFiewDVSSan5FPPeq6w2nLF2ekKLbg=; fh=AbZLXPTwDd6D4T6qkHRVC4qv5VyfsE5N5bMl5jebUv8=; b=phZ36U0xnNO5Ko5heLm8kZ2GBXt5+3AQxOsxFKKHOeVwrMCpzP3jV+2ICQ4Xl86BBo VyM0SJO7KR/2SHYzJS6zuwvJmFPeL51NZWBuLyAhwJoxtGdS9z5s5ulF2MzwapSHg9nL EPLtc6sOt3whbiPfb+7Dl/k+2cw9VItRoh2VOJkL/TvdYLePzCQKF9FFu//qtxG05tYf IUKukwQokeYPiSn7K79rx8clnhav0PLZ3n5Td4C2vZ1ZECmzGZRSpszpiA7OesZCe1Z0 5M3NtRWF5eUEuANkvzxh75xJoTp5K0wLVprbxpjV39abrHXIAD3Q87kui0lNzb0Fo9tH rBaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=RQesib1x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m20-20020aa7c2d4000000b0051df1a7b268si1150841edp.17.2023.07.10.21.46.28; Mon, 10 Jul 2023 21:46:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=RQesib1x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230527AbjGKEhM (ORCPT + 99 others); Tue, 11 Jul 2023 00:37:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230318AbjGKEg4 (ORCPT ); Tue, 11 Jul 2023 00:36:56 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F18EBE49 for ; Mon, 10 Jul 2023 21:36:31 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-6682909acadso2784109b3a.3 for ; Mon, 10 Jul 2023 21:36:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1689050191; x=1691642191; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=o2fbpRc1gP3OYJFiewDVSSan5FPPeq6w2nLF2ekKLbg=; b=RQesib1xN1ZmHsPS1BZxb8GFBw3bLOQP+UTjbpSvqSu+zXCUbswMRRjAQVntHnffgk 2E7MeVDBV3pc5dYbmgSn6MIm2amFwKOtJplCxUPOs4k2kU3oM5T7RL+2F9ANb+ranU8N cTamzNqo/wgS45OeJK1zXiqykdKVk4JG6kyQnw8eJDpaUqPUIkUPzbNhzXXwt17/i6dg koxv3ey5vV36NfWt0COANNWYLYE5QEZNoTZyYAyTVobEvSdbLe/RxfNmvTFEo+Olk8Dn BNMc0q1bCu/CaaEV8YEzXStHiJ5nkGZrRC5Gn+FtESHQPWr5TV0cdYOfjYn8FB/MEZYv N43w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689050191; x=1691642191; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o2fbpRc1gP3OYJFiewDVSSan5FPPeq6w2nLF2ekKLbg=; b=iPdjWY4xTtMWHQycMINErro8z6kMDiypeAKmHA97U5MlGAcPNsMZLSAEd2gkWJ4gyK Monh077Gj3/v/iwH0sQ1sSDCNBpWBTXDfgc2wTMZXzhBvjZvA6OnPi22v5dIn8jWZJmA WwT9Nz5cUXXGzXcrff1dpdwAv8HilOx2cvoQ+5DcbxWlL7jkVabQ300ldo7JihsIiDnh uOafiIq5zb7GjZ2N+LCrMXvzv6yhCZJiK8aKsQwIUynSUbMxYX1kxwYD3WS9yLKGfHlQ i9xSwmIhWcxAlLvoBHjCdHRc3UZCdgciCoYe3ny+rdfRVtSiCF25rFXWbUueNoYX8oZn 6zJA== X-Gm-Message-State: ABy/qLY7N38wSCzL33sUpmYKoao98MJB6q0h0FVkjOx55w7I0KjZhJCJ 8+nhiFBHqG/j+N+3MDjMHyW5WT/6h1gDQ22GecxAZw== X-Received: by 2002:a05:6a21:900c:b0:130:74c8:b501 with SMTP id tq12-20020a056a21900c00b0013074c8b501mr8444984pzb.30.1689050191294; Mon, 10 Jul 2023 21:36:31 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.236]) by smtp.gmail.com with ESMTPSA id ij9-20020a170902ab4900b001b9de67285dsm755259plb.156.2023.07.10.21.36.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 21:36:30 -0700 (PDT) From: Jiachen Zhang To: Miklos Szeredi , Jonathan Corbet , linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: me@jcix.top, Jiachen Zhang Subject: [PATCH 1/5] fuse: check attributes staleness on fuse_iget() Date: Tue, 11 Jul 2023 12:34:01 +0800 Message-Id: <20230711043405.66256-2-zhangjiachen.jaycee@bytedance.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230711043405.66256-1-zhangjiachen.jaycee@bytedance.com> References: <20230711043405.66256-1-zhangjiachen.jaycee@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771098144603465611 X-GMAIL-MSGID: 1771098144603465611 Function fuse_direntplus_link() might call fuse_iget() to initialize a new fuse_inode and change its attributes. If fi->attr_version is always initialized with 0, even if the attributes returned by the FUSE_READDIR request is staled, as the new fi->attr_version is 0, fuse_change_attributes will still set the staled attributes to inode. This wrong behaviour may cause file size inconsistency even when there is no changes from server-side. To reproduce the issue, consider the following 2 programs (A and B) are running concurrently, A B ---------------------------------- -------------------------------- { /fusemnt/dir/f is a file path in a fuse mount, the size of f is 0. } readdir(/fusemnt/dir) start //Daemon set size 0 to f direntry fallocate(f, 1024) stat(f) // B see size 1024 echo 2 > /proc/sys/vm/drop_caches readdir(/fusemnt/dir) reply to kernel Kernel set 0 to the I_NEW inode stat(f) // B see size 0 In the above case, only program B is modifying the file size, however, B observes file size changing between the 2 'readonly' stat() calls. To fix this issue, we should make sure readdirplus still follows the rule of attr_version staleness checking even if the fi->attr_version is lost due to inode eviction. So this patch increases fc->attr_version on inode eviction, and compares request attr_version and the fc->attr_version when a FUSE_READDIRPLUS request is finished. Signed-off-by: Jiachen Zhang --- fs/fuse/inode.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index 660be31aaabc..3e0b1fb1db17 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -115,6 +115,7 @@ static void fuse_free_inode(struct inode *inode) static void fuse_evict_inode(struct inode *inode) { + struct fuse_conn *fc = get_fuse_conn(inode); struct fuse_inode *fi = get_fuse_inode(inode); /* Will write inode on close/munmap and in all other dirtiers */ @@ -137,6 +138,8 @@ static void fuse_evict_inode(struct inode *inode) WARN_ON(!list_empty(&fi->write_files)); WARN_ON(!list_empty(&fi->queued_writes)); } + + atomic64_inc(&fc->attr_version); } static int fuse_reconfigure(struct fs_context *fsc) @@ -409,6 +412,10 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid, fi->nlookup++; spin_unlock(&fi->lock); fuse_change_attributes(inode, attr, attr_valid, attr_version); + spin_lock(&fi->lock); + if (attr_version < atomic64_read(&fc->attr_version)) + fuse_invalidate_attr(inode); + spin_unlock(&fi->lock); return inode; }