xref: /onnv-gate/usr/src/uts/common/fs/cachefs/cachefs_noopc.c (revision 5331:3047ad28a67b)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*5331Samw  * Common Development and Distribution License (the "License").
6*5331Samw  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*5331Samw  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #include <sys/param.h>
280Sstevel@tonic-gate #include <sys/types.h>
290Sstevel@tonic-gate #include <sys/systm.h>
300Sstevel@tonic-gate #include <sys/cred.h>
310Sstevel@tonic-gate #include <sys/proc.h>
320Sstevel@tonic-gate #include <sys/user.h>
330Sstevel@tonic-gate #include <sys/vfs.h>
340Sstevel@tonic-gate #include <sys/vnode.h>
350Sstevel@tonic-gate #include <sys/pathname.h>
360Sstevel@tonic-gate #include <sys/uio.h>
370Sstevel@tonic-gate #include <sys/tiuser.h>
380Sstevel@tonic-gate #include <sys/sysmacros.h>
390Sstevel@tonic-gate #include <sys/kmem.h>
400Sstevel@tonic-gate #include <sys/mount.h>
410Sstevel@tonic-gate #include <sys/ioctl.h>
420Sstevel@tonic-gate #include <sys/statvfs.h>
430Sstevel@tonic-gate #include <sys/errno.h>
440Sstevel@tonic-gate #include <sys/debug.h>
450Sstevel@tonic-gate #include <sys/cmn_err.h>
460Sstevel@tonic-gate #include <sys/utsname.h>
470Sstevel@tonic-gate #include <sys/bootconf.h>
480Sstevel@tonic-gate #include <sys/modctl.h>
490Sstevel@tonic-gate 
500Sstevel@tonic-gate #include <sys/fs/cachefs_fs.h>
510Sstevel@tonic-gate 
520Sstevel@tonic-gate /*ARGSUSED*/
530Sstevel@tonic-gate static int
c_nop_init_cached_object(fscache_t * fscp,cnode_t * cp,vattr_t * vap,cred_t * cr)540Sstevel@tonic-gate c_nop_init_cached_object(fscache_t *fscp, cnode_t *cp, vattr_t *vap,
550Sstevel@tonic-gate     cred_t *cr)
560Sstevel@tonic-gate {
570Sstevel@tonic-gate 	int error;
580Sstevel@tonic-gate 	cachefs_metadata_t *mdp = &cp->c_metadata;
590Sstevel@tonic-gate 
600Sstevel@tonic-gate 	ASSERT(cr != NULL);
610Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cp->c_statelock));
620Sstevel@tonic-gate 
630Sstevel@tonic-gate 	/* NFSv4 always sets strict consistency */
640Sstevel@tonic-gate 	ASSERT(CFS_ISFS_BACKFS_NFSV4(fscp) == 0);
650Sstevel@tonic-gate 
660Sstevel@tonic-gate 	/* if attributes not passed in then get them */
670Sstevel@tonic-gate 	if (vap == NULL) {
680Sstevel@tonic-gate 		/* if not connected then cannot get attrs */
690Sstevel@tonic-gate 		if ((fscp->fs_cdconnected != CFS_CD_CONNECTED) ||
700Sstevel@tonic-gate 		    (fscp->fs_backvfsp == NULL))
710Sstevel@tonic-gate 			return (ETIMEDOUT);
720Sstevel@tonic-gate 
730Sstevel@tonic-gate 		/* get backvp if necessary */
740Sstevel@tonic-gate 		if (cp->c_backvp == NULL) {
750Sstevel@tonic-gate 			error = cachefs_getbackvp(fscp, cp);
760Sstevel@tonic-gate 			if (error)
770Sstevel@tonic-gate 				return (error);
780Sstevel@tonic-gate 		}
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 		/* get the attributes */
810Sstevel@tonic-gate 		cp->c_attr.va_mask = AT_ALL;
820Sstevel@tonic-gate 		ASSERT(cp->c_backvp != NULL);
83*5331Samw 		error = VOP_GETATTR(cp->c_backvp, &cp->c_attr, 0, cr, NULL);
840Sstevel@tonic-gate 		if (error)
850Sstevel@tonic-gate 			return (error);
860Sstevel@tonic-gate 	} else {
870Sstevel@tonic-gate 		/* copy passed in attributes into the cnode */
880Sstevel@tonic-gate 		cp->c_attr = *vap;
890Sstevel@tonic-gate 	}
900Sstevel@tonic-gate 
910Sstevel@tonic-gate 	cp->c_size = cp->c_attr.va_size;
920Sstevel@tonic-gate 	mdp->md_consttype = CFS_FS_CONST_NOCONST;
930Sstevel@tonic-gate 	cp->c_flags |= CN_UPDATED;
940Sstevel@tonic-gate 	return (0);
950Sstevel@tonic-gate }
960Sstevel@tonic-gate 
970Sstevel@tonic-gate /*ARGSUSED*/
980Sstevel@tonic-gate static int
c_nop_check_cached_object(struct fscache * fscp,struct cnode * cp,int verify_what,cred_t * cr)990Sstevel@tonic-gate c_nop_check_cached_object(struct fscache *fscp, struct cnode *cp,
1000Sstevel@tonic-gate 	int verify_what, cred_t *cr)
1010Sstevel@tonic-gate {
1020Sstevel@tonic-gate 	struct vattr attrs;
1030Sstevel@tonic-gate 	int fail = 0, backhit = 0;
1040Sstevel@tonic-gate 	int error = 0;
1050Sstevel@tonic-gate 	cachefs_metadata_t *mdp = &cp->c_metadata;
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate 	ASSERT(cr);
1080Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cp->c_statelock));
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate 	/* nothing to do if not connected */
1110Sstevel@tonic-gate 	if ((fscp->fs_cdconnected != CFS_CD_CONNECTED) ||
1120Sstevel@tonic-gate 	    (fscp->fs_backvfsp == NULL))
1130Sstevel@tonic-gate 		goto out;
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate 	/* done if do not have to check */
1160Sstevel@tonic-gate 	if (((verify_what & C_BACK_CHECK) == 0) &&
1170Sstevel@tonic-gate 	    ((mdp->md_flags & MD_NEEDATTRS) == 0))
1180Sstevel@tonic-gate 		goto out;
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 	/* get backvp if necessary */
1210Sstevel@tonic-gate 	if (cp->c_backvp == NULL) {
1220Sstevel@tonic-gate 		error = cachefs_getbackvp(fscp, cp);
1230Sstevel@tonic-gate 		if (error)
1240Sstevel@tonic-gate 			goto out;
1250Sstevel@tonic-gate 	}
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate 	/* get the file attributes from the back fs */
1280Sstevel@tonic-gate 	attrs.va_mask = AT_ALL;
129*5331Samw 	error = VOP_GETATTR(cp->c_backvp, &attrs, 0, cr, NULL);
1300Sstevel@tonic-gate 	backhit = 1;
1310Sstevel@tonic-gate 	if (error)
1320Sstevel@tonic-gate 		goto out;
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate 	cp->c_attr = attrs;
1350Sstevel@tonic-gate 	if (attrs.va_size > cp->c_size)
1360Sstevel@tonic-gate 		cp->c_size = attrs.va_size;
1370Sstevel@tonic-gate 	mdp->md_flags &= ~MD_NEEDATTRS;
1380Sstevel@tonic-gate 	cachefs_cnode_setlocalstats(cp);
1390Sstevel@tonic-gate 	cp->c_flags |= CN_UPDATED;
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate out:
1420Sstevel@tonic-gate 	if (backhit != 0) {
1430Sstevel@tonic-gate 		if (fail != 0)
1440Sstevel@tonic-gate 			fscp->fs_stats.st_fails++;
1450Sstevel@tonic-gate 		else
1460Sstevel@tonic-gate 			fscp->fs_stats.st_passes++;
1470Sstevel@tonic-gate 	}
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate 	return (error);
1500Sstevel@tonic-gate }
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate static void
c_nop_modify_cached_object(struct fscache * fscp,struct cnode * cp,cred_t * cr)1530Sstevel@tonic-gate c_nop_modify_cached_object(struct fscache *fscp, struct cnode *cp, cred_t *cr)
1540Sstevel@tonic-gate {
1550Sstevel@tonic-gate 	struct vattr attrs;
1560Sstevel@tonic-gate 	int	error;
1570Sstevel@tonic-gate 	nlink_t	nlink;
1580Sstevel@tonic-gate 	cachefs_metadata_t *mdp = &cp->c_metadata;
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cp->c_statelock));
1610Sstevel@tonic-gate 	ASSERT(fscp->fs_cdconnected == CFS_CD_CONNECTED);
1620Sstevel@tonic-gate 	ASSERT(fscp->fs_backvfsp);
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 	fscp->fs_stats.st_modifies++;
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate 	/* from now on, make sure we're using the server's idea of time */
1670Sstevel@tonic-gate 	mdp->md_flags &= ~(MD_LOCALCTIME | MD_LOCALMTIME);
1680Sstevel@tonic-gate 	mdp->md_flags |= MD_NEEDATTRS;
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate 	/* if in write-around mode, make sure file is nocached */
1710Sstevel@tonic-gate 	if (CFS_ISFS_WRITE_AROUND(fscp)) {
1720Sstevel@tonic-gate 		if ((cp->c_flags & CN_NOCACHE) == 0)
1730Sstevel@tonic-gate 			cachefs_nocache(cp);
1740Sstevel@tonic-gate 	}
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate 	/* get the new attributes so we don't wait forever to get them */
1770Sstevel@tonic-gate 	if (cp->c_backvp == NULL) {
1780Sstevel@tonic-gate 		error = cachefs_getbackvp(fscp, cp);
1790Sstevel@tonic-gate 		if (error)
1800Sstevel@tonic-gate 			return;
1810Sstevel@tonic-gate 	}
1820Sstevel@tonic-gate 	attrs.va_mask = AT_ALL;
183*5331Samw 	error = VOP_GETATTR(cp->c_backvp, &attrs, 0, cr, NULL);
1840Sstevel@tonic-gate 	if (error)
1850Sstevel@tonic-gate 		return;
1860Sstevel@tonic-gate 	nlink = cp->c_attr.va_nlink;
1870Sstevel@tonic-gate 	cp->c_attr = attrs;
1880Sstevel@tonic-gate 	cp->c_attr.va_nlink = nlink;
1890Sstevel@tonic-gate 	if ((attrs.va_size > cp->c_size) || !vn_has_cached_data(CTOV(cp)))
1900Sstevel@tonic-gate 		cp->c_size = attrs.va_size;
1910Sstevel@tonic-gate 	mdp->md_flags &= ~MD_NEEDATTRS;
1920Sstevel@tonic-gate 	cachefs_cnode_setlocalstats(cp);
1930Sstevel@tonic-gate 	cp->c_flags |= CN_UPDATED;
1940Sstevel@tonic-gate }
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate /*ARGSUSED*/
1970Sstevel@tonic-gate static void
c_nop_invalidate_cached_object(struct fscache * fscp,struct cnode * cp,cred_t * cr)1980Sstevel@tonic-gate c_nop_invalidate_cached_object(struct fscache *fscp, struct cnode *cp,
1990Sstevel@tonic-gate 	cred_t *cr)
2000Sstevel@tonic-gate {
2010Sstevel@tonic-gate 	cachefs_metadata_t *mdp = &cp->c_metadata;
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cp->c_statelock));
2040Sstevel@tonic-gate 	mdp->md_flags |= MD_NEEDATTRS;
2050Sstevel@tonic-gate 	cp->c_flags |= CN_UPDATED;
2060Sstevel@tonic-gate }
2070Sstevel@tonic-gate 
2080Sstevel@tonic-gate /*ARGSUSED*/
2090Sstevel@tonic-gate static void
c_nop_convert_cached_object(struct fscache * fscp,struct cnode * cp,cred_t * cr)2100Sstevel@tonic-gate c_nop_convert_cached_object(struct fscache *fscp, struct cnode *cp,
2110Sstevel@tonic-gate 	cred_t *cr)
2120Sstevel@tonic-gate {
2130Sstevel@tonic-gate 	cachefs_metadata_t *mdp = &cp->c_metadata;
2140Sstevel@tonic-gate 	mdp->md_flags |= MD_NEEDATTRS;
2150Sstevel@tonic-gate 	mdp->md_consttype = CFS_FS_CONST_NOCONST;
2160Sstevel@tonic-gate 	cp->c_flags |= CN_UPDATED;
2170Sstevel@tonic-gate }
2180Sstevel@tonic-gate 
2190Sstevel@tonic-gate struct cachefsops nopcfsops = {
2200Sstevel@tonic-gate 	c_nop_init_cached_object,
2210Sstevel@tonic-gate 	c_nop_check_cached_object,
2220Sstevel@tonic-gate 	c_nop_modify_cached_object,
2230Sstevel@tonic-gate 	c_nop_invalidate_cached_object,
2240Sstevel@tonic-gate 	c_nop_convert_cached_object
2250Sstevel@tonic-gate };
226