Home | History | Annotate | Line # | Download | only in lfs
ulfs_vfsops.c revision 1.6
      1  1.6  dholland /*	$NetBSD: ulfs_vfsops.c,v 1.6 2013/06/06 00:51:50 dholland Exp $	*/
      2  1.1  dholland /*  from NetBSD: ufs_vfsops.c,v 1.52 2013/01/22 09:39:18 dholland Exp  */
      3  1.1  dholland 
      4  1.1  dholland /*
      5  1.1  dholland  * Copyright (c) 1991, 1993, 1994
      6  1.1  dholland  *	The Regents of the University of California.  All rights reserved.
      7  1.1  dholland  * (c) UNIX System Laboratories, Inc.
      8  1.1  dholland  * All or some portions of this file are derived from material licensed
      9  1.1  dholland  * to the University of California by American Telephone and Telegraph
     10  1.1  dholland  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
     11  1.1  dholland  * the permission of UNIX System Laboratories, Inc.
     12  1.1  dholland  *
     13  1.1  dholland  * Redistribution and use in source and binary forms, with or without
     14  1.1  dholland  * modification, are permitted provided that the following conditions
     15  1.1  dholland  * are met:
     16  1.1  dholland  * 1. Redistributions of source code must retain the above copyright
     17  1.1  dholland  *    notice, this list of conditions and the following disclaimer.
     18  1.1  dholland  * 2. Redistributions in binary form must reproduce the above copyright
     19  1.1  dholland  *    notice, this list of conditions and the following disclaimer in the
     20  1.1  dholland  *    documentation and/or other materials provided with the distribution.
     21  1.1  dholland  * 3. Neither the name of the University nor the names of its contributors
     22  1.1  dholland  *    may be used to endorse or promote products derived from this software
     23  1.1  dholland  *    without specific prior written permission.
     24  1.1  dholland  *
     25  1.1  dholland  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26  1.1  dholland  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  1.1  dholland  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  1.1  dholland  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29  1.1  dholland  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30  1.1  dholland  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31  1.1  dholland  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  1.1  dholland  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  1.1  dholland  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  1.1  dholland  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  1.1  dholland  * SUCH DAMAGE.
     36  1.1  dholland  *
     37  1.1  dholland  *	@(#)ufs_vfsops.c	8.8 (Berkeley) 5/20/95
     38  1.1  dholland  */
     39  1.1  dholland 
     40  1.1  dholland #include <sys/cdefs.h>
     41  1.6  dholland __KERNEL_RCSID(0, "$NetBSD: ulfs_vfsops.c,v 1.6 2013/06/06 00:51:50 dholland Exp $");
     42  1.1  dholland 
     43  1.1  dholland #if defined(_KERNEL_OPT)
     44  1.3  dholland #include "opt_lfs.h"
     45  1.1  dholland #include "opt_quota.h"
     46  1.1  dholland #endif
     47  1.1  dholland 
     48  1.1  dholland #include <sys/param.h>
     49  1.1  dholland #include <sys/mbuf.h>
     50  1.1  dholland #include <sys/mount.h>
     51  1.1  dholland #include <sys/proc.h>
     52  1.1  dholland #include <sys/buf.h>
     53  1.1  dholland #include <sys/vnode.h>
     54  1.1  dholland #include <sys/kmem.h>
     55  1.1  dholland #include <sys/kauth.h>
     56  1.6  dholland #include <sys/quotactl.h>
     57  1.1  dholland 
     58  1.1  dholland #include <miscfs/specfs/specdev.h>
     59  1.1  dholland 
     60  1.6  dholland #include <ufs/lfs/lfs.h>
     61  1.2  dholland #include <ufs/lfs/ulfs_quotacommon.h>
     62  1.2  dholland #include <ufs/lfs/ulfs_inode.h>
     63  1.2  dholland #include <ufs/lfs/ulfsmount.h>
     64  1.2  dholland #include <ufs/lfs/ulfs_extern.h>
     65  1.3  dholland #ifdef LFS_DIRHASH
     66  1.2  dholland #include <ufs/lfs/ulfs_dirhash.h>
     67  1.1  dholland #endif
     68  1.1  dholland 
     69  1.4  dholland /* how many times ulfs_init() was called */
     70  1.4  dholland static int ulfs_initcount = 0;
     71  1.1  dholland 
     72  1.4  dholland pool_cache_t ulfs_direct_cache;
     73  1.1  dholland 
     74  1.1  dholland /*
     75  1.1  dholland  * Make a filesystem operational.
     76  1.1  dholland  * Nothing to do at the moment.
     77  1.1  dholland  */
     78  1.1  dholland /* ARGSUSED */
     79  1.1  dholland int
     80  1.4  dholland ulfs_start(struct mount *mp, int flags)
     81  1.1  dholland {
     82  1.1  dholland 
     83  1.1  dholland 	return (0);
     84  1.1  dholland }
     85  1.1  dholland 
     86  1.1  dholland /*
     87  1.1  dholland  * Return the root of a filesystem.
     88  1.1  dholland  */
     89  1.1  dholland int
     90  1.4  dholland ulfs_root(struct mount *mp, struct vnode **vpp)
     91  1.1  dholland {
     92  1.1  dholland 	struct vnode *nvp;
     93  1.1  dholland 	int error;
     94  1.1  dholland 
     95  1.4  dholland 	if ((error = VFS_VGET(mp, (ino_t)ULFS_ROOTINO, &nvp)) != 0)
     96  1.1  dholland 		return (error);
     97  1.1  dholland 	*vpp = nvp;
     98  1.1  dholland 	return (0);
     99  1.1  dholland }
    100  1.1  dholland 
    101  1.1  dholland /*
    102  1.1  dholland  * Do operations associated with quotas
    103  1.1  dholland  */
    104  1.1  dholland int
    105  1.4  dholland ulfs_quotactl(struct mount *mp, struct quotactl_args *args)
    106  1.1  dholland {
    107  1.1  dholland 
    108  1.3  dholland #if !defined(LFS_QUOTA) && !defined(LFS_QUOTA2)
    109  1.1  dholland 	(void) mp;
    110  1.1  dholland 	(void) args;
    111  1.1  dholland 	return (EOPNOTSUPP);
    112  1.1  dholland #else
    113  1.1  dholland 	struct lwp *l = curlwp;
    114  1.1  dholland 	int error;
    115  1.1  dholland 
    116  1.1  dholland 	/* Mark the mount busy, as we're passing it to kauth(9). */
    117  1.1  dholland 	error = vfs_busy(mp, NULL);
    118  1.1  dholland 	if (error) {
    119  1.1  dholland 		return (error);
    120  1.1  dholland 	}
    121  1.1  dholland 	mutex_enter(&mp->mnt_updating);
    122  1.1  dholland 
    123  1.5  dholland 	error = lfsquota_handle_cmd(mp, l, args);
    124  1.1  dholland 
    125  1.1  dholland 	mutex_exit(&mp->mnt_updating);
    126  1.1  dholland 	vfs_unbusy(mp, false, NULL);
    127  1.1  dholland 	return (error);
    128  1.1  dholland #endif
    129  1.1  dholland }
    130  1.1  dholland 
    131  1.1  dholland #if 0
    132  1.1  dholland 	switch (cmd) {
    133  1.1  dholland 	case Q_SYNC:
    134  1.1  dholland 		break;
    135  1.1  dholland 
    136  1.1  dholland 	case Q_GETQUOTA:
    137  1.1  dholland 		/* The user can always query about his own quota. */
    138  1.1  dholland 		if (uid == kauth_cred_getuid(l->l_cred))
    139  1.1  dholland 			break;
    140  1.1  dholland 
    141  1.1  dholland 		error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA,
    142  1.1  dholland 		    KAUTH_REQ_SYSTEM_FS_QUOTA_GET, mp, KAUTH_ARG(uid), NULL);
    143  1.1  dholland 
    144  1.1  dholland 		break;
    145  1.1  dholland 
    146  1.1  dholland 	case Q_QUOTAON:
    147  1.1  dholland 	case Q_QUOTAOFF:
    148  1.1  dholland 		error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA,
    149  1.1  dholland 		    KAUTH_REQ_SYSTEM_FS_QUOTA_ONOFF, mp, NULL, NULL);
    150  1.1  dholland 
    151  1.1  dholland 		break;
    152  1.1  dholland 
    153  1.1  dholland 	case Q_SETQUOTA:
    154  1.1  dholland 	case Q_SETUSE:
    155  1.1  dholland 		error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA,
    156  1.1  dholland 		    KAUTH_REQ_SYSTEM_FS_QUOTA_MANAGE, mp, KAUTH_ARG(uid), NULL);
    157  1.1  dholland 
    158  1.1  dholland 		break;
    159  1.1  dholland 
    160  1.1  dholland 	default:
    161  1.1  dholland 		error = EINVAL;
    162  1.1  dholland 		break;
    163  1.1  dholland 	}
    164  1.1  dholland 
    165  1.1  dholland 	type = cmds & SUBCMDMASK;
    166  1.1  dholland 	if (!error) {
    167  1.1  dholland 		/* Only check if there was no error above. */
    168  1.1  dholland 		if ((u_int)type >= MAXQUOTAS)
    169  1.1  dholland 			error = EINVAL;
    170  1.1  dholland 	}
    171  1.1  dholland 
    172  1.1  dholland 	if (error) {
    173  1.1  dholland 		vfs_unbusy(mp, false, NULL);
    174  1.1  dholland 		return (error);
    175  1.1  dholland 	}
    176  1.1  dholland 
    177  1.1  dholland 	mutex_enter(&mp->mnt_updating);
    178  1.1  dholland 	switch (cmd) {
    179  1.1  dholland 
    180  1.1  dholland 	case Q_QUOTAON:
    181  1.1  dholland 		error = quotaon(l, mp, type, arg);
    182  1.1  dholland 		break;
    183  1.1  dholland 
    184  1.1  dholland 	case Q_QUOTAOFF:
    185  1.1  dholland 		error = quotaoff(l, mp, type);
    186  1.1  dholland 		break;
    187  1.1  dholland 
    188  1.1  dholland 	case Q_SETQUOTA:
    189  1.1  dholland 		error = setquota(mp, uid, type, arg);
    190  1.1  dholland 		break;
    191  1.1  dholland 
    192  1.1  dholland 	case Q_SETUSE:
    193  1.1  dholland 		error = setuse(mp, uid, type, arg);
    194  1.1  dholland 		break;
    195  1.1  dholland 
    196  1.1  dholland 	case Q_GETQUOTA:
    197  1.1  dholland 		error = getquota(mp, uid, type, arg);
    198  1.1  dholland 		break;
    199  1.1  dholland 
    200  1.1  dholland 	case Q_SYNC:
    201  1.5  dholland 		error = lfs_qsync(mp);
    202  1.1  dholland 		break;
    203  1.1  dholland 
    204  1.1  dholland 	default:
    205  1.1  dholland 		error = EINVAL;
    206  1.1  dholland 	}
    207  1.1  dholland 	mutex_exit(&mp->mnt_updating);
    208  1.1  dholland 	vfs_unbusy(mp, false, NULL);
    209  1.1  dholland 	return (error);
    210  1.1  dholland #endif
    211  1.1  dholland 
    212  1.1  dholland /*
    213  1.1  dholland  * This is the generic part of fhtovp called after the underlying
    214  1.1  dholland  * filesystem has validated the file handle.
    215  1.1  dholland  */
    216  1.1  dholland int
    217  1.4  dholland ulfs_fhtovp(struct mount *mp, struct ufid *ufhp, struct vnode **vpp)
    218  1.1  dholland {
    219  1.1  dholland 	struct vnode *nvp;
    220  1.1  dholland 	struct inode *ip;
    221  1.1  dholland 	int error;
    222  1.1  dholland 
    223  1.1  dholland 	if ((error = VFS_VGET(mp, ufhp->ufid_ino, &nvp)) != 0) {
    224  1.1  dholland 		*vpp = NULLVP;
    225  1.1  dholland 		return (error);
    226  1.1  dholland 	}
    227  1.1  dholland 	ip = VTOI(nvp);
    228  1.1  dholland 	KASSERT(ip != NULL);
    229  1.1  dholland 	if (ip->i_mode == 0 || ip->i_gen != ufhp->ufid_gen) {
    230  1.1  dholland 		vput(nvp);
    231  1.1  dholland 		*vpp = NULLVP;
    232  1.1  dholland 		return (ESTALE);
    233  1.1  dholland 	}
    234  1.1  dholland 	*vpp = nvp;
    235  1.1  dholland 	return (0);
    236  1.1  dholland }
    237  1.1  dholland 
    238  1.1  dholland /*
    239  1.4  dholland  * Initialize ULFS filesystems, done only once.
    240  1.1  dholland  */
    241  1.1  dholland void
    242  1.4  dholland ulfs_init(void)
    243  1.1  dholland {
    244  1.4  dholland 	if (ulfs_initcount++ > 0)
    245  1.1  dholland 		return;
    246  1.1  dholland 
    247  1.4  dholland 	ulfs_direct_cache = pool_cache_init(sizeof(struct direct), 0, 0, 0,
    248  1.4  dholland 	    "ulfsdir", NULL, IPL_NONE, NULL, NULL, NULL);
    249  1.1  dholland 
    250  1.4  dholland 	ulfs_ihashinit();
    251  1.3  dholland #if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
    252  1.5  dholland 	lfs_dqinit();
    253  1.1  dholland #endif
    254  1.3  dholland #ifdef LFS_DIRHASH
    255  1.4  dholland 	ulfsdirhash_init();
    256  1.1  dholland #endif
    257  1.3  dholland #ifdef LFS_EXTATTR
    258  1.4  dholland 	ulfs_extattr_init();
    259  1.1  dholland #endif
    260  1.1  dholland }
    261  1.1  dholland 
    262  1.1  dholland void
    263  1.4  dholland ulfs_reinit(void)
    264  1.1  dholland {
    265  1.4  dholland 	ulfs_ihashreinit();
    266  1.3  dholland #if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
    267  1.5  dholland 	lfs_dqreinit();
    268  1.1  dholland #endif
    269  1.1  dholland }
    270  1.1  dholland 
    271  1.1  dholland /*
    272  1.4  dholland  * Free ULFS filesystem resources, done only once.
    273  1.1  dholland  */
    274  1.1  dholland void
    275  1.4  dholland ulfs_done(void)
    276  1.1  dholland {
    277  1.4  dholland 	if (--ulfs_initcount > 0)
    278  1.1  dholland 		return;
    279  1.1  dholland 
    280  1.4  dholland 	ulfs_ihashdone();
    281  1.3  dholland #if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
    282  1.5  dholland 	lfs_dqdone();
    283  1.1  dholland #endif
    284  1.4  dholland 	pool_cache_destroy(ulfs_direct_cache);
    285  1.3  dholland #ifdef LFS_DIRHASH
    286  1.4  dholland 	ulfsdirhash_done();
    287  1.1  dholland #endif
    288  1.3  dholland #ifdef LFS_EXTATTR
    289  1.4  dholland 	ulfs_extattr_done();
    290  1.1  dholland #endif
    291  1.1  dholland }
    292