xref: /titanic_41/usr/src/uts/common/fs/cachefs/cachefs_cod.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 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <sys/param.h>
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <sys/systm.h>
317c478bd9Sstevel@tonic-gate #include <sys/cred.h>
327c478bd9Sstevel@tonic-gate #include <sys/proc.h>
337c478bd9Sstevel@tonic-gate #include <sys/user.h>
347c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
357c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
367c478bd9Sstevel@tonic-gate #include <sys/pathname.h>
377c478bd9Sstevel@tonic-gate #include <sys/uio.h>
387c478bd9Sstevel@tonic-gate #include <sys/tiuser.h>
397c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
407c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
417c478bd9Sstevel@tonic-gate #include <netinet/in.h>
427c478bd9Sstevel@tonic-gate #include <sys/mount.h>
437c478bd9Sstevel@tonic-gate #include <sys/ioctl.h>
447c478bd9Sstevel@tonic-gate #include <sys/statvfs.h>
457c478bd9Sstevel@tonic-gate #include <sys/errno.h>
467c478bd9Sstevel@tonic-gate #include <sys/debug.h>
477c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
487c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
497c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
507c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #include <vm/hat.h>
537c478bd9Sstevel@tonic-gate #include <vm/as.h>
547c478bd9Sstevel@tonic-gate #include <vm/page.h>
557c478bd9Sstevel@tonic-gate #include <vm/pvn.h>
567c478bd9Sstevel@tonic-gate #include <vm/seg.h>
577c478bd9Sstevel@tonic-gate #include <vm/seg_map.h>
587c478bd9Sstevel@tonic-gate #include <vm/seg_vn.h>
597c478bd9Sstevel@tonic-gate #include <vm/rm.h>
607c478bd9Sstevel@tonic-gate #include <sys/fs/cachefs_fs.h>
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate #define	C_CACHE_VALID(TOKEN_MTIME, NEW_MTIME)   \
637c478bd9Sstevel@tonic-gate 	((TOKEN_MTIME.tv_sec == NEW_MTIME.tv_sec) && \
647c478bd9Sstevel@tonic-gate 		(TOKEN_MTIME.tv_nsec == NEW_MTIME.tv_nsec))
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate static int
c_cod_init_cached_object(fscache_t * fscp,cnode_t * cp,vattr_t * vap,cred_t * cr)677c478bd9Sstevel@tonic-gate c_cod_init_cached_object(fscache_t *fscp, cnode_t *cp, vattr_t *vap,
687c478bd9Sstevel@tonic-gate     cred_t *cr)
697c478bd9Sstevel@tonic-gate {
707c478bd9Sstevel@tonic-gate 	int error;
717c478bd9Sstevel@tonic-gate 	cachefs_metadata_t *mdp = &cp->c_metadata;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 	ASSERT(cr != NULL);
747c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cp->c_statelock));
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 	/* NFSv4 option sets strict consistency */
777c478bd9Sstevel@tonic-gate 	ASSERT(CFS_ISFS_BACKFS_NFSV4(fscp) == 0);
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate 	/* if attributes not passed in then get them */
807c478bd9Sstevel@tonic-gate 	if (vap == NULL) {
817c478bd9Sstevel@tonic-gate 		/* if not connected then cannot get attrs */
827c478bd9Sstevel@tonic-gate 		if ((fscp->fs_cdconnected != CFS_CD_CONNECTED) ||
837c478bd9Sstevel@tonic-gate 		    (fscp->fs_backvfsp == NULL))
847c478bd9Sstevel@tonic-gate 			return (ETIMEDOUT);
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate 		/* get backvp if necessary */
877c478bd9Sstevel@tonic-gate 		if (cp->c_backvp == NULL) {
887c478bd9Sstevel@tonic-gate 			error = cachefs_getbackvp(fscp, cp);
897c478bd9Sstevel@tonic-gate 			if (error)
907c478bd9Sstevel@tonic-gate 				return (error);
917c478bd9Sstevel@tonic-gate 		}
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 		/* get the attributes */
947c478bd9Sstevel@tonic-gate 		cp->c_attr.va_mask = AT_ALL;
95*da6c28aaSamw 		error = VOP_GETATTR(cp->c_backvp, &cp->c_attr, 0, cr, NULL);
967c478bd9Sstevel@tonic-gate 		if (error)
977c478bd9Sstevel@tonic-gate 			return (error);
987c478bd9Sstevel@tonic-gate 	} else {
997c478bd9Sstevel@tonic-gate 		/* copy passed in attributes into the cnode */
1007c478bd9Sstevel@tonic-gate 		cp->c_attr = *vap;
1017c478bd9Sstevel@tonic-gate 	}
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 	cp->c_size = cp->c_attr.va_size;
1047c478bd9Sstevel@tonic-gate 	mdp->md_x_time = fscp->fs_cod_time;
1057c478bd9Sstevel@tonic-gate 	mdp->md_consttype = CFS_FS_CONST_CODCONST;
1067c478bd9Sstevel@tonic-gate 	cp->c_flags |= CN_UPDATED;
1077c478bd9Sstevel@tonic-gate 	return (0);
1087c478bd9Sstevel@tonic-gate }
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate static int
c_cod_check_cached_object(struct fscache * fscp,struct cnode * cp,int verify_what,cred_t * cr)1117c478bd9Sstevel@tonic-gate c_cod_check_cached_object(struct fscache *fscp, struct cnode *cp,
1127c478bd9Sstevel@tonic-gate     int verify_what, cred_t *cr)
1137c478bd9Sstevel@tonic-gate {
1147c478bd9Sstevel@tonic-gate 	struct vattr attrs;
1157c478bd9Sstevel@tonic-gate 	int fail = 0, backhit = 0;
1167c478bd9Sstevel@tonic-gate 	int error = 0;
1177c478bd9Sstevel@tonic-gate 	cachefs_metadata_t *mdp = &cp->c_metadata;
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate #ifdef CFSDEBUG
1207c478bd9Sstevel@tonic-gate 	CFS_DEBUG(CFSDEBUG_VOPS)
1217c478bd9Sstevel@tonic-gate 		printf("c_cod_check_cached_object: ENTER cp %p\n", cp);
1227c478bd9Sstevel@tonic-gate #endif
1237c478bd9Sstevel@tonic-gate 	ASSERT(cr);
1247c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cp->c_statelock));
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate 	/* nothing to do if not connected */
1277c478bd9Sstevel@tonic-gate 	if ((fscp->fs_cdconnected != CFS_CD_CONNECTED) ||
1287c478bd9Sstevel@tonic-gate 	    (fscp->fs_backvfsp == NULL))
1297c478bd9Sstevel@tonic-gate 		goto out;
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate 	/* done if do not have to check and cod button has not been pushed */
1327c478bd9Sstevel@tonic-gate 	if (((verify_what & C_BACK_CHECK) == 0) &&
1337c478bd9Sstevel@tonic-gate 	    (C_CACHE_VALID(mdp->md_x_time, fscp->fs_cod_time)) &&
1347c478bd9Sstevel@tonic-gate 	    ((mdp->md_flags & MD_NEEDATTRS) == 0))
1357c478bd9Sstevel@tonic-gate 		goto out;
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate 	/* get backvp if necessary */
1387c478bd9Sstevel@tonic-gate 	if (cp->c_backvp == NULL) {
1397c478bd9Sstevel@tonic-gate 		error = cachefs_getbackvp(fscp, cp);
1407c478bd9Sstevel@tonic-gate 		if (error)
1417c478bd9Sstevel@tonic-gate 			goto out;
1427c478bd9Sstevel@tonic-gate 	}
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate 	/*
1457c478bd9Sstevel@tonic-gate 	 * If the cnode is being populated, and we're not the populating
1467c478bd9Sstevel@tonic-gate 	 * thread, then block until the pop thread completes.  If we are the
1477c478bd9Sstevel@tonic-gate 	 * pop thread, then we may come in here, but not to nuke the directory
1487c478bd9Sstevel@tonic-gate 	 * cnode at a critical juncture.
1497c478bd9Sstevel@tonic-gate 	 */
1507c478bd9Sstevel@tonic-gate again:
1517c478bd9Sstevel@tonic-gate 	while ((cp->c_flags & CN_ASYNC_POP_WORKING) &&
1527c478bd9Sstevel@tonic-gate 	    (cp->c_popthrp != curthread)) {
1537c478bd9Sstevel@tonic-gate 		cv_wait(&cp->c_popcv, &cp->c_statelock);
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 		/*
1567c478bd9Sstevel@tonic-gate 		 * recheck backvp and connectivity - if backvp now null,
1577c478bd9Sstevel@tonic-gate 		 * something bad happened, so don't bother trying to 'get' it
1587c478bd9Sstevel@tonic-gate 		 */
1597c478bd9Sstevel@tonic-gate 		if ((cp->c_backvp == NULL) ||
1607c478bd9Sstevel@tonic-gate 			(fscp->fs_cdconnected != CFS_CD_CONNECTED) ||
1617c478bd9Sstevel@tonic-gate 			(fscp->fs_backvfsp == NULL)) {
1627c478bd9Sstevel@tonic-gate 			if (cp->c_flags | CN_STALE) {
1637c478bd9Sstevel@tonic-gate 				cp->c_flags |= CN_NOCACHE;
1647c478bd9Sstevel@tonic-gate 				error = ESTALE;
1657c478bd9Sstevel@tonic-gate 			}
1667c478bd9Sstevel@tonic-gate 			goto out;
1677c478bd9Sstevel@tonic-gate 		}
1687c478bd9Sstevel@tonic-gate 	}
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	/* get the file attributes from the back fs */
1717c478bd9Sstevel@tonic-gate 	attrs.va_mask = AT_ALL;
172*da6c28aaSamw 	error = VOP_GETATTR(cp->c_backvp, &attrs, 0, cr, NULL);
1737c478bd9Sstevel@tonic-gate 	backhit = 1;
1747c478bd9Sstevel@tonic-gate 	if (error)
1757c478bd9Sstevel@tonic-gate 		goto out;
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	/* if the mtime or size of the file has changed */
1787c478bd9Sstevel@tonic-gate 	if ((!C_CACHE_VALID(mdp->md_vattr.va_mtime, attrs.va_mtime) ||
1797c478bd9Sstevel@tonic-gate 	    (cp->c_size != attrs.va_size)) &&
1807c478bd9Sstevel@tonic-gate 	    ((mdp->md_flags & MD_NEEDATTRS) == 0)) {
1817c478bd9Sstevel@tonic-gate 		fail = 1;
1827c478bd9Sstevel@tonic-gate 		if (vn_has_cached_data(CTOV(cp))) {
1837c478bd9Sstevel@tonic-gate 			mutex_exit(&cp->c_statelock);
1847c478bd9Sstevel@tonic-gate 			error = cachefs_putpage_common(CTOV(cp),
1857c478bd9Sstevel@tonic-gate 			    (offset_t)0, 0, B_INVAL, cr);
1867c478bd9Sstevel@tonic-gate 			mutex_enter(&cp->c_statelock);
1877c478bd9Sstevel@tonic-gate 			if (CFS_TIMEOUT(fscp, error))
1887c478bd9Sstevel@tonic-gate 				goto out;
1897c478bd9Sstevel@tonic-gate 			error = 0;
1907c478bd9Sstevel@tonic-gate 			/*
1917c478bd9Sstevel@tonic-gate 			 * if an async pop started while the lock was
1927c478bd9Sstevel@tonic-gate 			 * dropped, go back and try again
1937c478bd9Sstevel@tonic-gate 			 */
1947c478bd9Sstevel@tonic-gate 			if ((cp->c_flags & CN_ASYNC_POP_WORKING) &&
1957c478bd9Sstevel@tonic-gate 			    (cp->c_popthrp != curthread))
1967c478bd9Sstevel@tonic-gate 				goto again;
1977c478bd9Sstevel@tonic-gate 		}
1987c478bd9Sstevel@tonic-gate 		/*
1997c478bd9Sstevel@tonic-gate 		 * We should properly handle the CN_NOCACHE flag here.
2007c478bd9Sstevel@tonic-gate 		 * In fact, we should remember that cachefs_inval_object()
2017c478bd9Sstevel@tonic-gate 		 * forcibly sets/unsets the flag, so we should keep a
2027c478bd9Sstevel@tonic-gate 		 * state of the flag over the call.
2037c478bd9Sstevel@tonic-gate 		 */
2047c478bd9Sstevel@tonic-gate 		if ((cp->c_flags & CN_NOCACHE) == 0)
2057c478bd9Sstevel@tonic-gate 			cachefs_inval_object(cp);
2067c478bd9Sstevel@tonic-gate 		else {
2077c478bd9Sstevel@tonic-gate 			cachefs_inval_object(cp);
2087c478bd9Sstevel@tonic-gate 			cp->c_flags |= CN_NOCACHE;
2097c478bd9Sstevel@tonic-gate 		}
2107c478bd9Sstevel@tonic-gate 		if ((CTOV(cp))->v_type == VREG) {
2117c478bd9Sstevel@tonic-gate 			attrs.va_mask = AT_ALL;
212*da6c28aaSamw 			error = VOP_GETATTR(cp->c_backvp, &attrs, 0, cr, NULL);
2137c478bd9Sstevel@tonic-gate 			if (error)
2147c478bd9Sstevel@tonic-gate 				goto out;
2157c478bd9Sstevel@tonic-gate 		}
2167c478bd9Sstevel@tonic-gate 		if (!vn_has_cached_data(CTOV(cp))) {
2177c478bd9Sstevel@tonic-gate 			cp->c_size = attrs.va_size;
2187c478bd9Sstevel@tonic-gate #ifdef CFSDEBUG
2197c478bd9Sstevel@tonic-gate 		} else {
2207c478bd9Sstevel@tonic-gate 			CFS_DEBUG(CFSDEBUG_VOPS)
2217c478bd9Sstevel@tonic-gate 				printf("c_cod_check: v_pages not null\n");
2227c478bd9Sstevel@tonic-gate #endif
2237c478bd9Sstevel@tonic-gate 		}
2247c478bd9Sstevel@tonic-gate 	}
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate 	/* toss cached acl info if ctime changed */
2277c478bd9Sstevel@tonic-gate 	if (!C_CACHE_VALID(mdp->md_vattr.va_ctime, attrs.va_ctime)) {
2287c478bd9Sstevel@tonic-gate 		cachefs_purgeacl(cp);
2297c478bd9Sstevel@tonic-gate 	}
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate 	cp->c_attr = attrs;
2327c478bd9Sstevel@tonic-gate 	if (attrs.va_size > cp->c_size)
2337c478bd9Sstevel@tonic-gate 		cp->c_size = attrs.va_size;
2347c478bd9Sstevel@tonic-gate 	mdp->md_x_time = fscp->fs_cod_time;
2357c478bd9Sstevel@tonic-gate 	mdp->md_flags &= ~MD_NEEDATTRS;
2367c478bd9Sstevel@tonic-gate 	cachefs_cnode_setlocalstats(cp);
2377c478bd9Sstevel@tonic-gate 	cp->c_flags |= CN_UPDATED;
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate out:
2407c478bd9Sstevel@tonic-gate 	if (backhit != 0) {
2417c478bd9Sstevel@tonic-gate 		if (fail != 0)
2427c478bd9Sstevel@tonic-gate 			fscp->fs_stats.st_fails++;
2437c478bd9Sstevel@tonic-gate 		else
2447c478bd9Sstevel@tonic-gate 			fscp->fs_stats.st_passes++;
2457c478bd9Sstevel@tonic-gate 	}
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate #ifdef CFSDEBUG
2487c478bd9Sstevel@tonic-gate 	CFS_DEBUG(CFSDEBUG_VOPS)
2497c478bd9Sstevel@tonic-gate 		printf("c_cod_check_cached_object: EXIT\n");
2507c478bd9Sstevel@tonic-gate #endif
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate 	return (error);
2537c478bd9Sstevel@tonic-gate }
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2567c478bd9Sstevel@tonic-gate static void
c_cod_modify_cached_object(struct fscache * fscp,struct cnode * cp,cred_t * cr)2577c478bd9Sstevel@tonic-gate c_cod_modify_cached_object(struct fscache *fscp, struct cnode *cp, cred_t *cr)
2587c478bd9Sstevel@tonic-gate {
2597c478bd9Sstevel@tonic-gate 	struct vattr attrs;
2607c478bd9Sstevel@tonic-gate 	int error = 0;
2617c478bd9Sstevel@tonic-gate 	nlink_t nlink;
2627c478bd9Sstevel@tonic-gate 	cachefs_metadata_t *mdp = &cp->c_metadata;
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cp->c_statelock));
2657c478bd9Sstevel@tonic-gate 	ASSERT(fscp->fs_cdconnected == CFS_CD_CONNECTED);
2667c478bd9Sstevel@tonic-gate 	ASSERT(fscp->fs_backvfsp);
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate 	fscp->fs_stats.st_modifies++;
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate 	/* from now on, make sure we're using the server's idea of time */
2717c478bd9Sstevel@tonic-gate 	mdp->md_flags &= ~(MD_LOCALCTIME | MD_LOCALMTIME);
2727c478bd9Sstevel@tonic-gate 	mdp->md_flags |= MD_NEEDATTRS;
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 	/* if in write-around mode, make sure file is nocached */
2757c478bd9Sstevel@tonic-gate 	if (CFS_ISFS_WRITE_AROUND(fscp)) {
2767c478bd9Sstevel@tonic-gate 		if ((cp->c_flags & CN_NOCACHE) == 0)
2777c478bd9Sstevel@tonic-gate 			cachefs_nocache(cp);
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 		/*
2807c478bd9Sstevel@tonic-gate 		 * If a directory, then defer getting the new attributes
2817c478bd9Sstevel@tonic-gate 		 * until requested.  Might be a little bit faster this way.
2827c478bd9Sstevel@tonic-gate 		 */
2837c478bd9Sstevel@tonic-gate 		if (CTOV(cp)->v_type == VDIR)
2847c478bd9Sstevel@tonic-gate 			goto out;
2857c478bd9Sstevel@tonic-gate 	}
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate 	/* get the new mtime so the next call to check_cobject does not fail */
2887c478bd9Sstevel@tonic-gate 	if (cp->c_backvp == NULL) {
2897c478bd9Sstevel@tonic-gate 		error = cachefs_getbackvp(fscp, cp);
2907c478bd9Sstevel@tonic-gate 		if (error) {
2917c478bd9Sstevel@tonic-gate 			mdp->md_vattr.va_mtime.tv_sec = 0;
2927c478bd9Sstevel@tonic-gate 			goto out;
2937c478bd9Sstevel@tonic-gate 		}
2947c478bd9Sstevel@tonic-gate 	}
2957c478bd9Sstevel@tonic-gate 	attrs.va_mask = AT_ALL;
2967c478bd9Sstevel@tonic-gate 	ASSERT(cp->c_backvp != NULL);
297*da6c28aaSamw 	error = VOP_GETATTR(cp->c_backvp, &attrs, 0, cr, NULL);
2987c478bd9Sstevel@tonic-gate 	if (error) {
2997c478bd9Sstevel@tonic-gate 		mdp->md_vattr.va_mtime.tv_sec = 0;
3007c478bd9Sstevel@tonic-gate 		goto out;
3017c478bd9Sstevel@tonic-gate 	}
3027c478bd9Sstevel@tonic-gate 	nlink = cp->c_attr.va_nlink;
3037c478bd9Sstevel@tonic-gate 	cp->c_attr = attrs;
3047c478bd9Sstevel@tonic-gate 	cp->c_attr.va_nlink = nlink;
3057c478bd9Sstevel@tonic-gate 	if ((attrs.va_size > cp->c_size) || !vn_has_cached_data(CTOV(cp)))
3067c478bd9Sstevel@tonic-gate 		cp->c_size = attrs.va_size;
3077c478bd9Sstevel@tonic-gate 	mdp->md_flags &= ~MD_NEEDATTRS;
3087c478bd9Sstevel@tonic-gate 	cachefs_cnode_setlocalstats(cp);
3097c478bd9Sstevel@tonic-gate out:
3107c478bd9Sstevel@tonic-gate 	cp->c_flags |= CN_UPDATED;
3117c478bd9Sstevel@tonic-gate }
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3147c478bd9Sstevel@tonic-gate static void
c_cod_invalidate_cached_object(struct fscache * fscp,struct cnode * cp,cred_t * cr)3157c478bd9Sstevel@tonic-gate c_cod_invalidate_cached_object(struct fscache *fscp, struct cnode *cp,
3167c478bd9Sstevel@tonic-gate     cred_t *cr)
3177c478bd9Sstevel@tonic-gate {
3187c478bd9Sstevel@tonic-gate 	cachefs_metadata_t *mdp = &cp->c_metadata;
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cp->c_statelock));
3217c478bd9Sstevel@tonic-gate 	mdp->md_vattr.va_mtime.tv_sec = 0;
3227c478bd9Sstevel@tonic-gate 	mdp->md_flags |= MD_NEEDATTRS;
3237c478bd9Sstevel@tonic-gate 	cp->c_flags |= CN_UPDATED;
3247c478bd9Sstevel@tonic-gate }
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3277c478bd9Sstevel@tonic-gate static void
c_cod_convert_cached_object(struct fscache * fscp,struct cnode * cp,cred_t * cr)3287c478bd9Sstevel@tonic-gate c_cod_convert_cached_object(struct fscache *fscp, struct cnode *cp,
3297c478bd9Sstevel@tonic-gate     cred_t *cr)
3307c478bd9Sstevel@tonic-gate {
3317c478bd9Sstevel@tonic-gate 	cachefs_metadata_t *mdp = &cp->c_metadata;
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cp->c_statelock));
3347c478bd9Sstevel@tonic-gate 	mdp->md_flags |= MD_NEEDATTRS;
3357c478bd9Sstevel@tonic-gate 	mdp->md_consttype = CFS_FS_CONST_CODCONST;
3367c478bd9Sstevel@tonic-gate 	cp->c_flags |= CN_UPDATED;
3377c478bd9Sstevel@tonic-gate }
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate struct cachefsops codcfsops = {
3407c478bd9Sstevel@tonic-gate 	c_cod_init_cached_object,
3417c478bd9Sstevel@tonic-gate 	c_cod_check_cached_object,
3427c478bd9Sstevel@tonic-gate 	c_cod_modify_cached_object,
3437c478bd9Sstevel@tonic-gate 	c_cod_invalidate_cached_object,
3447c478bd9Sstevel@tonic-gate 	c_cod_convert_cached_object
3457c478bd9Sstevel@tonic-gate };
346