sunrpc: Create per-rpc_clnt sysfs kobjects
These will eventually have files placed under them for sysfs operations. Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com> Signed-off-by: Olga Kornievskaia <kolga@netapp.com> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
This commit is contained in:
parent
c441f125de
commit
c5a382ebdb
|
@ -29,6 +29,7 @@
|
|||
#include <linux/sunrpc/xprtmultipath.h>
|
||||
|
||||
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
|
||||
*/
|
||||
|
|
|
@ -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_sysfs_client_setup(clnt, net);
|
||||
|
||||
pipefs_sb = rpc_get_sb_net(net);
|
||||
if (pipefs_sb) {
|
||||
|
@ -327,6 +329,7 @@ err_auth:
|
|||
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);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
*/
|
||||
#include <linux/sunrpc/clnt.h>
|
||||
#include <linux/kobject.h>
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue