xref: /illumos-gate/usr/src/cmd/fs.d/nfs/nfslog/fhtab.c (revision 2a8bcb4e)
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 /*
28*7c478bd9Sstevel@tonic-gate  * Code to maintain the runtime and on-disk filehandle mapping table for
29*7c478bd9Sstevel@tonic-gate  * nfslog.
30*7c478bd9Sstevel@tonic-gate  */
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include <assert.h>
33*7c478bd9Sstevel@tonic-gate #include <errno.h>
34*7c478bd9Sstevel@tonic-gate #include <nfs/nfs.h>
35*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
36*7c478bd9Sstevel@tonic-gate #include <string.h>
37*7c478bd9Sstevel@tonic-gate #include <strings.h>
38*7c478bd9Sstevel@tonic-gate #include <syslog.h>
39*7c478bd9Sstevel@tonic-gate #include <libintl.h>
40*7c478bd9Sstevel@tonic-gate #include <unistd.h>
41*7c478bd9Sstevel@tonic-gate #include <nfs/nfs.h>
42*7c478bd9Sstevel@tonic-gate #include <nfs/nfs_log.h>
43*7c478bd9Sstevel@tonic-gate #include "fhtab.h"
44*7c478bd9Sstevel@tonic-gate #include "nfslogd.h"
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate #define	ROUNDUP32(val)		(((val) + 3) & ~3)
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate #define	IS_DOT_FILENAME(name)						\
49*7c478bd9Sstevel@tonic-gate 	((strcmp(name, ".") == 0) || (strcmp(name, "..") == 0))
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate #define	PRINT_LINK_DATA(fp, func, dfh, name, str)			\
52*7c478bd9Sstevel@tonic-gate 	(void) fprintf(fp, "%s: name '%s', dfh ",			\
53*7c478bd9Sstevel@tonic-gate 		func, (((name) != NULL) ? name : ""));			\
54*7c478bd9Sstevel@tonic-gate 	debug_opaque_print(fp, dfh, sizeof (*(dfh)));			\
55*7c478bd9Sstevel@tonic-gate 	(void) fprintf(fp, "%s\n", str);
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate #define	PRINT_FULL_DATA(fp, func, dfh, fh, name, str)			\
59*7c478bd9Sstevel@tonic-gate 	(void) fprintf(fp, "%s: name '%s', dfh ",			\
60*7c478bd9Sstevel@tonic-gate 		func, (((name) != NULL) ? name : ""));			\
61*7c478bd9Sstevel@tonic-gate 	debug_opaque_print(fp, dfh, sizeof (*(dfh)));			\
62*7c478bd9Sstevel@tonic-gate 	if ((fh) != NULL) {						\
63*7c478bd9Sstevel@tonic-gate 		(void) fprintf(fp, ", fh ");				\
64*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(fp, fh, sizeof (*(fh)));		\
65*7c478bd9Sstevel@tonic-gate 	}								\
66*7c478bd9Sstevel@tonic-gate 	(void) fprintf(fp, "%s\n", str);
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate /*
69*7c478bd9Sstevel@tonic-gate  * export handle cache
70*7c478bd9Sstevel@tonic-gate  */
71*7c478bd9Sstevel@tonic-gate struct export_handle_cache {
72*7c478bd9Sstevel@tonic-gate 	fhandle_t			fh;
73*7c478bd9Sstevel@tonic-gate 	char				*name;
74*7c478bd9Sstevel@tonic-gate 	struct export_handle_cache	*next;
75*7c478bd9Sstevel@tonic-gate };
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate static struct export_handle_cache	*exp_handle_cache = NULL;
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate extern bool_t nfsl_prin_fh;
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate static int	fh_add(char *, fhandle_t *, fhandle_t *, char *);
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate static char *get_export_path(fhandle_t *, char *);
84*7c478bd9Sstevel@tonic-gate static void sprint_fid(char *, uint_t, const fhandle_t *);
85*7c478bd9Sstevel@tonic-gate static void fh_print_all_keys(char *fhpath, fhandle_t *fh);
86*7c478bd9Sstevel@tonic-gate static int fh_compare(fhandle_t *fh1, fhandle_t *fh2);
87*7c478bd9Sstevel@tonic-gate static fhlist_ent *fh_lookup(char *fhpath, fhandle_t *fh, fhlist_ent *fhrecp,
88*7c478bd9Sstevel@tonic-gate 	int *errorp);
89*7c478bd9Sstevel@tonic-gate static int fh_remove_mc_link(char *fhpath, fhandle_t *dfh, char *name,
90*7c478bd9Sstevel@tonic-gate 	char **pathp);
91*7c478bd9Sstevel@tonic-gate static int fh_remove(char *fhpath, fhandle_t *dfh, char *name, char **pathp);
92*7c478bd9Sstevel@tonic-gate static int fh_rename(char *fhpath, fhandle_t *from_dfh, char *from_name,
93*7c478bd9Sstevel@tonic-gate 	char **from_pathp, fhandle_t *to_dfh, char *to_name);
94*7c478bd9Sstevel@tonic-gate 
95*7c478bd9Sstevel@tonic-gate static fhlist_ent *fh_lookup_link(char *fhpath, fhandle_t *dfh, fhandle_t *fh,
96*7c478bd9Sstevel@tonic-gate 	char *name, fhlist_ent *fhrecp, int *errorp);
97*7c478bd9Sstevel@tonic-gate static struct nfsl_fh_proc_disp *nfslog_find_fh_dispatch(
98*7c478bd9Sstevel@tonic-gate 	nfslog_request_record *);
99*7c478bd9Sstevel@tonic-gate static struct export_handle_cache *find_fh_in_export_cache(fhandle_t *fh);
100*7c478bd9Sstevel@tonic-gate static void add_fh_to_export_cache(fhandle_t *fh, char *path);
101*7c478bd9Sstevel@tonic-gate static char *update_export_point(char *fhpath, fhandle_t *fh, char *path);
102*7c478bd9Sstevel@tonic-gate static char *fh_print_absolute(char *fhpath, fhandle_t *fh, char *name);
103*7c478bd9Sstevel@tonic-gate static void nfslog_null_fhargs(caddr_t *nfsl_args, caddr_t *nfsl_res,
104*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2);
105*7c478bd9Sstevel@tonic-gate static void nfslog_LOOKUP_calc(fhandle_t *dfh, char *name, fhandle_t *fh,
106*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2, char *str);
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate /*
109*7c478bd9Sstevel@tonic-gate  * NFS VERSION 2
110*7c478bd9Sstevel@tonic-gate  */
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate /*
113*7c478bd9Sstevel@tonic-gate  * Functions for updating the fhtable for fhtoppath and for returning
114*7c478bd9Sstevel@tonic-gate  * the absolute pathname
115*7c478bd9Sstevel@tonic-gate  */
116*7c478bd9Sstevel@tonic-gate static void nfslog_GETATTR2_fhargs(fhandle_t *,
117*7c478bd9Sstevel@tonic-gate 	nfsstat *, char *fhpath, char **, char **);
118*7c478bd9Sstevel@tonic-gate static void nfslog_SETATTR2_fhargs(nfslog_setattrargs *, nfsstat *,
119*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
120*7c478bd9Sstevel@tonic-gate static void nfslog_LOOKUP2_fhargs(nfslog_diropargs *, nfslog_diropres *,
121*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
122*7c478bd9Sstevel@tonic-gate static void nfslog_READLINK2_fhargs(fhandle_t *, nfslog_rdlnres *,
123*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
124*7c478bd9Sstevel@tonic-gate static void nfslog_READ2_fhargs(nfslog_nfsreadargs *, nfslog_rdresult *,
125*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
126*7c478bd9Sstevel@tonic-gate static void nfslog_WRITE2_fhargs(nfslog_writeargs *, nfslog_writeresult *,
127*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
128*7c478bd9Sstevel@tonic-gate static void nfslog_CREATE2_fhargs(nfslog_createargs *, nfslog_diropres*,
129*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
130*7c478bd9Sstevel@tonic-gate static void nfslog_REMOVE2_fhargs(nfslog_diropargs *, nfsstat *,
131*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
132*7c478bd9Sstevel@tonic-gate static void nfslog_RENAME2_fhargs(nfslog_rnmargs *, nfsstat *,
133*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
134*7c478bd9Sstevel@tonic-gate static void nfslog_LINK2_fhargs(nfslog_linkargs *, nfsstat *,
135*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
136*7c478bd9Sstevel@tonic-gate static void nfslog_SYMLINK2_fhargs(nfslog_symlinkargs *, nfsstat *,
137*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
138*7c478bd9Sstevel@tonic-gate static void nfslog_READDIR2_fhargs(nfslog_rddirargs *, nfslog_rddirres *,
139*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
140*7c478bd9Sstevel@tonic-gate static void nfslog_STATFS2_fhargs(fhandle_t *, nfsstat *,
141*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate /*
144*7c478bd9Sstevel@tonic-gate  * NFS VERSION 3
145*7c478bd9Sstevel@tonic-gate  *
146*7c478bd9Sstevel@tonic-gate  * Functions for updating the fhtable for fhtoppath
147*7c478bd9Sstevel@tonic-gate  */
148*7c478bd9Sstevel@tonic-gate static void nfslog_GETATTR3_fhargs(nfs_fh3 *, nfsstat3 *,
149*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
150*7c478bd9Sstevel@tonic-gate static void nfslog_SETATTR3_fhargs(nfslog_SETATTR3args *,	nfsstat3 *,
151*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
152*7c478bd9Sstevel@tonic-gate static void nfslog_LOOKUP3_fhargs(nfslog_diropargs3 *, nfslog_LOOKUP3res *,
153*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
154*7c478bd9Sstevel@tonic-gate static void nfslog_ACCESS3_fhargs(nfs_fh3 *, nfsstat3 *,
155*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
156*7c478bd9Sstevel@tonic-gate static void nfslog_READLINK3_fhargs(nfs_fh3 *, nfslog_READLINK3res *,
157*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
158*7c478bd9Sstevel@tonic-gate static void nfslog_READ3_fhargs(nfslog_READ3args *, nfslog_READ3res *,
159*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
160*7c478bd9Sstevel@tonic-gate static void nfslog_WRITE3_fhargs(nfslog_WRITE3args *, nfslog_WRITE3res *,
161*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
162*7c478bd9Sstevel@tonic-gate static void nfslog_CREATE3_fhargs(nfslog_CREATE3args *, nfslog_CREATE3res *,
163*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
164*7c478bd9Sstevel@tonic-gate static void nfslog_MKDIR3_fhargs(nfslog_MKDIR3args *, nfslog_MKDIR3res *,
165*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
166*7c478bd9Sstevel@tonic-gate static void nfslog_SYMLINK3_fhargs(nfslog_SYMLINK3args *, nfslog_SYMLINK3res *,
167*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
168*7c478bd9Sstevel@tonic-gate static void nfslog_MKNOD3_fhargs(nfslog_MKNOD3args *, nfslog_MKNOD3res *,
169*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
170*7c478bd9Sstevel@tonic-gate static void nfslog_REMOVE3_fhargs(nfslog_REMOVE3args *, nfsstat3 *,
171*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
172*7c478bd9Sstevel@tonic-gate static void nfslog_RMDIR3_fhargs(nfslog_RMDIR3args *, nfsstat3 *,
173*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
174*7c478bd9Sstevel@tonic-gate static void nfslog_RENAME3_fhargs(nfslog_RENAME3args *, nfsstat3 *,
175*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
176*7c478bd9Sstevel@tonic-gate static void nfslog_LINK3_fhargs(nfslog_LINK3args *, nfsstat3 *,
177*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
178*7c478bd9Sstevel@tonic-gate static void nfslog_READDIR3_fhargs(nfs_fh3 *, nfsstat3 *,
179*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
180*7c478bd9Sstevel@tonic-gate static void nfslog_READDIRPLUS3_fhargs(nfslog_READDIRPLUS3args *,
181*7c478bd9Sstevel@tonic-gate 	nfslog_READDIRPLUS3res *,
182*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
183*7c478bd9Sstevel@tonic-gate static void nfslog_FSSTAT3_fhargs(nfs_fh3 *, nfsstat3 *,
184*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
185*7c478bd9Sstevel@tonic-gate static void nfslog_FSINFO3_fhargs(nfs_fh3 *, nfsstat3 *,
186*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
187*7c478bd9Sstevel@tonic-gate static void nfslog_PATHCONF3_fhargs(nfs_fh3 *, nfsstat3 *,
188*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
189*7c478bd9Sstevel@tonic-gate static void nfslog_COMMIT3_fhargs(nfslog_COMMIT3args *, nfsstat3 *,
190*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
191*7c478bd9Sstevel@tonic-gate 
192*7c478bd9Sstevel@tonic-gate /*
193*7c478bd9Sstevel@tonic-gate  * NFSLOG VERSION 1
194*7c478bd9Sstevel@tonic-gate  *
195*7c478bd9Sstevel@tonic-gate  * Functions for updating the fhtable for fhtoppath
196*7c478bd9Sstevel@tonic-gate  */
197*7c478bd9Sstevel@tonic-gate static void nfslog_SHARE_fhargs(nfslog_sharefsargs *, nfslog_sharefsres *,
198*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
199*7c478bd9Sstevel@tonic-gate static void nfslog_UNSHARE_fhargs(nfslog_sharefsargs *, nfslog_sharefsres *,
200*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
201*7c478bd9Sstevel@tonic-gate static void nfslog_GETFH_fhargs(nfslog_getfhargs *, nfsstat *,
202*7c478bd9Sstevel@tonic-gate 	char *, char **, char **);
203*7c478bd9Sstevel@tonic-gate 
204*7c478bd9Sstevel@tonic-gate /*
205*7c478bd9Sstevel@tonic-gate  * Define the actions taken per prog/vers/proc:
206*7c478bd9Sstevel@tonic-gate  *
207*7c478bd9Sstevel@tonic-gate  * In some cases, the nl types are the same as the nfs types and a simple
208*7c478bd9Sstevel@tonic-gate  * bcopy should suffice. Rather that define tens of identical procedures,
209*7c478bd9Sstevel@tonic-gate  * simply define these to bcopy. Similarly this takes care of different
210*7c478bd9Sstevel@tonic-gate  * procs that use same parameter struct.
211*7c478bd9Sstevel@tonic-gate  */
212*7c478bd9Sstevel@tonic-gate 
213*7c478bd9Sstevel@tonic-gate static struct nfsl_fh_proc_disp nfsl_fh_proc_v2[] = {
214*7c478bd9Sstevel@tonic-gate 	/*
215*7c478bd9Sstevel@tonic-gate 	 * NFS VERSION 2
216*7c478bd9Sstevel@tonic-gate 	 */
217*7c478bd9Sstevel@tonic-gate 
218*7c478bd9Sstevel@tonic-gate 	/* RFS_NULL = 0 */
219*7c478bd9Sstevel@tonic-gate 	{nfslog_null_fhargs, xdr_void, xdr_void, 0, 0},
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate 	/* RFS_GETATTR = 1 */
222*7c478bd9Sstevel@tonic-gate 	{nfslog_GETATTR2_fhargs, xdr_fhandle, xdr_nfsstat,
223*7c478bd9Sstevel@tonic-gate 		sizeof (fhandle_t), sizeof (nfsstat)},
224*7c478bd9Sstevel@tonic-gate 
225*7c478bd9Sstevel@tonic-gate 	/* RFS_SETATTR = 2 */
226*7c478bd9Sstevel@tonic-gate 	{nfslog_SETATTR2_fhargs, xdr_nfslog_setattrargs, xdr_nfsstat,
227*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_setattrargs), sizeof (nfsstat)},
228*7c478bd9Sstevel@tonic-gate 
229*7c478bd9Sstevel@tonic-gate 	/* RFS_ROOT = 3 *** NO LONGER SUPPORTED *** */
230*7c478bd9Sstevel@tonic-gate 	{nfslog_null_fhargs, xdr_void, xdr_void, 0, 0},
231*7c478bd9Sstevel@tonic-gate 
232*7c478bd9Sstevel@tonic-gate 	/* RFS_LOOKUP = 4 */
233*7c478bd9Sstevel@tonic-gate 	{nfslog_LOOKUP2_fhargs, xdr_nfslog_diropargs, xdr_nfslog_diropres,
234*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_diropargs), sizeof (nfslog_diropres)},
235*7c478bd9Sstevel@tonic-gate 
236*7c478bd9Sstevel@tonic-gate 	/* RFS_READLINK = 5 */
237*7c478bd9Sstevel@tonic-gate 	{nfslog_READLINK2_fhargs, xdr_fhandle, xdr_nfslog_rdlnres,
238*7c478bd9Sstevel@tonic-gate 		sizeof (fhandle_t), sizeof (nfslog_rdlnres)},
239*7c478bd9Sstevel@tonic-gate 
240*7c478bd9Sstevel@tonic-gate 	/* RFS_READ = 6 */
241*7c478bd9Sstevel@tonic-gate 	{nfslog_READ2_fhargs, xdr_nfslog_nfsreadargs, xdr_nfslog_rdresult,
242*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_nfsreadargs), sizeof (nfslog_rdresult)},
243*7c478bd9Sstevel@tonic-gate 
244*7c478bd9Sstevel@tonic-gate 	/* RFS_WRITECACHE = 7 *** NO LONGER SUPPORTED *** */
245*7c478bd9Sstevel@tonic-gate 	{nfslog_null_fhargs, xdr_void, xdr_void, 0, 0},
246*7c478bd9Sstevel@tonic-gate 
247*7c478bd9Sstevel@tonic-gate 	/* RFS_WRITE = 8 */
248*7c478bd9Sstevel@tonic-gate 	{nfslog_WRITE2_fhargs, xdr_nfslog_writeargs, xdr_nfslog_writeresult,
249*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_writeargs), sizeof (nfslog_writeresult)},
250*7c478bd9Sstevel@tonic-gate 
251*7c478bd9Sstevel@tonic-gate 	/* RFS_CREATE = 9 */
252*7c478bd9Sstevel@tonic-gate 	{nfslog_CREATE2_fhargs, xdr_nfslog_createargs, xdr_nfslog_diropres,
253*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_createargs), sizeof (nfslog_diropres)},
254*7c478bd9Sstevel@tonic-gate 
255*7c478bd9Sstevel@tonic-gate 	/* RFS_REMOVE = 10 */
256*7c478bd9Sstevel@tonic-gate 	{nfslog_REMOVE2_fhargs, xdr_nfslog_diropargs, xdr_nfsstat,
257*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_diropargs), sizeof (nfsstat)},
258*7c478bd9Sstevel@tonic-gate 
259*7c478bd9Sstevel@tonic-gate 	/* RFS_RENAME = 11 */
260*7c478bd9Sstevel@tonic-gate 	{nfslog_RENAME2_fhargs, xdr_nfslog_rnmargs, xdr_nfsstat,
261*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_rnmargs), sizeof (nfsstat)},
262*7c478bd9Sstevel@tonic-gate 
263*7c478bd9Sstevel@tonic-gate 	/* RFS_LINK = 12 */
264*7c478bd9Sstevel@tonic-gate 	{nfslog_LINK2_fhargs, xdr_nfslog_linkargs, xdr_nfsstat,
265*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_linkargs), sizeof (nfsstat)},
266*7c478bd9Sstevel@tonic-gate 
267*7c478bd9Sstevel@tonic-gate 	/* RFS_SYMLINK = 13 */
268*7c478bd9Sstevel@tonic-gate 	{nfslog_SYMLINK2_fhargs, xdr_nfslog_symlinkargs, xdr_nfsstat,
269*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_symlinkargs), sizeof (nfsstat)},
270*7c478bd9Sstevel@tonic-gate 
271*7c478bd9Sstevel@tonic-gate 	/* RFS_MKDIR = 14 */
272*7c478bd9Sstevel@tonic-gate 	{nfslog_CREATE2_fhargs, xdr_nfslog_createargs, xdr_nfslog_diropres,
273*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_createargs), sizeof (nfslog_diropres)},
274*7c478bd9Sstevel@tonic-gate 
275*7c478bd9Sstevel@tonic-gate 	/* RFS_RMDIR = 15 */
276*7c478bd9Sstevel@tonic-gate 	{nfslog_REMOVE2_fhargs, xdr_nfslog_diropargs, xdr_nfsstat,
277*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_diropargs), sizeof (nfsstat)},
278*7c478bd9Sstevel@tonic-gate 
279*7c478bd9Sstevel@tonic-gate 	/* RFS_READDIR = 16 */
280*7c478bd9Sstevel@tonic-gate 	{nfslog_READDIR2_fhargs, xdr_nfslog_rddirargs, xdr_nfslog_rddirres,
281*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_rddirargs), sizeof (nfslog_rddirres)},
282*7c478bd9Sstevel@tonic-gate 
283*7c478bd9Sstevel@tonic-gate 	/* RFS_STATFS = 17 */
284*7c478bd9Sstevel@tonic-gate 	{nfslog_STATFS2_fhargs, xdr_fhandle, xdr_nfsstat,
285*7c478bd9Sstevel@tonic-gate 		sizeof (fhandle_t), sizeof (nfsstat)},
286*7c478bd9Sstevel@tonic-gate };
287*7c478bd9Sstevel@tonic-gate 
288*7c478bd9Sstevel@tonic-gate 
289*7c478bd9Sstevel@tonic-gate /*
290*7c478bd9Sstevel@tonic-gate  * NFS VERSION 3
291*7c478bd9Sstevel@tonic-gate  */
292*7c478bd9Sstevel@tonic-gate 
293*7c478bd9Sstevel@tonic-gate static struct nfsl_fh_proc_disp nfsl_fh_proc_v3[] = {
294*7c478bd9Sstevel@tonic-gate 
295*7c478bd9Sstevel@tonic-gate 	/* RFS_NULL = 0 */
296*7c478bd9Sstevel@tonic-gate 	{nfslog_null_fhargs, xdr_void, xdr_void, 0, 0},
297*7c478bd9Sstevel@tonic-gate 
298*7c478bd9Sstevel@tonic-gate 	/* RFS3_GETATTR = 1 */
299*7c478bd9Sstevel@tonic-gate 	{nfslog_GETATTR3_fhargs, xdr_nfs_fh3, xdr_nfsstat3,
300*7c478bd9Sstevel@tonic-gate 		sizeof (nfs_fh3), sizeof (nfsstat3)},
301*7c478bd9Sstevel@tonic-gate 
302*7c478bd9Sstevel@tonic-gate 	/* RFS3_SETATTR = 2 */
303*7c478bd9Sstevel@tonic-gate 	{nfslog_SETATTR3_fhargs, xdr_nfslog_SETATTR3args, xdr_nfsstat3,
304*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_SETATTR3args), sizeof (nfsstat3)},
305*7c478bd9Sstevel@tonic-gate 
306*7c478bd9Sstevel@tonic-gate 	/* RFS3_LOOKUP = 3 */
307*7c478bd9Sstevel@tonic-gate 	{nfslog_LOOKUP3_fhargs, xdr_nfslog_diropargs3, xdr_nfslog_LOOKUP3res,
308*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_diropargs3), sizeof (nfslog_LOOKUP3res)},
309*7c478bd9Sstevel@tonic-gate 
310*7c478bd9Sstevel@tonic-gate 	/* RFS3_ACCESS = 4 */
311*7c478bd9Sstevel@tonic-gate 	{nfslog_ACCESS3_fhargs, xdr_nfs_fh3, xdr_nfsstat3,
312*7c478bd9Sstevel@tonic-gate 		sizeof (nfs_fh3), sizeof (nfsstat3)},
313*7c478bd9Sstevel@tonic-gate 
314*7c478bd9Sstevel@tonic-gate 	/* RFS3_READLINK = 5 */
315*7c478bd9Sstevel@tonic-gate 	{nfslog_READLINK3_fhargs, xdr_nfs_fh3, xdr_nfslog_READLINK3res,
316*7c478bd9Sstevel@tonic-gate 		sizeof (nfs_fh3), sizeof (nfslog_READLINK3res)},
317*7c478bd9Sstevel@tonic-gate 
318*7c478bd9Sstevel@tonic-gate 	/* RFS3_READ = 6 */
319*7c478bd9Sstevel@tonic-gate 	{nfslog_READ3_fhargs, xdr_nfslog_READ3args, xdr_nfslog_READ3res,
320*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_READ3args), sizeof (nfslog_READ3res)},
321*7c478bd9Sstevel@tonic-gate 
322*7c478bd9Sstevel@tonic-gate 	/* RFS3_WRITE = 7 */
323*7c478bd9Sstevel@tonic-gate 	{nfslog_WRITE3_fhargs, xdr_nfslog_WRITE3args, xdr_nfslog_WRITE3res,
324*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_WRITE3args), sizeof (nfslog_WRITE3res)},
325*7c478bd9Sstevel@tonic-gate 
326*7c478bd9Sstevel@tonic-gate 	/* RFS3_CREATE = 8 */
327*7c478bd9Sstevel@tonic-gate 	{nfslog_CREATE3_fhargs, xdr_nfslog_CREATE3args, xdr_nfslog_CREATE3res,
328*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_CREATE3args), sizeof (nfslog_CREATE3res)},
329*7c478bd9Sstevel@tonic-gate 
330*7c478bd9Sstevel@tonic-gate 	/* RFS3_MKDIR = 9 */
331*7c478bd9Sstevel@tonic-gate 	{nfslog_MKDIR3_fhargs, xdr_nfslog_MKDIR3args, xdr_nfslog_MKDIR3res,
332*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_MKDIR3args), sizeof (nfslog_MKDIR3res)},
333*7c478bd9Sstevel@tonic-gate 
334*7c478bd9Sstevel@tonic-gate 	/* RFS3_SYMLINK = 10 */
335*7c478bd9Sstevel@tonic-gate 	{nfslog_SYMLINK3_fhargs, xdr_nfslog_SYMLINK3args,
336*7c478bd9Sstevel@tonic-gate 		xdr_nfslog_SYMLINK3res,
337*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_SYMLINK3args), sizeof (nfslog_SYMLINK3res)},
338*7c478bd9Sstevel@tonic-gate 
339*7c478bd9Sstevel@tonic-gate 	/* RFS3_MKNOD = 11 */
340*7c478bd9Sstevel@tonic-gate 	{nfslog_MKNOD3_fhargs, xdr_nfslog_MKNOD3args, xdr_nfslog_MKNOD3res,
341*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_MKNOD3args), sizeof (nfslog_MKNOD3res)},
342*7c478bd9Sstevel@tonic-gate 
343*7c478bd9Sstevel@tonic-gate 	/* RFS3_REMOVE = 12 */
344*7c478bd9Sstevel@tonic-gate 	{nfslog_REMOVE3_fhargs, xdr_nfslog_REMOVE3args, xdr_nfsstat3,
345*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_REMOVE3args), sizeof (nfsstat3)},
346*7c478bd9Sstevel@tonic-gate 
347*7c478bd9Sstevel@tonic-gate 	/* RFS3_RMDIR = 13 */
348*7c478bd9Sstevel@tonic-gate 	{nfslog_RMDIR3_fhargs, xdr_nfslog_RMDIR3args, xdr_nfsstat3,
349*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_RMDIR3args), sizeof (nfsstat3)},
350*7c478bd9Sstevel@tonic-gate 
351*7c478bd9Sstevel@tonic-gate 	/* RFS3_RENAME = 14 */
352*7c478bd9Sstevel@tonic-gate 	{nfslog_RENAME3_fhargs, xdr_nfslog_RENAME3args, xdr_nfsstat3,
353*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_RENAME3args), sizeof (nfsstat3)},
354*7c478bd9Sstevel@tonic-gate 
355*7c478bd9Sstevel@tonic-gate 	/* RFS3_LINK = 15 */
356*7c478bd9Sstevel@tonic-gate 	{nfslog_LINK3_fhargs, xdr_nfslog_LINK3args, xdr_nfsstat3,
357*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_LINK3args), sizeof (nfsstat3)},
358*7c478bd9Sstevel@tonic-gate 
359*7c478bd9Sstevel@tonic-gate 	/* RFS3_READDIR = 16 */
360*7c478bd9Sstevel@tonic-gate 	{nfslog_READDIR3_fhargs, xdr_nfs_fh3, xdr_nfsstat3,
361*7c478bd9Sstevel@tonic-gate 		sizeof (nfs_fh3), sizeof (nfsstat3)},
362*7c478bd9Sstevel@tonic-gate 
363*7c478bd9Sstevel@tonic-gate 	/* RFS3_READDIRPLUS = 17 */
364*7c478bd9Sstevel@tonic-gate 	{nfslog_READDIRPLUS3_fhargs,
365*7c478bd9Sstevel@tonic-gate 		xdr_nfslog_READDIRPLUS3args, xdr_nfslog_READDIRPLUS3res,
366*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_READDIRPLUS3args),
367*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_READDIRPLUS3res)},
368*7c478bd9Sstevel@tonic-gate 
369*7c478bd9Sstevel@tonic-gate 	/* RFS3_FSSTAT = 18 */
370*7c478bd9Sstevel@tonic-gate 	{nfslog_FSSTAT3_fhargs, xdr_nfs_fh3, xdr_nfsstat3,
371*7c478bd9Sstevel@tonic-gate 		sizeof (nfs_fh3), sizeof (nfsstat3)},
372*7c478bd9Sstevel@tonic-gate 
373*7c478bd9Sstevel@tonic-gate 	/* RFS3_FSINFO = 19 */
374*7c478bd9Sstevel@tonic-gate 	{nfslog_FSINFO3_fhargs, xdr_nfs_fh3, xdr_nfsstat3,
375*7c478bd9Sstevel@tonic-gate 		sizeof (nfs_fh3), sizeof (nfsstat3)},
376*7c478bd9Sstevel@tonic-gate 
377*7c478bd9Sstevel@tonic-gate 	/* RFS3_PATHCONF = 20 */
378*7c478bd9Sstevel@tonic-gate 	{nfslog_PATHCONF3_fhargs, xdr_nfs_fh3, xdr_nfsstat3,
379*7c478bd9Sstevel@tonic-gate 		sizeof (nfs_fh3), sizeof (nfsstat3)},
380*7c478bd9Sstevel@tonic-gate 
381*7c478bd9Sstevel@tonic-gate 	/* RFS3_COMMIT = 21 */
382*7c478bd9Sstevel@tonic-gate 	{nfslog_COMMIT3_fhargs, xdr_nfslog_COMMIT3args, xdr_nfsstat3,
383*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_COMMIT3args), sizeof (nfsstat3)},
384*7c478bd9Sstevel@tonic-gate };
385*7c478bd9Sstevel@tonic-gate 
386*7c478bd9Sstevel@tonic-gate /*
387*7c478bd9Sstevel@tonic-gate  * NFSLOG VERSION 1
388*7c478bd9Sstevel@tonic-gate  */
389*7c478bd9Sstevel@tonic-gate 
390*7c478bd9Sstevel@tonic-gate static struct nfsl_fh_proc_disp nfsl_log_fh_proc_v1[] = {
391*7c478bd9Sstevel@tonic-gate 
392*7c478bd9Sstevel@tonic-gate 	/* NFSLOG_NULL = 0 */
393*7c478bd9Sstevel@tonic-gate 	{nfslog_null_fhargs, xdr_void, xdr_void, 0, 0},
394*7c478bd9Sstevel@tonic-gate 
395*7c478bd9Sstevel@tonic-gate 	/* NFSLOG_SHARE = 1 */
396*7c478bd9Sstevel@tonic-gate 	{nfslog_SHARE_fhargs, xdr_nfslog_sharefsargs, xdr_nfslog_sharefsres,
397*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_sharefsargs), sizeof (nfslog_sharefsres)},
398*7c478bd9Sstevel@tonic-gate 
399*7c478bd9Sstevel@tonic-gate 	/* NFSLOG_UNSHARE = 2 */
400*7c478bd9Sstevel@tonic-gate 	{nfslog_UNSHARE_fhargs, xdr_nfslog_sharefsargs, xdr_nfslog_sharefsres,
401*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_sharefsargs), sizeof (nfslog_sharefsres)},
402*7c478bd9Sstevel@tonic-gate 
403*7c478bd9Sstevel@tonic-gate 	/* NFSLOG_LOOKUP3 = 3 */
404*7c478bd9Sstevel@tonic-gate 	{nfslog_LOOKUP3_fhargs, xdr_nfslog_diropargs3, xdr_nfslog_LOOKUP3res,
405*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_diropargs3), sizeof (nfslog_LOOKUP3res)},
406*7c478bd9Sstevel@tonic-gate 
407*7c478bd9Sstevel@tonic-gate 	/* NFSLOG_GETFH = 4 */
408*7c478bd9Sstevel@tonic-gate 	{nfslog_GETFH_fhargs, xdr_nfslog_getfhargs, xdr_nfsstat,
409*7c478bd9Sstevel@tonic-gate 		sizeof (nfslog_getfhargs), sizeof (nfsstat)},
410*7c478bd9Sstevel@tonic-gate };
411*7c478bd9Sstevel@tonic-gate 
412*7c478bd9Sstevel@tonic-gate static struct nfsl_fh_vers_disp nfsl_fh_vers_disptable[] = {
413*7c478bd9Sstevel@tonic-gate 	{sizeof (nfsl_fh_proc_v2) / sizeof (nfsl_fh_proc_v2[0]),
414*7c478bd9Sstevel@tonic-gate 	    nfsl_fh_proc_v2},
415*7c478bd9Sstevel@tonic-gate 	{sizeof (nfsl_fh_proc_v3) / sizeof (nfsl_fh_proc_v3[0]),
416*7c478bd9Sstevel@tonic-gate 	    nfsl_fh_proc_v3},
417*7c478bd9Sstevel@tonic-gate };
418*7c478bd9Sstevel@tonic-gate 
419*7c478bd9Sstevel@tonic-gate static struct nfsl_fh_vers_disp nfsl_log_fh_vers_disptable[] = {
420*7c478bd9Sstevel@tonic-gate 	{sizeof (nfsl_log_fh_proc_v1) / sizeof (nfsl_log_fh_proc_v1[0]),
421*7c478bd9Sstevel@tonic-gate 	    nfsl_log_fh_proc_v1},
422*7c478bd9Sstevel@tonic-gate };
423*7c478bd9Sstevel@tonic-gate 
424*7c478bd9Sstevel@tonic-gate static struct nfsl_fh_prog_disp nfsl_fh_dispatch_table[] = {
425*7c478bd9Sstevel@tonic-gate 	{NFS_PROGRAM,
426*7c478bd9Sstevel@tonic-gate 	    NFS_VERSMIN,
427*7c478bd9Sstevel@tonic-gate 	    sizeof (nfsl_fh_vers_disptable) /
428*7c478bd9Sstevel@tonic-gate 		sizeof (nfsl_fh_vers_disptable[0]),
429*7c478bd9Sstevel@tonic-gate 	    nfsl_fh_vers_disptable},
430*7c478bd9Sstevel@tonic-gate 	{NFSLOG_PROGRAM,
431*7c478bd9Sstevel@tonic-gate 	    NFSLOG_VERSMIN,
432*7c478bd9Sstevel@tonic-gate 	    sizeof (nfsl_log_fh_vers_disptable) /
433*7c478bd9Sstevel@tonic-gate 		sizeof (nfsl_log_fh_vers_disptable[0]),
434*7c478bd9Sstevel@tonic-gate 	    nfsl_log_fh_vers_disptable},
435*7c478bd9Sstevel@tonic-gate };
436*7c478bd9Sstevel@tonic-gate 
437*7c478bd9Sstevel@tonic-gate static int	nfsl_fh_dispatch_table_arglen =
438*7c478bd9Sstevel@tonic-gate 			sizeof (nfsl_fh_dispatch_table) /
439*7c478bd9Sstevel@tonic-gate 			sizeof (nfsl_fh_dispatch_table[0]);
440*7c478bd9Sstevel@tonic-gate 
441*7c478bd9Sstevel@tonic-gate extern int debug;
442*7c478bd9Sstevel@tonic-gate 
443*7c478bd9Sstevel@tonic-gate /*
444*7c478bd9Sstevel@tonic-gate  * print the fid into the given string as a series of hex digits.
445*7c478bd9Sstevel@tonic-gate  * XXX Ideally, we'd like to just convert the filehandle into an i-number,
446*7c478bd9Sstevel@tonic-gate  * but the fid encoding is a little tricky (see nfs_fhtovp() and
447*7c478bd9Sstevel@tonic-gate  * ufs_vget()) and may be private to UFS.
448*7c478bd9Sstevel@tonic-gate  */
449*7c478bd9Sstevel@tonic-gate 
450*7c478bd9Sstevel@tonic-gate static void
sprint_fid(char * buf,uint_t buflen,const fhandle_t * fh)451*7c478bd9Sstevel@tonic-gate sprint_fid(char *buf, uint_t buflen, const fhandle_t *fh)
452*7c478bd9Sstevel@tonic-gate {
453*7c478bd9Sstevel@tonic-gate 	int i;
454*7c478bd9Sstevel@tonic-gate 	uchar_t byte;
455*7c478bd9Sstevel@tonic-gate 	uint_t fhlen;
456*7c478bd9Sstevel@tonic-gate 
457*7c478bd9Sstevel@tonic-gate 	/*
458*7c478bd9Sstevel@tonic-gate 	 * If the filehandle somehow got corrupted, only print the part
459*7c478bd9Sstevel@tonic-gate 	 * that makes sense.
460*7c478bd9Sstevel@tonic-gate 	 */
461*7c478bd9Sstevel@tonic-gate 	if (fh->fh_len > NFS_FHMAXDATA)
462*7c478bd9Sstevel@tonic-gate 		fhlen = NFS_FHMAXDATA;
463*7c478bd9Sstevel@tonic-gate 	else
464*7c478bd9Sstevel@tonic-gate 		fhlen = fh->fh_len;
465*7c478bd9Sstevel@tonic-gate 	assert(2 * fhlen < buflen);
466*7c478bd9Sstevel@tonic-gate 
467*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < fhlen; i++) {
468*7c478bd9Sstevel@tonic-gate 		byte = fh->fh_data[i];
469*7c478bd9Sstevel@tonic-gate 		(void) sprintf(buf + 2 * i, "%02x", byte);
470*7c478bd9Sstevel@tonic-gate 	}
471*7c478bd9Sstevel@tonic-gate }
472*7c478bd9Sstevel@tonic-gate 
473*7c478bd9Sstevel@tonic-gate static void
fh_print_all_keys(char * fhpath,fhandle_t * fh)474*7c478bd9Sstevel@tonic-gate fh_print_all_keys(char *fhpath, fhandle_t *fh)
475*7c478bd9Sstevel@tonic-gate {
476*7c478bd9Sstevel@tonic-gate 	if ((fhpath == NULL) || (fh == NULL) || (debug <= 1))
477*7c478bd9Sstevel@tonic-gate 		return;
478*7c478bd9Sstevel@tonic-gate 	(void) printf("\nBegin all database keys\n");
479*7c478bd9Sstevel@tonic-gate 	db_print_all_keys(fhpath, &fh->fh_fsid, stdout);
480*7c478bd9Sstevel@tonic-gate 	(void) printf("\nEnd   all database keys\n");
481*7c478bd9Sstevel@tonic-gate }
482*7c478bd9Sstevel@tonic-gate 
483*7c478bd9Sstevel@tonic-gate #define	FH_ADD(path, dfh, fh, name) \
484*7c478bd9Sstevel@tonic-gate 	fh_add(path, dfh, fh, name)
485*7c478bd9Sstevel@tonic-gate 
486*7c478bd9Sstevel@tonic-gate /*
487*7c478bd9Sstevel@tonic-gate  * Add the filehandle "fh", which has the name "name" and lives in
488*7c478bd9Sstevel@tonic-gate  * directory "dfh", to the table "fhlist".  "fhlist" will be updated if the
489*7c478bd9Sstevel@tonic-gate  * entry is added to the front of the list.
490*7c478bd9Sstevel@tonic-gate  * Return 0 for success, error code otherwise.
491*7c478bd9Sstevel@tonic-gate  */
492*7c478bd9Sstevel@tonic-gate static int
fh_add(char * fhpath,fhandle_t * dfh,fhandle_t * fh,char * name)493*7c478bd9Sstevel@tonic-gate fh_add(char *fhpath, fhandle_t *dfh, fhandle_t *fh, char *name)
494*7c478bd9Sstevel@tonic-gate {
495*7c478bd9Sstevel@tonic-gate 	uint_t	flags = 0;
496*7c478bd9Sstevel@tonic-gate 	int	error;
497*7c478bd9Sstevel@tonic-gate 
498*7c478bd9Sstevel@tonic-gate 	if (IS_DOT_FILENAME(name)) {
499*7c478bd9Sstevel@tonic-gate 		/* we don't insert these to the database but not an error */
500*7c478bd9Sstevel@tonic-gate 		if (debug > 3) {
501*7c478bd9Sstevel@tonic-gate 			PRINT_FULL_DATA(stdout, "fh_add", dfh, fh, name,
502*7c478bd9Sstevel@tonic-gate 				" - no dot files")
503*7c478bd9Sstevel@tonic-gate 		}
504*7c478bd9Sstevel@tonic-gate 		return (0);
505*7c478bd9Sstevel@tonic-gate 	}
506*7c478bd9Sstevel@tonic-gate 	if (dfh && (memcmp(fh, dfh, NFS_FHSIZE) == 0)) {
507*7c478bd9Sstevel@tonic-gate 		flags |= EXPORT_POINT;
508*7c478bd9Sstevel@tonic-gate 	}
509*7c478bd9Sstevel@tonic-gate 
510*7c478bd9Sstevel@tonic-gate 	/* Add to database */
511*7c478bd9Sstevel@tonic-gate 	error = db_add(fhpath, dfh, name, fh, flags);
512*7c478bd9Sstevel@tonic-gate 	if (debug > 1) {
513*7c478bd9Sstevel@tonic-gate 		if (error != 0) {
514*7c478bd9Sstevel@tonic-gate 			(void) printf("db_add error %s:\n",
515*7c478bd9Sstevel@tonic-gate 				((error >= 0) ? strerror(error) : "Unknown"));
516*7c478bd9Sstevel@tonic-gate 			PRINT_FULL_DATA(stdout, "fh_add", dfh, fh, name, "")
517*7c478bd9Sstevel@tonic-gate 		} else if (debug > 2) {
518*7c478bd9Sstevel@tonic-gate 			PRINT_FULL_DATA(stdout, "fh_add", dfh, fh, name, "")
519*7c478bd9Sstevel@tonic-gate 		}
520*7c478bd9Sstevel@tonic-gate 	}
521*7c478bd9Sstevel@tonic-gate 	return (error);
522*7c478bd9Sstevel@tonic-gate }
523*7c478bd9Sstevel@tonic-gate 
524*7c478bd9Sstevel@tonic-gate /*
525*7c478bd9Sstevel@tonic-gate  * fh_compare returns 0 if the file handles match, error code otherwise
526*7c478bd9Sstevel@tonic-gate  */
527*7c478bd9Sstevel@tonic-gate static int
fh_compare(fhandle_t * fh1,fhandle_t * fh2)528*7c478bd9Sstevel@tonic-gate fh_compare(fhandle_t *fh1, fhandle_t *fh2)
529*7c478bd9Sstevel@tonic-gate {
530*7c478bd9Sstevel@tonic-gate 	if (memcmp(fh1, fh2, NFS_FHSIZE))
531*7c478bd9Sstevel@tonic-gate 		return (errno);
532*7c478bd9Sstevel@tonic-gate 	else
533*7c478bd9Sstevel@tonic-gate 		return (0);
534*7c478bd9Sstevel@tonic-gate }
535*7c478bd9Sstevel@tonic-gate 
536*7c478bd9Sstevel@tonic-gate /*
537*7c478bd9Sstevel@tonic-gate  * Try to find the filehandle "fh" in the table.  Returns 0 and the
538*7c478bd9Sstevel@tonic-gate  * corresponding table entry if found, error otherwise.
539*7c478bd9Sstevel@tonic-gate  * If successfull and fhrecpp is non-null then *fhrecpp points to the
540*7c478bd9Sstevel@tonic-gate  * returned record. If *fhrecpp was initially null, that record had
541*7c478bd9Sstevel@tonic-gate  * been malloc'd and must be freed by caller.
542*7c478bd9Sstevel@tonic-gate  */
543*7c478bd9Sstevel@tonic-gate 
544*7c478bd9Sstevel@tonic-gate static fhlist_ent *
fh_lookup(char * fhpath,fhandle_t * fh,fhlist_ent * fhrecp,int * errorp)545*7c478bd9Sstevel@tonic-gate fh_lookup(char *fhpath, fhandle_t *fh, fhlist_ent *fhrecp, int *errorp)
546*7c478bd9Sstevel@tonic-gate {
547*7c478bd9Sstevel@tonic-gate 	if (debug > 3) {
548*7c478bd9Sstevel@tonic-gate 		(void) printf("fh_lookup: fh ");
549*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, fh, sizeof (*fh));
550*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
551*7c478bd9Sstevel@tonic-gate 	}
552*7c478bd9Sstevel@tonic-gate 	return (db_lookup(fhpath, fh, fhrecp, errorp));
553*7c478bd9Sstevel@tonic-gate }
554*7c478bd9Sstevel@tonic-gate 
555*7c478bd9Sstevel@tonic-gate /*
556*7c478bd9Sstevel@tonic-gate  * Remove the mc link if exists when removing a regular link.
557*7c478bd9Sstevel@tonic-gate  * Return 0 for success, error code otherwise.
558*7c478bd9Sstevel@tonic-gate  */
559*7c478bd9Sstevel@tonic-gate static int
fh_remove_mc_link(char * fhpath,fhandle_t * dfh,char * name,char ** pathp)560*7c478bd9Sstevel@tonic-gate fh_remove_mc_link(char *fhpath, fhandle_t *dfh, char *name, char **pathp)
561*7c478bd9Sstevel@tonic-gate {
562*7c478bd9Sstevel@tonic-gate 	int	error;
563*7c478bd9Sstevel@tonic-gate 	char	*str, *str1;
564*7c478bd9Sstevel@tonic-gate 
565*7c478bd9Sstevel@tonic-gate 	/* Delete the multi-component path if exists */
566*7c478bd9Sstevel@tonic-gate 	if ((pathp == NULL) || (*pathp == NULL)) {
567*7c478bd9Sstevel@tonic-gate 		str = nfslog_get_path(dfh, name, fhpath, "remove_mc_link");
568*7c478bd9Sstevel@tonic-gate 		str1 = str;
569*7c478bd9Sstevel@tonic-gate 	} else {
570*7c478bd9Sstevel@tonic-gate 		str = *pathp;
571*7c478bd9Sstevel@tonic-gate 		str1 = NULL;
572*7c478bd9Sstevel@tonic-gate 	}
573*7c478bd9Sstevel@tonic-gate 	error = db_delete_link(fhpath, &public_fh, str);
574*7c478bd9Sstevel@tonic-gate 	if (str1 != NULL)
575*7c478bd9Sstevel@tonic-gate 		free(str1);
576*7c478bd9Sstevel@tonic-gate 	return (error);
577*7c478bd9Sstevel@tonic-gate }
578*7c478bd9Sstevel@tonic-gate 
579*7c478bd9Sstevel@tonic-gate /*
580*7c478bd9Sstevel@tonic-gate  * Remove the link entry from the fh table.
581*7c478bd9Sstevel@tonic-gate  * Return 0 for success, error code otherwise.
582*7c478bd9Sstevel@tonic-gate  */
583*7c478bd9Sstevel@tonic-gate static int
fh_remove(char * fhpath,fhandle_t * dfh,char * name,char ** pathp)584*7c478bd9Sstevel@tonic-gate fh_remove(char *fhpath, fhandle_t *dfh, char *name, char **pathp)
585*7c478bd9Sstevel@tonic-gate {
586*7c478bd9Sstevel@tonic-gate 	/*
587*7c478bd9Sstevel@tonic-gate 	 * disconnect element from list
588*7c478bd9Sstevel@tonic-gate 	 *
589*7c478bd9Sstevel@tonic-gate 	 * Remove the link entry for the file. Remove fh entry if last link.
590*7c478bd9Sstevel@tonic-gate 	 */
591*7c478bd9Sstevel@tonic-gate 	if (IS_DOT_FILENAME(name)) {
592*7c478bd9Sstevel@tonic-gate 		/* we don't insert these to the database but not an error */
593*7c478bd9Sstevel@tonic-gate 		if (debug > 2) {
594*7c478bd9Sstevel@tonic-gate 			PRINT_LINK_DATA(stdout, "fh_remove", dfh, name,
595*7c478bd9Sstevel@tonic-gate 				" - no dot files")
596*7c478bd9Sstevel@tonic-gate 		}
597*7c478bd9Sstevel@tonic-gate 		return (0);
598*7c478bd9Sstevel@tonic-gate 	}
599*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
600*7c478bd9Sstevel@tonic-gate 		PRINT_LINK_DATA(stdout, "fh_remove", dfh, name, "")
601*7c478bd9Sstevel@tonic-gate 	}
602*7c478bd9Sstevel@tonic-gate 	/* Delete the multi-component path if exists */
603*7c478bd9Sstevel@tonic-gate 	(void) fh_remove_mc_link(fhpath, dfh, name, pathp);
604*7c478bd9Sstevel@tonic-gate 	return (db_delete_link(fhpath, dfh, name));
605*7c478bd9Sstevel@tonic-gate }
606*7c478bd9Sstevel@tonic-gate 
607*7c478bd9Sstevel@tonic-gate /*
608*7c478bd9Sstevel@tonic-gate  * fh_rename - renames a link in the database (adds the new one if from link
609*7c478bd9Sstevel@tonic-gate  * did not exist).
610*7c478bd9Sstevel@tonic-gate  * Return 0 for success, error code otherwise.
611*7c478bd9Sstevel@tonic-gate  */
612*7c478bd9Sstevel@tonic-gate static int
fh_rename(char * fhpath,fhandle_t * from_dfh,char * from_name,char ** from_pathp,fhandle_t * to_dfh,char * to_name)613*7c478bd9Sstevel@tonic-gate fh_rename(char *fhpath, fhandle_t *from_dfh, char *from_name, char **from_pathp,
614*7c478bd9Sstevel@tonic-gate 	fhandle_t *to_dfh, char *to_name)
615*7c478bd9Sstevel@tonic-gate {
616*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
617*7c478bd9Sstevel@tonic-gate 		PRINT_LINK_DATA(stdout, "fh_rename: from:", from_dfh,
618*7c478bd9Sstevel@tonic-gate 		    from_name, "")
619*7c478bd9Sstevel@tonic-gate 		PRINT_LINK_DATA(stdout, "fh_rename: to  :", to_dfh,
620*7c478bd9Sstevel@tonic-gate 		    to_name, "")
621*7c478bd9Sstevel@tonic-gate 	}
622*7c478bd9Sstevel@tonic-gate 	/*
623*7c478bd9Sstevel@tonic-gate 	 * if any of these are dot files (should not happen), the rename
624*7c478bd9Sstevel@tonic-gate 	 * becomes a "delete" or "add" operation because the dot files
625*7c478bd9Sstevel@tonic-gate 	 * don't get in the database
626*7c478bd9Sstevel@tonic-gate 	 */
627*7c478bd9Sstevel@tonic-gate 	if (IS_DOT_FILENAME(to_name)) {
628*7c478bd9Sstevel@tonic-gate 		/* it is just a delete op */
629*7c478bd9Sstevel@tonic-gate 		if (debug > 2) {
630*7c478bd9Sstevel@tonic-gate 			(void) printf("to: no dot files\nDelete from: '%s'\n",
631*7c478bd9Sstevel@tonic-gate 				from_name);
632*7c478bd9Sstevel@tonic-gate 		}
633*7c478bd9Sstevel@tonic-gate 		return (fh_remove(fhpath, from_dfh, from_name, from_pathp));
634*7c478bd9Sstevel@tonic-gate 	} else if (IS_DOT_FILENAME(from_name)) {
635*7c478bd9Sstevel@tonic-gate 		/* we don't insert these to the database */
636*7c478bd9Sstevel@tonic-gate 		if (debug > 2) {
637*7c478bd9Sstevel@tonic-gate 			(void) printf("rename - from: no dot files\n");
638*7c478bd9Sstevel@tonic-gate 		}
639*7c478bd9Sstevel@tonic-gate 		/* can't insert the target, because don't have a handle */
640*7c478bd9Sstevel@tonic-gate 		return (EINVAL);
641*7c478bd9Sstevel@tonic-gate 	}
642*7c478bd9Sstevel@tonic-gate 	/* Delete the multi-component path if exists */
643*7c478bd9Sstevel@tonic-gate 	(void) fh_remove_mc_link(fhpath, from_dfh, from_name, from_pathp);
644*7c478bd9Sstevel@tonic-gate 	return (db_rename_link(fhpath, from_dfh, from_name, to_dfh, to_name));
645*7c478bd9Sstevel@tonic-gate }
646*7c478bd9Sstevel@tonic-gate 
647*7c478bd9Sstevel@tonic-gate /*
648*7c478bd9Sstevel@tonic-gate  * fh_lookup_link - search the fhtable for the link defined by (dfh,name,fh).
649*7c478bd9Sstevel@tonic-gate  * Return 0 and set *fhrecpp to the fhlist item corresponding to it if found,
650*7c478bd9Sstevel@tonic-gate  * or error if not found.
651*7c478bd9Sstevel@tonic-gate  * Possible configurations:
652*7c478bd9Sstevel@tonic-gate  * 1. dfh, fh, name are all non-null: Only exact match accepted.
653*7c478bd9Sstevel@tonic-gate  * 2. dfh,name non-null, fh null: return first match found.
654*7c478bd9Sstevel@tonic-gate  * 3. fh,name non-null, dfh null: return first match found.
655*7c478bd9Sstevel@tonic-gate  * 3. fh non-null, dfh, name null: return first match found.
656*7c478bd9Sstevel@tonic-gate  * If successfull and fhrecpp is non-null then *fhrecpp points to the
657*7c478bd9Sstevel@tonic-gate  * returned record. If *fhrecpp was initially null, that record had
658*7c478bd9Sstevel@tonic-gate  * been malloc'd and must be freed by caller.
659*7c478bd9Sstevel@tonic-gate  */
660*7c478bd9Sstevel@tonic-gate static fhlist_ent *
fh_lookup_link(char * fhpath,fhandle_t * dfh,fhandle_t * fh,char * name,fhlist_ent * fhrecp,int * errorp)661*7c478bd9Sstevel@tonic-gate fh_lookup_link(char *fhpath, fhandle_t *dfh, fhandle_t *fh, char *name,
662*7c478bd9Sstevel@tonic-gate 	fhlist_ent *fhrecp, int *errorp)
663*7c478bd9Sstevel@tonic-gate {
664*7c478bd9Sstevel@tonic-gate 	fhlist_ent	*in_fhrecp = fhrecp;
665*7c478bd9Sstevel@tonic-gate 
666*7c478bd9Sstevel@tonic-gate 	if ((name != NULL) && IS_DOT_FILENAME(name)) {
667*7c478bd9Sstevel@tonic-gate 		/* we don't insert these to the database but not an error */
668*7c478bd9Sstevel@tonic-gate 		if (debug > 2) {
669*7c478bd9Sstevel@tonic-gate 			PRINT_FULL_DATA(stdout, "fh_lookup_link", dfh, fh, name,
670*7c478bd9Sstevel@tonic-gate 				" - no dot files\n")
671*7c478bd9Sstevel@tonic-gate 		}
672*7c478bd9Sstevel@tonic-gate 		*errorp = 0;
673*7c478bd9Sstevel@tonic-gate 		return (NULL);
674*7c478bd9Sstevel@tonic-gate 	}
675*7c478bd9Sstevel@tonic-gate 	if (debug > 3) {
676*7c478bd9Sstevel@tonic-gate 		PRINT_FULL_DATA(stdout, "fh_lookup_link", dfh, fh, name, "")
677*7c478bd9Sstevel@tonic-gate 	}
678*7c478bd9Sstevel@tonic-gate 	/* Add to database */
679*7c478bd9Sstevel@tonic-gate 	if (fh != NULL) {
680*7c478bd9Sstevel@tonic-gate 		fhrecp = db_lookup(fhpath, fh, fhrecp, errorp);
681*7c478bd9Sstevel@tonic-gate 		if (fhrecp == NULL) {
682*7c478bd9Sstevel@tonic-gate 			if (debug > 3)
683*7c478bd9Sstevel@tonic-gate 				(void) printf("fh_lookup_link: fh not found\n");
684*7c478bd9Sstevel@tonic-gate 			return (NULL);
685*7c478bd9Sstevel@tonic-gate 		}
686*7c478bd9Sstevel@tonic-gate 		/* Check if name and dfh match, if not search link */
687*7c478bd9Sstevel@tonic-gate 		if (((dfh == NULL) || !fh_compare(dfh, &fhrecp->dfh)) &&
688*7c478bd9Sstevel@tonic-gate 		    ((name == NULL) || (strcmp(name, fhrecp->name) == 0))) {
689*7c478bd9Sstevel@tonic-gate 			/* found it */
690*7c478bd9Sstevel@tonic-gate 			goto exit;
691*7c478bd9Sstevel@tonic-gate 		}
692*7c478bd9Sstevel@tonic-gate 		/* Found the primary record, but it's a different link */
693*7c478bd9Sstevel@tonic-gate 		if (debug == 3) {	/* Only log if >2 but already printed */
694*7c478bd9Sstevel@tonic-gate 			PRINT_FULL_DATA(stdout, "fh_lookup_link", dfh, fh,
695*7c478bd9Sstevel@tonic-gate 				name, "")
696*7c478bd9Sstevel@tonic-gate 		}
697*7c478bd9Sstevel@tonic-gate 		if (debug > 2) {
698*7c478bd9Sstevel@tonic-gate 			PRINT_LINK_DATA(stdout, "Different primary link",
699*7c478bd9Sstevel@tonic-gate 				&fhrecp->dfh, fhrecp->name, "")
700*7c478bd9Sstevel@tonic-gate 		}
701*7c478bd9Sstevel@tonic-gate 		/* can now free the record unless it was supplied by caller */
702*7c478bd9Sstevel@tonic-gate 		if (fhrecp != in_fhrecp) {
703*7c478bd9Sstevel@tonic-gate 			free(fhrecp);
704*7c478bd9Sstevel@tonic-gate 			fhrecp = NULL;
705*7c478bd9Sstevel@tonic-gate 		}
706*7c478bd9Sstevel@tonic-gate 	}
707*7c478bd9Sstevel@tonic-gate 	/* If here, we must search by link */
708*7c478bd9Sstevel@tonic-gate 	if ((dfh == NULL) || (name == NULL)) {
709*7c478bd9Sstevel@tonic-gate 		if (debug > 2)
710*7c478bd9Sstevel@tonic-gate 			(void) printf("fh_lookup_link: invalid params\n");
711*7c478bd9Sstevel@tonic-gate 		*errorp = EINVAL;
712*7c478bd9Sstevel@tonic-gate 		return (NULL);
713*7c478bd9Sstevel@tonic-gate 	}
714*7c478bd9Sstevel@tonic-gate 	fhrecp = db_lookup_link(fhpath, dfh, name, fhrecp, errorp);
715*7c478bd9Sstevel@tonic-gate 	if (fhrecp == NULL) {
716*7c478bd9Sstevel@tonic-gate 		if (debug > 3)
717*7c478bd9Sstevel@tonic-gate 			(void) printf("fh_lookup_link: link not found: %s\n",
718*7c478bd9Sstevel@tonic-gate 			    ((*errorp >= 0) ? strerror(*errorp) : "Unknown"));
719*7c478bd9Sstevel@tonic-gate 		return (NULL);
720*7c478bd9Sstevel@tonic-gate 	}
721*7c478bd9Sstevel@tonic-gate 	/* If all args supplied, check if an exact match */
722*7c478bd9Sstevel@tonic-gate 	if ((fh != NULL) && fh_compare(fh, &fhrecp->fh)) {
723*7c478bd9Sstevel@tonic-gate 		if (debug > 2) {
724*7c478bd9Sstevel@tonic-gate 			PRINT_FULL_DATA(stderr, "fh_lookup_link", dfh, fh,
725*7c478bd9Sstevel@tonic-gate 				name, "")
726*7c478bd9Sstevel@tonic-gate 			PRINT_LINK_DATA(stderr, "Different primary link",
727*7c478bd9Sstevel@tonic-gate 			    &fhrecp->dfh, fhrecp->name, "")
728*7c478bd9Sstevel@tonic-gate 		}
729*7c478bd9Sstevel@tonic-gate 		if (fhrecp != in_fhrecp)
730*7c478bd9Sstevel@tonic-gate 			free(fhrecp);
731*7c478bd9Sstevel@tonic-gate 		*errorp = EINVAL;
732*7c478bd9Sstevel@tonic-gate 		return (NULL);
733*7c478bd9Sstevel@tonic-gate 	}
734*7c478bd9Sstevel@tonic-gate exit:
735*7c478bd9Sstevel@tonic-gate 	if (debug > 3)
736*7c478bd9Sstevel@tonic-gate 		(void) printf("lookup: found '%s' in fhtable\n", name);
737*7c478bd9Sstevel@tonic-gate 	*errorp = 0;
738*7c478bd9Sstevel@tonic-gate 	return (fhrecp);
739*7c478bd9Sstevel@tonic-gate }
740*7c478bd9Sstevel@tonic-gate 
741*7c478bd9Sstevel@tonic-gate /*
742*7c478bd9Sstevel@tonic-gate  * Export handle cache is maintained if we see an export handle that either
743*7c478bd9Sstevel@tonic-gate  * cannot have the path for it determined, or we failed store it.
744*7c478bd9Sstevel@tonic-gate  * Usually the path of an export handle can be identified in the NFSLOGTAB
745*7c478bd9Sstevel@tonic-gate  * and since every path for that filesystem will be affected, it's worth
746*7c478bd9Sstevel@tonic-gate  * caching the ones we had problem identifying.
747*7c478bd9Sstevel@tonic-gate  */
748*7c478bd9Sstevel@tonic-gate 
749*7c478bd9Sstevel@tonic-gate /*
750*7c478bd9Sstevel@tonic-gate  * find_fh_in_export_cache - given an export fh, find it in the cache and
751*7c478bd9Sstevel@tonic-gate  * return the handle
752*7c478bd9Sstevel@tonic-gate  */
753*7c478bd9Sstevel@tonic-gate static struct export_handle_cache *
find_fh_in_export_cache(fhandle_t * fh)754*7c478bd9Sstevel@tonic-gate find_fh_in_export_cache(fhandle_t *fh)
755*7c478bd9Sstevel@tonic-gate {
756*7c478bd9Sstevel@tonic-gate 	struct export_handle_cache	*p;
757*7c478bd9Sstevel@tonic-gate 
758*7c478bd9Sstevel@tonic-gate 	for (p = exp_handle_cache; p != NULL; p = p->next) {
759*7c478bd9Sstevel@tonic-gate 		if (memcmp(fh, &p->fh, sizeof (*fh)) == 0)
760*7c478bd9Sstevel@tonic-gate 			break;
761*7c478bd9Sstevel@tonic-gate 	}
762*7c478bd9Sstevel@tonic-gate 	return (p);
763*7c478bd9Sstevel@tonic-gate }
764*7c478bd9Sstevel@tonic-gate 
765*7c478bd9Sstevel@tonic-gate static void
add_fh_to_export_cache(fhandle_t * fh,char * path)766*7c478bd9Sstevel@tonic-gate add_fh_to_export_cache(fhandle_t *fh, char *path)
767*7c478bd9Sstevel@tonic-gate {
768*7c478bd9Sstevel@tonic-gate 	struct export_handle_cache	*new;
769*7c478bd9Sstevel@tonic-gate 
770*7c478bd9Sstevel@tonic-gate 	if ((new = malloc(sizeof (*new))) == NULL) {
771*7c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, gettext(
772*7c478bd9Sstevel@tonic-gate 		"add_fh_to_export_cache: alloc new for '%s' Error %s\n"),
773*7c478bd9Sstevel@tonic-gate 			((path != NULL) ? path : ""), strerror(errno));
774*7c478bd9Sstevel@tonic-gate 		return;
775*7c478bd9Sstevel@tonic-gate 	}
776*7c478bd9Sstevel@tonic-gate 	if (path != NULL) {
777*7c478bd9Sstevel@tonic-gate 		if ((new->name = malloc(strlen(path) + 1)) == NULL) {
778*7c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, gettext(
779*7c478bd9Sstevel@tonic-gate 				"add_fh_to_export_cache: alloc '%s'"
780*7c478bd9Sstevel@tonic-gate 				    " Error %s\n"), path, strerror(errno));
781*7c478bd9Sstevel@tonic-gate 			free(new);
782*7c478bd9Sstevel@tonic-gate 			return;
783*7c478bd9Sstevel@tonic-gate 		}
784*7c478bd9Sstevel@tonic-gate 		(void) strcpy(new->name, path);
785*7c478bd9Sstevel@tonic-gate 	} else {
786*7c478bd9Sstevel@tonic-gate 		new->name = NULL;
787*7c478bd9Sstevel@tonic-gate 	}
788*7c478bd9Sstevel@tonic-gate 	(void) memcpy(&new->fh, fh, sizeof (*fh));
789*7c478bd9Sstevel@tonic-gate 	new->next = exp_handle_cache;
790*7c478bd9Sstevel@tonic-gate 	exp_handle_cache = new;
791*7c478bd9Sstevel@tonic-gate }
792*7c478bd9Sstevel@tonic-gate 
793*7c478bd9Sstevel@tonic-gate /*
794*7c478bd9Sstevel@tonic-gate  * update_export_point - called when the path for fh cannot be determined.
795*7c478bd9Sstevel@tonic-gate  * In the past it called get_export_path() to get the name of the
796*7c478bd9Sstevel@tonic-gate  * export point given a filehandle. This was a hack, since there's no
797*7c478bd9Sstevel@tonic-gate  * reason why the filehandle should be lost.
798*7c478bd9Sstevel@tonic-gate  *
799*7c478bd9Sstevel@tonic-gate  * If a match is found, insert the path to the database.
800*7c478bd9Sstevel@tonic-gate  * Return the inserted fhrecp is found,
801*7c478bd9Sstevel@tonic-gate  * and NULL if not. If it is an exported fs but not in the list, log a
802*7c478bd9Sstevel@tonic-gate  * error.
803*7c478bd9Sstevel@tonic-gate  * If input fhrecp is non-null, it is a valid address for result,
804*7c478bd9Sstevel@tonic-gate  * otherwise malloc it.
805*7c478bd9Sstevel@tonic-gate  */
806*7c478bd9Sstevel@tonic-gate static char *
update_export_point(char * fhpath,fhandle_t * fh,char * path)807*7c478bd9Sstevel@tonic-gate update_export_point(char *fhpath, fhandle_t *fh, char *path)
808*7c478bd9Sstevel@tonic-gate {
809*7c478bd9Sstevel@tonic-gate 	struct export_handle_cache	*p;
810*7c478bd9Sstevel@tonic-gate 
811*7c478bd9Sstevel@tonic-gate 	if ((fh == NULL) || memcmp(&fh->fh_data, &fh->fh_xdata, fh->fh_len)) {
812*7c478bd9Sstevel@tonic-gate 		/* either null fh or not the root of a shared directory */
813*7c478bd9Sstevel@tonic-gate 		return (NULL);
814*7c478bd9Sstevel@tonic-gate 	}
815*7c478bd9Sstevel@tonic-gate 	/* Did we already see (and fail) this one? */
816*7c478bd9Sstevel@tonic-gate 	if ((p = find_fh_in_export_cache(fh)) != NULL) {
817*7c478bd9Sstevel@tonic-gate 		/* Found it! */
818*7c478bd9Sstevel@tonic-gate 		if (debug > 2) {
819*7c478bd9Sstevel@tonic-gate 			PRINT_LINK_DATA(stdout, "update_export_point",
820*7c478bd9Sstevel@tonic-gate 				fh, ((p->name != NULL) ? p->name : ""), "");
821*7c478bd9Sstevel@tonic-gate 		}
822*7c478bd9Sstevel@tonic-gate 		if (p->name == NULL)
823*7c478bd9Sstevel@tonic-gate 			return (NULL);
824*7c478bd9Sstevel@tonic-gate 		/*
825*7c478bd9Sstevel@tonic-gate 		 * We should not normally be here - only add to cache if
826*7c478bd9Sstevel@tonic-gate 		 * fh_add failed.
827*7c478bd9Sstevel@tonic-gate 		 */
828*7c478bd9Sstevel@tonic-gate 		if ((path == NULL) &&
829*7c478bd9Sstevel@tonic-gate 		    ((path = malloc(strlen(p->name) + 1)) == NULL)) {
830*7c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, gettext(
831*7c478bd9Sstevel@tonic-gate 				"update_export_point: malloc '%s' Error %s"),
832*7c478bd9Sstevel@tonic-gate 				    p->name, strerror(errno));
833*7c478bd9Sstevel@tonic-gate 			return (NULL);
834*7c478bd9Sstevel@tonic-gate 		}
835*7c478bd9Sstevel@tonic-gate 		(void) strcpy(path, p->name);
836*7c478bd9Sstevel@tonic-gate 		return (path);
837*7c478bd9Sstevel@tonic-gate 	}
838*7c478bd9Sstevel@tonic-gate 	if ((path = get_export_path(fh, path)) == NULL) {
839*7c478bd9Sstevel@tonic-gate 		add_fh_to_export_cache(fh, NULL);
840*7c478bd9Sstevel@tonic-gate 		return (NULL);
841*7c478bd9Sstevel@tonic-gate 	}
842*7c478bd9Sstevel@tonic-gate 	/* Found it! */
843*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
844*7c478bd9Sstevel@tonic-gate 		PRINT_LINK_DATA(stdout, "update_export_point", fh, path, "")
845*7c478bd9Sstevel@tonic-gate 	}
846*7c478bd9Sstevel@tonic-gate 	if (FH_ADD(fhpath, fh, fh, path)) {
847*7c478bd9Sstevel@tonic-gate 		/* cache this handle so we don't repeat the search */
848*7c478bd9Sstevel@tonic-gate 		add_fh_to_export_cache(fh, path);
849*7c478bd9Sstevel@tonic-gate 	}
850*7c478bd9Sstevel@tonic-gate 	return (path);
851*7c478bd9Sstevel@tonic-gate }
852*7c478bd9Sstevel@tonic-gate 
853*7c478bd9Sstevel@tonic-gate /*
854*7c478bd9Sstevel@tonic-gate  * HACK!!! To get rid of get_export_path() use
855*7c478bd9Sstevel@tonic-gate  */
856*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
857*7c478bd9Sstevel@tonic-gate static char *
get_export_path(fhandle_t * fh,char * path)858*7c478bd9Sstevel@tonic-gate get_export_path(fhandle_t *fh, char *path)
859*7c478bd9Sstevel@tonic-gate {
860*7c478bd9Sstevel@tonic-gate 	return (NULL);
861*7c478bd9Sstevel@tonic-gate }
862*7c478bd9Sstevel@tonic-gate 
863*7c478bd9Sstevel@tonic-gate /*
864*7c478bd9Sstevel@tonic-gate  * Return the absolute pathname for the filehandle "fh", using the mapping
865*7c478bd9Sstevel@tonic-gate  * table "fhlist".  The caller must free the return string.
866*7c478bd9Sstevel@tonic-gate  * name is an optional dir component name, to be appended at the end
867*7c478bd9Sstevel@tonic-gate  * (if name is non-null, the function assumes the fh is the parent directory)
868*7c478bd9Sstevel@tonic-gate  *
869*7c478bd9Sstevel@tonic-gate  * Note: The original code was recursive, which was much more elegant but
870*7c478bd9Sstevel@tonic-gate  * ran out of stack...
871*7c478bd9Sstevel@tonic-gate  */
872*7c478bd9Sstevel@tonic-gate 
873*7c478bd9Sstevel@tonic-gate static char *
fh_print_absolute(char * fhpath,fhandle_t * fh,char * name)874*7c478bd9Sstevel@tonic-gate fh_print_absolute(char *fhpath, fhandle_t *fh, char *name)
875*7c478bd9Sstevel@tonic-gate {
876*7c478bd9Sstevel@tonic-gate 	char		*str, *rootname, parent[MAXPATHLEN];
877*7c478bd9Sstevel@tonic-gate 	int		i, j, k, len, error;
878*7c478bd9Sstevel@tonic-gate 	fhlist_ent	fhrec, *fhrecp;
879*7c478bd9Sstevel@tonic-gate 	fhandle_t	prevfh;
880*7c478bd9Sstevel@tonic-gate 	int		namelen;
881*7c478bd9Sstevel@tonic-gate 
882*7c478bd9Sstevel@tonic-gate 	if (debug > 3)
883*7c478bd9Sstevel@tonic-gate 		(void) printf("fh_print_absolute: input name '%s'\n",
884*7c478bd9Sstevel@tonic-gate 			((name != NULL) ? name : ""));
885*7c478bd9Sstevel@tonic-gate 	/* If name starts with '/' we are done */
886*7c478bd9Sstevel@tonic-gate 	if ((name != NULL) && (name[0] == '/')) {
887*7c478bd9Sstevel@tonic-gate 		if ((str = strdup(name)) == NULL) {
888*7c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, gettext(
889*7c478bd9Sstevel@tonic-gate 				"fh_print_absolute: strdup '%s' error %s\n"),
890*7c478bd9Sstevel@tonic-gate 				name, strerror(errno));
891*7c478bd9Sstevel@tonic-gate 		}
892*7c478bd9Sstevel@tonic-gate 		return (str);
893*7c478bd9Sstevel@tonic-gate 	}
894*7c478bd9Sstevel@tonic-gate 	namelen = ((name != NULL) ? strlen(name) + 2 : 0);
895*7c478bd9Sstevel@tonic-gate 	parent[0] = '\0';
896*7c478bd9Sstevel@tonic-gate 
897*7c478bd9Sstevel@tonic-gate 	/* remember the last filehandle we've seen */
898*7c478bd9Sstevel@tonic-gate 	(void) memcpy((void *) &prevfh, (void *) fh, sizeof (*fh));
899*7c478bd9Sstevel@tonic-gate 	fh = &prevfh;
900*7c478bd9Sstevel@tonic-gate 
901*7c478bd9Sstevel@tonic-gate 	/* dump all names in reverse order */
902*7c478bd9Sstevel@tonic-gate 	while ((fhrecp = fh_lookup(fhpath, fh, &fhrec, &error)) != NULL &&
903*7c478bd9Sstevel@tonic-gate 		!(fhrecp->flags & (EXPORT_POINT | PUBLIC_PATH))) {
904*7c478bd9Sstevel@tonic-gate 
905*7c478bd9Sstevel@tonic-gate 		if (debug > 3) {
906*7c478bd9Sstevel@tonic-gate 			(void) printf("fh_print_absolute: name '%s'%s\n",
907*7c478bd9Sstevel@tonic-gate 				fhrecp->name,
908*7c478bd9Sstevel@tonic-gate 				((fhrecp->flags & EXPORT_POINT) ? "root" : ""));
909*7c478bd9Sstevel@tonic-gate 		}
910*7c478bd9Sstevel@tonic-gate 		if (memcmp(&prevfh, &fhrecp->dfh, sizeof (*fh)) == 0) {
911*7c478bd9Sstevel@tonic-gate 			/* dfh == prevfh but not an export point */
912*7c478bd9Sstevel@tonic-gate 			if (debug > 1) {
913*7c478bd9Sstevel@tonic-gate 				(void) printf(
914*7c478bd9Sstevel@tonic-gate 					"fh_print_absolute: fhrec loop:\n");
915*7c478bd9Sstevel@tonic-gate 					debug_opaque_print(stdout, fhrecp,
916*7c478bd9Sstevel@tonic-gate 					fhrecp->reclen);
917*7c478bd9Sstevel@tonic-gate 			}
918*7c478bd9Sstevel@tonic-gate 			break;
919*7c478bd9Sstevel@tonic-gate 		}
920*7c478bd9Sstevel@tonic-gate 		(void) strcat(parent, "/");
921*7c478bd9Sstevel@tonic-gate 		(void) strcat(parent, fhrecp->name);
922*7c478bd9Sstevel@tonic-gate 
923*7c478bd9Sstevel@tonic-gate 		/* remember the last filehandle we've seen */
924*7c478bd9Sstevel@tonic-gate 		(void) memcpy(&prevfh, &fhrecp->dfh, sizeof (fhrecp->dfh));
925*7c478bd9Sstevel@tonic-gate 	}
926*7c478bd9Sstevel@tonic-gate 	assert(fh == &prevfh);
927*7c478bd9Sstevel@tonic-gate 
928*7c478bd9Sstevel@tonic-gate 	if (fhrecp != NULL) {
929*7c478bd9Sstevel@tonic-gate 		rootname = fhrecp->name;
930*7c478bd9Sstevel@tonic-gate 	} else {
931*7c478bd9Sstevel@tonic-gate 		/* Check if export point, just in case... */
932*7c478bd9Sstevel@tonic-gate 		/* There should be enough room in parent, leave the '\0' */
933*7c478bd9Sstevel@tonic-gate 		rootname = update_export_point(
934*7c478bd9Sstevel@tonic-gate 				fhpath, fh, &parent[strlen(parent) + 1]);
935*7c478bd9Sstevel@tonic-gate 	}
936*7c478bd9Sstevel@tonic-gate 	/* Now need to reverse the order */
937*7c478bd9Sstevel@tonic-gate 	if (rootname != NULL) {	/* *fhrecp is the export point */
938*7c478bd9Sstevel@tonic-gate 		len = strlen(rootname) + 2;
939*7c478bd9Sstevel@tonic-gate 	} else {
940*7c478bd9Sstevel@tonic-gate 		len = 2 * (NFS_FHMAXDATA + fh->fh_len);	/* fid instead */
941*7c478bd9Sstevel@tonic-gate 	}
942*7c478bd9Sstevel@tonic-gate 	len = ROUNDUP32(len + namelen + strlen(parent));
943*7c478bd9Sstevel@tonic-gate 	if ((str = malloc(len)) == NULL) {
944*7c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, gettext(
945*7c478bd9Sstevel@tonic-gate 			"fh_print_absolute: malloc %d error %s\n"),
946*7c478bd9Sstevel@tonic-gate 			    len, strerror(errno));
947*7c478bd9Sstevel@tonic-gate 		return (NULL);
948*7c478bd9Sstevel@tonic-gate 	}
949*7c478bd9Sstevel@tonic-gate 	/* first put the export point path in */
950*7c478bd9Sstevel@tonic-gate 	if (rootname != NULL) {	/* *fhrecp is the export point */
951*7c478bd9Sstevel@tonic-gate 		(void) strcpy(str, rootname);
952*7c478bd9Sstevel@tonic-gate 	} else {
953*7c478bd9Sstevel@tonic-gate 		sprint_fid(str, len, fh);
954*7c478bd9Sstevel@tonic-gate 	}
955*7c478bd9Sstevel@tonic-gate 	for (k = strlen(str), i = strlen(parent); (k < len) && (i >= 0); i--) {
956*7c478bd9Sstevel@tonic-gate 		for (j = i; (j >= 0) && (parent[j] != '/'); j--);
957*7c478bd9Sstevel@tonic-gate 		if (j < 0)
958*7c478bd9Sstevel@tonic-gate 			break;
959*7c478bd9Sstevel@tonic-gate 		(void) strcpy(&str[k], &parent[j]);
960*7c478bd9Sstevel@tonic-gate 		k += strlen(&str[k]);
961*7c478bd9Sstevel@tonic-gate 		parent[j] = '\0';
962*7c478bd9Sstevel@tonic-gate 	}
963*7c478bd9Sstevel@tonic-gate 	if ((name != NULL) && ((k + namelen) <= len)) {
964*7c478bd9Sstevel@tonic-gate 		str[k] = '/';
965*7c478bd9Sstevel@tonic-gate 		(void) strcpy(&str[k + 1], name);
966*7c478bd9Sstevel@tonic-gate 	}
967*7c478bd9Sstevel@tonic-gate 	if (debug > 3)
968*7c478bd9Sstevel@tonic-gate 		(void) printf("fh_print_absolute: path '%s'\n", str);
969*7c478bd9Sstevel@tonic-gate 	return (str);
970*7c478bd9Sstevel@tonic-gate }
971*7c478bd9Sstevel@tonic-gate 
972*7c478bd9Sstevel@tonic-gate /*
973*7c478bd9Sstevel@tonic-gate  * nfslog_find_fh_dispatch - get the dispatch struct for this request
974*7c478bd9Sstevel@tonic-gate  */
975*7c478bd9Sstevel@tonic-gate static struct nfsl_fh_proc_disp *
nfslog_find_fh_dispatch(nfslog_request_record * logrec)976*7c478bd9Sstevel@tonic-gate nfslog_find_fh_dispatch(nfslog_request_record *logrec)
977*7c478bd9Sstevel@tonic-gate {
978*7c478bd9Sstevel@tonic-gate 	nfslog_record_header		*logrechdr = &logrec->re_header;
979*7c478bd9Sstevel@tonic-gate 	struct nfsl_fh_prog_disp	*progtable;	/* prog struct */
980*7c478bd9Sstevel@tonic-gate 	struct nfsl_fh_vers_disp	*verstable;	/* version struct */
981*7c478bd9Sstevel@tonic-gate 	int				i, vers;
982*7c478bd9Sstevel@tonic-gate 
983*7c478bd9Sstevel@tonic-gate 	/* Find prog element - search because can't use prog as array index */
984*7c478bd9Sstevel@tonic-gate 	for (i = 0; (i < nfsl_fh_dispatch_table_arglen) &&
985*7c478bd9Sstevel@tonic-gate 	    (logrechdr->rh_prognum != nfsl_fh_dispatch_table[i].nfsl_dis_prog);
986*7c478bd9Sstevel@tonic-gate 		i++);
987*7c478bd9Sstevel@tonic-gate 	if (i >= nfsl_fh_dispatch_table_arglen) {	/* program not logged */
988*7c478bd9Sstevel@tonic-gate 		/* not an error */
989*7c478bd9Sstevel@tonic-gate 		return (NULL);
990*7c478bd9Sstevel@tonic-gate 	}
991*7c478bd9Sstevel@tonic-gate 	progtable = &nfsl_fh_dispatch_table[i];
992*7c478bd9Sstevel@tonic-gate 	/* Find vers element - no validity check - if here it's valid vers */
993*7c478bd9Sstevel@tonic-gate 	vers = logrechdr->rh_version - progtable->nfsl_dis_versmin;
994*7c478bd9Sstevel@tonic-gate 	verstable = &progtable->nfsl_dis_vers_table[vers];
995*7c478bd9Sstevel@tonic-gate 	/* Find proc element - no validity check - if here it's valid proc */
996*7c478bd9Sstevel@tonic-gate 	return (&verstable->nfsl_dis_proc_table[logrechdr->rh_procnum]);
997*7c478bd9Sstevel@tonic-gate }
998*7c478bd9Sstevel@tonic-gate 
999*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1000*7c478bd9Sstevel@tonic-gate static void
nfslog_null_fhargs(caddr_t * nfsl_args,caddr_t * nfsl_res,char * fhpath,char ** pathp1,char ** pathp2)1001*7c478bd9Sstevel@tonic-gate nfslog_null_fhargs(caddr_t *nfsl_args, caddr_t *nfsl_res,
1002*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1003*7c478bd9Sstevel@tonic-gate {
1004*7c478bd9Sstevel@tonic-gate 	*pathp1 = NULL;
1005*7c478bd9Sstevel@tonic-gate 	*pathp2 = NULL;
1006*7c478bd9Sstevel@tonic-gate }
1007*7c478bd9Sstevel@tonic-gate 
1008*7c478bd9Sstevel@tonic-gate /*
1009*7c478bd9Sstevel@tonic-gate  * nfslog_LOOKUP_calc - called by both lookup3 and lookup2. Handles the
1010*7c478bd9Sstevel@tonic-gate  * mclookup as well as normal lookups.
1011*7c478bd9Sstevel@tonic-gate  */
1012*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1013*7c478bd9Sstevel@tonic-gate static void
nfslog_LOOKUP_calc(fhandle_t * dfh,char * name,fhandle_t * fh,char * fhpath,char ** pathp1,char ** pathp2,char * str)1014*7c478bd9Sstevel@tonic-gate nfslog_LOOKUP_calc(fhandle_t *dfh, char *name, fhandle_t *fh,
1015*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2, char *str)
1016*7c478bd9Sstevel@tonic-gate {
1017*7c478bd9Sstevel@tonic-gate 	int		error;
1018*7c478bd9Sstevel@tonic-gate 	fhlist_ent	fhrec;
1019*7c478bd9Sstevel@tonic-gate 	char		*name1 = NULL;
1020*7c478bd9Sstevel@tonic-gate 
1021*7c478bd9Sstevel@tonic-gate 	if (fh == &public_fh) {
1022*7c478bd9Sstevel@tonic-gate 		/* a fake lookup to inform us of the public fs path */
1023*7c478bd9Sstevel@tonic-gate 		if (error = FH_ADD(fhpath, fh, fh, name)) {
1024*7c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, gettext(
1025*7c478bd9Sstevel@tonic-gate 				"%s: Add Public fs '%s' failed: %s\n"),
1026*7c478bd9Sstevel@tonic-gate 				str, name,
1027*7c478bd9Sstevel@tonic-gate 				((error >= 0) ? strerror(error) : "Unknown"));
1028*7c478bd9Sstevel@tonic-gate 		}
1029*7c478bd9Sstevel@tonic-gate 		if (pathp1 != NULL) {
1030*7c478bd9Sstevel@tonic-gate 			*pathp1 = nfslog_get_path(dfh, NULL, fhpath, str);
1031*7c478bd9Sstevel@tonic-gate 			*pathp2 = NULL;
1032*7c478bd9Sstevel@tonic-gate 		}
1033*7c478bd9Sstevel@tonic-gate 		return;
1034*7c478bd9Sstevel@tonic-gate 	}
1035*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1036*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(dfh, name, fhpath, str);
1037*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1038*7c478bd9Sstevel@tonic-gate 	}
1039*7c478bd9Sstevel@tonic-gate 
1040*7c478bd9Sstevel@tonic-gate 	/* If public fh mclookup, then insert complete path */
1041*7c478bd9Sstevel@tonic-gate 	if (dfh == &public_fh) {
1042*7c478bd9Sstevel@tonic-gate 		if (pathp1 != NULL) {
1043*7c478bd9Sstevel@tonic-gate 			name = *pathp1;
1044*7c478bd9Sstevel@tonic-gate 		} else {
1045*7c478bd9Sstevel@tonic-gate 			name = nfslog_get_path(dfh, name, fhpath, str);
1046*7c478bd9Sstevel@tonic-gate 			name1 = name;
1047*7c478bd9Sstevel@tonic-gate 		}
1048*7c478bd9Sstevel@tonic-gate 	}
1049*7c478bd9Sstevel@tonic-gate 	if (fh_lookup_link(fhpath, dfh, fh, name, &fhrec, &error) != NULL) {
1050*7c478bd9Sstevel@tonic-gate 		/* link already in table */
1051*7c478bd9Sstevel@tonic-gate 		if (name1 != NULL)
1052*7c478bd9Sstevel@tonic-gate 			free(name1);
1053*7c478bd9Sstevel@tonic-gate 		return;
1054*7c478bd9Sstevel@tonic-gate 	}
1055*7c478bd9Sstevel@tonic-gate 	/* A new link so add it */
1056*7c478bd9Sstevel@tonic-gate 	if (error = FH_ADD(fhpath, dfh, fh, name)) {
1057*7c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, gettext(
1058*7c478bd9Sstevel@tonic-gate 			"%s: Add fh for '%s' failed: %s\n"), str,
1059*7c478bd9Sstevel@tonic-gate 			    name, ((error >= 0) ? strerror(error) : "Unknown"));
1060*7c478bd9Sstevel@tonic-gate 	}
1061*7c478bd9Sstevel@tonic-gate 	if (name1 != NULL)
1062*7c478bd9Sstevel@tonic-gate 		free(name1);
1063*7c478bd9Sstevel@tonic-gate }
1064*7c478bd9Sstevel@tonic-gate 
1065*7c478bd9Sstevel@tonic-gate /*
1066*7c478bd9Sstevel@tonic-gate  * NFS VERSION 2
1067*7c478bd9Sstevel@tonic-gate  */
1068*7c478bd9Sstevel@tonic-gate 
1069*7c478bd9Sstevel@tonic-gate /* Functions for updating the fhtable for fhtoppath */
1070*7c478bd9Sstevel@tonic-gate 
1071*7c478bd9Sstevel@tonic-gate /*
1072*7c478bd9Sstevel@tonic-gate  * nfslog_GETATTR2_fhargs - updates path1 but no fhtable changes
1073*7c478bd9Sstevel@tonic-gate  */
1074*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1075*7c478bd9Sstevel@tonic-gate static void
nfslog_GETATTR2_fhargs(fhandle_t * args,nfsstat * res,char * fhpath,char ** pathp1,char ** pathp2)1076*7c478bd9Sstevel@tonic-gate nfslog_GETATTR2_fhargs(fhandle_t *args, nfsstat *res,
1077*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1078*7c478bd9Sstevel@tonic-gate {
1079*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1080*7c478bd9Sstevel@tonic-gate 		(void) printf("=============\nGETATTR2: fh ");
1081*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, args, sizeof (*args));
1082*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
1083*7c478bd9Sstevel@tonic-gate 	}
1084*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1085*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE2(args),
1086*7c478bd9Sstevel@tonic-gate 				NULL, fhpath, "getattr2");
1087*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1088*7c478bd9Sstevel@tonic-gate 	}
1089*7c478bd9Sstevel@tonic-gate }
1090*7c478bd9Sstevel@tonic-gate 
1091*7c478bd9Sstevel@tonic-gate /*
1092*7c478bd9Sstevel@tonic-gate  * nfslog_SETATTR2_fhargs - updates path1 but no fhtable changes
1093*7c478bd9Sstevel@tonic-gate  */
1094*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1095*7c478bd9Sstevel@tonic-gate static void
nfslog_SETATTR2_fhargs(nfslog_setattrargs * args,nfsstat * res,char * fhpath,char ** pathp1,char ** pathp2)1096*7c478bd9Sstevel@tonic-gate nfslog_SETATTR2_fhargs(nfslog_setattrargs *args, nfsstat *res,
1097*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1098*7c478bd9Sstevel@tonic-gate {
1099*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1100*7c478bd9Sstevel@tonic-gate 		(void) printf("=============\nSETATTR2: fh ");
1101*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, &args->saa_fh,
1102*7c478bd9Sstevel@tonic-gate 			sizeof (args->saa_fh));
1103*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
1104*7c478bd9Sstevel@tonic-gate 	}
1105*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1106*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE2(&args->saa_fh),
1107*7c478bd9Sstevel@tonic-gate 				NULL, fhpath, "setattr2");
1108*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1109*7c478bd9Sstevel@tonic-gate 	}
1110*7c478bd9Sstevel@tonic-gate }
1111*7c478bd9Sstevel@tonic-gate 
1112*7c478bd9Sstevel@tonic-gate /*
1113*7c478bd9Sstevel@tonic-gate  * nfslog_LOOKUP2_fhargs - search the table to ensure we have not added this
1114*7c478bd9Sstevel@tonic-gate  * one already. Note that if the response status was anything but okay,
1115*7c478bd9Sstevel@tonic-gate  * there is no fh to check...
1116*7c478bd9Sstevel@tonic-gate  */
1117*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1118*7c478bd9Sstevel@tonic-gate static void
nfslog_LOOKUP2_fhargs(nfslog_diropargs * args,nfslog_diropres * res,char * fhpath,char ** pathp1,char ** pathp2)1119*7c478bd9Sstevel@tonic-gate nfslog_LOOKUP2_fhargs(nfslog_diropargs *args, nfslog_diropres *res,
1120*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1121*7c478bd9Sstevel@tonic-gate {
1122*7c478bd9Sstevel@tonic-gate 	char		*name;
1123*7c478bd9Sstevel@tonic-gate 	fhandle_t	*dfh, *fh;
1124*7c478bd9Sstevel@tonic-gate 
1125*7c478bd9Sstevel@tonic-gate 	dfh = &args->da_fhandle;
1126*7c478bd9Sstevel@tonic-gate 	name = args->da_name;
1127*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1128*7c478bd9Sstevel@tonic-gate 		if (res->dr_status == NFS_OK)
1129*7c478bd9Sstevel@tonic-gate 			fh = &res->nfslog_diropres_u.dr_ok.drok_fhandle;
1130*7c478bd9Sstevel@tonic-gate 		else
1131*7c478bd9Sstevel@tonic-gate 			fh = NULL;
1132*7c478bd9Sstevel@tonic-gate 		PRINT_FULL_DATA(stdout, "=============\nLOOKUP2",
1133*7c478bd9Sstevel@tonic-gate 			dfh, fh, name, "")
1134*7c478bd9Sstevel@tonic-gate 		if (res->dr_status !=  NFS_OK)
1135*7c478bd9Sstevel@tonic-gate 			(void) printf("status %d\n", res->dr_status);
1136*7c478bd9Sstevel@tonic-gate 	}
1137*7c478bd9Sstevel@tonic-gate 	dfh = NFSLOG_GET_FHANDLE2(dfh);
1138*7c478bd9Sstevel@tonic-gate 	if ((dfh == &public_fh) && (name[0] == '\x80')) {
1139*7c478bd9Sstevel@tonic-gate 		/* special mclookup */
1140*7c478bd9Sstevel@tonic-gate 		name = &name[1];
1141*7c478bd9Sstevel@tonic-gate 	}
1142*7c478bd9Sstevel@tonic-gate 	if (res->dr_status != NFS_OK) {
1143*7c478bd9Sstevel@tonic-gate 		if (pathp1 != NULL) {
1144*7c478bd9Sstevel@tonic-gate 			*pathp1 = nfslog_get_path(dfh, name, fhpath, "lookup2");
1145*7c478bd9Sstevel@tonic-gate 			*pathp2 = NULL;
1146*7c478bd9Sstevel@tonic-gate 		}
1147*7c478bd9Sstevel@tonic-gate 		return;
1148*7c478bd9Sstevel@tonic-gate 	}
1149*7c478bd9Sstevel@tonic-gate 	fh = NFSLOG_GET_FHANDLE2(&res->nfslog_diropres_u.dr_ok.drok_fhandle);
1150*7c478bd9Sstevel@tonic-gate 	nfslog_LOOKUP_calc(dfh, name, fh, fhpath, pathp1, pathp2, "Lookup2");
1151*7c478bd9Sstevel@tonic-gate }
1152*7c478bd9Sstevel@tonic-gate 
1153*7c478bd9Sstevel@tonic-gate /*
1154*7c478bd9Sstevel@tonic-gate  * nfslog_READLINK2_fhargs - updates path1 but no fhtable changes
1155*7c478bd9Sstevel@tonic-gate  */
1156*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1157*7c478bd9Sstevel@tonic-gate static void
nfslog_READLINK2_fhargs(fhandle_t * args,nfslog_rdlnres * res,char * fhpath,char ** pathp1,char ** pathp2)1158*7c478bd9Sstevel@tonic-gate nfslog_READLINK2_fhargs(fhandle_t *args, nfslog_rdlnres *res,
1159*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1160*7c478bd9Sstevel@tonic-gate {
1161*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1162*7c478bd9Sstevel@tonic-gate 		(void) printf("=============\nREADLINK2: fh ");
1163*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, args, sizeof (*args));
1164*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
1165*7c478bd9Sstevel@tonic-gate 	}
1166*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1167*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE2(args),
1168*7c478bd9Sstevel@tonic-gate 				NULL, fhpath, "readlink2");
1169*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1170*7c478bd9Sstevel@tonic-gate 	}
1171*7c478bd9Sstevel@tonic-gate }
1172*7c478bd9Sstevel@tonic-gate 
1173*7c478bd9Sstevel@tonic-gate /*
1174*7c478bd9Sstevel@tonic-gate  * nfslog_READ2_fhargs - updates path1 but no fhtable changes
1175*7c478bd9Sstevel@tonic-gate  */
1176*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1177*7c478bd9Sstevel@tonic-gate static void
nfslog_READ2_fhargs(nfslog_nfsreadargs * args,nfslog_rdresult * res,char * fhpath,char ** pathp1,char ** pathp2)1178*7c478bd9Sstevel@tonic-gate nfslog_READ2_fhargs(nfslog_nfsreadargs *args, nfslog_rdresult *res,
1179*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1180*7c478bd9Sstevel@tonic-gate {
1181*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1182*7c478bd9Sstevel@tonic-gate 		(void) printf("=============\nREAD2: fh ");
1183*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, &args->ra_fhandle,
1184*7c478bd9Sstevel@tonic-gate 			sizeof (args->ra_fhandle));
1185*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
1186*7c478bd9Sstevel@tonic-gate 	}
1187*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1188*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(
1189*7c478bd9Sstevel@tonic-gate 				NFSLOG_GET_FHANDLE2(&args->ra_fhandle),
1190*7c478bd9Sstevel@tonic-gate 				NULL, fhpath, "read2");
1191*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1192*7c478bd9Sstevel@tonic-gate 	}
1193*7c478bd9Sstevel@tonic-gate }
1194*7c478bd9Sstevel@tonic-gate 
1195*7c478bd9Sstevel@tonic-gate /*
1196*7c478bd9Sstevel@tonic-gate  * nfslog_WRITE2_fhargs - updates path1 but no fhtable changes
1197*7c478bd9Sstevel@tonic-gate  */
1198*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1199*7c478bd9Sstevel@tonic-gate static void
nfslog_WRITE2_fhargs(nfslog_writeargs * args,nfslog_writeresult * res,char * fhpath,char ** pathp1,char ** pathp2)1200*7c478bd9Sstevel@tonic-gate nfslog_WRITE2_fhargs(nfslog_writeargs *args, nfslog_writeresult *res,
1201*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1202*7c478bd9Sstevel@tonic-gate {
1203*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1204*7c478bd9Sstevel@tonic-gate 		(void) printf("=============\nWRITE2: fh ");
1205*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, &args->waargs_fhandle,
1206*7c478bd9Sstevel@tonic-gate 			sizeof (args->waargs_fhandle));
1207*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
1208*7c478bd9Sstevel@tonic-gate 	}
1209*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1210*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(
1211*7c478bd9Sstevel@tonic-gate 			NFSLOG_GET_FHANDLE2(&args->waargs_fhandle),
1212*7c478bd9Sstevel@tonic-gate 			NULL, fhpath, "write2");
1213*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1214*7c478bd9Sstevel@tonic-gate 	}
1215*7c478bd9Sstevel@tonic-gate }
1216*7c478bd9Sstevel@tonic-gate 
1217*7c478bd9Sstevel@tonic-gate /*
1218*7c478bd9Sstevel@tonic-gate  * nfslog_CREATE2_fhargs - if the operation succeeded, we are sure there can
1219*7c478bd9Sstevel@tonic-gate  * be no such link in the fhtable, so just add it.
1220*7c478bd9Sstevel@tonic-gate  */
1221*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1222*7c478bd9Sstevel@tonic-gate static void
nfslog_CREATE2_fhargs(nfslog_createargs * args,nfslog_diropres * res,char * fhpath,char ** pathp1,char ** pathp2)1223*7c478bd9Sstevel@tonic-gate nfslog_CREATE2_fhargs(nfslog_createargs *args, nfslog_diropres *res,
1224*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1225*7c478bd9Sstevel@tonic-gate {
1226*7c478bd9Sstevel@tonic-gate 	char		*name;
1227*7c478bd9Sstevel@tonic-gate 	fhandle_t	*dfh, *fh;
1228*7c478bd9Sstevel@tonic-gate 	int		error;
1229*7c478bd9Sstevel@tonic-gate 
1230*7c478bd9Sstevel@tonic-gate 	name = args->ca_da.da_name;
1231*7c478bd9Sstevel@tonic-gate 	dfh = &args->ca_da.da_fhandle;
1232*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1233*7c478bd9Sstevel@tonic-gate 		if (res->dr_status == NFS_OK)
1234*7c478bd9Sstevel@tonic-gate 			fh = &res->nfslog_diropres_u.dr_ok.drok_fhandle;
1235*7c478bd9Sstevel@tonic-gate 		else
1236*7c478bd9Sstevel@tonic-gate 			fh = NULL;
1237*7c478bd9Sstevel@tonic-gate 		PRINT_FULL_DATA(stdout, "=============\nCREATE2",
1238*7c478bd9Sstevel@tonic-gate 			dfh, fh, name, "")
1239*7c478bd9Sstevel@tonic-gate 		if (res->dr_status != NFS_OK)
1240*7c478bd9Sstevel@tonic-gate 			(void) printf("status %d\n", res->dr_status);
1241*7c478bd9Sstevel@tonic-gate 	}
1242*7c478bd9Sstevel@tonic-gate 	dfh = NFSLOG_GET_FHANDLE2(dfh);
1243*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1244*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(dfh, name, fhpath, "create2");
1245*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1246*7c478bd9Sstevel@tonic-gate 	}
1247*7c478bd9Sstevel@tonic-gate 
1248*7c478bd9Sstevel@tonic-gate 	if (res->dr_status != NFS_OK)
1249*7c478bd9Sstevel@tonic-gate 		/* no returned fh so nothing to add */
1250*7c478bd9Sstevel@tonic-gate 		return;
1251*7c478bd9Sstevel@tonic-gate 
1252*7c478bd9Sstevel@tonic-gate 	/* A new file handle so add it */
1253*7c478bd9Sstevel@tonic-gate 	fh = NFSLOG_GET_FHANDLE2(&res->nfslog_diropres_u.dr_ok.drok_fhandle);
1254*7c478bd9Sstevel@tonic-gate 	if (error = FH_ADD(fhpath, dfh, fh, name)) {
1255*7c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, gettext(
1256*7c478bd9Sstevel@tonic-gate 			"Create2: Add fh for '%s' failed: %s\n"),
1257*7c478bd9Sstevel@tonic-gate 			    name, ((error >= 0) ? strerror(error) : "Unknown"));
1258*7c478bd9Sstevel@tonic-gate 	}
1259*7c478bd9Sstevel@tonic-gate }
1260*7c478bd9Sstevel@tonic-gate 
1261*7c478bd9Sstevel@tonic-gate /*
1262*7c478bd9Sstevel@tonic-gate  * nfslog_REMOVE2_fhargs - if the operation succeeded, remove the link from
1263*7c478bd9Sstevel@tonic-gate  * the fhtable.
1264*7c478bd9Sstevel@tonic-gate  */
1265*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1266*7c478bd9Sstevel@tonic-gate static void
nfslog_REMOVE2_fhargs(nfslog_diropargs * args,nfsstat * res,char * fhpath,char ** pathp1,char ** pathp2)1267*7c478bd9Sstevel@tonic-gate nfslog_REMOVE2_fhargs(nfslog_diropargs *args, nfsstat *res,
1268*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1269*7c478bd9Sstevel@tonic-gate {
1270*7c478bd9Sstevel@tonic-gate 	char		*name;
1271*7c478bd9Sstevel@tonic-gate 	fhandle_t	*dfh;
1272*7c478bd9Sstevel@tonic-gate 	int		error;
1273*7c478bd9Sstevel@tonic-gate 
1274*7c478bd9Sstevel@tonic-gate 	name = args->da_name;
1275*7c478bd9Sstevel@tonic-gate 	dfh = &args->da_fhandle;
1276*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1277*7c478bd9Sstevel@tonic-gate 		PRINT_LINK_DATA(stdout, "=============\nREMOVE2", dfh, name, "")
1278*7c478bd9Sstevel@tonic-gate 		if (*res != NFS_OK)
1279*7c478bd9Sstevel@tonic-gate 			(void) printf("status %d\n", *res);
1280*7c478bd9Sstevel@tonic-gate 	}
1281*7c478bd9Sstevel@tonic-gate 	dfh = NFSLOG_GET_FHANDLE2(dfh);
1282*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1283*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(dfh, name, fhpath, "remove2");
1284*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1285*7c478bd9Sstevel@tonic-gate 	}
1286*7c478bd9Sstevel@tonic-gate 
1287*7c478bd9Sstevel@tonic-gate 	if (*res != NFS_OK)
1288*7c478bd9Sstevel@tonic-gate 		/* remove failed so nothing to update */
1289*7c478bd9Sstevel@tonic-gate 		return;
1290*7c478bd9Sstevel@tonic-gate 
1291*7c478bd9Sstevel@tonic-gate 	if (error = fh_remove(fhpath, dfh, name, pathp1)) {
1292*7c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, gettext("Remove2: '%s' failed: %s\n"),
1293*7c478bd9Sstevel@tonic-gate 			name, ((error >= 0) ? strerror(error) : "Unknown"));
1294*7c478bd9Sstevel@tonic-gate 	}
1295*7c478bd9Sstevel@tonic-gate }
1296*7c478bd9Sstevel@tonic-gate 
1297*7c478bd9Sstevel@tonic-gate /*
1298*7c478bd9Sstevel@tonic-gate  * nfsl_RENAME2_fhargs - updates the dfh and name fields for the given fh
1299*7c478bd9Sstevel@tonic-gate  *	to change them to the new name.
1300*7c478bd9Sstevel@tonic-gate  */
1301*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1302*7c478bd9Sstevel@tonic-gate static void
nfslog_RENAME2_fhargs(nfslog_rnmargs * args,nfsstat * res,char * fhpath,char ** pathp1,char ** pathp2)1303*7c478bd9Sstevel@tonic-gate nfslog_RENAME2_fhargs(nfslog_rnmargs *args, nfsstat *res,
1304*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1305*7c478bd9Sstevel@tonic-gate {
1306*7c478bd9Sstevel@tonic-gate 	char			*from_name, *to_name;
1307*7c478bd9Sstevel@tonic-gate 	fhandle_t		*from_dfh, *to_dfh;
1308*7c478bd9Sstevel@tonic-gate 	int			error;
1309*7c478bd9Sstevel@tonic-gate 
1310*7c478bd9Sstevel@tonic-gate 	from_name = args->rna_from.da_name;
1311*7c478bd9Sstevel@tonic-gate 	from_dfh = &args->rna_from.da_fhandle;
1312*7c478bd9Sstevel@tonic-gate 	to_name = args->rna_to.da_name;
1313*7c478bd9Sstevel@tonic-gate 	to_dfh = &args->rna_to.da_fhandle;
1314*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1315*7c478bd9Sstevel@tonic-gate 		PRINT_LINK_DATA(stdout, "=============\nRENAME2: from",
1316*7c478bd9Sstevel@tonic-gate 			from_dfh, from_name, "")
1317*7c478bd9Sstevel@tonic-gate 		PRINT_LINK_DATA(stdout, "RENAME2: to  ", to_dfh,
1318*7c478bd9Sstevel@tonic-gate 			to_name, "")
1319*7c478bd9Sstevel@tonic-gate 		if (*res != NFS_OK)
1320*7c478bd9Sstevel@tonic-gate 			(void) printf("status %d\n", *res);
1321*7c478bd9Sstevel@tonic-gate 	}
1322*7c478bd9Sstevel@tonic-gate 	from_dfh = NFSLOG_GET_FHANDLE2(from_dfh);
1323*7c478bd9Sstevel@tonic-gate 	to_dfh = NFSLOG_GET_FHANDLE2(to_dfh);
1324*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1325*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(from_dfh, from_name, fhpath,
1326*7c478bd9Sstevel@tonic-gate 			"rename2 from");
1327*7c478bd9Sstevel@tonic-gate 		*pathp2 = nfslog_get_path(to_dfh, to_name, fhpath,
1328*7c478bd9Sstevel@tonic-gate 			"rename2 to");
1329*7c478bd9Sstevel@tonic-gate 	}
1330*7c478bd9Sstevel@tonic-gate 
1331*7c478bd9Sstevel@tonic-gate 	if (*res != NFS_OK)
1332*7c478bd9Sstevel@tonic-gate 		/* rename failed so nothing to update */
1333*7c478bd9Sstevel@tonic-gate 		return;
1334*7c478bd9Sstevel@tonic-gate 
1335*7c478bd9Sstevel@tonic-gate 	/* Rename the link in the database */
1336*7c478bd9Sstevel@tonic-gate 	if (error = fh_rename(fhpath, from_dfh, from_name, pathp1,
1337*7c478bd9Sstevel@tonic-gate 			to_dfh, to_name)) {
1338*7c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, gettext(
1339*7c478bd9Sstevel@tonic-gate 			"Rename2: Update from '%s' to '%s' failed: %s\n"),
1340*7c478bd9Sstevel@tonic-gate 				from_name, to_name,
1341*7c478bd9Sstevel@tonic-gate 				((error >= 0) ? strerror(error) : "Unknown"));
1342*7c478bd9Sstevel@tonic-gate 	}
1343*7c478bd9Sstevel@tonic-gate }
1344*7c478bd9Sstevel@tonic-gate 
1345*7c478bd9Sstevel@tonic-gate /*
1346*7c478bd9Sstevel@tonic-gate  * nfslog_LINK2_fhargs - adds link name and fh to fhlist. Note that as a
1347*7c478bd9Sstevel@tonic-gate  *	result we may have more than one name for an fh.
1348*7c478bd9Sstevel@tonic-gate  */
1349*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1350*7c478bd9Sstevel@tonic-gate static void
nfslog_LINK2_fhargs(nfslog_linkargs * args,nfsstat * res,char * fhpath,char ** pathp1,char ** pathp2)1351*7c478bd9Sstevel@tonic-gate nfslog_LINK2_fhargs(nfslog_linkargs *args, nfsstat *res,
1352*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1353*7c478bd9Sstevel@tonic-gate {
1354*7c478bd9Sstevel@tonic-gate 	char		*name;
1355*7c478bd9Sstevel@tonic-gate 	fhandle_t	*dfh, *fh;
1356*7c478bd9Sstevel@tonic-gate 	int		error;
1357*7c478bd9Sstevel@tonic-gate 
1358*7c478bd9Sstevel@tonic-gate 	fh = &args->la_from;
1359*7c478bd9Sstevel@tonic-gate 	name = args->la_to.da_name;
1360*7c478bd9Sstevel@tonic-gate 	dfh = &args->la_to.da_fhandle;
1361*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1362*7c478bd9Sstevel@tonic-gate 		PRINT_FULL_DATA(stdout, "=============\nLINK2",
1363*7c478bd9Sstevel@tonic-gate 			dfh, fh, name, "")
1364*7c478bd9Sstevel@tonic-gate 		if (*res != NFS_OK)
1365*7c478bd9Sstevel@tonic-gate 			(void) printf("status %d\n", *res);
1366*7c478bd9Sstevel@tonic-gate 	}
1367*7c478bd9Sstevel@tonic-gate 	dfh = NFSLOG_GET_FHANDLE2(dfh);
1368*7c478bd9Sstevel@tonic-gate 	fh = NFSLOG_GET_FHANDLE2(fh);
1369*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1370*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(fh, NULL, fhpath, "link2 from");
1371*7c478bd9Sstevel@tonic-gate 		*pathp2 = nfslog_get_path(dfh, name, fhpath, "link2 to");
1372*7c478bd9Sstevel@tonic-gate 	}
1373*7c478bd9Sstevel@tonic-gate 
1374*7c478bd9Sstevel@tonic-gate 	if (*res != NFS_OK)
1375*7c478bd9Sstevel@tonic-gate 		/* no returned fh so nothing to add */
1376*7c478bd9Sstevel@tonic-gate 		return;
1377*7c478bd9Sstevel@tonic-gate 
1378*7c478bd9Sstevel@tonic-gate 	/* A new link so add it, have fh_add find the link count */
1379*7c478bd9Sstevel@tonic-gate 	if (error = FH_ADD(fhpath, dfh, fh, name)) {
1380*7c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, gettext(
1381*7c478bd9Sstevel@tonic-gate 			"Link2: Add fh for '%s' failed: %s\n"),
1382*7c478bd9Sstevel@tonic-gate 			    name, ((error >= 0) ? strerror(error) : "Unknown"));
1383*7c478bd9Sstevel@tonic-gate 	}
1384*7c478bd9Sstevel@tonic-gate }
1385*7c478bd9Sstevel@tonic-gate 
1386*7c478bd9Sstevel@tonic-gate /*
1387*7c478bd9Sstevel@tonic-gate  * nfslog_SYMLINK2_fhargs - adds symlink name and fh to fhlist if fh returned.
1388*7c478bd9Sstevel@tonic-gate  */
1389*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1390*7c478bd9Sstevel@tonic-gate static void
nfslog_SYMLINK2_fhargs(nfslog_symlinkargs * args,nfsstat * res,char * fhpath,char ** pathp1,char ** pathp2)1391*7c478bd9Sstevel@tonic-gate nfslog_SYMLINK2_fhargs(nfslog_symlinkargs *args, nfsstat *res,
1392*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1393*7c478bd9Sstevel@tonic-gate {
1394*7c478bd9Sstevel@tonic-gate 	char		*name;
1395*7c478bd9Sstevel@tonic-gate 	fhandle_t	*dfh;
1396*7c478bd9Sstevel@tonic-gate 
1397*7c478bd9Sstevel@tonic-gate 	name = args->sla_from.da_name;
1398*7c478bd9Sstevel@tonic-gate 	dfh = &args->sla_from.da_fhandle;
1399*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1400*7c478bd9Sstevel@tonic-gate 		PRINT_LINK_DATA(stdout, "=============\nSYMLINK2",
1401*7c478bd9Sstevel@tonic-gate 			dfh, name, "")
1402*7c478bd9Sstevel@tonic-gate 	}
1403*7c478bd9Sstevel@tonic-gate 	dfh = NFSLOG_GET_FHANDLE2(dfh);
1404*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1405*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(dfh, name, fhpath, "symlink2");
1406*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1407*7c478bd9Sstevel@tonic-gate 	}
1408*7c478bd9Sstevel@tonic-gate }
1409*7c478bd9Sstevel@tonic-gate 
1410*7c478bd9Sstevel@tonic-gate /*
1411*7c478bd9Sstevel@tonic-gate  * nfslog_READDIR2_fhargs - updates path1 but no fhtable changes
1412*7c478bd9Sstevel@tonic-gate  */
1413*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1414*7c478bd9Sstevel@tonic-gate static void
nfslog_READDIR2_fhargs(nfslog_rddirargs * args,nfslog_rddirres * res,char * fhpath,char ** pathp1,char ** pathp2)1415*7c478bd9Sstevel@tonic-gate nfslog_READDIR2_fhargs(nfslog_rddirargs *args, nfslog_rddirres *res,
1416*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1417*7c478bd9Sstevel@tonic-gate {
1418*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1419*7c478bd9Sstevel@tonic-gate 		(void) printf("=============\nREADDIR2: fh ");
1420*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, &args->rda_fh,
1421*7c478bd9Sstevel@tonic-gate 			sizeof (args->rda_fh));
1422*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
1423*7c478bd9Sstevel@tonic-gate 	}
1424*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1425*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE2(&args->rda_fh),
1426*7c478bd9Sstevel@tonic-gate 				NULL, fhpath, "readdir2");
1427*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1428*7c478bd9Sstevel@tonic-gate 	}
1429*7c478bd9Sstevel@tonic-gate }
1430*7c478bd9Sstevel@tonic-gate 
1431*7c478bd9Sstevel@tonic-gate /*
1432*7c478bd9Sstevel@tonic-gate  * nfslog_STATFS2_fhargs - updates path1 but no fhtable changes
1433*7c478bd9Sstevel@tonic-gate  */
1434*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1435*7c478bd9Sstevel@tonic-gate static void
nfslog_STATFS2_fhargs(fhandle_t * args,nfsstat * res,char * fhpath,char ** pathp1,char ** pathp2)1436*7c478bd9Sstevel@tonic-gate nfslog_STATFS2_fhargs(fhandle_t *args, nfsstat *res,
1437*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1438*7c478bd9Sstevel@tonic-gate {
1439*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1440*7c478bd9Sstevel@tonic-gate 		(void) printf("=============\nSTATFS2: fh ");
1441*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, args, sizeof (*args));
1442*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
1443*7c478bd9Sstevel@tonic-gate 	}
1444*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1445*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE2(args),
1446*7c478bd9Sstevel@tonic-gate 				NULL, fhpath, "statfs2");
1447*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1448*7c478bd9Sstevel@tonic-gate 	}
1449*7c478bd9Sstevel@tonic-gate }
1450*7c478bd9Sstevel@tonic-gate 
1451*7c478bd9Sstevel@tonic-gate /*
1452*7c478bd9Sstevel@tonic-gate  * NFS VERSION 3
1453*7c478bd9Sstevel@tonic-gate  */
1454*7c478bd9Sstevel@tonic-gate 
1455*7c478bd9Sstevel@tonic-gate /* Functions for updating the fhtable for fhtoppath */
1456*7c478bd9Sstevel@tonic-gate 
1457*7c478bd9Sstevel@tonic-gate /*
1458*7c478bd9Sstevel@tonic-gate  * nfslog_GETATTR3_fhargs - updates path1 but no fhtable changes
1459*7c478bd9Sstevel@tonic-gate  */
1460*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1461*7c478bd9Sstevel@tonic-gate static void
nfslog_GETATTR3_fhargs(nfs_fh3 * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)1462*7c478bd9Sstevel@tonic-gate nfslog_GETATTR3_fhargs(nfs_fh3 *args, nfsstat3 *res,
1463*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1464*7c478bd9Sstevel@tonic-gate {
1465*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1466*7c478bd9Sstevel@tonic-gate 		(void) printf("=============\nGETATTR3: fh ");
1467*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, args, sizeof (*args));
1468*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
1469*7c478bd9Sstevel@tonic-gate 	}
1470*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1471*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(args), NULL,
1472*7c478bd9Sstevel@tonic-gate 			fhpath, "getattr3");
1473*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1474*7c478bd9Sstevel@tonic-gate 	}
1475*7c478bd9Sstevel@tonic-gate }
1476*7c478bd9Sstevel@tonic-gate 
1477*7c478bd9Sstevel@tonic-gate /*
1478*7c478bd9Sstevel@tonic-gate  * nfslog_SETATTR3_fhargs - updates path1 but no fhtable changes
1479*7c478bd9Sstevel@tonic-gate  */
1480*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1481*7c478bd9Sstevel@tonic-gate static void
nfslog_SETATTR3_fhargs(nfslog_SETATTR3args * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)1482*7c478bd9Sstevel@tonic-gate nfslog_SETATTR3_fhargs(nfslog_SETATTR3args *args,	nfsstat3 *res,
1483*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1484*7c478bd9Sstevel@tonic-gate {
1485*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1486*7c478bd9Sstevel@tonic-gate 		(void) printf("=============\nSETATTR3: fh ");
1487*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, &args->object,
1488*7c478bd9Sstevel@tonic-gate 			sizeof (args->object));
1489*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
1490*7c478bd9Sstevel@tonic-gate 	}
1491*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1492*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->object),
1493*7c478bd9Sstevel@tonic-gate 			NULL, fhpath, "setattr3");
1494*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1495*7c478bd9Sstevel@tonic-gate 	}
1496*7c478bd9Sstevel@tonic-gate }
1497*7c478bd9Sstevel@tonic-gate 
1498*7c478bd9Sstevel@tonic-gate /*
1499*7c478bd9Sstevel@tonic-gate  * nfslog_LOOKUP3_fhargs - search the table to ensure we have not added this
1500*7c478bd9Sstevel@tonic-gate  * one already. Note that if the response status was anything but okay,
1501*7c478bd9Sstevel@tonic-gate  * there is no fh to check...
1502*7c478bd9Sstevel@tonic-gate  */
1503*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1504*7c478bd9Sstevel@tonic-gate static void
nfslog_LOOKUP3_fhargs(nfslog_diropargs3 * args,nfslog_LOOKUP3res * res,char * fhpath,char ** pathp1,char ** pathp2)1505*7c478bd9Sstevel@tonic-gate nfslog_LOOKUP3_fhargs(nfslog_diropargs3 *args, nfslog_LOOKUP3res *res,
1506*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1507*7c478bd9Sstevel@tonic-gate {
1508*7c478bd9Sstevel@tonic-gate 	char		*name;
1509*7c478bd9Sstevel@tonic-gate 	fhandle_t	*dfh, *fh;
1510*7c478bd9Sstevel@tonic-gate 
1511*7c478bd9Sstevel@tonic-gate 	name = args->name;
1512*7c478bd9Sstevel@tonic-gate 	dfh = NFSLOG_GET_FHANDLE3(&args->dir);
1513*7c478bd9Sstevel@tonic-gate 
1514*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1515*7c478bd9Sstevel@tonic-gate 		if (res->status == NFS3_OK)
1516*7c478bd9Sstevel@tonic-gate 			fh = NFSLOG_GET_FHANDLE3(
1517*7c478bd9Sstevel@tonic-gate 				&res->nfslog_LOOKUP3res_u.object);
1518*7c478bd9Sstevel@tonic-gate 		else
1519*7c478bd9Sstevel@tonic-gate 			fh = NULL;
1520*7c478bd9Sstevel@tonic-gate 		PRINT_FULL_DATA(stdout, "=============\nLOOKUP3",
1521*7c478bd9Sstevel@tonic-gate 			dfh, fh, name, "")
1522*7c478bd9Sstevel@tonic-gate 		if (res->status != NFS3_OK)
1523*7c478bd9Sstevel@tonic-gate 			(void) printf("status %d\n", res->status);
1524*7c478bd9Sstevel@tonic-gate 	}
1525*7c478bd9Sstevel@tonic-gate 	if ((dfh == &public_fh) && (name[0] == '\x80')) {
1526*7c478bd9Sstevel@tonic-gate 		/* special mclookup */
1527*7c478bd9Sstevel@tonic-gate 		name = &name[1];
1528*7c478bd9Sstevel@tonic-gate 	}
1529*7c478bd9Sstevel@tonic-gate 	if (res->status != NFS3_OK) {
1530*7c478bd9Sstevel@tonic-gate 		if (pathp1 != NULL) {
1531*7c478bd9Sstevel@tonic-gate 			*pathp1 = nfslog_get_path(dfh, name, fhpath, "lookup3");
1532*7c478bd9Sstevel@tonic-gate 			*pathp2 = NULL;
1533*7c478bd9Sstevel@tonic-gate 		}
1534*7c478bd9Sstevel@tonic-gate 		return;
1535*7c478bd9Sstevel@tonic-gate 	}
1536*7c478bd9Sstevel@tonic-gate 	fh = NFSLOG_GET_FHANDLE3(&res->nfslog_LOOKUP3res_u.object);
1537*7c478bd9Sstevel@tonic-gate 	nfslog_LOOKUP_calc(dfh, name, fh, fhpath, pathp1, pathp2, "Lookup3");
1538*7c478bd9Sstevel@tonic-gate }
1539*7c478bd9Sstevel@tonic-gate 
1540*7c478bd9Sstevel@tonic-gate /*
1541*7c478bd9Sstevel@tonic-gate  * nfslog_ACCESS3_fhargs - updates path1 but no fhtable changes
1542*7c478bd9Sstevel@tonic-gate  */
1543*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1544*7c478bd9Sstevel@tonic-gate static void
nfslog_ACCESS3_fhargs(nfs_fh3 * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)1545*7c478bd9Sstevel@tonic-gate nfslog_ACCESS3_fhargs(nfs_fh3 *args, nfsstat3 *res,
1546*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1547*7c478bd9Sstevel@tonic-gate {
1548*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1549*7c478bd9Sstevel@tonic-gate 		(void) printf("=============\nACCESS3: fh ");
1550*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, args,
1551*7c478bd9Sstevel@tonic-gate 			sizeof (*args));
1552*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
1553*7c478bd9Sstevel@tonic-gate 	}
1554*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1555*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(args),
1556*7c478bd9Sstevel@tonic-gate 			NULL, fhpath, "access3");
1557*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1558*7c478bd9Sstevel@tonic-gate 	}
1559*7c478bd9Sstevel@tonic-gate }
1560*7c478bd9Sstevel@tonic-gate 
1561*7c478bd9Sstevel@tonic-gate /*
1562*7c478bd9Sstevel@tonic-gate  * nfslog_READLINK3_fhargs - updates path1 but no fhtable changes
1563*7c478bd9Sstevel@tonic-gate  */
1564*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1565*7c478bd9Sstevel@tonic-gate static void
nfslog_READLINK3_fhargs(nfs_fh3 * args,nfslog_READLINK3res * res,char * fhpath,char ** pathp1,char ** pathp2)1566*7c478bd9Sstevel@tonic-gate nfslog_READLINK3_fhargs(nfs_fh3 *args, nfslog_READLINK3res *res,
1567*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1568*7c478bd9Sstevel@tonic-gate {
1569*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1570*7c478bd9Sstevel@tonic-gate 		(void) printf("=============\nREADLINK3: fh ");
1571*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, args, sizeof (*args));
1572*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
1573*7c478bd9Sstevel@tonic-gate 	}
1574*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1575*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(args), NULL,
1576*7c478bd9Sstevel@tonic-gate 			fhpath, "readlink3");
1577*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1578*7c478bd9Sstevel@tonic-gate 	}
1579*7c478bd9Sstevel@tonic-gate }
1580*7c478bd9Sstevel@tonic-gate 
1581*7c478bd9Sstevel@tonic-gate /*
1582*7c478bd9Sstevel@tonic-gate  * nfslog_READ3_fhargs - updates path1 but no fhtable changes
1583*7c478bd9Sstevel@tonic-gate  */
1584*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1585*7c478bd9Sstevel@tonic-gate static void
nfslog_READ3_fhargs(nfslog_READ3args * args,nfslog_READ3res * res,char * fhpath,char ** pathp1,char ** pathp2)1586*7c478bd9Sstevel@tonic-gate nfslog_READ3_fhargs(nfslog_READ3args *args, nfslog_READ3res *res,
1587*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1588*7c478bd9Sstevel@tonic-gate {
1589*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1590*7c478bd9Sstevel@tonic-gate 		(void) printf("=============\nREAD3: fh ");
1591*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, &args->file,
1592*7c478bd9Sstevel@tonic-gate 			sizeof (args->file));
1593*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
1594*7c478bd9Sstevel@tonic-gate 	}
1595*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1596*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->file),
1597*7c478bd9Sstevel@tonic-gate 			NULL, fhpath, "read3");
1598*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1599*7c478bd9Sstevel@tonic-gate 	}
1600*7c478bd9Sstevel@tonic-gate }
1601*7c478bd9Sstevel@tonic-gate 
1602*7c478bd9Sstevel@tonic-gate /*
1603*7c478bd9Sstevel@tonic-gate  * nfslog_WRITE3_fhargs - updates path1 but no fhtable changes
1604*7c478bd9Sstevel@tonic-gate  */
1605*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1606*7c478bd9Sstevel@tonic-gate static void
nfslog_WRITE3_fhargs(nfslog_WRITE3args * args,nfslog_WRITE3res * res,char * fhpath,char ** pathp1,char ** pathp2)1607*7c478bd9Sstevel@tonic-gate nfslog_WRITE3_fhargs(nfslog_WRITE3args *args, nfslog_WRITE3res *res,
1608*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1609*7c478bd9Sstevel@tonic-gate {
1610*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1611*7c478bd9Sstevel@tonic-gate 		(void) printf("=============\nWRITE3: fh ");
1612*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, &args->file,
1613*7c478bd9Sstevel@tonic-gate 			sizeof (args->file));
1614*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
1615*7c478bd9Sstevel@tonic-gate 	}
1616*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1617*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->file),
1618*7c478bd9Sstevel@tonic-gate 			NULL, fhpath, "write3");
1619*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1620*7c478bd9Sstevel@tonic-gate 	}
1621*7c478bd9Sstevel@tonic-gate }
1622*7c478bd9Sstevel@tonic-gate 
1623*7c478bd9Sstevel@tonic-gate /*
1624*7c478bd9Sstevel@tonic-gate  * nfslog_CREATE3_fhargs - if the operation succeeded, we are sure there can
1625*7c478bd9Sstevel@tonic-gate  * be no such link in the fhtable, so just add it.
1626*7c478bd9Sstevel@tonic-gate  */
1627*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1628*7c478bd9Sstevel@tonic-gate static void
nfslog_CREATE3_fhargs(nfslog_CREATE3args * args,nfslog_CREATE3res * res,char * fhpath,char ** pathp1,char ** pathp2)1629*7c478bd9Sstevel@tonic-gate nfslog_CREATE3_fhargs(nfslog_CREATE3args *args, nfslog_CREATE3res *res,
1630*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1631*7c478bd9Sstevel@tonic-gate {
1632*7c478bd9Sstevel@tonic-gate 	char		*name;
1633*7c478bd9Sstevel@tonic-gate 	fhandle_t	*dfh, *fh;
1634*7c478bd9Sstevel@tonic-gate 	int		error;
1635*7c478bd9Sstevel@tonic-gate 
1636*7c478bd9Sstevel@tonic-gate 	name = args->where.name;
1637*7c478bd9Sstevel@tonic-gate 	dfh = NFSLOG_GET_FHANDLE3(&args->where.dir);
1638*7c478bd9Sstevel@tonic-gate 
1639*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1640*7c478bd9Sstevel@tonic-gate 		if (res->status == NFS3_OK)
1641*7c478bd9Sstevel@tonic-gate 			fh = NFSLOG_GET_FHANDLE3(
1642*7c478bd9Sstevel@tonic-gate 				&res->nfslog_CREATE3res_u.ok.obj.handle);
1643*7c478bd9Sstevel@tonic-gate 		else
1644*7c478bd9Sstevel@tonic-gate 			fh = NULL;
1645*7c478bd9Sstevel@tonic-gate 		PRINT_FULL_DATA(stdout, "=============\nCREATE3",
1646*7c478bd9Sstevel@tonic-gate 			dfh, fh, name, "")
1647*7c478bd9Sstevel@tonic-gate 		if (res->status != NFS3_OK)
1648*7c478bd9Sstevel@tonic-gate 			(void) printf("status %d\n", res->status);
1649*7c478bd9Sstevel@tonic-gate 	}
1650*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1651*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(dfh, name, fhpath, "create3");
1652*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1653*7c478bd9Sstevel@tonic-gate 	}
1654*7c478bd9Sstevel@tonic-gate 
1655*7c478bd9Sstevel@tonic-gate 	if ((res->status != NFS3_OK) ||
1656*7c478bd9Sstevel@tonic-gate 		!res->nfslog_CREATE3res_u.ok.obj.handle_follows)
1657*7c478bd9Sstevel@tonic-gate 		/* no returned fh so nothing to add */
1658*7c478bd9Sstevel@tonic-gate 		return;
1659*7c478bd9Sstevel@tonic-gate 
1660*7c478bd9Sstevel@tonic-gate 	/* A new file handle so add it */
1661*7c478bd9Sstevel@tonic-gate 	fh = NFSLOG_GET_FHANDLE3(&res->nfslog_CREATE3res_u.ok.obj.handle);
1662*7c478bd9Sstevel@tonic-gate 	if (error = FH_ADD(fhpath, dfh, fh, name)) {
1663*7c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, gettext(
1664*7c478bd9Sstevel@tonic-gate 			"Create3: Add fh for '%s' failed: %s\n"),
1665*7c478bd9Sstevel@tonic-gate 			    name, ((error >= 0) ? strerror(error) : "Unknown"));
1666*7c478bd9Sstevel@tonic-gate 	}
1667*7c478bd9Sstevel@tonic-gate }
1668*7c478bd9Sstevel@tonic-gate 
1669*7c478bd9Sstevel@tonic-gate /*
1670*7c478bd9Sstevel@tonic-gate  * nfslog_MKDIR3_fhargs - if the operation succeeded, we are sure there can
1671*7c478bd9Sstevel@tonic-gate  * be no such link in the fhtable, so just add it.
1672*7c478bd9Sstevel@tonic-gate  */
1673*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1674*7c478bd9Sstevel@tonic-gate static void
nfslog_MKDIR3_fhargs(nfslog_MKDIR3args * args,nfslog_MKDIR3res * res,char * fhpath,char ** pathp1,char ** pathp2)1675*7c478bd9Sstevel@tonic-gate nfslog_MKDIR3_fhargs(nfslog_MKDIR3args *args, nfslog_MKDIR3res *res,
1676*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1677*7c478bd9Sstevel@tonic-gate {
1678*7c478bd9Sstevel@tonic-gate 	char		*name;
1679*7c478bd9Sstevel@tonic-gate 	fhandle_t	*dfh, *fh;
1680*7c478bd9Sstevel@tonic-gate 	int		error;
1681*7c478bd9Sstevel@tonic-gate 
1682*7c478bd9Sstevel@tonic-gate 	name = args->where.name;
1683*7c478bd9Sstevel@tonic-gate 	dfh = NFSLOG_GET_FHANDLE3(&args->where.dir);
1684*7c478bd9Sstevel@tonic-gate 
1685*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1686*7c478bd9Sstevel@tonic-gate 		if (res->status == NFS3_OK)
1687*7c478bd9Sstevel@tonic-gate 			fh = NFSLOG_GET_FHANDLE3(
1688*7c478bd9Sstevel@tonic-gate 				&res->nfslog_MKDIR3res_u.obj.handle);
1689*7c478bd9Sstevel@tonic-gate 		else
1690*7c478bd9Sstevel@tonic-gate 			fh = NULL;
1691*7c478bd9Sstevel@tonic-gate 		PRINT_FULL_DATA(stdout, "=============\nMKDIR3",
1692*7c478bd9Sstevel@tonic-gate 			dfh, fh, name, "")
1693*7c478bd9Sstevel@tonic-gate 		if (res->status != NFS3_OK)
1694*7c478bd9Sstevel@tonic-gate 			(void) printf("status %d\n", res->status);
1695*7c478bd9Sstevel@tonic-gate 	}
1696*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1697*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(dfh, name, fhpath, "mkdir3");
1698*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1699*7c478bd9Sstevel@tonic-gate 	}
1700*7c478bd9Sstevel@tonic-gate 
1701*7c478bd9Sstevel@tonic-gate 	if ((res->status != NFS3_OK) ||
1702*7c478bd9Sstevel@tonic-gate 		!res->nfslog_MKDIR3res_u.obj.handle_follows)
1703*7c478bd9Sstevel@tonic-gate 		/* no returned fh so nothing to add */
1704*7c478bd9Sstevel@tonic-gate 		return;
1705*7c478bd9Sstevel@tonic-gate 
1706*7c478bd9Sstevel@tonic-gate 	/* A new file handle so add it */
1707*7c478bd9Sstevel@tonic-gate 	fh = NFSLOG_GET_FHANDLE3(&res->nfslog_MKDIR3res_u.obj.handle);
1708*7c478bd9Sstevel@tonic-gate 	if (error = FH_ADD(fhpath, dfh, fh, name)) {
1709*7c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, gettext(
1710*7c478bd9Sstevel@tonic-gate 			"Mkdir3: Add fh for '%s' failed: %s\n"),
1711*7c478bd9Sstevel@tonic-gate 			    name, ((error >= 0) ? strerror(error) : "Unknown"));
1712*7c478bd9Sstevel@tonic-gate 	}
1713*7c478bd9Sstevel@tonic-gate }
1714*7c478bd9Sstevel@tonic-gate 
1715*7c478bd9Sstevel@tonic-gate /*
1716*7c478bd9Sstevel@tonic-gate  * nfslog_REMOVE3_fhargs - if the operation succeeded, remove the link from
1717*7c478bd9Sstevel@tonic-gate  * the fhtable.
1718*7c478bd9Sstevel@tonic-gate  */
1719*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1720*7c478bd9Sstevel@tonic-gate static void
nfslog_REMOVE3_fhargs(nfslog_REMOVE3args * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)1721*7c478bd9Sstevel@tonic-gate nfslog_REMOVE3_fhargs(nfslog_REMOVE3args *args, nfsstat3 *res,
1722*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1723*7c478bd9Sstevel@tonic-gate {
1724*7c478bd9Sstevel@tonic-gate 	char		*name;
1725*7c478bd9Sstevel@tonic-gate 	fhandle_t	*dfh;
1726*7c478bd9Sstevel@tonic-gate 	int		error;
1727*7c478bd9Sstevel@tonic-gate 
1728*7c478bd9Sstevel@tonic-gate 	name = args->object.name;
1729*7c478bd9Sstevel@tonic-gate 	dfh = NFSLOG_GET_FHANDLE3(&args->object.dir);
1730*7c478bd9Sstevel@tonic-gate 
1731*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1732*7c478bd9Sstevel@tonic-gate 		PRINT_LINK_DATA(stdout, "=============\nREMOVE3", dfh, name, "")
1733*7c478bd9Sstevel@tonic-gate 		if (*res != NFS3_OK)
1734*7c478bd9Sstevel@tonic-gate 			(void) printf("status %d\n", *res);
1735*7c478bd9Sstevel@tonic-gate 	}
1736*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1737*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(dfh, name, fhpath, "remove3");
1738*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1739*7c478bd9Sstevel@tonic-gate 	}
1740*7c478bd9Sstevel@tonic-gate 
1741*7c478bd9Sstevel@tonic-gate 	if (*res != NFS3_OK)
1742*7c478bd9Sstevel@tonic-gate 		/* remove failed so nothing to update */
1743*7c478bd9Sstevel@tonic-gate 		return;
1744*7c478bd9Sstevel@tonic-gate 
1745*7c478bd9Sstevel@tonic-gate 	if (error = fh_remove(fhpath, dfh, name, pathp1)) {
1746*7c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, gettext("Remove3: '%s' failed: %s\n"),
1747*7c478bd9Sstevel@tonic-gate 			name, ((error >= 0) ? strerror(error) : "Unknown"));
1748*7c478bd9Sstevel@tonic-gate 	}
1749*7c478bd9Sstevel@tonic-gate }
1750*7c478bd9Sstevel@tonic-gate 
1751*7c478bd9Sstevel@tonic-gate /*
1752*7c478bd9Sstevel@tonic-gate  * nfslog_RMDIR3_fhargs - if the operation succeeded, remove the link from
1753*7c478bd9Sstevel@tonic-gate  * the fhtable.
1754*7c478bd9Sstevel@tonic-gate  */
1755*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1756*7c478bd9Sstevel@tonic-gate static void
nfslog_RMDIR3_fhargs(nfslog_RMDIR3args * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)1757*7c478bd9Sstevel@tonic-gate nfslog_RMDIR3_fhargs(nfslog_RMDIR3args *args, nfsstat3 *res,
1758*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1759*7c478bd9Sstevel@tonic-gate {
1760*7c478bd9Sstevel@tonic-gate 	char		*name;
1761*7c478bd9Sstevel@tonic-gate 	fhandle_t	*dfh;
1762*7c478bd9Sstevel@tonic-gate 	int		error;
1763*7c478bd9Sstevel@tonic-gate 
1764*7c478bd9Sstevel@tonic-gate 	name = args->object.name;
1765*7c478bd9Sstevel@tonic-gate 	dfh = NFSLOG_GET_FHANDLE3(&args->object.dir);
1766*7c478bd9Sstevel@tonic-gate 
1767*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1768*7c478bd9Sstevel@tonic-gate 		PRINT_LINK_DATA(stdout, "=============\nRMDIR3", dfh, name, "")
1769*7c478bd9Sstevel@tonic-gate 		if (*res != NFS3_OK)
1770*7c478bd9Sstevel@tonic-gate 			(void) printf("status %d\n", *res);
1771*7c478bd9Sstevel@tonic-gate 	}
1772*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1773*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(dfh, name, fhpath, "rmdir3");
1774*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1775*7c478bd9Sstevel@tonic-gate 	}
1776*7c478bd9Sstevel@tonic-gate 
1777*7c478bd9Sstevel@tonic-gate 	if (*res != NFS3_OK)
1778*7c478bd9Sstevel@tonic-gate 		/* rmdir failed so nothing to update */
1779*7c478bd9Sstevel@tonic-gate 		return;
1780*7c478bd9Sstevel@tonic-gate 
1781*7c478bd9Sstevel@tonic-gate 	if (error = fh_remove(fhpath, dfh, name, pathp1)) {
1782*7c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, gettext("Rmdir3: '%s' failed: %s\n"),
1783*7c478bd9Sstevel@tonic-gate 			name, ((error >= 0) ? strerror(error) : "Unknown"));
1784*7c478bd9Sstevel@tonic-gate 	}
1785*7c478bd9Sstevel@tonic-gate }
1786*7c478bd9Sstevel@tonic-gate 
1787*7c478bd9Sstevel@tonic-gate /*
1788*7c478bd9Sstevel@tonic-gate  * nfslog_RENAME3_fhargs - if the operation succeeded, update the existing
1789*7c478bd9Sstevel@tonic-gate  * fhtable entry to point to new dir and name.
1790*7c478bd9Sstevel@tonic-gate  */
1791*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1792*7c478bd9Sstevel@tonic-gate static void
nfslog_RENAME3_fhargs(nfslog_RENAME3args * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)1793*7c478bd9Sstevel@tonic-gate nfslog_RENAME3_fhargs(nfslog_RENAME3args *args, nfsstat3 *res,
1794*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1795*7c478bd9Sstevel@tonic-gate {
1796*7c478bd9Sstevel@tonic-gate 	char			*from_name, *to_name;
1797*7c478bd9Sstevel@tonic-gate 	fhandle_t		*from_dfh, *to_dfh;
1798*7c478bd9Sstevel@tonic-gate 	int			error;
1799*7c478bd9Sstevel@tonic-gate 
1800*7c478bd9Sstevel@tonic-gate 	from_name = args->from.name;
1801*7c478bd9Sstevel@tonic-gate 	from_dfh = NFSLOG_GET_FHANDLE3(&args->from.dir);
1802*7c478bd9Sstevel@tonic-gate 	to_name = args->to.name;
1803*7c478bd9Sstevel@tonic-gate 	to_dfh = NFSLOG_GET_FHANDLE3(&args->to.dir);
1804*7c478bd9Sstevel@tonic-gate 
1805*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1806*7c478bd9Sstevel@tonic-gate 		PRINT_LINK_DATA(stdout, "=============\nRENAME3: from",
1807*7c478bd9Sstevel@tonic-gate 			from_dfh, from_name, "")
1808*7c478bd9Sstevel@tonic-gate 		PRINT_LINK_DATA(stdout, "=============\nRENAME3: to  ",
1809*7c478bd9Sstevel@tonic-gate 			to_dfh, to_name, "")
1810*7c478bd9Sstevel@tonic-gate 		if (*res != NFS3_OK)
1811*7c478bd9Sstevel@tonic-gate 			(void) printf("status %d\n", *res);
1812*7c478bd9Sstevel@tonic-gate 	}
1813*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1814*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(from_dfh, from_name, fhpath,
1815*7c478bd9Sstevel@tonic-gate 			"rename3 from");
1816*7c478bd9Sstevel@tonic-gate 		*pathp2 = nfslog_get_path(to_dfh, to_name, fhpath,
1817*7c478bd9Sstevel@tonic-gate 			"rename3 to");
1818*7c478bd9Sstevel@tonic-gate 	}
1819*7c478bd9Sstevel@tonic-gate 	if (*res != NFS3_OK)
1820*7c478bd9Sstevel@tonic-gate 		/* rename failed so nothing to update */
1821*7c478bd9Sstevel@tonic-gate 		return;
1822*7c478bd9Sstevel@tonic-gate 
1823*7c478bd9Sstevel@tonic-gate 	if (error = fh_rename(fhpath, from_dfh, from_name, pathp1,
1824*7c478bd9Sstevel@tonic-gate 			to_dfh, to_name)) {
1825*7c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, gettext(
1826*7c478bd9Sstevel@tonic-gate 			"Rename3: Update from '%s' to '%s' failed: %s\n"),
1827*7c478bd9Sstevel@tonic-gate 				from_name, to_name,
1828*7c478bd9Sstevel@tonic-gate 				((error >= 0) ? strerror(error) : "Unknown"));
1829*7c478bd9Sstevel@tonic-gate 	}
1830*7c478bd9Sstevel@tonic-gate }
1831*7c478bd9Sstevel@tonic-gate 
1832*7c478bd9Sstevel@tonic-gate /*
1833*7c478bd9Sstevel@tonic-gate  * nfslog_LINK3_fhargs - if the operation succeeded, we are sure there can
1834*7c478bd9Sstevel@tonic-gate  * be no such link in the fhtable, so just add it.
1835*7c478bd9Sstevel@tonic-gate  */
1836*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1837*7c478bd9Sstevel@tonic-gate static void
nfslog_LINK3_fhargs(nfslog_LINK3args * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)1838*7c478bd9Sstevel@tonic-gate nfslog_LINK3_fhargs(nfslog_LINK3args *args, nfsstat3 *res,
1839*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1840*7c478bd9Sstevel@tonic-gate {
1841*7c478bd9Sstevel@tonic-gate 	char			*name;
1842*7c478bd9Sstevel@tonic-gate 	fhandle_t		*dfh, *fh;
1843*7c478bd9Sstevel@tonic-gate 	int			error;
1844*7c478bd9Sstevel@tonic-gate 
1845*7c478bd9Sstevel@tonic-gate 	fh = NFSLOG_GET_FHANDLE3(&args->file);
1846*7c478bd9Sstevel@tonic-gate 	name = args->link.name;
1847*7c478bd9Sstevel@tonic-gate 	dfh = NFSLOG_GET_FHANDLE3(&args->link.dir);
1848*7c478bd9Sstevel@tonic-gate 
1849*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1850*7c478bd9Sstevel@tonic-gate 		PRINT_FULL_DATA(stdout, "=============\nLINK3",
1851*7c478bd9Sstevel@tonic-gate 			dfh, fh, name, "")
1852*7c478bd9Sstevel@tonic-gate 		if (*res != NFS3_OK)
1853*7c478bd9Sstevel@tonic-gate 			(void) printf("status %d\n", *res);
1854*7c478bd9Sstevel@tonic-gate 	}
1855*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1856*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(fh, NULL, fhpath, "link3 from");
1857*7c478bd9Sstevel@tonic-gate 		*pathp2 = nfslog_get_path(dfh, name, fhpath, "link3 to");
1858*7c478bd9Sstevel@tonic-gate 	}
1859*7c478bd9Sstevel@tonic-gate 
1860*7c478bd9Sstevel@tonic-gate 	if (*res != NFS3_OK)
1861*7c478bd9Sstevel@tonic-gate 		/* link failed so nothing to add */
1862*7c478bd9Sstevel@tonic-gate 		return;
1863*7c478bd9Sstevel@tonic-gate 
1864*7c478bd9Sstevel@tonic-gate 	/* A new link so add it, have fh_add find link count */
1865*7c478bd9Sstevel@tonic-gate 	if (error = FH_ADD(fhpath, dfh, fh, name)) {
1866*7c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, gettext(
1867*7c478bd9Sstevel@tonic-gate 			"Link3: Add fh for '%s' failed: %s\n"),
1868*7c478bd9Sstevel@tonic-gate 			    name, ((error >= 0) ? strerror(error) : "Unknown"));
1869*7c478bd9Sstevel@tonic-gate 	}
1870*7c478bd9Sstevel@tonic-gate }
1871*7c478bd9Sstevel@tonic-gate 
1872*7c478bd9Sstevel@tonic-gate /*
1873*7c478bd9Sstevel@tonic-gate  * nfslog_MKNOD3_fhargs - if the operation succeeded, we are sure there can
1874*7c478bd9Sstevel@tonic-gate  * be no such link in the fhtable, so just add it.
1875*7c478bd9Sstevel@tonic-gate  */
1876*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1877*7c478bd9Sstevel@tonic-gate static void
nfslog_MKNOD3_fhargs(nfslog_MKNOD3args * args,nfslog_MKNOD3res * res,char * fhpath,char ** pathp1,char ** pathp2)1878*7c478bd9Sstevel@tonic-gate nfslog_MKNOD3_fhargs(nfslog_MKNOD3args *args, nfslog_MKNOD3res *res,
1879*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1880*7c478bd9Sstevel@tonic-gate {
1881*7c478bd9Sstevel@tonic-gate 	char		*name;
1882*7c478bd9Sstevel@tonic-gate 	fhandle_t	*dfh, *fh;
1883*7c478bd9Sstevel@tonic-gate 	int		error;
1884*7c478bd9Sstevel@tonic-gate 
1885*7c478bd9Sstevel@tonic-gate 	name = args->where.name;
1886*7c478bd9Sstevel@tonic-gate 	dfh = NFSLOG_GET_FHANDLE3(&args->where.dir);
1887*7c478bd9Sstevel@tonic-gate 
1888*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1889*7c478bd9Sstevel@tonic-gate 		if (res->status == NFS3_OK)
1890*7c478bd9Sstevel@tonic-gate 			fh = NFSLOG_GET_FHANDLE3(
1891*7c478bd9Sstevel@tonic-gate 				&res->nfslog_MKNOD3res_u.obj.handle);
1892*7c478bd9Sstevel@tonic-gate 		else
1893*7c478bd9Sstevel@tonic-gate 			fh = NULL;
1894*7c478bd9Sstevel@tonic-gate 		PRINT_FULL_DATA(stdout, "=============\nMKNOD3",
1895*7c478bd9Sstevel@tonic-gate 			dfh, fh, name, "")
1896*7c478bd9Sstevel@tonic-gate 		if (res->status != NFS3_OK)
1897*7c478bd9Sstevel@tonic-gate 			(void) printf("status %d\n", res->status);
1898*7c478bd9Sstevel@tonic-gate 	}
1899*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1900*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(dfh, name, fhpath, "mknod3");
1901*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1902*7c478bd9Sstevel@tonic-gate 	}
1903*7c478bd9Sstevel@tonic-gate 	if ((res->status != NFS3_OK) ||
1904*7c478bd9Sstevel@tonic-gate 		!res->nfslog_MKNOD3res_u.obj.handle_follows)
1905*7c478bd9Sstevel@tonic-gate 		/* no returned fh so nothing to add */
1906*7c478bd9Sstevel@tonic-gate 		return;
1907*7c478bd9Sstevel@tonic-gate 
1908*7c478bd9Sstevel@tonic-gate 	/* A new file handle so add it */
1909*7c478bd9Sstevel@tonic-gate 	fh = NFSLOG_GET_FHANDLE3(&res->nfslog_MKNOD3res_u.obj.handle);
1910*7c478bd9Sstevel@tonic-gate 	if (error = FH_ADD(fhpath, dfh, fh, name)) {
1911*7c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, gettext("Mknod3: Add fh for '%s' failed: %s\n"),
1912*7c478bd9Sstevel@tonic-gate 			name, ((error >= 0) ? strerror(error) : "Unknown"));
1913*7c478bd9Sstevel@tonic-gate 	}
1914*7c478bd9Sstevel@tonic-gate }
1915*7c478bd9Sstevel@tonic-gate 
1916*7c478bd9Sstevel@tonic-gate /*
1917*7c478bd9Sstevel@tonic-gate  * nfslog_SYMLINK3_fhargs - if the operation succeeded, we are sure there can
1918*7c478bd9Sstevel@tonic-gate  * be no such link in the fhtable, so just add it.
1919*7c478bd9Sstevel@tonic-gate  */
1920*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1921*7c478bd9Sstevel@tonic-gate static void
nfslog_SYMLINK3_fhargs(nfslog_SYMLINK3args * args,nfslog_SYMLINK3res * res,char * fhpath,char ** pathp1,char ** pathp2)1922*7c478bd9Sstevel@tonic-gate nfslog_SYMLINK3_fhargs(nfslog_SYMLINK3args *args, nfslog_SYMLINK3res *res,
1923*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1924*7c478bd9Sstevel@tonic-gate {
1925*7c478bd9Sstevel@tonic-gate 	char		*name;
1926*7c478bd9Sstevel@tonic-gate 	fhandle_t	*dfh, *fh;
1927*7c478bd9Sstevel@tonic-gate 	int		error;
1928*7c478bd9Sstevel@tonic-gate 
1929*7c478bd9Sstevel@tonic-gate 	name = args->where.name;
1930*7c478bd9Sstevel@tonic-gate 	dfh = NFSLOG_GET_FHANDLE3(&args->where.dir);
1931*7c478bd9Sstevel@tonic-gate 
1932*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1933*7c478bd9Sstevel@tonic-gate 		if (res->status == NFS3_OK)
1934*7c478bd9Sstevel@tonic-gate 			fh = NFSLOG_GET_FHANDLE3(
1935*7c478bd9Sstevel@tonic-gate 				&res->nfslog_SYMLINK3res_u.obj.handle);
1936*7c478bd9Sstevel@tonic-gate 		else
1937*7c478bd9Sstevel@tonic-gate 			fh = NULL;
1938*7c478bd9Sstevel@tonic-gate 		PRINT_FULL_DATA(stdout, "=============\nSYMLINK3",
1939*7c478bd9Sstevel@tonic-gate 			dfh, fh, name, "")
1940*7c478bd9Sstevel@tonic-gate 		if (res->status != NFS3_OK)
1941*7c478bd9Sstevel@tonic-gate 			(void) printf("status %d\n", res->status);
1942*7c478bd9Sstevel@tonic-gate 	}
1943*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1944*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(dfh, name, fhpath, "symlink3");
1945*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1946*7c478bd9Sstevel@tonic-gate 	}
1947*7c478bd9Sstevel@tonic-gate 
1948*7c478bd9Sstevel@tonic-gate 	if ((res->status != NFS3_OK) ||
1949*7c478bd9Sstevel@tonic-gate 		!res->nfslog_SYMLINK3res_u.obj.handle_follows)
1950*7c478bd9Sstevel@tonic-gate 		/* no returned fh so nothing to add */
1951*7c478bd9Sstevel@tonic-gate 		return;
1952*7c478bd9Sstevel@tonic-gate 
1953*7c478bd9Sstevel@tonic-gate 	/* A new file handle so add it */
1954*7c478bd9Sstevel@tonic-gate 	fh = NFSLOG_GET_FHANDLE3(&res->nfslog_SYMLINK3res_u.obj.handle);
1955*7c478bd9Sstevel@tonic-gate 	if (error = FH_ADD(fhpath, dfh, fh, name)) {
1956*7c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, gettext(
1957*7c478bd9Sstevel@tonic-gate 			"Symlink3: Add fh for '%s' failed: %s\n"),
1958*7c478bd9Sstevel@tonic-gate 			    name, ((error >= 0) ? strerror(error) : "Unknown"));
1959*7c478bd9Sstevel@tonic-gate 	}
1960*7c478bd9Sstevel@tonic-gate }
1961*7c478bd9Sstevel@tonic-gate 
1962*7c478bd9Sstevel@tonic-gate /*
1963*7c478bd9Sstevel@tonic-gate  * nfslog_READDIR3_fhargs - updates path1 but no fhtable changes
1964*7c478bd9Sstevel@tonic-gate  */
1965*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1966*7c478bd9Sstevel@tonic-gate static void
nfslog_READDIR3_fhargs(nfs_fh3 * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)1967*7c478bd9Sstevel@tonic-gate nfslog_READDIR3_fhargs(nfs_fh3 *args, nfsstat3 *res,
1968*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1969*7c478bd9Sstevel@tonic-gate {
1970*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1971*7c478bd9Sstevel@tonic-gate 		(void) printf("=============\nREADDIR3: fh ");
1972*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, args,
1973*7c478bd9Sstevel@tonic-gate 			sizeof (*args));
1974*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
1975*7c478bd9Sstevel@tonic-gate 	}
1976*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
1977*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(args),
1978*7c478bd9Sstevel@tonic-gate 			NULL, fhpath, "readdir3");
1979*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
1980*7c478bd9Sstevel@tonic-gate 	}
1981*7c478bd9Sstevel@tonic-gate }
1982*7c478bd9Sstevel@tonic-gate 
1983*7c478bd9Sstevel@tonic-gate /*
1984*7c478bd9Sstevel@tonic-gate  * nfslog_READDIRPLUS3_fhargs - updates path1 but no fhtable changes
1985*7c478bd9Sstevel@tonic-gate  */
1986*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
1987*7c478bd9Sstevel@tonic-gate static void
nfslog_READDIRPLUS3_fhargs(nfslog_READDIRPLUS3args * args,nfslog_READDIRPLUS3res * res,char * fhpath,char ** pathp1,char ** pathp2)1988*7c478bd9Sstevel@tonic-gate nfslog_READDIRPLUS3_fhargs(nfslog_READDIRPLUS3args *args,
1989*7c478bd9Sstevel@tonic-gate 	nfslog_READDIRPLUS3res *res,
1990*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
1991*7c478bd9Sstevel@tonic-gate {
1992*7c478bd9Sstevel@tonic-gate 	char		*name;
1993*7c478bd9Sstevel@tonic-gate 	fhandle_t	*dfh, *fh;
1994*7c478bd9Sstevel@tonic-gate 	nfslog_entryplus3 *ep;
1995*7c478bd9Sstevel@tonic-gate 
1996*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
1997*7c478bd9Sstevel@tonic-gate 		(void) printf("=============\nREADDIRPLUS3: fh ");
1998*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, &args->dir,
1999*7c478bd9Sstevel@tonic-gate 			sizeof (args->dir));
2000*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
2001*7c478bd9Sstevel@tonic-gate 	}
2002*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
2003*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->dir),
2004*7c478bd9Sstevel@tonic-gate 			NULL, fhpath, "readdirplus3");
2005*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
2006*7c478bd9Sstevel@tonic-gate 	}
2007*7c478bd9Sstevel@tonic-gate 
2008*7c478bd9Sstevel@tonic-gate 	if (res->status == NFS3_OK) {
2009*7c478bd9Sstevel@tonic-gate 
2010*7c478bd9Sstevel@tonic-gate 		dfh = NFSLOG_GET_FHANDLE3(&args->dir);
2011*7c478bd9Sstevel@tonic-gate 
2012*7c478bd9Sstevel@tonic-gate 		/*
2013*7c478bd9Sstevel@tonic-gate 		 * Loop through the fh/name pair and add them
2014*7c478bd9Sstevel@tonic-gate 		 * to the mappings.
2015*7c478bd9Sstevel@tonic-gate 		 */
2016*7c478bd9Sstevel@tonic-gate 		for (ep = res->nfslog_READDIRPLUS3res_u.ok.reply.entries;
2017*7c478bd9Sstevel@tonic-gate 			ep != NULL;
2018*7c478bd9Sstevel@tonic-gate 			ep = ep->nextentry) {
2019*7c478bd9Sstevel@tonic-gate 
2020*7c478bd9Sstevel@tonic-gate 			name = ep->name;
2021*7c478bd9Sstevel@tonic-gate 
2022*7c478bd9Sstevel@tonic-gate 			fh = NFSLOG_GET_FHANDLE3(&ep->name_handle.handle);
2023*7c478bd9Sstevel@tonic-gate 
2024*7c478bd9Sstevel@tonic-gate 			nfslog_LOOKUP_calc(dfh, name, fh,
2025*7c478bd9Sstevel@tonic-gate 				fhpath, NULL, NULL,
2026*7c478bd9Sstevel@tonic-gate 				"ReaddirPlus3");
2027*7c478bd9Sstevel@tonic-gate 		}
2028*7c478bd9Sstevel@tonic-gate 	}
2029*7c478bd9Sstevel@tonic-gate }
2030*7c478bd9Sstevel@tonic-gate 
2031*7c478bd9Sstevel@tonic-gate /*
2032*7c478bd9Sstevel@tonic-gate  * nfslog_FSSTAT3_fhargs - updates path1 but no fhtable changes
2033*7c478bd9Sstevel@tonic-gate  */
2034*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
2035*7c478bd9Sstevel@tonic-gate static void
nfslog_FSSTAT3_fhargs(nfs_fh3 * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)2036*7c478bd9Sstevel@tonic-gate nfslog_FSSTAT3_fhargs(nfs_fh3 *args, nfsstat3 *res,
2037*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
2038*7c478bd9Sstevel@tonic-gate {
2039*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
2040*7c478bd9Sstevel@tonic-gate 		(void) printf("=============\nFSSTAT3: fh ");
2041*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, args,
2042*7c478bd9Sstevel@tonic-gate 			sizeof (*args));
2043*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
2044*7c478bd9Sstevel@tonic-gate 	}
2045*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
2046*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(args), NULL,
2047*7c478bd9Sstevel@tonic-gate 			fhpath, "fsstat3");
2048*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
2049*7c478bd9Sstevel@tonic-gate 	}
2050*7c478bd9Sstevel@tonic-gate }
2051*7c478bd9Sstevel@tonic-gate 
2052*7c478bd9Sstevel@tonic-gate /*
2053*7c478bd9Sstevel@tonic-gate  * nfslog_FSINFO3_fhargs - updates path1 but no fhtable changes
2054*7c478bd9Sstevel@tonic-gate  */
2055*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
2056*7c478bd9Sstevel@tonic-gate static void
nfslog_FSINFO3_fhargs(nfs_fh3 * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)2057*7c478bd9Sstevel@tonic-gate nfslog_FSINFO3_fhargs(nfs_fh3 *args, nfsstat3 *res,
2058*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
2059*7c478bd9Sstevel@tonic-gate {
2060*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
2061*7c478bd9Sstevel@tonic-gate 		(void) printf("=============\nFSINFO3: fh ");
2062*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, args,
2063*7c478bd9Sstevel@tonic-gate 			sizeof (*args));
2064*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
2065*7c478bd9Sstevel@tonic-gate 	}
2066*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
2067*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(args), NULL,
2068*7c478bd9Sstevel@tonic-gate 			fhpath, "fsinfo3");
2069*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
2070*7c478bd9Sstevel@tonic-gate 	}
2071*7c478bd9Sstevel@tonic-gate }
2072*7c478bd9Sstevel@tonic-gate 
2073*7c478bd9Sstevel@tonic-gate /*
2074*7c478bd9Sstevel@tonic-gate  * nfslog_PATHCONF3_fhargs - updates path1 but no fhtable changes
2075*7c478bd9Sstevel@tonic-gate  */
2076*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
2077*7c478bd9Sstevel@tonic-gate static void
nfslog_PATHCONF3_fhargs(nfs_fh3 * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)2078*7c478bd9Sstevel@tonic-gate nfslog_PATHCONF3_fhargs(nfs_fh3 *args, nfsstat3 *res,
2079*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
2080*7c478bd9Sstevel@tonic-gate {
2081*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
2082*7c478bd9Sstevel@tonic-gate 		(void) printf("=============\nPATHCONF3: fh ");
2083*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, args,
2084*7c478bd9Sstevel@tonic-gate 			sizeof (*args));
2085*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
2086*7c478bd9Sstevel@tonic-gate 	}
2087*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
2088*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(args), NULL,
2089*7c478bd9Sstevel@tonic-gate 			fhpath, "pathconf3");
2090*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
2091*7c478bd9Sstevel@tonic-gate 	}
2092*7c478bd9Sstevel@tonic-gate }
2093*7c478bd9Sstevel@tonic-gate 
2094*7c478bd9Sstevel@tonic-gate /*
2095*7c478bd9Sstevel@tonic-gate  * nfslog_COMMIT3_fhargs - updates path1 but no fhtable changes
2096*7c478bd9Sstevel@tonic-gate  */
2097*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
2098*7c478bd9Sstevel@tonic-gate static void
nfslog_COMMIT3_fhargs(nfslog_COMMIT3args * args,nfsstat3 * res,char * fhpath,char ** pathp1,char ** pathp2)2099*7c478bd9Sstevel@tonic-gate nfslog_COMMIT3_fhargs(nfslog_COMMIT3args *args, nfsstat3 *res,
2100*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
2101*7c478bd9Sstevel@tonic-gate {
2102*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
2103*7c478bd9Sstevel@tonic-gate 		(void) printf("=============\nCOMMIT3: fh ");
2104*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, &args->file,
2105*7c478bd9Sstevel@tonic-gate 			sizeof (args->file));
2106*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
2107*7c478bd9Sstevel@tonic-gate 	}
2108*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
2109*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(NFSLOG_GET_FHANDLE3(&args->file),
2110*7c478bd9Sstevel@tonic-gate 			NULL, fhpath, "commit3");
2111*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
2112*7c478bd9Sstevel@tonic-gate 	}
2113*7c478bd9Sstevel@tonic-gate }
2114*7c478bd9Sstevel@tonic-gate 
2115*7c478bd9Sstevel@tonic-gate /*
2116*7c478bd9Sstevel@tonic-gate  * NFSLOG VERSION 1
2117*7c478bd9Sstevel@tonic-gate  */
2118*7c478bd9Sstevel@tonic-gate 
2119*7c478bd9Sstevel@tonic-gate /*
2120*7c478bd9Sstevel@tonic-gate  * nfslog_SHARE_fhargs - adds export path and handle to fhlist
2121*7c478bd9Sstevel@tonic-gate  */
2122*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
2123*7c478bd9Sstevel@tonic-gate static void
nfslog_SHARE_fhargs(nfslog_sharefsargs * args,nfslog_sharefsres * res,char * fhpath,char ** pathp1,char ** pathp2)2124*7c478bd9Sstevel@tonic-gate nfslog_SHARE_fhargs(nfslog_sharefsargs *args, nfslog_sharefsres *res,
2125*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
2126*7c478bd9Sstevel@tonic-gate {
2127*7c478bd9Sstevel@tonic-gate 	fhlist_ent	fhrec;
2128*7c478bd9Sstevel@tonic-gate 	fhandle_t	*fh;
2129*7c478bd9Sstevel@tonic-gate 	int		error;
2130*7c478bd9Sstevel@tonic-gate 
2131*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
2132*7c478bd9Sstevel@tonic-gate 		(void) printf(
2133*7c478bd9Sstevel@tonic-gate 			"=============\nSHARE: name '%s', fh ", args->sh_path);
2134*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, &args->sh_fh_buf,
2135*7c478bd9Sstevel@tonic-gate 			sizeof (fhandle_t));
2136*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
2137*7c478bd9Sstevel@tonic-gate 	}
2138*7c478bd9Sstevel@tonic-gate 
2139*7c478bd9Sstevel@tonic-gate 	fh = &args->sh_fh_buf;
2140*7c478bd9Sstevel@tonic-gate 
2141*7c478bd9Sstevel@tonic-gate 	/*
2142*7c478bd9Sstevel@tonic-gate 	 * This bcopy is done because the fh_data for the export/share directory
2143*7c478bd9Sstevel@tonic-gate 	 * is not meaningful with respect to the database keys.  Therefore, we
2144*7c478bd9Sstevel@tonic-gate 	 * copy the export or fh_xdata fid to the fh_data so that a reasonable
2145*7c478bd9Sstevel@tonic-gate 	 * entry will be added in the data base.
2146*7c478bd9Sstevel@tonic-gate 	 */
2147*7c478bd9Sstevel@tonic-gate 	bcopy(fh->fh_xdata, fh->fh_data, fh->fh_xlen);
2148*7c478bd9Sstevel@tonic-gate 
2149*7c478bd9Sstevel@tonic-gate 	/* If debug print the database */
2150*7c478bd9Sstevel@tonic-gate 	if (debug > 10) {
2151*7c478bd9Sstevel@tonic-gate 		fh_print_all_keys(fhpath, fh);
2152*7c478bd9Sstevel@tonic-gate 	}
2153*7c478bd9Sstevel@tonic-gate 	if (fh_lookup_link(fhpath, fh, fh,
2154*7c478bd9Sstevel@tonic-gate 		args->sh_path, &fhrec, &error) == NULL) {
2155*7c478bd9Sstevel@tonic-gate 		if (error = FH_ADD(fhpath, fh, fh, args->sh_path)) {
2156*7c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, gettext(
2157*7c478bd9Sstevel@tonic-gate 				"Share: Add fh for '%s' failed: %s\n"),
2158*7c478bd9Sstevel@tonic-gate 				    args->sh_path, ((error >= 0) ?
2159*7c478bd9Sstevel@tonic-gate 				    strerror(error) : "Unknown"));
2160*7c478bd9Sstevel@tonic-gate 		}
2161*7c478bd9Sstevel@tonic-gate 	}
2162*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
2163*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(fh, NULL, fhpath, "share");
2164*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
2165*7c478bd9Sstevel@tonic-gate 	}
2166*7c478bd9Sstevel@tonic-gate }
2167*7c478bd9Sstevel@tonic-gate 
2168*7c478bd9Sstevel@tonic-gate /*
2169*7c478bd9Sstevel@tonic-gate  * nfslog_UNSHARE_fhargs - remove export path and handle from fhlist
2170*7c478bd9Sstevel@tonic-gate  */
2171*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
2172*7c478bd9Sstevel@tonic-gate static void
nfslog_UNSHARE_fhargs(nfslog_sharefsargs * args,nfslog_sharefsres * res,char * fhpath,char ** pathp1,char ** pathp2)2173*7c478bd9Sstevel@tonic-gate nfslog_UNSHARE_fhargs(nfslog_sharefsargs *args, nfslog_sharefsres *res,
2174*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
2175*7c478bd9Sstevel@tonic-gate {
2176*7c478bd9Sstevel@tonic-gate 	fhandle_t	*fh;
2177*7c478bd9Sstevel@tonic-gate 	int		error;
2178*7c478bd9Sstevel@tonic-gate 
2179*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
2180*7c478bd9Sstevel@tonic-gate 		(void) printf("=============\nUNSHARE: name '%s', fh ",
2181*7c478bd9Sstevel@tonic-gate 			args->sh_path);
2182*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, &args->sh_fh_buf,
2183*7c478bd9Sstevel@tonic-gate 			sizeof (fhandle_t));
2184*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
2185*7c478bd9Sstevel@tonic-gate 	}
2186*7c478bd9Sstevel@tonic-gate 
2187*7c478bd9Sstevel@tonic-gate 	fh = &args->sh_fh_buf;
2188*7c478bd9Sstevel@tonic-gate 
2189*7c478bd9Sstevel@tonic-gate 	/*
2190*7c478bd9Sstevel@tonic-gate 	 * This bcopy is done because the fh_data for the export/share directory
2191*7c478bd9Sstevel@tonic-gate 	 * is not meaningful with respect to the database keys.  Therefore, we
2192*7c478bd9Sstevel@tonic-gate 	 * copy the export or fh_xdata fid to the fh_data so that a reasonable
2193*7c478bd9Sstevel@tonic-gate 	 * entry will be added in the data base.
2194*7c478bd9Sstevel@tonic-gate 	 */
2195*7c478bd9Sstevel@tonic-gate 	bcopy(fh->fh_xdata, fh->fh_data, fh->fh_xlen);
2196*7c478bd9Sstevel@tonic-gate 
2197*7c478bd9Sstevel@tonic-gate 	/* If debug print the database */
2198*7c478bd9Sstevel@tonic-gate 	if (debug > 10) {
2199*7c478bd9Sstevel@tonic-gate 		fh_print_all_keys(fhpath, fh);
2200*7c478bd9Sstevel@tonic-gate 	}
2201*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
2202*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(fh, NULL, fhpath, "share");
2203*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
2204*7c478bd9Sstevel@tonic-gate 	}
2205*7c478bd9Sstevel@tonic-gate 	if (error = fh_remove(fhpath, fh, args->sh_path, pathp1)) {
2206*7c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, gettext("Unshare: '%s' failed: %s\n"),
2207*7c478bd9Sstevel@tonic-gate 			args->sh_path, ((error >= 0) ? strerror(error) :
2208*7c478bd9Sstevel@tonic-gate 			"Unknown"));
2209*7c478bd9Sstevel@tonic-gate 	}
2210*7c478bd9Sstevel@tonic-gate }
2211*7c478bd9Sstevel@tonic-gate 
2212*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
2213*7c478bd9Sstevel@tonic-gate static void
nfslog_GETFH_fhargs(nfslog_getfhargs * args,nfsstat * res,char * fhpath,char ** pathp1,char ** pathp2)2214*7c478bd9Sstevel@tonic-gate nfslog_GETFH_fhargs(nfslog_getfhargs *args, nfsstat *res,
2215*7c478bd9Sstevel@tonic-gate 	char *fhpath, char **pathp1, char **pathp2)
2216*7c478bd9Sstevel@tonic-gate {
2217*7c478bd9Sstevel@tonic-gate 	fhlist_ent	fhrec;
2218*7c478bd9Sstevel@tonic-gate 	fhandle_t	*fh;
2219*7c478bd9Sstevel@tonic-gate 	int		error;
2220*7c478bd9Sstevel@tonic-gate 
2221*7c478bd9Sstevel@tonic-gate 	if (debug > 2) {
2222*7c478bd9Sstevel@tonic-gate 		(void) printf("=============\nGETFH3: name '%s', fh ",
2223*7c478bd9Sstevel@tonic-gate 			args->gfh_path);
2224*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, &args->gfh_fh_buf,
2225*7c478bd9Sstevel@tonic-gate 			sizeof (fhandle_t));
2226*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
2227*7c478bd9Sstevel@tonic-gate 	}
2228*7c478bd9Sstevel@tonic-gate 
2229*7c478bd9Sstevel@tonic-gate 	fh = &args->gfh_fh_buf;
2230*7c478bd9Sstevel@tonic-gate 
2231*7c478bd9Sstevel@tonic-gate 	/* If debug print the database */
2232*7c478bd9Sstevel@tonic-gate 	if (debug > 10) {
2233*7c478bd9Sstevel@tonic-gate 		fh_print_all_keys(fhpath, fh);
2234*7c478bd9Sstevel@tonic-gate 	}
2235*7c478bd9Sstevel@tonic-gate 	if (fh_lookup_link(fhpath, fh, fh,
2236*7c478bd9Sstevel@tonic-gate 		args->gfh_path, &fhrec, &error) == NULL) {
2237*7c478bd9Sstevel@tonic-gate 		if (error = FH_ADD(fhpath, fh, fh, args->gfh_path)) {
2238*7c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, gettext(
2239*7c478bd9Sstevel@tonic-gate 				"Getfh: Add fh for '%s' failed: %s\n"),
2240*7c478bd9Sstevel@tonic-gate 				    args->gfh_path, ((error >= 0) ?
2241*7c478bd9Sstevel@tonic-gate 				    strerror(error) : "Unknown"));
2242*7c478bd9Sstevel@tonic-gate 		}
2243*7c478bd9Sstevel@tonic-gate 	}
2244*7c478bd9Sstevel@tonic-gate 	if (pathp1 != NULL) {
2245*7c478bd9Sstevel@tonic-gate 		*pathp1 = nfslog_get_path(fh, NULL, fhpath, "getfh");
2246*7c478bd9Sstevel@tonic-gate 		*pathp2 = NULL;
2247*7c478bd9Sstevel@tonic-gate 	}
2248*7c478bd9Sstevel@tonic-gate }
2249*7c478bd9Sstevel@tonic-gate 
2250*7c478bd9Sstevel@tonic-gate /*
2251*7c478bd9Sstevel@tonic-gate  * Exported function
2252*7c478bd9Sstevel@tonic-gate  */
2253*7c478bd9Sstevel@tonic-gate 
2254*7c478bd9Sstevel@tonic-gate /*
2255*7c478bd9Sstevel@tonic-gate  * nfslog_get_path - gets the path for this file. fh must be supplied,
2256*7c478bd9Sstevel@tonic-gate  * name may be null. If name is supplied, fh is assumed to be a directory
2257*7c478bd9Sstevel@tonic-gate  * filehandle, with name as its component. fhpath is the generic path for the
2258*7c478bd9Sstevel@tonic-gate  * fhtopath table and prtstr is the name of the caller (for debug purposes).
2259*7c478bd9Sstevel@tonic-gate  * Returns the malloc'd path. The caller must free it later.
2260*7c478bd9Sstevel@tonic-gate  */
2261*7c478bd9Sstevel@tonic-gate char *
nfslog_get_path(fhandle_t * fh,char * name,char * fhpath,char * prtstr)2262*7c478bd9Sstevel@tonic-gate nfslog_get_path(fhandle_t *fh, char *name, char *fhpath, char *prtstr)
2263*7c478bd9Sstevel@tonic-gate {
2264*7c478bd9Sstevel@tonic-gate 	char	*pathp = fh_print_absolute(fhpath, fh, name);
2265*7c478bd9Sstevel@tonic-gate 
2266*7c478bd9Sstevel@tonic-gate 	if (debug > 3) {
2267*7c478bd9Sstevel@tonic-gate 		(void) printf("   %s: path '%s', fh ", prtstr, pathp);
2268*7c478bd9Sstevel@tonic-gate 		debug_opaque_print(stdout, fh, sizeof (*fh));
2269*7c478bd9Sstevel@tonic-gate 		(void) printf("\n");
2270*7c478bd9Sstevel@tonic-gate 	}
2271*7c478bd9Sstevel@tonic-gate 	return (pathp);
2272*7c478bd9Sstevel@tonic-gate }
2273*7c478bd9Sstevel@tonic-gate 
2274*7c478bd9Sstevel@tonic-gate /*
2275*7c478bd9Sstevel@tonic-gate  * nfslog_process_fh_rec - updates the fh table based on the rpc req
2276*7c478bd9Sstevel@tonic-gate  * Return 0 for success, error otherwise. If success return the path
2277*7c478bd9Sstevel@tonic-gate  * for the input file handle(s) if so indicated.
2278*7c478bd9Sstevel@tonic-gate  */
2279*7c478bd9Sstevel@tonic-gate int
nfslog_process_fh_rec(struct nfslog_lr * lrp,char * fhpath,char ** pathp1,char ** pathp2,bool_t return_path)2280*7c478bd9Sstevel@tonic-gate nfslog_process_fh_rec(struct nfslog_lr *lrp, char *fhpath, char **pathp1,
2281*7c478bd9Sstevel@tonic-gate 	char **pathp2, bool_t return_path)
2282*7c478bd9Sstevel@tonic-gate {
2283*7c478bd9Sstevel@tonic-gate 	struct nfsl_fh_proc_disp	*disp;
2284*7c478bd9Sstevel@tonic-gate 	nfslog_request_record 		*logrec = &lrp->log_record;
2285*7c478bd9Sstevel@tonic-gate 	nfslog_record_header		*logrechdr = &logrec->re_header;
2286*7c478bd9Sstevel@tonic-gate 
2287*7c478bd9Sstevel@tonic-gate 	if ((disp = nfslog_find_fh_dispatch(logrec)) != NULL) {
2288*7c478bd9Sstevel@tonic-gate 		/*
2289*7c478bd9Sstevel@tonic-gate 		 * Allocate space for the args and results and decode
2290*7c478bd9Sstevel@tonic-gate 		 */
2291*7c478bd9Sstevel@tonic-gate 		logrec->re_rpc_arg = calloc(1, disp->args_size);
2292*7c478bd9Sstevel@tonic-gate 
2293*7c478bd9Sstevel@tonic-gate 		if (!(*disp->xdr_args)(&lrp->xdrs, logrec->re_rpc_arg)) {
2294*7c478bd9Sstevel@tonic-gate 			free(logrec->re_rpc_arg);
2295*7c478bd9Sstevel@tonic-gate 			logrec->re_rpc_arg = NULL;
2296*7c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, gettext("argument decode failed"));
2297*7c478bd9Sstevel@tonic-gate 			return (FALSE);
2298*7c478bd9Sstevel@tonic-gate 		}
2299*7c478bd9Sstevel@tonic-gate 		/* used later for free of data structures */
2300*7c478bd9Sstevel@tonic-gate 		lrp->xdrargs = disp->xdr_args;
2301*7c478bd9Sstevel@tonic-gate 
2302*7c478bd9Sstevel@tonic-gate 		logrec->re_rpc_res = calloc(1, disp->res_size);
2303*7c478bd9Sstevel@tonic-gate 		if (!(*disp->xdr_res)(&lrp->xdrs, logrec->re_rpc_res)) {
2304*7c478bd9Sstevel@tonic-gate 			free(logrec->re_rpc_res);
2305*7c478bd9Sstevel@tonic-gate 			logrec->re_rpc_res = NULL;
2306*7c478bd9Sstevel@tonic-gate 			syslog(LOG_ERR, gettext("results decode failed"));
2307*7c478bd9Sstevel@tonic-gate 			return (FALSE);
2308*7c478bd9Sstevel@tonic-gate 		}
2309*7c478bd9Sstevel@tonic-gate 		/* used later for free of data structures */
2310*7c478bd9Sstevel@tonic-gate 		lrp->xdrres = disp->xdr_res;
2311*7c478bd9Sstevel@tonic-gate 
2312*7c478bd9Sstevel@tonic-gate 		/*
2313*7c478bd9Sstevel@tonic-gate 		 * Process the operation within the context of the file handle
2314*7c478bd9Sstevel@tonic-gate 		 * mapping process
2315*7c478bd9Sstevel@tonic-gate 		 */
2316*7c478bd9Sstevel@tonic-gate 		if (return_path) {
2317*7c478bd9Sstevel@tonic-gate 			(*disp->nfsl_dis_args)(logrec->re_rpc_arg,
2318*7c478bd9Sstevel@tonic-gate 				logrec->re_rpc_res, fhpath, pathp1, pathp2);
2319*7c478bd9Sstevel@tonic-gate 		} else {
2320*7c478bd9Sstevel@tonic-gate 			if ((logrechdr->rh_version == NFS_VERSION &&
2321*7c478bd9Sstevel@tonic-gate 				logrechdr->rh_procnum == RFS_LINK) ||
2322*7c478bd9Sstevel@tonic-gate 				(logrechdr->rh_version == NFS_V3 &&
2323*7c478bd9Sstevel@tonic-gate 				logrechdr->rh_procnum == NFSPROC3_LINK)) {
2324*7c478bd9Sstevel@tonic-gate 
2325*7c478bd9Sstevel@tonic-gate 				(*disp->nfsl_dis_args)(logrec->re_rpc_arg,
2326*7c478bd9Sstevel@tonic-gate 					logrec->re_rpc_res,
2327*7c478bd9Sstevel@tonic-gate 					fhpath,	pathp1, pathp2);
2328*7c478bd9Sstevel@tonic-gate 			} else {
2329*7c478bd9Sstevel@tonic-gate 				(*disp->nfsl_dis_args)(logrec->re_rpc_arg,
2330*7c478bd9Sstevel@tonic-gate 					logrec->re_rpc_res,
2331*7c478bd9Sstevel@tonic-gate 					fhpath, NULL, NULL);
2332*7c478bd9Sstevel@tonic-gate 			}
2333*7c478bd9Sstevel@tonic-gate 		}
2334*7c478bd9Sstevel@tonic-gate 		return (TRUE);
2335*7c478bd9Sstevel@tonic-gate 	} else {
2336*7c478bd9Sstevel@tonic-gate 		syslog(LOG_ERR, gettext("procedure unknown"));
2337*7c478bd9Sstevel@tonic-gate 		return (FALSE);
2338*7c478bd9Sstevel@tonic-gate 	}
2339*7c478bd9Sstevel@tonic-gate }
2340