From patchwork Thu Aug 10 10:54:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 13349277 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 A9E5CC04A94 for ; Thu, 10 Aug 2023 10:56:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234407AbjHJK4C (ORCPT ); Thu, 10 Aug 2023 06:56:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230230AbjHJK4B (ORCPT ); Thu, 10 Aug 2023 06:56:01 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 777FD213F for ; Thu, 10 Aug 2023 03:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691664908; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b06CcaAE7+jk62SrlDLBDiqbuy9hcBibaIoFiOaaong=; b=gmb0pedJSFA/ncnEoJsJRHo/ueqWFKn87XulAFzPt8985/+up+EjPJGgI+rEiIp7qi7rPW g3G4H/v0Gp3T5C70MLDmadhKTbiqO8OMDLpm8Mp9wxCFZ45PNCfJgUEXGDR910lesRJIGk 27ZXcRKFCpz81aKKMwYDvH2xh4e6yYo= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-319-Zt_zfJSMOkmbitX68FJwCg-1; Thu, 10 Aug 2023 06:55:06 -0400 X-MC-Unique: Zt_zfJSMOkmbitX68FJwCg-1 Received: by mail-lf1-f72.google.com with SMTP id 2adb3069b0e04-4fe356c71d6so784890e87.1 for ; Thu, 10 Aug 2023 03:55:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691664904; x=1692269704; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b06CcaAE7+jk62SrlDLBDiqbuy9hcBibaIoFiOaaong=; b=keaFNb2S3TG2RTehI5aC+OOa/XVxr1n7H9lN6eZxQ86dRjVM4ueBJ1mf8DuXWwy5Vx 7C+x8fY0etX6c2+quL0UPPnDzz3I3NYtDZ5Umh3p6rQ5nwhG38MijYYwu7+E3ETK6CPa E7nHoe1oXmlOwJXj/e7xdGzfPU/49qy0u6bGUDBxdTsv6b9KFXfdaAcU4m3JXd4+nNNI vnF00sHN2aFFjP7z1Tamcm3U6TF5mpI564z2VQSmbODQWFVufeYK3hLimWYf/LJY7EhQ xgvm4/14Hu7XrNaAchBv3eLDkIIzgMaZjF0699czTXdltOfm7wJ0NJUvlkT/+kCI5AmS 0u2w== X-Gm-Message-State: AOJu0YxsjGOYYXXKgZ16TgA+mvCEoYkA4gnXZDZDLG2DlKoVK0C/r/sO /XbD8kCmuCeMjzEAsZobyppd9HitxvyJccGsbVnp0B2v4tkGBP4ui/6Y9mq7eVsJXAkVSIudTRZ HzJERcAMOvPnm8cwLLSz7OH2HyhhG9Tb7g6OtIMWnhk2LY1iRAJKUMfPhBMMDmCm9BN7XV0z8xk 2wlxT2NxyYeA== X-Received: by 2002:a19:6d0d:0:b0:4fd:da65:d10 with SMTP id i13-20020a196d0d000000b004fdda650d10mr1354581lfc.36.1691664904399; Thu, 10 Aug 2023 03:55:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF9k5W3ZufNymLkIVjFDgmLjut8wSSuK/UGQi9p3wr0US7W6Bl1KolUaZD3oi9ppigHF0rLFQ== X-Received: by 2002:a19:6d0d:0:b0:4fd:da65:d10 with SMTP id i13-20020a196d0d000000b004fdda650d10mr1354561lfc.36.1691664903952; Thu, 10 Aug 2023 03:55:03 -0700 (PDT) Received: from miu.piliscsaba.redhat.com (193-226-246-142.pool.digikabel.hu. [193.226.246.142]) by smtp.gmail.com with ESMTPSA id v20-20020aa7cd54000000b005231f324a0bsm643732edw.28.2023.08.10.03.55.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 03:55:03 -0700 (PDT) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Subject: [PATCH 1/5] fuse: handle empty request_mask in statx Date: Thu, 10 Aug 2023 12:54:57 +0200 Message-Id: <20230810105501.1418427-2-mszeredi@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230810105501.1418427-1-mszeredi@redhat.com> References: <20230810105501.1418427-1-mszeredi@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org If no attribute is requested, then don't send request to userspace. Signed-off-by: Miklos Szeredi --- fs/fuse/dir.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index f67bef9d83c4..d38ab93e2007 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -1209,7 +1209,12 @@ static int fuse_update_get_attr(struct inode *inode, struct file *file, u32 inval_mask = READ_ONCE(fi->inval_mask); u32 cache_mask = fuse_get_cache_mask(inode); - if (flags & AT_STATX_FORCE_SYNC) + /* FUSE only supports basic stats */ + request_mask &= STATX_BASIC_STATS; + + if (!request_mask) + sync = false; + else if (flags & AT_STATX_FORCE_SYNC) sync = true; else if (flags & AT_STATX_DONT_SYNC) sync = false; From patchwork Thu Aug 10 10:54:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 13349278 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 ADCF6C001DB for ; Thu, 10 Aug 2023 10:56:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233953AbjHJK4B (ORCPT ); Thu, 10 Aug 2023 06:56:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230510AbjHJK4B (ORCPT ); Thu, 10 Aug 2023 06:56:01 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43B1B268A for ; Thu, 10 Aug 2023 03:55:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691664909; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pfJH3noYbWyg5mwtDgx4Z5kj3eCpv/dKZ/d4TuLP0Yc=; b=LP0vlNl3hr9pNxgfLShQDf37Nw8xmiDtQt8nNGmx6mNQWv04X4CVj6h+L07KxU7gcWTdHK W6cuoIpN9PrHLvTKY8TxWeCeNOfkvkZ+ilIfK+lPluhNVYQP9+7V3Q2bZ8+oi9oEx1ETKw R6gYFIgFfFF3Eo0LKq8qG45hBa2cH6k= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-361-6V2vaXgIOBClHFwHCJDc-A-1; Thu, 10 Aug 2023 06:55:07 -0400 X-MC-Unique: 6V2vaXgIOBClHFwHCJDc-A-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-4fe7546f2a7so775254e87.3 for ; Thu, 10 Aug 2023 03:55:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691664905; x=1692269705; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pfJH3noYbWyg5mwtDgx4Z5kj3eCpv/dKZ/d4TuLP0Yc=; b=HVlb3qUeixdLvHluwokAgUxDQbLWk5a5BC3tppcBr0iWiehyvkVYyLWtKbk8dsbPpq tDiyWuvqpUHGU1ui4ByvIaawn/Pa48IwXAbRWxJodzCkFbZVRS7pDud15zIZe+ufr73V a8Cy/vGzHGVq/0xAYBdZ1uu67vKjHd+xKgFzr7mKHw0HXblxrGubPkQpeDQwY0aUUi2f ZP5I3aCsAKk58Hl8DBV9jvHx7PFzDuFJFHEPFmvsFrBi/WHittMh4ojAlrk+Ya0Cg+Z/ vdSauxnFiYObgWdD9phfvOby2/u1RFand4eBr+lz2qbTUEOpREn9UjG3i6R5dADRa4wb 29KQ== X-Gm-Message-State: AOJu0YxJTVA+XWfnS1vIvnZxxPLeB10iJjWnXTm7qaXSndjv9jISVdSM PNFcjjb+wydTWrVmzk4DR2qqL6oPj27GIsF228v9/PVhbIULiVmARNrkEmi6sPeZMC4UxlKr6/N n2g33AjPNqU9gLo1rIVKdzerB8W22jGB8QoX4m8pvIVkAdNWoCniN258ovdNRM0cMqXJ/vdbtfi 9BJbEGMygwXw== X-Received: by 2002:ac2:5e70:0:b0:4f8:661f:60a4 with SMTP id a16-20020ac25e70000000b004f8661f60a4mr1345653lfr.41.1691664905131; Thu, 10 Aug 2023 03:55:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFY7GxqJXA2cePG8IGrxbzknyDxGlhlrTIntijSq8/dSqIIoMteFEGSHaAFE1+hQs9SuoD2yQ== X-Received: by 2002:ac2:5e70:0:b0:4f8:661f:60a4 with SMTP id a16-20020ac25e70000000b004f8661f60a4mr1345637lfr.41.1691664904860; Thu, 10 Aug 2023 03:55:04 -0700 (PDT) Received: from miu.piliscsaba.redhat.com (193-226-246-142.pool.digikabel.hu. [193.226.246.142]) by smtp.gmail.com with ESMTPSA id v20-20020aa7cd54000000b005231f324a0bsm643732edw.28.2023.08.10.03.55.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 03:55:04 -0700 (PDT) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Subject: [PATCH 2/5] fuse: add STATX request Date: Thu, 10 Aug 2023 12:54:58 +0200 Message-Id: <20230810105501.1418427-3-mszeredi@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230810105501.1418427-1-mszeredi@redhat.com> References: <20230810105501.1418427-1-mszeredi@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use the same structure as statx. Signed-off-by: Miklos Szeredi --- include/uapi/linux/fuse.h | 56 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h index b3fcab13fcd3..fe700b91b33b 100644 --- a/include/uapi/linux/fuse.h +++ b/include/uapi/linux/fuse.h @@ -207,6 +207,9 @@ * - add FUSE_EXT_GROUPS * - add FUSE_CREATE_SUPP_GROUP * - add FUSE_HAS_EXPIRE_ONLY + * + * 7.39 + * - add FUSE_STATX and related structures */ #ifndef _LINUX_FUSE_H @@ -242,7 +245,7 @@ #define FUSE_KERNEL_VERSION 7 /** Minor version number of this interface */ -#define FUSE_KERNEL_MINOR_VERSION 38 +#define FUSE_KERNEL_MINOR_VERSION 39 /** The node ID of the root inode */ #define FUSE_ROOT_ID 1 @@ -269,6 +272,40 @@ struct fuse_attr { uint32_t flags; }; +/* + * The following structures are bit-for-bit compatible with the statx(2) ABI in + * Linux. + */ +struct fuse_sx_time { + int64_t tv_sec; + uint32_t tv_nsec; + int32_t __reserved; +}; + +struct fuse_statx { + uint32_t mask; + uint32_t blksize; + uint64_t attributes; + uint32_t nlink; + uint32_t uid; + uint32_t gid; + uint16_t mode; + uint16_t __spare0[1]; + uint64_t ino; + uint64_t size; + uint64_t blocks; + uint64_t attributes_mask; + struct fuse_sx_time atime; + struct fuse_sx_time btime; + struct fuse_sx_time ctime; + struct fuse_sx_time mtime; + uint32_t rdev_major; + uint32_t rdev_minor; + uint32_t dev_major; + uint32_t dev_minor; + uint64_t __spare2[14]; +}; + struct fuse_kstatfs { uint64_t blocks; uint64_t bfree; @@ -575,6 +612,7 @@ enum fuse_opcode { FUSE_REMOVEMAPPING = 49, FUSE_SYNCFS = 50, FUSE_TMPFILE = 51, + FUSE_STATX = 52, /* CUSE specific operations */ CUSE_INIT = 4096, @@ -639,6 +677,22 @@ struct fuse_attr_out { struct fuse_attr attr; }; +struct fuse_statx_in { + uint32_t getattr_flags; + uint32_t reserved; + uint64_t fh; + uint32_t sx_flags; + uint32_t sx_mask; +}; + +struct fuse_statx_out { + uint64_t attr_valid; /* Cache timeout for the attributes */ + uint32_t attr_valid_nsec; + uint32_t flags; + uint64_t spare[2]; + struct fuse_statx stat; +}; + #define FUSE_COMPAT_MKNOD_IN_SIZE 8 struct fuse_mknod_in { From patchwork Thu Aug 10 10:54:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 13349280 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 EEB2DC001DB for ; Thu, 10 Aug 2023 10:56:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234461AbjHJK4F (ORCPT ); Thu, 10 Aug 2023 06:56:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234373AbjHJK4C (ORCPT ); Thu, 10 Aug 2023 06:56:02 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4352B1736 for ; Thu, 10 Aug 2023 03:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691664909; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NPNRQJq/hyiYldLtrBMY3seKZRMqc2xitsd2NuT766U=; b=RiPLeBvw0uuzdLPCbsBr1eCw+hh4AAybdNrFhH9H7+1rrsZY8fdKvTsQVNnMC7gfkbSpYq HlcwpS1X1FI4Ifdq4GXObuKqN1MZpiy+DNE6B51GX5GzOfvw+JuM1IyZ8e8oHmmu9HFSun y9K5jOYfzUiEMPKl38rcepK1ipu5aRc= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-4Xw3uI9CMUCXHM6WcjuLdg-1; Thu, 10 Aug 2023 06:55:08 -0400 X-MC-Unique: 4Xw3uI9CMUCXHM6WcjuLdg-1 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-52349404bb0so535875a12.2 for ; Thu, 10 Aug 2023 03:55:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691664906; x=1692269706; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NPNRQJq/hyiYldLtrBMY3seKZRMqc2xitsd2NuT766U=; b=auqOzn8SoI3M8J+IatG5L8WcoB3R5uKQMVeMxi9JwmwVc2ywyChLe6UtTJW9hCinDq mBMaAXcKAsy4PImui26ihBb+lpuJvTNMfkyFd8DcC7/ldTSNYjS9b4slv6bhSxoRpSGA 6ujJ5DynfAqqd7pglgsjHYQl4l1ZLeXDFpdm7Fc580fboHvWnL6PU7MiGzoitVNhSn8g p0u2vqB60G8MoC1wPovFJuZdWpBwhPYaURDqhixWyA8u7Tolur1IGHlFPMRW+GH9wOZd AMZGDHJ0ZpMJAcz+mSYr6gXDRQEFUNsXwAZTXUKYKkwDmuFGze1LbTUTtBmJTbXrpRzh 8Jiw== X-Gm-Message-State: AOJu0YxCqNEXy1zHWCFMPmiCTr7VYaQjQC1qRVWXWK+FKKQuM7bdSgip iqFVIywARWg6Lkf+4keiipLoTy3cmjabWzN0txNqzbeG3mIrl6QyiEJIxnwAAEX+Zb4orRHuPta QZh9dv6RYC9RNgV/nPr/8xpgnoU6Ft0I/Wg07R5DiTq8Q3uuzPMECW2l3tZTSWRtZMDCZh55yH2 4qUwDa44tgrA== X-Received: by 2002:aa7:d646:0:b0:51e:53eb:88a3 with SMTP id v6-20020aa7d646000000b0051e53eb88a3mr1641341edr.25.1691664906534; Thu, 10 Aug 2023 03:55:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGpjv0QjJoe8gLhTAOi//9Ylb+gcQKJlx8YVL8Nuqm6t+2y/Bm/vapXtIKJXH/LOcZElgjxKQ== X-Received: by 2002:aa7:d646:0:b0:51e:53eb:88a3 with SMTP id v6-20020aa7d646000000b0051e53eb88a3mr1641332edr.25.1691664906171; Thu, 10 Aug 2023 03:55:06 -0700 (PDT) Received: from miu.piliscsaba.redhat.com (193-226-246-142.pool.digikabel.hu. [193.226.246.142]) by smtp.gmail.com with ESMTPSA id v20-20020aa7cd54000000b005231f324a0bsm643732edw.28.2023.08.10.03.55.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 03:55:05 -0700 (PDT) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Subject: [PATCH 3/5] fuse: add ATTR_TIMEOUT macro Date: Thu, 10 Aug 2023 12:54:59 +0200 Message-Id: <20230810105501.1418427-4-mszeredi@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230810105501.1418427-1-mszeredi@redhat.com> References: <20230810105501.1418427-1-mszeredi@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Next patch will introduce yet another type attribute reply. Add a macro that can handle attribute timeouts for all of the structs. Signed-off-by: Miklos Szeredi --- fs/fuse/dir.c | 26 ++++++++------------------ fs/fuse/fuse_i.h | 5 ++++- fs/fuse/readdir.c | 4 ++-- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index d38ab93e2007..04006db6e173 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -92,7 +92,7 @@ static void fuse_dentry_settime(struct dentry *dentry, u64 time) /* * Calculate the time in jiffies until a dentry/attributes are valid */ -static u64 time_to_jiffies(u64 sec, u32 nsec) +u64 fuse_time_to_jiffies(u64 sec, u32 nsec) { if (sec || nsec) { struct timespec64 ts = { @@ -112,17 +112,7 @@ static u64 time_to_jiffies(u64 sec, u32 nsec) void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o) { fuse_dentry_settime(entry, - time_to_jiffies(o->entry_valid, o->entry_valid_nsec)); -} - -static u64 attr_timeout(struct fuse_attr_out *o) -{ - return time_to_jiffies(o->attr_valid, o->attr_valid_nsec); -} - -u64 entry_attr_timeout(struct fuse_entry_out *o) -{ - return time_to_jiffies(o->attr_valid, o->attr_valid_nsec); + fuse_time_to_jiffies(o->entry_valid, o->entry_valid_nsec)); } void fuse_invalidate_attr_mask(struct inode *inode, u32 mask) @@ -266,7 +256,7 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags) forget_all_cached_acls(inode); fuse_change_attributes(inode, &outarg.attr, - entry_attr_timeout(&outarg), + ATTR_TIMEOUT(&outarg), attr_version); fuse_change_entry_timeout(entry, &outarg); } else if (inode) { @@ -399,7 +389,7 @@ int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name goto out_put_forget; *inode = fuse_iget(sb, outarg->nodeid, outarg->generation, - &outarg->attr, entry_attr_timeout(outarg), + &outarg->attr, ATTR_TIMEOUT(outarg), attr_version); err = -ENOMEM; if (!*inode) { @@ -686,7 +676,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, ff->nodeid = outentry.nodeid; ff->open_flags = outopen.open_flags; inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation, - &outentry.attr, entry_attr_timeout(&outentry), 0); + &outentry.attr, ATTR_TIMEOUT(&outentry), 0); if (!inode) { flags &= ~(O_CREAT | O_EXCL | O_TRUNC); fuse_sync_release(NULL, ff, flags); @@ -813,7 +803,7 @@ static int create_new_entry(struct fuse_mount *fm, struct fuse_args *args, goto out_put_forget_req; inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation, - &outarg.attr, entry_attr_timeout(&outarg), 0); + &outarg.attr, ATTR_TIMEOUT(&outarg), 0); if (!inode) { fuse_queue_forget(fm->fc, forget, outarg.nodeid, 1); return -ENOMEM; @@ -1190,7 +1180,7 @@ static int fuse_do_getattr(struct inode *inode, struct kstat *stat, err = -EIO; } else { fuse_change_attributes(inode, &outarg.attr, - attr_timeout(&outarg), + ATTR_TIMEOUT(&outarg), attr_version); if (stat) fuse_fillattr(inode, &outarg.attr, stat); @@ -1867,7 +1857,7 @@ int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, } fuse_change_attributes_common(inode, &outarg.attr, - attr_timeout(&outarg), + ATTR_TIMEOUT(&outarg), fuse_get_cache_mask(inode)); oldsize = inode->i_size; /* see the comment in fuse_change_attributes() */ diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 9b7fc7d3c7f1..fd55c09514cd 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1111,7 +1111,10 @@ void fuse_invalidate_entry_cache(struct dentry *entry); void fuse_invalidate_atime(struct inode *inode); -u64 entry_attr_timeout(struct fuse_entry_out *o); +u64 fuse_time_to_jiffies(u64 sec, u32 nsec); +#define ATTR_TIMEOUT(o) \ + fuse_time_to_jiffies((o)->attr_valid, (o)->attr_valid_nsec) + void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o); /** diff --git a/fs/fuse/readdir.c b/fs/fuse/readdir.c index dc603479b30e..48b3a6ec278b 100644 --- a/fs/fuse/readdir.c +++ b/fs/fuse/readdir.c @@ -224,7 +224,7 @@ static int fuse_direntplus_link(struct file *file, forget_all_cached_acls(inode); fuse_change_attributes(inode, &o->attr, - entry_attr_timeout(o), + ATTR_TIMEOUT(o), attr_version); /* * The other branch comes via fuse_iget() @@ -232,7 +232,7 @@ static int fuse_direntplus_link(struct file *file, */ } else { inode = fuse_iget(dir->i_sb, o->nodeid, o->generation, - &o->attr, entry_attr_timeout(o), + &o->attr, ATTR_TIMEOUT(o), attr_version); if (!inode) inode = ERR_PTR(-ENOMEM); From patchwork Thu Aug 10 10:55:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 13349279 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 E9A88C001E0 for ; Thu, 10 Aug 2023 10:56:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230510AbjHJK4D (ORCPT ); Thu, 10 Aug 2023 06:56:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234021AbjHJK4C (ORCPT ); Thu, 10 Aug 2023 06:56:02 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9140826AC for ; Thu, 10 Aug 2023 03:55:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691664910; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yobj2C2jpQ0SRM9YFm12DxRhqrSRbPGhdfbz0EvvYa0=; b=LAu33BZI8vj7TktBnjZvCZmeXzs+IIf+LEJ/gQ4spPi5MKIMIwxHfO7Unnz1rvlOenCEQ5 D6gz/8kBcysk6Z1SbJ4uMo0zn8hRTQ9j+G1kqWk/l1Unyx5mFuyuybEg7Lk+FEDhO9YdYg BkugO4V4ufoO8Qu1qafKQDZ13PqGwo4= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-107-6Dn8WLrUOsanhewdRrDuag-1; Thu, 10 Aug 2023 06:55:09 -0400 X-MC-Unique: 6Dn8WLrUOsanhewdRrDuag-1 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-52310538efaso533063a12.3 for ; Thu, 10 Aug 2023 03:55:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691664908; x=1692269708; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yobj2C2jpQ0SRM9YFm12DxRhqrSRbPGhdfbz0EvvYa0=; b=VtjGrK+7aiIbLW5UvvluTJGJPooMZOHOJ2G/67n5i3zGR/RW+vU+7EYgN2dedcJSu3 GuqtEHx2P18aJBnJbq7WZney9UYUfdONY4ZDfFyhkBusJjLjIz5SitBko222ba3ycrrF EvO9I6i5yBsFe+AwFzME1HbjcLos4sVJkAZi/D61Nl/xxXPOzt43XF6ZjaO46ux826Ao lDPlWq5TFvLrOgDrkTYcRiS4Xh6iV3e/+nXd8E/hO7TYZqWY4Q9ltX/ST2Tztj95NvCo pT1QyW14uj9fLZl6qZLCkBohLJc0alJQBPPjMyrXq1GIYV408+sNc1QZtV788/uNXJ9+ 17BQ== X-Gm-Message-State: AOJu0YySP/DIH6hgwkaBbfQ91EVlmzizi8DhtDi7IgsiH8HFBVVTSCSm RliH+c7pti/QfmCjo89arTnn2ZX+3zxCEKCqzy2/fvWVuTuFcUtDpaJfo6bYioYpkcx2rzlame+ +N1mrZeF0zk1RIff7jrrYm4SH3E8tAOA7XB8YCUXq2PVNIrUwQOj+mFFH/0ZWY6jvvyv8QLRxmj 3hB+0BO2Iyuw== X-Received: by 2002:aa7:c593:0:b0:521:e502:baf8 with SMTP id g19-20020aa7c593000000b00521e502baf8mr1767138edq.11.1691664907954; Thu, 10 Aug 2023 03:55:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGXQBIMk7o8IWE4YwMNtCJ0RBhm1xIYb4i6avmLM8PBpa2D3mChsTR3Sy94A7JYRbi6kk7XrA== X-Received: by 2002:aa7:c593:0:b0:521:e502:baf8 with SMTP id g19-20020aa7c593000000b00521e502baf8mr1767121edq.11.1691664907504; Thu, 10 Aug 2023 03:55:07 -0700 (PDT) Received: from miu.piliscsaba.redhat.com (193-226-246-142.pool.digikabel.hu. [193.226.246.142]) by smtp.gmail.com with ESMTPSA id v20-20020aa7cd54000000b005231f324a0bsm643732edw.28.2023.08.10.03.55.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 03:55:06 -0700 (PDT) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Subject: [PATCH 4/5] fuse: implement statx Date: Thu, 10 Aug 2023 12:55:00 +0200 Message-Id: <20230810105501.1418427-5-mszeredi@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230810105501.1418427-1-mszeredi@redhat.com> References: <20230810105501.1418427-1-mszeredi@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Allow querying btime. When btime is requested in mask, then FUSE_STATX request is sent. Otherwise keep using FUSE_GETATTR. The userspace interface for statx matches that of the statx(2) API. However there are limitations on how this interface is used: - returned basic stats and btime are used, stx_attributes, etc. are ignored - always query basic stats and btime, regardless of what was requested - requested sync type is ignored, the default is passed to the server - if server returns with some attributes missing from the result_mask, then no attributes will be cached - btime is not cached yet (next patch will fix that) For new inodes initialize fi->inval_mask to "all invalid", instead of "all valid" as previously. Also only clear basic stats from inval_mask when caching attributes. This will result in the caching logic not thinking that btime is cached. Signed-off-by: Miklos Szeredi Signed-off-by: Miklos Szeredi --- fs/fuse/dir.c | 106 ++++++++++++++++++++++++++++++++++++++++++++--- fs/fuse/fuse_i.h | 3 ++ fs/fuse/inode.c | 5 ++- 3 files changed, 107 insertions(+), 7 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 04006db6e173..552157bd6a4d 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -350,10 +350,14 @@ int fuse_valid_type(int m) S_ISBLK(m) || S_ISFIFO(m) || S_ISSOCK(m); } +bool fuse_valid_size(u64 size) +{ + return size <= LLONG_MAX; +} + bool fuse_invalid_attr(struct fuse_attr *attr) { - return !fuse_valid_type(attr->mode) || - attr->size > LLONG_MAX; + return !fuse_valid_type(attr->mode) || !fuse_valid_size(attr->size); } int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name, @@ -1143,6 +1147,84 @@ static void fuse_fillattr(struct inode *inode, struct fuse_attr *attr, stat->blksize = 1 << blkbits; } +static void fuse_statx_to_attr(struct fuse_statx *sx, struct fuse_attr *attr) +{ + memset(attr, 0, sizeof(*attr)); + attr->ino = sx->ino; + attr->size = sx->size; + attr->blocks = sx->blocks; + attr->atime = sx->atime.tv_sec; + attr->mtime = sx->mtime.tv_sec; + attr->ctime = sx->ctime.tv_sec; + attr->atimensec = sx->atime.tv_nsec; + attr->mtimensec = sx->mtime.tv_nsec; + attr->ctimensec = sx->ctime.tv_nsec; + attr->mode = sx->mode; + attr->nlink = sx->nlink; + attr->uid = sx->uid; + attr->gid = sx->gid; + attr->rdev = new_encode_dev(MKDEV(sx->rdev_major, sx->rdev_minor)); + attr->blksize = sx->blksize; +} + +static int fuse_do_statx(struct inode *inode, struct file *file, + struct kstat *stat) +{ + int err; + struct fuse_attr attr; + struct fuse_statx *sx; + struct fuse_statx_in inarg; + struct fuse_statx_out outarg; + struct fuse_mount *fm = get_fuse_mount(inode); + u64 attr_version = fuse_get_attr_version(fm->fc); + FUSE_ARGS(args); + + memset(&inarg, 0, sizeof(inarg)); + memset(&outarg, 0, sizeof(outarg)); + /* Directories have separate file-handle space */ + if (file && S_ISREG(inode->i_mode)) { + struct fuse_file *ff = file->private_data; + + inarg.getattr_flags |= FUSE_GETATTR_FH; + inarg.fh = ff->fh; + } + /* For now leave sync hints as the default, request all stats. */ + inarg.sx_flags = 0; + inarg.sx_mask = STATX_BASIC_STATS | STATX_BTIME; + args.opcode = FUSE_STATX; + args.nodeid = get_node_id(inode); + args.in_numargs = 1; + args.in_args[0].size = sizeof(inarg); + args.in_args[0].value = &inarg; + args.out_numargs = 1; + args.out_args[0].size = sizeof(outarg); + args.out_args[0].value = &outarg; + err = fuse_simple_request(fm, &args); + if (err) + return err; + + sx = &outarg.stat; + if (((sx->mask & STATX_SIZE) && !fuse_valid_size(sx->size)) || + ((sx->mask & STATX_TYPE) && (!fuse_valid_type(sx->mode) || + inode_wrong_type(inode, sx->mode)))) { + make_bad_inode(inode); + return -EIO; + } + + fuse_statx_to_attr(&outarg.stat, &attr); + if ((sx->mask & STATX_BASIC_STATS) == STATX_BASIC_STATS) { + fuse_change_attributes(inode, &attr, ATTR_TIMEOUT(&outarg), + attr_version); + } + stat->result_mask = sx->mask & (STATX_BASIC_STATS | STATX_BTIME); + stat->btime.tv_sec = sx->btime.tv_sec; + stat->btime.tv_nsec = min_t(u32, sx->btime.tv_nsec, NSEC_PER_SEC - 1); + fuse_fillattr(inode, &attr, stat); + stat->result_mask |= STATX_TYPE; + + return 0; +} + static int fuse_do_getattr(struct inode *inode, struct kstat *stat, struct file *file) { @@ -1194,13 +1276,18 @@ static int fuse_update_get_attr(struct inode *inode, struct file *file, unsigned int flags) { struct fuse_inode *fi = get_fuse_inode(inode); + struct fuse_conn *fc = get_fuse_conn(inode); int err = 0; bool sync; u32 inval_mask = READ_ONCE(fi->inval_mask); u32 cache_mask = fuse_get_cache_mask(inode); - /* FUSE only supports basic stats */ - request_mask &= STATX_BASIC_STATS; + + /* FUSE only supports basic stats and possibly btime */ + request_mask &= STATX_BASIC_STATS | STATX_BTIME; +retry: + if (fc->no_statx) + request_mask &= STATX_BASIC_STATS; if (!request_mask) sync = false; @@ -1215,7 +1302,16 @@ static int fuse_update_get_attr(struct inode *inode, struct file *file, if (sync) { forget_all_cached_acls(inode); - err = fuse_do_getattr(inode, stat, file); + /* Try statx if BTIME is requested */ + if (!fc->no_statx && (request_mask & ~STATX_BASIC_STATS)) { + err = fuse_do_statx(inode, file, stat); + if (err == -ENOSYS) { + fc->no_statx = 1; + goto retry; + } + } else { + err = fuse_do_getattr(inode, stat, file); + } } else if (stat) { generic_fillattr(&nop_mnt_idmap, inode, stat); stat->mode = fi->orig_i_mode; diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index fd55c09514cd..daae31c58754 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -792,6 +792,9 @@ struct fuse_conn { /* Is tmpfile not implemented by fs? */ unsigned int no_tmpfile:1; + /* Is statx not implemented by fs? */ + unsigned int no_statx:1; + /** The number of requests waiting for completion */ atomic_t num_waiting; diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index f19d748890f0..a6cc102e66bc 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -77,7 +77,7 @@ static struct inode *fuse_alloc_inode(struct super_block *sb) return NULL; fi->i_time = 0; - fi->inval_mask = 0; + fi->inval_mask = ~0; fi->nodeid = 0; fi->nlookup = 0; fi->attr_version = 0; @@ -172,7 +172,8 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, fi->attr_version = atomic64_inc_return(&fc->attr_version); fi->i_time = attr_valid; - WRITE_ONCE(fi->inval_mask, 0); + /* Clear basic stats from invalid mask */ + set_mask_bits(&fi->inval_mask, STATX_BASIC_STATS, 0); inode->i_ino = fuse_squash_ino(attr->ino); inode->i_mode = (inode->i_mode & S_IFMT) | (attr->mode & 07777); From patchwork Thu Aug 10 10:55:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 13349281 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 8547EC04E69 for ; Thu, 10 Aug 2023 10:56:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234476AbjHJK4G (ORCPT ); Thu, 10 Aug 2023 06:56:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234444AbjHJK4F (ORCPT ); Thu, 10 Aug 2023 06:56:05 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9A8E26B8 for ; Thu, 10 Aug 2023 03:55:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691664912; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Xwa6+6zF9pv0djpXrnIbd8z6z5wH7RTpeeZ5RrhlEq0=; b=I/gbyPC446Rh1yQGhNPA0lhOOX8m0wMc0ZKrxq31lcKfgv6nLqCAEkQ2A3ShjbS5W6CI5F 7C+q38ZUpFvO9o7bgZMg6ILg0k0Wt6qDMQuM7tbv5oZK0ky8o3dwdaEym8APaUjcuSEIJW +XGkX2SK/eralu/XEYK063MhvNoEovs= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-644-qe3Js4a4PSOciikMrrL3vg-1; Thu, 10 Aug 2023 06:55:10 -0400 X-MC-Unique: qe3Js4a4PSOciikMrrL3vg-1 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-523338c7bc8so566486a12.3 for ; Thu, 10 Aug 2023 03:55:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691664909; x=1692269709; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Xwa6+6zF9pv0djpXrnIbd8z6z5wH7RTpeeZ5RrhlEq0=; b=AJUkwfGMXEOoPvqwtbYJeHDD+O5Ze8V40JYVCHLyM5ODQsNleT191S3B8VpiZ6+SZI Ws+5eCcDMOAvCZ4TW5pVkHHl45nulOX7t3i3K8ViZgOpiNN8SNhfatgbREWXuuPSUd4O Br3CejzSulR1fVNvWS4QhfZ5E0frB4pWH2S8wvskdE2BksI64ogYb804axIOjZwodh7N ZKf5NhDRiNI9Jzwv+V3ybbQ0kjj1MNsdVQdLVaCwpOLVj+rWT8C8OgwcwqLXPYtzX6zg YTM3VeATg9wCXq5naF+w93ooUOhIGKEZG40rYTfEE3tDuybqQxLlXeDeX0pUrNEc7XBA TZMg== X-Gm-Message-State: AOJu0YzR5RAUzMuz5esm/FGADrpWYXwsmZ6IcycbOlKcInQ0wfhSLdzs RL3Vw8oMWU1mwDG/tq2FlKQIWdWP8FMDcVNLj3cM8s4o+gpyAdF5MMlLL+ZEe3Lcqmzjr+hWN+6 3kiVJyphAXpaOoU5Sg0dsoUiVDucvosrDRcaQ1Pmaiv1sqo0GEcoyP6ycDBgUcvHjantr5jyMDO rMhBiCmKWUtw== X-Received: by 2002:a50:ec84:0:b0:523:1ce9:1f41 with SMTP id e4-20020a50ec84000000b005231ce91f41mr1992692edr.18.1691664909397; Thu, 10 Aug 2023 03:55:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHFCuL0IZC0lTPmn/H8CQNSDJR7CUUSaNs1Lm2FwXonn3StFHC6uLjGfmFy+v/jcH7UcyD56g== X-Received: by 2002:a50:ec84:0:b0:523:1ce9:1f41 with SMTP id e4-20020a50ec84000000b005231ce91f41mr1992666edr.18.1691664909038; Thu, 10 Aug 2023 03:55:09 -0700 (PDT) Received: from miu.piliscsaba.redhat.com (193-226-246-142.pool.digikabel.hu. [193.226.246.142]) by smtp.gmail.com with ESMTPSA id v20-20020aa7cd54000000b005231f324a0bsm643732edw.28.2023.08.10.03.55.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 03:55:07 -0700 (PDT) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Subject: [PATCH 5/5] fuse: cache btime Date: Thu, 10 Aug 2023 12:55:01 +0200 Message-Id: <20230810105501.1418427-6-mszeredi@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230810105501.1418427-1-mszeredi@redhat.com> References: <20230810105501.1418427-1-mszeredi@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Not all inode attributes are supported by all filesystems, but for the basic stats (which are returned by stat(2) and friends) all of them will have some value, even if that doesn't reflect a real attribute of the file. Btime is different, in that filesystems are free to report or not report a value in statx. If the value is available, then STATX_BTIME bit is set in stx_mask. When caching the value of btime, remember the availability of the attribute as well as the value (if available). This is done by using the FUSE_I_BTIME bit in fuse_inode->state to indicate availability, while using fuse_inode->inval_mask & STATX_BTIME to indicate the state of the cache itself (i.e. set if cache is invalid, and cleared if cache is valid). Signed-off-by: Miklos Szeredi --- fs/fuse/dir.c | 14 +++++++++----- fs/fuse/fuse_i.h | 7 +++++++ fs/fuse/inode.c | 25 +++++++++++++++++++++++-- fs/fuse/readdir.c | 2 +- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 552157bd6a4d..42f49fe6e770 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -255,7 +255,7 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags) goto invalid; forget_all_cached_acls(inode); - fuse_change_attributes(inode, &outarg.attr, + fuse_change_attributes(inode, &outarg.attr, NULL, ATTR_TIMEOUT(&outarg), attr_version); fuse_change_entry_timeout(entry, &outarg); @@ -1213,8 +1213,8 @@ static int fuse_do_statx(struct inode *inode, struct file *file, fuse_statx_to_attr(&outarg.stat, &attr); if ((sx->mask & STATX_BASIC_STATS) == STATX_BASIC_STATS) { - fuse_change_attributes(inode, &attr, ATTR_TIMEOUT(&outarg), - attr_version); + fuse_change_attributes(inode, &attr, &outarg.stat, + ATTR_TIMEOUT(&outarg), attr_version); } stat->result_mask = sx->mask & (STATX_BASIC_STATS | STATX_BTIME); stat->btime.tv_sec = sx->btime.tv_sec; @@ -1261,7 +1261,7 @@ static int fuse_do_getattr(struct inode *inode, struct kstat *stat, fuse_make_bad(inode); err = -EIO; } else { - fuse_change_attributes(inode, &outarg.attr, + fuse_change_attributes(inode, &outarg.attr, NULL, ATTR_TIMEOUT(&outarg), attr_version); if (stat) @@ -1316,6 +1316,10 @@ static int fuse_update_get_attr(struct inode *inode, struct file *file, generic_fillattr(&nop_mnt_idmap, inode, stat); stat->mode = fi->orig_i_mode; stat->ino = fi->orig_ino; + if (test_bit(FUSE_I_BTIME, &fi->state)) { + stat->btime = fi->i_btime; + stat->result_mask |= STATX_BTIME; + } } return err; @@ -1952,7 +1956,7 @@ int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, /* FIXME: clear I_DIRTY_SYNC? */ } - fuse_change_attributes_common(inode, &outarg.attr, + fuse_change_attributes_common(inode, &outarg.attr, NULL, ATTR_TIMEOUT(&outarg), fuse_get_cache_mask(inode)); oldsize = inode->i_size; diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index daae31c58754..4608c3deab52 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -88,6 +88,9 @@ struct fuse_inode { preserve the original mode */ umode_t orig_i_mode; + /* Cache birthtime */ + struct timespec64 i_btime; + /** 64 bit inode number */ u64 orig_ino; @@ -167,6 +170,8 @@ enum { FUSE_I_SIZE_UNSTABLE, /* Bad inode */ FUSE_I_BAD, + /* Has btime */ + FUSE_I_BTIME, }; struct fuse_conn; @@ -1061,9 +1066,11 @@ void fuse_init_symlink(struct inode *inode); * Change attributes of an inode */ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, + struct fuse_statx *sx, u64 attr_valid, u64 attr_version); void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, + struct fuse_statx *sx, u64 attr_valid, u32 cache_mask); u32 fuse_get_cache_mask(struct inode *inode); diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index a6cc102e66bc..175ac7e4e06d 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -163,6 +163,7 @@ static ino_t fuse_squash_ino(u64 ino64) } void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, + struct fuse_statx *sx, u64 attr_valid, u32 cache_mask) { struct fuse_conn *fc = get_fuse_conn(inode); @@ -198,6 +199,25 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, inode->i_ctime.tv_sec = attr->ctime; inode->i_ctime.tv_nsec = attr->ctimensec; } + if (sx) { + /* Sanitize nsecs */ + sx->btime.tv_nsec = + min_t(u32, sx->btime.tv_nsec, NSEC_PER_SEC - 1); + + /* + * Btime has been queried, cache is valid (whether or not btime + * is available or not) so clear STATX_BTIME from inval_mask. + * + * Availability of the btime attribute is indicated in + * FUSE_I_BTIME + */ + set_mask_bits(&fi->inval_mask, STATX_BTIME, 0); + if (sx->mask & STATX_BTIME) { + set_bit(FUSE_I_BTIME, &fi->state); + fi->i_btime.tv_sec = sx->btime.tv_sec; + fi->i_btime.tv_nsec = sx->btime.tv_nsec; + } + } if (attr->blksize != 0) inode->i_blkbits = ilog2(attr->blksize); @@ -237,6 +257,7 @@ u32 fuse_get_cache_mask(struct inode *inode) } void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, + struct fuse_statx *sx, u64 attr_valid, u64 attr_version) { struct fuse_conn *fc = get_fuse_conn(inode); @@ -271,7 +292,7 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, } old_mtime = inode->i_mtime; - fuse_change_attributes_common(inode, attr, attr_valid, cache_mask); + fuse_change_attributes_common(inode, attr, sx, attr_valid, cache_mask); oldsize = inode->i_size; /* @@ -409,7 +430,7 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid, spin_lock(&fi->lock); fi->nlookup++; spin_unlock(&fi->lock); - fuse_change_attributes(inode, attr, attr_valid, attr_version); + fuse_change_attributes(inode, attr, NULL, attr_valid, attr_version); return inode; } diff --git a/fs/fuse/readdir.c b/fs/fuse/readdir.c index 48b3a6ec278b..1c5e5bfb5d58 100644 --- a/fs/fuse/readdir.c +++ b/fs/fuse/readdir.c @@ -223,7 +223,7 @@ static int fuse_direntplus_link(struct file *file, spin_unlock(&fi->lock); forget_all_cached_acls(inode); - fuse_change_attributes(inode, &o->attr, + fuse_change_attributes(inode, &o->attr, NULL, ATTR_TIMEOUT(o), attr_version); /*