lockd.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. nfserr = nfsd_open(rqstp, &fh, S_IFREG, NFSD_MAY_LOCK, filp);
  34. fh_put(&fh);
  35. /* We return nlm error codes as nlm doesn't know
  36. * about nfsd, but nfsd does know about nlm..
  37. */
  38. switch (nfserr) {
  39. case nfs_ok:
  40. return 0;
  41. case nfserr_dropit:
  42. return nlm_drop_reply;
  43. case nfserr_stale:
  44. return nlm_stale_fh;
  45. default:
  46. return nlm_failed;
  47. }
  48. }
  49. static void
  50. nlm_fclose(struct file *filp)
  51. {
  52. fput(filp);
  53. }
  54. static const struct nlmsvc_binding nfsd_nlm_ops = {
  55. .fopen = nlm_fopen, /* open file for locking */
  56. .fclose = nlm_fclose, /* close file */
  57. };
  58. void
  59. nfsd_lockd_init(void)
  60. {
  61. dprintk("nfsd: initializing lockd\n");
  62. nlmsvc_ops = &nfsd_nlm_ops;
  63. }
  64. void
  65. nfsd_lockd_shutdown(void)
  66. {
  67. nlmsvc_ops = NULL;
  68. }