Skip to content

Commit 24e3666

Browse files
neilbrownLinus Torvalds
authored andcommitted
[PATCH] knfsd: be more selective in which sockets lockd listens on
Currently lockd listens on UDP always, and TCP if CONFIG_NFSD_TCP is set. However as lockd performs services of the client as well, this is a problem. If CONFIG_NfSD_TCP is not set, and a tcp mount is used, the server will not be able to call back to lockd. So: - add an option to lockd_up saying which protocol is needed - Always open sockets for which an explicit port was given, otherwise only open a socket of the type required - Change nfsd to do one lockd_up per socket rather than one per thread. This - removes the dependancy on CONFIG_NFSD_TCP - means that lockd may open sockets other than at startup - means that lockd will *not* listen on UDP if the only mounts are TCP mount (and nfsd hasn't started). The latter is the only one that concerns me at all - I don't know if this might be a problem with some servers. Signed-off-by: Neil Brown <neilb@suse.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent bc591cc commit 24e3666

5 files changed

Lines changed: 54 additions & 16 deletions

File tree

‎fs/lockd/clntlock.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ reclaimer(void *ptr)
202202
/* This one ensures that our parent doesn't terminate while the
203203
* reclaim is in progress */
204204
lock_kernel();
205-
lockd_up();
205+
lockd_up(0);
206206

207207
nlmclnt_prepare_reclaim(host);
208208
/* First, reclaim all locks that have been marked. */

‎fs/lockd/svc.c‎

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <linux/sunrpc/clnt.h>
3232
#include <linux/sunrpc/svc.h>
3333
#include <linux/sunrpc/svcsock.h>
34+
#include <net/ip.h>
3435
#include <linux/lockd/lockd.h>
3536
#include <linux/nfs.h>
3637

@@ -46,6 +47,7 @@ EXPORT_SYMBOL(nlmsvc_ops);
4647
static DEFINE_MUTEX(nlmsvc_mutex);
4748
static unsigned int nlmsvc_users;
4849
static pid_t nlmsvc_pid;
50+
static struct svc_serv *nlmsvc_serv;
4951
int nlmsvc_grace_period;
5052
unsigned long nlmsvc_timeout;
5153

@@ -112,6 +114,7 @@ lockd(struct svc_rqst *rqstp)
112114
* Let our maker know we're running.
113115
*/
114116
nlmsvc_pid = current->pid;
117+
nlmsvc_serv = serv;
115118
complete(&lockd_start_done);
116119

117120
daemonize("lockd");
@@ -189,6 +192,7 @@ lockd(struct svc_rqst *rqstp)
189192
nlmsvc_invalidate_all();
190193
nlm_shutdown_hosts();
191194
nlmsvc_pid = 0;
195+
nlmsvc_serv = NULL;
192196
} else
193197
printk(KERN_DEBUG
194198
"lockd: new process, skipping host shutdown\n");
@@ -205,11 +209,42 @@ lockd(struct svc_rqst *rqstp)
205209
module_put_and_exit(0);
206210
}
207211

