All of lore.kernel.org
 help / color / mirror / Atom feed
From: schumaker.anna@gmail.com
To: linux-nfs@vger.kernel.org
Cc: Anna.Schumaker@Netapp.com
Subject: [PATCH v2 3/5] sunrpc: Create per-rpc_clnt sysfs kobjects
Date: Tue,  2 Feb 2021 13:42:42 -0500	[thread overview]
Message-ID: <20210202184244.288898-4-Anna.Schumaker@Netapp.com> (raw)
In-Reply-To: <20210202184244.288898-1-Anna.Schumaker@Netapp.com>

From: Anna Schumaker <Anna.Schumaker@Netapp.com>

These will eventually have files placed under them for sysfs operations.

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
---
 include/linux/sunrpc/clnt.h |  1 +
 net/sunrpc/clnt.c           |  5 ++++
 net/sunrpc/sysfs.c          | 60 +++++++++++++++++++++++++++++++++++++
 net/sunrpc/sysfs.h          |  8 +++++
 4 files changed, 74 insertions(+)

diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
index 02e7a5863d28..503653720e18 100644
--- a/include/linux/sunrpc/clnt.h
+++ b/include/linux/sunrpc/clnt.h
@@ -71,6 +71,7 @@ struct rpc_clnt {
 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
 	struct dentry		*cl_debugfs;	/* debugfs directory */
 #endif
+	void			*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 612f0a641f4c..02905eae5c0a 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -41,6 +41,7 @@
 #include <trace/events/sunrpc.h>
 
 #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_netns_sysfs_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_netns_sysfs_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_netns_sysfs_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_netns_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 ad6a5de5927c..42a690f8bb52 100644
--- a/net/sunrpc/sysfs.c
+++ b/net/sunrpc/sysfs.c
@@ -4,6 +4,7 @@
  */
 #include <linux/sunrpc/clnt.h>
 #include <linux/kobject.h>
+#include "sysfs.h"
 
 struct kobject *rpc_client_kobj;
 static struct kset *rpc_client_kset;
@@ -54,8 +55,67 @@ int rpc_sysfs_init(void)
 	return 0;
 }
 
+static void rpc_netns_client_release(struct kobject *kobj)
+{
+	struct rpc_netns_client *c;
+
+	c = container_of(kobj, struct rpc_netns_client, kobject);
+	kfree(c);
+}
+
+static const void *rpc_netns_client_namespace(struct kobject *kobj)
+{
+	return container_of(kobj, struct rpc_netns_client, kobject)->net;
+}
+
+static struct kobj_type rpc_netns_client_type = {
+	.release = rpc_netns_client_release,
+	.sysfs_ops = &kobj_sysfs_ops,
+	.namespace = rpc_netns_client_namespace,
+};
+
 void rpc_sysfs_exit(void)
 {
 	kobject_put(rpc_client_kobj);
 	kset_unregister(rpc_client_kset);
 }
+
+static struct rpc_netns_client *rpc_netns_client_alloc(struct kobject *parent,
+						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;
+		if (kobject_init_and_add(&p->kobject, &rpc_netns_client_type,
+					parent, "%d", clid) == 0)
+			return p;
+		kobject_put(&p->kobject);
+	}
+	return NULL;
+}
+
+void rpc_netns_sysfs_setup(struct rpc_clnt *clnt, struct net *net)
+{
+	struct rpc_netns_client *rpc_client;
+
+	rpc_client = rpc_netns_client_alloc(rpc_client_kobj, net, clnt->cl_clid);
+	if (rpc_client) {
+		clnt->cl_sysfs = rpc_client;
+		kobject_uevent(&rpc_client->kobject, KOBJ_ADD);
+	}
+}
+
+void rpc_netns_sysfs_destroy(struct rpc_clnt *clnt)
+{
+	struct rpc_netns_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 93c3cd220506..279a836594e7 100644
--- a/net/sunrpc/sysfs.h
+++ b/net/sunrpc/sysfs.h
@@ -5,9 +5,17 @@
 #ifndef __SUNRPC_SYSFS_H
 #define __SUNRPC_SYSFS_H
 
+struct rpc_netns_client {
+	struct kobject kobject;
+	struct net *net;
+};
+
 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);
+
 #endif
-- 
2.29.2


  parent reply	other threads:[~2021-02-02 18:45 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-02 18:42 [PATCH v2 0/5] SUNRPC: Create sysfs files for changing IP schumaker.anna
2021-02-02 18:42 ` [PATCH v2 1/5] sunrpc: Create a sunrpc directory under /sys/kernel/ schumaker.anna
2021-02-02 18:42 ` [PATCH v2 2/5] sunrpc: Create a net/ subdirectory in the sunrpc sysfs schumaker.anna
2021-02-02 18:42 ` schumaker.anna [this message]
2021-02-02 18:42 ` [PATCH v2 4/5] sunrpc: Prepare xs_connect() for taking NULL tasks schumaker.anna
2021-02-02 21:49   ` Trond Myklebust
2021-02-02 21:59     ` Trond Myklebust
2021-02-05 18:33       ` Anna Schumaker
2021-02-02 18:42 ` [PATCH v2 5/5] sunrpc: Create a per-rpc_clnt file for managing the destination IP address schumaker.anna
2021-02-06 14:02   ` [sunrpc] 32fea9c254: WARNING:suspicious_RCU_usage kernel test robot
2021-02-06 14:02     ` kernel test robot
2021-02-02 18:51 ` [PATCH v2 0/5] SUNRPC: Create sysfs files for changing IP Chuck Lever
2021-02-02 18:52   ` Anna Schumaker
2021-02-02 19:24     ` Dan Aloni
2021-02-02 19:46       ` Chuck Lever
2021-02-02 19:51         ` Anna Schumaker
2021-02-02 19:49       ` Benjamin Coddington
2021-02-02 22:17         ` Trond Myklebust
2021-02-02 22:21           ` Chuck Lever
2021-02-02 22:24             ` Trond Myklebust
2021-02-02 22:31               ` Chuck Lever
2021-02-03 21:20         ` Dan Aloni
2021-02-14 17:41           ` Dan Aloni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210202184244.288898-4-Anna.Schumaker@Netapp.com \
    --to=schumaker.anna@gmail.com \
    --cc=Anna.Schumaker@Netapp.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.