Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp649432ybf; Fri, 28 Feb 2020 05:09:56 -0800 (PST) X-Google-Smtp-Source: APXvYqz99wHmJD9a+dBQjgc4iA9XIEQLOUNgzDrGgX8kEsf0Wltx7kLePcoNPvZJOd/QJiNifNCY X-Received: by 2002:a54:450d:: with SMTP id l13mr3112357oil.117.1582895395918; Fri, 28 Feb 2020 05:09:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582895395; cv=none; d=google.com; s=arc-20160816; b=htvJmLZqYo5OuKykqooMUfS6nOjn/OG3YKBF6N0TYtxmPRZgRlI7UF8sYbIkkI7Frr b2z7bXc516orIl4wYnTX8Ycn1ab+Bp+HT52mgWUosH4dOWettKOvLKWuTJI+iR66vFyP 2cKdtjvP187UFcMo7aQx4SFYez7VYE5kJjH4qavLo4aohhR1mzLom/9IXQ+zdFBLdNzB oElxj6LPLjQ61cSspOE2o0xSFK8tVkNKJjWhzxsMcC28YoCso3ykREZAsEEeH5+j45F7 zBbA60B/5tJU/7SMgUBIf3VH2dwdZZew8qI2BGcWhHP8teECJZz0/CC+PUZQfZS2vQjR qXTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=R6+NgKOvGU7WnxAOSrWHkptT277VM35k/++AgcgpjME=; b=MeSDrk/2gIPWNRKNfFzrNA5D5tcNBvhQsgR+4MzHIkg3b8RVbhVD62W/PgQPz9sgcH 8IdrvbRYGexqCFvy9y71URfiD4V8e2vlHqXTUdIrB+SaX9yROSSZPXUnDzl8hleWKfrE x6uA1Z28ZF2i4DOSdEVTV+DGpnJHG85ulaiqsffp0NXAG6sjf9YPGB2Eut7K9Qv2uJb8 HcjkgjoWdPsUKBEot7nvpKOQt8d1zxE1z1WbKoZ+RdK1KxZee3GnsjnoGTriH3ByDypr nuV95t9eSBJF4hYCcwZZD38XXfRtXGXVDj0LI8sx8+Z6W1wzZaX5e8TWGCEGU4cf0CPm b+WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ejGqG8qu; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 71si1700303otm.111.2020.02.28.05.09.40; Fri, 28 Feb 2020 05:09:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ejGqG8qu; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725900AbgB1NJi (ORCPT + 99 others); Fri, 28 Feb 2020 08:09:38 -0500 Received: from mail-yw1-f65.google.com ([209.85.161.65]:34597 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725861AbgB1NJh (ORCPT ); Fri, 28 Feb 2020 08:09:37 -0500 Received: by mail-yw1-f65.google.com with SMTP id b186so3236743ywc.1 for ; Fri, 28 Feb 2020 05:09:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=R6+NgKOvGU7WnxAOSrWHkptT277VM35k/++AgcgpjME=; b=ejGqG8qu+KFADf9DvCM5VGMqrq18yE3cNed8IlmPuXO6iu3xbs615NM+K3aqb1Nga5 dR2YJPOjfRlL2vi3IOTl0FqV3Cjh2Pb3TdBnU9nAOajsJLaRqo9XONlcFyCqp53d3uXK RtsyrlVoFLBLfuvZtUc8IvR4iZK90FEHNQ7khYHOnI9m+yrO30Mt6ZSNVbGeZfJsrcSD aXnIS+wTWLo8sxr9bUML3jNkEiFtXiHWHLGDWqUigr5pk+2xpM0QkxFhC9ZnM6z1OgIz zyE5W+js+BD7aYHEsdqwVo0ZbvTmH3ZcEdlYwFxs0R7l7SP1dL3f5h3/24//c6Ei5KM5 o5Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R6+NgKOvGU7WnxAOSrWHkptT277VM35k/++AgcgpjME=; b=maC2sqsA7d/OpyECUnK6+gGi+t19zEq4GAtFs9st5w2V0M8aMHwJmtYm3kVpCV4W4k lN2EgZm1W+Tl40vsYF4KHV1deTNXLQ48JsnwQhZx3vap3e0an76nbrAytF7cbDc0TUCW jbYnTFM3u0RhOfeke8Jle+ekFWAOWPo0xxSYUWNw6yhHwm2HSHTQIQcrT3aHdS6UsnV4 6lH0CLEF/Dm6VaaUDm646yUglkxzTdc+BJRXfL+8IJFYe55LGTA0+F97sxQujCnysvCr SZ+D8ked1IYKogHTqjeBqOJic9NkLY0i9G0JkGivJueaSgImvT6sKat7QE2bNi5KPEoQ eEUw== X-Gm-Message-State: APjAAAUuB6GWVsr34TZReP+iHpDvEV+p2Vnu4RHrCn665pqgmGAJccJI NNZAZ7OnOtfD3LkJNFqap9D2Gt6aeA== X-Received: by 2002:a25:694c:: with SMTP id e73mr268710ybc.198.1582895376267; Fri, 28 Feb 2020 05:09:36 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id j23sm3925150ywb.93.2020.02.28.05.09.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2020 05:09:35 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH 3/7] NFS: Add a helper nfs_client_for_each_server() Date: Fri, 28 Feb 2020 08:07:21 -0500 Message-Id: <20200228130725.1330705-3-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200228130725.1330705-2-trond.myklebust@hammerspace.com> References: <20200228130725.1330705-1-trond.myklebust@hammerspace.com> <20200228130725.1330705-2-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Add a helper nfs_client_for_each_server() to iterate through all the filesystems that are attached to a struct nfs_client, and apply a function to all the active ones. Signed-off-by: Trond Myklebust --- fs/nfs/internal.h | 4 +++- fs/nfs/super.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index f80c47d5ff27..3b6fa9edc9b5 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h @@ -417,7 +417,9 @@ extern int __init register_nfs_fs(void); extern void __exit unregister_nfs_fs(void); extern bool nfs_sb_active(struct super_block *sb); extern void nfs_sb_deactive(struct super_block *sb); - +extern int nfs_client_for_each_server(struct nfs_client *clp, + int (*fn)(struct nfs_server *, void *), + void *data); /* io.c */ extern void nfs_start_io_read(struct inode *inode); extern void nfs_end_io_read(struct inode *inode); diff --git a/fs/nfs/super.c b/fs/nfs/super.c index dada09b391c6..eb3a85492396 100644 --- a/fs/nfs/super.c +++ b/fs/nfs/super.c @@ -176,6 +176,41 @@ void nfs_sb_deactive(struct super_block *sb) } EXPORT_SYMBOL_GPL(nfs_sb_deactive); +static int __nfs_list_for_each_server(struct list_head *head, + int (*fn)(struct nfs_server *, void *), + void *data) +{ + struct nfs_server *server, *last = NULL; + int ret = 0; + + rcu_read_lock(); + list_for_each_entry_rcu(server, head, client_link) { + if (!nfs_sb_active(server->super)) + continue; + rcu_read_unlock(); + if (last) + nfs_sb_deactive(last->super); + last = server; + ret = fn(server, data); + if (ret) + goto out; + rcu_read_lock(); + } + rcu_read_unlock(); +out: + if (last) + nfs_sb_deactive(last->super); + return ret; +} + +int nfs_client_for_each_server(struct nfs_client *clp, + int (*fn)(struct nfs_server *, void *), + void *data) +{ + return __nfs_list_for_each_server(&clp->cl_superblocks, fn, data); +} +EXPORT_SYMBOL_GPL(nfs_client_for_each_server); + /* * Deliver file system statistics to userspace */ -- 2.24.1