Skip to content

Commit

Permalink
NFS: Add sysfs links to sunrpc clients for nfs_clients
Browse files Browse the repository at this point in the history
For the general and state management nfs_client under each mount, create
symlinks to their respective rpc_client sysfs entries.

Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
  • Loading branch information
Benjamin Coddington authored and Trond Myklebust committed Jun 19, 2023
1 parent 1c72511 commit e13b549
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
5 changes: 5 additions & 0 deletions fs/nfs/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ int nfs_init_server_rpcclient(struct nfs_server *server,
if (server->flags & NFS_MOUNT_SOFT)
server->client->cl_softrtry = 1;

nfs_sysfs_link_rpc_client(server, server->client, NULL);
return 0;
}
EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
Expand Down Expand Up @@ -699,6 +700,7 @@ static int nfs_init_server(struct nfs_server *server,

server->nfs_client = clp;
nfs_sysfs_add_server(server);
nfs_sysfs_link_rpc_client(server, clp->cl_rpcclient, "_state");

/* Initialise the client representation from the mount data */
server->flags = ctx->flags;
Expand Down Expand Up @@ -1125,6 +1127,9 @@ struct nfs_server *nfs_clone_server(struct nfs_server *source,

nfs_sysfs_add_server(server);

nfs_sysfs_link_rpc_client(server,
server->nfs_client->cl_rpcclient, "_state");

error = nfs_init_server_rpcclient(server,
source->client->cl_timeout,
flavor);
Expand Down
1 change: 1 addition & 0 deletions fs/nfs/nfs4client.c
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,7 @@ static int nfs4_set_client(struct nfs_server *server,

server->nfs_client = clp;
nfs_sysfs_add_server(server);
nfs_sysfs_link_rpc_client(server, clp->cl_rpcclient, "_state");

return 0;
}
Expand Down
20 changes: 20 additions & 0 deletions fs/nfs/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,26 @@ void nfs_netns_sysfs_destroy(struct nfs_net *netns)
}
}

#define RPC_CLIENT_NAME_SIZE 64

void nfs_sysfs_link_rpc_client(struct nfs_server *server,
struct rpc_clnt *clnt, const char *uniq)
{
char name[RPC_CLIENT_NAME_SIZE];
int ret;

strcpy(name, clnt->cl_program->name);
strcat(name, uniq ? uniq : "");
strcat(name, "_client");

ret = sysfs_create_link_nowarn(&server->kobj,
&clnt->cl_sysfs->kobject, name);
if (ret < 0)
pr_warn("NFS: can't create link to %s in sysfs (%d)\n",
name, ret);
}
EXPORT_SYMBOL_GPL(nfs_sysfs_link_rpc_client);

static void nfs_sysfs_sb_release(struct kobject *kobj)
{
/* no-op: why? see lib/kobject.c kobject_cleanup() */
Expand Down
2 changes: 2 additions & 0 deletions fs/nfs/sysfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ extern void nfs_sysfs_exit(void);
void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net);
void nfs_netns_sysfs_destroy(struct nfs_net *netns);

void nfs_sysfs_link_rpc_client(struct nfs_server *server,
struct rpc_clnt *clnt, const char *sysfs_prefix);
void nfs_sysfs_add_server(struct nfs_server *s);
void nfs_sysfs_move_server_to_sb(struct super_block *s);
void nfs_sysfs_move_sb_to_server(struct nfs_server *s);
Expand Down
8 changes: 7 additions & 1 deletion include/linux/sunrpc/clnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@
#include <linux/sunrpc/xprtmultipath.h>

struct rpc_inode;
struct rpc_sysfs_client;
struct rpc_sysfs_client {
struct kobject kobject;
struct net *net;
struct rpc_clnt *clnt;
struct rpc_xprt_switch *xprt_switch;
};


/*
* The high-level client handle
Expand Down
7 changes: 0 additions & 7 deletions net/sunrpc/sysfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
#ifndef __SUNRPC_SYSFS_H
#define __SUNRPC_SYSFS_H

struct rpc_sysfs_client {
struct kobject kobject;
struct net *net;
struct rpc_clnt *clnt;
struct rpc_xprt_switch *xprt_switch;
};

struct rpc_sysfs_xprt_switch {
struct kobject kobject;
struct net *net;
Expand Down

0 comments on commit e13b549

Please sign in to comment.