Convert 67 namei call sites to use namei_simple, in these functions:
check_console, veriexecclose, veriexec_delete, veriexec_file_add,
emul_find_root, coff_load_shlib (sh3 version), coff_load_shlib,
compat_20_sys_statfs, compat_20_netbsd32_statfs,
ELFNAME2(netbsd32,probe_noteless), darwin_sys_statfs,
ibcs2_sys_statfs, ibcs2_sys_statvfs, linux_sys_uselib,
osf1_sys_statfs, sunos_sys_statfs, sunos32_sys_statfs,
ultrix_sys_statfs, do_sys_mount, fss_create_files (3 of 4),
adosfs_mount, cd9660_mount, coda_ioctl, coda_mount, ext2fs_mount,
ffs_mount, filecore_mount, hfs_mount, lfs_mount, msdosfs_mount,
ntfs_mount, sysvbfs_mount, udf_mount, union_mount, sys_chflags,
sys_lchflags, sys_chmod, sys_lchmod, sys_chown, sys_lchown,
sys___posix_chown, sys___posix_lchown, sys_link, do_sys_pstatvfs,
sys_quotactl, sys_revoke, sys_truncate, do_sys_utimes, sys_extattrctl,
sys_extattr_set_file, sys_extattr_set_link, sys_extattr_get_file,
sys_extattr_get_link, sys_extattr_delete_file,
sys_extattr_delete_link, sys_extattr_list_file, sys_extattr_list_link,
sys_setxattr, sys_lsetxattr, sys_getxattr, sys_lgetxattr,
sys_listxattr, sys_llistxattr, sys_removexattr, sys_lremovexattr
All have been scrutinized (several times, in fact) and compile-tested,
but not all have been explicitly tested in action.
XXX: While I haven't (intentionally) changed the use or nonuse of
XXX: TRYEMULROOT in any of these places, I'm not convinced all the
XXX: uses are correct; an audit might be desirable.
2009-06-29 09:08:15 +04:00
|
|
|
/* $NetBSD: filecore_vfsops.c,v 1.60 2009/06/29 05:08:17 dholland Exp $ */
|
1998-08-14 07:26:12 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1994 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* filecore_vfsops.c 1.1 1998/6/26
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 Andrew McMurry
|
|
|
|
*
|
|
|
|
* 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.
|
1998-08-14 07:26:12 +04:00
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* filecore_vfsops.c 1.1 1998/6/26
|
|
|
|
*/
|
|
|
|
|
2001-11-13 01:54:03 +03:00
|
|
|
#include <sys/cdefs.h>
|
Convert 67 namei call sites to use namei_simple, in these functions:
check_console, veriexecclose, veriexec_delete, veriexec_file_add,
emul_find_root, coff_load_shlib (sh3 version), coff_load_shlib,
compat_20_sys_statfs, compat_20_netbsd32_statfs,
ELFNAME2(netbsd32,probe_noteless), darwin_sys_statfs,
ibcs2_sys_statfs, ibcs2_sys_statvfs, linux_sys_uselib,
osf1_sys_statfs, sunos_sys_statfs, sunos32_sys_statfs,
ultrix_sys_statfs, do_sys_mount, fss_create_files (3 of 4),
adosfs_mount, cd9660_mount, coda_ioctl, coda_mount, ext2fs_mount,
ffs_mount, filecore_mount, hfs_mount, lfs_mount, msdosfs_mount,
ntfs_mount, sysvbfs_mount, udf_mount, union_mount, sys_chflags,
sys_lchflags, sys_chmod, sys_lchmod, sys_chown, sys_lchown,
sys___posix_chown, sys___posix_lchown, sys_link, do_sys_pstatvfs,
sys_quotactl, sys_revoke, sys_truncate, do_sys_utimes, sys_extattrctl,
sys_extattr_set_file, sys_extattr_set_link, sys_extattr_get_file,
sys_extattr_get_link, sys_extattr_delete_file,
sys_extattr_delete_link, sys_extattr_list_file, sys_extattr_list_link,
sys_setxattr, sys_lsetxattr, sys_getxattr, sys_lgetxattr,
sys_listxattr, sys_llistxattr, sys_removexattr, sys_lremovexattr
All have been scrutinized (several times, in fact) and compile-tested,
but not all have been explicitly tested in action.
XXX: While I haven't (intentionally) changed the use or nonuse of
XXX: TRYEMULROOT in any of these places, I'm not convinced all the
XXX: uses are correct; an audit might be desirable.
2009-06-29 09:08:15 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: filecore_vfsops.c,v 1.60 2009/06/29 05:08:17 dholland Exp $");
|
2001-11-13 01:54:03 +03:00
|
|
|
|
2001-05-30 15:40:35 +04:00
|
|
|
#if defined(_KERNEL_OPT)
|
1998-12-18 17:24:43 +03:00
|
|
|
#include "opt_compat_netbsd.h"
|
|
|
|
#endif
|
|
|
|
|
1998-08-14 07:26:12 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/vnode.h>
|
2008-01-28 17:31:15 +03:00
|
|
|
#include <miscfs/genfs/genfs.h>
|
1998-08-14 07:26:12 +04:00
|
|
|
#include <miscfs/specfs/specdev.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/malloc.h>
|
1998-09-01 08:09:30 +04:00
|
|
|
#include <sys/pool.h>
|
2002-09-06 17:18:43 +04:00
|
|
|
#include <sys/conf.h>
|
2003-12-05 03:51:08 +03:00
|
|
|
#include <sys/sysctl.h>
|
2006-05-15 05:29:02 +04:00
|
|
|
#include <sys/kauth.h>
|
2008-05-10 06:26:09 +04:00
|
|
|
#include <sys/module.h>
|
1998-08-14 07:26:12 +04:00
|
|
|
|
2002-12-23 20:30:36 +03:00
|
|
|
#include <fs/filecorefs/filecore.h>
|
|
|
|
#include <fs/filecorefs/filecore_extern.h>
|
|
|
|
#include <fs/filecorefs/filecore_node.h>
|
|
|
|
#include <fs/filecorefs/filecore_mount.h>
|
1998-08-14 07:26:12 +04:00
|
|
|
|
2008-05-10 06:26:09 +04:00
|
|
|
MODULE(MODULE_CLASS_VFS, filecorefs, NULL);
|
|
|
|
|
2007-06-30 13:37:53 +04:00
|
|
|
MALLOC_JUSTDEFINE(M_FILECOREMNT,
|
|
|
|
"filecore mount", "Filecore FS mount structures");
|
2007-09-24 04:42:12 +04:00
|
|
|
MALLOC_JUSTDEFINE(M_FILECORETMP,
|
|
|
|
"filecore temp", "Filecore FS temporary structures");
|
2003-02-01 09:23:35 +03:00
|
|
|
|
2008-06-28 05:34:05 +04:00
|
|
|
static struct sysctllog *filecore_sysctl_log;
|
|
|
|
|
2001-01-22 16:32:23 +03:00
|
|
|
extern const struct vnodeopv_desc filecore_vnodeop_opv_desc;
|
1998-08-14 07:26:12 +04:00
|
|
|
|
2001-01-22 16:32:23 +03:00
|
|
|
const struct vnodeopv_desc * const filecore_vnodeopv_descs[] = {
|
1998-08-14 07:26:12 +04:00
|
|
|
&filecore_vnodeop_opv_desc,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vfsops filecore_vfsops = {
|
|
|
|
MOUNT_FILECORE,
|
2007-07-12 23:35:32 +04:00
|
|
|
sizeof (struct filecore_args),
|
1998-08-14 07:26:12 +04:00
|
|
|
filecore_mount,
|
|
|
|
filecore_start,
|
|
|
|
filecore_unmount,
|
|
|
|
filecore_root,
|
2007-11-26 22:01:26 +03:00
|
|
|
(void *)eopnotsupp, /* vfs_quotactl */
|
2004-04-21 05:05:31 +04:00
|
|
|
filecore_statvfs,
|
1998-08-14 07:26:12 +04:00
|
|
|
filecore_sync,
|
|
|
|
filecore_vget,
|
|
|
|
filecore_fhtovp,
|
|
|
|
filecore_vptofh,
|
|
|
|
filecore_init,
|
2001-09-15 20:12:54 +04:00
|
|
|
filecore_reinit,
|
2000-03-16 21:08:17 +03:00
|
|
|
filecore_done,
|
1998-08-14 07:26:12 +04:00
|
|
|
NULL, /* filecore_mountroot */
|
2004-05-25 18:54:55 +04:00
|
|
|
(int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
|
2005-01-02 19:08:28 +03:00
|
|
|
vfs_stdextattrctl,
|
2007-07-27 02:57:36 +04:00
|
|
|
(void *)eopnotsupp, /* vfs_suspendctl */
|
2008-01-28 17:31:15 +03:00
|
|
|
genfs_renamelock_enter,
|
|
|
|
genfs_renamelock_exit,
|
2008-04-29 22:18:08 +04:00
|
|
|
(void *)eopnotsupp,
|
1998-08-14 07:26:12 +04:00
|
|
|
filecore_vnodeopv_descs,
|
2006-12-09 19:11:50 +03:00
|
|
|
0,
|
|
|
|
{ NULL, NULL }
|
1998-08-14 07:26:12 +04:00
|
|
|
};
|
|
|
|
|
2005-06-28 13:30:37 +04:00
|
|
|
static const struct genfs_ops filecore_genfsops = {
|
|
|
|
.gop_size = genfs_size,
|
2001-09-30 22:47:48 +04:00
|
|
|
};
|
|
|
|
|
2008-05-10 06:26:09 +04:00
|
|
|
static int
|
|
|
|
filecorefs_modcmd(modcmd_t cmd, void *arg)
|
|
|
|
{
|
2008-06-28 05:34:05 +04:00
|
|
|
int error;
|
2008-05-10 06:26:09 +04:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case MODULE_CMD_INIT:
|
2008-06-28 05:34:05 +04:00
|
|
|
error = vfs_attach(&filecore_vfsops);
|
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
sysctl_createv(&filecore_sysctl_log, 0, NULL, NULL,
|
|
|
|
CTLFLAG_PERMANENT,
|
|
|
|
CTLTYPE_NODE, "vfs", NULL,
|
|
|
|
NULL, 0, NULL, 0,
|
|
|
|
CTL_VFS, CTL_EOL);
|
|
|
|
sysctl_createv(&filecore_sysctl_log, 0, NULL, NULL,
|
|
|
|
CTLFLAG_PERMANENT,
|
|
|
|
CTLTYPE_NODE, "filecore",
|
|
|
|
SYSCTL_DESCR("Acorn FILECORE file system"),
|
|
|
|
NULL, 0, NULL, 0,
|
|
|
|
CTL_VFS, 19, CTL_EOL);
|
|
|
|
/*
|
|
|
|
* XXX the "19" above could be dynamic, thereby eliminating
|
|
|
|
* one more instance of the "number to vfs" mapping problem,
|
|
|
|
* but "19" is the order as taken from sys/mount.h
|
|
|
|
*/
|
|
|
|
break;
|
2008-05-10 06:26:09 +04:00
|
|
|
case MODULE_CMD_FINI:
|
2008-06-28 05:34:05 +04:00
|
|
|
error = vfs_detach(&filecore_vfsops);
|
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
sysctl_teardown(&filecore_sysctl_log);
|
|
|
|
break;
|
2008-05-10 06:26:09 +04:00
|
|
|
default:
|
2008-06-28 05:34:05 +04:00
|
|
|
error = ENOTTY;
|
|
|
|
break;
|
2008-05-10 06:26:09 +04:00
|
|
|
}
|
2008-06-28 05:34:05 +04:00
|
|
|
|
|
|
|
return (error);
|
2008-05-10 06:26:09 +04:00
|
|
|
}
|
|
|
|
|
1998-08-14 07:26:12 +04:00
|
|
|
/*
|
|
|
|
* Called by vfs_mountroot when iso is going to be mounted as root.
|
|
|
|
*
|
|
|
|
* Name is updated by mount(8) after booting.
|
|
|
|
*/
|
|
|
|
|
2009-03-14 17:45:51 +03:00
|
|
|
static int filecore_mountfs(struct vnode *devvp, struct mount *mp,
|
|
|
|
struct lwp *l, struct filecore_args *argp);
|
1998-08-14 07:26:12 +04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
int
|
2009-03-18 13:22:21 +03:00
|
|
|
filecore_mountroot(void)
|
1998-08-14 07:26:12 +04:00
|
|
|
{
|
|
|
|
struct mount *mp;
|
|
|
|
extern struct vnode *rootvp;
|
|
|
|
struct proc *p = curproc; /* XXX */
|
|
|
|
int error;
|
|
|
|
struct filecore_args args;
|
|
|
|
|
2006-02-21 07:32:38 +03:00
|
|
|
if (device_class(root_device) != DV_DISK)
|
1998-08-14 07:26:12 +04:00
|
|
|
return (ENODEV);
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1998-08-14 07:26:12 +04:00
|
|
|
/*
|
|
|
|
* Get vnodes for swapdev and rootdev.
|
|
|
|
*/
|
|
|
|
if (bdevvp(rootdev, &rootvp))
|
|
|
|
panic("filecore_mountroot: can't setup rootvp");
|
|
|
|
|
|
|
|
if ((error = vfs_rootmountalloc(MOUNT_FILECORE, "root_device", &mp)) != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
args.flags = FILECOREMNT_ROOT;
|
|
|
|
if ((error = filecore_mountfs(rootvp, mp, p, &args)) != 0) {
|
2008-04-30 16:49:16 +04:00
|
|
|
vfs_unbusy(mp, false, NULL);
|
PR kern/38141 lookup/vfs_busy acquire rwlock recursively
Simplify the mount locking. Remove all the crud to deal with recursion on
the mount lock, and crud to deal with unmount as another weirdo lock.
Hopefully this will once and for all fix the deadlocks with this. With this
commit there are two locks on each mount:
- krwlock_t mnt_unmounting. This is used to prevent unmount across critical
sections like getnewvnode(). It's only ever read locked with rw_tryenter(),
and is only ever write locked in dounmount(). A write hold can't be taken
on this lock if the current LWP could hold a vnode lock.
- kmutex_t mnt_updating. This is taken by threads updating the mount, for
example when going r/o -> r/w, and is only present to serialize updates.
In order to take this lock, a read hold must first be taken on
mnt_unmounting, and the two need to be held across the operation.
One effect of this change: previously if an unmount failed, we would make a
half hearted attempt to back out of it gracefully, but that was unlikely to
work in a lot of cases. Now while an unmount that will be aborted is in
progress, new file operations within the mount will fail instead of being
delayed. That is unlikely to be a problem though, because if the admin
requests unmount of a file system then s(he) has made a decision to deny
access to the resource.
2008-05-06 22:43:44 +04:00
|
|
|
vfs_destroy(mp);
|
1998-08-14 07:26:12 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
simple_lock(&mountlist_slock);
|
|
|
|
CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
|
|
|
|
simple_unlock(&mountlist_slock);
|
2004-04-21 05:05:31 +04:00
|
|
|
(void)filecore_statvfs(mp, &mp->mnt_stat, p);
|
2008-04-30 16:49:16 +04:00
|
|
|
vfs_unbusy(mp, false, NULL);
|
1998-08-14 07:26:12 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* VFS Operations.
|
|
|
|
*
|
|
|
|
* mount system call
|
|
|
|
*/
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
filecore_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
|
1998-08-14 07:26:12 +04:00
|
|
|
{
|
2007-11-26 22:01:26 +03:00
|
|
|
struct lwp *l = curlwp;
|
1998-08-14 07:26:12 +04:00
|
|
|
struct vnode *devvp;
|
2007-07-12 23:35:32 +04:00
|
|
|
struct filecore_args *args = data;
|
1998-08-14 07:26:12 +04:00
|
|
|
int error;
|
|
|
|
struct filecore_mnt *fcmp = NULL;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
2007-07-12 23:35:32 +04:00
|
|
|
if (*data_len < sizeof *args)
|
|
|
|
return EINVAL;
|
|
|
|
|
2002-09-21 22:10:34 +04:00
|
|
|
if (mp->mnt_flag & MNT_GETARGS) {
|
|
|
|
fcmp = VFSTOFILECORE(mp);
|
|
|
|
if (fcmp == NULL)
|
|
|
|
return EIO;
|
2007-07-12 23:35:32 +04:00
|
|
|
args->flags = fcmp->fc_mntflags;
|
|
|
|
args->uid = fcmp->fc_uid;
|
|
|
|
args->gid = fcmp->fc_gid;
|
|
|
|
args->fspec = NULL;
|
|
|
|
*data_len = sizeof *args;
|
|
|
|
return 0;
|
2002-09-21 22:10:34 +04:00
|
|
|
}
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1998-08-14 07:26:12 +04:00
|
|
|
if ((mp->mnt_flag & MNT_RDONLY) == 0)
|
|
|
|
return (EROFS);
|
2005-02-27 01:58:54 +03:00
|
|
|
|
2007-07-12 23:35:32 +04:00
|
|
|
if ((mp->mnt_flag & MNT_UPDATE) && args->fspec == NULL)
|
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
|
|
|
return EINVAL;
|
|
|
|
|
1998-08-14 07:26:12 +04:00
|
|
|
/*
|
|
|
|
* Not an update, or updating the name: look up the name
|
|
|
|
* and verify that it refers to a sensible block device.
|
|
|
|
*/
|
Convert 67 namei call sites to use namei_simple, in these functions:
check_console, veriexecclose, veriexec_delete, veriexec_file_add,
emul_find_root, coff_load_shlib (sh3 version), coff_load_shlib,
compat_20_sys_statfs, compat_20_netbsd32_statfs,
ELFNAME2(netbsd32,probe_noteless), darwin_sys_statfs,
ibcs2_sys_statfs, ibcs2_sys_statvfs, linux_sys_uselib,
osf1_sys_statfs, sunos_sys_statfs, sunos32_sys_statfs,
ultrix_sys_statfs, do_sys_mount, fss_create_files (3 of 4),
adosfs_mount, cd9660_mount, coda_ioctl, coda_mount, ext2fs_mount,
ffs_mount, filecore_mount, hfs_mount, lfs_mount, msdosfs_mount,
ntfs_mount, sysvbfs_mount, udf_mount, union_mount, sys_chflags,
sys_lchflags, sys_chmod, sys_lchmod, sys_chown, sys_lchown,
sys___posix_chown, sys___posix_lchown, sys_link, do_sys_pstatvfs,
sys_quotactl, sys_revoke, sys_truncate, do_sys_utimes, sys_extattrctl,
sys_extattr_set_file, sys_extattr_set_link, sys_extattr_get_file,
sys_extattr_get_link, sys_extattr_delete_file,
sys_extattr_delete_link, sys_extattr_list_file, sys_extattr_list_link,
sys_setxattr, sys_lsetxattr, sys_getxattr, sys_lgetxattr,
sys_listxattr, sys_llistxattr, sys_removexattr, sys_lremovexattr
All have been scrutinized (several times, in fact) and compile-tested,
but not all have been explicitly tested in action.
XXX: While I haven't (intentionally) changed the use or nonuse of
XXX: TRYEMULROOT in any of these places, I'm not convinced all the
XXX: uses are correct; an audit might be desirable.
2009-06-29 09:08:15 +04:00
|
|
|
error = namei_simple_user(args->fspec,
|
|
|
|
NSM_FOLLOW_NOEMULROOT, &devvp);
|
|
|
|
if (error != 0)
|
1998-08-14 07:26:12 +04:00
|
|
|
return (error);
|
|
|
|
|
|
|
|
if (devvp->v_type != VBLK) {
|
|
|
|
vrele(devvp);
|
|
|
|
return ENOTBLK;
|
|
|
|
}
|
2002-09-06 17:18:43 +04:00
|
|
|
if (bdevsw_lookup(devvp->v_rdev) == NULL) {
|
1998-08-14 07:26:12 +04:00
|
|
|
vrele(devvp);
|
|
|
|
return ENXIO;
|
|
|
|
}
|
1998-09-05 08:34:47 +04:00
|
|
|
/*
|
|
|
|
* If mount by non-root, then verify that user has necessary
|
|
|
|
* permissions on the device.
|
|
|
|
*/
|
2009-04-25 22:53:43 +04:00
|
|
|
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
|
|
|
|
error = genfs_can_mount(devvp, VREAD, l->l_cred);
|
|
|
|
VOP_UNLOCK(devvp, 0);
|
|
|
|
if (error) {
|
|
|
|
vrele(devvp);
|
|
|
|
return (error);
|
1998-09-05 08:34:47 +04:00
|
|
|
}
|
1998-08-14 07:26:12 +04:00
|
|
|
if ((mp->mnt_flag & MNT_UPDATE) == 0)
|
2007-07-12 23:35:32 +04:00
|
|
|
error = filecore_mountfs(devvp, mp, l, args);
|
1998-08-14 07:26:12 +04:00
|
|
|
else {
|
|
|
|
if (devvp != fcmp->fc_devvp)
|
|
|
|
error = EINVAL; /* needs translation */
|
|
|
|
else
|
|
|
|
vrele(devvp);
|
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
vrele(devvp);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
fcmp = VFSTOFILECORE(mp);
|
2007-07-12 23:35:32 +04:00
|
|
|
return set_statvfs_info(path, UIO_USERSPACE, args->fspec, UIO_USERSPACE,
|
2007-07-17 15:19:31 +04:00
|
|
|
mp->mnt_op->vfs_name, mp, l);
|
1998-08-14 07:26:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common code for mount and mountroot
|
|
|
|
*/
|
|
|
|
static int
|
2009-03-14 18:35:58 +03:00
|
|
|
filecore_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l, struct filecore_args *argp)
|
1998-08-14 07:26:12 +04:00
|
|
|
{
|
1998-08-14 22:04:04 +04:00
|
|
|
struct filecore_mnt *fcmp = (struct filecore_mnt *)0;
|
1998-08-14 07:26:12 +04:00
|
|
|
struct buf *bp = NULL;
|
|
|
|
dev_t dev = devvp->v_rdev;
|
|
|
|
int error = EINVAL;
|
|
|
|
int ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
|
|
|
|
struct filecore_disc_record *fcdr;
|
|
|
|
unsigned map;
|
|
|
|
unsigned log2secsize;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1998-08-14 07:26:12 +04:00
|
|
|
if (!ronly)
|
|
|
|
return EROFS;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
2008-01-24 20:32:52 +03:00
|
|
|
if ((error = vinvalbuf(devvp, V_SAVE, l->l_cred, l, 0, 0)) != 0)
|
1998-08-14 07:26:12 +04:00
|
|
|
return (error);
|
|
|
|
|
2007-11-26 22:01:26 +03:00
|
|
|
error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED);
|
1998-08-14 07:26:12 +04:00
|
|
|
if (error)
|
|
|
|
return error;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1998-08-14 07:26:12 +04:00
|
|
|
/* Read the filecore boot block to check FS validity and to find the map */
|
|
|
|
error = bread(devvp, FILECORE_BOOTBLOCK_BLKN,
|
2008-05-16 13:21:59 +04:00
|
|
|
FILECORE_BOOTBLOCK_SIZE, NOCRED, 0, &bp);
|
1998-08-14 07:26:12 +04:00
|
|
|
#ifdef FILECORE_DEBUG_BR
|
1998-08-14 22:04:04 +04:00
|
|
|
printf("bread(%p, %x, %d, CRED, %p)=%d\n", devvp,
|
1998-08-14 07:26:12 +04:00
|
|
|
FILECORE_BOOTBLOCK_BLKN, FILECORE_BOOTBLOCK_SIZE,
|
|
|
|
bp, error);
|
|
|
|
#endif
|
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
2006-09-29 22:30:37 +04:00
|
|
|
|
|
|
|
KASSERT(bp != NULL);
|
1998-08-14 07:26:12 +04:00
|
|
|
if (filecore_bbchecksum(bp->b_data) != 0) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2007-03-05 00:18:08 +03:00
|
|
|
fcdr = (struct filecore_disc_record *)((char *)(bp->b_data) +
|
|
|
|
FILECORE_BB_DISCREC);
|
1998-08-14 22:04:04 +04:00
|
|
|
map = ((((8 << fcdr->log2secsize) - fcdr->zone_spare)
|
|
|
|
* (fcdr->nzones / 2) - 8 * FILECORE_DISCREC_SIZE)
|
|
|
|
<< fcdr->log2bpmb) >> fcdr->log2secsize;
|
1998-08-14 07:26:12 +04:00
|
|
|
log2secsize = fcdr->log2secsize;
|
|
|
|
#ifdef FILECORE_DEBUG_BR
|
1998-08-14 22:04:04 +04:00
|
|
|
printf("brelse(%p) vf1\n", bp);
|
1998-08-14 07:26:12 +04:00
|
|
|
#endif
|
2007-10-08 22:02:53 +04:00
|
|
|
brelse(bp, BC_AGE);
|
1998-08-14 07:26:12 +04:00
|
|
|
bp = NULL;
|
|
|
|
|
|
|
|
/* Read the bootblock in the map */
|
2008-05-16 13:21:59 +04:00
|
|
|
error = bread(devvp, map, 1 << log2secsize, NOCRED, 0, &bp);
|
1998-08-14 07:26:12 +04:00
|
|
|
#ifdef FILECORE_DEBUG_BR
|
1998-08-14 22:04:04 +04:00
|
|
|
printf("bread(%p, %x, %d, CRED, %p)=%d\n", devvp,
|
|
|
|
map, 1 << log2secsize, bp, error);
|
1998-08-14 07:26:12 +04:00
|
|
|
#endif
|
|
|
|
if (error != 0)
|
|
|
|
goto out;
|
2007-03-05 00:18:08 +03:00
|
|
|
fcdr = (struct filecore_disc_record *)((char *)(bp->b_data) + 4);
|
1998-08-14 07:26:12 +04:00
|
|
|
fcmp = malloc(sizeof *fcmp, M_FILECOREMNT, M_WAITOK);
|
2004-05-04 17:26:58 +04:00
|
|
|
memset(fcmp, 0, sizeof *fcmp);
|
1998-08-14 07:26:12 +04:00
|
|
|
if (fcdr->log2bpmb > fcdr->log2secsize)
|
|
|
|
fcmp->log2bsize = fcdr->log2bpmb;
|
|
|
|
else fcmp->log2bsize = fcdr->log2secsize;
|
1998-08-14 22:04:04 +04:00
|
|
|
fcmp->blksize = 1 << fcmp->log2bsize;
|
2004-05-04 17:26:58 +04:00
|
|
|
memcpy(&fcmp->drec, fcdr, sizeof(*fcdr));
|
1998-08-14 22:04:04 +04:00
|
|
|
fcmp->map = map;
|
|
|
|
fcmp->idspz = ((8 << fcdr->log2secsize) - fcdr->zone_spare)
|
|
|
|
/ (fcdr->idlen + 1);
|
|
|
|
fcmp->mask = (1 << fcdr->idlen) - 1;
|
1998-08-14 07:26:12 +04:00
|
|
|
if (fcdr->big_flag & 1) {
|
1998-08-14 22:04:04 +04:00
|
|
|
fcmp->nblks = ((((u_int64_t)fcdr->disc_size_2) << 32)
|
|
|
|
+ fcdr->disc_size) / fcmp->blksize;
|
1998-08-14 07:26:12 +04:00
|
|
|
} else {
|
1998-08-14 22:04:04 +04:00
|
|
|
fcmp->nblks=fcdr->disc_size / fcmp->blksize;
|
1998-08-14 07:26:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef FILECORE_DEBUG_BR
|
1998-08-14 22:04:04 +04:00
|
|
|
printf("brelse(%p) vf2\n", bp);
|
1998-08-14 07:26:12 +04:00
|
|
|
#endif
|
2007-10-08 22:02:53 +04:00
|
|
|
brelse(bp, BC_AGE);
|
1998-08-14 07:26:12 +04:00
|
|
|
bp = NULL;
|
|
|
|
|
2002-07-30 11:40:07 +04:00
|
|
|
mp->mnt_data = fcmp;
|
2004-04-21 05:05:31 +04:00
|
|
|
mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)dev;
|
|
|
|
mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_FILECORE);
|
|
|
|
mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
|
2004-09-13 23:25:48 +04:00
|
|
|
mp->mnt_stat.f_namemax = 10;
|
1998-08-14 07:26:12 +04:00
|
|
|
mp->mnt_flag |= MNT_LOCAL;
|
2000-11-27 11:39:39 +03:00
|
|
|
mp->mnt_dev_bshift = fcdr->log2secsize;
|
|
|
|
mp->mnt_fs_bshift = fcmp->log2bsize;
|
|
|
|
|
1998-08-14 07:26:12 +04:00
|
|
|
fcmp->fc_mountp = mp;
|
|
|
|
fcmp->fc_dev = dev;
|
|
|
|
fcmp->fc_devvp = devvp;
|
|
|
|
fcmp->fc_mntflags = argp->flags;
|
|
|
|
if (argp->flags & FILECOREMNT_USEUID) {
|
2006-07-24 02:06:03 +04:00
|
|
|
fcmp->fc_uid = kauth_cred_getuid(l->l_cred);
|
|
|
|
fcmp->fc_gid = kauth_cred_getgid(l->l_cred);
|
1998-08-14 07:26:12 +04:00
|
|
|
} else {
|
1998-08-14 22:04:04 +04:00
|
|
|
fcmp->fc_uid = argp->uid;
|
|
|
|
fcmp->fc_gid = argp->gid;
|
1998-08-14 07:26:12 +04:00
|
|
|
}
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1998-08-14 07:26:12 +04:00
|
|
|
return 0;
|
|
|
|
out:
|
|
|
|
if (bp) {
|
|
|
|
#ifdef FILECORE_DEBUG_BR
|
1998-08-14 22:04:04 +04:00
|
|
|
printf("brelse(%p) vf3\n", bp);
|
1998-08-14 07:26:12 +04:00
|
|
|
#endif
|
2007-10-08 22:02:53 +04:00
|
|
|
brelse(bp, 0);
|
1998-08-14 07:26:12 +04:00
|
|
|
}
|
1999-10-17 03:53:26 +04:00
|
|
|
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
|
2007-11-26 22:01:26 +03:00
|
|
|
(void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED);
|
1999-10-17 03:53:26 +04:00
|
|
|
VOP_UNLOCK(devvp, 0);
|
1998-08-14 07:26:12 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make a filesystem operational.
|
|
|
|
* Nothing to do at the moment.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
filecore_start(struct mount *mp, int flags)
|
1998-08-14 07:26:12 +04:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* unmount system call
|
|
|
|
*/
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
filecore_unmount(struct mount *mp, int mntflags)
|
1998-08-14 07:26:12 +04:00
|
|
|
{
|
1998-08-14 22:04:04 +04:00
|
|
|
struct filecore_mnt *fcmp;
|
1998-08-14 07:26:12 +04:00
|
|
|
int error, flags = 0;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1998-08-14 07:26:12 +04:00
|
|
|
if (mntflags & MNT_FORCE)
|
|
|
|
flags |= FORCECLOSE;
|
|
|
|
if ((error = vflush(mp, NULLVP, flags)) != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
fcmp = VFSTOFILECORE(mp);
|
|
|
|
|
1999-10-20 18:32:09 +04:00
|
|
|
if (fcmp->fc_devvp->v_type != VBAD)
|
1999-11-15 21:49:07 +03:00
|
|
|
fcmp->fc_devvp->v_specmountpoint = NULL;
|
1999-10-17 03:53:26 +04:00
|
|
|
vn_lock(fcmp->fc_devvp, LK_EXCLUSIVE | LK_RETRY);
|
2007-11-26 22:01:26 +03:00
|
|
|
error = VOP_CLOSE(fcmp->fc_devvp, FREAD, NOCRED);
|
1999-10-17 03:53:26 +04:00
|
|
|
vput(fcmp->fc_devvp);
|
2004-05-04 17:26:58 +04:00
|
|
|
free(fcmp, M_FILECOREMNT);
|
2002-07-30 11:40:07 +04:00
|
|
|
mp->mnt_data = NULL;
|
1998-08-14 07:26:12 +04:00
|
|
|
mp->mnt_flag &= ~MNT_LOCAL;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return root of a filesystem
|
|
|
|
*/
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
filecore_root(struct mount *mp, struct vnode **vpp)
|
1998-08-14 07:26:12 +04:00
|
|
|
{
|
|
|
|
struct vnode *nvp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if ((error = VFS_VGET(mp, FILECORE_ROOTINO, &nvp)) != 0)
|
|
|
|
return (error);
|
|
|
|
*vpp = nvp;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get file system statistics.
|
|
|
|
*/
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
filecore_statvfs(struct mount *mp, struct statvfs *sbp)
|
1998-08-14 07:26:12 +04:00
|
|
|
{
|
1998-08-14 22:04:04 +04:00
|
|
|
struct filecore_mnt *fcmp = VFSTOFILECORE(mp);
|
1998-08-14 07:26:12 +04:00
|
|
|
|
|
|
|
sbp->f_bsize = fcmp->blksize;
|
2004-04-21 05:05:31 +04:00
|
|
|
sbp->f_frsize = sbp->f_bsize; /* XXX */
|
1998-08-14 07:26:12 +04:00
|
|
|
sbp->f_iosize = sbp->f_bsize; /* XXX */
|
|
|
|
sbp->f_blocks = fcmp->nblks;
|
|
|
|
sbp->f_bfree = 0; /* total free blocks */
|
|
|
|
sbp->f_bavail = 0; /* blocks free for non superuser */
|
2004-04-21 05:05:31 +04:00
|
|
|
sbp->f_bresvd = 0; /* reserved blocks */
|
1998-08-14 07:26:12 +04:00
|
|
|
sbp->f_files = 0; /* total files */
|
2004-04-21 05:05:31 +04:00
|
|
|
sbp->f_ffree = 0; /* free file nodes for non superuser */
|
|
|
|
sbp->f_favail = 0; /* free file nodes */
|
|
|
|
sbp->f_fresvd = 0; /* reserved file nodes */
|
|
|
|
copy_statvfs_info(sbp, mp);
|
1998-08-14 07:26:12 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
filecore_sync(struct mount *mp, int waitfor, kauth_cred_t cred)
|
1998-08-14 07:26:12 +04:00
|
|
|
{
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* File handle to vnode
|
|
|
|
*
|
|
|
|
* Have to be really careful about stale file handles:
|
|
|
|
* - check that the inode number is in range
|
|
|
|
* - call iget() to get the locked inode
|
|
|
|
* - check for an unallocated inode (i_mode == 0)
|
|
|
|
* - check that the generation number matches
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct ifid {
|
|
|
|
ushort ifid_len;
|
|
|
|
ushort ifid_pad;
|
|
|
|
u_int32_t ifid_ino;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
filecore_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
|
1998-08-14 07:26:12 +04:00
|
|
|
{
|
2006-07-13 16:00:24 +04:00
|
|
|
struct ifid ifh;
|
1998-08-14 07:26:12 +04:00
|
|
|
struct vnode *nvp;
|
|
|
|
struct filecore_node *ip;
|
|
|
|
int error;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
2006-07-13 16:00:24 +04:00
|
|
|
if (fhp->fid_len != sizeof(struct ifid))
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
memcpy(&ifh, fhp, sizeof(ifh));
|
|
|
|
if ((error = VFS_VGET(mp, ifh.ifid_ino, &nvp)) != 0) {
|
1998-08-14 07:26:12 +04:00
|
|
|
*vpp = NULLVP;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
ip = VTOI(nvp);
|
|
|
|
if (filecore_staleinode(ip)) {
|
|
|
|
vput(nvp);
|
|
|
|
*vpp = NULLVP;
|
|
|
|
return (ESTALE);
|
1999-02-27 02:44:43 +03:00
|
|
|
}
|
|
|
|
*vpp = nvp;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1998-08-14 07:26:12 +04:00
|
|
|
/* This looks complicated. Look at other vgets as well as the iso9660 one.
|
1998-08-14 22:04:04 +04:00
|
|
|
*
|
|
|
|
* The filecore inode number is made up of 1 byte directory entry index and
|
|
|
|
* 3 bytes of the internal disc address of the directory. On a read-only
|
|
|
|
* filesystem this is unique. For a read-write version we may not be able to
|
|
|
|
* do vget, see msdosfs.
|
|
|
|
*/
|
1998-08-14 07:26:12 +04:00
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
filecore_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
|
1998-08-14 07:26:12 +04:00
|
|
|
{
|
1998-08-14 22:04:04 +04:00
|
|
|
struct filecore_mnt *fcmp;
|
1998-08-14 07:26:12 +04:00
|
|
|
struct filecore_node *ip;
|
|
|
|
struct buf *bp;
|
|
|
|
struct vnode *vp;
|
|
|
|
dev_t dev;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
fcmp = VFSTOFILECORE(mp);
|
|
|
|
dev = fcmp->fc_dev;
|
|
|
|
if ((*vpp = filecore_ihashget(dev, ino)) != NULLVP)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* Allocate a new vnode/filecore_node. */
|
1998-08-14 22:04:04 +04:00
|
|
|
if ((error = getnewvnode(VT_FILECORE, mp, filecore_vnodeop_p, &vp))
|
|
|
|
!= 0) {
|
1998-08-14 07:26:12 +04:00
|
|
|
*vpp = NULLVP;
|
|
|
|
return (error);
|
|
|
|
}
|
1998-09-01 08:09:30 +04:00
|
|
|
ip = pool_get(&filecore_node_pool, PR_WAITOK);
|
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
|
|
|
memset(ip, 0, sizeof(struct filecore_node));
|
1998-08-14 07:26:12 +04:00
|
|
|
vp->v_data = ip;
|
|
|
|
ip->i_vnode = vp;
|
|
|
|
ip->i_dev = dev;
|
|
|
|
ip->i_number = ino;
|
|
|
|
ip->i_block = -1;
|
|
|
|
ip->i_parent = -2;
|
2008-02-05 18:18:36 +03:00
|
|
|
genfs_node_init(vp, &filecore_genfsops);
|
1998-08-14 07:26:12 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Put it onto its hash chain and lock it so that other requests for
|
|
|
|
* this inode will block if they arrive while we are sleeping waiting
|
|
|
|
* for old data structures to be purged or for the contents of the
|
|
|
|
* disk portion of this inode to be read.
|
|
|
|
*/
|
|
|
|
filecore_ihashins(ip);
|
|
|
|
|
1998-08-14 22:04:04 +04:00
|
|
|
if (ino == FILECORE_ROOTINO) {
|
1998-08-14 07:26:12 +04:00
|
|
|
/* Here we need to construct a root directory inode */
|
2004-05-04 17:26:58 +04:00
|
|
|
memcpy(ip->i_dirent.name, "root", 4);
|
1998-08-14 22:04:04 +04:00
|
|
|
ip->i_dirent.load = 0;
|
|
|
|
ip->i_dirent.exec = 0;
|
|
|
|
ip->i_dirent.len = FILECORE_DIR_SIZE;
|
|
|
|
ip->i_dirent.addr = fcmp->drec.root;
|
|
|
|
ip->i_dirent.attr = FILECORE_ATTR_DIR | FILECORE_ATTR_READ;
|
1998-08-14 07:26:12 +04:00
|
|
|
|
|
|
|
} else {
|
|
|
|
/* Read in Data from Directory Entry */
|
1998-08-14 22:04:04 +04:00
|
|
|
if ((error = filecore_bread(fcmp, ino & FILECORE_INO_MASK,
|
|
|
|
FILECORE_DIR_SIZE, NOCRED, &bp)) != 0) {
|
1998-08-14 07:26:12 +04:00
|
|
|
vput(vp);
|
|
|
|
#ifdef FILECORE_DEBUG_BR
|
1998-08-14 22:04:04 +04:00
|
|
|
printf("brelse(%p) vf4\n", bp);
|
1998-08-14 07:26:12 +04:00
|
|
|
#endif
|
2007-10-08 22:02:53 +04:00
|
|
|
brelse(bp, 0);
|
1998-08-14 07:26:12 +04:00
|
|
|
*vpp = NULL;
|
|
|
|
return (error);
|
|
|
|
}
|
2005-02-27 01:58:54 +03:00
|
|
|
|
2004-05-04 17:26:58 +04:00
|
|
|
memcpy(&ip->i_dirent,
|
|
|
|
fcdirentry(bp->b_data, ino >> FILECORE_INO_INDEX),
|
1998-08-14 07:26:12 +04:00
|
|
|
sizeof(struct filecore_direntry));
|
|
|
|
#ifdef FILECORE_DEBUG_BR
|
1998-08-14 22:04:04 +04:00
|
|
|
printf("brelse(%p) vf5\n", bp);
|
1998-08-14 07:26:12 +04:00
|
|
|
#endif
|
2007-10-08 22:02:53 +04:00
|
|
|
brelse(bp, 0);
|
1998-08-14 07:26:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ip->i_mnt = fcmp;
|
|
|
|
ip->i_devvp = fcmp->fc_devvp;
|
|
|
|
ip->i_diroff = 0;
|
|
|
|
VREF(ip->i_devvp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup type
|
|
|
|
*/
|
|
|
|
vp->v_type = VREG;
|
1998-08-14 22:04:04 +04:00
|
|
|
if (ip->i_dirent.attr & FILECORE_ATTR_DIR)
|
|
|
|
vp->v_type = VDIR;
|
1998-08-14 07:26:12 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the associated vnode
|
|
|
|
*/
|
|
|
|
switch (vp->v_type) {
|
|
|
|
case VFIFO:
|
|
|
|
case VCHR:
|
|
|
|
case VBLK:
|
|
|
|
/*
|
|
|
|
* Devices not supported.
|
|
|
|
*/
|
|
|
|
vput(vp);
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
case VLNK:
|
|
|
|
case VNON:
|
|
|
|
case VSOCK:
|
|
|
|
case VDIR:
|
|
|
|
case VBAD:
|
|
|
|
case VREG:
|
|
|
|
break;
|
|
|
|
}
|
2005-02-27 01:58:54 +03:00
|
|
|
|
1998-08-14 07:26:12 +04:00
|
|
|
if (ino == FILECORE_ROOTINO)
|
2007-10-11 00:42:20 +04:00
|
|
|
vp->v_vflag |= VV_ROOT;
|
1998-08-14 07:26:12 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX need generation number?
|
|
|
|
*/
|
|
|
|
|
2007-07-23 15:27:45 +04:00
|
|
|
uvm_vnp_setsize(vp, ip->i_size);
|
1998-08-14 07:26:12 +04:00
|
|
|
*vpp = vp;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Vnode pointer to File handle
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
filecore_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size)
|
1998-08-14 07:26:12 +04:00
|
|
|
{
|
1998-08-14 22:04:04 +04:00
|
|
|
struct filecore_node *ip = VTOI(vp);
|
2006-07-13 16:00:24 +04:00
|
|
|
struct ifid ifh;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
2006-07-13 16:00:24 +04:00
|
|
|
if (*fh_size < sizeof(struct ifid)) {
|
|
|
|
*fh_size = sizeof(struct ifid);
|
|
|
|
return E2BIG;
|
|
|
|
}
|
|
|
|
memset(&ifh, 0, sizeof(ifh));
|
|
|
|
ifh.ifid_len = sizeof(struct ifid);
|
|
|
|
ifh.ifid_ino = ip->i_number;
|
|
|
|
memcpy(fhp, &ifh, sizeof(ifh));
|
1998-08-14 07:26:12 +04:00
|
|
|
return 0;
|
|
|
|
}
|