Merge with Linux 2.5.48.
[linux-2.6/linux-mips.git] / fs / nfsd / lockd.c
blob479835b164dee86f5567f78c923d6838c49080f0
1 /*
2 * linux/fs/nfsd/lockd.c
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.
8 * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
9 */
11 #include <linux/types.h>
12 #include <linux/fs.h>
13 #include <linux/mount.h>
14 #include <linux/sunrpc/clnt.h>
15 #include <linux/sunrpc/svc.h>
16 #include <linux/nfsd/nfsd.h>
17 #include <linux/lockd/bind.h>
19 #define NFSDDBG_FACILITY NFSDDBG_LOCKD
22 * Note: we hold the dentry use count while the file is open.
24 static u32
25 nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file *filp)
27 u32 nfserr;
28 struct svc_fh fh;
30 /* must initialize before using! but maxsize doesn't matter */
31 fh_init(&fh,0);
32 fh.fh_handle.fh_size = f->size;
33 memcpy((char*)&fh.fh_handle.fh_base, f->data, f->size);
34 fh.fh_export = NULL;
36 exp_readlock();
37 nfserr = nfsd_open(rqstp, &fh, S_IFREG, MAY_LOCK, filp);
38 if (!nfserr) {
39 dget(filp->f_dentry);
40 mntget(filp->f_vfsmnt);
42 fh_put(&fh);
43 rqstp->rq_client = NULL;
44 exp_readunlock();
45 /* nlm and nfsd don't share error codes.
46 * we invent: 0 = no error
47 * 1 = stale file handle
48 * 2 = other error
50 switch (nfserr) {
51 case nfs_ok:
52 return 0;
53 case nfserr_stale:
54 return 1;
55 default:
56 return 2;
60 static void
61 nlm_fclose(struct file *filp)
63 nfsd_close(filp);
64 dput(filp->f_dentry);
65 mntput(filp->f_vfsmnt);
68 struct nlmsvc_binding nfsd_nlm_ops = {
69 .fopen = nlm_fopen, /* open file for locking */
70 .fclose = nlm_fclose, /* close file */
73 void
74 nfsd_lockd_init(void)
76 dprintk("nfsd: initializing lockd\n");
77 nlmsvc_ops = &nfsd_nlm_ops;
80 void
81 nfsd_lockd_shutdown(void)
83 nlmsvc_ops = NULL;