1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1989, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Rick Macklem at The University of Guelph.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1998-05-31 17:27:58 +00:00
|
|
|
* @(#)nfs_subs.c 8.8 (Berkeley) 5/22/95
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
|
2001-09-18 23:32:09 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* These functions support the macros and help fiddle mbuf chains for
|
|
|
|
* the nfs op functions. They do things like create the rpc header and
|
|
|
|
* copy data between mbuf chains and uio lists.
|
|
|
|
*/
|
2001-09-18 23:32:09 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
2000-05-05 09:59:14 +00:00
|
|
|
#include <sys/bio.h>
|
1999-06-27 11:44:22 +00:00
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/proc.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/stat.h>
|
1995-06-27 11:07:30 +00:00
|
|
|
#include <sys/malloc.h>
|
1994-09-22 22:10:49 +00:00
|
|
|
#include <sys/sysent.h>
|
|
|
|
#include <sys/syscall.h>
|
2001-09-18 23:32:09 +00:00
|
|
|
#include <sys/sysproto.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
1994-10-02 17:27:07 +00:00
|
|
|
#include <vm/vm.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <vm/vm_object.h>
|
|
|
|
#include <vm/vm_extern.h>
|
1997-12-27 02:56:39 +00:00
|
|
|
#include <vm/vm_zone.h>
|
1994-10-02 17:27:07 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <nfs/rpcv2.h>
|
1995-06-27 11:07:30 +00:00
|
|
|
#include <nfs/nfsproto.h>
|
2001-09-18 23:32:09 +00:00
|
|
|
#include <nfsserver/nfs.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <nfs/xdr_subs.h>
|
2001-09-18 23:32:09 +00:00
|
|
|
#include <nfsserver/nfsm_subs.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Data items converted to xdr at startup, since they are constant
|
|
|
|
* This is kinda hokey, but may save a little time doing byte swaps
|
|
|
|
*/
|
1998-05-31 20:09:01 +00:00
|
|
|
u_int32_t nfs_xdrneg1;
|
|
|
|
u_int32_t rpc_call, rpc_vers, rpc_reply, rpc_msgdenied, rpc_autherr,
|
2001-09-18 23:32:09 +00:00
|
|
|
rpc_mismatch, rpc_auth_unix, rpc_msgaccepted;
|
|
|
|
u_int32_t nfs_prog, nfs_true, nfs_false;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
/* And other global data */
|
2001-09-18 23:32:09 +00:00
|
|
|
static nfstype nfsv2_type[9] = { NFNON, NFREG, NFDIR, NFBLK, NFCHR, NFLNK,
|
|
|
|
NFNON, NFCHR, NFNON };
|
|
|
|
#define vtonfsv2_type(a) txdr_unsigned(nfsv2_type[((int32_t)(a))])
|
|
|
|
#define vtonfsv3_mode(m) txdr_unsigned((m) & ALLPERMS)
|
1995-12-17 21:14:36 +00:00
|
|
|
|
1995-06-27 11:07:30 +00:00
|
|
|
int nfs_ticks;
|
|
|
|
|
1995-07-29 11:44:31 +00:00
|
|
|
struct nfssvc_sockhead nfssvc_sockhead;
|
|
|
|
int nfssvc_sockhead_flag;
|
|
|
|
struct nfsd_head nfsd_head;
|
|
|
|
int nfsd_head_flag;
|
|
|
|
|
1998-09-07 05:42:15 +00:00
|
|
|
static int nfs_prev_nfssvc_sy_narg;
|
|
|
|
static sy_call_t *nfs_prev_nfssvc_sy_call;
|
|
|
|
|
1995-06-27 11:07:30 +00:00
|
|
|
/*
|
|
|
|
* Mapping of old NFS Version 2 RPC numbers to generic numbers.
|
|
|
|
*/
|
|
|
|
int nfsv3_procid[NFS_NPROCS] = {
|
|
|
|
NFSPROC_NULL,
|
|
|
|
NFSPROC_GETATTR,
|
|
|
|
NFSPROC_SETATTR,
|
|
|
|
NFSPROC_NOOP,
|
|
|
|
NFSPROC_LOOKUP,
|
|
|
|
NFSPROC_READLINK,
|
|
|
|
NFSPROC_READ,
|
|
|
|
NFSPROC_NOOP,
|
|
|
|
NFSPROC_WRITE,
|
|
|
|
NFSPROC_CREATE,
|
|
|
|
NFSPROC_REMOVE,
|
|
|
|
NFSPROC_RENAME,
|
|
|
|
NFSPROC_LINK,
|
|
|
|
NFSPROC_SYMLINK,
|
|
|
|
NFSPROC_MKDIR,
|
|
|
|
NFSPROC_RMDIR,
|
|
|
|
NFSPROC_READDIR,
|
|
|
|
NFSPROC_FSSTAT,
|
|
|
|
NFSPROC_NOOP,
|
|
|
|
NFSPROC_NOOP,
|
|
|
|
NFSPROC_NOOP,
|
|
|
|
NFSPROC_NOOP,
|
|
|
|
NFSPROC_NOOP,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* and the reverse mapping from generic to Version 2 procedure numbers
|
|
|
|
*/
|
2001-09-18 23:32:09 +00:00
|
|
|
int nfsrvv2_procid[NFS_NPROCS] = {
|
1995-06-27 11:07:30 +00:00
|
|
|
NFSV2PROC_NULL,
|
|
|
|
NFSV2PROC_GETATTR,
|
|
|
|
NFSV2PROC_SETATTR,
|
|
|
|
NFSV2PROC_LOOKUP,
|
|
|
|
NFSV2PROC_NOOP,
|
|
|
|
NFSV2PROC_READLINK,
|
|
|
|
NFSV2PROC_READ,
|
|
|
|
NFSV2PROC_WRITE,
|
|
|
|
NFSV2PROC_CREATE,
|
|
|
|
NFSV2PROC_MKDIR,
|
|
|
|
NFSV2PROC_SYMLINK,
|
|
|
|
NFSV2PROC_CREATE,
|
|
|
|
NFSV2PROC_REMOVE,
|
|
|
|
NFSV2PROC_RMDIR,
|
|
|
|
NFSV2PROC_RENAME,
|
|
|
|
NFSV2PROC_LINK,
|
|
|
|
NFSV2PROC_READDIR,
|
|
|
|
NFSV2PROC_NOOP,
|
|
|
|
NFSV2PROC_STATFS,
|
|
|
|
NFSV2PROC_NOOP,
|
|
|
|
NFSV2PROC_NOOP,
|
|
|
|
NFSV2PROC_NOOP,
|
|
|
|
NFSV2PROC_NOOP,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Maps errno values to nfs error numbers.
|
|
|
|
* Use NFSERR_IO as the catch all for ones not specifically defined in
|
|
|
|
* RFC 1094.
|
|
|
|
*/
|
|
|
|
static u_char nfsrv_v2errmap[ELAST] = {
|
|
|
|
NFSERR_PERM, NFSERR_NOENT, NFSERR_IO, NFSERR_IO, NFSERR_IO,
|
|
|
|
NFSERR_NXIO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO,
|
|
|
|
NFSERR_IO, NFSERR_IO, NFSERR_ACCES, NFSERR_IO, NFSERR_IO,
|
|
|
|
NFSERR_IO, NFSERR_EXIST, NFSERR_IO, NFSERR_NODEV, NFSERR_NOTDIR,
|
|
|
|
NFSERR_ISDIR, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO,
|
|
|
|
NFSERR_IO, NFSERR_FBIG, NFSERR_NOSPC, NFSERR_IO, NFSERR_ROFS,
|
|
|
|
NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO,
|
|
|
|
NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO,
|
|
|
|
NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO,
|
|
|
|
NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO,
|
|
|
|
NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO,
|
|
|
|
NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO,
|
|
|
|
NFSERR_IO, NFSERR_IO, NFSERR_NAMETOL, NFSERR_IO, NFSERR_IO,
|
|
|
|
NFSERR_NOTEMPTY, NFSERR_IO, NFSERR_IO, NFSERR_DQUOT, NFSERR_STALE,
|
|
|
|
NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO,
|
|
|
|
NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO,
|
1998-12-14 18:54:04 +00:00
|
|
|
NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO,
|
|
|
|
NFSERR_IO /* << Last is 86 */
|
1995-06-27 11:07:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Maps errno values to nfs error numbers.
|
|
|
|
* Although it is not obvious whether or not NFS clients really care if
|
|
|
|
* a returned error value is in the specified list for the procedure, the
|
|
|
|
* safest thing to do is filter them appropriately. For Version 2, the
|
|
|
|
* X/Open XNFS document is the only specification that defines error values
|
|
|
|
* for each RPC (The RFC simply lists all possible error values for all RPCs),
|
|
|
|
* so I have decided to not do this for Version 2.
|
|
|
|
* The first entry is the default error return and the rest are the valid
|
|
|
|
* errors for that RPC in increasing numeric order.
|
|
|
|
*/
|
|
|
|
static short nfsv3err_null[] = {
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short nfsv3err_getattr[] = {
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short nfsv3err_setattr[] = {
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_PERM,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_ACCES,
|
|
|
|
NFSERR_INVAL,
|
|
|
|
NFSERR_NOSPC,
|
|
|
|
NFSERR_ROFS,
|
|
|
|
NFSERR_DQUOT,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_NOT_SYNC,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short nfsv3err_lookup[] = {
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_NOENT,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_ACCES,
|
|
|
|
NFSERR_NOTDIR,
|
|
|
|
NFSERR_NAMETOL,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short nfsv3err_access[] = {
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short nfsv3err_readlink[] = {
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_ACCES,
|
|
|
|
NFSERR_INVAL,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_NOTSUPP,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short nfsv3err_read[] = {
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_NXIO,
|
|
|
|
NFSERR_ACCES,
|
|
|
|
NFSERR_INVAL,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short nfsv3err_write[] = {
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_ACCES,
|
|
|
|
NFSERR_INVAL,
|
|
|
|
NFSERR_FBIG,
|
|
|
|
NFSERR_NOSPC,
|
|
|
|
NFSERR_ROFS,
|
|
|
|
NFSERR_DQUOT,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short nfsv3err_create[] = {
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_ACCES,
|
|
|
|
NFSERR_EXIST,
|
|
|
|
NFSERR_NOTDIR,
|
|
|
|
NFSERR_NOSPC,
|
|
|
|
NFSERR_ROFS,
|
|
|
|
NFSERR_NAMETOL,
|
|
|
|
NFSERR_DQUOT,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_NOTSUPP,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short nfsv3err_mkdir[] = {
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_ACCES,
|
|
|
|
NFSERR_EXIST,
|
|
|
|
NFSERR_NOTDIR,
|
|
|
|
NFSERR_NOSPC,
|
|
|
|
NFSERR_ROFS,
|
|
|
|
NFSERR_NAMETOL,
|
|
|
|
NFSERR_DQUOT,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_NOTSUPP,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short nfsv3err_symlink[] = {
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_ACCES,
|
|
|
|
NFSERR_EXIST,
|
|
|
|
NFSERR_NOTDIR,
|
|
|
|
NFSERR_NOSPC,
|
|
|
|
NFSERR_ROFS,
|
|
|
|
NFSERR_NAMETOL,
|
|
|
|
NFSERR_DQUOT,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_NOTSUPP,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short nfsv3err_mknod[] = {
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_ACCES,
|
|
|
|
NFSERR_EXIST,
|
|
|
|
NFSERR_NOTDIR,
|
|
|
|
NFSERR_NOSPC,
|
|
|
|
NFSERR_ROFS,
|
|
|
|
NFSERR_NAMETOL,
|
|
|
|
NFSERR_DQUOT,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_NOTSUPP,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
NFSERR_BADTYPE,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short nfsv3err_remove[] = {
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_NOENT,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_ACCES,
|
|
|
|
NFSERR_NOTDIR,
|
|
|
|
NFSERR_ROFS,
|
|
|
|
NFSERR_NAMETOL,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short nfsv3err_rmdir[] = {
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_NOENT,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_ACCES,
|
|
|
|
NFSERR_EXIST,
|
|
|
|
NFSERR_NOTDIR,
|
|
|
|
NFSERR_INVAL,
|
|
|
|
NFSERR_ROFS,
|
|
|
|
NFSERR_NAMETOL,
|
|
|
|
NFSERR_NOTEMPTY,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_NOTSUPP,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short nfsv3err_rename[] = {
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_NOENT,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_ACCES,
|
|
|
|
NFSERR_EXIST,
|
|
|
|
NFSERR_XDEV,
|
|
|
|
NFSERR_NOTDIR,
|
|
|
|
NFSERR_ISDIR,
|
|
|
|
NFSERR_INVAL,
|
|
|
|
NFSERR_NOSPC,
|
|
|
|
NFSERR_ROFS,
|
|
|
|
NFSERR_MLINK,
|
|
|
|
NFSERR_NAMETOL,
|
|
|
|
NFSERR_NOTEMPTY,
|
|
|
|
NFSERR_DQUOT,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_NOTSUPP,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short nfsv3err_link[] = {
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_ACCES,
|
|
|
|
NFSERR_EXIST,
|
|
|
|
NFSERR_XDEV,
|
|
|
|
NFSERR_NOTDIR,
|
|
|
|
NFSERR_INVAL,
|
|
|
|
NFSERR_NOSPC,
|
|
|
|
NFSERR_ROFS,
|
|
|
|
NFSERR_MLINK,
|
|
|
|
NFSERR_NAMETOL,
|
|
|
|
NFSERR_DQUOT,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_NOTSUPP,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short nfsv3err_readdir[] = {
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_ACCES,
|
|
|
|
NFSERR_NOTDIR,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_BAD_COOKIE,
|
|
|
|
NFSERR_TOOSMALL,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short nfsv3err_readdirplus[] = {
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_ACCES,
|
|
|
|
NFSERR_NOTDIR,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_BAD_COOKIE,
|
|
|
|
NFSERR_NOTSUPP,
|
|
|
|
NFSERR_TOOSMALL,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short nfsv3err_fsstat[] = {
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short nfsv3err_fsinfo[] = {
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short nfsv3err_pathconf[] = {
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short nfsv3err_commit[] = {
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static short *nfsrv_v3errmap[] = {
|
|
|
|
nfsv3err_null,
|
|
|
|
nfsv3err_getattr,
|
|
|
|
nfsv3err_setattr,
|
|
|
|
nfsv3err_lookup,
|
|
|
|
nfsv3err_access,
|
|
|
|
nfsv3err_readlink,
|
|
|
|
nfsv3err_read,
|
|
|
|
nfsv3err_write,
|
|
|
|
nfsv3err_create,
|
|
|
|
nfsv3err_mkdir,
|
|
|
|
nfsv3err_symlink,
|
|
|
|
nfsv3err_mknod,
|
|
|
|
nfsv3err_remove,
|
|
|
|
nfsv3err_rmdir,
|
|
|
|
nfsv3err_rename,
|
|
|
|
nfsv3err_link,
|
|
|
|
nfsv3err_readdir,
|
|
|
|
nfsv3err_readdirplus,
|
|
|
|
nfsv3err_fsstat,
|
|
|
|
nfsv3err_fsinfo,
|
|
|
|
nfsv3err_pathconf,
|
|
|
|
nfsv3err_commit,
|
|
|
|
};
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Called once to initialize data structures...
|
|
|
|
*/
|
2001-09-18 23:32:09 +00:00
|
|
|
static int
|
|
|
|
nfs_init(void *dummy __unused)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
1998-05-24 14:41:56 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
rpc_vers = txdr_unsigned(RPC_VER2);
|
|
|
|
rpc_call = txdr_unsigned(RPC_CALL);
|
|
|
|
rpc_reply = txdr_unsigned(RPC_REPLY);
|
|
|
|
rpc_msgdenied = txdr_unsigned(RPC_MSGDENIED);
|
|
|
|
rpc_msgaccepted = txdr_unsigned(RPC_MSGACCEPTED);
|
|
|
|
rpc_mismatch = txdr_unsigned(RPC_MISMATCH);
|
|
|
|
rpc_autherr = txdr_unsigned(RPC_AUTHERR);
|
|
|
|
rpc_auth_unix = txdr_unsigned(RPCAUTH_UNIX);
|
|
|
|
nfs_prog = txdr_unsigned(NFS_PROG);
|
|
|
|
nfs_true = txdr_unsigned(TRUE);
|
|
|
|
nfs_false = txdr_unsigned(FALSE);
|
1994-10-17 17:47:45 +00:00
|
|
|
nfs_xdrneg1 = txdr_unsigned(-1);
|
1995-06-27 11:07:30 +00:00
|
|
|
nfs_ticks = (hz * NFS_TICKINTVL + 500) / 1000;
|
|
|
|
if (nfs_ticks < 1)
|
|
|
|
nfs_ticks = 1;
|
2001-09-18 23:32:09 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
nfsrv_init(0); /* Init server data structures */
|
|
|
|
nfsrv_initcache(); /* Init the server request cache */
|
|
|
|
|
2001-09-18 23:32:09 +00:00
|
|
|
nfsrv_timer(0);
|
1996-06-14 11:13:21 +00:00
|
|
|
|
1998-09-07 05:42:15 +00:00
|
|
|
nfs_prev_nfssvc_sy_narg = sysent[SYS_nfssvc].sy_narg;
|
1994-09-22 22:10:49 +00:00
|
|
|
sysent[SYS_nfssvc].sy_narg = 2;
|
1998-09-07 05:42:15 +00:00
|
|
|
nfs_prev_nfssvc_sy_call = sysent[SYS_nfssvc].sy_call;
|
1997-10-26 20:13:52 +00:00
|
|
|
sysent[SYS_nfssvc].sy_call = (sy_call_t *)nfssvc;
|
1994-09-22 22:10:49 +00:00
|
|
|
|
1994-05-25 09:21:21 +00:00
|
|
|
return (0);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
2001-09-18 23:32:09 +00:00
|
|
|
SYSINIT(nfs, SI_SUB_VFS, SI_ORDER_ANY, nfs_init, NULL);
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2001-09-18 23:32:09 +00:00
|
|
|
static int
|
|
|
|
nfs_uninit(void *dummy __unused)
|
1998-09-07 05:42:15 +00:00
|
|
|
{
|
|
|
|
|
2001-09-18 23:32:09 +00:00
|
|
|
untimeout(nfsrv_timer, (void *)NULL, nfsrv_timer_handle);
|
1998-09-07 05:42:15 +00:00
|
|
|
sysent[SYS_nfssvc].sy_narg = nfs_prev_nfssvc_sy_narg;
|
|
|
|
sysent[SYS_nfssvc].sy_call = nfs_prev_nfssvc_sy_call;
|
|
|
|
return (0);
|
|
|
|
}
|
2001-09-18 23:32:09 +00:00
|
|
|
SYSUNINIT(nfs, SI_SUB_VFS, SI_ORDER_ANY, nfs_uninit, NULL);
|
1998-09-07 05:42:15 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
1997-07-16 09:06:30 +00:00
|
|
|
* Set up nameidata for a lookup() call and do it.
|
|
|
|
*
|
|
|
|
* If pubflag is set, this call is done for a lookup operation on the
|
|
|
|
* public filehandle. In that case we allow crossing mountpoints and
|
|
|
|
* absolute pathnames. However, the caller is expected to check that
|
|
|
|
* the lookup result is within the public fs, and deny access if
|
|
|
|
* it is not.
|
1999-06-23 04:44:14 +00:00
|
|
|
*
|
|
|
|
* nfs_namei() clears out garbage fields that namei() might leave garbage.
|
|
|
|
* This is mainly ni_vp and ni_dvp when an error occurs, and ni_dvp when no
|
|
|
|
* error occurs but the parent was not requested.
|
|
|
|
*
|
2001-09-18 23:32:09 +00:00
|
|
|
* dirp may be set whether an error is returned or not, and must be
|
1999-06-23 04:44:14 +00:00
|
|
|
* released by the caller.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
1994-05-25 09:21:21 +00:00
|
|
|
int
|
2001-09-18 23:32:09 +00:00
|
|
|
nfs_namei(struct nameidata *ndp, fhandle_t *fhp, int len,
|
|
|
|
struct nfssvc_sock *slp, struct sockaddr *nam, struct mbuf **mdp,
|
|
|
|
caddr_t *dposp, struct vnode **retdirp, struct thread *td, int pubflag)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2001-09-18 23:32:09 +00:00
|
|
|
int i, rem;
|
|
|
|
struct mbuf *md;
|
|
|
|
char *fromcp, *tocp, *cp;
|
1997-07-16 09:06:30 +00:00
|
|
|
struct iovec aiov;
|
|
|
|
struct uio auio;
|
1994-05-24 10:09:53 +00:00
|
|
|
struct vnode *dp;
|
1997-07-16 09:06:30 +00:00
|
|
|
int error, rdonly, linklen;
|
1994-05-24 10:09:53 +00:00
|
|
|
struct componentname *cnp = &ndp->ni_cnd;
|
|
|
|
|
1995-06-27 11:07:30 +00:00
|
|
|
*retdirp = (struct vnode *)0;
|
1997-09-21 04:24:27 +00:00
|
|
|
cnp->cn_pnbuf = zalloc(namei_zone);
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Copy the name from the mbuf list to ndp->ni_pnbuf
|
|
|
|
* and set the various ndp fields appropriately.
|
|
|
|
*/
|
|
|
|
fromcp = *dposp;
|
|
|
|
tocp = cnp->cn_pnbuf;
|
|
|
|
md = *mdp;
|
|
|
|
rem = mtod(md, caddr_t) + md->m_len - fromcp;
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
while (rem == 0) {
|
|
|
|
md = md->m_next;
|
|
|
|
if (md == NULL) {
|
|
|
|
error = EBADRPC;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
fromcp = mtod(md, caddr_t);
|
|
|
|
rem = md->m_len;
|
|
|
|
}
|
1997-07-16 09:06:30 +00:00
|
|
|
if (*fromcp == '\0' || (!pubflag && *fromcp == '/')) {
|
1995-06-27 11:07:30 +00:00
|
|
|
error = EACCES;
|
1994-05-24 10:09:53 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
*tocp++ = *fromcp++;
|
|
|
|
rem--;
|
|
|
|
}
|
|
|
|
*tocp = '\0';
|
|
|
|
*mdp = md;
|
|
|
|
*dposp = fromcp;
|
|
|
|
len = nfsm_rndup(len)-len;
|
|
|
|
if (len > 0) {
|
|
|
|
if (rem >= len)
|
|
|
|
*dposp += len;
|
1997-07-22 15:35:57 +00:00
|
|
|
else if ((error = nfs_adv(mdp, dposp, len, rem)) != 0)
|
1995-06-27 11:07:30 +00:00
|
|
|
goto out;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
1997-07-16 09:06:30 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Extract and set starting directory.
|
|
|
|
*/
|
1997-07-16 09:06:30 +00:00
|
|
|
error = nfsrv_fhtovp(fhp, FALSE, &dp, ndp->ni_cnd.cn_cred, slp,
|
2001-09-18 23:32:09 +00:00
|
|
|
nam, &rdonly, pubflag);
|
1997-07-16 09:06:30 +00:00
|
|
|
if (error)
|
1994-05-24 10:09:53 +00:00
|
|
|
goto out;
|
|
|
|
if (dp->v_type != VDIR) {
|
1996-08-21 21:56:23 +00:00
|
|
|
vrele(dp);
|
1994-05-24 10:09:53 +00:00
|
|
|
error = ENOTDIR;
|
|
|
|
goto out;
|
|
|
|
}
|
1997-07-16 09:06:30 +00:00
|
|
|
|
|
|
|
if (rdonly)
|
|
|
|
cnp->cn_flags |= RDONLY;
|
|
|
|
|
1999-06-23 04:44:14 +00:00
|
|
|
/*
|
2001-09-18 23:32:09 +00:00
|
|
|
* Set return directory. Reference to dp is implicitly transfered
|
1999-06-23 04:44:14 +00:00
|
|
|
* to the returned pointer
|
|
|
|
*/
|
1997-07-22 15:35:57 +00:00
|
|
|
*retdirp = dp;
|
|
|
|
|
1997-07-16 09:06:30 +00:00
|
|
|
if (pubflag) {
|
|
|
|
/*
|
|
|
|
* Oh joy. For WebNFS, handle those pesky '%' escapes,
|
|
|
|
* and the 'native path' indicator.
|
|
|
|
*/
|
1997-09-21 04:24:27 +00:00
|
|
|
cp = zalloc(namei_zone);
|
1997-07-16 09:06:30 +00:00
|
|
|
fromcp = cnp->cn_pnbuf;
|
|
|
|
tocp = cp;
|
|
|
|
if ((unsigned char)*fromcp >= WEBNFS_SPECCHAR_START) {
|
|
|
|
switch ((unsigned char)*fromcp) {
|
|
|
|
case WEBNFS_NATIVE_CHAR:
|
|
|
|
/*
|
|
|
|
* 'Native' path for us is the same
|
|
|
|
* as a path according to the NFS spec,
|
|
|
|
* just skip the escape char.
|
|
|
|
*/
|
|
|
|
fromcp++;
|
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* More may be added in the future, range 0x80-0xff
|
|
|
|
*/
|
|
|
|
default:
|
|
|
|
error = EIO;
|
1997-09-21 04:24:27 +00:00
|
|
|
zfree(namei_zone, cp);
|
1997-07-16 09:06:30 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Translate the '%' escapes, URL-style.
|
|
|
|
*/
|
|
|
|
while (*fromcp != '\0') {
|
|
|
|
if (*fromcp == WEBNFS_ESC_CHAR) {
|
|
|
|
if (fromcp[1] != '\0' && fromcp[2] != '\0') {
|
|
|
|
fromcp++;
|
|
|
|
*tocp++ = HEXSTRTOI(fromcp);
|
|
|
|
fromcp += 2;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
error = ENOENT;
|
1997-09-21 04:24:27 +00:00
|
|
|
zfree(namei_zone, cp);
|
1997-07-16 09:06:30 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
*tocp++ = *fromcp++;
|
|
|
|
}
|
|
|
|
*tocp = '\0';
|
1997-09-21 04:24:27 +00:00
|
|
|
zfree(namei_zone, cnp->cn_pnbuf);
|
1997-07-16 09:06:30 +00:00
|
|
|
cnp->cn_pnbuf = cp;
|
|
|
|
}
|
|
|
|
|
|
|
|
ndp->ni_pathlen = (tocp - cnp->cn_pnbuf) + 1;
|
|
|
|
ndp->ni_segflg = UIO_SYSSPACE;
|
|
|
|
|
|
|
|
if (pubflag) {
|
|
|
|
ndp->ni_rootdir = rootvnode;
|
|
|
|
ndp->ni_loopcnt = 0;
|
|
|
|
if (cnp->cn_pnbuf[0] == '/')
|
|
|
|
dp = rootvnode;
|
|
|
|
} else {
|
1997-07-22 15:35:57 +00:00
|
|
|
cnp->cn_flags |= NOCROSSMOUNT;
|
1997-07-16 09:06:30 +00:00
|
|
|
}
|
|
|
|
|
1999-06-23 04:44:14 +00:00
|
|
|
/*
|
|
|
|
* Initialize for scan, set ni_startdir and bump ref on dp again
|
|
|
|
* becuase lookup() will dereference ni_startdir.
|
|
|
|
*/
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
cnp->cn_thread = td;
|
1995-06-27 11:07:30 +00:00
|
|
|
VREF(dp);
|
1994-05-24 10:09:53 +00:00
|
|
|
ndp->ni_startdir = dp;
|
1999-06-23 04:44:14 +00:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
cnp->cn_nameptr = cnp->cn_pnbuf;
|
|
|
|
/*
|
|
|
|
* Call lookup() to do the real work. If an error occurs,
|
|
|
|
* ndp->ni_vp and ni_dvp are left uninitialized or NULL and
|
|
|
|
* we do not have to dereference anything before returning.
|
|
|
|
* In either case ni_startdir will be dereferenced and NULLed
|
|
|
|
* out.
|
|
|
|
*/
|
|
|
|
error = lookup(ndp);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
2001-09-18 23:32:09 +00:00
|
|
|
* Check for encountering a symbolic link. Trivial
|
1999-06-23 04:44:14 +00:00
|
|
|
* termination occurs if no symlink encountered.
|
|
|
|
* Note: zfree is safe because error is 0, so we will
|
|
|
|
* not zfree it again when we break.
|
|
|
|
*/
|
|
|
|
if ((cnp->cn_flags & ISSYMLINK) == 0) {
|
|
|
|
nfsrv_object_create(ndp->ni_vp);
|
|
|
|
if (cnp->cn_flags & (SAVENAME | SAVESTART))
|
|
|
|
cnp->cn_flags |= HASBUF;
|
|
|
|
else
|
|
|
|
zfree(namei_zone, cnp->cn_pnbuf);
|
|
|
|
break;
|
1997-07-16 09:06:30 +00:00
|
|
|
}
|
1999-06-23 04:44:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Validate symlink
|
|
|
|
*/
|
1994-05-24 10:09:53 +00:00
|
|
|
if ((cnp->cn_flags & LOCKPARENT) && ndp->ni_pathlen == 1)
|
2001-09-12 08:38:13 +00:00
|
|
|
VOP_UNLOCK(ndp->ni_dvp, 0, td);
|
1997-07-16 09:06:30 +00:00
|
|
|
if (!pubflag) {
|
|
|
|
error = EINVAL;
|
1999-06-23 04:44:14 +00:00
|
|
|
goto badlink2;
|
1997-07-16 09:06:30 +00:00
|
|
|
}
|
1995-05-29 04:01:09 +00:00
|
|
|
|
1997-07-16 09:06:30 +00:00
|
|
|
if (ndp->ni_loopcnt++ >= MAXSYMLINKS) {
|
|
|
|
error = ELOOP;
|
1999-06-23 04:44:14 +00:00
|
|
|
goto badlink2;
|
1997-07-16 09:06:30 +00:00
|
|
|
}
|
1997-07-22 15:35:57 +00:00
|
|
|
if (ndp->ni_pathlen > 1)
|
1997-09-21 04:24:27 +00:00
|
|
|
cp = zalloc(namei_zone);
|
1997-07-16 09:06:30 +00:00
|
|
|
else
|
|
|
|
cp = cnp->cn_pnbuf;
|
|
|
|
aiov.iov_base = cp;
|
|
|
|
aiov.iov_len = MAXPATHLEN;
|
|
|
|
auio.uio_iov = &aiov;
|
|
|
|
auio.uio_iovcnt = 1;
|
|
|
|
auio.uio_offset = 0;
|
|
|
|
auio.uio_rw = UIO_READ;
|
|
|
|
auio.uio_segflg = UIO_SYSSPACE;
|
2001-09-12 08:38:13 +00:00
|
|
|
auio.uio_td = (struct thread *)0;
|
1997-07-16 09:06:30 +00:00
|
|
|
auio.uio_resid = MAXPATHLEN;
|
|
|
|
error = VOP_READLINK(ndp->ni_vp, &auio, cnp->cn_cred);
|
|
|
|
if (error) {
|
1999-06-23 04:44:14 +00:00
|
|
|
badlink1:
|
1997-07-16 09:06:30 +00:00
|
|
|
if (ndp->ni_pathlen > 1)
|
1997-09-21 04:24:27 +00:00
|
|
|
zfree(namei_zone, cp);
|
1999-06-23 04:44:14 +00:00
|
|
|
badlink2:
|
|
|
|
vrele(ndp->ni_dvp);
|
|
|
|
vput(ndp->ni_vp);
|
1997-07-16 09:06:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
linklen = MAXPATHLEN - auio.uio_resid;
|
|
|
|
if (linklen == 0) {
|
|
|
|
error = ENOENT;
|
1999-06-23 04:44:14 +00:00
|
|
|
goto badlink1;
|
1997-07-16 09:06:30 +00:00
|
|
|
}
|
|
|
|
if (linklen + ndp->ni_pathlen >= MAXPATHLEN) {
|
|
|
|
error = ENAMETOOLONG;
|
1999-06-23 04:44:14 +00:00
|
|
|
goto badlink1;
|
1997-07-16 09:06:30 +00:00
|
|
|
}
|
1999-06-23 04:44:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Adjust or replace path
|
|
|
|
*/
|
1997-07-16 09:06:30 +00:00
|
|
|
if (ndp->ni_pathlen > 1) {
|
|
|
|
bcopy(ndp->ni_next, cp + linklen, ndp->ni_pathlen);
|
1997-09-21 04:24:27 +00:00
|
|
|
zfree(namei_zone, cnp->cn_pnbuf);
|
1997-07-16 09:06:30 +00:00
|
|
|
cnp->cn_pnbuf = cp;
|
|
|
|
} else
|
|
|
|
cnp->cn_pnbuf[linklen] = '\0';
|
|
|
|
ndp->ni_pathlen += linklen;
|
1999-06-23 04:44:14 +00:00
|
|
|
|
1997-07-16 09:06:30 +00:00
|
|
|
/*
|
2001-09-18 23:32:09 +00:00
|
|
|
* Cleanup refs for next loop and check if root directory
|
|
|
|
* should replace current directory. Normally ni_dvp
|
1999-06-23 04:44:14 +00:00
|
|
|
* becomes the new base directory and is cleaned up when
|
|
|
|
* we loop. Explicitly null pointers after invalidation
|
|
|
|
* to clarify operation.
|
1997-07-16 09:06:30 +00:00
|
|
|
*/
|
1999-06-23 04:44:14 +00:00
|
|
|
vput(ndp->ni_vp);
|
|
|
|
ndp->ni_vp = NULL;
|
|
|
|
|
1997-07-16 09:06:30 +00:00
|
|
|
if (cnp->cn_pnbuf[0] == '/') {
|
1999-06-23 04:44:14 +00:00
|
|
|
vrele(ndp->ni_dvp);
|
|
|
|
ndp->ni_dvp = ndp->ni_rootdir;
|
|
|
|
VREF(ndp->ni_dvp);
|
1997-07-16 09:06:30 +00:00
|
|
|
}
|
1999-06-23 04:44:14 +00:00
|
|
|
ndp->ni_startdir = ndp->ni_dvp;
|
|
|
|
ndp->ni_dvp = NULL;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
1999-06-23 04:44:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* nfs_namei() guarentees that fields will not contain garbage
|
|
|
|
* whether an error occurs or not. This allows the caller to track
|
|
|
|
* cleanup state trivially.
|
|
|
|
*/
|
1994-05-24 10:09:53 +00:00
|
|
|
out:
|
1999-06-23 04:44:14 +00:00
|
|
|
if (error) {
|
|
|
|
zfree(namei_zone, cnp->cn_pnbuf);
|
|
|
|
ndp->ni_vp = NULL;
|
|
|
|
ndp->ni_dvp = NULL;
|
|
|
|
ndp->ni_startdir = NULL;
|
|
|
|
cnp->cn_flags &= ~HASBUF;
|
|
|
|
} else if ((ndp->ni_cnd.cn_flags & (WANTPARENT|LOCKPARENT)) == 0) {
|
|
|
|
ndp->ni_dvp = NULL;
|
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A fiddled version of m_adj() that ensures null fill to a long
|
|
|
|
* boundary and only trims off the back end
|
|
|
|
*/
|
|
|
|
void
|
2001-09-18 23:32:09 +00:00
|
|
|
nfsm_adj(struct mbuf *mp, int len, int nul)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2001-09-18 23:32:09 +00:00
|
|
|
struct mbuf *m;
|
|
|
|
int count, i;
|
|
|
|
char *cp;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Trim from tail. Scan the mbuf chain,
|
|
|
|
* calculating its length and finding the last mbuf.
|
|
|
|
* If the adjustment only affects this mbuf, then just
|
|
|
|
* adjust and return. Otherwise, rescan and truncate
|
|
|
|
* after the remaining size.
|
|
|
|
*/
|
|
|
|
count = 0;
|
|
|
|
m = mp;
|
|
|
|
for (;;) {
|
|
|
|
count += m->m_len;
|
|
|
|
if (m->m_next == (struct mbuf *)0)
|
|
|
|
break;
|
|
|
|
m = m->m_next;
|
|
|
|
}
|
|
|
|
if (m->m_len > len) {
|
|
|
|
m->m_len -= len;
|
|
|
|
if (nul > 0) {
|
|
|
|
cp = mtod(m, caddr_t)+m->m_len-nul;
|
|
|
|
for (i = 0; i < nul; i++)
|
|
|
|
*cp++ = '\0';
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
count -= len;
|
|
|
|
if (count < 0)
|
|
|
|
count = 0;
|
|
|
|
/*
|
|
|
|
* Correct length for chain is "count".
|
|
|
|
* Find the mbuf with last data, adjust its length,
|
|
|
|
* and toss data from remaining mbufs on chain.
|
|
|
|
*/
|
|
|
|
for (m = mp; m; m = m->m_next) {
|
|
|
|
if (m->m_len >= count) {
|
|
|
|
m->m_len = count;
|
|
|
|
if (nul > 0) {
|
|
|
|
cp = mtod(m, caddr_t)+m->m_len-nul;
|
|
|
|
for (i = 0; i < nul; i++)
|
|
|
|
*cp++ = '\0';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
count -= m->m_len;
|
|
|
|
}
|
1994-10-02 17:27:07 +00:00
|
|
|
for (m = m->m_next;m;m = m->m_next)
|
1994-05-24 10:09:53 +00:00
|
|
|
m->m_len = 0;
|
|
|
|
}
|
|
|
|
|
1995-06-27 11:07:30 +00:00
|
|
|
/*
|
|
|
|
* Make these functions instead of macros, so that the kernel text size
|
|
|
|
* doesn't get too big...
|
|
|
|
*/
|
|
|
|
void
|
2001-09-18 23:32:09 +00:00
|
|
|
nfsm_srvwcc(struct nfsrv_descript *nfsd, int before_ret,
|
|
|
|
struct vattr *before_vap, int after_ret, struct vattr *after_vap,
|
|
|
|
struct mbuf **mbp, char **bposp)
|
1995-06-27 11:07:30 +00:00
|
|
|
{
|
2001-09-18 23:32:09 +00:00
|
|
|
struct mbuf *mb = *mbp;
|
|
|
|
char *bpos = *bposp;
|
|
|
|
u_int32_t *tl;
|
1995-06-27 11:07:30 +00:00
|
|
|
|
|
|
|
if (before_ret) {
|
1998-05-31 20:09:01 +00:00
|
|
|
nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
|
1995-06-27 11:07:30 +00:00
|
|
|
*tl = nfs_false;
|
|
|
|
} else {
|
1998-05-31 20:09:01 +00:00
|
|
|
nfsm_build(tl, u_int32_t *, 7 * NFSX_UNSIGNED);
|
1995-06-27 11:07:30 +00:00
|
|
|
*tl++ = nfs_true;
|
1999-06-05 05:35:03 +00:00
|
|
|
txdr_hyper(before_vap->va_size, tl);
|
1995-06-27 11:07:30 +00:00
|
|
|
tl += 2;
|
|
|
|
txdr_nfsv3time(&(before_vap->va_mtime), tl);
|
|
|
|
tl += 2;
|
|
|
|
txdr_nfsv3time(&(before_vap->va_ctime), tl);
|
|
|
|
}
|
|
|
|
*bposp = bpos;
|
|
|
|
*mbp = mb;
|
|
|
|
nfsm_srvpostopattr(nfsd, after_ret, after_vap, mbp, bposp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-09-18 23:32:09 +00:00
|
|
|
nfsm_srvpostopattr(struct nfsrv_descript *nfsd, int after_ret,
|
|
|
|
struct vattr *after_vap, struct mbuf **mbp, char **bposp)
|
1995-06-27 11:07:30 +00:00
|
|
|
{
|
2001-09-18 23:32:09 +00:00
|
|
|
struct mbuf *mb = *mbp;
|
|
|
|
char *bpos = *bposp;
|
|
|
|
u_int32_t *tl;
|
|
|
|
struct nfs_fattr *fp;
|
1995-06-27 11:07:30 +00:00
|
|
|
|
|
|
|
if (after_ret) {
|
1998-05-31 20:09:01 +00:00
|
|
|
nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
|
1995-06-27 11:07:30 +00:00
|
|
|
*tl = nfs_false;
|
|
|
|
} else {
|
1998-05-31 20:09:01 +00:00
|
|
|
nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED + NFSX_V3FATTR);
|
1995-06-27 11:07:30 +00:00
|
|
|
*tl++ = nfs_true;
|
|
|
|
fp = (struct nfs_fattr *)tl;
|
|
|
|
nfsm_srvfattr(nfsd, after_vap, fp);
|
|
|
|
}
|
|
|
|
*mbp = mb;
|
|
|
|
*bposp = bpos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-09-18 23:32:09 +00:00
|
|
|
nfsm_srvfattr(struct nfsrv_descript *nfsd, struct vattr *vap,
|
|
|
|
struct nfs_fattr *fp)
|
1995-06-27 11:07:30 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
fp->fa_nlink = txdr_unsigned(vap->va_nlink);
|
|
|
|
fp->fa_uid = txdr_unsigned(vap->va_uid);
|
|
|
|
fp->fa_gid = txdr_unsigned(vap->va_gid);
|
|
|
|
if (nfsd->nd_flag & ND_NFSV3) {
|
|
|
|
fp->fa_type = vtonfsv3_type(vap->va_type);
|
|
|
|
fp->fa_mode = vtonfsv3_mode(vap->va_mode);
|
1999-06-05 05:35:03 +00:00
|
|
|
txdr_hyper(vap->va_size, &fp->fa3_size);
|
|
|
|
txdr_hyper(vap->va_bytes, &fp->fa3_used);
|
Divorce "dev_t" from the "major|minor" bitmap, which is now called
udev_t in the kernel but still called dev_t in userland.
Provide functions to manipulate both types:
major() umajor()
minor() uminor()
makedev() umakedev()
dev2udev() udev2dev()
For now they're functions, they will become in-line functions
after one of the next two steps in this process.
Return major/minor/makedev to macro-hood for userland.
Register a name in cdevsw[] for the "filedescriptor" driver.
In the kernel the udev_t appears in places where we have the
major/minor number combination, (ie: a potential device: we
may not have the driver nor the device), like in inodes, vattr,
cdevsw registration and so on, whereas the dev_t appears where
we carry around a reference to a actual device.
In the future the cdevsw and the aliased-from vnode will be hung
directly from the dev_t, along with up to two softc pointers for
the device driver and a few houskeeping bits. This will essentially
replace the current "alias" check code (same buck, bigger bang).
A little stunt has been provided to try to catch places where the
wrong type is being used (dev_t vs udev_t), if you see something
not working, #undef DEVT_FASCIST in kern/kern_conf.c and see if
it makes a difference. If it does, please try to track it down
(many hands make light work) or at least try to reproduce it
as simply as possible, and describe how to do that.
Without DEVT_FASCIST I belive this patch is a no-op.
Stylistic/posixoid comments about the userland view of the <sys/*.h>
files welcome now, from userland they now contain the end result.
Next planned step: make all dev_t's refer to the same devsw[] which
means convert BLK's to CHR's at the perimeter of the vnodes and
other places where they enter the game (bootdev, mknod, sysctl).
1999-05-11 19:55:07 +00:00
|
|
|
fp->fa3_rdev.specdata1 = txdr_unsigned(umajor(vap->va_rdev));
|
|
|
|
fp->fa3_rdev.specdata2 = txdr_unsigned(uminor(vap->va_rdev));
|
1995-06-27 11:07:30 +00:00
|
|
|
fp->fa3_fsid.nfsuquad[0] = 0;
|
|
|
|
fp->fa3_fsid.nfsuquad[1] = txdr_unsigned(vap->va_fsid);
|
|
|
|
fp->fa3_fileid.nfsuquad[0] = 0;
|
|
|
|
fp->fa3_fileid.nfsuquad[1] = txdr_unsigned(vap->va_fileid);
|
|
|
|
txdr_nfsv3time(&vap->va_atime, &fp->fa3_atime);
|
|
|
|
txdr_nfsv3time(&vap->va_mtime, &fp->fa3_mtime);
|
|
|
|
txdr_nfsv3time(&vap->va_ctime, &fp->fa3_ctime);
|
|
|
|
} else {
|
|
|
|
fp->fa_type = vtonfsv2_type(vap->va_type);
|
|
|
|
fp->fa_mode = vtonfsv2_mode(vap->va_type, vap->va_mode);
|
|
|
|
fp->fa2_size = txdr_unsigned(vap->va_size);
|
|
|
|
fp->fa2_blocksize = txdr_unsigned(vap->va_blocksize);
|
|
|
|
if (vap->va_type == VFIFO)
|
|
|
|
fp->fa2_rdev = 0xffffffff;
|
|
|
|
else
|
|
|
|
fp->fa2_rdev = txdr_unsigned(vap->va_rdev);
|
|
|
|
fp->fa2_blocks = txdr_unsigned(vap->va_bytes / NFS_FABLKSIZE);
|
|
|
|
fp->fa2_fsid = txdr_unsigned(vap->va_fsid);
|
|
|
|
fp->fa2_fileid = txdr_unsigned(vap->va_fileid);
|
|
|
|
txdr_nfsv2time(&vap->va_atime, &fp->fa2_atime);
|
|
|
|
txdr_nfsv2time(&vap->va_mtime, &fp->fa2_mtime);
|
|
|
|
txdr_nfsv2time(&vap->va_ctime, &fp->fa2_ctime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* nfsrv_fhtovp() - convert a fh to a vnode ptr (optionally locked)
|
|
|
|
* - look up fsid in mount list (if not found ret error)
|
|
|
|
* - get vp and export rights by calling VFS_FHTOVP()
|
|
|
|
* - if cred->cr_uid == 0 or MNT_EXPORTANON set it to credanon
|
|
|
|
* - if not lockflag unlock it with VOP_UNLOCK()
|
|
|
|
*/
|
1994-05-25 09:21:21 +00:00
|
|
|
int
|
2001-09-18 23:32:09 +00:00
|
|
|
nfsrv_fhtovp(fhandle_t *fhp, int lockflag, struct vnode **vpp,
|
|
|
|
struct ucred *cred, struct nfssvc_sock *slp, struct sockaddr *nam,
|
|
|
|
int *rdonlyp, int pubflag)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td = curthread; /* XXX */
|
2001-09-18 23:32:09 +00:00
|
|
|
struct mount *mp;
|
|
|
|
int i;
|
1994-05-24 10:09:53 +00:00
|
|
|
struct ucred *credanon;
|
|
|
|
int error, exflags;
|
1998-05-31 19:16:08 +00:00
|
|
|
#ifdef MNT_EXNORESPORT /* XXX needs mountd and /etc/exports help yet */
|
|
|
|
struct sockaddr_int *saddr;
|
|
|
|
#endif
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
*vpp = (struct vnode *)0;
|
1997-07-16 09:06:30 +00:00
|
|
|
|
|
|
|
if (nfs_ispublicfh(fhp)) {
|
|
|
|
if (!pubflag || !nfs_pub.np_valid)
|
|
|
|
return (ESTALE);
|
|
|
|
fhp = &nfs_pub.np_handle;
|
|
|
|
}
|
|
|
|
|
1997-02-10 02:22:35 +00:00
|
|
|
mp = vfs_getvfs(&fhp->fh_fsid);
|
1994-10-02 17:27:07 +00:00
|
|
|
if (!mp)
|
1994-05-24 10:09:53 +00:00
|
|
|
return (ESTALE);
|
1999-09-11 00:46:08 +00:00
|
|
|
error = VFS_CHECKEXP(mp, nam, &exflags, &credanon);
|
|
|
|
if (error)
|
2001-09-18 23:32:09 +00:00
|
|
|
return (error);
|
1999-09-11 00:46:08 +00:00
|
|
|
error = VFS_FHTOVP(mp, &fhp->fh_fid, vpp);
|
1994-10-02 17:27:07 +00:00
|
|
|
if (error)
|
1994-05-24 10:09:53 +00:00
|
|
|
return (error);
|
1998-05-31 19:16:08 +00:00
|
|
|
#ifdef MNT_EXNORESPORT
|
|
|
|
if (!(exflags & (MNT_EXNORESPORT|MNT_EXPUBLIC))) {
|
|
|
|
saddr = (struct sockaddr_in *)nam;
|
|
|
|
if (saddr->sin_family == AF_INET &&
|
|
|
|
ntohs(saddr->sin_port) >= IPPORT_RESERVED) {
|
|
|
|
vput(*vpp);
|
1999-12-12 07:06:39 +00:00
|
|
|
*vpp = NULL;
|
1998-05-31 19:16:08 +00:00
|
|
|
return (NFSERR_AUTHERR | AUTH_TOOWEAK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Check/setup credentials.
|
|
|
|
*/
|
2001-09-18 23:32:09 +00:00
|
|
|
if (cred->cr_uid == 0 || (exflags & MNT_EXPORTANON)) {
|
1994-05-24 10:09:53 +00:00
|
|
|
cred->cr_uid = credanon->cr_uid;
|
|
|
|
for (i = 0; i < credanon->cr_ngroups && i < NGROUPS; i++)
|
|
|
|
cred->cr_groups[i] = credanon->cr_groups[i];
|
1994-10-17 17:47:45 +00:00
|
|
|
cred->cr_ngroups = i;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
if (exflags & MNT_EXRDONLY)
|
|
|
|
*rdonlyp = 1;
|
|
|
|
else
|
|
|
|
*rdonlyp = 0;
|
1995-04-21 02:58:49 +00:00
|
|
|
|
1996-08-21 21:56:23 +00:00
|
|
|
nfsrv_object_create(*vpp);
|
1995-04-21 02:58:49 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
if (!lockflag)
|
2001-09-12 08:38:13 +00:00
|
|
|
VOP_UNLOCK(*vpp, 0, td);
|
1994-05-24 10:09:53 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1997-07-16 09:06:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* WebNFS: check if a filehandle is a public filehandle. For v3, this
|
|
|
|
* means a length of 0, for v2 it means all zeroes. nfsm_srvmtofh has
|
|
|
|
* transformed this to all zeroes in both cases, so check for it.
|
|
|
|
*/
|
|
|
|
int
|
2001-09-18 23:32:09 +00:00
|
|
|
nfs_ispublicfh(fhandle_t *fhp)
|
1997-07-16 09:06:30 +00:00
|
|
|
{
|
|
|
|
char *cp = (char *)fhp;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NFSX_V3FH; i++)
|
|
|
|
if (*cp++ != 0)
|
|
|
|
return (FALSE);
|
|
|
|
return (TRUE);
|
|
|
|
}
|
2001-09-18 23:32:09 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* This function compares two net addresses by family and returns TRUE
|
|
|
|
* if they are the same host.
|
|
|
|
* If there is any doubt, return FALSE.
|
|
|
|
* The AF_INET family is handled as a special case so that address mbufs
|
|
|
|
* don't need to be saved to store "struct in_addr", which is only 4 bytes.
|
|
|
|
*/
|
1994-05-25 09:21:21 +00:00
|
|
|
int
|
2001-09-18 23:32:09 +00:00
|
|
|
netaddr_match(int family, union nethostaddr *haddr, struct sockaddr *nam)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2001-09-18 23:32:09 +00:00
|
|
|
struct sockaddr_in *inetaddr;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
switch (family) {
|
|
|
|
case AF_INET:
|
1997-08-16 19:16:27 +00:00
|
|
|
inetaddr = (struct sockaddr_in *)nam;
|
1994-05-24 10:09:53 +00:00
|
|
|
if (inetaddr->sin_family == AF_INET &&
|
|
|
|
inetaddr->sin_addr.s_addr == haddr->had_inetaddr)
|
|
|
|
return (1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
return (0);
|
|
|
|
}
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
|
1995-06-27 11:07:30 +00:00
|
|
|
/*
|
|
|
|
* Map errnos to NFS error numbers. For Version 3 also filter out error
|
|
|
|
* numbers not specified for the associated procedure.
|
|
|
|
*/
|
|
|
|
int
|
2001-09-18 23:32:09 +00:00
|
|
|
nfsrv_errmap(struct nfsrv_descript *nd, int err)
|
1995-06-27 11:07:30 +00:00
|
|
|
{
|
2001-09-18 23:32:09 +00:00
|
|
|
short *defaulterrp, *errp;
|
1995-06-27 11:07:30 +00:00
|
|
|
|
|
|
|
if (nd->nd_flag & ND_NFSV3) {
|
|
|
|
if (nd->nd_procnum <= NFSPROC_COMMIT) {
|
|
|
|
errp = defaulterrp = nfsrv_v3errmap[nd->nd_procnum];
|
|
|
|
while (*++errp) {
|
|
|
|
if (*errp == err)
|
|
|
|
return (err);
|
|
|
|
else if (*errp > err)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ((int)*defaulterrp);
|
|
|
|
} else
|
|
|
|
return (err & 0xffff);
|
|
|
|
}
|
|
|
|
if (err <= ELAST)
|
|
|
|
return ((int)nfsrv_v2errmap[err - 1]);
|
|
|
|
return (NFSERR_IO);
|
|
|
|
}
|
|
|
|
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
int
|
2001-09-18 23:32:09 +00:00
|
|
|
nfsrv_object_create(struct vnode *vp)
|
1997-12-20 00:25:01 +00:00
|
|
|
{
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
|
1997-12-20 00:25:01 +00:00
|
|
|
if (vp == NULL || vp->v_type != VREG)
|
|
|
|
return (1);
|
2001-09-12 08:38:13 +00:00
|
|
|
return (vfs_object_create(vp, curthread,
|
|
|
|
curthread ? curthread->td_proc->p_ucred : NULL));
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
}
|
1998-05-31 17:27:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sort the group list in increasing numerical order.
|
|
|
|
* (Insertion sort by Chris Torek, who was grossed out by the bubble sort
|
|
|
|
* that used to be here.)
|
|
|
|
*/
|
|
|
|
void
|
2001-09-18 23:32:09 +00:00
|
|
|
nfsrvw_sort(gid_t *list, int num)
|
1998-05-31 17:27:58 +00:00
|
|
|
{
|
2001-09-18 23:32:09 +00:00
|
|
|
int i, j;
|
1998-05-31 17:27:58 +00:00
|
|
|
gid_t v;
|
|
|
|
|
|
|
|
/* Insertion sort. */
|
|
|
|
for (i = 1; i < num; i++) {
|
|
|
|
v = list[i];
|
|
|
|
/* find correct slot for value v, moving others up */
|
|
|
|
for (j = i; --j >= 0 && v < list[j];)
|
|
|
|
list[j + 1] = list[j];
|
|
|
|
list[j + 1] = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* copy credentials making sure that the result can be compared with bcmp().
|
|
|
|
*/
|
|
|
|
void
|
2001-09-18 23:32:09 +00:00
|
|
|
nfsrv_setcred(struct ucred *incred, struct ucred *outcred)
|
1998-05-31 17:27:58 +00:00
|
|
|
{
|
2001-09-18 23:32:09 +00:00
|
|
|
int i;
|
1998-05-31 17:27:58 +00:00
|
|
|
|
|
|
|
bzero((caddr_t)outcred, sizeof (struct ucred));
|
|
|
|
outcred->cr_ref = 1;
|
|
|
|
outcred->cr_uid = incred->cr_uid;
|
|
|
|
outcred->cr_ngroups = incred->cr_ngroups;
|
|
|
|
for (i = 0; i < incred->cr_ngroups; i++)
|
|
|
|
outcred->cr_groups[i] = incred->cr_groups[i];
|
|
|
|
nfsrvw_sort(outcred->cr_groups, outcred->cr_ngroups);
|
|
|
|
}
|
2001-09-18 23:32:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper functions for macros.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
nfsm_srvfhtom_xx(fhandle_t *f, int v3,
|
|
|
|
u_int32_t **tl, struct mbuf **mb, caddr_t *bpos)
|
|
|
|
{
|
|
|
|
u_int32_t *cp;
|
|
|
|
|
|
|
|
if (v3) {
|
|
|
|
nfsm_build_xx((void **)tl, NFSX_UNSIGNED + NFSX_V3FH, mb,
|
|
|
|
bpos);
|
|
|
|
*(*tl)++ = txdr_unsigned(NFSX_V3FH);
|
|
|
|
bcopy(f, (*tl), NFSX_V3FH);
|
|
|
|
} else {
|
|
|
|
nfsm_build_xx((void **)&cp, NFSX_V2FH, mb, bpos);
|
|
|
|
bcopy(f, cp, NFSX_V2FH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nfsm_srvpostop_fh_xx(fhandle_t *f,
|
|
|
|
u_int32_t **tl, struct mbuf **mb, caddr_t *bpos)
|
|
|
|
{
|
|
|
|
nfsm_build_xx((void **)tl, 2 * NFSX_UNSIGNED + NFSX_V3FH, mb, bpos);
|
|
|
|
*(*tl)++ = nfs_true;
|
|
|
|
*(*tl)++ = txdr_unsigned(NFSX_V3FH);
|
|
|
|
bcopy(f, (*tl), NFSX_V3FH);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nfsm_srvstrsiz_xx(int *s, int m,
|
|
|
|
u_int32_t **tl, struct mbuf **md, caddr_t *dpos)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
*s = fxdr_unsigned(int32_t, **tl);
|
|
|
|
if (*s > m || *s <= 0)
|
|
|
|
return EBADRPC;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nfsm_srvnamesiz_xx(int *s,
|
|
|
|
u_int32_t **tl, struct mbuf **md, caddr_t *dpos)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
*s = fxdr_unsigned(int32_t, **tl);
|
|
|
|
if (*s > NFS_MAXNAMLEN)
|
|
|
|
return NFSERR_NAMETOL;
|
|
|
|
if (*s <= 0)
|
|
|
|
return EBADRPC;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nfsm_clget_xx(u_int32_t **tl, struct mbuf *mb, struct mbuf **mp,
|
|
|
|
char **bp, char **be, caddr_t bpos)
|
|
|
|
{
|
|
|
|
struct mbuf *nmp;
|
|
|
|
|
|
|
|
if (*bp >= *be) {
|
|
|
|
if (*mp == mb)
|
|
|
|
(*mp)->m_len += *bp - bpos;
|
|
|
|
MGET(nmp, M_TRYWAIT, MT_DATA);
|
|
|
|
MCLGET(nmp, M_TRYWAIT);
|
|
|
|
nmp->m_len = NFSMSIZ(nmp);
|
|
|
|
(*mp)->m_next = nmp;
|
|
|
|
*mp = nmp;
|
|
|
|
*bp = mtod(*mp, caddr_t);
|
|
|
|
*be = *bp + (*mp)->m_len;
|
|
|
|
}
|
|
|
|
*tl = (u_int32_t *)*bp;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nfsm_srvmtofh_xx(fhandle_t *f, struct nfsrv_descript *nfsd,
|
|
|
|
u_int32_t **tl, struct mbuf **md, caddr_t *dpos)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
int fhlen;
|
|
|
|
|
|
|
|
if (nfsd->nd_flag & ND_NFSV3) {
|
|
|
|
error = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
fhlen = fxdr_unsigned(int, **tl);
|
|
|
|
if (fhlen != 0 && fhlen != NFSX_V3FH)
|
|
|
|
return EBADRPC;
|
|
|
|
} else {
|
|
|
|
fhlen = NFSX_V2FH;
|
|
|
|
}
|
|
|
|
if (fhlen != 0) {
|
|
|
|
error = nfsm_dissect_xx((void **)tl, fhlen, md, dpos);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
bcopy((caddr_t)*tl, (caddr_t)(f), fhlen);
|
|
|
|
} else {
|
|
|
|
bzero((caddr_t)(f), NFSX_V3FH);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nfsm_srvsattr_xx(struct vattr *a,
|
|
|
|
u_int32_t **tl, struct mbuf **md, caddr_t *dpos)
|
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
error = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
|
|
|
|
if (error)
|
|
|
|
goto bugout;
|
|
|
|
if (**tl == nfs_true) {
|
|
|
|
error = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
|
|
|
|
if (error)
|
|
|
|
goto bugout;
|
|
|
|
(a)->va_mode = nfstov_mode(**tl);
|
|
|
|
}
|
|
|
|
error = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
|
|
|
|
if (error)
|
|
|
|
goto bugout;
|
|
|
|
if (**tl == nfs_true) {
|
|
|
|
error = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
|
|
|
|
if (error)
|
|
|
|
goto bugout;
|
|
|
|
(a)->va_uid = fxdr_unsigned(uid_t, **tl);
|
|
|
|
}
|
|
|
|
error = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
|
|
|
|
if (error)
|
|
|
|
goto bugout;
|
|
|
|
if (**tl == nfs_true) {
|
|
|
|
error = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
|
|
|
|
if (error)
|
|
|
|
goto bugout;
|
|
|
|
(a)->va_gid = fxdr_unsigned(gid_t, **tl);
|
|
|
|
}
|
|
|
|
error = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
|
|
|
|
if (error)
|
|
|
|
goto bugout;
|
|
|
|
if (**tl == nfs_true) {
|
|
|
|
error = nfsm_dissect_xx((void **)tl, 2 * NFSX_UNSIGNED,
|
|
|
|
md, dpos);
|
|
|
|
if (error)
|
|
|
|
goto bugout;
|
|
|
|
(a)->va_size = fxdr_hyper(*tl);
|
|
|
|
}
|
|
|
|
error = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
|
|
|
|
if (error)
|
|
|
|
goto bugout;
|
|
|
|
switch (fxdr_unsigned(int, **tl)) {
|
|
|
|
case NFSV3SATTRTIME_TOCLIENT:
|
|
|
|
error = nfsm_dissect_xx((void **)tl, 2 * NFSX_UNSIGNED,
|
|
|
|
md, dpos);
|
|
|
|
if (error)
|
|
|
|
goto bugout;
|
|
|
|
fxdr_nfsv3time(*tl, &(a)->va_atime);
|
|
|
|
break;
|
|
|
|
case NFSV3SATTRTIME_TOSERVER:
|
|
|
|
getnanotime(&(a)->va_atime);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
error = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
|
|
|
|
if (error)
|
|
|
|
goto bugout;
|
|
|
|
switch (fxdr_unsigned(int, **tl)) {
|
|
|
|
case NFSV3SATTRTIME_TOCLIENT:
|
|
|
|
error = nfsm_dissect_xx((void **)tl, 2 * NFSX_UNSIGNED,
|
|
|
|
md, dpos);
|
|
|
|
if (error)
|
|
|
|
goto bugout;
|
|
|
|
fxdr_nfsv3time(*tl, &(a)->va_mtime);
|
|
|
|
break;
|
|
|
|
case NFSV3SATTRTIME_TOSERVER:
|
|
|
|
getnanotime(&(a)->va_mtime);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bugout:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nfs_rephead_xx(int s, struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
|
|
|
|
int error, struct mbuf **mrq, struct mbuf **mb,
|
|
|
|
struct mbuf **mreq, struct mbuf **mrep, caddr_t *bpos)
|
|
|
|
{
|
|
|
|
|
|
|
|
nfs_rephead(s, nfsd, slp, error, mrq, mb, bpos);
|
|
|
|
if (*mrep != NULL) {
|
|
|
|
m_freem(*mrep);
|
|
|
|
*mrep = NULL;
|
|
|
|
}
|
|
|
|
*mreq = *mrq;
|
|
|
|
}
|