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