Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp645928pxj; Fri, 14 May 2021 12:01:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWjXB2Zl6quc4PjW7LZOwelugWDgbNvZQVU5ZCBw3pjv33cefh0FzbYciof/zdE1zlJr+M X-Received: by 2002:a05:6402:1bc9:: with SMTP id ch9mr58755863edb.136.1621018882397; Fri, 14 May 2021 12:01:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621018882; cv=none; d=google.com; s=arc-20160816; b=Xo8GmhB6Tvj2eQfqHcufK/I0J0eor0Ug0J2b835mW2BCFtA7Zj0IOaWSLYhLYJX26R tnAhkUl6VR0JjzX6yIsSuEzQIpoEwhDEx5YI7KbAKMcezW3nJiX57Xj1XeYGcAqANxXv FAlYeB22QIr2PzMO7P4n+hGOP1FmIPrq8sdWCgywV8du0jIoQEcSJTF32fm0eFXq0jOT 9g4B2dyszyDmUZROZunCY4DcdgmeYweDG4blmlq8x/ZlhPw1NvxzFfkChk7cui1Sn30A blnAtLzNYQqi/cvXNTAzF/XmtveHLersdqY5Xb719p8lHdVMUzSIBxS5TdWtLuCyJES8 8rEA== 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=nLjSrJLE8b13pide6r5rsc+IF4XHjCeva4eWstGE7nU=; b=hj71VjoDDxjng2U9zQwFbz+rQl0adAv8aimSFQgsh9gl6mD+qIQdkGCDgAp6pufQ46 Bv0bSlKuRqrbzGJgYZk7pSfY/I9BclKDjmubeoaplbOSvfUa4DKYQkohARsPAahhJ4Bu I1WhWHY1DpAMQ7WMxpfuqrlHwC2evV7WgGzLHG/5buQgz76ssGaAVDiHzPNXcPUQyE2M 0cynZ7o5lx7/1LVh42mbvBe5WnMizlERqh1OBvY0uj3lisXOaFvUCEzqT1IDSbJ0TDvI xILBWoDC1vpB6e0ZOsvNY8ej6l4EDZZhv9H5V64483kKU8/cSygIPMSLMAee9AfWSQ8H oBnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZmBOFMaM; 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 q29si4206226edb.218.2021.05.14.12.00.58; Fri, 14 May 2021 12:01:22 -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=ZmBOFMaM; 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 S233043AbhENOOm (ORCPT + 99 others); Fri, 14 May 2021 10:14:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233040AbhENOOl (ORCPT ); Fri, 14 May 2021 10:14:41 -0400 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD38BC061574 for ; Fri, 14 May 2021 07:13:29 -0700 (PDT) Received: by mail-io1-xd31.google.com with SMTP id n10so28199495ion.8 for ; Fri, 14 May 2021 07:13:29 -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=nLjSrJLE8b13pide6r5rsc+IF4XHjCeva4eWstGE7nU=; b=ZmBOFMaMcGUUfWxf21zdfUr8t6/Ou9On8PdczAZgjp6UBrm6dwCyJTcgK/pH8AAvZj PhUOUFkuExvmLypN0LSY8IUt4l5zJm1a/4MSz2ICmDryiSMiPhu9vZ8d3UWlh107yq07 PjR9jGjzK9DKI1A8mSvoGNay4asF3n4KnUgWXbTqCiVgkvqZ+mE2J/D3ToyNyao/tzFW ovJolGUNwx9LZeABAW6vP+ye3vUNvES18CDJ3Bld/HHdMX0Z4/5Hv68B7W7CvSTwHRwp tZ/Gz8H4rxKEOslQKCpWzbE7z9zRzn9cb2XFTu4oaUowByEWHQsdTM9KXbYz0RuCHqr2 5JKQ== 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=nLjSrJLE8b13pide6r5rsc+IF4XHjCeva4eWstGE7nU=; b=inxXRvQkwy0GrflDwseM+u3aD7uHz+XO4XVo/VPiZyK1hA49Ix8OD5SeJ3PyxR7h/W fHU2cAvfhQQnd6N0NbXbQNbF9ue4Vdo8ex/QVSGOG2uVJPRBf4bWL18EnfM8Hc3wIauT zaOnb4RAhF+HXZrpmRM0loklE0pctKPCYAQpRnlr00rhH2tsLzNCxfWeLCyX8dAap57U Bg3bzrEodRiOk2uVzT/QjJ2vjZ/diL4IIxJIkClF8H1gdGoriyaEMe02okXminC9Sxqw 7I+aN/Tb0ltEr02GpYxKHLc/FK1bYHWc7V+rOBT6Qq7y/JWLlXkNokLklvY/VY5ABG2L hYZw== X-Gm-Message-State: AOAM530Hnv7iXFQgWA5S51PtRsWIrGm2ozeCu4AHO1DzeQeP5ysh2nZI 7DYF2XLVJugk9Ffp1Kast23E2fuvSuqmNg== X-Received: by 2002:a05:6638:3721:: with SMTP id k33mr815368jav.7.1621001609416; Fri, 14 May 2021 07:13:29 -0700 (PDT) Received: from kolga-mac-1.attlocal.net ([2600:1700:6a10:2e90:a4f7:32c8:9c05:11a7]) by smtp.gmail.com with ESMTPSA id b189sm2639263iof.48.2021.05.14.07.13.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 May 2021 07:13:28 -0700 (PDT) From: Olga Kornievskaia To: trond.myklebust@hammerspace.com, anna.schumaker@netapp.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v7 03/12] sunrpc: Create per-rpc_clnt sysfs kobjects Date: Fri, 14 May 2021 10:13:14 -0400 Message-Id: <20210514141323.67922-4-olga.kornievskaia@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20210514141323.67922-1-olga.kornievskaia@gmail.com> References: <20210514141323.67922-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 These will eventually have files placed under them for sysfs operations. Signed-off-by: Anna Schumaker Signed-off-by: Olga Kornievskaia --- include/linux/sunrpc/clnt.h | 2 ++ net/sunrpc/clnt.c | 5 +++ net/sunrpc/sysfs.c | 61 +++++++++++++++++++++++++++++++++++++ net/sunrpc/sysfs.h | 8 +++++ 4 files changed, 76 insertions(+) diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h index 02e7a5863d28..8b5d5c97553e 100644 --- a/include/linux/sunrpc/clnt.h +++ b/include/linux/sunrpc/clnt.h @@ -29,6 +29,7 @@ #include struct rpc_inode; +struct rpc_sysfs_client; /* * The high-level client handle @@ -71,6 +72,7 @@ struct rpc_clnt { #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) struct dentry *cl_debugfs; /* debugfs directory */ #endif + struct rpc_sysfs_client *cl_sysfs; /* sysfs directory */ /* cl_work is only needed after cl_xpi is no longer used, * and that are of similar size */ diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c index f555d335e910..ec9254a11a03 100644 --- a/net/sunrpc/clnt.c +++ b/net/sunrpc/clnt.c @@ -41,6 +41,7 @@ #include #include "sunrpc.h" +#include "sysfs.h" #include "netns.h" #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) @@ -300,6 +301,7 @@ static int rpc_client_register(struct rpc_clnt *clnt, int err; rpc_clnt_debugfs_register(clnt); + rpc_sysfs_client_setup(clnt, net); pipefs_sb = rpc_get_sb_net(net); if (pipefs_sb) { @@ -327,6 +329,7 @@ static int rpc_client_register(struct rpc_clnt *clnt, out: if (pipefs_sb) rpc_put_sb_net(net); + rpc_sysfs_client_destroy(clnt); rpc_clnt_debugfs_unregister(clnt); return err; } @@ -733,6 +736,7 @@ int rpc_switch_client_transport(struct rpc_clnt *clnt, rpc_unregister_client(clnt); __rpc_clnt_remove_pipedir(clnt); + rpc_sysfs_client_destroy(clnt); rpc_clnt_debugfs_unregister(clnt); /* @@ -879,6 +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_sysfs_client_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 fa03e2ef836a..f3b7547ee218 100644 --- a/net/sunrpc/sysfs.c +++ b/net/sunrpc/sysfs.c @@ -4,6 +4,7 @@ */ #include #include +#include "sysfs.h" static struct kset *rpc_sunrpc_kset; static struct kobject *rpc_sunrpc_client_kobj; @@ -56,8 +57,68 @@ int rpc_sysfs_init(void) return 0; } +static void rpc_sysfs_client_release(struct kobject *kobj) +{ + struct rpc_sysfs_client *c; + + c = container_of(kobj, struct rpc_sysfs_client, kobject); + kfree(c); +} + +static const void *rpc_sysfs_client_namespace(struct kobject *kobj) +{ + return container_of(kobj, struct rpc_sysfs_client, 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, +}; + void rpc_sysfs_exit(void) { kobject_put(rpc_sunrpc_client_kobj); kset_unregister(rpc_sunrpc_kset); } + +static struct rpc_sysfs_client *rpc_sysfs_client_alloc(struct kobject *parent, + struct net *net, + int clid) +{ + struct rpc_sysfs_client *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_sysfs_client_type, + parent, "clnt-%d", clid) == 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; + + rpc_client = rpc_sysfs_client_alloc(rpc_sunrpc_client_kobj, net, clnt->cl_clid); + if (rpc_client) { + clnt->cl_sysfs = rpc_client; + kobject_uevent(&rpc_client->kobject, KOBJ_ADD); + } +} + +void rpc_sysfs_client_destroy(struct rpc_clnt *clnt) +{ + struct rpc_sysfs_client *rpc_client = clnt->cl_sysfs; + + if (rpc_client) { + kobject_uevent(&rpc_client->kobject, KOBJ_REMOVE); + kobject_del(&rpc_client->kobject); + kobject_put(&rpc_client->kobject); + clnt->cl_sysfs = NULL; + } +} diff --git a/net/sunrpc/sysfs.h b/net/sunrpc/sysfs.h index f181c650aab8..c46afc848993 100644 --- a/net/sunrpc/sysfs.h +++ b/net/sunrpc/sysfs.h @@ -5,7 +5,15 @@ #ifndef __SUNRPC_SYSFS_H #define __SUNRPC_SYSFS_H +struct rpc_sysfs_client { + struct kobject kobject; + struct net *net; +}; + 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); + #endif -- 2.27.0