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. 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. case nfserr_stale:
  46. return nlm_stale_fh;
  47. default:
  48. return nlm_failed;
  49. }
  50. }
  51. static void
  52. nlm_fclose(struct file *filp)
  53. {
  54. fput(filp);
  55. }
  56. static struct nlmsvc_binding nfsd_nlm_ops = {
  57. .fopen = nlm_fopen, /* open file for locking */
  58. .fclose = nlm_fclose, /* close file */
  59. };
  60. void
  61. nfsd_lockd_init(void)
  62. {
  63. dprintk("nfsd: initializing lockd\n");
  64. nlmsvc_ops = &nfsd_nlm_ops;
  65. }
  66. void
  67. nfsd_lockd_shutdown(void)
  68. {
  69. nlmsvc_ops = NULL;
  70. }