/*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License"). You may not use this file except in compliance with the
- * License. Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
*
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @(#)nfs_vfsops.c 8.12 (Berkeley) 5/20/95
* FreeBSD-Id: nfs_vfsops.c,v 1.52 1997/11/12 05:42:21 julian Exp $
- *
- * History:
- *
- *
- * 23-May-97 Umesh Vaishampayan (umeshv@apple.com)
- * Added the ability to mount "/private" separately.
- * Fixed bug which caused incorrect reporting of "mounted on"
- * directory name in case of nfs root.
*/
#include <sys/param.h>
VFS_SET(nfs_vfsops, nfs, MOUNT_NFS, VFCF_NETWORK);
#endif
-/*
- * This structure must be filled in by a primary bootstrap or bootstrap
- * server for a diskless/dataless machine. It is initialized below just
- * to ensure that it is allocated to initialized data (.data not .bss).
- */
-struct nfs_diskless nfs_diskless = { 0 };
-int nfs_diskless_valid = 0;
-
-/* XXX CSM 11/25/97 Upgrade sysctl.h someday */
-#ifdef notyet
-SYSCTL_INT(_vfs_nfs, OID_AUTO, diskless_valid, CTLFLAG_RD,
- &nfs_diskless_valid, 0, "");
-
-SYSCTL_STRING(_vfs_nfs, OID_AUTO, diskless_rootpath, CTLFLAG_RD,
- nfs_diskless.root_hostnam, 0, "");
-
-SYSCTL_OPAQUE(_vfs_nfs, OID_AUTO, diskless_rootaddr, CTLFLAG_RD,
- &nfs_diskless.root_saddr, sizeof nfs_diskless.root_saddr,
- "%Ssockaddr_in", "");
-
-SYSCTL_STRING(_vfs_nfs, OID_AUTO, diskless_swappath, CTLFLAG_RD,
- nfs_diskless.swap_hostnam, 0, "");
-
-SYSCTL_OPAQUE(_vfs_nfs, OID_AUTO, diskless_swapaddr, CTLFLAG_RD,
- &nfs_diskless.swap_saddr, sizeof nfs_diskless.swap_saddr,
- "%Ssockaddr_in","");
-#endif
-
void nfsargs_ntoh __P((struct nfs_args *));
static int
* space.
*/
iosize = max(nmp->nm_rsize, nmp->nm_wsize);
- if (iosize < PAGE_SIZE) iosize = PAGE_SIZE;
-#if 0
- /* XXX UPL changes for UBC do not support multiple pages */
- iosize = PAGE_SIZE; /* XXX FIXME */
-#endif
- /* return iosize; */
+ if (iosize < PAGE_SIZE)
+ iosize = PAGE_SIZE;
return (trunc_page(iosize));
}
struct ucred *cred;
u_quad_t tquad;
extern int nfs_mount_type;
+ u_int64_t xid;
#ifndef nolint
sfp = (struct nfs_statfs *)0;
#endif
vp = nmp->nm_dvp;
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
+ if (error = vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p))
+ return(error);
cred = crget();
cred->cr_ngroups = 1;
if (v3 && (nmp->nm_flag & NFSMNT_GOTFSINFO) == 0)
nfsstats.rpccnt[NFSPROC_FSSTAT]++;
nfsm_reqhead(vp, NFSPROC_FSSTAT, NFSX_FH(v3));
nfsm_fhtom(vp, v3);
- nfsm_request(vp, NFSPROC_FSSTAT, p, cred);
+ nfsm_request(vp, NFSPROC_FSSTAT, p, cred, &xid);
if (v3)
- nfsm_postop_attr(vp, retattr);
+ nfsm_postop_attr(vp, retattr, &xid);
nfsm_dissect(sfp, struct nfs_statfs *, NFSX_STATFS(v3));
/* XXX CSM 12/2/97 Cleanup when/if we integrate FreeBSD mount.h */
caddr_t bpos, dpos, cp2;
int error = 0, retattr;
struct mbuf *mreq, *mrep, *md, *mb, *mb2;
+ u_int64_t xid;
nfsstats.rpccnt[NFSPROC_FSINFO]++;
nfsm_reqhead(vp, NFSPROC_FSINFO, NFSX_FH(1));
nfsm_fhtom(vp, 1);
- nfsm_request(vp, NFSPROC_FSINFO, p, cred);
- nfsm_postop_attr(vp, retattr);
+ nfsm_request(vp, NFSPROC_FSINFO, p, cred, &xid);
+ nfsm_postop_attr(vp, retattr, &xid);
if (!error) {
nfsm_dissect(fsp, struct nfsv3_fsinfo *, NFSX_V3FSINFO);
pref = fxdr_unsigned(u_long, fsp->fs_wtpref);
struct mount *mppriv;
struct vnode *vppriv;
#endif /* NO_MOUNT_PRIVATE */
+ int v3;
procp = current_proc(); /* XXX */
/*
* Call nfs_boot_init() to fill in the nfs_diskless struct.
- * Side effect: Finds and configures a network interface.
+ * Note: networking must already have been configured before
+ * we're called.
*/
bzero((caddr_t) &nd, sizeof(nd));
- nfs_boot_init(&nd, procp);
+ error = nfs_boot_init(&nd, procp);
+ if (error) {
+ panic("nfs_boot_init failed with %d\n", error);
+ }
+
+ /* try NFSv3 first, if that fails then try NFSv2 */
+ v3 = 1;
+
+tryagain:
+ error = nfs_boot_getfh(&nd, procp, v3);
+ if (error) {
+ if (v3) {
+ printf("nfs_boot_getfh(v3) failed with %d, trying v2...\n", error);
+ v3 = 0;
+ goto tryagain;
+ }
+ panic("nfs_boot_getfh(v2) failed with %d\n", error);
+ }
/*
* Create the root mount point.
#else
if (error = nfs_mount_diskless(&nd.nd_root, "/", NULL, &vp, &mp)) {
#endif /* NO_MOUNT_PRIVATE */
- return(error);
+ if (v3) {
+ printf("nfs_mount_diskless(v3) failed with %d, trying v2...\n", error);
+ v3 = 0;
+ goto tryagain;
+ }
+ panic("nfs_mount_diskless root failed with %d\n", error);
}
printf("root on %s\n", (char *)&nd.nd_root.ndm_host);
if (nd.nd_private.ndm_saddr.sin_addr.s_addr) {
error = nfs_mount_diskless_private(&nd.nd_private, "/private",
NULL, &vppriv, &mppriv);
- if (error)
- return(error);
+ if (error) {
+ panic("nfs_mount_diskless private failed with %d\n", error);
+ }
printf("private on %s\n", (char *)&nd.nd_private.ndm_host);
simple_lock(&mountlist_slock);
#endif /* NO_MOUNT_PRIVATE */
+ if (nd.nd_root.ndm_path)
+ FREE_ZONE(nd.nd_root.ndm_path, MAXPATHLEN, M_NAMEI);
+ if (nd.nd_private.ndm_path)
+ FREE_ZONE(nd.nd_private.ndm_path, MAXPATHLEN, M_NAMEI);
+
/* Get root attributes (for the time). */
error = VOP_GETATTR(vp, &attr, procp->p_ucred, procp);
if (error) panic("nfs_mountroot: getattr for root");
args.addrlen = args.addr->sa_len;
args.sotype = SOCK_DGRAM;
args.fh = ndmntp->ndm_fh;
- args.fhsize = NFSX_V2FH;
+ args.fhsize = ndmntp->ndm_fhlen;
args.hostname = ndmntp->ndm_host;
args.flags = NFSMNT_RESVPORT;
+ if (ndmntp->ndm_nfsv3)
+ args.flags |= NFSMNT_NFSV3;
MGET(m, M_DONTWAIT, MT_SONAME);
bcopy((caddr_t)args.addr, mtod(m, caddr_t),
/* Get the vnode for '/'. Set fdp->fd_cdir to reference it. */
if (VFS_ROOT(mountlist.cqh_first, &rootvnode))
panic("cannot find root vnode");
+ VREF(rootvnode);
fdp->fd_cdir = rootvnode;
- VREF(fdp->fd_cdir);
VOP_UNLOCK(rootvnode, 0, procp);
fdp->fd_rdir = NULL;
}
args.addrlen = args.addr->sa_len;
args.sotype = SOCK_DGRAM;
args.fh = ndmntp->ndm_fh;
- args.fhsize = NFSX_V2FH;
+ args.fhsize = ndmntp->ndm_fhlen;
args.hostname = ndmntp->ndm_host;
args.flags = NFSMNT_RESVPORT;
+ if (ndmntp->ndm_nfsv3)
+ args.flags |= NFSMNT_NFSV3;
MGET(m, M_DONTWAIT, MT_SONAME);
bcopy((caddr_t)args.addr, mtod(m, caddr_t),
* - Decrement reference on the vnode representing remote root.
* - Close the socket
* - Free up the data structures
- *
- * We need to decrement the ref. count on the nfsnode representing
- * the remote root. See comment in mountnfs(). The VFS unmount()
- * has done vput on this vnode, otherwise we would get deadlock!
*/
vp = nmp->nm_dvp;
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
/*
* Must handshake with nqnfs_clientd() if it is active.
*/
error = vflush(mp, vp, SKIPSWAP | flags);
if (mntflags & MNT_FORCE)
- error = vflush(mp, NULLVP, flags);
+ error = vflush(mp, NULLVP, flags); /* locks vp in the process */
else {
if (vp->v_usecount > 1) {
- VOP_UNLOCK(vp, 0, p);
nmp->nm_flag &= ~NFSMNT_DISMINPROG;
return (EBUSY);
}
}
if (error) {
- VOP_UNLOCK(vp, 0, p);
nmp->nm_flag &= ~NFSMNT_DISMINPROG;
return (error);
}
/*
* Release the root vnode reference held by mountnfs()
- * Note: vflush would have done the vgone for us if we
- * didn't skip over it due to mount reference held.
+ * vflush did the vgone for us when we didn't skip over
+ * it in the MNT_FORCE case. (Thus vp can't be locked when
+ * called vflush in non-skip vp case.)
*/
- vput(vp);
+ vrele(vp);
if (!(mntflags & MNT_FORCE))
vgone(vp);
mp->mnt_data = 0; /* don't want to end up using stale vp */
for (vp = mp->mnt_vnodelist.lh_first;
vp != NULL;
vp = vp->v_mntvnodes.le_next) {
+ int didhold = 0;
/*
* If the vnode that we are about to sync is no longer
* associated with this mount point, start over.
continue;
if (vget(vp, LK_EXCLUSIVE, p))
goto loop;
+ didhold = ubc_hold(vp);
error = VOP_FSYNC(vp, cred, waitfor, p);
if (error)
allerror = error;
- vput(vp);
+ VOP_UNLOCK(vp, 0, p);
+ if (didhold)
+ ubc_rele(vp);
+ vrele(vp);
}
return (allerror);
}