2005-11-25 23:01:38 +03:00
|
|
|
/* $NetBSD: nfs_subs.c,v 1.155 2005/11/25 20:01:38 thorpej Exp $ */
|
1994-06-29 10:39:25 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-06-08 15:33:09 +04:00
|
|
|
* Copyright (c) 1989, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* 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.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
* 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.
|
|
|
|
*
|
1996-02-18 14:53:36 +03:00
|
|
|
* @(#)nfs_subs.c 8.8 (Berkeley) 5/22/95
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
2000-09-20 02:13:55 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2000 Wasabi Systems, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Written by Frank van der Linden for Wasabi Systems, Inc.
|
|
|
|
*
|
|
|
|
* 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 for the NetBSD Project by
|
|
|
|
* Wasabi Systems, Inc.
|
|
|
|
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2001-11-10 13:59:08 +03:00
|
|
|
#include <sys/cdefs.h>
|
2005-11-25 23:01:38 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: nfs_subs.c,v 1.155 2005/11/25 20:01:38 thorpej Exp $");
|
2001-11-10 13:59:08 +03:00
|
|
|
|
1998-02-19 03:54:13 +03:00
|
|
|
#include "fs_nfs.h"
|
2000-09-19 21:04:50 +04:00
|
|
|
#include "opt_nfs.h"
|
1998-06-26 02:17:36 +04:00
|
|
|
#include "opt_nfsserver.h"
|
1998-07-05 08:37:35 +04:00
|
|
|
#include "opt_iso.h"
|
2000-06-09 04:00:17 +04:00
|
|
|
#include "opt_inet.h"
|
1996-02-18 14:53:36 +03:00
|
|
|
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
*/
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/mbuf.h>
|
1994-06-08 15:33:09 +04:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/stat.h>
|
1996-02-18 14:53:36 +03:00
|
|
|
#include <sys/malloc.h>
|
2001-09-28 01:44:56 +04:00
|
|
|
#include <sys/filedesc.h>
|
1996-07-07 16:23:49 +04:00
|
|
|
#include <sys/time.h>
|
1997-06-25 03:36:02 +04:00
|
|
|
#include <sys/dirent.h>
|
2005-11-25 23:01:38 +03:00
|
|
|
#include <sys/once.h>
|
1996-02-18 14:53:36 +03:00
|
|
|
|
1998-02-05 10:59:28 +03:00
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <nfs/rpcv2.h>
|
1996-02-18 14:53:36 +03:00
|
|
|
#include <nfs/nfsproto.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <nfs/nfsnode.h>
|
|
|
|
#include <nfs/nfs.h>
|
|
|
|
#include <nfs/xdr_subs.h>
|
|
|
|
#include <nfs/nfsm_subs.h>
|
1994-06-08 15:33:09 +04:00
|
|
|
#include <nfs/nfsmount.h>
|
|
|
|
#include <nfs/nqnfs.h>
|
|
|
|
#include <nfs/nfsrtt.h>
|
1996-02-10 00:48:19 +03:00
|
|
|
#include <nfs/nfs_var.h>
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
#include <miscfs/specfs/specdev.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#ifdef ISO
|
|
|
|
#include <netiso/iso.h>
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Data items converted to xdr at startup, since they are constant
|
|
|
|
* This is kinda hokey, but may save a little time doing byte swaps
|
|
|
|
*/
|
1995-12-20 02:07:11 +03:00
|
|
|
u_int32_t nfs_xdrneg1;
|
|
|
|
u_int32_t rpc_call, rpc_vers, rpc_reply, rpc_msgdenied, rpc_autherr,
|
1996-02-18 14:53:36 +03:00
|
|
|
rpc_mismatch, rpc_auth_unix, rpc_msgaccepted,
|
1994-06-08 15:33:09 +04:00
|
|
|
rpc_auth_kerb;
|
1996-02-18 14:53:36 +03:00
|
|
|
u_int32_t nfs_prog, nqnfs_prog, nfs_true, nfs_false;
|
1993-04-11 00:19:19 +04:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/* And other global data */
|
2001-01-18 23:28:15 +03:00
|
|
|
const nfstype nfsv2_type[9] =
|
|
|
|
{ NFNON, NFREG, NFDIR, NFBLK, NFCHR, NFLNK, NFNON, NFCHR, NFNON };
|
|
|
|
const nfstype nfsv3_type[9] =
|
|
|
|
{ NFNON, NFREG, NFDIR, NFBLK, NFCHR, NFLNK, NFSOCK, NFFIFO, NFNON };
|
|
|
|
const enum vtype nv2tov_type[8] =
|
|
|
|
{ VNON, VREG, VDIR, VBLK, VCHR, VLNK, VNON, VNON };
|
|
|
|
const enum vtype nv3tov_type[8] =
|
|
|
|
{ VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO };
|
1996-02-18 14:53:36 +03:00
|
|
|
int nfs_ticks;
|
2002-01-26 05:52:19 +03:00
|
|
|
int nfs_commitsize;
|
1996-02-18 14:53:36 +03:00
|
|
|
|
2003-02-10 20:31:01 +03:00
|
|
|
MALLOC_DEFINE(M_NFSDIROFF, "NFS diroff", "NFS directory cookies");
|
|
|
|
|
1996-12-03 03:22:43 +03:00
|
|
|
/* NFS client/server stats. */
|
|
|
|
struct nfsstats nfsstats;
|
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
/*
|
|
|
|
* Mapping of old NFS Version 2 RPC numbers to generic numbers.
|
|
|
|
*/
|
2001-01-18 23:28:15 +03:00
|
|
|
const int nfsv3_procid[NFS_NPROCS] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
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,
|
|
|
|
NFSPROC_NOOP,
|
|
|
|
NFSPROC_NOOP,
|
|
|
|
NFSPROC_NOOP
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* and the reverse mapping from generic to Version 2 procedure numbers
|
|
|
|
*/
|
2001-01-18 23:28:15 +03:00
|
|
|
const int nfsv2_procid[NFS_NPROCS] = {
|
1996-02-18 14:53:36 +03: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,
|
|
|
|
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.
|
|
|
|
*/
|
2001-01-18 23:28:15 +03:00
|
|
|
static const u_char nfsrv_v2errmap[ELAST] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
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-02-06 11:22:54 +03:00
|
|
|
NFSERR_IO, NFSERR_IO,
|
1996-02-18 14:53:36 +03: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.
|
|
|
|
*/
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short nfsv3err_null[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short nfsv3err_getattr[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short nfsv3err_setattr[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short nfsv3err_lookup[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_NOENT,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_ACCES,
|
|
|
|
NFSERR_NOTDIR,
|
|
|
|
NFSERR_NAMETOL,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short nfsv3err_access[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short nfsv3err_readlink[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_ACCES,
|
|
|
|
NFSERR_INVAL,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_NOTSUPP,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short nfsv3err_read[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_NXIO,
|
|
|
|
NFSERR_ACCES,
|
|
|
|
NFSERR_INVAL,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_SERVERFAULT,
|
1999-03-17 02:22:57 +03:00
|
|
|
NFSERR_JUKEBOX,
|
1996-02-18 14:53:36 +03:00
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short nfsv3err_write[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_ACCES,
|
|
|
|
NFSERR_INVAL,
|
|
|
|
NFSERR_FBIG,
|
|
|
|
NFSERR_NOSPC,
|
|
|
|
NFSERR_ROFS,
|
|
|
|
NFSERR_DQUOT,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_SERVERFAULT,
|
1999-03-17 02:24:28 +03:00
|
|
|
NFSERR_JUKEBOX,
|
1996-02-18 14:53:36 +03:00
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short nfsv3err_create[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short nfsv3err_mkdir[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short nfsv3err_symlink[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short nfsv3err_mknod[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short nfsv3err_remove[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_NOENT,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_ACCES,
|
|
|
|
NFSERR_NOTDIR,
|
|
|
|
NFSERR_ROFS,
|
|
|
|
NFSERR_NAMETOL,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short nfsv3err_rmdir[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short nfsv3err_rename[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short nfsv3err_link[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short nfsv3err_readdir[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_ACCES,
|
|
|
|
NFSERR_NOTDIR,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_BAD_COOKIE,
|
|
|
|
NFSERR_TOOSMALL,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short nfsv3err_readdirplus[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_ACCES,
|
|
|
|
NFSERR_NOTDIR,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_BAD_COOKIE,
|
|
|
|
NFSERR_NOTSUPP,
|
|
|
|
NFSERR_TOOSMALL,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short nfsv3err_fsstat[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short nfsv3err_fsinfo[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short nfsv3err_pathconf[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short nfsv3err_commit[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_IO,
|
|
|
|
NFSERR_STALE,
|
|
|
|
NFSERR_BADHANDLE,
|
|
|
|
NFSERR_SERVERFAULT,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2001-01-18 23:28:15 +03:00
|
|
|
static const short * const nfsrv_v3errmap[] = {
|
1996-02-18 14:53:36 +03:00
|
|
|
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-06-08 15:33:09 +04:00
|
|
|
extern struct nfsrtt nfsrtt;
|
|
|
|
extern time_t nqnfsstarttime;
|
|
|
|
extern int nqsrv_clockskew;
|
|
|
|
extern int nqsrv_writeslack;
|
|
|
|
extern int nqsrv_maxlease;
|
2001-02-22 00:39:52 +03:00
|
|
|
extern const int nqnfs_piggy[NFS_NPROCS];
|
1996-02-18 14:53:36 +03:00
|
|
|
extern struct nfsnodehashhead *nfsnodehashtbl;
|
|
|
|
extern u_long nfsnodehash;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-10 05:53:17 +04:00
|
|
|
u_long nfsdirhashmask;
|
1994-08-19 02:47:43 +04:00
|
|
|
|
1997-06-25 03:36:02 +04:00
|
|
|
int nfs_webnamei __P((struct nameidata *, struct vnode *, struct proc *));
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Create the header for an rpc request packet
|
|
|
|
* The hsiz is the size of the rest of the nfs request header.
|
|
|
|
* (just used to decide if a cluster is a good idea)
|
|
|
|
*/
|
1994-06-08 15:33:09 +04:00
|
|
|
struct mbuf *
|
2003-04-25 01:21:04 +04:00
|
|
|
nfsm_reqh(np, procid, hsiz, bposp)
|
|
|
|
struct nfsnode *np;
|
1993-03-21 12:45:37 +03:00
|
|
|
u_long procid;
|
|
|
|
int hsiz;
|
1994-06-08 15:33:09 +04:00
|
|
|
caddr_t *bposp;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mbuf *mb;
|
|
|
|
caddr_t bpos;
|
2000-09-27 22:36:03 +04:00
|
|
|
#ifndef NFS_V2_ONLY
|
2003-04-25 01:21:04 +04:00
|
|
|
struct nfsmount *nmp;
|
2000-09-27 22:36:03 +04:00
|
|
|
u_int32_t *tl;
|
1994-06-08 15:33:09 +04:00
|
|
|
int nqflag;
|
2000-09-27 22:36:03 +04:00
|
|
|
#endif
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2003-02-26 09:31:08 +03:00
|
|
|
mb = m_get(M_WAIT, MT_DATA);
|
|
|
|
MCLAIM(mb, &nfs_mowner);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (hsiz >= MINCLSIZE)
|
2003-02-26 09:31:08 +03:00
|
|
|
m_clget(mb, M_WAIT);
|
1994-06-08 15:33:09 +04:00
|
|
|
mb->m_len = 0;
|
|
|
|
bpos = mtod(mb, caddr_t);
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2003-04-25 01:21:04 +04:00
|
|
|
#ifndef NFS_V2_ONLY
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-06-08 15:33:09 +04:00
|
|
|
* For NQNFS, add lease request.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2003-04-25 01:21:04 +04:00
|
|
|
if (np) {
|
|
|
|
nmp = VFSTONFS(np->n_vnode->v_mount);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (nmp->nm_flag & NFSMNT_NQNFS) {
|
2003-04-25 01:21:04 +04:00
|
|
|
nqflag = NQNFS_NEEDLEASE(np, procid);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (nqflag) {
|
1995-12-20 02:07:11 +03:00
|
|
|
nfsm_build(tl, u_int32_t *, 2*NFSX_UNSIGNED);
|
1994-06-08 15:33:09 +04:00
|
|
|
*tl++ = txdr_unsigned(nqflag);
|
|
|
|
*tl = txdr_unsigned(nmp->nm_leaseterm);
|
|
|
|
} else {
|
1995-12-20 02:07:11 +03:00
|
|
|
nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
|
1994-06-08 15:33:09 +04:00
|
|
|
*tl = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-04-25 01:21:04 +04:00
|
|
|
#endif
|
1994-06-08 15:33:09 +04:00
|
|
|
/* Finally, return values */
|
|
|
|
*bposp = bpos;
|
|
|
|
return (mb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Build the RPC header and fill in the authorization info.
|
|
|
|
* The authorization string argument is only used when the credentials
|
|
|
|
* come from outside of the kernel.
|
|
|
|
* Returns the head of the mbuf list.
|
|
|
|
*/
|
|
|
|
struct mbuf *
|
1996-02-18 14:53:36 +03:00
|
|
|
nfsm_rpchead(cr, nmflag, procid, auth_type, auth_len, auth_str, verf_len,
|
|
|
|
verf_str, mrest, mrest_len, mbp, xidp)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct ucred *cr;
|
1996-02-18 14:53:36 +03:00
|
|
|
int nmflag;
|
1994-06-08 15:33:09 +04:00
|
|
|
int procid;
|
|
|
|
int auth_type;
|
|
|
|
int auth_len;
|
|
|
|
char *auth_str;
|
1996-02-18 14:53:36 +03:00
|
|
|
int verf_len;
|
|
|
|
char *verf_str;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct mbuf *mrest;
|
|
|
|
int mrest_len;
|
|
|
|
struct mbuf **mbp;
|
1995-12-20 02:07:11 +03:00
|
|
|
u_int32_t *xidp;
|
1994-06-08 15:33:09 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mbuf *mb;
|
|
|
|
u_int32_t *tl;
|
|
|
|
caddr_t bpos;
|
|
|
|
int i;
|
2003-02-26 09:31:08 +03:00
|
|
|
struct mbuf *mreq;
|
1994-06-08 15:33:09 +04:00
|
|
|
int siz, grpsiz, authsiz;
|
|
|
|
|
|
|
|
authsiz = nfsm_rndup(auth_len);
|
2003-02-26 09:31:08 +03:00
|
|
|
mb = m_gethdr(M_WAIT, MT_DATA);
|
|
|
|
MCLAIM(mb, &nfs_mowner);
|
1996-02-18 14:53:36 +03:00
|
|
|
if ((authsiz + 10 * NFSX_UNSIGNED) >= MINCLSIZE) {
|
2003-02-26 09:31:08 +03:00
|
|
|
m_clget(mb, M_WAIT);
|
1996-02-18 14:53:36 +03:00
|
|
|
} else if ((authsiz + 10 * NFSX_UNSIGNED) < MHLEN) {
|
|
|
|
MH_ALIGN(mb, authsiz + 10 * NFSX_UNSIGNED);
|
1994-06-08 15:33:09 +04:00
|
|
|
} else {
|
1996-02-18 14:53:36 +03:00
|
|
|
MH_ALIGN(mb, 8 * NFSX_UNSIGNED);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
mb->m_len = 0;
|
|
|
|
mreq = mb;
|
|
|
|
bpos = mtod(mb, caddr_t);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First the RPC header.
|
|
|
|
*/
|
1996-02-18 14:53:36 +03:00
|
|
|
nfsm_build(tl, u_int32_t *, 8 * NFSX_UNSIGNED);
|
1996-07-07 16:23:49 +04:00
|
|
|
|
2003-07-23 17:52:23 +04:00
|
|
|
*tl++ = *xidp = nfs_getxid();
|
1993-03-21 12:45:37 +03:00
|
|
|
*tl++ = rpc_call;
|
|
|
|
*tl++ = rpc_vers;
|
1996-02-18 14:53:36 +03:00
|
|
|
if (nmflag & NFSMNT_NQNFS) {
|
1994-06-08 15:33:09 +04:00
|
|
|
*tl++ = txdr_unsigned(NQNFS_PROG);
|
1996-02-18 14:53:36 +03:00
|
|
|
*tl++ = txdr_unsigned(NQNFS_VER3);
|
1993-03-21 12:45:37 +03:00
|
|
|
} else {
|
1994-06-08 15:33:09 +04:00
|
|
|
*tl++ = txdr_unsigned(NFS_PROG);
|
1996-02-18 14:53:36 +03:00
|
|
|
if (nmflag & NFSMNT_NFSV3)
|
|
|
|
*tl++ = txdr_unsigned(NFS_VER3);
|
|
|
|
else
|
|
|
|
*tl++ = txdr_unsigned(NFS_VER2);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1996-02-18 14:53:36 +03:00
|
|
|
if (nmflag & NFSMNT_NFSV3)
|
|
|
|
*tl++ = txdr_unsigned(procid);
|
|
|
|
else
|
|
|
|
*tl++ = txdr_unsigned(nfsv2_procid[procid]);
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* And then the authorization cred.
|
|
|
|
*/
|
|
|
|
*tl++ = txdr_unsigned(auth_type);
|
|
|
|
*tl = txdr_unsigned(authsiz);
|
|
|
|
switch (auth_type) {
|
|
|
|
case RPCAUTH_UNIX:
|
1995-12-20 02:07:11 +03:00
|
|
|
nfsm_build(tl, u_int32_t *, auth_len);
|
1994-06-08 15:33:09 +04:00
|
|
|
*tl++ = 0; /* stamp ?? */
|
|
|
|
*tl++ = 0; /* NULL hostname */
|
|
|
|
*tl++ = txdr_unsigned(cr->cr_uid);
|
1995-06-02 02:43:30 +04:00
|
|
|
*tl++ = txdr_unsigned(cr->cr_gid);
|
1994-06-08 15:33:09 +04:00
|
|
|
grpsiz = (auth_len >> 2) - 5;
|
|
|
|
*tl++ = txdr_unsigned(grpsiz);
|
1995-06-02 22:35:50 +04:00
|
|
|
for (i = 0; i < grpsiz; i++)
|
1994-06-08 15:33:09 +04:00
|
|
|
*tl++ = txdr_unsigned(cr->cr_groups[i]);
|
|
|
|
break;
|
1996-02-18 14:53:36 +03:00
|
|
|
case RPCAUTH_KERB4:
|
1994-06-08 15:33:09 +04:00
|
|
|
siz = auth_len;
|
|
|
|
while (siz > 0) {
|
|
|
|
if (M_TRAILINGSPACE(mb) == 0) {
|
2003-02-26 09:31:08 +03:00
|
|
|
struct mbuf *mb2;
|
|
|
|
mb2 = m_get(M_WAIT, MT_DATA);
|
|
|
|
MCLAIM(mb2, &nfs_mowner);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (siz >= MINCLSIZE)
|
2003-02-26 09:31:08 +03:00
|
|
|
m_clget(mb2, M_WAIT);
|
1994-06-08 15:33:09 +04:00
|
|
|
mb->m_next = mb2;
|
|
|
|
mb = mb2;
|
|
|
|
mb->m_len = 0;
|
|
|
|
bpos = mtod(mb, caddr_t);
|
|
|
|
}
|
|
|
|
i = min(siz, M_TRAILINGSPACE(mb));
|
1998-08-10 00:51:08 +04:00
|
|
|
memcpy(bpos, auth_str, i);
|
1994-06-08 15:33:09 +04:00
|
|
|
mb->m_len += i;
|
|
|
|
auth_str += i;
|
|
|
|
bpos += i;
|
|
|
|
siz -= i;
|
|
|
|
}
|
|
|
|
if ((siz = (nfsm_rndup(auth_len) - auth_len)) > 0) {
|
|
|
|
for (i = 0; i < siz; i++)
|
|
|
|
*bpos++ = '\0';
|
|
|
|
mb->m_len += siz;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
};
|
1996-02-18 14:53:36 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* And the verifier...
|
|
|
|
*/
|
|
|
|
nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
|
|
|
|
if (verf_str) {
|
|
|
|
*tl++ = txdr_unsigned(RPCAUTH_KERB4);
|
|
|
|
*tl = txdr_unsigned(verf_len);
|
|
|
|
siz = verf_len;
|
|
|
|
while (siz > 0) {
|
|
|
|
if (M_TRAILINGSPACE(mb) == 0) {
|
2003-02-26 09:31:08 +03:00
|
|
|
struct mbuf *mb2;
|
|
|
|
mb2 = m_get(M_WAIT, MT_DATA);
|
|
|
|
MCLAIM(mb2, &nfs_mowner);
|
1996-02-18 14:53:36 +03:00
|
|
|
if (siz >= MINCLSIZE)
|
2003-02-26 09:31:08 +03:00
|
|
|
m_clget(mb2, M_WAIT);
|
1996-02-18 14:53:36 +03:00
|
|
|
mb->m_next = mb2;
|
|
|
|
mb = mb2;
|
|
|
|
mb->m_len = 0;
|
|
|
|
bpos = mtod(mb, caddr_t);
|
|
|
|
}
|
|
|
|
i = min(siz, M_TRAILINGSPACE(mb));
|
1998-08-10 00:51:08 +04:00
|
|
|
memcpy(bpos, verf_str, i);
|
1996-02-18 14:53:36 +03:00
|
|
|
mb->m_len += i;
|
|
|
|
verf_str += i;
|
|
|
|
bpos += i;
|
|
|
|
siz -= i;
|
|
|
|
}
|
|
|
|
if ((siz = (nfsm_rndup(verf_len) - verf_len)) > 0) {
|
|
|
|
for (i = 0; i < siz; i++)
|
|
|
|
*bpos++ = '\0';
|
|
|
|
mb->m_len += siz;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*tl++ = txdr_unsigned(RPCAUTH_NULL);
|
|
|
|
*tl = 0;
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
mb->m_next = mrest;
|
1996-02-18 14:53:36 +03:00
|
|
|
mreq->m_pkthdr.len = authsiz + 10 * NFSX_UNSIGNED + mrest_len;
|
1994-06-08 15:33:09 +04:00
|
|
|
mreq->m_pkthdr.rcvif = (struct ifnet *)0;
|
|
|
|
*mbp = mb;
|
1993-03-21 12:45:37 +03:00
|
|
|
return (mreq);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* copies mbuf chain to the uio scatter/gather list
|
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
nfsm_mbuftouio(mrep, uiop, siz, dpos)
|
|
|
|
struct mbuf **mrep;
|
2000-03-30 16:51:13 +04:00
|
|
|
struct uio *uiop;
|
1993-03-21 12:45:37 +03:00
|
|
|
int siz;
|
|
|
|
caddr_t *dpos;
|
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
char *mbufcp, *uiocp;
|
|
|
|
int xfer, left, len;
|
|
|
|
struct mbuf *mp;
|
1993-03-21 12:45:37 +03:00
|
|
|
long uiosiz, rem;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
mp = *mrep;
|
|
|
|
mbufcp = *dpos;
|
|
|
|
len = mtod(mp, caddr_t)+mp->m_len-mbufcp;
|
|
|
|
rem = nfsm_rndup(siz)-siz;
|
|
|
|
while (siz > 0) {
|
|
|
|
if (uiop->uio_iovcnt <= 0 || uiop->uio_iov == NULL)
|
|
|
|
return (EFBIG);
|
|
|
|
left = uiop->uio_iov->iov_len;
|
|
|
|
uiocp = uiop->uio_iov->iov_base;
|
|
|
|
if (left > siz)
|
|
|
|
left = siz;
|
|
|
|
uiosiz = left;
|
|
|
|
while (left > 0) {
|
|
|
|
while (len == 0) {
|
|
|
|
mp = mp->m_next;
|
|
|
|
if (mp == NULL)
|
|
|
|
return (EBADRPC);
|
|
|
|
mbufcp = mtod(mp, caddr_t);
|
|
|
|
len = mp->m_len;
|
|
|
|
}
|
|
|
|
xfer = (left > len) ? len : left;
|
|
|
|
#ifdef notdef
|
|
|
|
/* Not Yet.. */
|
|
|
|
if (uiop->uio_iov->iov_op != NULL)
|
|
|
|
(*(uiop->uio_iov->iov_op))
|
|
|
|
(mbufcp, uiocp, xfer);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if (uiop->uio_segflg == UIO_SYSSPACE)
|
1998-08-10 00:51:08 +04:00
|
|
|
memcpy(uiocp, mbufcp, xfer);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
2005-07-07 06:05:03 +04:00
|
|
|
if ((error = copyout_proc(uiop->uio_procp,
|
|
|
|
mbufcp, uiocp, xfer)) != 0)
|
|
|
|
return error;
|
1993-03-21 12:45:37 +03:00
|
|
|
left -= xfer;
|
|
|
|
len -= xfer;
|
|
|
|
mbufcp += xfer;
|
|
|
|
uiocp += xfer;
|
|
|
|
uiop->uio_offset += xfer;
|
|
|
|
uiop->uio_resid -= xfer;
|
|
|
|
}
|
|
|
|
if (uiop->uio_iov->iov_len <= siz) {
|
|
|
|
uiop->uio_iovcnt--;
|
|
|
|
uiop->uio_iov++;
|
|
|
|
} else {
|
2001-06-07 05:04:40 +04:00
|
|
|
uiop->uio_iov->iov_base =
|
|
|
|
(caddr_t)uiop->uio_iov->iov_base + uiosiz;
|
1993-03-21 12:45:37 +03:00
|
|
|
uiop->uio_iov->iov_len -= uiosiz;
|
|
|
|
}
|
|
|
|
siz -= uiosiz;
|
|
|
|
}
|
|
|
|
*dpos = mbufcp;
|
|
|
|
*mrep = mp;
|
|
|
|
if (rem > 0) {
|
|
|
|
if (len < rem)
|
|
|
|
error = nfs_adv(mrep, dpos, rem, len);
|
|
|
|
else
|
|
|
|
*dpos += rem;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1996-07-01 14:22:47 +04:00
|
|
|
* copies a uio scatter/gather list to an mbuf chain.
|
|
|
|
* NOTE: can ony handle iovcnt == 1
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
nfsm_uiotombuf(uiop, mq, siz, bpos)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct uio *uiop;
|
1993-03-21 12:45:37 +03:00
|
|
|
struct mbuf **mq;
|
|
|
|
int siz;
|
|
|
|
caddr_t *bpos;
|
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
char *uiocp;
|
|
|
|
struct mbuf *mp, *mp2;
|
|
|
|
int xfer, left, mlen;
|
1993-03-21 12:45:37 +03:00
|
|
|
int uiosiz, clflg, rem;
|
|
|
|
char *cp;
|
|
|
|
|
1996-07-01 14:22:47 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (uiop->uio_iovcnt != 1)
|
|
|
|
panic("nfsm_uiotombuf: iovcnt != 1");
|
|
|
|
#endif
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (siz > MLEN) /* or should it >= MCLBYTES ?? */
|
|
|
|
clflg = 1;
|
|
|
|
else
|
|
|
|
clflg = 0;
|
|
|
|
rem = nfsm_rndup(siz)-siz;
|
1994-06-08 15:33:09 +04:00
|
|
|
mp = mp2 = *mq;
|
1993-03-21 12:45:37 +03:00
|
|
|
while (siz > 0) {
|
|
|
|
left = uiop->uio_iov->iov_len;
|
|
|
|
uiocp = uiop->uio_iov->iov_base;
|
|
|
|
if (left > siz)
|
|
|
|
left = siz;
|
|
|
|
uiosiz = left;
|
|
|
|
while (left > 0) {
|
1994-06-08 15:33:09 +04:00
|
|
|
mlen = M_TRAILINGSPACE(mp);
|
|
|
|
if (mlen == 0) {
|
2003-02-26 09:31:08 +03:00
|
|
|
mp = m_get(M_WAIT, MT_DATA);
|
|
|
|
MCLAIM(mp, &nfs_mowner);
|
1994-06-08 15:33:09 +04:00
|
|
|
if (clflg)
|
2003-02-26 09:31:08 +03:00
|
|
|
m_clget(mp, M_WAIT);
|
1994-06-08 15:33:09 +04:00
|
|
|
mp->m_len = 0;
|
|
|
|
mp2->m_next = mp;
|
|
|
|
mp2 = mp;
|
|
|
|
mlen = M_TRAILINGSPACE(mp);
|
|
|
|
}
|
|
|
|
xfer = (left > mlen) ? mlen : left;
|
2005-07-07 06:05:03 +04:00
|
|
|
cp = mtod(mp, caddr_t) + mp->m_len;
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifdef notdef
|
|
|
|
/* Not Yet.. */
|
|
|
|
if (uiop->uio_iov->iov_op != NULL)
|
2005-07-07 06:05:03 +04:00
|
|
|
(*(uiop->uio_iov->iov_op))(uiocp, cp, xfer);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if (uiop->uio_segflg == UIO_SYSSPACE)
|
2005-07-07 06:05:03 +04:00
|
|
|
(void)memcpy(cp, uiocp, xfer);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
2005-07-07 06:05:03 +04:00
|
|
|
/*XXX: Check error */
|
|
|
|
(void)copyin_proc(uiop->uio_procp, uiocp,
|
|
|
|
cp, xfer);
|
1994-06-08 15:33:09 +04:00
|
|
|
mp->m_len += xfer;
|
1993-03-21 12:45:37 +03:00
|
|
|
left -= xfer;
|
|
|
|
uiocp += xfer;
|
|
|
|
uiop->uio_offset += xfer;
|
|
|
|
uiop->uio_resid -= xfer;
|
|
|
|
}
|
2001-06-07 05:04:40 +04:00
|
|
|
uiop->uio_iov->iov_base = (caddr_t)uiop->uio_iov->iov_base +
|
|
|
|
uiosiz;
|
1996-07-01 14:22:47 +04:00
|
|
|
uiop->uio_iov->iov_len -= uiosiz;
|
1993-03-21 12:45:37 +03:00
|
|
|
siz -= uiosiz;
|
|
|
|
}
|
|
|
|
if (rem > 0) {
|
1994-06-08 15:33:09 +04:00
|
|
|
if (rem > M_TRAILINGSPACE(mp)) {
|
2003-02-26 09:31:08 +03:00
|
|
|
mp = m_get(M_WAIT, MT_DATA);
|
|
|
|
MCLAIM(mp, &nfs_mowner);
|
1993-03-21 12:45:37 +03:00
|
|
|
mp->m_len = 0;
|
|
|
|
mp2->m_next = mp;
|
|
|
|
}
|
2005-07-07 06:05:03 +04:00
|
|
|
cp = mtod(mp, caddr_t) + mp->m_len;
|
1993-03-21 12:45:37 +03:00
|
|
|
for (left = 0; left < rem; left++)
|
|
|
|
*cp++ = '\0';
|
|
|
|
mp->m_len += rem;
|
|
|
|
*bpos = cp;
|
|
|
|
} else
|
|
|
|
*bpos = mtod(mp, caddr_t)+mp->m_len;
|
|
|
|
*mq = mp;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-02-22 06:03:03 +03:00
|
|
|
* Get at least "siz" bytes of correctly aligned data.
|
|
|
|
* When called the mbuf pointers are not necessarily correct,
|
|
|
|
* dsosp points to what ought to be in m_data and left contains
|
2005-02-27 01:31:44 +03:00
|
|
|
* what ought to be in m_len.
|
1994-06-08 15:33:09 +04:00
|
|
|
* This is used by the macros nfsm_dissect and nfsm_dissecton for tough
|
1993-03-21 12:45:37 +03:00
|
|
|
* cases. (The macros use the vars. dpos and dpos2)
|
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
int
|
1994-06-08 15:33:09 +04:00
|
|
|
nfsm_disct(mdp, dposp, siz, left, cp2)
|
1993-03-21 12:45:37 +03:00
|
|
|
struct mbuf **mdp;
|
|
|
|
caddr_t *dposp;
|
|
|
|
int siz;
|
|
|
|
int left;
|
|
|
|
caddr_t *cp2;
|
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mbuf *m1, *m2;
|
1997-02-22 06:03:03 +03:00
|
|
|
struct mbuf *havebuf = NULL;
|
|
|
|
caddr_t src = *dposp;
|
|
|
|
caddr_t dst;
|
|
|
|
int len;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-02-22 06:03:03 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (left < 0)
|
2005-02-27 01:31:44 +03:00
|
|
|
panic("nfsm_disct: left < 0");
|
1997-02-22 06:03:03 +03:00
|
|
|
#endif
|
|
|
|
m1 = *mdp;
|
|
|
|
/*
|
|
|
|
* Skip through the mbuf chain looking for an mbuf with
|
|
|
|
* some data. If the first mbuf found has enough data
|
|
|
|
* and it is correctly aligned return it.
|
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
while (left == 0) {
|
1997-02-22 06:03:03 +03:00
|
|
|
havebuf = m1;
|
|
|
|
*mdp = m1 = m1->m_next;
|
|
|
|
if (m1 == NULL)
|
1993-03-21 12:45:37 +03:00
|
|
|
return (EBADRPC);
|
1997-02-22 06:03:03 +03:00
|
|
|
src = mtod(m1, caddr_t);
|
|
|
|
left = m1->m_len;
|
|
|
|
/*
|
|
|
|
* If we start a new mbuf and it is big enough
|
|
|
|
* and correctly aligned just return it, don't
|
|
|
|
* do any pull up.
|
|
|
|
*/
|
|
|
|
if (left >= siz && nfsm_aligned(src)) {
|
|
|
|
*cp2 = src;
|
|
|
|
*dposp = src + siz;
|
|
|
|
return (0);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-02-22 06:03:03 +03:00
|
|
|
if (m1->m_flags & M_EXT) {
|
|
|
|
if (havebuf) {
|
|
|
|
/* If the first mbuf with data has external data
|
|
|
|
* and there is a previous empty mbuf use it
|
|
|
|
* to move the data into.
|
|
|
|
*/
|
|
|
|
m2 = m1;
|
|
|
|
*mdp = m1 = havebuf;
|
|
|
|
if (m1->m_flags & M_EXT) {
|
1997-03-27 23:40:09 +03:00
|
|
|
MEXTREMOVE(m1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-02-22 06:03:03 +03:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If the first mbuf has a external data
|
|
|
|
* and there is no previous empty mbuf
|
|
|
|
* allocate a new mbuf and move the external
|
2005-02-27 01:31:44 +03:00
|
|
|
* data to the new mbuf. Also make the first
|
1997-02-22 06:03:03 +03:00
|
|
|
* mbuf look empty.
|
|
|
|
*/
|
|
|
|
m2 = m_get(M_WAIT, MT_DATA);
|
|
|
|
m2->m_ext = m1->m_ext;
|
|
|
|
m2->m_data = src;
|
|
|
|
m2->m_len = left;
|
1997-03-27 23:40:09 +03:00
|
|
|
MCLADDREFERENCE(m1, m2);
|
|
|
|
MEXTREMOVE(m1);
|
1997-02-22 06:03:03 +03:00
|
|
|
m2->m_next = m1->m_next;
|
|
|
|
m1->m_next = m2;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-02-22 06:03:03 +03:00
|
|
|
m1->m_len = 0;
|
2003-10-02 10:01:51 +04:00
|
|
|
if (m1->m_flags & M_PKTHDR)
|
|
|
|
dst = m1->m_pktdat;
|
|
|
|
else
|
|
|
|
dst = m1->m_dat;
|
|
|
|
m1->m_data = dst;
|
1997-02-22 06:03:03 +03:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If the first mbuf has no external data
|
|
|
|
* move the data to the front of the mbuf.
|
|
|
|
*/
|
2003-10-02 10:01:51 +04:00
|
|
|
if (m1->m_flags & M_PKTHDR)
|
|
|
|
dst = m1->m_pktdat;
|
|
|
|
else
|
|
|
|
dst = m1->m_dat;
|
|
|
|
m1->m_data = dst;
|
|
|
|
if (dst != src)
|
1998-08-10 00:51:08 +04:00
|
|
|
memmove(dst, src, left);
|
2005-02-27 01:31:44 +03:00
|
|
|
dst += left;
|
1997-02-22 06:03:03 +03:00
|
|
|
m1->m_len = left;
|
|
|
|
m2 = m1->m_next;
|
|
|
|
}
|
2003-10-02 10:01:51 +04:00
|
|
|
*cp2 = m1->m_data;
|
1997-02-22 06:03:03 +03:00
|
|
|
*dposp = mtod(m1, caddr_t) + siz;
|
|
|
|
/*
|
|
|
|
* Loop through mbufs pulling data up into first mbuf until
|
|
|
|
* the first mbuf is full or there is no more data to
|
|
|
|
* pullup.
|
|
|
|
*/
|
2003-10-02 10:01:51 +04:00
|
|
|
while ((len = M_TRAILINGSPACE(m1)) != 0 && m2) {
|
1997-02-22 06:03:03 +03:00
|
|
|
if ((len = min(len, m2->m_len)) != 0)
|
1998-08-10 00:51:08 +04:00
|
|
|
memcpy(dst, m2->m_data, len);
|
1997-02-22 06:03:03 +03:00
|
|
|
m1->m_len += len;
|
|
|
|
dst += len;
|
|
|
|
m2->m_data += len;
|
|
|
|
m2->m_len -= len;
|
|
|
|
m2 = m2->m_next;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-02-22 06:03:03 +03:00
|
|
|
if (m1->m_len < siz)
|
|
|
|
return (EBADRPC);
|
1993-03-21 12:45:37 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Advance the position in the mbuf chain.
|
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
nfs_adv(mdp, dposp, offs, left)
|
|
|
|
struct mbuf **mdp;
|
|
|
|
caddr_t *dposp;
|
|
|
|
int offs;
|
|
|
|
int left;
|
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mbuf *m;
|
|
|
|
int s;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
m = *mdp;
|
|
|
|
s = left;
|
|
|
|
while (s < offs) {
|
|
|
|
offs -= s;
|
|
|
|
m = m->m_next;
|
|
|
|
if (m == NULL)
|
|
|
|
return (EBADRPC);
|
|
|
|
s = m->m_len;
|
|
|
|
}
|
|
|
|
*mdp = m;
|
|
|
|
*dposp = mtod(m, caddr_t)+offs;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy a string into mbufs for the hard cases...
|
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
nfsm_strtmbuf(mb, bpos, cp, siz)
|
|
|
|
struct mbuf **mb;
|
|
|
|
char **bpos;
|
1996-10-26 03:13:58 +04:00
|
|
|
const char *cp;
|
1993-03-21 12:45:37 +03:00
|
|
|
long siz;
|
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mbuf *m1 = NULL, *m2;
|
1993-03-21 12:45:37 +03:00
|
|
|
long left, xfer, len, tlen;
|
1995-12-20 02:07:11 +03:00
|
|
|
u_int32_t *tl;
|
1993-03-21 12:45:37 +03:00
|
|
|
int putsize;
|
|
|
|
|
|
|
|
putsize = 1;
|
|
|
|
m2 = *mb;
|
1994-06-08 15:33:09 +04:00
|
|
|
left = M_TRAILINGSPACE(m2);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (left > 0) {
|
1995-12-20 02:07:11 +03:00
|
|
|
tl = ((u_int32_t *)(*bpos));
|
1993-03-21 12:45:37 +03:00
|
|
|
*tl++ = txdr_unsigned(siz);
|
|
|
|
putsize = 0;
|
|
|
|
left -= NFSX_UNSIGNED;
|
|
|
|
m2->m_len += NFSX_UNSIGNED;
|
|
|
|
if (left > 0) {
|
1998-08-10 00:51:08 +04:00
|
|
|
memcpy((caddr_t) tl, cp, left);
|
1993-03-21 12:45:37 +03:00
|
|
|
siz -= left;
|
|
|
|
cp += left;
|
|
|
|
m2->m_len += left;
|
|
|
|
left = 0;
|
|
|
|
}
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
/* Loop around adding mbufs */
|
1993-03-21 12:45:37 +03:00
|
|
|
while (siz > 0) {
|
2003-02-26 09:31:08 +03:00
|
|
|
m1 = m_get(M_WAIT, MT_DATA);
|
|
|
|
MCLAIM(m1, &nfs_mowner);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (siz > MLEN)
|
2003-02-26 09:31:08 +03:00
|
|
|
m_clget(m1, M_WAIT);
|
1993-03-21 12:45:37 +03:00
|
|
|
m1->m_len = NFSMSIZ(m1);
|
|
|
|
m2->m_next = m1;
|
|
|
|
m2 = m1;
|
1995-12-20 02:07:11 +03:00
|
|
|
tl = mtod(m1, u_int32_t *);
|
1993-03-21 12:45:37 +03:00
|
|
|
tlen = 0;
|
|
|
|
if (putsize) {
|
|
|
|
*tl++ = txdr_unsigned(siz);
|
|
|
|
m1->m_len -= NFSX_UNSIGNED;
|
|
|
|
tlen = NFSX_UNSIGNED;
|
|
|
|
putsize = 0;
|
|
|
|
}
|
|
|
|
if (siz < m1->m_len) {
|
|
|
|
len = nfsm_rndup(siz);
|
|
|
|
xfer = siz;
|
|
|
|
if (xfer < len)
|
|
|
|
*(tl+(xfer>>2)) = 0;
|
|
|
|
} else {
|
|
|
|
xfer = len = m1->m_len;
|
|
|
|
}
|
1998-08-10 00:51:08 +04:00
|
|
|
memcpy((caddr_t) tl, cp, xfer);
|
1993-03-21 12:45:37 +03:00
|
|
|
m1->m_len = len+tlen;
|
|
|
|
siz -= xfer;
|
|
|
|
cp += xfer;
|
|
|
|
}
|
|
|
|
*mb = m1;
|
|
|
|
*bpos = mtod(m1, caddr_t)+m1->m_len;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1997-10-19 05:46:15 +04:00
|
|
|
/*
|
|
|
|
* Directory caching routines. They work as follows:
|
|
|
|
* - a cache is maintained per VDIR nfsnode.
|
|
|
|
* - for each offset cookie that is exported to userspace, and can
|
|
|
|
* thus be thrown back at us as an offset to VOP_READDIR, store
|
|
|
|
* information in the cache.
|
|
|
|
* - cached are:
|
|
|
|
* - cookie itself
|
|
|
|
* - blocknumber (essentially just a search key in the buffer cache)
|
|
|
|
* - entry number in block.
|
|
|
|
* - offset cookie of block in which this entry is stored
|
|
|
|
* - 32 bit cookie if NFSMNT_XLATECOOKIE is used.
|
|
|
|
* - entries are looked up in a hash table
|
|
|
|
* - also maintained is an LRU list of entries, used to determine
|
|
|
|
* which ones to delete if the cache grows too large.
|
|
|
|
* - if 32 <-> 64 translation mode is requested for a filesystem,
|
|
|
|
* the cache also functions as a translation table
|
|
|
|
* - in the translation case, invalidating the cache does not mean
|
|
|
|
* flushing it, but just marking entries as invalid, except for
|
|
|
|
* the <64bit cookie, 32bitcookie> pair which is still valid, to
|
|
|
|
* still be able to use the cache as a translation table.
|
|
|
|
* - 32 bit cookies are uniquely created by combining the hash table
|
|
|
|
* entry value, and one generation count per hash table entry,
|
|
|
|
* incremented each time an entry is appended to the chain.
|
|
|
|
* - the cache is invalidated each time a direcory is modified
|
|
|
|
* - sanity checks are also done; if an entry in a block turns
|
|
|
|
* out not to have a matching cookie, the cache is invalidated
|
|
|
|
* and a new block starting from the wanted offset is fetched from
|
|
|
|
* the server.
|
|
|
|
* - directory entries as read from the server are extended to contain
|
|
|
|
* the 64bit and, optionally, the 32bit cookies, for sanity checking
|
|
|
|
* the cache and exporting them to userspace through the cookie
|
|
|
|
* argument to VOP_READDIR.
|
|
|
|
*/
|
|
|
|
|
1997-10-10 05:53:17 +04:00
|
|
|
u_long
|
|
|
|
nfs_dirhash(off)
|
|
|
|
off_t off;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *cp = (char *)&off;
|
|
|
|
u_long sum = 0L;
|
|
|
|
|
|
|
|
for (i = 0 ; i < sizeof (off); i++)
|
|
|
|
sum += *cp++;
|
|
|
|
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
2004-09-15 13:50:56 +04:00
|
|
|
#define _NFSDC_MTX(np) (&NFSTOV(np)->v_interlock)
|
|
|
|
#define NFSDC_LOCK(np) simple_lock(_NFSDC_MTX(np))
|
|
|
|
#define NFSDC_UNLOCK(np) simple_unlock(_NFSDC_MTX(np))
|
|
|
|
#define NFSDC_ASSERT_LOCKED(np) LOCK_ASSERT(simple_lock_held(_NFSDC_MTX(np)))
|
|
|
|
|
1997-10-19 05:46:15 +04:00
|
|
|
void
|
|
|
|
nfs_initdircache(vp)
|
|
|
|
struct vnode *vp;
|
|
|
|
{
|
|
|
|
struct nfsnode *np = VTONFS(vp);
|
2004-09-15 13:50:56 +04:00
|
|
|
struct nfsdirhashhead *dircache;
|
2003-05-22 18:14:02 +04:00
|
|
|
|
2004-09-15 13:50:56 +04:00
|
|
|
dircache = hashinit(NFS_DIRHASHSIZ, HASH_LIST, M_NFSDIROFF,
|
2000-11-08 17:28:12 +03:00
|
|
|
M_WAITOK, &nfsdirhashmask);
|
2004-09-15 13:50:56 +04:00
|
|
|
|
|
|
|
NFSDC_LOCK(np);
|
|
|
|
if (np->n_dircache == NULL) {
|
|
|
|
np->n_dircachesize = 0;
|
|
|
|
np->n_dircache = dircache;
|
|
|
|
dircache = NULL;
|
|
|
|
TAILQ_INIT(&np->n_dirchain);
|
|
|
|
}
|
|
|
|
NFSDC_UNLOCK(np);
|
|
|
|
if (dircache)
|
|
|
|
hashdone(dircache, M_NFSDIROFF);
|
2003-05-22 18:14:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nfs_initdirxlatecookie(vp)
|
|
|
|
struct vnode *vp;
|
|
|
|
{
|
|
|
|
struct nfsnode *np = VTONFS(vp);
|
2004-09-15 13:50:56 +04:00
|
|
|
unsigned *dirgens;
|
2003-05-22 18:14:02 +04:00
|
|
|
|
|
|
|
KASSERT(VFSTONFS(vp->v_mount)->nm_flag & NFSMNT_XLATECOOKIE);
|
|
|
|
|
2004-09-15 13:50:56 +04:00
|
|
|
dirgens = malloc(NFS_DIRHASHSIZ * sizeof (unsigned), M_NFSDIROFF,
|
|
|
|
M_WAITOK|M_ZERO);
|
|
|
|
NFSDC_LOCK(np);
|
|
|
|
if (np->n_dirgens == NULL) {
|
|
|
|
np->n_dirgens = dirgens;
|
|
|
|
dirgens = NULL;
|
|
|
|
}
|
|
|
|
NFSDC_UNLOCK(np);
|
|
|
|
if (dirgens)
|
|
|
|
free(dirgens, M_NFSDIROFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct nfsdircache dzero;
|
|
|
|
|
|
|
|
static void nfs_unlinkdircache __P((struct nfsnode *np, struct nfsdircache *));
|
|
|
|
static void nfs_putdircache_unlocked __P((struct nfsnode *,
|
|
|
|
struct nfsdircache *));
|
|
|
|
|
|
|
|
static void
|
|
|
|
nfs_unlinkdircache(np, ndp)
|
|
|
|
struct nfsnode *np;
|
|
|
|
struct nfsdircache *ndp;
|
|
|
|
{
|
|
|
|
|
|
|
|
NFSDC_ASSERT_LOCKED(np);
|
|
|
|
KASSERT(ndp != &dzero);
|
|
|
|
|
|
|
|
if (LIST_NEXT(ndp, dc_hash) == (void *)-1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
TAILQ_REMOVE(&np->n_dirchain, ndp, dc_chain);
|
|
|
|
LIST_REMOVE(ndp, dc_hash);
|
|
|
|
LIST_NEXT(ndp, dc_hash) = (void *)-1; /* mark as unlinked */
|
|
|
|
|
|
|
|
nfs_putdircache_unlocked(np, ndp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nfs_putdircache(np, ndp)
|
|
|
|
struct nfsnode *np;
|
|
|
|
struct nfsdircache *ndp;
|
|
|
|
{
|
|
|
|
int ref;
|
|
|
|
|
|
|
|
if (ndp == &dzero)
|
|
|
|
return;
|
|
|
|
|
|
|
|
KASSERT(ndp->dc_refcnt > 0);
|
|
|
|
NFSDC_LOCK(np);
|
|
|
|
ref = --ndp->dc_refcnt;
|
|
|
|
NFSDC_UNLOCK(np);
|
|
|
|
|
|
|
|
if (ref == 0)
|
|
|
|
free(ndp, M_NFSDIROFF);
|
1997-10-19 05:46:15 +04:00
|
|
|
}
|
|
|
|
|
2004-09-15 13:50:56 +04:00
|
|
|
static void
|
|
|
|
nfs_putdircache_unlocked(np, ndp)
|
|
|
|
struct nfsnode *np;
|
|
|
|
struct nfsdircache *ndp;
|
|
|
|
{
|
|
|
|
int ref;
|
|
|
|
|
|
|
|
NFSDC_ASSERT_LOCKED(np);
|
|
|
|
|
|
|
|
if (ndp == &dzero)
|
|
|
|
return;
|
|
|
|
|
|
|
|
KASSERT(ndp->dc_refcnt > 0);
|
|
|
|
ref = --ndp->dc_refcnt;
|
|
|
|
if (ref == 0)
|
|
|
|
free(ndp, M_NFSDIROFF);
|
|
|
|
}
|
1997-10-10 05:53:17 +04:00
|
|
|
|
|
|
|
struct nfsdircache *
|
1997-10-19 05:46:15 +04:00
|
|
|
nfs_searchdircache(vp, off, do32, hashent)
|
1997-10-10 05:53:17 +04:00
|
|
|
struct vnode *vp;
|
|
|
|
off_t off;
|
1997-10-19 05:46:15 +04:00
|
|
|
int do32;
|
|
|
|
int *hashent;
|
|
|
|
{
|
|
|
|
struct nfsdirhashhead *ndhp;
|
|
|
|
struct nfsdircache *ndp = NULL;
|
|
|
|
struct nfsnode *np = VTONFS(vp);
|
|
|
|
unsigned ent;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Zero is always a valid cookie.
|
|
|
|
*/
|
|
|
|
if (off == 0)
|
2005-05-30 00:58:13 +04:00
|
|
|
/* XXXUNCONST */
|
|
|
|
return (struct nfsdircache *)__UNCONST(&dzero);
|
1997-10-19 05:46:15 +04:00
|
|
|
|
2004-06-14 16:28:35 +04:00
|
|
|
if (!np->n_dircache)
|
|
|
|
return NULL;
|
|
|
|
|
1997-10-19 05:46:15 +04:00
|
|
|
/*
|
|
|
|
* We use a 32bit cookie as search key, directly reconstruct
|
|
|
|
* the hashentry. Else use the hashfunction.
|
|
|
|
*/
|
|
|
|
if (do32) {
|
|
|
|
ent = (u_int32_t)off >> 24;
|
|
|
|
if (ent >= NFS_DIRHASHSIZ)
|
|
|
|
return NULL;
|
|
|
|
ndhp = &np->n_dircache[ent];
|
|
|
|
} else {
|
|
|
|
ndhp = NFSDIRHASH(np, off);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hashent)
|
|
|
|
*hashent = (int)(ndhp - np->n_dircache);
|
2004-09-15 13:50:56 +04:00
|
|
|
|
|
|
|
NFSDC_LOCK(np);
|
1997-10-19 05:46:15 +04:00
|
|
|
if (do32) {
|
2003-04-02 19:14:19 +04:00
|
|
|
LIST_FOREACH(ndp, ndhp, dc_hash) {
|
1997-10-19 05:46:15 +04:00
|
|
|
if (ndp->dc_cookie32 == (u_int32_t)off) {
|
|
|
|
/*
|
|
|
|
* An invalidated entry will become the
|
|
|
|
* start of a new block fetched from
|
|
|
|
* the server.
|
|
|
|
*/
|
2004-09-15 13:50:56 +04:00
|
|
|
if (ndp->dc_flags & NFSDC_INVALID) {
|
1997-10-19 05:46:15 +04:00
|
|
|
ndp->dc_blkcookie = ndp->dc_cookie;
|
|
|
|
ndp->dc_entry = 0;
|
2004-09-15 13:50:56 +04:00
|
|
|
ndp->dc_flags &= ~NFSDC_INVALID;
|
1997-10-19 05:46:15 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2003-04-02 19:14:19 +04:00
|
|
|
LIST_FOREACH(ndp, ndhp, dc_hash) {
|
1997-10-19 05:46:15 +04:00
|
|
|
if (ndp->dc_cookie == off)
|
|
|
|
break;
|
2003-04-02 19:14:19 +04:00
|
|
|
}
|
1997-10-19 05:46:15 +04:00
|
|
|
}
|
2004-09-15 13:50:56 +04:00
|
|
|
if (ndp != NULL)
|
|
|
|
ndp->dc_refcnt++;
|
|
|
|
NFSDC_UNLOCK(np);
|
1997-10-19 05:46:15 +04:00
|
|
|
return ndp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct nfsdircache *
|
|
|
|
nfs_enterdircache(vp, off, blkoff, en, blkno)
|
|
|
|
struct vnode *vp;
|
|
|
|
off_t off, blkoff;
|
|
|
|
int en;
|
2002-03-12 01:56:47 +03:00
|
|
|
daddr_t blkno;
|
1997-10-10 05:53:17 +04:00
|
|
|
{
|
|
|
|
struct nfsnode *np = VTONFS(vp);
|
|
|
|
struct nfsdirhashhead *ndhp;
|
2004-09-15 13:50:56 +04:00
|
|
|
struct nfsdircache *ndp = NULL;
|
|
|
|
struct nfsdircache *newndp = NULL;
|
1997-10-19 05:46:15 +04:00
|
|
|
struct nfsmount *nmp = VFSTONFS(vp->v_mount);
|
|
|
|
int hashent, gen, overwrite;
|
1997-10-10 05:53:17 +04:00
|
|
|
|
2004-09-15 13:50:56 +04:00
|
|
|
/*
|
|
|
|
* XXX refuse entries for offset 0. amd(8) erroneously sets
|
|
|
|
* cookie 0 for the '.' entry, making this necessary. This
|
|
|
|
* isn't so bad, as 0 is a special case anyway.
|
|
|
|
*/
|
|
|
|
if (off == 0)
|
2005-05-30 00:58:13 +04:00
|
|
|
/* XXXUNCONST */
|
|
|
|
return (struct nfsdircache *)__UNCONST(&dzero);
|
2004-09-15 13:50:56 +04:00
|
|
|
|
1997-10-19 05:46:15 +04:00
|
|
|
if (!np->n_dircache)
|
|
|
|
/*
|
|
|
|
* XXX would like to do this in nfs_nget but vtype
|
|
|
|
* isn't known at that time.
|
|
|
|
*/
|
|
|
|
nfs_initdircache(vp);
|
|
|
|
|
2003-05-22 18:14:02 +04:00
|
|
|
if ((nmp->nm_flag & NFSMNT_XLATECOOKIE) && !np->n_dirgens)
|
|
|
|
nfs_initdirxlatecookie(vp);
|
|
|
|
|
2004-09-15 13:50:56 +04:00
|
|
|
retry:
|
1997-10-19 05:46:15 +04:00
|
|
|
ndp = nfs_searchdircache(vp, off, 0, &hashent);
|
|
|
|
|
2004-09-15 13:50:56 +04:00
|
|
|
NFSDC_LOCK(np);
|
|
|
|
if (ndp && (ndp->dc_flags & NFSDC_INVALID) == 0) {
|
1997-10-19 05:46:15 +04:00
|
|
|
/*
|
|
|
|
* Overwriting an old entry. Check if it's the same.
|
|
|
|
* If so, just return. If not, remove the old entry.
|
|
|
|
*/
|
|
|
|
if (ndp->dc_blkcookie == blkoff && ndp->dc_entry == en)
|
2004-09-15 13:50:56 +04:00
|
|
|
goto done;
|
|
|
|
nfs_unlinkdircache(np, ndp);
|
|
|
|
nfs_putdircache_unlocked(np, ndp);
|
|
|
|
ndp = NULL;
|
1997-10-10 05:53:17 +04:00
|
|
|
}
|
|
|
|
|
1997-10-19 05:46:15 +04:00
|
|
|
ndhp = &np->n_dircache[hashent];
|
1997-10-10 05:53:17 +04:00
|
|
|
|
1997-10-19 05:46:15 +04:00
|
|
|
if (!ndp) {
|
2004-09-15 13:50:56 +04:00
|
|
|
if (newndp == NULL) {
|
|
|
|
NFSDC_UNLOCK(np);
|
|
|
|
newndp = malloc(sizeof(*ndp), M_NFSDIROFF, M_WAITOK);
|
|
|
|
newndp->dc_refcnt = 1;
|
|
|
|
LIST_NEXT(newndp, dc_hash) = (void *)-1;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
ndp = newndp;
|
|
|
|
newndp = NULL;
|
1997-10-19 05:46:15 +04:00
|
|
|
overwrite = 0;
|
|
|
|
if (nmp->nm_flag & NFSMNT_XLATECOOKIE) {
|
|
|
|
/*
|
|
|
|
* We're allocating a new entry, so bump the
|
|
|
|
* generation number.
|
|
|
|
*/
|
|
|
|
gen = ++np->n_dirgens[hashent];
|
|
|
|
if (gen == 0) {
|
|
|
|
np->n_dirgens[hashent]++;
|
|
|
|
gen++;
|
|
|
|
}
|
|
|
|
ndp->dc_cookie32 = (hashent << 24) | (gen & 0xffffff);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
overwrite = 1;
|
1997-10-10 05:53:17 +04:00
|
|
|
|
1997-10-19 05:46:15 +04:00
|
|
|
ndp->dc_cookie = off;
|
|
|
|
ndp->dc_blkcookie = blkoff;
|
1997-10-10 05:53:17 +04:00
|
|
|
ndp->dc_entry = en;
|
2004-10-03 14:51:28 +04:00
|
|
|
ndp->dc_flags = 0;
|
1997-10-10 05:53:17 +04:00
|
|
|
|
1997-10-19 05:46:15 +04:00
|
|
|
if (overwrite)
|
2004-09-15 13:50:56 +04:00
|
|
|
goto done;
|
1997-10-19 05:46:15 +04:00
|
|
|
|
1997-10-10 05:53:17 +04:00
|
|
|
/*
|
|
|
|
* If the maximum directory cookie cache size has been reached
|
|
|
|
* for this node, take one off the front. The idea is that
|
|
|
|
* directories are typically read front-to-back once, so that
|
|
|
|
* the oldest entries can be thrown away without much performance
|
|
|
|
* loss.
|
|
|
|
*/
|
|
|
|
if (np->n_dircachesize == NFS_MAXDIRCACHE) {
|
2004-09-15 13:50:56 +04:00
|
|
|
nfs_unlinkdircache(np, TAILQ_FIRST(&np->n_dirchain));
|
1997-10-10 05:53:17 +04:00
|
|
|
} else
|
|
|
|
np->n_dircachesize++;
|
2005-02-27 01:31:44 +03:00
|
|
|
|
2004-09-15 13:50:56 +04:00
|
|
|
KASSERT(ndp->dc_refcnt == 1);
|
1997-10-10 05:53:17 +04:00
|
|
|
LIST_INSERT_HEAD(ndhp, ndp, dc_hash);
|
|
|
|
TAILQ_INSERT_TAIL(&np->n_dirchain, ndp, dc_chain);
|
2004-09-15 13:50:56 +04:00
|
|
|
ndp->dc_refcnt++;
|
|
|
|
done:
|
|
|
|
KASSERT(ndp->dc_refcnt > 0);
|
|
|
|
NFSDC_UNLOCK(np);
|
|
|
|
if (newndp)
|
|
|
|
nfs_putdircache(np, newndp);
|
1997-10-10 05:53:17 +04:00
|
|
|
return ndp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-01-27 14:33:26 +03:00
|
|
|
nfs_invaldircache(vp, flags)
|
1997-10-10 05:53:17 +04:00
|
|
|
struct vnode *vp;
|
2005-01-27 14:33:26 +03:00
|
|
|
int flags;
|
1997-10-10 05:53:17 +04:00
|
|
|
{
|
|
|
|
struct nfsnode *np = VTONFS(vp);
|
|
|
|
struct nfsdircache *ndp = NULL;
|
1997-10-19 05:46:15 +04:00
|
|
|
struct nfsmount *nmp = VFSTONFS(vp->v_mount);
|
2005-01-27 14:33:26 +03:00
|
|
|
const boolean_t forcefree = flags & NFS_INVALDIRCACHE_FORCE;
|
1997-10-10 05:53:17 +04:00
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (vp->v_type != VDIR)
|
|
|
|
panic("nfs: invaldircache: not dir");
|
|
|
|
#endif
|
|
|
|
|
2005-01-27 14:33:26 +03:00
|
|
|
if ((flags & NFS_INVALDIRCACHE_KEEPEOF) == 0)
|
|
|
|
np->n_flag &= ~NEOFVALID;
|
2005-01-26 13:30:58 +03:00
|
|
|
|
1997-10-10 05:53:17 +04:00
|
|
|
if (!np->n_dircache)
|
|
|
|
return;
|
|
|
|
|
2004-09-15 13:50:56 +04:00
|
|
|
NFSDC_LOCK(np);
|
1997-10-19 05:46:15 +04:00
|
|
|
if (!(nmp->nm_flag & NFSMNT_XLATECOOKIE) || forcefree) {
|
2004-09-15 13:50:56 +04:00
|
|
|
while ((ndp = TAILQ_FIRST(&np->n_dirchain)) != NULL) {
|
|
|
|
KASSERT(!forcefree || ndp->dc_refcnt == 1);
|
|
|
|
nfs_unlinkdircache(np, ndp);
|
1997-10-19 05:46:15 +04:00
|
|
|
}
|
|
|
|
np->n_dircachesize = 0;
|
|
|
|
if (forcefree && np->n_dirgens) {
|
|
|
|
FREE(np->n_dirgens, M_NFSDIROFF);
|
2003-05-22 18:14:02 +04:00
|
|
|
np->n_dirgens = NULL;
|
1997-10-19 05:46:15 +04:00
|
|
|
}
|
|
|
|
} else {
|
2004-09-15 13:50:56 +04:00
|
|
|
TAILQ_FOREACH(ndp, &np->n_dirchain, dc_chain)
|
|
|
|
ndp->dc_flags |= NFSDC_INVALID;
|
1997-10-10 05:53:17 +04:00
|
|
|
}
|
|
|
|
|
2004-09-15 13:50:56 +04:00
|
|
|
NFSDC_UNLOCK(np);
|
1997-10-10 05:53:17 +04:00
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1996-12-03 03:22:43 +03:00
|
|
|
* Called once before VFS init to initialize shared and
|
|
|
|
* server-specific data structures.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2005-11-25 23:01:38 +03:00
|
|
|
static void
|
|
|
|
nfs_init0(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-06-08 15:33:09 +04:00
|
|
|
nfsrtt.pos = 0;
|
1993-03-21 12:45:37 +03: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);
|
1994-06-08 15:33:09 +04:00
|
|
|
rpc_autherr = txdr_unsigned(RPC_AUTHERR);
|
1993-03-21 12:45:37 +03:00
|
|
|
rpc_auth_unix = txdr_unsigned(RPCAUTH_UNIX);
|
1996-02-18 14:53:36 +03:00
|
|
|
rpc_auth_kerb = txdr_unsigned(RPCAUTH_KERB4);
|
1993-03-21 12:45:37 +03:00
|
|
|
nfs_prog = txdr_unsigned(NFS_PROG);
|
1996-02-18 14:53:36 +03:00
|
|
|
nqnfs_prog = txdr_unsigned(NQNFS_PROG);
|
1993-03-21 12:45:37 +03:00
|
|
|
nfs_true = txdr_unsigned(TRUE);
|
|
|
|
nfs_false = txdr_unsigned(FALSE);
|
1994-06-08 15:33:09 +04:00
|
|
|
nfs_xdrneg1 = txdr_unsigned(-1);
|
1996-02-18 14:53:36 +03:00
|
|
|
nfs_ticks = (hz * NFS_TICKINTVL + 500) / 1000;
|
|
|
|
if (nfs_ticks < 1)
|
|
|
|
nfs_ticks = 1;
|
1993-04-11 00:19:19 +04:00
|
|
|
#ifdef NFSSERVER
|
1994-06-08 15:33:09 +04:00
|
|
|
nfsrv_init(0); /* Init server data structures */
|
1993-03-21 12:45:37 +03:00
|
|
|
nfsrv_initcache(); /* Init the server request cache */
|
2003-05-22 18:16:23 +04:00
|
|
|
pool_init(&nfs_srvdesc_pool, sizeof(struct nfsrv_descript),
|
|
|
|
0, 0, 0, "nfsrvdescpl", &pool_allocator_nointr);
|
1996-12-09 13:46:20 +03:00
|
|
|
#endif /* NFSSERVER */
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2000-09-20 03:26:25 +04:00
|
|
|
#if defined(NFSSERVER) || !defined(NFS_V2_ONLY)
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
1996-12-09 14:31:11 +03:00
|
|
|
* Initialize the nqnfs data structures.
|
1994-06-08 15:33:09 +04:00
|
|
|
*/
|
|
|
|
if (nqnfsstarttime == 0) {
|
|
|
|
nqnfsstarttime = boottime.tv_sec + nqsrv_maxlease
|
|
|
|
+ nqsrv_clockskew + nqsrv_writeslack;
|
|
|
|
NQLOADNOVRAM(nqnfsstarttime);
|
1994-08-19 02:47:43 +04:00
|
|
|
CIRCLEQ_INIT(&nqtimerhead);
|
2000-11-08 17:28:12 +03:00
|
|
|
nqfhhashtbl = hashinit(NQLCHSZ, HASH_LIST, M_NQLEASE,
|
|
|
|
M_WAITOK, &nqfhhash);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
2000-09-20 03:26:25 +04:00
|
|
|
#endif
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2002-03-18 01:22:39 +03:00
|
|
|
exithook_establish(nfs_exit, NULL);
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Initialize reply list and start timer
|
|
|
|
*/
|
1994-08-17 15:41:36 +04:00
|
|
|
TAILQ_INIT(&nfs_reqq);
|
1996-02-10 00:48:19 +03:00
|
|
|
nfs_timer(NULL);
|
2003-02-26 09:31:08 +03:00
|
|
|
MOWNER_ATTACH(&nfs_mowner);
|
2002-10-23 13:10:23 +04:00
|
|
|
|
|
|
|
#ifdef NFS
|
|
|
|
/* Initialize the kqueue structures */
|
|
|
|
nfs_kqinit();
|
2003-05-07 20:18:53 +04:00
|
|
|
/* Initialize the iod structures */
|
|
|
|
nfs_iodinit();
|
2002-10-23 13:10:23 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2005-11-25 23:01:38 +03:00
|
|
|
void
|
|
|
|
nfs_init(void)
|
|
|
|
{
|
|
|
|
static ONCE_DECL(nfs_init_once);
|
|
|
|
|
|
|
|
RUN_ONCE(&nfs_init_once, nfs_init0);
|
|
|
|
}
|
|
|
|
|
1997-01-31 05:58:48 +03:00
|
|
|
#ifdef NFS
|
1996-12-03 03:22:43 +03:00
|
|
|
/*
|
|
|
|
* Called once at VFS init to initialize client-specific data structures.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nfs_vfs_init()
|
|
|
|
{
|
2005-11-25 23:01:38 +03:00
|
|
|
/* Initialize NFS server / client shared data. */
|
|
|
|
nfs_init();
|
|
|
|
|
1996-12-03 03:22:43 +03:00
|
|
|
nfs_nhinit(); /* Init the nfsnode table */
|
2002-01-26 05:52:19 +03:00
|
|
|
nfs_commitsize = uvmexp.npages << (PAGE_SHIFT - 4);
|
1996-12-03 03:22:43 +03:00
|
|
|
}
|
|
|
|
|
2001-09-15 20:12:54 +04:00
|
|
|
void
|
|
|
|
nfs_vfs_reinit()
|
|
|
|
{
|
|
|
|
nfs_nhreinit();
|
|
|
|
}
|
|
|
|
|
2000-03-16 21:08:17 +03:00
|
|
|
void
|
|
|
|
nfs_vfs_done()
|
|
|
|
{
|
|
|
|
nfs_nhdone();
|
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-06-08 15:33:09 +04:00
|
|
|
* Attribute cache routines.
|
|
|
|
* nfs_loadattrcache() - loads or updates the cache contents from attributes
|
|
|
|
* that are on the mbuf list
|
|
|
|
* nfs_getattrcache() - returns valid attributes if found in cache, returns
|
|
|
|
* error otherwise
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Load the attribute cache (that lives in the nfsnode entry) with
|
|
|
|
* the values on the mbuf list and
|
|
|
|
* Iff vap not NULL
|
|
|
|
* copy the attributes to *vaper
|
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
int
|
2002-10-21 16:52:32 +04:00
|
|
|
nfsm_loadattrcache(vpp, mdp, dposp, vaper, flags)
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vnode **vpp;
|
|
|
|
struct mbuf **mdp;
|
|
|
|
caddr_t *dposp;
|
|
|
|
struct vattr *vaper;
|
2002-10-21 16:52:32 +04:00
|
|
|
int flags;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
int32_t t1;
|
1996-02-18 14:53:36 +03:00
|
|
|
caddr_t cp2;
|
|
|
|
int error = 0;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct mbuf *md;
|
1997-07-15 00:46:20 +04:00
|
|
|
int v3 = NFS_ISV3(*vpp);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
md = *mdp;
|
1996-02-18 14:53:36 +03:00
|
|
|
t1 = (mtod(md, caddr_t) + md->m_len) - *dposp;
|
|
|
|
error = nfsm_disct(mdp, dposp, NFSX_FATTR(v3), t1, &cp2);
|
1996-02-10 00:48:19 +03:00
|
|
|
if (error)
|
1994-06-08 15:33:09 +04:00
|
|
|
return (error);
|
2002-10-21 16:52:32 +04:00
|
|
|
return nfs_loadattrcache(vpp, (struct nfs_fattr *)cp2, vaper, flags);
|
1997-07-15 00:46:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-10-21 16:52:32 +04:00
|
|
|
nfs_loadattrcache(vpp, fp, vaper, flags)
|
1997-07-15 00:46:20 +04:00
|
|
|
struct vnode **vpp;
|
|
|
|
struct nfs_fattr *fp;
|
|
|
|
struct vattr *vaper;
|
2002-10-21 16:52:32 +04:00
|
|
|
int flags;
|
1997-07-15 00:46:20 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct vnode *vp = *vpp;
|
|
|
|
struct vattr *vap;
|
1997-07-15 00:46:20 +04:00
|
|
|
int v3 = NFS_ISV3(vp);
|
|
|
|
enum vtype vtyp;
|
|
|
|
u_short vmode;
|
|
|
|
struct timespec mtime;
|
2005-01-06 14:52:44 +03:00
|
|
|
struct timespec ctime;
|
1997-07-15 00:46:20 +04:00
|
|
|
struct vnode *nvp;
|
|
|
|
int32_t rdev;
|
2000-03-30 16:51:13 +04:00
|
|
|
struct nfsnode *np;
|
1997-07-15 00:46:20 +04:00
|
|
|
extern int (**spec_nfsv2nodeop_p) __P((void *));
|
2002-03-01 00:38:08 +03:00
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
1997-07-15 00:46:20 +04:00
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
if (v3) {
|
|
|
|
vtyp = nfsv3tov_type(fp->fa_type);
|
|
|
|
vmode = fxdr_unsigned(u_short, fp->fa_mode);
|
1999-09-06 13:27:18 +04:00
|
|
|
rdev = makedev(fxdr_unsigned(u_int32_t, fp->fa3_rdev.specdata1),
|
|
|
|
fxdr_unsigned(u_int32_t, fp->fa3_rdev.specdata2));
|
1996-02-18 14:53:36 +03:00
|
|
|
fxdr_nfsv3time(&fp->fa3_mtime, &mtime);
|
2005-01-06 14:52:44 +03:00
|
|
|
fxdr_nfsv3time(&fp->fa3_ctime, &ctime);
|
1994-06-08 15:33:09 +04:00
|
|
|
} else {
|
1996-02-18 14:53:36 +03:00
|
|
|
vtyp = nfsv2tov_type(fp->fa_type);
|
|
|
|
vmode = fxdr_unsigned(u_short, fp->fa_mode);
|
|
|
|
if (vtyp == VNON || vtyp == VREG)
|
|
|
|
vtyp = IFTOVT(vmode);
|
|
|
|
rdev = fxdr_unsigned(int32_t, fp->fa2_rdev);
|
|
|
|
fxdr_nfsv2time(&fp->fa2_mtime, &mtime);
|
2005-01-06 14:52:44 +03:00
|
|
|
ctime.tv_sec = fxdr_unsigned(u_int32_t,
|
|
|
|
fp->fa2_ctime.nfsv2_sec);
|
|
|
|
ctime.tv_nsec = 0;
|
1996-02-18 14:53:36 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Really ugly NFSv2 kludge.
|
|
|
|
*/
|
|
|
|
if (vtyp == VCHR && rdev == 0xffffffff)
|
|
|
|
vtyp = VFIFO;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
1996-02-18 14:53:36 +03:00
|
|
|
|
2002-03-01 00:38:08 +03:00
|
|
|
vmode &= ALLPERMS;
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* If v_type == VNON it is a new node, so fill in the v_type,
|
2005-02-27 01:31:44 +03:00
|
|
|
* n_mtime fields. Check to see if it represents a special
|
1994-06-08 15:33:09 +04:00
|
|
|
* device, and if so, check for a possible alias. Once the
|
|
|
|
* correct vnode has been obtained, fill in the rest of the
|
|
|
|
* information.
|
|
|
|
*/
|
|
|
|
np = VTONFS(vp);
|
2000-10-24 16:02:04 +04:00
|
|
|
if (vp->v_type == VNON) {
|
1996-02-18 14:53:36 +03:00
|
|
|
vp->v_type = vtyp;
|
1994-06-08 15:33:09 +04:00
|
|
|
if (vp->v_type == VFIFO) {
|
1996-02-10 00:48:19 +03:00
|
|
|
extern int (**fifo_nfsv2nodeop_p) __P((void *));
|
1994-06-08 15:33:09 +04:00
|
|
|
vp->v_op = fifo_nfsv2nodeop_p;
|
2004-03-12 19:52:37 +03:00
|
|
|
} else if (vp->v_type == VREG) {
|
|
|
|
lockinit(&np->n_commitlock, PINOD, "nfsclock", 0, 0);
|
|
|
|
} else if (vp->v_type == VCHR || vp->v_type == VBLK) {
|
1994-06-08 15:33:09 +04:00
|
|
|
vp->v_op = spec_nfsv2nodeop_p;
|
1996-02-10 00:48:19 +03:00
|
|
|
nvp = checkalias(vp, (dev_t)rdev, vp->v_mount);
|
|
|
|
if (nvp) {
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Discard unneeded vnode, but save its nfsnode.
|
1996-02-18 14:53:36 +03:00
|
|
|
* Since the nfsnode does not have a lock, its
|
|
|
|
* vnode lock has to be carried over.
|
1994-06-08 15:33:09 +04:00
|
|
|
*/
|
2001-04-22 01:35:53 +04:00
|
|
|
/*
|
|
|
|
* XXX is the old node sure to be locked here?
|
|
|
|
*/
|
|
|
|
KASSERT(lockstatus(&vp->v_lock) ==
|
|
|
|
LK_EXCLUSIVE);
|
1994-06-08 15:33:09 +04:00
|
|
|
nvp->v_data = vp->v_data;
|
|
|
|
vp->v_data = NULL;
|
2001-03-24 00:10:48 +03:00
|
|
|
VOP_UNLOCK(vp, 0);
|
1994-06-08 15:33:09 +04:00
|
|
|
vp->v_op = spec_vnodeop_p;
|
2001-03-24 00:10:48 +03:00
|
|
|
vrele(vp);
|
1994-06-08 15:33:09 +04:00
|
|
|
vgone(vp);
|
2001-04-22 01:35:53 +04:00
|
|
|
lockmgr(&nvp->v_lock, LK_EXCLUSIVE,
|
|
|
|
&nvp->v_interlock);
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Reinitialize aliased node.
|
|
|
|
*/
|
|
|
|
np->n_vnode = nvp;
|
|
|
|
*vpp = vp = nvp;
|
|
|
|
}
|
|
|
|
}
|
2003-09-26 15:51:53 +04:00
|
|
|
np->n_mtime = mtime;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
2002-03-01 00:38:08 +03:00
|
|
|
uid = fxdr_unsigned(uid_t, fp->fa_uid);
|
|
|
|
gid = fxdr_unsigned(gid_t, fp->fa_gid);
|
1997-10-19 05:46:15 +04:00
|
|
|
vap = np->n_vattr;
|
2002-03-01 00:38:08 +03:00
|
|
|
|
|
|
|
/*
|
2005-01-06 14:52:44 +03:00
|
|
|
* Invalidate access cache if uid, gid, mode or ctime changed.
|
2002-03-01 00:38:08 +03:00
|
|
|
*/
|
|
|
|
if (np->n_accstamp != -1 &&
|
2005-01-06 14:52:44 +03:00
|
|
|
(gid != vap->va_gid || uid != vap->va_uid || vmode != vap->va_mode
|
|
|
|
|| timespeccmp(&ctime, &vap->va_ctime, !=)))
|
2002-03-01 00:38:08 +03:00
|
|
|
np->n_accstamp = -1;
|
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
vap->va_type = vtyp;
|
2002-03-01 00:38:08 +03:00
|
|
|
vap->va_mode = vmode;
|
1994-06-08 15:33:09 +04:00
|
|
|
vap->va_rdev = (dev_t)rdev;
|
|
|
|
vap->va_mtime = mtime;
|
2005-01-06 14:52:44 +03:00
|
|
|
vap->va_ctime = ctime;
|
2004-04-21 05:05:31 +04:00
|
|
|
vap->va_fsid = vp->v_mount->mnt_stat.f_fsidx.__fsid_val[0];
|
1999-11-02 00:32:41 +03:00
|
|
|
switch (vtyp) {
|
|
|
|
case VDIR:
|
|
|
|
vap->va_blocksize = NFS_DIRFRAGSIZ;
|
|
|
|
break;
|
|
|
|
case VBLK:
|
|
|
|
vap->va_blocksize = BLKDEV_IOSIZE;
|
|
|
|
break;
|
|
|
|
case VCHR:
|
|
|
|
vap->va_blocksize = MAXBSIZE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
vap->va_blocksize = v3 ? vp->v_mount->mnt_stat.f_iosize :
|
|
|
|
fxdr_unsigned(int32_t, fp->fa2_blocksize);
|
|
|
|
break;
|
|
|
|
}
|
1996-02-18 14:53:36 +03:00
|
|
|
if (v3) {
|
|
|
|
vap->va_nlink = fxdr_unsigned(u_short, fp->fa_nlink);
|
2002-03-01 00:38:08 +03:00
|
|
|
vap->va_uid = uid;
|
|
|
|
vap->va_gid = gid;
|
1999-03-06 08:34:40 +03:00
|
|
|
vap->va_size = fxdr_hyper(&fp->fa3_size);
|
|
|
|
vap->va_bytes = fxdr_hyper(&fp->fa3_used);
|
2005-08-19 16:47:23 +04:00
|
|
|
vap->va_fileid = fxdr_hyper(&fp->fa3_fileid);
|
1996-02-18 14:53:36 +03:00
|
|
|
fxdr_nfsv3time(&fp->fa3_atime, &vap->va_atime);
|
|
|
|
vap->va_flags = 0;
|
|
|
|
vap->va_filerev = 0;
|
1994-06-08 15:33:09 +04:00
|
|
|
} else {
|
1996-02-18 14:53:36 +03:00
|
|
|
vap->va_nlink = fxdr_unsigned(u_short, fp->fa_nlink);
|
2002-03-01 00:38:08 +03:00
|
|
|
vap->va_uid = uid;
|
|
|
|
vap->va_gid = gid;
|
1996-02-18 14:53:36 +03:00
|
|
|
vap->va_size = fxdr_unsigned(u_int32_t, fp->fa2_size);
|
|
|
|
vap->va_bytes = fxdr_unsigned(int32_t, fp->fa2_blocks)
|
|
|
|
* NFS_FABLKSIZE;
|
|
|
|
vap->va_fileid = fxdr_unsigned(int32_t, fp->fa2_fileid);
|
|
|
|
fxdr_nfsv2time(&fp->fa2_atime, &vap->va_atime);
|
1994-06-08 15:33:09 +04:00
|
|
|
vap->va_flags = 0;
|
1996-02-18 14:53:36 +03:00
|
|
|
vap->va_gen = fxdr_unsigned(u_int32_t,fp->fa2_ctime.nfsv2_usec);
|
1994-06-08 15:33:09 +04:00
|
|
|
vap->va_filerev = 0;
|
|
|
|
}
|
|
|
|
if (vap->va_size != np->n_size) {
|
2000-11-27 11:39:39 +03:00
|
|
|
if ((np->n_flag & NMODIFIED) && vap->va_size < np->n_size) {
|
|
|
|
vap->va_size = np->n_size;
|
|
|
|
} else {
|
1994-06-08 15:33:09 +04:00
|
|
|
np->n_size = vap->va_size;
|
2000-11-27 11:39:39 +03:00
|
|
|
if (vap->va_type == VREG) {
|
2005-01-09 04:32:32 +03:00
|
|
|
/*
|
|
|
|
* we can't free pages if NAC_NOTRUNC because
|
|
|
|
* the pages can be owned by ourselves.
|
|
|
|
*/
|
|
|
|
if (flags & NAC_NOTRUNC) {
|
2002-10-21 16:52:32 +04:00
|
|
|
np->n_flag |= NTRUNCDELAYED;
|
2005-01-09 04:32:32 +03:00
|
|
|
} else {
|
|
|
|
simple_lock(&vp->v_interlock);
|
|
|
|
(void)VOP_PUTPAGES(vp, 0,
|
|
|
|
0, PGO_SYNCIO | PGO_CLEANIT |
|
|
|
|
PGO_FREE | PGO_ALLPAGES);
|
2002-10-21 16:52:32 +04:00
|
|
|
uvm_vnp_setsize(vp, np->n_size);
|
|
|
|
}
|
2000-11-27 11:39:39 +03:00
|
|
|
}
|
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
2005-01-21 17:31:29 +03:00
|
|
|
np->n_attrstamp = mono_time.tv_sec;
|
1994-06-08 15:33:09 +04:00
|
|
|
if (vaper != NULL) {
|
1998-08-10 00:51:08 +04:00
|
|
|
memcpy((caddr_t)vaper, (caddr_t)vap, sizeof(*vap));
|
1994-06-08 15:33:09 +04:00
|
|
|
if (np->n_flag & NCHG) {
|
1996-02-18 14:53:36 +03:00
|
|
|
if (np->n_flag & NACC)
|
|
|
|
vaper->va_atime = np->n_atim;
|
|
|
|
if (np->n_flag & NUPD)
|
|
|
|
vaper->va_mtime = np->n_mtim;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the time stamp
|
|
|
|
* If the cache is valid, copy contents to *vap and return 0
|
|
|
|
* otherwise return an error
|
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
int
|
1994-06-08 15:33:09 +04:00
|
|
|
nfs_getattrcache(vp, vaper)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct vnode *vp;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct vattr *vaper;
|
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct nfsnode *np = VTONFS(vp);
|
2005-09-19 04:49:52 +04:00
|
|
|
struct nfsmount *nmp = VFSTONFS(vp->v_mount);
|
2000-03-30 16:51:13 +04:00
|
|
|
struct vattr *vap;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
2004-03-19 16:53:28 +03:00
|
|
|
if (np->n_attrstamp == 0 ||
|
2005-09-19 04:49:52 +04:00
|
|
|
(mono_time.tv_sec - np->n_attrstamp) >= NFS_ATTRTIMEO(nmp, np)) {
|
1994-06-08 15:33:09 +04:00
|
|
|
nfsstats.attrcache_misses++;
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
nfsstats.attrcache_hits++;
|
1997-10-19 05:46:15 +04:00
|
|
|
vap = np->n_vattr;
|
1994-06-08 15:33:09 +04:00
|
|
|
if (vap->va_size != np->n_size) {
|
|
|
|
if (vap->va_type == VREG) {
|
|
|
|
if (np->n_flag & NMODIFIED) {
|
|
|
|
if (vap->va_size < np->n_size)
|
|
|
|
vap->va_size = np->n_size;
|
|
|
|
else
|
|
|
|
np->n_size = vap->va_size;
|
|
|
|
} else
|
|
|
|
np->n_size = vap->va_size;
|
1998-02-05 10:59:28 +03:00
|
|
|
uvm_vnp_setsize(vp, np->n_size);
|
1994-06-08 15:33:09 +04:00
|
|
|
} else
|
|
|
|
np->n_size = vap->va_size;
|
|
|
|
}
|
1998-08-10 00:51:08 +04:00
|
|
|
memcpy((caddr_t)vaper, (caddr_t)vap, sizeof(struct vattr));
|
1994-06-08 15:33:09 +04:00
|
|
|
if (np->n_flag & NCHG) {
|
1996-02-18 14:53:36 +03:00
|
|
|
if (np->n_flag & NACC)
|
|
|
|
vaper->va_atime = np->n_atim;
|
|
|
|
if (np->n_flag & NUPD)
|
|
|
|
vaper->va_mtime = np->n_mtim;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-10-11 06:09:48 +04:00
|
|
|
|
2002-10-21 16:52:32 +04:00
|
|
|
void
|
|
|
|
nfs_delayedtruncate(vp)
|
|
|
|
struct vnode *vp;
|
|
|
|
{
|
|
|
|
struct nfsnode *np = VTONFS(vp);
|
|
|
|
|
|
|
|
if (np->n_flag & NTRUNCDELAYED) {
|
|
|
|
np->n_flag &= ~NTRUNCDELAYED;
|
2005-01-09 04:32:32 +03:00
|
|
|
simple_lock(&vp->v_interlock);
|
|
|
|
(void)VOP_PUTPAGES(vp, 0,
|
|
|
|
0, PGO_SYNCIO | PGO_CLEANIT | PGO_FREE | PGO_ALLPAGES);
|
2002-10-21 16:52:32 +04:00
|
|
|
uvm_vnp_setsize(vp, np->n_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-19 19:22:19 +03:00
|
|
|
#define NFS_WCCKLUDGE_TIMEOUT (24 * 60 * 60) /* 1 day */
|
|
|
|
#define NFS_WCCKLUDGE(nmp, now) \
|
|
|
|
(((nmp)->nm_iflag & NFSMNT_WCCKLUDGE) && \
|
|
|
|
((now) - (nmp)->nm_wcckludgetime - NFS_WCCKLUDGE_TIMEOUT) < 0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nfs_check_wccdata: check inaccurate wcc_data
|
|
|
|
*
|
|
|
|
* => return non-zero if we shouldn't trust the wcc_data.
|
|
|
|
* => NFS_WCCKLUDGE_TIMEOUT is for the case that the server is "fixed".
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
nfs_check_wccdata(struct nfsnode *np, const struct timespec *ctime,
|
|
|
|
struct timespec *mtime, boolean_t docheck)
|
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
#if !defined(NFS_V2_ONLY)
|
|
|
|
|
|
|
|
if (docheck) {
|
|
|
|
struct vnode *vp = NFSTOV(np);
|
|
|
|
struct nfsmount *nmp;
|
|
|
|
long now = mono_time.tv_sec;
|
|
|
|
#if defined(DEBUG)
|
|
|
|
const char *reason = NULL; /* XXX: gcc */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (timespeccmp(&np->n_vattr->va_mtime, mtime, <=)) {
|
|
|
|
#if defined(DEBUG)
|
|
|
|
reason = "mtime";
|
|
|
|
#endif
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vp->v_type == VDIR &&
|
|
|
|
timespeccmp(&np->n_vattr->va_ctime, ctime, <=)) {
|
|
|
|
#if defined(DEBUG)
|
|
|
|
reason = "ctime";
|
|
|
|
#endif
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
nmp = VFSTONFS(vp->v_mount);
|
|
|
|
if (error) {
|
2005-01-25 15:20:32 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* despite of the fact that we've updated the file,
|
|
|
|
* timestamps of the file were not updated as we
|
|
|
|
* expected.
|
|
|
|
* it means that the server has incompatible
|
|
|
|
* semantics of timestamps or (more likely)
|
|
|
|
* the server time is not precise enough to
|
|
|
|
* track each modifications.
|
|
|
|
* in that case, we disable wcc processing.
|
|
|
|
*
|
|
|
|
* yes, strictly speaking, we should disable all
|
|
|
|
* caching. it's a compromise.
|
|
|
|
*/
|
|
|
|
|
2005-01-19 19:22:19 +03:00
|
|
|
simple_lock(&nmp->nm_slock);
|
|
|
|
#if defined(DEBUG)
|
|
|
|
if (!NFS_WCCKLUDGE(nmp, now)) {
|
|
|
|
printf("%s: inaccurate wcc data (%s) detected,"
|
|
|
|
" disabling wcc\n",
|
|
|
|
vp->v_mount->mnt_stat.f_mntfromname,
|
|
|
|
reason);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
nmp->nm_iflag |= NFSMNT_WCCKLUDGE;
|
|
|
|
nmp->nm_wcckludgetime = now;
|
|
|
|
simple_unlock(&nmp->nm_slock);
|
|
|
|
} else if (NFS_WCCKLUDGE(nmp, now)) {
|
|
|
|
error = EPERM; /* XXX */
|
|
|
|
} else if (nmp->nm_iflag & NFSMNT_WCCKLUDGE) {
|
|
|
|
simple_lock(&nmp->nm_slock);
|
|
|
|
if (nmp->nm_iflag & NFSMNT_WCCKLUDGE) {
|
|
|
|
#if defined(DEBUG)
|
|
|
|
printf("%s: re-enabling wcc\n",
|
|
|
|
vp->v_mount->mnt_stat.f_mntfromname);
|
|
|
|
#endif
|
|
|
|
nmp->nm_iflag &= ~NFSMNT_WCCKLUDGE;
|
|
|
|
}
|
|
|
|
simple_unlock(&nmp->nm_slock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !defined(NFS_V2_ONLY) */
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
1997-10-11 06:09:48 +04:00
|
|
|
/*
|
|
|
|
* Heuristic to see if the server XDR encodes directory cookies or not.
|
|
|
|
* it is not supposed to, but a lot of servers may do this. Also, since
|
|
|
|
* most/all servers will implement V2 as well, it is expected that they
|
|
|
|
* may return just 32 bits worth of cookie information, so we need to
|
|
|
|
* find out in which 32 bits this information is available. We do this
|
|
|
|
* to avoid trouble with emulated binaries that can't handle 64 bit
|
|
|
|
* directory offsets.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2003-06-30 02:28:00 +04:00
|
|
|
nfs_cookieheuristic(vp, flagp, p, cred)
|
1997-10-11 06:09:48 +04:00
|
|
|
struct vnode *vp;
|
|
|
|
int *flagp;
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p;
|
1997-10-11 06:09:48 +04:00
|
|
|
struct ucred *cred;
|
|
|
|
{
|
|
|
|
struct uio auio;
|
|
|
|
struct iovec aiov;
|
2005-05-30 00:58:13 +04:00
|
|
|
caddr_t tbuf, cp;
|
1997-10-11 06:09:48 +04:00
|
|
|
struct dirent *dp;
|
1998-03-03 16:38:32 +03:00
|
|
|
off_t *cookies = NULL, *cop;
|
1997-10-11 06:09:48 +04:00
|
|
|
int error, eof, nc, len;
|
|
|
|
|
2005-05-30 00:58:13 +04:00
|
|
|
MALLOC(tbuf, caddr_t, NFS_DIRFRAGSIZ, M_TEMP, M_WAITOK);
|
1997-10-11 06:09:48 +04:00
|
|
|
|
2005-05-30 00:58:13 +04:00
|
|
|
aiov.iov_base = tbuf;
|
1997-10-11 06:09:48 +04:00
|
|
|
aiov.iov_len = NFS_DIRFRAGSIZ;
|
|
|
|
auio.uio_iov = &aiov;
|
|
|
|
auio.uio_iovcnt = 1;
|
|
|
|
auio.uio_rw = UIO_READ;
|
|
|
|
auio.uio_segflg = UIO_SYSSPACE;
|
2004-09-17 18:11:20 +04:00
|
|
|
auio.uio_procp = NULL;
|
1997-10-11 06:09:48 +04:00
|
|
|
auio.uio_resid = NFS_DIRFRAGSIZ;
|
|
|
|
auio.uio_offset = 0;
|
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
error = VOP_READDIR(vp, &auio, cred, &eof, &cookies, &nc);
|
1997-10-11 06:09:48 +04:00
|
|
|
|
|
|
|
len = NFS_DIRFRAGSIZ - auio.uio_resid;
|
|
|
|
if (error || len == 0) {
|
2005-05-30 00:58:13 +04:00
|
|
|
FREE(tbuf, M_TEMP);
|
1998-03-03 16:38:32 +03:00
|
|
|
if (cookies)
|
2000-08-03 10:15:02 +04:00
|
|
|
free(cookies, M_TEMP);
|
1997-10-11 06:09:48 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the first valid entry and look at its offset cookie.
|
|
|
|
*/
|
|
|
|
|
2005-05-30 00:58:13 +04:00
|
|
|
cp = tbuf;
|
1997-10-11 06:09:48 +04:00
|
|
|
for (cop = cookies; len > 0; len -= dp->d_reclen) {
|
|
|
|
dp = (struct dirent *)cp;
|
|
|
|
if (dp->d_fileno != 0 && len >= dp->d_reclen) {
|
|
|
|
if ((*cop >> 32) != 0 && (*cop & 0xffffffffLL) == 0) {
|
|
|
|
*flagp |= NFSMNT_SWAPCOOKIE;
|
1997-10-19 05:46:15 +04:00
|
|
|
nfs_invaldircache(vp, 0);
|
2003-06-30 02:28:00 +04:00
|
|
|
nfs_vinvalbuf(vp, 0, cred, p, 1);
|
1997-10-11 06:09:48 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cop++;
|
|
|
|
cp += dp->d_reclen;
|
|
|
|
}
|
|
|
|
|
2005-05-30 00:58:13 +04:00
|
|
|
FREE(tbuf, M_TEMP);
|
2000-08-03 10:15:02 +04:00
|
|
|
free(cookies, M_TEMP);
|
1997-10-11 06:09:48 +04:00
|
|
|
}
|
1997-01-31 05:58:48 +03:00
|
|
|
#endif /* NFS */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
Apply the NFS exports list rototill patch:
- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.
Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
2005-09-23 16:10:31 +04:00
|
|
|
#ifdef NFSSERVER
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1997-06-25 03:36:02 +04: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.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
int
|
2003-06-30 02:28:00 +04:00
|
|
|
nfs_namei(ndp, fhp, len, slp, nam, mdp, dposp, retdirp, p, kerbflag, pubflag)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct nameidata *ndp;
|
1993-03-21 12:45:37 +03:00
|
|
|
fhandle_t *fhp;
|
2003-03-28 16:05:47 +03:00
|
|
|
uint32_t len;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct nfssvc_sock *slp;
|
|
|
|
struct mbuf *nam;
|
1993-03-21 12:45:37 +03:00
|
|
|
struct mbuf **mdp;
|
|
|
|
caddr_t *dposp;
|
1996-02-18 14:53:36 +03:00
|
|
|
struct vnode **retdirp;
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p;
|
1997-06-25 03:36:02 +04:00
|
|
|
int kerbflag, pubflag;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
int i, rem;
|
|
|
|
struct mbuf *md;
|
|
|
|
char *fromcp, *tocp, *cp;
|
1997-06-25 03:36:02 +04:00
|
|
|
struct iovec aiov;
|
|
|
|
struct uio auio;
|
1993-03-21 12:45:37 +03:00
|
|
|
struct vnode *dp;
|
1997-06-25 03:36:02 +04:00
|
|
|
int error, rdonly, linklen;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct componentname *cnp = &ndp->ni_cnd;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
*retdirp = (struct vnode *)0;
|
2000-08-04 00:41:05 +04:00
|
|
|
|
|
|
|
if ((len + 1) > MAXPATHLEN)
|
|
|
|
return (ENAMETOOLONG);
|
2005-01-28 13:12:23 +03:00
|
|
|
if (len == 0)
|
|
|
|
return (EACCES);
|
2000-08-04 00:41:05 +04:00
|
|
|
cnp->cn_pnbuf = PNBUF_GET();
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Copy the name from the mbuf list to ndp->ni_pnbuf
|
|
|
|
* and set the various ndp fields appropriately.
|
|
|
|
*/
|
|
|
|
fromcp = *dposp;
|
1994-06-08 15:33:09 +04:00
|
|
|
tocp = cnp->cn_pnbuf;
|
1993-03-21 12:45:37 +03:00
|
|
|
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-06-25 03:36:02 +04:00
|
|
|
if (*fromcp == '\0' || (!pubflag && *fromcp == '/')) {
|
1996-02-18 14:53:36 +03:00
|
|
|
error = EACCES;
|
1993-03-21 12:45:37 +03: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;
|
1996-02-10 00:48:19 +03:00
|
|
|
else if ((error = nfs_adv(mdp, dposp, len, rem)) != 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
goto out;
|
|
|
|
}
|
1997-06-25 03:36:02 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Extract and set starting directory.
|
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
error = nfsrv_fhtovp(fhp, FALSE, &dp, ndp->ni_cnd.cn_cred, slp,
|
2003-06-29 22:43:21 +04:00
|
|
|
nam, &rdonly, kerbflag, pubflag);
|
1996-02-10 00:48:19 +03:00
|
|
|
if (error)
|
1993-03-21 12:45:37 +03:00
|
|
|
goto out;
|
|
|
|
if (dp->v_type != VDIR) {
|
|
|
|
vrele(dp);
|
|
|
|
error = ENOTDIR;
|
|
|
|
goto out;
|
|
|
|
}
|
1997-06-25 03:36:02 +04:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
if (rdonly)
|
1997-06-25 03:36:02 +04:00
|
|
|
cnp->cn_flags |= RDONLY;
|
|
|
|
|
|
|
|
*retdirp = dp;
|
|
|
|
|
|
|
|
if (pubflag) {
|
|
|
|
/*
|
|
|
|
* Oh joy. For WebNFS, handle those pesky '%' escapes,
|
|
|
|
* and the 'native path' indicator.
|
|
|
|
*/
|
2000-08-04 00:41:05 +04:00
|
|
|
cp = PNBUF_GET();
|
1997-06-25 03:36:02 +04: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;
|
2002-08-23 09:38:51 +04:00
|
|
|
PNBUF_PUT(cp);
|
1997-06-25 03:36:02 +04: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;
|
2002-08-23 09:38:51 +04:00
|
|
|
PNBUF_PUT(cp);
|
1997-06-25 03:36:02 +04:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
*tocp++ = *fromcp++;
|
|
|
|
}
|
|
|
|
*tocp = '\0';
|
2000-08-04 00:41:05 +04:00
|
|
|
PNBUF_PUT(cnp->cn_pnbuf);
|
1997-06-25 03:36:02 +04:00
|
|
|
cnp->cn_pnbuf = cp;
|
|
|
|
}
|
|
|
|
|
|
|
|
ndp->ni_pathlen = (tocp - cnp->cn_pnbuf) + 1;
|
|
|
|
ndp->ni_segflg = UIO_SYSSPACE;
|
2001-09-28 01:44:56 +04:00
|
|
|
ndp->ni_rootdir = rootvnode;
|
1997-06-25 03:36:02 +04:00
|
|
|
|
|
|
|
if (pubflag) {
|
|
|
|
ndp->ni_loopcnt = 0;
|
|
|
|
if (cnp->cn_pnbuf[0] == '/')
|
|
|
|
dp = rootvnode;
|
|
|
|
} else {
|
1994-06-08 15:33:09 +04:00
|
|
|
cnp->cn_flags |= NOCROSSMOUNT;
|
1997-06-25 03:36:02 +04:00
|
|
|
}
|
|
|
|
|
2003-06-30 02:28:00 +04:00
|
|
|
cnp->cn_proc = p;
|
1997-06-25 03:36:02 +04:00
|
|
|
VREF(dp);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
cnp->cn_nameptr = cnp->cn_pnbuf;
|
|
|
|
ndp->ni_startdir = dp;
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* And call lookup() to do the real work
|
|
|
|
*/
|
1996-02-18 14:53:36 +03:00
|
|
|
error = lookup(ndp);
|
2001-02-14 18:36:45 +03:00
|
|
|
if (error) {
|
|
|
|
PNBUF_PUT(cnp->cn_pnbuf);
|
|
|
|
return (error);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Check for encountering a symbolic link
|
|
|
|
*/
|
1997-06-25 03:36:02 +04:00
|
|
|
if ((cnp->cn_flags & ISSYMLINK) == 0) {
|
2001-02-14 18:36:45 +03:00
|
|
|
if (cnp->cn_flags & (SAVENAME | SAVESTART))
|
1997-06-25 03:36:02 +04:00
|
|
|
cnp->cn_flags |= HASBUF;
|
2001-02-14 18:36:45 +03:00
|
|
|
else
|
|
|
|
PNBUF_PUT(cnp->cn_pnbuf);
|
|
|
|
return (0);
|
1997-06-25 03:36:02 +04:00
|
|
|
} else {
|
2001-02-14 18:36:45 +03:00
|
|
|
if ((cnp->cn_flags & LOCKPARENT) && (cnp->cn_flags & ISLASTCN))
|
1998-03-01 05:20:01 +03:00
|
|
|
VOP_UNLOCK(ndp->ni_dvp, 0);
|
1997-06-25 03:36:02 +04:00
|
|
|
if (!pubflag) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ndp->ni_loopcnt++ >= MAXSYMLINKS) {
|
|
|
|
error = ELOOP;
|
|
|
|
break;
|
|
|
|
}
|
2001-02-14 18:36:45 +03:00
|
|
|
if (ndp->ni_vp->v_mount->mnt_flag & MNT_SYMPERM) {
|
|
|
|
error = VOP_ACCESS(ndp->ni_vp, VEXEC, cnp->cn_cred,
|
2003-06-30 02:28:00 +04:00
|
|
|
cnp->cn_proc);
|
2001-02-14 18:36:45 +03:00
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
}
|
1997-06-25 03:36:02 +04:00
|
|
|
if (ndp->ni_pathlen > 1)
|
2000-08-04 00:41:05 +04:00
|
|
|
cp = PNBUF_GET();
|
1997-06-25 03:36:02 +04: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;
|
2004-09-17 18:11:20 +04:00
|
|
|
auio.uio_procp = NULL;
|
1997-06-25 03:36:02 +04:00
|
|
|
auio.uio_resid = MAXPATHLEN;
|
|
|
|
error = VOP_READLINK(ndp->ni_vp, &auio, cnp->cn_cred);
|
|
|
|
if (error) {
|
|
|
|
badlink:
|
|
|
|
if (ndp->ni_pathlen > 1)
|
2000-08-04 00:41:05 +04:00
|
|
|
PNBUF_PUT(cp);
|
1997-06-25 03:36:02 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
linklen = MAXPATHLEN - auio.uio_resid;
|
|
|
|
if (linklen == 0) {
|
|
|
|
error = ENOENT;
|
|
|
|
goto badlink;
|
|
|
|
}
|
|
|
|
if (linklen + ndp->ni_pathlen >= MAXPATHLEN) {
|
|
|
|
error = ENAMETOOLONG;
|
|
|
|
goto badlink;
|
|
|
|
}
|
|
|
|
if (ndp->ni_pathlen > 1) {
|
1998-08-10 00:51:08 +04:00
|
|
|
memcpy(cp + linklen, ndp->ni_next, ndp->ni_pathlen);
|
2000-08-04 00:41:05 +04:00
|
|
|
PNBUF_PUT(cnp->cn_pnbuf);
|
1997-06-25 03:36:02 +04:00
|
|
|
cnp->cn_pnbuf = cp;
|
|
|
|
} else
|
|
|
|
cnp->cn_pnbuf[linklen] = '\0';
|
|
|
|
ndp->ni_pathlen += linklen;
|
1993-03-21 12:45:37 +03:00
|
|
|
vput(ndp->ni_vp);
|
1997-06-25 03:36:02 +04:00
|
|
|
dp = ndp->ni_dvp;
|
|
|
|
/*
|
|
|
|
* Check if root directory should replace current directory.
|
|
|
|
*/
|
|
|
|
if (cnp->cn_pnbuf[0] == '/') {
|
|
|
|
vrele(dp);
|
|
|
|
dp = ndp->ni_rootdir;
|
|
|
|
VREF(dp);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-06-25 03:36:02 +04:00
|
|
|
}
|
2001-02-14 18:36:45 +03:00
|
|
|
vrele(ndp->ni_dvp);
|
|
|
|
vput(ndp->ni_vp);
|
|
|
|
ndp->ni_vp = NULL;
|
1993-03-21 12:45:37 +03:00
|
|
|
out:
|
2000-08-04 00:41:05 +04:00
|
|
|
PNBUF_PUT(cnp->cn_pnbuf);
|
1993-03-21 12:45:37 +03:00
|
|
|
return (error);
|
|
|
|
}
|
Apply the NFS exports list rototill patch:
- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.
Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
2005-09-23 16:10:31 +04:00
|
|
|
#endif /* NFSSERVER */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
2003-05-03 22:07:42 +04:00
|
|
|
* A fiddled version of m_adj() that ensures null fill to a 32-bit
|
1993-03-21 12:45:37 +03:00
|
|
|
* boundary and only trims off the back end
|
2003-06-09 17:10:31 +04:00
|
|
|
*
|
|
|
|
* 1. trim off 'len' bytes as m_adj(mp, -len).
|
|
|
|
* 2. add zero-padding 'nul' bytes at the end of the mbuf chain.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1994-06-08 15:33:09 +04:00
|
|
|
void
|
2003-06-09 17:10:31 +04:00
|
|
|
nfs_zeropad(mp, len, nul)
|
1993-03-21 12:45:37 +03:00
|
|
|
struct mbuf *mp;
|
2000-03-30 16:51:13 +04:00
|
|
|
int len;
|
1993-03-21 12:45:37 +03:00
|
|
|
int nul;
|
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mbuf *m;
|
2003-11-29 22:31:13 +03:00
|
|
|
int count;
|
1993-03-21 12:45:37 +03: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;
|
2003-06-09 17:10:31 +04:00
|
|
|
if (m->m_next == NULL)
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
m = m->m_next;
|
|
|
|
}
|
2003-06-09 17:10:31 +04:00
|
|
|
|
|
|
|
KDASSERT(count >= len);
|
|
|
|
|
|
|
|
if (m->m_len >= len) {
|
1993-03-21 12:45:37 +03:00
|
|
|
m->m_len -= len;
|
2003-06-09 17:10:31 +04:00
|
|
|
} else {
|
|
|
|
count -= len;
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
break;
|
2003-05-03 22:07:42 +04:00
|
|
|
}
|
2003-06-09 17:10:31 +04:00
|
|
|
count -= m->m_len;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2003-06-09 17:10:31 +04:00
|
|
|
m_freem(m->m_next);
|
|
|
|
m->m_next = NULL;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2003-06-09 17:10:31 +04:00
|
|
|
|
2003-11-29 22:31:13 +03:00
|
|
|
KDASSERT(m->m_next == NULL);
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
2003-06-09 17:10:31 +04:00
|
|
|
* zero-padding.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2003-06-09 17:10:31 +04:00
|
|
|
if (nul > 0) {
|
2003-11-29 22:31:13 +03:00
|
|
|
char *cp;
|
|
|
|
int i;
|
|
|
|
|
2003-06-09 17:10:31 +04:00
|
|
|
if (M_ROMAP(m) || M_TRAILINGSPACE(m) < nul) {
|
|
|
|
struct mbuf *n;
|
|
|
|
|
|
|
|
KDASSERT(MLEN >= nul);
|
|
|
|
n = m_get(M_WAIT, MT_DATA);
|
|
|
|
MCLAIM(n, &nfs_mowner);
|
|
|
|
n->m_len = nul;
|
2003-11-29 22:31:13 +03:00
|
|
|
n->m_next = NULL;
|
2003-06-09 17:10:31 +04:00
|
|
|
m->m_next = n;
|
|
|
|
cp = mtod(n, caddr_t);
|
|
|
|
} else {
|
|
|
|
cp = mtod(m, caddr_t) + m->m_len;
|
|
|
|
m->m_len += nul;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2003-06-09 17:10:31 +04:00
|
|
|
for (i = 0; i < nul; i++)
|
|
|
|
*cp++ = '\0';
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2003-06-09 17:10:31 +04:00
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
/*
|
|
|
|
* Make these functions instead of macros, so that the kernel text size
|
|
|
|
* doesn't get too big...
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nfsm_srvwcc(nfsd, before_ret, before_vap, after_ret, after_vap, mbp, bposp)
|
|
|
|
struct nfsrv_descript *nfsd;
|
|
|
|
int before_ret;
|
2000-03-30 16:51:13 +04:00
|
|
|
struct vattr *before_vap;
|
1996-02-18 14:53:36 +03:00
|
|
|
int after_ret;
|
|
|
|
struct vattr *after_vap;
|
|
|
|
struct mbuf **mbp;
|
|
|
|
char **bposp;
|
|
|
|
{
|
2003-02-26 09:31:08 +03:00
|
|
|
struct mbuf *mb = *mbp;
|
2000-03-30 16:51:13 +04:00
|
|
|
char *bpos = *bposp;
|
|
|
|
u_int32_t *tl;
|
1996-02-18 14:53:36 +03:00
|
|
|
|
|
|
|
if (before_ret) {
|
|
|
|
nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
|
|
|
|
*tl = nfs_false;
|
|
|
|
} else {
|
|
|
|
nfsm_build(tl, u_int32_t *, 7 * NFSX_UNSIGNED);
|
|
|
|
*tl++ = nfs_true;
|
1999-03-06 08:34:40 +03:00
|
|
|
txdr_hyper(before_vap->va_size, tl);
|
1996-02-18 14:53:36 +03: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
|
|
|
|
nfsm_srvpostopattr(nfsd, after_ret, after_vap, mbp, bposp)
|
|
|
|
struct nfsrv_descript *nfsd;
|
|
|
|
int after_ret;
|
|
|
|
struct vattr *after_vap;
|
|
|
|
struct mbuf **mbp;
|
|
|
|
char **bposp;
|
|
|
|
{
|
2003-02-26 09:31:08 +03:00
|
|
|
struct mbuf *mb = *mbp;
|
2000-03-30 16:51:13 +04:00
|
|
|
char *bpos = *bposp;
|
|
|
|
u_int32_t *tl;
|
|
|
|
struct nfs_fattr *fp;
|
1996-02-18 14:53:36 +03:00
|
|
|
|
|
|
|
if (after_ret) {
|
|
|
|
nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
|
|
|
|
*tl = nfs_false;
|
|
|
|
} else {
|
|
|
|
nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED + NFSX_V3FATTR);
|
|
|
|
*tl++ = nfs_true;
|
|
|
|
fp = (struct nfs_fattr *)tl;
|
|
|
|
nfsm_srvfattr(nfsd, after_vap, fp);
|
|
|
|
}
|
|
|
|
*mbp = mb;
|
|
|
|
*bposp = bpos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nfsm_srvfattr(nfsd, vap, fp)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct nfsrv_descript *nfsd;
|
|
|
|
struct vattr *vap;
|
|
|
|
struct nfs_fattr *fp;
|
1996-02-18 14:53:36 +03: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-03-06 08:34:40 +03:00
|
|
|
txdr_hyper(vap->va_size, &fp->fa3_size);
|
|
|
|
txdr_hyper(vap->va_bytes, &fp->fa3_used);
|
1996-02-18 14:53:36 +03:00
|
|
|
fp->fa3_rdev.specdata1 = txdr_unsigned(major(vap->va_rdev));
|
|
|
|
fp->fa3_rdev.specdata2 = txdr_unsigned(minor(vap->va_rdev));
|
|
|
|
fp->fa3_fsid.nfsuquad[0] = 0;
|
|
|
|
fp->fa3_fsid.nfsuquad[1] = txdr_unsigned(vap->va_fsid);
|
2005-08-19 16:47:23 +04:00
|
|
|
txdr_hyper(vap->va_fileid, &fp->fa3_fileid);
|
1996-02-18 14:53:36 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Apply the NFS exports list rototill patch:
- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.
Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
2005-09-23 16:10:31 +04:00
|
|
|
#ifdef NFSSERVER
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* nfsrv_fhtovp() - convert a fh to a vnode ptr (optionally locked)
|
|
|
|
* - look up fsid in mount list (if not found ret error)
|
1994-06-08 15:33:09 +04:00
|
|
|
* - get vp and export rights by calling VFS_FHTOVP()
|
|
|
|
* - if cred->cr_uid == 0 or MNT_EXPORTANON set it to credanon
|
1993-03-21 12:45:37 +03:00
|
|
|
* - if not lockflag unlock it with VOP_UNLOCK()
|
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
int
|
2003-06-29 22:43:21 +04:00
|
|
|
nfsrv_fhtovp(fhp, lockflag, vpp, cred, slp, nam, rdonlyp, kerbflag, pubflag)
|
1993-03-21 12:45:37 +03:00
|
|
|
fhandle_t *fhp;
|
|
|
|
int lockflag;
|
|
|
|
struct vnode **vpp;
|
|
|
|
struct ucred *cred;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct nfssvc_sock *slp;
|
|
|
|
struct mbuf *nam;
|
|
|
|
int *rdonlyp;
|
1996-02-18 14:53:36 +03:00
|
|
|
int kerbflag;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mount *mp;
|
|
|
|
int i;
|
1994-06-08 15:33:09 +04:00
|
|
|
struct ucred *credanon;
|
|
|
|
int error, exflags;
|
1997-03-23 23:55:51 +03:00
|
|
|
struct sockaddr_in *saddr;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
*vpp = (struct vnode *)0;
|
1997-06-25 03:36:02 +04:00
|
|
|
|
|
|
|
if (nfs_ispublicfh(fhp)) {
|
|
|
|
if (!pubflag || !nfs_pub.np_valid)
|
|
|
|
return (ESTALE);
|
|
|
|
fhp = &nfs_pub.np_handle;
|
|
|
|
}
|
|
|
|
|
2005-11-22 07:44:29 +03:00
|
|
|
error = netexport_check(&fhp->fh_fsid, nam, &mp, &exflags, &credanon);
|
|
|
|
if (error) {
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2003-06-29 22:43:21 +04:00
|
|
|
error = VFS_FHTOVP(mp, &fhp->fh_fid, vpp);
|
1996-02-10 00:48:19 +03:00
|
|
|
if (error)
|
1994-06-08 15:33:09 +04:00
|
|
|
return (error);
|
1997-03-23 23:55:51 +03:00
|
|
|
|
1997-06-25 03:36:02 +04:00
|
|
|
if (!(exflags & (MNT_EXNORESPORT|MNT_EXPUBLIC))) {
|
1997-03-23 23:55:51 +03:00
|
|
|
saddr = mtod(nam, struct sockaddr_in *);
|
2000-06-09 04:00:17 +04:00
|
|
|
if ((saddr->sin_family == AF_INET) &&
|
1997-03-23 23:55:51 +03:00
|
|
|
ntohs(saddr->sin_port) >= IPPORT_RESERVED) {
|
|
|
|
vput(*vpp);
|
|
|
|
return (NFSERR_AUTHERR | AUTH_TOOWEAK);
|
|
|
|
}
|
2000-06-09 04:00:17 +04:00
|
|
|
#ifdef INET6
|
|
|
|
if ((saddr->sin_family == AF_INET6) &&
|
|
|
|
ntohs(saddr->sin_port) >= IPV6PORT_RESERVED) {
|
|
|
|
vput(*vpp);
|
|
|
|
return (NFSERR_AUTHERR | AUTH_TOOWEAK);
|
|
|
|
}
|
|
|
|
#endif
|
1997-03-23 23:55:51 +03:00
|
|
|
}
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Check/setup credentials.
|
|
|
|
*/
|
|
|
|
if (exflags & MNT_EXKERB) {
|
1996-02-18 14:53:36 +03:00
|
|
|
if (!kerbflag) {
|
1994-06-08 15:33:09 +04:00
|
|
|
vput(*vpp);
|
1996-02-18 14:53:36 +03:00
|
|
|
return (NFSERR_AUTHERR | AUTH_TOOWEAK);
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
1996-02-18 14:53:36 +03:00
|
|
|
} else if (kerbflag) {
|
|
|
|
vput(*vpp);
|
|
|
|
return (NFSERR_AUTHERR | AUTH_TOOWEAK);
|
1994-06-08 15:33:09 +04:00
|
|
|
} else if (cred->cr_uid == 0 || (exflags & MNT_EXPORTANON)) {
|
|
|
|
cred->cr_uid = credanon->cr_uid;
|
1995-06-02 02:43:30 +04:00
|
|
|
cred->cr_gid = credanon->cr_gid;
|
1994-06-08 15:33:09 +04:00
|
|
|
for (i = 0; i < credanon->cr_ngroups && i < NGROUPS; i++)
|
|
|
|
cred->cr_groups[i] = credanon->cr_groups[i];
|
1994-07-23 03:16:36 +04:00
|
|
|
cred->cr_ngroups = i;
|
1994-06-08 15:33:09 +04:00
|
|
|
}
|
|
|
|
if (exflags & MNT_EXRDONLY)
|
|
|
|
*rdonlyp = 1;
|
|
|
|
else
|
|
|
|
*rdonlyp = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
if (!lockflag)
|
1998-03-01 05:20:01 +03:00
|
|
|
VOP_UNLOCK(*vpp, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1997-06-25 03:36:02 +04: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
|
|
|
|
nfs_ispublicfh(fhp)
|
|
|
|
fhandle_t *fhp;
|
|
|
|
{
|
|
|
|
char *cp = (char *)fhp;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NFSX_V3FH; i++)
|
|
|
|
if (*cp++ != 0)
|
|
|
|
return (FALSE);
|
|
|
|
return (TRUE);
|
|
|
|
}
|
Apply the NFS exports list rototill patch:
- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.
Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
2005-09-23 16:10:31 +04:00
|
|
|
#endif /* NFSSERVER */
|
1997-06-25 03:36:02 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-06-08 15:33:09 +04: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.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1996-02-10 00:48:19 +03:00
|
|
|
int
|
1994-06-08 15:33:09 +04:00
|
|
|
netaddr_match(family, haddr, nam)
|
|
|
|
int family;
|
|
|
|
union nethostaddr *haddr;
|
|
|
|
struct mbuf *nam;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct sockaddr_in *inetaddr;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
switch (family) {
|
|
|
|
case AF_INET:
|
|
|
|
inetaddr = mtod(nam, struct sockaddr_in *);
|
|
|
|
if (inetaddr->sin_family == AF_INET &&
|
|
|
|
inetaddr->sin_addr.s_addr == haddr->had_inetaddr)
|
|
|
|
return (1);
|
|
|
|
break;
|
2000-06-09 04:00:17 +04:00
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
{
|
|
|
|
struct sockaddr_in6 *sin6_1, *sin6_2;
|
|
|
|
|
|
|
|
sin6_1 = mtod(nam, struct sockaddr_in6 *);
|
|
|
|
sin6_2 = mtod(haddr->had_nam, struct sockaddr_in6 *);
|
|
|
|
if (sin6_1->sin6_family == AF_INET6 &&
|
|
|
|
IN6_ARE_ADDR_EQUAL(&sin6_1->sin6_addr, &sin6_2->sin6_addr))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
1994-06-08 15:33:09 +04:00
|
|
|
#ifdef ISO
|
|
|
|
case AF_ISO:
|
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct sockaddr_iso *isoaddr1, *isoaddr2;
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
isoaddr1 = mtod(nam, struct sockaddr_iso *);
|
|
|
|
isoaddr2 = mtod(haddr->had_nam, struct sockaddr_iso *);
|
|
|
|
if (isoaddr1->siso_family == AF_ISO &&
|
|
|
|
isoaddr1->siso_nlen > 0 &&
|
|
|
|
isoaddr1->siso_nlen == isoaddr2->siso_nlen &&
|
|
|
|
SAME_ISOADDR(isoaddr1, isoaddr2))
|
|
|
|
return (1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif /* ISO */
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1996-02-18 14:53:36 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The write verifier has changed (probably due to a server reboot), so all
|
2003-04-16 18:51:55 +04:00
|
|
|
* PG_NEEDCOMMIT pages will have to be written again. Since they are marked
|
2003-05-03 20:35:22 +04:00
|
|
|
* as dirty or are being written out just now, all this takes is clearing
|
|
|
|
* the PG_NEEDCOMMIT flag. Once done the new write verifier can be set for
|
|
|
|
* the mount point.
|
1996-02-18 14:53:36 +03:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
nfs_clearcommit(mp)
|
|
|
|
struct mount *mp;
|
|
|
|
{
|
2000-11-27 11:39:39 +03:00
|
|
|
struct vnode *vp;
|
2000-09-20 02:13:55 +04:00
|
|
|
struct nfsnode *np;
|
2000-11-27 11:39:39 +03:00
|
|
|
struct vm_page *pg;
|
2003-05-03 20:28:57 +04:00
|
|
|
struct nfsmount *nmp = VFSTONFS(mp);
|
|
|
|
|
|
|
|
lockmgr(&nmp->nm_writeverflock, LK_EXCLUSIVE, NULL);
|
1996-02-18 14:53:36 +03:00
|
|
|
|
2000-11-27 11:39:39 +03:00
|
|
|
LIST_FOREACH(vp, &mp->mnt_vnodelist, v_mntvnodes) {
|
|
|
|
KASSERT(vp->v_mount == mp);
|
2005-01-28 13:11:31 +03:00
|
|
|
if (vp->v_type != VREG)
|
2000-09-24 10:59:21 +04:00
|
|
|
continue;
|
2000-09-20 02:13:55 +04:00
|
|
|
np = VTONFS(vp);
|
|
|
|
np->n_pushlo = np->n_pushhi = np->n_pushedlo =
|
|
|
|
np->n_pushedhi = 0;
|
|
|
|
np->n_commitflags &=
|
|
|
|
~(NFS_COMMIT_PUSH_VALID | NFS_COMMIT_PUSHED_VALID);
|
a whole bunch of changes to improve performance and robustness under load:
- remove special treatment of pager_map mappings in pmaps. this is
required now, since I've removed the globals that expose the address range.
pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's
no longer any need to special-case it.
- eliminate struct uvm_vnode by moving its fields into struct vnode.
- rewrite the pageout path. the pager is now responsible for handling the
high-level requests instead of only getting control after a bunch of work
has already been done on its behalf. this will allow us to UBCify LFS,
which needs tighter control over its pages than other filesystems do.
writing a page to disk no longer requires making it read-only, which
allows us to write wired pages without causing all kinds of havoc.
- use a new PG_PAGEOUT flag to indicate that a page should be freed
on behalf of the pagedaemon when it's unlocked. this flag is very similar
to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the
pageout fails due to eg. an indirect-block buffer being locked.
this allows us to remove the "version" field from struct vm_page,
and together with shrinking "loan_count" from 32 bits to 16,
struct vm_page is now 4 bytes smaller.
- no longer use PG_RELEASED for swap-backed pages. if the page is busy
because it's being paged out, we can't release the swap slot to be
reallocated until that write is complete, but unlike with vnodes we
don't keep a count of in-progress writes so there's no good way to
know when the write is done. instead, when we need to free a busy
swap-backed page, just sleep until we can get it busy ourselves.
- implement a fast-path for extending writes which allows us to avoid
zeroing new pages. this substantially reduces cpu usage.
- encapsulate the data used by the genfs code in a struct genfs_node,
which must be the first element of the filesystem-specific vnode data
for filesystems which use genfs_{get,put}pages().
- eliminate many of the UVM pagerops, since they aren't needed anymore
now that the pager "put" operation is a higher-level operation.
- enhance the genfs code to allow NFS to use the genfs_{get,put}pages
instead of a modified copy.
- clean up struct vnode by removing all the fields that used to be used by
the vfs_cluster.c code (which we don't use anymore with UBC).
- remove kmem_object and mb_object since they were useless.
instead of allocating pages to these objects, we now just allocate
pages with no object. such pages are mapped in the kernel until they
are freed, so we can use the mapping to find the page to free it.
this allows us to remove splvm() protection in several places.
The sum of all these changes improves write throughput on my
decstation 5000/200 to within 1% of the rate of NetBSD 1.5
and reduces the elapsed time for "make release" of a NetBSD 1.5
source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
|
|
|
simple_lock(&vp->v_uobj.vmobjlock);
|
|
|
|
TAILQ_FOREACH(pg, &vp->v_uobj.memq, listq) {
|
2000-11-27 11:39:39 +03:00
|
|
|
pg->flags &= ~PG_NEEDCOMMIT;
|
1996-02-18 14:53:36 +03:00
|
|
|
}
|
a whole bunch of changes to improve performance and robustness under load:
- remove special treatment of pager_map mappings in pmaps. this is
required now, since I've removed the globals that expose the address range.
pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's
no longer any need to special-case it.
- eliminate struct uvm_vnode by moving its fields into struct vnode.
- rewrite the pageout path. the pager is now responsible for handling the
high-level requests instead of only getting control after a bunch of work
has already been done on its behalf. this will allow us to UBCify LFS,
which needs tighter control over its pages than other filesystems do.
writing a page to disk no longer requires making it read-only, which
allows us to write wired pages without causing all kinds of havoc.
- use a new PG_PAGEOUT flag to indicate that a page should be freed
on behalf of the pagedaemon when it's unlocked. this flag is very similar
to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the
pageout fails due to eg. an indirect-block buffer being locked.
this allows us to remove the "version" field from struct vm_page,
and together with shrinking "loan_count" from 32 bits to 16,
struct vm_page is now 4 bytes smaller.
- no longer use PG_RELEASED for swap-backed pages. if the page is busy
because it's being paged out, we can't release the swap slot to be
reallocated until that write is complete, but unlike with vnodes we
don't keep a count of in-progress writes so there's no good way to
know when the write is done. instead, when we need to free a busy
swap-backed page, just sleep until we can get it busy ourselves.
- implement a fast-path for extending writes which allows us to avoid
zeroing new pages. this substantially reduces cpu usage.
- encapsulate the data used by the genfs code in a struct genfs_node,
which must be the first element of the filesystem-specific vnode data
for filesystems which use genfs_{get,put}pages().
- eliminate many of the UVM pagerops, since they aren't needed anymore
now that the pager "put" operation is a higher-level operation.
- enhance the genfs code to allow NFS to use the genfs_{get,put}pages
instead of a modified copy.
- clean up struct vnode by removing all the fields that used to be used by
the vfs_cluster.c code (which we don't use anymore with UBC).
- remove kmem_object and mb_object since they were useless.
instead of allocating pages to these objects, we now just allocate
pages with no object. such pages are mapped in the kernel until they
are freed, so we can use the mapping to find the page to free it.
this allows us to remove splvm() protection in several places.
The sum of all these changes improves write throughput on my
decstation 5000/200 to within 1% of the rate of NetBSD 1.5
and reduces the elapsed time for "make release" of a NetBSD 1.5
source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
|
|
|
simple_unlock(&vp->v_uobj.vmobjlock);
|
1996-02-18 14:53:36 +03:00
|
|
|
}
|
2003-05-03 20:28:57 +04:00
|
|
|
simple_lock(&nmp->nm_slock);
|
|
|
|
nmp->nm_iflag &= ~NFSMNT_STALEWRITEVERF;
|
|
|
|
simple_unlock(&nmp->nm_slock);
|
|
|
|
lockmgr(&nmp->nm_writeverflock, LK_RELEASE, NULL);
|
1996-02-18 14:53:36 +03:00
|
|
|
}
|
|
|
|
|
2000-09-20 02:13:55 +04:00
|
|
|
void
|
|
|
|
nfs_merge_commit_ranges(vp)
|
|
|
|
struct vnode *vp;
|
|
|
|
{
|
|
|
|
struct nfsnode *np = VTONFS(vp);
|
|
|
|
|
2003-04-01 15:59:03 +04:00
|
|
|
KASSERT(np->n_commitflags & NFS_COMMIT_PUSH_VALID);
|
|
|
|
|
2000-09-20 02:13:55 +04:00
|
|
|
if (!(np->n_commitflags & NFS_COMMIT_PUSHED_VALID)) {
|
|
|
|
np->n_pushedlo = np->n_pushlo;
|
|
|
|
np->n_pushedhi = np->n_pushhi;
|
|
|
|
np->n_commitflags |= NFS_COMMIT_PUSHED_VALID;
|
|
|
|
} else {
|
|
|
|
if (np->n_pushlo < np->n_pushedlo)
|
|
|
|
np->n_pushedlo = np->n_pushlo;
|
|
|
|
if (np->n_pushhi > np->n_pushedhi)
|
|
|
|
np->n_pushedhi = np->n_pushhi;
|
|
|
|
}
|
|
|
|
|
|
|
|
np->n_pushlo = np->n_pushhi = 0;
|
|
|
|
np->n_commitflags &= ~NFS_COMMIT_PUSH_VALID;
|
|
|
|
|
2003-03-31 18:47:03 +04:00
|
|
|
#ifdef NFS_DEBUG_COMMIT
|
2000-09-20 02:13:55 +04:00
|
|
|
printf("merge: committed: %u - %u\n", (unsigned)np->n_pushedlo,
|
|
|
|
(unsigned)np->n_pushedhi);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-11-27 11:39:39 +03:00
|
|
|
nfs_in_committed_range(vp, off, len)
|
2000-09-20 02:13:55 +04:00
|
|
|
struct vnode *vp;
|
2000-11-27 11:39:39 +03:00
|
|
|
off_t off, len;
|
2000-09-20 02:13:55 +04:00
|
|
|
{
|
|
|
|
struct nfsnode *np = VTONFS(vp);
|
|
|
|
off_t lo, hi;
|
|
|
|
|
|
|
|
if (!(np->n_commitflags & NFS_COMMIT_PUSHED_VALID))
|
|
|
|
return 0;
|
2000-11-27 11:39:39 +03:00
|
|
|
lo = off;
|
|
|
|
hi = lo + len;
|
2000-09-20 02:13:55 +04:00
|
|
|
|
|
|
|
return (lo >= np->n_pushedlo && hi <= np->n_pushedhi);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-11-27 11:39:39 +03:00
|
|
|
nfs_in_tobecommitted_range(vp, off, len)
|
2000-09-20 02:13:55 +04:00
|
|
|
struct vnode *vp;
|
2000-11-27 11:39:39 +03:00
|
|
|
off_t off, len;
|
2000-09-20 02:13:55 +04:00
|
|
|
{
|
|
|
|
struct nfsnode *np = VTONFS(vp);
|
|
|
|
off_t lo, hi;
|
|
|
|
|
|
|
|
if (!(np->n_commitflags & NFS_COMMIT_PUSH_VALID))
|
|
|
|
return 0;
|
2000-11-27 11:39:39 +03:00
|
|
|
lo = off;
|
|
|
|
hi = lo + len;
|
2000-09-20 02:13:55 +04:00
|
|
|
|
|
|
|
return (lo >= np->n_pushlo && hi <= np->n_pushhi);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-11-27 11:39:39 +03:00
|
|
|
nfs_add_committed_range(vp, off, len)
|
2000-09-20 02:13:55 +04:00
|
|
|
struct vnode *vp;
|
2000-11-27 11:39:39 +03:00
|
|
|
off_t off, len;
|
2000-09-20 02:13:55 +04:00
|
|
|
{
|
|
|
|
struct nfsnode *np = VTONFS(vp);
|
|
|
|
off_t lo, hi;
|
|
|
|
|
2000-11-27 11:39:39 +03:00
|
|
|
lo = off;
|
|
|
|
hi = lo + len;
|
2000-09-20 02:13:55 +04:00
|
|
|
|
|
|
|
if (!(np->n_commitflags & NFS_COMMIT_PUSHED_VALID)) {
|
|
|
|
np->n_pushedlo = lo;
|
|
|
|
np->n_pushedhi = hi;
|
|
|
|
np->n_commitflags |= NFS_COMMIT_PUSHED_VALID;
|
|
|
|
} else {
|
|
|
|
if (hi > np->n_pushedhi)
|
|
|
|
np->n_pushedhi = hi;
|
|
|
|
if (lo < np->n_pushedlo)
|
|
|
|
np->n_pushedlo = lo;
|
|
|
|
}
|
2003-03-31 18:47:03 +04:00
|
|
|
#ifdef NFS_DEBUG_COMMIT
|
2000-09-20 02:13:55 +04:00
|
|
|
printf("add: committed: %u - %u\n", (unsigned)np->n_pushedlo,
|
|
|
|
(unsigned)np->n_pushedhi);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-11-27 11:39:39 +03:00
|
|
|
nfs_del_committed_range(vp, off, len)
|
2000-09-20 02:13:55 +04:00
|
|
|
struct vnode *vp;
|
2000-11-27 11:39:39 +03:00
|
|
|
off_t off, len;
|
2000-09-20 02:13:55 +04:00
|
|
|
{
|
|
|
|
struct nfsnode *np = VTONFS(vp);
|
|
|
|
off_t lo, hi;
|
|
|
|
|
|
|
|
if (!(np->n_commitflags & NFS_COMMIT_PUSHED_VALID))
|
|
|
|
return;
|
|
|
|
|
2000-11-27 11:39:39 +03:00
|
|
|
lo = off;
|
|
|
|
hi = lo + len;
|
2000-09-20 02:13:55 +04:00
|
|
|
|
|
|
|
if (lo > np->n_pushedhi || hi < np->n_pushedlo)
|
|
|
|
return;
|
|
|
|
if (lo <= np->n_pushedlo)
|
|
|
|
np->n_pushedlo = hi;
|
|
|
|
else if (hi >= np->n_pushedhi)
|
|
|
|
np->n_pushedhi = lo;
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* XXX There's only one range. If the deleted range
|
|
|
|
* is in the middle, pick the largest of the
|
|
|
|
* contiguous ranges that it leaves.
|
|
|
|
*/
|
|
|
|
if ((np->n_pushedlo - lo) > (hi - np->n_pushedhi))
|
|
|
|
np->n_pushedhi = lo;
|
|
|
|
else
|
|
|
|
np->n_pushedlo = hi;
|
|
|
|
}
|
2003-03-31 18:47:03 +04:00
|
|
|
#ifdef NFS_DEBUG_COMMIT
|
2000-09-20 02:13:55 +04:00
|
|
|
printf("del: committed: %u - %u\n", (unsigned)np->n_pushedlo,
|
|
|
|
(unsigned)np->n_pushedhi);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-11-27 11:39:39 +03:00
|
|
|
nfs_add_tobecommitted_range(vp, off, len)
|
2000-09-20 02:13:55 +04:00
|
|
|
struct vnode *vp;
|
2000-11-27 11:39:39 +03:00
|
|
|
off_t off, len;
|
2000-09-20 02:13:55 +04:00
|
|
|
{
|
|
|
|
struct nfsnode *np = VTONFS(vp);
|
|
|
|
off_t lo, hi;
|
|
|
|
|
2000-11-27 11:39:39 +03:00
|
|
|
lo = off;
|
|
|
|
hi = lo + len;
|
2000-09-20 02:13:55 +04:00
|
|
|
|
|
|
|
if (!(np->n_commitflags & NFS_COMMIT_PUSH_VALID)) {
|
|
|
|
np->n_pushlo = lo;
|
|
|
|
np->n_pushhi = hi;
|
|
|
|
np->n_commitflags |= NFS_COMMIT_PUSH_VALID;
|
|
|
|
} else {
|
|
|
|
if (lo < np->n_pushlo)
|
|
|
|
np->n_pushlo = lo;
|
|
|
|
if (hi > np->n_pushhi)
|
|
|
|
np->n_pushhi = hi;
|
|
|
|
}
|
2003-03-31 18:47:03 +04:00
|
|
|
#ifdef NFS_DEBUG_COMMIT
|
2000-09-20 02:13:55 +04:00
|
|
|
printf("add: tobecommitted: %u - %u\n", (unsigned)np->n_pushlo,
|
|
|
|
(unsigned)np->n_pushhi);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-11-27 11:39:39 +03:00
|
|
|
nfs_del_tobecommitted_range(vp, off, len)
|
2000-09-20 02:13:55 +04:00
|
|
|
struct vnode *vp;
|
2000-11-27 11:39:39 +03:00
|
|
|
off_t off, len;
|
2000-09-20 02:13:55 +04:00
|
|
|
{
|
|
|
|
struct nfsnode *np = VTONFS(vp);
|
|
|
|
off_t lo, hi;
|
|
|
|
|
|
|
|
if (!(np->n_commitflags & NFS_COMMIT_PUSH_VALID))
|
|
|
|
return;
|
|
|
|
|
2000-11-27 11:39:39 +03:00
|
|
|
lo = off;
|
|
|
|
hi = lo + len;
|
2000-09-20 02:13:55 +04:00
|
|
|
|
|
|
|
if (lo > np->n_pushhi || hi < np->n_pushlo)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (lo <= np->n_pushlo)
|
|
|
|
np->n_pushlo = hi;
|
|
|
|
else if (hi >= np->n_pushhi)
|
|
|
|
np->n_pushhi = lo;
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* XXX There's only one range. If the deleted range
|
|
|
|
* is in the middle, pick the largest of the
|
|
|
|
* contiguous ranges that it leaves.
|
|
|
|
*/
|
|
|
|
if ((np->n_pushlo - lo) > (hi - np->n_pushhi))
|
|
|
|
np->n_pushhi = lo;
|
|
|
|
else
|
|
|
|
np->n_pushlo = hi;
|
|
|
|
}
|
2003-03-31 18:47:03 +04:00
|
|
|
#ifdef NFS_DEBUG_COMMIT
|
2000-09-20 02:13:55 +04:00
|
|
|
printf("del: tobecommitted: %u - %u\n", (unsigned)np->n_pushlo,
|
|
|
|
(unsigned)np->n_pushhi);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1996-02-18 14:53:36 +03:00
|
|
|
/*
|
|
|
|
* Map errnos to NFS error numbers. For Version 3 also filter out error
|
|
|
|
* numbers not specified for the associated procedure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
nfsrv_errmap(nd, err)
|
|
|
|
struct nfsrv_descript *nd;
|
2000-03-30 16:51:13 +04:00
|
|
|
int err;
|
1996-02-18 14:53:36 +03:00
|
|
|
{
|
2001-01-18 23:28:15 +03:00
|
|
|
const short *defaulterrp, *errp;
|
1996-02-18 14:53:36 +03: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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
nfsrvw_sort(list, num)
|
2000-03-30 16:51:13 +04:00
|
|
|
gid_t *list;
|
|
|
|
int num;
|
1996-02-18 14:53:36 +03:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
int i, j;
|
1996-02-18 14:53:36 +03: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1998-08-10 00:51:08 +04:00
|
|
|
* copy credentials making sure that the result can be compared with memcmp().
|
1996-02-18 14:53:36 +03:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
nfsrv_setcred(incred, outcred)
|
2000-03-30 16:51:13 +04:00
|
|
|
struct ucred *incred, *outcred;
|
1996-02-18 14:53:36 +03:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
int i;
|
1996-02-18 14:53:36 +03:00
|
|
|
|
1998-08-10 00:51:08 +04:00
|
|
|
memset((caddr_t)outcred, 0, sizeof (struct ucred));
|
1996-02-18 14:53:36 +03:00
|
|
|
outcred->cr_ref = 1;
|
|
|
|
outcred->cr_uid = incred->cr_uid;
|
|
|
|
outcred->cr_gid = incred->cr_gid;
|
|
|
|
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);
|
|
|
|
}
|
2003-07-23 17:52:23 +04:00
|
|
|
|
|
|
|
u_int32_t
|
|
|
|
nfs_getxid()
|
|
|
|
{
|
|
|
|
static u_int32_t base;
|
|
|
|
static u_int32_t nfs_xid = 0;
|
|
|
|
static struct simplelock nfs_xidlock = SIMPLELOCK_INITIALIZER;
|
|
|
|
u_int32_t newxid;
|
|
|
|
|
|
|
|
simple_lock(&nfs_xidlock);
|
|
|
|
/*
|
|
|
|
* derive initial xid from system time
|
|
|
|
* XXX time is invalid if root not yet mounted
|
|
|
|
*/
|
|
|
|
if (__predict_false(!base && (rootvp))) {
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
microtime(&tv);
|
|
|
|
base = tv.tv_sec << 12;
|
|
|
|
nfs_xid = base;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip zero xid if it should ever happen.
|
|
|
|
*/
|
|
|
|
if (__predict_false(++nfs_xid == 0))
|
|
|
|
nfs_xid++;
|
|
|
|
newxid = nfs_xid;
|
|
|
|
simple_unlock(&nfs_xidlock);
|
|
|
|
|
|
|
|
return txdr_unsigned(newxid);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* assign a new xid for existing request.
|
|
|
|
* used for NFSERR_JUKEBOX handling.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nfs_renewxid(struct nfsreq *req)
|
|
|
|
{
|
|
|
|
u_int32_t xid;
|
|
|
|
int off;
|
|
|
|
|
|
|
|
xid = nfs_getxid();
|
|
|
|
if (req->r_nmp->nm_sotype == SOCK_STREAM)
|
|
|
|
off = sizeof(u_int32_t); /* RPC record mark */
|
|
|
|
else
|
|
|
|
off = 0;
|
|
|
|
|
|
|
|
m_copyback(req->r_mreq, off, sizeof(xid), (void *)&xid);
|
|
|
|
req->r_xid = xid;
|
|
|
|
}
|