Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2350037rda; Tue, 24 Oct 2023 23:11:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHG7g3yGlAnL3ftXS2AiObsKKkYTeW+N3FX7DW40wZxl4+DowMOqKKZXV3Mlr9yctnWUq5S X-Received: by 2002:a05:620a:430c:b0:778:a4a5:8bc5 with SMTP id u12-20020a05620a430c00b00778a4a58bc5mr15145712qko.6.1698214292891; Tue, 24 Oct 2023 23:11:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698214292; cv=none; d=google.com; s=arc-20160816; b=yXgX/1WLFfO/aBl7o5P9UkF0sjVkCmVD/3uWTVk2Omqg7d5YE1D053n+LeqAM7twYh n8nSnE//SiIqqWreM9HZq2ZY2wuH3azmQgFwCZLAjSpzXFhsLP3fkJjQLLdklA+rABXQ yU/iD45bsU63WQlmx9LgrUOu3ZbbtnTb520GJqwi88mj3107RoifeWCpX0lIvVyxJdc3 Mtc6+fI/olqmg/Z6s8vSGbVUwiAxoXgF8BU5U6Cm98oLoOBcBaWgU9SVeFyNbvfePwJk Uo4MaBRyL1BzZrQGdZVg0BsQ0u7DdMpeuRHFmSS9c0qI7EmxFoiytJG89c9iHWVaZYPX kTHw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=GjREnK1xDi9U0NJUrdaQZ7C6GoivK/F80JCHW1qci0s=; fh=t8eJKysYusQYbxbY9GmrTuMurErjcLa883CjLUQCUFU=; b=g/r9ABCdVldRQ0xBJ0+mo9BU2nQ4hD7M9C5fnyg8YSySh0xqzHB8+NZ+4Ks6U5cYe2 rDrWJjPeWgrxfpP4yKSBt1pMeB0nj5ClRMDYcFy+09CBEYI7CXMmOs7D9YqpNvt9CF9C VKUs3DXkBhdRl8u42lwTZBc9HaOrO3T5gljclwO7LDqRJKJX3ZsCMNAcwhjezTn372O6 0qF6WI5WcQlPsZH/RV+HknHM7/GRQoJdUOlALpn2DrG6sGnXQlMIfzCeCSbQnYdj/4UA xBJBwvC1lSyIje7HZWxBmip3bJRLGSjjg5/vZcJReBVj8XVi1PzMC83wb30wKxmFtcED sZug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DmCrEewM; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id t39-20020a252d27000000b00d9a38112775si9427021ybt.597.2023.10.24.23.11.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 23:11:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DmCrEewM; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 09BCB80CB16D; Tue, 24 Oct 2023 23:11:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231732AbjJYGL1 (ORCPT + 99 others); Wed, 25 Oct 2023 02:11:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231776AbjJYGL0 (ORCPT ); Wed, 25 Oct 2023 02:11:26 -0400 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E9E2A6; Tue, 24 Oct 2023 23:11:23 -0700 (PDT) Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2c59a4dcdacso16035621fa.1; Tue, 24 Oct 2023 23:11:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698214282; x=1698819082; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=GjREnK1xDi9U0NJUrdaQZ7C6GoivK/F80JCHW1qci0s=; b=DmCrEewMY9MuAujOQU96YsLMPmhvng+gsymauH0S4IeIUf17RrlDv9UsCc3f+gYJWD HAxNICHS22ec39uzrc6U5/ggZF65YrUcLK077dQd41qVlMbZbywkdJthpTHv5ai8zSH9 2wxMmXxd1ys5KBzfD3ZZHZ5xA9ZHN5mpL5pmmaZdeST7D1gn3GV1XrKjP8uAxDNBAI31 4wOlTsGKfF9bcJ741QB2dLfyCcqHSa4qtlnt3W2le5Qak/nEfZc4X4NFNFPJX/DwM2gA A6pB8WgJioPwL+yubDUTenbmM+xhUGcybmMU1qzAuOJtzZY/Zngmi8KmdU2TA2lAHEIP JvYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698214282; x=1698819082; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GjREnK1xDi9U0NJUrdaQZ7C6GoivK/F80JCHW1qci0s=; b=w9EoquK/TrA7bSKXU0CBTIsnro+HzHtH74sq60yKCu9eefx60YyYCIr2kaDggkqniL TxGb12UurCjSCr7B6Hy3yoHyM9rrGXYKn6HLRPquOglqqmGO442uc7tXRxh4EyUIuYIH Sr82g+1tNKfSqnDatdjL+FWthy30l1ksnV7jQZDHckU0Tet2DB31AYJj0I7XUxSTqa4+ qHT4THzj98Xa3dCbBHC8c+vVaTOjYv80xh9kTN9hVxxr8mpGiK+bO7i7YVMCxWC+VfeH BxP8lI7vYt9j3v6mQvT+TlAzDEVc8uVL8+hLlxUP5XEMojPSQLN3Q2aT2Gf6rKeQT7DC P4TQ== X-Gm-Message-State: AOJu0YxNlwy1CT9OniM3Z8vLSAoeaznZg1orGWnDCSTYsqFckbsXevVQ r1VhQjw8y60xcarUW39+9fA= X-Received: by 2002:a2e:8899:0:b0:2bc:c650:81b with SMTP id k25-20020a2e8899000000b002bcc650081bmr9828416lji.15.1698214281551; Tue, 24 Oct 2023 23:11:21 -0700 (PDT) Received: from amir-ThinkPad-T480.lan ([5.29.249.86]) by smtp.gmail.com with ESMTPSA id v19-20020a05600c471300b00405959bbf4fsm13851112wmo.19.2023.10.24.23.11.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 23:11:21 -0700 (PDT) From: Amir Goldstein To: Trond Myklebust , Anna Schumaker Cc: Benjamin Coddington , Jeff Layton , Chuck Lever , Christian Brauner , Jan Kara , linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org Subject: [PATCH v2] nfs: derive f_fsid from s_dev and server's fsid Date: Wed, 25 Oct 2023 09:11:17 +0300 Message-Id: <20231025061117.3068417-1-amir73il@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 24 Oct 2023 23:11:28 -0700 (PDT) Use s_dev number and the server's fsid to report f_fsid in statfs(2). The server's fsid could be zero for NFSv4 root export and is not unique across different servers, so we use the s_dev number to avoid local f_fsid collisions. The s_dev number could be easily recycled, so we use a 32bit hash of the server's fsid to try to avoid the recycling of same local f_fsid for different remote fs. The anon bdev number is only 20 bits (major is 0), so we could use more bits for the server's fsid hash, but avoiding f_fsid recycling is not critical, so 32bit hash is enough. This allows nfs client to be monitored by fanotify filesystem watch for local client access if nfs supports re-export. For example, with inotify-tools 4.23.8.0, the following command can be used to watch local client access over entire nfs filesystem: fsnotifywatch --filesystem /mnt/nfs Note that fanotify filesystem watch does not report remote changes on server. It provides the same notifications as inotify, but it watches over the entire filesystem and reports file handle of objects and fsid with events. Signed-off-by: Amir Goldstein --- Anna, Trond, I have changed v2 according to feedback from Ben. I would like to refer you to the documentation of f_fsid in statfs(2): "Nobody knows what f_fsid is supposed to contain... The general idea is that f_fsid contains some random stuff such that the pair (f_fsid,ino) uniquely determines a file. Some operating systems use (a variation on) the device number, or the device number combined with the filesystem type..." This definition leaves a lot of room for interpretations. I chose f_fsid format {dev_num, fsid_hash}, because I think that it nicely extends f_fsid format {dev_num, 0}, used by many fs without persistent fsid. Thanks, Amir. Changes since v1: - Use d_sev number to avoid collisions (bcodding) fs/nfs/super.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/nfs/super.c b/fs/nfs/super.c index 0d6473cb00cb..30bcd53da3bc 100644 --- a/fs/nfs/super.c +++ b/fs/nfs/super.c @@ -295,6 +295,15 @@ int nfs_statfs(struct dentry *dentry, struct kstatfs *buf) buf->f_ffree = res.afiles; buf->f_namelen = server->namelen; + /* + * Using the anon bdev number to avoid local f_fsid collisions. + * Server's fsid could be zero for NFSv4 root export and is not unique + * across different servers, but we use it as best effort to try to + * avoid the recycling of same local f_fsid for different remote fs. + */ + buf->f_fsid.val[0] = new_encode_dev(server->s_dev); + buf->f_fsid.val[1] = hash_64(server->fsid.major, 32) ^ + hash_64(server->fsid.minor, 32); return 0; -- 2.34.1