Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 294405
b: refs/heads/master
c: dff02d4
h: refs/heads/master
i:
  294403: 067ff29
v: v3
  • Loading branch information
Stanislav Kinsbursky authored and Trond Myklebust committed Feb 1, 2012
1 parent c1e8472 commit 0f7838a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 30 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 961a828df64979d2a9faeeeee043391670a193b9
refs/heads/master: dff02d499c067bdde589b764321b35fe763569f6
5 changes: 5 additions & 0 deletions trunk/net/sunrpc/netns.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ struct sunrpc_net {

struct list_head all_clients;
spinlock_t rpc_client_lock;

struct rpc_clnt *rpcb_local_clnt;
struct rpc_clnt *rpcb_local_clnt4;
spinlock_t rpcb_clnt_lock;
unsigned int rpcb_users;
};

extern int sunrpc_net_id;
Expand Down
64 changes: 35 additions & 29 deletions trunk/net/sunrpc/rpcb_clnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@
#include <linux/errno.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/nsproxy.h>
#include <net/ipv6.h>

#include <linux/sunrpc/clnt.h>
#include <linux/sunrpc/sched.h>
#include <linux/sunrpc/xprtsock.h>

#include "netns.h"

#ifdef RPC_DEBUG
# define RPCDBG_FACILITY RPCDBG_BIND
#endif
Expand Down Expand Up @@ -111,12 +114,6 @@ static void rpcb_getport_done(struct rpc_task *, void *);
static void rpcb_map_release(void *data);
static struct rpc_program rpcb_program;

static struct rpc_clnt * rpcb_local_clnt;
static struct rpc_clnt * rpcb_local_clnt4;

DEFINE_SPINLOCK(rpcb_clnt_lock);
unsigned int rpcb_users;

