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/file.h>
  11. #include <linux/nfsd/nfsd.h>
  12. #include <linux/lockd/bind.h>
  13. #include "vfs.h"
  14. #define NFSDDBG_FACILITY NFSDDBG_LOCKD
  15. #ifdef CONFIG_LOCKD_V4
  16. #define nlm_stale_fh nlm4_stale_fh
  17. #define nlm_failed nlm4_failed
  18. #else
  19. #define nlm_stale_fh nlm_lck_denied_nolocks
  20. #define nlm_failed nlm_lck_denied_nolocks
  21. #endif
  22. /*
  23. * Note: we hold the dentry use count while the file is open.
  24. */
  25. static __be32
  26. nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp)
  27. {
  28. __be32 nfserr;
  29. 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;
  35. exp_readlock();
  36. nfserr = nfsd_open(rqstp, &fh, S_IFREG, NFSD_MAY_LOCK, filp);
  37. fh_put(&fh);
  38. rqstp->rq_client = NULL;
  39. exp_readunlock();
  40. /* We return nlm error codes as nlm doesn't know
  41. * about nfsd, but nfsd does know about nlm..
  42. */
  43. switch (nfserr) {
  44. case nfs_ok:
  45. return 0;
  46. case nfserr_dropit:
  47. return nlm_drop_reply;
  48. case nfserr_stale:
  49. return nlm_stale_fh;
  50. default:
  51. return nlm_failed;
  52. }
  53. }
  54. static void
  55. nlm_fclose(struct file *filp)
  56. {
  57. fput(filp);
  58. }
  59. static struct nlmsvc_binding nfsd_nlm_ops = {
  60. .fopen = nlm_fopen, /* open file for locking */
  61. .fclose = nlm_fclose, /* close file */
  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. }