212+
213+
static int find_socket(struct svc_serv *serv, int proto)
214+
{
215+
struct svc_sock *svsk;
216+
int found = 0;
217+
list_for_each_entry(svsk, &serv->sv_permsocks, sk_list)
218+
if (svsk->sk_sk->sk_protocol == proto) {
219+
found = 1;
220+
break;
221+
}
222+
return found;
223+
}
224+
225+
static int make_socks(struct svc_serv *serv, int proto)
226+
{
227+
/* Make any sockets that are needed but not present.
228+
* If nlm_udpport or nlm_tcpport were set as module
229+
* options, make those sockets unconditionally
230+
*/
231+
int err = 0;
232+
if (proto == IPPROTO_UDP || nlm_udpport)
233+
if (!find_socket(serv, IPPROTO_UDP))
234+
err = svc_makesock(serv, IPPROTO_UDP, nlm_udpport);
235+
if (err)
236+
return err;
237+
if (proto == IPPROTO_TCP || nlm_tcpport)
238+
if (!find_socket(serv, IPPROTO_TCP))
239+
err= svc_makesock(serv, IPPROTO_TCP, nlm_tcpport);
240+
return err;
241+
}
242+
208243
/*
209244
* Bring up the lockd process if it's not already up.
210245
*/
211246
int
212-
lockd_up(void)
247+
lockd_up(int proto) /* Maybe add a 'family' option when IPv6 is supported ?? */
213248
{
214249
static int warned;
215250
struct svc_serv * serv;
@@ -224,8 +259,10 @@ lockd_up(void)
224259
/*
225260
* Check whether we're already up and running.
226261
*/
227-
if (nlmsvc_pid)
262+
if (nlmsvc_pid) {
263+
error = make_socks(nlmsvc_serv, proto);
228264
goto out;
265+
}
229266

230267
/*
231268
* Sanity check: if there's no pid,
@@ -242,11 +279,7 @@ lockd_up(void)
242279
goto out;
243280
}
244281

245-
if ((error = svc_makesock(serv, IPPROTO_UDP, nlm_udpport)) < 0
246-
#ifdef CONFIG_NFSD_TCP
247-
|| (error = svc_makesock(serv, IPPROTO_TCP, nlm_tcpport)) < 0
248-
#endif
249-
) {
282+
if ((error = make_socks(serv, proto)) < 0) {
250283
if (warned++ == 0)
251284
printk(KERN_WARNING
252285
"lockd_up: makesock failed, error=%d\n", error);

‎fs/nfs/client.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,8 @@ static int nfs_start_lockd(struct nfs_server *server)
460460
goto out;
461461
if (server->flags & NFS_MOUNT_NONLM)
462462
goto out;
463-
error = lockd_up();
463+
error = lockd_up((server->flags & NFS_MOUNT_TCP) ?
464+
IPPROTO_TCP : IPPROTO_UDP);
464465
if (error < 0)
465466
server->flags |= NFS_MOUNT_NONLM;
466467
else

‎fs/nfsd/nfssvc.c‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ static int killsig; /* signal that was used to kill last nfsd */
134134
static void nfsd_last_thread(struct svc_serv *serv)
135135
{
136136
/* When last nfsd thread exits we need to do some clean-up */
137+
struct svc_sock *svsk;
138+
list_for_each_entry(svsk, &serv->sv_permsocks, sk_list)
139+
lockd_down();
137140
nfsd_serv = NULL;
138141
nfsd_racache_shutdown();
139142
nfs4_state_shutdown();
@@ -218,11 +221,16 @@ nfsd_svc(unsigned short port, int nrservs)
218221
error = svc_makesock(nfsd_serv, IPPROTO_UDP, port);
219222
if (error < 0)
220223
goto failure;
221-
224+
error = lockd_up(IPPROTO_UDP);
225+
if (error < 0)
226+
goto failure;
222227
#ifdef CONFIG_NFSD_TCP
223228
error = svc_makesock(nfsd_serv, IPPROTO_TCP, port);
224229
if (error < 0)
225230
goto failure;
231+
error = lockd_up(IPPROTO_TCP);
232+
if (error < 0)
233+
goto failure;
226234
#endif
227235
do_gettimeofday(&nfssvc_boot); /* record boot time */
228236
} else
@@ -306,8 +314,6 @@ nfsd(struct svc_rqst *rqstp)
306314

307315
nfsdstats.th_cnt++;
308316

309-
lockd_up(); /* start lockd */
310-
311317
me.task = current;
312318
list_add(&me.list, &nfsd_list);
313319

@@ -364,13 +370,11 @@ nfsd(struct svc_rqst *rqstp)
364370
break;
365371
killsig = signo;
366372
}
367-
/* Clear signals before calling lockd_down() and svc_exit_thread() */
373+
/* Clear signals before calling svc_exit_thread() */
368374
flush_signals(current);
369375

370376
lock_kernel();
371377

372-
/* Release lockd */
373-
lockd_down();
374378
list_del(&me.list);
375379
nfsdstats.th_cnt --;
376380

‎include/linux/lockd/bind.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extern struct nlmsvc_binding * nlmsvc_ops;
3030
* Functions exported by the lockd module
3131
*/
3232
extern int nlmclnt_proc(struct inode *, int, struct file_lock *);
33-
extern int lockd_up(void);
33+
extern int lockd_up(int proto);
3434
extern void lockd_down(void);
3535

3636
#endif /* LINUX_LOCKD_BIND_H */

0 commit comments

Comments
 (0)