lockd.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. 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. /*
  37. * Allow BYPASS_GSS as some client implementations use AUTH_SYS
  38. * for NLM even when GSS is used for NFS.
  39. * Allow OWNER_OVERRIDE as permission might have been changed
  40. * after the file was opened.
  41. * Pass MAY_NLM so that authentication can be completely bypassed
  42. * if NFSEXP_NOAUTHNLM is set. Some older clients use AUTH_NULL
  43. * for NLM requests.
  44. */
  45. access = (mode == O_WRONLY) ? NFSD_MAY_WRITE : NFSD_MAY_READ;
  46. access |= NFSD_MAY_NLM | NFSD_MAY_OWNER_OVERRIDE | NFSD_MAY_BYPASS_GSS;
  47. nfserr = nfsd_open(rqstp, &fh, S_IFREG, access, filp);
  48. fh_put(&fh);
  49. /* We return nlm error codes as nlm doesn't know
  50. * about nfsd, but nfsd does know about nlm..
  51. */
  52. switch (nfserr) {
  53. case nfs_ok:
  54. return 0;
  55. case nfserr_jukebox:
  56. /* this error can indicate a presence of a conflicting
  57. * delegation to an NLM lock request. Options are:
  58. * (1) For now, drop this request and make the client
  59. * retry. When delegation is returned, client's lock retry
  60. * will complete.
  61. * (2) NLM4_DENIED as per "spec" signals to the client
  62. * that the lock is unavailable now but client can retry.
  63. * Linux client implementation does not. It treats
  64. * NLM4_DENIED same as NLM4_FAILED and errors the request.
  65. * (3) For the future, treat this as blocked lock and try
  66. * to callback when the delegation is returned but might
  67. * not have a proper lock request to block on.
  68. */
  69. return nlm_drop_reply;
  70. case nfserr_stale:
  71. return nlm_stale_fh;
  72. default:
  73. return nlm_failed;
  74. }
  75. }
  76. static void
  77. nlm_fclose(struct file *filp)
  78. {
  79. fput(filp);
  80. }
  81. static const struct nlmsvc_binding nfsd_nlm_ops = {
  82. .fopen = nlm_fopen, /* open file for locking */
  83. .fclose = nlm_fclose, /* close file */
  84. };
  85. void
  86. nfsd_lockd_init(void)
  87. {
  88. dprintk("nfsd: initializing lockd\n");
  89. nlmsvc_ops = &nfsd_nlm_ops;
  90. }
  91. void
  92. nfsd_lockd_shutdown(void)
  93. {
  94. nlmsvc_ops = NULL;
  95. }