lockd.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * This file contains all the stubs needed when communicating with lockd.
  3. * This level of indirection is necessary so we can run nfsd+lockd without
  4. * requiring the nfs client to be compiled in/loaded, and vice versa.
  5. *
  6. * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
  7. */
  8. #include <linux/file.h>
  9. #include <linux/lockd/bind.h>
  10. #include "nfsd.h"
  11. #include "vfs.h"
  12. #define NFSDDBG_FACILITY NFSDDBG_LOCKD
  13. #ifdef CONFIG_LOCKD_V4
  14. #define nlm_stale_fh nlm4_stale_fh
  15. #define nlm_failed nlm4_failed
  16. #else
  17. #define nlm_stale_fh nlm_lck_denied_nolocks
  18. #define nlm_failed nlm_lck_denied_nolocks
  19. #endif
  20. /*
  21. * Note: we hold the dentry use count while the file is open.
  22. */
  23. static __be32
  24. nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp)
  25. {
  26. __be32 nfserr;
  27. struct svc_fh fh;
  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. exp_readlock();
  34. nfserr = nfsd_open(rqstp, &fh, S_IFREG, NFSD_MAY_LOCK, filp);
  35. fh_put(&fh);
  36. rqstp->rq_client = NULL;
  37. exp_readunlock();
  38. /* We return nlm error codes as nlm doesn't know
  39. * about nfsd, but nfsd does know about nlm..
  40. */
  41. switch (nfserr) {
  42. case nfs_ok:
  43. return 0;
  44. case nfserr_dropit:
  45. return nlm_drop_reply;
  46. case nfserr_stale:
  47. return nlm_stale_fh;
  48. default:
  49. return nlm_failed;
  50. }
  51. }
  52. static void
  53. nlm_fclose(struct file *filp)
  54. {
  55. fput(filp);
  56. }
  57. static struct nlmsvc_binding nfsd_nlm_ops = {
  58. .fopen = nlm_fopen, /* open file for locking */
  59. .fclose = nlm_fclose, /* close file */
  60. };
  61. void
  62. nfsd_lockd_init(void)
  63. {
  64. dprintk("nfsd: initializing lockd\n");
  65. nlmsvc_ops = &nfsd_nlm_ops;
  66. }
  67. void
  68. nfsd_lockd_shutdown(void)
  69. {
  70. nlmsvc_ops = NULL;
  71. }