mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-27 04:54:41 +08:00
d8b26071e6
Most of the fields in 'struct knfsd_fh' are 2 levels deep (a union and a struct) and are accessed using macros like: #define fh_FOO fh_base.fh_new.fb_FOO This patch makes the union and struct anonymous, so that "fh_FOO" can be a name directly within 'struct knfsd_fh' and the #defines aren't needed. The file handle as a whole is sometimes accessed as "fh_base" or "fh_base.fh_pad", neither of which are particularly helpful names. As the struct holding the filehandle is now anonymous, we cannot use the name of that, so we union it with 'fh_raw' and use that where the raw filehandle is needed. fh_raw also ensure the structure is large enough for the largest possible filehandle. fh_raw is a 'char' array, removing any need to cast it for memcpy etc. SVCFH_fmt() is simplified using the "%ph" printk format. This changes the appearance of filehandles in dprintk() debugging, making them a little more precise. Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
83 lines
1.8 KiB
C
83 lines
1.8 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* This file contains all the stubs needed when communicating with lockd.
|
|
* This level of indirection is necessary so we can run nfsd+lockd without
|
|
* requiring the nfs client to be compiled in/loaded, and vice versa.
|
|
*
|
|
* Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
|
|
*/
|
|
|
|
#include <linux/file.h>
|
|
#include <linux/lockd/bind.h>
|
|
#include "nfsd.h"
|
|
#include "vfs.h"
|
|
|
|
#define NFSDDBG_FACILITY NFSDDBG_LOCKD
|
|
|
|
#ifdef CONFIG_LOCKD_V4
|
|
#define nlm_stale_fh nlm4_stale_fh
|
|
#define nlm_failed nlm4_failed
|
|
#else
|
|
#define nlm_stale_fh nlm_lck_denied_nolocks
|
|
#define nlm_failed nlm_lck_denied_nolocks
|
|
#endif
|
|
/*
|
|
* Note: we hold the dentry use count while the file is open.
|
|
*/
|
|
static __be32
|
|
nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp,
|
|
int mode)
|
|
{
|
|
__be32 nfserr;
|
|
int access;
|
|
struct svc_fh fh;
|
|
|
|
/* must initialize before using! but maxsize doesn't matter */
|
|
fh_init(&fh,0);
|
|
fh.fh_handle.fh_size = f->size;
|
|
memcpy(&fh.fh_handle.fh_raw, f->data, f->size);
|
|
fh.fh_export = NULL;
|
|
|
|
access = (mode == O_WRONLY) ? NFSD_MAY_WRITE : NFSD_MAY_READ;
|
|
access |= NFSD_MAY_LOCK;
|
|
nfserr = nfsd_open(rqstp, &fh, S_IFREG, access, filp);
|
|
fh_put(&fh);
|
|
/* We return nlm error codes as nlm doesn't know
|
|
* about nfsd, but nfsd does know about nlm..
|
|
*/
|
|
switch (nfserr) {
|
|
case nfs_ok:
|
|
return 0;
|
|
case nfserr_dropit:
|
|
return nlm_drop_reply;
|
|
case nfserr_stale:
|
|
return nlm_stale_fh;
|
|
default:
|
|
return nlm_failed;
|
|
}
|
|
}
|
|
|
|
static void
|
|
nlm_fclose(struct file *filp)
|
|
{
|
|
fput(filp);
|
|
}
|
|
|
|
static const struct nlmsvc_binding nfsd_nlm_ops = {
|
|
.fopen = nlm_fopen, /* open file for locking */
|
|
.fclose = nlm_fclose, /* close file */
|
|
};
|
|
|
|
void
|
|
nfsd_lockd_init(void)
|
|
{
|
|
dprintk("nfsd: initializing lockd\n");
|
|
nlmsvc_ops = &nfsd_nlm_ops;
|
|
}
|
|
|
|
void
|
|
nfsd_lockd_shutdown(void)
|
|
{
|
|
nlmsvc_ops = NULL;
|
|
}
|