Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3814221pxy; Mon, 26 Apr 2021 10:21:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmHZkazj2QUhP/R6vo5j08ma7FRKLQkfd9CfTfV0vWvsjiQ+oEel4UPa8XQ5noleTfl77r X-Received: by 2002:aa7:c893:: with SMTP id p19mr22631167eds.256.1619457662312; Mon, 26 Apr 2021 10:21:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619457662; cv=none; d=google.com; s=arc-20160816; b=x+1KAVvhUwR7aRKnGgZwIVpDObhwCUIeX5i1a0Luzy1ATK9lSHDWxFh3V6TNAA8BJO Nj/5L725oDUWaY2wuccMij4xR0KohekPYgVHyGgQHHw3sNkTA2BYXPYgguu+VcBbZ7D7 pZjczpTRE+3Ifso3JWQ08lrre8jaicWl+hIRffRnyB2iLbHPUSGscQwYZ8kARkTIroO8 dYlC25XIp02reLCe/9VHv0PuGyzKD6osD4hSV/hVigZvJ3HoeoErcM7vJM5ULJNKGovN zItGRgD16/hSEhstNqEVGcFwsIHKW9LegmEMg1arIhXmKQzkm0UbrNsIF3T+d6nRobmh xO8g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JnukR7EdQqY8PvozClts/MwX3SH4ugLOmxenrgo63Kc=; b=K3tAvj+78427pEQU8cqqhCD9gYtytVd47cIE/IiLsWV6EkWiLZzqkWsc0EnALRQ3gP YXpjulogMt/dxgJpdvkTDeOHqyrTdghgDQgNs8dNnd57a7cKNDxJJhumygNtbMDmJbcn z9IvKx5KNXGuC4j3HJFBJkAUO58AUgtUzKrdDdrZPxZP1M3bijFQ0zaOocGP7AR9Nmhr rTUPdaZDjBdWc2ErvGqEFXLFyzba9XKkU6eBthXc9husdZ0mbBQ7GFQoo7xXiJIrBfmu 7oty6CLXBEwOm0lmOMU9ADpMSuStBdqKAWsdGnh0BQ7irT41S85WF3MK8ZpSY3ZY7inU 2rMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AJwVfu2b; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id eb13si346873edb.223.2021.04.26.10.20.39; Mon, 26 Apr 2021 10:21:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AJwVfu2b; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 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 S236774AbhDZRUz (ORCPT + 99 others); Mon, 26 Apr 2021 13:20:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236184AbhDZRUm (ORCPT ); Mon, 26 Apr 2021 13:20:42 -0400 Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E270C061756 for ; Mon, 26 Apr 2021 10:19:59 -0700 (PDT) Received: by mail-il1-x12e.google.com with SMTP id j12so2372116ils.4 for ; Mon, 26 Apr 2021 10:19:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JnukR7EdQqY8PvozClts/MwX3SH4ugLOmxenrgo63Kc=; b=AJwVfu2bfFaj3x58+kUuHw6o6CifkuLqwqlOehxSMTtD26pq80hfBggYgIadhTTXnk VHLDZk9jEZQliSNWepIETV4Yd6FN4XFWW0481vqusb8kTVKKe75hANlJBjkr6Xmiyscw QAyfyYvSY0jKy+rf4ehCkDWE/lpFN44WsZvqa53FsuoEINX24jnK7rFgHm3fmBOHhcSx xIbv0C0pUtO9g7olQ4/KGu2GxqDL3xLI2eULISbAy4f1xOFbPkidBmKhnoKJMRoKxk2E OeRkCJ6bEqG7nGRtlAm4DeuHQ0N70EM2ATQu2sD7jUBj+OxADrTmdeTzyJk8RPpRxiWl nfcg== 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=JnukR7EdQqY8PvozClts/MwX3SH4ugLOmxenrgo63Kc=; b=gou76UxoAulIkpcFSt7OqEwAdMbkTUscmg3w1oTrqYOs0eOZ+Rf0ygm7Cm1/kVBvYC K4N1boNAxIcH/vyFjYOy00o4jl9bskB9CckgI0fUwEzjGrUaarIe88jeoyAQLccFgPQI VXOp5f4sJeCcNyFRIJirTB4sZ43W2J5xW/P9k1fWXoeJTdEv3TcdlsrlVdhxzrFM85pB Jn5+yQucxvERO3eCaLEq/1Up2vmILeRQK/bOAZrc9J6pD7j2Mi86jT32eKO2aUmonzbS KuALlWLTk6aetYnqh4ZZ9rVamPY/DzMiJzUVNrh+8wJamwQMuHoMPr6U/HYlzyqtQRrx Dj2g== X-Gm-Message-State: AOAM533ilUAO4JeZKvvVcPBy7MxaBhlHnlodW/1epav8Dj7NsBEbGm0f 9GplinmzmDQFOMQ1AqNIUbw= X-Received: by 2002:a05:6e02:1c42:: with SMTP id d2mr13791022ilg.287.1619457599048; Mon, 26 Apr 2021 10:19:59 -0700 (PDT) Received: from kolga-mac-1.attlocal.net (172-10-226-31.lightspeed.livnmi.sbcglobal.net. [172.10.226.31]) by smtp.gmail.com with ESMTPSA id x13sm207297ilq.85.2021.04.26.10.19.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Apr 2021 10:19:58 -0700 (PDT) From: Olga Kornievskaia To: trond.myklebust@hammerspace.com, anna.schumaker@netapp.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v3 08/13] sunrpc: add xprt_switch direcotry to sunrpc's sysfs Date: Mon, 26 Apr 2021 13:19:42 -0400 Message-Id: <20210426171947.99233-9-olga.kornievskaia@gmail.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20210426171947.99233-1-olga.kornievskaia@gmail.com> References: <20210426171947.99233-1-olga.kornievskaia@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Olga Kornievskaia Add xprt_switch directory to the sysfs and create individual xprt_swith subdirectories for multipath transport group. Signed-off-by: Olga Kornievskaia --- include/linux/sunrpc/xprtmultipath.h | 1 + net/sunrpc/sysfs.c | 99 ++++++++++++++++++++++++++-- net/sunrpc/sysfs.h | 10 +++ net/sunrpc/xprtmultipath.c | 4 ++ 4 files changed, 107 insertions(+), 7 deletions(-) diff --git a/include/linux/sunrpc/xprtmultipath.h b/include/linux/sunrpc/xprtmultipath.h index ef95a6f18ccf..47b0a85cdcfa 100644 --- a/include/linux/sunrpc/xprtmultipath.h +++ b/include/linux/sunrpc/xprtmultipath.h @@ -24,6 +24,7 @@ struct rpc_xprt_switch { const struct rpc_xprt_iter_ops *xps_iter_ops; + void *xps_sysfs; struct rcu_head xps_rcu; }; diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c index d14d54f33c65..03ea6d3ace95 100644 --- a/net/sunrpc/sysfs.c +++ b/net/sunrpc/sysfs.c @@ -7,7 +7,7 @@ #include "sysfs.h" static struct kset *rpc_sunrpc_kset; -static struct kobject *rpc_sunrpc_client_kobj; +static struct kobject *rpc_sunrpc_client_kobj, *rpc_sunrpc_xprt_switch_kobj; static void rpc_sysfs_object_release(struct kobject *kobj) { @@ -47,13 +47,22 @@ int rpc_sysfs_init(void) rpc_sunrpc_kset = kset_create_and_add("sunrpc", NULL, kernel_kobj); if (!rpc_sunrpc_kset) return -ENOMEM; - rpc_sunrpc_client_kobj = rpc_sysfs_object_alloc("client", rpc_sunrpc_kset, NULL); - if (!rpc_sunrpc_client_kobj) { - kset_unregister(rpc_sunrpc_kset); - rpc_sunrpc_client_kobj = NULL; - return -ENOMEM; - } + rpc_sunrpc_client_kobj = + rpc_sysfs_object_alloc("rpc-clients", rpc_sunrpc_kset, NULL); + if (!rpc_sunrpc_client_kobj) + goto err_client; + rpc_sunrpc_xprt_switch_kobj = + rpc_sysfs_object_alloc("xprt-switches", rpc_sunrpc_kset, NULL); + if (!rpc_sunrpc_xprt_switch_kobj) + goto err_switch; return 0; +err_switch: + kobject_put(rpc_sunrpc_client_kobj); + rpc_sunrpc_client_kobj = NULL; +err_client: + kset_unregister(rpc_sunrpc_kset); + rpc_sunrpc_kset = NULL; + return -ENOMEM; } static void rpc_sysfs_client_release(struct kobject *kobj) @@ -64,20 +73,40 @@ static void rpc_sysfs_client_release(struct kobject *kobj) kfree(c); } +static void rpc_sysfs_xprt_switch_release(struct kobject *kobj) +{ + struct rpc_sysfs_xprt_switch *xprt_switch; + + xprt_switch = container_of(kobj, struct rpc_sysfs_xprt_switch, kobject); + kfree(xprt_switch); +} + static const void *rpc_sysfs_client_namespace(struct kobject *kobj) { return container_of(kobj, struct rpc_sysfs_client, kobject)->net; } +static const void *rpc_sysfs_xprt_switch_namespace(struct kobject *kobj) +{ + return container_of(kobj, struct rpc_sysfs_xprt_switch, kobject)->net; +} + static struct kobj_type rpc_sysfs_client_type = { .release = rpc_sysfs_client_release, .sysfs_ops = &kobj_sysfs_ops, .namespace = rpc_sysfs_client_namespace, }; +static struct kobj_type rpc_sysfs_xprt_switch_type = { + .release = rpc_sysfs_xprt_switch_release, + .sysfs_ops = &kobj_sysfs_ops, + .namespace = rpc_sysfs_xprt_switch_namespace, +}; + void rpc_sysfs_exit(void) { kobject_put(rpc_sunrpc_client_kobj); + kobject_put(rpc_sunrpc_xprt_switch_kobj); kset_unregister(rpc_sunrpc_kset); } @@ -99,6 +128,28 @@ static struct rpc_sysfs_client *rpc_sysfs_client_alloc(struct kobject *parent, return NULL; } +static struct rpc_sysfs_xprt_switch * +rpc_sysfs_xprt_switch_alloc(struct kobject *parent, + struct rpc_xprt_switch *xprt_switch, + struct net *net, + gfp_t gfp_flags) +{ + struct rpc_sysfs_xprt_switch *p; + + p = kzalloc(sizeof(*p), gfp_flags); + if (p) { + p->net = net; + p->kobject.kset = rpc_sunrpc_kset; + if (kobject_init_and_add(&p->kobject, + &rpc_sysfs_xprt_switch_type, + parent, "switch-%d", + xprt_switch->xps_id) == 0) + return p; + kobject_put(&p->kobject); + } + return NULL; +} + void rpc_sysfs_client_setup(struct rpc_clnt *clnt, struct net *net) { struct rpc_sysfs_client *rpc_client; @@ -110,6 +161,28 @@ void rpc_sysfs_client_setup(struct rpc_clnt *clnt, struct net *net) } } +void rpc_sysfs_xprt_switch_setup(struct rpc_xprt_switch *xprt_switch, + struct rpc_xprt *xprt, + gfp_t gfp_flags) +{ + struct rpc_sysfs_xprt_switch *rpc_xprt_switch; + struct net *net; + + if (xprt_switch->xps_net) + net = xprt_switch->xps_net; + else + net = xprt->xprt_net; + rpc_xprt_switch = + rpc_sysfs_xprt_switch_alloc(rpc_sunrpc_xprt_switch_kobj, + xprt_switch, net, gfp_flags); + if (rpc_xprt_switch) { + xprt_switch->xps_sysfs = rpc_xprt_switch; + rpc_xprt_switch->xprt_switch = xprt_switch; + rpc_xprt_switch->xprt = xprt; + kobject_uevent(&rpc_xprt_switch->kobject, KOBJ_ADD); + } +} + void rpc_sysfs_client_destroy(struct rpc_clnt *clnt) { struct rpc_sysfs_client *rpc_client = clnt->cl_sysfs; @@ -121,3 +194,15 @@ void rpc_sysfs_client_destroy(struct rpc_clnt *clnt) clnt->cl_sysfs = NULL; } } + +void rpc_sysfs_xprt_switch_destroy(struct rpc_xprt_switch *xprt_switch) +{ + struct rpc_sysfs_xprt_switch *rpc_xprt_switch = xprt_switch->xps_sysfs; + + if (rpc_xprt_switch) { + kobject_uevent(&rpc_xprt_switch->kobject, KOBJ_REMOVE); + kobject_del(&rpc_xprt_switch->kobject); + kobject_put(&rpc_xprt_switch->kobject); + xprt_switch->xps_sysfs = NULL; + } +} diff --git a/net/sunrpc/sysfs.h b/net/sunrpc/sysfs.h index c46afc848993..52ec472bd4a9 100644 --- a/net/sunrpc/sysfs.h +++ b/net/sunrpc/sysfs.h @@ -10,10 +10,20 @@ struct rpc_sysfs_client { struct net *net; }; +struct rpc_sysfs_xprt_switch { + struct kobject kobject; + struct net *net; + struct rpc_xprt_switch *xprt_switch; + struct rpc_xprt *xprt; +}; + int rpc_sysfs_init(void); void rpc_sysfs_exit(void); void rpc_sysfs_client_setup(struct rpc_clnt *clnt, struct net *net); void rpc_sysfs_client_destroy(struct rpc_clnt *clnt); +void rpc_sysfs_xprt_switch_setup(struct rpc_xprt_switch *xprt_switch, + struct rpc_xprt *xprt, gfp_t gfp_flags); +void rpc_sysfs_xprt_switch_destroy(struct rpc_xprt_switch *xprt); #endif diff --git a/net/sunrpc/xprtmultipath.c b/net/sunrpc/xprtmultipath.c index 4969a4c216f7..2d73a35df9ee 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); @@ -133,6 +135,7 @@ struct rpc_xprt_switch *xprt_switch_alloc(struct rpc_xprt *xprt, xps->xps_net = NULL; INIT_LIST_HEAD(&xps->xps_xprt_list); xps->xps_iter_ops = &rpc_xprt_iter_singular; + rpc_sysfs_xprt_switch_setup(xps, xprt, gfp_flags); xprt_switch_add_xprt_locked(xps, xprt); } @@ -161,6 +164,7 @@ static void xprt_switch_free(struct kref *kref) struct rpc_xprt_switch, xps_kref); xprt_switch_free_entries(xps); + rpc_sysfs_xprt_switch_destroy(xps); xprt_switch_free_id(xps); kfree_rcu(xps, xps_rcu); } -- 2.27.0