lockd.c 1.7 KB

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