xref: /titanic_44/usr/src/uts/common/fs/cachefs/cachefs_log.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
5f48205beScasper  * Common Development and Distribution License (the "License").
6f48205beScasper  * 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 /*
22f48205beScasper  * 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/errno.h>
297c478bd9Sstevel@tonic-gate #include <sys/param.h>
307c478bd9Sstevel@tonic-gate #include <sys/types.h>
317c478bd9Sstevel@tonic-gate #include <sys/systm.h>
327c478bd9Sstevel@tonic-gate #include <sys/user.h>
337c478bd9Sstevel@tonic-gate #include <sys/stat.h>
347c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
357c478bd9Sstevel@tonic-gate #include <sys/time.h>
367c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
377c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
387c478bd9Sstevel@tonic-gate #include <sys/file.h>
397c478bd9Sstevel@tonic-gate #include <rpc/types.h>
407c478bd9Sstevel@tonic-gate #include <rpc/xdr.h>
417c478bd9Sstevel@tonic-gate #include <sys/mode.h>
427c478bd9Sstevel@tonic-gate #include <sys/pathname.h>
437c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
447c478bd9Sstevel@tonic-gate #include <sys/debug.h>
457c478bd9Sstevel@tonic-gate #include <sys/fs/cachefs_fs.h>
467c478bd9Sstevel@tonic-gate #include <sys/fs/cachefs_log.h>
477c478bd9Sstevel@tonic-gate #include <vm/seg.h>
487c478bd9Sstevel@tonic-gate #include <vm/seg_map.h>
497c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * ino64_t is a unsigned long on LP64 and unsigned long long on ILP32,
537c478bd9Sstevel@tonic-gate  * the compiler emits many warnings when calling xdr_u_longlong_t with an
547c478bd9Sstevel@tonic-gate  * unsigned long pointer on LP64 even though it's safe.
557c478bd9Sstevel@tonic-gate  */
567c478bd9Sstevel@tonic-gate #define	xdr_ino64(xdrs, p)	xdr_u_longlong_t((xdrs), (u_longlong_t *)(p))
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate /*
597c478bd9Sstevel@tonic-gate  * cfs_time_t is an int in both LP64 and ILP32. To avoid compiler warnings
60*da6c28aaSamw  * define its xdr here explicitly
617c478bd9Sstevel@tonic-gate  */
627c478bd9Sstevel@tonic-gate #define	xdr_cfs_time_t(xdrs, p)	xdr_int((xdrs), (int *)(p))
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate #define	CACHEFS_LOG_MAX_BUFFERED	65536
657c478bd9Sstevel@tonic-gate #define	CACHEFS_LOG_LOWATER		 8192
667c478bd9Sstevel@tonic-gate #define	CACHEFS_LOG_ENCODE_SIZE		 4096
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate #if (defined(_SYSCALL32_IMPL) || defined(_LP64))
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate #define	OUT_IF_TIME_OVERFLOW(cachep, time)				\
717c478bd9Sstevel@tonic-gate 	if (TIME_OVERFLOW(time)) {					\
727c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, EOVERFLOW, 1);		\
737c478bd9Sstevel@tonic-gate 		goto out;						\
747c478bd9Sstevel@tonic-gate 	}
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #define	RET_IF_TIME_OVERFLOW(cachep, time)				\
777c478bd9Sstevel@tonic-gate 	if (TIME_OVERFLOW(time)) {					\
787c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, EOVERFLOW, 1);		\
797c478bd9Sstevel@tonic-gate 		return;							\
807c478bd9Sstevel@tonic-gate 	}
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate #else /* not (_SYSCALL32_IMPL || _LP64) */
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate #define	OUT_IF_TIME_OVERFLOW(cachep, time)
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate #define	RET_IF_TIME_OVERFLOW(cachep, time)
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate #endif /* (_SYSCALL32_IMPL || _LP64) */
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate typedef struct cachefs_log_work_list {
917c478bd9Sstevel@tonic-gate 	void *data;
927c478bd9Sstevel@tonic-gate 	size_t size;
937c478bd9Sstevel@tonic-gate 	xdrproc_t translate;
947c478bd9Sstevel@tonic-gate 	struct cachefs_log_work_list *next;
957c478bd9Sstevel@tonic-gate } *cachefs_log_work_list_t;
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate /* forward declarations of static functions */
987c478bd9Sstevel@tonic-gate static void cachefs_log_enqueue(cachefscache_t *, void *, int, xdrproc_t);
997c478bd9Sstevel@tonic-gate static int cachefs_log_save_lc(cachefscache_t *);
1007c478bd9Sstevel@tonic-gate static int cachefs_log_write_header(struct vnode *, cachefscache_t *, int);
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_logfile_header(XDR *,
1037c478bd9Sstevel@tonic-gate     struct cachefs_log_logfile_header *);
1047c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_mount(XDR *, struct cachefs_log_mount_record *);
1057c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_umount(XDR *, struct cachefs_log_umount_record *);
1067c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_getpage(XDR *, struct cachefs_log_getpage_record *);
1077c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_readdir(XDR *, struct cachefs_log_readdir_record *);
1087c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_readlink(XDR *,
1097c478bd9Sstevel@tonic-gate     struct cachefs_log_readlink_record *);
1107c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_remove(XDR *, struct cachefs_log_remove_record *);
1117c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_rmdir(XDR *, struct cachefs_log_rmdir_record *);
1127c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_truncate(XDR *,
1137c478bd9Sstevel@tonic-gate     struct cachefs_log_truncate_record *);
1147c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_putpage(XDR *, struct cachefs_log_putpage_record *);
1157c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_create(XDR *, struct cachefs_log_create_record *);
1167c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_mkdir(XDR *, struct cachefs_log_mkdir_record *);
1177c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_rename(XDR *, struct cachefs_log_rename_record *);
1187c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_symlink(XDR *, struct cachefs_log_symlink_record *);
1197c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_populate(XDR *,
1207c478bd9Sstevel@tonic-gate     struct cachefs_log_populate_record *);
1217c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_csymlink(XDR *,
1227c478bd9Sstevel@tonic-gate     struct cachefs_log_csymlink_record *);
1237c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_filldir(XDR *,
1247c478bd9Sstevel@tonic-gate     struct cachefs_log_filldir_record *);
1257c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_mdcreate(XDR *,
1267c478bd9Sstevel@tonic-gate     struct cachefs_log_mdcreate_record *);
1277c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_gpfront(XDR *,
1287c478bd9Sstevel@tonic-gate     struct cachefs_log_gpfront_record *);
1297c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_rfdir(XDR *,
1307c478bd9Sstevel@tonic-gate     struct cachefs_log_rfdir_record *);
1317c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_ualloc(XDR *,
1327c478bd9Sstevel@tonic-gate     struct cachefs_log_ualloc_record *);
1337c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_calloc(XDR *,
1347c478bd9Sstevel@tonic-gate     struct cachefs_log_calloc_record *);
1357c478bd9Sstevel@tonic-gate static bool_t cachefs_xdr_nocache(XDR *,
1367c478bd9Sstevel@tonic-gate     struct cachefs_log_nocache_record *);
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate extern time_t time;
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate /*
1427c478bd9Sstevel@tonic-gate  * cachefs_log_kstat_snapshot(kstat_t *ksp, void *buf, int rw)
1437c478bd9Sstevel@tonic-gate  *
1447c478bd9Sstevel@tonic-gate  * called from /dev/kstat or somesuch.
1457c478bd9Sstevel@tonic-gate  *
1467c478bd9Sstevel@tonic-gate  */
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate int
cachefs_log_kstat_snapshot(kstat_t * ksp,void * buf,int rw)1497c478bd9Sstevel@tonic-gate cachefs_log_kstat_snapshot(kstat_t *ksp, void *buf, int rw)
1507c478bd9Sstevel@tonic-gate {
1517c478bd9Sstevel@tonic-gate 	cachefs_log_control_t *lc = (cachefs_log_control_t *)ksp->ks_data;
1527c478bd9Sstevel@tonic-gate 	cachefs_log_control_t *buflc = (cachefs_log_control_t *)buf;
1537c478bd9Sstevel@tonic-gate 	cachefscache_t *cachep = (cachefscache_t *)(uintptr_t)lc->lc_cachep;
1547c478bd9Sstevel@tonic-gate 	cachefs_log_cookie_t *cl = cachep->c_log;
1557c478bd9Sstevel@tonic-gate 	int error = 0;
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cachep->c_log_mutex));
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	/* if they just want to read the kstat, get that out of the way. */
1607c478bd9Sstevel@tonic-gate 	if (rw != KSTAT_WRITE) {
1617c478bd9Sstevel@tonic-gate 		bcopy(lc, buflc, sizeof (*lc));
1627c478bd9Sstevel@tonic-gate 		return (0);
1637c478bd9Sstevel@tonic-gate 	}
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 	/* make sure they're passing us a valid control cookie */
1667c478bd9Sstevel@tonic-gate 	if ((buflc->lc_cachep != lc->lc_cachep) ||
1677c478bd9Sstevel@tonic-gate 	    (buflc->lc_magic != CACHEFS_LOG_MAGIC))
1687c478bd9Sstevel@tonic-gate 		return (EIO);
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	/*
1717c478bd9Sstevel@tonic-gate 	 * if logging is currently off
1727c478bd9Sstevel@tonic-gate 	 *   o insist that we're being handed a logfile path
1737c478bd9Sstevel@tonic-gate 	 *   o set cl, and give our cachep its value
1747c478bd9Sstevel@tonic-gate 	 *
1757c478bd9Sstevel@tonic-gate 	 * after that, if something goes wrong, we must call
1767c478bd9Sstevel@tonic-gate 	 * cachefs_log_error to clear cachep->c_log.
1777c478bd9Sstevel@tonic-gate 	 */
1787c478bd9Sstevel@tonic-gate 	if (cl == NULL) {
1797c478bd9Sstevel@tonic-gate 		if (buflc->lc_path[0] == '\0')
1807c478bd9Sstevel@tonic-gate 			return (EIO);
1817c478bd9Sstevel@tonic-gate 		cl = cachep->c_log = cachefs_log_create_cookie(lc);
1827c478bd9Sstevel@tonic-gate 		if (cl == NULL) {
1837c478bd9Sstevel@tonic-gate 			cachefs_log_error(cachep, ENOMEM, 0);
1847c478bd9Sstevel@tonic-gate 			return (EIO);
1857c478bd9Sstevel@tonic-gate 		}
1867c478bd9Sstevel@tonic-gate 	}
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate 	/*
1897c478bd9Sstevel@tonic-gate 	 * if we're being handed an empty logpath, then they must be
1907c478bd9Sstevel@tonic-gate 	 * turning off logging; also, logging must have been turned on
1917c478bd9Sstevel@tonic-gate 	 * before, or else the previous paragraph would have caught
1927c478bd9Sstevel@tonic-gate 	 * it.
1937c478bd9Sstevel@tonic-gate 	 */
1947c478bd9Sstevel@tonic-gate 	if (buflc->lc_path[0] == '\0') {
1957c478bd9Sstevel@tonic-gate 		cachefs_log_process_queue(cachep, 0);
1967c478bd9Sstevel@tonic-gate 		cachep->c_log = NULL;
1977c478bd9Sstevel@tonic-gate 		cachefs_log_destroy_cookie(cl);
1987c478bd9Sstevel@tonic-gate 		bzero(lc, sizeof (*lc));
1997c478bd9Sstevel@tonic-gate 		lc->lc_magic = CACHEFS_LOG_MAGIC;
2007c478bd9Sstevel@tonic-gate 		lc->lc_cachep = (uint64_t)(uintptr_t)cachep;
201*da6c28aaSamw 		(void) VOP_REMOVE(cachep->c_dirvp, LOG_STATUS_NAME, kcred, NULL,
202*da6c28aaSamw 		    0);
2037c478bd9Sstevel@tonic-gate 		return (0);
2047c478bd9Sstevel@tonic-gate 	}
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 	/*
2077c478bd9Sstevel@tonic-gate 	 * if we get here, we know that we're being handed a valid log
2087c478bd9Sstevel@tonic-gate 	 * control cookie, and that a path is set.  try to open the
2097c478bd9Sstevel@tonic-gate 	 * log file, even if it's the same path, because they might
2107c478bd9Sstevel@tonic-gate 	 * have removed the old log file out from under us.  if it
2117c478bd9Sstevel@tonic-gate 	 * really is the same file, no harm done.
2127c478bd9Sstevel@tonic-gate 	 */
2137c478bd9Sstevel@tonic-gate 	if ((error = cachefs_log_logfile_open(cachep, buflc->lc_path)) != 0) {
2147c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, error, 0);
2157c478bd9Sstevel@tonic-gate 		return (EIO);
2167c478bd9Sstevel@tonic-gate 	}
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	/*
2197c478bd9Sstevel@tonic-gate 	 * if we get here, we have a valid logfile open.  we don't do
2207c478bd9Sstevel@tonic-gate 	 * anything here with the bitmap of what's being logged, other
2217c478bd9Sstevel@tonic-gate 	 * than copy it.  we're home free!
2227c478bd9Sstevel@tonic-gate 	 */
2237c478bd9Sstevel@tonic-gate 	bcopy(buflc, lc, sizeof (*lc));
2247c478bd9Sstevel@tonic-gate 	if ((error = cachefs_log_save_lc(cachep)) != 0) {
2257c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, error, 0);
2267c478bd9Sstevel@tonic-gate 		return (EIO);
2277c478bd9Sstevel@tonic-gate 	}
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	return (0);
2307c478bd9Sstevel@tonic-gate }
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate static int
cachefs_log_save_lc(cachefscache_t * cachep)2337c478bd9Sstevel@tonic-gate cachefs_log_save_lc(cachefscache_t *cachep)
2347c478bd9Sstevel@tonic-gate {
2357c478bd9Sstevel@tonic-gate 	cachefs_log_control_t *lc = (cachefs_log_control_t *)cachep->c_log_ctl;
2367c478bd9Sstevel@tonic-gate 	struct vnode *savevp;
2377c478bd9Sstevel@tonic-gate 	struct vattr attr;
2387c478bd9Sstevel@tonic-gate 	int error = 0;
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate 	if (lc == NULL)
2417c478bd9Sstevel@tonic-gate 		return (EINVAL);
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate 	attr.va_mode = S_IFREG | 0666;
2447c478bd9Sstevel@tonic-gate 	attr.va_uid = 0;
2457c478bd9Sstevel@tonic-gate 	attr.va_gid = 0;
2467c478bd9Sstevel@tonic-gate 	attr.va_type = VREG;
2477c478bd9Sstevel@tonic-gate 	attr.va_mask = AT_TYPE | AT_MODE | AT_UID | AT_GID;
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 	if (((error = VOP_LOOKUP(cachep->c_dirvp, LOG_STATUS_NAME, &savevp,
250*da6c28aaSamw 	    NULL, 0, NULL, kcred, NULL, NULL, NULL)) != 0) &&
2517c478bd9Sstevel@tonic-gate 	    ((error = VOP_CREATE(cachep->c_dirvp, LOG_STATUS_NAME, &attr, EXCL,
252*da6c28aaSamw 	    0600, &savevp, kcred, 0, NULL, NULL)) != 0))
2537c478bd9Sstevel@tonic-gate 		return (error);
2547c478bd9Sstevel@tonic-gate 	ASSERT(savevp != NULL);
2557c478bd9Sstevel@tonic-gate 	if (savevp == NULL)
2567c478bd9Sstevel@tonic-gate 		return (ENOENT);
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate 	error = vn_rdwr(UIO_WRITE, savevp,
2597c478bd9Sstevel@tonic-gate 	    (caddr_t)lc, sizeof (*lc),
2607c478bd9Sstevel@tonic-gate 	    0LL, UIO_SYSSPACE, FSYNC, (rlim64_t)RLIM_INFINITY, kcred, NULL);
2617c478bd9Sstevel@tonic-gate 
2627c478bd9Sstevel@tonic-gate 	VN_RELE(savevp);
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 	return (error);
2657c478bd9Sstevel@tonic-gate }
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate /*
2687c478bd9Sstevel@tonic-gate  * cachefs_log_cookie_t *cachefs_log_create_cookie(void *)
2697c478bd9Sstevel@tonic-gate  *
2707c478bd9Sstevel@tonic-gate  * creates and initializes the cookie, which lives in cachep.  called
2717c478bd9Sstevel@tonic-gate  * from either a kstat write which turns on logging, or from
2727c478bd9Sstevel@tonic-gate  * initializing cachep when a log-info-file exists.
2737c478bd9Sstevel@tonic-gate  */
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate cachefs_log_cookie_t *
cachefs_log_create_cookie(cachefs_log_control_t * lc)2767c478bd9Sstevel@tonic-gate cachefs_log_create_cookie(cachefs_log_control_t *lc)
2777c478bd9Sstevel@tonic-gate {
2787c478bd9Sstevel@tonic-gate 	cachefs_log_cookie_t *rc;
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 	rc = cachefs_kmem_zalloc(sizeof (*rc), KM_NOSLEEP);
2817c478bd9Sstevel@tonic-gate 	if (rc == NULL)
2827c478bd9Sstevel@tonic-gate 		return (NULL);
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 	rc->cl_magic = CACHEFS_LOG_MAGIC;
2857c478bd9Sstevel@tonic-gate 	rc->cl_logctl = lc;
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate 	return (rc);
2887c478bd9Sstevel@tonic-gate }
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate /*
2917c478bd9Sstevel@tonic-gate  * void cachefs_log_destroy_cookie(cachefs_log_cookie_t *)
2927c478bd9Sstevel@tonic-gate  *
2937c478bd9Sstevel@tonic-gate  * destroys the log cookie.  called from cachefs_log_error, or from
2947c478bd9Sstevel@tonic-gate  * destroying the cachep.
2957c478bd9Sstevel@tonic-gate  *
2967c478bd9Sstevel@tonic-gate  */
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate void
cachefs_log_destroy_cookie(cachefs_log_cookie_t * cl)2997c478bd9Sstevel@tonic-gate cachefs_log_destroy_cookie(cachefs_log_cookie_t *cl)
3007c478bd9Sstevel@tonic-gate {
3017c478bd9Sstevel@tonic-gate 	cachefs_log_work_list_t node, oldnode;
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate 	if (cl == NULL)
3047c478bd9Sstevel@tonic-gate 		return;
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate 	ASSERT(cl->cl_magic == CACHEFS_LOG_MAGIC);
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate 	cl->cl_magic++;
3097c478bd9Sstevel@tonic-gate 	node = cl->cl_head;
3107c478bd9Sstevel@tonic-gate 	while (node != NULL) {
3117c478bd9Sstevel@tonic-gate 		cachefs_kmem_free(node->data, node->size);
3127c478bd9Sstevel@tonic-gate 		oldnode = node;
3137c478bd9Sstevel@tonic-gate 		node = node->next;
3147c478bd9Sstevel@tonic-gate 		cachefs_kmem_free(oldnode, sizeof (*oldnode));
3157c478bd9Sstevel@tonic-gate 	}
3167c478bd9Sstevel@tonic-gate 	if (cl->cl_logvp != NULL)
3177c478bd9Sstevel@tonic-gate 		VN_RELE(cl->cl_logvp);
3187c478bd9Sstevel@tonic-gate 	cachefs_kmem_free(cl, sizeof (*cl));
3197c478bd9Sstevel@tonic-gate }
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate /*
3227c478bd9Sstevel@tonic-gate  * int cachefs_log_logfile_open(cachefscache_t *, char *)
3237c478bd9Sstevel@tonic-gate  *
3247c478bd9Sstevel@tonic-gate  * opens the logfile, and stores the path string if its successful.
3257c478bd9Sstevel@tonic-gate  *
326*da6c28aaSamw  * returns an errno if one occurred.
3277c478bd9Sstevel@tonic-gate  *
3287c478bd9Sstevel@tonic-gate  */
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate int
cachefs_log_logfile_open(cachefscache_t * cachep,char * path)3317c478bd9Sstevel@tonic-gate cachefs_log_logfile_open(cachefscache_t *cachep, char *path)
3327c478bd9Sstevel@tonic-gate {
3337c478bd9Sstevel@tonic-gate 	cachefs_log_cookie_t *cl = cachep->c_log;
3347c478bd9Sstevel@tonic-gate 	struct vnode *newvp = NULL;
3357c478bd9Sstevel@tonic-gate 	int error = 0;
3367c478bd9Sstevel@tonic-gate 	int i;
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&cachep->c_log_mutex));
3397c478bd9Sstevel@tonic-gate 	ASSERT(cl != NULL);
3407c478bd9Sstevel@tonic-gate 	ASSERT(cl->cl_magic == CACHEFS_LOG_MAGIC);
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate 	/* lookup the pathname -- it must already exist! */
3437c478bd9Sstevel@tonic-gate 	error = lookupname(path, UIO_SYSSPACE, FOLLOW, NULL, &newvp);
3447c478bd9Sstevel@tonic-gate 	if (error)
3457c478bd9Sstevel@tonic-gate 		goto out;
3467c478bd9Sstevel@tonic-gate 	ASSERT(newvp != NULL);
3477c478bd9Sstevel@tonic-gate 	if (newvp == NULL) {
3487c478bd9Sstevel@tonic-gate 		error = ENOENT; /* XXX this shouldn't happen (yeah right) */
3497c478bd9Sstevel@tonic-gate 		goto out;
3507c478bd9Sstevel@tonic-gate 	}
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 	/* easy out if we just re-opened the same logfile */
3537c478bd9Sstevel@tonic-gate 	if (cl->cl_logvp == newvp) {
3547c478bd9Sstevel@tonic-gate 		VN_RELE(newvp);
3557c478bd9Sstevel@tonic-gate 		goto out;
3567c478bd9Sstevel@tonic-gate 	}
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate 	/* XXX we may change this to allow named pipes */
3597c478bd9Sstevel@tonic-gate 	if (newvp->v_type != VREG) {
3607c478bd9Sstevel@tonic-gate 		error = EINVAL;
3617c478bd9Sstevel@tonic-gate 		goto out;
3627c478bd9Sstevel@tonic-gate 	}
3637c478bd9Sstevel@tonic-gate 	if (vn_matchops(newvp, cachefs_getvnodeops())) {
3647c478bd9Sstevel@tonic-gate 		error = EINVAL;
3657c478bd9Sstevel@tonic-gate 		goto out;
3667c478bd9Sstevel@tonic-gate 	}
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate 	/* write out the header */
3697c478bd9Sstevel@tonic-gate 	error = cachefs_log_write_header(newvp, cachep, 0);
3707c478bd9Sstevel@tonic-gate 	if (error)
3717c478bd9Sstevel@tonic-gate 		goto out;
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate 	/* if we get here, we successfully opened the log. */
3747c478bd9Sstevel@tonic-gate 	if (cl->cl_logvp != NULL)
3757c478bd9Sstevel@tonic-gate 		VN_RELE(cl->cl_logvp);
3767c478bd9Sstevel@tonic-gate 	cl->cl_logvp = newvp;
3777c478bd9Sstevel@tonic-gate 
3787c478bd9Sstevel@tonic-gate 	/*
3797c478bd9Sstevel@tonic-gate 	 * `fake' a mount entry for each mounted cachefs filesystem.
3807c478bd9Sstevel@tonic-gate 	 * this is overkill, but it's easiest and most foolproof way
3817c478bd9Sstevel@tonic-gate 	 * to do things here.  the user-level consumers of the logfile
3827c478bd9Sstevel@tonic-gate 	 * have to expect extraneous mount entries and deal with it
3837c478bd9Sstevel@tonic-gate 	 * correctly.
3847c478bd9Sstevel@tonic-gate 	 */
3857c478bd9Sstevel@tonic-gate 	mutex_exit(&cachep->c_log_mutex);
3867c478bd9Sstevel@tonic-gate 	for (i = 0; i < cachefs_kstat_key_n; i++) {
3877c478bd9Sstevel@tonic-gate 		cachefs_kstat_key_t *k;
3887c478bd9Sstevel@tonic-gate 		struct vfs *vfsp;
3897c478bd9Sstevel@tonic-gate 		struct fscache *fscp;
3907c478bd9Sstevel@tonic-gate 
3917c478bd9Sstevel@tonic-gate 		k = cachefs_kstat_key + i;
3927c478bd9Sstevel@tonic-gate 		if (! k->ks_mounted)
3937c478bd9Sstevel@tonic-gate 			continue;
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate 		vfsp = (struct vfs *)(uintptr_t)k->ks_vfsp;
3967c478bd9Sstevel@tonic-gate 		fscp = VFS_TO_FSCACHE(vfsp);
3977c478bd9Sstevel@tonic-gate 		cachefs_log_mount(cachep, 0, vfsp, fscp,
3987c478bd9Sstevel@tonic-gate 		    (char *)(uintptr_t)k->ks_mountpoint, UIO_SYSSPACE,
3997c478bd9Sstevel@tonic-gate 		    (char *)(uintptr_t)k->ks_cacheid);
4007c478bd9Sstevel@tonic-gate 	}
4017c478bd9Sstevel@tonic-gate 	mutex_enter(&cachep->c_log_mutex);
4027c478bd9Sstevel@tonic-gate 
4037c478bd9Sstevel@tonic-gate out:
4047c478bd9Sstevel@tonic-gate 	if ((error != 0) && (newvp != NULL))
4057c478bd9Sstevel@tonic-gate 		VN_RELE(newvp);
4067c478bd9Sstevel@tonic-gate 	return (error);
4077c478bd9Sstevel@tonic-gate }
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate /*
410*da6c28aaSamw  * called when an error occurred during logging.  send the error to
4117c478bd9Sstevel@tonic-gate  * syslog, invalidate the logfile, and stop logging.
4127c478bd9Sstevel@tonic-gate  */
4137c478bd9Sstevel@tonic-gate 
4147c478bd9Sstevel@tonic-gate void
cachefs_log_error(cachefscache_t * cachep,int error,int getlock)4157c478bd9Sstevel@tonic-gate cachefs_log_error(cachefscache_t *cachep, int error, int getlock)
4167c478bd9Sstevel@tonic-gate {
4177c478bd9Sstevel@tonic-gate 	cachefs_log_cookie_t *cl = cachep->c_log;
4187c478bd9Sstevel@tonic-gate 	cachefs_log_control_t *lc = cachep->c_log_ctl;
4197c478bd9Sstevel@tonic-gate 	int writable = 0;
4207c478bd9Sstevel@tonic-gate 
4217c478bd9Sstevel@tonic-gate 	ASSERT((getlock) || (MUTEX_HELD(&cachep->c_log_mutex)));
4227c478bd9Sstevel@tonic-gate 
4237c478bd9Sstevel@tonic-gate 	if (getlock)
4247c478bd9Sstevel@tonic-gate 		mutex_enter(&cachep->c_log_mutex);
4257c478bd9Sstevel@tonic-gate 
4267c478bd9Sstevel@tonic-gate 	if ((cachep->c_flags & (CACHE_NOCACHE | CACHE_NOFILL)) == 0)
4277c478bd9Sstevel@tonic-gate 		writable = 1;
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate 	cmn_err(CE_WARN, "cachefs logging: error %d\n", error);
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate 	if ((writable) && (cl != NULL) && (cl->cl_logvp != NULL))
4327c478bd9Sstevel@tonic-gate 		(void) cachefs_log_write_header(cl->cl_logvp, cachep, error);
4337c478bd9Sstevel@tonic-gate 
4347c478bd9Sstevel@tonic-gate 	cachep->c_log = NULL;
4357c478bd9Sstevel@tonic-gate 	if (cl != NULL)
4367c478bd9Sstevel@tonic-gate 		cachefs_log_destroy_cookie(cl);
4377c478bd9Sstevel@tonic-gate 	bzero(lc, sizeof (cachefs_log_control_t));
4387c478bd9Sstevel@tonic-gate 	lc->lc_magic = CACHEFS_LOG_MAGIC;
4397c478bd9Sstevel@tonic-gate 	lc->lc_cachep = (uint64_t)(uintptr_t)cachep;
4407c478bd9Sstevel@tonic-gate 	if (writable)
441*da6c28aaSamw 		(void) VOP_REMOVE(cachep->c_dirvp, LOG_STATUS_NAME, kcred, NULL,
442*da6c28aaSamw 		    0);
4437c478bd9Sstevel@tonic-gate 
4447c478bd9Sstevel@tonic-gate 	if (getlock)
4457c478bd9Sstevel@tonic-gate 		mutex_exit(&cachep->c_log_mutex);
4467c478bd9Sstevel@tonic-gate }
4477c478bd9Sstevel@tonic-gate 
4487c478bd9Sstevel@tonic-gate static int
cachefs_log_write_header(struct vnode * vp,cachefscache_t * cachep,int error)4497c478bd9Sstevel@tonic-gate cachefs_log_write_header(struct vnode *vp, cachefscache_t *cachep, int error)
4507c478bd9Sstevel@tonic-gate {
4517c478bd9Sstevel@tonic-gate 	struct cachefs_log_logfile_header header, oheader;
4527c478bd9Sstevel@tonic-gate 	char buffy[2 * sizeof (header)];
4537c478bd9Sstevel@tonic-gate 	int Errno = 0;
4547c478bd9Sstevel@tonic-gate 	struct vattr attr;
4557c478bd9Sstevel@tonic-gate 	int gotold = 0;
4567c478bd9Sstevel@tonic-gate 	XDR xdrm;
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate 	attr.va_mask = AT_SIZE;
459*da6c28aaSamw 	if ((error = VOP_GETATTR(vp, &attr, 0, kcred, NULL)) != 0)
4607c478bd9Sstevel@tonic-gate 		goto out;
4617c478bd9Sstevel@tonic-gate 	if (attr.va_size != 0) {
4627c478bd9Sstevel@tonic-gate 		error = vn_rdwr(UIO_READ, vp, buffy,
4637c478bd9Sstevel@tonic-gate 		    MIN(sizeof (buffy), attr.va_size),
4647c478bd9Sstevel@tonic-gate 		    0LL, UIO_SYSSPACE, 0, (rlim64_t)RLIM_INFINITY, kcred, NULL);
4657c478bd9Sstevel@tonic-gate 		if (error != 0)
4667c478bd9Sstevel@tonic-gate 			goto out;
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate 		xdrm.x_ops = NULL;
4697c478bd9Sstevel@tonic-gate 		xdrmem_create(&xdrm, buffy, sizeof (buffy), XDR_DECODE);
4707c478bd9Sstevel@tonic-gate 		if ((xdrm.x_ops == NULL) ||
4717c478bd9Sstevel@tonic-gate 		    (! cachefs_xdr_logfile_header(&xdrm, &oheader))) {
4727c478bd9Sstevel@tonic-gate 			if (xdrm.x_ops != NULL)
4737c478bd9Sstevel@tonic-gate 				xdr_destroy(&xdrm);
4747c478bd9Sstevel@tonic-gate 			error = EINVAL;
4757c478bd9Sstevel@tonic-gate 			goto out;
4767c478bd9Sstevel@tonic-gate 		}
4777c478bd9Sstevel@tonic-gate 		xdr_destroy(&xdrm);
4787c478bd9Sstevel@tonic-gate 		gotold = 1;
4797c478bd9Sstevel@tonic-gate 
4807c478bd9Sstevel@tonic-gate 		if (oheader.lh_magic != CACHEFS_LOG_MAGIC) {
4817c478bd9Sstevel@tonic-gate 			error = EINVAL;
4827c478bd9Sstevel@tonic-gate 			goto out;
4837c478bd9Sstevel@tonic-gate 		}
4847c478bd9Sstevel@tonic-gate 	}
4857c478bd9Sstevel@tonic-gate 
4867c478bd9Sstevel@tonic-gate 	xdrm.x_ops = NULL;
4877c478bd9Sstevel@tonic-gate 
4887c478bd9Sstevel@tonic-gate 	xdrmem_create(&xdrm, buffy, sizeof (buffy), XDR_ENCODE);
4897c478bd9Sstevel@tonic-gate 
4907c478bd9Sstevel@tonic-gate 	if (gotold) {
4917c478bd9Sstevel@tonic-gate 		header = oheader;
4927c478bd9Sstevel@tonic-gate 	} else {
4937c478bd9Sstevel@tonic-gate 		header.lh_magic = CACHEFS_LOG_MAGIC;
4947c478bd9Sstevel@tonic-gate 		header.lh_revision = CACHEFS_LOG_FILE_REV;
4957c478bd9Sstevel@tonic-gate 		header.lh_blocks = cachep->c_usage.cu_blksused;
4967c478bd9Sstevel@tonic-gate 		header.lh_files = cachep->c_usage.cu_filesused;
4977c478bd9Sstevel@tonic-gate 		header.lh_maxbsize = MAXBSIZE;
4987c478bd9Sstevel@tonic-gate 		header.lh_pagesize = PAGESIZE;
4997c478bd9Sstevel@tonic-gate 	}
5007c478bd9Sstevel@tonic-gate 
5017c478bd9Sstevel@tonic-gate 	/* these are things that we stomp over for every header write */
5027c478bd9Sstevel@tonic-gate 	header.lh_errno = Errno;
5037c478bd9Sstevel@tonic-gate 
5047c478bd9Sstevel@tonic-gate 	if (! cachefs_xdr_logfile_header(&xdrm, &header)) {
5057c478bd9Sstevel@tonic-gate 		error = ENOMEM;
5067c478bd9Sstevel@tonic-gate 		goto out;
5077c478bd9Sstevel@tonic-gate 	}
5087c478bd9Sstevel@tonic-gate 
5097c478bd9Sstevel@tonic-gate 	error = vn_rdwr(UIO_WRITE, vp,
5107c478bd9Sstevel@tonic-gate 	    (caddr_t)buffy, xdr_getpos(&xdrm),
5117c478bd9Sstevel@tonic-gate 	    0LL, UIO_SYSSPACE, FSYNC, (rlim64_t)RLIM_INFINITY, kcred, NULL);
5127c478bd9Sstevel@tonic-gate 	if (error)
5137c478bd9Sstevel@tonic-gate 		goto out;
5147c478bd9Sstevel@tonic-gate 
5157c478bd9Sstevel@tonic-gate out:
5167c478bd9Sstevel@tonic-gate 	if (xdrm.x_ops != NULL)
5177c478bd9Sstevel@tonic-gate 		xdr_destroy(&xdrm);
5187c478bd9Sstevel@tonic-gate 	return (error);
5197c478bd9Sstevel@tonic-gate }
5207c478bd9Sstevel@tonic-gate 
5217c478bd9Sstevel@tonic-gate /*
5227c478bd9Sstevel@tonic-gate  * enqueues a record to be written to the logfile.
5237c478bd9Sstevel@tonic-gate  */
5247c478bd9Sstevel@tonic-gate 
5257c478bd9Sstevel@tonic-gate static void
cachefs_log_enqueue(cachefscache_t * cachep,void * record,int size,xdrproc_t translate)5267c478bd9Sstevel@tonic-gate cachefs_log_enqueue(cachefscache_t *cachep, void *record, int size,
5277c478bd9Sstevel@tonic-gate     xdrproc_t translate)
5287c478bd9Sstevel@tonic-gate {
5297c478bd9Sstevel@tonic-gate 	cachefs_log_cookie_t *cl;
5307c478bd9Sstevel@tonic-gate 	cachefs_log_work_list_t newnode, oldnode;
5317c478bd9Sstevel@tonic-gate 
5327c478bd9Sstevel@tonic-gate 	mutex_enter(&cachep->c_log_mutex);
5337c478bd9Sstevel@tonic-gate 	cl = cachep->c_log;
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate 	if (cl == NULL) { /* someone turned off logging out from under us */
5367c478bd9Sstevel@tonic-gate 		mutex_exit(&cachep->c_log_mutex);
5377c478bd9Sstevel@tonic-gate 		cachefs_kmem_free(record, size);
5387c478bd9Sstevel@tonic-gate 		return;
5397c478bd9Sstevel@tonic-gate 	}
5407c478bd9Sstevel@tonic-gate 	ASSERT(cl->cl_magic == CACHEFS_LOG_MAGIC);
5417c478bd9Sstevel@tonic-gate 
5427c478bd9Sstevel@tonic-gate 	cl->cl_size += size;
5437c478bd9Sstevel@tonic-gate 	newnode = cachefs_kmem_zalloc(sizeof (*newnode), KM_NOSLEEP);
5447c478bd9Sstevel@tonic-gate 	if ((cl->cl_size > CACHEFS_LOG_MAX_BUFFERED) || (newnode == NULL)) {
5457c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 0);
5467c478bd9Sstevel@tonic-gate 		if (newnode != NULL)
5477c478bd9Sstevel@tonic-gate 			cachefs_kmem_free(newnode, sizeof (*newnode));
5487c478bd9Sstevel@tonic-gate 		cachefs_kmem_free(record, size);
5497c478bd9Sstevel@tonic-gate 		mutex_exit(&cachep->c_log_mutex);
5507c478bd9Sstevel@tonic-gate 		return;
5517c478bd9Sstevel@tonic-gate 	}
5527c478bd9Sstevel@tonic-gate 
5537c478bd9Sstevel@tonic-gate 	newnode->data = record;
5547c478bd9Sstevel@tonic-gate 	newnode->size = size;
5557c478bd9Sstevel@tonic-gate 	newnode->translate = translate;
5567c478bd9Sstevel@tonic-gate 	newnode->next = NULL;
5577c478bd9Sstevel@tonic-gate 
5587c478bd9Sstevel@tonic-gate 	oldnode = (cachefs_log_work_list_t)cl->cl_tail;
5597c478bd9Sstevel@tonic-gate 	if (oldnode != NULL)
5607c478bd9Sstevel@tonic-gate 		oldnode->next = newnode;
5617c478bd9Sstevel@tonic-gate 	cl->cl_tail = newnode;
5627c478bd9Sstevel@tonic-gate 	if (cl->cl_head == NULL)
5637c478bd9Sstevel@tonic-gate 		cl->cl_head = newnode;
5647c478bd9Sstevel@tonic-gate 	mutex_exit(&cachep->c_log_mutex);
5657c478bd9Sstevel@tonic-gate 
5667c478bd9Sstevel@tonic-gate 	if (cl->cl_size >= CACHEFS_LOG_LOWATER) {
5677c478bd9Sstevel@tonic-gate 		mutex_enter(&cachep->c_workq.wq_queue_lock);
5687c478bd9Sstevel@tonic-gate 		cachep->c_workq.wq_logwork = 1;
5697c478bd9Sstevel@tonic-gate 		cv_signal(&cachep->c_workq.wq_req_cv);
5707c478bd9Sstevel@tonic-gate 		mutex_exit(&cachep->c_workq.wq_queue_lock);
5717c478bd9Sstevel@tonic-gate 	}
5727c478bd9Sstevel@tonic-gate }
5737c478bd9Sstevel@tonic-gate 
5747c478bd9Sstevel@tonic-gate /*
5757c478bd9Sstevel@tonic-gate  * processes the log queue.  run by an async worker thread, or via
5767c478bd9Sstevel@tonic-gate  * cachefs_cache_sync().
5777c478bd9Sstevel@tonic-gate  */
5787c478bd9Sstevel@tonic-gate 
5797c478bd9Sstevel@tonic-gate void
cachefs_log_process_queue(cachefscache_t * cachep,int getlock)5807c478bd9Sstevel@tonic-gate cachefs_log_process_queue(cachefscache_t *cachep, int getlock)
5817c478bd9Sstevel@tonic-gate {
5827c478bd9Sstevel@tonic-gate 	cachefs_log_cookie_t *cl;
5837c478bd9Sstevel@tonic-gate 	cachefs_log_work_list_t work, workhead, oldwork;
5847c478bd9Sstevel@tonic-gate 	struct vnode *logvp = NULL;
5857c478bd9Sstevel@tonic-gate 	struct uio uio;
5867c478bd9Sstevel@tonic-gate 	struct iovec iov;
5877c478bd9Sstevel@tonic-gate 	int error = 0;
5887c478bd9Sstevel@tonic-gate 	XDR xdrm;
5897c478bd9Sstevel@tonic-gate 	char *buffy = NULL;
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate 	/*
5927c478bd9Sstevel@tonic-gate 	 * NULL out the x_ops field of XDR.  this way, if x_ops !=
5937c478bd9Sstevel@tonic-gate 	 * NULL, we know that we did the xdr*_create() successfully.
5947c478bd9Sstevel@tonic-gate 	 * this is documented in the xdr_create man page.
5957c478bd9Sstevel@tonic-gate 	 */
5967c478bd9Sstevel@tonic-gate 
5977c478bd9Sstevel@tonic-gate 	xdrm.x_ops = NULL;
5987c478bd9Sstevel@tonic-gate 
5997c478bd9Sstevel@tonic-gate 	/* see if we're still logging */
6007c478bd9Sstevel@tonic-gate 	if (getlock)
6017c478bd9Sstevel@tonic-gate 		mutex_enter(&cachep->c_log_mutex);
6027c478bd9Sstevel@tonic-gate 	cl = cachep->c_log;
6037c478bd9Sstevel@tonic-gate 	if ((cl == NULL) || (cl->cl_magic != CACHEFS_LOG_MAGIC)) {
6047c478bd9Sstevel@tonic-gate 		if (getlock)
6057c478bd9Sstevel@tonic-gate 			mutex_exit(&cachep->c_log_mutex);
6067c478bd9Sstevel@tonic-gate 		return;
6077c478bd9Sstevel@tonic-gate 	}
6087c478bd9Sstevel@tonic-gate 
6097c478bd9Sstevel@tonic-gate 	/* get the work, and let go of the mutex asap. */
6107c478bd9Sstevel@tonic-gate 	workhead = cl->cl_head;
6117c478bd9Sstevel@tonic-gate 	cl->cl_head = cl->cl_tail = NULL;
6127c478bd9Sstevel@tonic-gate 	cl->cl_size = 0;
6137c478bd9Sstevel@tonic-gate 	logvp = cl->cl_logvp;
6147c478bd9Sstevel@tonic-gate 	ASSERT(logvp != NULL);
6157c478bd9Sstevel@tonic-gate 	if (logvp == NULL) {
6167c478bd9Sstevel@tonic-gate 		if (getlock)
6177c478bd9Sstevel@tonic-gate 			mutex_exit(&cachep->c_log_mutex);
6187c478bd9Sstevel@tonic-gate 		return;
6197c478bd9Sstevel@tonic-gate 	}
6207c478bd9Sstevel@tonic-gate 	VN_HOLD(logvp);
6217c478bd9Sstevel@tonic-gate 	if (getlock)
6227c478bd9Sstevel@tonic-gate 		mutex_exit(&cachep->c_log_mutex);
6237c478bd9Sstevel@tonic-gate 
6247c478bd9Sstevel@tonic-gate 	/* we don't use vn_rdwr() because there's no way to set FNONBLOCK */
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate 	uio.uio_iov = &iov;
6277c478bd9Sstevel@tonic-gate 	uio.uio_iovcnt = 1;
6287c478bd9Sstevel@tonic-gate 	uio.uio_loffset = 0; /* fake -- we do FAPPEND */
6297c478bd9Sstevel@tonic-gate 	uio.uio_segflg = (short)UIO_SYSSPACE;
6307c478bd9Sstevel@tonic-gate 	uio.uio_llimit = MAXOFFSET_T;
6317c478bd9Sstevel@tonic-gate 	uio.uio_fmode = FWRITE | FNONBLOCK;
6327c478bd9Sstevel@tonic-gate 	uio.uio_extflg = UIO_COPY_CACHED;
6337c478bd9Sstevel@tonic-gate 
6347c478bd9Sstevel@tonic-gate 	buffy = cachefs_kmem_alloc(CACHEFS_LOG_ENCODE_SIZE, KM_SLEEP);
6357c478bd9Sstevel@tonic-gate 	xdrmem_create(&xdrm, buffy, CACHEFS_LOG_ENCODE_SIZE, XDR_ENCODE);
6367c478bd9Sstevel@tonic-gate 
6377c478bd9Sstevel@tonic-gate 	(void) VOP_RWLOCK(logvp, V_WRITELOCK_TRUE, NULL);
6387c478bd9Sstevel@tonic-gate 	for (work = workhead; work != NULL; work = work->next) {
6397c478bd9Sstevel@tonic-gate 		if (! (work->translate)(&xdrm, work->data)) {
6407c478bd9Sstevel@tonic-gate 			VOP_RWUNLOCK(logvp, V_WRITELOCK_TRUE, NULL);
6417c478bd9Sstevel@tonic-gate 			error = ENOMEM;
6427c478bd9Sstevel@tonic-gate 			goto out;
6437c478bd9Sstevel@tonic-gate 		}
6447c478bd9Sstevel@tonic-gate 
6457c478bd9Sstevel@tonic-gate 		iov.iov_base = buffy;
6467c478bd9Sstevel@tonic-gate 		iov.iov_len = uio.uio_resid = xdr_getpos(&xdrm);
6477c478bd9Sstevel@tonic-gate 		(void) xdr_setpos(&xdrm, 0);
6487c478bd9Sstevel@tonic-gate 
6497c478bd9Sstevel@tonic-gate 		error = VOP_WRITE(logvp, &uio, FAPPEND, kcred, NULL);
6507c478bd9Sstevel@tonic-gate 
6517c478bd9Sstevel@tonic-gate 		/* XXX future -- check for EAGAIN */
6527c478bd9Sstevel@tonic-gate 
6537c478bd9Sstevel@tonic-gate 		if ((error) || (uio.uio_resid)) {
6547c478bd9Sstevel@tonic-gate 			if (uio.uio_resid != 0)
6557c478bd9Sstevel@tonic-gate 				error = EIO;
6567c478bd9Sstevel@tonic-gate 			VOP_RWUNLOCK(logvp, V_WRITELOCK_TRUE, NULL);
6577c478bd9Sstevel@tonic-gate 			goto out;
6587c478bd9Sstevel@tonic-gate 		}
6597c478bd9Sstevel@tonic-gate 	}
6607c478bd9Sstevel@tonic-gate 	VOP_RWUNLOCK(logvp, V_WRITELOCK_TRUE, NULL);
6617c478bd9Sstevel@tonic-gate 
6627c478bd9Sstevel@tonic-gate out:
6637c478bd9Sstevel@tonic-gate 	if (xdrm.x_ops != NULL)
6647c478bd9Sstevel@tonic-gate 		xdr_destroy(&xdrm);
6657c478bd9Sstevel@tonic-gate 	if (buffy != NULL)
6667c478bd9Sstevel@tonic-gate 		cachefs_kmem_free(buffy, CACHEFS_LOG_ENCODE_SIZE);
6677c478bd9Sstevel@tonic-gate 
6687c478bd9Sstevel@tonic-gate 	/*
669*da6c28aaSamw 	 * if an error occurred, we need to free the buffers ourselves.
6707c478bd9Sstevel@tonic-gate 	 * cachefs_destory_cookie() can't do it.
6717c478bd9Sstevel@tonic-gate 	 */
6727c478bd9Sstevel@tonic-gate 
6737c478bd9Sstevel@tonic-gate 	work = workhead;
6747c478bd9Sstevel@tonic-gate 	while (work != NULL) {
6757c478bd9Sstevel@tonic-gate 		cachefs_kmem_free(work->data, work->size);
6767c478bd9Sstevel@tonic-gate 		oldwork = work;
6777c478bd9Sstevel@tonic-gate 		work = work->next;
6787c478bd9Sstevel@tonic-gate 		cachefs_kmem_free(oldwork, sizeof (*oldwork));
6797c478bd9Sstevel@tonic-gate 	}
6807c478bd9Sstevel@tonic-gate 	if (logvp != NULL)
6817c478bd9Sstevel@tonic-gate 		VN_RELE(logvp);
6827c478bd9Sstevel@tonic-gate 	if (error) {
6837c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, error, 1);
6847c478bd9Sstevel@tonic-gate 		return;
6857c478bd9Sstevel@tonic-gate 	}
6867c478bd9Sstevel@tonic-gate }
6877c478bd9Sstevel@tonic-gate 
6887c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_logfile_header(XDR * xdrs,struct cachefs_log_logfile_header * h)6897c478bd9Sstevel@tonic-gate cachefs_xdr_logfile_header(XDR *xdrs, struct cachefs_log_logfile_header *h)
6907c478bd9Sstevel@tonic-gate {
6917c478bd9Sstevel@tonic-gate 	if ((! xdr_u_int(xdrs, &h->lh_magic)) ||
6927c478bd9Sstevel@tonic-gate 	    (! xdr_u_int(xdrs, &h->lh_revision)) ||
6937c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &h->lh_errno)) ||
6947c478bd9Sstevel@tonic-gate 	    (! xdr_u_int(xdrs, &h->lh_blocks)) ||
6957c478bd9Sstevel@tonic-gate 	    (! xdr_u_int(xdrs, &h->lh_files)) ||
6967c478bd9Sstevel@tonic-gate 	    (! xdr_u_int(xdrs, &h->lh_maxbsize)) ||
6977c478bd9Sstevel@tonic-gate 	    (! xdr_u_int(xdrs, &h->lh_pagesize)))
6987c478bd9Sstevel@tonic-gate 		return (FALSE);
6997c478bd9Sstevel@tonic-gate 
7007c478bd9Sstevel@tonic-gate 	return (TRUE);
7017c478bd9Sstevel@tonic-gate }
7027c478bd9Sstevel@tonic-gate 
7037c478bd9Sstevel@tonic-gate /*
7047c478bd9Sstevel@tonic-gate  * the routines for logging each transaction follow...
7057c478bd9Sstevel@tonic-gate  */
7067c478bd9Sstevel@tonic-gate 
7077c478bd9Sstevel@tonic-gate void
cachefs_log_mount(cachefscache_t * cachep,int Errno,struct vfs * vfsp,fscache_t * fscp,char * upath,enum uio_seg seg,char * cacheid)7087c478bd9Sstevel@tonic-gate cachefs_log_mount(cachefscache_t *cachep, int Errno, struct vfs *vfsp,
7097c478bd9Sstevel@tonic-gate     fscache_t *fscp, char *upath, enum uio_seg seg, char *cacheid)
7107c478bd9Sstevel@tonic-gate {
7117c478bd9Sstevel@tonic-gate 	struct cachefs_log_mount_record *record;
7127c478bd9Sstevel@tonic-gate 	char *cacheidt;
7137c478bd9Sstevel@tonic-gate 	char *path = NULL;
7147c478bd9Sstevel@tonic-gate 	size_t len;
7157c478bd9Sstevel@tonic-gate 	int len1, len2;
7167c478bd9Sstevel@tonic-gate 	int size, error;
7177c478bd9Sstevel@tonic-gate 
7187c478bd9Sstevel@tonic-gate 	/* In Solaris 64 - if can't represent time don't bother */
7197c478bd9Sstevel@tonic-gate 	OUT_IF_TIME_OVERFLOW(cachep, time)
7207c478bd9Sstevel@tonic-gate 	if (seg == UIO_USERSPACE) {
7217c478bd9Sstevel@tonic-gate 		path = cachefs_kmem_alloc(MAXPATHLEN, KM_NOSLEEP);
7227c478bd9Sstevel@tonic-gate 		if (path == NULL) {
7237c478bd9Sstevel@tonic-gate 			cachefs_log_error(cachep, ENOMEM, 1);
7247c478bd9Sstevel@tonic-gate 			goto out;
7257c478bd9Sstevel@tonic-gate 		}
7267c478bd9Sstevel@tonic-gate 		if ((error = copyinstr(upath, path, MAXPATHLEN, &len)) != 0) {
7277c478bd9Sstevel@tonic-gate 			cachefs_log_error(cachep, error, 1);
7287c478bd9Sstevel@tonic-gate 			goto out;
7297c478bd9Sstevel@tonic-gate 		}
7307c478bd9Sstevel@tonic-gate 	} else {
7317c478bd9Sstevel@tonic-gate 		path = upath;
7327c478bd9Sstevel@tonic-gate 	}
7337c478bd9Sstevel@tonic-gate 
7347c478bd9Sstevel@tonic-gate 	len1 = (path != NULL) ? strlen(path) : 0;
7357c478bd9Sstevel@tonic-gate 	len2 = (cacheid != NULL) ? strlen(cacheid) : 0;
7367c478bd9Sstevel@tonic-gate 	size = (int)sizeof (*record) + len1 + len2 -
7377c478bd9Sstevel@tonic-gate 	    (int)CLPAD(cachefs_log_mount_record, path);
7387c478bd9Sstevel@tonic-gate 	record = cachefs_kmem_zalloc(size, KM_NOSLEEP);
7397c478bd9Sstevel@tonic-gate 	if (record == NULL) {
7407c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 1);
7417c478bd9Sstevel@tonic-gate 		goto out;
7427c478bd9Sstevel@tonic-gate 	}
7437c478bd9Sstevel@tonic-gate 
7447c478bd9Sstevel@tonic-gate 	record->type = CACHEFS_LOG_MOUNT;
7457c478bd9Sstevel@tonic-gate 	record->time = time;
7467c478bd9Sstevel@tonic-gate 
7477c478bd9Sstevel@tonic-gate 	record->error = Errno;
7487c478bd9Sstevel@tonic-gate 	record->vfsp = (uint64_t)(uintptr_t)vfsp;
7497c478bd9Sstevel@tonic-gate 
7507c478bd9Sstevel@tonic-gate 	if (fscp) {
7517c478bd9Sstevel@tonic-gate 		record->flags = fscp->fs_info.fi_mntflags;
7527c478bd9Sstevel@tonic-gate 		record->popsize = fscp->fs_info.fi_popsize;
7537c478bd9Sstevel@tonic-gate 		record->fgsize = fscp->fs_info.fi_fgsize;
7547c478bd9Sstevel@tonic-gate 	}
7557c478bd9Sstevel@tonic-gate 
7567c478bd9Sstevel@tonic-gate 	record->pathlen = (ushort_t)len1;
7577c478bd9Sstevel@tonic-gate 	record->cacheidlen = (ushort_t)len2;
7587c478bd9Sstevel@tonic-gate 	if (path != NULL)
7597c478bd9Sstevel@tonic-gate 		(void) strcpy(record->path, path);
7607c478bd9Sstevel@tonic-gate 	cacheidt = record->path + len1 + 1;
7617c478bd9Sstevel@tonic-gate 	if (cacheid != NULL)
7627c478bd9Sstevel@tonic-gate 		(void) strcpy(cacheidt, cacheid);
7637c478bd9Sstevel@tonic-gate 
7647c478bd9Sstevel@tonic-gate 	cachefs_log_enqueue(cachep, record, size, cachefs_xdr_mount);
7657c478bd9Sstevel@tonic-gate 
7667c478bd9Sstevel@tonic-gate out:
7677c478bd9Sstevel@tonic-gate 	if ((seg == UIO_USERSPACE) && (path != NULL))
7687c478bd9Sstevel@tonic-gate 		cachefs_kmem_free(path, MAXPATHLEN);
7697c478bd9Sstevel@tonic-gate }
7707c478bd9Sstevel@tonic-gate 
7717c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_mount(XDR * xdrs,struct cachefs_log_mount_record * rec)7727c478bd9Sstevel@tonic-gate cachefs_xdr_mount(XDR *xdrs, struct cachefs_log_mount_record *rec)
7737c478bd9Sstevel@tonic-gate {
7747c478bd9Sstevel@tonic-gate 	char *path = rec->path;
7757c478bd9Sstevel@tonic-gate 	char *cacheid;
7767c478bd9Sstevel@tonic-gate 
7777c478bd9Sstevel@tonic-gate 	cacheid = path + strlen(path) + 1;
7787c478bd9Sstevel@tonic-gate 
7797c478bd9Sstevel@tonic-gate 	if ((! xdr_int(xdrs, &rec->type)) ||
7807c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->error)) ||
7817c478bd9Sstevel@tonic-gate 	    (! xdr_cfs_time_t(xdrs, &rec->time)) ||
7827c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->vfsp, sizeof (rec->vfsp))) ||
7837c478bd9Sstevel@tonic-gate 	    (! xdr_u_int(xdrs, &rec->flags)) ||
7847c478bd9Sstevel@tonic-gate 	    (! xdr_u_int(xdrs, &rec->popsize)) ||
7857c478bd9Sstevel@tonic-gate 	    (! xdr_u_int(xdrs, &rec->fgsize)) ||
7867c478bd9Sstevel@tonic-gate 	    (! xdr_u_short(xdrs, &rec->pathlen)) ||
7877c478bd9Sstevel@tonic-gate 	    (! xdr_u_short(xdrs, &rec->cacheidlen)) ||
7887c478bd9Sstevel@tonic-gate 	    (! xdr_wrapstring(xdrs, &path)) ||
7897c478bd9Sstevel@tonic-gate 	    (! xdr_wrapstring(xdrs, &cacheid)))
7907c478bd9Sstevel@tonic-gate 		return (FALSE);
7917c478bd9Sstevel@tonic-gate 
7927c478bd9Sstevel@tonic-gate 	return (TRUE);
7937c478bd9Sstevel@tonic-gate }
7947c478bd9Sstevel@tonic-gate 
7957c478bd9Sstevel@tonic-gate void
cachefs_log_umount(cachefscache_t * cachep,int Errno,struct vfs * vfsp)7967c478bd9Sstevel@tonic-gate cachefs_log_umount(cachefscache_t *cachep, int Errno, struct vfs *vfsp)
7977c478bd9Sstevel@tonic-gate {
7987c478bd9Sstevel@tonic-gate 	struct cachefs_log_umount_record *record;
7997c478bd9Sstevel@tonic-gate 
8007c478bd9Sstevel@tonic-gate 	/* In Solaris 64 - if can't represent time don't bother */
8017c478bd9Sstevel@tonic-gate 	RET_IF_TIME_OVERFLOW(cachep, time)
8027c478bd9Sstevel@tonic-gate 	record = cachefs_kmem_zalloc(sizeof (*record), KM_NOSLEEP);
8037c478bd9Sstevel@tonic-gate 	if (record == NULL) {
8047c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 1);
8057c478bd9Sstevel@tonic-gate 		return;
8067c478bd9Sstevel@tonic-gate 	}
8077c478bd9Sstevel@tonic-gate 
8087c478bd9Sstevel@tonic-gate 	record->type = CACHEFS_LOG_UMOUNT;
8097c478bd9Sstevel@tonic-gate 	record->time = time;
8107c478bd9Sstevel@tonic-gate 
8117c478bd9Sstevel@tonic-gate 	record->error = Errno;
8127c478bd9Sstevel@tonic-gate 	record->vfsp = (uint64_t)(uintptr_t)vfsp;
8137c478bd9Sstevel@tonic-gate 
8147c478bd9Sstevel@tonic-gate 	cachefs_log_enqueue(cachep, record, (int)sizeof (*record),
8157c478bd9Sstevel@tonic-gate 	    cachefs_xdr_umount);
8167c478bd9Sstevel@tonic-gate }
8177c478bd9Sstevel@tonic-gate 
8187c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_umount(XDR * xdrs,struct cachefs_log_umount_record * rec)8197c478bd9Sstevel@tonic-gate cachefs_xdr_umount(XDR *xdrs, struct cachefs_log_umount_record *rec)
8207c478bd9Sstevel@tonic-gate {
8217c478bd9Sstevel@tonic-gate 	if ((! xdr_int(xdrs, &rec->type)) ||
8227c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->error)) ||
8237c478bd9Sstevel@tonic-gate 	    (! xdr_cfs_time_t(xdrs, &rec->time)) ||
8247c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->vfsp, sizeof (rec->vfsp))))
8257c478bd9Sstevel@tonic-gate 		return (FALSE);
8267c478bd9Sstevel@tonic-gate 
8277c478bd9Sstevel@tonic-gate 	return (TRUE);
8287c478bd9Sstevel@tonic-gate }
8297c478bd9Sstevel@tonic-gate 
8307c478bd9Sstevel@tonic-gate void
cachefs_log_getpage(cachefscache_t * cachep,int Errno,struct vfs * vfsp,fid_t * fidp,ino64_t fileno,uid_t uid,u_offset_t offset,size_t len)8317c478bd9Sstevel@tonic-gate cachefs_log_getpage(cachefscache_t *cachep, int Errno, struct vfs *vfsp,
8327c478bd9Sstevel@tonic-gate     fid_t *fidp, ino64_t fileno, uid_t uid, u_offset_t offset, size_t len)
8337c478bd9Sstevel@tonic-gate {
8347c478bd9Sstevel@tonic-gate 	struct cachefs_log_getpage_record *record;
8357c478bd9Sstevel@tonic-gate 
8367c478bd9Sstevel@tonic-gate 	/* In Solaris 64 - if can't represent time don't bother */
8377c478bd9Sstevel@tonic-gate 	RET_IF_TIME_OVERFLOW(cachep, time)
8387c478bd9Sstevel@tonic-gate 	record = cachefs_kmem_zalloc(sizeof (*record), KM_NOSLEEP);
8397c478bd9Sstevel@tonic-gate 	if (record == NULL) {
8407c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 1);
8417c478bd9Sstevel@tonic-gate 		return;
8427c478bd9Sstevel@tonic-gate 	}
8437c478bd9Sstevel@tonic-gate 
8447c478bd9Sstevel@tonic-gate 	record->type = CACHEFS_LOG_GETPAGE;
8457c478bd9Sstevel@tonic-gate 	record->time = time;
8467c478bd9Sstevel@tonic-gate 
8477c478bd9Sstevel@tonic-gate 	record->error = Errno;
8487c478bd9Sstevel@tonic-gate 	record->vfsp = (uint64_t)(uintptr_t)vfsp;
8497c478bd9Sstevel@tonic-gate 	if (fidp != NULL) {
8507c478bd9Sstevel@tonic-gate 		CACHEFS_FID_COPY(fidp, &record->fid);
8517c478bd9Sstevel@tonic-gate 	}
8527c478bd9Sstevel@tonic-gate 	record->fileno = fileno;
8537c478bd9Sstevel@tonic-gate 	record->uid = uid;
8547c478bd9Sstevel@tonic-gate 	record->offset = offset;
8557c478bd9Sstevel@tonic-gate 	record->len = (uint_t)len;
8567c478bd9Sstevel@tonic-gate 
8577c478bd9Sstevel@tonic-gate 	cachefs_log_enqueue(cachep, record, (int)sizeof (*record),
8587c478bd9Sstevel@tonic-gate 	    cachefs_xdr_getpage);
8597c478bd9Sstevel@tonic-gate }
8607c478bd9Sstevel@tonic-gate 
8617c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_getpage(XDR * xdrs,struct cachefs_log_getpage_record * rec)8627c478bd9Sstevel@tonic-gate cachefs_xdr_getpage(XDR *xdrs, struct cachefs_log_getpage_record *rec)
8637c478bd9Sstevel@tonic-gate {
8647c478bd9Sstevel@tonic-gate 	if ((! xdr_int(xdrs, &rec->type)) ||
8657c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->error)) ||
8667c478bd9Sstevel@tonic-gate 	    (! xdr_cfs_time_t(xdrs, &rec->time)) ||
8677c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->vfsp, sizeof (rec->vfsp))) ||
8687c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->fid, sizeof (rec->fid))) ||
8697c478bd9Sstevel@tonic-gate 	    (! xdr_ino64(xdrs, &rec->fileno)) ||
870f48205beScasper 	    (! xdr_u_int(xdrs, &rec->uid)) ||
8717c478bd9Sstevel@tonic-gate 	    (! xdr_u_longlong_t(xdrs, &rec->offset)) ||
8727c478bd9Sstevel@tonic-gate 	    (! xdr_u_int(xdrs, &rec->len)))
8737c478bd9Sstevel@tonic-gate 		return (FALSE);
8747c478bd9Sstevel@tonic-gate 
8757c478bd9Sstevel@tonic-gate 	return (TRUE);
8767c478bd9Sstevel@tonic-gate }
8777c478bd9Sstevel@tonic-gate 
8787c478bd9Sstevel@tonic-gate void
cachefs_log_readdir(cachefscache_t * cachep,int Errno,struct vfs * vfsp,fid_t * fidp,ino64_t fileno,uid_t uid,u_offset_t offset,int eof)8797c478bd9Sstevel@tonic-gate cachefs_log_readdir(cachefscache_t *cachep, int Errno, struct vfs *vfsp,
8807c478bd9Sstevel@tonic-gate     fid_t *fidp, ino64_t fileno, uid_t uid, u_offset_t offset, int eof)
8817c478bd9Sstevel@tonic-gate {
8827c478bd9Sstevel@tonic-gate 	struct cachefs_log_readdir_record *record;
8837c478bd9Sstevel@tonic-gate 
8847c478bd9Sstevel@tonic-gate 	/* In Solaris 64 - if can't represent time don't bother */
8857c478bd9Sstevel@tonic-gate 	RET_IF_TIME_OVERFLOW(cachep, time)
8867c478bd9Sstevel@tonic-gate 	record = cachefs_kmem_zalloc(sizeof (*record), KM_NOSLEEP);
8877c478bd9Sstevel@tonic-gate 	if (record == NULL) {
8887c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 1);
8897c478bd9Sstevel@tonic-gate 		return;
8907c478bd9Sstevel@tonic-gate 	}
8917c478bd9Sstevel@tonic-gate 
8927c478bd9Sstevel@tonic-gate 	record->type = CACHEFS_LOG_READDIR;
8937c478bd9Sstevel@tonic-gate 	record->time = time;
8947c478bd9Sstevel@tonic-gate 
8957c478bd9Sstevel@tonic-gate 	record->error = Errno;
8967c478bd9Sstevel@tonic-gate 	record->vfsp = (uint64_t)(uintptr_t)vfsp;
8977c478bd9Sstevel@tonic-gate 	if (fidp != NULL) {
8987c478bd9Sstevel@tonic-gate 		CACHEFS_FID_COPY(fidp, &record->fid);
8997c478bd9Sstevel@tonic-gate 	}
9007c478bd9Sstevel@tonic-gate 	record->fileno = fileno;
9017c478bd9Sstevel@tonic-gate 	record->uid = uid;
9027c478bd9Sstevel@tonic-gate 	record->offset = offset;
9037c478bd9Sstevel@tonic-gate 	record->eof = eof;
9047c478bd9Sstevel@tonic-gate 
9057c478bd9Sstevel@tonic-gate 	cachefs_log_enqueue(cachep, record, (int)sizeof (*record),
9067c478bd9Sstevel@tonic-gate 	    cachefs_xdr_readdir);
9077c478bd9Sstevel@tonic-gate }
9087c478bd9Sstevel@tonic-gate 
9097c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_readdir(XDR * xdrs,struct cachefs_log_readdir_record * rec)9107c478bd9Sstevel@tonic-gate cachefs_xdr_readdir(XDR *xdrs, struct cachefs_log_readdir_record *rec)
9117c478bd9Sstevel@tonic-gate {
9127c478bd9Sstevel@tonic-gate 	if ((! xdr_int(xdrs, &rec->type)) ||
9137c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->error)) ||
9147c478bd9Sstevel@tonic-gate 	    (! xdr_cfs_time_t(xdrs, &rec->time)) ||
9157c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->vfsp, sizeof (rec->vfsp))) ||
9167c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->fid, sizeof (rec->fid))) ||
9177c478bd9Sstevel@tonic-gate 	    (! xdr_ino64(xdrs, &rec->fileno)) ||
918f48205beScasper 	    (! xdr_u_int(xdrs, &rec->uid)) ||
9197c478bd9Sstevel@tonic-gate 	    (! xdr_u_longlong_t(xdrs, (u_longlong_t *)&rec->offset)) ||
9207c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->eof)))
9217c478bd9Sstevel@tonic-gate 		return (FALSE);
9227c478bd9Sstevel@tonic-gate 
9237c478bd9Sstevel@tonic-gate 	return (TRUE);
9247c478bd9Sstevel@tonic-gate }
9257c478bd9Sstevel@tonic-gate 
9267c478bd9Sstevel@tonic-gate void
cachefs_log_readlink(cachefscache_t * cachep,int Errno,struct vfs * vfsp,fid_t * fidp,ino64_t fileno,uid_t uid,size_t length)9277c478bd9Sstevel@tonic-gate cachefs_log_readlink(cachefscache_t *cachep, int Errno, struct vfs *vfsp,
9287c478bd9Sstevel@tonic-gate     fid_t *fidp, ino64_t fileno, uid_t uid, size_t length)
9297c478bd9Sstevel@tonic-gate {
9307c478bd9Sstevel@tonic-gate 	struct cachefs_log_readlink_record *record;
9317c478bd9Sstevel@tonic-gate 
9327c478bd9Sstevel@tonic-gate 	/* In Solaris 64 - if can't represent time don't bother */
9337c478bd9Sstevel@tonic-gate 	RET_IF_TIME_OVERFLOW(cachep, time)
9347c478bd9Sstevel@tonic-gate 	record = cachefs_kmem_zalloc(sizeof (*record), KM_NOSLEEP);
9357c478bd9Sstevel@tonic-gate 	if (record == NULL) {
9367c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 1);
9377c478bd9Sstevel@tonic-gate 		return;
9387c478bd9Sstevel@tonic-gate 	}
9397c478bd9Sstevel@tonic-gate 
9407c478bd9Sstevel@tonic-gate 	record->type = CACHEFS_LOG_READLINK;
9417c478bd9Sstevel@tonic-gate 	record->time = time;
9427c478bd9Sstevel@tonic-gate 
9437c478bd9Sstevel@tonic-gate 	record->error = Errno;
9447c478bd9Sstevel@tonic-gate 	record->vfsp = (uint64_t)(uintptr_t)vfsp;
9457c478bd9Sstevel@tonic-gate 	if (fidp != NULL) {
9467c478bd9Sstevel@tonic-gate 		CACHEFS_FID_COPY(fidp, &record->fid);
9477c478bd9Sstevel@tonic-gate 	}
9487c478bd9Sstevel@tonic-gate 	record->fileno = fileno;
9497c478bd9Sstevel@tonic-gate 	record->uid = uid;
9507c478bd9Sstevel@tonic-gate 	record->length = (uint_t)length;
9517c478bd9Sstevel@tonic-gate 
9527c478bd9Sstevel@tonic-gate 	cachefs_log_enqueue(cachep, record, (int)sizeof (*record),
9537c478bd9Sstevel@tonic-gate 	    cachefs_xdr_readlink);
9547c478bd9Sstevel@tonic-gate }
9557c478bd9Sstevel@tonic-gate 
9567c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_readlink(XDR * xdrs,struct cachefs_log_readlink_record * rec)9577c478bd9Sstevel@tonic-gate cachefs_xdr_readlink(XDR *xdrs, struct cachefs_log_readlink_record *rec)
9587c478bd9Sstevel@tonic-gate {
9597c478bd9Sstevel@tonic-gate 	if ((! xdr_int(xdrs, &rec->type)) ||
9607c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->error)) ||
9617c478bd9Sstevel@tonic-gate 	    (! xdr_cfs_time_t(xdrs, &rec->time)) ||
9627c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->vfsp, sizeof (rec->vfsp))) ||
9637c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->fid, sizeof (rec->fid))) ||
9647c478bd9Sstevel@tonic-gate 	    (! xdr_ino64(xdrs, &rec->fileno)) ||
965f48205beScasper 	    (! xdr_u_int(xdrs, &rec->uid)) ||
9667c478bd9Sstevel@tonic-gate 	    (! xdr_u_int(xdrs, &rec->length)))
9677c478bd9Sstevel@tonic-gate 		return (FALSE);
9687c478bd9Sstevel@tonic-gate 
9697c478bd9Sstevel@tonic-gate 	return (TRUE);
9707c478bd9Sstevel@tonic-gate }
9717c478bd9Sstevel@tonic-gate 
9727c478bd9Sstevel@tonic-gate void
cachefs_log_remove(cachefscache_t * cachep,int Errno,struct vfs * vfsp,fid_t * fidp,ino64_t fileno,uid_t uid)9737c478bd9Sstevel@tonic-gate cachefs_log_remove(cachefscache_t *cachep, int Errno, struct vfs *vfsp,
9747c478bd9Sstevel@tonic-gate     fid_t *fidp, ino64_t fileno, uid_t uid)
9757c478bd9Sstevel@tonic-gate {
9767c478bd9Sstevel@tonic-gate 	struct cachefs_log_remove_record *record;
9777c478bd9Sstevel@tonic-gate 
9787c478bd9Sstevel@tonic-gate 	/* In Solaris 64 - if can't represent time don't bother */
9797c478bd9Sstevel@tonic-gate 	RET_IF_TIME_OVERFLOW(cachep, time)
9807c478bd9Sstevel@tonic-gate 	record = cachefs_kmem_zalloc(sizeof (*record), KM_NOSLEEP);
9817c478bd9Sstevel@tonic-gate 	if (record == NULL) {
9827c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 1);
9837c478bd9Sstevel@tonic-gate 		return;
9847c478bd9Sstevel@tonic-gate 	}
9857c478bd9Sstevel@tonic-gate 
9867c478bd9Sstevel@tonic-gate 	record->type = CACHEFS_LOG_REMOVE;
9877c478bd9Sstevel@tonic-gate 	record->time = time;
9887c478bd9Sstevel@tonic-gate 
9897c478bd9Sstevel@tonic-gate 	record->error = Errno;
9907c478bd9Sstevel@tonic-gate 	record->vfsp = (uint64_t)(uintptr_t)vfsp;
9917c478bd9Sstevel@tonic-gate 	if (fidp != NULL) {
9927c478bd9Sstevel@tonic-gate 		CACHEFS_FID_COPY(fidp, &record->fid);
9937c478bd9Sstevel@tonic-gate 	}
9947c478bd9Sstevel@tonic-gate 	record->fileno = fileno;
9957c478bd9Sstevel@tonic-gate 	record->uid = uid;
9967c478bd9Sstevel@tonic-gate 
9977c478bd9Sstevel@tonic-gate 	cachefs_log_enqueue(cachep, record, (int)sizeof (*record),
9987c478bd9Sstevel@tonic-gate 	    cachefs_xdr_remove);
9997c478bd9Sstevel@tonic-gate }
10007c478bd9Sstevel@tonic-gate 
10017c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_remove(XDR * xdrs,struct cachefs_log_remove_record * rec)10027c478bd9Sstevel@tonic-gate cachefs_xdr_remove(XDR *xdrs, struct cachefs_log_remove_record *rec)
10037c478bd9Sstevel@tonic-gate {
10047c478bd9Sstevel@tonic-gate 	if ((! xdr_int(xdrs, &rec->type)) ||
10057c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->error)) ||
10067c478bd9Sstevel@tonic-gate 	    (! xdr_cfs_time_t(xdrs, &rec->time)) ||
10077c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->vfsp, sizeof (rec->vfsp))) ||
10087c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->fid, sizeof (rec->fid))) ||
10097c478bd9Sstevel@tonic-gate 	    (! xdr_ino64(xdrs, &rec->fileno)) ||
1010f48205beScasper 	    (! xdr_u_int(xdrs, &rec->uid)))
10117c478bd9Sstevel@tonic-gate 		return (FALSE);
10127c478bd9Sstevel@tonic-gate 
10137c478bd9Sstevel@tonic-gate 	return (TRUE);
10147c478bd9Sstevel@tonic-gate }
10157c478bd9Sstevel@tonic-gate 
10167c478bd9Sstevel@tonic-gate void
cachefs_log_rmdir(cachefscache_t * cachep,int Errno,struct vfs * vfsp,fid_t * fidp,ino64_t fileno,uid_t uid)10177c478bd9Sstevel@tonic-gate cachefs_log_rmdir(cachefscache_t *cachep, int Errno,
10187c478bd9Sstevel@tonic-gate     struct vfs *vfsp, fid_t *fidp, ino64_t fileno, uid_t uid)
10197c478bd9Sstevel@tonic-gate {
10207c478bd9Sstevel@tonic-gate 	struct cachefs_log_rmdir_record *record;
10217c478bd9Sstevel@tonic-gate 
10227c478bd9Sstevel@tonic-gate 	/* In Solaris 64 - if can't represent time don't bother */
10237c478bd9Sstevel@tonic-gate 	RET_IF_TIME_OVERFLOW(cachep, time)
10247c478bd9Sstevel@tonic-gate 	record = cachefs_kmem_zalloc(sizeof (*record), KM_NOSLEEP);
10257c478bd9Sstevel@tonic-gate 	if (record == NULL) {
10267c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 1);
10277c478bd9Sstevel@tonic-gate 		return;
10287c478bd9Sstevel@tonic-gate 	}
10297c478bd9Sstevel@tonic-gate 
10307c478bd9Sstevel@tonic-gate 	record->type = CACHEFS_LOG_RMDIR;
10317c478bd9Sstevel@tonic-gate 	record->time = time;
10327c478bd9Sstevel@tonic-gate 
10337c478bd9Sstevel@tonic-gate 	record->error = Errno;
10347c478bd9Sstevel@tonic-gate 	record->vfsp = (uint64_t)(uintptr_t)vfsp;
10357c478bd9Sstevel@tonic-gate 	if (fidp != NULL) {
10367c478bd9Sstevel@tonic-gate 		CACHEFS_FID_COPY(fidp, &record->fid);
10377c478bd9Sstevel@tonic-gate 	}
10387c478bd9Sstevel@tonic-gate 	record->fileno = fileno;
10397c478bd9Sstevel@tonic-gate 	record->uid = uid;
10407c478bd9Sstevel@tonic-gate 
10417c478bd9Sstevel@tonic-gate 	cachefs_log_enqueue(cachep, record, (int)sizeof (*record),
10427c478bd9Sstevel@tonic-gate 	    cachefs_xdr_rmdir);
10437c478bd9Sstevel@tonic-gate }
10447c478bd9Sstevel@tonic-gate 
10457c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_rmdir(XDR * xdrs,struct cachefs_log_rmdir_record * rec)10467c478bd9Sstevel@tonic-gate cachefs_xdr_rmdir(XDR *xdrs, struct cachefs_log_rmdir_record *rec)
10477c478bd9Sstevel@tonic-gate {
10487c478bd9Sstevel@tonic-gate 	if ((! xdr_int(xdrs, &rec->type)) ||
10497c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->error)) ||
10507c478bd9Sstevel@tonic-gate 	    (! xdr_cfs_time_t(xdrs, &rec->time)) ||
10517c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->vfsp, sizeof (rec->vfsp))) ||
10527c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->fid, sizeof (rec->fid))) ||
10537c478bd9Sstevel@tonic-gate 	    (! xdr_ino64(xdrs, &rec->fileno)) ||
1054f48205beScasper 	    (! xdr_u_int(xdrs, &rec->uid)))
10557c478bd9Sstevel@tonic-gate 		return (FALSE);
10567c478bd9Sstevel@tonic-gate 
10577c478bd9Sstevel@tonic-gate 	return (TRUE);
10587c478bd9Sstevel@tonic-gate }
10597c478bd9Sstevel@tonic-gate 
10607c478bd9Sstevel@tonic-gate void
cachefs_log_truncate(cachefscache_t * cachep,int Errno,struct vfs * vfsp,fid_t * fidp,ino64_t fileno,uid_t uid,u_offset_t size)10617c478bd9Sstevel@tonic-gate cachefs_log_truncate(cachefscache_t *cachep, int Errno, struct vfs *vfsp,
10627c478bd9Sstevel@tonic-gate     fid_t *fidp, ino64_t fileno, uid_t uid, u_offset_t size)
10637c478bd9Sstevel@tonic-gate {
10647c478bd9Sstevel@tonic-gate 	struct cachefs_log_truncate_record *record;
10657c478bd9Sstevel@tonic-gate 
10667c478bd9Sstevel@tonic-gate 	/* In Solaris 64 - if can't represent time don't bother */
10677c478bd9Sstevel@tonic-gate 	RET_IF_TIME_OVERFLOW(cachep, time)
10687c478bd9Sstevel@tonic-gate 	record = cachefs_kmem_zalloc(sizeof (*record), KM_NOSLEEP);
10697c478bd9Sstevel@tonic-gate 	if (record == NULL) {
10707c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 1);
10717c478bd9Sstevel@tonic-gate 		return;
10727c478bd9Sstevel@tonic-gate 	}
10737c478bd9Sstevel@tonic-gate 
10747c478bd9Sstevel@tonic-gate 	record->type = CACHEFS_LOG_TRUNCATE;
10757c478bd9Sstevel@tonic-gate 	record->time = time;
10767c478bd9Sstevel@tonic-gate 
10777c478bd9Sstevel@tonic-gate 	record->error = Errno;
10787c478bd9Sstevel@tonic-gate 	record->vfsp = (uint64_t)(uintptr_t)vfsp;
10797c478bd9Sstevel@tonic-gate 	if (fidp != NULL) {
10807c478bd9Sstevel@tonic-gate 		CACHEFS_FID_COPY(fidp, &record->fid);
10817c478bd9Sstevel@tonic-gate 	}
10827c478bd9Sstevel@tonic-gate 	record->fileno = fileno;
10837c478bd9Sstevel@tonic-gate 	record->uid = uid;
10847c478bd9Sstevel@tonic-gate 	record->size = size;
10857c478bd9Sstevel@tonic-gate 
10867c478bd9Sstevel@tonic-gate 	cachefs_log_enqueue(cachep, record, (int)sizeof (*record),
10877c478bd9Sstevel@tonic-gate 	    cachefs_xdr_truncate);
10887c478bd9Sstevel@tonic-gate }
10897c478bd9Sstevel@tonic-gate 
10907c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_truncate(XDR * xdrs,struct cachefs_log_truncate_record * rec)10917c478bd9Sstevel@tonic-gate cachefs_xdr_truncate(XDR *xdrs, struct cachefs_log_truncate_record *rec)
10927c478bd9Sstevel@tonic-gate {
10937c478bd9Sstevel@tonic-gate 	if ((! xdr_int(xdrs, &rec->type)) ||
10947c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->error)) ||
10957c478bd9Sstevel@tonic-gate 	    (! xdr_cfs_time_t(xdrs, &rec->time)) ||
10967c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->vfsp, sizeof (rec->vfsp))) ||
10977c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->fid, sizeof (rec->fid))) ||
10987c478bd9Sstevel@tonic-gate 	    (! xdr_ino64(xdrs, &rec->fileno)) ||
1099f48205beScasper 	    (! xdr_u_int(xdrs, &rec->uid)) ||
11007c478bd9Sstevel@tonic-gate 	    (! xdr_u_longlong_t(xdrs, &rec->size)))
11017c478bd9Sstevel@tonic-gate 		return (FALSE);
11027c478bd9Sstevel@tonic-gate 
11037c478bd9Sstevel@tonic-gate 	return (TRUE);
11047c478bd9Sstevel@tonic-gate }
11057c478bd9Sstevel@tonic-gate 
11067c478bd9Sstevel@tonic-gate void
cachefs_log_putpage(cachefscache_t * cachep,int Errno,struct vfs * vfsp,fid_t * fidp,ino64_t fileno,uid_t uid,u_offset_t offset,size_t len)11077c478bd9Sstevel@tonic-gate cachefs_log_putpage(cachefscache_t *cachep, int Errno, struct vfs *vfsp,
11087c478bd9Sstevel@tonic-gate     fid_t *fidp, ino64_t fileno, uid_t uid, u_offset_t offset, size_t len)
11097c478bd9Sstevel@tonic-gate {
11107c478bd9Sstevel@tonic-gate 	struct cachefs_log_putpage_record *record;
11117c478bd9Sstevel@tonic-gate 
11127c478bd9Sstevel@tonic-gate 	/* In Solaris 64 - if can't represent time don't bother */
11137c478bd9Sstevel@tonic-gate 	RET_IF_TIME_OVERFLOW(cachep, time)
11147c478bd9Sstevel@tonic-gate 	record = cachefs_kmem_zalloc(sizeof (*record), KM_NOSLEEP);
11157c478bd9Sstevel@tonic-gate 	if (record == NULL) {
11167c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 1);
11177c478bd9Sstevel@tonic-gate 		return;
11187c478bd9Sstevel@tonic-gate 	}
11197c478bd9Sstevel@tonic-gate 
11207c478bd9Sstevel@tonic-gate 	record->type = CACHEFS_LOG_PUTPAGE;
11217c478bd9Sstevel@tonic-gate 	record->time = time;
11227c478bd9Sstevel@tonic-gate 
11237c478bd9Sstevel@tonic-gate 	record->error = Errno;
11247c478bd9Sstevel@tonic-gate 	record->vfsp = (uint64_t)(uintptr_t)vfsp;
11257c478bd9Sstevel@tonic-gate 	if (fidp != NULL) {
11267c478bd9Sstevel@tonic-gate 		CACHEFS_FID_COPY(fidp, &record->fid);
11277c478bd9Sstevel@tonic-gate 	}
11287c478bd9Sstevel@tonic-gate 	record->fileno = fileno;
11297c478bd9Sstevel@tonic-gate 	record->uid = uid;
11307c478bd9Sstevel@tonic-gate 	record->offset = offset;
11317c478bd9Sstevel@tonic-gate 	record->len = (uint_t)len;
11327c478bd9Sstevel@tonic-gate 
11337c478bd9Sstevel@tonic-gate 	cachefs_log_enqueue(cachep, record, (int)sizeof (*record),
11347c478bd9Sstevel@tonic-gate 	    cachefs_xdr_putpage);
11357c478bd9Sstevel@tonic-gate }
11367c478bd9Sstevel@tonic-gate 
11377c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_putpage(XDR * xdrs,struct cachefs_log_putpage_record * rec)11387c478bd9Sstevel@tonic-gate cachefs_xdr_putpage(XDR *xdrs, struct cachefs_log_putpage_record *rec)
11397c478bd9Sstevel@tonic-gate {
11407c478bd9Sstevel@tonic-gate 	if ((! xdr_int(xdrs, &rec->type)) ||
11417c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->error)) ||
11427c478bd9Sstevel@tonic-gate 	    (! xdr_cfs_time_t(xdrs, &rec->time)) ||
11437c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->vfsp, sizeof (rec->vfsp))) ||
11447c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->fid, sizeof (rec->fid))) ||
11457c478bd9Sstevel@tonic-gate 	    (! xdr_ino64(xdrs, &rec->fileno)) ||
1146f48205beScasper 	    (! xdr_u_int(xdrs, &rec->uid)) ||
11477c478bd9Sstevel@tonic-gate 	    (! xdr_u_longlong_t(xdrs, (u_longlong_t *)&rec->offset)) ||
11487c478bd9Sstevel@tonic-gate 	    (! xdr_u_int(xdrs, &rec->len)))
11497c478bd9Sstevel@tonic-gate 		return (FALSE);
11507c478bd9Sstevel@tonic-gate 
11517c478bd9Sstevel@tonic-gate 	return (TRUE);
11527c478bd9Sstevel@tonic-gate }
11537c478bd9Sstevel@tonic-gate 
11547c478bd9Sstevel@tonic-gate void
cachefs_log_create(cachefscache_t * cachep,int Errno,struct vfs * vfsp,fid_t * filefidp,ino64_t fileno,uid_t uid)11557c478bd9Sstevel@tonic-gate cachefs_log_create(cachefscache_t *cachep, int Errno, struct vfs *vfsp,
11567c478bd9Sstevel@tonic-gate     fid_t *filefidp, ino64_t fileno, uid_t uid)
11577c478bd9Sstevel@tonic-gate {
11587c478bd9Sstevel@tonic-gate 	struct cachefs_log_create_record *record;
11597c478bd9Sstevel@tonic-gate 
11607c478bd9Sstevel@tonic-gate 	/* In Solaris 64 - if can't represent time don't bother */
11617c478bd9Sstevel@tonic-gate 	RET_IF_TIME_OVERFLOW(cachep, time)
11627c478bd9Sstevel@tonic-gate 	record = cachefs_kmem_zalloc(sizeof (*record), KM_NOSLEEP);
11637c478bd9Sstevel@tonic-gate 	if (record == NULL) {
11647c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 1);
11657c478bd9Sstevel@tonic-gate 		return;
11667c478bd9Sstevel@tonic-gate 	}
11677c478bd9Sstevel@tonic-gate 
11687c478bd9Sstevel@tonic-gate 	record->type = CACHEFS_LOG_CREATE;
11697c478bd9Sstevel@tonic-gate 	record->time = time;
11707c478bd9Sstevel@tonic-gate 
11717c478bd9Sstevel@tonic-gate 	record->error = Errno;
11727c478bd9Sstevel@tonic-gate 	record->vfsp = (uint64_t)(uintptr_t)vfsp;
11737c478bd9Sstevel@tonic-gate 	if (filefidp != NULL) {
11747c478bd9Sstevel@tonic-gate 		CACHEFS_FID_COPY(filefidp, &record->fid);
11757c478bd9Sstevel@tonic-gate 	}
11767c478bd9Sstevel@tonic-gate 	record->fileno = fileno;
11777c478bd9Sstevel@tonic-gate 	record->uid = uid;
11787c478bd9Sstevel@tonic-gate 
11797c478bd9Sstevel@tonic-gate 	cachefs_log_enqueue(cachep, record, (int)sizeof (*record),
11807c478bd9Sstevel@tonic-gate 	    cachefs_xdr_create);
11817c478bd9Sstevel@tonic-gate }
11827c478bd9Sstevel@tonic-gate 
11837c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_create(XDR * xdrs,struct cachefs_log_create_record * rec)11847c478bd9Sstevel@tonic-gate cachefs_xdr_create(XDR *xdrs, struct cachefs_log_create_record *rec)
11857c478bd9Sstevel@tonic-gate {
11867c478bd9Sstevel@tonic-gate 	if ((! xdr_int(xdrs, &rec->type)) ||
11877c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->error)) ||
11887c478bd9Sstevel@tonic-gate 	    (! xdr_cfs_time_t(xdrs, &rec->time)) ||
11897c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->vfsp, sizeof (rec->vfsp))) ||
11907c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->fid, sizeof (rec->fid))) ||
11917c478bd9Sstevel@tonic-gate 	    (! xdr_ino64(xdrs, &rec->fileno)) ||
1192f48205beScasper 	    (! xdr_u_int(xdrs, &rec->uid)))
11937c478bd9Sstevel@tonic-gate 		return (FALSE);
11947c478bd9Sstevel@tonic-gate 
11957c478bd9Sstevel@tonic-gate 	return (TRUE);
11967c478bd9Sstevel@tonic-gate }
11977c478bd9Sstevel@tonic-gate 
11987c478bd9Sstevel@tonic-gate void
cachefs_log_mkdir(cachefscache_t * cachep,int Errno,struct vfs * vfsp,fid_t * cfidp,ino64_t fileno,uid_t uid)11997c478bd9Sstevel@tonic-gate cachefs_log_mkdir(cachefscache_t *cachep, int Errno, struct vfs *vfsp,
12007c478bd9Sstevel@tonic-gate     fid_t *cfidp, ino64_t fileno, uid_t uid)
12017c478bd9Sstevel@tonic-gate {
12027c478bd9Sstevel@tonic-gate 	struct cachefs_log_mkdir_record *record;
12037c478bd9Sstevel@tonic-gate 	int size;
12047c478bd9Sstevel@tonic-gate 
12057c478bd9Sstevel@tonic-gate 	/* In Solaris 64 - if can't represent time don't bother */
12067c478bd9Sstevel@tonic-gate 	RET_IF_TIME_OVERFLOW(cachep, time)
12077c478bd9Sstevel@tonic-gate 	size = (int)sizeof (*record);
12087c478bd9Sstevel@tonic-gate 	record = cachefs_kmem_zalloc(size, KM_NOSLEEP);
12097c478bd9Sstevel@tonic-gate 	if (record == NULL) {
12107c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 1);
12117c478bd9Sstevel@tonic-gate 		return;
12127c478bd9Sstevel@tonic-gate 	}
12137c478bd9Sstevel@tonic-gate 
12147c478bd9Sstevel@tonic-gate 	record->type = CACHEFS_LOG_MKDIR;
12157c478bd9Sstevel@tonic-gate 	record->time = time;
12167c478bd9Sstevel@tonic-gate 
12177c478bd9Sstevel@tonic-gate 	record->error = Errno;
12187c478bd9Sstevel@tonic-gate 	record->vfsp = (uint64_t)(uintptr_t)vfsp;
12197c478bd9Sstevel@tonic-gate 	if (cfidp != NULL) {
12207c478bd9Sstevel@tonic-gate 		CACHEFS_FID_COPY(cfidp, &record->fid);
12217c478bd9Sstevel@tonic-gate 	}
12227c478bd9Sstevel@tonic-gate 	record->fileno = fileno;
12237c478bd9Sstevel@tonic-gate 	record->uid = uid;
12247c478bd9Sstevel@tonic-gate 
12257c478bd9Sstevel@tonic-gate 	cachefs_log_enqueue(cachep, record, size,
12267c478bd9Sstevel@tonic-gate 	    cachefs_xdr_mkdir);
12277c478bd9Sstevel@tonic-gate }
12287c478bd9Sstevel@tonic-gate 
12297c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_mkdir(XDR * xdrs,struct cachefs_log_mkdir_record * rec)12307c478bd9Sstevel@tonic-gate cachefs_xdr_mkdir(XDR *xdrs, struct cachefs_log_mkdir_record *rec)
12317c478bd9Sstevel@tonic-gate {
12327c478bd9Sstevel@tonic-gate 	if ((! xdr_int(xdrs, &rec->type)) ||
12337c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->error)) ||
12347c478bd9Sstevel@tonic-gate 	    (! xdr_cfs_time_t(xdrs, &rec->time)) ||
12357c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->vfsp, sizeof (rec->vfsp))) ||
12367c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->fid, sizeof (rec->fid))) ||
12377c478bd9Sstevel@tonic-gate 	    (! xdr_ino64(xdrs, &rec->fileno)) ||
1238f48205beScasper 	    (! xdr_u_int(xdrs, &rec->uid)))
12397c478bd9Sstevel@tonic-gate 		return (FALSE);
12407c478bd9Sstevel@tonic-gate 
12417c478bd9Sstevel@tonic-gate 	return (TRUE);
12427c478bd9Sstevel@tonic-gate }
12437c478bd9Sstevel@tonic-gate 
12447c478bd9Sstevel@tonic-gate void
cachefs_log_rename(cachefscache_t * cachep,int Errno,struct vfs * vfsp,fid_t * gfp,ino64_t fileno,int removed,uid_t uid)12457c478bd9Sstevel@tonic-gate cachefs_log_rename(cachefscache_t *cachep, int Errno, struct vfs *vfsp,
12467c478bd9Sstevel@tonic-gate     fid_t *gfp, ino64_t fileno, int removed, uid_t uid)
12477c478bd9Sstevel@tonic-gate {
12487c478bd9Sstevel@tonic-gate 	struct cachefs_log_rename_record *record;
12497c478bd9Sstevel@tonic-gate 
12507c478bd9Sstevel@tonic-gate 	/* In Solaris 64 - if can't represent time don't bother */
12517c478bd9Sstevel@tonic-gate 	RET_IF_TIME_OVERFLOW(cachep, time)
12527c478bd9Sstevel@tonic-gate 	record = cachefs_kmem_zalloc(sizeof (*record), KM_NOSLEEP);
12537c478bd9Sstevel@tonic-gate 	if (record == NULL) {
12547c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 1);
12557c478bd9Sstevel@tonic-gate 		return;
12567c478bd9Sstevel@tonic-gate 	}
12577c478bd9Sstevel@tonic-gate 
12587c478bd9Sstevel@tonic-gate 	record->type = CACHEFS_LOG_RENAME;
12597c478bd9Sstevel@tonic-gate 	record->time = time;
12607c478bd9Sstevel@tonic-gate 
12617c478bd9Sstevel@tonic-gate 	record->error = Errno;
12627c478bd9Sstevel@tonic-gate 	record->vfsp = (uint64_t)(uintptr_t)vfsp;
12637c478bd9Sstevel@tonic-gate 	if (gfp != NULL) {
12647c478bd9Sstevel@tonic-gate 		CACHEFS_FID_COPY(gfp, &record->gone);
12657c478bd9Sstevel@tonic-gate 	}
12667c478bd9Sstevel@tonic-gate 	record->fileno = fileno;
12677c478bd9Sstevel@tonic-gate 	record->removed = removed;
12687c478bd9Sstevel@tonic-gate 	record->uid = uid;
12697c478bd9Sstevel@tonic-gate 
12707c478bd9Sstevel@tonic-gate 	cachefs_log_enqueue(cachep, record, (int)sizeof (*record),
12717c478bd9Sstevel@tonic-gate 	    cachefs_xdr_rename);
12727c478bd9Sstevel@tonic-gate }
12737c478bd9Sstevel@tonic-gate 
12747c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_rename(XDR * xdrs,struct cachefs_log_rename_record * rec)12757c478bd9Sstevel@tonic-gate cachefs_xdr_rename(XDR *xdrs, struct cachefs_log_rename_record *rec)
12767c478bd9Sstevel@tonic-gate {
12777c478bd9Sstevel@tonic-gate 	if ((! xdr_int(xdrs, &rec->type)) ||
12787c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->error)) ||
12797c478bd9Sstevel@tonic-gate 	    (! xdr_cfs_time_t(xdrs, &rec->time)) ||
12807c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->vfsp, sizeof (rec->vfsp))) ||
12817c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->gone, sizeof (rec->gone))) ||
12827c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->removed)) ||
1283f48205beScasper 	    (! xdr_u_int(xdrs, &rec->uid)))
12847c478bd9Sstevel@tonic-gate 		return (FALSE);
12857c478bd9Sstevel@tonic-gate 
12867c478bd9Sstevel@tonic-gate 	return (TRUE);
12877c478bd9Sstevel@tonic-gate }
12887c478bd9Sstevel@tonic-gate 
12897c478bd9Sstevel@tonic-gate 
12907c478bd9Sstevel@tonic-gate void
cachefs_log_symlink(cachefscache_t * cachep,int Errno,struct vfs * vfsp,fid_t * fidp,ino64_t fileno,uid_t uid,int size)12917c478bd9Sstevel@tonic-gate cachefs_log_symlink(cachefscache_t *cachep, int Errno, struct vfs *vfsp,
12927c478bd9Sstevel@tonic-gate     fid_t *fidp, ino64_t fileno, uid_t uid, int size)
12937c478bd9Sstevel@tonic-gate {
12947c478bd9Sstevel@tonic-gate 	struct cachefs_log_symlink_record *record;
12957c478bd9Sstevel@tonic-gate 
12967c478bd9Sstevel@tonic-gate 	/* In Solaris 64 - if can't represent time don't bother */
12977c478bd9Sstevel@tonic-gate 	RET_IF_TIME_OVERFLOW(cachep, time)
12987c478bd9Sstevel@tonic-gate 	record = cachefs_kmem_zalloc(sizeof (*record), KM_NOSLEEP);
12997c478bd9Sstevel@tonic-gate 	if (record == NULL) {
13007c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 1);
13017c478bd9Sstevel@tonic-gate 		return;
13027c478bd9Sstevel@tonic-gate 	}
13037c478bd9Sstevel@tonic-gate 
13047c478bd9Sstevel@tonic-gate 	record->type = CACHEFS_LOG_SYMLINK;
13057c478bd9Sstevel@tonic-gate 	record->time = time;
13067c478bd9Sstevel@tonic-gate 
13077c478bd9Sstevel@tonic-gate 	record->error = Errno;
13087c478bd9Sstevel@tonic-gate 	record->vfsp = (uint64_t)(uintptr_t)vfsp;
13097c478bd9Sstevel@tonic-gate 	if (fidp != NULL) {
13107c478bd9Sstevel@tonic-gate 		CACHEFS_FID_COPY(fidp, &record->fid);
13117c478bd9Sstevel@tonic-gate 	}
13127c478bd9Sstevel@tonic-gate 	record->fileno = fileno;
13137c478bd9Sstevel@tonic-gate 	record->uid = uid;
13147c478bd9Sstevel@tonic-gate 	record->size = size;
13157c478bd9Sstevel@tonic-gate 
13167c478bd9Sstevel@tonic-gate 	cachefs_log_enqueue(cachep, record, (int)sizeof (*record),
13177c478bd9Sstevel@tonic-gate 	    cachefs_xdr_symlink);
13187c478bd9Sstevel@tonic-gate }
13197c478bd9Sstevel@tonic-gate 
13207c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_symlink(XDR * xdrs,struct cachefs_log_symlink_record * rec)13217c478bd9Sstevel@tonic-gate cachefs_xdr_symlink(XDR *xdrs, struct cachefs_log_symlink_record *rec)
13227c478bd9Sstevel@tonic-gate {
13237c478bd9Sstevel@tonic-gate 	if ((! xdr_int(xdrs, &rec->type)) ||
13247c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->error)) ||
13257c478bd9Sstevel@tonic-gate 	    (! xdr_cfs_time_t(xdrs, &rec->time)) ||
13267c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->vfsp, sizeof (rec->vfsp))) ||
13277c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->fid, sizeof (rec->fid))) ||
13287c478bd9Sstevel@tonic-gate 	    (! xdr_ino64(xdrs, &rec->fileno)) ||
1329f48205beScasper 	    (! xdr_u_int(xdrs, &rec->uid)) ||
13307c478bd9Sstevel@tonic-gate 	    (! xdr_u_int(xdrs, &rec->size)))
13317c478bd9Sstevel@tonic-gate 		return (FALSE);
13327c478bd9Sstevel@tonic-gate 
13337c478bd9Sstevel@tonic-gate 	return (TRUE);
13347c478bd9Sstevel@tonic-gate }
13357c478bd9Sstevel@tonic-gate 
13367c478bd9Sstevel@tonic-gate void
cachefs_log_populate(cachefscache_t * cachep,int Errno,struct vfs * vfsp,fid_t * fidp,ino64_t fileno,u_offset_t off,size_t popsize)13377c478bd9Sstevel@tonic-gate cachefs_log_populate(cachefscache_t *cachep, int Errno, struct vfs *vfsp,
13387c478bd9Sstevel@tonic-gate     fid_t *fidp, ino64_t fileno, u_offset_t off, size_t popsize)
13397c478bd9Sstevel@tonic-gate {
13407c478bd9Sstevel@tonic-gate 	struct cachefs_log_populate_record *record;
13417c478bd9Sstevel@tonic-gate 
13427c478bd9Sstevel@tonic-gate 	/* In Solaris 64 - if can't represent time don't bother */
13437c478bd9Sstevel@tonic-gate 	RET_IF_TIME_OVERFLOW(cachep, time)
13447c478bd9Sstevel@tonic-gate 	record = cachefs_kmem_zalloc(sizeof (*record), KM_NOSLEEP);
13457c478bd9Sstevel@tonic-gate 	if (record == NULL) {
13467c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 1);
13477c478bd9Sstevel@tonic-gate 		return;
13487c478bd9Sstevel@tonic-gate 	}
13497c478bd9Sstevel@tonic-gate 
13507c478bd9Sstevel@tonic-gate 	record->type = CACHEFS_LOG_POPULATE;
13517c478bd9Sstevel@tonic-gate 	record->time = time;
13527c478bd9Sstevel@tonic-gate 	record->error = Errno;
13537c478bd9Sstevel@tonic-gate 
13547c478bd9Sstevel@tonic-gate 	record->vfsp = (uint64_t)(uintptr_t)vfsp;
13557c478bd9Sstevel@tonic-gate 	if (fidp != NULL) {
13567c478bd9Sstevel@tonic-gate 		CACHEFS_FID_COPY(fidp, &record->fid);
13577c478bd9Sstevel@tonic-gate 	}
13587c478bd9Sstevel@tonic-gate 	record->fileno = fileno;
13597c478bd9Sstevel@tonic-gate 	record->off = off;
13607c478bd9Sstevel@tonic-gate 	record->size = (int)popsize;
13617c478bd9Sstevel@tonic-gate 
13627c478bd9Sstevel@tonic-gate 	cachefs_log_enqueue(cachep, record, (int)sizeof (*record),
13637c478bd9Sstevel@tonic-gate 	    cachefs_xdr_populate);
13647c478bd9Sstevel@tonic-gate }
13657c478bd9Sstevel@tonic-gate 
13667c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_populate(XDR * xdrs,struct cachefs_log_populate_record * rec)13677c478bd9Sstevel@tonic-gate cachefs_xdr_populate(XDR *xdrs, struct cachefs_log_populate_record *rec)
13687c478bd9Sstevel@tonic-gate {
13697c478bd9Sstevel@tonic-gate 	if ((! xdr_int(xdrs, &rec->type)) ||
13707c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->error)) ||
13717c478bd9Sstevel@tonic-gate 	    (! xdr_cfs_time_t(xdrs, &rec->time)) ||
13727c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->vfsp, sizeof (rec->vfsp))) ||
13737c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->fid, sizeof (rec->fid))) ||
13747c478bd9Sstevel@tonic-gate 	    (! xdr_ino64(xdrs, &rec->fileno)) ||
13757c478bd9Sstevel@tonic-gate 	    (! xdr_u_longlong_t(xdrs, (u_longlong_t *)&rec->off)) ||
13767c478bd9Sstevel@tonic-gate 	    (! xdr_u_int(xdrs, &rec->size)))
13777c478bd9Sstevel@tonic-gate 		return (FALSE);
13787c478bd9Sstevel@tonic-gate 
13797c478bd9Sstevel@tonic-gate 	return (TRUE);
13807c478bd9Sstevel@tonic-gate }
13817c478bd9Sstevel@tonic-gate 
13827c478bd9Sstevel@tonic-gate void
cachefs_log_csymlink(cachefscache_t * cachep,int Errno,struct vfs * vfsp,fid_t * fidp,ino64_t fileno,int size)13837c478bd9Sstevel@tonic-gate cachefs_log_csymlink(cachefscache_t *cachep, int Errno, struct vfs *vfsp,
13847c478bd9Sstevel@tonic-gate     fid_t *fidp, ino64_t fileno, int size)
13857c478bd9Sstevel@tonic-gate {
13867c478bd9Sstevel@tonic-gate 	struct cachefs_log_csymlink_record *record;
13877c478bd9Sstevel@tonic-gate 
13887c478bd9Sstevel@tonic-gate 	/* In Solaris 64 - if can't represent time don't bother */
13897c478bd9Sstevel@tonic-gate 	RET_IF_TIME_OVERFLOW(cachep, time)
13907c478bd9Sstevel@tonic-gate 	record = cachefs_kmem_zalloc(sizeof (*record), KM_NOSLEEP);
13917c478bd9Sstevel@tonic-gate 	if (record == NULL) {
13927c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 1);
13937c478bd9Sstevel@tonic-gate 		return;
13947c478bd9Sstevel@tonic-gate 	}
13957c478bd9Sstevel@tonic-gate 
13967c478bd9Sstevel@tonic-gate 	record->type = CACHEFS_LOG_CSYMLINK;
13977c478bd9Sstevel@tonic-gate 	record->time = time;
13987c478bd9Sstevel@tonic-gate 	record->error = Errno;
13997c478bd9Sstevel@tonic-gate 
14007c478bd9Sstevel@tonic-gate 	record->vfsp = (uint64_t)(uintptr_t)vfsp;
14017c478bd9Sstevel@tonic-gate 	if (fidp != NULL) {
14027c478bd9Sstevel@tonic-gate 		CACHEFS_FID_COPY(fidp, &record->fid);
14037c478bd9Sstevel@tonic-gate 	}
14047c478bd9Sstevel@tonic-gate 	record->fileno = fileno;
14057c478bd9Sstevel@tonic-gate 	record->size = size;
14067c478bd9Sstevel@tonic-gate 
14077c478bd9Sstevel@tonic-gate 	cachefs_log_enqueue(cachep, record, (int)sizeof (*record),
14087c478bd9Sstevel@tonic-gate 	    cachefs_xdr_csymlink);
14097c478bd9Sstevel@tonic-gate }
14107c478bd9Sstevel@tonic-gate 
14117c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_csymlink(XDR * xdrs,struct cachefs_log_csymlink_record * rec)14127c478bd9Sstevel@tonic-gate cachefs_xdr_csymlink(XDR *xdrs, struct cachefs_log_csymlink_record *rec)
14137c478bd9Sstevel@tonic-gate {
14147c478bd9Sstevel@tonic-gate 	if ((! xdr_int(xdrs, &rec->type)) ||
14157c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->error)) ||
14167c478bd9Sstevel@tonic-gate 	    (! xdr_cfs_time_t(xdrs, &rec->time)) ||
14177c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->vfsp, sizeof (rec->vfsp))) ||
14187c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->fid, sizeof (rec->fid))) ||
14197c478bd9Sstevel@tonic-gate 	    (! xdr_ino64(xdrs, &rec->fileno)) ||
14207c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->size)))
14217c478bd9Sstevel@tonic-gate 		return (FALSE);
14227c478bd9Sstevel@tonic-gate 
14237c478bd9Sstevel@tonic-gate 	return (TRUE);
14247c478bd9Sstevel@tonic-gate }
14257c478bd9Sstevel@tonic-gate 
14267c478bd9Sstevel@tonic-gate void
cachefs_log_filldir(cachefscache_t * cachep,int Errno,struct vfs * vfsp,fid_t * fidp,ino64_t fileno,u_offset_t size)14277c478bd9Sstevel@tonic-gate cachefs_log_filldir(cachefscache_t *cachep, int Errno, struct vfs *vfsp,
14287c478bd9Sstevel@tonic-gate     fid_t *fidp, ino64_t fileno, u_offset_t size)
14297c478bd9Sstevel@tonic-gate {
14307c478bd9Sstevel@tonic-gate 	struct cachefs_log_filldir_record *record;
14317c478bd9Sstevel@tonic-gate 
14327c478bd9Sstevel@tonic-gate 	/* In Solaris 64 - if can't represent time don't bother */
14337c478bd9Sstevel@tonic-gate 	RET_IF_TIME_OVERFLOW(cachep, time)
14347c478bd9Sstevel@tonic-gate 	record = cachefs_kmem_zalloc(sizeof (*record), KM_NOSLEEP);
14357c478bd9Sstevel@tonic-gate 	if (record == NULL) {
14367c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 1);
14377c478bd9Sstevel@tonic-gate 		return;
14387c478bd9Sstevel@tonic-gate 	}
14397c478bd9Sstevel@tonic-gate 
14407c478bd9Sstevel@tonic-gate 	record->type = CACHEFS_LOG_FILLDIR;
14417c478bd9Sstevel@tonic-gate 	record->time = time;
14427c478bd9Sstevel@tonic-gate 	record->error = Errno;
14437c478bd9Sstevel@tonic-gate 
14447c478bd9Sstevel@tonic-gate 	record->vfsp = (uint64_t)(uintptr_t)vfsp;
14457c478bd9Sstevel@tonic-gate 	if (fidp != NULL) {
14467c478bd9Sstevel@tonic-gate 		CACHEFS_FID_COPY(fidp, &record->fid);
14477c478bd9Sstevel@tonic-gate 	}
14487c478bd9Sstevel@tonic-gate 	record->fileno = fileno;
14497c478bd9Sstevel@tonic-gate 	record->size = (uint_t)size;
14507c478bd9Sstevel@tonic-gate 
14517c478bd9Sstevel@tonic-gate 	cachefs_log_enqueue(cachep, record, (int)sizeof (*record),
14527c478bd9Sstevel@tonic-gate 	    cachefs_xdr_filldir);
14537c478bd9Sstevel@tonic-gate }
14547c478bd9Sstevel@tonic-gate 
14557c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_filldir(XDR * xdrs,struct cachefs_log_filldir_record * rec)14567c478bd9Sstevel@tonic-gate cachefs_xdr_filldir(XDR *xdrs, struct cachefs_log_filldir_record *rec)
14577c478bd9Sstevel@tonic-gate {
14587c478bd9Sstevel@tonic-gate 	if ((! xdr_int(xdrs, &rec->type)) ||
14597c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->error)) ||
14607c478bd9Sstevel@tonic-gate 	    (! xdr_cfs_time_t(xdrs, &rec->time)) ||
14617c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->vfsp, sizeof (rec->vfsp))) ||
14627c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->fid, sizeof (rec->fid))) ||
14637c478bd9Sstevel@tonic-gate 	    (! xdr_ino64(xdrs, &rec->fileno)) ||
14647c478bd9Sstevel@tonic-gate 	    (! xdr_u_int(xdrs, (uint_t *)&rec->size)))
14657c478bd9Sstevel@tonic-gate 		return (FALSE);
14667c478bd9Sstevel@tonic-gate 
14677c478bd9Sstevel@tonic-gate 	return (TRUE);
14687c478bd9Sstevel@tonic-gate }
14697c478bd9Sstevel@tonic-gate 
14707c478bd9Sstevel@tonic-gate void
cachefs_log_mdcreate(cachefscache_t * cachep,int Errno,struct vfs * vfsp,fid_t * fidp,ino64_t fileno,uint_t count)14717c478bd9Sstevel@tonic-gate cachefs_log_mdcreate(cachefscache_t *cachep, int Errno, struct vfs *vfsp,
14727c478bd9Sstevel@tonic-gate     fid_t *fidp, ino64_t fileno, uint_t count)
14737c478bd9Sstevel@tonic-gate {
14747c478bd9Sstevel@tonic-gate 	struct cachefs_log_mdcreate_record *record;
14757c478bd9Sstevel@tonic-gate 
14767c478bd9Sstevel@tonic-gate 	/* In Solaris 64 - if can't represent time don't bother */
14777c478bd9Sstevel@tonic-gate 	RET_IF_TIME_OVERFLOW(cachep, time)
14787c478bd9Sstevel@tonic-gate 	record = cachefs_kmem_zalloc(sizeof (*record), KM_NOSLEEP);
14797c478bd9Sstevel@tonic-gate 	if (record == NULL) {
14807c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 1);
14817c478bd9Sstevel@tonic-gate 		return;
14827c478bd9Sstevel@tonic-gate 	}
14837c478bd9Sstevel@tonic-gate 
14847c478bd9Sstevel@tonic-gate 	record->type = CACHEFS_LOG_MDCREATE;
14857c478bd9Sstevel@tonic-gate 	record->time = time;
14867c478bd9Sstevel@tonic-gate 	record->error = Errno;
14877c478bd9Sstevel@tonic-gate 
14887c478bd9Sstevel@tonic-gate 	record->vfsp = (uint64_t)(uintptr_t)vfsp;
14897c478bd9Sstevel@tonic-gate 	if (fidp != NULL) {
14907c478bd9Sstevel@tonic-gate 		CACHEFS_FID_COPY(fidp, &record->fid);
14917c478bd9Sstevel@tonic-gate 	}
14927c478bd9Sstevel@tonic-gate 	record->fileno = fileno;
14937c478bd9Sstevel@tonic-gate 	record->count = count;
14947c478bd9Sstevel@tonic-gate 
14957c478bd9Sstevel@tonic-gate 	cachefs_log_enqueue(cachep, record, (int)sizeof (*record),
14967c478bd9Sstevel@tonic-gate 	    cachefs_xdr_mdcreate);
14977c478bd9Sstevel@tonic-gate }
14987c478bd9Sstevel@tonic-gate 
14997c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_mdcreate(XDR * xdrs,struct cachefs_log_mdcreate_record * rec)15007c478bd9Sstevel@tonic-gate cachefs_xdr_mdcreate(XDR *xdrs, struct cachefs_log_mdcreate_record *rec)
15017c478bd9Sstevel@tonic-gate {
15027c478bd9Sstevel@tonic-gate 	if ((! xdr_int(xdrs, &rec->type)) ||
15037c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->error)) ||
15047c478bd9Sstevel@tonic-gate 	    (! xdr_cfs_time_t(xdrs, &rec->time)) ||
15057c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->vfsp, sizeof (rec->vfsp))) ||
15067c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->fid, sizeof (rec->fid))) ||
15077c478bd9Sstevel@tonic-gate 	    (! xdr_ino64(xdrs, &rec->fileno)) ||
15087c478bd9Sstevel@tonic-gate 	    (! xdr_u_int(xdrs, &rec->count)))
15097c478bd9Sstevel@tonic-gate 		return (FALSE);
15107c478bd9Sstevel@tonic-gate 
15117c478bd9Sstevel@tonic-gate 	return (TRUE);
15127c478bd9Sstevel@tonic-gate }
15137c478bd9Sstevel@tonic-gate 
15147c478bd9Sstevel@tonic-gate void
cachefs_log_gpfront(cachefscache_t * cachep,int Errno,struct vfs * vfsp,fid_t * fidp,ino64_t fileno,uid_t uid,u_offset_t offset,uint_t len)15157c478bd9Sstevel@tonic-gate cachefs_log_gpfront(cachefscache_t *cachep, int Errno, struct vfs *vfsp,
15167c478bd9Sstevel@tonic-gate     fid_t *fidp, ino64_t fileno, uid_t uid, u_offset_t offset, uint_t len)
15177c478bd9Sstevel@tonic-gate {
15187c478bd9Sstevel@tonic-gate 	struct cachefs_log_gpfront_record *record;
15197c478bd9Sstevel@tonic-gate 
15207c478bd9Sstevel@tonic-gate 	/* In Solaris 64 - if can't represent time don't bother */
15217c478bd9Sstevel@tonic-gate 	RET_IF_TIME_OVERFLOW(cachep, time)
15227c478bd9Sstevel@tonic-gate 	record = cachefs_kmem_zalloc(sizeof (*record), KM_NOSLEEP);
15237c478bd9Sstevel@tonic-gate 	if (record == NULL) {
15247c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 1);
15257c478bd9Sstevel@tonic-gate 		return;
15267c478bd9Sstevel@tonic-gate 	}
15277c478bd9Sstevel@tonic-gate 
15287c478bd9Sstevel@tonic-gate 	record->type = CACHEFS_LOG_GPFRONT;
15297c478bd9Sstevel@tonic-gate 	record->time = time;
15307c478bd9Sstevel@tonic-gate 	record->error = Errno;
15317c478bd9Sstevel@tonic-gate 
15327c478bd9Sstevel@tonic-gate 	record->vfsp = (uint64_t)(uintptr_t)vfsp;
15337c478bd9Sstevel@tonic-gate 	if (fidp != NULL) {
15347c478bd9Sstevel@tonic-gate 		CACHEFS_FID_COPY(fidp, &record->fid);
15357c478bd9Sstevel@tonic-gate 	}
15367c478bd9Sstevel@tonic-gate 	record->fileno = fileno;
15377c478bd9Sstevel@tonic-gate 	record->uid = uid;
15387c478bd9Sstevel@tonic-gate 	record->off = offset;
15397c478bd9Sstevel@tonic-gate 	record->len = len;
15407c478bd9Sstevel@tonic-gate 
15417c478bd9Sstevel@tonic-gate 	cachefs_log_enqueue(cachep, record, (int)sizeof (*record),
15427c478bd9Sstevel@tonic-gate 	    cachefs_xdr_gpfront);
15437c478bd9Sstevel@tonic-gate }
15447c478bd9Sstevel@tonic-gate 
15457c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_gpfront(XDR * xdrs,struct cachefs_log_gpfront_record * rec)15467c478bd9Sstevel@tonic-gate cachefs_xdr_gpfront(XDR *xdrs, struct cachefs_log_gpfront_record *rec)
15477c478bd9Sstevel@tonic-gate {
15487c478bd9Sstevel@tonic-gate 	if ((! xdr_int(xdrs, &rec->type)) ||
15497c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->error)) ||
15507c478bd9Sstevel@tonic-gate 	    (! xdr_cfs_time_t(xdrs, &rec->time)) ||
15517c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->vfsp, sizeof (rec->vfsp))) ||
15527c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->fid, sizeof (rec->fid))) ||
15537c478bd9Sstevel@tonic-gate 	    (! xdr_ino64(xdrs, &rec->fileno)) ||
1554f48205beScasper 	    (! xdr_u_int(xdrs, &rec->uid)) ||
15557c478bd9Sstevel@tonic-gate 	    (! xdr_u_longlong_t(xdrs, (u_longlong_t *)&rec->off)) ||
15567c478bd9Sstevel@tonic-gate 	    (! xdr_u_int(xdrs, &rec->len)))
15577c478bd9Sstevel@tonic-gate 		return (FALSE);
15587c478bd9Sstevel@tonic-gate 
15597c478bd9Sstevel@tonic-gate 	return (TRUE);
15607c478bd9Sstevel@tonic-gate }
15617c478bd9Sstevel@tonic-gate 
15627c478bd9Sstevel@tonic-gate void
cachefs_log_rfdir(cachefscache_t * cachep,int Errno,struct vfs * vfsp,fid_t * fidp,ino64_t fileno,uid_t uid)15637c478bd9Sstevel@tonic-gate cachefs_log_rfdir(cachefscache_t *cachep, int Errno, struct vfs *vfsp,
15647c478bd9Sstevel@tonic-gate     fid_t *fidp, ino64_t fileno, uid_t uid)
15657c478bd9Sstevel@tonic-gate {
15667c478bd9Sstevel@tonic-gate 	struct cachefs_log_rfdir_record *record;
15677c478bd9Sstevel@tonic-gate 
15687c478bd9Sstevel@tonic-gate 	/* In Solaris 64 - if can't represent time don't bother */
15697c478bd9Sstevel@tonic-gate 	RET_IF_TIME_OVERFLOW(cachep, time)
15707c478bd9Sstevel@tonic-gate 	record = cachefs_kmem_zalloc(sizeof (*record), KM_NOSLEEP);
15717c478bd9Sstevel@tonic-gate 	if (record == NULL) {
15727c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 1);
15737c478bd9Sstevel@tonic-gate 		return;
15747c478bd9Sstevel@tonic-gate 	}
15757c478bd9Sstevel@tonic-gate 
15767c478bd9Sstevel@tonic-gate 	record->type = CACHEFS_LOG_RFDIR;
15777c478bd9Sstevel@tonic-gate 	record->time = time;
15787c478bd9Sstevel@tonic-gate 	record->error = Errno;
15797c478bd9Sstevel@tonic-gate 
15807c478bd9Sstevel@tonic-gate 	record->vfsp = (uint64_t)(uintptr_t)vfsp;
15817c478bd9Sstevel@tonic-gate 	if (fidp != NULL) {
15827c478bd9Sstevel@tonic-gate 		CACHEFS_FID_COPY(fidp, &record->fid);
15837c478bd9Sstevel@tonic-gate 	}
15847c478bd9Sstevel@tonic-gate 	record->fileno = fileno;
15857c478bd9Sstevel@tonic-gate 	record->uid = uid;
15867c478bd9Sstevel@tonic-gate 
15877c478bd9Sstevel@tonic-gate 	cachefs_log_enqueue(cachep, record, (int)sizeof (*record),
15887c478bd9Sstevel@tonic-gate 	    cachefs_xdr_rfdir);
15897c478bd9Sstevel@tonic-gate }
15907c478bd9Sstevel@tonic-gate 
15917c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_rfdir(XDR * xdrs,struct cachefs_log_rfdir_record * rec)15927c478bd9Sstevel@tonic-gate cachefs_xdr_rfdir(XDR *xdrs, struct cachefs_log_rfdir_record *rec)
15937c478bd9Sstevel@tonic-gate {
15947c478bd9Sstevel@tonic-gate 	if ((! xdr_int(xdrs, &rec->type)) ||
15957c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->error)) ||
15967c478bd9Sstevel@tonic-gate 	    (! xdr_cfs_time_t(xdrs, &rec->time)) ||
15977c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->vfsp, sizeof (rec->vfsp))) ||
15987c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->fid, sizeof (rec->fid))) ||
15997c478bd9Sstevel@tonic-gate 	    (! xdr_ino64(xdrs, &rec->fileno)) ||
1600f48205beScasper 	    (! xdr_u_int(xdrs, &rec->uid)))
16017c478bd9Sstevel@tonic-gate 		return (FALSE);
16027c478bd9Sstevel@tonic-gate 
16037c478bd9Sstevel@tonic-gate 	return (TRUE);
16047c478bd9Sstevel@tonic-gate }
16057c478bd9Sstevel@tonic-gate 
16067c478bd9Sstevel@tonic-gate void
cachefs_log_ualloc(cachefscache_t * cachep,int Errno,struct vfs * vfsp,fid_t * fidp,ino64_t fileno,u_offset_t off,size_t len)16077c478bd9Sstevel@tonic-gate cachefs_log_ualloc(cachefscache_t *cachep, int Errno, struct vfs *vfsp,
16087c478bd9Sstevel@tonic-gate     fid_t *fidp, ino64_t fileno, u_offset_t off, size_t len)
16097c478bd9Sstevel@tonic-gate {
16107c478bd9Sstevel@tonic-gate 	struct cachefs_log_ualloc_record *record;
16117c478bd9Sstevel@tonic-gate 
16127c478bd9Sstevel@tonic-gate 	/* In Solaris 64 - if can't represent time don't bother */
16137c478bd9Sstevel@tonic-gate 	RET_IF_TIME_OVERFLOW(cachep, time)
16147c478bd9Sstevel@tonic-gate 	record = cachefs_kmem_zalloc(sizeof (*record), KM_NOSLEEP);
16157c478bd9Sstevel@tonic-gate 	if (record == NULL) {
16167c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 1);
16177c478bd9Sstevel@tonic-gate 		return;
16187c478bd9Sstevel@tonic-gate 	}
16197c478bd9Sstevel@tonic-gate 
16207c478bd9Sstevel@tonic-gate 	record->type = CACHEFS_LOG_UALLOC;
16217c478bd9Sstevel@tonic-gate 	record->time = time;
16227c478bd9Sstevel@tonic-gate 	record->error = Errno;
16237c478bd9Sstevel@tonic-gate 
16247c478bd9Sstevel@tonic-gate 	record->vfsp = (uint64_t)(uintptr_t)vfsp;
16257c478bd9Sstevel@tonic-gate 	if (fidp != NULL) {
16267c478bd9Sstevel@tonic-gate 		CACHEFS_FID_COPY(fidp, &record->fid);
16277c478bd9Sstevel@tonic-gate 	}
16287c478bd9Sstevel@tonic-gate 	record->fileno = fileno;
16297c478bd9Sstevel@tonic-gate 	record->off = off;
16307c478bd9Sstevel@tonic-gate 	record->len = (uint_t)len;
16317c478bd9Sstevel@tonic-gate 
16327c478bd9Sstevel@tonic-gate 	cachefs_log_enqueue(cachep, record, (int)sizeof (*record),
16337c478bd9Sstevel@tonic-gate 	    cachefs_xdr_ualloc);
16347c478bd9Sstevel@tonic-gate }
16357c478bd9Sstevel@tonic-gate 
16367c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_ualloc(XDR * xdrs,struct cachefs_log_ualloc_record * rec)16377c478bd9Sstevel@tonic-gate cachefs_xdr_ualloc(XDR *xdrs, struct cachefs_log_ualloc_record *rec)
16387c478bd9Sstevel@tonic-gate {
16397c478bd9Sstevel@tonic-gate 	if ((! xdr_int(xdrs, &rec->type)) ||
16407c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->error)) ||
16417c478bd9Sstevel@tonic-gate 	    (! xdr_cfs_time_t(xdrs, &rec->time)) ||
16427c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->vfsp, sizeof (rec->vfsp))) ||
16437c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->fid, sizeof (rec->fid))) ||
16447c478bd9Sstevel@tonic-gate 	    (! xdr_ino64(xdrs, &rec->fileno)) ||
16457c478bd9Sstevel@tonic-gate 	    (! xdr_u_longlong_t(xdrs, (u_longlong_t *)&rec->off)) ||
16467c478bd9Sstevel@tonic-gate 	    (! xdr_u_int(xdrs, (uint_t *)&rec->len)))
16477c478bd9Sstevel@tonic-gate 		return (FALSE);
16487c478bd9Sstevel@tonic-gate 
16497c478bd9Sstevel@tonic-gate 	return (TRUE);
16507c478bd9Sstevel@tonic-gate }
16517c478bd9Sstevel@tonic-gate 
16527c478bd9Sstevel@tonic-gate void
cachefs_log_calloc(cachefscache_t * cachep,int Errno,struct vfs * vfsp,fid_t * fidp,ino64_t fileno,u_offset_t off,size_t len)16537c478bd9Sstevel@tonic-gate cachefs_log_calloc(cachefscache_t *cachep, int Errno, struct vfs *vfsp,
16547c478bd9Sstevel@tonic-gate     fid_t *fidp, ino64_t fileno, u_offset_t off, size_t len)
16557c478bd9Sstevel@tonic-gate {
16567c478bd9Sstevel@tonic-gate 	struct cachefs_log_calloc_record *record;
16577c478bd9Sstevel@tonic-gate 
16587c478bd9Sstevel@tonic-gate 	/* In Solaris 64 - if can't represent time don't bother */
16597c478bd9Sstevel@tonic-gate 	RET_IF_TIME_OVERFLOW(cachep, time)
16607c478bd9Sstevel@tonic-gate 	record = cachefs_kmem_zalloc(sizeof (*record), KM_NOSLEEP);
16617c478bd9Sstevel@tonic-gate 	if (record == NULL) {
16627c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 1);
16637c478bd9Sstevel@tonic-gate 		return;
16647c478bd9Sstevel@tonic-gate 	}
16657c478bd9Sstevel@tonic-gate 
16667c478bd9Sstevel@tonic-gate 	record->type = CACHEFS_LOG_CALLOC;
16677c478bd9Sstevel@tonic-gate 	record->time = time;
16687c478bd9Sstevel@tonic-gate 	record->error = Errno;
16697c478bd9Sstevel@tonic-gate 
16707c478bd9Sstevel@tonic-gate 	record->vfsp = (uint64_t)(uintptr_t)vfsp;
16717c478bd9Sstevel@tonic-gate 	if (fidp != NULL) {
16727c478bd9Sstevel@tonic-gate 		CACHEFS_FID_COPY(fidp, &record->fid);
16737c478bd9Sstevel@tonic-gate 	}
16747c478bd9Sstevel@tonic-gate 	record->fileno = fileno;
16757c478bd9Sstevel@tonic-gate 	record->off = off;
16767c478bd9Sstevel@tonic-gate 	record->len = (uint_t)len;
16777c478bd9Sstevel@tonic-gate 
16787c478bd9Sstevel@tonic-gate 	cachefs_log_enqueue(cachep, record, (int)sizeof (*record),
16797c478bd9Sstevel@tonic-gate 	    cachefs_xdr_calloc);
16807c478bd9Sstevel@tonic-gate }
16817c478bd9Sstevel@tonic-gate 
16827c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_calloc(XDR * xdrs,struct cachefs_log_calloc_record * rec)16837c478bd9Sstevel@tonic-gate cachefs_xdr_calloc(XDR *xdrs, struct cachefs_log_calloc_record *rec)
16847c478bd9Sstevel@tonic-gate {
16857c478bd9Sstevel@tonic-gate 	if ((! xdr_int(xdrs, &rec->type)) ||
16867c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->error)) ||
16877c478bd9Sstevel@tonic-gate 	    (! xdr_cfs_time_t(xdrs, &rec->time)) ||
16887c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->vfsp, sizeof (rec->vfsp))) ||
16897c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->fid, sizeof (rec->fid))) ||
16907c478bd9Sstevel@tonic-gate 	    (! xdr_ino64(xdrs, &rec->fileno)) ||
16917c478bd9Sstevel@tonic-gate 	    (! xdr_u_longlong_t(xdrs, (u_longlong_t *)&rec->off)) ||
16927c478bd9Sstevel@tonic-gate 	    (! xdr_u_int(xdrs, &rec->len)))
16937c478bd9Sstevel@tonic-gate 		return (FALSE);
16947c478bd9Sstevel@tonic-gate 
16957c478bd9Sstevel@tonic-gate 	return (TRUE);
16967c478bd9Sstevel@tonic-gate }
16977c478bd9Sstevel@tonic-gate 
16987c478bd9Sstevel@tonic-gate void
cachefs_log_nocache(cachefscache_t * cachep,int Errno,struct vfs * vfsp,fid_t * fidp,ino64_t fileno)16997c478bd9Sstevel@tonic-gate cachefs_log_nocache(cachefscache_t *cachep, int Errno, struct vfs *vfsp,
17007c478bd9Sstevel@tonic-gate     fid_t *fidp, ino64_t fileno)
17017c478bd9Sstevel@tonic-gate {
17027c478bd9Sstevel@tonic-gate 	struct cachefs_log_nocache_record *record;
17037c478bd9Sstevel@tonic-gate 
17047c478bd9Sstevel@tonic-gate 	/* In Solaris 64 - if can't represent time don't bother */
17057c478bd9Sstevel@tonic-gate 	RET_IF_TIME_OVERFLOW(cachep, time)
17067c478bd9Sstevel@tonic-gate 	record = cachefs_kmem_zalloc(sizeof (*record), KM_NOSLEEP);
17077c478bd9Sstevel@tonic-gate 	if (record == NULL) {
17087c478bd9Sstevel@tonic-gate 		cachefs_log_error(cachep, ENOMEM, 1);
17097c478bd9Sstevel@tonic-gate 		return;
17107c478bd9Sstevel@tonic-gate 	}
17117c478bd9Sstevel@tonic-gate 
17127c478bd9Sstevel@tonic-gate 	record->type = CACHEFS_LOG_NOCACHE;
17137c478bd9Sstevel@tonic-gate 	record->time = time;
17147c478bd9Sstevel@tonic-gate 	record->error = Errno;
17157c478bd9Sstevel@tonic-gate 
17167c478bd9Sstevel@tonic-gate 	record->vfsp = (uint64_t)(uintptr_t)vfsp;
17177c478bd9Sstevel@tonic-gate 	if (fidp != NULL) {
17187c478bd9Sstevel@tonic-gate 		CACHEFS_FID_COPY(fidp, &record->fid);
17197c478bd9Sstevel@tonic-gate 	}
17207c478bd9Sstevel@tonic-gate 	record->fileno = fileno;
17217c478bd9Sstevel@tonic-gate 
17227c478bd9Sstevel@tonic-gate 	cachefs_log_enqueue(cachep, record, (int)sizeof (*record),
17237c478bd9Sstevel@tonic-gate 	    cachefs_xdr_nocache);
17247c478bd9Sstevel@tonic-gate 
17257c478bd9Sstevel@tonic-gate }
17267c478bd9Sstevel@tonic-gate 
17277c478bd9Sstevel@tonic-gate static bool_t
cachefs_xdr_nocache(XDR * xdrs,struct cachefs_log_nocache_record * rec)17287c478bd9Sstevel@tonic-gate cachefs_xdr_nocache(XDR *xdrs, struct cachefs_log_nocache_record *rec)
17297c478bd9Sstevel@tonic-gate {
17307c478bd9Sstevel@tonic-gate 	if ((! xdr_int(xdrs, &rec->type)) ||
17317c478bd9Sstevel@tonic-gate 	    (! xdr_int(xdrs, &rec->error)) ||
17327c478bd9Sstevel@tonic-gate 	    (! xdr_cfs_time_t(xdrs, &rec->time)) ||
17337c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->vfsp, sizeof (rec->vfsp))) ||
17347c478bd9Sstevel@tonic-gate 	    (! xdr_opaque(xdrs, (caddr_t)&rec->fid, sizeof (rec->fid))) ||
17357c478bd9Sstevel@tonic-gate 	    (! xdr_ino64(xdrs, &rec->fileno)))
17367c478bd9Sstevel@tonic-gate 		return (FALSE);
17377c478bd9Sstevel@tonic-gate 
17387c478bd9Sstevel@tonic-gate 	return (TRUE);
17397c478bd9Sstevel@tonic-gate }
1740