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 fh_put(&fh);
38 /* nlm and nfsd don't share error codes.
39 * we invent: 0 = no error
40 * 1 = stale file handle
41 * 2 = other error
42 */
43 switch (nfserr) {
44 case nfs_ok:
45 return 0;
46 case nfserr_stale:
47 return 1;
48 default:
49 return 2;
50 }
51 }
52
53 static void
54 nlm_fclose(struct file *filp)
55 {
56 nfsd_close(filp);
57 dput(filp->f_dentry);
58 }
59
60 struct nlmsvc_binding nfsd_nlm_ops = {
61 exp_readlock, /* lock export table for reading */
62 exp_unlock, /* unlock export table */
63 exp_getclient, /* look up NFS client */
64 nlm_fopen, /* open file for locking */
65 nlm_fclose, /* close file */
66 exp_nlmdetach, /* lockd shutdown notification */
67 };
68
69 /*
70 * When removing an NFS client entry, notify lockd that it is gone.
71 * FIXME: We should do the same when unexporting an NFS volume.
72 */
73 void
74 nfsd_lockd_unexport(struct svc_client *clnt)
75 {
76 nlmsvc_invalidate_client(clnt);
77 }
78
79 void
80 nfsd_lockd_init(void)
81 {
82 dprintk("nfsd: initializing lockd\n");
83 nlmsvc_ops = &nfsd_nlm_ops;
84 }
85
86 void
87 nfsd_lockd_shutdown(void)
88 {
89 nlmsvc_ops = NULL;
90 }
91
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.