From patchwork Tue Jul 11 04:34:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiachen Zhang X-Patchwork-Id: 118252 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp246324vqm; Mon, 10 Jul 2023 21:59:21 -0700 (PDT) X-Google-Smtp-Source: APBJJlFwkWoWEcYjq5Z16uR4nuPtbKZRL/xLX32pZy3yCDU1Se/820UAKOXyQSVTheVF8l+ik8bi X-Received: by 2002:a05:6a20:394a:b0:126:aa77:a118 with SMTP id r10-20020a056a20394a00b00126aa77a118mr18387859pzg.16.1689051561241; Mon, 10 Jul 2023 21:59:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689051561; cv=none; d=google.com; s=arc-20160816; b=R8Qct760+lfBfPB8EatPcHtQnUDEubw78E2APRNdZWG286QL9kuy2ZuoBC5sJcFrze CmAPwb8GCeJljjtigtIDaBFHQIGds/xrgG+5rI2SHc3pZ0VQkAEMIFoeJGqPpLMoN0bu PelcanyUSUdV0ibrqClx/yhMpDm3WoZa74wY7I7aG5Mx97q48SeMD6om040dxV8kTOfE sy8PbJ1bW/RwPvKBB7rjtiCPGmVkAFGkvmeBAobb4a92auqdk7p9CGmDV/SDaJ+uFhC1 x0mEUj/LxeZ/6G4TIi+pLXTIz7nyhPyAF3HZI3Ta51DmiKl8bbfEhBONUPI7Sa2VikVY CgRQ== 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=LYyneuFOya7q2sTcPQVJeQ03ke3KB9TyjkGjVTDlnv0=; fh=AbZLXPTwDd6D4T6qkHRVC4qv5VyfsE5N5bMl5jebUv8=; b=sDe0pcRLqXXbRGPZyWq3X+3RxgVhI0E73fi4bBLODx3fb5vXxqADXVCdr5ZShuAE2/ yzUpmcu2SvVWkI3193dd7CNg9pLw//G2Ldq8o5qW7xx2Qig5nd+M1iLqy+FHhOoAgDNW LlGSTaqlBxaFOL/48uXSzDmql63gxsuQHD877nt9sSWIHqwqqBhW4k7r62+7EMLJH7WK dzVC6qx11+C5qRRhjKddnfz3rSAGJLyLqPc3mK0ViN8m6fibVKg+KsuOxmvIM4Xco2VG zIWmMtPt50UbhdJCrUDI4pu9V0h6yqxpiiy9d1PNq4YxLmcx3Xftbvso4ftMbcATW3Al yzVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=US+yv14l; 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 t33-20020a634461000000b0055baf9fc384si736943pgk.823.2023.07.10.21.59.07; Mon, 10 Jul 2023 21:59:21 -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=US+yv14l; 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 S230245AbjGKEgn (ORCPT + 99 others); Tue, 11 Jul 2023 00:36:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbjGKEgk (ORCPT ); Tue, 11 Jul 2023 00:36:40 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52E11E57 for ; Mon, 10 Jul 2023 21:36:38 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-557790487feso3796863a12.0 for ; Mon, 10 Jul 2023 21:36:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1689050198; x=1691642198; 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=LYyneuFOya7q2sTcPQVJeQ03ke3KB9TyjkGjVTDlnv0=; b=US+yv14lPeyTCnFdCgqlMbJNwE5KFha2iFb4bUJz85g79tWQwveWhVddRTdv1h409z sTqEZOWjzTPRfgsJPWBR7Xx5TMSMfStlFaNsHvHzD2rRTGfDherNOCKdeLsuMxgINzR2 RQ/zGyLXnd+lNknbGvcDuOHlIVtsGnIVwOVpXPUZtRNkx761pJZXbBpAEj6JPPSqf78Y thC7FMr85gmT+MdH6x1W87SMix0tqX2IT2CXnXTw0rGKCjfu9FSlEa2NOjTvXSK9JIpO x4C5KSu2PyHdX8/MP4lTcW1T5X3bIbebYofTJvZNNZEApZEH8RJguPodrK/KFIeniH2p hCRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689050198; x=1691642198; 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=LYyneuFOya7q2sTcPQVJeQ03ke3KB9TyjkGjVTDlnv0=; b=aHuOTtTsFwNgH7wHVl2tT0f8e/wmfXcSmre9xj44dCTFVkfoMvxs4w2REtON8VWUuJ xV4moSiHkU9jBIdCYfhZOHwK8H/4fhIrnW6g4tS6oi6ADch76Mp7WvFhZ6WsNhNAymPR U3yt12CSJaKX+WrJIhHin91WWK34/0dhwP7bubMFmNI/l0imje+lcleiNU09kgi6x8kD SkZqVUQvdqB/S4TBTQV7A+GQM5Eto+W9oi3iqiZob+TYFkYZOs5k0amvc/2OnWZVZvin Dr75Zi8T/VmRIvFTwBZ1gUTr7wlOmX42b0CWHeKe/bVnOxzekoub0n42O/RPDb+Rx80d hc8Q== X-Gm-Message-State: ABy/qLbZfNwVEePQkro7F6yh9C67+5bPdgBma9emlH5c+KBMVL/42EpW DjL48kF4kLk/OvvJ01BV7R0ehA== X-Received: by 2002:a17:902:e88b:b0:1b8:1d4b:f5fc with SMTP id w11-20020a170902e88b00b001b81d4bf5fcmr17269445plg.30.1689050197840; Mon, 10 Jul 2023 21:36:37 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 21:36:37 -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 3/5] fuse: add FOPEN_INVAL_ATTR Date: Tue, 11 Jul 2023 12:34:03 +0800 Message-Id: <20230711043405.66256-4-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: 1771098929907682842 X-GMAIL-MSGID: 1771098929907682842 Add FOPEN_INVAL_ATTR so that the fuse daemon can ask kernel to invalidate the attr cache on file open. The fi->attr_version should be increased when handling FOPEN_INVAL_ATTR. Because if a FUSE request returning attributes (getattr, setattr, lookup, and readdirplus) starts before a FUSE_OPEN replying FOPEN_INVAL_ATTR, but finishes after the FUSE_OPEN, staled attributes will be set to the inode and falsely clears the inval_mask. Signed-off-by: Jiachen Zhang --- fs/fuse/file.c | 10 ++++++++++ include/uapi/linux/fuse.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index de37a3a06a71..412824a11b7b 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -215,6 +215,16 @@ void fuse_finish_open(struct inode *inode, struct file *file) file_update_time(file); fuse_invalidate_attr_mask(inode, FUSE_STATX_MODSIZE); } + + if (ff->open_flags & FOPEN_INVAL_ATTR) { + struct fuse_inode *fi = get_fuse_inode(inode); + + spin_lock(&fi->lock); + fi->attr_version = atomic64_inc_return(&fc->attr_version); + fuse_invalidate_attr(inode); + spin_unlock(&fi->lock); + } + if ((file->f_mode & FMODE_WRITE) && fc->writeback_cache) fuse_link_write_file(file); } diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h index b3fcab13fcd3..1a24c11637a4 100644 --- a/include/uapi/linux/fuse.h +++ b/include/uapi/linux/fuse.h @@ -315,6 +315,7 @@ struct fuse_file_lock { * FOPEN_STREAM: the file is stream-like (no file position at all) * FOPEN_NOFLUSH: don't flush data cache on close (unless FUSE_WRITEBACK_CACHE) * FOPEN_PARALLEL_DIRECT_WRITES: Allow concurrent direct writes on the same inode + * FOPEN_INVAL_ATTR: invalidate the attr cache on open */ #define FOPEN_DIRECT_IO (1 << 0) #define FOPEN_KEEP_CACHE (1 << 1) @@ -323,6 +324,7 @@ struct fuse_file_lock { #define FOPEN_STREAM (1 << 4) #define FOPEN_NOFLUSH (1 << 5) #define FOPEN_PARALLEL_DIRECT_WRITES (1 << 6) +#define FOPEN_INVAL_ATTR (1 << 7) /** * INIT request/reply flags