File: /usr/src/linux/fs/nfsd/lockd.c

1     /*
2      * linux/fs/nfsd/lockd.c
3      *
4      * This file contains all the stubs needed when communicating with lockd.
5      * This level of indirection is necessary so we can run nfsd+lockd without
6      * requiring the nfs client to be compiled in/loaded, and vice versa.
7      *
8      * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
9      */
10     
11     #include <linux/types.h>
12     #include <linux/sunrpc/clnt.h>
13     #include <linux/sunrpc/svc.h>
14     #include <linux/nfsd/nfsd.h>
15     #include <linux/lockd/bind.h>
16     
17     #define NFSDDBG_FACILITY		NFSDDBG_LOCKD
18     
19     /*
20      * Note: we hold the dentry use count while the file is open.
21      */
22     static u32
23     nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file *filp)
24     {
25     	u32		nfserr;
26     	struct svc_fh	fh;
27     
28     	/* must initialize before using! but maxsize doesn't matter */
29     	fh_init(&fh,0);
30     	fh.fh_handle.fh_size = f->size;
31     	memcpy((char*)&fh.fh_handle.fh_base, f->data, f->size);
32     	fh.fh_export = NULL;
33     
34     	nfserr = nfsd_open(rqstp, &fh, S_IFREG, MAY_LOCK, filp);
35     	if (!nfserr) {
36     		dget(filp->f_dentry);
37     		mntget(filp->f_vfsmnt);
38     	}
39     	fh_put(&fh);
40      	/* nlm and nfsd don't share error codes.
41     	 * we invent: 0 = no error
42     	 *            1 = stale file handle
43     	 *	      2 = other error
44     	 */
45     	switch (nfserr) {
46     	case nfs_ok:
47     		return 0;
48     	case nfserr_stale:
49     		return 1;
50     	default:
51     		return 2;
52     	}
53     }
54     
55     static void
56     nlm_fclose(struct file *filp)
57     {
58     	nfsd_close(filp);
59     	dput(filp->f_dentry);
60     	mntput(filp->f_vfsmnt);
61     }
62     
63     struct nlmsvc_binding		nfsd_nlm_ops = {
64     	exp_readlock,		/* lock export table for reading */
65     	exp_unlock,		/* unlock export table */
66     	exp_getclient,		/* look up NFS client */
67     	nlm_fopen,		/* open file for locking */
68     	nlm_fclose,		/* close file */
69     	exp_nlmdetach,		/* lockd shutdown notification */
70     };
71     
72     /*
73      * When removing an NFS client entry, notify lockd that it is gone.
74      * FIXME: We should do the same when unexporting an NFS volume.
75      */
76     void
77     nfsd_lockd_unexport(struct svc_client *clnt)
78     {
79     	nlmsvc_invalidate_client(clnt);
80     }
81     
82     void
83     nfsd_lockd_init(void)
84     {
85     	dprintk("nfsd: initializing lockd\n");
86     	nlmsvc_ops = &nfsd_nlm_ops;
87     }
88     
89     void
90     nfsd_lockd_shutdown(void)
91     {
92     	nlmsvc_ops = NULL;
93     }
94