]>
Commit | Line | Data |
---|---|---|
a1cd50fd GKH |
1 | From stable-bounces@linux.kernel.org Mon Mar 5 22:14:11 2007 |
2 | From: NeilBrown <neilb@suse.de> | |
3 | Date: Tue, 6 Mar 2007 17:11:33 +1100 | |
4 | Subject: Fix recently introduced problem with shutting down a busy NFS server. | |
5 | To: stable@kernel.org | |
6 | Message-ID: <1070306061133.10640@suse.de> | |
7 | ||
8 | From: NeilBrown <neilb@suse.de> | |
9 | ||
10 | ||
11 | When the last thread of nfsd exits, it shuts down all related sockets. | |
12 | It currently uses svc_close_socket to do this, but that only is | |
13 | immediately effective if the socket is not SK_BUSY. | |
14 | ||
15 | If the socket is busy - i.e. if a request has arrived that has not yet | |
16 | been processes - svc_close_socket is not effective and the shutdown | |
17 | process spins. | |
18 | ||
19 | So create a new svc_force_close_socket which removes the SK_BUSY flag | |
20 | is set and then calls svc_close_socket. | |
21 | ||
22 | Also change some open-codes loops in svc_destroy to use | |
23 | list_for_each_entry_safe. | |
24 | ||
25 | Signed-off-by: Neil Brown <neilb@suse.de> | |
26 | Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> | |
27 | ||
28 | ||
29 | --- | |
30 | include/linux/sunrpc/svcsock.h | 2 +- | |
31 | net/sunrpc/svc.c | 23 ++++++++++------------- | |
32 | net/sunrpc/svcsock.c | 16 +++++++++++++++- | |
33 | 3 files changed, 26 insertions(+), 15 deletions(-) | |
34 | ||
35 | --- linux-2.6.20.1.orig/include/linux/sunrpc/svcsock.h | |
36 | +++ linux-2.6.20.1/include/linux/sunrpc/svcsock.h | |
37 | @@ -63,7 +63,7 @@ struct svc_sock { | |
38 | * Function prototypes. | |
39 | */ | |
40 | int svc_makesock(struct svc_serv *, int, unsigned short); | |
41 | -void svc_close_socket(struct svc_sock *); | |
42 | +void svc_force_close_socket(struct svc_sock *); | |
43 | int svc_recv(struct svc_rqst *, long); | |
44 | int svc_send(struct svc_rqst *); | |
45 | void svc_drop(struct svc_rqst *); | |
46 | --- linux-2.6.20.1.orig/net/sunrpc/svc.c | |
47 | +++ linux-2.6.20.1/net/sunrpc/svc.c | |
48 | @@ -371,6 +371,7 @@ void | |
49 | svc_destroy(struct svc_serv *serv) | |
50 | { | |
51 | struct svc_sock *svsk; | |
52 | + struct svc_sock *tmp; | |
53 | ||
54 | dprintk("RPC: svc_destroy(%s, %d)\n", | |
55 | serv->sv_program->pg_name, | |
56 | @@ -386,22 +387,18 @@ svc_destroy(struct svc_serv *serv) | |
57 | ||
58 | del_timer_sync(&serv->sv_temptimer); | |
59 | ||
60 | - while (!list_empty(&serv->sv_tempsocks)) { | |
61 | - svsk = list_entry(serv->sv_tempsocks.next, | |
62 | - struct svc_sock, | |
63 | - sk_list); | |
64 | - svc_close_socket(svsk); | |
65 | - } | |
66 | + list_for_each_entry_safe(svsk, tmp, &serv->sv_tempsocks, sk_list) | |
67 | + svc_force_close_socket(svsk); | |
68 | + | |
69 | if (serv->sv_shutdown) | |
70 | serv->sv_shutdown(serv); | |
71 | ||
72 | - while (!list_empty(&serv->sv_permsocks)) { | |
73 | - svsk = list_entry(serv->sv_permsocks.next, | |
74 | - struct svc_sock, | |
75 | - sk_list); | |
76 | - svc_close_socket(svsk); | |
77 | - } | |
78 | - | |
79 | + list_for_each_entry_safe(svsk, tmp, &serv->sv_permsocks, sk_list) | |
80 | + svc_force_close_socket(svsk); | |
81 | + | |
82 | + BUG_ON(!list_empty(&serv->sv_permsocks)); | |
83 | + BUG_ON(!list_empty(&serv->sv_tempsocks)); | |
84 | + | |
85 | cache_clean_deferred(serv); | |
86 | ||
87 | /* Unregister service with the portmapper */ | |
88 | --- linux-2.6.20.1.orig/net/sunrpc/svcsock.c | |
89 | +++ linux-2.6.20.1/net/sunrpc/svcsock.c | |
90 | @@ -80,6 +80,7 @@ static void svc_delete_socket(struct sv | |
91 | static void svc_udp_data_ready(struct sock *, int); | |
92 | static int svc_udp_recvfrom(struct svc_rqst *); | |
93 | static int svc_udp_sendto(struct svc_rqst *); | |
94 | +static void svc_close_socket(struct svc_sock *svsk); | |
95 | ||
96 | static struct svc_deferred_req *svc_deferred_dequeue(struct svc_sock *svsk); | |
97 | static int svc_deferred_recv(struct svc_rqst *rqstp); | |
98 | @@ -1668,7 +1669,7 @@ svc_delete_socket(struct svc_sock *svsk) | |
99 | spin_unlock_bh(&serv->sv_lock); | |
100 | } | |
101 | ||
102 | -void svc_close_socket(struct svc_sock *svsk) | |
103 | +static void svc_close_socket(struct svc_sock *svsk) | |
104 | { | |
105 | set_bit(SK_CLOSE, &svsk->sk_flags); | |
106 | if (test_and_set_bit(SK_BUSY, &svsk->sk_flags)) | |
107 | @@ -1681,6 +1682,19 @@ void svc_close_socket(struct svc_sock *s | |
108 | svc_sock_put(svsk); | |
109 | } | |
110 | ||
111 | +void svc_force_close_socket(struct svc_sock *svsk) | |
112 | +{ | |
113 | + set_bit(SK_CLOSE, &svsk->sk_flags); | |
114 | + if (test_bit(SK_BUSY, &svsk->sk_flags)) { | |
115 | + /* Waiting to be processed, but no threads left, | |
116 | + * So just remove it from the waiting list | |
117 | + */ | |
118 | + list_del_init(&svsk->sk_ready); | |
119 | + clear_bit(SK_BUSY, &svsk->sk_flags); | |
120 | + } | |
121 | + svc_close_socket(svsk); | |
122 | +} | |
123 | + | |
124 | /* | |
125 | * Make a socket for nfsd and lockd | |
126 | */ |