nfs_vfsops.c revision e8dc3b7db5649f094399356b5f050a719a27ab43
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Copyright (c) 1983,1984,1985,1986,1987,1988,1989 AT&T.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/pathname.h>
#include <sys/sysmacros.h>
#include <sys/bootconf.h>
#include <sys/netconfig.h>
#include <nfs/nfs_clnt.h>
/*
*/
extern void sec_clnt_freeinfo(struct sec_data *);
static void pathconf_rele(struct mntinfo *);
/*
* The order and contents of this structure must be kept in sync with that of
* rfsreqcnt_v2_tmpl in nfs_stats.c
*/
static char *rfsnames_v2[] = {
"null", "getattr", "setattr", "unused", "lookup", "readlink", "read",
"unused", "write", "create", "remove", "rename", "link", "symlink",
"mkdir", "rmdir", "readdir", "fsstat"
};
/*
* This table maps from NFS protocol number into call type.
* Zero means a "Lookup" type call
* One means a "Read" type call
* Two means a "Write" type call
* This is used to select a default time-out.
*/
static uchar_t call_type_v2[] = {
0, 0, 1, 0, 0, 0, 1,
0, 2, 2, 2, 2, 2, 2,
2, 2, 1, 0
};
/*
* Similar table, but to determine which timer to use
* (only real reads and writes!)
*/
static uchar_t timer_type_v2[] = {
0, 0, 0, 0, 0, 0, 1,
0, 2, 0, 0, 0, 0, 0,
0, 0, 1, 0
};
/*
* This table maps from NFS protocol number into a call type
* for the semisoft mount option.
* Zero means do not repeat operation.
* One means repeat.
*/
static uchar_t ss_call_type_v2[] = {
0, 0, 1, 0, 0, 0, 0,
0, 1, 1, 1, 1, 1, 1,
1, 1, 0, 0
};
/*
* nfs vfs operations.
*/
static void nfs_freevfs(vfs_t *);
/*
* Initialize the vfs structure
*/
int nfsfstyp;
/*
* Debug variable to check for rdma based
* transport startup and cleanup. Controlled
*/
int rdma_debug = 0;
int
{
static const fs_operation_def_t nfs_vfsops_template[] = {
};
int error;
if (error != 0) {
"nfsinit: bad vfs ops template");
return (error);
}
if (error != 0) {
(void) vfs_freevfsops_by_type(fstyp);
"nfsinit: bad vnode ops template");
return (error);
}
return (0);
}
void
nfsfini(void)
{
}
/*
* nfs mount vfsop
* Set up mount info record and attach it to vfs struct.
*/
static int
{
int error;
char *p, *pf;
return (error);
return (ENOTDIR);
/*
* get arguments
*
* nfs_args is now versioned and is extensible, so
* uap->datalen might be different from sizeof (args)
* in a compatible situation.
*/
more:
STRUCT_SIZE(args))))
return (EFAULT);
size_t n;
else
if (error) {
if (error == ENAMETOOLONG)
return (EINVAL);
return (error);
}
/*
* This check is to ensure that the request is a
* genuine nfs remount request.
*/
return (EINVAL);
/*
* If the request changes the locking type, disallow the
* remount,
* because it's questionable whether we can transfer the
* locking state correctly.
*
* Remounts need to save the pathconf information.
* Part of the infamous static kludge.
*/
if (old_mi_llock != new_mi_llock)
return (EBUSY);
}
}
return (EBUSY);
}
/* make sure things are zeroed for errout: */
/*
* A valid knetconfig structure is required.
*/
if (!(flags & NFSMNT_KNCONF))
return (EINVAL);
/*
* Allocate a servinfo struct.
*/
if (svp_tail) {
} else {
svp_2ndlast = svp;
}
/*
* Allocate space for a knetconfig structure and
* its strings and copy in from user-land.
*/
STRUCT_SIZE(knconf_tmp))) {
return (EFAULT);
}
if (get_udatamodel() != DATAMODEL_LP64) {
} else {
}
if (error) {
kmem_free(p, KNC_STRSIZE);
return (error);
}
if (error) {
kmem_free(p, KNC_STRSIZE);
return (error);
}
/*
* Get server address
*/
STRUCT_SIZE(addr_tmp))) {
} else {
char *userbufptr;
}
if (error)
goto errout;
/*
* Get the root fhandle
*/
NFS_FHSIZE)) {
goto errout;
}
/*
* Get server's hostname
*/
if (flags & NFSMNT_HOSTNAME) {
if (error)
goto errout;
} else {
char *p = "unknown-host";
}
/*
* RDMA MOUNT SUPPORT FOR NFS v2:
* Establish, is it possible to use RDMA, if so overload the
* knconf with rdma specific knconf and free the orignal.
*/
/*
* Determine the addr type for RDMA, IPv4 or v6.
*/
&rdma_knconf) == 0) {
/*
* If successful, hijack, the orignal knconf and
* replace with a new one, depending on the flags.
*/
} else {
if (flags & NFSMNT_TRYRDMA) {
#ifdef DEBUG
if (rdma_debug)
"no RDMA onboard, revert\n");
#endif
}
if (flags & NFSMNT_DORDMA) {
/*
* If proto=rdma is specified and no RDMA
* path to this server is avialable then
* ditch this server.
* This is not included in the mountable
* server list or the replica list.
* Check if more servers are specified;
* Failover case, otherwise bail out of mount.
*/
!(flags & NFSMNT_SOFT)) {
data = (char *)
svp_2ndlast = NULL;
goto more;
} else {
NULL;
goto more;
}
}
} else {
/*
* This is the last server specified
* in the nfs_args list passed down
* and its not rdma capable.
*/
/*
* Is this the only one
*/
#ifdef DEBUG
if (rdma_debug)
"No RDMA srv");
#endif
goto errout;
} else {
/*
* There is list, since some
* servers specified before
* this passed all requirements
*/
goto proceed;
}
}
}
}
}
/*
* Get the extention data which has the new security data structure.
*/
if (flags & NFSMNT_NEWARGS) {
case NFS_ARGS_EXTA:
case NFS_ARGS_EXTB:
/*
* Indicating the application is using the new
* sec_data structure to pass in the security
* data.
*/
if (STRUCT_FGETP(args,
} else {
&secdata, get_udatamodel());
}
break;
default:
break;
}
} else if (flags & NFSMNT_SECURE) {
/*
* Keep this for backward compatibility to support
* NFSMNT_SECURE/NFSMNT_RPCTIMESYNC flags.
*/
} else {
/*
* get time sync address.
*/
STRUCT_SIZE(addr_tmp))) {
} else {
char *userbufptr;
KM_SLEEP);
}
/*
* get server's netname
*/
if (!error) {
}
}
}
/*
* Move security related data to the sec_data structure.
*/
if (!error) {
char *pf, *p;
if (flags & NFSMNT_RPCTIMESYNC)
/*
* duplicate the knconf information for the
* new opaque data.
*/
/* move server netname to the sec_data structure */
if (nlen != 0) {
}
}
} else {
}
if (error)
goto errout;
/*
* See bug 1180236.
* If mount secure failed, we will fall back to AUTH_NONE
* and try again. nfs3rootvp() will turn this back off.
*
* The NFS Version 2 mount uses GETATTR and STATFS procedures.
* The server does not care if these procedures have the proper
* authentication flavor, so if mount retries using AUTH_NONE
* that does not require a credential setup for root then the
* automounter would work without requiring root to be
* keylogged into AUTH_DES.
*/
/*
* Failover support:
*
* We may have a linked list of nfs_args structures,
* which means the user is looking for failover. If
* the mount is either not "read-only" or "soft",
* we want to bail out with EINVAL.
*/
goto more;
}
goto errout;
}
/*
* Determine the zone we're being mounted into.
*/
if (getzoneid() == GLOBAL_ZONEID) {
goto errout;
}
}
/*
* Stop the mount from going any further if the zone is going away.
*/
goto errout;
}
/*
* Get root vnode.
*/
if (error)
goto errout;
/*
* Set option fields in the mount info record
*/
if (!error) {
/* static pathconf kludge */
}
if (error) {
}
if (mi->mi_io_kstats) {
}
if (mi->mi_ro_kstats) {
}
}
}
return (error);
}
/*
* The pathconf information is kept on a linked list of kmem_alloc'ed
* structs. We search the list & add a new struct iff there is no other
* struct with the same information.
* See sys/pathconf.h for ``the rest of the story.''
*/
static int
{
struct pathcnf *p;
int i;
#ifdef lint
#endif
}
return (EFAULT);
return (EINVAL);
for (i = 0; i < _PC_N; i++)
break;
}
if (p != NULL) {
mi->mi_pathconf = p;
p->pc_refcnt++;
} else {
p = kmem_alloc(sizeof (*p), KM_SLEEP);
*p = pc;
p->pc_refcnt = 1;
}
}
return (0);
}
/*
* release the static pathconf information
*/
static void
{
struct pathcnf *p;
p2 = p;
p = p->pc_next;
}
if (p == NULL) {
panic("mi->pathconf");
/*NOTREACHED*/
}
if (p == allpc)
else
kmem_free(p, sizeof (*p));
}
}
}
static int
{
int error;
int i;
/*
* Create a mount record and link it to the vfs struct.
*/
if (!(flags & NFSMNT_SOFT))
if ((flags & NFSMNT_SEMISOFT))
if ((flags & NFSMNT_NOPRINT))
if (flags & NFSMNT_INT)
else
if (nfs_dynamic)
if (flags & NFSMNT_DIRECTIO)
/*
* Make a vfs struct for nfs. We do this here instead of below
* because rtvp needs a vfs before we can do a getattr on it.
*
* Assign a unique device id to the mount
*/
do {
} while (vfs_devismounted(nfs_dev));
/*
* Initialize fields used to support async putpage operations.
*/
for (i = 0; i < NFS_ASYNC_TYPES; i++)
/*
* Make the root vnode, use it to get attributes,
* then remake it with the attributes.
*/
/*
* If the uid is set then set the creds for secure mounts
* by proxy processes such as automountd.
*/
}
if (error)
goto bad;
/*
* Poll every server to get the filesystem stats; we're
* only interested in the server's transfer size, and we
* want the minimum.
*
* While we're looping, we'll turn off AUTH_F_TRYNONE,
* which is only for the mount operation.
*/
int douprintf;
douprintf = 1;
if (error)
goto bad;
}
/*
* Start the manager thread responsible for handling async worker
* threads.
*/
vfsp, 0, minclsyspri);
/*
* Initialize kstats
*/
return (0);
bad:
/*
* An error occurred somewhere, need to clean up...
* We need to release our reference to the root vnode and
* destroy the mntinfo struct that we just created.
*/
if (mi->mi_io_kstats) {
}
if (mi->mi_ro_kstats) {
}
return (error);
}
/*
* vfs operations
*/
static int
{
return (EPERM);
/*
* We need to stop the manager thread explicitly; the worker
* threads can time out and exit on their own.
*/
if (mi->mi_io_kstats) {
}
if (mi->mi_ro_kstats) {
}
return (0);
}
/*
* Wait until all asynchronous putpage operations on
* this file system are complete before flushing rnodes
* from the cache.
*/
if (nfs_async_stop_sig(vfsp)) {
return (EINTR);
}
/*
* If there are any active vnodes on this file system,
* then the file system is busy and can't be umounted.
*/
if (check_rtable(vfsp)) {
return (EBUSY);
}
/*
* The unmount can't fail from now on; stop the manager thread.
*/
/*
* Destroy all rnodes belonging to this file system from the
* rnode hash queues and purge any resources allocated to
* them.
*/
if (mi->mi_io_kstats) {
}
if (mi->mi_ro_kstats) {
}
return (0);
}
/*
* find root of nfs
*/
static int
{
return (EPERM);
return (ENOENT);
}
return (ENOENT);
}
return (0);
}
/*
* Get file system statistics.
*/
static int
{
int error;
int douprintf;
if (error)
return (error);
douprintf = 1;
if (!error) {
if (!error) {
} else {
}
/*
* Some servers may return negative available
* block counts. They may do this because they
* calculate the number of available blocks by
* subtracting the number of used blocks from
* the total number of blocks modified by the
* minimum free value. For example, if the
* minumum free percentage is 10 and the file
* system is greater than 90 percent full, then
* 90 percent of the total blocks minus the
* actual number of used blocks may be a
* negative number.
*
* In this case, we need to sign extend the
* negative number through the assignment from
* the 32 bit bavail count to the 64 bit bavail
* count.
*
* We need to be able to discern between there
* just being a lot of available blocks on the
* file system and the case described above.
* We are making the assumption that it does
* not make sense to have more available blocks
* than there are free blocks. So, if there
* are, then we treat the number as if it were
* a negative number and arrange to have it
* sign extended when it is converted from 32
* bits to 64 bits.
*/
else {
}
} else {
}
}
return (error);
}
static kmutex_t nfs_syncbusy;
/*
* Flush dirty nfs files for file system vfsp.
* If vfsp == NULL, all nfs files are flushed.
*/
/* ARGSUSED */
static int
{
/*
* Cross-zone calls are OK here, since this translates to a
* VOP_PUTPAGE(B_ASYNC), which gets picked up by the right zone.
*/
}
return (0);
}
/* ARGSUSED */
static int
{
int error;
return (EPERM);
#ifdef DEBUG
(int)(sizeof (*nfsfidp) - sizeof (short)));
#endif
return (ESTALE);
}
return (ENOENT);
}
if (error) {
return (error);
}
}
return (0);
}
/* ARGSUSED */
static int
{
int error;
int vfsflags;
char *root_path;
char *name;
static char token[10];
/* do this BEFORE getfile which causes xid stamps to be initialized */
if (why == ROOT_REMOUNT) {
/*
* Shouldn't happen.
*/
panic("nfs_mountroot: why == ROOT_REMOUNT");
}
if (why == ROOT_UNMOUNT) {
/*
* Nothing to do for NFS.
*/
return (0);
}
/*
* why == ROOT_INIT
*/
*name = 0;
/*
* Get server address
* Get the root fhandle
* Get server's transport
* Get server's hostname
* Get options
*/
vfsflags = 0;
"nfs_mountroot: mount_root failed: %m");
return (error);
}
/*
* Force root partition to always be mounted with AUTH_UNIX for now
*/
if (error) {
goto errout;
}
if (error) {
"nfs_mountroot: invalid root mount options");
goto errout;
}
(void) vfs_lock_wait(vfsp);
if (error) {
}
return (error);
}
/*
* Initialization routine for VFS routines. Should only be called once
*/
int
nfs_vfsinit(void)
{
return (0);
}
void
nfs_vfsfini(void)
{
}
void
{
/* free up the resources */
/*
* By this time we should have already deleted the
* mi kstats in the unmount code. If they are still around
* somethings wrong
*/
}