Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1802077rda; Tue, 24 Oct 2023 03:59:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF65QmBfk8YOgGLTrJhCi9ExbdijCsk8hXV5oxFEcGQIjKqlgdPK80RsIB0NbD7F4TuYMYM X-Received: by 2002:a05:6a00:234c:b0:6b5:ec98:4289 with SMTP id j12-20020a056a00234c00b006b5ec984289mr9782766pfj.14.1698145143044; Tue, 24 Oct 2023 03:59:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698145143; cv=none; d=google.com; s=arc-20160816; b=tAE2JWyW07CtEgUSsfIh6wqjLgtUho135hpJrgyvWWyVzWl9PKEtSP3DPsUniOAD0U uGR4ZXRcm+V+UN/TjZ9c5j4XkcQsv2CpK8SV9lXmXobfWsWrsBYFK3G2RzAJD2EAHbP5 EAMhgWqihhCI/P2/ZHa/PTjyE30iOzBt5HgZoqUQPF27zjKwXFrSHhvFVmVherH0ejpU 0pON4IGEyT696+JOb6YDTua9citWNeTaa88O40/tN8DfHm7IDazLloPVgjs/qTm382qE D7b6xdb+JHnqJWVrU+2ab515oAWDnY1TPPZ5wZDuCuLVJ7sjC57VYGwkxIfYNmygfR1s a0uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=kfWiK2J4LcfYCXN2E5eTL3h5Rd/X+mU2pyacm/S+Zos=; fh=OkKekuiIVmuONiS36kbc8I/q6ZL1PQBddaHbHF56xxs=; b=m3sLRre9ToIr3ZIL8IR9IgrtshNEEdGHfmWwONX9WkbosRrSTYxwYLgppFuEvuBH7K wwFPZ9PLuerdUP1COVwBFVhtoIw6qn1c0quVmg37hq80dJPM9q17j7gfeqxOw92gp2MZ bx4SWOkkP+TCcTRieZ4HYYeELTEb+zrDhdzYAkpvv4rqCnDo0O6y+ym2c962Lcdgb9zR K2VG8MHu3ek2ZaLW6VGbSTuQHkH/GB9hzl83M6MnS06luWdtvUHxUFwE4uR85wjwKB7Y xfJ41RgaCFRunjnJA9cQnPnpdFDg7u+4utgHTchIiDejJ/RY0JiN2az2eww0W0hfCZTY dcDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=YjdOxtqP; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id d2-20020a056a0010c200b006bbe72a826asi8489368pfu.180.2023.10.24.03.59.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 03:59:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=YjdOxtqP; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 2D9E9807F49C; Tue, 24 Oct 2023 03:58:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229578AbjJXK65 (ORCPT + 99 others); Tue, 24 Oct 2023 06:58:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231433AbjJXK6y (ORCPT ); Tue, 24 Oct 2023 06:58:54 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89CD3109; Tue, 24 Oct 2023 03:58:52 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D0CDD1FD8B; Tue, 24 Oct 2023 10:58:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1698145130; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kfWiK2J4LcfYCXN2E5eTL3h5Rd/X+mU2pyacm/S+Zos=; b=YjdOxtqPnBFysJ8z7JAP2eEOLt4p8Cxh6XZiL9/ttc8+T55yo8TbBH5+8U5x0Aw3LklLNR c3vDpBPnQsNcTsRvHnxlmaUZE0pAz7kNqw1ZMJdhDjIzSxuqclXsQwqLC2+nfxmy2TP4lN MsYJPMtkaaWxqw9eWblCQFBwOrrY7XU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1698145130; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kfWiK2J4LcfYCXN2E5eTL3h5Rd/X+mU2pyacm/S+Zos=; b=mrEUG6pBFa9mXije4YNR5yf+yCbaFljOXklerk8FLZa+/j+7dHBJF4dpeHr5ZfOx2PAkSI dYKKQ70R0dTxYEAA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id BF7591391C; Tue, 24 Oct 2023 10:58:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id VNKwLmqjN2WQNgAAMHmgww (envelope-from ); Tue, 24 Oct 2023 10:58:50 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 4B680A05BC; Tue, 24 Oct 2023 12:58:50 +0200 (CEST) Date: Tue, 24 Oct 2023 12:58:50 +0200 From: Jan Kara To: Amir Goldstein Cc: Jan Kara , Jeff Layton , Chuck Lever , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, Jeremy Kerr , Ard Biesheuvel , Mike Kravetz , Muchun Song , Greg Kroah-Hartman , Tejun Heo , Eric Van Hensbergen , Latchesar Ionkov , Dominique Martinet Subject: Re: [PATCH] fs: report f_fsid from s_dev for "simple" filesystems Message-ID: <20231024105850.uooxnz5b7wtmrpbs@quack3> References: <20231023143049.2944970-1-amir73il@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231023143049.2944970-1-amir73il@gmail.com> Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: -6.60 X-Spamd-Result: default: False [-6.60 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-3.00)[-1.000]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; NEURAL_HAM_SHORT(-1.00)[-1.000]; RCPT_COUNT_TWELVE(0.00)[16]; FREEMAIL_TO(0.00)[gmail.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; MID_RHS_NOT_FQDN(0.50)[]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 24 Oct 2023 03:58:57 -0700 (PDT) On Mon 23-10-23 17:30:49, Amir Goldstein wrote: > There are many "simple" filesystems (*) that report null f_fsid in > statfs(2). Those "simple" filesystems report sb->s_dev as the st_dev > field of the stat syscalls for all inodes of the filesystem (**). > > In order to enable fanotify reporting of events with fsid on those > "simple" filesystems, report the sb->s_dev number in f_fsid field of > statfs(2). > > (*) For most of the "simple" filesystem refered to in this commit, the > ->statfs() operation is simple_statfs(). Some of those fs assign the > simple_statfs() method directly in their ->s_op struct and some assign it > indirectly via a call to simple_fill_super() or to pseudo_fs_fill_super() > with either custom or "simple" s_op. > We also make the same change to efivarfs and hugetlbfs, although they do > not use simple_statfs(), because they use the simple_* inode opreations > (e.g. simple_lookup()). > > (**) For most of the "simple" filesystems, the ->getattr() method is not > assigned, so stat() is implemented by generic_fillattr(). A few "simple" > filesystem use the simple_getattr() method which also calls > generic_fillattr() to fill most of the stat struct. > > The two exceptions are procfs and 9p. procfs implements several different > ->getattr() methods, but they all end up calling generic_fillattr() to > fill the st_dev field from sb->s_dev. > > 9p has more complicated ->getattr() methods, but they too, end up calling > generic_fillattr() to fill the st_dev field from sb->s_dev. > > Note that 9p and kernfs also call simple_statfs() from custom ->statfs() > methods which already fill the f_fsid field, but v9fs_statfs() calls > simple_statfs() only in case f_fsid was not filled and kenrfs_statfs() > overwrites f_fsid after calling simple_statfs(). > > Link: https://lore.kernel.org/r/20230919094820.g5bwharbmy2dq46w@quack3/ > Signed-off-by: Amir Goldstein Looks good. I agree with your choice of sb->s_dev for fsid. Feel free to add: Reviewed-by: Jan Kara Honza > --- > > Jan, > > This is a variant of the approach that you suggested in the Link above. > The two variations from your suggestion are: > > 1. I chose to use s_dev instead of s_uuid - I see no point in generating > s_uuid for those simple filesystems. IMO, for the simple filesystems > without open_by_handle_at() support, fanotify fid doesn't need to be > more unique than {st_dev,st_ino}, because the inode mark pins the > inode and prevent st_dev,st_ino collisions. > > 2. f_fsid is not filled by vfs according to fstype flag, but by > ->statfs() implementations (simple_statfs() for the majority). > > When applied together with the generic AT_HANDLE_FID support patches [1], > all of those simple filesystems can be watches with FAN_ERPORT_FID. > > According to your audit of filesystems in the Link above, this leaves: > "afs, coda, nfs - networking filesystems where inotify and fanotify have > dubious value anyway. > > freevxfs - the only real filesystem without f_fsid. Trivial to handle one > way or the other. > " > > There are two other filesystems that I found in my audit which also don't > fill f_fsid: fuse and gfs2. > > fuse is also a sort of a networking filesystems. Also, fuse supports NFS > export (as does nfs in some configurations) and I would like to stick to > the rule that filesystems the support decodable file handles, use an fsid > that is more unique than s_dev. > > gfs2 already has s_uuid, so we know what f_fsid should be. > BTW, afs also has a server uuid, it just doesn't set s_uuid. > > For btrfs, which fills a non-null, but non-uniform fsid, I already have > patches for inode_get_fsid [2] per your suggestion. > > IMO, we can defer dealing with all those remaining cases for later and > solve the "simple" cases first. > > Do you agree? > > So far, there were no objections to the generic AT_HANDLE_FID support > patches [1], although I am still waiting on an ACK from you on the last > patch. If this fsid patch is also aaceptable, do you think they could > be candidated for upcoming 6.7? > > Thanks, > Amir. > > [1] https://lore.kernel.org/r/20231018100000.2453965-1-amir73il@gmail.com/ > [2] https://github.com/amir73il/linux/commits/inode_fsid > > fs/efivarfs/super.c | 2 ++ > fs/hugetlbfs/inode.c | 2 ++ > fs/libfs.c | 3 +++ > 3 files changed, 7 insertions(+) > > diff --git a/fs/efivarfs/super.c b/fs/efivarfs/super.c > index 996271473609..2933090ad11f 100644 > --- a/fs/efivarfs/super.c > +++ b/fs/efivarfs/super.c > @@ -30,6 +30,7 @@ static int efivarfs_statfs(struct dentry *dentry, struct kstatfs *buf) > EFI_VARIABLE_BOOTSERVICE_ACCESS | > EFI_VARIABLE_RUNTIME_ACCESS; > u64 storage_space, remaining_space, max_variable_size; > + u64 id = huge_encode_dev(dentry->d_sb->s_dev); > efi_status_t status; > > /* Some UEFI firmware does not implement QueryVariableInfo() */ > @@ -53,6 +54,7 @@ static int efivarfs_statfs(struct dentry *dentry, struct kstatfs *buf) > buf->f_blocks = storage_space; > buf->f_bfree = remaining_space; > buf->f_type = dentry->d_sb->s_magic; > + buf->f_fsid = u64_to_fsid(id); > > /* > * In f_bavail we declare the free space that the kernel will allow writing > diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c > index 316c4cebd3f3..c003a27be6fe 100644 > --- a/fs/hugetlbfs/inode.c > +++ b/fs/hugetlbfs/inode.c > @@ -1204,7 +1204,9 @@ static int hugetlbfs_statfs(struct dentry *dentry, struct kstatfs *buf) > { > struct hugetlbfs_sb_info *sbinfo = HUGETLBFS_SB(dentry->d_sb); > struct hstate *h = hstate_inode(d_inode(dentry)); > + u64 id = huge_encode_dev(dentry->d_sb->s_dev); > > + buf->f_fsid = u64_to_fsid(id); > buf->f_type = HUGETLBFS_MAGIC; > buf->f_bsize = huge_page_size(h); > if (sbinfo) { > diff --git a/fs/libfs.c b/fs/libfs.c > index 37f2d34ee090..8117b24b929d 100644 > --- a/fs/libfs.c > +++ b/fs/libfs.c > @@ -41,6 +41,9 @@ EXPORT_SYMBOL(simple_getattr); > > int simple_statfs(struct dentry *dentry, struct kstatfs *buf) > { > + u64 id = huge_encode_dev(dentry->d_sb->s_dev); > + > + buf->f_fsid = u64_to_fsid(id); > buf->f_type = dentry->d_sb->s_magic; > buf->f_bsize = PAGE_SIZE; > buf->f_namelen = NAME_MAX; > -- > 2.34.1 > -- Jan Kara SUSE Labs, CR