struct rpcbind_args {
struct rpc_xprt * r_xprt;

Expand Down Expand Up @@ -167,29 +164,31 @@ static void rpcb_map_release(void *data)
static int rpcb_get_local(void)
{
int cnt;
struct sunrpc_net *sn = net_generic(&init_net, sunrpc_net_id);

spin_lock(&rpcb_clnt_lock);
if (rpcb_users)
rpcb_users++;
cnt = rpcb_users;
spin_unlock(&rpcb_clnt_lock);
spin_lock(&sn->rpcb_clnt_lock);
if (sn->rpcb_users)
sn->rpcb_users++;
cnt = sn->rpcb_users;
spin_unlock(&sn->rpcb_clnt_lock);

return cnt;
}

void rpcb_put_local(void)
{
struct rpc_clnt *clnt = rpcb_local_clnt;
struct rpc_clnt *clnt4 = rpcb_local_clnt4;
struct sunrpc_net *sn = net_generic(&init_net, sunrpc_net_id);
struct rpc_clnt *clnt = sn->rpcb_local_clnt;
struct rpc_clnt *clnt4 = sn->rpcb_local_clnt4;
int shutdown;

spin_lock(&rpcb_clnt_lock);
if (--rpcb_users == 0) {
rpcb_local_clnt = NULL;
rpcb_local_clnt4 = NULL;
spin_lock(&sn->rpcb_clnt_lock);
if (--sn->rpcb_users == 0) {
sn->rpcb_local_clnt = NULL;
sn->rpcb_local_clnt4 = NULL;
}
shutdown = !rpcb_users;
spin_unlock(&rpcb_clnt_lock);
shutdown = !sn->rpcb_users;
spin_unlock(&sn->rpcb_clnt_lock);

if (shutdown) {
/*
Expand All @@ -204,14 +203,16 @@ void rpcb_put_local(void)

static void rpcb_set_local(struct rpc_clnt *clnt, struct rpc_clnt *clnt4)
{
struct sunrpc_net *sn = net_generic(&init_net, sunrpc_net_id);

/* Protected by rpcb_create_local_mutex */
rpcb_local_clnt = clnt;
rpcb_local_clnt4 = clnt4;
sn->rpcb_local_clnt = clnt;
sn->rpcb_local_clnt4 = clnt4;
smp_wmb();
rpcb_users = 1;
sn->rpcb_users = 1;
dprintk("RPC: created new rpcb local clients (rpcb_local_clnt: "
"%p, rpcb_local_clnt4: %p)\n", rpcb_local_clnt,
rpcb_local_clnt4);
"%p, rpcb_local_clnt4: %p)\n", sn->rpcb_local_clnt,
sn->rpcb_local_clnt4);
}

/*
Expand Down Expand Up @@ -431,6 +432,7 @@ int rpcb_register(u32 prog, u32 vers, int prot, unsigned short port)
struct rpc_message msg = {
.rpc_argp = &map,
};
struct sunrpc_net *sn = net_generic(&init_net, sunrpc_net_id);

dprintk("RPC: %sregistering (%u, %u, %d, %u) with local "
"rpcbind\n", (port ? "" : "un"),
Expand All @@ -440,7 +442,7 @@ int rpcb_register(u32 prog, u32 vers, int prot, unsigned short port)
if (port)
msg.rpc_proc = &rpcb_procedures2[RPCBPROC_SET];

return rpcb_register_call(rpcb_local_clnt, &msg);
return rpcb_register_call(sn->rpcb_local_clnt, &msg);
}

/*
Expand All @@ -453,6 +455,7 @@ static int rpcb_register_inet4(const struct sockaddr *sap,
struct rpcbind_args *map = msg->rpc_argp;
unsigned short port = ntohs(sin->sin_port);
int result;
struct sunrpc_net *sn = net_generic(&init_net, sunrpc_net_id);

map->r_addr = rpc_sockaddr2uaddr(sap, GFP_KERNEL);

Expand All @@ -465,7 +468,7 @@ static int rpcb_register_inet4(const struct sockaddr *sap,
if (port)
msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET];

result = rpcb_register_call(rpcb_local_clnt4, msg);
result = rpcb_register_call(sn->rpcb_local_clnt4, msg);
kfree(map->r_addr);
return result;
}
Expand All @@ -480,6 +483,7 @@ static int rpcb_register_inet6(const struct sockaddr *sap,
struct rpcbind_args *map = msg->rpc_argp;
unsigned short port = ntohs(sin6->sin6_port);
int result;
struct sunrpc_net *sn = net_generic(&init_net, sunrpc_net_id);

map->r_addr = rpc_sockaddr2uaddr(sap, GFP_KERNEL);

Expand All @@ -492,14 +496,15 @@ static int rpcb_register_inet6(const struct sockaddr *sap,
if (port)
msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET];

result = rpcb_register_call(rpcb_local_clnt4, msg);
result = rpcb_register_call(sn->rpcb_local_clnt4, msg);
kfree(map->r_addr);
return result;
}

static int rpcb_unregister_all_protofamilies(struct rpc_message *msg)
{
struct rpcbind_args *map = msg->rpc_argp;
struct sunrpc_net *sn = net_generic(&init_net, sunrpc_net_id);

dprintk("RPC: unregistering [%u, %u, '%s'] with "
"local rpcbind\n",
Expand All @@ -508,7 +513,7 @@ static int rpcb_unregister_all_protofamilies(struct rpc_message *msg)
map->r_addr = "";
msg->rpc_proc = &rpcb_procedures4[RPCBPROC_UNSET];

return rpcb_register_call(rpcb_local_clnt4, msg);
return rpcb_register_call(sn->rpcb_local_clnt4, msg);
}

/**
Expand Down Expand Up @@ -566,8 +571,9 @@ int rpcb_v4_register(const u32 program, const u32 version,
struct rpc_message msg = {
.rpc_argp = &map,
};
struct sunrpc_net *sn = net_generic(&init_net, sunrpc_net_id);

if (rpcb_local_clnt4 == NULL)
if (sn->rpcb_local_clnt4 == NULL)
return -EPROTONOSUPPORT;

if (address == NULL)
Expand Down

0 comments on commit 0f7838a

Please sign in to comment.