xref: /titanic_44/usr/src/uts/common/fs/cachefs/cachefs_noopc.c (revision da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*da6c28aaSamw  * Common Development and Distribution License (the "License").
6*da6c28aaSamw  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*da6c28aaSamw  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #include <sys/param.h>
287c478bd9Sstevel@tonic-gate #include <sys/types.h>
297c478bd9Sstevel@tonic-gate #include <sys/systm.h>
307c478bd9Sstevel@tonic-gate #include <sys/cred.h>
317c478bd9Sstevel@tonic-gate #include <sys/proc.h>
327c478bd9Sstevel@tonic-gate #include <sys/user.h>
337c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
347c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
357c478bd9Sstevel@tonic-gate #include <sys/pathname.h>
367c478bd9Sstevel@tonic-gate #include <sys/uio.h>
377c478bd9Sstevel@tonic-gate #include <sys/tiuser.h>
387c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
397c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
407c478bd9Sstevel@tonic-gate #include <sys/mount.h>
417c478bd9Sstevel@tonic-gate #include <sys/ioctl.h>
427c478bd9Sstevel@tonic-gate #include <sys/statvfs.h>
437c478bd9Sstevel@tonic-gate #include <sys/errno.h>
447c478bd9Sstevel@tonic-gate #include <sys/debug.h>
457c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
467c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
477c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
487c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #include <sys/fs/cachefs_fs.h>
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /*ARGSUSED*/
537c478bd9Sstevel@tonic-gate static int
c_nop_init_cached_object(fscache_t * fscp,cnode_t * cp,vattr_t * vap,cred_t * cr)547c478bd9Sstevel@tonic-gate c_nop_init_cached_object(fscache_t *fscp, cnode_t *cp, vattr_t *vap,
557c478bd9Sstevel@tonic-gate     cred_t *cr)
567c478bd9Sstevel@tonic-gate {
577c478bd9Sstevel@tonic-gate 	int error;
587c478bd9Sstevel@tonic-gate 	cachefs_metadata_t *mdp = &cp->c_metadata;
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate 	ASSERT(cr != NULL);
617c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cp->c_statelock));
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate 	/* NFSv4 always sets strict consistency */
647c478bd9Sstevel@tonic-gate 	ASSERT(CFS_ISFS_BACKFS_NFSV4(fscp) == 0);
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 	/* if attributes not passed in then get them */
677c478bd9Sstevel@tonic-gate 	if (vap == NULL) {
687c478bd9Sstevel@tonic-gate 		/* if not connected then cannot get attrs */
697c478bd9Sstevel@tonic-gate 		if ((fscp->fs_cdconnected != CFS_CD_CONNECTED) ||
707c478bd9Sstevel@tonic-gate 		    (fscp->fs_backvfsp == NULL))
717c478bd9Sstevel@tonic-gate 			return (ETIMEDOUT);
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 		/* get backvp if necessary */
747c478bd9Sstevel@tonic-gate 		if (cp->c_backvp == NULL) {
757c478bd9Sstevel@tonic-gate 			error = cachefs_getbackvp(fscp, cp);
767c478bd9Sstevel@tonic-gate 			if (error)
777c478bd9Sstevel@tonic-gate 				return (error);
787c478bd9Sstevel@tonic-gate 		}
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 		/* get the attributes */
817c478bd9Sstevel@tonic-gate 		cp->c_attr.va_mask = AT_ALL;
827c478bd9Sstevel@tonic-gate 		ASSERT(cp->c_backvp != NULL);
83*da6c28aaSamw 		error = VOP_GETATTR(cp->c_backvp, &cp->c_attr, 0, cr, NULL);
847c478bd9Sstevel@tonic-gate 		if (error)
857c478bd9Sstevel@tonic-gate 			return (error);
867c478bd9Sstevel@tonic-gate 	} else {
877c478bd9Sstevel@tonic-gate 		/* copy passed in attributes into the cnode */
887c478bd9Sstevel@tonic-gate 		cp->c_attr = *vap;
897c478bd9Sstevel@tonic-gate 	}
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate 	cp->c_size = cp->c_attr.va_size;
927c478bd9Sstevel@tonic-gate 	mdp->md_consttype = CFS_FS_CONST_NOCONST;
937c478bd9Sstevel@tonic-gate 	cp->c_flags |= CN_UPDATED;
947c478bd9Sstevel@tonic-gate 	return (0);
957c478bd9Sstevel@tonic-gate }
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate /*ARGSUSED*/
987c478bd9Sstevel@tonic-gate static int
c_nop_check_cached_object(struct fscache * fscp,struct cnode * cp,int verify_what,cred_t * cr)997c478bd9Sstevel@tonic-gate c_nop_check_cached_object(struct fscache *fscp, struct cnode *cp,
1007c478bd9Sstevel@tonic-gate 	int verify_what, cred_t *cr)
1017c478bd9Sstevel@tonic-gate {
1027c478bd9Sstevel@tonic-gate 	struct vattr attrs;
1037c478bd9Sstevel@tonic-gate 	int fail = 0, backhit = 0;
1047c478bd9Sstevel@tonic-gate 	int error = 0;
1057c478bd9Sstevel@tonic-gate 	cachefs_metadata_t *mdp = &cp->c_metadata;
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 	ASSERT(cr);
1087c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cp->c_statelock));
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	/* nothing to do if not connected */
1117c478bd9Sstevel@tonic-gate 	if ((fscp->fs_cdconnected != CFS_CD_CONNECTED) ||
1127c478bd9Sstevel@tonic-gate 	    (fscp->fs_backvfsp == NULL))
1137c478bd9Sstevel@tonic-gate 		goto out;
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate 	/* done if do not have to check */
1167c478bd9Sstevel@tonic-gate 	if (((verify_what & C_BACK_CHECK) == 0) &&
1177c478bd9Sstevel@tonic-gate 	    ((mdp->md_flags & MD_NEEDATTRS) == 0))
1187c478bd9Sstevel@tonic-gate 		goto out;
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 	/* get backvp if necessary */
1217c478bd9Sstevel@tonic-gate 	if (cp->c_backvp == NULL) {
1227c478bd9Sstevel@tonic-gate 		error = cachefs_getbackvp(fscp, cp);
1237c478bd9Sstevel@tonic-gate 		if (error)
1247c478bd9Sstevel@tonic-gate 			goto out;
1257c478bd9Sstevel@tonic-gate 	}
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 	/* get the file attributes from the back fs */
1287c478bd9Sstevel@tonic-gate 	attrs.va_mask = AT_ALL;
129*da6c28aaSamw 	error = VOP_GETATTR(cp->c_backvp, &attrs, 0, cr, NULL);
1307c478bd9Sstevel@tonic-gate 	backhit = 1;
1317c478bd9Sstevel@tonic-gate 	if (error)
1327c478bd9Sstevel@tonic-gate 		goto out;
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	cp->c_attr = attrs;
1357c478bd9Sstevel@tonic-gate 	if (attrs.va_size > cp->c_size)
1367c478bd9Sstevel@tonic-gate 		cp->c_size = attrs.va_size;
1377c478bd9Sstevel@tonic-gate 	mdp->md_flags &= ~MD_NEEDATTRS;
1387c478bd9Sstevel@tonic-gate 	cachefs_cnode_setlocalstats(cp);
1397c478bd9Sstevel@tonic-gate 	cp->c_flags |= CN_UPDATED;
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate out:
1427c478bd9Sstevel@tonic-gate 	if (backhit != 0) {
1437c478bd9Sstevel@tonic-gate 		if (fail != 0)
1447c478bd9Sstevel@tonic-gate 			fscp->fs_stats.st_fails++;
1457c478bd9Sstevel@tonic-gate 		else
1467c478bd9Sstevel@tonic-gate 			fscp->fs_stats.st_passes++;
1477c478bd9Sstevel@tonic-gate 	}
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 	return (error);
1507c478bd9Sstevel@tonic-gate }
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate static void
c_nop_modify_cached_object(struct fscache * fscp,struct cnode * cp,cred_t * cr)1537c478bd9Sstevel@tonic-gate c_nop_modify_cached_object(struct fscache *fscp, struct cnode *cp, cred_t *cr)
1547c478bd9Sstevel@tonic-gate {
1557c478bd9Sstevel@tonic-gate 	struct vattr attrs;
1567c478bd9Sstevel@tonic-gate 	int	error;
1577c478bd9Sstevel@tonic-gate 	nlink_t	nlink;
1587c478bd9Sstevel@tonic-gate 	cachefs_metadata_t *mdp = &cp->c_metadata;
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cp->c_statelock));
1617c478bd9Sstevel@tonic-gate 	ASSERT(fscp->fs_cdconnected == CFS_CD_CONNECTED);
1627c478bd9Sstevel@tonic-gate 	ASSERT(fscp->fs_backvfsp);
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 	fscp->fs_stats.st_modifies++;
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 	/* from now on, make sure we're using the server's idea of time */
1677c478bd9Sstevel@tonic-gate 	mdp->md_flags &= ~(MD_LOCALCTIME | MD_LOCALMTIME);
1687c478bd9Sstevel@tonic-gate 	mdp->md_flags |= MD_NEEDATTRS;
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	/* if in write-around mode, make sure file is nocached */
1717c478bd9Sstevel@tonic-gate 	if (CFS_ISFS_WRITE_AROUND(fscp)) {
1727c478bd9Sstevel@tonic-gate 		if ((cp->c_flags & CN_NOCACHE) == 0)
1737c478bd9Sstevel@tonic-gate 			cachefs_nocache(cp);
1747c478bd9Sstevel@tonic-gate 	}
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 	/* get the new attributes so we don't wait forever to get them */
1777c478bd9Sstevel@tonic-gate 	if (cp->c_backvp == NULL) {
1787c478bd9Sstevel@tonic-gate 		error = cachefs_getbackvp(fscp, cp);
1797c478bd9Sstevel@tonic-gate 		if (error)
1807c478bd9Sstevel@tonic-gate 			return;
1817c478bd9Sstevel@tonic-gate 	}
1827c478bd9Sstevel@tonic-gate 	attrs.va_mask = AT_ALL;
183*da6c28aaSamw 	error = VOP_GETATTR(cp->c_backvp, &attrs, 0, cr, NULL);
1847c478bd9Sstevel@tonic-gate 	if (error)
1857c478bd9Sstevel@tonic-gate 		return;
1867c478bd9Sstevel@tonic-gate 	nlink = cp->c_attr.va_nlink;
1877c478bd9Sstevel@tonic-gate 	cp->c_attr = attrs;
1887c478bd9Sstevel@tonic-gate 	cp->c_attr.va_nlink = nlink;
1897c478bd9Sstevel@tonic-gate 	if ((attrs.va_size > cp->c_size) || !vn_has_cached_data(CTOV(cp)))
1907c478bd9Sstevel@tonic-gate 		cp->c_size = attrs.va_size;
1917c478bd9Sstevel@tonic-gate 	mdp->md_flags &= ~MD_NEEDATTRS;
1927c478bd9Sstevel@tonic-gate 	cachefs_cnode_setlocalstats(cp);
1937c478bd9Sstevel@tonic-gate 	cp->c_flags |= CN_UPDATED;
1947c478bd9Sstevel@tonic-gate }
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1977c478bd9Sstevel@tonic-gate static void
c_nop_invalidate_cached_object(struct fscache * fscp,struct cnode * cp,cred_t * cr)1987c478bd9Sstevel@tonic-gate c_nop_invalidate_cached_object(struct fscache *fscp, struct cnode *cp,
1997c478bd9Sstevel@tonic-gate 	cred_t *cr)
2007c478bd9Sstevel@tonic-gate {
2017c478bd9Sstevel@tonic-gate 	cachefs_metadata_t *mdp = &cp->c_metadata;
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cp->c_statelock));
2047c478bd9Sstevel@tonic-gate 	mdp->md_flags |= MD_NEEDATTRS;
2057c478bd9Sstevel@tonic-gate 	cp->c_flags |= CN_UPDATED;
2067c478bd9Sstevel@tonic-gate }
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2097c478bd9Sstevel@tonic-gate static void
c_nop_convert_cached_object(struct fscache * fscp,struct cnode * cp,cred_t * cr)2107c478bd9Sstevel@tonic-gate c_nop_convert_cached_object(struct fscache *fscp, struct cnode *cp,
2117c478bd9Sstevel@tonic-gate 	cred_t *cr)
2127c478bd9Sstevel@tonic-gate {
2137c478bd9Sstevel@tonic-gate 	cachefs_metadata_t *mdp = &cp->c_metadata;
2147c478bd9Sstevel@tonic-gate 	mdp->md_flags |= MD_NEEDATTRS;
2157c478bd9Sstevel@tonic-gate 	mdp->md_consttype = CFS_FS_CONST_NOCONST;
2167c478bd9Sstevel@tonic-gate 	cp->c_flags |= CN_UPDATED;
2177c478bd9Sstevel@tonic-gate }
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate struct cachefsops nopcfsops = {
2207c478bd9Sstevel@tonic-gate 	c_nop_init_cached_object,
2217c478bd9Sstevel@tonic-gate 	c_nop_check_cached_object,
2227c478bd9Sstevel@tonic-gate 	c_nop_modify_cached_object,
2237c478bd9Sstevel@tonic-gate 	c_nop_invalidate_cached_object,
2247c478bd9Sstevel@tonic-gate 	c_nop_convert_cached_object
2257c478bd9Sstevel@tonic-gate };
226