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
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
23*47644099Sgt29601 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate * Routines for cachefs logging.
317c478bd9Sstevel@tonic-gate */
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate #include <stdio.h>
347c478bd9Sstevel@tonic-gate #include <stdlib.h>
357c478bd9Sstevel@tonic-gate #include <stddef.h>
367c478bd9Sstevel@tonic-gate #include <sys/types.h>
377c478bd9Sstevel@tonic-gate #include <sys/param.h>
387c478bd9Sstevel@tonic-gate #include <errno.h>
397c478bd9Sstevel@tonic-gate #include <sys/stat.h>
407c478bd9Sstevel@tonic-gate #include <fcntl.h>
417c478bd9Sstevel@tonic-gate #include <unistd.h>
427c478bd9Sstevel@tonic-gate #include <libintl.h>
437c478bd9Sstevel@tonic-gate #include <time.h>
447c478bd9Sstevel@tonic-gate #include <string.h>
457c478bd9Sstevel@tonic-gate #include <sys/fs/cachefs_fs.h>
467c478bd9Sstevel@tonic-gate #include <sys/fs/cachefs_log.h>
477c478bd9Sstevel@tonic-gate #include <malloc.h>
487c478bd9Sstevel@tonic-gate #include <limits.h>
497c478bd9Sstevel@tonic-gate #include "stats.h"
507c478bd9Sstevel@tonic-gate #include <assert.h>
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate /* forward declarations of statics */
537c478bd9Sstevel@tonic-gate static kstat_t *stats_log_kstat_read(stats_cookie_t *);
547c478bd9Sstevel@tonic-gate static char *stats_log_fmtfid(cfs_fid_t *);
557c478bd9Sstevel@tonic-gate static bool_t stats_xdr_loghead(XDR *, struct cachefs_log_logfile_header *);
567c478bd9Sstevel@tonic-gate static int stats_log_fi_comp(const void *a, const void *b);
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate int
stats_log_kernel_setname(stats_cookie_t * st,char * path)597c478bd9Sstevel@tonic-gate stats_log_kernel_setname(stats_cookie_t *st, char *path)
607c478bd9Sstevel@tonic-gate {
617c478bd9Sstevel@tonic-gate int error = 0;
627c478bd9Sstevel@tonic-gate kstat_t *log;
637c478bd9Sstevel@tonic-gate cachefs_log_control_t *lc;
647c478bd9Sstevel@tonic-gate int exists = 0;
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate assert(stats_good(st));
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate if ((log = stats_log_kstat_read(st)) == NULL) {
697c478bd9Sstevel@tonic-gate error = stats_errno(st);
707c478bd9Sstevel@tonic-gate goto out;
717c478bd9Sstevel@tonic-gate }
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate lc = (cachefs_log_control_t *)log->ks_data;
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate /*
767c478bd9Sstevel@tonic-gate * the stats_ API allows a NULL or an empty path to turn off
777c478bd9Sstevel@tonic-gate * logging, but the kstat interface has the string buffered,
787c478bd9Sstevel@tonic-gate * so we need to make an empty string.
797c478bd9Sstevel@tonic-gate */
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate if (path == NULL)
827c478bd9Sstevel@tonic-gate path = "";
837c478bd9Sstevel@tonic-gate if ((lc->lc_path[0] == 0) && (path[0] == 0))
847c478bd9Sstevel@tonic-gate goto out;
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate (void) strlcpy(lc->lc_path, path, sizeof (lc->lc_path));
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate if (path[0] != '\0') {
897c478bd9Sstevel@tonic-gate struct stat64 s;
907c478bd9Sstevel@tonic-gate int f;
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate exists = access(path, F_OK);
937c478bd9Sstevel@tonic-gate /* logfile will be <2GB */
947c478bd9Sstevel@tonic-gate f = open(path, O_WRONLY | O_CREAT, 0666);
957c478bd9Sstevel@tonic-gate if (f < 0) {
967c478bd9Sstevel@tonic-gate stats_perror(st, error = SE_FILE,
977c478bd9Sstevel@tonic-gate gettext("Cannot open/create logfile: %s"),
987c478bd9Sstevel@tonic-gate strerror(errno));
997c478bd9Sstevel@tonic-gate goto out;
1007c478bd9Sstevel@tonic-gate }
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate if (fstat64(f, &s) < 0) {
1037c478bd9Sstevel@tonic-gate stats_perror(st, error = SE_FILE,
1047c478bd9Sstevel@tonic-gate gettext("Cannot stat logfile: %s"),
1057c478bd9Sstevel@tonic-gate strerror(errno));
1067c478bd9Sstevel@tonic-gate (void) close(f);
1077c478bd9Sstevel@tonic-gate goto out;
1087c478bd9Sstevel@tonic-gate }
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate /*
1117c478bd9Sstevel@tonic-gate * the kernel will accept an empty file as a logfile. we must
1127c478bd9Sstevel@tonic-gate * make sure that we created this empty file, i.e. that it's
1137c478bd9Sstevel@tonic-gate * not an already existing file that happened to be empty.
1147c478bd9Sstevel@tonic-gate *
1157c478bd9Sstevel@tonic-gate * if we hand the kernel a nonempty file, it will check the
1167c478bd9Sstevel@tonic-gate * magic number. thus, if they hand it something like
1177c478bd9Sstevel@tonic-gate * /etc/passwd, the kernel should reject it. we just have to
1187c478bd9Sstevel@tonic-gate * catch the cases of empty files we don't want to be
1197c478bd9Sstevel@tonic-gate * logfiles.
1207c478bd9Sstevel@tonic-gate */
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate if ((exists == 0) && (s.st_size == 0LL)) {
1237c478bd9Sstevel@tonic-gate stats_perror(st, error = SE_INVAL,
1247c478bd9Sstevel@tonic-gate gettext(
1257c478bd9Sstevel@tonic-gate "Cannot use existing empty file as a logfile"));
1267c478bd9Sstevel@tonic-gate (void) close(f);
1277c478bd9Sstevel@tonic-gate goto out;
1287c478bd9Sstevel@tonic-gate }
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gate (void) close(f);
1317c478bd9Sstevel@tonic-gate }
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate if (kstat_write(st->st_kstat_cookie, log, NULL) < 0) {
1347c478bd9Sstevel@tonic-gate stats_perror(st, error = SE_KERNEL,
1357c478bd9Sstevel@tonic-gate gettext("Cannot set logfile path for this filesystem"));
1367c478bd9Sstevel@tonic-gate goto out;
1377c478bd9Sstevel@tonic-gate }
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate out:
1407c478bd9Sstevel@tonic-gate if ((error != 0) && (path[0] != '\0') && (exists != 0))
1417c478bd9Sstevel@tonic-gate (void) unlink(path);
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate return (error);
1447c478bd9Sstevel@tonic-gate }
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate int
stats_log_which(stats_cookie_t * st,int which,int onoff)1477c478bd9Sstevel@tonic-gate stats_log_which(stats_cookie_t *st, int which, int onoff)
1487c478bd9Sstevel@tonic-gate {
1497c478bd9Sstevel@tonic-gate int error = 0;
1507c478bd9Sstevel@tonic-gate kstat_t *log;
1517c478bd9Sstevel@tonic-gate cachefs_log_control_t *lc;
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate assert(stats_good(st));
1547c478bd9Sstevel@tonic-gate
1557c478bd9Sstevel@tonic-gate if ((log = stats_log_kstat_read(st)) == NULL) {
1567c478bd9Sstevel@tonic-gate error = stats_errno(st);
1577c478bd9Sstevel@tonic-gate goto out;
1587c478bd9Sstevel@tonic-gate }
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate lc = (cachefs_log_control_t *)log->ks_data;
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gate if (onoff)
1637c478bd9Sstevel@tonic-gate CACHEFS_LOG_SET(lc, which);
1647c478bd9Sstevel@tonic-gate else
1657c478bd9Sstevel@tonic-gate CACHEFS_LOG_CLEAR(lc, which);
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gate if (kstat_write(st->st_kstat_cookie, log, NULL) < 0) {
1687c478bd9Sstevel@tonic-gate stats_perror(st, error = SE_KERNEL,
1697c478bd9Sstevel@tonic-gate gettext("Cannot set log bitmap for this filesystem"));
1707c478bd9Sstevel@tonic-gate goto out;
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate out:
1747c478bd9Sstevel@tonic-gate return (error);
1757c478bd9Sstevel@tonic-gate }
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gate char *
stats_log_kernel_getname(stats_cookie_t * st)1787c478bd9Sstevel@tonic-gate stats_log_kernel_getname(stats_cookie_t *st)
1797c478bd9Sstevel@tonic-gate {
1807c478bd9Sstevel@tonic-gate char *rc = NULL;
1817c478bd9Sstevel@tonic-gate kstat_t *log;
1827c478bd9Sstevel@tonic-gate cachefs_log_control_t *lc;
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate assert(stats_good(st));
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate if ((log = stats_log_kstat_read(st)) == NULL)
1877c478bd9Sstevel@tonic-gate goto out;
1887c478bd9Sstevel@tonic-gate
1897c478bd9Sstevel@tonic-gate lc = (cachefs_log_control_t *)log->ks_data;
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate rc = lc->lc_path; /* rc[0] will be '\0' if we're not logging */
1927c478bd9Sstevel@tonic-gate
1937c478bd9Sstevel@tonic-gate out:
1947c478bd9Sstevel@tonic-gate return (rc);
1957c478bd9Sstevel@tonic-gate }
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate static kstat_t *
stats_log_kstat_read(stats_cookie_t * st)1987c478bd9Sstevel@tonic-gate stats_log_kstat_read(stats_cookie_t *st)
1997c478bd9Sstevel@tonic-gate {
2007c478bd9Sstevel@tonic-gate kstat_t *rc;
2017c478bd9Sstevel@tonic-gate
2027c478bd9Sstevel@tonic-gate assert(stats_good(st));
2037c478bd9Sstevel@tonic-gate assert(st->st_flags & ST_BOUND);
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate if ((rc = kstat_lookup(st->st_kstat_cookie,
2067c478bd9Sstevel@tonic-gate "cachefs", st->st_fsid, "log")) == NULL) {
2077c478bd9Sstevel@tonic-gate /*
2087c478bd9Sstevel@tonic-gate * XXX if st was created for a particular cachedir, we
2097c478bd9Sstevel@tonic-gate * should scan for another st->st_fsid that'll get us
2107c478bd9Sstevel@tonic-gate * the same cache.
2117c478bd9Sstevel@tonic-gate */
2127c478bd9Sstevel@tonic-gate stats_perror(st, SE_KERNEL,
2137c478bd9Sstevel@tonic-gate gettext("Cannot lookup kstats for this filesystem"));
2147c478bd9Sstevel@tonic-gate goto out;
2157c478bd9Sstevel@tonic-gate }
2167c478bd9Sstevel@tonic-gate if (kstat_read(st->st_kstat_cookie, rc, NULL) < 0) {
2177c478bd9Sstevel@tonic-gate stats_perror(st, SE_KERNEL,
2187c478bd9Sstevel@tonic-gate gettext("Cannot read kstats for this filesystem"));
2197c478bd9Sstevel@tonic-gate rc = NULL;
2207c478bd9Sstevel@tonic-gate goto out;
2217c478bd9Sstevel@tonic-gate }
2227c478bd9Sstevel@tonic-gate
2237c478bd9Sstevel@tonic-gate out:
2247c478bd9Sstevel@tonic-gate return (rc);
2257c478bd9Sstevel@tonic-gate }
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate int
stats_log_logfile_open(stats_cookie_t * st,char * fname)2287c478bd9Sstevel@tonic-gate stats_log_logfile_open(stats_cookie_t *st, char *fname)
2297c478bd9Sstevel@tonic-gate {
2307c478bd9Sstevel@tonic-gate int rc = 0;
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate assert(stats_good(st));
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate if ((fname == NULL) || (fname[0] == '\0')) {
2357c478bd9Sstevel@tonic-gate kstat_t *log;
2367c478bd9Sstevel@tonic-gate cachefs_log_control_t *lc;
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate if ((log = stats_log_kstat_read(st)) == NULL) {
2397c478bd9Sstevel@tonic-gate rc = -1;
2407c478bd9Sstevel@tonic-gate goto out;
2417c478bd9Sstevel@tonic-gate }
2427c478bd9Sstevel@tonic-gate lc = (cachefs_log_control_t *)log->ks_data;
2437c478bd9Sstevel@tonic-gate fname = lc->lc_path;
2447c478bd9Sstevel@tonic-gate }
2457c478bd9Sstevel@tonic-gate
2467c478bd9Sstevel@tonic-gate /* logfile will be <2GB */
2477c478bd9Sstevel@tonic-gate if ((st->st_logstream = fopen(fname, "r")) == NULL) {
2487c478bd9Sstevel@tonic-gate stats_perror(st, SE_FILE,
2497c478bd9Sstevel@tonic-gate gettext("Cannot open logfile %s"), fname);
2507c478bd9Sstevel@tonic-gate rc = -1;
2517c478bd9Sstevel@tonic-gate goto out;
2527c478bd9Sstevel@tonic-gate }
2537c478bd9Sstevel@tonic-gate xdrstdio_create(&st->st_logxdr, st->st_logstream, XDR_DECODE);
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gate if (! stats_xdr_loghead(&st->st_logxdr, &st->st_loghead)) {
2567c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
2577c478bd9Sstevel@tonic-gate gettext("Cannot read header from logfile %s"), fname);
2587c478bd9Sstevel@tonic-gate rc = -1;
2597c478bd9Sstevel@tonic-gate goto out;
2607c478bd9Sstevel@tonic-gate }
2617c478bd9Sstevel@tonic-gate if (st->st_loghead.lh_magic != CACHEFS_LOG_MAGIC) {
2627c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
2637c478bd9Sstevel@tonic-gate gettext("%s: Invalid log file header"), fname);
2647c478bd9Sstevel@tonic-gate rc = -1;
2657c478bd9Sstevel@tonic-gate goto out;
2667c478bd9Sstevel@tonic-gate }
2677c478bd9Sstevel@tonic-gate if (st->st_loghead.lh_revision > CACHEFS_LOG_FILE_REV) {
2687c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
2697c478bd9Sstevel@tonic-gate gettext("%s: Revision too high"), fname);
2707c478bd9Sstevel@tonic-gate rc = -1;
2717c478bd9Sstevel@tonic-gate goto out;
2727c478bd9Sstevel@tonic-gate }
2737c478bd9Sstevel@tonic-gate
2747c478bd9Sstevel@tonic-gate st->st_flags |= ST_LFOPEN;
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gate out:
2777c478bd9Sstevel@tonic-gate if (rc != 0) {
2787c478bd9Sstevel@tonic-gate if (st->st_logstream != NULL) {
2797c478bd9Sstevel@tonic-gate (void) fclose(st->st_logstream);
2807c478bd9Sstevel@tonic-gate st->st_logstream = NULL;
2817c478bd9Sstevel@tonic-gate }
2827c478bd9Sstevel@tonic-gate if (st->st_logxdr.x_ops != NULL) {
2837c478bd9Sstevel@tonic-gate xdr_destroy(&st->st_logxdr);
2847c478bd9Sstevel@tonic-gate st->st_logxdr.x_ops = NULL;
2857c478bd9Sstevel@tonic-gate }
2867c478bd9Sstevel@tonic-gate }
2877c478bd9Sstevel@tonic-gate return (rc);
2887c478bd9Sstevel@tonic-gate }
2897c478bd9Sstevel@tonic-gate
2907c478bd9Sstevel@tonic-gate static bool_t
stats_xdr_loghead(XDR * xdrs,struct cachefs_log_logfile_header * lh)2917c478bd9Sstevel@tonic-gate stats_xdr_loghead(XDR *xdrs, struct cachefs_log_logfile_header *lh)
2927c478bd9Sstevel@tonic-gate {
2937c478bd9Sstevel@tonic-gate if ((! xdr_u_int(xdrs, &lh->lh_magic)) ||
2947c478bd9Sstevel@tonic-gate (! xdr_u_int(xdrs, &lh->lh_revision)) ||
2957c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, &lh->lh_errno)) ||
2967c478bd9Sstevel@tonic-gate (! xdr_u_int(xdrs, &lh->lh_blocks)) ||
2977c478bd9Sstevel@tonic-gate (! xdr_u_int(xdrs, &lh->lh_files)) ||
2987c478bd9Sstevel@tonic-gate (! xdr_u_int(xdrs, &lh->lh_maxbsize)) ||
2997c478bd9Sstevel@tonic-gate (! xdr_u_int(xdrs, &lh->lh_pagesize)))
3007c478bd9Sstevel@tonic-gate return (FALSE);
3017c478bd9Sstevel@tonic-gate
3027c478bd9Sstevel@tonic-gate return (TRUE);
3037c478bd9Sstevel@tonic-gate }
3047c478bd9Sstevel@tonic-gate
3057c478bd9Sstevel@tonic-gate void *
stats_log_logfile_read(stats_cookie_t * st,int * type)3067c478bd9Sstevel@tonic-gate stats_log_logfile_read(stats_cookie_t *st, int *type)
3077c478bd9Sstevel@tonic-gate {
3087c478bd9Sstevel@tonic-gate void *rc = NULL;
3097c478bd9Sstevel@tonic-gate size_t size;
3107c478bd9Sstevel@tonic-gate int ttype;
3117c478bd9Sstevel@tonic-gate XDR *xdrs;
3127c478bd9Sstevel@tonic-gate char *string1, *string2;
3137c478bd9Sstevel@tonic-gate
3147c478bd9Sstevel@tonic-gate assert(stats_good(st));
3157c478bd9Sstevel@tonic-gate
3167c478bd9Sstevel@tonic-gate xdrs = &st->st_logxdr;
3177c478bd9Sstevel@tonic-gate
3187c478bd9Sstevel@tonic-gate if (! (st->st_flags & ST_LFOPEN)) {
3197c478bd9Sstevel@tonic-gate stats_perror(st, SE_INVAL,
3207c478bd9Sstevel@tonic-gate gettext("Logfile was not open"));
3217c478bd9Sstevel@tonic-gate goto out;
3227c478bd9Sstevel@tonic-gate }
3237c478bd9Sstevel@tonic-gate
3247c478bd9Sstevel@tonic-gate if (type == NULL)
3257c478bd9Sstevel@tonic-gate type = &ttype;
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate if (! xdr_int(xdrs, type))
3287c478bd9Sstevel@tonic-gate goto out;
3297c478bd9Sstevel@tonic-gate
3307c478bd9Sstevel@tonic-gate switch (*type) {
3317c478bd9Sstevel@tonic-gate struct cachefs_log_mount_record mount, *mountp;
3327c478bd9Sstevel@tonic-gate struct cachefs_log_umount_record umount;
3337c478bd9Sstevel@tonic-gate struct cachefs_log_getpage_record getpage;
3347c478bd9Sstevel@tonic-gate struct cachefs_log_readdir_record readdir;
3357c478bd9Sstevel@tonic-gate struct cachefs_log_readlink_record readlink;
3367c478bd9Sstevel@tonic-gate struct cachefs_log_remove_record remove;
3377c478bd9Sstevel@tonic-gate struct cachefs_log_rmdir_record rmdir;
3387c478bd9Sstevel@tonic-gate struct cachefs_log_truncate_record truncate;
3397c478bd9Sstevel@tonic-gate struct cachefs_log_putpage_record putpage;
3407c478bd9Sstevel@tonic-gate struct cachefs_log_create_record create;
3417c478bd9Sstevel@tonic-gate struct cachefs_log_mkdir_record mkdir;
3427c478bd9Sstevel@tonic-gate struct cachefs_log_rename_record rename;
3437c478bd9Sstevel@tonic-gate struct cachefs_log_symlink_record symlink;
3447c478bd9Sstevel@tonic-gate struct cachefs_log_populate_record populate;
3457c478bd9Sstevel@tonic-gate struct cachefs_log_csymlink_record csymlink;
3467c478bd9Sstevel@tonic-gate struct cachefs_log_filldir_record filldir;
3477c478bd9Sstevel@tonic-gate struct cachefs_log_mdcreate_record mdcreate;
3487c478bd9Sstevel@tonic-gate struct cachefs_log_gpfront_record gpfront;
3497c478bd9Sstevel@tonic-gate struct cachefs_log_rfdir_record rfdir;
3507c478bd9Sstevel@tonic-gate struct cachefs_log_ualloc_record ualloc;
3517c478bd9Sstevel@tonic-gate struct cachefs_log_calloc_record challoc;
3527c478bd9Sstevel@tonic-gate struct cachefs_log_nocache_record nocache;
3537c478bd9Sstevel@tonic-gate
3547c478bd9Sstevel@tonic-gate case CACHEFS_LOG_MOUNT:
3557c478bd9Sstevel@tonic-gate if ((! xdr_int(xdrs, &mount.error)) ||
3567c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&mount.time)) ||
3577c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&mount.vfsp,
3587c478bd9Sstevel@tonic-gate sizeof (mount.vfsp))) ||
3597c478bd9Sstevel@tonic-gate (! xdr_u_int(xdrs, &mount.flags)) ||
3607c478bd9Sstevel@tonic-gate (! xdr_u_int(xdrs, &mount.popsize)) ||
3617c478bd9Sstevel@tonic-gate (! xdr_u_int(xdrs, &mount.fgsize)) ||
3627c478bd9Sstevel@tonic-gate (! xdr_u_short(xdrs, &mount.pathlen)) ||
3637c478bd9Sstevel@tonic-gate (! xdr_u_short(xdrs, &mount.cacheidlen))) {
3647c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
3657c478bd9Sstevel@tonic-gate gettext("Truncated mount record"));
3667c478bd9Sstevel@tonic-gate goto out;
3677c478bd9Sstevel@tonic-gate }
3687c478bd9Sstevel@tonic-gate mount.type = *type;
3697c478bd9Sstevel@tonic-gate size = sizeof (mount) + mount.pathlen + mount.cacheidlen -
3707c478bd9Sstevel@tonic-gate CLPAD(cachefs_log_mount_record, path);
3717c478bd9Sstevel@tonic-gate if ((rc = mountp =
3727c478bd9Sstevel@tonic-gate (struct cachefs_log_mount_record *)
3737c478bd9Sstevel@tonic-gate calloc(1, size)) == NULL) {
3747c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
3757c478bd9Sstevel@tonic-gate gettext("Cannot malloc record"));
3767c478bd9Sstevel@tonic-gate goto out;
3777c478bd9Sstevel@tonic-gate }
3787c478bd9Sstevel@tonic-gate memcpy(rc, &mount, size);
3797c478bd9Sstevel@tonic-gate string1 = mountp->path;
3807c478bd9Sstevel@tonic-gate string2 = mountp->path + mount.pathlen + 1;
3817c478bd9Sstevel@tonic-gate (void) xdr_wrapstring(xdrs, &string1);
3827c478bd9Sstevel@tonic-gate (void) xdr_wrapstring(xdrs, &string2);
3837c478bd9Sstevel@tonic-gate break;
3847c478bd9Sstevel@tonic-gate
3857c478bd9Sstevel@tonic-gate case CACHEFS_LOG_UMOUNT:
3867c478bd9Sstevel@tonic-gate if ((! xdr_int(xdrs, &umount.error)) ||
3877c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&umount.time)) ||
3887c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&umount.vfsp,
3897c478bd9Sstevel@tonic-gate sizeof (umount.vfsp)))) {
3907c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
3917c478bd9Sstevel@tonic-gate gettext("Truncated umount record"));
3927c478bd9Sstevel@tonic-gate goto out;
3937c478bd9Sstevel@tonic-gate }
3947c478bd9Sstevel@tonic-gate umount.type = *type;
3957c478bd9Sstevel@tonic-gate size = sizeof (umount);
3967c478bd9Sstevel@tonic-gate if ((rc = (caddr_t)calloc(1, size)) == NULL) {
3977c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
3987c478bd9Sstevel@tonic-gate gettext("Cannot malloc record"));
3997c478bd9Sstevel@tonic-gate goto out;
4007c478bd9Sstevel@tonic-gate }
4017c478bd9Sstevel@tonic-gate memcpy(rc, &umount, size);
4027c478bd9Sstevel@tonic-gate break;
4037c478bd9Sstevel@tonic-gate
4047c478bd9Sstevel@tonic-gate case CACHEFS_LOG_GETPAGE:
4057c478bd9Sstevel@tonic-gate if ((! xdr_int(xdrs, &getpage.error)) ||
4067c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&getpage.time)) ||
4077c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&getpage.vfsp,
4087c478bd9Sstevel@tonic-gate sizeof (getpage.vfsp))) ||
4097c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&getpage.fid,
4107c478bd9Sstevel@tonic-gate sizeof (getpage.fid))) ||
4117c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs,
4127c478bd9Sstevel@tonic-gate (u_longlong_t *)&getpage.fileno)) ||
4137c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&getpage.uid)) ||
4147c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs,
4157c478bd9Sstevel@tonic-gate (u_longlong_t *)&getpage.offset)) ||
4167c478bd9Sstevel@tonic-gate (! xdr_u_int(xdrs, &getpage.len))) {
4177c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
4187c478bd9Sstevel@tonic-gate gettext("Truncated getpage record"));
4197c478bd9Sstevel@tonic-gate goto out;
4207c478bd9Sstevel@tonic-gate }
4217c478bd9Sstevel@tonic-gate getpage.type = *type;
4227c478bd9Sstevel@tonic-gate size = sizeof (getpage);
4237c478bd9Sstevel@tonic-gate if ((rc = (caddr_t)calloc(1, size)) == NULL) {
4247c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
4257c478bd9Sstevel@tonic-gate gettext("Cannot malloc record"));
4267c478bd9Sstevel@tonic-gate goto out;
4277c478bd9Sstevel@tonic-gate }
4287c478bd9Sstevel@tonic-gate memcpy(rc, &getpage, size);
4297c478bd9Sstevel@tonic-gate break;
4307c478bd9Sstevel@tonic-gate
4317c478bd9Sstevel@tonic-gate case CACHEFS_LOG_READDIR:
4327c478bd9Sstevel@tonic-gate if ((! xdr_int(xdrs, &readdir.error)) ||
4337c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&readdir.time)) ||
4347c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&readdir.vfsp,
4357c478bd9Sstevel@tonic-gate sizeof (readdir.vfsp))) ||
4367c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&readdir.fid,
4377c478bd9Sstevel@tonic-gate sizeof (readdir.fid))) ||
4387c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs,
4397c478bd9Sstevel@tonic-gate (u_longlong_t *)&readdir.fileno)) ||
4407c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&readdir.uid)) ||
4417c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs,
4427c478bd9Sstevel@tonic-gate (u_longlong_t *)&readdir.offset)) ||
4437c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, &readdir.eof))) {
4447c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
4457c478bd9Sstevel@tonic-gate gettext("Truncated readdir record"));
4467c478bd9Sstevel@tonic-gate goto out;
4477c478bd9Sstevel@tonic-gate }
4487c478bd9Sstevel@tonic-gate readdir.type = *type;
4497c478bd9Sstevel@tonic-gate size = sizeof (readdir);
4507c478bd9Sstevel@tonic-gate if ((rc = (caddr_t)calloc(1, size)) == NULL) {
4517c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
4527c478bd9Sstevel@tonic-gate gettext("Cannot malloc record"));
4537c478bd9Sstevel@tonic-gate goto out;
4547c478bd9Sstevel@tonic-gate }
4557c478bd9Sstevel@tonic-gate memcpy(rc, &readdir, size);
4567c478bd9Sstevel@tonic-gate break;
4577c478bd9Sstevel@tonic-gate
4587c478bd9Sstevel@tonic-gate case CACHEFS_LOG_READLINK:
4597c478bd9Sstevel@tonic-gate if ((! xdr_int(xdrs, &readlink.error)) ||
4607c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&readlink.time)) ||
4617c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&readlink.vfsp,
4627c478bd9Sstevel@tonic-gate sizeof (readlink.vfsp))) ||
4637c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&readlink.fid,
4647c478bd9Sstevel@tonic-gate sizeof (readlink.fid))) ||
4657c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs,
4667c478bd9Sstevel@tonic-gate (u_longlong_t *)&readlink.fileno)) ||
4677c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&readlink.uid)) ||
4687c478bd9Sstevel@tonic-gate (! xdr_u_int(xdrs,
4697c478bd9Sstevel@tonic-gate &readlink.length))) {
4707c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
4717c478bd9Sstevel@tonic-gate gettext("Truncated readlink record"));
4727c478bd9Sstevel@tonic-gate goto out;
4737c478bd9Sstevel@tonic-gate }
4747c478bd9Sstevel@tonic-gate readlink.type = *type;
4757c478bd9Sstevel@tonic-gate size = sizeof (readlink);
4767c478bd9Sstevel@tonic-gate if ((rc = (caddr_t)calloc(1, size)) == NULL) {
4777c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
4787c478bd9Sstevel@tonic-gate gettext("Cannot malloc record"));
4797c478bd9Sstevel@tonic-gate goto out;
4807c478bd9Sstevel@tonic-gate }
4817c478bd9Sstevel@tonic-gate memcpy(rc, &readlink, size);
4827c478bd9Sstevel@tonic-gate break;
4837c478bd9Sstevel@tonic-gate
4847c478bd9Sstevel@tonic-gate case CACHEFS_LOG_REMOVE:
4857c478bd9Sstevel@tonic-gate if ((! xdr_int(xdrs, &remove.error)) ||
4867c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&remove.time)) ||
4877c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&remove.vfsp,
4887c478bd9Sstevel@tonic-gate sizeof (remove.vfsp))) ||
4897c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&remove.fid,
4907c478bd9Sstevel@tonic-gate sizeof (remove.fid))) ||
4917c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs,
4927c478bd9Sstevel@tonic-gate (u_longlong_t *)&remove.fileno)) ||
4937c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&remove.uid))) {
4947c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
4957c478bd9Sstevel@tonic-gate gettext("Truncated remove record"));
4967c478bd9Sstevel@tonic-gate goto out;
4977c478bd9Sstevel@tonic-gate }
4987c478bd9Sstevel@tonic-gate remove.type = *type;
4997c478bd9Sstevel@tonic-gate size = sizeof (remove);
5007c478bd9Sstevel@tonic-gate if ((rc = (caddr_t)calloc(1, size)) == NULL) {
5017c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
5027c478bd9Sstevel@tonic-gate gettext("Cannot malloc record"));
5037c478bd9Sstevel@tonic-gate goto out;
5047c478bd9Sstevel@tonic-gate }
5057c478bd9Sstevel@tonic-gate memcpy(rc, &remove, size);
5067c478bd9Sstevel@tonic-gate break;
5077c478bd9Sstevel@tonic-gate
5087c478bd9Sstevel@tonic-gate case CACHEFS_LOG_RMDIR:
5097c478bd9Sstevel@tonic-gate if ((! xdr_int(xdrs, &rmdir.error)) ||
5107c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&rmdir.time)) ||
5117c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&rmdir.vfsp,
5127c478bd9Sstevel@tonic-gate sizeof (rmdir.vfsp))) ||
5137c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&rmdir.fid,
5147c478bd9Sstevel@tonic-gate sizeof (rmdir.fid))) ||
5157c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, (u_longlong_t *)&rmdir.fileno)) ||
5167c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&rmdir.uid))) {
5177c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
5187c478bd9Sstevel@tonic-gate gettext("Truncated rmdir record"));
5197c478bd9Sstevel@tonic-gate goto out;
5207c478bd9Sstevel@tonic-gate }
5217c478bd9Sstevel@tonic-gate rmdir.type = *type;
5227c478bd9Sstevel@tonic-gate size = sizeof (rmdir);
5237c478bd9Sstevel@tonic-gate if ((rc = (caddr_t)calloc(1, size)) == NULL) {
5247c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
5257c478bd9Sstevel@tonic-gate gettext("Cannot malloc record"));
5267c478bd9Sstevel@tonic-gate goto out;
5277c478bd9Sstevel@tonic-gate }
5287c478bd9Sstevel@tonic-gate memcpy(rc, &rmdir, size);
5297c478bd9Sstevel@tonic-gate break;
5307c478bd9Sstevel@tonic-gate
5317c478bd9Sstevel@tonic-gate case CACHEFS_LOG_TRUNCATE:
5327c478bd9Sstevel@tonic-gate if ((! xdr_int(xdrs, &truncate.error)) ||
5337c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&truncate.time)) ||
5347c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&truncate.vfsp,
5357c478bd9Sstevel@tonic-gate sizeof (truncate.vfsp))) ||
5367c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&truncate.fid,
5377c478bd9Sstevel@tonic-gate sizeof (truncate.fid))) ||
5387c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs,
5397c478bd9Sstevel@tonic-gate (u_longlong_t *)&truncate.fileno)) ||
5407c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&truncate.uid)) ||
5417c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs,
5427c478bd9Sstevel@tonic-gate (u_longlong_t *)&truncate.size))) {
5437c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
5447c478bd9Sstevel@tonic-gate gettext("Truncated truncate record"));
5457c478bd9Sstevel@tonic-gate goto out;
5467c478bd9Sstevel@tonic-gate }
5477c478bd9Sstevel@tonic-gate truncate.type = *type;
5487c478bd9Sstevel@tonic-gate size = sizeof (truncate);
5497c478bd9Sstevel@tonic-gate if ((rc = (caddr_t)calloc(1, size)) == NULL) {
5507c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
5517c478bd9Sstevel@tonic-gate gettext("Cannot malloc record"));
5527c478bd9Sstevel@tonic-gate goto out;
5537c478bd9Sstevel@tonic-gate }
5547c478bd9Sstevel@tonic-gate memcpy(rc, &truncate, size);
5557c478bd9Sstevel@tonic-gate break;
5567c478bd9Sstevel@tonic-gate
5577c478bd9Sstevel@tonic-gate case CACHEFS_LOG_PUTPAGE:
5587c478bd9Sstevel@tonic-gate if ((! xdr_int(xdrs, &putpage.error)) ||
5597c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&putpage.time)) ||
5607c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&putpage.vfsp,
5617c478bd9Sstevel@tonic-gate sizeof (putpage.vfsp))) ||
5627c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&putpage.fid,
5637c478bd9Sstevel@tonic-gate sizeof (putpage.fid))) ||
5647c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs,
5657c478bd9Sstevel@tonic-gate (u_longlong_t *)&putpage.fileno)) ||
5667c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&putpage.uid)) ||
5677c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs,
5687c478bd9Sstevel@tonic-gate (u_longlong_t *)&putpage.offset)) ||
5697c478bd9Sstevel@tonic-gate (! xdr_u_int(xdrs, &putpage.len))) {
5707c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
5717c478bd9Sstevel@tonic-gate gettext("Truncated putpage record"));
5727c478bd9Sstevel@tonic-gate goto out;
5737c478bd9Sstevel@tonic-gate }
5747c478bd9Sstevel@tonic-gate putpage.type = *type;
5757c478bd9Sstevel@tonic-gate size = sizeof (putpage);
5767c478bd9Sstevel@tonic-gate if ((rc = (caddr_t)calloc(1, size)) == NULL) {
5777c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
5787c478bd9Sstevel@tonic-gate gettext("Cannot malloc record"));
5797c478bd9Sstevel@tonic-gate goto out;
5807c478bd9Sstevel@tonic-gate }
5817c478bd9Sstevel@tonic-gate memcpy(rc, &putpage, size);
5827c478bd9Sstevel@tonic-gate break;
5837c478bd9Sstevel@tonic-gate
5847c478bd9Sstevel@tonic-gate case CACHEFS_LOG_CREATE:
5857c478bd9Sstevel@tonic-gate if ((! xdr_int(xdrs, &create.error)) ||
5867c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&create.time)) ||
5877c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&create.vfsp,
5887c478bd9Sstevel@tonic-gate sizeof (create.vfsp))) ||
5897c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&create.fid,
5907c478bd9Sstevel@tonic-gate sizeof (create.fid))) ||
5917c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs,
5927c478bd9Sstevel@tonic-gate (u_longlong_t *)&create.fileno)) ||
5937c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&create.uid))) {
5947c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
5957c478bd9Sstevel@tonic-gate gettext("Truncated create record"));
5967c478bd9Sstevel@tonic-gate goto out;
5977c478bd9Sstevel@tonic-gate }
5987c478bd9Sstevel@tonic-gate create.type = *type;
5997c478bd9Sstevel@tonic-gate size = sizeof (create);
6007c478bd9Sstevel@tonic-gate if ((rc = (struct cachefs_log_create_record *)
6017c478bd9Sstevel@tonic-gate calloc(1, size)) == NULL) {
6027c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
6037c478bd9Sstevel@tonic-gate gettext("Cannot malloc record"));
6047c478bd9Sstevel@tonic-gate goto out;
6057c478bd9Sstevel@tonic-gate }
6067c478bd9Sstevel@tonic-gate memcpy(rc, &create, size);
6077c478bd9Sstevel@tonic-gate break;
6087c478bd9Sstevel@tonic-gate
6097c478bd9Sstevel@tonic-gate case CACHEFS_LOG_MKDIR:
6107c478bd9Sstevel@tonic-gate if ((! xdr_int(xdrs, &mkdir.error)) ||
6117c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&mkdir.time)) ||
6127c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&mkdir.vfsp,
6137c478bd9Sstevel@tonic-gate sizeof (mkdir.vfsp))) ||
6147c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&mkdir.fid,
6157c478bd9Sstevel@tonic-gate sizeof (mkdir.fid))) ||
6167c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, (u_longlong_t *)&mkdir.fileno)) ||
6177c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&mkdir.uid))) {
6187c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
6197c478bd9Sstevel@tonic-gate gettext("Truncated mkdir record"));
6207c478bd9Sstevel@tonic-gate goto out;
6217c478bd9Sstevel@tonic-gate }
6227c478bd9Sstevel@tonic-gate mkdir.type = *type;
6237c478bd9Sstevel@tonic-gate size = sizeof (mkdir);
6247c478bd9Sstevel@tonic-gate if ((rc = (struct cachefs_log_mkdir_record *)
6257c478bd9Sstevel@tonic-gate calloc(1, size)) == NULL) {
6267c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
6277c478bd9Sstevel@tonic-gate gettext("Cannot malloc record"));
6287c478bd9Sstevel@tonic-gate goto out;
6297c478bd9Sstevel@tonic-gate }
6307c478bd9Sstevel@tonic-gate memcpy(rc, &mkdir, size);
6317c478bd9Sstevel@tonic-gate break;
6327c478bd9Sstevel@tonic-gate
6337c478bd9Sstevel@tonic-gate case CACHEFS_LOG_RENAME:
6347c478bd9Sstevel@tonic-gate if ((! xdr_int(xdrs, &rename.error)) ||
6357c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&rename.time)) ||
6367c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&rename.vfsp,
6377c478bd9Sstevel@tonic-gate sizeof (rename.vfsp))) ||
6387c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&rename.gone,
6397c478bd9Sstevel@tonic-gate sizeof (rename.gone))) ||
6407c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, &rename.removed)) ||
6417c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&rename.uid))) {
6427c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
6437c478bd9Sstevel@tonic-gate gettext("Truncated rename record"));
6447c478bd9Sstevel@tonic-gate goto out;
6457c478bd9Sstevel@tonic-gate }
6467c478bd9Sstevel@tonic-gate rename.type = *type;
6477c478bd9Sstevel@tonic-gate size = sizeof (rename);
6487c478bd9Sstevel@tonic-gate if ((rc = (struct cachefs_log_rename_record *)
6497c478bd9Sstevel@tonic-gate calloc(1, size)) == NULL) {
6507c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
6517c478bd9Sstevel@tonic-gate gettext("Cannot malloc record"));
6527c478bd9Sstevel@tonic-gate goto out;
6537c478bd9Sstevel@tonic-gate }
6547c478bd9Sstevel@tonic-gate memcpy(rc, &rename, size);
6557c478bd9Sstevel@tonic-gate break;
6567c478bd9Sstevel@tonic-gate
6577c478bd9Sstevel@tonic-gate case CACHEFS_LOG_SYMLINK:
6587c478bd9Sstevel@tonic-gate if ((! xdr_int(xdrs, &symlink.error)) ||
6597c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&symlink.time)) ||
6607c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&symlink.vfsp,
6617c478bd9Sstevel@tonic-gate sizeof (symlink.vfsp))) ||
6627c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&symlink.fid,
6637c478bd9Sstevel@tonic-gate sizeof (symlink.fid))) ||
6647c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs,
6657c478bd9Sstevel@tonic-gate (u_longlong_t *)&symlink.fileno)) ||
6667c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&symlink.uid)) ||
6677c478bd9Sstevel@tonic-gate (! xdr_u_int(xdrs, &symlink.size))) {
6687c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
6697c478bd9Sstevel@tonic-gate gettext("Truncated symlink record"));
6707c478bd9Sstevel@tonic-gate goto out;
6717c478bd9Sstevel@tonic-gate }
6727c478bd9Sstevel@tonic-gate symlink.type = *type;
6737c478bd9Sstevel@tonic-gate size = sizeof (symlink);
6747c478bd9Sstevel@tonic-gate if ((rc = (struct cachefs_log_symlink_record *)
6757c478bd9Sstevel@tonic-gate calloc(1, size)) == NULL) {
6767c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
6777c478bd9Sstevel@tonic-gate gettext("Cannot malloc record"));
6787c478bd9Sstevel@tonic-gate goto out;
6797c478bd9Sstevel@tonic-gate }
6807c478bd9Sstevel@tonic-gate memcpy(rc, &symlink, size);
6817c478bd9Sstevel@tonic-gate break;
6827c478bd9Sstevel@tonic-gate
6837c478bd9Sstevel@tonic-gate case CACHEFS_LOG_POPULATE:
6847c478bd9Sstevel@tonic-gate if ((! xdr_int(xdrs, &populate.error)) ||
6857c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&populate.time)) ||
6867c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&populate.vfsp,
6877c478bd9Sstevel@tonic-gate sizeof (populate.vfsp))) ||
6887c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&populate.fid,
6897c478bd9Sstevel@tonic-gate sizeof (populate.fid))) ||
6907c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs,
6917c478bd9Sstevel@tonic-gate (u_longlong_t *)&populate.fileno)) ||
6927c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, (u_longlong_t *)&populate.off)) ||
6937c478bd9Sstevel@tonic-gate (! xdr_u_int(xdrs, &populate.size))) {
6947c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
6957c478bd9Sstevel@tonic-gate gettext("Truncated populate record"));
6967c478bd9Sstevel@tonic-gate goto out;
6977c478bd9Sstevel@tonic-gate }
6987c478bd9Sstevel@tonic-gate populate.type = *type;
6997c478bd9Sstevel@tonic-gate if ((rc = (struct cachefs_log_populate_record *)
7007c478bd9Sstevel@tonic-gate calloc(1, sizeof (populate))) == NULL) {
7017c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
7027c478bd9Sstevel@tonic-gate gettext("Cannot malloc record"));
7037c478bd9Sstevel@tonic-gate goto out;
7047c478bd9Sstevel@tonic-gate }
7057c478bd9Sstevel@tonic-gate memcpy(rc, &populate, sizeof (populate));
7067c478bd9Sstevel@tonic-gate break;
7077c478bd9Sstevel@tonic-gate
7087c478bd9Sstevel@tonic-gate case CACHEFS_LOG_CSYMLINK:
7097c478bd9Sstevel@tonic-gate if ((! xdr_int(xdrs, &csymlink.error)) ||
7107c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&csymlink.time)) ||
7117c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&csymlink.vfsp,
7127c478bd9Sstevel@tonic-gate sizeof (csymlink.vfsp))) ||
7137c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&csymlink.fid,
7147c478bd9Sstevel@tonic-gate sizeof (csymlink.fid))) ||
7157c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs,
7167c478bd9Sstevel@tonic-gate (u_longlong_t *)&csymlink.fileno)) ||
7177c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, &csymlink.size))) {
7187c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
7197c478bd9Sstevel@tonic-gate gettext("Truncated csymlink record"));
7207c478bd9Sstevel@tonic-gate goto out;
7217c478bd9Sstevel@tonic-gate }
7227c478bd9Sstevel@tonic-gate csymlink.type = *type;
7237c478bd9Sstevel@tonic-gate if ((rc = (struct cachefs_log_csymlink_record *)
7247c478bd9Sstevel@tonic-gate calloc(1, sizeof (csymlink))) == NULL) {
7257c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
7267c478bd9Sstevel@tonic-gate gettext("Cannot malloc record"));
7277c478bd9Sstevel@tonic-gate goto out;
7287c478bd9Sstevel@tonic-gate }
7297c478bd9Sstevel@tonic-gate memcpy(rc, &csymlink, sizeof (csymlink));
7307c478bd9Sstevel@tonic-gate break;
7317c478bd9Sstevel@tonic-gate
7327c478bd9Sstevel@tonic-gate case CACHEFS_LOG_FILLDIR:
7337c478bd9Sstevel@tonic-gate if ((! xdr_int(xdrs, &filldir.error)) ||
7347c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&filldir.time)) ||
7357c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&filldir.vfsp,
7367c478bd9Sstevel@tonic-gate sizeof (filldir.vfsp))) ||
7377c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&filldir.fid,
7387c478bd9Sstevel@tonic-gate sizeof (filldir.fid))) ||
7397c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs,
7407c478bd9Sstevel@tonic-gate (u_longlong_t *)&filldir.fileno)) ||
7417c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, &filldir.size))) {
7427c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
7437c478bd9Sstevel@tonic-gate gettext("Truncated filldir record"));
7447c478bd9Sstevel@tonic-gate goto out;
7457c478bd9Sstevel@tonic-gate }
7467c478bd9Sstevel@tonic-gate filldir.type = *type;
7477c478bd9Sstevel@tonic-gate if ((rc = (struct cachefs_log_filldir_record *)
7487c478bd9Sstevel@tonic-gate calloc(1, sizeof (filldir))) == NULL) {
7497c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
7507c478bd9Sstevel@tonic-gate gettext("Cannot malloc record"));
7517c478bd9Sstevel@tonic-gate goto out;
7527c478bd9Sstevel@tonic-gate }
7537c478bd9Sstevel@tonic-gate memcpy(rc, &filldir, sizeof (filldir));
7547c478bd9Sstevel@tonic-gate break;
7557c478bd9Sstevel@tonic-gate
7567c478bd9Sstevel@tonic-gate case CACHEFS_LOG_MDCREATE:
7577c478bd9Sstevel@tonic-gate if ((! xdr_int(xdrs, &mdcreate.error)) ||
7587c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&mdcreate.time)) ||
7597c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&mdcreate.vfsp,
7607c478bd9Sstevel@tonic-gate sizeof (mdcreate.vfsp))) ||
7617c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&mdcreate.fid,
7627c478bd9Sstevel@tonic-gate sizeof (mdcreate.fid))) ||
7637c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs,
7647c478bd9Sstevel@tonic-gate (u_longlong_t *)&mdcreate.fileno)) ||
7657c478bd9Sstevel@tonic-gate (! xdr_u_int(xdrs, &mdcreate.count))) {
7667c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
7677c478bd9Sstevel@tonic-gate gettext("Truncated mdcreate record"));
7687c478bd9Sstevel@tonic-gate goto out;
7697c478bd9Sstevel@tonic-gate }
7707c478bd9Sstevel@tonic-gate mdcreate.type = *type;
7717c478bd9Sstevel@tonic-gate if ((rc = (struct cachefs_log_mdcreate_record *)
7727c478bd9Sstevel@tonic-gate calloc(1, sizeof (mdcreate))) == NULL) {
7737c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
7747c478bd9Sstevel@tonic-gate gettext("Cannot malloc record"));
7757c478bd9Sstevel@tonic-gate goto out;
7767c478bd9Sstevel@tonic-gate }
7777c478bd9Sstevel@tonic-gate memcpy(rc, &mdcreate, sizeof (mdcreate));
7787c478bd9Sstevel@tonic-gate break;
7797c478bd9Sstevel@tonic-gate
7807c478bd9Sstevel@tonic-gate case CACHEFS_LOG_GPFRONT:
7817c478bd9Sstevel@tonic-gate if ((! xdr_int(xdrs, &gpfront.error)) ||
7827c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&gpfront.time)) ||
7837c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&gpfront.vfsp,
7847c478bd9Sstevel@tonic-gate sizeof (gpfront.vfsp))) ||
7857c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&gpfront.fid,
7867c478bd9Sstevel@tonic-gate sizeof (gpfront.fid))) ||
7877c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs,
7887c478bd9Sstevel@tonic-gate (u_longlong_t *)&gpfront.fileno)) ||
7897c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&gpfront.uid)) ||
7907c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, (u_longlong_t *)&gpfront.off)) ||
7917c478bd9Sstevel@tonic-gate (! xdr_u_int(xdrs, &gpfront.len))) {
7927c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
7937c478bd9Sstevel@tonic-gate gettext("Truncated gpfront record"));
7947c478bd9Sstevel@tonic-gate goto out;
7957c478bd9Sstevel@tonic-gate }
7967c478bd9Sstevel@tonic-gate gpfront.type = *type;
7977c478bd9Sstevel@tonic-gate if ((rc = (struct cachefs_log_gpfront_record *)
7987c478bd9Sstevel@tonic-gate calloc(1, sizeof (gpfront))) == NULL) {
7997c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
8007c478bd9Sstevel@tonic-gate gettext("Cannot malloc record"));
8017c478bd9Sstevel@tonic-gate goto out;
8027c478bd9Sstevel@tonic-gate }
8037c478bd9Sstevel@tonic-gate memcpy(rc, &gpfront, sizeof (gpfront));
8047c478bd9Sstevel@tonic-gate break;
8057c478bd9Sstevel@tonic-gate
8067c478bd9Sstevel@tonic-gate case CACHEFS_LOG_RFDIR:
8077c478bd9Sstevel@tonic-gate if ((! xdr_int(xdrs, &rfdir.error)) ||
8087c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&rfdir.time)) ||
8097c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&rfdir.vfsp,
8107c478bd9Sstevel@tonic-gate sizeof (rfdir.vfsp))) ||
8117c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&rfdir.fid,
8127c478bd9Sstevel@tonic-gate sizeof (rfdir.fid))) ||
8137c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, (u_longlong_t *)&rfdir.fileno)) ||
8147c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&rfdir.uid))) {
8157c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
8167c478bd9Sstevel@tonic-gate gettext("Truncated rfdir record"));
8177c478bd9Sstevel@tonic-gate goto out;
8187c478bd9Sstevel@tonic-gate }
8197c478bd9Sstevel@tonic-gate rfdir.type = *type;
8207c478bd9Sstevel@tonic-gate if ((rc = (struct cachefs_log_rfdir_record *)
8217c478bd9Sstevel@tonic-gate calloc(1, sizeof (rfdir))) == NULL) {
8227c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
8237c478bd9Sstevel@tonic-gate gettext("Cannot malloc record"));
8247c478bd9Sstevel@tonic-gate goto out;
8257c478bd9Sstevel@tonic-gate }
8267c478bd9Sstevel@tonic-gate memcpy(rc, &rfdir, sizeof (rfdir));
8277c478bd9Sstevel@tonic-gate break;
8287c478bd9Sstevel@tonic-gate
8297c478bd9Sstevel@tonic-gate case CACHEFS_LOG_UALLOC:
8307c478bd9Sstevel@tonic-gate if ((! xdr_int(xdrs, &ualloc.error)) ||
8317c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&ualloc.time)) ||
8327c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&ualloc.vfsp,
8337c478bd9Sstevel@tonic-gate sizeof (ualloc.vfsp))) ||
8347c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&ualloc.fid,
8357c478bd9Sstevel@tonic-gate sizeof (ualloc.fid))) ||
8367c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs,
8377c478bd9Sstevel@tonic-gate (u_longlong_t *)&ualloc.fileno)) ||
8387c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, (u_longlong_t *)&ualloc.off)) ||
8397c478bd9Sstevel@tonic-gate (! xdr_u_int(xdrs, &ualloc.len))) {
8407c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
8417c478bd9Sstevel@tonic-gate gettext("Truncated ualloc record"));
8427c478bd9Sstevel@tonic-gate goto out;
8437c478bd9Sstevel@tonic-gate }
8447c478bd9Sstevel@tonic-gate ualloc.type = *type;
8457c478bd9Sstevel@tonic-gate if ((rc = (struct cachefs_log_ualloc_record *)
8467c478bd9Sstevel@tonic-gate calloc(1, sizeof (ualloc))) == NULL) {
8477c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
8487c478bd9Sstevel@tonic-gate gettext("Cannot malloc record"));
8497c478bd9Sstevel@tonic-gate goto out;
8507c478bd9Sstevel@tonic-gate }
8517c478bd9Sstevel@tonic-gate memcpy(rc, &ualloc, sizeof (ualloc));
8527c478bd9Sstevel@tonic-gate break;
8537c478bd9Sstevel@tonic-gate
8547c478bd9Sstevel@tonic-gate case CACHEFS_LOG_CALLOC:
8557c478bd9Sstevel@tonic-gate if ((! xdr_int(xdrs, &challoc.error)) ||
8567c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&challoc.time)) ||
8577c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&challoc.vfsp,
8587c478bd9Sstevel@tonic-gate sizeof (challoc.vfsp))) ||
8597c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&challoc.fid,
8607c478bd9Sstevel@tonic-gate sizeof (challoc.fid))) ||
8617c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs,
8627c478bd9Sstevel@tonic-gate (u_longlong_t *)&challoc.fileno)) ||
8637c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, (u_longlong_t *)&challoc.off)) ||
8647c478bd9Sstevel@tonic-gate (! xdr_u_int(xdrs, &challoc.len))) {
8657c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
8667c478bd9Sstevel@tonic-gate gettext("Truncated calloc record"));
8677c478bd9Sstevel@tonic-gate goto out;
8687c478bd9Sstevel@tonic-gate }
8697c478bd9Sstevel@tonic-gate challoc.type = *type;
8707c478bd9Sstevel@tonic-gate if ((rc = (struct cachefs_log_calloc_record *)
8717c478bd9Sstevel@tonic-gate calloc(1, sizeof (challoc))) == NULL) {
8727c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
8737c478bd9Sstevel@tonic-gate gettext("Cannot malloc record"));
8747c478bd9Sstevel@tonic-gate goto out;
8757c478bd9Sstevel@tonic-gate }
8767c478bd9Sstevel@tonic-gate memcpy(rc, &challoc, sizeof (challoc));
8777c478bd9Sstevel@tonic-gate break;
8787c478bd9Sstevel@tonic-gate
8797c478bd9Sstevel@tonic-gate case CACHEFS_LOG_NOCACHE:
8807c478bd9Sstevel@tonic-gate if ((! xdr_int(xdrs, &nocache.error)) ||
8817c478bd9Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&nocache.time)) ||
8827c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&nocache.vfsp,
8837c478bd9Sstevel@tonic-gate sizeof (nocache.vfsp))) ||
8847c478bd9Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&nocache.fid,
8857c478bd9Sstevel@tonic-gate sizeof (nocache.fid))) ||
8867c478bd9Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs,
8877c478bd9Sstevel@tonic-gate (u_longlong_t *)&nocache.fileno))) {
8887c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
8897c478bd9Sstevel@tonic-gate gettext("Truncated nocache record"));
8907c478bd9Sstevel@tonic-gate goto out;
8917c478bd9Sstevel@tonic-gate }
8927c478bd9Sstevel@tonic-gate nocache.type = *type;
8937c478bd9Sstevel@tonic-gate if ((rc = (struct cachefs_log_nocache_record *)
8947c478bd9Sstevel@tonic-gate calloc(1, sizeof (nocache))) == NULL) {
8957c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM,
8967c478bd9Sstevel@tonic-gate gettext("Cannot malloc record"));
8977c478bd9Sstevel@tonic-gate goto out;
8987c478bd9Sstevel@tonic-gate }
8997c478bd9Sstevel@tonic-gate memcpy(rc, &nocache, sizeof (nocache));
9007c478bd9Sstevel@tonic-gate break;
9017c478bd9Sstevel@tonic-gate
9027c478bd9Sstevel@tonic-gate default:
9037c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
9047c478bd9Sstevel@tonic-gate gettext("Corrupt logfile (position %x)"),
9057c478bd9Sstevel@tonic-gate ftell(st->st_logstream));
9067c478bd9Sstevel@tonic-gate break;
9077c478bd9Sstevel@tonic-gate }
9087c478bd9Sstevel@tonic-gate
9097c478bd9Sstevel@tonic-gate out:
9107c478bd9Sstevel@tonic-gate return (rc);
9117c478bd9Sstevel@tonic-gate }
9127c478bd9Sstevel@tonic-gate
9137c478bd9Sstevel@tonic-gate /*
9147c478bd9Sstevel@tonic-gate * convert a logfile record (read by stats_log_logfile_read()) to
9157c478bd9Sstevel@tonic-gate * ascii. probably not for end-user consumption, but this should be
9167c478bd9Sstevel@tonic-gate * the official way to do it.
9177c478bd9Sstevel@tonic-gate */
9187c478bd9Sstevel@tonic-gate
9197c478bd9Sstevel@tonic-gate char *
stats_log_record_toascii(stats_cookie_t * st,void * recp)9207c478bd9Sstevel@tonic-gate stats_log_record_toascii(stats_cookie_t *st, void *recp)
9217c478bd9Sstevel@tonic-gate {
9227c478bd9Sstevel@tonic-gate int rectype = *((int *)recp);
9237c478bd9Sstevel@tonic-gate int recerror = *((int *)recp + 1);
9247c478bd9Sstevel@tonic-gate time_t tt = *((time_t *)((int *)recp + 2));
9257c478bd9Sstevel@tonic-gate struct tm *tm = localtime(&tt);
9267c478bd9Sstevel@tonic-gate char buffy[BUFSIZ], *fidstr, *fidstr2, *fidstr3;
9277c478bd9Sstevel@tonic-gate
9287c478bd9Sstevel@tonic-gate struct cachefs_log_mount_record *mountp;
9297c478bd9Sstevel@tonic-gate struct cachefs_log_umount_record *umountp;
9307c478bd9Sstevel@tonic-gate struct cachefs_log_getpage_record *getpagep;
9317c478bd9Sstevel@tonic-gate struct cachefs_log_readdir_record *readdirp;
9327c478bd9Sstevel@tonic-gate struct cachefs_log_readlink_record *readlinkp;
9337c478bd9Sstevel@tonic-gate struct cachefs_log_remove_record *removep;
9347c478bd9Sstevel@tonic-gate struct cachefs_log_rmdir_record *rmdirp;
9357c478bd9Sstevel@tonic-gate struct cachefs_log_truncate_record *truncatep;
9367c478bd9Sstevel@tonic-gate struct cachefs_log_putpage_record *putpagep;
9377c478bd9Sstevel@tonic-gate struct cachefs_log_create_record *createp;
9387c478bd9Sstevel@tonic-gate struct cachefs_log_mkdir_record *mkdirp;
9397c478bd9Sstevel@tonic-gate struct cachefs_log_rename_record *renamep;
9407c478bd9Sstevel@tonic-gate struct cachefs_log_symlink_record *symlinkp;
9417c478bd9Sstevel@tonic-gate struct cachefs_log_populate_record *populatep;
9427c478bd9Sstevel@tonic-gate struct cachefs_log_csymlink_record *csymlinkp;
9437c478bd9Sstevel@tonic-gate struct cachefs_log_filldir_record *filldirp;
9447c478bd9Sstevel@tonic-gate struct cachefs_log_mdcreate_record *mdcreatep;
9457c478bd9Sstevel@tonic-gate struct cachefs_log_gpfront_record *gpfrontp;
9467c478bd9Sstevel@tonic-gate struct cachefs_log_rfdir_record *rfdirp;
9477c478bd9Sstevel@tonic-gate struct cachefs_log_ualloc_record *uallocp;
9487c478bd9Sstevel@tonic-gate struct cachefs_log_calloc_record *callocp;
9497c478bd9Sstevel@tonic-gate struct cachefs_log_nocache_record *nocachep;
9507c478bd9Sstevel@tonic-gate
9517c478bd9Sstevel@tonic-gate assert(stats_good(st));
9527c478bd9Sstevel@tonic-gate
9537c478bd9Sstevel@tonic-gate (void) sprintf(st->st_asciirec, "%2d/%-2d %2d:%.2d %2d",
9547c478bd9Sstevel@tonic-gate tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min,
9557c478bd9Sstevel@tonic-gate recerror);
9567c478bd9Sstevel@tonic-gate
9577c478bd9Sstevel@tonic-gate switch (rectype) {
9587c478bd9Sstevel@tonic-gate case CACHEFS_LOG_MOUNT:
9597c478bd9Sstevel@tonic-gate mountp = (struct cachefs_log_mount_record *)recp;
9607c478bd9Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy),
9617c478bd9Sstevel@tonic-gate " %-8s %llx %8x %d %d %s (%s)", "Mount", mountp->vfsp,
9627c478bd9Sstevel@tonic-gate mountp->flags, mountp->popsize,
9637c478bd9Sstevel@tonic-gate mountp->fgsize, mountp->path,
9647c478bd9Sstevel@tonic-gate mountp->path + mountp->pathlen + 1);
9657c478bd9Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy,
9667c478bd9Sstevel@tonic-gate sizeof (st->st_asciirec));
9677c478bd9Sstevel@tonic-gate break;
9687c478bd9Sstevel@tonic-gate
9697c478bd9Sstevel@tonic-gate case CACHEFS_LOG_UMOUNT:
9707c478bd9Sstevel@tonic-gate umountp = (struct cachefs_log_umount_record *)recp;
9717c478bd9Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), " %-8s %llx",
9727c478bd9Sstevel@tonic-gate "Umount", umountp->vfsp);
9737c478bd9Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy,
9747c478bd9Sstevel@tonic-gate sizeof (st->st_asciirec));
9757c478bd9Sstevel@tonic-gate break;
9767c478bd9Sstevel@tonic-gate
9777c478bd9Sstevel@tonic-gate case CACHEFS_LOG_GETPAGE:
9787c478bd9Sstevel@tonic-gate getpagep = (struct cachefs_log_getpage_record *)recp;
9797c478bd9Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy),
9807c478bd9Sstevel@tonic-gate " %-8s %llx %s %llu %ld %llu %u",
9817c478bd9Sstevel@tonic-gate "Getpage",
9827c478bd9Sstevel@tonic-gate getpagep->vfsp, fidstr = stats_log_fmtfid(&getpagep->fid),
9837c478bd9Sstevel@tonic-gate getpagep->fileno,
9847c478bd9Sstevel@tonic-gate getpagep->uid, getpagep->offset, getpagep->len);
9857c478bd9Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy,
9867c478bd9Sstevel@tonic-gate sizeof (st->st_asciirec));
9877c478bd9Sstevel@tonic-gate free(fidstr);
9887c478bd9Sstevel@tonic-gate break;
9897c478bd9Sstevel@tonic-gate
9907c478bd9Sstevel@tonic-gate case CACHEFS_LOG_READDIR:
9917c478bd9Sstevel@tonic-gate readdirp = (struct cachefs_log_readdir_record *)recp;
9927c478bd9Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy),
9937c478bd9Sstevel@tonic-gate " %-8s %llx %s %llu %d %llx %d", "Readdir",
9947c478bd9Sstevel@tonic-gate readdirp->vfsp, fidstr = stats_log_fmtfid(&readdirp->fid),
9957c478bd9Sstevel@tonic-gate readdirp->fileno,
9967c478bd9Sstevel@tonic-gate readdirp->uid, readdirp->offset, readdirp->eof);
9977c478bd9Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy,
9987c478bd9Sstevel@tonic-gate sizeof (st->st_asciirec));
9997c478bd9Sstevel@tonic-gate free(fidstr);
10007c478bd9Sstevel@tonic-gate break;
10017c478bd9Sstevel@tonic-gate
10027c478bd9Sstevel@tonic-gate case CACHEFS_LOG_READLINK:
10037c478bd9Sstevel@tonic-gate readlinkp = (struct cachefs_log_readlink_record *)recp;
10047c478bd9Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy),
10057c478bd9Sstevel@tonic-gate " %-8s %llx %s %llu %d %u", "Readlink",
10067c478bd9Sstevel@tonic-gate readlinkp->vfsp,
10077c478bd9Sstevel@tonic-gate fidstr = stats_log_fmtfid(&readlinkp->fid),
10087c478bd9Sstevel@tonic-gate readlinkp->fileno,
10097c478bd9Sstevel@tonic-gate readlinkp->uid, readlinkp->length);
10107c478bd9Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy,
10117c478bd9Sstevel@tonic-gate sizeof (st->st_asciirec));
10127c478bd9Sstevel@tonic-gate free(fidstr);
10137c478bd9Sstevel@tonic-gate break;
10147c478bd9Sstevel@tonic-gate
10157c478bd9Sstevel@tonic-gate case CACHEFS_LOG_REMOVE:
10167c478bd9Sstevel@tonic-gate removep = (struct cachefs_log_remove_record *)recp;
10177c478bd9Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy),
10187c478bd9Sstevel@tonic-gate " %-8s %llx %s %llu %d", "Remove",
10197c478bd9Sstevel@tonic-gate removep->vfsp, fidstr = stats_log_fmtfid(&removep->fid),
10207c478bd9Sstevel@tonic-gate removep->fileno,
10217c478bd9Sstevel@tonic-gate removep->uid);
10227c478bd9Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy,
10237c478bd9Sstevel@tonic-gate sizeof (st->st_asciirec));
10247c478bd9Sstevel@tonic-gate free(fidstr);
10257c478bd9Sstevel@tonic-gate break;
10267c478bd9Sstevel@tonic-gate
10277c478bd9Sstevel@tonic-gate case CACHEFS_LOG_RMDIR:
10287c478bd9Sstevel@tonic-gate rmdirp = (struct cachefs_log_rmdir_record *)recp;
10297c478bd9Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy),
10307c478bd9Sstevel@tonic-gate " %-8s %llx %s %llu %d", "Rmdir",
10317c478bd9Sstevel@tonic-gate rmdirp->vfsp, fidstr = stats_log_fmtfid(&rmdirp->fid),
10327c478bd9Sstevel@tonic-gate rmdirp->fileno,
10337c478bd9Sstevel@tonic-gate rmdirp->uid);
10347c478bd9Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy,
10357c478bd9Sstevel@tonic-gate sizeof (st->st_asciirec));
10367c478bd9Sstevel@tonic-gate free(fidstr);
10377c478bd9Sstevel@tonic-gate break;
10387c478bd9Sstevel@tonic-gate
10397c478bd9Sstevel@tonic-gate case CACHEFS_LOG_TRUNCATE:
10407c478bd9Sstevel@tonic-gate truncatep = (struct cachefs_log_truncate_record *)recp;
10417c478bd9Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy),
10427c478bd9Sstevel@tonic-gate " %-8s %llx %s %llu %d %llu", "Truncate",
10437c478bd9Sstevel@tonic-gate truncatep->vfsp,
10447c478bd9Sstevel@tonic-gate fidstr = stats_log_fmtfid(&truncatep->fid),
10457c478bd9Sstevel@tonic-gate truncatep->fileno,
10467c478bd9Sstevel@tonic-gate truncatep->uid, truncatep->size);
10477c478bd9Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy,
10487c478bd9Sstevel@tonic-gate sizeof (st->st_asciirec));
10497c478bd9Sstevel@tonic-gate free(fidstr);
10507c478bd9Sstevel@tonic-gate break;
10517c478bd9Sstevel@tonic-gate
10527c478bd9Sstevel@tonic-gate case CACHEFS_LOG_PUTPAGE:
10537c478bd9Sstevel@tonic-gate putpagep = (struct cachefs_log_putpage_record *)recp;
10547c478bd9Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy),
10557c478bd9Sstevel@tonic-gate " %-8s %llx %s %llu %d %llu %u", "Putpage",
10567c478bd9Sstevel@tonic-gate putpagep->vfsp, fidstr = stats_log_fmtfid(&putpagep->fid),
10577c478bd9Sstevel@tonic-gate putpagep->fileno,
10587c478bd9Sstevel@tonic-gate putpagep->uid, putpagep->offset, putpagep->len);
10597c478bd9Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy,
10607c478bd9Sstevel@tonic-gate sizeof (st->st_asciirec));
10617c478bd9Sstevel@tonic-gate free(fidstr);
10627c478bd9Sstevel@tonic-gate break;
10637c478bd9Sstevel@tonic-gate
10647c478bd9Sstevel@tonic-gate case CACHEFS_LOG_CREATE:
10657c478bd9Sstevel@tonic-gate createp = (struct cachefs_log_create_record *)recp;
10667c478bd9Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy),
10677c478bd9Sstevel@tonic-gate " %-8s %llx %s %llu %d", "Create",
10687c478bd9Sstevel@tonic-gate createp->vfsp,
10697c478bd9Sstevel@tonic-gate fidstr = stats_log_fmtfid(&createp->fid),
10707c478bd9Sstevel@tonic-gate createp->fileno,
10717c478bd9Sstevel@tonic-gate createp->uid);
10727c478bd9Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy,
10737c478bd9Sstevel@tonic-gate sizeof (st->st_asciirec));
10747c478bd9Sstevel@tonic-gate free(fidstr);
10757c478bd9Sstevel@tonic-gate break;
10767c478bd9Sstevel@tonic-gate
10777c478bd9Sstevel@tonic-gate case CACHEFS_LOG_MKDIR:
10787c478bd9Sstevel@tonic-gate mkdirp = (struct cachefs_log_mkdir_record *)recp;
10797c478bd9Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy),
10807c478bd9Sstevel@tonic-gate " %-8s %llx %s %llu %d", "Mkdir",
10817c478bd9Sstevel@tonic-gate mkdirp->vfsp,
10827c478bd9Sstevel@tonic-gate fidstr = stats_log_fmtfid(&mkdirp->fid),
10837c478bd9Sstevel@tonic-gate mkdirp->fileno,
10847c478bd9Sstevel@tonic-gate mkdirp->uid);
10857c478bd9Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy,
10867c478bd9Sstevel@tonic-gate sizeof (st->st_asciirec));
10877c478bd9Sstevel@tonic-gate free(fidstr);
10887c478bd9Sstevel@tonic-gate break;
10897c478bd9Sstevel@tonic-gate
10907c478bd9Sstevel@tonic-gate case CACHEFS_LOG_RENAME:
10917c478bd9Sstevel@tonic-gate renamep = (struct cachefs_log_rename_record *)recp;
10927c478bd9Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy),
10937c478bd9Sstevel@tonic-gate " %-8s %llx %s %llu %d %d", "Rename",
10947c478bd9Sstevel@tonic-gate renamep->vfsp,
10957c478bd9Sstevel@tonic-gate fidstr = stats_log_fmtfid(&renamep->gone),
10967c478bd9Sstevel@tonic-gate renamep->fileno,
10977c478bd9Sstevel@tonic-gate renamep->removed, renamep->uid);
10987c478bd9Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy,
10997c478bd9Sstevel@tonic-gate sizeof (st->st_asciirec));
11007c478bd9Sstevel@tonic-gate free(fidstr);
11017c478bd9Sstevel@tonic-gate break;
11027c478bd9Sstevel@tonic-gate
11037c478bd9Sstevel@tonic-gate case CACHEFS_LOG_SYMLINK:
11047c478bd9Sstevel@tonic-gate symlinkp = (struct cachefs_log_symlink_record *)recp;
11057c478bd9Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy),
11067c478bd9Sstevel@tonic-gate " %-8s %llx %s %llu %d %u", "Symlink",
11077c478bd9Sstevel@tonic-gate symlinkp->vfsp,
11087c478bd9Sstevel@tonic-gate fidstr = stats_log_fmtfid(&symlinkp->fid),
11097c478bd9Sstevel@tonic-gate symlinkp->fileno,
11107c478bd9Sstevel@tonic-gate symlinkp->uid, symlinkp->size);
11117c478bd9Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy,
11127c478bd9Sstevel@tonic-gate sizeof (st->st_asciirec));
11137c478bd9Sstevel@tonic-gate free(fidstr);
11147c478bd9Sstevel@tonic-gate break;
11157c478bd9Sstevel@tonic-gate
11167c478bd9Sstevel@tonic-gate case CACHEFS_LOG_POPULATE:
11177c478bd9Sstevel@tonic-gate populatep = (struct cachefs_log_populate_record *)recp;
11187c478bd9Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy),
11197c478bd9Sstevel@tonic-gate " %-8s %llx %s %llu %llu %d", "Populate",
11207c478bd9Sstevel@tonic-gate populatep->vfsp,
11217c478bd9Sstevel@tonic-gate fidstr = stats_log_fmtfid(&populatep->fid),
11227c478bd9Sstevel@tonic-gate populatep->fileno,
11237c478bd9Sstevel@tonic-gate populatep->off, populatep->size);
11247c478bd9Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy,
11257c478bd9Sstevel@tonic-gate sizeof (st->st_asciirec));
11267c478bd9Sstevel@tonic-gate free(fidstr);
11277c478bd9Sstevel@tonic-gate break;
11287c478bd9Sstevel@tonic-gate
11297c478bd9Sstevel@tonic-gate case CACHEFS_LOG_CSYMLINK:
11307c478bd9Sstevel@tonic-gate csymlinkp = (struct cachefs_log_csymlink_record *)recp;
11317c478bd9Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy),
11327c478bd9Sstevel@tonic-gate " %-8s %llx %s %llu %d", "Csymlink",
11337c478bd9Sstevel@tonic-gate csymlinkp->vfsp,
11347c478bd9Sstevel@tonic-gate fidstr = stats_log_fmtfid(&csymlinkp->fid),
11357c478bd9Sstevel@tonic-gate csymlinkp->fileno,
11367c478bd9Sstevel@tonic-gate csymlinkp->size);
11377c478bd9Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy,
11387c478bd9Sstevel@tonic-gate sizeof (st->st_asciirec));
11397c478bd9Sstevel@tonic-gate free(fidstr);
11407c478bd9Sstevel@tonic-gate break;
11417c478bd9Sstevel@tonic-gate
11427c478bd9Sstevel@tonic-gate case CACHEFS_LOG_FILLDIR:
11437c478bd9Sstevel@tonic-gate filldirp = (struct cachefs_log_filldir_record *)recp;
11447c478bd9Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy),
11457c478bd9Sstevel@tonic-gate " %-8s %llx %s %llu %d", "Filldir",
11467c478bd9Sstevel@tonic-gate filldirp->vfsp,
11477c478bd9Sstevel@tonic-gate fidstr = stats_log_fmtfid(&filldirp->fid),
11487c478bd9Sstevel@tonic-gate filldirp->fileno,
11497c478bd9Sstevel@tonic-gate filldirp->size);
11507c478bd9Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy,
11517c478bd9Sstevel@tonic-gate sizeof (st->st_asciirec));
11527c478bd9Sstevel@tonic-gate free(fidstr);
11537c478bd9Sstevel@tonic-gate break;
11547c478bd9Sstevel@tonic-gate
11557c478bd9Sstevel@tonic-gate case CACHEFS_LOG_MDCREATE:
11567c478bd9Sstevel@tonic-gate mdcreatep = (struct cachefs_log_mdcreate_record *)recp;
11577c478bd9Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy),
11587c478bd9Sstevel@tonic-gate " %-8s %llx %s %llu %u", "Mdcreate",
11597c478bd9Sstevel@tonic-gate mdcreatep->vfsp,
11607c478bd9Sstevel@tonic-gate fidstr = stats_log_fmtfid(&mdcreatep->fid),
11617c478bd9Sstevel@tonic-gate mdcreatep->fileno, mdcreatep->count);
11627c478bd9Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy,
11637c478bd9Sstevel@tonic-gate sizeof (st->st_asciirec));
11647c478bd9Sstevel@tonic-gate free(fidstr);
11657c478bd9Sstevel@tonic-gate break;
11667c478bd9Sstevel@tonic-gate
11677c478bd9Sstevel@tonic-gate case CACHEFS_LOG_GPFRONT:
11687c478bd9Sstevel@tonic-gate gpfrontp = (struct cachefs_log_gpfront_record *)recp;
11697c478bd9Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy),
11707c478bd9Sstevel@tonic-gate " %-8s %llx %s %llu %d %llu %u", "Gpfront",
11717c478bd9Sstevel@tonic-gate gpfrontp->vfsp,
11727c478bd9Sstevel@tonic-gate fidstr = stats_log_fmtfid(&gpfrontp->fid),
11737c478bd9Sstevel@tonic-gate gpfrontp->fileno,
11747c478bd9Sstevel@tonic-gate gpfrontp->uid, gpfrontp->off, gpfrontp->len);
11757c478bd9Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy,
11767c478bd9Sstevel@tonic-gate sizeof (st->st_asciirec));
11777c478bd9Sstevel@tonic-gate free(fidstr);
11787c478bd9Sstevel@tonic-gate break;
11797c478bd9Sstevel@tonic-gate
11807c478bd9Sstevel@tonic-gate case CACHEFS_LOG_RFDIR:
11817c478bd9Sstevel@tonic-gate rfdirp = (struct cachefs_log_rfdir_record *)recp;
11827c478bd9Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy),
11837c478bd9Sstevel@tonic-gate " %-8s %llx %s %llu %d", "Rfdir",
11847c478bd9Sstevel@tonic-gate rfdirp->vfsp,
11857c478bd9Sstevel@tonic-gate fidstr = stats_log_fmtfid(&rfdirp->fid),
11867c478bd9Sstevel@tonic-gate rfdirp->fileno,
11877c478bd9Sstevel@tonic-gate rfdirp->uid);
11887c478bd9Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy,
11897c478bd9Sstevel@tonic-gate sizeof (st->st_asciirec));
11907c478bd9Sstevel@tonic-gate free(fidstr);
11917c478bd9Sstevel@tonic-gate break;
11927c478bd9Sstevel@tonic-gate
11937c478bd9Sstevel@tonic-gate case CACHEFS_LOG_UALLOC:
11947c478bd9Sstevel@tonic-gate uallocp = (struct cachefs_log_ualloc_record *)recp;
11957c478bd9Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy),
11967c478bd9Sstevel@tonic-gate " %-8s %llx %s %llu %llu %u", "Ualloc",
11977c478bd9Sstevel@tonic-gate uallocp->vfsp,
11987c478bd9Sstevel@tonic-gate fidstr = stats_log_fmtfid(&uallocp->fid),
11997c478bd9Sstevel@tonic-gate uallocp->fileno,
12007c478bd9Sstevel@tonic-gate uallocp->off, uallocp->len);
12017c478bd9Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy,
12027c478bd9Sstevel@tonic-gate sizeof (st->st_asciirec));
12037c478bd9Sstevel@tonic-gate free(fidstr);
12047c478bd9Sstevel@tonic-gate break;
12057c478bd9Sstevel@tonic-gate
12067c478bd9Sstevel@tonic-gate case CACHEFS_LOG_CALLOC:
12077c478bd9Sstevel@tonic-gate callocp = (struct cachefs_log_calloc_record *)recp;
12087c478bd9Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy),
12097c478bd9Sstevel@tonic-gate " %-8s %llx %s %llu %llu %u", "Calloc",
12107c478bd9Sstevel@tonic-gate callocp->vfsp,
12117c478bd9Sstevel@tonic-gate fidstr = stats_log_fmtfid(&callocp->fid),
12127c478bd9Sstevel@tonic-gate callocp->fileno, callocp->off, callocp->len);
12137c478bd9Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy,
12147c478bd9Sstevel@tonic-gate sizeof (st->st_asciirec));
12157c478bd9Sstevel@tonic-gate free(fidstr);
12167c478bd9Sstevel@tonic-gate break;
12177c478bd9Sstevel@tonic-gate
12187c478bd9Sstevel@tonic-gate case CACHEFS_LOG_NOCACHE:
12197c478bd9Sstevel@tonic-gate nocachep = (struct cachefs_log_nocache_record *)recp;
12207c478bd9Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy),
12217c478bd9Sstevel@tonic-gate " %-8s %llx %s %llu", "Nocache",
12227c478bd9Sstevel@tonic-gate nocachep->vfsp,
12237c478bd9Sstevel@tonic-gate fidstr = stats_log_fmtfid(&nocachep->fid),
12247c478bd9Sstevel@tonic-gate nocachep->fileno);
12257c478bd9Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy,
12267c478bd9Sstevel@tonic-gate sizeof (st->st_asciirec));
12277c478bd9Sstevel@tonic-gate free(fidstr);
12287c478bd9Sstevel@tonic-gate break;
12297c478bd9Sstevel@tonic-gate
12307c478bd9Sstevel@tonic-gate default:
12317c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
12327c478bd9Sstevel@tonic-gate gettext(
12337c478bd9Sstevel@tonic-gate "Attempt to format invalid log type=%d (position %x)"),
12347c478bd9Sstevel@tonic-gate rectype, ftell(st->st_logstream));
12357c478bd9Sstevel@tonic-gate return (NULL);
12367c478bd9Sstevel@tonic-gate }
12377c478bd9Sstevel@tonic-gate
12387c478bd9Sstevel@tonic-gate return (st->st_asciirec);
12397c478bd9Sstevel@tonic-gate }
12407c478bd9Sstevel@tonic-gate
12417c478bd9Sstevel@tonic-gate uint_t
stats_log_get_record_info(stats_cookie_t * sc,void * recp,caddr_t * vfsp,cfs_fid_t ** fidp,ino64_t * filenop,u_offset_t * offp,u_offset_t * lenp)12427c478bd9Sstevel@tonic-gate stats_log_get_record_info(stats_cookie_t *sc,
12437c478bd9Sstevel@tonic-gate void *recp, caddr_t *vfsp, cfs_fid_t **fidp, ino64_t *filenop,
12447c478bd9Sstevel@tonic-gate u_offset_t *offp, u_offset_t *lenp)
12457c478bd9Sstevel@tonic-gate {
12467c478bd9Sstevel@tonic-gate int type = ((int *)recp)[0];
12477c478bd9Sstevel@tonic-gate int error = ((int *)recp)[1];
12487c478bd9Sstevel@tonic-gate uint_t rc = 0;
12497c478bd9Sstevel@tonic-gate
12507c478bd9Sstevel@tonic-gate struct cachefs_log_getpage_record *getpagep;
12517c478bd9Sstevel@tonic-gate struct cachefs_log_readdir_record *readdirp;
12527c478bd9Sstevel@tonic-gate struct cachefs_log_readlink_record *readlinkp;
12537c478bd9Sstevel@tonic-gate struct cachefs_log_remove_record *removep;
12547c478bd9Sstevel@tonic-gate struct cachefs_log_rmdir_record *rmdirp;
12557c478bd9Sstevel@tonic-gate struct cachefs_log_truncate_record *truncatep;
12567c478bd9Sstevel@tonic-gate struct cachefs_log_putpage_record *putpagep;
12577c478bd9Sstevel@tonic-gate struct cachefs_log_create_record *createp;
12587c478bd9Sstevel@tonic-gate struct cachefs_log_mkdir_record *mkdirp;
12597c478bd9Sstevel@tonic-gate struct cachefs_log_rename_record *renamep;
12607c478bd9Sstevel@tonic-gate struct cachefs_log_symlink_record *symlinkp;
12617c478bd9Sstevel@tonic-gate struct cachefs_log_populate_record *populatep;
12627c478bd9Sstevel@tonic-gate struct cachefs_log_csymlink_record *csymlinkp;
12637c478bd9Sstevel@tonic-gate struct cachefs_log_filldir_record *filldirp;
12647c478bd9Sstevel@tonic-gate struct cachefs_log_mdcreate_record *mdcreatep;
12657c478bd9Sstevel@tonic-gate struct cachefs_log_gpfront_record *gpfrontp;
12667c478bd9Sstevel@tonic-gate struct cachefs_log_rfdir_record *rfdirp;
12677c478bd9Sstevel@tonic-gate struct cachefs_log_ualloc_record *uallocp;
12687c478bd9Sstevel@tonic-gate struct cachefs_log_calloc_record *callocp;
12697c478bd9Sstevel@tonic-gate struct cachefs_log_nocache_record *nocachep;
12707c478bd9Sstevel@tonic-gate
12717c478bd9Sstevel@tonic-gate switch (type) {
12727c478bd9Sstevel@tonic-gate case CACHEFS_LOG_RFDIR:
12737c478bd9Sstevel@tonic-gate if ((error == EINVAL) || (error == ENOENT))
12747c478bd9Sstevel@tonic-gate error = 0;
12757c478bd9Sstevel@tonic-gate break;
12767c478bd9Sstevel@tonic-gate }
12777c478bd9Sstevel@tonic-gate
12787c478bd9Sstevel@tonic-gate if (error != 0)
12797c478bd9Sstevel@tonic-gate return (0);
12807c478bd9Sstevel@tonic-gate
12817c478bd9Sstevel@tonic-gate switch (type) {
12827c478bd9Sstevel@tonic-gate case CACHEFS_LOG_GETPAGE:
12837c478bd9Sstevel@tonic-gate getpagep = (struct cachefs_log_getpage_record *)recp;
12847c478bd9Sstevel@tonic-gate *fidp = &getpagep->fid;
12857c478bd9Sstevel@tonic-gate *filenop = getpagep->fileno;
1286*47644099Sgt29601 *vfsp = (caddr_t)(uintptr_t)getpagep->vfsp;
12877c478bd9Sstevel@tonic-gate *offp = getpagep->offset;
12887c478bd9Sstevel@tonic-gate *lenp = (u_offset_t)getpagep->len;
12897c478bd9Sstevel@tonic-gate rc = (GRI_ADD | GRI_EXPENSIVE);
12907c478bd9Sstevel@tonic-gate break;
12917c478bd9Sstevel@tonic-gate
12927c478bd9Sstevel@tonic-gate case CACHEFS_LOG_READDIR:
12937c478bd9Sstevel@tonic-gate readdirp = (struct cachefs_log_readdir_record *)recp;
12947c478bd9Sstevel@tonic-gate *fidp = &readdirp->fid;
12957c478bd9Sstevel@tonic-gate *filenop = readdirp->fileno;
1296*47644099Sgt29601 *vfsp = (caddr_t)(uintptr_t)readdirp->vfsp;
12977c478bd9Sstevel@tonic-gate *offp = readdirp->offset;
12987c478bd9Sstevel@tonic-gate *lenp = (u_offset_t)sc->st_loghead.lh_maxbsize;
12997c478bd9Sstevel@tonic-gate rc = (GRI_ADD | GRI_EXPENSIVE);
13007c478bd9Sstevel@tonic-gate break;
13017c478bd9Sstevel@tonic-gate
13027c478bd9Sstevel@tonic-gate case CACHEFS_LOG_READLINK:
13037c478bd9Sstevel@tonic-gate readlinkp = (struct cachefs_log_readlink_record *)recp;
13047c478bd9Sstevel@tonic-gate *fidp = &readlinkp->fid;
13057c478bd9Sstevel@tonic-gate *filenop = readlinkp->fileno;
1306*47644099Sgt29601 *vfsp = (caddr_t)(uintptr_t)readlinkp->vfsp;
13077c478bd9Sstevel@tonic-gate *offp = 0LL;
13087c478bd9Sstevel@tonic-gate *lenp = (u_offset_t)((readlinkp->length > C_FSL_SIZE) ?
13097c478bd9Sstevel@tonic-gate readlinkp->length : 0);
13107c478bd9Sstevel@tonic-gate rc = (GRI_ADD | GRI_EXPENSIVE);
13117c478bd9Sstevel@tonic-gate break;
13127c478bd9Sstevel@tonic-gate
13137c478bd9Sstevel@tonic-gate case CACHEFS_LOG_REMOVE:
13147c478bd9Sstevel@tonic-gate removep = (struct cachefs_log_remove_record *)recp;
13157c478bd9Sstevel@tonic-gate *fidp = &removep->fid;
13167c478bd9Sstevel@tonic-gate *filenop = removep->fileno;
1317*47644099Sgt29601 *vfsp = (caddr_t)(uintptr_t)removep->vfsp;
13187c478bd9Sstevel@tonic-gate *offp = *lenp = 0LL;
13197c478bd9Sstevel@tonic-gate rc = (GRI_TRUNC | GRI_MODIFY);
13207c478bd9Sstevel@tonic-gate break;
13217c478bd9Sstevel@tonic-gate
13227c478bd9Sstevel@tonic-gate case CACHEFS_LOG_RMDIR:
13237c478bd9Sstevel@tonic-gate rmdirp = (struct cachefs_log_rmdir_record *)recp;
13247c478bd9Sstevel@tonic-gate *fidp = &rmdirp->fid;
13257c478bd9Sstevel@tonic-gate *filenop = rmdirp->fileno;
1326*47644099Sgt29601 *vfsp = (caddr_t)(uintptr_t)rmdirp->vfsp;
13277c478bd9Sstevel@tonic-gate *offp = *lenp = 0LL;
13287c478bd9Sstevel@tonic-gate rc = (GRI_TRUNC | GRI_MODIFY);
13297c478bd9Sstevel@tonic-gate break;
13307c478bd9Sstevel@tonic-gate
13317c478bd9Sstevel@tonic-gate case CACHEFS_LOG_TRUNCATE:
13327c478bd9Sstevel@tonic-gate truncatep = (struct cachefs_log_truncate_record *)recp;
13337c478bd9Sstevel@tonic-gate *fidp = &truncatep->fid;
13347c478bd9Sstevel@tonic-gate *filenop = truncatep->fileno;
1335*47644099Sgt29601 *vfsp = (caddr_t)(uintptr_t)truncatep->vfsp;
13367c478bd9Sstevel@tonic-gate *offp = 0LL;
13377c478bd9Sstevel@tonic-gate *lenp = truncatep->size;
13387c478bd9Sstevel@tonic-gate rc = (GRI_TRUNC | GRI_MODIFY);
13397c478bd9Sstevel@tonic-gate break;
13407c478bd9Sstevel@tonic-gate
13417c478bd9Sstevel@tonic-gate case CACHEFS_LOG_PUTPAGE:
13427c478bd9Sstevel@tonic-gate putpagep = (struct cachefs_log_putpage_record *)recp;
13437c478bd9Sstevel@tonic-gate *fidp = &putpagep->fid;
13447c478bd9Sstevel@tonic-gate *filenop = putpagep->fileno;
1345*47644099Sgt29601 *vfsp = (caddr_t)(uintptr_t)putpagep->vfsp;
13467c478bd9Sstevel@tonic-gate *offp = putpagep->offset;
13477c478bd9Sstevel@tonic-gate *lenp = (u_offset_t)putpagep->len;
13487c478bd9Sstevel@tonic-gate rc = (GRI_ADD | GRI_MODIFY);
13497c478bd9Sstevel@tonic-gate break;
13507c478bd9Sstevel@tonic-gate
13517c478bd9Sstevel@tonic-gate case CACHEFS_LOG_CREATE:
13527c478bd9Sstevel@tonic-gate createp = (struct cachefs_log_create_record *)recp;
13537c478bd9Sstevel@tonic-gate *fidp = &createp->fid;
13547c478bd9Sstevel@tonic-gate *filenop = createp->fileno;
1355*47644099Sgt29601 *vfsp = (caddr_t)(uintptr_t)createp->vfsp;
13567c478bd9Sstevel@tonic-gate *offp = *lenp = 0LL;
13577c478bd9Sstevel@tonic-gate rc = (GRI_ADD | GRI_MODIFY);
13587c478bd9Sstevel@tonic-gate break;
13597c478bd9Sstevel@tonic-gate
13607c478bd9Sstevel@tonic-gate case CACHEFS_LOG_MKDIR:
13617c478bd9Sstevel@tonic-gate mkdirp = (struct cachefs_log_mkdir_record *)recp;
13627c478bd9Sstevel@tonic-gate *fidp = &mkdirp->fid;
13637c478bd9Sstevel@tonic-gate *filenop = mkdirp->fileno;
1364*47644099Sgt29601 *vfsp = (caddr_t)(uintptr_t)mkdirp->vfsp;
13657c478bd9Sstevel@tonic-gate *offp = *lenp = 0LL;
13667c478bd9Sstevel@tonic-gate rc = (GRI_ADD | GRI_MODIFY);
13677c478bd9Sstevel@tonic-gate break;
13687c478bd9Sstevel@tonic-gate
13697c478bd9Sstevel@tonic-gate case CACHEFS_LOG_RENAME:
13707c478bd9Sstevel@tonic-gate renamep = (struct cachefs_log_rename_record *)recp;
13717c478bd9Sstevel@tonic-gate *fidp = &renamep->gone;
13727c478bd9Sstevel@tonic-gate *filenop = renamep->fileno;
1373*47644099Sgt29601 *vfsp = (caddr_t)(uintptr_t)renamep->vfsp;
13747c478bd9Sstevel@tonic-gate *offp = *lenp = 0LL;
13757c478bd9Sstevel@tonic-gate rc = GRI_MODIFY;
13767c478bd9Sstevel@tonic-gate if (renamep->removed)
13777c478bd9Sstevel@tonic-gate rc |= GRI_TRUNC;
13787c478bd9Sstevel@tonic-gate break;
13797c478bd9Sstevel@tonic-gate
13807c478bd9Sstevel@tonic-gate case CACHEFS_LOG_SYMLINK:
13817c478bd9Sstevel@tonic-gate symlinkp = (struct cachefs_log_symlink_record *)recp;
13827c478bd9Sstevel@tonic-gate *fidp = &symlinkp->fid;
13837c478bd9Sstevel@tonic-gate *filenop = symlinkp->fileno;
1384*47644099Sgt29601 *vfsp = (caddr_t)(uintptr_t)symlinkp->vfsp;
13857c478bd9Sstevel@tonic-gate *offp = 0LL;
13867c478bd9Sstevel@tonic-gate *lenp = (u_offset_t)((symlinkp->size > C_FSL_SIZE) ?
13877c478bd9Sstevel@tonic-gate symlinkp->size : 0);
13887c478bd9Sstevel@tonic-gate rc = (GRI_ADD | GRI_MODIFY);
13897c478bd9Sstevel@tonic-gate break;
13907c478bd9Sstevel@tonic-gate
13917c478bd9Sstevel@tonic-gate case CACHEFS_LOG_POPULATE:
13927c478bd9Sstevel@tonic-gate populatep = (struct cachefs_log_populate_record *)recp;
13937c478bd9Sstevel@tonic-gate *fidp = &populatep->fid;
13947c478bd9Sstevel@tonic-gate *filenop = populatep->fileno;
1395*47644099Sgt29601 *vfsp = (caddr_t)(uintptr_t)populatep->vfsp;
13967c478bd9Sstevel@tonic-gate *offp = populatep->off;
13977c478bd9Sstevel@tonic-gate *lenp = (u_offset_t)populatep->size;
13987c478bd9Sstevel@tonic-gate rc = GRI_ADD;
13997c478bd9Sstevel@tonic-gate break;
14007c478bd9Sstevel@tonic-gate
14017c478bd9Sstevel@tonic-gate case CACHEFS_LOG_CSYMLINK:
14027c478bd9Sstevel@tonic-gate csymlinkp = (struct cachefs_log_csymlink_record *)recp;
14037c478bd9Sstevel@tonic-gate *fidp = &csymlinkp->fid;
14047c478bd9Sstevel@tonic-gate *filenop = csymlinkp->fileno;
1405*47644099Sgt29601 *vfsp = (caddr_t)(uintptr_t)csymlinkp->vfsp;
14067c478bd9Sstevel@tonic-gate *offp = 0LL;
14077c478bd9Sstevel@tonic-gate *lenp = (u_offset_t)((csymlinkp->size > C_FSL_SIZE) ?
14087c478bd9Sstevel@tonic-gate csymlinkp->size : 0);
14097c478bd9Sstevel@tonic-gate rc = GRI_ADD;
14107c478bd9Sstevel@tonic-gate break;
14117c478bd9Sstevel@tonic-gate
14127c478bd9Sstevel@tonic-gate case CACHEFS_LOG_FILLDIR:
14137c478bd9Sstevel@tonic-gate filldirp = (struct cachefs_log_filldir_record *)recp;
14147c478bd9Sstevel@tonic-gate *fidp = &filldirp->fid;
14157c478bd9Sstevel@tonic-gate *filenop = filldirp->fileno;
1416*47644099Sgt29601 *vfsp = (caddr_t)(uintptr_t)filldirp->vfsp;
14177c478bd9Sstevel@tonic-gate *offp = 0LL;
14187c478bd9Sstevel@tonic-gate *lenp = (u_offset_t)(filldirp->size);
14197c478bd9Sstevel@tonic-gate rc = GRI_ADD;
14207c478bd9Sstevel@tonic-gate break;
14217c478bd9Sstevel@tonic-gate
14227c478bd9Sstevel@tonic-gate case CACHEFS_LOG_MDCREATE:
14237c478bd9Sstevel@tonic-gate mdcreatep = (struct cachefs_log_mdcreate_record *)recp;
14247c478bd9Sstevel@tonic-gate *fidp = &mdcreatep->fid;
14257c478bd9Sstevel@tonic-gate *filenop = mdcreatep->fileno;
1426*47644099Sgt29601 *vfsp = (caddr_t)(uintptr_t)mdcreatep->vfsp;
14277c478bd9Sstevel@tonic-gate *lenp = (u_offset_t)mdcreatep->count;
14287c478bd9Sstevel@tonic-gate rc = GRI_METADATA;
14297c478bd9Sstevel@tonic-gate break;
14307c478bd9Sstevel@tonic-gate
14317c478bd9Sstevel@tonic-gate case CACHEFS_LOG_GPFRONT:
14327c478bd9Sstevel@tonic-gate gpfrontp = (struct cachefs_log_gpfront_record *)recp;
14337c478bd9Sstevel@tonic-gate *fidp = &gpfrontp->fid;
14347c478bd9Sstevel@tonic-gate *filenop = gpfrontp->fileno;
1435*47644099Sgt29601 *vfsp = (caddr_t)(uintptr_t)gpfrontp->vfsp;
14367c478bd9Sstevel@tonic-gate *offp = gpfrontp->off;
14377c478bd9Sstevel@tonic-gate *lenp = (u_offset_t)sc->st_loghead.lh_pagesize;
14387c478bd9Sstevel@tonic-gate rc = (GRI_ADD | GRI_EXPENSIVE);
14397c478bd9Sstevel@tonic-gate break;
14407c478bd9Sstevel@tonic-gate
14417c478bd9Sstevel@tonic-gate case CACHEFS_LOG_RFDIR:
14427c478bd9Sstevel@tonic-gate rfdirp = (struct cachefs_log_rfdir_record *)recp;
14437c478bd9Sstevel@tonic-gate rfdirp->error = 0;
14447c478bd9Sstevel@tonic-gate *fidp = &rfdirp->fid;
14457c478bd9Sstevel@tonic-gate *filenop = rfdirp->fileno;
1446*47644099Sgt29601 *vfsp = (caddr_t)(uintptr_t)rfdirp->vfsp;
14477c478bd9Sstevel@tonic-gate *offp = 0LL;
14487c478bd9Sstevel@tonic-gate *lenp = (u_offset_t)sc->st_loghead.lh_maxbsize;
14497c478bd9Sstevel@tonic-gate rc = (GRI_ADD | GRI_EXPENSIVE);
14507c478bd9Sstevel@tonic-gate break;
14517c478bd9Sstevel@tonic-gate
14527c478bd9Sstevel@tonic-gate case CACHEFS_LOG_UALLOC:
14537c478bd9Sstevel@tonic-gate uallocp = (struct cachefs_log_ualloc_record *)recp;
14547c478bd9Sstevel@tonic-gate *fidp = &uallocp->fid;
14557c478bd9Sstevel@tonic-gate *filenop = uallocp->fileno;
1456*47644099Sgt29601 *vfsp = (caddr_t)(uintptr_t)uallocp->vfsp;
14577c478bd9Sstevel@tonic-gate *offp = uallocp->off;
14587c478bd9Sstevel@tonic-gate *lenp = (u_offset_t)uallocp->len;
14597c478bd9Sstevel@tonic-gate rc = (GRI_ADD);
14607c478bd9Sstevel@tonic-gate break;
14617c478bd9Sstevel@tonic-gate
14627c478bd9Sstevel@tonic-gate case CACHEFS_LOG_CALLOC:
14637c478bd9Sstevel@tonic-gate callocp = (struct cachefs_log_calloc_record *)recp;
14647c478bd9Sstevel@tonic-gate *fidp = &callocp->fid;
14657c478bd9Sstevel@tonic-gate *filenop = callocp->fileno;
1466*47644099Sgt29601 *vfsp = (caddr_t)(uintptr_t)callocp->vfsp;
14677c478bd9Sstevel@tonic-gate *offp = callocp->off;
14687c478bd9Sstevel@tonic-gate *lenp = (u_offset_t)callocp->len;
14697c478bd9Sstevel@tonic-gate rc = (GRI_ADD | GRI_EXPENSIVE);
14707c478bd9Sstevel@tonic-gate break;
14717c478bd9Sstevel@tonic-gate
14727c478bd9Sstevel@tonic-gate case CACHEFS_LOG_NOCACHE:
14737c478bd9Sstevel@tonic-gate nocachep = (struct cachefs_log_nocache_record *)recp;
14747c478bd9Sstevel@tonic-gate *fidp = &nocachep->fid;
14757c478bd9Sstevel@tonic-gate *filenop = nocachep->fileno;
1476*47644099Sgt29601 *vfsp = (caddr_t)(uintptr_t)nocachep->vfsp;
14777c478bd9Sstevel@tonic-gate *offp = *lenp = 0LL;
14787c478bd9Sstevel@tonic-gate rc = (GRI_TRUNC);
14797c478bd9Sstevel@tonic-gate break;
14807c478bd9Sstevel@tonic-gate }
14817c478bd9Sstevel@tonic-gate
14827c478bd9Sstevel@tonic-gate return (rc);
14837c478bd9Sstevel@tonic-gate }
14847c478bd9Sstevel@tonic-gate
14857c478bd9Sstevel@tonic-gate /*
14867c478bd9Sstevel@tonic-gate * ascii formatter for fids. returns a malloc()ed string -- it's up to
14877c478bd9Sstevel@tonic-gate * the caller to free it.
14887c478bd9Sstevel@tonic-gate */
14897c478bd9Sstevel@tonic-gate
14907c478bd9Sstevel@tonic-gate static char *
stats_log_fmtfid(cfs_fid_t * fidp)14917c478bd9Sstevel@tonic-gate stats_log_fmtfid(cfs_fid_t *fidp)
14927c478bd9Sstevel@tonic-gate {
14937c478bd9Sstevel@tonic-gate char buffy[BUFSIZ], *rc;
14947c478bd9Sstevel@tonic-gate
14957c478bd9Sstevel@tonic-gate (void) strcpy(buffy, "<fid>");
14967c478bd9Sstevel@tonic-gate
14977c478bd9Sstevel@tonic-gate rc = strdup(buffy);
14987c478bd9Sstevel@tonic-gate if (rc == NULL)
14997c478bd9Sstevel@tonic-gate rc = "out of memory";
15007c478bd9Sstevel@tonic-gate
15017c478bd9Sstevel@tonic-gate return (rc);
15027c478bd9Sstevel@tonic-gate }
15037c478bd9Sstevel@tonic-gate
15047c478bd9Sstevel@tonic-gate void
stats_log_fi_add(stats_cookie_t * st,fid_info * fip,u_offset_t off,u_offset_t len)15057c478bd9Sstevel@tonic-gate stats_log_fi_add(stats_cookie_t *st, fid_info *fip, u_offset_t off,
15067c478bd9Sstevel@tonic-gate u_offset_t len)
15077c478bd9Sstevel@tonic-gate {
15087c478bd9Sstevel@tonic-gate int i, j;
15097c478bd9Sstevel@tonic-gate u_offset_t iend, jend, tmp;
15107c478bd9Sstevel@tonic-gate
15117c478bd9Sstevel@tonic-gate assert(stats_good(st));
15127c478bd9Sstevel@tonic-gate assert(st->st_flags & ST_DBMOPEN);
15137c478bd9Sstevel@tonic-gate assert(st->st_flags & ST_LFOPEN);
15147c478bd9Sstevel@tonic-gate
15157c478bd9Sstevel@tonic-gate /* shortcut if we had some sort of zero-length thing */
15167c478bd9Sstevel@tonic-gate
15177c478bd9Sstevel@tonic-gate if (len == 0LL)
15187c478bd9Sstevel@tonic-gate return;
15197c478bd9Sstevel@tonic-gate
15207c478bd9Sstevel@tonic-gate /* `smear' the offset and length to block boundaries */
15217c478bd9Sstevel@tonic-gate
15227c478bd9Sstevel@tonic-gate /*
15237c478bd9Sstevel@tonic-gate * pre-largefiles: iend = off & ~(st->st_loghead.lh_maxbsize - 1);
15247c478bd9Sstevel@tonic-gate * largefiles: make sure that we ~ all bits in the 64 bit
15257c478bd9Sstevel@tonic-gate * version of (st->st_loghead.lh_maxbsize - 1)
15267c478bd9Sstevel@tonic-gate */
15277c478bd9Sstevel@tonic-gate tmp = (u_offset_t)(st->st_loghead.lh_maxbsize - 1);
15287c478bd9Sstevel@tonic-gate iend = off & ~tmp;
15297c478bd9Sstevel@tonic-gate
15307c478bd9Sstevel@tonic-gate jend = off + len;
15317c478bd9Sstevel@tonic-gate jend += (u_offset_t)(st->st_loghead.lh_maxbsize - 1);
15327c478bd9Sstevel@tonic-gate /*
15337c478bd9Sstevel@tonic-gate * pre-largefiles: jend &= ~(st->st_loghead.lh_maxbsize - 1);
15347c478bd9Sstevel@tonic-gate * largefiles: make sure that we ~ all bits in the 64 bit
15357c478bd9Sstevel@tonic-gate * version of (st->st_loghead.lh_maxbsize - 1)
15367c478bd9Sstevel@tonic-gate */
15377c478bd9Sstevel@tonic-gate jend &= ~tmp;
15387c478bd9Sstevel@tonic-gate
15397c478bd9Sstevel@tonic-gate off = iend;
15407c478bd9Sstevel@tonic-gate len = jend - off;
15417c478bd9Sstevel@tonic-gate
15427c478bd9Sstevel@tonic-gate /* see if our offset falls within an existing chunk */
15437c478bd9Sstevel@tonic-gate for (i = 0; i < fip->fi_ent_n; i++) {
15447c478bd9Sstevel@tonic-gate iend = fip->fi_ent[i].offset + fip->fi_ent[i].len;
15457c478bd9Sstevel@tonic-gate if ((fip->fi_ent[i].offset <= off) && (iend >= off))
15467c478bd9Sstevel@tonic-gate break;
15477c478bd9Sstevel@tonic-gate }
15487c478bd9Sstevel@tonic-gate
15497c478bd9Sstevel@tonic-gate /* update the chunk, or make a new one */
15507c478bd9Sstevel@tonic-gate if (i < fip->fi_ent_n) {
15517c478bd9Sstevel@tonic-gate if ((off + len) > iend)
15527c478bd9Sstevel@tonic-gate fip->fi_ent[i].len = off + len - fip->fi_ent[i].offset;
15537c478bd9Sstevel@tonic-gate } else if (i < C_MAX_ALLOCINFO_SLOTS) {
15547c478bd9Sstevel@tonic-gate fip->fi_ent_n = i + 1;
15557c478bd9Sstevel@tonic-gate fip->fi_ent[i].offset = off;
15567c478bd9Sstevel@tonic-gate fip->fi_ent[i].len = len;
15577c478bd9Sstevel@tonic-gate } else {
15587c478bd9Sstevel@tonic-gate /* cachefs does a nocache, so we'll immitate */
15597c478bd9Sstevel@tonic-gate
15607c478bd9Sstevel@tonic-gate /*
15617c478bd9Sstevel@tonic-gate * XXX we're free to grow again. assume we got
15627c478bd9Sstevel@tonic-gate * inactivated right away -- the worst case!
15637c478bd9Sstevel@tonic-gate */
15647c478bd9Sstevel@tonic-gate
15657c478bd9Sstevel@tonic-gate fip->fi_ent_n = 0;
15667c478bd9Sstevel@tonic-gate fip->fi_total = 0LL;
15677c478bd9Sstevel@tonic-gate }
15687c478bd9Sstevel@tonic-gate
15697c478bd9Sstevel@tonic-gate /* quit for the trivial (hopefully the usual) case... */
15707c478bd9Sstevel@tonic-gate if (fip->fi_ent_n <= 1) {
15717c478bd9Sstevel@tonic-gate if (fip->fi_ent_n == 0)
15727c478bd9Sstevel@tonic-gate fip->fi_total = 0LL;
15737c478bd9Sstevel@tonic-gate else
15747c478bd9Sstevel@tonic-gate fip->fi_total = fip->fi_ent[0].len;
15757c478bd9Sstevel@tonic-gate return;
15767c478bd9Sstevel@tonic-gate }
15777c478bd9Sstevel@tonic-gate
15787c478bd9Sstevel@tonic-gate /*
15797c478bd9Sstevel@tonic-gate * we have to see if we can consolidate any chunks. the
15807c478bd9Sstevel@tonic-gate * chunks aren't guaranteed to be in any kind of order, so we
15817c478bd9Sstevel@tonic-gate * do a qsort. otherwise, the consolidation would be N^2 (but
15827c478bd9Sstevel@tonic-gate * we're probably close here).
15837c478bd9Sstevel@tonic-gate */
15847c478bd9Sstevel@tonic-gate
15857c478bd9Sstevel@tonic-gate qsort(fip->fi_ent, fip->fi_ent_n, sizeof (fip->fi_ent[0]),
15867c478bd9Sstevel@tonic-gate stats_log_fi_comp);
15877c478bd9Sstevel@tonic-gate
15887c478bd9Sstevel@tonic-gate /* tag non-essential entries with offset == -1, and consolidate */
15897c478bd9Sstevel@tonic-gate for (i = 0; i < fip->fi_ent_n - 1; i++) {
15907c478bd9Sstevel@tonic-gate if ((offset_t)fip->fi_ent[i].offset < 0)
15917c478bd9Sstevel@tonic-gate continue;
15927c478bd9Sstevel@tonic-gate iend = fip->fi_ent[i].offset + fip->fi_ent[i].len;
15937c478bd9Sstevel@tonic-gate
15947c478bd9Sstevel@tonic-gate for (j = i + 1; j < fip->fi_ent_n; j++) {
15957c478bd9Sstevel@tonic-gate if (iend < fip->fi_ent[j].offset)
15967c478bd9Sstevel@tonic-gate break;
15977c478bd9Sstevel@tonic-gate jend = fip->fi_ent[j].offset + fip->fi_ent[j].len;
15987c478bd9Sstevel@tonic-gate if (jend >= iend)
15997c478bd9Sstevel@tonic-gate fip->fi_ent[i].len =
16007c478bd9Sstevel@tonic-gate jend - fip->fi_ent[i].offset;
16017c478bd9Sstevel@tonic-gate fip->fi_ent[j].offset = (u_offset_t)-1;
16027c478bd9Sstevel@tonic-gate }
16037c478bd9Sstevel@tonic-gate }
16047c478bd9Sstevel@tonic-gate
16057c478bd9Sstevel@tonic-gate /* get rid of non-essential entries (without preserving order) */
16067c478bd9Sstevel@tonic-gate for (i = 0; i < fip->fi_ent_n; i++)
16077c478bd9Sstevel@tonic-gate if ((offset_t)fip->fi_ent[i].offset < 0)
16087c478bd9Sstevel@tonic-gate fip->fi_ent[i--] = fip->fi_ent[--(fip->fi_ent_n)];
16097c478bd9Sstevel@tonic-gate
16107c478bd9Sstevel@tonic-gate /* add up the new total size */
16117c478bd9Sstevel@tonic-gate for (i = fip->fi_total = 0LL; i < fip->fi_ent_n; i++)
16127c478bd9Sstevel@tonic-gate fip->fi_total += fip->fi_ent[i].len;
16137c478bd9Sstevel@tonic-gate }
16147c478bd9Sstevel@tonic-gate
16157c478bd9Sstevel@tonic-gate static int
stats_log_fi_comp(const void * a,const void * b)16167c478bd9Sstevel@tonic-gate stats_log_fi_comp(const void *a, const void *b)
16177c478bd9Sstevel@tonic-gate {
16187c478bd9Sstevel@tonic-gate struct fid_info_allocent *fa = (struct fid_info_allocent *)a;
16197c478bd9Sstevel@tonic-gate struct fid_info_allocent *fb = (struct fid_info_allocent *)b;
16207c478bd9Sstevel@tonic-gate
16217c478bd9Sstevel@tonic-gate if ((offset_t)(fa->offset - fb->offset) > 0)
16227c478bd9Sstevel@tonic-gate return (1);
16237c478bd9Sstevel@tonic-gate if ((offset_t)(fa->offset - fb->offset) < 0)
16247c478bd9Sstevel@tonic-gate return (-1);
16257c478bd9Sstevel@tonic-gate return (0);
16267c478bd9Sstevel@tonic-gate }
16277c478bd9Sstevel@tonic-gate
16287c478bd9Sstevel@tonic-gate void
stats_log_fi_trunc(stats_cookie_t * st,fid_info * fip,u_offset_t off,u_offset_t len)16297c478bd9Sstevel@tonic-gate stats_log_fi_trunc(stats_cookie_t *st, fid_info *fip, u_offset_t off,
16307c478bd9Sstevel@tonic-gate u_offset_t len)
16317c478bd9Sstevel@tonic-gate {
16327c478bd9Sstevel@tonic-gate fip->fi_ent_n = 1;
16337c478bd9Sstevel@tonic-gate fip->fi_ent[0].offset = off;
16347c478bd9Sstevel@tonic-gate fip->fi_ent[0].len = len;
16357c478bd9Sstevel@tonic-gate fip->fi_total = len;
16367c478bd9Sstevel@tonic-gate }
16377c478bd9Sstevel@tonic-gate
16387c478bd9Sstevel@tonic-gate struct cachefs_log_logfile_header *
stats_log_getheader(stats_cookie_t * st)16397c478bd9Sstevel@tonic-gate stats_log_getheader(stats_cookie_t *st)
16407c478bd9Sstevel@tonic-gate {
16417c478bd9Sstevel@tonic-gate assert(stats_good(st));
16427c478bd9Sstevel@tonic-gate assert(st->st_flags & ST_LFOPEN);
16437c478bd9Sstevel@tonic-gate
16447c478bd9Sstevel@tonic-gate return (&st->st_loghead);
16457c478bd9Sstevel@tonic-gate }
16467c478bd9Sstevel@tonic-gate
16477c478bd9Sstevel@tonic-gate void
stats_log_compute_wssize(stats_cookie_t * st)16487c478bd9Sstevel@tonic-gate stats_log_compute_wssize(stats_cookie_t *st)
16497c478bd9Sstevel@tonic-gate {
16507c478bd9Sstevel@tonic-gate void *record;
16517c478bd9Sstevel@tonic-gate int type;
16527c478bd9Sstevel@tonic-gate struct cachefs_log_mount_record *mountp;
16537c478bd9Sstevel@tonic-gate struct cachefs_log_umount_record *umountp;
16547c478bd9Sstevel@tonic-gate datum key;
16557c478bd9Sstevel@tonic-gate caddr_t vfsp;
16567c478bd9Sstevel@tonic-gate mount_info *mi = NULL, *mip;
16577c478bd9Sstevel@tonic-gate size_t len1, len2, maxlen;
16587c478bd9Sstevel@tonic-gate char *string1, *string2;
16597c478bd9Sstevel@tonic-gate uint_t rflags;
16607c478bd9Sstevel@tonic-gate fid_info fi, *fip;
16617c478bd9Sstevel@tonic-gate cfs_fid_t *fidp;
16627c478bd9Sstevel@tonic-gate ino64_t fileno;
16637c478bd9Sstevel@tonic-gate u_offset_t off;
16647c478bd9Sstevel@tonic-gate u_offset_t len;
16657c478bd9Sstevel@tonic-gate struct cachefs_log_logfile_header *lh = &st->st_loghead;
16667c478bd9Sstevel@tonic-gate size_t delta;
16677c478bd9Sstevel@tonic-gate
16687c478bd9Sstevel@tonic-gate assert(stats_good(st));
16697c478bd9Sstevel@tonic-gate assert(st->st_flags & ST_LFOPEN);
16707c478bd9Sstevel@tonic-gate assert(st->st_flags & ST_DBMOPEN);
16717c478bd9Sstevel@tonic-gate
16727c478bd9Sstevel@tonic-gate /*
16737c478bd9Sstevel@tonic-gate * The maximum size of a mount_info structure is the size of
16747c478bd9Sstevel@tonic-gate * the structure less the space already defined for char mi_path[]
16757c478bd9Sstevel@tonic-gate * plus the maximum size of mi_path.
16767c478bd9Sstevel@tonic-gate *
16777c478bd9Sstevel@tonic-gate * Additional space is allocated to mi_path at runtime using
16787c478bd9Sstevel@tonic-gate * malloc(). The size needs to be calculated in-situ as ANSI C
16797c478bd9Sstevel@tonic-gate * will only allow 'sizeof expression' or 'sizeof (type)'.
16807c478bd9Sstevel@tonic-gate */
16817c478bd9Sstevel@tonic-gate
16827c478bd9Sstevel@tonic-gate mi = malloc(sizeof (*mi) - sizeof (mi->mi_path) + MI_MAX_MI_PATH);
16837c478bd9Sstevel@tonic-gate if (mi == NULL) {
16847c478bd9Sstevel@tonic-gate stats_perror(st, SE_NOMEM, gettext("Out of memory"));
16857c478bd9Sstevel@tonic-gate goto out;
16867c478bd9Sstevel@tonic-gate }
16877c478bd9Sstevel@tonic-gate
16887c478bd9Sstevel@tonic-gate st->st_ws_init = st->st_loghead.lh_blocks;
16897c478bd9Sstevel@tonic-gate
16907c478bd9Sstevel@tonic-gate while (record = stats_log_logfile_read(st, &type)) {
16917c478bd9Sstevel@tonic-gate switch (type) {
16927c478bd9Sstevel@tonic-gate case CACHEFS_LOG_MOUNT:
16937c478bd9Sstevel@tonic-gate mountp = (struct cachefs_log_mount_record *)record;
16947c478bd9Sstevel@tonic-gate if (mountp->error != 0)
16957c478bd9Sstevel@tonic-gate break;
16967c478bd9Sstevel@tonic-gate for (key = stats_dbm_firstkey(st);
16977c478bd9Sstevel@tonic-gate key.dptr != NULL;
16987c478bd9Sstevel@tonic-gate key = stats_dbm_nextkey(st)) {
16997c478bd9Sstevel@tonic-gate if (key.dsize != sizeof (vfsp))
17007c478bd9Sstevel@tonic-gate continue;
17017c478bd9Sstevel@tonic-gate
17027c478bd9Sstevel@tonic-gate memcpy((caddr_t)&vfsp, key.dptr,
17037c478bd9Sstevel@tonic-gate sizeof (vfsp));
17047c478bd9Sstevel@tonic-gate mip = stats_dbm_fetch_byvfsp(st, vfsp);
17057c478bd9Sstevel@tonic-gate if (mip == NULL)
17067c478bd9Sstevel@tonic-gate continue;
17077c478bd9Sstevel@tonic-gate
17087c478bd9Sstevel@tonic-gate len1 = strlen(mip->mi_path);
17097c478bd9Sstevel@tonic-gate len2 = strlen(mip->mi_path + len1 + 1);
17107c478bd9Sstevel@tonic-gate memcpy((caddr_t)mi, mip, sizeof (*mi) +
17117c478bd9Sstevel@tonic-gate len1 + len2 - CLPAD(mount_info, mi_path));
17127c478bd9Sstevel@tonic-gate free(mip);
17137c478bd9Sstevel@tonic-gate
17147c478bd9Sstevel@tonic-gate string1 = mi->mi_path + len1 + 1;
17157c478bd9Sstevel@tonic-gate string2 = mountp->path + mountp->pathlen + 1;
17167c478bd9Sstevel@tonic-gate if (strcmp(string1, string2) == 0) {
17177c478bd9Sstevel@tonic-gate stats_dbm_delete_byvfsp(st, vfsp);
17187c478bd9Sstevel@tonic-gate break;
17197c478bd9Sstevel@tonic-gate }
17207c478bd9Sstevel@tonic-gate }
17217c478bd9Sstevel@tonic-gate if (key.dptr == NULL) {
17227c478bd9Sstevel@tonic-gate /* non-idempotent setup stuff */
17237c478bd9Sstevel@tonic-gate memset(mi, '\0', sizeof (*mi));
17247c478bd9Sstevel@tonic-gate mi->mi_flags = mountp->flags;
17257c478bd9Sstevel@tonic-gate mi->mi_filegrp_size = mountp->fgsize;
17267c478bd9Sstevel@tonic-gate }
17277c478bd9Sstevel@tonic-gate
17287c478bd9Sstevel@tonic-gate /*
17297c478bd9Sstevel@tonic-gate * idempotent setup stuff
17307c478bd9Sstevel@tonic-gate *
17317c478bd9Sstevel@tonic-gate * Careful string handling around mi_path
17327c478bd9Sstevel@tonic-gate * is required as it contains two NULL
17337c478bd9Sstevel@tonic-gate * terminated strings.
17347c478bd9Sstevel@tonic-gate */
17357c478bd9Sstevel@tonic-gate
17367c478bd9Sstevel@tonic-gate mi->mi_mounted = 1;
17377c478bd9Sstevel@tonic-gate maxlen = MI_MAX_MI_PATH - 1;
17387c478bd9Sstevel@tonic-gate len1 = strlcpy(mi->mi_path, mountp->path, maxlen);
17397c478bd9Sstevel@tonic-gate if (len1 >= maxlen) {
17407c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
17417c478bd9Sstevel@tonic-gate gettext("Path too long in log file"));
17427c478bd9Sstevel@tonic-gate break;
17437c478bd9Sstevel@tonic-gate }
17447c478bd9Sstevel@tonic-gate
17457c478bd9Sstevel@tonic-gate len1 = strlen(mi->mi_path);
17467c478bd9Sstevel@tonic-gate maxlen = MI_MAX_MI_PATH - (len1 + 1);
17477c478bd9Sstevel@tonic-gate len2 = strlcpy(mi->mi_path + len1 + 1,
17487c478bd9Sstevel@tonic-gate mountp->path + mountp->pathlen + 1, maxlen);
17497c478bd9Sstevel@tonic-gate if (len2 >= maxlen) {
17507c478bd9Sstevel@tonic-gate stats_perror(st, SE_CORRUPT,
17517c478bd9Sstevel@tonic-gate gettext("CacheID too long in log file"));
17527c478bd9Sstevel@tonic-gate break;
17537c478bd9Sstevel@tonic-gate }
17547c478bd9Sstevel@tonic-gate
1755*47644099Sgt29601 stats_dbm_store_byvfsp(st,
1756*47644099Sgt29601 (caddr_t)(uintptr_t)mountp->vfsp, mi);
17577c478bd9Sstevel@tonic-gate break;
17587c478bd9Sstevel@tonic-gate
17597c478bd9Sstevel@tonic-gate case CACHEFS_LOG_UMOUNT:
17607c478bd9Sstevel@tonic-gate umountp = (struct cachefs_log_umount_record *)record;
17617c478bd9Sstevel@tonic-gate if (umountp->error != 0)
17627c478bd9Sstevel@tonic-gate break;
17637c478bd9Sstevel@tonic-gate mip = stats_dbm_fetch_byvfsp(st,
1764*47644099Sgt29601 (caddr_t)(uintptr_t)umountp->vfsp);
17657c478bd9Sstevel@tonic-gate if (mip == NULL)
17667c478bd9Sstevel@tonic-gate break;
17677c478bd9Sstevel@tonic-gate mip->mi_mounted = 0;
1768*47644099Sgt29601 stats_dbm_store_byvfsp(st,
1769*47644099Sgt29601 (caddr_t)(uintptr_t)umountp->vfsp, mip);
17707c478bd9Sstevel@tonic-gate free(mip);
17717c478bd9Sstevel@tonic-gate break;
17727c478bd9Sstevel@tonic-gate
17737c478bd9Sstevel@tonic-gate default:
17747c478bd9Sstevel@tonic-gate rflags = stats_log_get_record_info(st, record,
17757c478bd9Sstevel@tonic-gate &vfsp, &fidp, &fileno, &off, &len);
17767c478bd9Sstevel@tonic-gate if (rflags == 0) /* shortcut */
17777c478bd9Sstevel@tonic-gate break;
17787c478bd9Sstevel@tonic-gate
17797c478bd9Sstevel@tonic-gate mip = stats_dbm_fetch_byvfsp(st, vfsp);
17807c478bd9Sstevel@tonic-gate if (mip == NULL) /* hopefully very rare */
17817c478bd9Sstevel@tonic-gate break;
17827c478bd9Sstevel@tonic-gate
17837c478bd9Sstevel@tonic-gate fip = stats_dbm_fetch_byfid(st, fidp);
17847c478bd9Sstevel@tonic-gate if (fip == NULL) {
17857c478bd9Sstevel@tonic-gate fip = &fi;
17867c478bd9Sstevel@tonic-gate memset(&fi, '\0', sizeof (fi));
17877c478bd9Sstevel@tonic-gate fi.fi_vfsp = vfsp;
17887c478bd9Sstevel@tonic-gate }
17897c478bd9Sstevel@tonic-gate
17907c478bd9Sstevel@tonic-gate /* account for the creation of the fscache */
17917c478bd9Sstevel@tonic-gate if (! mip->mi_used) {
17927c478bd9Sstevel@tonic-gate mip->mi_used = 1;
17937c478bd9Sstevel@tonic-gate
17947c478bd9Sstevel@tonic-gate /* account for the .cfs_option file */
17957c478bd9Sstevel@tonic-gate mip->mi_current += (u_offset_t)lh->lh_maxbsize;
17967c478bd9Sstevel@tonic-gate st->st_ws_current +=
17977c478bd9Sstevel@tonic-gate (u_offset_t)lh->lh_maxbsize;
17987c478bd9Sstevel@tonic-gate }
17997c478bd9Sstevel@tonic-gate
18007c478bd9Sstevel@tonic-gate /*
18017c478bd9Sstevel@tonic-gate * Add in the size-growth of the attrcache.
18027c478bd9Sstevel@tonic-gate * len will be non-zero only for the record type
18037c478bd9Sstevel@tonic-gate * CACHEFS_LOG_MDCREATE, and len can't be > 2GB because
18047c478bd9Sstevel@tonic-gate * it refers to the number of entries in
18057c478bd9Sstevel@tonic-gate * the attribute cache file.
18067c478bd9Sstevel@tonic-gate */
18077c478bd9Sstevel@tonic-gate assert(len <= UINT_MAX);
18087c478bd9Sstevel@tonic-gate delta = stats_dbm_attrcache_addsize(st, mip, fileno,
18097c478bd9Sstevel@tonic-gate (type == CACHEFS_LOG_MDCREATE) ? (uint_t)len : 0);
18107c478bd9Sstevel@tonic-gate st->st_ws_current += (u_offset_t)delta;
18117c478bd9Sstevel@tonic-gate mip->mi_current += (u_offset_t)delta;
18127c478bd9Sstevel@tonic-gate
18137c478bd9Sstevel@tonic-gate /* see if this is an `expensive' logfile */
18147c478bd9Sstevel@tonic-gate if ((! st->st_ws_expensive) && (rflags & GRI_EXPENSIVE))
18157c478bd9Sstevel@tonic-gate st->st_ws_expensive = 1;
18167c478bd9Sstevel@tonic-gate
18177c478bd9Sstevel@tonic-gate /* subtract current frontfile size ... */
18187c478bd9Sstevel@tonic-gate st->st_ws_current -= fip->fi_total;
18197c478bd9Sstevel@tonic-gate mip->mi_current -= fip->fi_total;
18207c478bd9Sstevel@tonic-gate
18217c478bd9Sstevel@tonic-gate /* compute new frontfile size */
18227c478bd9Sstevel@tonic-gate if ((mip->mi_flags & CFS_WRITE_AROUND) &&
18237c478bd9Sstevel@tonic-gate (rflags & GRI_MODIFY)) {
18247c478bd9Sstevel@tonic-gate fip->fi_total = 0LL;
18257c478bd9Sstevel@tonic-gate fip->fi_ent_n = 0;
18267c478bd9Sstevel@tonic-gate } else if (rflags & GRI_ADD) {
18277c478bd9Sstevel@tonic-gate stats_log_fi_add(st, fip, off, len);
18287c478bd9Sstevel@tonic-gate } else if (rflags & GRI_TRUNC) {
18297c478bd9Sstevel@tonic-gate stats_log_fi_trunc(st, fip, off, len);
18307c478bd9Sstevel@tonic-gate }
18317c478bd9Sstevel@tonic-gate if (rflags & GRI_METADATA)
18327c478bd9Sstevel@tonic-gate fip->fi_flags |= FI_METADATA;
18337c478bd9Sstevel@tonic-gate
18347c478bd9Sstevel@tonic-gate /* add back in new frontfile size */
18357c478bd9Sstevel@tonic-gate mip->mi_current += fip->fi_total;
18367c478bd9Sstevel@tonic-gate if (mip->mi_current > mip->mi_high)
18377c478bd9Sstevel@tonic-gate mip->mi_high = mip->mi_current;
18387c478bd9Sstevel@tonic-gate stats_dbm_store_byvfsp(st, vfsp, mip);
18397c478bd9Sstevel@tonic-gate free(mip);
18407c478bd9Sstevel@tonic-gate st->st_ws_current += fip->fi_total;
18417c478bd9Sstevel@tonic-gate if (st->st_ws_current > st->st_ws_high)
18427c478bd9Sstevel@tonic-gate st->st_ws_high = st->st_ws_current;
18437c478bd9Sstevel@tonic-gate
18447c478bd9Sstevel@tonic-gate stats_dbm_store_byfid(st, fidp, fip);
18457c478bd9Sstevel@tonic-gate if (fip != &fi)
18467c478bd9Sstevel@tonic-gate free(fip);
18477c478bd9Sstevel@tonic-gate break;
18487c478bd9Sstevel@tonic-gate }
18497c478bd9Sstevel@tonic-gate
18507c478bd9Sstevel@tonic-gate free(record);
18517c478bd9Sstevel@tonic-gate
18527c478bd9Sstevel@tonic-gate if (stats_inerror(st))
18537c478bd9Sstevel@tonic-gate break;
18547c478bd9Sstevel@tonic-gate }
18557c478bd9Sstevel@tonic-gate
18567c478bd9Sstevel@tonic-gate out:
18577c478bd9Sstevel@tonic-gate if (mi != NULL)
18587c478bd9Sstevel@tonic-gate free(mi);
18597c478bd9Sstevel@tonic-gate if (! stats_inerror(st))
18607c478bd9Sstevel@tonic-gate st->st_flags |= ST_WSCOMP;
18617c478bd9Sstevel@tonic-gate }
18627c478bd9Sstevel@tonic-gate
18637c478bd9Sstevel@tonic-gate int
stats_log_wssize_init(stats_cookie_t * st)18647c478bd9Sstevel@tonic-gate stats_log_wssize_init(stats_cookie_t *st)
18657c478bd9Sstevel@tonic-gate {
18667c478bd9Sstevel@tonic-gate assert(stats_good(st));
18677c478bd9Sstevel@tonic-gate assert(st->st_flags & ST_WSCOMP);
18687c478bd9Sstevel@tonic-gate
18697c478bd9Sstevel@tonic-gate return (st->st_ws_init);
18707c478bd9Sstevel@tonic-gate }
18717c478bd9Sstevel@tonic-gate
18727c478bd9Sstevel@tonic-gate u_offset_t
stats_log_wssize_current(stats_cookie_t * st)18737c478bd9Sstevel@tonic-gate stats_log_wssize_current(stats_cookie_t *st)
18747c478bd9Sstevel@tonic-gate {
18757c478bd9Sstevel@tonic-gate assert(stats_good(st));
18767c478bd9Sstevel@tonic-gate assert(st->st_flags & ST_WSCOMP);
18777c478bd9Sstevel@tonic-gate
18787c478bd9Sstevel@tonic-gate return (st->st_ws_current);
18797c478bd9Sstevel@tonic-gate }
18807c478bd9Sstevel@tonic-gate
18817c478bd9Sstevel@tonic-gate u_offset_t
stats_log_wssize_high(stats_cookie_t * st)18827c478bd9Sstevel@tonic-gate stats_log_wssize_high(stats_cookie_t *st)
18837c478bd9Sstevel@tonic-gate {
18847c478bd9Sstevel@tonic-gate assert(stats_good(st));
18857c478bd9Sstevel@tonic-gate assert(st->st_flags & ST_WSCOMP);
18867c478bd9Sstevel@tonic-gate
18877c478bd9Sstevel@tonic-gate return (st->st_ws_high);
18887c478bd9Sstevel@tonic-gate }
18897c478bd9Sstevel@tonic-gate
18907c478bd9Sstevel@tonic-gate
18917c478bd9Sstevel@tonic-gate int
stats_log_wssize_expensive(stats_cookie_t * st)18927c478bd9Sstevel@tonic-gate stats_log_wssize_expensive(stats_cookie_t *st)
18937c478bd9Sstevel@tonic-gate {
18947c478bd9Sstevel@tonic-gate assert(stats_good(st));
18957c478bd9Sstevel@tonic-gate assert(st->st_flags & ST_WSCOMP);
18967c478bd9Sstevel@tonic-gate
18977c478bd9Sstevel@tonic-gate return (st->st_ws_expensive);
18987c478bd9Sstevel@tonic-gate }
1899