Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Split off parts of vfs_subr.c into vfs_vnode.c and vfs_m...
details: https://anonhg.NetBSD.org/src/rev/473326fbf3ad
branches: trunk
changeset: 763733:473326fbf3ad
user: rmind <rmind%NetBSD.org@localhost>
date: Sat Apr 02 04:28:56 2011 +0000
description:
Split off parts of vfs_subr.c into vfs_vnode.c and vfs_mount.c modules.
No functional change. Discussed on tech-kern@.
diffstat:
sys/conf/files | 4 +-
sys/kern/vfs_mount.c | 1396 ++++++++++++++++++
sys/kern/vfs_subr.c | 2132 +----------------------------
sys/kern/vfs_syscalls.c | 327 +----
sys/kern/vfs_vnode.c | 1156 +++++++++++++++
sys/rump/librump/rumpvfs/Makefile.rumpvfs | 7 +-
sys/sys/mount.h | 6 +-
sys/sys/vnode.h | 7 +-
sys/ufs/lfs/lfs_segment.c | 6 +-
9 files changed, 2608 insertions(+), 2433 deletions(-)
diffs (truncated from 5327 to 300 lines):
diff -r 586d84c1c580 -r 473326fbf3ad sys/conf/files
--- a/sys/conf/files Fri Apr 01 17:40:54 2011 +0000
+++ b/sys/conf/files Sat Apr 02 04:28:56 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files,v 1.1006 2011/03/31 19:40:51 dyoung Exp $
+# $NetBSD: files,v 1.1007 2011/04/02 04:28:56 rmind Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
version 20100430
@@ -1594,9 +1594,11 @@
file kern/vfs_init.c
file kern/vfs_lockf.c
file kern/vfs_lookup.c
+file kern/vfs_mount.c
file kern/vfs_subr.c
file kern/vfs_syscalls.c
file kern/vfs_trans.c
+file kern/vfs_vnode.c
file kern/vfs_vnops.c
file kern/vfs_wapbl.c wapbl
file kern/vfs_xattr.c
diff -r 586d84c1c580 -r 473326fbf3ad sys/kern/vfs_mount.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/kern/vfs_mount.c Sat Apr 02 04:28:56 2011 +0000
@@ -0,0 +1,1396 @@
+/* $NetBSD: vfs_mount.c,v 1.1 2011/04/02 04:28:56 rmind Exp $ */
+
+/*-
+ * Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
+ * NASA Ames Research Center, by Charles M. Hannum, and by Andrew Doran.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, 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. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)vfs_subr.c 8.13 (Berkeley) 4/18/94
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.1 2011/04/02 04:28:56 rmind Exp $");
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+
+#include <sys/atomic.h>
+#include <sys/buf.h>
+#include <sys/conf.h>
+#include <sys/fcntl.h>
+#include <sys/filedesc.h>
+#include <sys/device.h>
+#include <sys/kauth.h>
+#include <sys/kmem.h>
+#include <sys/module.h>
+#include <sys/mount.h>
+#include <sys/namei.h>
+#include <sys/syscallargs.h>
+#include <sys/sysctl.h>
+#include <sys/systm.h>
+#include <sys/vnode.h>
+
+#include <miscfs/genfs/genfs.h>
+#include <miscfs/syncfs/syncfs.h>
+#include <miscfs/specfs/specdev.h>
+
+/* Root filesystem and device. */
+vnode_t * rootvnode;
+struct device * root_device;
+
+/* Mounted filesystem list. */
+struct mntlist mountlist;
+kmutex_t mountlist_lock;
+
+kmutex_t mntvnode_lock;
+kmutex_t vfs_list_lock;
+
+static specificdata_domain_t mount_specificdata_domain;
+static kmutex_t mntid_lock;
+
+static kmutex_t mountgen_lock;
+static uint64_t mountgen;
+
+void
+vfs_mount_sysinit(void)
+{
+
+ CIRCLEQ_INIT(&mountlist);
+ mutex_init(&mountlist_lock, MUTEX_DEFAULT, IPL_NONE);
+ mutex_init(&mntvnode_lock, MUTEX_DEFAULT, IPL_NONE);
+ mutex_init(&vfs_list_lock, MUTEX_DEFAULT, IPL_NONE);
+
+ mount_specificdata_domain = specificdata_domain_create();
+ mutex_init(&mntid_lock, MUTEX_DEFAULT, IPL_NONE);
+ mutex_init(&mountgen_lock, MUTEX_DEFAULT, IPL_NONE);
+ mountgen = 0;
+}
+
+struct mount *
+vfs_mountalloc(struct vfsops *vfsops, vnode_t *vp)
+{
+ struct mount *mp;
+ int error;
+
+ mp = kmem_zalloc(sizeof(*mp), KM_SLEEP);
+ if (mp == NULL)
+ return NULL;
+
+ mp->mnt_op = vfsops;
+ mp->mnt_refcnt = 1;
+ TAILQ_INIT(&mp->mnt_vnodelist);
+ rw_init(&mp->mnt_unmounting);
+ mutex_init(&mp->mnt_renamelock, MUTEX_DEFAULT, IPL_NONE);
+ mutex_init(&mp->mnt_updating, MUTEX_DEFAULT, IPL_NONE);
+ error = vfs_busy(mp, NULL);
+ KASSERT(error == 0);
+ mp->mnt_vnodecovered = vp;
+ mount_initspecific(mp);
+
+ mutex_enter(&mountgen_lock);
+ mp->mnt_gen = mountgen++;
+ mutex_exit(&mountgen_lock);
+
+ return mp;
+}
+
+/*
+ * vfs_rootmountalloc: lookup a filesystem type, and if found allocate and
+ * initialize a mount structure for it.
+ *
+ * Devname is usually updated by mount(8) after booting.
+ */
+int
+vfs_rootmountalloc(const char *fstypename, const char *devname,
+ struct mount **mpp)
+{
+ struct vfsops *vfsp = NULL;
+ struct mount *mp;
+
+ mutex_enter(&vfs_list_lock);
+ LIST_FOREACH(vfsp, &vfs_list, vfs_list)
+ if (!strncmp(vfsp->vfs_name, fstypename,
+ sizeof(mp->mnt_stat.f_fstypename)))
+ break;
+ if (vfsp == NULL) {
+ mutex_exit(&vfs_list_lock);
+ return (ENODEV);
+ }
+ vfsp->vfs_refcount++;
+ mutex_exit(&vfs_list_lock);
+
+ if ((mp = vfs_mountalloc(vfsp, NULL)) == NULL)
+ return ENOMEM;
+ mp->mnt_flag = MNT_RDONLY;
+ (void)strlcpy(mp->mnt_stat.f_fstypename, vfsp->vfs_name,
+ sizeof(mp->mnt_stat.f_fstypename));
+ mp->mnt_stat.f_mntonname[0] = '/';
+ mp->mnt_stat.f_mntonname[1] = '\0';
+ mp->mnt_stat.f_mntfromname[sizeof(mp->mnt_stat.f_mntfromname) - 1] =
+ '\0';
+ (void)copystr(devname, mp->mnt_stat.f_mntfromname,
+ sizeof(mp->mnt_stat.f_mntfromname) - 1, 0);
+ *mpp = mp;
+ return 0;
+}
+
+/*
+ * vfs_getnewfsid: get a new unique fsid.
+ */
+void
+vfs_getnewfsid(struct mount *mp)
+{
+ static u_short xxxfs_mntid;
+ fsid_t tfsid;
+ int mtype;
+
+ mutex_enter(&mntid_lock);
+ mtype = makefstype(mp->mnt_op->vfs_name);
+ mp->mnt_stat.f_fsidx.__fsid_val[0] = makedev(mtype, 0);
+ mp->mnt_stat.f_fsidx.__fsid_val[1] = mtype;
+ mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
+ if (xxxfs_mntid == 0)
+ ++xxxfs_mntid;
+ tfsid.__fsid_val[0] = makedev(mtype & 0xff, xxxfs_mntid);
+ tfsid.__fsid_val[1] = mtype;
+ if (!CIRCLEQ_EMPTY(&mountlist)) {
+ while (vfs_getvfs(&tfsid)) {
+ tfsid.__fsid_val[0]++;
+ xxxfs_mntid++;
+ }
+ }
+ mp->mnt_stat.f_fsidx.__fsid_val[0] = tfsid.__fsid_val[0];
+ mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
+ mutex_exit(&mntid_lock);
+}
+
+/*
+ * Lookup a mount point by filesystem identifier.
+ *
+ * XXX Needs to add a reference to the mount point.
+ */
+struct mount *
+vfs_getvfs(fsid_t *fsid)
+{
+ struct mount *mp;
+
+ mutex_enter(&mountlist_lock);
+ CIRCLEQ_FOREACH(mp, &mountlist, mnt_list) {
+ if (mp->mnt_stat.f_fsidx.__fsid_val[0] == fsid->__fsid_val[0] &&
+ mp->mnt_stat.f_fsidx.__fsid_val[1] == fsid->__fsid_val[1]) {
+ mutex_exit(&mountlist_lock);
+ return (mp);
+ }
+ }
+ mutex_exit(&mountlist_lock);
+ return NULL;
+}
+
+/*
+ * Drop a reference to a mount structure, freeing if the last reference.
+ */
+void
+vfs_destroy(struct mount *mp)
+{
+
+ if (__predict_true((int)atomic_dec_uint_nv(&mp->mnt_refcnt) > 0)) {
+ return;
+ }
+
+ /*
+ * Nothing else has visibility of the mount: we can now
+ * free the data structures.
+ */
+ KASSERT(mp->mnt_refcnt == 0);
+ specificdata_fini(mount_specificdata_domain, &mp->mnt_specdataref);
+ rw_destroy(&mp->mnt_unmounting);
+ mutex_destroy(&mp->mnt_updating);
+ mutex_destroy(&mp->mnt_renamelock);
+ if (mp->mnt_op != NULL) {
+ vfs_delref(mp->mnt_op);
+ }
+ kmem_free(mp, sizeof(*mp));
+}
+
+/*
+ * Mark a mount point as busy, and gain a new reference to it. Used to
+ * prevent the file system from being unmounted during critical sections.
Home |
Main Index |
Thread Index |
Old Index