1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 1996-2003 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate /* 30*0Sstevel@tonic-gate * Routines for cachefs logging. 31*0Sstevel@tonic-gate */ 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate #include <stdio.h> 34*0Sstevel@tonic-gate #include <stdlib.h> 35*0Sstevel@tonic-gate #include <stddef.h> 36*0Sstevel@tonic-gate #include <sys/types.h> 37*0Sstevel@tonic-gate #include <sys/param.h> 38*0Sstevel@tonic-gate #include <errno.h> 39*0Sstevel@tonic-gate #include <sys/stat.h> 40*0Sstevel@tonic-gate #include <fcntl.h> 41*0Sstevel@tonic-gate #include <unistd.h> 42*0Sstevel@tonic-gate #include <libintl.h> 43*0Sstevel@tonic-gate #include <time.h> 44*0Sstevel@tonic-gate #include <string.h> 45*0Sstevel@tonic-gate #include <sys/fs/cachefs_fs.h> 46*0Sstevel@tonic-gate #include <sys/fs/cachefs_log.h> 47*0Sstevel@tonic-gate #include <malloc.h> 48*0Sstevel@tonic-gate #include <limits.h> 49*0Sstevel@tonic-gate #include "stats.h" 50*0Sstevel@tonic-gate #include <assert.h> 51*0Sstevel@tonic-gate 52*0Sstevel@tonic-gate /* forward declarations of statics */ 53*0Sstevel@tonic-gate static kstat_t *stats_log_kstat_read(stats_cookie_t *); 54*0Sstevel@tonic-gate static char *stats_log_fmtfid(cfs_fid_t *); 55*0Sstevel@tonic-gate static bool_t stats_xdr_loghead(XDR *, struct cachefs_log_logfile_header *); 56*0Sstevel@tonic-gate static int stats_log_fi_comp(const void *a, const void *b); 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gate int 59*0Sstevel@tonic-gate stats_log_kernel_setname(stats_cookie_t *st, char *path) 60*0Sstevel@tonic-gate { 61*0Sstevel@tonic-gate int error = 0; 62*0Sstevel@tonic-gate kstat_t *log; 63*0Sstevel@tonic-gate cachefs_log_control_t *lc; 64*0Sstevel@tonic-gate int exists = 0; 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate assert(stats_good(st)); 67*0Sstevel@tonic-gate 68*0Sstevel@tonic-gate if ((log = stats_log_kstat_read(st)) == NULL) { 69*0Sstevel@tonic-gate error = stats_errno(st); 70*0Sstevel@tonic-gate goto out; 71*0Sstevel@tonic-gate } 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate lc = (cachefs_log_control_t *)log->ks_data; 74*0Sstevel@tonic-gate 75*0Sstevel@tonic-gate /* 76*0Sstevel@tonic-gate * the stats_ API allows a NULL or an empty path to turn off 77*0Sstevel@tonic-gate * logging, but the kstat interface has the string buffered, 78*0Sstevel@tonic-gate * so we need to make an empty string. 79*0Sstevel@tonic-gate */ 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gate if (path == NULL) 82*0Sstevel@tonic-gate path = ""; 83*0Sstevel@tonic-gate if ((lc->lc_path[0] == 0) && (path[0] == 0)) 84*0Sstevel@tonic-gate goto out; 85*0Sstevel@tonic-gate 86*0Sstevel@tonic-gate (void) strlcpy(lc->lc_path, path, sizeof (lc->lc_path)); 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gate if (path[0] != '\0') { 89*0Sstevel@tonic-gate struct stat64 s; 90*0Sstevel@tonic-gate int f; 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate exists = access(path, F_OK); 93*0Sstevel@tonic-gate /* logfile will be <2GB */ 94*0Sstevel@tonic-gate f = open(path, O_WRONLY | O_CREAT, 0666); 95*0Sstevel@tonic-gate if (f < 0) { 96*0Sstevel@tonic-gate stats_perror(st, error = SE_FILE, 97*0Sstevel@tonic-gate gettext("Cannot open/create logfile: %s"), 98*0Sstevel@tonic-gate strerror(errno)); 99*0Sstevel@tonic-gate goto out; 100*0Sstevel@tonic-gate } 101*0Sstevel@tonic-gate 102*0Sstevel@tonic-gate if (fstat64(f, &s) < 0) { 103*0Sstevel@tonic-gate stats_perror(st, error = SE_FILE, 104*0Sstevel@tonic-gate gettext("Cannot stat logfile: %s"), 105*0Sstevel@tonic-gate strerror(errno)); 106*0Sstevel@tonic-gate (void) close(f); 107*0Sstevel@tonic-gate goto out; 108*0Sstevel@tonic-gate } 109*0Sstevel@tonic-gate 110*0Sstevel@tonic-gate /* 111*0Sstevel@tonic-gate * the kernel will accept an empty file as a logfile. we must 112*0Sstevel@tonic-gate * make sure that we created this empty file, i.e. that it's 113*0Sstevel@tonic-gate * not an already existing file that happened to be empty. 114*0Sstevel@tonic-gate * 115*0Sstevel@tonic-gate * if we hand the kernel a nonempty file, it will check the 116*0Sstevel@tonic-gate * magic number. thus, if they hand it something like 117*0Sstevel@tonic-gate * /etc/passwd, the kernel should reject it. we just have to 118*0Sstevel@tonic-gate * catch the cases of empty files we don't want to be 119*0Sstevel@tonic-gate * logfiles. 120*0Sstevel@tonic-gate */ 121*0Sstevel@tonic-gate 122*0Sstevel@tonic-gate if ((exists == 0) && (s.st_size == 0LL)) { 123*0Sstevel@tonic-gate stats_perror(st, error = SE_INVAL, 124*0Sstevel@tonic-gate gettext( 125*0Sstevel@tonic-gate "Cannot use existing empty file as a logfile")); 126*0Sstevel@tonic-gate (void) close(f); 127*0Sstevel@tonic-gate goto out; 128*0Sstevel@tonic-gate } 129*0Sstevel@tonic-gate 130*0Sstevel@tonic-gate (void) close(f); 131*0Sstevel@tonic-gate } 132*0Sstevel@tonic-gate 133*0Sstevel@tonic-gate if (kstat_write(st->st_kstat_cookie, log, NULL) < 0) { 134*0Sstevel@tonic-gate stats_perror(st, error = SE_KERNEL, 135*0Sstevel@tonic-gate gettext("Cannot set logfile path for this filesystem")); 136*0Sstevel@tonic-gate goto out; 137*0Sstevel@tonic-gate } 138*0Sstevel@tonic-gate 139*0Sstevel@tonic-gate out: 140*0Sstevel@tonic-gate if ((error != 0) && (path[0] != '\0') && (exists != 0)) 141*0Sstevel@tonic-gate (void) unlink(path); 142*0Sstevel@tonic-gate 143*0Sstevel@tonic-gate return (error); 144*0Sstevel@tonic-gate } 145*0Sstevel@tonic-gate 146*0Sstevel@tonic-gate int 147*0Sstevel@tonic-gate stats_log_which(stats_cookie_t *st, int which, int onoff) 148*0Sstevel@tonic-gate { 149*0Sstevel@tonic-gate int error = 0; 150*0Sstevel@tonic-gate kstat_t *log; 151*0Sstevel@tonic-gate cachefs_log_control_t *lc; 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate assert(stats_good(st)); 154*0Sstevel@tonic-gate 155*0Sstevel@tonic-gate if ((log = stats_log_kstat_read(st)) == NULL) { 156*0Sstevel@tonic-gate error = stats_errno(st); 157*0Sstevel@tonic-gate goto out; 158*0Sstevel@tonic-gate } 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gate lc = (cachefs_log_control_t *)log->ks_data; 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gate if (onoff) 163*0Sstevel@tonic-gate CACHEFS_LOG_SET(lc, which); 164*0Sstevel@tonic-gate else 165*0Sstevel@tonic-gate CACHEFS_LOG_CLEAR(lc, which); 166*0Sstevel@tonic-gate 167*0Sstevel@tonic-gate if (kstat_write(st->st_kstat_cookie, log, NULL) < 0) { 168*0Sstevel@tonic-gate stats_perror(st, error = SE_KERNEL, 169*0Sstevel@tonic-gate gettext("Cannot set log bitmap for this filesystem")); 170*0Sstevel@tonic-gate goto out; 171*0Sstevel@tonic-gate } 172*0Sstevel@tonic-gate 173*0Sstevel@tonic-gate out: 174*0Sstevel@tonic-gate return (error); 175*0Sstevel@tonic-gate } 176*0Sstevel@tonic-gate 177*0Sstevel@tonic-gate char * 178*0Sstevel@tonic-gate stats_log_kernel_getname(stats_cookie_t *st) 179*0Sstevel@tonic-gate { 180*0Sstevel@tonic-gate char *rc = NULL; 181*0Sstevel@tonic-gate kstat_t *log; 182*0Sstevel@tonic-gate cachefs_log_control_t *lc; 183*0Sstevel@tonic-gate 184*0Sstevel@tonic-gate assert(stats_good(st)); 185*0Sstevel@tonic-gate 186*0Sstevel@tonic-gate if ((log = stats_log_kstat_read(st)) == NULL) 187*0Sstevel@tonic-gate goto out; 188*0Sstevel@tonic-gate 189*0Sstevel@tonic-gate lc = (cachefs_log_control_t *)log->ks_data; 190*0Sstevel@tonic-gate 191*0Sstevel@tonic-gate rc = lc->lc_path; /* rc[0] will be '\0' if we're not logging */ 192*0Sstevel@tonic-gate 193*0Sstevel@tonic-gate out: 194*0Sstevel@tonic-gate return (rc); 195*0Sstevel@tonic-gate } 196*0Sstevel@tonic-gate 197*0Sstevel@tonic-gate static kstat_t * 198*0Sstevel@tonic-gate stats_log_kstat_read(stats_cookie_t *st) 199*0Sstevel@tonic-gate { 200*0Sstevel@tonic-gate kstat_t *rc; 201*0Sstevel@tonic-gate 202*0Sstevel@tonic-gate assert(stats_good(st)); 203*0Sstevel@tonic-gate assert(st->st_flags & ST_BOUND); 204*0Sstevel@tonic-gate 205*0Sstevel@tonic-gate if ((rc = kstat_lookup(st->st_kstat_cookie, 206*0Sstevel@tonic-gate "cachefs", st->st_fsid, "log")) == NULL) { 207*0Sstevel@tonic-gate /* 208*0Sstevel@tonic-gate * XXX if st was created for a particular cachedir, we 209*0Sstevel@tonic-gate * should scan for another st->st_fsid that'll get us 210*0Sstevel@tonic-gate * the same cache. 211*0Sstevel@tonic-gate */ 212*0Sstevel@tonic-gate stats_perror(st, SE_KERNEL, 213*0Sstevel@tonic-gate gettext("Cannot lookup kstats for this filesystem")); 214*0Sstevel@tonic-gate goto out; 215*0Sstevel@tonic-gate } 216*0Sstevel@tonic-gate if (kstat_read(st->st_kstat_cookie, rc, NULL) < 0) { 217*0Sstevel@tonic-gate stats_perror(st, SE_KERNEL, 218*0Sstevel@tonic-gate gettext("Cannot read kstats for this filesystem")); 219*0Sstevel@tonic-gate rc = NULL; 220*0Sstevel@tonic-gate goto out; 221*0Sstevel@tonic-gate } 222*0Sstevel@tonic-gate 223*0Sstevel@tonic-gate out: 224*0Sstevel@tonic-gate return (rc); 225*0Sstevel@tonic-gate } 226*0Sstevel@tonic-gate 227*0Sstevel@tonic-gate int 228*0Sstevel@tonic-gate stats_log_logfile_open(stats_cookie_t *st, char *fname) 229*0Sstevel@tonic-gate { 230*0Sstevel@tonic-gate int rc = 0; 231*0Sstevel@tonic-gate 232*0Sstevel@tonic-gate assert(stats_good(st)); 233*0Sstevel@tonic-gate 234*0Sstevel@tonic-gate if ((fname == NULL) || (fname[0] == '\0')) { 235*0Sstevel@tonic-gate kstat_t *log; 236*0Sstevel@tonic-gate cachefs_log_control_t *lc; 237*0Sstevel@tonic-gate 238*0Sstevel@tonic-gate if ((log = stats_log_kstat_read(st)) == NULL) { 239*0Sstevel@tonic-gate rc = -1; 240*0Sstevel@tonic-gate goto out; 241*0Sstevel@tonic-gate } 242*0Sstevel@tonic-gate lc = (cachefs_log_control_t *)log->ks_data; 243*0Sstevel@tonic-gate fname = lc->lc_path; 244*0Sstevel@tonic-gate } 245*0Sstevel@tonic-gate 246*0Sstevel@tonic-gate /* logfile will be <2GB */ 247*0Sstevel@tonic-gate if ((st->st_logstream = fopen(fname, "r")) == NULL) { 248*0Sstevel@tonic-gate stats_perror(st, SE_FILE, 249*0Sstevel@tonic-gate gettext("Cannot open logfile %s"), fname); 250*0Sstevel@tonic-gate rc = -1; 251*0Sstevel@tonic-gate goto out; 252*0Sstevel@tonic-gate } 253*0Sstevel@tonic-gate xdrstdio_create(&st->st_logxdr, st->st_logstream, XDR_DECODE); 254*0Sstevel@tonic-gate 255*0Sstevel@tonic-gate if (! stats_xdr_loghead(&st->st_logxdr, &st->st_loghead)) { 256*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 257*0Sstevel@tonic-gate gettext("Cannot read header from logfile %s"), fname); 258*0Sstevel@tonic-gate rc = -1; 259*0Sstevel@tonic-gate goto out; 260*0Sstevel@tonic-gate } 261*0Sstevel@tonic-gate if (st->st_loghead.lh_magic != CACHEFS_LOG_MAGIC) { 262*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 263*0Sstevel@tonic-gate gettext("%s: Invalid log file header"), fname); 264*0Sstevel@tonic-gate rc = -1; 265*0Sstevel@tonic-gate goto out; 266*0Sstevel@tonic-gate } 267*0Sstevel@tonic-gate if (st->st_loghead.lh_revision > CACHEFS_LOG_FILE_REV) { 268*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 269*0Sstevel@tonic-gate gettext("%s: Revision too high"), fname); 270*0Sstevel@tonic-gate rc = -1; 271*0Sstevel@tonic-gate goto out; 272*0Sstevel@tonic-gate } 273*0Sstevel@tonic-gate 274*0Sstevel@tonic-gate st->st_flags |= ST_LFOPEN; 275*0Sstevel@tonic-gate 276*0Sstevel@tonic-gate out: 277*0Sstevel@tonic-gate if (rc != 0) { 278*0Sstevel@tonic-gate if (st->st_logstream != NULL) { 279*0Sstevel@tonic-gate (void) fclose(st->st_logstream); 280*0Sstevel@tonic-gate st->st_logstream = NULL; 281*0Sstevel@tonic-gate } 282*0Sstevel@tonic-gate if (st->st_logxdr.x_ops != NULL) { 283*0Sstevel@tonic-gate xdr_destroy(&st->st_logxdr); 284*0Sstevel@tonic-gate st->st_logxdr.x_ops = NULL; 285*0Sstevel@tonic-gate } 286*0Sstevel@tonic-gate } 287*0Sstevel@tonic-gate return (rc); 288*0Sstevel@tonic-gate } 289*0Sstevel@tonic-gate 290*0Sstevel@tonic-gate static bool_t 291*0Sstevel@tonic-gate stats_xdr_loghead(XDR *xdrs, struct cachefs_log_logfile_header *lh) 292*0Sstevel@tonic-gate { 293*0Sstevel@tonic-gate if ((! xdr_u_int(xdrs, &lh->lh_magic)) || 294*0Sstevel@tonic-gate (! xdr_u_int(xdrs, &lh->lh_revision)) || 295*0Sstevel@tonic-gate (! xdr_int(xdrs, &lh->lh_errno)) || 296*0Sstevel@tonic-gate (! xdr_u_int(xdrs, &lh->lh_blocks)) || 297*0Sstevel@tonic-gate (! xdr_u_int(xdrs, &lh->lh_files)) || 298*0Sstevel@tonic-gate (! xdr_u_int(xdrs, &lh->lh_maxbsize)) || 299*0Sstevel@tonic-gate (! xdr_u_int(xdrs, &lh->lh_pagesize))) 300*0Sstevel@tonic-gate return (FALSE); 301*0Sstevel@tonic-gate 302*0Sstevel@tonic-gate return (TRUE); 303*0Sstevel@tonic-gate } 304*0Sstevel@tonic-gate 305*0Sstevel@tonic-gate void * 306*0Sstevel@tonic-gate stats_log_logfile_read(stats_cookie_t *st, int *type) 307*0Sstevel@tonic-gate { 308*0Sstevel@tonic-gate void *rc = NULL; 309*0Sstevel@tonic-gate size_t size; 310*0Sstevel@tonic-gate int ttype; 311*0Sstevel@tonic-gate XDR *xdrs; 312*0Sstevel@tonic-gate char *string1, *string2; 313*0Sstevel@tonic-gate 314*0Sstevel@tonic-gate assert(stats_good(st)); 315*0Sstevel@tonic-gate 316*0Sstevel@tonic-gate xdrs = &st->st_logxdr; 317*0Sstevel@tonic-gate 318*0Sstevel@tonic-gate if (! (st->st_flags & ST_LFOPEN)) { 319*0Sstevel@tonic-gate stats_perror(st, SE_INVAL, 320*0Sstevel@tonic-gate gettext("Logfile was not open")); 321*0Sstevel@tonic-gate goto out; 322*0Sstevel@tonic-gate } 323*0Sstevel@tonic-gate 324*0Sstevel@tonic-gate if (type == NULL) 325*0Sstevel@tonic-gate type = &ttype; 326*0Sstevel@tonic-gate 327*0Sstevel@tonic-gate if (! xdr_int(xdrs, type)) 328*0Sstevel@tonic-gate goto out; 329*0Sstevel@tonic-gate 330*0Sstevel@tonic-gate switch (*type) { 331*0Sstevel@tonic-gate struct cachefs_log_mount_record mount, *mountp; 332*0Sstevel@tonic-gate struct cachefs_log_umount_record umount; 333*0Sstevel@tonic-gate struct cachefs_log_getpage_record getpage; 334*0Sstevel@tonic-gate struct cachefs_log_readdir_record readdir; 335*0Sstevel@tonic-gate struct cachefs_log_readlink_record readlink; 336*0Sstevel@tonic-gate struct cachefs_log_remove_record remove; 337*0Sstevel@tonic-gate struct cachefs_log_rmdir_record rmdir; 338*0Sstevel@tonic-gate struct cachefs_log_truncate_record truncate; 339*0Sstevel@tonic-gate struct cachefs_log_putpage_record putpage; 340*0Sstevel@tonic-gate struct cachefs_log_create_record create; 341*0Sstevel@tonic-gate struct cachefs_log_mkdir_record mkdir; 342*0Sstevel@tonic-gate struct cachefs_log_rename_record rename; 343*0Sstevel@tonic-gate struct cachefs_log_symlink_record symlink; 344*0Sstevel@tonic-gate struct cachefs_log_populate_record populate; 345*0Sstevel@tonic-gate struct cachefs_log_csymlink_record csymlink; 346*0Sstevel@tonic-gate struct cachefs_log_filldir_record filldir; 347*0Sstevel@tonic-gate struct cachefs_log_mdcreate_record mdcreate; 348*0Sstevel@tonic-gate struct cachefs_log_gpfront_record gpfront; 349*0Sstevel@tonic-gate struct cachefs_log_rfdir_record rfdir; 350*0Sstevel@tonic-gate struct cachefs_log_ualloc_record ualloc; 351*0Sstevel@tonic-gate struct cachefs_log_calloc_record challoc; 352*0Sstevel@tonic-gate struct cachefs_log_nocache_record nocache; 353*0Sstevel@tonic-gate 354*0Sstevel@tonic-gate case CACHEFS_LOG_MOUNT: 355*0Sstevel@tonic-gate if ((! xdr_int(xdrs, &mount.error)) || 356*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&mount.time)) || 357*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&mount.vfsp, 358*0Sstevel@tonic-gate sizeof (mount.vfsp))) || 359*0Sstevel@tonic-gate (! xdr_u_int(xdrs, &mount.flags)) || 360*0Sstevel@tonic-gate (! xdr_u_int(xdrs, &mount.popsize)) || 361*0Sstevel@tonic-gate (! xdr_u_int(xdrs, &mount.fgsize)) || 362*0Sstevel@tonic-gate (! xdr_u_short(xdrs, &mount.pathlen)) || 363*0Sstevel@tonic-gate (! xdr_u_short(xdrs, &mount.cacheidlen))) { 364*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 365*0Sstevel@tonic-gate gettext("Truncated mount record")); 366*0Sstevel@tonic-gate goto out; 367*0Sstevel@tonic-gate } 368*0Sstevel@tonic-gate mount.type = *type; 369*0Sstevel@tonic-gate size = sizeof (mount) + mount.pathlen + mount.cacheidlen - 370*0Sstevel@tonic-gate CLPAD(cachefs_log_mount_record, path); 371*0Sstevel@tonic-gate if ((rc = mountp = 372*0Sstevel@tonic-gate (struct cachefs_log_mount_record *) 373*0Sstevel@tonic-gate calloc(1, size)) == NULL) { 374*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, 375*0Sstevel@tonic-gate gettext("Cannot malloc record")); 376*0Sstevel@tonic-gate goto out; 377*0Sstevel@tonic-gate } 378*0Sstevel@tonic-gate memcpy(rc, &mount, size); 379*0Sstevel@tonic-gate string1 = mountp->path; 380*0Sstevel@tonic-gate string2 = mountp->path + mount.pathlen + 1; 381*0Sstevel@tonic-gate (void) xdr_wrapstring(xdrs, &string1); 382*0Sstevel@tonic-gate (void) xdr_wrapstring(xdrs, &string2); 383*0Sstevel@tonic-gate break; 384*0Sstevel@tonic-gate 385*0Sstevel@tonic-gate case CACHEFS_LOG_UMOUNT: 386*0Sstevel@tonic-gate if ((! xdr_int(xdrs, &umount.error)) || 387*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&umount.time)) || 388*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&umount.vfsp, 389*0Sstevel@tonic-gate sizeof (umount.vfsp)))) { 390*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 391*0Sstevel@tonic-gate gettext("Truncated umount record")); 392*0Sstevel@tonic-gate goto out; 393*0Sstevel@tonic-gate } 394*0Sstevel@tonic-gate umount.type = *type; 395*0Sstevel@tonic-gate size = sizeof (umount); 396*0Sstevel@tonic-gate if ((rc = (caddr_t)calloc(1, size)) == NULL) { 397*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, 398*0Sstevel@tonic-gate gettext("Cannot malloc record")); 399*0Sstevel@tonic-gate goto out; 400*0Sstevel@tonic-gate } 401*0Sstevel@tonic-gate memcpy(rc, &umount, size); 402*0Sstevel@tonic-gate break; 403*0Sstevel@tonic-gate 404*0Sstevel@tonic-gate case CACHEFS_LOG_GETPAGE: 405*0Sstevel@tonic-gate if ((! xdr_int(xdrs, &getpage.error)) || 406*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&getpage.time)) || 407*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&getpage.vfsp, 408*0Sstevel@tonic-gate sizeof (getpage.vfsp))) || 409*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&getpage.fid, 410*0Sstevel@tonic-gate sizeof (getpage.fid))) || 411*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, 412*0Sstevel@tonic-gate (u_longlong_t *)&getpage.fileno)) || 413*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&getpage.uid)) || 414*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, 415*0Sstevel@tonic-gate (u_longlong_t *)&getpage.offset)) || 416*0Sstevel@tonic-gate (! xdr_u_int(xdrs, &getpage.len))) { 417*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 418*0Sstevel@tonic-gate gettext("Truncated getpage record")); 419*0Sstevel@tonic-gate goto out; 420*0Sstevel@tonic-gate } 421*0Sstevel@tonic-gate getpage.type = *type; 422*0Sstevel@tonic-gate size = sizeof (getpage); 423*0Sstevel@tonic-gate if ((rc = (caddr_t)calloc(1, size)) == NULL) { 424*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, 425*0Sstevel@tonic-gate gettext("Cannot malloc record")); 426*0Sstevel@tonic-gate goto out; 427*0Sstevel@tonic-gate } 428*0Sstevel@tonic-gate memcpy(rc, &getpage, size); 429*0Sstevel@tonic-gate break; 430*0Sstevel@tonic-gate 431*0Sstevel@tonic-gate case CACHEFS_LOG_READDIR: 432*0Sstevel@tonic-gate if ((! xdr_int(xdrs, &readdir.error)) || 433*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&readdir.time)) || 434*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&readdir.vfsp, 435*0Sstevel@tonic-gate sizeof (readdir.vfsp))) || 436*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&readdir.fid, 437*0Sstevel@tonic-gate sizeof (readdir.fid))) || 438*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, 439*0Sstevel@tonic-gate (u_longlong_t *)&readdir.fileno)) || 440*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&readdir.uid)) || 441*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, 442*0Sstevel@tonic-gate (u_longlong_t *)&readdir.offset)) || 443*0Sstevel@tonic-gate (! xdr_int(xdrs, &readdir.eof))) { 444*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 445*0Sstevel@tonic-gate gettext("Truncated readdir record")); 446*0Sstevel@tonic-gate goto out; 447*0Sstevel@tonic-gate } 448*0Sstevel@tonic-gate readdir.type = *type; 449*0Sstevel@tonic-gate size = sizeof (readdir); 450*0Sstevel@tonic-gate if ((rc = (caddr_t)calloc(1, size)) == NULL) { 451*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, 452*0Sstevel@tonic-gate gettext("Cannot malloc record")); 453*0Sstevel@tonic-gate goto out; 454*0Sstevel@tonic-gate } 455*0Sstevel@tonic-gate memcpy(rc, &readdir, size); 456*0Sstevel@tonic-gate break; 457*0Sstevel@tonic-gate 458*0Sstevel@tonic-gate case CACHEFS_LOG_READLINK: 459*0Sstevel@tonic-gate if ((! xdr_int(xdrs, &readlink.error)) || 460*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&readlink.time)) || 461*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&readlink.vfsp, 462*0Sstevel@tonic-gate sizeof (readlink.vfsp))) || 463*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&readlink.fid, 464*0Sstevel@tonic-gate sizeof (readlink.fid))) || 465*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, 466*0Sstevel@tonic-gate (u_longlong_t *)&readlink.fileno)) || 467*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&readlink.uid)) || 468*0Sstevel@tonic-gate (! xdr_u_int(xdrs, 469*0Sstevel@tonic-gate &readlink.length))) { 470*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 471*0Sstevel@tonic-gate gettext("Truncated readlink record")); 472*0Sstevel@tonic-gate goto out; 473*0Sstevel@tonic-gate } 474*0Sstevel@tonic-gate readlink.type = *type; 475*0Sstevel@tonic-gate size = sizeof (readlink); 476*0Sstevel@tonic-gate if ((rc = (caddr_t)calloc(1, size)) == NULL) { 477*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, 478*0Sstevel@tonic-gate gettext("Cannot malloc record")); 479*0Sstevel@tonic-gate goto out; 480*0Sstevel@tonic-gate } 481*0Sstevel@tonic-gate memcpy(rc, &readlink, size); 482*0Sstevel@tonic-gate break; 483*0Sstevel@tonic-gate 484*0Sstevel@tonic-gate case CACHEFS_LOG_REMOVE: 485*0Sstevel@tonic-gate if ((! xdr_int(xdrs, &remove.error)) || 486*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&remove.time)) || 487*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&remove.vfsp, 488*0Sstevel@tonic-gate sizeof (remove.vfsp))) || 489*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&remove.fid, 490*0Sstevel@tonic-gate sizeof (remove.fid))) || 491*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, 492*0Sstevel@tonic-gate (u_longlong_t *)&remove.fileno)) || 493*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&remove.uid))) { 494*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 495*0Sstevel@tonic-gate gettext("Truncated remove record")); 496*0Sstevel@tonic-gate goto out; 497*0Sstevel@tonic-gate } 498*0Sstevel@tonic-gate remove.type = *type; 499*0Sstevel@tonic-gate size = sizeof (remove); 500*0Sstevel@tonic-gate if ((rc = (caddr_t)calloc(1, size)) == NULL) { 501*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, 502*0Sstevel@tonic-gate gettext("Cannot malloc record")); 503*0Sstevel@tonic-gate goto out; 504*0Sstevel@tonic-gate } 505*0Sstevel@tonic-gate memcpy(rc, &remove, size); 506*0Sstevel@tonic-gate break; 507*0Sstevel@tonic-gate 508*0Sstevel@tonic-gate case CACHEFS_LOG_RMDIR: 509*0Sstevel@tonic-gate if ((! xdr_int(xdrs, &rmdir.error)) || 510*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&rmdir.time)) || 511*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&rmdir.vfsp, 512*0Sstevel@tonic-gate sizeof (rmdir.vfsp))) || 513*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&rmdir.fid, 514*0Sstevel@tonic-gate sizeof (rmdir.fid))) || 515*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, (u_longlong_t *)&rmdir.fileno)) || 516*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&rmdir.uid))) { 517*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 518*0Sstevel@tonic-gate gettext("Truncated rmdir record")); 519*0Sstevel@tonic-gate goto out; 520*0Sstevel@tonic-gate } 521*0Sstevel@tonic-gate rmdir.type = *type; 522*0Sstevel@tonic-gate size = sizeof (rmdir); 523*0Sstevel@tonic-gate if ((rc = (caddr_t)calloc(1, size)) == NULL) { 524*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, 525*0Sstevel@tonic-gate gettext("Cannot malloc record")); 526*0Sstevel@tonic-gate goto out; 527*0Sstevel@tonic-gate } 528*0Sstevel@tonic-gate memcpy(rc, &rmdir, size); 529*0Sstevel@tonic-gate break; 530*0Sstevel@tonic-gate 531*0Sstevel@tonic-gate case CACHEFS_LOG_TRUNCATE: 532*0Sstevel@tonic-gate if ((! xdr_int(xdrs, &truncate.error)) || 533*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&truncate.time)) || 534*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&truncate.vfsp, 535*0Sstevel@tonic-gate sizeof (truncate.vfsp))) || 536*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&truncate.fid, 537*0Sstevel@tonic-gate sizeof (truncate.fid))) || 538*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, 539*0Sstevel@tonic-gate (u_longlong_t *)&truncate.fileno)) || 540*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&truncate.uid)) || 541*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, 542*0Sstevel@tonic-gate (u_longlong_t *)&truncate.size))) { 543*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 544*0Sstevel@tonic-gate gettext("Truncated truncate record")); 545*0Sstevel@tonic-gate goto out; 546*0Sstevel@tonic-gate } 547*0Sstevel@tonic-gate truncate.type = *type; 548*0Sstevel@tonic-gate size = sizeof (truncate); 549*0Sstevel@tonic-gate if ((rc = (caddr_t)calloc(1, size)) == NULL) { 550*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, 551*0Sstevel@tonic-gate gettext("Cannot malloc record")); 552*0Sstevel@tonic-gate goto out; 553*0Sstevel@tonic-gate } 554*0Sstevel@tonic-gate memcpy(rc, &truncate, size); 555*0Sstevel@tonic-gate break; 556*0Sstevel@tonic-gate 557*0Sstevel@tonic-gate case CACHEFS_LOG_PUTPAGE: 558*0Sstevel@tonic-gate if ((! xdr_int(xdrs, &putpage.error)) || 559*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&putpage.time)) || 560*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&putpage.vfsp, 561*0Sstevel@tonic-gate sizeof (putpage.vfsp))) || 562*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&putpage.fid, 563*0Sstevel@tonic-gate sizeof (putpage.fid))) || 564*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, 565*0Sstevel@tonic-gate (u_longlong_t *)&putpage.fileno)) || 566*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&putpage.uid)) || 567*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, 568*0Sstevel@tonic-gate (u_longlong_t *)&putpage.offset)) || 569*0Sstevel@tonic-gate (! xdr_u_int(xdrs, &putpage.len))) { 570*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 571*0Sstevel@tonic-gate gettext("Truncated putpage record")); 572*0Sstevel@tonic-gate goto out; 573*0Sstevel@tonic-gate } 574*0Sstevel@tonic-gate putpage.type = *type; 575*0Sstevel@tonic-gate size = sizeof (putpage); 576*0Sstevel@tonic-gate if ((rc = (caddr_t)calloc(1, size)) == NULL) { 577*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, 578*0Sstevel@tonic-gate gettext("Cannot malloc record")); 579*0Sstevel@tonic-gate goto out; 580*0Sstevel@tonic-gate } 581*0Sstevel@tonic-gate memcpy(rc, &putpage, size); 582*0Sstevel@tonic-gate break; 583*0Sstevel@tonic-gate 584*0Sstevel@tonic-gate case CACHEFS_LOG_CREATE: 585*0Sstevel@tonic-gate if ((! xdr_int(xdrs, &create.error)) || 586*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&create.time)) || 587*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&create.vfsp, 588*0Sstevel@tonic-gate sizeof (create.vfsp))) || 589*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&create.fid, 590*0Sstevel@tonic-gate sizeof (create.fid))) || 591*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, 592*0Sstevel@tonic-gate (u_longlong_t *)&create.fileno)) || 593*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&create.uid))) { 594*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 595*0Sstevel@tonic-gate gettext("Truncated create record")); 596*0Sstevel@tonic-gate goto out; 597*0Sstevel@tonic-gate } 598*0Sstevel@tonic-gate create.type = *type; 599*0Sstevel@tonic-gate size = sizeof (create); 600*0Sstevel@tonic-gate if ((rc = (struct cachefs_log_create_record *) 601*0Sstevel@tonic-gate calloc(1, size)) == NULL) { 602*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, 603*0Sstevel@tonic-gate gettext("Cannot malloc record")); 604*0Sstevel@tonic-gate goto out; 605*0Sstevel@tonic-gate } 606*0Sstevel@tonic-gate memcpy(rc, &create, size); 607*0Sstevel@tonic-gate break; 608*0Sstevel@tonic-gate 609*0Sstevel@tonic-gate case CACHEFS_LOG_MKDIR: 610*0Sstevel@tonic-gate if ((! xdr_int(xdrs, &mkdir.error)) || 611*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&mkdir.time)) || 612*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&mkdir.vfsp, 613*0Sstevel@tonic-gate sizeof (mkdir.vfsp))) || 614*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&mkdir.fid, 615*0Sstevel@tonic-gate sizeof (mkdir.fid))) || 616*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, (u_longlong_t *)&mkdir.fileno)) || 617*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&mkdir.uid))) { 618*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 619*0Sstevel@tonic-gate gettext("Truncated mkdir record")); 620*0Sstevel@tonic-gate goto out; 621*0Sstevel@tonic-gate } 622*0Sstevel@tonic-gate mkdir.type = *type; 623*0Sstevel@tonic-gate size = sizeof (mkdir); 624*0Sstevel@tonic-gate if ((rc = (struct cachefs_log_mkdir_record *) 625*0Sstevel@tonic-gate calloc(1, size)) == NULL) { 626*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, 627*0Sstevel@tonic-gate gettext("Cannot malloc record")); 628*0Sstevel@tonic-gate goto out; 629*0Sstevel@tonic-gate } 630*0Sstevel@tonic-gate memcpy(rc, &mkdir, size); 631*0Sstevel@tonic-gate break; 632*0Sstevel@tonic-gate 633*0Sstevel@tonic-gate case CACHEFS_LOG_RENAME: 634*0Sstevel@tonic-gate if ((! xdr_int(xdrs, &rename.error)) || 635*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&rename.time)) || 636*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&rename.vfsp, 637*0Sstevel@tonic-gate sizeof (rename.vfsp))) || 638*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&rename.gone, 639*0Sstevel@tonic-gate sizeof (rename.gone))) || 640*0Sstevel@tonic-gate (! xdr_int(xdrs, &rename.removed)) || 641*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&rename.uid))) { 642*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 643*0Sstevel@tonic-gate gettext("Truncated rename record")); 644*0Sstevel@tonic-gate goto out; 645*0Sstevel@tonic-gate } 646*0Sstevel@tonic-gate rename.type = *type; 647*0Sstevel@tonic-gate size = sizeof (rename); 648*0Sstevel@tonic-gate if ((rc = (struct cachefs_log_rename_record *) 649*0Sstevel@tonic-gate calloc(1, size)) == NULL) { 650*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, 651*0Sstevel@tonic-gate gettext("Cannot malloc record")); 652*0Sstevel@tonic-gate goto out; 653*0Sstevel@tonic-gate } 654*0Sstevel@tonic-gate memcpy(rc, &rename, size); 655*0Sstevel@tonic-gate break; 656*0Sstevel@tonic-gate 657*0Sstevel@tonic-gate case CACHEFS_LOG_SYMLINK: 658*0Sstevel@tonic-gate if ((! xdr_int(xdrs, &symlink.error)) || 659*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&symlink.time)) || 660*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&symlink.vfsp, 661*0Sstevel@tonic-gate sizeof (symlink.vfsp))) || 662*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&symlink.fid, 663*0Sstevel@tonic-gate sizeof (symlink.fid))) || 664*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, 665*0Sstevel@tonic-gate (u_longlong_t *)&symlink.fileno)) || 666*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&symlink.uid)) || 667*0Sstevel@tonic-gate (! xdr_u_int(xdrs, &symlink.size))) { 668*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 669*0Sstevel@tonic-gate gettext("Truncated symlink record")); 670*0Sstevel@tonic-gate goto out; 671*0Sstevel@tonic-gate } 672*0Sstevel@tonic-gate symlink.type = *type; 673*0Sstevel@tonic-gate size = sizeof (symlink); 674*0Sstevel@tonic-gate if ((rc = (struct cachefs_log_symlink_record *) 675*0Sstevel@tonic-gate calloc(1, size)) == NULL) { 676*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, 677*0Sstevel@tonic-gate gettext("Cannot malloc record")); 678*0Sstevel@tonic-gate goto out; 679*0Sstevel@tonic-gate } 680*0Sstevel@tonic-gate memcpy(rc, &symlink, size); 681*0Sstevel@tonic-gate break; 682*0Sstevel@tonic-gate 683*0Sstevel@tonic-gate case CACHEFS_LOG_POPULATE: 684*0Sstevel@tonic-gate if ((! xdr_int(xdrs, &populate.error)) || 685*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&populate.time)) || 686*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&populate.vfsp, 687*0Sstevel@tonic-gate sizeof (populate.vfsp))) || 688*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&populate.fid, 689*0Sstevel@tonic-gate sizeof (populate.fid))) || 690*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, 691*0Sstevel@tonic-gate (u_longlong_t *)&populate.fileno)) || 692*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, (u_longlong_t *)&populate.off)) || 693*0Sstevel@tonic-gate (! xdr_u_int(xdrs, &populate.size))) { 694*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 695*0Sstevel@tonic-gate gettext("Truncated populate record")); 696*0Sstevel@tonic-gate goto out; 697*0Sstevel@tonic-gate } 698*0Sstevel@tonic-gate populate.type = *type; 699*0Sstevel@tonic-gate if ((rc = (struct cachefs_log_populate_record *) 700*0Sstevel@tonic-gate calloc(1, sizeof (populate))) == NULL) { 701*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, 702*0Sstevel@tonic-gate gettext("Cannot malloc record")); 703*0Sstevel@tonic-gate goto out; 704*0Sstevel@tonic-gate } 705*0Sstevel@tonic-gate memcpy(rc, &populate, sizeof (populate)); 706*0Sstevel@tonic-gate break; 707*0Sstevel@tonic-gate 708*0Sstevel@tonic-gate case CACHEFS_LOG_CSYMLINK: 709*0Sstevel@tonic-gate if ((! xdr_int(xdrs, &csymlink.error)) || 710*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&csymlink.time)) || 711*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&csymlink.vfsp, 712*0Sstevel@tonic-gate sizeof (csymlink.vfsp))) || 713*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&csymlink.fid, 714*0Sstevel@tonic-gate sizeof (csymlink.fid))) || 715*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, 716*0Sstevel@tonic-gate (u_longlong_t *)&csymlink.fileno)) || 717*0Sstevel@tonic-gate (! xdr_int(xdrs, &csymlink.size))) { 718*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 719*0Sstevel@tonic-gate gettext("Truncated csymlink record")); 720*0Sstevel@tonic-gate goto out; 721*0Sstevel@tonic-gate } 722*0Sstevel@tonic-gate csymlink.type = *type; 723*0Sstevel@tonic-gate if ((rc = (struct cachefs_log_csymlink_record *) 724*0Sstevel@tonic-gate calloc(1, sizeof (csymlink))) == NULL) { 725*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, 726*0Sstevel@tonic-gate gettext("Cannot malloc record")); 727*0Sstevel@tonic-gate goto out; 728*0Sstevel@tonic-gate } 729*0Sstevel@tonic-gate memcpy(rc, &csymlink, sizeof (csymlink)); 730*0Sstevel@tonic-gate break; 731*0Sstevel@tonic-gate 732*0Sstevel@tonic-gate case CACHEFS_LOG_FILLDIR: 733*0Sstevel@tonic-gate if ((! xdr_int(xdrs, &filldir.error)) || 734*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&filldir.time)) || 735*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&filldir.vfsp, 736*0Sstevel@tonic-gate sizeof (filldir.vfsp))) || 737*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&filldir.fid, 738*0Sstevel@tonic-gate sizeof (filldir.fid))) || 739*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, 740*0Sstevel@tonic-gate (u_longlong_t *)&filldir.fileno)) || 741*0Sstevel@tonic-gate (! xdr_int(xdrs, &filldir.size))) { 742*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 743*0Sstevel@tonic-gate gettext("Truncated filldir record")); 744*0Sstevel@tonic-gate goto out; 745*0Sstevel@tonic-gate } 746*0Sstevel@tonic-gate filldir.type = *type; 747*0Sstevel@tonic-gate if ((rc = (struct cachefs_log_filldir_record *) 748*0Sstevel@tonic-gate calloc(1, sizeof (filldir))) == NULL) { 749*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, 750*0Sstevel@tonic-gate gettext("Cannot malloc record")); 751*0Sstevel@tonic-gate goto out; 752*0Sstevel@tonic-gate } 753*0Sstevel@tonic-gate memcpy(rc, &filldir, sizeof (filldir)); 754*0Sstevel@tonic-gate break; 755*0Sstevel@tonic-gate 756*0Sstevel@tonic-gate case CACHEFS_LOG_MDCREATE: 757*0Sstevel@tonic-gate if ((! xdr_int(xdrs, &mdcreate.error)) || 758*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&mdcreate.time)) || 759*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&mdcreate.vfsp, 760*0Sstevel@tonic-gate sizeof (mdcreate.vfsp))) || 761*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&mdcreate.fid, 762*0Sstevel@tonic-gate sizeof (mdcreate.fid))) || 763*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, 764*0Sstevel@tonic-gate (u_longlong_t *)&mdcreate.fileno)) || 765*0Sstevel@tonic-gate (! xdr_u_int(xdrs, &mdcreate.count))) { 766*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 767*0Sstevel@tonic-gate gettext("Truncated mdcreate record")); 768*0Sstevel@tonic-gate goto out; 769*0Sstevel@tonic-gate } 770*0Sstevel@tonic-gate mdcreate.type = *type; 771*0Sstevel@tonic-gate if ((rc = (struct cachefs_log_mdcreate_record *) 772*0Sstevel@tonic-gate calloc(1, sizeof (mdcreate))) == NULL) { 773*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, 774*0Sstevel@tonic-gate gettext("Cannot malloc record")); 775*0Sstevel@tonic-gate goto out; 776*0Sstevel@tonic-gate } 777*0Sstevel@tonic-gate memcpy(rc, &mdcreate, sizeof (mdcreate)); 778*0Sstevel@tonic-gate break; 779*0Sstevel@tonic-gate 780*0Sstevel@tonic-gate case CACHEFS_LOG_GPFRONT: 781*0Sstevel@tonic-gate if ((! xdr_int(xdrs, &gpfront.error)) || 782*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&gpfront.time)) || 783*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&gpfront.vfsp, 784*0Sstevel@tonic-gate sizeof (gpfront.vfsp))) || 785*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&gpfront.fid, 786*0Sstevel@tonic-gate sizeof (gpfront.fid))) || 787*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, 788*0Sstevel@tonic-gate (u_longlong_t *)&gpfront.fileno)) || 789*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&gpfront.uid)) || 790*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, (u_longlong_t *)&gpfront.off)) || 791*0Sstevel@tonic-gate (! xdr_u_int(xdrs, &gpfront.len))) { 792*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 793*0Sstevel@tonic-gate gettext("Truncated gpfront record")); 794*0Sstevel@tonic-gate goto out; 795*0Sstevel@tonic-gate } 796*0Sstevel@tonic-gate gpfront.type = *type; 797*0Sstevel@tonic-gate if ((rc = (struct cachefs_log_gpfront_record *) 798*0Sstevel@tonic-gate calloc(1, sizeof (gpfront))) == NULL) { 799*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, 800*0Sstevel@tonic-gate gettext("Cannot malloc record")); 801*0Sstevel@tonic-gate goto out; 802*0Sstevel@tonic-gate } 803*0Sstevel@tonic-gate memcpy(rc, &gpfront, sizeof (gpfront)); 804*0Sstevel@tonic-gate break; 805*0Sstevel@tonic-gate 806*0Sstevel@tonic-gate case CACHEFS_LOG_RFDIR: 807*0Sstevel@tonic-gate if ((! xdr_int(xdrs, &rfdir.error)) || 808*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&rfdir.time)) || 809*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&rfdir.vfsp, 810*0Sstevel@tonic-gate sizeof (rfdir.vfsp))) || 811*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&rfdir.fid, 812*0Sstevel@tonic-gate sizeof (rfdir.fid))) || 813*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, (u_longlong_t *)&rfdir.fileno)) || 814*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&rfdir.uid))) { 815*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 816*0Sstevel@tonic-gate gettext("Truncated rfdir record")); 817*0Sstevel@tonic-gate goto out; 818*0Sstevel@tonic-gate } 819*0Sstevel@tonic-gate rfdir.type = *type; 820*0Sstevel@tonic-gate if ((rc = (struct cachefs_log_rfdir_record *) 821*0Sstevel@tonic-gate calloc(1, sizeof (rfdir))) == NULL) { 822*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, 823*0Sstevel@tonic-gate gettext("Cannot malloc record")); 824*0Sstevel@tonic-gate goto out; 825*0Sstevel@tonic-gate } 826*0Sstevel@tonic-gate memcpy(rc, &rfdir, sizeof (rfdir)); 827*0Sstevel@tonic-gate break; 828*0Sstevel@tonic-gate 829*0Sstevel@tonic-gate case CACHEFS_LOG_UALLOC: 830*0Sstevel@tonic-gate if ((! xdr_int(xdrs, &ualloc.error)) || 831*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&ualloc.time)) || 832*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&ualloc.vfsp, 833*0Sstevel@tonic-gate sizeof (ualloc.vfsp))) || 834*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&ualloc.fid, 835*0Sstevel@tonic-gate sizeof (ualloc.fid))) || 836*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, 837*0Sstevel@tonic-gate (u_longlong_t *)&ualloc.fileno)) || 838*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, (u_longlong_t *)&ualloc.off)) || 839*0Sstevel@tonic-gate (! xdr_u_int(xdrs, &ualloc.len))) { 840*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 841*0Sstevel@tonic-gate gettext("Truncated ualloc record")); 842*0Sstevel@tonic-gate goto out; 843*0Sstevel@tonic-gate } 844*0Sstevel@tonic-gate ualloc.type = *type; 845*0Sstevel@tonic-gate if ((rc = (struct cachefs_log_ualloc_record *) 846*0Sstevel@tonic-gate calloc(1, sizeof (ualloc))) == NULL) { 847*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, 848*0Sstevel@tonic-gate gettext("Cannot malloc record")); 849*0Sstevel@tonic-gate goto out; 850*0Sstevel@tonic-gate } 851*0Sstevel@tonic-gate memcpy(rc, &ualloc, sizeof (ualloc)); 852*0Sstevel@tonic-gate break; 853*0Sstevel@tonic-gate 854*0Sstevel@tonic-gate case CACHEFS_LOG_CALLOC: 855*0Sstevel@tonic-gate if ((! xdr_int(xdrs, &challoc.error)) || 856*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&challoc.time)) || 857*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&challoc.vfsp, 858*0Sstevel@tonic-gate sizeof (challoc.vfsp))) || 859*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&challoc.fid, 860*0Sstevel@tonic-gate sizeof (challoc.fid))) || 861*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, 862*0Sstevel@tonic-gate (u_longlong_t *)&challoc.fileno)) || 863*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, (u_longlong_t *)&challoc.off)) || 864*0Sstevel@tonic-gate (! xdr_u_int(xdrs, &challoc.len))) { 865*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 866*0Sstevel@tonic-gate gettext("Truncated calloc record")); 867*0Sstevel@tonic-gate goto out; 868*0Sstevel@tonic-gate } 869*0Sstevel@tonic-gate challoc.type = *type; 870*0Sstevel@tonic-gate if ((rc = (struct cachefs_log_calloc_record *) 871*0Sstevel@tonic-gate calloc(1, sizeof (challoc))) == NULL) { 872*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, 873*0Sstevel@tonic-gate gettext("Cannot malloc record")); 874*0Sstevel@tonic-gate goto out; 875*0Sstevel@tonic-gate } 876*0Sstevel@tonic-gate memcpy(rc, &challoc, sizeof (challoc)); 877*0Sstevel@tonic-gate break; 878*0Sstevel@tonic-gate 879*0Sstevel@tonic-gate case CACHEFS_LOG_NOCACHE: 880*0Sstevel@tonic-gate if ((! xdr_int(xdrs, &nocache.error)) || 881*0Sstevel@tonic-gate (! xdr_int(xdrs, (int *)&nocache.time)) || 882*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&nocache.vfsp, 883*0Sstevel@tonic-gate sizeof (nocache.vfsp))) || 884*0Sstevel@tonic-gate (! xdr_opaque(xdrs, (caddr_t)&nocache.fid, 885*0Sstevel@tonic-gate sizeof (nocache.fid))) || 886*0Sstevel@tonic-gate (! xdr_u_longlong_t(xdrs, 887*0Sstevel@tonic-gate (u_longlong_t *)&nocache.fileno))) { 888*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 889*0Sstevel@tonic-gate gettext("Truncated nocache record")); 890*0Sstevel@tonic-gate goto out; 891*0Sstevel@tonic-gate } 892*0Sstevel@tonic-gate nocache.type = *type; 893*0Sstevel@tonic-gate if ((rc = (struct cachefs_log_nocache_record *) 894*0Sstevel@tonic-gate calloc(1, sizeof (nocache))) == NULL) { 895*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, 896*0Sstevel@tonic-gate gettext("Cannot malloc record")); 897*0Sstevel@tonic-gate goto out; 898*0Sstevel@tonic-gate } 899*0Sstevel@tonic-gate memcpy(rc, &nocache, sizeof (nocache)); 900*0Sstevel@tonic-gate break; 901*0Sstevel@tonic-gate 902*0Sstevel@tonic-gate default: 903*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 904*0Sstevel@tonic-gate gettext("Corrupt logfile (position %x)"), 905*0Sstevel@tonic-gate ftell(st->st_logstream)); 906*0Sstevel@tonic-gate break; 907*0Sstevel@tonic-gate } 908*0Sstevel@tonic-gate 909*0Sstevel@tonic-gate out: 910*0Sstevel@tonic-gate return (rc); 911*0Sstevel@tonic-gate } 912*0Sstevel@tonic-gate 913*0Sstevel@tonic-gate /* 914*0Sstevel@tonic-gate * convert a logfile record (read by stats_log_logfile_read()) to 915*0Sstevel@tonic-gate * ascii. probably not for end-user consumption, but this should be 916*0Sstevel@tonic-gate * the official way to do it. 917*0Sstevel@tonic-gate */ 918*0Sstevel@tonic-gate 919*0Sstevel@tonic-gate char * 920*0Sstevel@tonic-gate stats_log_record_toascii(stats_cookie_t *st, void *recp) 921*0Sstevel@tonic-gate { 922*0Sstevel@tonic-gate int rectype = *((int *)recp); 923*0Sstevel@tonic-gate int recerror = *((int *)recp + 1); 924*0Sstevel@tonic-gate time_t tt = *((time_t *)((int *)recp + 2)); 925*0Sstevel@tonic-gate struct tm *tm = localtime(&tt); 926*0Sstevel@tonic-gate char buffy[BUFSIZ], *fidstr, *fidstr2, *fidstr3; 927*0Sstevel@tonic-gate 928*0Sstevel@tonic-gate struct cachefs_log_mount_record *mountp; 929*0Sstevel@tonic-gate struct cachefs_log_umount_record *umountp; 930*0Sstevel@tonic-gate struct cachefs_log_getpage_record *getpagep; 931*0Sstevel@tonic-gate struct cachefs_log_readdir_record *readdirp; 932*0Sstevel@tonic-gate struct cachefs_log_readlink_record *readlinkp; 933*0Sstevel@tonic-gate struct cachefs_log_remove_record *removep; 934*0Sstevel@tonic-gate struct cachefs_log_rmdir_record *rmdirp; 935*0Sstevel@tonic-gate struct cachefs_log_truncate_record *truncatep; 936*0Sstevel@tonic-gate struct cachefs_log_putpage_record *putpagep; 937*0Sstevel@tonic-gate struct cachefs_log_create_record *createp; 938*0Sstevel@tonic-gate struct cachefs_log_mkdir_record *mkdirp; 939*0Sstevel@tonic-gate struct cachefs_log_rename_record *renamep; 940*0Sstevel@tonic-gate struct cachefs_log_symlink_record *symlinkp; 941*0Sstevel@tonic-gate struct cachefs_log_populate_record *populatep; 942*0Sstevel@tonic-gate struct cachefs_log_csymlink_record *csymlinkp; 943*0Sstevel@tonic-gate struct cachefs_log_filldir_record *filldirp; 944*0Sstevel@tonic-gate struct cachefs_log_mdcreate_record *mdcreatep; 945*0Sstevel@tonic-gate struct cachefs_log_gpfront_record *gpfrontp; 946*0Sstevel@tonic-gate struct cachefs_log_rfdir_record *rfdirp; 947*0Sstevel@tonic-gate struct cachefs_log_ualloc_record *uallocp; 948*0Sstevel@tonic-gate struct cachefs_log_calloc_record *callocp; 949*0Sstevel@tonic-gate struct cachefs_log_nocache_record *nocachep; 950*0Sstevel@tonic-gate 951*0Sstevel@tonic-gate assert(stats_good(st)); 952*0Sstevel@tonic-gate 953*0Sstevel@tonic-gate (void) sprintf(st->st_asciirec, "%2d/%-2d %2d:%.2d %2d", 954*0Sstevel@tonic-gate tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, 955*0Sstevel@tonic-gate recerror); 956*0Sstevel@tonic-gate 957*0Sstevel@tonic-gate switch (rectype) { 958*0Sstevel@tonic-gate case CACHEFS_LOG_MOUNT: 959*0Sstevel@tonic-gate mountp = (struct cachefs_log_mount_record *)recp; 960*0Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), 961*0Sstevel@tonic-gate " %-8s %llx %8x %d %d %s (%s)", "Mount", mountp->vfsp, 962*0Sstevel@tonic-gate mountp->flags, mountp->popsize, 963*0Sstevel@tonic-gate mountp->fgsize, mountp->path, 964*0Sstevel@tonic-gate mountp->path + mountp->pathlen + 1); 965*0Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy, 966*0Sstevel@tonic-gate sizeof (st->st_asciirec)); 967*0Sstevel@tonic-gate break; 968*0Sstevel@tonic-gate 969*0Sstevel@tonic-gate case CACHEFS_LOG_UMOUNT: 970*0Sstevel@tonic-gate umountp = (struct cachefs_log_umount_record *)recp; 971*0Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), " %-8s %llx", 972*0Sstevel@tonic-gate "Umount", umountp->vfsp); 973*0Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy, 974*0Sstevel@tonic-gate sizeof (st->st_asciirec)); 975*0Sstevel@tonic-gate break; 976*0Sstevel@tonic-gate 977*0Sstevel@tonic-gate case CACHEFS_LOG_GETPAGE: 978*0Sstevel@tonic-gate getpagep = (struct cachefs_log_getpage_record *)recp; 979*0Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), 980*0Sstevel@tonic-gate " %-8s %llx %s %llu %ld %llu %u", 981*0Sstevel@tonic-gate "Getpage", 982*0Sstevel@tonic-gate getpagep->vfsp, fidstr = stats_log_fmtfid(&getpagep->fid), 983*0Sstevel@tonic-gate getpagep->fileno, 984*0Sstevel@tonic-gate getpagep->uid, getpagep->offset, getpagep->len); 985*0Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy, 986*0Sstevel@tonic-gate sizeof (st->st_asciirec)); 987*0Sstevel@tonic-gate free(fidstr); 988*0Sstevel@tonic-gate break; 989*0Sstevel@tonic-gate 990*0Sstevel@tonic-gate case CACHEFS_LOG_READDIR: 991*0Sstevel@tonic-gate readdirp = (struct cachefs_log_readdir_record *)recp; 992*0Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), 993*0Sstevel@tonic-gate " %-8s %llx %s %llu %d %llx %d", "Readdir", 994*0Sstevel@tonic-gate readdirp->vfsp, fidstr = stats_log_fmtfid(&readdirp->fid), 995*0Sstevel@tonic-gate readdirp->fileno, 996*0Sstevel@tonic-gate readdirp->uid, readdirp->offset, readdirp->eof); 997*0Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy, 998*0Sstevel@tonic-gate sizeof (st->st_asciirec)); 999*0Sstevel@tonic-gate free(fidstr); 1000*0Sstevel@tonic-gate break; 1001*0Sstevel@tonic-gate 1002*0Sstevel@tonic-gate case CACHEFS_LOG_READLINK: 1003*0Sstevel@tonic-gate readlinkp = (struct cachefs_log_readlink_record *)recp; 1004*0Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), 1005*0Sstevel@tonic-gate " %-8s %llx %s %llu %d %u", "Readlink", 1006*0Sstevel@tonic-gate readlinkp->vfsp, 1007*0Sstevel@tonic-gate fidstr = stats_log_fmtfid(&readlinkp->fid), 1008*0Sstevel@tonic-gate readlinkp->fileno, 1009*0Sstevel@tonic-gate readlinkp->uid, readlinkp->length); 1010*0Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy, 1011*0Sstevel@tonic-gate sizeof (st->st_asciirec)); 1012*0Sstevel@tonic-gate free(fidstr); 1013*0Sstevel@tonic-gate break; 1014*0Sstevel@tonic-gate 1015*0Sstevel@tonic-gate case CACHEFS_LOG_REMOVE: 1016*0Sstevel@tonic-gate removep = (struct cachefs_log_remove_record *)recp; 1017*0Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), 1018*0Sstevel@tonic-gate " %-8s %llx %s %llu %d", "Remove", 1019*0Sstevel@tonic-gate removep->vfsp, fidstr = stats_log_fmtfid(&removep->fid), 1020*0Sstevel@tonic-gate removep->fileno, 1021*0Sstevel@tonic-gate removep->uid); 1022*0Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy, 1023*0Sstevel@tonic-gate sizeof (st->st_asciirec)); 1024*0Sstevel@tonic-gate free(fidstr); 1025*0Sstevel@tonic-gate break; 1026*0Sstevel@tonic-gate 1027*0Sstevel@tonic-gate case CACHEFS_LOG_RMDIR: 1028*0Sstevel@tonic-gate rmdirp = (struct cachefs_log_rmdir_record *)recp; 1029*0Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), 1030*0Sstevel@tonic-gate " %-8s %llx %s %llu %d", "Rmdir", 1031*0Sstevel@tonic-gate rmdirp->vfsp, fidstr = stats_log_fmtfid(&rmdirp->fid), 1032*0Sstevel@tonic-gate rmdirp->fileno, 1033*0Sstevel@tonic-gate rmdirp->uid); 1034*0Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy, 1035*0Sstevel@tonic-gate sizeof (st->st_asciirec)); 1036*0Sstevel@tonic-gate free(fidstr); 1037*0Sstevel@tonic-gate break; 1038*0Sstevel@tonic-gate 1039*0Sstevel@tonic-gate case CACHEFS_LOG_TRUNCATE: 1040*0Sstevel@tonic-gate truncatep = (struct cachefs_log_truncate_record *)recp; 1041*0Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), 1042*0Sstevel@tonic-gate " %-8s %llx %s %llu %d %llu", "Truncate", 1043*0Sstevel@tonic-gate truncatep->vfsp, 1044*0Sstevel@tonic-gate fidstr = stats_log_fmtfid(&truncatep->fid), 1045*0Sstevel@tonic-gate truncatep->fileno, 1046*0Sstevel@tonic-gate truncatep->uid, truncatep->size); 1047*0Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy, 1048*0Sstevel@tonic-gate sizeof (st->st_asciirec)); 1049*0Sstevel@tonic-gate free(fidstr); 1050*0Sstevel@tonic-gate break; 1051*0Sstevel@tonic-gate 1052*0Sstevel@tonic-gate case CACHEFS_LOG_PUTPAGE: 1053*0Sstevel@tonic-gate putpagep = (struct cachefs_log_putpage_record *)recp; 1054*0Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), 1055*0Sstevel@tonic-gate " %-8s %llx %s %llu %d %llu %u", "Putpage", 1056*0Sstevel@tonic-gate putpagep->vfsp, fidstr = stats_log_fmtfid(&putpagep->fid), 1057*0Sstevel@tonic-gate putpagep->fileno, 1058*0Sstevel@tonic-gate putpagep->uid, putpagep->offset, putpagep->len); 1059*0Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy, 1060*0Sstevel@tonic-gate sizeof (st->st_asciirec)); 1061*0Sstevel@tonic-gate free(fidstr); 1062*0Sstevel@tonic-gate break; 1063*0Sstevel@tonic-gate 1064*0Sstevel@tonic-gate case CACHEFS_LOG_CREATE: 1065*0Sstevel@tonic-gate createp = (struct cachefs_log_create_record *)recp; 1066*0Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), 1067*0Sstevel@tonic-gate " %-8s %llx %s %llu %d", "Create", 1068*0Sstevel@tonic-gate createp->vfsp, 1069*0Sstevel@tonic-gate fidstr = stats_log_fmtfid(&createp->fid), 1070*0Sstevel@tonic-gate createp->fileno, 1071*0Sstevel@tonic-gate createp->uid); 1072*0Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy, 1073*0Sstevel@tonic-gate sizeof (st->st_asciirec)); 1074*0Sstevel@tonic-gate free(fidstr); 1075*0Sstevel@tonic-gate break; 1076*0Sstevel@tonic-gate 1077*0Sstevel@tonic-gate case CACHEFS_LOG_MKDIR: 1078*0Sstevel@tonic-gate mkdirp = (struct cachefs_log_mkdir_record *)recp; 1079*0Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), 1080*0Sstevel@tonic-gate " %-8s %llx %s %llu %d", "Mkdir", 1081*0Sstevel@tonic-gate mkdirp->vfsp, 1082*0Sstevel@tonic-gate fidstr = stats_log_fmtfid(&mkdirp->fid), 1083*0Sstevel@tonic-gate mkdirp->fileno, 1084*0Sstevel@tonic-gate mkdirp->uid); 1085*0Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy, 1086*0Sstevel@tonic-gate sizeof (st->st_asciirec)); 1087*0Sstevel@tonic-gate free(fidstr); 1088*0Sstevel@tonic-gate break; 1089*0Sstevel@tonic-gate 1090*0Sstevel@tonic-gate case CACHEFS_LOG_RENAME: 1091*0Sstevel@tonic-gate renamep = (struct cachefs_log_rename_record *)recp; 1092*0Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), 1093*0Sstevel@tonic-gate " %-8s %llx %s %llu %d %d", "Rename", 1094*0Sstevel@tonic-gate renamep->vfsp, 1095*0Sstevel@tonic-gate fidstr = stats_log_fmtfid(&renamep->gone), 1096*0Sstevel@tonic-gate renamep->fileno, 1097*0Sstevel@tonic-gate renamep->removed, renamep->uid); 1098*0Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy, 1099*0Sstevel@tonic-gate sizeof (st->st_asciirec)); 1100*0Sstevel@tonic-gate free(fidstr); 1101*0Sstevel@tonic-gate break; 1102*0Sstevel@tonic-gate 1103*0Sstevel@tonic-gate case CACHEFS_LOG_SYMLINK: 1104*0Sstevel@tonic-gate symlinkp = (struct cachefs_log_symlink_record *)recp; 1105*0Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), 1106*0Sstevel@tonic-gate " %-8s %llx %s %llu %d %u", "Symlink", 1107*0Sstevel@tonic-gate symlinkp->vfsp, 1108*0Sstevel@tonic-gate fidstr = stats_log_fmtfid(&symlinkp->fid), 1109*0Sstevel@tonic-gate symlinkp->fileno, 1110*0Sstevel@tonic-gate symlinkp->uid, symlinkp->size); 1111*0Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy, 1112*0Sstevel@tonic-gate sizeof (st->st_asciirec)); 1113*0Sstevel@tonic-gate free(fidstr); 1114*0Sstevel@tonic-gate break; 1115*0Sstevel@tonic-gate 1116*0Sstevel@tonic-gate case CACHEFS_LOG_POPULATE: 1117*0Sstevel@tonic-gate populatep = (struct cachefs_log_populate_record *)recp; 1118*0Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), 1119*0Sstevel@tonic-gate " %-8s %llx %s %llu %llu %d", "Populate", 1120*0Sstevel@tonic-gate populatep->vfsp, 1121*0Sstevel@tonic-gate fidstr = stats_log_fmtfid(&populatep->fid), 1122*0Sstevel@tonic-gate populatep->fileno, 1123*0Sstevel@tonic-gate populatep->off, populatep->size); 1124*0Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy, 1125*0Sstevel@tonic-gate sizeof (st->st_asciirec)); 1126*0Sstevel@tonic-gate free(fidstr); 1127*0Sstevel@tonic-gate break; 1128*0Sstevel@tonic-gate 1129*0Sstevel@tonic-gate case CACHEFS_LOG_CSYMLINK: 1130*0Sstevel@tonic-gate csymlinkp = (struct cachefs_log_csymlink_record *)recp; 1131*0Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), 1132*0Sstevel@tonic-gate " %-8s %llx %s %llu %d", "Csymlink", 1133*0Sstevel@tonic-gate csymlinkp->vfsp, 1134*0Sstevel@tonic-gate fidstr = stats_log_fmtfid(&csymlinkp->fid), 1135*0Sstevel@tonic-gate csymlinkp->fileno, 1136*0Sstevel@tonic-gate csymlinkp->size); 1137*0Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy, 1138*0Sstevel@tonic-gate sizeof (st->st_asciirec)); 1139*0Sstevel@tonic-gate free(fidstr); 1140*0Sstevel@tonic-gate break; 1141*0Sstevel@tonic-gate 1142*0Sstevel@tonic-gate case CACHEFS_LOG_FILLDIR: 1143*0Sstevel@tonic-gate filldirp = (struct cachefs_log_filldir_record *)recp; 1144*0Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), 1145*0Sstevel@tonic-gate " %-8s %llx %s %llu %d", "Filldir", 1146*0Sstevel@tonic-gate filldirp->vfsp, 1147*0Sstevel@tonic-gate fidstr = stats_log_fmtfid(&filldirp->fid), 1148*0Sstevel@tonic-gate filldirp->fileno, 1149*0Sstevel@tonic-gate filldirp->size); 1150*0Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy, 1151*0Sstevel@tonic-gate sizeof (st->st_asciirec)); 1152*0Sstevel@tonic-gate free(fidstr); 1153*0Sstevel@tonic-gate break; 1154*0Sstevel@tonic-gate 1155*0Sstevel@tonic-gate case CACHEFS_LOG_MDCREATE: 1156*0Sstevel@tonic-gate mdcreatep = (struct cachefs_log_mdcreate_record *)recp; 1157*0Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), 1158*0Sstevel@tonic-gate " %-8s %llx %s %llu %u", "Mdcreate", 1159*0Sstevel@tonic-gate mdcreatep->vfsp, 1160*0Sstevel@tonic-gate fidstr = stats_log_fmtfid(&mdcreatep->fid), 1161*0Sstevel@tonic-gate mdcreatep->fileno, mdcreatep->count); 1162*0Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy, 1163*0Sstevel@tonic-gate sizeof (st->st_asciirec)); 1164*0Sstevel@tonic-gate free(fidstr); 1165*0Sstevel@tonic-gate break; 1166*0Sstevel@tonic-gate 1167*0Sstevel@tonic-gate case CACHEFS_LOG_GPFRONT: 1168*0Sstevel@tonic-gate gpfrontp = (struct cachefs_log_gpfront_record *)recp; 1169*0Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), 1170*0Sstevel@tonic-gate " %-8s %llx %s %llu %d %llu %u", "Gpfront", 1171*0Sstevel@tonic-gate gpfrontp->vfsp, 1172*0Sstevel@tonic-gate fidstr = stats_log_fmtfid(&gpfrontp->fid), 1173*0Sstevel@tonic-gate gpfrontp->fileno, 1174*0Sstevel@tonic-gate gpfrontp->uid, gpfrontp->off, gpfrontp->len); 1175*0Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy, 1176*0Sstevel@tonic-gate sizeof (st->st_asciirec)); 1177*0Sstevel@tonic-gate free(fidstr); 1178*0Sstevel@tonic-gate break; 1179*0Sstevel@tonic-gate 1180*0Sstevel@tonic-gate case CACHEFS_LOG_RFDIR: 1181*0Sstevel@tonic-gate rfdirp = (struct cachefs_log_rfdir_record *)recp; 1182*0Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), 1183*0Sstevel@tonic-gate " %-8s %llx %s %llu %d", "Rfdir", 1184*0Sstevel@tonic-gate rfdirp->vfsp, 1185*0Sstevel@tonic-gate fidstr = stats_log_fmtfid(&rfdirp->fid), 1186*0Sstevel@tonic-gate rfdirp->fileno, 1187*0Sstevel@tonic-gate rfdirp->uid); 1188*0Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy, 1189*0Sstevel@tonic-gate sizeof (st->st_asciirec)); 1190*0Sstevel@tonic-gate free(fidstr); 1191*0Sstevel@tonic-gate break; 1192*0Sstevel@tonic-gate 1193*0Sstevel@tonic-gate case CACHEFS_LOG_UALLOC: 1194*0Sstevel@tonic-gate uallocp = (struct cachefs_log_ualloc_record *)recp; 1195*0Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), 1196*0Sstevel@tonic-gate " %-8s %llx %s %llu %llu %u", "Ualloc", 1197*0Sstevel@tonic-gate uallocp->vfsp, 1198*0Sstevel@tonic-gate fidstr = stats_log_fmtfid(&uallocp->fid), 1199*0Sstevel@tonic-gate uallocp->fileno, 1200*0Sstevel@tonic-gate uallocp->off, uallocp->len); 1201*0Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy, 1202*0Sstevel@tonic-gate sizeof (st->st_asciirec)); 1203*0Sstevel@tonic-gate free(fidstr); 1204*0Sstevel@tonic-gate break; 1205*0Sstevel@tonic-gate 1206*0Sstevel@tonic-gate case CACHEFS_LOG_CALLOC: 1207*0Sstevel@tonic-gate callocp = (struct cachefs_log_calloc_record *)recp; 1208*0Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), 1209*0Sstevel@tonic-gate " %-8s %llx %s %llu %llu %u", "Calloc", 1210*0Sstevel@tonic-gate callocp->vfsp, 1211*0Sstevel@tonic-gate fidstr = stats_log_fmtfid(&callocp->fid), 1212*0Sstevel@tonic-gate callocp->fileno, callocp->off, callocp->len); 1213*0Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy, 1214*0Sstevel@tonic-gate sizeof (st->st_asciirec)); 1215*0Sstevel@tonic-gate free(fidstr); 1216*0Sstevel@tonic-gate break; 1217*0Sstevel@tonic-gate 1218*0Sstevel@tonic-gate case CACHEFS_LOG_NOCACHE: 1219*0Sstevel@tonic-gate nocachep = (struct cachefs_log_nocache_record *)recp; 1220*0Sstevel@tonic-gate (void) snprintf(buffy, sizeof (buffy), 1221*0Sstevel@tonic-gate " %-8s %llx %s %llu", "Nocache", 1222*0Sstevel@tonic-gate nocachep->vfsp, 1223*0Sstevel@tonic-gate fidstr = stats_log_fmtfid(&nocachep->fid), 1224*0Sstevel@tonic-gate nocachep->fileno); 1225*0Sstevel@tonic-gate (void) strlcat(st->st_asciirec, buffy, 1226*0Sstevel@tonic-gate sizeof (st->st_asciirec)); 1227*0Sstevel@tonic-gate free(fidstr); 1228*0Sstevel@tonic-gate break; 1229*0Sstevel@tonic-gate 1230*0Sstevel@tonic-gate default: 1231*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 1232*0Sstevel@tonic-gate gettext( 1233*0Sstevel@tonic-gate "Attempt to format invalid log type=%d (position %x)"), 1234*0Sstevel@tonic-gate rectype, ftell(st->st_logstream)); 1235*0Sstevel@tonic-gate return (NULL); 1236*0Sstevel@tonic-gate } 1237*0Sstevel@tonic-gate 1238*0Sstevel@tonic-gate return (st->st_asciirec); 1239*0Sstevel@tonic-gate } 1240*0Sstevel@tonic-gate 1241*0Sstevel@tonic-gate uint_t 1242*0Sstevel@tonic-gate stats_log_get_record_info(stats_cookie_t *sc, 1243*0Sstevel@tonic-gate void *recp, caddr_t *vfsp, cfs_fid_t **fidp, ino64_t *filenop, 1244*0Sstevel@tonic-gate u_offset_t *offp, u_offset_t *lenp) 1245*0Sstevel@tonic-gate { 1246*0Sstevel@tonic-gate int type = ((int *)recp)[0]; 1247*0Sstevel@tonic-gate int error = ((int *)recp)[1]; 1248*0Sstevel@tonic-gate uint_t rc = 0; 1249*0Sstevel@tonic-gate 1250*0Sstevel@tonic-gate struct cachefs_log_getpage_record *getpagep; 1251*0Sstevel@tonic-gate struct cachefs_log_readdir_record *readdirp; 1252*0Sstevel@tonic-gate struct cachefs_log_readlink_record *readlinkp; 1253*0Sstevel@tonic-gate struct cachefs_log_remove_record *removep; 1254*0Sstevel@tonic-gate struct cachefs_log_rmdir_record *rmdirp; 1255*0Sstevel@tonic-gate struct cachefs_log_truncate_record *truncatep; 1256*0Sstevel@tonic-gate struct cachefs_log_putpage_record *putpagep; 1257*0Sstevel@tonic-gate struct cachefs_log_create_record *createp; 1258*0Sstevel@tonic-gate struct cachefs_log_mkdir_record *mkdirp; 1259*0Sstevel@tonic-gate struct cachefs_log_rename_record *renamep; 1260*0Sstevel@tonic-gate struct cachefs_log_symlink_record *symlinkp; 1261*0Sstevel@tonic-gate struct cachefs_log_populate_record *populatep; 1262*0Sstevel@tonic-gate struct cachefs_log_csymlink_record *csymlinkp; 1263*0Sstevel@tonic-gate struct cachefs_log_filldir_record *filldirp; 1264*0Sstevel@tonic-gate struct cachefs_log_mdcreate_record *mdcreatep; 1265*0Sstevel@tonic-gate struct cachefs_log_gpfront_record *gpfrontp; 1266*0Sstevel@tonic-gate struct cachefs_log_rfdir_record *rfdirp; 1267*0Sstevel@tonic-gate struct cachefs_log_ualloc_record *uallocp; 1268*0Sstevel@tonic-gate struct cachefs_log_calloc_record *callocp; 1269*0Sstevel@tonic-gate struct cachefs_log_nocache_record *nocachep; 1270*0Sstevel@tonic-gate 1271*0Sstevel@tonic-gate switch (type) { 1272*0Sstevel@tonic-gate case CACHEFS_LOG_RFDIR: 1273*0Sstevel@tonic-gate if ((error == EINVAL) || (error == ENOENT)) 1274*0Sstevel@tonic-gate error = 0; 1275*0Sstevel@tonic-gate break; 1276*0Sstevel@tonic-gate } 1277*0Sstevel@tonic-gate 1278*0Sstevel@tonic-gate if (error != 0) 1279*0Sstevel@tonic-gate return (0); 1280*0Sstevel@tonic-gate 1281*0Sstevel@tonic-gate switch (type) { 1282*0Sstevel@tonic-gate case CACHEFS_LOG_GETPAGE: 1283*0Sstevel@tonic-gate getpagep = (struct cachefs_log_getpage_record *)recp; 1284*0Sstevel@tonic-gate *fidp = &getpagep->fid; 1285*0Sstevel@tonic-gate *filenop = getpagep->fileno; 1286*0Sstevel@tonic-gate *vfsp = (caddr_t)getpagep->vfsp; 1287*0Sstevel@tonic-gate *offp = getpagep->offset; 1288*0Sstevel@tonic-gate *lenp = (u_offset_t)getpagep->len; 1289*0Sstevel@tonic-gate rc = (GRI_ADD | GRI_EXPENSIVE); 1290*0Sstevel@tonic-gate break; 1291*0Sstevel@tonic-gate 1292*0Sstevel@tonic-gate case CACHEFS_LOG_READDIR: 1293*0Sstevel@tonic-gate readdirp = (struct cachefs_log_readdir_record *)recp; 1294*0Sstevel@tonic-gate *fidp = &readdirp->fid; 1295*0Sstevel@tonic-gate *filenop = readdirp->fileno; 1296*0Sstevel@tonic-gate *vfsp = (caddr_t)readdirp->vfsp; 1297*0Sstevel@tonic-gate *offp = readdirp->offset; 1298*0Sstevel@tonic-gate *lenp = (u_offset_t)sc->st_loghead.lh_maxbsize; 1299*0Sstevel@tonic-gate rc = (GRI_ADD | GRI_EXPENSIVE); 1300*0Sstevel@tonic-gate break; 1301*0Sstevel@tonic-gate 1302*0Sstevel@tonic-gate case CACHEFS_LOG_READLINK: 1303*0Sstevel@tonic-gate readlinkp = (struct cachefs_log_readlink_record *)recp; 1304*0Sstevel@tonic-gate *fidp = &readlinkp->fid; 1305*0Sstevel@tonic-gate *filenop = readlinkp->fileno; 1306*0Sstevel@tonic-gate *vfsp = (caddr_t)readlinkp->vfsp; 1307*0Sstevel@tonic-gate *offp = 0LL; 1308*0Sstevel@tonic-gate *lenp = (u_offset_t)((readlinkp->length > C_FSL_SIZE) ? 1309*0Sstevel@tonic-gate readlinkp->length : 0); 1310*0Sstevel@tonic-gate rc = (GRI_ADD | GRI_EXPENSIVE); 1311*0Sstevel@tonic-gate break; 1312*0Sstevel@tonic-gate 1313*0Sstevel@tonic-gate case CACHEFS_LOG_REMOVE: 1314*0Sstevel@tonic-gate removep = (struct cachefs_log_remove_record *)recp; 1315*0Sstevel@tonic-gate *fidp = &removep->fid; 1316*0Sstevel@tonic-gate *filenop = removep->fileno; 1317*0Sstevel@tonic-gate *vfsp = (caddr_t)removep->vfsp; 1318*0Sstevel@tonic-gate *offp = *lenp = 0LL; 1319*0Sstevel@tonic-gate rc = (GRI_TRUNC | GRI_MODIFY); 1320*0Sstevel@tonic-gate break; 1321*0Sstevel@tonic-gate 1322*0Sstevel@tonic-gate case CACHEFS_LOG_RMDIR: 1323*0Sstevel@tonic-gate rmdirp = (struct cachefs_log_rmdir_record *)recp; 1324*0Sstevel@tonic-gate *fidp = &rmdirp->fid; 1325*0Sstevel@tonic-gate *filenop = rmdirp->fileno; 1326*0Sstevel@tonic-gate *vfsp = (caddr_t)rmdirp->vfsp; 1327*0Sstevel@tonic-gate *offp = *lenp = 0LL; 1328*0Sstevel@tonic-gate rc = (GRI_TRUNC | GRI_MODIFY); 1329*0Sstevel@tonic-gate break; 1330*0Sstevel@tonic-gate 1331*0Sstevel@tonic-gate case CACHEFS_LOG_TRUNCATE: 1332*0Sstevel@tonic-gate truncatep = (struct cachefs_log_truncate_record *)recp; 1333*0Sstevel@tonic-gate *fidp = &truncatep->fid; 1334*0Sstevel@tonic-gate *filenop = truncatep->fileno; 1335*0Sstevel@tonic-gate *vfsp = (caddr_t)truncatep->vfsp; 1336*0Sstevel@tonic-gate *offp = 0LL; 1337*0Sstevel@tonic-gate *lenp = truncatep->size; 1338*0Sstevel@tonic-gate rc = (GRI_TRUNC | GRI_MODIFY); 1339*0Sstevel@tonic-gate break; 1340*0Sstevel@tonic-gate 1341*0Sstevel@tonic-gate case CACHEFS_LOG_PUTPAGE: 1342*0Sstevel@tonic-gate putpagep = (struct cachefs_log_putpage_record *)recp; 1343*0Sstevel@tonic-gate *fidp = &putpagep->fid; 1344*0Sstevel@tonic-gate *filenop = putpagep->fileno; 1345*0Sstevel@tonic-gate *vfsp = (caddr_t)putpagep->vfsp; 1346*0Sstevel@tonic-gate *offp = putpagep->offset; 1347*0Sstevel@tonic-gate *lenp = (u_offset_t)putpagep->len; 1348*0Sstevel@tonic-gate rc = (GRI_ADD | GRI_MODIFY); 1349*0Sstevel@tonic-gate break; 1350*0Sstevel@tonic-gate 1351*0Sstevel@tonic-gate case CACHEFS_LOG_CREATE: 1352*0Sstevel@tonic-gate createp = (struct cachefs_log_create_record *)recp; 1353*0Sstevel@tonic-gate *fidp = &createp->fid; 1354*0Sstevel@tonic-gate *filenop = createp->fileno; 1355*0Sstevel@tonic-gate *vfsp = (caddr_t)createp->vfsp; 1356*0Sstevel@tonic-gate *offp = *lenp = 0LL; 1357*0Sstevel@tonic-gate rc = (GRI_ADD | GRI_MODIFY); 1358*0Sstevel@tonic-gate break; 1359*0Sstevel@tonic-gate 1360*0Sstevel@tonic-gate case CACHEFS_LOG_MKDIR: 1361*0Sstevel@tonic-gate mkdirp = (struct cachefs_log_mkdir_record *)recp; 1362*0Sstevel@tonic-gate *fidp = &mkdirp->fid; 1363*0Sstevel@tonic-gate *filenop = mkdirp->fileno; 1364*0Sstevel@tonic-gate *vfsp = (caddr_t)mkdirp->vfsp; 1365*0Sstevel@tonic-gate *offp = *lenp = 0LL; 1366*0Sstevel@tonic-gate rc = (GRI_ADD | GRI_MODIFY); 1367*0Sstevel@tonic-gate break; 1368*0Sstevel@tonic-gate 1369*0Sstevel@tonic-gate case CACHEFS_LOG_RENAME: 1370*0Sstevel@tonic-gate renamep = (struct cachefs_log_rename_record *)recp; 1371*0Sstevel@tonic-gate *fidp = &renamep->gone; 1372*0Sstevel@tonic-gate *filenop = renamep->fileno; 1373*0Sstevel@tonic-gate *vfsp = (caddr_t)renamep->vfsp; 1374*0Sstevel@tonic-gate *offp = *lenp = 0LL; 1375*0Sstevel@tonic-gate rc = GRI_MODIFY; 1376*0Sstevel@tonic-gate if (renamep->removed) 1377*0Sstevel@tonic-gate rc |= GRI_TRUNC; 1378*0Sstevel@tonic-gate break; 1379*0Sstevel@tonic-gate 1380*0Sstevel@tonic-gate case CACHEFS_LOG_SYMLINK: 1381*0Sstevel@tonic-gate symlinkp = (struct cachefs_log_symlink_record *)recp; 1382*0Sstevel@tonic-gate *fidp = &symlinkp->fid; 1383*0Sstevel@tonic-gate *filenop = symlinkp->fileno; 1384*0Sstevel@tonic-gate *vfsp = (caddr_t)symlinkp->vfsp; 1385*0Sstevel@tonic-gate *offp = 0LL; 1386*0Sstevel@tonic-gate *lenp = (u_offset_t)((symlinkp->size > C_FSL_SIZE) ? 1387*0Sstevel@tonic-gate symlinkp->size : 0); 1388*0Sstevel@tonic-gate rc = (GRI_ADD | GRI_MODIFY); 1389*0Sstevel@tonic-gate break; 1390*0Sstevel@tonic-gate 1391*0Sstevel@tonic-gate case CACHEFS_LOG_POPULATE: 1392*0Sstevel@tonic-gate populatep = (struct cachefs_log_populate_record *)recp; 1393*0Sstevel@tonic-gate *fidp = &populatep->fid; 1394*0Sstevel@tonic-gate *filenop = populatep->fileno; 1395*0Sstevel@tonic-gate *vfsp = (caddr_t)populatep->vfsp; 1396*0Sstevel@tonic-gate *offp = populatep->off; 1397*0Sstevel@tonic-gate *lenp = (u_offset_t)populatep->size; 1398*0Sstevel@tonic-gate rc = GRI_ADD; 1399*0Sstevel@tonic-gate break; 1400*0Sstevel@tonic-gate 1401*0Sstevel@tonic-gate case CACHEFS_LOG_CSYMLINK: 1402*0Sstevel@tonic-gate csymlinkp = (struct cachefs_log_csymlink_record *)recp; 1403*0Sstevel@tonic-gate *fidp = &csymlinkp->fid; 1404*0Sstevel@tonic-gate *filenop = csymlinkp->fileno; 1405*0Sstevel@tonic-gate *vfsp = (caddr_t)csymlinkp->vfsp; 1406*0Sstevel@tonic-gate *offp = 0LL; 1407*0Sstevel@tonic-gate *lenp = (u_offset_t)((csymlinkp->size > C_FSL_SIZE) ? 1408*0Sstevel@tonic-gate csymlinkp->size : 0); 1409*0Sstevel@tonic-gate rc = GRI_ADD; 1410*0Sstevel@tonic-gate break; 1411*0Sstevel@tonic-gate 1412*0Sstevel@tonic-gate case CACHEFS_LOG_FILLDIR: 1413*0Sstevel@tonic-gate filldirp = (struct cachefs_log_filldir_record *)recp; 1414*0Sstevel@tonic-gate *fidp = &filldirp->fid; 1415*0Sstevel@tonic-gate *filenop = filldirp->fileno; 1416*0Sstevel@tonic-gate *vfsp = (caddr_t)filldirp->vfsp; 1417*0Sstevel@tonic-gate *offp = 0LL; 1418*0Sstevel@tonic-gate *lenp = (u_offset_t)(filldirp->size); 1419*0Sstevel@tonic-gate rc = GRI_ADD; 1420*0Sstevel@tonic-gate break; 1421*0Sstevel@tonic-gate 1422*0Sstevel@tonic-gate case CACHEFS_LOG_MDCREATE: 1423*0Sstevel@tonic-gate mdcreatep = (struct cachefs_log_mdcreate_record *)recp; 1424*0Sstevel@tonic-gate *fidp = &mdcreatep->fid; 1425*0Sstevel@tonic-gate *filenop = mdcreatep->fileno; 1426*0Sstevel@tonic-gate *vfsp = (caddr_t)mdcreatep->vfsp; 1427*0Sstevel@tonic-gate *lenp = (u_offset_t)mdcreatep->count; 1428*0Sstevel@tonic-gate rc = GRI_METADATA; 1429*0Sstevel@tonic-gate break; 1430*0Sstevel@tonic-gate 1431*0Sstevel@tonic-gate case CACHEFS_LOG_GPFRONT: 1432*0Sstevel@tonic-gate gpfrontp = (struct cachefs_log_gpfront_record *)recp; 1433*0Sstevel@tonic-gate *fidp = &gpfrontp->fid; 1434*0Sstevel@tonic-gate *filenop = gpfrontp->fileno; 1435*0Sstevel@tonic-gate *vfsp = (caddr_t)gpfrontp->vfsp; 1436*0Sstevel@tonic-gate *offp = gpfrontp->off; 1437*0Sstevel@tonic-gate *lenp = (u_offset_t)sc->st_loghead.lh_pagesize; 1438*0Sstevel@tonic-gate rc = (GRI_ADD | GRI_EXPENSIVE); 1439*0Sstevel@tonic-gate break; 1440*0Sstevel@tonic-gate 1441*0Sstevel@tonic-gate case CACHEFS_LOG_RFDIR: 1442*0Sstevel@tonic-gate rfdirp = (struct cachefs_log_rfdir_record *)recp; 1443*0Sstevel@tonic-gate rfdirp->error = 0; 1444*0Sstevel@tonic-gate *fidp = &rfdirp->fid; 1445*0Sstevel@tonic-gate *filenop = rfdirp->fileno; 1446*0Sstevel@tonic-gate *vfsp = (caddr_t)rfdirp->vfsp; 1447*0Sstevel@tonic-gate *offp = 0LL; 1448*0Sstevel@tonic-gate *lenp = (u_offset_t)sc->st_loghead.lh_maxbsize; 1449*0Sstevel@tonic-gate rc = (GRI_ADD | GRI_EXPENSIVE); 1450*0Sstevel@tonic-gate break; 1451*0Sstevel@tonic-gate 1452*0Sstevel@tonic-gate case CACHEFS_LOG_UALLOC: 1453*0Sstevel@tonic-gate uallocp = (struct cachefs_log_ualloc_record *)recp; 1454*0Sstevel@tonic-gate *fidp = &uallocp->fid; 1455*0Sstevel@tonic-gate *filenop = uallocp->fileno; 1456*0Sstevel@tonic-gate *vfsp = (caddr_t)uallocp->vfsp; 1457*0Sstevel@tonic-gate *offp = uallocp->off; 1458*0Sstevel@tonic-gate *lenp = (u_offset_t)uallocp->len; 1459*0Sstevel@tonic-gate rc = (GRI_ADD); 1460*0Sstevel@tonic-gate break; 1461*0Sstevel@tonic-gate 1462*0Sstevel@tonic-gate case CACHEFS_LOG_CALLOC: 1463*0Sstevel@tonic-gate callocp = (struct cachefs_log_calloc_record *)recp; 1464*0Sstevel@tonic-gate *fidp = &callocp->fid; 1465*0Sstevel@tonic-gate *filenop = callocp->fileno; 1466*0Sstevel@tonic-gate *vfsp = (caddr_t)callocp->vfsp; 1467*0Sstevel@tonic-gate *offp = callocp->off; 1468*0Sstevel@tonic-gate *lenp = (u_offset_t)callocp->len; 1469*0Sstevel@tonic-gate rc = (GRI_ADD | GRI_EXPENSIVE); 1470*0Sstevel@tonic-gate break; 1471*0Sstevel@tonic-gate 1472*0Sstevel@tonic-gate case CACHEFS_LOG_NOCACHE: 1473*0Sstevel@tonic-gate nocachep = (struct cachefs_log_nocache_record *)recp; 1474*0Sstevel@tonic-gate *fidp = &nocachep->fid; 1475*0Sstevel@tonic-gate *filenop = nocachep->fileno; 1476*0Sstevel@tonic-gate *vfsp = (caddr_t)nocachep->vfsp; 1477*0Sstevel@tonic-gate *offp = *lenp = 0LL; 1478*0Sstevel@tonic-gate rc = (GRI_TRUNC); 1479*0Sstevel@tonic-gate break; 1480*0Sstevel@tonic-gate } 1481*0Sstevel@tonic-gate 1482*0Sstevel@tonic-gate return (rc); 1483*0Sstevel@tonic-gate } 1484*0Sstevel@tonic-gate 1485*0Sstevel@tonic-gate /* 1486*0Sstevel@tonic-gate * ascii formatter for fids. returns a malloc()ed string -- it's up to 1487*0Sstevel@tonic-gate * the caller to free it. 1488*0Sstevel@tonic-gate */ 1489*0Sstevel@tonic-gate 1490*0Sstevel@tonic-gate static char * 1491*0Sstevel@tonic-gate stats_log_fmtfid(cfs_fid_t *fidp) 1492*0Sstevel@tonic-gate { 1493*0Sstevel@tonic-gate char buffy[BUFSIZ], *rc; 1494*0Sstevel@tonic-gate 1495*0Sstevel@tonic-gate (void) strcpy(buffy, "<fid>"); 1496*0Sstevel@tonic-gate 1497*0Sstevel@tonic-gate rc = strdup(buffy); 1498*0Sstevel@tonic-gate if (rc == NULL) 1499*0Sstevel@tonic-gate rc = "out of memory"; 1500*0Sstevel@tonic-gate 1501*0Sstevel@tonic-gate return (rc); 1502*0Sstevel@tonic-gate } 1503*0Sstevel@tonic-gate 1504*0Sstevel@tonic-gate void 1505*0Sstevel@tonic-gate stats_log_fi_add(stats_cookie_t *st, fid_info *fip, u_offset_t off, 1506*0Sstevel@tonic-gate u_offset_t len) 1507*0Sstevel@tonic-gate { 1508*0Sstevel@tonic-gate int i, j; 1509*0Sstevel@tonic-gate u_offset_t iend, jend, tmp; 1510*0Sstevel@tonic-gate 1511*0Sstevel@tonic-gate assert(stats_good(st)); 1512*0Sstevel@tonic-gate assert(st->st_flags & ST_DBMOPEN); 1513*0Sstevel@tonic-gate assert(st->st_flags & ST_LFOPEN); 1514*0Sstevel@tonic-gate 1515*0Sstevel@tonic-gate /* shortcut if we had some sort of zero-length thing */ 1516*0Sstevel@tonic-gate 1517*0Sstevel@tonic-gate if (len == 0LL) 1518*0Sstevel@tonic-gate return; 1519*0Sstevel@tonic-gate 1520*0Sstevel@tonic-gate /* `smear' the offset and length to block boundaries */ 1521*0Sstevel@tonic-gate 1522*0Sstevel@tonic-gate /* 1523*0Sstevel@tonic-gate * pre-largefiles: iend = off & ~(st->st_loghead.lh_maxbsize - 1); 1524*0Sstevel@tonic-gate * largefiles: make sure that we ~ all bits in the 64 bit 1525*0Sstevel@tonic-gate * version of (st->st_loghead.lh_maxbsize - 1) 1526*0Sstevel@tonic-gate */ 1527*0Sstevel@tonic-gate tmp = (u_offset_t)(st->st_loghead.lh_maxbsize - 1); 1528*0Sstevel@tonic-gate iend = off & ~tmp; 1529*0Sstevel@tonic-gate 1530*0Sstevel@tonic-gate jend = off + len; 1531*0Sstevel@tonic-gate jend += (u_offset_t)(st->st_loghead.lh_maxbsize - 1); 1532*0Sstevel@tonic-gate /* 1533*0Sstevel@tonic-gate * pre-largefiles: jend &= ~(st->st_loghead.lh_maxbsize - 1); 1534*0Sstevel@tonic-gate * largefiles: make sure that we ~ all bits in the 64 bit 1535*0Sstevel@tonic-gate * version of (st->st_loghead.lh_maxbsize - 1) 1536*0Sstevel@tonic-gate */ 1537*0Sstevel@tonic-gate jend &= ~tmp; 1538*0Sstevel@tonic-gate 1539*0Sstevel@tonic-gate off = iend; 1540*0Sstevel@tonic-gate len = jend - off; 1541*0Sstevel@tonic-gate 1542*0Sstevel@tonic-gate /* see if our offset falls within an existing chunk */ 1543*0Sstevel@tonic-gate for (i = 0; i < fip->fi_ent_n; i++) { 1544*0Sstevel@tonic-gate iend = fip->fi_ent[i].offset + fip->fi_ent[i].len; 1545*0Sstevel@tonic-gate if ((fip->fi_ent[i].offset <= off) && (iend >= off)) 1546*0Sstevel@tonic-gate break; 1547*0Sstevel@tonic-gate } 1548*0Sstevel@tonic-gate 1549*0Sstevel@tonic-gate /* update the chunk, or make a new one */ 1550*0Sstevel@tonic-gate if (i < fip->fi_ent_n) { 1551*0Sstevel@tonic-gate if ((off + len) > iend) 1552*0Sstevel@tonic-gate fip->fi_ent[i].len = off + len - fip->fi_ent[i].offset; 1553*0Sstevel@tonic-gate } else if (i < C_MAX_ALLOCINFO_SLOTS) { 1554*0Sstevel@tonic-gate fip->fi_ent_n = i + 1; 1555*0Sstevel@tonic-gate fip->fi_ent[i].offset = off; 1556*0Sstevel@tonic-gate fip->fi_ent[i].len = len; 1557*0Sstevel@tonic-gate } else { 1558*0Sstevel@tonic-gate /* cachefs does a nocache, so we'll immitate */ 1559*0Sstevel@tonic-gate 1560*0Sstevel@tonic-gate /* 1561*0Sstevel@tonic-gate * XXX we're free to grow again. assume we got 1562*0Sstevel@tonic-gate * inactivated right away -- the worst case! 1563*0Sstevel@tonic-gate */ 1564*0Sstevel@tonic-gate 1565*0Sstevel@tonic-gate fip->fi_ent_n = 0; 1566*0Sstevel@tonic-gate fip->fi_total = 0LL; 1567*0Sstevel@tonic-gate } 1568*0Sstevel@tonic-gate 1569*0Sstevel@tonic-gate /* quit for the trivial (hopefully the usual) case... */ 1570*0Sstevel@tonic-gate if (fip->fi_ent_n <= 1) { 1571*0Sstevel@tonic-gate if (fip->fi_ent_n == 0) 1572*0Sstevel@tonic-gate fip->fi_total = 0LL; 1573*0Sstevel@tonic-gate else 1574*0Sstevel@tonic-gate fip->fi_total = fip->fi_ent[0].len; 1575*0Sstevel@tonic-gate return; 1576*0Sstevel@tonic-gate } 1577*0Sstevel@tonic-gate 1578*0Sstevel@tonic-gate /* 1579*0Sstevel@tonic-gate * we have to see if we can consolidate any chunks. the 1580*0Sstevel@tonic-gate * chunks aren't guaranteed to be in any kind of order, so we 1581*0Sstevel@tonic-gate * do a qsort. otherwise, the consolidation would be N^2 (but 1582*0Sstevel@tonic-gate * we're probably close here). 1583*0Sstevel@tonic-gate */ 1584*0Sstevel@tonic-gate 1585*0Sstevel@tonic-gate qsort(fip->fi_ent, fip->fi_ent_n, sizeof (fip->fi_ent[0]), 1586*0Sstevel@tonic-gate stats_log_fi_comp); 1587*0Sstevel@tonic-gate 1588*0Sstevel@tonic-gate /* tag non-essential entries with offset == -1, and consolidate */ 1589*0Sstevel@tonic-gate for (i = 0; i < fip->fi_ent_n - 1; i++) { 1590*0Sstevel@tonic-gate if ((offset_t)fip->fi_ent[i].offset < 0) 1591*0Sstevel@tonic-gate continue; 1592*0Sstevel@tonic-gate iend = fip->fi_ent[i].offset + fip->fi_ent[i].len; 1593*0Sstevel@tonic-gate 1594*0Sstevel@tonic-gate for (j = i + 1; j < fip->fi_ent_n; j++) { 1595*0Sstevel@tonic-gate if (iend < fip->fi_ent[j].offset) 1596*0Sstevel@tonic-gate break; 1597*0Sstevel@tonic-gate jend = fip->fi_ent[j].offset + fip->fi_ent[j].len; 1598*0Sstevel@tonic-gate if (jend >= iend) 1599*0Sstevel@tonic-gate fip->fi_ent[i].len = 1600*0Sstevel@tonic-gate jend - fip->fi_ent[i].offset; 1601*0Sstevel@tonic-gate fip->fi_ent[j].offset = (u_offset_t)-1; 1602*0Sstevel@tonic-gate } 1603*0Sstevel@tonic-gate } 1604*0Sstevel@tonic-gate 1605*0Sstevel@tonic-gate /* get rid of non-essential entries (without preserving order) */ 1606*0Sstevel@tonic-gate for (i = 0; i < fip->fi_ent_n; i++) 1607*0Sstevel@tonic-gate if ((offset_t)fip->fi_ent[i].offset < 0) 1608*0Sstevel@tonic-gate fip->fi_ent[i--] = fip->fi_ent[--(fip->fi_ent_n)]; 1609*0Sstevel@tonic-gate 1610*0Sstevel@tonic-gate /* add up the new total size */ 1611*0Sstevel@tonic-gate for (i = fip->fi_total = 0LL; i < fip->fi_ent_n; i++) 1612*0Sstevel@tonic-gate fip->fi_total += fip->fi_ent[i].len; 1613*0Sstevel@tonic-gate } 1614*0Sstevel@tonic-gate 1615*0Sstevel@tonic-gate static int 1616*0Sstevel@tonic-gate stats_log_fi_comp(const void *a, const void *b) 1617*0Sstevel@tonic-gate { 1618*0Sstevel@tonic-gate struct fid_info_allocent *fa = (struct fid_info_allocent *)a; 1619*0Sstevel@tonic-gate struct fid_info_allocent *fb = (struct fid_info_allocent *)b; 1620*0Sstevel@tonic-gate 1621*0Sstevel@tonic-gate if ((offset_t)(fa->offset - fb->offset) > 0) 1622*0Sstevel@tonic-gate return (1); 1623*0Sstevel@tonic-gate if ((offset_t)(fa->offset - fb->offset) < 0) 1624*0Sstevel@tonic-gate return (-1); 1625*0Sstevel@tonic-gate return (0); 1626*0Sstevel@tonic-gate } 1627*0Sstevel@tonic-gate 1628*0Sstevel@tonic-gate void 1629*0Sstevel@tonic-gate stats_log_fi_trunc(stats_cookie_t *st, fid_info *fip, u_offset_t off, 1630*0Sstevel@tonic-gate u_offset_t len) 1631*0Sstevel@tonic-gate { 1632*0Sstevel@tonic-gate fip->fi_ent_n = 1; 1633*0Sstevel@tonic-gate fip->fi_ent[0].offset = off; 1634*0Sstevel@tonic-gate fip->fi_ent[0].len = len; 1635*0Sstevel@tonic-gate fip->fi_total = len; 1636*0Sstevel@tonic-gate } 1637*0Sstevel@tonic-gate 1638*0Sstevel@tonic-gate struct cachefs_log_logfile_header * 1639*0Sstevel@tonic-gate stats_log_getheader(stats_cookie_t *st) 1640*0Sstevel@tonic-gate { 1641*0Sstevel@tonic-gate assert(stats_good(st)); 1642*0Sstevel@tonic-gate assert(st->st_flags & ST_LFOPEN); 1643*0Sstevel@tonic-gate 1644*0Sstevel@tonic-gate return (&st->st_loghead); 1645*0Sstevel@tonic-gate } 1646*0Sstevel@tonic-gate 1647*0Sstevel@tonic-gate void 1648*0Sstevel@tonic-gate stats_log_compute_wssize(stats_cookie_t *st) 1649*0Sstevel@tonic-gate { 1650*0Sstevel@tonic-gate void *record; 1651*0Sstevel@tonic-gate int type; 1652*0Sstevel@tonic-gate struct cachefs_log_mount_record *mountp; 1653*0Sstevel@tonic-gate struct cachefs_log_umount_record *umountp; 1654*0Sstevel@tonic-gate datum key; 1655*0Sstevel@tonic-gate caddr_t vfsp; 1656*0Sstevel@tonic-gate mount_info *mi = NULL, *mip; 1657*0Sstevel@tonic-gate size_t len1, len2, maxlen; 1658*0Sstevel@tonic-gate char *string1, *string2; 1659*0Sstevel@tonic-gate uint_t rflags; 1660*0Sstevel@tonic-gate fid_info fi, *fip; 1661*0Sstevel@tonic-gate cfs_fid_t *fidp; 1662*0Sstevel@tonic-gate ino64_t fileno; 1663*0Sstevel@tonic-gate u_offset_t off; 1664*0Sstevel@tonic-gate u_offset_t len; 1665*0Sstevel@tonic-gate struct cachefs_log_logfile_header *lh = &st->st_loghead; 1666*0Sstevel@tonic-gate size_t delta; 1667*0Sstevel@tonic-gate 1668*0Sstevel@tonic-gate assert(stats_good(st)); 1669*0Sstevel@tonic-gate assert(st->st_flags & ST_LFOPEN); 1670*0Sstevel@tonic-gate assert(st->st_flags & ST_DBMOPEN); 1671*0Sstevel@tonic-gate 1672*0Sstevel@tonic-gate /* 1673*0Sstevel@tonic-gate * The maximum size of a mount_info structure is the size of 1674*0Sstevel@tonic-gate * the structure less the space already defined for char mi_path[] 1675*0Sstevel@tonic-gate * plus the maximum size of mi_path. 1676*0Sstevel@tonic-gate * 1677*0Sstevel@tonic-gate * Additional space is allocated to mi_path at runtime using 1678*0Sstevel@tonic-gate * malloc(). The size needs to be calculated in-situ as ANSI C 1679*0Sstevel@tonic-gate * will only allow 'sizeof expression' or 'sizeof (type)'. 1680*0Sstevel@tonic-gate */ 1681*0Sstevel@tonic-gate 1682*0Sstevel@tonic-gate mi = malloc(sizeof (*mi) - sizeof (mi->mi_path) + MI_MAX_MI_PATH); 1683*0Sstevel@tonic-gate if (mi == NULL) { 1684*0Sstevel@tonic-gate stats_perror(st, SE_NOMEM, gettext("Out of memory")); 1685*0Sstevel@tonic-gate goto out; 1686*0Sstevel@tonic-gate } 1687*0Sstevel@tonic-gate 1688*0Sstevel@tonic-gate st->st_ws_init = st->st_loghead.lh_blocks; 1689*0Sstevel@tonic-gate 1690*0Sstevel@tonic-gate while (record = stats_log_logfile_read(st, &type)) { 1691*0Sstevel@tonic-gate switch (type) { 1692*0Sstevel@tonic-gate case CACHEFS_LOG_MOUNT: 1693*0Sstevel@tonic-gate mountp = (struct cachefs_log_mount_record *)record; 1694*0Sstevel@tonic-gate if (mountp->error != 0) 1695*0Sstevel@tonic-gate break; 1696*0Sstevel@tonic-gate for (key = stats_dbm_firstkey(st); 1697*0Sstevel@tonic-gate key.dptr != NULL; 1698*0Sstevel@tonic-gate key = stats_dbm_nextkey(st)) { 1699*0Sstevel@tonic-gate if (key.dsize != sizeof (vfsp)) 1700*0Sstevel@tonic-gate continue; 1701*0Sstevel@tonic-gate 1702*0Sstevel@tonic-gate memcpy((caddr_t)&vfsp, key.dptr, 1703*0Sstevel@tonic-gate sizeof (vfsp)); 1704*0Sstevel@tonic-gate mip = stats_dbm_fetch_byvfsp(st, vfsp); 1705*0Sstevel@tonic-gate if (mip == NULL) 1706*0Sstevel@tonic-gate continue; 1707*0Sstevel@tonic-gate 1708*0Sstevel@tonic-gate len1 = strlen(mip->mi_path); 1709*0Sstevel@tonic-gate len2 = strlen(mip->mi_path + len1 + 1); 1710*0Sstevel@tonic-gate memcpy((caddr_t)mi, mip, sizeof (*mi) + 1711*0Sstevel@tonic-gate len1 + len2 - CLPAD(mount_info, mi_path)); 1712*0Sstevel@tonic-gate free(mip); 1713*0Sstevel@tonic-gate 1714*0Sstevel@tonic-gate string1 = mi->mi_path + len1 + 1; 1715*0Sstevel@tonic-gate string2 = mountp->path + mountp->pathlen + 1; 1716*0Sstevel@tonic-gate if (strcmp(string1, string2) == 0) { 1717*0Sstevel@tonic-gate stats_dbm_delete_byvfsp(st, vfsp); 1718*0Sstevel@tonic-gate break; 1719*0Sstevel@tonic-gate } 1720*0Sstevel@tonic-gate } 1721*0Sstevel@tonic-gate if (key.dptr == NULL) { 1722*0Sstevel@tonic-gate /* non-idempotent setup stuff */ 1723*0Sstevel@tonic-gate memset(mi, '\0', sizeof (*mi)); 1724*0Sstevel@tonic-gate mi->mi_flags = mountp->flags; 1725*0Sstevel@tonic-gate mi->mi_filegrp_size = mountp->fgsize; 1726*0Sstevel@tonic-gate } 1727*0Sstevel@tonic-gate 1728*0Sstevel@tonic-gate /* 1729*0Sstevel@tonic-gate * idempotent setup stuff 1730*0Sstevel@tonic-gate * 1731*0Sstevel@tonic-gate * Careful string handling around mi_path 1732*0Sstevel@tonic-gate * is required as it contains two NULL 1733*0Sstevel@tonic-gate * terminated strings. 1734*0Sstevel@tonic-gate */ 1735*0Sstevel@tonic-gate 1736*0Sstevel@tonic-gate mi->mi_mounted = 1; 1737*0Sstevel@tonic-gate maxlen = MI_MAX_MI_PATH - 1; 1738*0Sstevel@tonic-gate len1 = strlcpy(mi->mi_path, mountp->path, maxlen); 1739*0Sstevel@tonic-gate if (len1 >= maxlen) { 1740*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 1741*0Sstevel@tonic-gate gettext("Path too long in log file")); 1742*0Sstevel@tonic-gate break; 1743*0Sstevel@tonic-gate } 1744*0Sstevel@tonic-gate 1745*0Sstevel@tonic-gate len1 = strlen(mi->mi_path); 1746*0Sstevel@tonic-gate maxlen = MI_MAX_MI_PATH - (len1 + 1); 1747*0Sstevel@tonic-gate len2 = strlcpy(mi->mi_path + len1 + 1, 1748*0Sstevel@tonic-gate mountp->path + mountp->pathlen + 1, maxlen); 1749*0Sstevel@tonic-gate if (len2 >= maxlen) { 1750*0Sstevel@tonic-gate stats_perror(st, SE_CORRUPT, 1751*0Sstevel@tonic-gate gettext("CacheID too long in log file")); 1752*0Sstevel@tonic-gate break; 1753*0Sstevel@tonic-gate } 1754*0Sstevel@tonic-gate 1755*0Sstevel@tonic-gate stats_dbm_store_byvfsp(st, (caddr_t)mountp->vfsp, mi); 1756*0Sstevel@tonic-gate break; 1757*0Sstevel@tonic-gate 1758*0Sstevel@tonic-gate case CACHEFS_LOG_UMOUNT: 1759*0Sstevel@tonic-gate umountp = (struct cachefs_log_umount_record *)record; 1760*0Sstevel@tonic-gate if (umountp->error != 0) 1761*0Sstevel@tonic-gate break; 1762*0Sstevel@tonic-gate mip = stats_dbm_fetch_byvfsp(st, 1763*0Sstevel@tonic-gate (caddr_t)umountp->vfsp); 1764*0Sstevel@tonic-gate if (mip == NULL) 1765*0Sstevel@tonic-gate break; 1766*0Sstevel@tonic-gate mip->mi_mounted = 0; 1767*0Sstevel@tonic-gate stats_dbm_store_byvfsp(st, (caddr_t)umountp->vfsp, mip); 1768*0Sstevel@tonic-gate free(mip); 1769*0Sstevel@tonic-gate break; 1770*0Sstevel@tonic-gate 1771*0Sstevel@tonic-gate default: 1772*0Sstevel@tonic-gate rflags = stats_log_get_record_info(st, record, 1773*0Sstevel@tonic-gate &vfsp, &fidp, &fileno, &off, &len); 1774*0Sstevel@tonic-gate if (rflags == 0) /* shortcut */ 1775*0Sstevel@tonic-gate break; 1776*0Sstevel@tonic-gate 1777*0Sstevel@tonic-gate mip = stats_dbm_fetch_byvfsp(st, vfsp); 1778*0Sstevel@tonic-gate if (mip == NULL) /* hopefully very rare */ 1779*0Sstevel@tonic-gate break; 1780*0Sstevel@tonic-gate 1781*0Sstevel@tonic-gate fip = stats_dbm_fetch_byfid(st, fidp); 1782*0Sstevel@tonic-gate if (fip == NULL) { 1783*0Sstevel@tonic-gate fip = &fi; 1784*0Sstevel@tonic-gate memset(&fi, '\0', sizeof (fi)); 1785*0Sstevel@tonic-gate fi.fi_vfsp = vfsp; 1786*0Sstevel@tonic-gate } 1787*0Sstevel@tonic-gate 1788*0Sstevel@tonic-gate /* account for the creation of the fscache */ 1789*0Sstevel@tonic-gate if (! mip->mi_used) { 1790*0Sstevel@tonic-gate mip->mi_used = 1; 1791*0Sstevel@tonic-gate 1792*0Sstevel@tonic-gate /* account for the .cfs_option file */ 1793*0Sstevel@tonic-gate mip->mi_current += (u_offset_t)lh->lh_maxbsize; 1794*0Sstevel@tonic-gate st->st_ws_current += 1795*0Sstevel@tonic-gate (u_offset_t)lh->lh_maxbsize; 1796*0Sstevel@tonic-gate } 1797*0Sstevel@tonic-gate 1798*0Sstevel@tonic-gate /* 1799*0Sstevel@tonic-gate * Add in the size-growth of the attrcache. 1800*0Sstevel@tonic-gate * len will be non-zero only for the record type 1801*0Sstevel@tonic-gate * CACHEFS_LOG_MDCREATE, and len can't be > 2GB because 1802*0Sstevel@tonic-gate * it refers to the number of entries in 1803*0Sstevel@tonic-gate * the attribute cache file. 1804*0Sstevel@tonic-gate */ 1805*0Sstevel@tonic-gate assert(len <= UINT_MAX); 1806*0Sstevel@tonic-gate delta = stats_dbm_attrcache_addsize(st, mip, fileno, 1807*0Sstevel@tonic-gate (type == CACHEFS_LOG_MDCREATE) ? (uint_t)len : 0); 1808*0Sstevel@tonic-gate st->st_ws_current += (u_offset_t)delta; 1809*0Sstevel@tonic-gate mip->mi_current += (u_offset_t)delta; 1810*0Sstevel@tonic-gate 1811*0Sstevel@tonic-gate /* see if this is an `expensive' logfile */ 1812*0Sstevel@tonic-gate if ((! st->st_ws_expensive) && (rflags & GRI_EXPENSIVE)) 1813*0Sstevel@tonic-gate st->st_ws_expensive = 1; 1814*0Sstevel@tonic-gate 1815*0Sstevel@tonic-gate /* subtract current frontfile size ... */ 1816*0Sstevel@tonic-gate st->st_ws_current -= fip->fi_total; 1817*0Sstevel@tonic-gate mip->mi_current -= fip->fi_total; 1818*0Sstevel@tonic-gate 1819*0Sstevel@tonic-gate /* compute new frontfile size */ 1820*0Sstevel@tonic-gate if ((mip->mi_flags & CFS_WRITE_AROUND) && 1821*0Sstevel@tonic-gate (rflags & GRI_MODIFY)) { 1822*0Sstevel@tonic-gate fip->fi_total = 0LL; 1823*0Sstevel@tonic-gate fip->fi_ent_n = 0; 1824*0Sstevel@tonic-gate } else if (rflags & GRI_ADD) { 1825*0Sstevel@tonic-gate stats_log_fi_add(st, fip, off, len); 1826*0Sstevel@tonic-gate } else if (rflags & GRI_TRUNC) { 1827*0Sstevel@tonic-gate stats_log_fi_trunc(st, fip, off, len); 1828*0Sstevel@tonic-gate } 1829*0Sstevel@tonic-gate if (rflags & GRI_METADATA) 1830*0Sstevel@tonic-gate fip->fi_flags |= FI_METADATA; 1831*0Sstevel@tonic-gate 1832*0Sstevel@tonic-gate /* add back in new frontfile size */ 1833*0Sstevel@tonic-gate mip->mi_current += fip->fi_total; 1834*0Sstevel@tonic-gate if (mip->mi_current > mip->mi_high) 1835*0Sstevel@tonic-gate mip->mi_high = mip->mi_current; 1836*0Sstevel@tonic-gate stats_dbm_store_byvfsp(st, vfsp, mip); 1837*0Sstevel@tonic-gate free(mip); 1838*0Sstevel@tonic-gate st->st_ws_current += fip->fi_total; 1839*0Sstevel@tonic-gate if (st->st_ws_current > st->st_ws_high) 1840*0Sstevel@tonic-gate st->st_ws_high = st->st_ws_current; 1841*0Sstevel@tonic-gate 1842*0Sstevel@tonic-gate stats_dbm_store_byfid(st, fidp, fip); 1843*0Sstevel@tonic-gate if (fip != &fi) 1844*0Sstevel@tonic-gate free(fip); 1845*0Sstevel@tonic-gate break; 1846*0Sstevel@tonic-gate } 1847*0Sstevel@tonic-gate 1848*0Sstevel@tonic-gate free(record); 1849*0Sstevel@tonic-gate 1850*0Sstevel@tonic-gate if (stats_inerror(st)) 1851*0Sstevel@tonic-gate break; 1852*0Sstevel@tonic-gate } 1853*0Sstevel@tonic-gate 1854*0Sstevel@tonic-gate out: 1855*0Sstevel@tonic-gate if (mi != NULL) 1856*0Sstevel@tonic-gate free(mi); 1857*0Sstevel@tonic-gate if (! stats_inerror(st)) 1858*0Sstevel@tonic-gate st->st_flags |= ST_WSCOMP; 1859*0Sstevel@tonic-gate } 1860*0Sstevel@tonic-gate 1861*0Sstevel@tonic-gate int 1862*0Sstevel@tonic-gate stats_log_wssize_init(stats_cookie_t *st) 1863*0Sstevel@tonic-gate { 1864*0Sstevel@tonic-gate assert(stats_good(st)); 1865*0Sstevel@tonic-gate assert(st->st_flags & ST_WSCOMP); 1866*0Sstevel@tonic-gate 1867*0Sstevel@tonic-gate return (st->st_ws_init); 1868*0Sstevel@tonic-gate } 1869*0Sstevel@tonic-gate 1870*0Sstevel@tonic-gate u_offset_t 1871*0Sstevel@tonic-gate stats_log_wssize_current(stats_cookie_t *st) 1872*0Sstevel@tonic-gate { 1873*0Sstevel@tonic-gate assert(stats_good(st)); 1874*0Sstevel@tonic-gate assert(st->st_flags & ST_WSCOMP); 1875*0Sstevel@tonic-gate 1876*0Sstevel@tonic-gate return (st->st_ws_current); 1877*0Sstevel@tonic-gate } 1878*0Sstevel@tonic-gate 1879*0Sstevel@tonic-gate u_offset_t 1880*0Sstevel@tonic-gate stats_log_wssize_high(stats_cookie_t *st) 1881*0Sstevel@tonic-gate { 1882*0Sstevel@tonic-gate assert(stats_good(st)); 1883*0Sstevel@tonic-gate assert(st->st_flags & ST_WSCOMP); 1884*0Sstevel@tonic-gate 1885*0Sstevel@tonic-gate return (st->st_ws_high); 1886*0Sstevel@tonic-gate } 1887*0Sstevel@tonic-gate 1888*0Sstevel@tonic-gate 1889*0Sstevel@tonic-gate int 1890*0Sstevel@tonic-gate stats_log_wssize_expensive(stats_cookie_t *st) 1891*0Sstevel@tonic-gate { 1892*0Sstevel@tonic-gate assert(stats_good(st)); 1893*0Sstevel@tonic-gate assert(st->st_flags & ST_WSCOMP); 1894*0Sstevel@tonic-gate 1895*0Sstevel@tonic-gate return (st->st_ws_expensive); 1896*0Sstevel@tonic-gate } 1897