xref: /titanic_44/usr/src/uts/common/fs/cachefs/cachefs_strict.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(SAVED_MTIME, NEW_MTIME)   \
637c478bd9Sstevel@tonic-gate 	((SAVED_MTIME.tv_sec == NEW_MTIME.tv_sec) && \
647c478bd9Sstevel@tonic-gate 		(SAVED_MTIME.tv_nsec == NEW_MTIME.tv_nsec))
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate static time_t cachefs_gettime_cached_object(struct fscache *fscp,
677c478bd9Sstevel@tonic-gate     struct cnode *cp, time_t mtime);
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate static int
c_strict_init_cached_object(fscache_t * fscp,cnode_t * cp,vattr_t * vap,cred_t * cr)707c478bd9Sstevel@tonic-gate c_strict_init_cached_object(fscache_t *fscp, cnode_t *cp, vattr_t *vap,
717c478bd9Sstevel@tonic-gate     cred_t *cr)
727c478bd9Sstevel@tonic-gate {
737c478bd9Sstevel@tonic-gate 	int error;
747c478bd9Sstevel@tonic-gate 	cachefs_metadata_t *mdp = &cp->c_metadata;
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 	ASSERT(cr);
777c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cp->c_statelock));
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 	/*
1047c478bd9Sstevel@tonic-gate 	 * Expire time is based on the number of seconds since
1057c478bd9Sstevel@tonic-gate 	 * the last change.
1067c478bd9Sstevel@tonic-gate 	 * (i.e. files that changed recently are likely to change soon)
1077c478bd9Sstevel@tonic-gate 	 */
1087c478bd9Sstevel@tonic-gate 	mdp->md_x_time.tv_nsec = 0;
1097c478bd9Sstevel@tonic-gate 	mdp->md_x_time.tv_sec = cachefs_gettime_cached_object(fscp, cp,
1107c478bd9Sstevel@tonic-gate 		cp->c_attr.va_mtime.tv_sec);
1117c478bd9Sstevel@tonic-gate 	mdp->md_consttype = CFS_FS_CONST_STRICT;
1127c478bd9Sstevel@tonic-gate 	cp->c_size = cp->c_attr.va_size;
1137c478bd9Sstevel@tonic-gate 	cp->c_flags |= CN_UPDATED;
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate 	return (0);
1167c478bd9Sstevel@tonic-gate }
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate static int
c_strict_check_cached_object(struct fscache * fscp,struct cnode * cp,int verify_what,cred_t * cr)1197c478bd9Sstevel@tonic-gate c_strict_check_cached_object(struct fscache *fscp, struct cnode *cp,
1207c478bd9Sstevel@tonic-gate 	int verify_what, cred_t *cr)
1217c478bd9Sstevel@tonic-gate {
1227c478bd9Sstevel@tonic-gate 	struct vattr attrs;
1237c478bd9Sstevel@tonic-gate 	int error = 0;
1247c478bd9Sstevel@tonic-gate 	int fail = 0, backhit = 0;
1257c478bd9Sstevel@tonic-gate 	cachefs_metadata_t *mdp = &cp->c_metadata;
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate #ifdef CFSDEBUG
1287c478bd9Sstevel@tonic-gate 	CFS_DEBUG(CFSDEBUG_VOPS)
1297c478bd9Sstevel@tonic-gate 		printf("c_strict_check_cached_object: ENTER cp %p\n",
1307c478bd9Sstevel@tonic-gate 		    (void *)cp);
1317c478bd9Sstevel@tonic-gate #endif
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 	ASSERT(cr);
1347c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cp->c_statelock));
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate 	if ((fscp->fs_cdconnected != CFS_CD_CONNECTED) ||
1377c478bd9Sstevel@tonic-gate 	    (fscp->fs_backvfsp == NULL))
1387c478bd9Sstevel@tonic-gate 		goto out;
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate 	/*
1417c478bd9Sstevel@tonic-gate 	 * If backfs is NFSv4, do a getattr to update link count,
1427c478bd9Sstevel@tonic-gate 	 * all other attributes are not used, and the backfs is
1437c478bd9Sstevel@tonic-gate 	 * called on a getattr request.
1447c478bd9Sstevel@tonic-gate 	 */
1457c478bd9Sstevel@tonic-gate 	if (CFS_ISFS_BACKFS_NFSV4(fscp)) {
1467c478bd9Sstevel@tonic-gate 		backhit = 1;
1477c478bd9Sstevel@tonic-gate 		attrs.va_mask = AT_ALL;
148*da6c28aaSamw 		error = VOP_GETATTR(cp->c_backvp, &attrs, 0, cr, NULL);
1497c478bd9Sstevel@tonic-gate 		if (error)
1507c478bd9Sstevel@tonic-gate 			goto out;
1517c478bd9Sstevel@tonic-gate 		cp->c_attr = attrs;
1527c478bd9Sstevel@tonic-gate 		goto out;
1537c478bd9Sstevel@tonic-gate 	}
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 	/* done if do not have to check and time has not expired */
1567c478bd9Sstevel@tonic-gate 	if (((verify_what & C_BACK_CHECK) == 0) &&
1577c478bd9Sstevel@tonic-gate 	    (gethrestime_sec() < mdp->md_x_time.tv_sec) &&
1587c478bd9Sstevel@tonic-gate 	    ((mdp->md_flags & MD_NEEDATTRS) == 0))
1597c478bd9Sstevel@tonic-gate 		goto out;
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 	/* get backvp if necessary */
1627c478bd9Sstevel@tonic-gate 	if (cp->c_backvp == NULL) {
1637c478bd9Sstevel@tonic-gate 		error = cachefs_getbackvp(fscp, cp);
1647c478bd9Sstevel@tonic-gate 		if (error)
1657c478bd9Sstevel@tonic-gate 			goto out;
1667c478bd9Sstevel@tonic-gate 	}
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 	/*
1697c478bd9Sstevel@tonic-gate 	 * If the cnode is being populated, and we're not the populating
1707c478bd9Sstevel@tonic-gate 	 * thread, then block until the pop thread completes.  If we are the
1717c478bd9Sstevel@tonic-gate 	 * pop thread, then we may come in here, but not to nuke the directory
1727c478bd9Sstevel@tonic-gate 	 * cnode at a critical juncture.
1737c478bd9Sstevel@tonic-gate 	 */
1747c478bd9Sstevel@tonic-gate again:
1757c478bd9Sstevel@tonic-gate 	while ((cp->c_flags & CN_ASYNC_POP_WORKING) &&
1767c478bd9Sstevel@tonic-gate 	    (cp->c_popthrp != curthread)) {
1777c478bd9Sstevel@tonic-gate 		cv_wait(&cp->c_popcv, &cp->c_statelock);
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 		/*
1807c478bd9Sstevel@tonic-gate 		 * recheck backvp and connectivity - if backvp now null,
1817c478bd9Sstevel@tonic-gate 		 * something bad happened, so don't bother trying to 'get' it
1827c478bd9Sstevel@tonic-gate 		 */
1837c478bd9Sstevel@tonic-gate 		if ((cp->c_backvp == NULL) ||
1847c478bd9Sstevel@tonic-gate 			(fscp->fs_cdconnected != CFS_CD_CONNECTED) ||
1857c478bd9Sstevel@tonic-gate 			(fscp->fs_backvfsp == NULL)) {
1867c478bd9Sstevel@tonic-gate 			if (cp->c_flags | CN_STALE) {
1877c478bd9Sstevel@tonic-gate 				cp->c_flags |= CN_NOCACHE;
1887c478bd9Sstevel@tonic-gate 				error = ESTALE;
1897c478bd9Sstevel@tonic-gate 			}
1907c478bd9Sstevel@tonic-gate 			goto out;
1917c478bd9Sstevel@tonic-gate 		}
1927c478bd9Sstevel@tonic-gate 	}
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 	/* get the file attributes from the back fs */
1957c478bd9Sstevel@tonic-gate 	attrs.va_mask = AT_ALL;
196*da6c28aaSamw 	error = VOP_GETATTR(cp->c_backvp, &attrs, 0, cr, NULL);
1977c478bd9Sstevel@tonic-gate 	backhit = 1;
1987c478bd9Sstevel@tonic-gate 	if (error)
1997c478bd9Sstevel@tonic-gate 		goto out;
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 	/* if the mtime or size of the file has changed */
2027c478bd9Sstevel@tonic-gate 	if ((!C_CACHE_VALID(mdp->md_vattr.va_mtime, attrs.va_mtime) ||
2037c478bd9Sstevel@tonic-gate 	    (cp->c_size != attrs.va_size)) &&
2047c478bd9Sstevel@tonic-gate 	    ((mdp->md_flags & MD_NEEDATTRS) == 0)) {
2057c478bd9Sstevel@tonic-gate 		fail = 1;
2067c478bd9Sstevel@tonic-gate #ifdef CFSDEBUG
2077c478bd9Sstevel@tonic-gate 		CFS_DEBUG(CFSDEBUG_INVALIDATE)
2087c478bd9Sstevel@tonic-gate 			printf("c_strict_check: invalidating %llu\n",
2097c478bd9Sstevel@tonic-gate 			    (u_longlong_t)cp->c_id.cid_fileno);
2107c478bd9Sstevel@tonic-gate #endif
2117c478bd9Sstevel@tonic-gate 		if (vn_has_cached_data(CTOV(cp))) {
2127c478bd9Sstevel@tonic-gate 			mutex_exit(&cp->c_statelock);
2137c478bd9Sstevel@tonic-gate 			error = cachefs_putpage_common(CTOV(cp),
2147c478bd9Sstevel@tonic-gate 			    (offset_t)0, 0, B_INVAL, cr);
2157c478bd9Sstevel@tonic-gate 			mutex_enter(&cp->c_statelock);
2167c478bd9Sstevel@tonic-gate 			if (CFS_TIMEOUT(fscp, error))
2177c478bd9Sstevel@tonic-gate 				goto out;
2187c478bd9Sstevel@tonic-gate 			error = 0;
2197c478bd9Sstevel@tonic-gate 			/*
2207c478bd9Sstevel@tonic-gate 			 * if an async pop started while the lock was
2217c478bd9Sstevel@tonic-gate 			 * dropped, go back and try again
2227c478bd9Sstevel@tonic-gate 			 */
2237c478bd9Sstevel@tonic-gate 			if ((cp->c_flags & CN_ASYNC_POP_WORKING) &&
2247c478bd9Sstevel@tonic-gate 			    (cp->c_popthrp != curthread))
2257c478bd9Sstevel@tonic-gate 				goto again;
2267c478bd9Sstevel@tonic-gate 		}
2277c478bd9Sstevel@tonic-gate 		/*
2287c478bd9Sstevel@tonic-gate 		 * We should properly handle the CN_NOCACHE flag here.
2297c478bd9Sstevel@tonic-gate 		 * In fact, we should remember that cachefs_inval_object()
2307c478bd9Sstevel@tonic-gate 		 * forcibly sets/unsets the flag, so we should keep a
2317c478bd9Sstevel@tonic-gate 		 * state of the flag over the call.
2327c478bd9Sstevel@tonic-gate 		 */
2337c478bd9Sstevel@tonic-gate 		if ((cp->c_flags & CN_NOCACHE) == 0)
2347c478bd9Sstevel@tonic-gate 			cachefs_inval_object(cp);
2357c478bd9Sstevel@tonic-gate 		else {
2367c478bd9Sstevel@tonic-gate 			cachefs_inval_object(cp);
2377c478bd9Sstevel@tonic-gate 			cp->c_flags |= CN_NOCACHE;
2387c478bd9Sstevel@tonic-gate 		}
2397c478bd9Sstevel@tonic-gate 		if ((CTOV(cp))->v_type == VREG) {
2407c478bd9Sstevel@tonic-gate 			attrs.va_mask = AT_ALL;
241*da6c28aaSamw 			error = VOP_GETATTR(cp->c_backvp, &attrs, 0, cr, NULL);
2427c478bd9Sstevel@tonic-gate 			if (error)
2437c478bd9Sstevel@tonic-gate 				goto out;
2447c478bd9Sstevel@tonic-gate 		}
2457c478bd9Sstevel@tonic-gate 		if (!vn_has_cached_data(CTOV(cp))) {
2467c478bd9Sstevel@tonic-gate 			cp->c_size = attrs.va_size;
2477c478bd9Sstevel@tonic-gate 		}
2487c478bd9Sstevel@tonic-gate #ifdef CFSDEBUG
2497c478bd9Sstevel@tonic-gate 		else {
2507c478bd9Sstevel@tonic-gate 			CFS_DEBUG(CFSDEBUG_VOPS)
2517c478bd9Sstevel@tonic-gate 				printf("c_strict_check: v_pages not null\n");
2527c478bd9Sstevel@tonic-gate 		}
2537c478bd9Sstevel@tonic-gate #endif
2547c478bd9Sstevel@tonic-gate 	}
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate 	/* toss cached acl info if ctime changed */
2577c478bd9Sstevel@tonic-gate 	if (!C_CACHE_VALID(mdp->md_vattr.va_ctime, attrs.va_ctime)) {
2587c478bd9Sstevel@tonic-gate 		cachefs_purgeacl(cp);
2597c478bd9Sstevel@tonic-gate 	}
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate 	cp->c_attr = attrs;
2627c478bd9Sstevel@tonic-gate 	if (attrs.va_size > cp->c_size)
2637c478bd9Sstevel@tonic-gate 		cp->c_size = attrs.va_size;
2647c478bd9Sstevel@tonic-gate 	mdp->md_x_time.tv_sec =
2657c478bd9Sstevel@tonic-gate 	    cachefs_gettime_cached_object(fscp, cp, attrs.va_mtime.tv_sec);
2667c478bd9Sstevel@tonic-gate 	mdp->md_flags &= ~MD_NEEDATTRS;
2677c478bd9Sstevel@tonic-gate 	cachefs_cnode_setlocalstats(cp);
2687c478bd9Sstevel@tonic-gate 	cp->c_flags |= CN_UPDATED;
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate out:
2717c478bd9Sstevel@tonic-gate 	if (backhit != 0) {
2727c478bd9Sstevel@tonic-gate 		if (fail != 0)
2737c478bd9Sstevel@tonic-gate 			fscp->fs_stats.st_fails++;
2747c478bd9Sstevel@tonic-gate 		else
2757c478bd9Sstevel@tonic-gate 			fscp->fs_stats.st_passes++;
2767c478bd9Sstevel@tonic-gate 	}
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate #ifdef CFSDEBUG
2797c478bd9Sstevel@tonic-gate 	CFS_DEBUG(CFSDEBUG_VOPS)
2807c478bd9Sstevel@tonic-gate 		printf("c_strict_check_cached_object: EXIT expires %lx\n",
2817c478bd9Sstevel@tonic-gate 			(long)mdp->md_x_time.tv_sec);
2827c478bd9Sstevel@tonic-gate #endif
2837c478bd9Sstevel@tonic-gate 	return (error);
2847c478bd9Sstevel@tonic-gate }
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate static void
c_strict_modify_cached_object(struct fscache * fscp,struct cnode * cp,cred_t * cr)2877c478bd9Sstevel@tonic-gate c_strict_modify_cached_object(struct fscache *fscp, struct cnode *cp,
2887c478bd9Sstevel@tonic-gate 	cred_t *cr)
2897c478bd9Sstevel@tonic-gate {
2907c478bd9Sstevel@tonic-gate 	struct vattr attrs;
2917c478bd9Sstevel@tonic-gate 	int error = 0;
2927c478bd9Sstevel@tonic-gate 	nlink_t nlink;
2937c478bd9Sstevel@tonic-gate 	cachefs_metadata_t *mdp = &cp->c_metadata;
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cp->c_statelock));
2967c478bd9Sstevel@tonic-gate 	ASSERT(fscp->fs_cdconnected == CFS_CD_CONNECTED);
2977c478bd9Sstevel@tonic-gate 	ASSERT(fscp->fs_backvfsp);
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate 	/*
3007c478bd9Sstevel@tonic-gate 	 * Don't do a getattr if NFSv4, which maintains
3017c478bd9Sstevel@tonic-gate 	 * its attributes (and link count) by doing a call
3027c478bd9Sstevel@tonic-gate 	 * to CFSOP_CHECK_COBJECT() during vnode operations.
3037c478bd9Sstevel@tonic-gate 	 */
3047c478bd9Sstevel@tonic-gate 	if (CFS_ISFS_BACKFS_NFSV4(fscp))
3057c478bd9Sstevel@tonic-gate 		goto out;
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 	fscp->fs_stats.st_modifies++;
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate 	/* from now on, make sure we're using the server's idea of time */
3107c478bd9Sstevel@tonic-gate 	mdp->md_flags &= ~(MD_LOCALCTIME | MD_LOCALMTIME);
3117c478bd9Sstevel@tonic-gate 	mdp->md_flags |= MD_NEEDATTRS;
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate 	/* if in write-around mode, make sure file is nocached */
3147c478bd9Sstevel@tonic-gate 	if (CFS_ISFS_WRITE_AROUND(fscp)) {
3157c478bd9Sstevel@tonic-gate 		if ((cp->c_flags & CN_NOCACHE) == 0)
3167c478bd9Sstevel@tonic-gate 			cachefs_nocache(cp);
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate 		/*
3197c478bd9Sstevel@tonic-gate 		 * If a directory, then defer getting the new attributes
3207c478bd9Sstevel@tonic-gate 		 * until requested.  Might be a little bit faster this way.
3217c478bd9Sstevel@tonic-gate 		 */
3227c478bd9Sstevel@tonic-gate 		if (CTOV(cp)->v_type == VDIR)
3237c478bd9Sstevel@tonic-gate 			goto out;
3247c478bd9Sstevel@tonic-gate 	}
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 	/* get the new mtime so the next call to check_cobject does not fail */
3277c478bd9Sstevel@tonic-gate 	if (cp->c_backvp == NULL) {
3287c478bd9Sstevel@tonic-gate 		error = cachefs_getbackvp(fscp, cp);
3297c478bd9Sstevel@tonic-gate 		if (error) {
3307c478bd9Sstevel@tonic-gate 			mdp->md_vattr.va_mtime.tv_sec = 0;
3317c478bd9Sstevel@tonic-gate 			goto out;
3327c478bd9Sstevel@tonic-gate 		}
3337c478bd9Sstevel@tonic-gate 	}
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate 	attrs.va_mask = AT_ALL;
3367c478bd9Sstevel@tonic-gate 	ASSERT(cp->c_backvp != NULL);
337*da6c28aaSamw 	error = VOP_GETATTR(cp->c_backvp, &attrs, 0, cr, NULL);
3387c478bd9Sstevel@tonic-gate 	if (error) {
3397c478bd9Sstevel@tonic-gate 		mdp->md_vattr.va_mtime.tv_sec = 0;
3407c478bd9Sstevel@tonic-gate 		goto out;
3417c478bd9Sstevel@tonic-gate 	}
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate 	mdp->md_x_time.tv_sec =
3447c478bd9Sstevel@tonic-gate 	    cachefs_gettime_cached_object(fscp, cp, attrs.va_mtime.tv_sec);
3457c478bd9Sstevel@tonic-gate 	nlink = cp->c_attr.va_nlink;
3467c478bd9Sstevel@tonic-gate 	cp->c_attr = attrs;
3477c478bd9Sstevel@tonic-gate 	cp->c_attr.va_nlink = nlink;
3487c478bd9Sstevel@tonic-gate 	if ((attrs.va_size > cp->c_size) || !vn_has_cached_data(CTOV(cp)))
3497c478bd9Sstevel@tonic-gate 		cp->c_size = attrs.va_size;
3507c478bd9Sstevel@tonic-gate 	mdp->md_flags &= ~MD_NEEDATTRS;
3517c478bd9Sstevel@tonic-gate 	cachefs_cnode_setlocalstats(cp);
3527c478bd9Sstevel@tonic-gate out:
3537c478bd9Sstevel@tonic-gate 	cp->c_flags |= CN_UPDATED;
3547c478bd9Sstevel@tonic-gate }
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3577c478bd9Sstevel@tonic-gate static void
c_strict_invalidate_cached_object(struct fscache * fscp,struct cnode * cp,cred_t * cr)3587c478bd9Sstevel@tonic-gate c_strict_invalidate_cached_object(struct fscache *fscp, struct cnode *cp,
3597c478bd9Sstevel@tonic-gate 	cred_t *cr)
3607c478bd9Sstevel@tonic-gate {
3617c478bd9Sstevel@tonic-gate 	cachefs_metadata_t *mdp = &cp->c_metadata;
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cp->c_statelock));
3647c478bd9Sstevel@tonic-gate 	mdp->md_vattr.va_mtime.tv_sec = 0;
3657c478bd9Sstevel@tonic-gate 	mdp->md_flags |= MD_NEEDATTRS;
3667c478bd9Sstevel@tonic-gate 	cp->c_flags |= CN_UPDATED;
3677c478bd9Sstevel@tonic-gate }
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3707c478bd9Sstevel@tonic-gate static void
c_strict_convert_cached_object(struct fscache * fscp,struct cnode * cp,cred_t * cr)3717c478bd9Sstevel@tonic-gate c_strict_convert_cached_object(struct fscache *fscp, struct cnode *cp,
3727c478bd9Sstevel@tonic-gate 	cred_t *cr)
3737c478bd9Sstevel@tonic-gate {
3747c478bd9Sstevel@tonic-gate 	cachefs_metadata_t *mdp = &cp->c_metadata;
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cp->c_statelock));
3777c478bd9Sstevel@tonic-gate 	mdp->md_flags |= MD_NEEDATTRS;
3787c478bd9Sstevel@tonic-gate 	mdp->md_consttype = CFS_FS_CONST_STRICT;
3797c478bd9Sstevel@tonic-gate 	cp->c_flags |= CN_UPDATED;
3807c478bd9Sstevel@tonic-gate }
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate /*
3837c478bd9Sstevel@tonic-gate  * Returns the tod in secs when the consistency of the object should
3847c478bd9Sstevel@tonic-gate  * be checked.
3857c478bd9Sstevel@tonic-gate  */
3867c478bd9Sstevel@tonic-gate static time_t
cachefs_gettime_cached_object(struct fscache * fscp,struct cnode * cp,time_t mtime)3877c478bd9Sstevel@tonic-gate cachefs_gettime_cached_object(struct fscache *fscp, struct cnode *cp,
3887c478bd9Sstevel@tonic-gate 	time_t mtime)
3897c478bd9Sstevel@tonic-gate {
3907c478bd9Sstevel@tonic-gate 	time_t xsec;
3917c478bd9Sstevel@tonic-gate 	time_t acmin, acmax;
3927c478bd9Sstevel@tonic-gate 	time_t now;
3937c478bd9Sstevel@tonic-gate 
3947c478bd9Sstevel@tonic-gate 	/*
3957c478bd9Sstevel@tonic-gate 	 * Expire time is based on the number of seconds since the last change
3967c478bd9Sstevel@tonic-gate 	 * (i.e. files that changed recently are likely to change soon),
3977c478bd9Sstevel@tonic-gate 	 */
3987c478bd9Sstevel@tonic-gate 	if ((CTOV(cp))->v_type == VDIR) {
3997c478bd9Sstevel@tonic-gate 		acmin = fscp->fs_acdirmin;
4007c478bd9Sstevel@tonic-gate 		acmax = fscp->fs_acdirmax;
4017c478bd9Sstevel@tonic-gate 	} else {
4027c478bd9Sstevel@tonic-gate 		acmin = fscp->fs_acregmin;
4037c478bd9Sstevel@tonic-gate 		acmax = fscp->fs_acregmax;
4047c478bd9Sstevel@tonic-gate 	}
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate 	now = gethrestime_sec();
4077c478bd9Sstevel@tonic-gate 	xsec = now - mtime;
4087c478bd9Sstevel@tonic-gate 	xsec = MAX(xsec, acmin);
4097c478bd9Sstevel@tonic-gate 	xsec = MIN(xsec, acmax);
4107c478bd9Sstevel@tonic-gate 	xsec += now;
4117c478bd9Sstevel@tonic-gate 	return (xsec);
4127c478bd9Sstevel@tonic-gate }
4137c478bd9Sstevel@tonic-gate 
4147c478bd9Sstevel@tonic-gate struct cachefsops strictcfsops = {
4157c478bd9Sstevel@tonic-gate 	c_strict_init_cached_object,
4167c478bd9Sstevel@tonic-gate 	c_strict_check_cached_object,
4177c478bd9Sstevel@tonic-gate 	c_strict_modify_cached_object,
4187c478bd9Sstevel@tonic-gate 	c_strict_invalidate_cached_object,
4197c478bd9Sstevel@tonic-gate 	c_strict_convert_cached_object
4207c478bd9Sstevel@tonic-gate };
421