Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * This file contains all the stubs needed when communicating with lockd.
0004  * This level of indirection is necessary so we can run nfsd+lockd without
0005  * requiring the nfs client to be compiled in/loaded, and vice versa.
0006  *
0007  * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
0008  */
0009 
0010 #include <linux/file.h>
0011 #include <linux/lockd/bind.h>
0012 #include "nfsd.h"
0013 #include "vfs.h"
0014 
0015 #define NFSDDBG_FACILITY        NFSDDBG_LOCKD
0016 
0017 #ifdef CONFIG_LOCKD_V4
0018 #define nlm_stale_fh    nlm4_stale_fh
0019 #define nlm_failed  nlm4_failed
0020 #else
0021 #define nlm_stale_fh    nlm_lck_denied_nolocks
0022 #define nlm_failed  nlm_lck_denied_nolocks
0023 #endif
0024 /*
0025  * Note: we hold the dentry use count while the file is open.
0026  */
0027 static __be32
0028 nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp,
0029         int mode)
0030 {
0031     __be32      nfserr;
0032     int     access;
0033     struct svc_fh   fh;
0034 
0035     /* must initialize before using! but maxsize doesn't matter */
0036     fh_init(&fh,0);
0037     fh.fh_handle.fh_size = f->size;
0038     memcpy(&fh.fh_handle.fh_raw, f->data, f->size);
0039     fh.fh_export = NULL;
0040 
0041     access = (mode == O_WRONLY) ? NFSD_MAY_WRITE : NFSD_MAY_READ;
0042     access |= NFSD_MAY_LOCK;
0043     nfserr = nfsd_open(rqstp, &fh, S_IFREG, access, filp);
0044     fh_put(&fh);
0045     /* We return nlm error codes as nlm doesn't know
0046      * about nfsd, but nfsd does know about nlm..
0047      */
0048     switch (nfserr) {
0049     case nfs_ok:
0050         return 0;
0051     case nfserr_dropit:
0052         return nlm_drop_reply;
0053     case nfserr_stale:
0054         return nlm_stale_fh;
0055     default:
0056         return nlm_failed;
0057     }
0058 }
0059 
0060 static void
0061 nlm_fclose(struct file *filp)
0062 {
0063     fput(filp);
0064 }
0065 
0066 static const struct nlmsvc_binding nfsd_nlm_ops = {
0067     .fopen      = nlm_fopen,        /* open file for locking */
0068     .fclose     = nlm_fclose,       /* close file */
0069 };
0070 
0071 void
0072 nfsd_lockd_init(void)
0073 {
0074     dprintk("nfsd: initializing lockd\n");
0075     nlmsvc_ops = &nfsd_nlm_ops;
0076 }
0077 
0078 void
0079 nfsd_lockd_shutdown(void)
0080 {
0081     nlmsvc_ops = NULL;
0082 }