From nobody Mon Feb 9 21:20:46 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96D3AEB64DC for ; Tue, 11 Jul 2023 04:36:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230239AbjGKEgo (ORCPT ); Tue, 11 Jul 2023 00:36:44 -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-Google-Smtp-Source: APBJJlHIf59vPvuJkt+nHEjvyzXHNkLoYRaEdMaHVely1xqgzY3bc4iYFFavqAdHFMoBUkKWqV62rg== 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 =3D get_fuse_inode(inode); + + spin_lock(&fi->lock); + fi->attr_version =3D 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_C= ACHE) * FOPEN_PARALLEL_DIRECT_WRITES: Allow concurrent direct writes on the sam= e 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) =20 /** * INIT request/reply flags --=20 2.20.1