lockd.c 1.9 KB

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