lockd.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 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. }