1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright (c) 1999 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate * All rights reserved.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate #include <stdio.h>
30*7c478bd9Sstevel@tonic-gate #include <errno.h>
31*7c478bd9Sstevel@tonic-gate #include <malloc.h>
32*7c478bd9Sstevel@tonic-gate #include <strings.h>
33*7c478bd9Sstevel@tonic-gate #include <stddef.h>
34*7c478bd9Sstevel@tonic-gate #include <search.h>
35*7c478bd9Sstevel@tonic-gate #include <syslog.h>
36*7c478bd9Sstevel@tonic-gate #include <libintl.h>
37*7c478bd9Sstevel@tonic-gate #include <unistd.h>
38*7c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
39*7c478bd9Sstevel@tonic-gate #include <netconfig.h>
40*7c478bd9Sstevel@tonic-gate #include <netdir.h>
41*7c478bd9Sstevel@tonic-gate #include <nfs/nfs_sec.h>
42*7c478bd9Sstevel@tonic-gate #include <nfs/export.h>
43*7c478bd9Sstevel@tonic-gate #include <rpc/auth.h>
44*7c478bd9Sstevel@tonic-gate #include <rpc/svc.h>
45*7c478bd9Sstevel@tonic-gate #include <rpc/xdr.h>
46*7c478bd9Sstevel@tonic-gate #include <rpc/clnt.h>
47*7c478bd9Sstevel@tonic-gate #include <nfs/nfs.h>
48*7c478bd9Sstevel@tonic-gate #include <nfs/nfs_log.h>
49*7c478bd9Sstevel@tonic-gate #include <assert.h>
50*7c478bd9Sstevel@tonic-gate #include "fhtab.h"
51*7c478bd9Sstevel@tonic-gate #include "nfslogd.h"
52*7c478bd9Sstevel@tonic-gate
53*7c478bd9Sstevel@tonic-gate /*
54*7c478bd9Sstevel@tonic-gate * How long should an entry stay in the list before being forced
55*7c478bd9Sstevel@tonic-gate * out and a trans log entry printed
56*7c478bd9Sstevel@tonic-gate */
57*7c478bd9Sstevel@tonic-gate #define TRANS_ENTRY_TIMEOUT 60
58*7c478bd9Sstevel@tonic-gate
59*7c478bd9Sstevel@tonic-gate extern char *addrtoname(void *);
60*7c478bd9Sstevel@tonic-gate
61*7c478bd9Sstevel@tonic-gate struct transentry {
62*7c478bd9Sstevel@tonic-gate struct transentry *next;
63*7c478bd9Sstevel@tonic-gate struct transentry *prev;
64*7c478bd9Sstevel@tonic-gate timestruc32_t starttime; /* when did transaction start? */
65*7c478bd9Sstevel@tonic-gate timestruc32_t lastupdate; /* last operation for this entry */
66*7c478bd9Sstevel@tonic-gate #define TRANS_OPER_READ 1
67*7c478bd9Sstevel@tonic-gate #define TRANS_OPER_WRITE 2
68*7c478bd9Sstevel@tonic-gate #define TRANS_OPER_SETATTR 3
69*7c478bd9Sstevel@tonic-gate #define TRANS_OPER_REMOVE 4
70*7c478bd9Sstevel@tonic-gate #define TRANS_OPER_MKDIR 5
71*7c478bd9Sstevel@tonic-gate #define TRANS_OPER_CREATE 6
72*7c478bd9Sstevel@tonic-gate #define TRANS_OPER_RMDIR 7
73*7c478bd9Sstevel@tonic-gate #define TRANS_OPER_RENAME 8
74*7c478bd9Sstevel@tonic-gate #define TRANS_OPER_MKNOD 9
75*7c478bd9Sstevel@tonic-gate #define TRANS_OPER_LINK 10
76*7c478bd9Sstevel@tonic-gate #define TRANS_OPER_SYMLINK 11
77*7c478bd9Sstevel@tonic-gate uchar_t optype; /* read, write, ...? */
78*7c478bd9Sstevel@tonic-gate #define TRANS_DATATYPE_NA /* not applicable data type */
79*7c478bd9Sstevel@tonic-gate #define TRANS_DATATYPE_ASCII 0 /* transfer done as ascii */
80*7c478bd9Sstevel@tonic-gate #define TRANS_DATATYPE_BINARY 1 /* transfer done as binary */
81*7c478bd9Sstevel@tonic-gate uchar_t datatype;
82*7c478bd9Sstevel@tonic-gate /*
83*7c478bd9Sstevel@tonic-gate * Action taken by server before transfer was made -- noaction,
84*7c478bd9Sstevel@tonic-gate * compressed, tar or uncompressed.
85*7c478bd9Sstevel@tonic-gate */
86*7c478bd9Sstevel@tonic-gate #define TRANS_OPTION_NOACTION 0
87*7c478bd9Sstevel@tonic-gate uchar_t transoption;
88*7c478bd9Sstevel@tonic-gate char *pathname;
89*7c478bd9Sstevel@tonic-gate struct netbuf *pnb;
90*7c478bd9Sstevel@tonic-gate uid_t uid;
91*7c478bd9Sstevel@tonic-gate int nfsvers;
92*7c478bd9Sstevel@tonic-gate char *netid;
93*7c478bd9Sstevel@tonic-gate char *principal_name;
94*7c478bd9Sstevel@tonic-gate uint64_t totalbytes; /* total operated upon in history */
95*7c478bd9Sstevel@tonic-gate union {
96*7c478bd9Sstevel@tonic-gate fhandle_t fh;
97*7c478bd9Sstevel@tonic-gate nfs_fh3 fh3;
98*7c478bd9Sstevel@tonic-gate } fh_u;
99*7c478bd9Sstevel@tonic-gate };
100*7c478bd9Sstevel@tonic-gate
101*7c478bd9Sstevel@tonic-gate struct nfslog_trans_file {
102*7c478bd9Sstevel@tonic-gate struct nfslog_trans_file *next; /* next file in list */
103*7c478bd9Sstevel@tonic-gate struct nfslog_trans_file *prev; /* next file in list */
104*7c478bd9Sstevel@tonic-gate int refcnt; /* number of references to this struct */
105*7c478bd9Sstevel@tonic-gate char *path; /* pathname of file */
106*7c478bd9Sstevel@tonic-gate FILE *fp; /* file pointer */
107*7c478bd9Sstevel@tonic-gate /* timestamp of the last transaction processed for this file */
108*7c478bd9Sstevel@tonic-gate timestruc32_t lasttrans_timestamp;
109*7c478bd9Sstevel@tonic-gate /* 'current' time that last trans was processed */
110*7c478bd9Sstevel@tonic-gate time_t last_trans_read;
111*7c478bd9Sstevel@tonic-gate uint32_t trans_to_log; /* transactions that are to be logged */
112*7c478bd9Sstevel@tonic-gate uint32_t trans_output_type;
113*7c478bd9Sstevel@tonic-gate struct transentry *te_list_v3_read;
114*7c478bd9Sstevel@tonic-gate struct transentry *te_list_v3_write;
115*7c478bd9Sstevel@tonic-gate struct transentry *te_list_v2_read;
116*7c478bd9Sstevel@tonic-gate struct transentry *te_list_v2_write;
117*7c478bd9Sstevel@tonic-gate };
118*7c478bd9Sstevel@tonic-gate
119*7c478bd9Sstevel@tonic-gate static struct nfslog_trans_file *trans_file_head = NULL;
120*7c478bd9Sstevel@tonic-gate
121*7c478bd9Sstevel@tonic-gate static void nfslog_print_trans_logentry(struct transentry *,
122*7c478bd9Sstevel@tonic-gate struct nfslog_trans_file *);
123*7c478bd9Sstevel@tonic-gate
124*7c478bd9Sstevel@tonic-gate
125*7c478bd9Sstevel@tonic-gate static struct netbuf *
netbufdup(struct netbuf * pnb)126*7c478bd9Sstevel@tonic-gate netbufdup(struct netbuf *pnb)
127*7c478bd9Sstevel@tonic-gate {
128*7c478bd9Sstevel@tonic-gate struct netbuf *pnewnb;
129*7c478bd9Sstevel@tonic-gate uint32_t size;
130*7c478bd9Sstevel@tonic-gate
131*7c478bd9Sstevel@tonic-gate size = offsetof(struct netbuf, buf);
132*7c478bd9Sstevel@tonic-gate size += pnb->len;
133*7c478bd9Sstevel@tonic-gate
134*7c478bd9Sstevel@tonic-gate if ((pnewnb = (struct netbuf *)malloc(sizeof (*pnewnb))) == NULL)
135*7c478bd9Sstevel@tonic-gate return (NULL);
136*7c478bd9Sstevel@tonic-gate if ((pnewnb->buf = malloc(pnb->len)) == NULL) {
137*7c478bd9Sstevel@tonic-gate free(pnewnb);
138*7c478bd9Sstevel@tonic-gate return (NULL);
139*7c478bd9Sstevel@tonic-gate }
140*7c478bd9Sstevel@tonic-gate
141*7c478bd9Sstevel@tonic-gate pnewnb->maxlen = pnb->maxlen;
142*7c478bd9Sstevel@tonic-gate pnewnb->len = pnb->len;
143*7c478bd9Sstevel@tonic-gate bcopy(pnb->buf, pnewnb->buf, pnb->len);
144*7c478bd9Sstevel@tonic-gate return (pnewnb);
145*7c478bd9Sstevel@tonic-gate }
146*7c478bd9Sstevel@tonic-gate
147*7c478bd9Sstevel@tonic-gate static void
freenetbuf(struct netbuf * pnb)148*7c478bd9Sstevel@tonic-gate freenetbuf(struct netbuf *pnb)
149*7c478bd9Sstevel@tonic-gate {
150*7c478bd9Sstevel@tonic-gate free(pnb->buf);
151*7c478bd9Sstevel@tonic-gate free(pnb);
152*7c478bd9Sstevel@tonic-gate }
153*7c478bd9Sstevel@tonic-gate
154*7c478bd9Sstevel@tonic-gate static struct transentry *
create_te()155*7c478bd9Sstevel@tonic-gate create_te()
156*7c478bd9Sstevel@tonic-gate {
157*7c478bd9Sstevel@tonic-gate struct transentry *pte;
158*7c478bd9Sstevel@tonic-gate
159*7c478bd9Sstevel@tonic-gate if ((pte = (struct transentry *)calloc(1, sizeof (*pte))) == NULL) {
160*7c478bd9Sstevel@tonic-gate /* failure message or action */
161*7c478bd9Sstevel@tonic-gate return (NULL);
162*7c478bd9Sstevel@tonic-gate }
163*7c478bd9Sstevel@tonic-gate
164*7c478bd9Sstevel@tonic-gate pte->next = pte->prev = NULL;
165*7c478bd9Sstevel@tonic-gate
166*7c478bd9Sstevel@tonic-gate return (pte);
167*7c478bd9Sstevel@tonic-gate }
168*7c478bd9Sstevel@tonic-gate
169*7c478bd9Sstevel@tonic-gate static struct transentry *
insert_te(struct transentry * te_list,struct transentry * entry)170*7c478bd9Sstevel@tonic-gate insert_te(
171*7c478bd9Sstevel@tonic-gate struct transentry *te_list,
172*7c478bd9Sstevel@tonic-gate struct transentry *entry)
173*7c478bd9Sstevel@tonic-gate {
174*7c478bd9Sstevel@tonic-gate struct transentry *pte;
175*7c478bd9Sstevel@tonic-gate
176*7c478bd9Sstevel@tonic-gate /*
177*7c478bd9Sstevel@tonic-gate * First check for any non-filehandle comparisons that may be needed.
178*7c478bd9Sstevel@tonic-gate */
179*7c478bd9Sstevel@tonic-gate switch (entry->optype) {
180*7c478bd9Sstevel@tonic-gate case TRANS_OPER_REMOVE:
181*7c478bd9Sstevel@tonic-gate case TRANS_OPER_RENAME:
182*7c478bd9Sstevel@tonic-gate for (pte = te_list->next; pte != te_list; pte = pte->next) {
183*7c478bd9Sstevel@tonic-gate /* if path names match, then return */
184*7c478bd9Sstevel@tonic-gate if (strcmp(pte->pathname, entry->pathname) == 0) {
185*7c478bd9Sstevel@tonic-gate return (pte);
186*7c478bd9Sstevel@tonic-gate }
187*7c478bd9Sstevel@tonic-gate }
188*7c478bd9Sstevel@tonic-gate return (NULL);
189*7c478bd9Sstevel@tonic-gate default:
190*7c478bd9Sstevel@tonic-gate break;
191*7c478bd9Sstevel@tonic-gate }
192*7c478bd9Sstevel@tonic-gate
193*7c478bd9Sstevel@tonic-gate for (pte = te_list->next; pte != te_list; pte = pte->next) {
194*7c478bd9Sstevel@tonic-gate /* If the file handles match, then we have a hit */
195*7c478bd9Sstevel@tonic-gate if (entry->nfsvers == NFS_VERSION) {
196*7c478bd9Sstevel@tonic-gate if (bcmp(&(pte->fh_u.fh), &(entry->fh_u.fh),
197*7c478bd9Sstevel@tonic-gate sizeof (fhandle_t)) == 0) {
198*7c478bd9Sstevel@tonic-gate switch (entry->optype) {
199*7c478bd9Sstevel@tonic-gate case TRANS_OPER_READ:
200*7c478bd9Sstevel@tonic-gate case TRANS_OPER_WRITE:
201*7c478bd9Sstevel@tonic-gate if (pte->uid == entry->uid) {
202*7c478bd9Sstevel@tonic-gate return (pte);
203*7c478bd9Sstevel@tonic-gate }
204*7c478bd9Sstevel@tonic-gate break;
205*7c478bd9Sstevel@tonic-gate default:
206*7c478bd9Sstevel@tonic-gate return (pte);
207*7c478bd9Sstevel@tonic-gate }
208*7c478bd9Sstevel@tonic-gate }
209*7c478bd9Sstevel@tonic-gate } else {
210*7c478bd9Sstevel@tonic-gate if (pte->fh_u.fh3.fh3_length ==
211*7c478bd9Sstevel@tonic-gate entry->fh_u.fh3.fh3_length &&
212*7c478bd9Sstevel@tonic-gate bcmp(pte->fh_u.fh3.fh3_u.data,
213*7c478bd9Sstevel@tonic-gate entry->fh_u.fh3.fh3_u.data,
214*7c478bd9Sstevel@tonic-gate pte->fh_u.fh3.fh3_length) == 0)
215*7c478bd9Sstevel@tonic-gate switch (entry->optype) {
216*7c478bd9Sstevel@tonic-gate case TRANS_OPER_READ:
217*7c478bd9Sstevel@tonic-gate case TRANS_OPER_WRITE:
218*7c478bd9Sstevel@tonic-gate if (pte->uid == entry->uid) {
219*7c478bd9Sstevel@tonic-gate return (pte);
220*7c478bd9Sstevel@tonic-gate }
221*7c478bd9Sstevel@tonic-gate break;
222*7c478bd9Sstevel@tonic-gate default:
223*7c478bd9Sstevel@tonic-gate return (pte);
224*7c478bd9Sstevel@tonic-gate }
225*7c478bd9Sstevel@tonic-gate }
226*7c478bd9Sstevel@tonic-gate }
227*7c478bd9Sstevel@tonic-gate /*
228*7c478bd9Sstevel@tonic-gate * XXX - should compare more of the information to make sure
229*7c478bd9Sstevel@tonic-gate * it is a match.
230*7c478bd9Sstevel@tonic-gate */
231*7c478bd9Sstevel@tonic-gate
232*7c478bd9Sstevel@tonic-gate /*
233*7c478bd9Sstevel@tonic-gate * other operation types do not generate an entry for
234*7c478bd9Sstevel@tonic-gate * further analysis
235*7c478bd9Sstevel@tonic-gate */
236*7c478bd9Sstevel@tonic-gate switch (entry->optype) {
237*7c478bd9Sstevel@tonic-gate case TRANS_OPER_READ:
238*7c478bd9Sstevel@tonic-gate case TRANS_OPER_WRITE:
239*7c478bd9Sstevel@tonic-gate break;
240*7c478bd9Sstevel@tonic-gate default:
241*7c478bd9Sstevel@tonic-gate return (NULL);
242*7c478bd9Sstevel@tonic-gate }
243*7c478bd9Sstevel@tonic-gate
244*7c478bd9Sstevel@tonic-gate insque(entry, te_list);
245*7c478bd9Sstevel@tonic-gate
246*7c478bd9Sstevel@tonic-gate return (NULL); /* NULL signifies insertion and no record found */
247*7c478bd9Sstevel@tonic-gate }
248*7c478bd9Sstevel@tonic-gate
249*7c478bd9Sstevel@tonic-gate static void
remove_te(struct transentry * pte)250*7c478bd9Sstevel@tonic-gate remove_te(struct transentry *pte)
251*7c478bd9Sstevel@tonic-gate {
252*7c478bd9Sstevel@tonic-gate if (pte->next)
253*7c478bd9Sstevel@tonic-gate remque(pte);
254*7c478bd9Sstevel@tonic-gate
255*7c478bd9Sstevel@tonic-gate if (pte->principal_name) free(pte->principal_name);
256*7c478bd9Sstevel@tonic-gate if (pte->pathname) free(pte->pathname);
257*7c478bd9Sstevel@tonic-gate if (pte->pnb) freenetbuf(pte->pnb);
258*7c478bd9Sstevel@tonic-gate if (pte->netid) free(pte->netid);
259*7c478bd9Sstevel@tonic-gate
260*7c478bd9Sstevel@tonic-gate free(pte);
261*7c478bd9Sstevel@tonic-gate }
262*7c478bd9Sstevel@tonic-gate
263*7c478bd9Sstevel@tonic-gate /*
264*7c478bd9Sstevel@tonic-gate * nfslog_trans_file_free - frees a record
265*7c478bd9Sstevel@tonic-gate */
266*7c478bd9Sstevel@tonic-gate static void
nfslog_trans_file_free(struct nfslog_trans_file * transrec)267*7c478bd9Sstevel@tonic-gate nfslog_trans_file_free(struct nfslog_trans_file *transrec)
268*7c478bd9Sstevel@tonic-gate {
269*7c478bd9Sstevel@tonic-gate if (transrec == NULL)
270*7c478bd9Sstevel@tonic-gate return;
271*7c478bd9Sstevel@tonic-gate if (transrec->path != NULL) {
272*7c478bd9Sstevel@tonic-gate if (debug)
273*7c478bd9Sstevel@tonic-gate (void) printf("freeing transpath '%s'\n",
274*7c478bd9Sstevel@tonic-gate transrec->path);
275*7c478bd9Sstevel@tonic-gate free(transrec->path);
276*7c478bd9Sstevel@tonic-gate }
277*7c478bd9Sstevel@tonic-gate free(transrec);
278*7c478bd9Sstevel@tonic-gate }
279*7c478bd9Sstevel@tonic-gate
280*7c478bd9Sstevel@tonic-gate /*
281*7c478bd9Sstevel@tonic-gate * On success returns a pointer to the trans_file that matches
282*7c478bd9Sstevel@tonic-gate * 'path', 'output_type' and 'transtolog'. The reference count for this
283*7c478bd9Sstevel@tonic-gate * object is incremented as well.
284*7c478bd9Sstevel@tonic-gate * Returns NULL if it is not in the list.
285*7c478bd9Sstevel@tonic-gate */
286*7c478bd9Sstevel@tonic-gate static struct nfslog_trans_file *
nfslog_trans_file_find(char * path,uint32_t output_type,uint32_t transtolog)287*7c478bd9Sstevel@tonic-gate nfslog_trans_file_find(
288*7c478bd9Sstevel@tonic-gate char *path,
289*7c478bd9Sstevel@tonic-gate uint32_t output_type,
290*7c478bd9Sstevel@tonic-gate uint32_t transtolog)
291*7c478bd9Sstevel@tonic-gate {
292*7c478bd9Sstevel@tonic-gate struct nfslog_trans_file *tfp;
293*7c478bd9Sstevel@tonic-gate
294*7c478bd9Sstevel@tonic-gate for (tfp = trans_file_head; tfp != NULL; tfp = tfp->next) {
295*7c478bd9Sstevel@tonic-gate if ((strcmp(path, tfp->path) == 0) &&
296*7c478bd9Sstevel@tonic-gate (output_type == tfp->trans_output_type) &&
297*7c478bd9Sstevel@tonic-gate (transtolog == tfp->trans_to_log)) {
298*7c478bd9Sstevel@tonic-gate if (debug)
299*7c478bd9Sstevel@tonic-gate (void) printf("Found transfile '%s'\n", path);
300*7c478bd9Sstevel@tonic-gate (tfp->refcnt)++;
301*7c478bd9Sstevel@tonic-gate return (tfp);
302*7c478bd9Sstevel@tonic-gate }
303*7c478bd9Sstevel@tonic-gate }
304*7c478bd9Sstevel@tonic-gate return (NULL);
305*7c478bd9Sstevel@tonic-gate }
306*7c478bd9Sstevel@tonic-gate
307*7c478bd9Sstevel@tonic-gate
308*7c478bd9Sstevel@tonic-gate /*
309*7c478bd9Sstevel@tonic-gate * nfslog_close_trans_file - decrements the reference count on
310*7c478bd9Sstevel@tonic-gate * this object. On last reference it closes transfile and
311*7c478bd9Sstevel@tonic-gate * frees resources
312*7c478bd9Sstevel@tonic-gate */
313*7c478bd9Sstevel@tonic-gate static void
nfslog_close_trans_file(struct nfslog_trans_file * tf)314*7c478bd9Sstevel@tonic-gate nfslog_close_trans_file(struct nfslog_trans_file *tf)
315*7c478bd9Sstevel@tonic-gate {
316*7c478bd9Sstevel@tonic-gate assert(tf != NULL);
317*7c478bd9Sstevel@tonic-gate assert(tf->refcnt > 0);
318*7c478bd9Sstevel@tonic-gate if (tf->refcnt > 1) {
319*7c478bd9Sstevel@tonic-gate (tf->refcnt)--;
320*7c478bd9Sstevel@tonic-gate return;
321*7c478bd9Sstevel@tonic-gate }
322*7c478bd9Sstevel@tonic-gate
323*7c478bd9Sstevel@tonic-gate if (tf->fp != NULL) {
324*7c478bd9Sstevel@tonic-gate (void) fsync(fileno(tf->fp));
325*7c478bd9Sstevel@tonic-gate (void) fclose(tf->fp);
326*7c478bd9Sstevel@tonic-gate }
327*7c478bd9Sstevel@tonic-gate
328*7c478bd9Sstevel@tonic-gate /*
329*7c478bd9Sstevel@tonic-gate * Disconnect from list
330*7c478bd9Sstevel@tonic-gate */
331*7c478bd9Sstevel@tonic-gate tf->prev->next = tf->next;
332*7c478bd9Sstevel@tonic-gate if (tf->next != NULL)
333*7c478bd9Sstevel@tonic-gate tf->next->prev = tf->prev;
334*7c478bd9Sstevel@tonic-gate
335*7c478bd9Sstevel@tonic-gate /*
336*7c478bd9Sstevel@tonic-gate * Adjust the head of the list if appropriate
337*7c478bd9Sstevel@tonic-gate */
338*7c478bd9Sstevel@tonic-gate if (tf == trans_file_head)
339*7c478bd9Sstevel@tonic-gate trans_file_head = tf->next;
340*7c478bd9Sstevel@tonic-gate
341*7c478bd9Sstevel@tonic-gate nfslog_trans_file_free(tf);
342*7c478bd9Sstevel@tonic-gate }
343*7c478bd9Sstevel@tonic-gate
344*7c478bd9Sstevel@tonic-gate /*
345*7c478bd9Sstevel@tonic-gate * nfslog_open_trans_file - open the output trans file and mallocs.
346*7c478bd9Sstevel@tonic-gate * The object is then inserted at the beginning of the global
347*7c478bd9Sstevel@tonic-gate * transfile list.
348*7c478bd9Sstevel@tonic-gate * Returns 0 for success, error else.
349*7c478bd9Sstevel@tonic-gate *
350*7c478bd9Sstevel@tonic-gate * *error contains the last error encountered on this object. It can
351*7c478bd9Sstevel@tonic-gate * be used to avoid reporting the same error endlessly, by comparing
352*7c478bd9Sstevel@tonic-gate * the current error to the last error. It is reset to the current error
353*7c478bd9Sstevel@tonic-gate * code on return.
354*7c478bd9Sstevel@tonic-gate */
355*7c478bd9Sstevel@tonic-gate void *
nfslog_open_trans_file(char * transpath,uint32_t output_type,uint32_t transtolog,int * error)356*7c478bd9Sstevel@tonic-gate nfslog_open_trans_file(
357*7c478bd9Sstevel@tonic-gate char *transpath,
358*7c478bd9Sstevel@tonic-gate uint32_t output_type,
359*7c478bd9Sstevel@tonic-gate uint32_t transtolog,
360*7c478bd9Sstevel@tonic-gate int *error)
361*7c478bd9Sstevel@tonic-gate {
362*7c478bd9Sstevel@tonic-gate int preverror = *error;
363*7c478bd9Sstevel@tonic-gate struct nfslog_trans_file *transrec;
364*7c478bd9Sstevel@tonic-gate
365*7c478bd9Sstevel@tonic-gate transrec = nfslog_trans_file_find(transpath, output_type, transtolog);
366*7c478bd9Sstevel@tonic-gate if (transrec != NULL)
367*7c478bd9Sstevel@tonic-gate return (transrec);
368*7c478bd9Sstevel@tonic-gate
369*7c478bd9Sstevel@tonic-gate if ((transrec = malloc(sizeof (*transrec))) == NULL) {
370*7c478bd9Sstevel@tonic-gate *error = errno;
371*7c478bd9Sstevel@tonic-gate if (*error != preverror) {
372*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, gettext("nfslog_open_trans_file: %s"),
373*7c478bd9Sstevel@tonic-gate strerror(*error));
374*7c478bd9Sstevel@tonic-gate }
375*7c478bd9Sstevel@tonic-gate return (NULL);
376*7c478bd9Sstevel@tonic-gate }
377*7c478bd9Sstevel@tonic-gate bzero(transrec, sizeof (*transrec));
378*7c478bd9Sstevel@tonic-gate
379*7c478bd9Sstevel@tonic-gate if ((transrec->path = strdup(transpath)) == NULL) {
380*7c478bd9Sstevel@tonic-gate *error = errno;
381*7c478bd9Sstevel@tonic-gate if (*error != preverror) {
382*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, gettext("nfslog_open_trans_file: %s"),
383*7c478bd9Sstevel@tonic-gate strerror(*error));
384*7c478bd9Sstevel@tonic-gate }
385*7c478bd9Sstevel@tonic-gate nfslog_trans_file_free(transrec);
386*7c478bd9Sstevel@tonic-gate return (NULL);
387*7c478bd9Sstevel@tonic-gate }
388*7c478bd9Sstevel@tonic-gate
389*7c478bd9Sstevel@tonic-gate if ((transrec->fp = fopen(transpath, "a")) == NULL) {
390*7c478bd9Sstevel@tonic-gate *error = errno;
391*7c478bd9Sstevel@tonic-gate if (*error != preverror) {
392*7c478bd9Sstevel@tonic-gate syslog(LOG_ERR, gettext("Cannot open '%s': %s"),
393*7c478bd9Sstevel@tonic-gate transpath, strerror(*error));
394*7c478bd9Sstevel@tonic-gate }
395*7c478bd9Sstevel@tonic-gate nfslog_trans_file_free(transrec);
396*7c478bd9Sstevel@tonic-gate return (NULL);
397*7c478bd9Sstevel@tonic-gate }
398*7c478bd9Sstevel@tonic-gate
399*7c478bd9Sstevel@tonic-gate transrec->te_list_v3_read =
400*7c478bd9Sstevel@tonic-gate (struct transentry *)malloc(sizeof (struct transentry));
401*7c478bd9Sstevel@tonic-gate transrec->te_list_v3_write =
402*7c478bd9Sstevel@tonic-gate (struct transentry *)malloc(sizeof (struct transentry));
403*7c478bd9Sstevel@tonic-gate transrec->te_list_v2_read =
404*7c478bd9Sstevel@tonic-gate (struct transentry *)malloc(sizeof (struct transentry));
405*7c478bd9Sstevel@tonic-gate transrec->te_list_v2_write =
406*7c478bd9Sstevel@tonic-gate (struct transentry *)malloc(sizeof (struct transentry));
407*7c478bd9Sstevel@tonic-gate
408*7c478bd9Sstevel@tonic-gate if (transrec->te_list_v3_read == NULL ||
409*7c478bd9Sstevel@tonic-gate transrec->te_list_v3_write == NULL ||
410*7c478bd9Sstevel@tonic-gate transrec->te_list_v2_read == NULL ||
411*7c478bd9Sstevel@tonic-gate transrec->te_list_v2_write == NULL) {
412*7c478bd9Sstevel@tonic-gate if (transrec->te_list_v3_read)
413*7c478bd9Sstevel@tonic-gate free(transrec->te_list_v3_read);
414*7c478bd9Sstevel@tonic-gate if (transrec->te_list_v3_write)
415*7c478bd9Sstevel@tonic-gate free(transrec->te_list_v3_write);
416*7c478bd9Sstevel@tonic-gate if (transrec->te_list_v2_read)
417*7c478bd9Sstevel@tonic-gate free(transrec->te_list_v2_read);
418*7c478bd9Sstevel@tonic-gate if (transrec->te_list_v2_write)
419*7c478bd9Sstevel@tonic-gate free(transrec->te_list_v2_write);
420*7c478bd9Sstevel@tonic-gate nfslog_close_trans_file(transrec);
421*7c478bd9Sstevel@tonic-gate return (NULL);
422*7c478bd9Sstevel@tonic-gate }
423*7c478bd9Sstevel@tonic-gate
424*7c478bd9Sstevel@tonic-gate transrec->te_list_v3_read->next =
425*7c478bd9Sstevel@tonic-gate transrec->te_list_v3_read->prev = transrec->te_list_v3_read;
426*7c478bd9Sstevel@tonic-gate transrec->te_list_v3_write->next =
427*7c478bd9Sstevel@tonic-gate transrec->te_list_v3_write->prev = transrec->te_list_v3_write;
428*7c478bd9Sstevel@tonic-gate transrec->te_list_v2_read->next =
429*7c478bd9Sstevel@tonic-gate transrec->te_list_v2_read->prev = transrec->te_list_v2_read;
430*7c478bd9Sstevel@tonic-gate transrec->te_list_v2_write->next =
431*7c478bd9Sstevel@tonic-gate transrec->te_list_v2_write->prev = transrec->te_list_v2_write;
432*7c478bd9Sstevel@tonic-gate
433*7c478bd9Sstevel@tonic-gate /*
434*7c478bd9Sstevel@tonic-gate * Indicate what transaction types to log
435*7c478bd9Sstevel@tonic-gate */
436*7c478bd9Sstevel@tonic-gate transrec->trans_to_log = transtolog;
437*7c478bd9Sstevel@tonic-gate
438*7c478bd9Sstevel@tonic-gate /*
439*7c478bd9Sstevel@tonic-gate * Indicate whether to print 'full' or 'basic' version
440*7c478bd9Sstevel@tonic-gate * of the transactions
441*7c478bd9Sstevel@tonic-gate */
442*7c478bd9Sstevel@tonic-gate transrec->trans_output_type = output_type;
443*7c478bd9Sstevel@tonic-gate
444*7c478bd9Sstevel@tonic-gate /*
445*7c478bd9Sstevel@tonic-gate * Insert at the beginning of the list.
446*7c478bd9Sstevel@tonic-gate */
447*7c478bd9Sstevel@tonic-gate transrec->next = trans_file_head;
448*7c478bd9Sstevel@tonic-gate if (trans_file_head != NULL)
449*7c478bd9Sstevel@tonic-gate trans_file_head->prev = transrec;
450*7c478bd9Sstevel@tonic-gate trans_file_head = transrec->prev = transrec;
451*7c478bd9Sstevel@tonic-gate
452*7c478bd9Sstevel@tonic-gate transrec->refcnt = 1;
453*7c478bd9Sstevel@tonic-gate
454*7c478bd9Sstevel@tonic-gate transrec->lasttrans_timestamp.tv_sec = 0;
455*7c478bd9Sstevel@tonic-gate transrec->lasttrans_timestamp.tv_nsec = 0;
456*7c478bd9Sstevel@tonic-gate transrec->last_trans_read = time(0);
457*7c478bd9Sstevel@tonic-gate
458*7c478bd9Sstevel@tonic-gate if (debug)
459*7c478bd9Sstevel@tonic-gate (void) printf("New transfile '%s'\n", transrec->path);
460*7c478bd9Sstevel@tonic-gate
461*7c478bd9Sstevel@tonic-gate return (transrec);
462*7c478bd9Sstevel@tonic-gate }
463*7c478bd9Sstevel@tonic-gate
464*7c478bd9Sstevel@tonic-gate void
nfslog_process_trans_timeout(struct nfslog_trans_file * tf,uint32_t force_flush)465*7c478bd9Sstevel@tonic-gate nfslog_process_trans_timeout(
466*7c478bd9Sstevel@tonic-gate struct nfslog_trans_file *tf,
467*7c478bd9Sstevel@tonic-gate uint32_t force_flush)
468*7c478bd9Sstevel@tonic-gate {
469*7c478bd9Sstevel@tonic-gate struct transentry *pte;
470*7c478bd9Sstevel@tonic-gate time_t cur_time = time(0);
471*7c478bd9Sstevel@tonic-gate
472*7c478bd9Sstevel@tonic-gate /*
473*7c478bd9Sstevel@tonic-gate * If we have not seen a transaction on this file for
474*7c478bd9Sstevel@tonic-gate * a long time, then we need to flush everything out since
475*7c478bd9Sstevel@tonic-gate * we may not be getting anything else in for awhile.
476*7c478bd9Sstevel@tonic-gate */
477*7c478bd9Sstevel@tonic-gate if (difftime(cur_time, tf->last_trans_read) >
478*7c478bd9Sstevel@tonic-gate (2 * MAX(TRANS_ENTRY_TIMEOUT, idle_time)))
479*7c478bd9Sstevel@tonic-gate force_flush = TRUE;
480*7c478bd9Sstevel@tonic-gate
481*7c478bd9Sstevel@tonic-gate restart1:
482*7c478bd9Sstevel@tonic-gate for (pte = tf->te_list_v3_read->next;
483*7c478bd9Sstevel@tonic-gate pte != tf->te_list_v3_read;
484*7c478bd9Sstevel@tonic-gate pte = pte->next) {
485*7c478bd9Sstevel@tonic-gate if (force_flush == TRUE ||
486*7c478bd9Sstevel@tonic-gate (difftime(tf->lasttrans_timestamp.tv_sec,
487*7c478bd9Sstevel@tonic-gate pte->lastupdate.tv_sec) >
488*7c478bd9Sstevel@tonic-gate MAX(TRANS_ENTRY_TIMEOUT, idle_time))) {
489*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
490*7c478bd9Sstevel@tonic-gate remove_te(pte);
491*7c478bd9Sstevel@tonic-gate goto restart1;
492*7c478bd9Sstevel@tonic-gate }
493*7c478bd9Sstevel@tonic-gate }
494*7c478bd9Sstevel@tonic-gate restart2:
495*7c478bd9Sstevel@tonic-gate for (pte = tf->te_list_v3_write->next;
496*7c478bd9Sstevel@tonic-gate pte != tf->te_list_v3_write;
497*7c478bd9Sstevel@tonic-gate pte = pte->next) {
498*7c478bd9Sstevel@tonic-gate if (force_flush == TRUE ||
499*7c478bd9Sstevel@tonic-gate (difftime(tf->lasttrans_timestamp.tv_sec,
500*7c478bd9Sstevel@tonic-gate pte->lastupdate.tv_sec) >
501*7c478bd9Sstevel@tonic-gate MAX(TRANS_ENTRY_TIMEOUT, idle_time))) {
502*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
503*7c478bd9Sstevel@tonic-gate remove_te(pte);
504*7c478bd9Sstevel@tonic-gate goto restart2;
505*7c478bd9Sstevel@tonic-gate }
506*7c478bd9Sstevel@tonic-gate }
507*7c478bd9Sstevel@tonic-gate restart3:
508*7c478bd9Sstevel@tonic-gate for (pte = tf->te_list_v2_read->next;
509*7c478bd9Sstevel@tonic-gate pte != tf->te_list_v2_read;
510*7c478bd9Sstevel@tonic-gate pte = pte->next) {
511*7c478bd9Sstevel@tonic-gate if (force_flush == TRUE ||
512*7c478bd9Sstevel@tonic-gate (difftime(tf->lasttrans_timestamp.tv_sec,
513*7c478bd9Sstevel@tonic-gate pte->lastupdate.tv_sec) >
514*7c478bd9Sstevel@tonic-gate MAX(TRANS_ENTRY_TIMEOUT, idle_time))) {
515*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
516*7c478bd9Sstevel@tonic-gate remove_te(pte);
517*7c478bd9Sstevel@tonic-gate goto restart3;
518*7c478bd9Sstevel@tonic-gate }
519*7c478bd9Sstevel@tonic-gate }
520*7c478bd9Sstevel@tonic-gate restart4:
521*7c478bd9Sstevel@tonic-gate for (pte = tf->te_list_v2_write->next;
522*7c478bd9Sstevel@tonic-gate pte != tf->te_list_v2_write;
523*7c478bd9Sstevel@tonic-gate pte = pte->next) {
524*7c478bd9Sstevel@tonic-gate if (force_flush == TRUE ||
525*7c478bd9Sstevel@tonic-gate (difftime(tf->lasttrans_timestamp.tv_sec,
526*7c478bd9Sstevel@tonic-gate pte->lastupdate.tv_sec) >
527*7c478bd9Sstevel@tonic-gate MAX(TRANS_ENTRY_TIMEOUT, idle_time))) {
528*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
529*7c478bd9Sstevel@tonic-gate remove_te(pte);
530*7c478bd9Sstevel@tonic-gate goto restart4;
531*7c478bd9Sstevel@tonic-gate }
532*7c478bd9Sstevel@tonic-gate }
533*7c478bd9Sstevel@tonic-gate
534*7c478bd9Sstevel@tonic-gate (void) fflush(tf->fp);
535*7c478bd9Sstevel@tonic-gate }
536*7c478bd9Sstevel@tonic-gate
537*7c478bd9Sstevel@tonic-gate /*
538*7c478bd9Sstevel@tonic-gate * Flushes outstanding transactions to disk, and closes
539*7c478bd9Sstevel@tonic-gate * the transaction log.
540*7c478bd9Sstevel@tonic-gate */
541*7c478bd9Sstevel@tonic-gate void
nfslog_close_transactions(void ** transcookie)542*7c478bd9Sstevel@tonic-gate nfslog_close_transactions(void **transcookie)
543*7c478bd9Sstevel@tonic-gate {
544*7c478bd9Sstevel@tonic-gate assert(*transcookie != NULL);
545*7c478bd9Sstevel@tonic-gate nfslog_process_trans_timeout(
546*7c478bd9Sstevel@tonic-gate (struct nfslog_trans_file *)(*transcookie), TRUE);
547*7c478bd9Sstevel@tonic-gate nfslog_close_trans_file((struct nfslog_trans_file *)(*transcookie));
548*7c478bd9Sstevel@tonic-gate *transcookie = NULL;
549*7c478bd9Sstevel@tonic-gate }
550*7c478bd9Sstevel@tonic-gate
551*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_read(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1)552*7c478bd9Sstevel@tonic-gate trans_read(
553*7c478bd9Sstevel@tonic-gate nfslog_request_record *logrec,
554*7c478bd9Sstevel@tonic-gate struct nfslog_trans_file *tf,
555*7c478bd9Sstevel@tonic-gate char *fhpath,
556*7c478bd9Sstevel@tonic-gate char *path1)
557*7c478bd9Sstevel@tonic-gate {
558*7c478bd9Sstevel@tonic-gate struct transentry *newte;
559*7c478bd9Sstevel@tonic-gate struct transentry *pte = NULL;
560*7c478bd9Sstevel@tonic-gate /* LINTED */
561*7c478bd9Sstevel@tonic-gate nfslog_nfsreadargs *args = (nfslog_nfsreadargs *)logrec->re_rpc_arg;
562*7c478bd9Sstevel@tonic-gate /* LINTED */
563*7c478bd9Sstevel@tonic-gate nfslog_rdresult *res = (nfslog_rdresult *)logrec->re_rpc_res;
564*7c478bd9Sstevel@tonic-gate
565*7c478bd9Sstevel@tonic-gate if (res->r_status != NFS_OK)
566*7c478bd9Sstevel@tonic-gate return (NULL);
567*7c478bd9Sstevel@tonic-gate
568*7c478bd9Sstevel@tonic-gate if ((newte = create_te()) == NULL)
569*7c478bd9Sstevel@tonic-gate return (NULL);
570*7c478bd9Sstevel@tonic-gate
571*7c478bd9Sstevel@tonic-gate if (!path1) {
572*7c478bd9Sstevel@tonic-gate newte->pathname = nfslog_get_path(&args->ra_fhandle,
573*7c478bd9Sstevel@tonic-gate NULL, fhpath, "trans_read");
574*7c478bd9Sstevel@tonic-gate } else {
575*7c478bd9Sstevel@tonic-gate newte->pathname = strdup(path1);
576*7c478bd9Sstevel@tonic-gate }
577*7c478bd9Sstevel@tonic-gate
578*7c478bd9Sstevel@tonic-gate /* prep the struct for insertion */
579*7c478bd9Sstevel@tonic-gate newte->starttime = logrec->re_header.rh_timestamp;
580*7c478bd9Sstevel@tonic-gate newte->lastupdate = logrec->re_header.rh_timestamp;
581*7c478bd9Sstevel@tonic-gate newte->optype = TRANS_OPER_READ;
582*7c478bd9Sstevel@tonic-gate newte->datatype = TRANS_DATATYPE_BINARY;
583*7c478bd9Sstevel@tonic-gate newte->transoption = TRANS_OPTION_NOACTION;
584*7c478bd9Sstevel@tonic-gate newte->pnb = netbufdup(&(logrec->re_ipaddr));
585*7c478bd9Sstevel@tonic-gate newte->uid = logrec->re_header.rh_uid;
586*7c478bd9Sstevel@tonic-gate newte->nfsvers = NFS_VERSION;
587*7c478bd9Sstevel@tonic-gate newte->netid = strdup(logrec->re_netid);
588*7c478bd9Sstevel@tonic-gate if (logrec->re_principal_name)
589*7c478bd9Sstevel@tonic-gate newte->principal_name = strdup(logrec->re_principal_name);
590*7c478bd9Sstevel@tonic-gate else
591*7c478bd9Sstevel@tonic-gate newte->principal_name = NULL;
592*7c478bd9Sstevel@tonic-gate newte->totalbytes = res->nfslog_rdresult_u.r_ok.rrok_count;
593*7c478bd9Sstevel@tonic-gate newte->fh_u.fh = *(NFSLOG_GET_FHANDLE2(&args->ra_fhandle));
594*7c478bd9Sstevel@tonic-gate
595*7c478bd9Sstevel@tonic-gate if (res->nfslog_rdresult_u.r_ok.rrok_count <
596*7c478bd9Sstevel@tonic-gate res->nfslog_rdresult_u.r_ok.filesize) {
597*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v2_read, newte)) {
598*7c478bd9Sstevel@tonic-gate /* free this since entry was found (not inserted) */
599*7c478bd9Sstevel@tonic-gate remove_te(newte);
600*7c478bd9Sstevel@tonic-gate
601*7c478bd9Sstevel@tonic-gate pte->totalbytes +=
602*7c478bd9Sstevel@tonic-gate res->nfslog_rdresult_u.r_ok.rrok_count;
603*7c478bd9Sstevel@tonic-gate
604*7c478bd9Sstevel@tonic-gate if (pte->lastupdate.tv_sec <=
605*7c478bd9Sstevel@tonic-gate logrec->re_header.rh_timestamp.tv_sec)
606*7c478bd9Sstevel@tonic-gate pte->lastupdate =
607*7c478bd9Sstevel@tonic-gate logrec->re_header.rh_timestamp;
608*7c478bd9Sstevel@tonic-gate
609*7c478bd9Sstevel@tonic-gate if (pte->totalbytes <
610*7c478bd9Sstevel@tonic-gate res->nfslog_rdresult_u.r_ok.filesize) {
611*7c478bd9Sstevel@tonic-gate pte = NULL; /* prevent printing of log entry */
612*7c478bd9Sstevel@tonic-gate }
613*7c478bd9Sstevel@tonic-gate }
614*7c478bd9Sstevel@tonic-gate } else {
615*7c478bd9Sstevel@tonic-gate pte = newte; /* print a log record - complete file read */
616*7c478bd9Sstevel@tonic-gate }
617*7c478bd9Sstevel@tonic-gate
618*7c478bd9Sstevel@tonic-gate return (pte);
619*7c478bd9Sstevel@tonic-gate }
620*7c478bd9Sstevel@tonic-gate
621*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_write(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1)622*7c478bd9Sstevel@tonic-gate trans_write(
623*7c478bd9Sstevel@tonic-gate nfslog_request_record *logrec,
624*7c478bd9Sstevel@tonic-gate struct nfslog_trans_file *tf,
625*7c478bd9Sstevel@tonic-gate char *fhpath,
626*7c478bd9Sstevel@tonic-gate char *path1)
627*7c478bd9Sstevel@tonic-gate {
628*7c478bd9Sstevel@tonic-gate struct transentry *newte;
629*7c478bd9Sstevel@tonic-gate struct transentry *pte = NULL;
630*7c478bd9Sstevel@tonic-gate /* LINTED */
631*7c478bd9Sstevel@tonic-gate nfslog_writeargs *args = (nfslog_writeargs *)logrec->re_rpc_arg;
632*7c478bd9Sstevel@tonic-gate /* LINTED */
633*7c478bd9Sstevel@tonic-gate nfslog_writeresult *res = (nfslog_writeresult *)logrec->re_rpc_res;
634*7c478bd9Sstevel@tonic-gate
635*7c478bd9Sstevel@tonic-gate if (res->wr_status != NFS_OK)
636*7c478bd9Sstevel@tonic-gate return (NULL);
637*7c478bd9Sstevel@tonic-gate
638*7c478bd9Sstevel@tonic-gate if ((newte = create_te()) == NULL)
639*7c478bd9Sstevel@tonic-gate return (NULL);
640*7c478bd9Sstevel@tonic-gate
641*7c478bd9Sstevel@tonic-gate if (!path1) {
642*7c478bd9Sstevel@tonic-gate newte->pathname = nfslog_get_path(&args->waargs_fhandle,
643*7c478bd9Sstevel@tonic-gate NULL, fhpath, "trans_write");
644*7c478bd9Sstevel@tonic-gate } else {
645*7c478bd9Sstevel@tonic-gate newte->pathname = strdup(path1);
646*7c478bd9Sstevel@tonic-gate }
647*7c478bd9Sstevel@tonic-gate
648*7c478bd9Sstevel@tonic-gate newte->starttime = logrec->re_header.rh_timestamp;
649*7c478bd9Sstevel@tonic-gate newte->lastupdate = logrec->re_header.rh_timestamp;
650*7c478bd9Sstevel@tonic-gate newte->optype = TRANS_OPER_WRITE;
651*7c478bd9Sstevel@tonic-gate newte->datatype = TRANS_DATATYPE_BINARY;
652*7c478bd9Sstevel@tonic-gate newte->transoption = TRANS_OPTION_NOACTION;
653*7c478bd9Sstevel@tonic-gate newte->pnb = netbufdup(&(logrec->re_ipaddr));
654*7c478bd9Sstevel@tonic-gate newte->uid = logrec->re_header.rh_uid;
655*7c478bd9Sstevel@tonic-gate newte->nfsvers = NFS_VERSION;
656*7c478bd9Sstevel@tonic-gate newte->netid = strdup(logrec->re_netid);
657*7c478bd9Sstevel@tonic-gate if (logrec->re_principal_name)
658*7c478bd9Sstevel@tonic-gate newte->principal_name = strdup(logrec->re_principal_name);
659*7c478bd9Sstevel@tonic-gate else
660*7c478bd9Sstevel@tonic-gate newte->principal_name = NULL;
661*7c478bd9Sstevel@tonic-gate newte->totalbytes = args->waargs_totcount;
662*7c478bd9Sstevel@tonic-gate newte->fh_u.fh = *(NFSLOG_GET_FHANDLE2(&args->waargs_fhandle));
663*7c478bd9Sstevel@tonic-gate
664*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v2_write, newte)) {
665*7c478bd9Sstevel@tonic-gate /*
666*7c478bd9Sstevel@tonic-gate * if the write would have increased the total byte count
667*7c478bd9Sstevel@tonic-gate * over the filesize, then generate a log entry and remove
668*7c478bd9Sstevel@tonic-gate * the write record and insert the new one.
669*7c478bd9Sstevel@tonic-gate */
670*7c478bd9Sstevel@tonic-gate if (pte->totalbytes + args->waargs_totcount >
671*7c478bd9Sstevel@tonic-gate res->nfslog_writeresult_u.wr_size) {
672*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
673*7c478bd9Sstevel@tonic-gate remove_te(pte);
674*7c478bd9Sstevel@tonic-gate (void) insert_te(tf->te_list_v2_write, newte);
675*7c478bd9Sstevel@tonic-gate pte = NULL;
676*7c478bd9Sstevel@tonic-gate } else {
677*7c478bd9Sstevel@tonic-gate /* free this since entry was found (not inserted) */
678*7c478bd9Sstevel@tonic-gate remove_te(newte);
679*7c478bd9Sstevel@tonic-gate
680*7c478bd9Sstevel@tonic-gate pte->totalbytes += args->waargs_totcount;
681*7c478bd9Sstevel@tonic-gate
682*7c478bd9Sstevel@tonic-gate if (pte->lastupdate.tv_sec <=
683*7c478bd9Sstevel@tonic-gate logrec->re_header.rh_timestamp.tv_sec) {
684*7c478bd9Sstevel@tonic-gate pte->lastupdate =
685*7c478bd9Sstevel@tonic-gate logrec->re_header.rh_timestamp;
686*7c478bd9Sstevel@tonic-gate }
687*7c478bd9Sstevel@tonic-gate pte = NULL; /* prevent printing of log entry */
688*7c478bd9Sstevel@tonic-gate }
689*7c478bd9Sstevel@tonic-gate }
690*7c478bd9Sstevel@tonic-gate return (pte);
691*7c478bd9Sstevel@tonic-gate }
692*7c478bd9Sstevel@tonic-gate
693*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_setattr(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1)694*7c478bd9Sstevel@tonic-gate trans_setattr(
695*7c478bd9Sstevel@tonic-gate nfslog_request_record *logrec,
696*7c478bd9Sstevel@tonic-gate struct nfslog_trans_file *tf,
697*7c478bd9Sstevel@tonic-gate char *fhpath,
698*7c478bd9Sstevel@tonic-gate char *path1)
699*7c478bd9Sstevel@tonic-gate {
700*7c478bd9Sstevel@tonic-gate struct transentry *newte;
701*7c478bd9Sstevel@tonic-gate struct transentry *pte = NULL;
702*7c478bd9Sstevel@tonic-gate /* LINTED */
703*7c478bd9Sstevel@tonic-gate nfslog_setattrargs *args = (nfslog_setattrargs *)logrec->re_rpc_arg;
704*7c478bd9Sstevel@tonic-gate /* LINTED */
705*7c478bd9Sstevel@tonic-gate nfsstat *res = (nfsstat *)logrec->re_rpc_res;
706*7c478bd9Sstevel@tonic-gate
707*7c478bd9Sstevel@tonic-gate if (*res != NFS_OK)
708*7c478bd9Sstevel@tonic-gate return (NULL);
709*7c478bd9Sstevel@tonic-gate
710*7c478bd9Sstevel@tonic-gate if (args->saa_sa.sa_size == (uint32_t)-1)
711*7c478bd9Sstevel@tonic-gate return (NULL);
712*7c478bd9Sstevel@tonic-gate /*
713*7c478bd9Sstevel@tonic-gate * should check the size of the file to see if it
714*7c478bd9Sstevel@tonic-gate * is being truncated below current eof. if so
715*7c478bd9Sstevel@tonic-gate * a record should be generated.... XXX
716*7c478bd9Sstevel@tonic-gate */
717*7c478bd9Sstevel@tonic-gate if (args->saa_sa.sa_size != 0)
718*7c478bd9Sstevel@tonic-gate return (NULL);
719*7c478bd9Sstevel@tonic-gate
720*7c478bd9Sstevel@tonic-gate if ((newte = create_te()) == NULL)
721*7c478bd9Sstevel@tonic-gate return (NULL);
722*7c478bd9Sstevel@tonic-gate
723*7c478bd9Sstevel@tonic-gate if (!path1) {
724*7c478bd9Sstevel@tonic-gate newte->pathname = nfslog_get_path(&args->saa_fh, NULL,
725*7c478bd9Sstevel@tonic-gate fhpath, "trans_setattr2");
726*7c478bd9Sstevel@tonic-gate } else {
727*7c478bd9Sstevel@tonic-gate newte->pathname = strdup(path1);
728*7c478bd9Sstevel@tonic-gate }
729*7c478bd9Sstevel@tonic-gate
730*7c478bd9Sstevel@tonic-gate newte->starttime = logrec->re_header.rh_timestamp;
731*7c478bd9Sstevel@tonic-gate newte->lastupdate = logrec->re_header.rh_timestamp;
732*7c478bd9Sstevel@tonic-gate newte->optype = TRANS_OPER_SETATTR;
733*7c478bd9Sstevel@tonic-gate newte->datatype = TRANS_DATATYPE_BINARY;
734*7c478bd9Sstevel@tonic-gate newte->transoption = TRANS_OPTION_NOACTION;
735*7c478bd9Sstevel@tonic-gate newte->pnb = netbufdup(&(logrec->re_ipaddr));
736*7c478bd9Sstevel@tonic-gate newte->uid = logrec->re_header.rh_uid;
737*7c478bd9Sstevel@tonic-gate newte->nfsvers = NFS_VERSION;
738*7c478bd9Sstevel@tonic-gate newte->netid = strdup(logrec->re_netid);
739*7c478bd9Sstevel@tonic-gate if (logrec->re_principal_name)
740*7c478bd9Sstevel@tonic-gate newte->principal_name = strdup(logrec->re_principal_name);
741*7c478bd9Sstevel@tonic-gate else
742*7c478bd9Sstevel@tonic-gate newte->principal_name = NULL;
743*7c478bd9Sstevel@tonic-gate newte->totalbytes = 0;
744*7c478bd9Sstevel@tonic-gate newte->fh_u.fh = *(NFSLOG_GET_FHANDLE2(&args->saa_fh));
745*7c478bd9Sstevel@tonic-gate
746*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v2_write, newte)) {
747*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
748*7c478bd9Sstevel@tonic-gate remove_te(pte);
749*7c478bd9Sstevel@tonic-gate }
750*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v2_read, newte)) {
751*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
752*7c478bd9Sstevel@tonic-gate remove_te(pte);
753*7c478bd9Sstevel@tonic-gate }
754*7c478bd9Sstevel@tonic-gate
755*7c478bd9Sstevel@tonic-gate return (newte);
756*7c478bd9Sstevel@tonic-gate }
757*7c478bd9Sstevel@tonic-gate
758*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_create(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1)759*7c478bd9Sstevel@tonic-gate trans_create(
760*7c478bd9Sstevel@tonic-gate nfslog_request_record *logrec,
761*7c478bd9Sstevel@tonic-gate struct nfslog_trans_file *tf,
762*7c478bd9Sstevel@tonic-gate char *fhpath,
763*7c478bd9Sstevel@tonic-gate char *path1)
764*7c478bd9Sstevel@tonic-gate {
765*7c478bd9Sstevel@tonic-gate struct transentry *newte;
766*7c478bd9Sstevel@tonic-gate struct transentry *pte = NULL;
767*7c478bd9Sstevel@tonic-gate /* LINTED */
768*7c478bd9Sstevel@tonic-gate nfslog_createargs *args = (nfslog_createargs *)logrec->re_rpc_arg;
769*7c478bd9Sstevel@tonic-gate /* LINTED */
770*7c478bd9Sstevel@tonic-gate nfslog_diropres *res = (nfslog_diropres *)logrec->re_rpc_res;
771*7c478bd9Sstevel@tonic-gate
772*7c478bd9Sstevel@tonic-gate if (res->dr_status != NFS_OK)
773*7c478bd9Sstevel@tonic-gate return (NULL);
774*7c478bd9Sstevel@tonic-gate
775*7c478bd9Sstevel@tonic-gate if ((newte = create_te()) == NULL)
776*7c478bd9Sstevel@tonic-gate return (NULL);
777*7c478bd9Sstevel@tonic-gate
778*7c478bd9Sstevel@tonic-gate if (!path1) {
779*7c478bd9Sstevel@tonic-gate newte->pathname =
780*7c478bd9Sstevel@tonic-gate nfslog_get_path(&args->ca_da.da_fhandle,
781*7c478bd9Sstevel@tonic-gate args->ca_da.da_name,
782*7c478bd9Sstevel@tonic-gate fhpath, "trans_create2");
783*7c478bd9Sstevel@tonic-gate } else {
784*7c478bd9Sstevel@tonic-gate newte->pathname = strdup(path1);
785*7c478bd9Sstevel@tonic-gate }
786*7c478bd9Sstevel@tonic-gate
787*7c478bd9Sstevel@tonic-gate newte->starttime = logrec->re_header.rh_timestamp;
788*7c478bd9Sstevel@tonic-gate newte->lastupdate = logrec->re_header.rh_timestamp;
789*7c478bd9Sstevel@tonic-gate newte->optype = TRANS_OPER_CREATE;
790*7c478bd9Sstevel@tonic-gate newte->datatype = TRANS_DATATYPE_BINARY;
791*7c478bd9Sstevel@tonic-gate newte->transoption = TRANS_OPTION_NOACTION;
792*7c478bd9Sstevel@tonic-gate newte->pnb = netbufdup(&(logrec->re_ipaddr));
793*7c478bd9Sstevel@tonic-gate newte->uid = logrec->re_header.rh_uid;
794*7c478bd9Sstevel@tonic-gate newte->nfsvers = NFS_VERSION;
795*7c478bd9Sstevel@tonic-gate newte->netid = strdup(logrec->re_netid);
796*7c478bd9Sstevel@tonic-gate if (logrec->re_principal_name)
797*7c478bd9Sstevel@tonic-gate newte->principal_name = strdup(logrec->re_principal_name);
798*7c478bd9Sstevel@tonic-gate else
799*7c478bd9Sstevel@tonic-gate newte->principal_name = NULL;
800*7c478bd9Sstevel@tonic-gate
801*7c478bd9Sstevel@tonic-gate if (args->ca_sa.sa_size == (uint32_t)-1)
802*7c478bd9Sstevel@tonic-gate newte->totalbytes = 0;
803*7c478bd9Sstevel@tonic-gate else
804*7c478bd9Sstevel@tonic-gate newte->totalbytes = args->ca_sa.sa_size;
805*7c478bd9Sstevel@tonic-gate
806*7c478bd9Sstevel@tonic-gate newte->fh_u.fh = *(NFSLOG_GET_FHANDLE2(
807*7c478bd9Sstevel@tonic-gate &res->nfslog_diropres_u.dr_ok.drok_fhandle));
808*7c478bd9Sstevel@tonic-gate
809*7c478bd9Sstevel@tonic-gate /*
810*7c478bd9Sstevel@tonic-gate * if the file is being truncated on create, we need to flush
811*7c478bd9Sstevel@tonic-gate * any outstanding read/write transactions
812*7c478bd9Sstevel@tonic-gate */
813*7c478bd9Sstevel@tonic-gate if (args->ca_sa.sa_size != (uint32_t)-1) {
814*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v2_write, newte)) {
815*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
816*7c478bd9Sstevel@tonic-gate remove_te(pte);
817*7c478bd9Sstevel@tonic-gate }
818*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v2_read, newte)) {
819*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
820*7c478bd9Sstevel@tonic-gate remove_te(pte);
821*7c478bd9Sstevel@tonic-gate }
822*7c478bd9Sstevel@tonic-gate }
823*7c478bd9Sstevel@tonic-gate
824*7c478bd9Sstevel@tonic-gate return (newte);
825*7c478bd9Sstevel@tonic-gate }
826*7c478bd9Sstevel@tonic-gate
827*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_remove(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1)828*7c478bd9Sstevel@tonic-gate trans_remove(
829*7c478bd9Sstevel@tonic-gate nfslog_request_record *logrec,
830*7c478bd9Sstevel@tonic-gate struct nfslog_trans_file *tf,
831*7c478bd9Sstevel@tonic-gate char *fhpath,
832*7c478bd9Sstevel@tonic-gate char *path1)
833*7c478bd9Sstevel@tonic-gate {
834*7c478bd9Sstevel@tonic-gate struct transentry *newte;
835*7c478bd9Sstevel@tonic-gate struct transentry *pte = NULL;
836*7c478bd9Sstevel@tonic-gate /* LINTED */
837*7c478bd9Sstevel@tonic-gate nfslog_diropargs *args = (nfslog_diropargs *)logrec->re_rpc_arg;
838*7c478bd9Sstevel@tonic-gate /* LINTED */
839*7c478bd9Sstevel@tonic-gate nfsstat *res = (nfsstat *)logrec->re_rpc_res;
840*7c478bd9Sstevel@tonic-gate
841*7c478bd9Sstevel@tonic-gate if (*res != NFS_OK)
842*7c478bd9Sstevel@tonic-gate return (NULL);
843*7c478bd9Sstevel@tonic-gate
844*7c478bd9Sstevel@tonic-gate if ((newte = create_te()) == NULL)
845*7c478bd9Sstevel@tonic-gate return (NULL);
846*7c478bd9Sstevel@tonic-gate
847*7c478bd9Sstevel@tonic-gate if (!path1) {
848*7c478bd9Sstevel@tonic-gate char *name = args->da_name;
849*7c478bd9Sstevel@tonic-gate fhandle_t *dfh = &args->da_fhandle;
850*7c478bd9Sstevel@tonic-gate newte->pathname = nfslog_get_path(dfh, name,
851*7c478bd9Sstevel@tonic-gate fhpath, "trans_remove2");
852*7c478bd9Sstevel@tonic-gate } else {
853*7c478bd9Sstevel@tonic-gate newte->pathname = strdup(path1);
854*7c478bd9Sstevel@tonic-gate }
855*7c478bd9Sstevel@tonic-gate
856*7c478bd9Sstevel@tonic-gate newte->starttime = logrec->re_header.rh_timestamp;
857*7c478bd9Sstevel@tonic-gate newte->lastupdate = logrec->re_header.rh_timestamp;
858*7c478bd9Sstevel@tonic-gate newte->optype = TRANS_OPER_REMOVE;
859*7c478bd9Sstevel@tonic-gate newte->datatype = TRANS_DATATYPE_BINARY;
860*7c478bd9Sstevel@tonic-gate newte->transoption = TRANS_OPTION_NOACTION;
861*7c478bd9Sstevel@tonic-gate newte->pnb = netbufdup(&(logrec->re_ipaddr));
862*7c478bd9Sstevel@tonic-gate newte->uid = logrec->re_header.rh_uid;
863*7c478bd9Sstevel@tonic-gate newte->nfsvers = NFS_VERSION;
864*7c478bd9Sstevel@tonic-gate newte->netid = strdup(logrec->re_netid);
865*7c478bd9Sstevel@tonic-gate if (logrec->re_principal_name)
866*7c478bd9Sstevel@tonic-gate newte->principal_name = strdup(logrec->re_principal_name);
867*7c478bd9Sstevel@tonic-gate else
868*7c478bd9Sstevel@tonic-gate newte->principal_name = NULL;
869*7c478bd9Sstevel@tonic-gate newte->totalbytes = 0;
870*7c478bd9Sstevel@tonic-gate newte->fh_u.fh = *(NFSLOG_GET_FHANDLE2(&args->da_fhandle));
871*7c478bd9Sstevel@tonic-gate
872*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v2_write, newte)) {
873*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
874*7c478bd9Sstevel@tonic-gate remove_te(pte);
875*7c478bd9Sstevel@tonic-gate }
876*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v2_read, newte)) {
877*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
878*7c478bd9Sstevel@tonic-gate remove_te(pte);
879*7c478bd9Sstevel@tonic-gate }
880*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v3_write, newte)) {
881*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
882*7c478bd9Sstevel@tonic-gate remove_te(pte);
883*7c478bd9Sstevel@tonic-gate }
884*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v3_read, newte)) {
885*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
886*7c478bd9Sstevel@tonic-gate remove_te(pte);
887*7c478bd9Sstevel@tonic-gate }
888*7c478bd9Sstevel@tonic-gate
889*7c478bd9Sstevel@tonic-gate return (newte);
890*7c478bd9Sstevel@tonic-gate }
891*7c478bd9Sstevel@tonic-gate
892*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_mkdir(nfslog_request_record * logrec,char * fhpath,char * path1)893*7c478bd9Sstevel@tonic-gate trans_mkdir(
894*7c478bd9Sstevel@tonic-gate nfslog_request_record *logrec,
895*7c478bd9Sstevel@tonic-gate char *fhpath,
896*7c478bd9Sstevel@tonic-gate char *path1)
897*7c478bd9Sstevel@tonic-gate {
898*7c478bd9Sstevel@tonic-gate struct transentry *newte;
899*7c478bd9Sstevel@tonic-gate /* LINTED */
900*7c478bd9Sstevel@tonic-gate nfslog_createargs *args = (nfslog_createargs *)logrec->re_rpc_arg;
901*7c478bd9Sstevel@tonic-gate /* LINTED */
902*7c478bd9Sstevel@tonic-gate nfslog_diropres *res = (nfslog_diropres *)logrec->re_rpc_res;
903*7c478bd9Sstevel@tonic-gate
904*7c478bd9Sstevel@tonic-gate if (res->dr_status != NFS_OK)
905*7c478bd9Sstevel@tonic-gate return (NULL);
906*7c478bd9Sstevel@tonic-gate
907*7c478bd9Sstevel@tonic-gate if ((newte = create_te()) == NULL)
908*7c478bd9Sstevel@tonic-gate return (NULL);
909*7c478bd9Sstevel@tonic-gate
910*7c478bd9Sstevel@tonic-gate if (!path1) {
911*7c478bd9Sstevel@tonic-gate nfslog_diropargs *dargs = &args->ca_da;
912*7c478bd9Sstevel@tonic-gate char *name = dargs->da_name;
913*7c478bd9Sstevel@tonic-gate fhandle_t *dfh = &dargs->da_fhandle;
914*7c478bd9Sstevel@tonic-gate newte->pathname = nfslog_get_path(dfh, name,
915*7c478bd9Sstevel@tonic-gate fhpath, "trans_mkdir2");
916*7c478bd9Sstevel@tonic-gate } else {
917*7c478bd9Sstevel@tonic-gate newte->pathname = strdup(path1);
918*7c478bd9Sstevel@tonic-gate }
919*7c478bd9Sstevel@tonic-gate
920*7c478bd9Sstevel@tonic-gate newte->starttime = logrec->re_header.rh_timestamp;
921*7c478bd9Sstevel@tonic-gate newte->lastupdate = logrec->re_header.rh_timestamp;
922*7c478bd9Sstevel@tonic-gate newte->optype = TRANS_OPER_MKDIR;
923*7c478bd9Sstevel@tonic-gate newte->datatype = TRANS_DATATYPE_BINARY;
924*7c478bd9Sstevel@tonic-gate newte->transoption = TRANS_OPTION_NOACTION;
925*7c478bd9Sstevel@tonic-gate newte->pnb = netbufdup(&(logrec->re_ipaddr));
926*7c478bd9Sstevel@tonic-gate newte->uid = logrec->re_header.rh_uid;
927*7c478bd9Sstevel@tonic-gate newte->nfsvers = NFS_VERSION;
928*7c478bd9Sstevel@tonic-gate newte->netid = strdup(logrec->re_netid);
929*7c478bd9Sstevel@tonic-gate if (logrec->re_principal_name)
930*7c478bd9Sstevel@tonic-gate newte->principal_name = strdup(logrec->re_principal_name);
931*7c478bd9Sstevel@tonic-gate else
932*7c478bd9Sstevel@tonic-gate newte->principal_name = NULL;
933*7c478bd9Sstevel@tonic-gate newte->totalbytes = 0;
934*7c478bd9Sstevel@tonic-gate newte->fh_u.fh = *(NFSLOG_GET_FHANDLE2(&args->ca_da.da_fhandle));
935*7c478bd9Sstevel@tonic-gate
936*7c478bd9Sstevel@tonic-gate return (newte);
937*7c478bd9Sstevel@tonic-gate }
938*7c478bd9Sstevel@tonic-gate
939*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_rmdir(nfslog_request_record * logrec,char * fhpath,char * path1)940*7c478bd9Sstevel@tonic-gate trans_rmdir(
941*7c478bd9Sstevel@tonic-gate nfslog_request_record *logrec,
942*7c478bd9Sstevel@tonic-gate char *fhpath,
943*7c478bd9Sstevel@tonic-gate char *path1)
944*7c478bd9Sstevel@tonic-gate {
945*7c478bd9Sstevel@tonic-gate struct transentry *newte;
946*7c478bd9Sstevel@tonic-gate /* LINTED */
947*7c478bd9Sstevel@tonic-gate nfslog_diropargs *args = (nfslog_diropargs *)logrec->re_rpc_arg;
948*7c478bd9Sstevel@tonic-gate /* LINTED */
949*7c478bd9Sstevel@tonic-gate nfsstat *res = (nfsstat *)logrec->re_rpc_res;
950*7c478bd9Sstevel@tonic-gate
951*7c478bd9Sstevel@tonic-gate if (*res != NFS_OK)
952*7c478bd9Sstevel@tonic-gate return (NULL);
953*7c478bd9Sstevel@tonic-gate
954*7c478bd9Sstevel@tonic-gate if ((newte = create_te()) == NULL)
955*7c478bd9Sstevel@tonic-gate return (NULL);
956*7c478bd9Sstevel@tonic-gate
957*7c478bd9Sstevel@tonic-gate if (!path1) {
958*7c478bd9Sstevel@tonic-gate char *name = args->da_name;
959*7c478bd9Sstevel@tonic-gate fhandle_t *dfh = &args->da_fhandle;
960*7c478bd9Sstevel@tonic-gate newte->pathname = nfslog_get_path(dfh, name,
961*7c478bd9Sstevel@tonic-gate fhpath, "trans_rmdir2");
962*7c478bd9Sstevel@tonic-gate } else {
963*7c478bd9Sstevel@tonic-gate newte->pathname = strdup(path1);
964*7c478bd9Sstevel@tonic-gate }
965*7c478bd9Sstevel@tonic-gate
966*7c478bd9Sstevel@tonic-gate newte->starttime = logrec->re_header.rh_timestamp;
967*7c478bd9Sstevel@tonic-gate newte->lastupdate = logrec->re_header.rh_timestamp;
968*7c478bd9Sstevel@tonic-gate newte->optype = TRANS_OPER_RMDIR;
969*7c478bd9Sstevel@tonic-gate newte->datatype = TRANS_DATATYPE_BINARY;
970*7c478bd9Sstevel@tonic-gate newte->transoption = TRANS_OPTION_NOACTION;
971*7c478bd9Sstevel@tonic-gate newte->pnb = netbufdup(&(logrec->re_ipaddr));
972*7c478bd9Sstevel@tonic-gate newte->uid = logrec->re_header.rh_uid;
973*7c478bd9Sstevel@tonic-gate newte->nfsvers = NFS_VERSION;
974*7c478bd9Sstevel@tonic-gate newte->netid = strdup(logrec->re_netid);
975*7c478bd9Sstevel@tonic-gate if (logrec->re_principal_name)
976*7c478bd9Sstevel@tonic-gate newte->principal_name = strdup(logrec->re_principal_name);
977*7c478bd9Sstevel@tonic-gate else
978*7c478bd9Sstevel@tonic-gate newte->principal_name = NULL;
979*7c478bd9Sstevel@tonic-gate newte->totalbytes = 0;
980*7c478bd9Sstevel@tonic-gate newte->fh_u.fh = *(NFSLOG_GET_FHANDLE2(&args->da_fhandle));
981*7c478bd9Sstevel@tonic-gate
982*7c478bd9Sstevel@tonic-gate return (newte);
983*7c478bd9Sstevel@tonic-gate }
984*7c478bd9Sstevel@tonic-gate
985*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_rename(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1,char * path2)986*7c478bd9Sstevel@tonic-gate trans_rename(
987*7c478bd9Sstevel@tonic-gate nfslog_request_record *logrec,
988*7c478bd9Sstevel@tonic-gate struct nfslog_trans_file *tf,
989*7c478bd9Sstevel@tonic-gate char *fhpath,
990*7c478bd9Sstevel@tonic-gate char *path1,
991*7c478bd9Sstevel@tonic-gate char *path2)
992*7c478bd9Sstevel@tonic-gate {
993*7c478bd9Sstevel@tonic-gate struct transentry *newte;
994*7c478bd9Sstevel@tonic-gate struct transentry *pte = NULL;
995*7c478bd9Sstevel@tonic-gate /* LINTED */
996*7c478bd9Sstevel@tonic-gate nfslog_rnmargs *args = (nfslog_rnmargs *)logrec->re_rpc_arg;
997*7c478bd9Sstevel@tonic-gate /* LINTED */
998*7c478bd9Sstevel@tonic-gate nfsstat *res = (nfsstat *)logrec->re_rpc_res;
999*7c478bd9Sstevel@tonic-gate char *tpath1 = NULL;
1000*7c478bd9Sstevel@tonic-gate char *tpath2 = NULL;
1001*7c478bd9Sstevel@tonic-gate
1002*7c478bd9Sstevel@tonic-gate if (*res != NFS_OK)
1003*7c478bd9Sstevel@tonic-gate return (NULL);
1004*7c478bd9Sstevel@tonic-gate
1005*7c478bd9Sstevel@tonic-gate if ((newte = create_te()) == NULL)
1006*7c478bd9Sstevel@tonic-gate return (NULL);
1007*7c478bd9Sstevel@tonic-gate
1008*7c478bd9Sstevel@tonic-gate if (!path1) {
1009*7c478bd9Sstevel@tonic-gate char *from_name, *to_name;
1010*7c478bd9Sstevel@tonic-gate fhandle_t *from_dfh, *to_dfh;
1011*7c478bd9Sstevel@tonic-gate
1012*7c478bd9Sstevel@tonic-gate from_name = args->rna_from.da_name;
1013*7c478bd9Sstevel@tonic-gate from_dfh = &args->rna_from.da_fhandle;
1014*7c478bd9Sstevel@tonic-gate to_name = args->rna_to.da_name;
1015*7c478bd9Sstevel@tonic-gate to_dfh = &args->rna_to.da_fhandle;
1016*7c478bd9Sstevel@tonic-gate
1017*7c478bd9Sstevel@tonic-gate path1 = tpath1 = nfslog_get_path(from_dfh, from_name,
1018*7c478bd9Sstevel@tonic-gate fhpath, "trans_rename from");
1019*7c478bd9Sstevel@tonic-gate path2 = tpath2 = nfslog_get_path(to_dfh, to_name,
1020*7c478bd9Sstevel@tonic-gate fhpath, "trans_rename to");
1021*7c478bd9Sstevel@tonic-gate }
1022*7c478bd9Sstevel@tonic-gate
1023*7c478bd9Sstevel@tonic-gate newte->pathname = path1; /* no need to strdup here */
1024*7c478bd9Sstevel@tonic-gate newte->starttime = logrec->re_header.rh_timestamp;
1025*7c478bd9Sstevel@tonic-gate newte->lastupdate = logrec->re_header.rh_timestamp;
1026*7c478bd9Sstevel@tonic-gate newte->optype = TRANS_OPER_RENAME;
1027*7c478bd9Sstevel@tonic-gate newte->datatype = TRANS_DATATYPE_BINARY;
1028*7c478bd9Sstevel@tonic-gate newte->transoption = TRANS_OPTION_NOACTION;
1029*7c478bd9Sstevel@tonic-gate newte->pnb = netbufdup(&(logrec->re_ipaddr));
1030*7c478bd9Sstevel@tonic-gate newte->uid = logrec->re_header.rh_uid;
1031*7c478bd9Sstevel@tonic-gate newte->nfsvers = NFS_VERSION;
1032*7c478bd9Sstevel@tonic-gate newte->netid = strdup(logrec->re_netid);
1033*7c478bd9Sstevel@tonic-gate if (logrec->re_principal_name)
1034*7c478bd9Sstevel@tonic-gate newte->principal_name = strdup(logrec->re_principal_name);
1035*7c478bd9Sstevel@tonic-gate else
1036*7c478bd9Sstevel@tonic-gate newte->principal_name = NULL;
1037*7c478bd9Sstevel@tonic-gate newte->totalbytes = 0;
1038*7c478bd9Sstevel@tonic-gate newte->fh_u.fh = *(NFSLOG_GET_FHANDLE2(&args->rna_from.da_fhandle));
1039*7c478bd9Sstevel@tonic-gate
1040*7c478bd9Sstevel@tonic-gate /* switch path names for the file for renames */
1041*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v2_write, newte)) {
1042*7c478bd9Sstevel@tonic-gate free(pte->pathname);
1043*7c478bd9Sstevel@tonic-gate pte->pathname = strdup(path2);
1044*7c478bd9Sstevel@tonic-gate }
1045*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v2_read, newte)) {
1046*7c478bd9Sstevel@tonic-gate free(pte->pathname);
1047*7c478bd9Sstevel@tonic-gate pte->pathname = strdup(path2);
1048*7c478bd9Sstevel@tonic-gate }
1049*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v3_write, newte)) {
1050*7c478bd9Sstevel@tonic-gate free(pte->pathname);
1051*7c478bd9Sstevel@tonic-gate pte->pathname = strdup(path2);
1052*7c478bd9Sstevel@tonic-gate }
1053*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v3_read, newte)) {
1054*7c478bd9Sstevel@tonic-gate free(pte->pathname);
1055*7c478bd9Sstevel@tonic-gate pte->pathname = strdup(path2);
1056*7c478bd9Sstevel@tonic-gate }
1057*7c478bd9Sstevel@tonic-gate
1058*7c478bd9Sstevel@tonic-gate newte->pathname = (char *)malloc(strlen(path1) + strlen(path2) + 3);
1059*7c478bd9Sstevel@tonic-gate /* check for NULL malloc */
1060*7c478bd9Sstevel@tonic-gate (void) sprintf(newte->pathname, "%s->%s", path1, path2);
1061*7c478bd9Sstevel@tonic-gate
1062*7c478bd9Sstevel@tonic-gate if (tpath1) {
1063*7c478bd9Sstevel@tonic-gate free(tpath1);
1064*7c478bd9Sstevel@tonic-gate free(tpath2);
1065*7c478bd9Sstevel@tonic-gate }
1066*7c478bd9Sstevel@tonic-gate
1067*7c478bd9Sstevel@tonic-gate return (newte);
1068*7c478bd9Sstevel@tonic-gate }
1069*7c478bd9Sstevel@tonic-gate
1070*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_link(nfslog_request_record * logrec,char * fhpath,char * path1,char * path2)1071*7c478bd9Sstevel@tonic-gate trans_link(
1072*7c478bd9Sstevel@tonic-gate nfslog_request_record *logrec,
1073*7c478bd9Sstevel@tonic-gate char *fhpath,
1074*7c478bd9Sstevel@tonic-gate char *path1,
1075*7c478bd9Sstevel@tonic-gate char *path2)
1076*7c478bd9Sstevel@tonic-gate {
1077*7c478bd9Sstevel@tonic-gate struct transentry *newte;
1078*7c478bd9Sstevel@tonic-gate /* LINTED */
1079*7c478bd9Sstevel@tonic-gate nfslog_linkargs *args = (nfslog_linkargs *)logrec->re_rpc_arg;
1080*7c478bd9Sstevel@tonic-gate /* LINTED */
1081*7c478bd9Sstevel@tonic-gate nfsstat *res = (nfsstat *)logrec->re_rpc_res;
1082*7c478bd9Sstevel@tonic-gate char *tpath1 = NULL;
1083*7c478bd9Sstevel@tonic-gate char *tpath2 = NULL;
1084*7c478bd9Sstevel@tonic-gate
1085*7c478bd9Sstevel@tonic-gate if (*res != NFS_OK)
1086*7c478bd9Sstevel@tonic-gate return (NULL);
1087*7c478bd9Sstevel@tonic-gate
1088*7c478bd9Sstevel@tonic-gate if ((newte = create_te()) == NULL)
1089*7c478bd9Sstevel@tonic-gate return (NULL);
1090*7c478bd9Sstevel@tonic-gate
1091*7c478bd9Sstevel@tonic-gate if (!path1) {
1092*7c478bd9Sstevel@tonic-gate fhandle_t *fh = &args->la_from;
1093*7c478bd9Sstevel@tonic-gate char *name = args->la_to.da_name;
1094*7c478bd9Sstevel@tonic-gate fhandle_t *dfh = &args->la_to.da_fhandle;
1095*7c478bd9Sstevel@tonic-gate
1096*7c478bd9Sstevel@tonic-gate path1 = tpath1 = nfslog_get_path(fh, NULL,
1097*7c478bd9Sstevel@tonic-gate fhpath, "trans_link from");
1098*7c478bd9Sstevel@tonic-gate path2 = tpath2 = nfslog_get_path(dfh, name,
1099*7c478bd9Sstevel@tonic-gate fhpath, "trans_link to");
1100*7c478bd9Sstevel@tonic-gate }
1101*7c478bd9Sstevel@tonic-gate
1102*7c478bd9Sstevel@tonic-gate newte->starttime = logrec->re_header.rh_timestamp;
1103*7c478bd9Sstevel@tonic-gate newte->lastupdate = logrec->re_header.rh_timestamp;
1104*7c478bd9Sstevel@tonic-gate newte->optype = TRANS_OPER_LINK;
1105*7c478bd9Sstevel@tonic-gate newte->datatype = TRANS_DATATYPE_BINARY;
1106*7c478bd9Sstevel@tonic-gate newte->transoption = TRANS_OPTION_NOACTION;
1107*7c478bd9Sstevel@tonic-gate newte->pnb = netbufdup(&(logrec->re_ipaddr));
1108*7c478bd9Sstevel@tonic-gate newte->uid = logrec->re_header.rh_uid;
1109*7c478bd9Sstevel@tonic-gate newte->nfsvers = NFS_VERSION;
1110*7c478bd9Sstevel@tonic-gate newte->netid = strdup(logrec->re_netid);
1111*7c478bd9Sstevel@tonic-gate if (logrec->re_principal_name)
1112*7c478bd9Sstevel@tonic-gate newte->principal_name = strdup(logrec->re_principal_name);
1113*7c478bd9Sstevel@tonic-gate else
1114*7c478bd9Sstevel@tonic-gate newte->principal_name = NULL;
1115*7c478bd9Sstevel@tonic-gate newte->totalbytes = 0;
1116*7c478bd9Sstevel@tonic-gate newte->fh_u.fh = *(NFSLOG_GET_FHANDLE2(&args->la_from));
1117*7c478bd9Sstevel@tonic-gate
1118*7c478bd9Sstevel@tonic-gate newte->pathname = (char *)malloc(strlen(path1) + strlen(path2) + 3);
1119*7c478bd9Sstevel@tonic-gate /* check for NULL malloc */
1120*7c478bd9Sstevel@tonic-gate (void) sprintf(newte->pathname, "%s->%s", path1, path2);
1121*7c478bd9Sstevel@tonic-gate
1122*7c478bd9Sstevel@tonic-gate if (tpath1) {
1123*7c478bd9Sstevel@tonic-gate free(tpath1);
1124*7c478bd9Sstevel@tonic-gate free(tpath2);
1125*7c478bd9Sstevel@tonic-gate }
1126*7c478bd9Sstevel@tonic-gate
1127*7c478bd9Sstevel@tonic-gate return (newte);
1128*7c478bd9Sstevel@tonic-gate }
1129*7c478bd9Sstevel@tonic-gate
1130*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_symlink(nfslog_request_record * logrec,char * fhpath,char * path1)1131*7c478bd9Sstevel@tonic-gate trans_symlink(
1132*7c478bd9Sstevel@tonic-gate nfslog_request_record *logrec,
1133*7c478bd9Sstevel@tonic-gate char *fhpath,
1134*7c478bd9Sstevel@tonic-gate char *path1)
1135*7c478bd9Sstevel@tonic-gate {
1136*7c478bd9Sstevel@tonic-gate struct transentry *newte;
1137*7c478bd9Sstevel@tonic-gate /* LINTED */
1138*7c478bd9Sstevel@tonic-gate nfslog_symlinkargs *args = (nfslog_symlinkargs *)logrec->re_rpc_arg;
1139*7c478bd9Sstevel@tonic-gate /* LINTED */
1140*7c478bd9Sstevel@tonic-gate nfsstat *res = (nfsstat *)logrec->re_rpc_res;
1141*7c478bd9Sstevel@tonic-gate char *tpath1 = NULL;
1142*7c478bd9Sstevel@tonic-gate
1143*7c478bd9Sstevel@tonic-gate if (*res != NFS_OK)
1144*7c478bd9Sstevel@tonic-gate return (NULL);
1145*7c478bd9Sstevel@tonic-gate
1146*7c478bd9Sstevel@tonic-gate if ((newte = create_te()) == NULL)
1147*7c478bd9Sstevel@tonic-gate return (NULL);
1148*7c478bd9Sstevel@tonic-gate
1149*7c478bd9Sstevel@tonic-gate if (!path1) {
1150*7c478bd9Sstevel@tonic-gate char *name = args->sla_from.da_name;
1151*7c478bd9Sstevel@tonic-gate fhandle_t *dfh = &args->sla_from.da_fhandle;
1152*7c478bd9Sstevel@tonic-gate
1153*7c478bd9Sstevel@tonic-gate path1 = tpath1 = nfslog_get_path(dfh, name,
1154*7c478bd9Sstevel@tonic-gate fhpath, "trans_symlink");
1155*7c478bd9Sstevel@tonic-gate }
1156*7c478bd9Sstevel@tonic-gate
1157*7c478bd9Sstevel@tonic-gate newte->starttime = logrec->re_header.rh_timestamp;
1158*7c478bd9Sstevel@tonic-gate newte->lastupdate = logrec->re_header.rh_timestamp;
1159*7c478bd9Sstevel@tonic-gate newte->optype = TRANS_OPER_SYMLINK;
1160*7c478bd9Sstevel@tonic-gate newte->datatype = TRANS_DATATYPE_BINARY;
1161*7c478bd9Sstevel@tonic-gate newte->transoption = TRANS_OPTION_NOACTION;
1162*7c478bd9Sstevel@tonic-gate newte->pnb = netbufdup(&(logrec->re_ipaddr));
1163*7c478bd9Sstevel@tonic-gate newte->uid = logrec->re_header.rh_uid;
1164*7c478bd9Sstevel@tonic-gate newte->nfsvers = NFS_VERSION;
1165*7c478bd9Sstevel@tonic-gate newte->netid = strdup(logrec->re_netid);
1166*7c478bd9Sstevel@tonic-gate if (logrec->re_principal_name)
1167*7c478bd9Sstevel@tonic-gate newte->principal_name = strdup(logrec->re_principal_name);
1168*7c478bd9Sstevel@tonic-gate else
1169*7c478bd9Sstevel@tonic-gate newte->principal_name = NULL;
1170*7c478bd9Sstevel@tonic-gate newte->totalbytes = 0;
1171*7c478bd9Sstevel@tonic-gate newte->fh_u.fh = *(NFSLOG_GET_FHANDLE2(&args->sla_from.da_fhandle));
1172*7c478bd9Sstevel@tonic-gate
1173*7c478bd9Sstevel@tonic-gate newte->pathname = (char *)malloc(strlen(path1) +
1174*7c478bd9Sstevel@tonic-gate strlen(args->sla_tnm) + 3);
1175*7c478bd9Sstevel@tonic-gate (void) sprintf(newte->pathname, "%s->%s", path1, args->sla_tnm);
1176*7c478bd9Sstevel@tonic-gate
1177*7c478bd9Sstevel@tonic-gate if (tpath1)
1178*7c478bd9Sstevel@tonic-gate free(tpath1);
1179*7c478bd9Sstevel@tonic-gate
1180*7c478bd9Sstevel@tonic-gate return (newte);
1181*7c478bd9Sstevel@tonic-gate }
1182*7c478bd9Sstevel@tonic-gate
1183*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_read3(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1)1184*7c478bd9Sstevel@tonic-gate trans_read3(
1185*7c478bd9Sstevel@tonic-gate nfslog_request_record *logrec,
1186*7c478bd9Sstevel@tonic-gate struct nfslog_trans_file *tf,
1187*7c478bd9Sstevel@tonic-gate char *fhpath,
1188*7c478bd9Sstevel@tonic-gate char *path1)
1189*7c478bd9Sstevel@tonic-gate {
1190*7c478bd9Sstevel@tonic-gate struct transentry *newte;
1191*7c478bd9Sstevel@tonic-gate struct transentry *pte = NULL;
1192*7c478bd9Sstevel@tonic-gate /* LINTED */
1193*7c478bd9Sstevel@tonic-gate nfslog_READ3args *args = (nfslog_READ3args *)logrec->re_rpc_arg;
1194*7c478bd9Sstevel@tonic-gate /* LINTED */
1195*7c478bd9Sstevel@tonic-gate nfslog_READ3res *res = (nfslog_READ3res *)logrec->re_rpc_res;
1196*7c478bd9Sstevel@tonic-gate
1197*7c478bd9Sstevel@tonic-gate if (res->status != NFS3_OK)
1198*7c478bd9Sstevel@tonic-gate return (NULL);
1199*7c478bd9Sstevel@tonic-gate
1200*7c478bd9Sstevel@tonic-gate if ((newte = create_te()) == NULL)
1201*7c478bd9Sstevel@tonic-gate return (NULL);
1202*7c478bd9Sstevel@tonic-gate
1203*7c478bd9Sstevel@tonic-gate if (!path1) {
1204*7c478bd9Sstevel@tonic-gate fhandle_t *fh = NFSLOG_GET_FHANDLE3(&args->file);
1205*7c478bd9Sstevel@tonic-gate newte->pathname = nfslog_get_path(fh, NULL,
1206*7c478bd9Sstevel@tonic-gate fhpath, "trans_read3");
1207*7c478bd9Sstevel@tonic-gate } else {
1208*7c478bd9Sstevel@tonic-gate newte->pathname = strdup(path1);
1209*7c478bd9Sstevel@tonic-gate }
1210*7c478bd9Sstevel@tonic-gate
1211*7c478bd9Sstevel@tonic-gate /* prep the struct for insertion */
1212*7c478bd9Sstevel@tonic-gate newte->starttime = logrec->re_header.rh_timestamp;
1213*7c478bd9Sstevel@tonic-gate newte->lastupdate = logrec->re_header.rh_timestamp;
1214*7c478bd9Sstevel@tonic-gate newte->optype = TRANS_OPER_READ;
1215*7c478bd9Sstevel@tonic-gate newte->datatype = TRANS_DATATYPE_BINARY;
1216*7c478bd9Sstevel@tonic-gate newte->transoption = TRANS_OPTION_NOACTION;
1217*7c478bd9Sstevel@tonic-gate newte->pnb = netbufdup(&(logrec->re_ipaddr));
1218*7c478bd9Sstevel@tonic-gate newte->uid = logrec->re_header.rh_uid;
1219*7c478bd9Sstevel@tonic-gate newte->nfsvers = NFS_V3;
1220*7c478bd9Sstevel@tonic-gate newte->netid = strdup(logrec->re_netid);
1221*7c478bd9Sstevel@tonic-gate if (logrec->re_principal_name)
1222*7c478bd9Sstevel@tonic-gate newte->principal_name = strdup(logrec->re_principal_name);
1223*7c478bd9Sstevel@tonic-gate else
1224*7c478bd9Sstevel@tonic-gate newte->principal_name = NULL;
1225*7c478bd9Sstevel@tonic-gate newte->totalbytes = res->nfslog_READ3res_u.ok.count;
1226*7c478bd9Sstevel@tonic-gate newte->fh_u.fh3 = args->file;
1227*7c478bd9Sstevel@tonic-gate
1228*7c478bd9Sstevel@tonic-gate if (res->nfslog_READ3res_u.ok.count <
1229*7c478bd9Sstevel@tonic-gate res->nfslog_READ3res_u.ok.filesize) {
1230*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v3_read, newte)) {
1231*7c478bd9Sstevel@tonic-gate /* free this since entry was found (not inserted) */
1232*7c478bd9Sstevel@tonic-gate remove_te(newte);
1233*7c478bd9Sstevel@tonic-gate
1234*7c478bd9Sstevel@tonic-gate pte->totalbytes += res->nfslog_READ3res_u.ok.count;
1235*7c478bd9Sstevel@tonic-gate
1236*7c478bd9Sstevel@tonic-gate if (pte->lastupdate.tv_sec <=
1237*7c478bd9Sstevel@tonic-gate logrec->re_header.rh_timestamp.tv_sec)
1238*7c478bd9Sstevel@tonic-gate pte->lastupdate =
1239*7c478bd9Sstevel@tonic-gate logrec->re_header.rh_timestamp;
1240*7c478bd9Sstevel@tonic-gate
1241*7c478bd9Sstevel@tonic-gate if (pte->totalbytes <
1242*7c478bd9Sstevel@tonic-gate res->nfslog_READ3res_u.ok.filesize) {
1243*7c478bd9Sstevel@tonic-gate pte = NULL; /* prevent printing of log entry */
1244*7c478bd9Sstevel@tonic-gate }
1245*7c478bd9Sstevel@tonic-gate }
1246*7c478bd9Sstevel@tonic-gate } else {
1247*7c478bd9Sstevel@tonic-gate pte = newte; /* print a log record - complete file read */
1248*7c478bd9Sstevel@tonic-gate }
1249*7c478bd9Sstevel@tonic-gate
1250*7c478bd9Sstevel@tonic-gate return (pte);
1251*7c478bd9Sstevel@tonic-gate }
1252*7c478bd9Sstevel@tonic-gate
1253*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_write3(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1)1254*7c478bd9Sstevel@tonic-gate trans_write3(
1255*7c478bd9Sstevel@tonic-gate nfslog_request_record *logrec,
1256*7c478bd9Sstevel@tonic-gate struct nfslog_trans_file *tf,
1257*7c478bd9Sstevel@tonic-gate char *fhpath,
1258*7c478bd9Sstevel@tonic-gate char *path1)
1259*7c478bd9Sstevel@tonic-gate {
1260*7c478bd9Sstevel@tonic-gate struct transentry *newte;
1261*7c478bd9Sstevel@tonic-gate struct transentry *pte = NULL;
1262*7c478bd9Sstevel@tonic-gate /* LINTED */
1263*7c478bd9Sstevel@tonic-gate nfslog_WRITE3args *args = (nfslog_WRITE3args *)logrec->re_rpc_arg;
1264*7c478bd9Sstevel@tonic-gate /* LINTED */
1265*7c478bd9Sstevel@tonic-gate nfslog_WRITE3res *res = (nfslog_WRITE3res *)logrec->re_rpc_res;
1266*7c478bd9Sstevel@tonic-gate
1267*7c478bd9Sstevel@tonic-gate if (res->status != NFS3_OK)
1268*7c478bd9Sstevel@tonic-gate return (NULL);
1269*7c478bd9Sstevel@tonic-gate
1270*7c478bd9Sstevel@tonic-gate if ((newte = create_te()) == NULL)
1271*7c478bd9Sstevel@tonic-gate return (NULL);
1272*7c478bd9Sstevel@tonic-gate
1273*7c478bd9Sstevel@tonic-gate if (!path1) {
1274*7c478bd9Sstevel@tonic-gate fhandle_t *fh = NFSLOG_GET_FHANDLE3(&args->file);
1275*7c478bd9Sstevel@tonic-gate newte->pathname = nfslog_get_path(fh, NULL,
1276*7c478bd9Sstevel@tonic-gate fhpath, "trans_write3");
1277*7c478bd9Sstevel@tonic-gate } else {
1278*7c478bd9Sstevel@tonic-gate newte->pathname = strdup(path1);
1279*7c478bd9Sstevel@tonic-gate }
1280*7c478bd9Sstevel@tonic-gate
1281*7c478bd9Sstevel@tonic-gate newte->starttime = logrec->re_header.rh_timestamp;
1282*7c478bd9Sstevel@tonic-gate newte->lastupdate = logrec->re_header.rh_timestamp;
1283*7c478bd9Sstevel@tonic-gate newte->optype = TRANS_OPER_WRITE;
1284*7c478bd9Sstevel@tonic-gate newte->datatype = TRANS_DATATYPE_BINARY;
1285*7c478bd9Sstevel@tonic-gate newte->transoption = TRANS_OPTION_NOACTION;
1286*7c478bd9Sstevel@tonic-gate newte->pnb = netbufdup(&(logrec->re_ipaddr));
1287*7c478bd9Sstevel@tonic-gate newte->uid = logrec->re_header.rh_uid;
1288*7c478bd9Sstevel@tonic-gate newte->nfsvers = NFS_V3;
1289*7c478bd9Sstevel@tonic-gate newte->netid = strdup(logrec->re_netid);
1290*7c478bd9Sstevel@tonic-gate if (logrec->re_principal_name)
1291*7c478bd9Sstevel@tonic-gate newte->principal_name = strdup(logrec->re_principal_name);
1292*7c478bd9Sstevel@tonic-gate else
1293*7c478bd9Sstevel@tonic-gate newte->principal_name = NULL;
1294*7c478bd9Sstevel@tonic-gate newte->totalbytes = res->nfslog_WRITE3res_u.ok.count;
1295*7c478bd9Sstevel@tonic-gate newte->fh_u.fh3 = args->file;
1296*7c478bd9Sstevel@tonic-gate
1297*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v3_write, newte)) {
1298*7c478bd9Sstevel@tonic-gate /*
1299*7c478bd9Sstevel@tonic-gate * if the write would have increased the total byte count
1300*7c478bd9Sstevel@tonic-gate * over the filesize, then generate a log entry and remove
1301*7c478bd9Sstevel@tonic-gate * the write record and insert the new one.
1302*7c478bd9Sstevel@tonic-gate */
1303*7c478bd9Sstevel@tonic-gate if (pte->totalbytes + res->nfslog_WRITE3res_u.ok.count >
1304*7c478bd9Sstevel@tonic-gate res->nfslog_WRITE3res_u.ok.filesize) {
1305*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
1306*7c478bd9Sstevel@tonic-gate remove_te(pte);
1307*7c478bd9Sstevel@tonic-gate (void) insert_te(tf->te_list_v3_write, newte);
1308*7c478bd9Sstevel@tonic-gate pte = NULL;
1309*7c478bd9Sstevel@tonic-gate } else {
1310*7c478bd9Sstevel@tonic-gate /* free this since entry was found (not inserted) */
1311*7c478bd9Sstevel@tonic-gate remove_te(newte);
1312*7c478bd9Sstevel@tonic-gate
1313*7c478bd9Sstevel@tonic-gate pte->totalbytes += res->nfslog_WRITE3res_u.ok.count;
1314*7c478bd9Sstevel@tonic-gate
1315*7c478bd9Sstevel@tonic-gate if (pte->lastupdate.tv_sec <=
1316*7c478bd9Sstevel@tonic-gate logrec->re_header.rh_timestamp.tv_sec) {
1317*7c478bd9Sstevel@tonic-gate pte->lastupdate =
1318*7c478bd9Sstevel@tonic-gate logrec->re_header.rh_timestamp;
1319*7c478bd9Sstevel@tonic-gate }
1320*7c478bd9Sstevel@tonic-gate pte = NULL; /* prevent printing of log entry */
1321*7c478bd9Sstevel@tonic-gate }
1322*7c478bd9Sstevel@tonic-gate }
1323*7c478bd9Sstevel@tonic-gate return (pte);
1324*7c478bd9Sstevel@tonic-gate }
1325*7c478bd9Sstevel@tonic-gate
1326*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_setattr3(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1)1327*7c478bd9Sstevel@tonic-gate trans_setattr3(
1328*7c478bd9Sstevel@tonic-gate nfslog_request_record *logrec,
1329*7c478bd9Sstevel@tonic-gate struct nfslog_trans_file *tf,
1330*7c478bd9Sstevel@tonic-gate char *fhpath,
1331*7c478bd9Sstevel@tonic-gate char *path1)
1332*7c478bd9Sstevel@tonic-gate {
1333*7c478bd9Sstevel@tonic-gate struct transentry *newte;
1334*7c478bd9Sstevel@tonic-gate struct transentry *pte = NULL;
1335*7c478bd9Sstevel@tonic-gate /* LINTED */
1336*7c478bd9Sstevel@tonic-gate nfslog_SETATTR3args *args = (nfslog_SETATTR3args *)logrec->re_rpc_arg;
1337*7c478bd9Sstevel@tonic-gate /* LINTED */
1338*7c478bd9Sstevel@tonic-gate nfsstat3 *res = (nfsstat3 *)logrec->re_rpc_res;
1339*7c478bd9Sstevel@tonic-gate
1340*7c478bd9Sstevel@tonic-gate if (*res != NFS3_OK)
1341*7c478bd9Sstevel@tonic-gate return (NULL);
1342*7c478bd9Sstevel@tonic-gate
1343*7c478bd9Sstevel@tonic-gate if (!args->size.set_it)
1344*7c478bd9Sstevel@tonic-gate return (NULL);
1345*7c478bd9Sstevel@tonic-gate /*
1346*7c478bd9Sstevel@tonic-gate * should check the size of the file to see if it
1347*7c478bd9Sstevel@tonic-gate * is being truncated below current eof. if so
1348*7c478bd9Sstevel@tonic-gate * a record should be generated.... XXX
1349*7c478bd9Sstevel@tonic-gate */
1350*7c478bd9Sstevel@tonic-gate if (args->size.size != 0)
1351*7c478bd9Sstevel@tonic-gate return (NULL);
1352*7c478bd9Sstevel@tonic-gate
1353*7c478bd9Sstevel@tonic-gate if ((newte = create_te()) == NULL)
1354*7c478bd9Sstevel@tonic-gate return (NULL);
1355*7c478bd9Sstevel@tonic-gate
1356*7c478bd9Sstevel@tonic-gate if (!path1) {
1357*7c478bd9Sstevel@tonic-gate fhandle_t *fh = NFSLOG_GET_FHANDLE3(&args->object);
1358*7c478bd9Sstevel@tonic-gate newte->pathname = nfslog_get_path(fh, NULL,
1359*7c478bd9Sstevel@tonic-gate fhpath, "trans_setattr3");
1360*7c478bd9Sstevel@tonic-gate } else {
1361*7c478bd9Sstevel@tonic-gate newte->pathname = strdup(path1);
1362*7c478bd9Sstevel@tonic-gate }
1363*7c478bd9Sstevel@tonic-gate
1364*7c478bd9Sstevel@tonic-gate newte->starttime = logrec->re_header.rh_timestamp;
1365*7c478bd9Sstevel@tonic-gate newte->lastupdate = logrec->re_header.rh_timestamp;
1366*7c478bd9Sstevel@tonic-gate newte->optype = TRANS_OPER_SETATTR;
1367*7c478bd9Sstevel@tonic-gate newte->datatype = TRANS_DATATYPE_BINARY;
1368*7c478bd9Sstevel@tonic-gate newte->transoption = TRANS_OPTION_NOACTION;
1369*7c478bd9Sstevel@tonic-gate newte->pnb = netbufdup(&(logrec->re_ipaddr));
1370*7c478bd9Sstevel@tonic-gate newte->uid = logrec->re_header.rh_uid;
1371*7c478bd9Sstevel@tonic-gate newte->nfsvers = NFS_V3;
1372*7c478bd9Sstevel@tonic-gate newte->netid = strdup(logrec->re_netid);
1373*7c478bd9Sstevel@tonic-gate if (logrec->re_principal_name)
1374*7c478bd9Sstevel@tonic-gate newte->principal_name = strdup(logrec->re_principal_name);
1375*7c478bd9Sstevel@tonic-gate else
1376*7c478bd9Sstevel@tonic-gate newte->principal_name = NULL;
1377*7c478bd9Sstevel@tonic-gate newte->totalbytes = 0;
1378*7c478bd9Sstevel@tonic-gate newte->fh_u.fh3 = args->object;
1379*7c478bd9Sstevel@tonic-gate
1380*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v3_write, newte)) {
1381*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
1382*7c478bd9Sstevel@tonic-gate remove_te(pte);
1383*7c478bd9Sstevel@tonic-gate }
1384*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v3_read, newte)) {
1385*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
1386*7c478bd9Sstevel@tonic-gate remove_te(pte);
1387*7c478bd9Sstevel@tonic-gate }
1388*7c478bd9Sstevel@tonic-gate
1389*7c478bd9Sstevel@tonic-gate return (newte);
1390*7c478bd9Sstevel@tonic-gate }
1391*7c478bd9Sstevel@tonic-gate
1392*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_create3(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1)1393*7c478bd9Sstevel@tonic-gate trans_create3(
1394*7c478bd9Sstevel@tonic-gate nfslog_request_record *logrec,
1395*7c478bd9Sstevel@tonic-gate struct nfslog_trans_file *tf,
1396*7c478bd9Sstevel@tonic-gate char *fhpath,
1397*7c478bd9Sstevel@tonic-gate char *path1)
1398*7c478bd9Sstevel@tonic-gate {
1399*7c478bd9Sstevel@tonic-gate struct transentry *newte;
1400*7c478bd9Sstevel@tonic-gate struct transentry *pte = NULL;
1401*7c478bd9Sstevel@tonic-gate /* LINTED */
1402*7c478bd9Sstevel@tonic-gate nfslog_CREATE3args *args = (nfslog_CREATE3args *)logrec->re_rpc_arg;
1403*7c478bd9Sstevel@tonic-gate /* LINTED */
1404*7c478bd9Sstevel@tonic-gate nfslog_CREATE3res *res = (nfslog_CREATE3res *)logrec->re_rpc_res;
1405*7c478bd9Sstevel@tonic-gate
1406*7c478bd9Sstevel@tonic-gate if (res->status != NFS3_OK)
1407*7c478bd9Sstevel@tonic-gate return (NULL);
1408*7c478bd9Sstevel@tonic-gate
1409*7c478bd9Sstevel@tonic-gate if ((newte = create_te()) == NULL)
1410*7c478bd9Sstevel@tonic-gate return (NULL);
1411*7c478bd9Sstevel@tonic-gate
1412*7c478bd9Sstevel@tonic-gate if (!path1) {
1413*7c478bd9Sstevel@tonic-gate newte->pathname =
1414*7c478bd9Sstevel@tonic-gate nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->where.dir),
1415*7c478bd9Sstevel@tonic-gate args->where.name,
1416*7c478bd9Sstevel@tonic-gate fhpath, "trans_create3");
1417*7c478bd9Sstevel@tonic-gate } else {
1418*7c478bd9Sstevel@tonic-gate newte->pathname = strdup(path1);
1419*7c478bd9Sstevel@tonic-gate }
1420*7c478bd9Sstevel@tonic-gate
1421*7c478bd9Sstevel@tonic-gate newte->starttime = logrec->re_header.rh_timestamp;
1422*7c478bd9Sstevel@tonic-gate newte->lastupdate = logrec->re_header.rh_timestamp;
1423*7c478bd9Sstevel@tonic-gate newte->optype = TRANS_OPER_CREATE;
1424*7c478bd9Sstevel@tonic-gate newte->datatype = TRANS_DATATYPE_BINARY;
1425*7c478bd9Sstevel@tonic-gate newte->transoption = TRANS_OPTION_NOACTION;
1426*7c478bd9Sstevel@tonic-gate newte->pnb = netbufdup(&(logrec->re_ipaddr));
1427*7c478bd9Sstevel@tonic-gate newte->uid = logrec->re_header.rh_uid;
1428*7c478bd9Sstevel@tonic-gate newte->nfsvers = NFS_V3;
1429*7c478bd9Sstevel@tonic-gate newte->netid = strdup(logrec->re_netid);
1430*7c478bd9Sstevel@tonic-gate if (logrec->re_principal_name)
1431*7c478bd9Sstevel@tonic-gate newte->principal_name = strdup(logrec->re_principal_name);
1432*7c478bd9Sstevel@tonic-gate else
1433*7c478bd9Sstevel@tonic-gate newte->principal_name = NULL;
1434*7c478bd9Sstevel@tonic-gate
1435*7c478bd9Sstevel@tonic-gate if (!args->how.nfslog_createhow3_u.size.set_it)
1436*7c478bd9Sstevel@tonic-gate newte->totalbytes = 0;
1437*7c478bd9Sstevel@tonic-gate else
1438*7c478bd9Sstevel@tonic-gate newte->totalbytes =
1439*7c478bd9Sstevel@tonic-gate args->how.nfslog_createhow3_u.size.size;
1440*7c478bd9Sstevel@tonic-gate
1441*7c478bd9Sstevel@tonic-gate newte->fh_u.fh3 = args->where.dir;
1442*7c478bd9Sstevel@tonic-gate
1443*7c478bd9Sstevel@tonic-gate if (args->how.nfslog_createhow3_u.size.set_it) {
1444*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v3_write, newte)) {
1445*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
1446*7c478bd9Sstevel@tonic-gate remove_te(pte);
1447*7c478bd9Sstevel@tonic-gate }
1448*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v3_read, newte)) {
1449*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
1450*7c478bd9Sstevel@tonic-gate remove_te(pte);
1451*7c478bd9Sstevel@tonic-gate }
1452*7c478bd9Sstevel@tonic-gate }
1453*7c478bd9Sstevel@tonic-gate
1454*7c478bd9Sstevel@tonic-gate return (newte);
1455*7c478bd9Sstevel@tonic-gate }
1456*7c478bd9Sstevel@tonic-gate
1457*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_remove3(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1)1458*7c478bd9Sstevel@tonic-gate trans_remove3(
1459*7c478bd9Sstevel@tonic-gate nfslog_request_record *logrec,
1460*7c478bd9Sstevel@tonic-gate struct nfslog_trans_file *tf,
1461*7c478bd9Sstevel@tonic-gate char *fhpath,
1462*7c478bd9Sstevel@tonic-gate char *path1)
1463*7c478bd9Sstevel@tonic-gate {
1464*7c478bd9Sstevel@tonic-gate struct transentry *newte;
1465*7c478bd9Sstevel@tonic-gate struct transentry *pte = NULL;
1466*7c478bd9Sstevel@tonic-gate /* LINTED */
1467*7c478bd9Sstevel@tonic-gate nfslog_REMOVE3args *args = (nfslog_REMOVE3args *)logrec->re_rpc_arg;
1468*7c478bd9Sstevel@tonic-gate /* LINTED */
1469*7c478bd9Sstevel@tonic-gate nfsstat3 *res = (nfsstat3 *)logrec->re_rpc_res;
1470*7c478bd9Sstevel@tonic-gate
1471*7c478bd9Sstevel@tonic-gate if (*res != NFS3_OK)
1472*7c478bd9Sstevel@tonic-gate return (NULL);
1473*7c478bd9Sstevel@tonic-gate
1474*7c478bd9Sstevel@tonic-gate if ((newte = create_te()) == NULL)
1475*7c478bd9Sstevel@tonic-gate return (NULL);
1476*7c478bd9Sstevel@tonic-gate
1477*7c478bd9Sstevel@tonic-gate if (!path1) {
1478*7c478bd9Sstevel@tonic-gate newte->pathname =
1479*7c478bd9Sstevel@tonic-gate nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->object.dir),
1480*7c478bd9Sstevel@tonic-gate args->object.name,
1481*7c478bd9Sstevel@tonic-gate fhpath, "trans_remove3");
1482*7c478bd9Sstevel@tonic-gate } else {
1483*7c478bd9Sstevel@tonic-gate newte->pathname = strdup(path1);
1484*7c478bd9Sstevel@tonic-gate }
1485*7c478bd9Sstevel@tonic-gate
1486*7c478bd9Sstevel@tonic-gate newte->starttime = logrec->re_header.rh_timestamp;
1487*7c478bd9Sstevel@tonic-gate newte->lastupdate = logrec->re_header.rh_timestamp;
1488*7c478bd9Sstevel@tonic-gate newte->optype = TRANS_OPER_REMOVE;
1489*7c478bd9Sstevel@tonic-gate newte->datatype = TRANS_DATATYPE_BINARY;
1490*7c478bd9Sstevel@tonic-gate newte->transoption = TRANS_OPTION_NOACTION;
1491*7c478bd9Sstevel@tonic-gate newte->pnb = netbufdup(&(logrec->re_ipaddr));
1492*7c478bd9Sstevel@tonic-gate newte->uid = logrec->re_header.rh_uid;
1493*7c478bd9Sstevel@tonic-gate newte->nfsvers = NFS_V3;
1494*7c478bd9Sstevel@tonic-gate newte->netid = strdup(logrec->re_netid);
1495*7c478bd9Sstevel@tonic-gate if (logrec->re_principal_name)
1496*7c478bd9Sstevel@tonic-gate newte->principal_name = strdup(logrec->re_principal_name);
1497*7c478bd9Sstevel@tonic-gate else
1498*7c478bd9Sstevel@tonic-gate newte->principal_name = NULL;
1499*7c478bd9Sstevel@tonic-gate newte->totalbytes = 0;
1500*7c478bd9Sstevel@tonic-gate newte->fh_u.fh3 = args->object.dir;
1501*7c478bd9Sstevel@tonic-gate
1502*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v3_write, newte)) {
1503*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
1504*7c478bd9Sstevel@tonic-gate remove_te(pte);
1505*7c478bd9Sstevel@tonic-gate }
1506*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v3_read, newte)) {
1507*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
1508*7c478bd9Sstevel@tonic-gate remove_te(pte);
1509*7c478bd9Sstevel@tonic-gate }
1510*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v2_write, newte)) {
1511*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
1512*7c478bd9Sstevel@tonic-gate remove_te(pte);
1513*7c478bd9Sstevel@tonic-gate }
1514*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v2_read, newte)) {
1515*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
1516*7c478bd9Sstevel@tonic-gate remove_te(pte);
1517*7c478bd9Sstevel@tonic-gate }
1518*7c478bd9Sstevel@tonic-gate
1519*7c478bd9Sstevel@tonic-gate return (newte);
1520*7c478bd9Sstevel@tonic-gate }
1521*7c478bd9Sstevel@tonic-gate
1522*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_mkdir3(nfslog_request_record * logrec,char * fhpath,char * path1)1523*7c478bd9Sstevel@tonic-gate trans_mkdir3(
1524*7c478bd9Sstevel@tonic-gate nfslog_request_record *logrec,
1525*7c478bd9Sstevel@tonic-gate char *fhpath,
1526*7c478bd9Sstevel@tonic-gate char *path1)
1527*7c478bd9Sstevel@tonic-gate {
1528*7c478bd9Sstevel@tonic-gate struct transentry *newte;
1529*7c478bd9Sstevel@tonic-gate /* LINTED */
1530*7c478bd9Sstevel@tonic-gate nfslog_MKDIR3args *args = (nfslog_MKDIR3args *)logrec->re_rpc_arg;
1531*7c478bd9Sstevel@tonic-gate /* LINTED */
1532*7c478bd9Sstevel@tonic-gate nfslog_MKDIR3res *res = (nfslog_MKDIR3res *)logrec->re_rpc_res;
1533*7c478bd9Sstevel@tonic-gate
1534*7c478bd9Sstevel@tonic-gate if (res->status != NFS3_OK)
1535*7c478bd9Sstevel@tonic-gate return (NULL);
1536*7c478bd9Sstevel@tonic-gate
1537*7c478bd9Sstevel@tonic-gate if ((newte = create_te()) == NULL)
1538*7c478bd9Sstevel@tonic-gate return (NULL);
1539*7c478bd9Sstevel@tonic-gate
1540*7c478bd9Sstevel@tonic-gate if (!path1) {
1541*7c478bd9Sstevel@tonic-gate newte->pathname =
1542*7c478bd9Sstevel@tonic-gate nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->where.dir),
1543*7c478bd9Sstevel@tonic-gate args->where.name,
1544*7c478bd9Sstevel@tonic-gate fhpath, "trans_mkdir3");
1545*7c478bd9Sstevel@tonic-gate } else {
1546*7c478bd9Sstevel@tonic-gate newte->pathname = strdup(path1);
1547*7c478bd9Sstevel@tonic-gate }
1548*7c478bd9Sstevel@tonic-gate
1549*7c478bd9Sstevel@tonic-gate newte->starttime = logrec->re_header.rh_timestamp;
1550*7c478bd9Sstevel@tonic-gate newte->lastupdate = logrec->re_header.rh_timestamp;
1551*7c478bd9Sstevel@tonic-gate newte->optype = TRANS_OPER_MKDIR;
1552*7c478bd9Sstevel@tonic-gate newte->datatype = TRANS_DATATYPE_BINARY;
1553*7c478bd9Sstevel@tonic-gate newte->transoption = TRANS_OPTION_NOACTION;
1554*7c478bd9Sstevel@tonic-gate newte->pnb = netbufdup(&(logrec->re_ipaddr));
1555*7c478bd9Sstevel@tonic-gate newte->uid = logrec->re_header.rh_uid;
1556*7c478bd9Sstevel@tonic-gate newte->nfsvers = NFS_V3;
1557*7c478bd9Sstevel@tonic-gate newte->netid = strdup(logrec->re_netid);
1558*7c478bd9Sstevel@tonic-gate if (logrec->re_principal_name)
1559*7c478bd9Sstevel@tonic-gate newte->principal_name = strdup(logrec->re_principal_name);
1560*7c478bd9Sstevel@tonic-gate else
1561*7c478bd9Sstevel@tonic-gate newte->principal_name = NULL;
1562*7c478bd9Sstevel@tonic-gate newte->totalbytes = 0;
1563*7c478bd9Sstevel@tonic-gate newte->fh_u.fh3 = args->where.dir;
1564*7c478bd9Sstevel@tonic-gate
1565*7c478bd9Sstevel@tonic-gate return (newte);
1566*7c478bd9Sstevel@tonic-gate }
1567*7c478bd9Sstevel@tonic-gate
1568*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_rmdir3(nfslog_request_record * logrec,char * fhpath,char * path1)1569*7c478bd9Sstevel@tonic-gate trans_rmdir3(
1570*7c478bd9Sstevel@tonic-gate nfslog_request_record *logrec,
1571*7c478bd9Sstevel@tonic-gate char *fhpath,
1572*7c478bd9Sstevel@tonic-gate char *path1)
1573*7c478bd9Sstevel@tonic-gate {
1574*7c478bd9Sstevel@tonic-gate struct transentry *newte;
1575*7c478bd9Sstevel@tonic-gate /* LINTED */
1576*7c478bd9Sstevel@tonic-gate nfslog_RMDIR3args *args = (nfslog_RMDIR3args *)logrec->re_rpc_arg;
1577*7c478bd9Sstevel@tonic-gate /* LINTED */
1578*7c478bd9Sstevel@tonic-gate nfsstat3 *res = (nfsstat3 *)logrec->re_rpc_res;
1579*7c478bd9Sstevel@tonic-gate
1580*7c478bd9Sstevel@tonic-gate if (*res != NFS3_OK)
1581*7c478bd9Sstevel@tonic-gate return (NULL);
1582*7c478bd9Sstevel@tonic-gate
1583*7c478bd9Sstevel@tonic-gate if ((newte = create_te()) == NULL)
1584*7c478bd9Sstevel@tonic-gate return (NULL);
1585*7c478bd9Sstevel@tonic-gate
1586*7c478bd9Sstevel@tonic-gate if (!path1) {
1587*7c478bd9Sstevel@tonic-gate newte->pathname =
1588*7c478bd9Sstevel@tonic-gate nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->object.dir),
1589*7c478bd9Sstevel@tonic-gate args->object.name,
1590*7c478bd9Sstevel@tonic-gate fhpath, "trans_rmdir3");
1591*7c478bd9Sstevel@tonic-gate } else {
1592*7c478bd9Sstevel@tonic-gate newte->pathname = strdup(path1);
1593*7c478bd9Sstevel@tonic-gate }
1594*7c478bd9Sstevel@tonic-gate
1595*7c478bd9Sstevel@tonic-gate newte->starttime = logrec->re_header.rh_timestamp;
1596*7c478bd9Sstevel@tonic-gate newte->lastupdate = logrec->re_header.rh_timestamp;
1597*7c478bd9Sstevel@tonic-gate newte->optype = TRANS_OPER_RMDIR;
1598*7c478bd9Sstevel@tonic-gate newte->datatype = TRANS_DATATYPE_BINARY;
1599*7c478bd9Sstevel@tonic-gate newte->transoption = TRANS_OPTION_NOACTION;
1600*7c478bd9Sstevel@tonic-gate newte->pnb = netbufdup(&(logrec->re_ipaddr));
1601*7c478bd9Sstevel@tonic-gate newte->uid = logrec->re_header.rh_uid;
1602*7c478bd9Sstevel@tonic-gate newte->nfsvers = NFS_V3;
1603*7c478bd9Sstevel@tonic-gate newte->netid = strdup(logrec->re_netid);
1604*7c478bd9Sstevel@tonic-gate if (logrec->re_principal_name)
1605*7c478bd9Sstevel@tonic-gate newte->principal_name = strdup(logrec->re_principal_name);
1606*7c478bd9Sstevel@tonic-gate else
1607*7c478bd9Sstevel@tonic-gate newte->principal_name = NULL;
1608*7c478bd9Sstevel@tonic-gate newte->totalbytes = 0;
1609*7c478bd9Sstevel@tonic-gate newte->fh_u.fh3 = args->object.dir;
1610*7c478bd9Sstevel@tonic-gate
1611*7c478bd9Sstevel@tonic-gate return (newte);
1612*7c478bd9Sstevel@tonic-gate }
1613*7c478bd9Sstevel@tonic-gate
1614*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_rename3(nfslog_request_record * logrec,struct nfslog_trans_file * tf,char * fhpath,char * path1,char * path2)1615*7c478bd9Sstevel@tonic-gate trans_rename3(
1616*7c478bd9Sstevel@tonic-gate nfslog_request_record *logrec,
1617*7c478bd9Sstevel@tonic-gate struct nfslog_trans_file *tf,
1618*7c478bd9Sstevel@tonic-gate char *fhpath,
1619*7c478bd9Sstevel@tonic-gate char *path1,
1620*7c478bd9Sstevel@tonic-gate char *path2)
1621*7c478bd9Sstevel@tonic-gate {
1622*7c478bd9Sstevel@tonic-gate struct transentry *newte;
1623*7c478bd9Sstevel@tonic-gate struct transentry *pte = NULL;
1624*7c478bd9Sstevel@tonic-gate /* LINTED */
1625*7c478bd9Sstevel@tonic-gate nfslog_RENAME3args *args = (nfslog_RENAME3args *)logrec->re_rpc_arg;
1626*7c478bd9Sstevel@tonic-gate /* LINTED */
1627*7c478bd9Sstevel@tonic-gate nfsstat3 *res = (nfsstat3 *)logrec->re_rpc_res;
1628*7c478bd9Sstevel@tonic-gate char *tpath1 = NULL;
1629*7c478bd9Sstevel@tonic-gate char *tpath2 = NULL;
1630*7c478bd9Sstevel@tonic-gate
1631*7c478bd9Sstevel@tonic-gate if (*res != NFS3_OK)
1632*7c478bd9Sstevel@tonic-gate return (NULL);
1633*7c478bd9Sstevel@tonic-gate
1634*7c478bd9Sstevel@tonic-gate if ((newte = create_te()) == NULL)
1635*7c478bd9Sstevel@tonic-gate return (NULL);
1636*7c478bd9Sstevel@tonic-gate
1637*7c478bd9Sstevel@tonic-gate if (!path1) {
1638*7c478bd9Sstevel@tonic-gate path1 = tpath1 =
1639*7c478bd9Sstevel@tonic-gate nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->from.dir),
1640*7c478bd9Sstevel@tonic-gate args->from.name, fhpath, "trans_rename3 from");
1641*7c478bd9Sstevel@tonic-gate path2 = tpath2 =
1642*7c478bd9Sstevel@tonic-gate nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->to.dir),
1643*7c478bd9Sstevel@tonic-gate args->to.name, fhpath, "trans_rename3 to");
1644*7c478bd9Sstevel@tonic-gate }
1645*7c478bd9Sstevel@tonic-gate
1646*7c478bd9Sstevel@tonic-gate newte->pathname = path1; /* no need to strdup here */
1647*7c478bd9Sstevel@tonic-gate newte->starttime = logrec->re_header.rh_timestamp;
1648*7c478bd9Sstevel@tonic-gate newte->lastupdate = logrec->re_header.rh_timestamp;
1649*7c478bd9Sstevel@tonic-gate newte->optype = TRANS_OPER_RENAME;
1650*7c478bd9Sstevel@tonic-gate newte->datatype = TRANS_DATATYPE_BINARY;
1651*7c478bd9Sstevel@tonic-gate newte->transoption = TRANS_OPTION_NOACTION;
1652*7c478bd9Sstevel@tonic-gate newte->pnb = netbufdup(&(logrec->re_ipaddr));
1653*7c478bd9Sstevel@tonic-gate newte->uid = logrec->re_header.rh_uid;
1654*7c478bd9Sstevel@tonic-gate newte->nfsvers = NFS_V3;
1655*7c478bd9Sstevel@tonic-gate newte->netid = strdup(logrec->re_netid);
1656*7c478bd9Sstevel@tonic-gate if (logrec->re_principal_name)
1657*7c478bd9Sstevel@tonic-gate newte->principal_name = strdup(logrec->re_principal_name);
1658*7c478bd9Sstevel@tonic-gate else
1659*7c478bd9Sstevel@tonic-gate newte->principal_name = NULL;
1660*7c478bd9Sstevel@tonic-gate newte->totalbytes = 0;
1661*7c478bd9Sstevel@tonic-gate newte->fh_u.fh3 = args->from.dir;
1662*7c478bd9Sstevel@tonic-gate
1663*7c478bd9Sstevel@tonic-gate /* switch path names for the file for renames */
1664*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v3_write, newte)) {
1665*7c478bd9Sstevel@tonic-gate free(pte->pathname);
1666*7c478bd9Sstevel@tonic-gate pte->pathname = strdup(path2);
1667*7c478bd9Sstevel@tonic-gate }
1668*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v3_read, newte)) {
1669*7c478bd9Sstevel@tonic-gate free(pte->pathname);
1670*7c478bd9Sstevel@tonic-gate pte->pathname = strdup(path2);
1671*7c478bd9Sstevel@tonic-gate }
1672*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v2_write, newte)) {
1673*7c478bd9Sstevel@tonic-gate free(pte->pathname);
1674*7c478bd9Sstevel@tonic-gate pte->pathname = strdup(path2);
1675*7c478bd9Sstevel@tonic-gate }
1676*7c478bd9Sstevel@tonic-gate if (pte = insert_te(tf->te_list_v2_read, newte)) {
1677*7c478bd9Sstevel@tonic-gate free(pte->pathname);
1678*7c478bd9Sstevel@tonic-gate pte->pathname = strdup(path2);
1679*7c478bd9Sstevel@tonic-gate }
1680*7c478bd9Sstevel@tonic-gate
1681*7c478bd9Sstevel@tonic-gate newte->pathname = (char *)malloc(strlen(path1) + strlen(path2) + 3);
1682*7c478bd9Sstevel@tonic-gate /* check for NULL malloc */
1683*7c478bd9Sstevel@tonic-gate (void) sprintf(newte->pathname, "%s->%s", path1, path2);
1684*7c478bd9Sstevel@tonic-gate
1685*7c478bd9Sstevel@tonic-gate if (tpath1) {
1686*7c478bd9Sstevel@tonic-gate free(tpath1);
1687*7c478bd9Sstevel@tonic-gate free(tpath2);
1688*7c478bd9Sstevel@tonic-gate }
1689*7c478bd9Sstevel@tonic-gate
1690*7c478bd9Sstevel@tonic-gate return (newte);
1691*7c478bd9Sstevel@tonic-gate }
1692*7c478bd9Sstevel@tonic-gate
1693*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_mknod3(nfslog_request_record * logrec,char * fhpath,char * path1)1694*7c478bd9Sstevel@tonic-gate trans_mknod3(
1695*7c478bd9Sstevel@tonic-gate nfslog_request_record *logrec,
1696*7c478bd9Sstevel@tonic-gate char *fhpath,
1697*7c478bd9Sstevel@tonic-gate char *path1)
1698*7c478bd9Sstevel@tonic-gate {
1699*7c478bd9Sstevel@tonic-gate struct transentry *newte;
1700*7c478bd9Sstevel@tonic-gate /* LINTED */
1701*7c478bd9Sstevel@tonic-gate nfslog_MKNOD3args *args = (nfslog_MKNOD3args *)logrec->re_rpc_arg;
1702*7c478bd9Sstevel@tonic-gate /* LINTED */
1703*7c478bd9Sstevel@tonic-gate nfslog_MKNOD3res *res = (nfslog_MKNOD3res *)logrec->re_rpc_res;
1704*7c478bd9Sstevel@tonic-gate
1705*7c478bd9Sstevel@tonic-gate if (res->status != NFS3_OK)
1706*7c478bd9Sstevel@tonic-gate return (NULL);
1707*7c478bd9Sstevel@tonic-gate
1708*7c478bd9Sstevel@tonic-gate if ((newte = create_te()) == NULL)
1709*7c478bd9Sstevel@tonic-gate return (NULL);
1710*7c478bd9Sstevel@tonic-gate
1711*7c478bd9Sstevel@tonic-gate if (!path1) {
1712*7c478bd9Sstevel@tonic-gate newte->pathname =
1713*7c478bd9Sstevel@tonic-gate nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->where.dir),
1714*7c478bd9Sstevel@tonic-gate args->where.name,
1715*7c478bd9Sstevel@tonic-gate fhpath, "trans_mknod3");
1716*7c478bd9Sstevel@tonic-gate } else {
1717*7c478bd9Sstevel@tonic-gate newte->pathname = strdup(path1);
1718*7c478bd9Sstevel@tonic-gate }
1719*7c478bd9Sstevel@tonic-gate
1720*7c478bd9Sstevel@tonic-gate newte->starttime = logrec->re_header.rh_timestamp;
1721*7c478bd9Sstevel@tonic-gate newte->lastupdate = logrec->re_header.rh_timestamp;
1722*7c478bd9Sstevel@tonic-gate newte->optype = TRANS_OPER_MKNOD;
1723*7c478bd9Sstevel@tonic-gate newte->datatype = TRANS_DATATYPE_BINARY;
1724*7c478bd9Sstevel@tonic-gate newte->transoption = TRANS_OPTION_NOACTION;
1725*7c478bd9Sstevel@tonic-gate newte->pnb = netbufdup(&(logrec->re_ipaddr));
1726*7c478bd9Sstevel@tonic-gate newte->uid = logrec->re_header.rh_uid;
1727*7c478bd9Sstevel@tonic-gate newte->nfsvers = NFS_V3;
1728*7c478bd9Sstevel@tonic-gate newte->netid = strdup(logrec->re_netid);
1729*7c478bd9Sstevel@tonic-gate if (logrec->re_principal_name)
1730*7c478bd9Sstevel@tonic-gate newte->principal_name = strdup(logrec->re_principal_name);
1731*7c478bd9Sstevel@tonic-gate else
1732*7c478bd9Sstevel@tonic-gate newte->principal_name = NULL;
1733*7c478bd9Sstevel@tonic-gate
1734*7c478bd9Sstevel@tonic-gate newte->totalbytes = 0;
1735*7c478bd9Sstevel@tonic-gate newte->fh_u.fh3 = args->where.dir;
1736*7c478bd9Sstevel@tonic-gate
1737*7c478bd9Sstevel@tonic-gate return (newte);
1738*7c478bd9Sstevel@tonic-gate }
1739*7c478bd9Sstevel@tonic-gate
1740*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_link3(nfslog_request_record * logrec,char * fhpath,char * path1,char * path2)1741*7c478bd9Sstevel@tonic-gate trans_link3(
1742*7c478bd9Sstevel@tonic-gate nfslog_request_record *logrec,
1743*7c478bd9Sstevel@tonic-gate char *fhpath,
1744*7c478bd9Sstevel@tonic-gate char *path1,
1745*7c478bd9Sstevel@tonic-gate char *path2)
1746*7c478bd9Sstevel@tonic-gate {
1747*7c478bd9Sstevel@tonic-gate struct transentry *newte;
1748*7c478bd9Sstevel@tonic-gate /* LINTED */
1749*7c478bd9Sstevel@tonic-gate nfslog_LINK3args *args = (nfslog_LINK3args *)logrec->re_rpc_arg;
1750*7c478bd9Sstevel@tonic-gate /* LINTED */
1751*7c478bd9Sstevel@tonic-gate nfsstat3 *res = (nfsstat3 *)logrec->re_rpc_res;
1752*7c478bd9Sstevel@tonic-gate
1753*7c478bd9Sstevel@tonic-gate char *tpath1 = NULL;
1754*7c478bd9Sstevel@tonic-gate char *tpath2 = NULL;
1755*7c478bd9Sstevel@tonic-gate
1756*7c478bd9Sstevel@tonic-gate if (*res != NFS3_OK)
1757*7c478bd9Sstevel@tonic-gate return (NULL);
1758*7c478bd9Sstevel@tonic-gate
1759*7c478bd9Sstevel@tonic-gate if ((newte = create_te()) == NULL)
1760*7c478bd9Sstevel@tonic-gate return (NULL);
1761*7c478bd9Sstevel@tonic-gate
1762*7c478bd9Sstevel@tonic-gate if (!path1) {
1763*7c478bd9Sstevel@tonic-gate tpath1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->file),
1764*7c478bd9Sstevel@tonic-gate NULL, fhpath, "trans_link3 from");
1765*7c478bd9Sstevel@tonic-gate tpath2 = nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->link.dir),
1766*7c478bd9Sstevel@tonic-gate args->link.name, fhpath, "trans_link3 to");
1767*7c478bd9Sstevel@tonic-gate path1 = tpath1;
1768*7c478bd9Sstevel@tonic-gate path2 = tpath2;
1769*7c478bd9Sstevel@tonic-gate }
1770*7c478bd9Sstevel@tonic-gate
1771*7c478bd9Sstevel@tonic-gate newte->starttime = logrec->re_header.rh_timestamp;
1772*7c478bd9Sstevel@tonic-gate newte->lastupdate = logrec->re_header.rh_timestamp;
1773*7c478bd9Sstevel@tonic-gate newte->optype = TRANS_OPER_LINK;
1774*7c478bd9Sstevel@tonic-gate newte->datatype = TRANS_DATATYPE_BINARY;
1775*7c478bd9Sstevel@tonic-gate newte->transoption = TRANS_OPTION_NOACTION;
1776*7c478bd9Sstevel@tonic-gate newte->pnb = netbufdup(&(logrec->re_ipaddr));
1777*7c478bd9Sstevel@tonic-gate newte->uid = logrec->re_header.rh_uid;
1778*7c478bd9Sstevel@tonic-gate newte->nfsvers = NFS_V3;
1779*7c478bd9Sstevel@tonic-gate newte->netid = strdup(logrec->re_netid);
1780*7c478bd9Sstevel@tonic-gate if (logrec->re_principal_name)
1781*7c478bd9Sstevel@tonic-gate newte->principal_name = strdup(logrec->re_principal_name);
1782*7c478bd9Sstevel@tonic-gate else
1783*7c478bd9Sstevel@tonic-gate newte->principal_name = NULL;
1784*7c478bd9Sstevel@tonic-gate newte->totalbytes = 0;
1785*7c478bd9Sstevel@tonic-gate newte->fh_u.fh3 = args->file;
1786*7c478bd9Sstevel@tonic-gate
1787*7c478bd9Sstevel@tonic-gate newte->pathname = (char *)malloc(strlen(path1) + strlen(path2) + 3);
1788*7c478bd9Sstevel@tonic-gate /* check for NULL malloc */
1789*7c478bd9Sstevel@tonic-gate (void) sprintf(newte->pathname, "%s->%s", path1, path2);
1790*7c478bd9Sstevel@tonic-gate
1791*7c478bd9Sstevel@tonic-gate if (tpath1) {
1792*7c478bd9Sstevel@tonic-gate free(tpath1);
1793*7c478bd9Sstevel@tonic-gate free(tpath2);
1794*7c478bd9Sstevel@tonic-gate }
1795*7c478bd9Sstevel@tonic-gate
1796*7c478bd9Sstevel@tonic-gate return (newte);
1797*7c478bd9Sstevel@tonic-gate }
1798*7c478bd9Sstevel@tonic-gate
1799*7c478bd9Sstevel@tonic-gate static struct transentry *
trans_symlink3(nfslog_request_record * logrec,char * fhpath,char * path1)1800*7c478bd9Sstevel@tonic-gate trans_symlink3(
1801*7c478bd9Sstevel@tonic-gate nfslog_request_record *logrec,
1802*7c478bd9Sstevel@tonic-gate char *fhpath,
1803*7c478bd9Sstevel@tonic-gate char *path1)
1804*7c478bd9Sstevel@tonic-gate {
1805*7c478bd9Sstevel@tonic-gate struct transentry *newte;
1806*7c478bd9Sstevel@tonic-gate /* LINTED */
1807*7c478bd9Sstevel@tonic-gate nfslog_SYMLINK3args *args = (nfslog_SYMLINK3args *)logrec->re_rpc_arg;
1808*7c478bd9Sstevel@tonic-gate /* LINTED */
1809*7c478bd9Sstevel@tonic-gate nfslog_SYMLINK3res *res = (nfslog_SYMLINK3res *)logrec->re_rpc_res;
1810*7c478bd9Sstevel@tonic-gate char *name;
1811*7c478bd9Sstevel@tonic-gate
1812*7c478bd9Sstevel@tonic-gate if (res->status != NFS3_OK)
1813*7c478bd9Sstevel@tonic-gate return (NULL);
1814*7c478bd9Sstevel@tonic-gate
1815*7c478bd9Sstevel@tonic-gate if ((newte = create_te()) == NULL)
1816*7c478bd9Sstevel@tonic-gate return (NULL);
1817*7c478bd9Sstevel@tonic-gate
1818*7c478bd9Sstevel@tonic-gate if (path1) {
1819*7c478bd9Sstevel@tonic-gate name = strdup(path1);
1820*7c478bd9Sstevel@tonic-gate } else {
1821*7c478bd9Sstevel@tonic-gate name = nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->where.dir),
1822*7c478bd9Sstevel@tonic-gate args->where.name, fhpath, "trans_symlink3");
1823*7c478bd9Sstevel@tonic-gate }
1824*7c478bd9Sstevel@tonic-gate
1825*7c478bd9Sstevel@tonic-gate newte->starttime = logrec->re_header.rh_timestamp;
1826*7c478bd9Sstevel@tonic-gate newte->lastupdate = logrec->re_header.rh_timestamp;
1827*7c478bd9Sstevel@tonic-gate newte->optype = TRANS_OPER_SYMLINK;
1828*7c478bd9Sstevel@tonic-gate newte->datatype = TRANS_DATATYPE_BINARY;
1829*7c478bd9Sstevel@tonic-gate newte->transoption = TRANS_OPTION_NOACTION;
1830*7c478bd9Sstevel@tonic-gate newte->pnb = netbufdup(&(logrec->re_ipaddr));
1831*7c478bd9Sstevel@tonic-gate newte->uid = logrec->re_header.rh_uid;
1832*7c478bd9Sstevel@tonic-gate newte->nfsvers = NFS_V3;
1833*7c478bd9Sstevel@tonic-gate newte->netid = strdup(logrec->re_netid);
1834*7c478bd9Sstevel@tonic-gate if (logrec->re_principal_name)
1835*7c478bd9Sstevel@tonic-gate newte->principal_name = strdup(logrec->re_principal_name);
1836*7c478bd9Sstevel@tonic-gate else
1837*7c478bd9Sstevel@tonic-gate newte->principal_name = NULL;
1838*7c478bd9Sstevel@tonic-gate newte->totalbytes = 0;
1839*7c478bd9Sstevel@tonic-gate newte->fh_u.fh3 = args->where.dir;
1840*7c478bd9Sstevel@tonic-gate
1841*7c478bd9Sstevel@tonic-gate newte->pathname = (char *)malloc(strlen(name) +
1842*7c478bd9Sstevel@tonic-gate strlen(args->symlink_data) + 3);
1843*7c478bd9Sstevel@tonic-gate /* check for NULL malloc */
1844*7c478bd9Sstevel@tonic-gate (void) sprintf(newte->pathname, "%s->%s", name, args->symlink_data);
1845*7c478bd9Sstevel@tonic-gate
1846*7c478bd9Sstevel@tonic-gate free(name);
1847*7c478bd9Sstevel@tonic-gate
1848*7c478bd9Sstevel@tonic-gate return (newte);
1849*7c478bd9Sstevel@tonic-gate }
1850*7c478bd9Sstevel@tonic-gate
1851*7c478bd9Sstevel@tonic-gate /*
1852*7c478bd9Sstevel@tonic-gate * nfslog_process_trans_rec - processes the record in the buffer and outputs
1853*7c478bd9Sstevel@tonic-gate * to the trans log.
1854*7c478bd9Sstevel@tonic-gate * Return 0 for success, errno else.
1855*7c478bd9Sstevel@tonic-gate */
1856*7c478bd9Sstevel@tonic-gate int
nfslog_process_trans_rec(void * transcookie,nfslog_request_record * logrec,char * fhpath,char * path1,char * path2)1857*7c478bd9Sstevel@tonic-gate nfslog_process_trans_rec(void *transcookie, nfslog_request_record *logrec,
1858*7c478bd9Sstevel@tonic-gate char *fhpath, char *path1, char *path2)
1859*7c478bd9Sstevel@tonic-gate {
1860*7c478bd9Sstevel@tonic-gate struct transentry *pte = NULL;
1861*7c478bd9Sstevel@tonic-gate struct nfslog_trans_file *tf = (struct nfslog_trans_file *)transcookie;
1862*7c478bd9Sstevel@tonic-gate
1863*7c478bd9Sstevel@tonic-gate /* ignore programs other than nfs */
1864*7c478bd9Sstevel@tonic-gate if (logrec->re_header.rh_prognum != NFS_PROGRAM)
1865*7c478bd9Sstevel@tonic-gate return (0);
1866*7c478bd9Sstevel@tonic-gate
1867*7c478bd9Sstevel@tonic-gate /* update the timestamp for use later in the timeout sequences */
1868*7c478bd9Sstevel@tonic-gate if (tf->lasttrans_timestamp.tv_sec <
1869*7c478bd9Sstevel@tonic-gate logrec->re_header.rh_timestamp.tv_sec)
1870*7c478bd9Sstevel@tonic-gate tf->lasttrans_timestamp =
1871*7c478bd9Sstevel@tonic-gate logrec->re_header.rh_timestamp;
1872*7c478bd9Sstevel@tonic-gate
1873*7c478bd9Sstevel@tonic-gate /* current time of this processing */
1874*7c478bd9Sstevel@tonic-gate tf->last_trans_read = time(0);
1875*7c478bd9Sstevel@tonic-gate
1876*7c478bd9Sstevel@tonic-gate /* ignore anything that is not a read or write */
1877*7c478bd9Sstevel@tonic-gate switch (logrec->re_header.rh_version) {
1878*7c478bd9Sstevel@tonic-gate case NFS_VERSION:
1879*7c478bd9Sstevel@tonic-gate switch (logrec->re_header.rh_procnum) {
1880*7c478bd9Sstevel@tonic-gate case RFS_READ:
1881*7c478bd9Sstevel@tonic-gate if (tf->trans_to_log & TRANSTOLOG_OPER_READ)
1882*7c478bd9Sstevel@tonic-gate pte = trans_read(logrec, tf, fhpath, path1);
1883*7c478bd9Sstevel@tonic-gate break;
1884*7c478bd9Sstevel@tonic-gate case RFS_WRITE:
1885*7c478bd9Sstevel@tonic-gate if (tf->trans_to_log & TRANSTOLOG_OPER_WRITE)
1886*7c478bd9Sstevel@tonic-gate pte = trans_write(logrec, tf, fhpath, path1);
1887*7c478bd9Sstevel@tonic-gate break;
1888*7c478bd9Sstevel@tonic-gate case RFS_SETATTR:
1889*7c478bd9Sstevel@tonic-gate if (tf->trans_to_log & TRANSTOLOG_OPER_SETATTR)
1890*7c478bd9Sstevel@tonic-gate pte = trans_setattr(logrec, tf,
1891*7c478bd9Sstevel@tonic-gate fhpath, path1);
1892*7c478bd9Sstevel@tonic-gate break;
1893*7c478bd9Sstevel@tonic-gate case RFS_REMOVE:
1894*7c478bd9Sstevel@tonic-gate if (tf->trans_to_log & TRANSTOLOG_OPER_REMOVE)
1895*7c478bd9Sstevel@tonic-gate pte = trans_remove(logrec, tf, fhpath, path1);
1896*7c478bd9Sstevel@tonic-gate break;
1897*7c478bd9Sstevel@tonic-gate case RFS_MKDIR:
1898*7c478bd9Sstevel@tonic-gate if (tf->trans_to_log & TRANSTOLOG_OPER_MKDIR)
1899*7c478bd9Sstevel@tonic-gate pte = trans_mkdir(logrec, fhpath, path1);
1900*7c478bd9Sstevel@tonic-gate break;
1901*7c478bd9Sstevel@tonic-gate case RFS_RMDIR:
1902*7c478bd9Sstevel@tonic-gate if (tf->trans_to_log & TRANSTOLOG_OPER_RMDIR)
1903*7c478bd9Sstevel@tonic-gate pte = trans_rmdir(logrec, fhpath, path1);
1904*7c478bd9Sstevel@tonic-gate break;
1905*7c478bd9Sstevel@tonic-gate case RFS_CREATE:
1906*7c478bd9Sstevel@tonic-gate if (tf->trans_to_log & TRANSTOLOG_OPER_CREATE)
1907*7c478bd9Sstevel@tonic-gate pte = trans_create(logrec, tf, fhpath, path1);
1908*7c478bd9Sstevel@tonic-gate break;
1909*7c478bd9Sstevel@tonic-gate case RFS_RENAME:
1910*7c478bd9Sstevel@tonic-gate if (tf->trans_to_log & TRANSTOLOG_OPER_RENAME)
1911*7c478bd9Sstevel@tonic-gate pte = trans_rename(logrec, tf,
1912*7c478bd9Sstevel@tonic-gate fhpath, path1, path2);
1913*7c478bd9Sstevel@tonic-gate break;
1914*7c478bd9Sstevel@tonic-gate case RFS_LINK:
1915*7c478bd9Sstevel@tonic-gate if (tf->trans_to_log & TRANSTOLOG_OPER_LINK)
1916*7c478bd9Sstevel@tonic-gate pte = trans_link(logrec, fhpath, path1, path2);
1917*7c478bd9Sstevel@tonic-gate break;
1918*7c478bd9Sstevel@tonic-gate case RFS_SYMLINK:
1919*7c478bd9Sstevel@tonic-gate if (tf->trans_to_log & TRANSTOLOG_OPER_SYMLINK)
1920*7c478bd9Sstevel@tonic-gate pte = trans_symlink(logrec, fhpath, path1);
1921*7c478bd9Sstevel@tonic-gate break;
1922*7c478bd9Sstevel@tonic-gate default:
1923*7c478bd9Sstevel@tonic-gate break;
1924*7c478bd9Sstevel@tonic-gate }
1925*7c478bd9Sstevel@tonic-gate break;
1926*7c478bd9Sstevel@tonic-gate case NFS_V3:
1927*7c478bd9Sstevel@tonic-gate switch (logrec->re_header.rh_procnum) {
1928*7c478bd9Sstevel@tonic-gate case NFSPROC3_READ:
1929*7c478bd9Sstevel@tonic-gate if (tf->trans_to_log & TRANSTOLOG_OPER_READ)
1930*7c478bd9Sstevel@tonic-gate pte = trans_read3(logrec, tf, fhpath, path1);
1931*7c478bd9Sstevel@tonic-gate break;
1932*7c478bd9Sstevel@tonic-gate case NFSPROC3_WRITE:
1933*7c478bd9Sstevel@tonic-gate if (tf->trans_to_log & TRANSTOLOG_OPER_WRITE)
1934*7c478bd9Sstevel@tonic-gate pte = trans_write3(logrec, tf, fhpath, path1);
1935*7c478bd9Sstevel@tonic-gate break;
1936*7c478bd9Sstevel@tonic-gate case NFSPROC3_SETATTR:
1937*7c478bd9Sstevel@tonic-gate if (tf->trans_to_log & TRANSTOLOG_OPER_SETATTR)
1938*7c478bd9Sstevel@tonic-gate pte = trans_setattr3(logrec, tf,
1939*7c478bd9Sstevel@tonic-gate fhpath, path1);
1940*7c478bd9Sstevel@tonic-gate break;
1941*7c478bd9Sstevel@tonic-gate case NFSPROC3_REMOVE:
1942*7c478bd9Sstevel@tonic-gate if (tf->trans_to_log & TRANSTOLOG_OPER_REMOVE)
1943*7c478bd9Sstevel@tonic-gate pte = trans_remove3(logrec, tf,
1944*7c478bd9Sstevel@tonic-gate fhpath, path1);
1945*7c478bd9Sstevel@tonic-gate break;
1946*7c478bd9Sstevel@tonic-gate case NFSPROC3_MKDIR:
1947*7c478bd9Sstevel@tonic-gate if (tf->trans_to_log & TRANSTOLOG_OPER_MKDIR)
1948*7c478bd9Sstevel@tonic-gate pte = trans_mkdir3(logrec, fhpath, path1);
1949*7c478bd9Sstevel@tonic-gate break;
1950*7c478bd9Sstevel@tonic-gate case NFSPROC3_RMDIR:
1951*7c478bd9Sstevel@tonic-gate if (tf->trans_to_log & TRANSTOLOG_OPER_RMDIR)
1952*7c478bd9Sstevel@tonic-gate pte = trans_rmdir3(logrec, fhpath, path1);
1953*7c478bd9Sstevel@tonic-gate break;
1954*7c478bd9Sstevel@tonic-gate case NFSPROC3_CREATE:
1955*7c478bd9Sstevel@tonic-gate if (tf->trans_to_log & TRANSTOLOG_OPER_CREATE)
1956*7c478bd9Sstevel@tonic-gate pte = trans_create3(logrec, tf,
1957*7c478bd9Sstevel@tonic-gate fhpath, path1);
1958*7c478bd9Sstevel@tonic-gate break;
1959*7c478bd9Sstevel@tonic-gate case NFSPROC3_RENAME:
1960*7c478bd9Sstevel@tonic-gate if (tf->trans_to_log & TRANSTOLOG_OPER_RENAME)
1961*7c478bd9Sstevel@tonic-gate pte = trans_rename3(logrec, tf,
1962*7c478bd9Sstevel@tonic-gate fhpath, path1, path2);
1963*7c478bd9Sstevel@tonic-gate break;
1964*7c478bd9Sstevel@tonic-gate case NFSPROC3_MKNOD:
1965*7c478bd9Sstevel@tonic-gate if (tf->trans_to_log & TRANSTOLOG_OPER_MKNOD)
1966*7c478bd9Sstevel@tonic-gate pte = trans_mknod3(logrec, fhpath, path1);
1967*7c478bd9Sstevel@tonic-gate break;
1968*7c478bd9Sstevel@tonic-gate case NFSPROC3_LINK:
1969*7c478bd9Sstevel@tonic-gate if (tf->trans_to_log & TRANSTOLOG_OPER_LINK)
1970*7c478bd9Sstevel@tonic-gate pte = trans_link3(logrec,
1971*7c478bd9Sstevel@tonic-gate fhpath, path1, path2);
1972*7c478bd9Sstevel@tonic-gate break;
1973*7c478bd9Sstevel@tonic-gate case NFSPROC3_SYMLINK:
1974*7c478bd9Sstevel@tonic-gate if (tf->trans_to_log & TRANSTOLOG_OPER_SYMLINK)
1975*7c478bd9Sstevel@tonic-gate pte = trans_symlink3(logrec, fhpath, path1);
1976*7c478bd9Sstevel@tonic-gate break;
1977*7c478bd9Sstevel@tonic-gate default:
1978*7c478bd9Sstevel@tonic-gate break;
1979*7c478bd9Sstevel@tonic-gate }
1980*7c478bd9Sstevel@tonic-gate break;
1981*7c478bd9Sstevel@tonic-gate default:
1982*7c478bd9Sstevel@tonic-gate break;
1983*7c478bd9Sstevel@tonic-gate }
1984*7c478bd9Sstevel@tonic-gate
1985*7c478bd9Sstevel@tonic-gate if (pte != NULL) {
1986*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(pte, tf);
1987*7c478bd9Sstevel@tonic-gate remove_te(pte);
1988*7c478bd9Sstevel@tonic-gate }
1989*7c478bd9Sstevel@tonic-gate
1990*7c478bd9Sstevel@tonic-gate return (0);
1991*7c478bd9Sstevel@tonic-gate }
1992*7c478bd9Sstevel@tonic-gate
1993*7c478bd9Sstevel@tonic-gate static void
nfslog_print_trans_logentry(struct transentry * pte,struct nfslog_trans_file * tf)1994*7c478bd9Sstevel@tonic-gate nfslog_print_trans_logentry(struct transentry *pte,
1995*7c478bd9Sstevel@tonic-gate struct nfslog_trans_file *tf)
1996*7c478bd9Sstevel@tonic-gate {
1997*7c478bd9Sstevel@tonic-gate char *remotehost;
1998*7c478bd9Sstevel@tonic-gate char datatype;
1999*7c478bd9Sstevel@tonic-gate char transoption;
2000*7c478bd9Sstevel@tonic-gate char *optype;
2001*7c478bd9Sstevel@tonic-gate char *prin;
2002*7c478bd9Sstevel@tonic-gate int prinid;
2003*7c478bd9Sstevel@tonic-gate char nfs_ident[32];
2004*7c478bd9Sstevel@tonic-gate
2005*7c478bd9Sstevel@tonic-gate remotehost = addrtoname(pte->pnb->buf);
2006*7c478bd9Sstevel@tonic-gate
2007*7c478bd9Sstevel@tonic-gate datatype = (pte->datatype == TRANS_DATATYPE_BINARY ? 'b' : 'a');
2008*7c478bd9Sstevel@tonic-gate transoption = (pte->transoption == TRANS_OPTION_NOACTION ? '_' : '?');
2009*7c478bd9Sstevel@tonic-gate
2010*7c478bd9Sstevel@tonic-gate if (tf->trans_output_type == TRANSLOG_BASIC) {
2011*7c478bd9Sstevel@tonic-gate (void) strcpy(nfs_ident, "nfs");
2012*7c478bd9Sstevel@tonic-gate } else {
2013*7c478bd9Sstevel@tonic-gate (void) strcpy(nfs_ident,
2014*7c478bd9Sstevel@tonic-gate (pte->nfsvers == NFS_V3 ? "nfs3-" : "nfs-"));
2015*7c478bd9Sstevel@tonic-gate (void) strcat(nfs_ident, pte->netid);
2016*7c478bd9Sstevel@tonic-gate }
2017*7c478bd9Sstevel@tonic-gate
2018*7c478bd9Sstevel@tonic-gate switch (pte->optype) {
2019*7c478bd9Sstevel@tonic-gate case TRANS_OPER_READ:
2020*7c478bd9Sstevel@tonic-gate optype = (tf->trans_output_type == TRANSLOG_EXTENDED ?
2021*7c478bd9Sstevel@tonic-gate "read" : "o");
2022*7c478bd9Sstevel@tonic-gate break;
2023*7c478bd9Sstevel@tonic-gate case TRANS_OPER_WRITE:
2024*7c478bd9Sstevel@tonic-gate optype = (tf->trans_output_type == TRANSLOG_EXTENDED ?
2025*7c478bd9Sstevel@tonic-gate "write" : "i");
2026*7c478bd9Sstevel@tonic-gate break;
2027*7c478bd9Sstevel@tonic-gate case TRANS_OPER_REMOVE:
2028*7c478bd9Sstevel@tonic-gate optype = (tf->trans_output_type == TRANSLOG_EXTENDED ?
2029*7c478bd9Sstevel@tonic-gate "remove" : "?");
2030*7c478bd9Sstevel@tonic-gate break;
2031*7c478bd9Sstevel@tonic-gate case TRANS_OPER_MKDIR:
2032*7c478bd9Sstevel@tonic-gate optype = (tf->trans_output_type == TRANSLOG_EXTENDED ?
2033*7c478bd9Sstevel@tonic-gate "mkdir" : "?");
2034*7c478bd9Sstevel@tonic-gate break;
2035*7c478bd9Sstevel@tonic-gate case TRANS_OPER_CREATE:
2036*7c478bd9Sstevel@tonic-gate optype = (tf->trans_output_type == TRANSLOG_EXTENDED ?
2037*7c478bd9Sstevel@tonic-gate "create" : "?");
2038*7c478bd9Sstevel@tonic-gate break;
2039*7c478bd9Sstevel@tonic-gate case TRANS_OPER_RMDIR:
2040*7c478bd9Sstevel@tonic-gate optype = (tf->trans_output_type == TRANSLOG_EXTENDED ?
2041*7c478bd9Sstevel@tonic-gate "rmdir" : "?");
2042*7c478bd9Sstevel@tonic-gate break;
2043*7c478bd9Sstevel@tonic-gate case TRANS_OPER_SETATTR:
2044*7c478bd9Sstevel@tonic-gate optype = (tf->trans_output_type == TRANSLOG_EXTENDED ?
2045*7c478bd9Sstevel@tonic-gate "setattr" : "?");
2046*7c478bd9Sstevel@tonic-gate break;
2047*7c478bd9Sstevel@tonic-gate case TRANS_OPER_RENAME:
2048*7c478bd9Sstevel@tonic-gate optype = (tf->trans_output_type == TRANSLOG_EXTENDED ?
2049*7c478bd9Sstevel@tonic-gate "rename" : "?");
2050*7c478bd9Sstevel@tonic-gate break;
2051*7c478bd9Sstevel@tonic-gate case TRANS_OPER_MKNOD:
2052*7c478bd9Sstevel@tonic-gate optype = (tf->trans_output_type == TRANSLOG_EXTENDED ?
2053*7c478bd9Sstevel@tonic-gate "mknod" : "?");
2054*7c478bd9Sstevel@tonic-gate break;
2055*7c478bd9Sstevel@tonic-gate case TRANS_OPER_LINK:
2056*7c478bd9Sstevel@tonic-gate optype = (tf->trans_output_type == TRANSLOG_EXTENDED ?
2057*7c478bd9Sstevel@tonic-gate "link" : "?");
2058*7c478bd9Sstevel@tonic-gate break;
2059*7c478bd9Sstevel@tonic-gate case TRANS_OPER_SYMLINK:
2060*7c478bd9Sstevel@tonic-gate optype = (tf->trans_output_type == TRANSLOG_EXTENDED ?
2061*7c478bd9Sstevel@tonic-gate "symlink" : "?");
2062*7c478bd9Sstevel@tonic-gate break;
2063*7c478bd9Sstevel@tonic-gate default:
2064*7c478bd9Sstevel@tonic-gate optype = "?";
2065*7c478bd9Sstevel@tonic-gate break;
2066*7c478bd9Sstevel@tonic-gate }
2067*7c478bd9Sstevel@tonic-gate if (strcmp(pte->principal_name, "") == 0) {
2068*7c478bd9Sstevel@tonic-gate prinid = 0;
2069*7c478bd9Sstevel@tonic-gate prin = "*";
2070*7c478bd9Sstevel@tonic-gate } else {
2071*7c478bd9Sstevel@tonic-gate prinid = 1;
2072*7c478bd9Sstevel@tonic-gate prin = pte->principal_name;
2073*7c478bd9Sstevel@tonic-gate }
2074*7c478bd9Sstevel@tonic-gate (void) fprintf(tf->fp,
2075*7c478bd9Sstevel@tonic-gate "%.24s %d %s %d %s %c %c %s %c %ld %s %d %s\n",
2076*7c478bd9Sstevel@tonic-gate ctime((time_t *)&pte->starttime.tv_sec),
2077*7c478bd9Sstevel@tonic-gate pte->lastupdate.tv_sec - pte->starttime.tv_sec,
2078*7c478bd9Sstevel@tonic-gate remotehost,
2079*7c478bd9Sstevel@tonic-gate (uint32_t)pte->totalbytes,
2080*7c478bd9Sstevel@tonic-gate pte->pathname,
2081*7c478bd9Sstevel@tonic-gate datatype,
2082*7c478bd9Sstevel@tonic-gate transoption,
2083*7c478bd9Sstevel@tonic-gate optype,
2084*7c478bd9Sstevel@tonic-gate 'r', /* anonymous == 'a', guest == 'g', real == 'r'), */
2085*7c478bd9Sstevel@tonic-gate pte->uid,
2086*7c478bd9Sstevel@tonic-gate nfs_ident,
2087*7c478bd9Sstevel@tonic-gate /* authenticated - fill in kerb/security? */
2088*7c478bd9Sstevel@tonic-gate prinid,
2089*7c478bd9Sstevel@tonic-gate /* authenticated ? authuser : "*" */
2090*7c478bd9Sstevel@tonic-gate prin);
2091*7c478bd9Sstevel@tonic-gate }
2092