lockd.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. /*
  20. * Note: we hold the dentry use count while the file is open.
  21. */
  22. static __be32
  23. nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp)
  24. {
  25. __be32 nfserr;
  26. struct svc_fh fh;
  27. /* must initialize before using! but maxsize doesn't matter */
  28. fh_init(&fh,0);
  29. fh.fh_handle.fh_size = f->size;
  30. memcpy((char*)&fh.fh_handle.fh_base, f->data, f->size);
  31. fh.fh_export = NULL;
  32. exp_readlock();
  33. nfserr = nfsd_open(rqstp, &fh, S_IFREG, MAY_LOCK, filp);
  34. fh_put(&fh);
  35. rqstp->rq_client = NULL;
  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. #ifdef CONFIG_LOCKD_V4
  46. case nfserr_stale:
  47. return nlm4_stale_fh;
  48. #endif
  49. default:
  50. return nlm_lck_denied;
  51. }
  52. }
  53. static void
  54. nlm_fclose(struct file *filp)
  55. {
  56. fput(filp);
  57. }
  58. static struct nlmsvc_binding nfsd_nlm_ops = {
  59. .fopen = nlm_fopen, /* open file for locking */
  60. .fclose = nlm_fclose, /* close file */
  61. };
  62. void
  63. nfsd_lockd_init(void)
  64. {
  65. dprintk("nfsd: initializing lockd\n");
  66. nlmsvc_ops = &nfsd_nlm_ops;
  67. }
  68. void
  69. nfsd_lockd_shutdown(void)
  70. {
  71. nlmsvc_ops = NULL;
  72. }