lockd.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. #include <linux/types.h>
  11. #include <linux/fs.h>
  12. #include <linux/file.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>
  18. #define NFSDDBG_FACILITY NFSDDBG_LOCKD
  19. /*
  20. * Note: we hold the dentry use count while the file is open.
  21. */
  22. static __be32
  23. nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp)
  24. {
  25. __be32 nfserr;
  26. struct svc_fh fh;
  27. /* must initialize before using! but maxsize doesn't matter */
  28. fh_init(&fh,0);
  29. fh.fh_handle.fh_size = f->size;
  30. memcpy((char*)&fh.fh_handle.fh_base, f->data, f->size);
  31. fh.fh_export = NULL;
  32. exp_readlock();
  33. nfserr = nfsd_open(rqstp, &fh, S_IFREG, MAY_LOCK, filp);
  34. fh_put(&fh);
  35. rqstp->rq_client = NULL;
  36. exp_readunlock();
  37. /* We return nlm error codes as nlm doesn't know
  38. * about nfsd, but nfsd does know about nlm..
  39. */
  40. switch (nfserr) {
  41. case nfs_ok:
  42. return 0;
  43. case nfserr_dropit:
  44. return nlm_drop_reply;
  45. #ifdef CONFIG_LOCKD_V4
  46. case nfserr_stale:
  47. return nlm4_stale_fh;
  48. #endif
  49. default:
  50. return nlm_lck_denied;
  51. }
  52. }
  53. static void
  54. nlm_fclose(struct file *filp)
  55. {
  56. fput(filp);
  57. }
  58. static struct nlmsvc_binding nfsd_nlm_ops = {
  59. .fopen = nlm_fopen, /* open file for locking */
  60. .fclose = nlm_fclose, /* close file */
  61. .get_grace_period = get_nfs4_grace_period,
  62. };
  63. void
  64. nfsd_lockd_init(void)
  65. {
  66. dprintk("nfsd: initializing lockd\n");
  67. nlmsvc_ops = &nfsd_nlm_ops;
  68. }
  69. void
  70. nfsd_lockd_shutdown(void)
  71. {
  72. nlmsvc_ops = NULL;
  73. }