Skip to content

Commit bb2224d

Browse files
Stanislav KinsburskyTrond Myklebust
authored andcommitted
Lockd: per-net up and down routines introduced
This patch introduces per-net Lockd initialization and destruction routines. The logic is the same as in global Lockd up and down routines. Probably the solution is not the best one. But at least it looks clear. So per-net "up" routine are called only in case of lockd is running already. If per-net resources are not allocated yet, then service is being registered with local portmapper and lockd sockets created. Per-net "down" routine is called on every lockd_down() call in case of global users counter is not zero. Signed-off-by: Stanislav Kinsbursky <skinsbursky@parallels.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
1 parent a9c5d73 commit bb2224d

3 files changed

Lines changed: 49 additions & 3 deletions

File tree

‎fs/lockd/svc.c‎

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,45 @@ static int make_socks(struct svc_serv *serv, struct net *net)
251251
return err;
252252
}
253253

254+
static int lockd_up_net(struct net *net)
255+
{
256+
struct lockd_net *ln = net_generic(net, lockd_net_id);
257+
struct svc_serv *serv = nlmsvc_rqst->rq_server;
258+
int error;
259+
260+
if (ln->nlmsvc_users)
261+
return 0;
262+
263+
error = svc_rpcb_setup(serv, net);
264+
if (error)
265+
goto err_rpcb;
266+
267+
error = make_socks(serv, net);
268+
if (error < 0)
269+
goto err_socks;
270+
return 0;
271+
272+
err_socks:
273+
svc_rpcb_cleanup(serv, net);
274+
err_rpcb:
275+
return error;
276+
}
277+
278+
static void lockd_down_net(struct net *net)
279+
{
280+
struct lockd_net *ln = net_generic(net, lockd_net_id);
281+
struct svc_serv *serv = nlmsvc_rqst->rq_server;
282+
283+
if (ln->nlmsvc_users) {
284+
if (--ln->nlmsvc_users == 0)
285+
svc_shutdown_net(serv, net);
286+
} else {
287+
printk(KERN_ERR "lockd_down_net: no users! task=%p, net=%p\n",
288+
nlmsvc_task, net);
289+
BUG();
290+
}
291+
}
292+
254293
/*
255294
* Bring up the lockd process if it's not already up.
256295
*/
@@ -264,8 +303,10 @@ int lockd_up(void)
264303
/*
265304
* Check whether we're already up and running.
266305
*/
267-
if (nlmsvc_rqst)
306+
if (nlmsvc_rqst) {
307+
error = lockd_up_net(net);
268308
goto out;
309+
}
269310

270311
/*
271312
* Sanity check: if there's no pid,
@@ -339,8 +380,10 @@ lockd_down(void)
339380
{
340381
mutex_lock(&nlmsvc_mutex);
341382
if (nlmsvc_users) {
342-
if (--nlmsvc_users)
383+
if (--nlmsvc_users) {
384+
lockd_down_net(current->nsproxy->net_ns);
343385
goto out;
386+
}
344387
} else {
345388
printk(KERN_ERR "lockd_down: no users! task=%p\n",
346389
nlmsvc_task);

‎include/linux/sunrpc/svc.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ struct svc_procedure {
414414
/*
415415
* Function prototypes.
416416
*/
417+
int svc_rpcb_setup(struct svc_serv *serv, struct net *net);
417418
void svc_rpcb_cleanup(struct svc_serv *serv, struct net *net);
418419
struct svc_serv *svc_create(struct svc_program *, unsigned int,
419420
void (*shutdown)(struct svc_serv *, struct net *net));
@@ -426,6 +427,7 @@ struct svc_serv * svc_create_pooled(struct svc_program *, unsigned int,
426427
int svc_set_num_threads(struct svc_serv *, struct svc_pool *, int);
427428
int svc_pool_stats_open(struct svc_serv *serv, struct file *file);
428429
void svc_destroy(struct svc_serv *);
430+
void svc_shutdown_net(struct svc_serv *, struct net *);
429431
int svc_process(struct svc_rqst *);
430432
int bc_svc_process(struct svc_serv *, struct rpc_rqst *,
431433
struct svc_rqst *);

‎net/sunrpc/svc.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ svc_pool_for_cpu(struct svc_serv *serv, int cpu)
369369
return &serv->sv_pools[pidx % serv->sv_nrpools];
370370
}
371371

372-
static int svc_rpcb_setup(struct svc_serv *serv, struct net *net)
372+
int svc_rpcb_setup(struct svc_serv *serv, struct net *net)
373373
{
374374
int err;
375375

@@ -381,6 +381,7 @@ static int svc_rpcb_setup(struct svc_serv *serv, struct net *net)
381381
svc_unregister(serv, net);
382382
return 0;
383383
}
384+
EXPORT_SYMBOL_GPL(svc_rpcb_setup);
384385

385386
void svc_rpcb_cleanup(struct svc_serv *serv, struct net *net)
386387
{

0 commit comments

Comments
 (0)