4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
28 * Code to maintain the runtime and on-disk filehandle mapping table for
42 #include <nfs/nfs_log.h>
46 #define ROUNDUP32(val) (((val) + 3) & ~3)
48 #define IS_DOT_FILENAME(name) \
49 ((strcmp(name, ".") == 0) || (strcmp(name, "..") == 0))
51 #define PRINT_LINK_DATA(fp, func, dfh, name, str) \
52 (void) fprintf(fp, "%s: name '%s', dfh ", \
53 func, (((name) != NULL) ? name : "")); \
54 debug_opaque_print(fp, dfh, sizeof (*(dfh))); \
55 (void) fprintf(fp, "%s\n", str);
58 #define PRINT_FULL_DATA(fp, func, dfh, fh, name, str) \
59 (void) fprintf(fp, "%s: name '%s', dfh ", \
60 func, (((name) != NULL) ? name : "")); \
61 debug_opaque_print(fp, dfh, sizeof (*(dfh))); \
63 (void) fprintf(fp, ", fh "); \
64 debug_opaque_print(fp, fh, sizeof (*(fh))); \
66 (void) fprintf(fp, "%s\n", str);
71 struct export_handle_cache
{
74 struct export_handle_cache
*next
;
77 static struct export_handle_cache
*exp_handle_cache
= NULL
;
79 extern bool_t nfsl_prin_fh
;
81 static int fh_add(char *, fhandle_t
*, fhandle_t
*, char *);
83 static char *get_export_path(fhandle_t
*, char *);
84 static void sprint_fid(char *, uint_t
, const fhandle_t
*);
85 static void fh_print_all_keys(char *fhpath
, fhandle_t
*fh
);
86 static int fh_compare(fhandle_t
*fh1
, fhandle_t
*fh2
);
87 static fhlist_ent
*fh_lookup(char *fhpath
, fhandle_t
*fh
, fhlist_ent
*fhrecp
,
89 static int fh_remove_mc_link(char *fhpath
, fhandle_t
*dfh
, char *name
,
91 static int fh_remove(char *fhpath
, fhandle_t
*dfh
, char *name
, char **pathp
);
92 static int fh_rename(char *fhpath
, fhandle_t
*from_dfh
, char *from_name
,
93 char **from_pathp
, fhandle_t
*to_dfh
, char *to_name
);
95 static fhlist_ent
*fh_lookup_link(char *fhpath
, fhandle_t
*dfh
, fhandle_t
*fh
,
96 char *name
, fhlist_ent
*fhrecp
, int *errorp
);
97 static struct nfsl_fh_proc_disp
*nfslog_find_fh_dispatch(
98 nfslog_request_record
*);
99 static struct export_handle_cache
*find_fh_in_export_cache(fhandle_t
*fh
);
100 static void add_fh_to_export_cache(fhandle_t
*fh
, char *path
);
101 static char *update_export_point(char *fhpath
, fhandle_t
*fh
, char *path
);
102 static char *fh_print_absolute(char *fhpath
, fhandle_t
*fh
, char *name
);
103 static void nfslog_null_fhargs(caddr_t
*nfsl_args
, caddr_t
*nfsl_res
,
104 char *fhpath
, char **pathp1
, char **pathp2
);
105 static void nfslog_LOOKUP_calc(fhandle_t
*dfh
, char *name
, fhandle_t
*fh
,
106 char *fhpath
, char **pathp1
, char **pathp2
, char *str
);
113 * Functions for updating the fhtable for fhtoppath and for returning
114 * the absolute pathname
116 static void nfslog_GETATTR2_fhargs(fhandle_t
*,
117 nfsstat
*, char *fhpath
, char **, char **);
118 static void nfslog_SETATTR2_fhargs(nfslog_setattrargs
*, nfsstat
*,
119 char *, char **, char **);
120 static void nfslog_LOOKUP2_fhargs(nfslog_diropargs
*, nfslog_diropres
*,
121 char *, char **, char **);
122 static void nfslog_READLINK2_fhargs(fhandle_t
*, nfslog_rdlnres
*,
123 char *, char **, char **);
124 static void nfslog_READ2_fhargs(nfslog_nfsreadargs
*, nfslog_rdresult
*,
125 char *, char **, char **);
126 static void nfslog_WRITE2_fhargs(nfslog_writeargs
*, nfslog_writeresult
*,
127 char *, char **, char **);
128 static void nfslog_CREATE2_fhargs(nfslog_createargs
*, nfslog_diropres
*,
129 char *, char **, char **);
130 static void nfslog_REMOVE2_fhargs(nfslog_diropargs
*, nfsstat
*,
131 char *, char **, char **);
132 static void nfslog_RENAME2_fhargs(nfslog_rnmargs
*, nfsstat
*,
133 char *, char **, char **);
134 static void nfslog_LINK2_fhargs(nfslog_linkargs
*, nfsstat
*,
135 char *, char **, char **);
136 static void nfslog_SYMLINK2_fhargs(nfslog_symlinkargs
*, nfsstat
*,
137 char *, char **, char **);
138 static void nfslog_READDIR2_fhargs(nfslog_rddirargs
*, nfslog_rddirres
*,
139 char *, char **, char **);
140 static void nfslog_STATFS2_fhargs(fhandle_t
*, nfsstat
*,
141 char *, char **, char **);
146 * Functions for updating the fhtable for fhtoppath
148 static void nfslog_GETATTR3_fhargs(nfs_fh3
*, nfsstat3
*,
149 char *, char **, char **);
150 static void nfslog_SETATTR3_fhargs(nfslog_SETATTR3args
*, nfsstat3
*,
151 char *, char **, char **);
152 static void nfslog_LOOKUP3_fhargs(nfslog_diropargs3
*, nfslog_LOOKUP3res
*,
153 char *, char **, char **);
154 static void nfslog_ACCESS3_fhargs(nfs_fh3
*, nfsstat3
*,
155 char *, char **, char **);
156 static void nfslog_READLINK3_fhargs(nfs_fh3
*, nfslog_READLINK3res
*,
157 char *, char **, char **);
158 static void nfslog_READ3_fhargs(nfslog_READ3args
*, nfslog_READ3res
*,
159 char *, char **, char **);
160 static void nfslog_WRITE3_fhargs(nfslog_WRITE3args
*, nfslog_WRITE3res
*,
161 char *, char **, char **);
162 static void nfslog_CREATE3_fhargs(nfslog_CREATE3args
*, nfslog_CREATE3res
*,
163 char *, char **, char **);
164 static void nfslog_MKDIR3_fhargs(nfslog_MKDIR3args
*, nfslog_MKDIR3res
*,
165 char *, char **, char **);
166 static void nfslog_SYMLINK3_fhargs(nfslog_SYMLINK3args
*, nfslog_SYMLINK3res
*,
167 char *, char **, char **);
168 static void nfslog_MKNOD3_fhargs(nfslog_MKNOD3args
*, nfslog_MKNOD3res
*,
169 char *, char **, char **);
170 static void nfslog_REMOVE3_fhargs(nfslog_REMOVE3args
*, nfsstat3
*,
171 char *, char **, char **);
172 static void nfslog_RMDIR3_fhargs(nfslog_RMDIR3args
*, nfsstat3
*,
173 char *, char **, char **);
174 static void nfslog_RENAME3_fhargs(nfslog_RENAME3args
*, nfsstat3
*,
175 char *, char **, char **);
176 static void nfslog_LINK3_fhargs(nfslog_LINK3args
*, nfsstat3
*,
177 char *, char **, char **);
178 static void nfslog_READDIR3_fhargs(nfs_fh3
*, nfsstat3
*,
179 char *, char **, char **);
180 static void nfslog_READDIRPLUS3_fhargs(nfslog_READDIRPLUS3args
*,
181 nfslog_READDIRPLUS3res
*,
182 char *, char **, char **);
183 static void nfslog_FSSTAT3_fhargs(nfs_fh3
*, nfsstat3
*,
184 char *, char **, char **);
185 static void nfslog_FSINFO3_fhargs(nfs_fh3
*, nfsstat3
*,
186 char *, char **, char **);
187 static void nfslog_PATHCONF3_fhargs(nfs_fh3
*, nfsstat3
*,
188 char *, char **, char **);
189 static void nfslog_COMMIT3_fhargs(nfslog_COMMIT3args
*, nfsstat3
*,
190 char *, char **, char **);
195 * Functions for updating the fhtable for fhtoppath
197 static void nfslog_SHARE_fhargs(nfslog_sharefsargs
*, nfslog_sharefsres
*,
198 char *, char **, char **);
199 static void nfslog_UNSHARE_fhargs(nfslog_sharefsargs
*, nfslog_sharefsres
*,
200 char *, char **, char **);
201 static void nfslog_GETFH_fhargs(nfslog_getfhargs
*, nfsstat
*,
202 char *, char **, char **);
205 * Define the actions taken per prog/vers/proc:
207 * In some cases, the nl types are the same as the nfs types and a simple
208 * bcopy should suffice. Rather that define tens of identical procedures,
209 * simply define these to bcopy. Similarly this takes care of different
210 * procs that use same parameter struct.
213 static struct nfsl_fh_proc_disp nfsl_fh_proc_v2
[] = {
219 {nfslog_null_fhargs
, xdr_void
, xdr_void
, 0, 0},
221 /* RFS_GETATTR = 1 */
222 {nfslog_GETATTR2_fhargs
, xdr_fhandle
, xdr_nfsstat
,
223 sizeof (fhandle_t
), sizeof (nfsstat
)},
225 /* RFS_SETATTR = 2 */
226 {nfslog_SETATTR2_fhargs
, xdr_nfslog_setattrargs
, xdr_nfsstat
,
227 sizeof (nfslog_setattrargs
), sizeof (nfsstat
)},
229 /* RFS_ROOT = 3 *** NO LONGER SUPPORTED *** */
230 {nfslog_null_fhargs
, xdr_void
, xdr_void
, 0, 0},
233 {nfslog_LOOKUP2_fhargs
, xdr_nfslog_diropargs
, xdr_nfslog_diropres
,
234 sizeof (nfslog_diropargs
), sizeof (nfslog_diropres
)},
236 /* RFS_READLINK = 5 */
237 {nfslog_READLINK2_fhargs
, xdr_fhandle
, xdr_nfslog_rdlnres
,
238 sizeof (fhandle_t
), sizeof (nfslog_rdlnres
)},
241 {nfslog_READ2_fhargs
, xdr_nfslog_nfsreadargs
, xdr_nfslog_rdresult
,
242 sizeof (nfslog_nfsreadargs
), sizeof (nfslog_rdresult
)},
244 /* RFS_WRITECACHE = 7 *** NO LONGER SUPPORTED *** */
245 {nfslog_null_fhargs
, xdr_void
, xdr_void
, 0, 0},
248 {nfslog_WRITE2_fhargs
, xdr_nfslog_writeargs
, xdr_nfslog_writeresult
,
249 sizeof (nfslog_writeargs
), sizeof (nfslog_writeresult
)},
252 {nfslog_CREATE2_fhargs
, xdr_nfslog_createargs
, xdr_nfslog_diropres
,
253 sizeof (nfslog_createargs
), sizeof (nfslog_diropres
)},
255 /* RFS_REMOVE = 10 */
256 {nfslog_REMOVE2_fhargs
, xdr_nfslog_diropargs
, xdr_nfsstat
,
257 sizeof (nfslog_diropargs
), sizeof (nfsstat
)},
259 /* RFS_RENAME = 11 */
260 {nfslog_RENAME2_fhargs
, xdr_nfslog_rnmargs
, xdr_nfsstat
,
261 sizeof (nfslog_rnmargs
), sizeof (nfsstat
)},
264 {nfslog_LINK2_fhargs
, xdr_nfslog_linkargs
, xdr_nfsstat
,
265 sizeof (nfslog_linkargs
), sizeof (nfsstat
)},
267 /* RFS_SYMLINK = 13 */
268 {nfslog_SYMLINK2_fhargs
, xdr_nfslog_symlinkargs
, xdr_nfsstat
,
269 sizeof (nfslog_symlinkargs
), sizeof (nfsstat
)},
272 {nfslog_CREATE2_fhargs
, xdr_nfslog_createargs
, xdr_nfslog_diropres
,
273 sizeof (nfslog_createargs
), sizeof (nfslog_diropres
)},
276 {nfslog_REMOVE2_fhargs
, xdr_nfslog_diropargs
, xdr_nfsstat
,
277 sizeof (nfslog_diropargs
), sizeof (nfsstat
)},
279 /* RFS_READDIR = 16 */
280 {nfslog_READDIR2_fhargs
, xdr_nfslog_rddirargs
, xdr_nfslog_rddirres
,
281 sizeof (nfslog_rddirargs
), sizeof (nfslog_rddirres
)},
283 /* RFS_STATFS = 17 */
284 {nfslog_STATFS2_fhargs
, xdr_fhandle
, xdr_nfsstat
,
285 sizeof (fhandle_t
), sizeof (nfsstat
)},
293 static struct nfsl_fh_proc_disp nfsl_fh_proc_v3
[] = {
296 {nfslog_null_fhargs
, xdr_void
, xdr_void
, 0, 0},
298 /* RFS3_GETATTR = 1 */
299 {nfslog_GETATTR3_fhargs
, xdr_nfs_fh3
, xdr_nfsstat3
,
300 sizeof (nfs_fh3
), sizeof (nfsstat3
)},
302 /* RFS3_SETATTR = 2 */
303 {nfslog_SETATTR3_fhargs
, xdr_nfslog_SETATTR3args
, xdr_nfsstat3
,
304 sizeof (nfslog_SETATTR3args
), sizeof (nfsstat3
)},
306 /* RFS3_LOOKUP = 3 */
307 {nfslog_LOOKUP3_fhargs
, xdr_nfslog_diropargs3
, xdr_nfslog_LOOKUP3res
,
308 sizeof (nfslog_diropargs3
), sizeof (nfslog_LOOKUP3res
)},
310 /* RFS3_ACCESS = 4 */
311 {nfslog_ACCESS3_fhargs
, xdr_nfs_fh3
, xdr_nfsstat3
,
312 sizeof (nfs_fh3
), sizeof (nfsstat3
)},
314 /* RFS3_READLINK = 5 */
315 {nfslog_READLINK3_fhargs
, xdr_nfs_fh3
, xdr_nfslog_READLINK3res
,
316 sizeof (nfs_fh3
), sizeof (nfslog_READLINK3res
)},
319 {nfslog_READ3_fhargs
, xdr_nfslog_READ3args
, xdr_nfslog_READ3res
,
320 sizeof (nfslog_READ3args
), sizeof (nfslog_READ3res
)},
323 {nfslog_WRITE3_fhargs
, xdr_nfslog_WRITE3args
, xdr_nfslog_WRITE3res
,
324 sizeof (nfslog_WRITE3args
), sizeof (nfslog_WRITE3res
)},
326 /* RFS3_CREATE = 8 */
327 {nfslog_CREATE3_fhargs
, xdr_nfslog_CREATE3args
, xdr_nfslog_CREATE3res
,
328 sizeof (nfslog_CREATE3args
), sizeof (nfslog_CREATE3res
)},
331 {nfslog_MKDIR3_fhargs
, xdr_nfslog_MKDIR3args
, xdr_nfslog_MKDIR3res
,
332 sizeof (nfslog_MKDIR3args
), sizeof (nfslog_MKDIR3res
)},
334 /* RFS3_SYMLINK = 10 */
335 {nfslog_SYMLINK3_fhargs
, xdr_nfslog_SYMLINK3args
,
336 xdr_nfslog_SYMLINK3res
,
337 sizeof (nfslog_SYMLINK3args
), sizeof (nfslog_SYMLINK3res
)},
339 /* RFS3_MKNOD = 11 */
340 {nfslog_MKNOD3_fhargs
, xdr_nfslog_MKNOD3args
, xdr_nfslog_MKNOD3res
,
341 sizeof (nfslog_MKNOD3args
), sizeof (nfslog_MKNOD3res
)},
343 /* RFS3_REMOVE = 12 */
344 {nfslog_REMOVE3_fhargs
, xdr_nfslog_REMOVE3args
, xdr_nfsstat3
,
345 sizeof (nfslog_REMOVE3args
), sizeof (nfsstat3
)},
347 /* RFS3_RMDIR = 13 */
348 {nfslog_RMDIR3_fhargs
, xdr_nfslog_RMDIR3args
, xdr_nfsstat3
,
349 sizeof (nfslog_RMDIR3args
), sizeof (nfsstat3
)},
351 /* RFS3_RENAME = 14 */
352 {nfslog_RENAME3_fhargs
, xdr_nfslog_RENAME3args
, xdr_nfsstat3
,
353 sizeof (nfslog_RENAME3args
), sizeof (nfsstat3
)},
356 {nfslog_LINK3_fhargs
, xdr_nfslog_LINK3args
, xdr_nfsstat3
,
357 sizeof (nfslog_LINK3args
), sizeof (nfsstat3
)},
359 /* RFS3_READDIR = 16 */
360 {nfslog_READDIR3_fhargs
, xdr_nfs_fh3
, xdr_nfsstat3
,
361 sizeof (nfs_fh3
), sizeof (nfsstat3
)},
363 /* RFS3_READDIRPLUS = 17 */
364 {nfslog_READDIRPLUS3_fhargs
,
365 xdr_nfslog_READDIRPLUS3args
, xdr_nfslog_READDIRPLUS3res
,
366 sizeof (nfslog_READDIRPLUS3args
),
367 sizeof (nfslog_READDIRPLUS3res
)},
369 /* RFS3_FSSTAT = 18 */
370 {nfslog_FSSTAT3_fhargs
, xdr_nfs_fh3
, xdr_nfsstat3
,
371 sizeof (nfs_fh3
), sizeof (nfsstat3
)},
373 /* RFS3_FSINFO = 19 */
374 {nfslog_FSINFO3_fhargs
, xdr_nfs_fh3
, xdr_nfsstat3
,
375 sizeof (nfs_fh3
), sizeof (nfsstat3
)},
377 /* RFS3_PATHCONF = 20 */
378 {nfslog_PATHCONF3_fhargs
, xdr_nfs_fh3
, xdr_nfsstat3
,
379 sizeof (nfs_fh3
), sizeof (nfsstat3
)},
381 /* RFS3_COMMIT = 21 */
382 {nfslog_COMMIT3_fhargs
, xdr_nfslog_COMMIT3args
, xdr_nfsstat3
,
383 sizeof (nfslog_COMMIT3args
), sizeof (nfsstat3
)},
390 static struct nfsl_fh_proc_disp nfsl_log_fh_proc_v1
[] = {
392 /* NFSLOG_NULL = 0 */
393 {nfslog_null_fhargs
, xdr_void
, xdr_void
, 0, 0},
395 /* NFSLOG_SHARE = 1 */
396 {nfslog_SHARE_fhargs
, xdr_nfslog_sharefsargs
, xdr_nfslog_sharefsres
,
397 sizeof (nfslog_sharefsargs
), sizeof (nfslog_sharefsres
)},
399 /* NFSLOG_UNSHARE = 2 */
400 {nfslog_UNSHARE_fhargs
, xdr_nfslog_sharefsargs
, xdr_nfslog_sharefsres
,
401 sizeof (nfslog_sharefsargs
), sizeof (nfslog_sharefsres
)},
403 /* NFSLOG_LOOKUP3 = 3 */
404 {nfslog_LOOKUP3_fhargs
, xdr_nfslog_diropargs3
, xdr_nfslog_LOOKUP3res
,
405 sizeof (nfslog_diropargs3
), sizeof (nfslog_LOOKUP3res
)},
407 /* NFSLOG_GETFH = 4 */
408 {nfslog_GETFH_fhargs
, xdr_nfslog_getfhargs
, xdr_nfsstat
,
409 sizeof (nfslog_getfhargs
), sizeof (nfsstat
)},
412 static struct nfsl_fh_vers_disp nfsl_fh_vers_disptable
[] = {
413 {sizeof (nfsl_fh_proc_v2
) / sizeof (nfsl_fh_proc_v2
[0]),
415 {sizeof (nfsl_fh_proc_v3
) / sizeof (nfsl_fh_proc_v3
[0]),
419 static struct nfsl_fh_vers_disp nfsl_log_fh_vers_disptable
[] = {
420 {sizeof (nfsl_log_fh_proc_v1
) / sizeof (nfsl_log_fh_proc_v1
[0]),
421 nfsl_log_fh_proc_v1
},
424 static struct nfsl_fh_prog_disp nfsl_fh_dispatch_table
[] = {
427 sizeof (nfsl_fh_vers_disptable
) /
428 sizeof (nfsl_fh_vers_disptable
[0]),
429 nfsl_fh_vers_disptable
},
432 sizeof (nfsl_log_fh_vers_disptable
) /
433 sizeof (nfsl_log_fh_vers_disptable
[0]),
434 nfsl_log_fh_vers_disptable
},
437 static int nfsl_fh_dispatch_table_arglen
=
438 sizeof (nfsl_fh_dispatch_table
) /
439 sizeof (nfsl_fh_dispatch_table
[0]);
444 * print the fid into the given string as a series of hex digits.
445 * XXX Ideally, we'd like to just convert the filehandle into an i-number,
446 * but the fid encoding is a little tricky (see nfs_fhtovp() and
447 * ufs_vget()) and may be private to UFS.
451 sprint_fid(char *buf
, uint_t buflen
, const fhandle_t
*fh
)
458 * If the filehandle somehow got corrupted, only print the part
461 if (fh
->fh_len
> NFS_FHMAXDATA
)
462 fhlen
= NFS_FHMAXDATA
;
465 assert(2 * fhlen
< buflen
);
467 for (i
= 0; i
< fhlen
; i
++) {
468 byte
= fh
->fh_data
[i
];
469 (void) sprintf(buf
+ 2 * i
, "%02x", byte
);
474 fh_print_all_keys(char *fhpath
, fhandle_t
*fh
)
476 if ((fhpath
== NULL
) || (fh
== NULL
) || (debug
<= 1))
478 (void) printf("\nBegin all database keys\n");
479 db_print_all_keys(fhpath
, &fh
->fh_fsid
, stdout
);
480 (void) printf("\nEnd all database keys\n");
483 #define FH_ADD(path, dfh, fh, name) \
484 fh_add(path, dfh, fh, name)
487 * Add the filehandle "fh", which has the name "name" and lives in
488 * directory "dfh", to the table "fhlist". "fhlist" will be updated if the
489 * entry is added to the front of the list.
490 * Return 0 for success, error code otherwise.
493 fh_add(char *fhpath
, fhandle_t
*dfh
, fhandle_t
*fh
, char *name
)
498 if (IS_DOT_FILENAME(name
)) {
499 /* we don't insert these to the database but not an error */
501 PRINT_FULL_DATA(stdout
, "fh_add", dfh
, fh
, name
,
506 if (dfh
&& (memcmp(fh
, dfh
, NFS_FHSIZE
) == 0)) {
507 flags
|= EXPORT_POINT
;
510 /* Add to database */
511 error
= db_add(fhpath
, dfh
, name
, fh
, flags
);
514 (void) printf("db_add error %s:\n",
515 ((error
>= 0) ? strerror(error
) : "Unknown"));
516 PRINT_FULL_DATA(stdout
, "fh_add", dfh
, fh
, name
, "")
517 } else if (debug
> 2) {
518 PRINT_FULL_DATA(stdout
, "fh_add", dfh
, fh
, name
, "")
525 * fh_compare returns 0 if the file handles match, error code otherwise
528 fh_compare(fhandle_t
*fh1
, fhandle_t
*fh2
)
530 if (memcmp(fh1
, fh2
, NFS_FHSIZE
))
537 * Try to find the filehandle "fh" in the table. Returns 0 and the
538 * corresponding table entry if found, error otherwise.
539 * If successfull and fhrecpp is non-null then *fhrecpp points to the
540 * returned record. If *fhrecpp was initially null, that record had
541 * been malloc'd and must be freed by caller.
545 fh_lookup(char *fhpath
, fhandle_t
*fh
, fhlist_ent
*fhrecp
, int *errorp
)
548 (void) printf("fh_lookup: fh ");
549 debug_opaque_print(stdout
, fh
, sizeof (*fh
));
552 return (db_lookup(fhpath
, fh
, fhrecp
, errorp
));
556 * Remove the mc link if exists when removing a regular link.
557 * Return 0 for success, error code otherwise.
560 fh_remove_mc_link(char *fhpath
, fhandle_t
*dfh
, char *name
, char **pathp
)
565 /* Delete the multi-component path if exists */
566 if ((pathp
== NULL
) || (*pathp
== NULL
)) {
567 str
= nfslog_get_path(dfh
, name
, fhpath
, "remove_mc_link");
573 error
= db_delete_link(fhpath
, &public_fh
, str
);
579 * Remove the link entry from the fh table.
580 * Return 0 for success, error code otherwise.
583 fh_remove(char *fhpath
, fhandle_t
*dfh
, char *name
, char **pathp
)
586 * disconnect element from list
588 * Remove the link entry for the file. Remove fh entry if last link.
590 if (IS_DOT_FILENAME(name
)) {
591 /* we don't insert these to the database but not an error */
593 PRINT_LINK_DATA(stdout
, "fh_remove", dfh
, name
,
599 PRINT_LINK_DATA(stdout
, "fh_remove", dfh
, name
, "")
601 /* Delete the multi-component path if exists */
602 (void) fh_remove_mc_link(fhpath
, dfh
, name
, pathp
);
603 return (db_delete_link(fhpath
, dfh
, name
));
607 * fh_rename - renames a link in the database (adds the new one if from link
609 * Return 0 for success, error code otherwise.
612 fh_rename(char *fhpath
, fhandle_t
*from_dfh
, char *from_name
, char **from_pathp
,
613 fhandle_t
*to_dfh
, char *to_name
)
616 PRINT_LINK_DATA(stdout
, "fh_rename: from:", from_dfh
,
618 PRINT_LINK_DATA(stdout
, "fh_rename: to :", to_dfh
,
622 * if any of these are dot files (should not happen), the rename
623 * becomes a "delete" or "add" operation because the dot files
624 * don't get in the database
626 if (IS_DOT_FILENAME(to_name
)) {
627 /* it is just a delete op */
629 (void) printf("to: no dot files\nDelete from: '%s'\n",
632 return (fh_remove(fhpath
, from_dfh
, from_name
, from_pathp
));
633 } else if (IS_DOT_FILENAME(from_name
)) {
634 /* we don't insert these to the database */
636 (void) printf("rename - from: no dot files\n");
638 /* can't insert the target, because don't have a handle */
641 /* Delete the multi-component path if exists */
642 (void) fh_remove_mc_link(fhpath
, from_dfh
, from_name
, from_pathp
);
643 return (db_rename_link(fhpath
, from_dfh
, from_name
, to_dfh
, to_name
));
647 * fh_lookup_link - search the fhtable for the link defined by (dfh,name,fh).
648 * Return 0 and set *fhrecpp to the fhlist item corresponding to it if found,
649 * or error if not found.
650 * Possible configurations:
651 * 1. dfh, fh, name are all non-null: Only exact match accepted.
652 * 2. dfh,name non-null, fh null: return first match found.
653 * 3. fh,name non-null, dfh null: return first match found.
654 * 3. fh non-null, dfh, name null: return first match found.
655 * If successfull and fhrecpp is non-null then *fhrecpp points to the
656 * returned record. If *fhrecpp was initially null, that record had
657 * been malloc'd and must be freed by caller.
660 fh_lookup_link(char *fhpath
, fhandle_t
*dfh
, fhandle_t
*fh
, char *name
,
661 fhlist_ent
*fhrecp
, int *errorp
)
663 fhlist_ent
*in_fhrecp
= fhrecp
;
665 if ((name
!= NULL
) && IS_DOT_FILENAME(name
)) {
666 /* we don't insert these to the database but not an error */
668 PRINT_FULL_DATA(stdout
, "fh_lookup_link", dfh
, fh
, name
,
675 PRINT_FULL_DATA(stdout
, "fh_lookup_link", dfh
, fh
, name
, "")
677 /* Add to database */
679 fhrecp
= db_lookup(fhpath
, fh
, fhrecp
, errorp
);
680 if (fhrecp
== NULL
) {
682 (void) printf("fh_lookup_link: fh not found\n");
685 /* Check if name and dfh match, if not search link */
686 if (((dfh
== NULL
) || !fh_compare(dfh
, &fhrecp
->dfh
)) &&
687 ((name
== NULL
) || (strcmp(name
, fhrecp
->name
) == 0))) {
691 /* Found the primary record, but it's a different link */
692 if (debug
== 3) { /* Only log if >2 but already printed */
693 PRINT_FULL_DATA(stdout
, "fh_lookup_link", dfh
, fh
,
697 PRINT_LINK_DATA(stdout
, "Different primary link",
698 &fhrecp
->dfh
, fhrecp
->name
, "")
700 /* can now free the record unless it was supplied by caller */
701 if (fhrecp
!= in_fhrecp
) {
706 /* If here, we must search by link */
707 if ((dfh
== NULL
) || (name
== NULL
)) {
709 (void) printf("fh_lookup_link: invalid params\n");
713 fhrecp
= db_lookup_link(fhpath
, dfh
, name
, fhrecp
, errorp
);
714 if (fhrecp
== NULL
) {
716 (void) printf("fh_lookup_link: link not found: %s\n",
717 ((*errorp
>= 0) ? strerror(*errorp
) : "Unknown"));
720 /* If all args supplied, check if an exact match */
721 if ((fh
!= NULL
) && fh_compare(fh
, &fhrecp
->fh
)) {
723 PRINT_FULL_DATA(stderr
, "fh_lookup_link", dfh
, fh
,
725 PRINT_LINK_DATA(stderr
, "Different primary link",
726 &fhrecp
->dfh
, fhrecp
->name
, "")
728 if (fhrecp
!= in_fhrecp
)
735 (void) printf("lookup: found '%s' in fhtable\n", name
);
741 * Export handle cache is maintained if we see an export handle that either
742 * cannot have the path for it determined, or we failed store it.
743 * Usually the path of an export handle can be identified in the NFSLOGTAB
744 * and since every path for that filesystem will be affected, it's worth
745 * caching the ones we had problem identifying.
749 * find_fh_in_export_cache - given an export fh, find it in the cache and
752 static struct export_handle_cache
*
753 find_fh_in_export_cache(fhandle_t
*fh
)
755 struct export_handle_cache
*p
;
757 for (p
= exp_handle_cache
; p
!= NULL
; p
= p
->next
) {
758 if (memcmp(fh
, &p
->fh
, sizeof (*fh
)) == 0)
765 add_fh_to_export_cache(fhandle_t
*fh
, char *path
)
767 struct export_handle_cache
*new;
769 if ((new = malloc(sizeof (*new))) == NULL
) {
770 syslog(LOG_ERR
, gettext(
771 "add_fh_to_export_cache: alloc new for '%s' Error %s\n"),
772 ((path
!= NULL
) ? path
: ""), strerror(errno
));
776 if ((new->name
= malloc(strlen(path
) + 1)) == NULL
) {
777 syslog(LOG_ERR
, gettext(
778 "add_fh_to_export_cache: alloc '%s'"
779 " Error %s\n"), path
, strerror(errno
));
783 (void) strcpy(new->name
, path
);
787 (void) memcpy(&new->fh
, fh
, sizeof (*fh
));
788 new->next
= exp_handle_cache
;
789 exp_handle_cache
= new;
793 * update_export_point - called when the path for fh cannot be determined.
794 * In the past it called get_export_path() to get the name of the
795 * export point given a filehandle. This was a hack, since there's no
796 * reason why the filehandle should be lost.
798 * If a match is found, insert the path to the database.
799 * Return the inserted fhrecp is found,
800 * and NULL if not. If it is an exported fs but not in the list, log a
802 * If input fhrecp is non-null, it is a valid address for result,
803 * otherwise malloc it.
806 update_export_point(char *fhpath
, fhandle_t
*fh
, char *path
)
808 struct export_handle_cache
*p
;
810 if ((fh
== NULL
) || memcmp(&fh
->fh_data
, &fh
->fh_xdata
, fh
->fh_len
)) {
811 /* either null fh or not the root of a shared directory */
814 /* Did we already see (and fail) this one? */
815 if ((p
= find_fh_in_export_cache(fh
)) != NULL
) {
818 PRINT_LINK_DATA(stdout
, "update_export_point",
819 fh
, ((p
->name
!= NULL
) ? p
->name
: ""), "");
824 * We should not normally be here - only add to cache if
827 if ((path
== NULL
) &&
828 ((path
= malloc(strlen(p
->name
) + 1)) == NULL
)) {
829 syslog(LOG_ERR
, gettext(
830 "update_export_point: malloc '%s' Error %s"),
831 p
->name
, strerror(errno
));
834 (void) strcpy(path
, p
->name
);
837 if ((path
= get_export_path(fh
, path
)) == NULL
) {
838 add_fh_to_export_cache(fh
, NULL
);
843 PRINT_LINK_DATA(stdout
, "update_export_point", fh
, path
, "")
845 if (FH_ADD(fhpath
, fh
, fh
, path
)) {
846 /* cache this handle so we don't repeat the search */
847 add_fh_to_export_cache(fh
, path
);
853 * HACK!!! To get rid of get_export_path() use
857 get_export_path(fhandle_t
*fh
, char *path
)
863 * Return the absolute pathname for the filehandle "fh", using the mapping
864 * table "fhlist". The caller must free the return string.
865 * name is an optional dir component name, to be appended at the end
866 * (if name is non-null, the function assumes the fh is the parent directory)
868 * Note: The original code was recursive, which was much more elegant but
869 * ran out of stack...
873 fh_print_absolute(char *fhpath
, fhandle_t
*fh
, char *name
)
875 char *str
, *rootname
, parent
[MAXPATHLEN
];
876 int i
, j
, k
, len
, error
;
877 fhlist_ent fhrec
, *fhrecp
;
882 (void) printf("fh_print_absolute: input name '%s'\n",
883 ((name
!= NULL
) ? name
: ""));
884 /* If name starts with '/' we are done */
885 if ((name
!= NULL
) && (name
[0] == '/')) {
886 if ((str
= strdup(name
)) == NULL
) {
887 syslog(LOG_ERR
, gettext(
888 "fh_print_absolute: strdup '%s' error %s\n"),
889 name
, strerror(errno
));
893 namelen
= ((name
!= NULL
) ? strlen(name
) + 2 : 0);
896 /* remember the last filehandle we've seen */
897 (void) memcpy((void *) &prevfh
, (void *) fh
, sizeof (*fh
));
900 /* dump all names in reverse order */
901 while ((fhrecp
= fh_lookup(fhpath
, fh
, &fhrec
, &error
)) != NULL
&&
902 !(fhrecp
->flags
& (EXPORT_POINT
| PUBLIC_PATH
))) {
905 (void) printf("fh_print_absolute: name '%s'%s\n",
907 ((fhrecp
->flags
& EXPORT_POINT
) ? "root" : ""));
909 if (memcmp(&prevfh
, &fhrecp
->dfh
, sizeof (*fh
)) == 0) {
910 /* dfh == prevfh but not an export point */
913 "fh_print_absolute: fhrec loop:\n");
914 debug_opaque_print(stdout
, fhrecp
,
919 (void) strcat(parent
, "/");
920 (void) strcat(parent
, fhrecp
->name
);
922 /* remember the last filehandle we've seen */
923 (void) memcpy(&prevfh
, &fhrecp
->dfh
, sizeof (fhrecp
->dfh
));
925 assert(fh
== &prevfh
);
927 if (fhrecp
!= NULL
) {
928 rootname
= fhrecp
->name
;
930 /* Check if export point, just in case... */
931 /* There should be enough room in parent, leave the '\0' */
932 rootname
= update_export_point(
933 fhpath
, fh
, &parent
[strlen(parent
) + 1]);
935 /* Now need to reverse the order */
936 if (rootname
!= NULL
) { /* *fhrecp is the export point */
937 len
= strlen(rootname
) + 2;
939 len
= 2 * (NFS_FHMAXDATA
+ fh
->fh_len
); /* fid instead */
941 len
= ROUNDUP32(len
+ namelen
+ strlen(parent
));
942 if ((str
= malloc(len
)) == NULL
) {
943 syslog(LOG_ERR
, gettext(
944 "fh_print_absolute: malloc %d error %s\n"),
945 len
, strerror(errno
));
948 /* first put the export point path in */
949 if (rootname
!= NULL
) { /* *fhrecp is the export point */
950 (void) strcpy(str
, rootname
);
952 sprint_fid(str
, len
, fh
);
954 for (k
= strlen(str
), i
= strlen(parent
); (k
< len
) && (i
>= 0); i
--) {
955 for (j
= i
; (j
>= 0) && (parent
[j
] != '/'); j
--);
958 (void) strcpy(&str
[k
], &parent
[j
]);
959 k
+= strlen(&str
[k
]);
962 if ((name
!= NULL
) && ((k
+ namelen
) <= len
)) {
964 (void) strcpy(&str
[k
+ 1], name
);
967 (void) printf("fh_print_absolute: path '%s'\n", str
);
972 * nfslog_find_fh_dispatch - get the dispatch struct for this request
974 static struct nfsl_fh_proc_disp
*
975 nfslog_find_fh_dispatch(nfslog_request_record
*logrec
)
977 nfslog_record_header
*logrechdr
= &logrec
->re_header
;
978 struct nfsl_fh_prog_disp
*progtable
; /* prog struct */
979 struct nfsl_fh_vers_disp
*verstable
; /* version struct */
982 /* Find prog element - search because can't use prog as array index */
983 for (i
= 0; (i
< nfsl_fh_dispatch_table_arglen
) &&
984 (logrechdr
->rh_prognum
!= nfsl_fh_dispatch_table
[i
].nfsl_dis_prog
);
986 if (i
>= nfsl_fh_dispatch_table_arglen
) { /* program not logged */
990 progtable
= &nfsl_fh_dispatch_table
[i
];
991 /* Find vers element - no validity check - if here it's valid vers */
992 vers
= logrechdr
->rh_version
- progtable
->nfsl_dis_versmin
;
993 verstable
= &progtable
->nfsl_dis_vers_table
[vers
];
994 /* Find proc element - no validity check - if here it's valid proc */
995 return (&verstable
->nfsl_dis_proc_table
[logrechdr
->rh_procnum
]);
1000 nfslog_null_fhargs(caddr_t
*nfsl_args
, caddr_t
*nfsl_res
,
1001 char *fhpath
, char **pathp1
, char **pathp2
)
1008 * nfslog_LOOKUP_calc - called by both lookup3 and lookup2. Handles the
1009 * mclookup as well as normal lookups.
1013 nfslog_LOOKUP_calc(fhandle_t
*dfh
, char *name
, fhandle_t
*fh
,
1014 char *fhpath
, char **pathp1
, char **pathp2
, char *str
)
1020 if (fh
== &public_fh
) {
1021 /* a fake lookup to inform us of the public fs path */
1022 if (error
= FH_ADD(fhpath
, fh
, fh
, name
)) {
1023 syslog(LOG_ERR
, gettext(
1024 "%s: Add Public fs '%s' failed: %s\n"),
1026 ((error
>= 0) ? strerror(error
) : "Unknown"));
1028 if (pathp1
!= NULL
) {
1029 *pathp1
= nfslog_get_path(dfh
, NULL
, fhpath
, str
);
1034 if (pathp1
!= NULL
) {
1035 *pathp1
= nfslog_get_path(dfh
, name
, fhpath
, str
);
1039 /* If public fh mclookup, then insert complete path */
1040 if (dfh
== &public_fh
) {
1041 if (pathp1
!= NULL
) {
1044 name
= nfslog_get_path(dfh
, name
, fhpath
, str
);
1048 if (fh_lookup_link(fhpath
, dfh
, fh
, name
, &fhrec
, &error
) != NULL
) {
1049 /* link already in table */
1053 /* A new link so add it */
1054 if (error
= FH_ADD(fhpath
, dfh
, fh
, name
)) {
1055 syslog(LOG_ERR
, gettext(
1056 "%s: Add fh for '%s' failed: %s\n"), str
,
1057 name
, ((error
>= 0) ? strerror(error
) : "Unknown"));
1066 /* Functions for updating the fhtable for fhtoppath */
1069 * nfslog_GETATTR2_fhargs - updates path1 but no fhtable changes
1073 nfslog_GETATTR2_fhargs(fhandle_t
*args
, nfsstat
*res
,
1074 char *fhpath
, char **pathp1
, char **pathp2
)
1077 (void) printf("=============\nGETATTR2: fh ");
1078 debug_opaque_print(stdout
, args
, sizeof (*args
));
1079 (void) printf("\n");
1081 if (pathp1
!= NULL
) {
1082 *pathp1
= nfslog_get_path(NFSLOG_GET_FHANDLE2(args
),
1083 NULL
, fhpath
, "getattr2");
1089 * nfslog_SETATTR2_fhargs - updates path1 but no fhtable changes
1093 nfslog_SETATTR2_fhargs(nfslog_setattrargs
*args
, nfsstat
*res
,
1094 char *fhpath
, char **pathp1
, char **pathp2
)
1097 (void) printf("=============\nSETATTR2: fh ");
1098 debug_opaque_print(stdout
, &args
->saa_fh
,
1099 sizeof (args
->saa_fh
));
1100 (void) printf("\n");
1102 if (pathp1
!= NULL
) {
1103 *pathp1
= nfslog_get_path(NFSLOG_GET_FHANDLE2(&args
->saa_fh
),
1104 NULL
, fhpath
, "setattr2");
1110 * nfslog_LOOKUP2_fhargs - search the table to ensure we have not added this
1111 * one already. Note that if the response status was anything but okay,
1112 * there is no fh to check...
1116 nfslog_LOOKUP2_fhargs(nfslog_diropargs
*args
, nfslog_diropres
*res
,
1117 char *fhpath
, char **pathp1
, char **pathp2
)
1120 fhandle_t
*dfh
, *fh
;
1122 dfh
= &args
->da_fhandle
;
1123 name
= args
->da_name
;
1125 if (res
->dr_status
== NFS_OK
)
1126 fh
= &res
->nfslog_diropres_u
.dr_ok
.drok_fhandle
;
1129 PRINT_FULL_DATA(stdout
, "=============\nLOOKUP2",
1131 if (res
->dr_status
!= NFS_OK
)
1132 (void) printf("status %d\n", res
->dr_status
);
1134 dfh
= NFSLOG_GET_FHANDLE2(dfh
);
1135 if ((dfh
== &public_fh
) && (name
[0] == '\x80')) {
1136 /* special mclookup */
1139 if (res
->dr_status
!= NFS_OK
) {
1140 if (pathp1
!= NULL
) {
1141 *pathp1
= nfslog_get_path(dfh
, name
, fhpath
, "lookup2");
1146 fh
= NFSLOG_GET_FHANDLE2(&res
->nfslog_diropres_u
.dr_ok
.drok_fhandle
);
1147 nfslog_LOOKUP_calc(dfh
, name
, fh
, fhpath
, pathp1
, pathp2
, "Lookup2");
1151 * nfslog_READLINK2_fhargs - updates path1 but no fhtable changes
1155 nfslog_READLINK2_fhargs(fhandle_t
*args
, nfslog_rdlnres
*res
,
1156 char *fhpath
, char **pathp1
, char **pathp2
)
1159 (void) printf("=============\nREADLINK2: fh ");
1160 debug_opaque_print(stdout
, args
, sizeof (*args
));
1161 (void) printf("\n");
1163 if (pathp1
!= NULL
) {
1164 *pathp1
= nfslog_get_path(NFSLOG_GET_FHANDLE2(args
),
1165 NULL
, fhpath
, "readlink2");
1171 * nfslog_READ2_fhargs - updates path1 but no fhtable changes
1175 nfslog_READ2_fhargs(nfslog_nfsreadargs
*args
, nfslog_rdresult
*res
,
1176 char *fhpath
, char **pathp1
, char **pathp2
)
1179 (void) printf("=============\nREAD2: fh ");
1180 debug_opaque_print(stdout
, &args
->ra_fhandle
,
1181 sizeof (args
->ra_fhandle
));
1182 (void) printf("\n");
1184 if (pathp1
!= NULL
) {
1185 *pathp1
= nfslog_get_path(
1186 NFSLOG_GET_FHANDLE2(&args
->ra_fhandle
),
1187 NULL
, fhpath
, "read2");
1193 * nfslog_WRITE2_fhargs - updates path1 but no fhtable changes
1197 nfslog_WRITE2_fhargs(nfslog_writeargs
*args
, nfslog_writeresult
*res
,
1198 char *fhpath
, char **pathp1
, char **pathp2
)
1201 (void) printf("=============\nWRITE2: fh ");
1202 debug_opaque_print(stdout
, &args
->waargs_fhandle
,
1203 sizeof (args
->waargs_fhandle
));
1204 (void) printf("\n");
1206 if (pathp1
!= NULL
) {
1207 *pathp1
= nfslog_get_path(
1208 NFSLOG_GET_FHANDLE2(&args
->waargs_fhandle
),
1209 NULL
, fhpath
, "write2");
1215 * nfslog_CREATE2_fhargs - if the operation succeeded, we are sure there can
1216 * be no such link in the fhtable, so just add it.
1220 nfslog_CREATE2_fhargs(nfslog_createargs
*args
, nfslog_diropres
*res
,
1221 char *fhpath
, char **pathp1
, char **pathp2
)
1224 fhandle_t
*dfh
, *fh
;
1227 name
= args
->ca_da
.da_name
;
1228 dfh
= &args
->ca_da
.da_fhandle
;
1230 if (res
->dr_status
== NFS_OK
)
1231 fh
= &res
->nfslog_diropres_u
.dr_ok
.drok_fhandle
;
1234 PRINT_FULL_DATA(stdout
, "=============\nCREATE2",
1236 if (res
->dr_status
!= NFS_OK
)
1237 (void) printf("status %d\n", res
->dr_status
);
1239 dfh
= NFSLOG_GET_FHANDLE2(dfh
);
1240 if (pathp1
!= NULL
) {
1241 *pathp1
= nfslog_get_path(dfh
, name
, fhpath
, "create2");
1245 if (res
->dr_status
!= NFS_OK
)
1246 /* no returned fh so nothing to add */
1249 /* A new file handle so add it */
1250 fh
= NFSLOG_GET_FHANDLE2(&res
->nfslog_diropres_u
.dr_ok
.drok_fhandle
);
1251 if (error
= FH_ADD(fhpath
, dfh
, fh
, name
)) {
1252 syslog(LOG_ERR
, gettext(
1253 "Create2: Add fh for '%s' failed: %s\n"),
1254 name
, ((error
>= 0) ? strerror(error
) : "Unknown"));
1259 * nfslog_REMOVE2_fhargs - if the operation succeeded, remove the link from
1264 nfslog_REMOVE2_fhargs(nfslog_diropargs
*args
, nfsstat
*res
,
1265 char *fhpath
, char **pathp1
, char **pathp2
)
1271 name
= args
->da_name
;
1272 dfh
= &args
->da_fhandle
;
1274 PRINT_LINK_DATA(stdout
, "=============\nREMOVE2", dfh
, name
, "")
1276 (void) printf("status %d\n", *res
);
1278 dfh
= NFSLOG_GET_FHANDLE2(dfh
);
1279 if (pathp1
!= NULL
) {
1280 *pathp1
= nfslog_get_path(dfh
, name
, fhpath
, "remove2");
1285 /* remove failed so nothing to update */
1288 if (error
= fh_remove(fhpath
, dfh
, name
, pathp1
)) {
1289 syslog(LOG_ERR
, gettext("Remove2: '%s' failed: %s\n"),
1290 name
, ((error
>= 0) ? strerror(error
) : "Unknown"));
1295 * nfsl_RENAME2_fhargs - updates the dfh and name fields for the given fh
1296 * to change them to the new name.
1300 nfslog_RENAME2_fhargs(nfslog_rnmargs
*args
, nfsstat
*res
,
1301 char *fhpath
, char **pathp1
, char **pathp2
)
1303 char *from_name
, *to_name
;
1304 fhandle_t
*from_dfh
, *to_dfh
;
1307 from_name
= args
->rna_from
.da_name
;
1308 from_dfh
= &args
->rna_from
.da_fhandle
;
1309 to_name
= args
->rna_to
.da_name
;
1310 to_dfh
= &args
->rna_to
.da_fhandle
;
1312 PRINT_LINK_DATA(stdout
, "=============\nRENAME2: from",
1313 from_dfh
, from_name
, "")
1314 PRINT_LINK_DATA(stdout
, "RENAME2: to ", to_dfh
,
1317 (void) printf("status %d\n", *res
);
1319 from_dfh
= NFSLOG_GET_FHANDLE2(from_dfh
);
1320 to_dfh
= NFSLOG_GET_FHANDLE2(to_dfh
);
1321 if (pathp1
!= NULL
) {
1322 *pathp1
= nfslog_get_path(from_dfh
, from_name
, fhpath
,
1324 *pathp2
= nfslog_get_path(to_dfh
, to_name
, fhpath
,
1329 /* rename failed so nothing to update */
1332 /* Rename the link in the database */
1333 if (error
= fh_rename(fhpath
, from_dfh
, from_name
, pathp1
,
1335 syslog(LOG_ERR
, gettext(
1336 "Rename2: Update from '%s' to '%s' failed: %s\n"),
1338 ((error
>= 0) ? strerror(error
) : "Unknown"));
1343 * nfslog_LINK2_fhargs - adds link name and fh to fhlist. Note that as a
1344 * result we may have more than one name for an fh.
1348 nfslog_LINK2_fhargs(nfslog_linkargs
*args
, nfsstat
*res
,
1349 char *fhpath
, char **pathp1
, char **pathp2
)
1352 fhandle_t
*dfh
, *fh
;
1355 fh
= &args
->la_from
;
1356 name
= args
->la_to
.da_name
;
1357 dfh
= &args
->la_to
.da_fhandle
;
1359 PRINT_FULL_DATA(stdout
, "=============\nLINK2",
1362 (void) printf("status %d\n", *res
);
1364 dfh
= NFSLOG_GET_FHANDLE2(dfh
);
1365 fh
= NFSLOG_GET_FHANDLE2(fh
);
1366 if (pathp1
!= NULL
) {
1367 *pathp1
= nfslog_get_path(fh
, NULL
, fhpath
, "link2 from");
1368 *pathp2
= nfslog_get_path(dfh
, name
, fhpath
, "link2 to");
1372 /* no returned fh so nothing to add */
1375 /* A new link so add it, have fh_add find the link count */
1376 if (error
= FH_ADD(fhpath
, dfh
, fh
, name
)) {
1377 syslog(LOG_ERR
, gettext(
1378 "Link2: Add fh for '%s' failed: %s\n"),
1379 name
, ((error
>= 0) ? strerror(error
) : "Unknown"));
1384 * nfslog_SYMLINK2_fhargs - adds symlink name and fh to fhlist if fh returned.
1388 nfslog_SYMLINK2_fhargs(nfslog_symlinkargs
*args
, nfsstat
*res
,
1389 char *fhpath
, char **pathp1
, char **pathp2
)
1394 name
= args
->sla_from
.da_name
;
1395 dfh
= &args
->sla_from
.da_fhandle
;
1397 PRINT_LINK_DATA(stdout
, "=============\nSYMLINK2",
1400 dfh
= NFSLOG_GET_FHANDLE2(dfh
);
1401 if (pathp1
!= NULL
) {
1402 *pathp1
= nfslog_get_path(dfh
, name
, fhpath
, "symlink2");
1408 * nfslog_READDIR2_fhargs - updates path1 but no fhtable changes
1412 nfslog_READDIR2_fhargs(nfslog_rddirargs
*args
, nfslog_rddirres
*res
,
1413 char *fhpath
, char **pathp1
, char **pathp2
)
1416 (void) printf("=============\nREADDIR2: fh ");
1417 debug_opaque_print(stdout
, &args
->rda_fh
,
1418 sizeof (args
->rda_fh
));
1419 (void) printf("\n");
1421 if (pathp1
!= NULL
) {
1422 *pathp1
= nfslog_get_path(NFSLOG_GET_FHANDLE2(&args
->rda_fh
),
1423 NULL
, fhpath
, "readdir2");
1429 * nfslog_STATFS2_fhargs - updates path1 but no fhtable changes
1433 nfslog_STATFS2_fhargs(fhandle_t
*args
, nfsstat
*res
,
1434 char *fhpath
, char **pathp1
, char **pathp2
)
1437 (void) printf("=============\nSTATFS2: fh ");
1438 debug_opaque_print(stdout
, args
, sizeof (*args
));
1439 (void) printf("\n");
1441 if (pathp1
!= NULL
) {
1442 *pathp1
= nfslog_get_path(NFSLOG_GET_FHANDLE2(args
),
1443 NULL
, fhpath
, "statfs2");
1452 /* Functions for updating the fhtable for fhtoppath */
1455 * nfslog_GETATTR3_fhargs - updates path1 but no fhtable changes
1459 nfslog_GETATTR3_fhargs(nfs_fh3
*args
, nfsstat3
*res
,
1460 char *fhpath
, char **pathp1
, char **pathp2
)
1463 (void) printf("=============\nGETATTR3: fh ");
1464 debug_opaque_print(stdout
, args
, sizeof (*args
));
1465 (void) printf("\n");
1467 if (pathp1
!= NULL
) {
1468 *pathp1
= nfslog_get_path(NFSLOG_GET_FHANDLE3(args
), NULL
,
1469 fhpath
, "getattr3");
1475 * nfslog_SETATTR3_fhargs - updates path1 but no fhtable changes
1479 nfslog_SETATTR3_fhargs(nfslog_SETATTR3args
*args
, nfsstat3
*res
,
1480 char *fhpath
, char **pathp1
, char **pathp2
)
1483 (void) printf("=============\nSETATTR3: fh ");
1484 debug_opaque_print(stdout
, &args
->object
,
1485 sizeof (args
->object
));
1486 (void) printf("\n");
1488 if (pathp1
!= NULL
) {
1489 *pathp1
= nfslog_get_path(NFSLOG_GET_FHANDLE3(&args
->object
),
1490 NULL
, fhpath
, "setattr3");
1496 * nfslog_LOOKUP3_fhargs - search the table to ensure we have not added this
1497 * one already. Note that if the response status was anything but okay,
1498 * there is no fh to check...
1502 nfslog_LOOKUP3_fhargs(nfslog_diropargs3
*args
, nfslog_LOOKUP3res
*res
,
1503 char *fhpath
, char **pathp1
, char **pathp2
)
1506 fhandle_t
*dfh
, *fh
;
1509 dfh
= NFSLOG_GET_FHANDLE3(&args
->dir
);
1512 if (res
->status
== NFS3_OK
)
1513 fh
= NFSLOG_GET_FHANDLE3(
1514 &res
->nfslog_LOOKUP3res_u
.object
);
1517 PRINT_FULL_DATA(stdout
, "=============\nLOOKUP3",
1519 if (res
->status
!= NFS3_OK
)
1520 (void) printf("status %d\n", res
->status
);
1522 if ((dfh
== &public_fh
) && (name
[0] == '\x80')) {
1523 /* special mclookup */
1526 if (res
->status
!= NFS3_OK
) {
1527 if (pathp1
!= NULL
) {
1528 *pathp1
= nfslog_get_path(dfh
, name
, fhpath
, "lookup3");
1533 fh
= NFSLOG_GET_FHANDLE3(&res
->nfslog_LOOKUP3res_u
.object
);
1534 nfslog_LOOKUP_calc(dfh
, name
, fh
, fhpath
, pathp1
, pathp2
, "Lookup3");
1538 * nfslog_ACCESS3_fhargs - updates path1 but no fhtable changes
1542 nfslog_ACCESS3_fhargs(nfs_fh3
*args
, nfsstat3
*res
,
1543 char *fhpath
, char **pathp1
, char **pathp2
)
1546 (void) printf("=============\nACCESS3: fh ");
1547 debug_opaque_print(stdout
, args
,
1549 (void) printf("\n");
1551 if (pathp1
!= NULL
) {
1552 *pathp1
= nfslog_get_path(NFSLOG_GET_FHANDLE3(args
),
1553 NULL
, fhpath
, "access3");
1559 * nfslog_READLINK3_fhargs - updates path1 but no fhtable changes
1563 nfslog_READLINK3_fhargs(nfs_fh3
*args
, nfslog_READLINK3res
*res
,
1564 char *fhpath
, char **pathp1
, char **pathp2
)
1567 (void) printf("=============\nREADLINK3: fh ");
1568 debug_opaque_print(stdout
, args
, sizeof (*args
));
1569 (void) printf("\n");
1571 if (pathp1
!= NULL
) {
1572 *pathp1
= nfslog_get_path(NFSLOG_GET_FHANDLE3(args
), NULL
,
1573 fhpath
, "readlink3");
1579 * nfslog_READ3_fhargs - updates path1 but no fhtable changes
1583 nfslog_READ3_fhargs(nfslog_READ3args
*args
, nfslog_READ3res
*res
,
1584 char *fhpath
, char **pathp1
, char **pathp2
)
1587 (void) printf("=============\nREAD3: fh ");
1588 debug_opaque_print(stdout
, &args
->file
,
1589 sizeof (args
->file
));
1590 (void) printf("\n");
1592 if (pathp1
!= NULL
) {
1593 *pathp1
= nfslog_get_path(NFSLOG_GET_FHANDLE3(&args
->file
),
1594 NULL
, fhpath
, "read3");
1600 * nfslog_WRITE3_fhargs - updates path1 but no fhtable changes
1604 nfslog_WRITE3_fhargs(nfslog_WRITE3args
*args
, nfslog_WRITE3res
*res
,
1605 char *fhpath
, char **pathp1
, char **pathp2
)
1608 (void) printf("=============\nWRITE3: fh ");
1609 debug_opaque_print(stdout
, &args
->file
,
1610 sizeof (args
->file
));
1611 (void) printf("\n");
1613 if (pathp1
!= NULL
) {
1614 *pathp1
= nfslog_get_path(NFSLOG_GET_FHANDLE3(&args
->file
),
1615 NULL
, fhpath
, "write3");
1621 * nfslog_CREATE3_fhargs - if the operation succeeded, we are sure there can
1622 * be no such link in the fhtable, so just add it.
1626 nfslog_CREATE3_fhargs(nfslog_CREATE3args
*args
, nfslog_CREATE3res
*res
,
1627 char *fhpath
, char **pathp1
, char **pathp2
)
1630 fhandle_t
*dfh
, *fh
;
1633 name
= args
->where
.name
;
1634 dfh
= NFSLOG_GET_FHANDLE3(&args
->where
.dir
);
1637 if (res
->status
== NFS3_OK
)
1638 fh
= NFSLOG_GET_FHANDLE3(
1639 &res
->nfslog_CREATE3res_u
.ok
.obj
.handle
);
1642 PRINT_FULL_DATA(stdout
, "=============\nCREATE3",
1644 if (res
->status
!= NFS3_OK
)
1645 (void) printf("status %d\n", res
->status
);
1647 if (pathp1
!= NULL
) {
1648 *pathp1
= nfslog_get_path(dfh
, name
, fhpath
, "create3");
1652 if ((res
->status
!= NFS3_OK
) ||
1653 !res
->nfslog_CREATE3res_u
.ok
.obj
.handle_follows
)
1654 /* no returned fh so nothing to add */
1657 /* A new file handle so add it */
1658 fh
= NFSLOG_GET_FHANDLE3(&res
->nfslog_CREATE3res_u
.ok
.obj
.handle
);
1659 if (error
= FH_ADD(fhpath
, dfh
, fh
, name
)) {
1660 syslog(LOG_ERR
, gettext(
1661 "Create3: Add fh for '%s' failed: %s\n"),
1662 name
, ((error
>= 0) ? strerror(error
) : "Unknown"));
1667 * nfslog_MKDIR3_fhargs - if the operation succeeded, we are sure there can
1668 * be no such link in the fhtable, so just add it.
1672 nfslog_MKDIR3_fhargs(nfslog_MKDIR3args
*args
, nfslog_MKDIR3res
*res
,
1673 char *fhpath
, char **pathp1
, char **pathp2
)
1676 fhandle_t
*dfh
, *fh
;
1679 name
= args
->where
.name
;
1680 dfh
= NFSLOG_GET_FHANDLE3(&args
->where
.dir
);
1683 if (res
->status
== NFS3_OK
)
1684 fh
= NFSLOG_GET_FHANDLE3(
1685 &res
->nfslog_MKDIR3res_u
.obj
.handle
);
1688 PRINT_FULL_DATA(stdout
, "=============\nMKDIR3",
1690 if (res
->status
!= NFS3_OK
)
1691 (void) printf("status %d\n", res
->status
);
1693 if (pathp1
!= NULL
) {
1694 *pathp1
= nfslog_get_path(dfh
, name
, fhpath
, "mkdir3");
1698 if ((res
->status
!= NFS3_OK
) ||
1699 !res
->nfslog_MKDIR3res_u
.obj
.handle_follows
)
1700 /* no returned fh so nothing to add */
1703 /* A new file handle so add it */
1704 fh
= NFSLOG_GET_FHANDLE3(&res
->nfslog_MKDIR3res_u
.obj
.handle
);
1705 if (error
= FH_ADD(fhpath
, dfh
, fh
, name
)) {
1706 syslog(LOG_ERR
, gettext(
1707 "Mkdir3: Add fh for '%s' failed: %s\n"),
1708 name
, ((error
>= 0) ? strerror(error
) : "Unknown"));
1713 * nfslog_REMOVE3_fhargs - if the operation succeeded, remove the link from
1718 nfslog_REMOVE3_fhargs(nfslog_REMOVE3args
*args
, nfsstat3
*res
,
1719 char *fhpath
, char **pathp1
, char **pathp2
)
1725 name
= args
->object
.name
;
1726 dfh
= NFSLOG_GET_FHANDLE3(&args
->object
.dir
);
1729 PRINT_LINK_DATA(stdout
, "=============\nREMOVE3", dfh
, name
, "")
1730 if (*res
!= NFS3_OK
)
1731 (void) printf("status %d\n", *res
);
1733 if (pathp1
!= NULL
) {
1734 *pathp1
= nfslog_get_path(dfh
, name
, fhpath
, "remove3");
1738 if (*res
!= NFS3_OK
)
1739 /* remove failed so nothing to update */
1742 if (error
= fh_remove(fhpath
, dfh
, name
, pathp1
)) {
1743 syslog(LOG_ERR
, gettext("Remove3: '%s' failed: %s\n"),
1744 name
, ((error
>= 0) ? strerror(error
) : "Unknown"));
1749 * nfslog_RMDIR3_fhargs - if the operation succeeded, remove the link from
1754 nfslog_RMDIR3_fhargs(nfslog_RMDIR3args
*args
, nfsstat3
*res
,
1755 char *fhpath
, char **pathp1
, char **pathp2
)
1761 name
= args
->object
.name
;
1762 dfh
= NFSLOG_GET_FHANDLE3(&args
->object
.dir
);
1765 PRINT_LINK_DATA(stdout
, "=============\nRMDIR3", dfh
, name
, "")
1766 if (*res
!= NFS3_OK
)
1767 (void) printf("status %d\n", *res
);
1769 if (pathp1
!= NULL
) {
1770 *pathp1
= nfslog_get_path(dfh
, name
, fhpath
, "rmdir3");
1774 if (*res
!= NFS3_OK
)
1775 /* rmdir failed so nothing to update */
1778 if (error
= fh_remove(fhpath
, dfh
, name
, pathp1
)) {
1779 syslog(LOG_ERR
, gettext("Rmdir3: '%s' failed: %s\n"),
1780 name
, ((error
>= 0) ? strerror(error
) : "Unknown"));
1785 * nfslog_RENAME3_fhargs - if the operation succeeded, update the existing
1786 * fhtable entry to point to new dir and name.
1790 nfslog_RENAME3_fhargs(nfslog_RENAME3args
*args
, nfsstat3
*res
,
1791 char *fhpath
, char **pathp1
, char **pathp2
)
1793 char *from_name
, *to_name
;
1794 fhandle_t
*from_dfh
, *to_dfh
;
1797 from_name
= args
->from
.name
;
1798 from_dfh
= NFSLOG_GET_FHANDLE3(&args
->from
.dir
);
1799 to_name
= args
->to
.name
;
1800 to_dfh
= NFSLOG_GET_FHANDLE3(&args
->to
.dir
);
1803 PRINT_LINK_DATA(stdout
, "=============\nRENAME3: from",
1804 from_dfh
, from_name
, "")
1805 PRINT_LINK_DATA(stdout
, "=============\nRENAME3: to ",
1806 to_dfh
, to_name
, "")
1807 if (*res
!= NFS3_OK
)
1808 (void) printf("status %d\n", *res
);
1810 if (pathp1
!= NULL
) {
1811 *pathp1
= nfslog_get_path(from_dfh
, from_name
, fhpath
,
1813 *pathp2
= nfslog_get_path(to_dfh
, to_name
, fhpath
,
1816 if (*res
!= NFS3_OK
)
1817 /* rename failed so nothing to update */
1820 if (error
= fh_rename(fhpath
, from_dfh
, from_name
, pathp1
,
1822 syslog(LOG_ERR
, gettext(
1823 "Rename3: Update from '%s' to '%s' failed: %s\n"),
1825 ((error
>= 0) ? strerror(error
) : "Unknown"));
1830 * nfslog_LINK3_fhargs - if the operation succeeded, we are sure there can
1831 * be no such link in the fhtable, so just add it.
1835 nfslog_LINK3_fhargs(nfslog_LINK3args
*args
, nfsstat3
*res
,
1836 char *fhpath
, char **pathp1
, char **pathp2
)
1839 fhandle_t
*dfh
, *fh
;
1842 fh
= NFSLOG_GET_FHANDLE3(&args
->file
);
1843 name
= args
->link
.name
;
1844 dfh
= NFSLOG_GET_FHANDLE3(&args
->link
.dir
);
1847 PRINT_FULL_DATA(stdout
, "=============\nLINK3",
1849 if (*res
!= NFS3_OK
)
1850 (void) printf("status %d\n", *res
);
1852 if (pathp1
!= NULL
) {
1853 *pathp1
= nfslog_get_path(fh
, NULL
, fhpath
, "link3 from");
1854 *pathp2
= nfslog_get_path(dfh
, name
, fhpath
, "link3 to");
1857 if (*res
!= NFS3_OK
)
1858 /* link failed so nothing to add */
1861 /* A new link so add it, have fh_add find link count */
1862 if (error
= FH_ADD(fhpath
, dfh
, fh
, name
)) {
1863 syslog(LOG_ERR
, gettext(
1864 "Link3: Add fh for '%s' failed: %s\n"),
1865 name
, ((error
>= 0) ? strerror(error
) : "Unknown"));
1870 * nfslog_MKNOD3_fhargs - if the operation succeeded, we are sure there can
1871 * be no such link in the fhtable, so just add it.
1875 nfslog_MKNOD3_fhargs(nfslog_MKNOD3args
*args
, nfslog_MKNOD3res
*res
,
1876 char *fhpath
, char **pathp1
, char **pathp2
)
1879 fhandle_t
*dfh
, *fh
;
1882 name
= args
->where
.name
;
1883 dfh
= NFSLOG_GET_FHANDLE3(&args
->where
.dir
);
1886 if (res
->status
== NFS3_OK
)
1887 fh
= NFSLOG_GET_FHANDLE3(
1888 &res
->nfslog_MKNOD3res_u
.obj
.handle
);
1891 PRINT_FULL_DATA(stdout
, "=============\nMKNOD3",
1893 if (res
->status
!= NFS3_OK
)
1894 (void) printf("status %d\n", res
->status
);
1896 if (pathp1
!= NULL
) {
1897 *pathp1
= nfslog_get_path(dfh
, name
, fhpath
, "mknod3");
1900 if ((res
->status
!= NFS3_OK
) ||
1901 !res
->nfslog_MKNOD3res_u
.obj
.handle_follows
)
1902 /* no returned fh so nothing to add */
1905 /* A new file handle so add it */
1906 fh
= NFSLOG_GET_FHANDLE3(&res
->nfslog_MKNOD3res_u
.obj
.handle
);
1907 if (error
= FH_ADD(fhpath
, dfh
, fh
, name
)) {
1908 syslog(LOG_ERR
, gettext("Mknod3: Add fh for '%s' failed: %s\n"),
1909 name
, ((error
>= 0) ? strerror(error
) : "Unknown"));
1914 * nfslog_SYMLINK3_fhargs - if the operation succeeded, we are sure there can
1915 * be no such link in the fhtable, so just add it.
1919 nfslog_SYMLINK3_fhargs(nfslog_SYMLINK3args
*args
, nfslog_SYMLINK3res
*res
,
1920 char *fhpath
, char **pathp1
, char **pathp2
)
1923 fhandle_t
*dfh
, *fh
;
1926 name
= args
->where
.name
;
1927 dfh
= NFSLOG_GET_FHANDLE3(&args
->where
.dir
);
1930 if (res
->status
== NFS3_OK
)
1931 fh
= NFSLOG_GET_FHANDLE3(
1932 &res
->nfslog_SYMLINK3res_u
.obj
.handle
);
1935 PRINT_FULL_DATA(stdout
, "=============\nSYMLINK3",
1937 if (res
->status
!= NFS3_OK
)
1938 (void) printf("status %d\n", res
->status
);
1940 if (pathp1
!= NULL
) {
1941 *pathp1
= nfslog_get_path(dfh
, name
, fhpath
, "symlink3");
1945 if ((res
->status
!= NFS3_OK
) ||
1946 !res
->nfslog_SYMLINK3res_u
.obj
.handle_follows
)
1947 /* no returned fh so nothing to add */
1950 /* A new file handle so add it */
1951 fh
= NFSLOG_GET_FHANDLE3(&res
->nfslog_SYMLINK3res_u
.obj
.handle
);
1952 if (error
= FH_ADD(fhpath
, dfh
, fh
, name
)) {
1953 syslog(LOG_ERR
, gettext(
1954 "Symlink3: Add fh for '%s' failed: %s\n"),
1955 name
, ((error
>= 0) ? strerror(error
) : "Unknown"));
1960 * nfslog_READDIR3_fhargs - updates path1 but no fhtable changes
1964 nfslog_READDIR3_fhargs(nfs_fh3
*args
, nfsstat3
*res
,
1965 char *fhpath
, char **pathp1
, char **pathp2
)
1968 (void) printf("=============\nREADDIR3: fh ");
1969 debug_opaque_print(stdout
, args
,
1971 (void) printf("\n");
1973 if (pathp1
!= NULL
) {
1974 *pathp1
= nfslog_get_path(NFSLOG_GET_FHANDLE3(args
),
1975 NULL
, fhpath
, "readdir3");
1981 * nfslog_READDIRPLUS3_fhargs - updates path1 but no fhtable changes
1985 nfslog_READDIRPLUS3_fhargs(nfslog_READDIRPLUS3args
*args
,
1986 nfslog_READDIRPLUS3res
*res
,
1987 char *fhpath
, char **pathp1
, char **pathp2
)
1990 fhandle_t
*dfh
, *fh
;
1991 nfslog_entryplus3
*ep
;
1994 (void) printf("=============\nREADDIRPLUS3: fh ");
1995 debug_opaque_print(stdout
, &args
->dir
,
1996 sizeof (args
->dir
));
1997 (void) printf("\n");
1999 if (pathp1
!= NULL
) {
2000 *pathp1
= nfslog_get_path(NFSLOG_GET_FHANDLE3(&args
->dir
),
2001 NULL
, fhpath
, "readdirplus3");
2005 if (res
->status
== NFS3_OK
) {
2007 dfh
= NFSLOG_GET_FHANDLE3(&args
->dir
);
2010 * Loop through the fh/name pair and add them
2013 for (ep
= res
->nfslog_READDIRPLUS3res_u
.ok
.reply
.entries
;
2015 ep
= ep
->nextentry
) {
2019 fh
= NFSLOG_GET_FHANDLE3(&ep
->name_handle
.handle
);
2021 nfslog_LOOKUP_calc(dfh
, name
, fh
,
2029 * nfslog_FSSTAT3_fhargs - updates path1 but no fhtable changes
2033 nfslog_FSSTAT3_fhargs(nfs_fh3
*args
, nfsstat3
*res
,
2034 char *fhpath
, char **pathp1
, char **pathp2
)
2037 (void) printf("=============\nFSSTAT3: fh ");
2038 debug_opaque_print(stdout
, args
,
2040 (void) printf("\n");
2042 if (pathp1
!= NULL
) {
2043 *pathp1
= nfslog_get_path(NFSLOG_GET_FHANDLE3(args
), NULL
,
2050 * nfslog_FSINFO3_fhargs - updates path1 but no fhtable changes
2054 nfslog_FSINFO3_fhargs(nfs_fh3
*args
, nfsstat3
*res
,
2055 char *fhpath
, char **pathp1
, char **pathp2
)
2058 (void) printf("=============\nFSINFO3: fh ");
2059 debug_opaque_print(stdout
, args
,
2061 (void) printf("\n");
2063 if (pathp1
!= NULL
) {
2064 *pathp1
= nfslog_get_path(NFSLOG_GET_FHANDLE3(args
), NULL
,
2071 * nfslog_PATHCONF3_fhargs - updates path1 but no fhtable changes
2075 nfslog_PATHCONF3_fhargs(nfs_fh3
*args
, nfsstat3
*res
,
2076 char *fhpath
, char **pathp1
, char **pathp2
)
2079 (void) printf("=============\nPATHCONF3: fh ");
2080 debug_opaque_print(stdout
, args
,
2082 (void) printf("\n");
2084 if (pathp1
!= NULL
) {
2085 *pathp1
= nfslog_get_path(NFSLOG_GET_FHANDLE3(args
), NULL
,
2086 fhpath
, "pathconf3");
2092 * nfslog_COMMIT3_fhargs - updates path1 but no fhtable changes
2096 nfslog_COMMIT3_fhargs(nfslog_COMMIT3args
*args
, nfsstat3
*res
,
2097 char *fhpath
, char **pathp1
, char **pathp2
)
2100 (void) printf("=============\nCOMMIT3: fh ");
2101 debug_opaque_print(stdout
, &args
->file
,
2102 sizeof (args
->file
));
2103 (void) printf("\n");
2105 if (pathp1
!= NULL
) {
2106 *pathp1
= nfslog_get_path(NFSLOG_GET_FHANDLE3(&args
->file
),
2107 NULL
, fhpath
, "commit3");
2117 * nfslog_SHARE_fhargs - adds export path and handle to fhlist
2121 nfslog_SHARE_fhargs(nfslog_sharefsargs
*args
, nfslog_sharefsres
*res
,
2122 char *fhpath
, char **pathp1
, char **pathp2
)
2130 "=============\nSHARE: name '%s', fh ", args
->sh_path
);
2131 debug_opaque_print(stdout
, &args
->sh_fh_buf
,
2132 sizeof (fhandle_t
));
2133 (void) printf("\n");
2136 fh
= &args
->sh_fh_buf
;
2139 * This bcopy is done because the fh_data for the export/share directory
2140 * is not meaningful with respect to the database keys. Therefore, we
2141 * copy the export or fh_xdata fid to the fh_data so that a reasonable
2142 * entry will be added in the data base.
2144 bcopy(fh
->fh_xdata
, fh
->fh_data
, fh
->fh_xlen
);
2146 /* If debug print the database */
2148 fh_print_all_keys(fhpath
, fh
);
2150 if (fh_lookup_link(fhpath
, fh
, fh
,
2151 args
->sh_path
, &fhrec
, &error
) == NULL
) {
2152 if (error
= FH_ADD(fhpath
, fh
, fh
, args
->sh_path
)) {
2153 syslog(LOG_ERR
, gettext(
2154 "Share: Add fh for '%s' failed: %s\n"),
2155 args
->sh_path
, ((error
>= 0) ?
2156 strerror(error
) : "Unknown"));
2159 if (pathp1
!= NULL
) {
2160 *pathp1
= nfslog_get_path(fh
, NULL
, fhpath
, "share");
2166 * nfslog_UNSHARE_fhargs - remove export path and handle from fhlist
2170 nfslog_UNSHARE_fhargs(nfslog_sharefsargs
*args
, nfslog_sharefsres
*res
,
2171 char *fhpath
, char **pathp1
, char **pathp2
)
2177 (void) printf("=============\nUNSHARE: name '%s', fh ",
2179 debug_opaque_print(stdout
, &args
->sh_fh_buf
,
2180 sizeof (fhandle_t
));
2181 (void) printf("\n");
2184 fh
= &args
->sh_fh_buf
;
2187 * This bcopy is done because the fh_data for the export/share directory
2188 * is not meaningful with respect to the database keys. Therefore, we
2189 * copy the export or fh_xdata fid to the fh_data so that a reasonable
2190 * entry will be added in the data base.
2192 bcopy(fh
->fh_xdata
, fh
->fh_data
, fh
->fh_xlen
);
2194 /* If debug print the database */
2196 fh_print_all_keys(fhpath
, fh
);
2198 if (pathp1
!= NULL
) {
2199 *pathp1
= nfslog_get_path(fh
, NULL
, fhpath
, "share");
2202 if (error
= fh_remove(fhpath
, fh
, args
->sh_path
, pathp1
)) {
2203 syslog(LOG_ERR
, gettext("Unshare: '%s' failed: %s\n"),
2204 args
->sh_path
, ((error
>= 0) ? strerror(error
) :
2211 nfslog_GETFH_fhargs(nfslog_getfhargs
*args
, nfsstat
*res
,
2212 char *fhpath
, char **pathp1
, char **pathp2
)
2219 (void) printf("=============\nGETFH3: name '%s', fh ",
2221 debug_opaque_print(stdout
, &args
->gfh_fh_buf
,
2222 sizeof (fhandle_t
));
2223 (void) printf("\n");
2226 fh
= &args
->gfh_fh_buf
;
2228 /* If debug print the database */
2230 fh_print_all_keys(fhpath
, fh
);
2232 if (fh_lookup_link(fhpath
, fh
, fh
,
2233 args
->gfh_path
, &fhrec
, &error
) == NULL
) {
2234 if (error
= FH_ADD(fhpath
, fh
, fh
, args
->gfh_path
)) {
2235 syslog(LOG_ERR
, gettext(
2236 "Getfh: Add fh for '%s' failed: %s\n"),
2237 args
->gfh_path
, ((error
>= 0) ?
2238 strerror(error
) : "Unknown"));
2241 if (pathp1
!= NULL
) {
2242 *pathp1
= nfslog_get_path(fh
, NULL
, fhpath
, "getfh");
2252 * nfslog_get_path - gets the path for this file. fh must be supplied,
2253 * name may be null. If name is supplied, fh is assumed to be a directory
2254 * filehandle, with name as its component. fhpath is the generic path for the
2255 * fhtopath table and prtstr is the name of the caller (for debug purposes).
2256 * Returns the malloc'd path. The caller must free it later.
2259 nfslog_get_path(fhandle_t
*fh
, char *name
, char *fhpath
, char *prtstr
)
2261 char *pathp
= fh_print_absolute(fhpath
, fh
, name
);
2264 (void) printf(" %s: path '%s', fh ", prtstr
, pathp
);
2265 debug_opaque_print(stdout
, fh
, sizeof (*fh
));
2266 (void) printf("\n");
2272 * nfslog_process_fh_rec - updates the fh table based on the rpc req
2273 * Return 0 for success, error otherwise. If success return the path
2274 * for the input file handle(s) if so indicated.
2277 nfslog_process_fh_rec(struct nfslog_lr
*lrp
, char *fhpath
, char **pathp1
,
2278 char **pathp2
, bool_t return_path
)
2280 struct nfsl_fh_proc_disp
*disp
;
2281 nfslog_request_record
*logrec
= &lrp
->log_record
;
2282 nfslog_record_header
*logrechdr
= &logrec
->re_header
;
2284 if ((disp
= nfslog_find_fh_dispatch(logrec
)) != NULL
) {
2286 * Allocate space for the args and results and decode
2288 logrec
->re_rpc_arg
= calloc(1, disp
->args_size
);
2290 if (!(*disp
->xdr_args
)(&lrp
->xdrs
, logrec
->re_rpc_arg
)) {
2291 free(logrec
->re_rpc_arg
);
2292 logrec
->re_rpc_arg
= NULL
;
2293 syslog(LOG_ERR
, gettext("argument decode failed"));
2296 /* used later for free of data structures */
2297 lrp
->xdrargs
= disp
->xdr_args
;
2299 logrec
->re_rpc_res
= calloc(1, disp
->res_size
);
2300 if (!(*disp
->xdr_res
)(&lrp
->xdrs
, logrec
->re_rpc_res
)) {
2301 free(logrec
->re_rpc_res
);
2302 logrec
->re_rpc_res
= NULL
;
2303 syslog(LOG_ERR
, gettext("results decode failed"));
2306 /* used later for free of data structures */
2307 lrp
->xdrres
= disp
->xdr_res
;
2310 * Process the operation within the context of the file handle
2314 (*disp
->nfsl_dis_args
)(logrec
->re_rpc_arg
,
2315 logrec
->re_rpc_res
, fhpath
, pathp1
, pathp2
);
2317 if ((logrechdr
->rh_version
== NFS_VERSION
&&
2318 logrechdr
->rh_procnum
== RFS_LINK
) ||
2319 (logrechdr
->rh_version
== NFS_V3
&&
2320 logrechdr
->rh_procnum
== NFSPROC3_LINK
)) {
2322 (*disp
->nfsl_dis_args
)(logrec
->re_rpc_arg
,
2324 fhpath
, pathp1
, pathp2
);
2326 (*disp
->nfsl_dis_args
)(logrec
->re_rpc_arg
,
2328 fhpath
, NULL
, NULL
);
2333 syslog(LOG_ERR
, gettext("procedure unknown"));