From patchwork Mon Feb 15 17:39:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Aloni X-Patchwork-Id: 12089045 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8482C43381 for ; Mon, 15 Feb 2021 17:41:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C79F464E37 for ; Mon, 15 Feb 2021 17:41:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230097AbhBORkz (ORCPT ); Mon, 15 Feb 2021 12:40:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231817AbhBORks (ORCPT ); Mon, 15 Feb 2021 12:40:48 -0500 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51882C061756 for ; Mon, 15 Feb 2021 09:40:08 -0800 (PST) Received: by mail-ed1-x532.google.com with SMTP id y18so9034325edw.13 for ; Mon, 15 Feb 2021 09:40:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernelim-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=niMm2T2Ds/z5dELiVAItbXe2qBqmyEJ1FhyXGa6auzQ=; b=bfPc3KoKEpJsCeibzLgmJfNGtZ/wskMzK2b7wlQAeVoH9IUc5JrG0i4qQuJX2P0RM1 QWBz7LJ+1pQMzp4/5xn88Hb2fxMVcJoo3O8lKL+4wxB02rI9CRi5clBjbrGWuLBW+YAp crZcNFDq1kUlRtRNNx+R8SyXqvcIPmIs+vpowbP0bkdcZ+TnT6mbba1dq6hBMd5xZhCm eWAo6r4dU/voZ9yfA+OINKbzz3x8Vslwc4l8I7hWYd390L3ehEQbayAHtH1EQsX+qtkG emGweGW2Rt1g1odANd5CvD4ETmsuc9aLWKacMhxRc9z8l3VYbNgtmMYdEO5J0XJas4ts upkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=niMm2T2Ds/z5dELiVAItbXe2qBqmyEJ1FhyXGa6auzQ=; b=HDhwzUMCBW7KTIXF6sH021LlId+d9/PDYcQbxgFVnZ/+LNj1HNpFDMabawSxhDh9pM kMJ9Mq24obki6X0Rk2z2ykGREnSmsZ1YVBLIFWgpSFHK3cN0QySPQUpX3QpE5rZEpn/f bCHa4cRklFeZ1DaU6WrchWNDeUv+UY4/6RvucfWIu7p+ZE828+Ci5OVyHIUdFa9nvWx/ LnQbKmHzhL1eCyu4mjN8GZkFZ5ngYAkZzurG3uIl5k+X2feGlh0XM8JHlQgklR5YT+QO ICoipSgZtD1i4cue4/o1DkNP+kfcp5KXjmZADB4epDOdogEpI7biCClOGnhIoLrZ7q+V 8Qrw== X-Gm-Message-State: AOAM530iB1IBnlKKazBsJA9+oID57mMx79t86cKOpBhC2QJ4O+zzqh0e Wi/r/UlxkDqxISc/gcIyPBfVw5/SAdklGw== X-Google-Smtp-Source: ABdhPJzc6iVX3aaPcHjDgERrkl5u5tk2AmZr6EgyGADtSmM7QvYtrJAsLy0v9pYLUNB3aKhRFqeZzw== X-Received: by 2002:a05:6402:22b0:: with SMTP id cx16mr16627948edb.255.1613410806719; Mon, 15 Feb 2021 09:40:06 -0800 (PST) Received: from jupiter.home.aloni.org ([77.124.84.167]) by smtp.gmail.com with ESMTPSA id e11sm11257485ejz.94.2021.02.15.09.40.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 09:40:06 -0800 (PST) From: Dan Aloni To: linux-nfs@vger.kernel.org, Anna Schumaker Cc: Trond Myklebust Subject: [PATCH v1 1/8] sunrpc: rename 'net' to 'client' Date: Mon, 15 Feb 2021 19:39:55 +0200 Message-Id: <20210215174002.2376333-2-dan@kernelim.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210215174002.2376333-1-dan@kernelim.com> References: <20210215174002.2376333-1-dan@kernelim.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org This is in preparation to adding a second directory to keep track of each transport. Signed-off-by: Dan Aloni --- net/sunrpc/clnt.c | 8 ++++---- net/sunrpc/sysfs.c | 22 +++++++++++----------- net/sunrpc/sysfs.h | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c index 02905eae5c0a..0a4811be01cd 100644 --- a/net/sunrpc/clnt.c +++ b/net/sunrpc/clnt.c @@ -301,7 +301,7 @@ static int rpc_client_register(struct rpc_clnt *clnt, int err; rpc_clnt_debugfs_register(clnt); - rpc_netns_sysfs_setup(clnt, net); + rpc_netns_client_sysfs_setup(clnt, net); pipefs_sb = rpc_get_sb_net(net); if (pipefs_sb) { @@ -329,7 +329,7 @@ static int rpc_client_register(struct rpc_clnt *clnt, out: if (pipefs_sb) rpc_put_sb_net(net); - rpc_netns_sysfs_destroy(clnt); + rpc_netns_client_sysfs_destroy(clnt); rpc_clnt_debugfs_unregister(clnt); return err; } @@ -736,7 +736,7 @@ int rpc_switch_client_transport(struct rpc_clnt *clnt, rpc_unregister_client(clnt); __rpc_clnt_remove_pipedir(clnt); - rpc_netns_sysfs_destroy(clnt); + rpc_netns_client_sysfs_destroy(clnt); rpc_clnt_debugfs_unregister(clnt); /* @@ -883,7 +883,7 @@ static void rpc_free_client_work(struct work_struct *work) * so they cannot be called in rpciod, so they are handled separately * here. */ - rpc_netns_sysfs_destroy(clnt); + rpc_netns_client_sysfs_destroy(clnt); rpc_clnt_debugfs_unregister(clnt); rpc_free_clid(clnt); rpc_clnt_remove_pipedir(clnt); diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c index 8b01b4df64ee..3fe814795ed9 100644 --- a/net/sunrpc/sysfs.c +++ b/net/sunrpc/sysfs.c @@ -9,7 +9,7 @@ #include "sysfs.h" struct kobject *rpc_client_kobj; -static struct kset *rpc_client_kset; +static struct kset *rpc_sunrpc_kset; static void rpc_netns_object_release(struct kobject *kobj) { @@ -45,13 +45,13 @@ static struct kobject *rpc_netns_object_alloc(const char *name, int rpc_sysfs_init(void) { - rpc_client_kset = kset_create_and_add("sunrpc", NULL, kernel_kobj); - if (!rpc_client_kset) + rpc_sunrpc_kset = kset_create_and_add("sunrpc", NULL, kernel_kobj); + if (!rpc_sunrpc_kset) return -ENOMEM; - rpc_client_kobj = rpc_netns_object_alloc("net", rpc_client_kset, NULL); + rpc_client_kobj = rpc_netns_object_alloc("client", rpc_sunrpc_kset, NULL); if (!rpc_client_kobj) { - kset_unregister(rpc_client_kset); - rpc_client_kset = NULL; + kset_unregister(rpc_sunrpc_kset); + rpc_sunrpc_kset = NULL; return -ENOMEM; } return 0; @@ -119,18 +119,18 @@ static struct kobj_type rpc_netns_client_type = { void rpc_sysfs_exit(void) { kobject_put(rpc_client_kobj); - kset_unregister(rpc_client_kset); + kset_unregister(rpc_sunrpc_kset); } static struct rpc_netns_client *rpc_netns_client_alloc(struct kobject *parent, - struct net *net, int clid) + struct net *net, int clid) { struct rpc_netns_client *p; p = kzalloc(sizeof(*p), GFP_KERNEL); if (p) { p->net = net; - p->kobject.kset = rpc_client_kset; + p->kobject.kset = rpc_sunrpc_kset; if (kobject_init_and_add(&p->kobject, &rpc_netns_client_type, parent, "%d", clid) == 0) return p; @@ -139,7 +139,7 @@ static struct rpc_netns_client *rpc_netns_client_alloc(struct kobject *parent, return NULL; } -void rpc_netns_sysfs_setup(struct rpc_clnt *clnt, struct net *net) +void rpc_netns_client_sysfs_setup(struct rpc_clnt *clnt, struct net *net) { struct rpc_netns_client *rpc_client; struct rpc_xprt *xprt = rcu_dereference(clnt->cl_xprt); @@ -155,7 +155,7 @@ void rpc_netns_sysfs_setup(struct rpc_clnt *clnt, struct net *net) } } -void rpc_netns_sysfs_destroy(struct rpc_clnt *clnt) +void rpc_netns_client_sysfs_destroy(struct rpc_clnt *clnt) { struct rpc_netns_client *rpc_client = clnt->cl_sysfs; diff --git a/net/sunrpc/sysfs.h b/net/sunrpc/sysfs.h index 137a12c87954..ab75c3cc91b6 100644 --- a/net/sunrpc/sysfs.h +++ b/net/sunrpc/sysfs.h @@ -16,7 +16,7 @@ extern struct kobject *rpc_client_kobj; extern int rpc_sysfs_init(void); extern void rpc_sysfs_exit(void); -void rpc_netns_sysfs_setup(struct rpc_clnt *clnt, struct net *net); -void rpc_netns_sysfs_destroy(struct rpc_clnt *clnt); +void rpc_netns_client_sysfs_setup(struct rpc_clnt *clnt, struct net *net); +void rpc_netns_client_sysfs_destroy(struct rpc_clnt *clnt); #endif From patchwork Mon Feb 15 17:39:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Aloni X-Patchwork-Id: 12089049 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0967C433E0 for ; Mon, 15 Feb 2021 17:41:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E6FF64DEC for ; Mon, 15 Feb 2021 17:41:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231238AbhBORlE (ORCPT ); Mon, 15 Feb 2021 12:41:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231866AbhBORkt (ORCPT ); Mon, 15 Feb 2021 12:40:49 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43EB7C0613D6 for ; Mon, 15 Feb 2021 09:40:09 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id f14so12507031ejc.8 for ; Mon, 15 Feb 2021 09:40:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernelim-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ci5HE9rOCY9XgU05vBcOkC3fmwgmO/4Car2EJUGflaE=; b=Whrcwx/m6M/XyTOBe6voO6Sy9UTS8XptMOl/peoZIsmYQvhQdUlwjrGhMNKp+bDuLV XeIRVc7KcneHWkk6huqQ2/FqbdWlN5vjOGT8WavN22cDFR7fv8sgc5dAKijMy5R3lG1k oj3aRGYd+rqFsqd6woouUiBkjNSVTI5Q0UxbIRkZ9W09raBjceicL0z/tYIK7zQAdJzN E+z3Syx/2+U/OPYhbZE91uZJoE7ewJ/ft8D/loEO/4Fk73Jg//yCpGIHqsCD3gxPYmLN QeSOrTnW5Blr0xElYaNHBzqfCckIick7W6k5DKb6VE572Mm200NIHb2yz9Stdfrr3tIo jPwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ci5HE9rOCY9XgU05vBcOkC3fmwgmO/4Car2EJUGflaE=; b=f18KvFZ1TwaeNo9dqKM9mGy96GYsWSJGQ4Ph+j+ngWkQiSqRlzsespFc+RGo1CXNm0 bJlUWXrr5YHhQ7IwxSHMRFEDjvIyY7gk5UUrldBYj92Z1W6Gz37V2PuFDY1Qall3UD/z bx0dHVSqjX+gxsF4fAE3O4tP7jEBq7+qG9XYTtlhBszmK+kTbgJF5LtlVvWjCHW/7NQr +M8QlOtWBK6DUOPP/jEt0kwjWExHL+sFplxiOrZ0DnZFqfOwMO31lSc98ShZ3mRONaLE gRrtjuSBXrtCBgoh+7zNkXhBCCqqspnxhkO2K+4BVinB0mftmSkhWNpHorBqXcrx8doQ n+ew== X-Gm-Message-State: AOAM531pALq2k46Coqe4Y0rvWG9YJphHy3CVk9dhAxoHe+1F8Sx8DtGl mdR6qXRh9fMwvKLvB1nigy/GfJkT+xs2Mg== X-Google-Smtp-Source: ABdhPJx0NYFtDUiKadA/62OtgmDaKzc3HvN44ENEvWmJvj4MGGwe0XPfMDoOF2TThoSMrwYlyO2UMg== X-Received: by 2002:a17:906:4a8a:: with SMTP id x10mr6807715eju.407.1613410807757; Mon, 15 Feb 2021 09:40:07 -0800 (PST) Received: from jupiter.home.aloni.org ([77.124.84.167]) by smtp.gmail.com with ESMTPSA id e11sm11257485ejz.94.2021.02.15.09.40.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 09:40:07 -0800 (PST) From: Dan Aloni To: linux-nfs@vger.kernel.org, Anna Schumaker Cc: Trond Myklebust Subject: [PATCH v1 2/8] sunrpc: add xprt id Date: Mon, 15 Feb 2021 19:39:56 +0200 Message-Id: <20210215174002.2376333-3-dan@kernelim.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210215174002.2376333-1-dan@kernelim.com> References: <20210215174002.2376333-1-dan@kernelim.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org This adds a unique identifier for a sunrpc transport in sysfs, which is similarly managed to the unique IDs of clients. Signed-off-by: Dan Aloni --- include/linux/sunrpc/xprt.h | 2 ++ net/sunrpc/sunrpc_syms.c | 1 + net/sunrpc/xprt.c | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/include/linux/sunrpc/xprt.h b/include/linux/sunrpc/xprt.h index d2e97ee802af..fbf57a87dc47 100644 --- a/include/linux/sunrpc/xprt.h +++ b/include/linux/sunrpc/xprt.h @@ -185,6 +185,7 @@ enum xprt_transports { struct rpc_xprt { struct kref kref; /* Reference count */ const struct rpc_xprt_ops *ops; /* transport methods */ + unsigned int id; /* transport id */ const struct rpc_timeout *timeout; /* timeout parms */ struct sockaddr_storage addr; /* server address */ @@ -367,6 +368,7 @@ struct rpc_xprt * xprt_alloc(struct net *net, size_t size, unsigned int num_prealloc, unsigned int max_req); void xprt_free(struct rpc_xprt *); +void xprt_cleanup_ids(void); static inline int xprt_enable_swap(struct rpc_xprt *xprt) diff --git a/net/sunrpc/sunrpc_syms.c b/net/sunrpc/sunrpc_syms.c index 3b57efc692ec..b61b74c00483 100644 --- a/net/sunrpc/sunrpc_syms.c +++ b/net/sunrpc/sunrpc_syms.c @@ -133,6 +133,7 @@ cleanup_sunrpc(void) { rpc_sysfs_exit(); rpc_cleanup_clids(); + xprt_cleanup_ids(); rpcauth_remove_module(); cleanup_socket_xprt(); svc_cleanup_xprt_sock(); diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c index 691ccf8049a4..e30acd1f0e31 100644 --- a/net/sunrpc/xprt.c +++ b/net/sunrpc/xprt.c @@ -1717,6 +1717,30 @@ static void xprt_free_all_slots(struct rpc_xprt *xprt) } } +static DEFINE_IDA(rpc_xprt_ids); + +void xprt_cleanup_ids(void) +{ + ida_destroy(&rpc_xprt_ids); +} + +static int xprt_alloc_id(struct rpc_xprt *xprt) +{ + int id; + + id = ida_simple_get(&rpc_xprt_ids, 0, 0, GFP_KERNEL); + if (id < 0) + return id; + + xprt->id = id; + return 0; +} + +static void xprt_free_id(struct rpc_xprt *xprt) +{ + ida_simple_remove(&rpc_xprt_ids, xprt->id); +} + struct rpc_xprt *xprt_alloc(struct net *net, size_t size, unsigned int num_prealloc, unsigned int max_alloc) @@ -1729,6 +1753,7 @@ struct rpc_xprt *xprt_alloc(struct net *net, size_t size, if (xprt == NULL) goto out; + xprt_alloc_id(xprt); xprt_init(xprt, net); for (i = 0; i < num_prealloc; i++) { @@ -1757,6 +1782,7 @@ void xprt_free(struct rpc_xprt *xprt) { put_net(xprt->xprt_net); xprt_free_all_slots(xprt); + xprt_free_id(xprt); kfree_rcu(xprt, rcu); } EXPORT_SYMBOL_GPL(xprt_free); From patchwork Mon Feb 15 17:39:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Aloni X-Patchwork-Id: 12089051 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE757C433E9 for ; Mon, 15 Feb 2021 17:41:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE10B60C3D for ; Mon, 15 Feb 2021 17:41:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231490AbhBORlH (ORCPT ); Mon, 15 Feb 2021 12:41:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230243AbhBORkv (ORCPT ); Mon, 15 Feb 2021 12:40:51 -0500 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43836C061786 for ; Mon, 15 Feb 2021 09:40:11 -0800 (PST) Received: by mail-ed1-x52a.google.com with SMTP id v9so4721827edw.8 for ; Mon, 15 Feb 2021 09:40:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernelim-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4vOEnK2HsKBbY/sCYpmM2/D5Q9BpmbWCzs85+zBCCgE=; b=MJ9dtjaFn157TCktfgAYZ+5dgsyU5H8/VqNXdE2m0D9zXfNn4xe32xgRnuBT1yvJJJ /E7VbLo6E+C0MGlqtsBSSfwwx4dezgy3nvRRqwu2j2a9cVqXoKE8PDFuMh3r3IiEOdAt bGyZXlO6k5VWCeVs5EdNe6awWpNRwvi6os+JzYjb0MZHKDgvlIixMed8/wCKb7NOijqx sw6mkc2GOUZaJYTw8IZUV2j7EHF/+3K9PRcYf9DK6/FZlAYN2pfnyIhywuezpY6ey8iq Q9FE995nTqpL4aqkErQhrBKI779DU3UPRv6sKTdObZG9EO2mmoAO994qi/RbGVFRZYyb 4Llg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4vOEnK2HsKBbY/sCYpmM2/D5Q9BpmbWCzs85+zBCCgE=; b=JoJr5jHXzGsX78doOKv9Aea+FIhUZG95oxgjKNXoOYHgsODw08z17OYcOE8Vw4+91+ gE9mnPb9n6V3M48hhBgJXdAXRKo3YJbAAWTNAnN4cvEWhzw/lHYxipvE3JkEb/BnEgZQ no884tyTr0qaYcysj6EIxsmx5HlV87ZT9Rl7Cfb8LlYDikD+FVaTUVWkNQcsWthRJsIM 9nQ51RY+0rXnxjtLT1swWgDURI5t4iJaxvhNZ2YlQeMWBz7tsbTpukXVxFMcFESMKe0k avnFEB3BoHJzKugnlQb3aXPrMHqZQ4bWAdu33wxE4XmnsZ4YLXpvVjuK2sxsif5jPWDS 6cNA== X-Gm-Message-State: AOAM533b+oPvAeN3DfM2OvcBNeZsTAzx3gOuZVKsnrK3pPiqkjWRXGEi VsoHU0sAl9VyfZBQelu+YelyywkOMisF3g== X-Google-Smtp-Source: ABdhPJzubm601LVYfs/wpUSj76p1RNRzUtW9CZux+8+I5eQjCjib95SSpAusR6dgKF+GBvtOQ2l1dw== X-Received: by 2002:aa7:cd8d:: with SMTP id x13mr16545579edv.286.1613410808805; Mon, 15 Feb 2021 09:40:08 -0800 (PST) Received: from jupiter.home.aloni.org ([77.124.84.167]) by smtp.gmail.com with ESMTPSA id e11sm11257485ejz.94.2021.02.15.09.40.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 09:40:08 -0800 (PST) From: Dan Aloni To: linux-nfs@vger.kernel.org, Anna Schumaker Cc: Trond Myklebust Subject: [PATCH v1 3/8] sunrpc: add a directory per sunrpc xprt Date: Mon, 15 Feb 2021 19:39:57 +0200 Message-Id: <20210215174002.2376333-4-dan@kernelim.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210215174002.2376333-1-dan@kernelim.com> References: <20210215174002.2376333-1-dan@kernelim.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org This uses much of the code from the per-client directory, except that now we have direct access to the transport struct. The per-client direct is adjusted in a subsequent commit. Signed-off-by: Dan Aloni --- include/linux/sunrpc/xprt.h | 1 + net/sunrpc/sysfs.c | 131 ++++++++++++++++++++++++++++++++++-- net/sunrpc/sysfs.h | 9 +++ net/sunrpc/xprt.c | 3 + 4 files changed, 139 insertions(+), 5 deletions(-) diff --git a/include/linux/sunrpc/xprt.h b/include/linux/sunrpc/xprt.h index fbf57a87dc47..df0252de58f4 100644 --- a/include/linux/sunrpc/xprt.h +++ b/include/linux/sunrpc/xprt.h @@ -260,6 +260,7 @@ struct rpc_xprt { * items */ struct list_head bc_pa_list; /* List of preallocated * backchannel rpc_rqst's */ + void *sysfs; /* /sys/kernel/sunrpc/xprt/ */ #endif /* CONFIG_SUNRPC_BACKCHANNEL */ struct rb_root recv_queue; /* Receive queue */ diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c index 3fe814795ed9..687d4470b90d 100644 --- a/net/sunrpc/sysfs.c +++ b/net/sunrpc/sysfs.c @@ -9,6 +9,7 @@ #include "sysfs.h" struct kobject *rpc_client_kobj; +struct kobject *rpc_xprt_kobj; static struct kset *rpc_sunrpc_kset; static void rpc_netns_object_release(struct kobject *kobj) @@ -48,13 +49,24 @@ int rpc_sysfs_init(void) rpc_sunrpc_kset = kset_create_and_add("sunrpc", NULL, kernel_kobj); if (!rpc_sunrpc_kset) return -ENOMEM; + rpc_client_kobj = rpc_netns_object_alloc("client", rpc_sunrpc_kset, NULL); - if (!rpc_client_kobj) { - kset_unregister(rpc_sunrpc_kset); - rpc_sunrpc_kset = NULL; - return -ENOMEM; - } + if (!rpc_client_kobj) + goto err_kset; + + rpc_xprt_kobj = rpc_netns_object_alloc("transport", rpc_sunrpc_kset, NULL); + if (!rpc_xprt_kobj) + goto err_client; + return 0; + +err_client: + kobject_put(rpc_client_kobj); + rpc_client_kobj = NULL; +err_kset: + kset_unregister(rpc_sunrpc_kset); + rpc_sunrpc_kset = NULL; + return -ENOMEM; } static ssize_t rpc_netns_dstaddr_show(struct kobject *kobj, @@ -118,6 +130,7 @@ static struct kobj_type rpc_netns_client_type = { void rpc_sysfs_exit(void) { + kobject_put(rpc_xprt_kobj); kobject_put(rpc_client_kobj); kset_unregister(rpc_sunrpc_kset); } @@ -166,3 +179,111 @@ void rpc_netns_client_sysfs_destroy(struct rpc_clnt *clnt) clnt->cl_sysfs = NULL; } } + +static ssize_t rpc_netns_xprt_dstaddr_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct rpc_netns_xprt *c = container_of(kobj, + struct rpc_netns_xprt, kobject); + struct rpc_xprt *xprt = c->xprt; + + if (!(xprt->prot & (IPPROTO_TCP | XPRT_TRANSPORT_RDMA))) { + sprintf(buf, "N/A"); + return 0; + } + + return rpc_ntop((struct sockaddr *)&xprt->addr, buf, PAGE_SIZE); +} + +static ssize_t rpc_netns_xprt_dstaddr_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct rpc_netns_xprt *c = container_of(kobj, + struct rpc_netns_xprt, kobject); + struct rpc_xprt *xprt = c->xprt; + struct sockaddr *saddr = (struct sockaddr *)&xprt->addr; + int port; + + if (!(xprt->prot & (IPPROTO_TCP | XPRT_TRANSPORT_RDMA))) + return -EINVAL; + + port = rpc_get_port(saddr); + + xprt->addrlen = rpc_pton(xprt->xprt_net, buf, count - 1, saddr, sizeof(*saddr)); + rpc_set_port(saddr, port); + + kfree(xprt->address_strings[RPC_DISPLAY_ADDR]); + xprt->address_strings[RPC_DISPLAY_ADDR] = kstrndup(buf, count - 1, GFP_KERNEL); + + xprt->ops->connect(xprt, NULL); + return count; +} + +static void rpc_netns_xprt_release(struct kobject *kobj) +{ + struct rpc_netns_xprt *c; + + c = container_of(kobj, struct rpc_netns_xprt, kobject); + kfree(c); +} + +static const void *rpc_netns_xprt_namespace(struct kobject *kobj) +{ + return container_of(kobj, struct rpc_netns_xprt, kobject)->net; +} + +static struct kobj_attribute rpc_netns_xprt_dstaddr = __ATTR(dstaddr, + 0644, rpc_netns_xprt_dstaddr_show, rpc_netns_xprt_dstaddr_store); + +static struct attribute *rpc_netns_xprt_attrs[] = { + &rpc_netns_xprt_dstaddr.attr, + NULL, +}; + +static struct kobj_type rpc_netns_xprt_type = { + .release = rpc_netns_xprt_release, + .default_attrs = rpc_netns_xprt_attrs, + .sysfs_ops = &kobj_sysfs_ops, + .namespace = rpc_netns_xprt_namespace, +}; + +static struct rpc_netns_xprt *rpc_netns_xprt_alloc(struct kobject *parent, + struct net *net, int id) +{ + struct rpc_netns_xprt *p; + + p = kzalloc(sizeof(*p), GFP_KERNEL); + if (p) { + p->net = net; + p->kobject.kset = rpc_sunrpc_kset; + if (kobject_init_and_add(&p->kobject, &rpc_netns_xprt_type, + parent, "%d", id) == 0) + return p; + kobject_put(&p->kobject); + } + return NULL; +} + +void rpc_netns_xprt_sysfs_setup(struct rpc_xprt *xprt, struct net *net) +{ + struct rpc_netns_xprt *rpc_xprt; + + rpc_xprt = rpc_netns_xprt_alloc(rpc_xprt_kobj, net, xprt->id); + if (rpc_xprt) { + xprt->sysfs = rpc_xprt; + rpc_xprt->xprt = xprt; + kobject_uevent(&rpc_xprt->kobject, KOBJ_ADD); + } +} + +void rpc_netns_xprt_sysfs_destroy(struct rpc_xprt *xprt) +{ + struct rpc_netns_xprt *rpc_xprt = xprt->sysfs; + + if (rpc_xprt) { + kobject_uevent(&rpc_xprt->kobject, KOBJ_REMOVE); + kobject_del(&rpc_xprt->kobject); + kobject_put(&rpc_xprt->kobject); + xprt->sysfs = NULL; + } +} diff --git a/net/sunrpc/sysfs.h b/net/sunrpc/sysfs.h index ab75c3cc91b6..e08dd7f6a1ec 100644 --- a/net/sunrpc/sysfs.h +++ b/net/sunrpc/sysfs.h @@ -11,12 +11,21 @@ struct rpc_netns_client { struct rpc_clnt *clnt; }; +struct rpc_netns_xprt { + struct kobject kobject; + struct net *net; + struct rpc_xprt *xprt; +}; + extern struct kobject *rpc_client_kobj; +extern struct kobject *rpc_xprt_kobj; extern int rpc_sysfs_init(void); extern void rpc_sysfs_exit(void); void rpc_netns_client_sysfs_setup(struct rpc_clnt *clnt, struct net *net); void rpc_netns_client_sysfs_destroy(struct rpc_clnt *clnt); +void rpc_netns_xprt_sysfs_setup(struct rpc_xprt *xprt, struct net *net); +void rpc_netns_xprt_sysfs_destroy(struct rpc_xprt *xprt); #endif diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c index e30acd1f0e31..4098cb6b1453 100644 --- a/net/sunrpc/xprt.c +++ b/net/sunrpc/xprt.c @@ -55,6 +55,7 @@ #include #include "sunrpc.h" +#include "sysfs.h" /* * Local variables @@ -1768,6 +1769,7 @@ struct rpc_xprt *xprt_alloc(struct net *net, size_t size, xprt->max_reqs = num_prealloc; xprt->min_reqs = num_prealloc; xprt->num_reqs = num_prealloc; + rpc_netns_xprt_sysfs_setup(xprt, net); return xprt; @@ -1780,6 +1782,7 @@ EXPORT_SYMBOL_GPL(xprt_alloc); void xprt_free(struct rpc_xprt *xprt) { + rpc_netns_xprt_sysfs_destroy(xprt); put_net(xprt->xprt_net); xprt_free_all_slots(xprt); xprt_free_id(xprt); From patchwork Mon Feb 15 17:39:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Aloni X-Patchwork-Id: 12089053 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 345F1C433DB for ; Mon, 15 Feb 2021 17:41:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0DFB464DF0 for ; Mon, 15 Feb 2021 17:41:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232082AbhBORlS (ORCPT ); Mon, 15 Feb 2021 12:41:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231740AbhBORkw (ORCPT ); Mon, 15 Feb 2021 12:40:52 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 749A6C061788 for ; Mon, 15 Feb 2021 09:40:11 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id y26so12462432eju.13 for ; Mon, 15 Feb 2021 09:40:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernelim-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8+mPZIGjaM6z+1A3zSLRNc6/eBHpbPT5IAsVWg1K64U=; b=jfpHf66T/7XIYphGMhf1IufHW+u5zu6HAX8mwLHh0zz14Ep/oHH3vHIXBYNbQWVhdK zWCJVovoPpvQuTTRVeKm5gawmb26C0HX5Fa/zPejUnrHrZzTjGcRLDhR88WmD7QnRlPb Wnh58x5xsd8WG2ISL3fbC9PNKEms9htYv5czeyWHIPryFxbhUU+oL4Uaf4gCULSDHLZQ 5WmdGHZkmtLxQWYfDVOfw0ZVtm3unxbflABycvjQco7/w+NCQ6lajgsTnephX5lMRrf+ gDfBHwvuDiZY+s4lqQ4bye+A4tygUf3khlcWiVIWzxAASp7DzMtxDLUcGpvbykEs7rql C1UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8+mPZIGjaM6z+1A3zSLRNc6/eBHpbPT5IAsVWg1K64U=; b=oELnmZc42JXP5bQIVtMBlC+f3gL15slvcRMyK1mOpmJtRh8TRj6PrArKd1bNK0xPcq cuuf8HpB/2tpzOD6NubtXk5IHuJbjgKfZtiNlFVENX3gE0X/JoN3QAOvd7tKKc/BRiD1 HOrG5pY4gOUNzccVVD00IALDpZICdF43YOyePSXZvv7jI16YjNbFzglFP8b0i8uxteeb cn1uI/kzk6F2DmlSe6sAic4Ki7vR5Ye2duXQS55TC7J0JpvqEzALhWcGoZsIvu4qW0tT WT4iQqXcYyS4ge5PDyw+SZebNsQbtsuu2vQWHgnkDTAH2BzFYRi7nTLYoae6IS4TOu2L jXoQ== X-Gm-Message-State: AOAM531PXkSa78BzdNK7/SLe8uKQlZodUcgqJMaXmrnlS/iWUzh0fja6 Rdl9yWalqihI2RGNodceSoB6bcjxbdq/tg== X-Google-Smtp-Source: ABdhPJy7ZaSo9uY3aCbQA4eanVVzrtdqFnS23X0aQauleD3LiVhDdiU/AF+Q+XW74JL0cWf5ikubHA== X-Received: by 2002:a17:906:708e:: with SMTP id b14mr10042084ejk.325.1613410809913; Mon, 15 Feb 2021 09:40:09 -0800 (PST) Received: from jupiter.home.aloni.org ([77.124.84.167]) by smtp.gmail.com with ESMTPSA id e11sm11257485ejz.94.2021.02.15.09.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 09:40:09 -0800 (PST) From: Dan Aloni To: linux-nfs@vger.kernel.org, Anna Schumaker Cc: Trond Myklebust Subject: [PATCH v1 4/8] sunrpc: have client directory a symlink to the root transport Date: Mon, 15 Feb 2021 19:39:58 +0200 Message-Id: <20210215174002.2376333-5-dan@kernelim.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210215174002.2376333-1-dan@kernelim.com> References: <20210215174002.2376333-1-dan@kernelim.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Instead of duplicating `dstaddr` in client directory, we add a symlink to the relevant transport directory which now hosts a `dstaddr`. Signed-off-by: Dan Aloni --- net/sunrpc/sysfs.c | 44 ++++++-------------------------------------- 1 file changed, 6 insertions(+), 38 deletions(-) diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c index 687d4470b90d..ae608235d7e0 100644 --- a/net/sunrpc/sysfs.c +++ b/net/sunrpc/sysfs.c @@ -69,37 +69,6 @@ int rpc_sysfs_init(void) return -ENOMEM; } -static ssize_t rpc_netns_dstaddr_show(struct kobject *kobj, - struct kobj_attribute *attr, char *buf) -{ - struct rpc_netns_client *c = container_of(kobj, - struct rpc_netns_client, kobject); - struct rpc_clnt *clnt = c->clnt; - struct rpc_xprt *xprt = rcu_dereference(clnt->cl_xprt); - - return rpc_ntop((struct sockaddr *)&xprt->addr, buf, PAGE_SIZE); -} - -static ssize_t rpc_netns_dstaddr_store(struct kobject *kobj, - struct kobj_attribute *attr, const char *buf, size_t count) -{ - struct rpc_netns_client *c = container_of(kobj, - struct rpc_netns_client, kobject); - struct rpc_clnt *clnt = c->clnt; - struct rpc_xprt *xprt = rcu_dereference(clnt->cl_xprt); - struct sockaddr *saddr = (struct sockaddr *)&xprt->addr; - int port = rpc_get_port(saddr); - - xprt->addrlen = rpc_pton(xprt->xprt_net, buf, count - 1, saddr, sizeof(*saddr)); - rpc_set_port(saddr, port); - - kfree(xprt->address_strings[RPC_DISPLAY_ADDR]); - xprt->address_strings[RPC_DISPLAY_ADDR] = kstrndup(buf, count - 1, GFP_KERNEL); - - xprt->ops->connect(xprt, NULL); - return count; -} - static void rpc_netns_client_release(struct kobject *kobj) { struct rpc_netns_client *c; @@ -113,11 +82,7 @@ static const void *rpc_netns_client_namespace(struct kobject *kobj) return container_of(kobj, struct rpc_netns_client, kobject)->net; } -static struct kobj_attribute rpc_netns_client_dstaddr = __ATTR(dstaddr, - 0644, rpc_netns_dstaddr_show, rpc_netns_dstaddr_store); - static struct attribute *rpc_netns_client_attrs[] = { - &rpc_netns_client_dstaddr.attr, NULL, }; @@ -156,12 +121,14 @@ void rpc_netns_client_sysfs_setup(struct rpc_clnt *clnt, struct net *net) { struct rpc_netns_client *rpc_client; struct rpc_xprt *xprt = rcu_dereference(clnt->cl_xprt); - - if (!(xprt->prot & (IPPROTO_TCP | XPRT_TRANSPORT_RDMA))) - return; + struct rpc_netns_xprt *rpc_xprt; + int ret; rpc_client = rpc_netns_client_alloc(rpc_client_kobj, net, clnt->cl_clid); if (rpc_client) { + rpc_xprt = xprt->sysfs; + ret = sysfs_create_link_nowarn(&rpc_client->kobject, + &rpc_xprt->kobject, "transport"); clnt->cl_sysfs = rpc_client; rpc_client->clnt = clnt; kobject_uevent(&rpc_client->kobject, KOBJ_ADD); @@ -173,6 +140,7 @@ void rpc_netns_client_sysfs_destroy(struct rpc_clnt *clnt) struct rpc_netns_client *rpc_client = clnt->cl_sysfs; if (rpc_client) { + sysfs_remove_link(&rpc_client->kobject, "transport"); kobject_uevent(&rpc_client->kobject, KOBJ_REMOVE); kobject_del(&rpc_client->kobject); kobject_put(&rpc_client->kobject); From patchwork Mon Feb 15 17:39:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Aloni X-Patchwork-Id: 12089059 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2246C433DB for ; Mon, 15 Feb 2021 17:42:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F8BE64DEB for ; Mon, 15 Feb 2021 17:42:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231192AbhBORlr (ORCPT ); Mon, 15 Feb 2021 12:41:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230413AbhBORlb (ORCPT ); Mon, 15 Feb 2021 12:41:31 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FAA0C06178A for ; Mon, 15 Feb 2021 09:40:12 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id y26so12462535eju.13 for ; Mon, 15 Feb 2021 09:40:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernelim-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZTkj77Ym7544w3Cv1HEeqhGGGNI3jkJddVNjSgF5JSM=; b=aBhRRxYEGjKIVnW+nFZ2F9hmFqHwnugVFPEzBWtK1AmuexsqeIe9A+M6EPrlISuvoz XjOm8hCocShBgUcZqwAl6syKi9vIYRc0Ctu6/ZgraGGAP7rin8fimBdmJUGIM+NI15jj ovHFtHo/tXILWDfdW5OMc8xMf8/vcpaSPMoHdalEZKve0IJdWICotjWXgcT6NyQnoqLl ZDMQ0kjJEVvq39FCtNm1vP5uXQNbQJOVufIMlVqjjb4Zzi9yoZZqOmmZYuoliHaqDhtQ SxCCfNwMoHF01krCcHEwetBDaTu327TxoCi7tMlcFDqC9D9w256RfTYl+/jaWIbxrHEu uMUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZTkj77Ym7544w3Cv1HEeqhGGGNI3jkJddVNjSgF5JSM=; b=Tk18dftFzxGK7G+qY0h/er18zgw3/J8YVT19FyM09OhOVR8B/n896SLVJNEYkv5VjR zenrqkgS0IW3LrMqU1K8ts5KkvA3lE7UCWsSksA27x1G9e3TSwD44JFgs0Yxx2Y8trfe yrcVHRuMJBCDXxXAULIK6Uo0Xh7olf1vK6p3Sn2CJRdUi2CfK4OrSHpx0bMq5vduKBEZ MZAG0Y5J6nn6YEDdQ1GmFB8oIqogY6eCEcLAeyeCYYYTOL3zHwNXA7O07SS6S/T570Hy zTH5gfm2dhiVns8+sfUPmlBe4AxeWTzTVGauuugFYO9rF0otvPa98+DgtdRQMj5y2z3D TYbQ== X-Gm-Message-State: AOAM5336u8xU7kgb6MNu/eYD11NSZwtIYC+Wjj/rxk54zt22n4AoPvg+ VrzC97QE2C05r0xYLLzYOkSNDuLlxmqN6Q== X-Google-Smtp-Source: ABdhPJwDB4FmKOP6iI9YzsZTgSoPqQs9AlvQqocxmvtjcKoFD9C2teTbegtNDfOj3XbAMldL6dhmWw== X-Received: by 2002:a17:906:1d51:: with SMTP id o17mr16852474ejh.85.1613410810984; Mon, 15 Feb 2021 09:40:10 -0800 (PST) Received: from jupiter.home.aloni.org ([77.124.84.167]) by smtp.gmail.com with ESMTPSA id e11sm11257485ejz.94.2021.02.15.09.40.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 09:40:10 -0800 (PST) From: Dan Aloni To: linux-nfs@vger.kernel.org, Anna Schumaker Cc: Trond Myklebust Subject: [PATCH v1 5/8] sunrpc: add IDs to multipath Date: Mon, 15 Feb 2021 19:39:59 +0200 Message-Id: <20210215174002.2376333-6-dan@kernelim.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210215174002.2376333-1-dan@kernelim.com> References: <20210215174002.2376333-1-dan@kernelim.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org This is used to uniquely identify sunrpc multipath objects in /sys. Signed-off-by: Dan Aloni --- include/linux/sunrpc/xprtmultipath.h | 4 ++++ net/sunrpc/sunrpc_syms.c | 1 + net/sunrpc/xprtmultipath.c | 27 +++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/include/linux/sunrpc/xprtmultipath.h b/include/linux/sunrpc/xprtmultipath.h index c6cce3fbf29d..ef95a6f18ccf 100644 --- a/include/linux/sunrpc/xprtmultipath.h +++ b/include/linux/sunrpc/xprtmultipath.h @@ -14,6 +14,7 @@ struct rpc_xprt_switch { spinlock_t xps_lock; struct kref xps_kref; + unsigned int xps_id; unsigned int xps_nxprts; unsigned int xps_nactive; atomic_long_t xps_queuelen; @@ -71,4 +72,7 @@ extern struct rpc_xprt *xprt_iter_get_next(struct rpc_xprt_iter *xpi); extern bool rpc_xprt_switch_has_addr(struct rpc_xprt_switch *xps, const struct sockaddr *sap); + +extern void xprt_multipath_cleanup_ids(void); + #endif diff --git a/net/sunrpc/sunrpc_syms.c b/net/sunrpc/sunrpc_syms.c index b61b74c00483..691c0000e9ea 100644 --- a/net/sunrpc/sunrpc_syms.c +++ b/net/sunrpc/sunrpc_syms.c @@ -134,6 +134,7 @@ cleanup_sunrpc(void) rpc_sysfs_exit(); rpc_cleanup_clids(); xprt_cleanup_ids(); + xprt_multipath_cleanup_ids(); rpcauth_remove_module(); cleanup_socket_xprt(); svc_cleanup_xprt_sock(); diff --git a/net/sunrpc/xprtmultipath.c b/net/sunrpc/xprtmultipath.c index 78c075a68c04..52a9584b23af 100644 --- a/net/sunrpc/xprtmultipath.c +++ b/net/sunrpc/xprtmultipath.c @@ -86,6 +86,31 @@ void rpc_xprt_switch_remove_xprt(struct rpc_xprt_switch *xps, xprt_put(xprt); } +static DEFINE_IDA(rpc_xprtswitch_ids); + +void xprt_multipath_cleanup_ids(void) +{ + ida_destroy(&rpc_xprtswitch_ids); +} + +static int xprt_switch_alloc_id(struct rpc_xprt_switch *xps) +{ + int id; + + id = ida_simple_get(&rpc_xprtswitch_ids, 0, 0, GFP_KERNEL); + if (id < 0) + return id; + + xps->xps_id = id; + return 0; +} + +static void xprt_switch_free_id(struct rpc_xprt_switch *xps) +{ + ida_simple_remove(&rpc_xprtswitch_ids, xps->xps_id); +} + + /** * xprt_switch_alloc - Allocate a new struct rpc_xprt_switch * @xprt: pointer to struct rpc_xprt @@ -103,6 +128,7 @@ struct rpc_xprt_switch *xprt_switch_alloc(struct rpc_xprt *xprt, if (xps != NULL) { spin_lock_init(&xps->xps_lock); kref_init(&xps->xps_kref); + xprt_switch_alloc_id(xps); xps->xps_nxprts = xps->xps_nactive = 0; atomic_long_set(&xps->xps_queuelen, 0); xps->xps_net = NULL; @@ -136,6 +162,7 @@ static void xprt_switch_free(struct kref *kref) struct rpc_xprt_switch, xps_kref); xprt_switch_free_entries(xps); + xprt_switch_free_id(xps); kfree_rcu(xps, xps_rcu); } From patchwork Mon Feb 15 17:40:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Aloni X-Patchwork-Id: 12089061 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0A13C433E0 for ; Mon, 15 Feb 2021 17:42:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A328664DEC for ; Mon, 15 Feb 2021 17:42:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230413AbhBORlu (ORCPT ); Mon, 15 Feb 2021 12:41:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230497AbhBORlb (ORCPT ); Mon, 15 Feb 2021 12:41:31 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8282C06178B for ; Mon, 15 Feb 2021 09:40:13 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id ot7so9865139ejb.9 for ; Mon, 15 Feb 2021 09:40:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernelim-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KMJwaE085VRNtJZh9eXFNy6KZgDYnyktHgUAm71FMVY=; b=EC6SW1/X0H0hql3o1tfvknduBtdvtjFZxL01Jb0JMDV6+fGOBUhPkbAYPMN3XEzO4t K2CvAVNubb0YnLF0n5jv8x1D2WZxFjSGYgLWQgcIx0kDuT79J7tQDpabPjb05s2VGOu7 FhHgB/Z9ADQHNVrCFHVA4jUilg5FWBbOQCzLf+KLSbFUP479pJG1OenZWoQdi4j74Cle Kfk1DdX2mfaq9GPjbhT7haaNc9MbuwCLz3XJAZPS5fkMZtTcaWWkXIentQfXgZc4Nr5K eJhHulhVe41eE2RZQx/dr3dJYy4JC/MoGrqtAQou/5e12iAQzsgRZzYQR4jjeOl2jLD2 TVjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KMJwaE085VRNtJZh9eXFNy6KZgDYnyktHgUAm71FMVY=; b=S2reMJLFgyUGx63FxjCnFuJmXBCWg26c3hsgbDLZR991oLzdJgBvYjOvx6PK4ipM/k qh9wDx9h7Dwv3OvTlQp5sXQSGURKglI6n+Mzgu7bKSzhBGCzBhIG7byhqa1CCTByEgf3 HMwdJI4uoEWTlpSqw8zs+JlTknZrm9eP/tLUgCSbXSxYykZsClC+f8PBFR49PQoVfysL vVSnB+FtbqxlIm13LE3VO0SI3R2srOVk3p+NXvkHk0+fWAcmt6RftfJ+Ae7/81DFIE63 srthL/9gstUHG+UVD3C5U2sukpSsgqHFluF2JrXkqAiFPwbj+0HqN/nhTLgY0SljTCGp SsGw== X-Gm-Message-State: AOAM53169aHl4s6fHY9bRNyBkQ/dX+ZThVWYb/MB3mYENjxOFxB9AcNS 7UpP9IDpAvlETppydo+QKmGRygcaeZAB0g== X-Google-Smtp-Source: ABdhPJxoTMhJxnouCNEmc+SY/9IvyxyxBZSHOBaJkdTXvU6Jj0x2D4DKIf83/521zRv8dKjI8vP6yg== X-Received: by 2002:a17:906:bce5:: with SMTP id op5mr3599494ejb.83.1613410812066; Mon, 15 Feb 2021 09:40:12 -0800 (PST) Received: from jupiter.home.aloni.org ([77.124.84.167]) by smtp.gmail.com with ESMTPSA id e11sm11257485ejz.94.2021.02.15.09.40.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 09:40:11 -0800 (PST) From: Dan Aloni To: linux-nfs@vger.kernel.org, Anna Schumaker Cc: Trond Myklebust Subject: [PATCH v1 6/8] sunrpc: add multipath directory and symlink from client Date: Mon, 15 Feb 2021 19:40:00 +0200 Message-Id: <20210215174002.2376333-7-dan@kernelim.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210215174002.2376333-1-dan@kernelim.com> References: <20210215174002.2376333-1-dan@kernelim.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org This also adds a `list` attribute to multipath directory that provides the transport IDs of the transports contained in the multipath object. Signed-off-by: Dan Aloni --- include/linux/sunrpc/xprtmultipath.h | 2 + net/sunrpc/sysfs.c | 122 +++++++++++++++++++++++++++ net/sunrpc/sysfs.h | 8 ++ net/sunrpc/xprtmultipath.c | 10 +++ 4 files changed, 142 insertions(+) diff --git a/include/linux/sunrpc/xprtmultipath.h b/include/linux/sunrpc/xprtmultipath.h index ef95a6f18ccf..2d0832dc10f5 100644 --- a/include/linux/sunrpc/xprtmultipath.h +++ b/include/linux/sunrpc/xprtmultipath.h @@ -24,6 +24,8 @@ struct rpc_xprt_switch { const struct rpc_xprt_iter_ops *xps_iter_ops; + void *xps_sysfs; /* /sys/kernel/sunrpc/multipath/ */ + struct rcu_head xps_rcu; }; diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c index ae608235d7e0..3592f3b862b2 100644 --- a/net/sunrpc/sysfs.c +++ b/net/sunrpc/sysfs.c @@ -10,6 +10,7 @@ struct kobject *rpc_client_kobj; struct kobject *rpc_xprt_kobj; +struct kobject *rpc_xps_kobj; static struct kset *rpc_sunrpc_kset; static void rpc_netns_object_release(struct kobject *kobj) @@ -58,8 +59,15 @@ int rpc_sysfs_init(void) if (!rpc_xprt_kobj) goto err_client; + rpc_xps_kobj = rpc_netns_object_alloc("multipath", rpc_sunrpc_kset, NULL); + if (!rpc_xps_kobj) + goto err_xprt; + return 0; +err_xprt: + kobject_put(rpc_xprt_kobj); + rpc_xprt_kobj = NULL; err_client: kobject_put(rpc_client_kobj); rpc_client_kobj = NULL; @@ -95,6 +103,7 @@ static struct kobj_type rpc_netns_client_type = { void rpc_sysfs_exit(void) { + kobject_put(rpc_xps_kobj); kobject_put(rpc_xprt_kobj); kobject_put(rpc_client_kobj); kset_unregister(rpc_sunrpc_kset); @@ -122,17 +131,29 @@ void rpc_netns_client_sysfs_setup(struct rpc_clnt *clnt, struct net *net) struct rpc_netns_client *rpc_client; struct rpc_xprt *xprt = rcu_dereference(clnt->cl_xprt); struct rpc_netns_xprt *rpc_xprt; + struct rpc_netns_multipath *rpc_multipath; + struct rpc_xprt_switch *xps; int ret; + xps = xprt_switch_get(rcu_dereference(clnt->cl_xpi.xpi_xpswitch)); + rpc_client = rpc_netns_client_alloc(rpc_client_kobj, net, clnt->cl_clid); if (rpc_client) { rpc_xprt = xprt->sysfs; ret = sysfs_create_link_nowarn(&rpc_client->kobject, &rpc_xprt->kobject, "transport"); + if (xps) { + rpc_multipath = xps->xps_sysfs; + ret = sysfs_create_link_nowarn(&rpc_client->kobject, + &rpc_multipath->kobject, + "multipath"); + } clnt->cl_sysfs = rpc_client; rpc_client->clnt = clnt; kobject_uevent(&rpc_client->kobject, KOBJ_ADD); } + + xprt_switch_put(xps); } void rpc_netns_client_sysfs_destroy(struct rpc_clnt *clnt) @@ -141,6 +162,7 @@ void rpc_netns_client_sysfs_destroy(struct rpc_clnt *clnt) if (rpc_client) { sysfs_remove_link(&rpc_client->kobject, "transport"); + sysfs_remove_link(&rpc_client->kobject, "multipath"); kobject_uevent(&rpc_client->kobject, KOBJ_REMOVE); kobject_del(&rpc_client->kobject); kobject_put(&rpc_client->kobject); @@ -255,3 +277,103 @@ void rpc_netns_xprt_sysfs_destroy(struct rpc_xprt *xprt) xprt->sysfs = NULL; } } + +static void rpc_netns_multipath_release(struct kobject *kobj) +{ + struct rpc_netns_multipath *c; + + c = container_of(kobj, struct rpc_netns_multipath, kobject); + kfree(c); +} + +static const void *rpc_netns_multipath_namespace(struct kobject *kobj) +{ + return container_of(kobj, struct rpc_netns_multipath, kobject)->net; +} + +static ssize_t rpc_netns_multipath_list_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct rpc_netns_multipath *c = + container_of(kobj, struct rpc_netns_multipath, kobject); + struct rpc_xprt_switch *xps = c->xps; + struct rpc_xprt_iter xpi; + int pos = 0; + + xprt_iter_init_listall(&xpi, xps); + for (;;) { + struct rpc_xprt *xprt = xprt_iter_get_next(&xpi); + if (!xprt) + break; + + snprintf(&buf[pos], PAGE_SIZE - pos, "%d\n", xprt->id); + pos += strlen(&buf[pos]); + xprt_put(xprt); + } + xprt_iter_destroy(&xpi); + + return pos; +} + +static ssize_t rpc_netns_multipath_list_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + return -EINVAL; +} + +static struct kobj_attribute rpc_netns_multipath_list = __ATTR(list, + 0644, rpc_netns_multipath_list_show, rpc_netns_multipath_list_store); + + +static struct attribute *rpc_netns_multipath_attrs[] = { + &rpc_netns_multipath_list.attr, + NULL, +}; + +static struct kobj_type rpc_netns_multipath_type = { + .release = rpc_netns_multipath_release, + .default_attrs = rpc_netns_multipath_attrs, + .sysfs_ops = &kobj_sysfs_ops, + .namespace = rpc_netns_multipath_namespace, +}; + +static struct rpc_netns_multipath *rpc_netns_multipath_alloc(struct kobject *parent, + struct net *net, int id) +{ + struct rpc_netns_multipath *p; + + p = kzalloc(sizeof(*p), GFP_KERNEL); + if (p) { + p->net = net; + p->kobject.kset = rpc_sunrpc_kset; + if (kobject_init_and_add(&p->kobject, &rpc_netns_multipath_type, + parent, "%d", id) == 0) + return p; + kobject_put(&p->kobject); + } + return NULL; +} + +void rpc_netns_multipath_sysfs_setup(struct rpc_xprt_switch *xps, struct net *net) +{ + struct rpc_netns_multipath *rpc_multipath; + + rpc_multipath = rpc_netns_multipath_alloc(rpc_xps_kobj, net, xps->xps_id); + if (rpc_multipath) { + xps->xps_sysfs = rpc_multipath; + rpc_multipath->xps = xps; + kobject_uevent(&rpc_multipath->kobject, KOBJ_ADD); + } +} + +void rpc_netns_multipath_sysfs_destroy(struct rpc_xprt_switch *xps) +{ + struct rpc_netns_multipath *rpc_multipath = xps->xps_sysfs; + + if (rpc_multipath) { + kobject_uevent(&rpc_multipath->kobject, KOBJ_REMOVE); + kobject_del(&rpc_multipath->kobject); + kobject_put(&rpc_multipath->kobject); + xps->xps_sysfs = NULL; + } +} diff --git a/net/sunrpc/sysfs.h b/net/sunrpc/sysfs.h index e08dd7f6a1ec..b2e379f78b91 100644 --- a/net/sunrpc/sysfs.h +++ b/net/sunrpc/sysfs.h @@ -17,6 +17,12 @@ struct rpc_netns_xprt { struct rpc_xprt *xprt; }; +struct rpc_netns_multipath { + struct kobject kobject; + struct net *net; + struct rpc_xprt_switch *xps; +}; + extern struct kobject *rpc_client_kobj; extern struct kobject *rpc_xprt_kobj; @@ -27,5 +33,7 @@ void rpc_netns_client_sysfs_setup(struct rpc_clnt *clnt, struct net *net); void rpc_netns_client_sysfs_destroy(struct rpc_clnt *clnt); void rpc_netns_xprt_sysfs_setup(struct rpc_xprt *xprt, struct net *net); void rpc_netns_xprt_sysfs_destroy(struct rpc_xprt *xprt); +void rpc_netns_multipath_sysfs_setup(struct rpc_xprt_switch *xps, struct net *net); +void rpc_netns_multipath_sysfs_destroy(struct rpc_xprt_switch *xps); #endif diff --git a/net/sunrpc/xprtmultipath.c b/net/sunrpc/xprtmultipath.c index 52a9584b23af..d03fb3bb74ce 100644 --- a/net/sunrpc/xprtmultipath.c +++ b/net/sunrpc/xprtmultipath.c @@ -19,6 +19,8 @@ #include #include +#include "sysfs.h" + typedef struct rpc_xprt *(*xprt_switch_find_xprt_t)(struct rpc_xprt_switch *xps, const struct rpc_xprt *cur); @@ -83,6 +85,9 @@ void rpc_xprt_switch_remove_xprt(struct rpc_xprt_switch *xps, spin_lock(&xps->xps_lock); xprt_switch_remove_xprt_locked(xps, xprt); spin_unlock(&xps->xps_lock); + + if (!xps->xps_net) + rpc_netns_multipath_sysfs_destroy(xps); xprt_put(xprt); } @@ -135,6 +140,10 @@ struct rpc_xprt_switch *xprt_switch_alloc(struct rpc_xprt *xprt, INIT_LIST_HEAD(&xps->xps_xprt_list); xps->xps_iter_ops = &rpc_xprt_iter_singular; xprt_switch_add_xprt_locked(xps, xprt); + xps->xps_sysfs = NULL; + + if (xprt->xprt_net != NULL) + rpc_netns_multipath_sysfs_setup(xps, xprt->xprt_net); } return xps; @@ -162,6 +171,7 @@ static void xprt_switch_free(struct kref *kref) struct rpc_xprt_switch, xps_kref); xprt_switch_free_entries(xps); + rpc_netns_multipath_sysfs_destroy(xps); xprt_switch_free_id(xps); kfree_rcu(xps, xps_rcu); } From patchwork Mon Feb 15 17:40:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Aloni X-Patchwork-Id: 12089057 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16A16C433DB for ; Mon, 15 Feb 2021 17:41:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE4E064DEC for ; Mon, 15 Feb 2021 17:41:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231194AbhBORlp (ORCPT ); Mon, 15 Feb 2021 12:41:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231192AbhBORld (ORCPT ); Mon, 15 Feb 2021 12:41:33 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD1BEC06178C for ; Mon, 15 Feb 2021 09:40:14 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id z22so9061046edb.9 for ; Mon, 15 Feb 2021 09:40:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernelim-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HxL4xgluh2lEgYgmCoXEb71nIHVpJpsiBxGVUgUXHxk=; b=ydpIb8BdWIvZQJDen7oaUJC36KrToEq/CzAiqC+wy0M5WKzYu7SDurbOI6LC7mpvep w7x1dsw9wCN+Nr0BXrsZNux1+kC/VNeNQROa7e5wN8BzlM+FLo+ymVnf1DdwLQuo9xrJ wxjmRjCCmo3mtAPeBoB55qdd99iicafhp+Ysaxk8Q+YvEqpaszkuKGK8x2XPf1J/MiUJ 0C3PLou6WZWf3aGCHJyIOARGoF1ca9zqVlkMrqmnxhX3CasvSGhRIMsXuisYcD8eBnqK TW3EjPsWTUEsBfrwncuS+8sWgCXjtJ7GxVlZHaCeYT9nY5o3P7HF/Dx4Xf0I95Xjz5lC uu3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HxL4xgluh2lEgYgmCoXEb71nIHVpJpsiBxGVUgUXHxk=; b=EslLba2WFjeKaWKrsvgdP+jEn6x79qpNGuCHRnp2l7LCVh7M1j5HLNW7yFDRhOtCpw yRVaYP9dH6NZ0+FP+cRuUDC+tKg0X8oFVCdlanu+Cuz6HheVc/LPFQ8L1OKumSCGwYx7 GPZ5RvowcMZTBYCSAzfsvQTnzSho+iq+V0k4IJuGUXIX7KSTDzkdu9I2LH67m0XxwAG/ 35gRQHu/LcgnmAjy5mklBoSOTxlau2LWcfHX87F+h6N4gXM1WuyWQ4GBi7PpWt8DMI4C toYYk/wALT6QwGYHOKiQSGHdnh4I1HemUoansAEC5qMMIQrshXy70D+42S53ZYkucE+1 qtxw== X-Gm-Message-State: AOAM533x33Z7DKOtQhy9vIl1vQQz9cE5XjDjRZY9H5TSvdeiTbUfk6KY p81Ws3iwhjUktZn3IW81ZI6lH9OlDW9MBw== X-Google-Smtp-Source: ABdhPJzIYmhG4MTsWYZ680kXyYpv/yNY2SURiPGw9kW3zTYJwSKRkrfGOkmsBn88Bc+Y5v8b5oMmeg== X-Received: by 2002:aa7:d849:: with SMTP id f9mr3619350eds.76.1613410813165; Mon, 15 Feb 2021 09:40:13 -0800 (PST) Received: from jupiter.home.aloni.org ([77.124.84.167]) by smtp.gmail.com with ESMTPSA id e11sm11257485ejz.94.2021.02.15.09.40.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 09:40:12 -0800 (PST) From: Dan Aloni To: linux-nfs@vger.kernel.org, Anna Schumaker Cc: Trond Myklebust Subject: [PATCH v1 7/8] sunrpc: change rpc_clnt_add_xprt() to rpc_add_xprt() Date: Mon, 15 Feb 2021 19:40:01 +0200 Message-Id: <20210215174002.2376333-8-dan@kernelim.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210215174002.2376333-1-dan@kernelim.com> References: <20210215174002.2376333-1-dan@kernelim.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org This change of API allows adding transports without holding a reference to an rpc client. Signed-off-by: Dan Aloni --- fs/nfs/pnfs_nfs.c | 12 +++++++----- include/linux/sunrpc/clnt.h | 12 +++++++----- net/sunrpc/clnt.c | 31 +++++++++++++++++-------------- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/fs/nfs/pnfs_nfs.c b/fs/nfs/pnfs_nfs.c index 49d3389bd813..1e61626bd0fa 100644 --- a/fs/nfs/pnfs_nfs.c +++ b/fs/nfs/pnfs_nfs.c @@ -878,8 +878,9 @@ static int _nfs4_pnfs_v3_ds_connect(struct nfs_server *mds_srv, if (da->da_addr.ss_family != clp->cl_addr.ss_family) continue; /* Add this address as an alias */ - rpc_clnt_add_xprt(clp->cl_rpcclient, &xprt_args, - rpc_clnt_test_and_add_xprt, NULL); + rpc_add_xprt(&clp->cl_rpcclient->cl_xpi, + clp->cl_rpcclient, &xprt_args, + rpc_clnt_test_and_add_xprt, NULL); continue; } clp = get_v3_ds_connect(mds_srv, @@ -945,9 +946,10 @@ static int _nfs4_pnfs_v4_ds_connect(struct nfs_server *mds_srv, * add as an alias */ xprtdata.cred = nfs4_get_clid_cred(clp), - rpc_clnt_add_xprt(clp->cl_rpcclient, &xprt_args, - rpc_clnt_setup_test_and_add_xprt, - &rpcdata); + rpc_add_xprt(&clp->cl_rpcclient->cl_xpi, + clp->cl_rpcclient, &xprt_args, + rpc_clnt_setup_test_and_add_xprt, + &rpcdata); if (xprtdata.cred) put_cred(xprtdata.cred); } else { diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h index 503653720e18..19bb23143eef 100644 --- a/include/linux/sunrpc/clnt.h +++ b/include/linux/sunrpc/clnt.h @@ -210,21 +210,23 @@ int rpc_clnt_iterate_for_each_xprt(struct rpc_clnt *clnt, int (*fn)(struct rpc_clnt *, struct rpc_xprt *, void *), void *data); -int rpc_clnt_test_and_add_xprt(struct rpc_clnt *clnt, +int rpc_clnt_test_and_add_xprt(void *clnt, struct rpc_xprt_switch *xps, struct rpc_xprt *xprt, void *dummy); -int rpc_clnt_add_xprt(struct rpc_clnt *, struct xprt_create *, - int (*setup)(struct rpc_clnt *, +int rpc_add_xprt(struct rpc_xprt_iter *iter, + void *ctx, + struct xprt_create *xprtargs, + int (*setup)(void *ctx, struct rpc_xprt_switch *, struct rpc_xprt *, void *), - void *data); + void *data); void rpc_set_connect_timeout(struct rpc_clnt *clnt, unsigned long connect_timeout, unsigned long reconnect_timeout); -int rpc_clnt_setup_test_and_add_xprt(struct rpc_clnt *, +int rpc_clnt_setup_test_and_add_xprt(void *, struct rpc_xprt_switch *, struct rpc_xprt *, void *); diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c index 0a4811be01cd..b94d274a5446 100644 --- a/net/sunrpc/clnt.c +++ b/net/sunrpc/clnt.c @@ -598,7 +598,7 @@ struct rpc_clnt *rpc_create(struct rpc_create_args *args) return clnt; for (i = 0; i < args->nconnect - 1; i++) { - if (rpc_clnt_add_xprt(clnt, &xprtargs, NULL, NULL) < 0) + if (rpc_add_xprt(&clnt->cl_xpi, NULL, &xprtargs, NULL, NULL) < 0) break; } return clnt; @@ -2751,10 +2751,11 @@ static const struct rpc_call_ops rpc_cb_add_xprt_call_ops = { * @xprt: pointer struct rpc_xprt * @dummy: unused */ -int rpc_clnt_test_and_add_xprt(struct rpc_clnt *clnt, +int rpc_clnt_test_and_add_xprt(void *ptr, struct rpc_xprt_switch *xps, struct rpc_xprt *xprt, void *dummy) { + struct rpc_clnt *clnt = ptr; struct rpc_cb_add_xprt_calldata *data; struct rpc_task *task; @@ -2795,11 +2796,12 @@ EXPORT_SYMBOL_GPL(rpc_clnt_test_and_add_xprt); * @data: a struct rpc_add_xprt_test pointer that holds the test function * and test function call data */ -int rpc_clnt_setup_test_and_add_xprt(struct rpc_clnt *clnt, +int rpc_clnt_setup_test_and_add_xprt(void *ptr, struct rpc_xprt_switch *xps, struct rpc_xprt *xprt, void *data) { + struct rpc_clnt *clnt = ptr; struct rpc_task *task; struct rpc_add_xprt_test *xtest = (struct rpc_add_xprt_test *)data; int status = -EADDRINUSE; @@ -2852,13 +2854,14 @@ EXPORT_SYMBOL_GPL(rpc_clnt_setup_test_and_add_xprt); * adding the new transport. * */ -int rpc_clnt_add_xprt(struct rpc_clnt *clnt, - struct xprt_create *xprtargs, - int (*setup)(struct rpc_clnt *, - struct rpc_xprt_switch *, - struct rpc_xprt *, - void *), - void *data) +int rpc_add_xprt(struct rpc_xprt_iter *iter, + void *ctx, + struct xprt_create *xprtargs, + int (*setup)(void *ctx, + struct rpc_xprt_switch *, + struct rpc_xprt *, + void *), + void *data) { struct rpc_xprt_switch *xps; struct rpc_xprt *xprt; @@ -2868,8 +2871,8 @@ int rpc_clnt_add_xprt(struct rpc_clnt *clnt, int ret = 0; rcu_read_lock(); - xps = xprt_switch_get(rcu_dereference(clnt->cl_xpi.xpi_xpswitch)); - xprt = xprt_iter_xprt(&clnt->cl_xpi); + xps = xprt_switch_get(rcu_dereference(iter->xpi_xpswitch)); + xprt = xprt_iter_xprt(iter); if (xps == NULL || xprt == NULL) { rcu_read_unlock(); xprt_switch_put(xps); @@ -2895,7 +2898,7 @@ int rpc_clnt_add_xprt(struct rpc_clnt *clnt, rpc_xprt_switch_set_roundrobin(xps); if (setup) { - ret = setup(clnt, xps, xprt, data); + ret = setup(ctx, xps, xprt, data); if (ret != 0) goto out_put_xprt; } @@ -2906,7 +2909,7 @@ int rpc_clnt_add_xprt(struct rpc_clnt *clnt, xprt_switch_put(xps); return ret; } -EXPORT_SYMBOL_GPL(rpc_clnt_add_xprt); +EXPORT_SYMBOL_GPL(rpc_add_xprt); struct connect_timeout_data { unsigned long connect_timeout; From patchwork Mon Feb 15 17:40:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Aloni X-Patchwork-Id: 12089055 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12DD5C433E0 for ; Mon, 15 Feb 2021 17:41:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DEF6464DF0 for ; Mon, 15 Feb 2021 17:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231462AbhBORlm (ORCPT ); Mon, 15 Feb 2021 12:41:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231194AbhBORld (ORCPT ); Mon, 15 Feb 2021 12:41:33 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D83C3C061793 for ; Mon, 15 Feb 2021 09:40:15 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id jj19so12568394ejc.4 for ; Mon, 15 Feb 2021 09:40:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernelim-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j3CklkawBYlWE0T+slCXVcG84oQksA0ep6RTt5W4hSc=; b=dsUwtoDU2LG8JjqiVFBZaRuHBY2wpELQR2CvThGIFmuD8X2EPzN+fo2un6WEQJ4BoO PhE/DLBlhM4mw5XrbMOU4j+pnbyyALUqv+7vPOWYmSnaLo6UBdyqnkf6cukxzLGAWsPE JGr3fgu+nkojaIOPbrSwLNN1rVk69EU2fnstA1jTQ4tXygG352xVMXdZ21/5oEHtCjmp YqNWL7hJAVw7uWoUljhE/piwmJUiMKwUrej9aTcqWuJhqnLZLHBCXirdAVBvVOZcK2I8 W4JFVAeVbnm4OgGW+a8Kk+pDLwOrxCdhb1voIkStOErSBR3Mae+3eL/Tuix4dWN4gx2D 9Q+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j3CklkawBYlWE0T+slCXVcG84oQksA0ep6RTt5W4hSc=; b=tmlSrQhk79f9B304qs9E664OPsYldczoSm1h6ZpklY1gxf7/X7z9vPHpfdxVYPa9iu 90TlzWSIvZky02iT3L3ll/wxpV4Azy23bKoQxxe2xoW0Vz15O38Sbla9bM4ftmLCX5NK 4Jbynx/z9o4Rlz0P4LM25I7JOaZXyh9kWsnrJfwGwA8Xj51LmS2bysNEA2rxvrEIcruF RYZudNdqrH2Zm6blIdRjAMRVN7vPjOoc6X3hgUo/IhodiJA1RBlfcXVrsvUBV/tt1Hz5 mODMzDUb9je7/IjlMewF9Eqw0HHKQg7ZtwOOuO5kqV0UViD9UDSxXMdmoLu3XHUUFw4a clOg== X-Gm-Message-State: AOAM531WC6C5o2A1H4xuMZPuSjDxCDFpjQpa6ShuDeu+zgQpZnAMj3JS LBNcLyFBQJOBx8Y42rdolLL/X5OuGW2JEA== X-Google-Smtp-Source: ABdhPJy+mHe/TaiwSAuhC3Y/duDVXZ6AZJ6ljXU6J40F/0dyZbb8ykRqcwLIv3EnH34pjf010ojBmw== X-Received: by 2002:a17:906:3f96:: with SMTP id b22mr16416022ejj.478.1613410814217; Mon, 15 Feb 2021 09:40:14 -0800 (PST) Received: from jupiter.home.aloni.org ([77.124.84.167]) by smtp.gmail.com with ESMTPSA id e11sm11257485ejz.94.2021.02.15.09.40.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 09:40:13 -0800 (PST) From: Dan Aloni To: linux-nfs@vger.kernel.org, Anna Schumaker Cc: Trond Myklebust Subject: [PATCH v1 8/8] sunrpc: introduce an 'add' node to 'multipath' sysfs directory Date: Mon, 15 Feb 2021 19:40:02 +0200 Message-Id: <20210215174002.2376333-9-dan@kernelim.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210215174002.2376333-1-dan@kernelim.com> References: <20210215174002.2376333-1-dan@kernelim.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org This allows adding new transports to an existing multipath switch. This is similar to what the `nconnect` mount parameter does, but instead we can do this while the NFS mount is live. For example: echo 'dstaddr 192.168.40.8 kind rdma' \ > /sys/kernel/sunrpc/client/0/multipath/add Signed-off-by: Dan Aloni --- net/sunrpc/sysfs.c | 104 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 3 deletions(-) diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c index 3592f3b862b2..d745dfb7cef4 100644 --- a/net/sunrpc/sysfs.c +++ b/net/sunrpc/sysfs.c @@ -315,18 +315,116 @@ static ssize_t rpc_netns_multipath_list_show(struct kobject *kobj, return pos; } -static ssize_t rpc_netns_multipath_list_store(struct kobject *kobj, +static ssize_t rpc_netns_multipath_add_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { - return -EINVAL; + struct rpc_netns_multipath *c = + container_of(kobj, struct rpc_netns_multipath, kobject); + struct rpc_xprt_switch *xps = c->xps; + struct rpc_xprt_iter xpi; + struct sockaddr_storage addr; + struct xprt_create xprt_args = { + .ident = XPRT_TRANSPORT_RDMA, + .net = c->net, + .dstaddr = (struct sockaddr *)&addr, + }; + struct rpc_xprt *existing_xprt; + char *opt, *str, *arg; + bool has_dstaddr = false; + bool has_kind = false; + int err; + + opt = kstrndup(buf, count, GFP_KERNEL); + if (!opt) + return -ENOMEM; + + str = strstrip(opt); + + while (1) { + arg = strsep(&str, " "); + if (!arg) + break; + + if (sysfs_streq(arg, "kind")) { + arg = strsep(&str, " "); + if (!arg) { + err = -EINVAL; + goto out; + } + if (has_kind) { + err = -EINVAL; + goto out; + } + + if (sysfs_streq(arg, "rdma")) { + xprt_args.ident = XPRT_TRANSPORT_RDMA; + } else if (sysfs_streq(arg, "tcp")) { + xprt_args.ident = XPRT_TRANSPORT_TCP; + } else { + err = -EINVAL; + goto out; + } + + has_kind = true; + } else if (sysfs_streq(arg, "dstaddr")) { + arg = strsep(&str, " "); + if (!arg) { + err = -EINVAL; + goto out; + } + xprt_args.addrlen = rpc_pton(c->net, + arg, strlen(arg), (struct sockaddr *)&addr, + sizeof(addr)); + if (has_dstaddr || !xprt_args.addrlen) { + err = -EINVAL; + goto out; + } + + has_dstaddr = true; + } else { + break; + } + } + + if (!has_dstaddr || !has_kind) { + err = -EINVAL; + goto out; + } + + + /* Discover an existing xprt */ + xprt_iter_init_listall(&xpi, xps); + existing_xprt = xprt_iter_get_next(&xpi); + xprt_iter_destroy(&xpi); + + if (!existing_xprt) { + err = -ENOENT; + goto out; + } + + xprt_args.servername = existing_xprt->servername; + xprt_iter_init_listall(&xpi, xps); + rpc_add_xprt(&xpi, NULL, &xprt_args, NULL, NULL); + xprt_iter_destroy(&xpi); + + xprt_put(existing_xprt); + + err = count; +out: + kfree(opt); + + return err; } static struct kobj_attribute rpc_netns_multipath_list = __ATTR(list, - 0644, rpc_netns_multipath_list_show, rpc_netns_multipath_list_store); + 0444, rpc_netns_multipath_list_show, NULL); +static struct kobj_attribute rpc_netns_multipath_add = __ATTR(add, + 0200, NULL, rpc_netns_multipath_add_store); static struct attribute *rpc_netns_multipath_attrs[] = { &rpc_netns_multipath_list.attr, + &rpc_netns_multipath_add.attr, NULL, };