Skip to content

Commit

Permalink
svcrpc: fix xpt_list traversal locking on shutdown
Browse files Browse the repository at this point in the history
Server threads are not running at this point, but svc_age_temp_xprts
still may be, so we need this locking.

Signed-off-by: J. Bruce Fields <bfields@redhat.com>
  • Loading branch information
J. Bruce Fields committed Aug 21, 2012
1 parent 21179d8 commit 719f8bc
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions net/sunrpc/svc_xprt.c
Original file line number Diff line number Diff line change
Expand Up @@ -917,16 +917,18 @@ void svc_close_xprt(struct svc_xprt *xprt)
}
EXPORT_SYMBOL_GPL(svc_close_xprt);

static void svc_close_list(struct list_head *xprt_list, struct net *net)
static void svc_close_list(struct svc_serv *serv, struct list_head *xprt_list, struct net *net)
{
struct svc_xprt *xprt;

spin_lock(&serv->sv_lock);
list_for_each_entry(xprt, xprt_list, xpt_list) {
if (xprt->xpt_net != net)
continue;
set_bit(XPT_CLOSE, &xprt->xpt_flags);
set_bit(XPT_BUSY, &xprt->xpt_flags);
}
spin_unlock(&serv->sv_lock);
}

static void svc_clear_pools(struct svc_serv *serv, struct net *net)
Expand All @@ -949,33 +951,37 @@ static void svc_clear_pools(struct svc_serv *serv, struct net *net)
}
}

static void svc_clear_list(struct list_head *xprt_list, struct net *net)
static void svc_clear_list(struct svc_serv *serv, struct list_head *xprt_list, struct net *net)
{
struct svc_xprt *xprt;
struct svc_xprt *tmp;
LIST_HEAD(victims);

spin_lock(&serv->sv_lock);
list_for_each_entry_safe(xprt, tmp, xprt_list, xpt_list) {
if (xprt->xpt_net != net)
continue;
svc_delete_xprt(xprt);
list_move(&xprt->xpt_list, &victims);
}
list_for_each_entry(xprt, xprt_list, xpt_list)
BUG_ON(xprt->xpt_net == net);
spin_unlock(&serv->sv_lock);

list_for_each_entry_safe(xprt, tmp, &victims, xpt_list)
svc_delete_xprt(xprt);
}

void svc_close_net(struct svc_serv *serv, struct net *net)
{
svc_close_list(&serv->sv_tempsocks, net);
svc_close_list(&serv->sv_permsocks, net);
svc_close_list(serv, &serv->sv_tempsocks, net);
svc_close_list(serv, &serv->sv_permsocks, net);

svc_clear_pools(serv, net);
/*
* At this point the sp_sockets lists will stay empty, since
* svc_xprt_enqueue will not add new entries without taking the
* sp_lock and checking XPT_BUSY.
*/
svc_clear_list(&serv->sv_tempsocks, net);
svc_clear_list(&serv->sv_permsocks, net);
svc_clear_list(serv, &serv->sv_tempsocks, net);
svc_clear_list(serv, &serv->sv_permsocks, net);
}

/*
Expand Down

0 comments on commit 719f8bc

Please sign in to comment.