lockd.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 <[email protected]>
  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. int mode)
  27. {
  28. __be32 nfserr;
  29. int access;
  30. struct svc_fh fh;
  31. /* must initialize before using! but maxsize doesn't matter */
  32. fh_init(&fh,0);
  33. fh.fh_handle.fh_size = f->size;
  34. memcpy(&fh.fh_handle.fh_raw, f->data, f->size);
  35. fh.fh_export = NULL;
  36. access = (mode == O_WRONLY) ? NFSD_MAY_WRITE : NFSD_MAY_READ;
  37. access |= NFSD_MAY_LOCK;
  38. nfserr = nfsd_open(rqstp, &fh, S_IFREG, access, filp);
  39. fh_put(&fh);
  40. /* We return nlm error codes as nlm doesn't know
  41. * about nfsd, but nfsd does know about nlm..
  42. */
  43. switch (nfserr) {
  44. case nfs_ok:
  45. return 0;
  46. case nfserr_dropit:
  47. return nlm_drop_reply;
  48. case nfserr_stale:
  49. return nlm_stale_fh;
  50. default:
  51. return nlm_failed;
  52. }
  53. }
  54. static void
  55. nlm_fclose(struct file *filp)
  56. {
  57. fput(filp);
  58. }
  59. static const struct nlmsvc_binding nfsd_nlm_ops = {
  60. .fopen = nlm_fopen, /* open file for locking */
  61. .fclose = nlm_fclose, /* close file */
  62. };
  63. void
  64. nfsd_lockd_init(void)
  65. {
  66. dprintk("nfsd: initializing lockd\n");
  67. nlmsvc_ops = &nfsd_nlm_ops;
  68. }
  69. void
  70. nfsd_lockd_shutdown(void)
  71. {
  72. nlmsvc_ops = NULL;
  73. }