Print this page
OS-20 share_nfs(1m) charset handling is unreliable
OS-22 Page fault at nfscmd_dropped_entrysize+0x1e()
OS-23 NFSv2/3/4: READDIR responses are inconsistent when charset conversion fails
OS-24 rfs3_readdir(): Issues related to nfscmd_convdirent()
Reviewed by: Jan Kryl <jan.kryl@nexenta.com>
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/fs/nfs/nfs4_srv_readdir.c
+++ new/usr/src/uts/common/fs/nfs/nfs4_srv_readdir.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
|
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
20 20 */
21 21
22 22 /*
23 23 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
24 24 */
25 25
26 26 /*
27 27 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
28 28 * Use is subject to license terms.
29 29 */
30 +/*
31 + * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
32 + */
30 33
31 34 #include <sys/param.h>
32 35 #include <sys/types.h>
33 36 #include <sys/systm.h>
34 37 #include <sys/cred.h>
35 38 #include <sys/buf.h>
36 39 #include <sys/vfs.h>
37 40 #include <sys/vnode.h>
38 41 #include <sys/uio.h>
39 42 #include <sys/errno.h>
40 43 #include <sys/sysmacros.h>
41 44 #include <sys/statvfs.h>
42 45 #include <sys/kmem.h>
43 46 #include <sys/dirent.h>
44 47 #include <rpc/types.h>
45 48 #include <rpc/auth.h>
46 49 #include <rpc/rpcsec_gss.h>
47 50 #include <rpc/svc.h>
48 51 #include <sys/strsubr.h>
49 52 #include <sys/strsun.h>
50 53 #include <sys/sdt.h>
51 54
52 55 #include <nfs/nfs.h>
53 56 #include <nfs/export.h>
54 57 #include <nfs/nfs4.h>
55 58 #include <nfs/nfs_cmd.h>
56 59
57 60
58 61 /*
59 62 * RFS4_MINLEN_ENTRY4: XDR-encoded size of smallest possible dirent.
60 63 * This is used to return NFS4ERR_TOOSMALL when clients specify
61 64 * maxcount that isn't large enough to hold the smallest possible
62 65 * XDR encoded dirent.
63 66 *
64 67 * sizeof cookie (8 bytes) +
65 68 * sizeof name_len (4 bytes) +
66 69 * sizeof smallest (padded) name (4 bytes) +
67 70 * sizeof bitmap4_len (12 bytes) + NOTE: we always encode len=2 bm4
68 71 * sizeof attrlist4_len (4 bytes) +
69 72 * sizeof next boolean (4 bytes)
70 73 *
71 74 * RFS4_MINLEN_RDDIR4: XDR-encoded size of READDIR op reply containing
72 75 * the smallest possible entry4 (assumes no attrs requested).
73 76 * sizeof nfsstat4 (4 bytes) +
74 77 * sizeof verifier4 (8 bytes) +
75 78 * sizeof entsecond_to_ry4list bool (4 bytes) +
76 79 * sizeof entry4 (36 bytes) +
77 80 * sizeof eof bool (4 bytes)
78 81 *
79 82 * RFS4_MINLEN_RDDIR_BUF: minimum length of buffer server will provide to
80 83 * VOP_READDIR. Its value is the size of the maximum possible dirent
81 84 * for solaris. The DIRENT64_RECLEN macro returns the size of dirent
82 85 * required for a given name length. MAXNAMELEN is the maximum
83 86 * filename length allowed in Solaris. The first two DIRENT64_RECLEN()
84 87 * macros are to allow for . and .. entries -- just a minor tweak to try
85 88 * and guarantee that buffer we give to VOP_READDIR will be large enough
86 89 * to hold ., .., and the largest possible solaris dirent64.
87 90 */
88 91 #define RFS4_MINLEN_ENTRY4 36
89 92 #define RFS4_MINLEN_RDDIR4 (4 + NFS4_VERIFIER_SIZE + 4 + RFS4_MINLEN_ENTRY4 + 4)
90 93 #define RFS4_MINLEN_RDDIR_BUF \
91 94 (DIRENT64_RECLEN(1) + DIRENT64_RECLEN(2) + DIRENT64_RECLEN(MAXNAMELEN))
92 95
93 96
94 97 #ifdef nextdp
95 98 #undef nextdp
96 99 #endif
97 100 #define nextdp(dp) ((struct dirent64 *)((char *)(dp) + (dp)->d_reclen))
98 101
99 102 verifier4 Readdir4verf = 0x0;
100 103
101 104 static nfs_ftype4 vt_to_nf4[] = {
102 105 0, NF4REG, NF4DIR, NF4BLK, NF4CHR, NF4LNK, NF4FIFO, 0, 0, NF4SOCK, 0
103 106 };
104 107
105 108 int
106 109 nfs4_readdir_getvp(vnode_t *dvp, char *d_name, vnode_t **vpp,
107 110 struct exportinfo **exi, struct svc_req *req, struct compound_state *cs,
108 111 int expseudo)
109 112 {
110 113 int error;
111 114 int ismntpt;
112 115 fid_t fid;
113 116 vnode_t *vp, *pre_tvp;
114 117 nfsstat4 status;
115 118 struct exportinfo *newexi, *saveexi;
116 119 cred_t *scr;
117 120
118 121 *vpp = vp = NULL;
119 122
120 123 if (error = VOP_LOOKUP(dvp, d_name, &vp, NULL, 0, NULL, cs->cr,
121 124 NULL, NULL, NULL))
122 125 return (error);
123 126
124 127 /*
125 128 * If the directory is a referral point, don't return the
126 129 * attrs, instead set rdattr_error to MOVED.
127 130 */
128 131 if (vn_is_nfs_reparse(vp, cs->cr) && !client_is_downrev(req)) {
129 132 VN_RELE(vp);
130 133 DTRACE_PROBE2(nfs4serv__func__referral__moved,
131 134 vnode_t *, vp, char *, "nfs4_readdir_getvp");
132 135 return (NFS4ERR_MOVED);
133 136 }
134 137
135 138 /* Is this object mounted upon? */
136 139 ismntpt = vn_ismntpt(vp);
137 140
138 141 /*
139 142 * Nothing more to do if object is not a mount point or
140 143 * a possible LOFS shadow of an LOFS mount (which won't
141 144 * have v_vfsmountedhere set)
142 145 */
143 146 if (ismntpt == 0 && dvp->v_vfsp == vp->v_vfsp && expseudo == 0) {
144 147 *vpp = vp;
145 148 return (0);
146 149 }
147 150
148 151 if (ismntpt) {
149 152 /*
150 153 * Something is mounted here. Traverse and manage the
151 154 * namespace
152 155 */
153 156 pre_tvp = vp;
154 157 VN_HOLD(pre_tvp);
155 158
156 159 if ((error = traverse(&vp)) != 0) {
157 160 VN_RELE(vp);
158 161 VN_RELE(pre_tvp);
159 162 return (error);
160 163 }
161 164 if (vn_is_nfs_reparse(vp, cs->cr)) {
162 165 VN_RELE(vp);
163 166 VN_RELE(pre_tvp);
164 167 DTRACE_PROBE2(nfs4serv__func__referral__moved,
165 168 vnode_t *, vp, char *, "nfs4_readdir_getvp");
166 169 return (NFS4ERR_MOVED);
167 170 }
168 171 }
169 172
170 173 bzero(&fid, sizeof (fid));
171 174 fid.fid_len = MAXFIDSZ;
172 175
173 176 /*
174 177 * If VOP_FID not supported by underlying fs (mntfs, procfs,
175 178 * etc.), then return attrs for stub instead of VROOT object.
176 179 * If it fails for any other reason, then return the error.
177 180 */
178 181 if (error = VOP_FID(vp, &fid, NULL)) {
179 182 if (ismntpt == 0) {
180 183 VN_RELE(vp);
181 184 return (error);
182 185 }
183 186
184 187 if (error != ENOSYS && error != ENOTSUP) {
185 188 VN_RELE(vp);
186 189 VN_RELE(pre_tvp);
187 190 return (error);
188 191 }
189 192 /* go back to vnode that is "under" mount */
190 193 VN_RELE(vp);
191 194 *vpp = pre_tvp;
192 195 return (0);
193 196 }
194 197
195 198 newexi = checkexport4(&vp->v_vfsp->vfs_fsid, &fid, vp);
196 199 if (newexi == NULL) {
197 200 if (ismntpt == 0) {
198 201 *vpp = vp;
199 202 } else {
200 203 VN_RELE(vp);
201 204 *vpp = pre_tvp;
202 205 }
203 206 return (0);
204 207 }
205 208
206 209 if (ismntpt)
207 210 VN_RELE(pre_tvp);
208 211
209 212 /* Save the exi and present the new one to checkauth4() */
210 213 saveexi = cs->exi;
211 214 cs->exi = newexi;
212 215
213 216 /* Get the right cred like lookup does */
214 217 scr = cs->cr;
215 218 cs->cr = crdup(cs->basecr);
216 219
217 220 status = call_checkauth4(cs, req);
218 221
219 222 crfree(cs->cr);
220 223 cs->cr = scr;
221 224 cs->exi = saveexi;
222 225
223 226 /* Reset what call_checkauth4() may have set */
224 227 *cs->statusp = NFS4_OK;
225 228
226 229 if (status != NFS4_OK) {
227 230 VN_RELE(vp);
228 231 if (status == NFS4ERR_DELAY)
229 232 status = NFS4ERR_ACCESS;
230 233 return (status);
231 234 }
232 235 *vpp = vp;
233 236 *exi = newexi;
234 237
235 238 return (0);
236 239 }
237 240
238 241 /* This is the set of pathconf data for vfs */
239 242 typedef struct {
240 243 uint64_t maxfilesize;
241 244 uint32_t maxlink;
242 245 uint32_t maxname;
243 246 } rfs4_pc_encode_t;
244 247
245 248
246 249 static int
247 250 rfs4_get_pc_encode(vnode_t *vp, rfs4_pc_encode_t *pce, bitmap4 ar, cred_t *cr)
248 251 {
249 252 int error;
250 253 ulong_t pc_val;
251 254
252 255 pce->maxfilesize = 0;
253 256 pce->maxlink = 0;
254 257 pce->maxname = 0;
255 258
256 259 if (ar & FATTR4_MAXFILESIZE_MASK) {
257 260 /* Maximum File Size */
258 261 error = VOP_PATHCONF(vp, _PC_FILESIZEBITS, &pc_val, cr, NULL);
259 262 if (error)
260 263 return (error);
261 264
262 265 /*
263 266 * If the underlying file system does not support
264 267 * _PC_FILESIZEBITS, return a reasonable default. Note that
265 268 * error code on VOP_PATHCONF will be 0, even if the underlying
266 269 * file system does not support _PC_FILESIZEBITS.
267 270 */
268 271 if (pc_val == (ulong_t)-1) {
269 272 pce->maxfilesize = MAXOFF32_T;
270 273 } else {
271 274 if (pc_val >= (sizeof (uint64_t) * 8))
272 275 pce->maxfilesize = INT64_MAX;
273 276 else
274 277 pce->maxfilesize = ((1LL << (pc_val - 1)) - 1);
275 278 }
276 279 }
277 280
278 281 if (ar & FATTR4_MAXLINK_MASK) {
279 282 /* Maximum Link Count */
280 283 error = VOP_PATHCONF(vp, _PC_LINK_MAX, &pc_val, cr, NULL);
281 284 if (error)
282 285 return (error);
283 286
284 287 pce->maxlink = pc_val;
285 288 }
286 289
287 290 if (ar & FATTR4_MAXNAME_MASK) {
288 291 /* Maximum Name Length */
289 292 error = VOP_PATHCONF(vp, _PC_NAME_MAX, &pc_val, cr, NULL);
290 293 if (error)
291 294 return (error);
292 295
293 296 pce->maxname = pc_val;
294 297 }
295 298
296 299 return (0);
297 300 }
298 301
299 302 /* This is the set of statvfs data that is ready for encoding */
300 303 typedef struct {
301 304 uint64_t space_avail;
302 305 uint64_t space_free;
303 306 uint64_t space_total;
304 307 u_longlong_t fa;
305 308 u_longlong_t ff;
306 309 u_longlong_t ft;
307 310 } rfs4_sb_encode_t;
308 311
309 312 static int
310 313 rfs4_get_sb_encode(vfs_t *vfsp, rfs4_sb_encode_t *psbe)
311 314 {
312 315 int error;
313 316 struct statvfs64 sb;
314 317
315 318 /* Grab the per filesystem info */
316 319 if (error = VFS_STATVFS(vfsp, &sb)) {
317 320 return (error);
318 321 }
319 322
320 323 /* Calculate space available */
321 324 if (sb.f_bavail != (fsblkcnt64_t)-1) {
322 325 psbe->space_avail =
323 326 (fattr4_space_avail) sb.f_frsize *
324 327 (fattr4_space_avail) sb.f_bavail;
325 328 } else {
326 329 psbe->space_avail =
327 330 (fattr4_space_avail) sb.f_bavail;
328 331 }
329 332
330 333 /* Calculate space free */
331 334 if (sb.f_bfree != (fsblkcnt64_t)-1) {
332 335 psbe->space_free =
333 336 (fattr4_space_free) sb.f_frsize *
334 337 (fattr4_space_free) sb.f_bfree;
335 338 } else {
336 339 psbe->space_free =
337 340 (fattr4_space_free) sb.f_bfree;
338 341 }
339 342
340 343 /* Calculate space total */
341 344 if (sb.f_blocks != (fsblkcnt64_t)-1) {
342 345 psbe->space_total =
343 346 (fattr4_space_total) sb.f_frsize *
344 347 (fattr4_space_total) sb.f_blocks;
345 348 } else {
346 349 psbe->space_total =
347 350 (fattr4_space_total) sb.f_blocks;
348 351 }
349 352
350 353 /* For use later on attr encode */
351 354 psbe->fa = sb.f_favail;
352 355 psbe->ff = sb.f_ffree;
353 356 psbe->ft = sb.f_files;
354 357
355 358 return (0);
356 359 }
357 360
358 361 /*
359 362 * Macros to handle if we have don't have enough space for the requested
360 363 * attributes and this is the first entry and the
361 364 * requested attributes are more than the minimal useful
362 365 * set, reset the attributes to the minimal set and
363 366 * retry the encoding. If the client has asked for both
364 367 * mounted_on_fileid and fileid, prefer mounted_on_fileid.
365 368 */
366 369 #define MINIMAL_RD_ATTRS \
367 370 (FATTR4_MOUNTED_ON_FILEID_MASK| \
368 371 FATTR4_FILEID_MASK| \
369 372 FATTR4_RDATTR_ERROR_MASK)
370 373
371 374 #define MINIMIZE_ATTR_MASK(m) { \
372 375 if ((m) & FATTR4_MOUNTED_ON_FILEID_MASK) \
373 376 (m) &= FATTR4_RDATTR_ERROR_MASK|FATTR4_MOUNTED_ON_FILEID_MASK;\
374 377 else \
375 378 (m) &= FATTR4_RDATTR_ERROR_MASK|FATTR4_FILEID_MASK; \
376 379 }
377 380
378 381 #define IS_MIN_ATTR_MASK(m) (((m) & ~MINIMAL_RD_ATTRS) == 0)
379 382 /*
380 383 * If readdir only needs to return FILEID, we can take it from the
381 384 * dirent struct and save doing the lookup.
382 385 */
383 386 /* ARGSUSED */
384 387 void
385 388 rfs4_op_readdir(nfs_argop4 *argop, nfs_resop4 *resop, struct svc_req *req,
386 389 struct compound_state *cs)
387 390 {
388 391 READDIR4args *args = &argop->nfs_argop4_u.opreaddir;
389 392 READDIR4res *resp = &resop->nfs_resop4_u.opreaddir;
390 393 struct exportinfo *newexi = NULL;
391 394 int error;
392 395 mblk_t *mp;
393 396 uint_t mpcount;
394 397 int alloc_err = 0;
395 398 vnode_t *dvp = cs->vp;
396 399 vnode_t *vp;
397 400 vattr_t va;
398 401 struct dirent64 *dp;
399 402 rfs4_sb_encode_t dsbe, sbe;
400 403 int vfs_different;
401 404 int rddir_data_len, rddir_result_size;
402 405 caddr_t rddir_data;
403 406 offset_t rddir_next_offset;
404 407 int dircount;
405 408 int no_space;
406 409 int iseofdir;
407 410 uint_t eof;
408 411 struct iovec iov;
409 412 struct uio uio;
410 413 int tsize;
411 414 int check_visible;
412 415 struct exp_visible *visp;
413 416
414 417 uint32_t *ptr, *ptr_redzone;
415 418 uint32_t *beginning_ptr;
416 419 uint32_t *lastentry_ptr;
417 420 uint32_t *attrmask_ptr;
418 421 uint32_t *attr_offset_ptr;
419 422 uint32_t attr_length;
420 423 uint32_t rndup;
421 424 uint32_t namelen;
422 425 uint32_t rddirattr_error = 0;
423 426 int nents;
424 427 bitmap4 ar = args->attr_request & NFS4_SRV_RDDIR_SUPPORTED_ATTRS;
425 428 bitmap4 ae;
426 429 rfs4_pc_encode_t dpce, pce;
427 430 ulong_t pc_val;
428 431 uint64_t maxread;
429 432 uint64_t maxwrite;
430 433 uint_t true = TRUE;
431 434 uint_t false = FALSE;
432 435 uid_t lastuid;
433 436 gid_t lastgid;
434 437 int lu_set, lg_set;
435 438 utf8string owner, group;
436 439 int owner_error, group_error;
437 440 struct sockaddr *ca;
438 441 char *name = NULL;
439 442
440 443 DTRACE_NFSV4_2(op__readdir__start, struct compound_state *, cs,
441 444 READDIR4args *, args);
442 445
443 446 lu_set = lg_set = 0;
444 447 owner.utf8string_len = group.utf8string_len = 0;
445 448 owner.utf8string_val = group.utf8string_val = NULL;
446 449
447 450 resp->mblk = NULL;
448 451
449 452 /* Maximum read and write size */
450 453 maxread = maxwrite = rfs4_tsize(req);
451 454
452 455 if (dvp == NULL) {
453 456 *cs->statusp = resp->status = NFS4ERR_NOFILEHANDLE;
454 457 goto out;
455 458 }
456 459
457 460 /*
458 461 * If there is an unshared filesystem mounted on this vnode,
459 462 * do not allow readdir in this directory.
460 463 */
461 464 if (vn_ismntpt(dvp)) {
462 465 *cs->statusp = resp->status = NFS4ERR_ACCESS;
463 466 goto out;
464 467 }
465 468
466 469 if (dvp->v_type != VDIR) {
467 470 *cs->statusp = resp->status = NFS4ERR_NOTDIR;
468 471 goto out;
469 472 }
470 473
471 474 if (args->maxcount <= RFS4_MINLEN_RDDIR4) {
472 475 *cs->statusp = resp->status = NFS4ERR_TOOSMALL;
473 476 goto out;
474 477 }
475 478
476 479 /*
477 480 * If write-only attrs are requested, then fail the readdir op
478 481 */
479 482 if (args->attr_request &
480 483 (FATTR4_TIME_MODIFY_SET_MASK | FATTR4_TIME_ACCESS_SET_MASK)) {
481 484 *cs->statusp = resp->status = NFS4ERR_INVAL;
482 485 goto out;
483 486 }
484 487
485 488 error = VOP_ACCESS(dvp, VREAD, 0, cs->cr, NULL);
486 489 if (error) {
487 490 *cs->statusp = resp->status = puterrno4(error);
488 491 goto out;
489 492 }
490 493
491 494 if (args->cookieverf != Readdir4verf) {
492 495 *cs->statusp = resp->status = NFS4ERR_NOT_SAME;
493 496 goto out;
494 497 }
495 498
496 499 /* Is there pseudo-fs work that is needed for this readdir? */
497 500 check_visible = PSEUDO(cs->exi) ||
498 501 ! is_exported_sec(cs->nfsflavor, cs->exi) ||
499 502 cs->access & CS_ACCESS_LIMITED;
500 503
501 504 /* Check the requested attributes and only do the work if needed */
502 505
503 506 if (ar & (FATTR4_MAXFILESIZE_MASK |
504 507 FATTR4_MAXLINK_MASK |
505 508 FATTR4_MAXNAME_MASK)) {
506 509 if (error = rfs4_get_pc_encode(cs->vp, &dpce, ar, cs->cr)) {
507 510 *cs->statusp = resp->status = puterrno4(error);
508 511 goto out;
509 512 }
510 513 pce = dpce;
511 514 }
512 515
513 516 /* If there is statvfs data requested, pick it up once */
514 517 if (ar &
515 518 (FATTR4_FILES_AVAIL_MASK |
516 519 FATTR4_FILES_FREE_MASK |
517 520 FATTR4_FILES_TOTAL_MASK |
518 521 FATTR4_FILES_AVAIL_MASK |
519 522 FATTR4_FILES_FREE_MASK |
520 523 FATTR4_FILES_TOTAL_MASK)) {
521 524 if (error = rfs4_get_sb_encode(dvp->v_vfsp, &dsbe)) {
522 525 *cs->statusp = resp->status = puterrno4(error);
523 526 goto out;
524 527 }
525 528 sbe = dsbe;
526 529 }
527 530
528 531 /*
529 532 * Max transfer size of the server is the absolute limite.
530 533 * If the client has decided to max out with something really
531 534 * tiny, then return toosmall. Otherwise, move forward and
532 535 * see if a single entry can be encoded.
533 536 */
534 537 tsize = rfs4_tsize(req);
535 538 if (args->maxcount > tsize)
536 539 args->maxcount = tsize;
537 540 else if (args->maxcount < RFS4_MINLEN_RDDIR_BUF) {
538 541 if (args->maxcount < RFS4_MINLEN_ENTRY4) {
539 542 *cs->statusp = resp->status = NFS4ERR_TOOSMALL;
540 543 goto out;
541 544 }
542 545 }
543 546
544 547 /*
545 548 * How large should the mblk be for outgoing encoding.
546 549 */
547 550 if (args->maxcount < MAXBSIZE)
548 551 mpcount = MAXBSIZE;
549 552 else
550 553 mpcount = args->maxcount;
551 554
552 555 /*
553 556 * mp will contain the data to be sent out in the readdir reply.
554 557 * It will be freed after the reply has been sent.
555 558 * Let's roundup the data to a BYTES_PER_XDR_UNIX multiple,
556 559 * so that the call to xdrmblk_putmblk() never fails.
557 560 */
558 561 mp = allocb(RNDUP(mpcount), BPRI_MED);
559 562
560 563 if (mp == NULL) {
561 564 /*
562 565 * The allocation of the client's requested size has
563 566 * failed. It may be that the size is too large for
564 567 * current system utilization; step down to a "common"
565 568 * size and wait for the allocation to occur.
566 569 */
567 570 if (mpcount > MAXBSIZE)
568 571 args->maxcount = mpcount = MAXBSIZE;
569 572 mp = allocb_wait(RNDUP(mpcount), BPRI_MED,
570 573 STR_NOSIG, &alloc_err);
571 574 }
572 575
573 576 ASSERT(mp != NULL);
574 577 ASSERT(alloc_err == 0);
575 578
576 579 resp->mblk = mp;
577 580
578 581 ptr = beginning_ptr = (uint32_t *)mp->b_datap->db_base;
579 582
580 583 /*
581 584 * The "redzone" at the end of the encoding buffer is used
582 585 * to deal with xdr encoding length. Instead of checking
583 586 * each encoding of an attribute value before it is done,
584 587 * make the assumption that it will fit into the buffer and
585 588 * check occasionally.
586 589 *
587 590 * The largest block of attributes that are encoded without
588 591 * checking the redzone is 18 * BYTES_PER_XDR_UNIT (72 bytes)
589 592 * "round" to 128 as the redzone size.
590 593 */
591 594 if (args->maxcount < (mpcount - 128))
592 595 ptr_redzone =
593 596 (uint32_t *)(((char *)ptr) + RNDUP(args->maxcount));
594 597 else
595 598 ptr_redzone =
596 599 (uint32_t *)((((char *)ptr) + RNDUP(mpcount)) - 128);
597 600
598 601 /*
599 602 * Set the dircount; this will be used as the size for the
600 603 * readdir of the underlying filesystem. First make sure
601 604 * that it is large enough to do a reasonable readdir (client
602 605 * may have short changed us - it is an advisory number);
603 606 * then make sure that it isn't too large.
604 607 * After all of that, if maxcount is "small" then just use
605 608 * that for the dircount number.
606 609 */
607 610 dircount = (args->dircount < MAXBSIZE) ? MAXBSIZE : args->dircount;
608 611 dircount = (dircount > tsize) ? tsize : dircount;
609 612 if (dircount > args->maxcount)
610 613 dircount = args->maxcount;
611 614 if (args->maxcount <= MAXBSIZE) {
612 615 if (args->maxcount < RFS4_MINLEN_RDDIR_BUF)
613 616 dircount = RFS4_MINLEN_RDDIR_BUF;
614 617 else
615 618 dircount = args->maxcount;
616 619 }
617 620
618 621 /* number of entries fully encoded in outgoing buffer */
619 622 nents = 0;
620 623
621 624 /* ENCODE READDIR4res.cookieverf */
622 625 IXDR_PUT_HYPER(ptr, Readdir4verf);
623 626
624 627 rddir_data_len = dircount;
625 628 rddir_data = kmem_alloc(rddir_data_len, KM_NOSLEEP);
626 629 if (rddir_data == NULL) {
627 630 /* The allocation failed; downsize and wait for it this time */
628 631 if (rddir_data_len > MAXBSIZE)
629 632 rddir_data_len = dircount = MAXBSIZE;
630 633 rddir_data = kmem_alloc(rddir_data_len, KM_SLEEP);
631 634 }
632 635
633 636 rddir_next_offset = (offset_t)args->cookie;
634 637
635 638 ca = (struct sockaddr *)svc_getrpccaller(req->rq_xprt)->buf;
636 639
637 640 readagain:
638 641
639 642 no_space = FALSE;
640 643 iseofdir = FALSE;
641 644
642 645 vp = NULL;
643 646
644 647 /* Move on to reading the directory contents */
645 648 iov.iov_base = rddir_data;
646 649 iov.iov_len = rddir_data_len;
647 650 uio.uio_iov = &iov;
648 651 uio.uio_iovcnt = 1;
649 652 uio.uio_segflg = UIO_SYSSPACE;
650 653 uio.uio_extflg = UIO_COPY_CACHED;
651 654 uio.uio_loffset = rddir_next_offset;
652 655 uio.uio_resid = rddir_data_len;
653 656
654 657 (void) VOP_RWLOCK(dvp, V_WRITELOCK_FALSE, NULL);
655 658
656 659 error = VOP_READDIR(dvp, &uio, cs->cr, &iseofdir, NULL, 0);
657 660
658 661 VOP_RWUNLOCK(dvp, V_WRITELOCK_FALSE, NULL);
659 662
660 663 if (error) {
661 664 kmem_free((caddr_t)rddir_data, rddir_data_len);
662 665 freeb(resp->mblk);
663 666 resp->mblk = NULL;
664 667 resp->data_len = 0;
665 668 *cs->statusp = resp->status = puterrno4(error);
666 669 goto out;
667 670 }
668 671
669 672
670 673 rddir_result_size = rddir_data_len - uio.uio_resid;
671 674
672 675 /* No data were read. Check if we reached the end of the directory. */
673 676 if (rddir_result_size == 0) {
674 677 /* encode the BOOLEAN marking no further entries */
675 678 IXDR_PUT_U_INT32(ptr, false);
676 679 /* encode the BOOLEAN signifying end of directory */
677 680 IXDR_PUT_U_INT32(ptr, iseofdir ? true : false);
678 681 resp->data_len = (char *)ptr - (char *)beginning_ptr;
679 682 resp->mblk->b_wptr += resp->data_len;
680 683 kmem_free((caddr_t)rddir_data, rddir_data_len);
681 684 *cs->statusp = resp->status = NFS4_OK;
682 685 goto out;
683 686 }
684 687
685 688 lastentry_ptr = ptr;
686 689 no_space = 0;
687 690 for (dp = (struct dirent64 *)rddir_data;
688 691 !no_space && rddir_result_size > 0; dp = nextdp(dp)) {
689 692
690 693 /* reset visp */
691 694 visp = NULL;
692 695
693 696 if (vp) {
694 697 VN_RELE(vp);
695 698 vp = NULL;
696 699 }
697 700
698 701 if (newexi)
699 702 newexi = NULL;
700 703
701 704 rddir_result_size -= dp->d_reclen;
702 705
703 706 /* skip "." and ".." entries */
704 707 if (dp->d_ino == 0 || NFS_IS_DOTNAME(dp->d_name)) {
705 708 rddir_next_offset = dp->d_off;
706 709 continue;
707 710 }
708 711
709 712 if (check_visible &&
710 713 !nfs_visible_inode(cs->exi, dp->d_ino, &visp)) {
711 714 rddir_next_offset = dp->d_off;
712 715 continue;
713 716 }
714 717
715 718 /*
716 719 * Only if the client requested attributes...
717 720 * If the VOP_LOOKUP fails ENOENT, then skip this entry
718 721 * for the readdir response. If there was another error,
719 722 * then set the rddirattr_error and the error will be
720 723 * encoded later in the "attributes" section.
721 724 */
722 725 ae = ar;
723 726 if (ar == 0)
724 727 goto reencode_attrs;
725 728
726 729 error = nfs4_readdir_getvp(dvp, dp->d_name,
727 730 &vp, &newexi, req, cs,
728 731 visp != NULL ? visp->vis_exported : 0);
729 732 if (error == ENOENT) {
730 733 rddir_next_offset = dp->d_off;
731 734 continue;
732 735 }
733 736
734 737 rddirattr_error = error;
735 738
736 739 /*
737 740 * The vp obtained from above may be from a
738 741 * different filesystem mount and the vfs-like
739 742 * attributes should be obtained from that
740 743 * different vfs; only do this if appropriate.
741 744 */
742 745 if (vp &&
743 746 (vfs_different = (dvp->v_vfsp != vp->v_vfsp))) {
744 747 if (ar & (FATTR4_FILES_AVAIL_MASK |
745 748 FATTR4_FILES_FREE_MASK |
746 749 FATTR4_FILES_TOTAL_MASK |
747 750 FATTR4_FILES_AVAIL_MASK |
748 751 FATTR4_FILES_FREE_MASK |
749 752 FATTR4_FILES_TOTAL_MASK)) {
750 753 if (error =
751 754 rfs4_get_sb_encode(dvp->v_vfsp,
752 755 &sbe)) {
753 756 /* Remove attrs from encode */
754 757 ae &= ~(FATTR4_FILES_AVAIL_MASK |
755 758 FATTR4_FILES_FREE_MASK |
756 759 FATTR4_FILES_TOTAL_MASK |
757 760 FATTR4_FILES_AVAIL_MASK |
758 761 FATTR4_FILES_FREE_MASK |
759 762 FATTR4_FILES_TOTAL_MASK);
760 763 rddirattr_error = error;
761 764 }
762 765 }
763 766 if (ar & (FATTR4_MAXFILESIZE_MASK |
764 767 FATTR4_MAXLINK_MASK |
765 768 FATTR4_MAXNAME_MASK)) {
766 769 if (error = rfs4_get_pc_encode(cs->vp,
|
↓ open down ↓ |
727 lines elided |
↑ open up ↑ |
767 770 &pce, ar, cs->cr)) {
768 771 ar &= ~(FATTR4_MAXFILESIZE_MASK |
769 772 FATTR4_MAXLINK_MASK |
770 773 FATTR4_MAXNAME_MASK);
771 774 rddirattr_error = error;
772 775 }
773 776 }
774 777 }
775 778
776 779 reencode_attrs:
777 - /* encode the BOOLEAN for the existence of the next entry */
778 - IXDR_PUT_U_INT32(ptr, true);
779 - /* encode the COOKIE for the entry */
780 - IXDR_PUT_U_HYPER(ptr, dp->d_off);
781 -
782 780 name = nfscmd_convname(ca, cs->exi, dp->d_name,
783 781 NFSCMD_CONV_OUTBOUND, MAXPATHLEN + 1);
784 782
785 783 if (name == NULL) {
786 784 rddir_next_offset = dp->d_off;
787 785 continue;
788 786 }
789 787 /* Calculate the dirent name length */
790 788 namelen = strlen(name);
791 789
792 790 rndup = RNDUP(namelen) / BYTES_PER_XDR_UNIT;
793 791
794 792 /* room for LENGTH + string ? */
795 793 if ((ptr + (1 + rndup)) > ptr_redzone) {
796 794 no_space = TRUE;
795 + if (name != dp->d_name)
796 + kmem_free(name, MAXPATHLEN + 1);
797 797 continue;
798 798 }
799 799
800 - /* encode the LENGTH of the name */
801 - IXDR_PUT_U_INT32(ptr, namelen);
802 - /* encode the RNDUP FILL first */
803 - ptr[rndup - 1] = 0;
804 - /* encode the NAME of the entry */
805 - bcopy(name, (char *)ptr, namelen);
806 - /* now bump the ptr after... */
807 - ptr += rndup;
808 -
809 - if (name != dp->d_name)
810 - kmem_free(name, MAXPATHLEN + 1);
811 -
812 800 /*
813 801 * Keep checking on the dircount to see if we have
814 802 * reached the limit; from the RFC, dircount is to be
815 803 * the XDR encoded limit of the cookie plus name.
816 804 * So the count is the name, XDR_UNIT of length for
817 805 * that name and 2 * XDR_UNIT bytes of cookie;
818 806 * However, use the regular DIRENT64 to match most
819 807 * client's APIs.
820 808 */
821 809 dircount -= DIRENT64_RECLEN(namelen);
822 810 if (nents != 0 && dircount < 0) {
823 811 no_space = TRUE;
812 + if (name != dp->d_name)
813 + kmem_free(name, MAXPATHLEN + 1);
824 814 continue;
825 815 }
826 816
817 + /* encode the BOOLEAN for the existence of the next entry */
818 + IXDR_PUT_U_INT32(ptr, true);
819 + /* encode the COOKIE for the entry */
820 + IXDR_PUT_U_HYPER(ptr, dp->d_off);
821 +
822 + /* encode the LENGTH of the name */
823 + IXDR_PUT_U_INT32(ptr, namelen);
824 + /* encode the RNDUP FILL first */
825 + ptr[rndup - 1] = 0;
826 + /* encode the NAME of the entry */
827 + bcopy(name, (char *)ptr, namelen);
828 + /* now bump the ptr after... */
829 + ptr += rndup;
830 +
831 + if (name != dp->d_name)
832 + kmem_free(name, MAXPATHLEN + 1);
833 +
827 834 /*
828 835 * Attributes requested?
829 836 * Gather up the attribute info and the previous VOP_LOOKUP()
830 837 * succeeded; if an error occurs on the VOP_GETATTR() then
831 838 * return just the error (again if it is requested).
832 839 * Note that the previous VOP_LOOKUP() could have failed
833 840 * itself which leaves this code without anything for
834 841 * a VOP_GETATTR().
835 842 * Also note that the readdir_attr_error is left in the
836 843 * encoding mask if requested and so is the mounted_on_fileid.
837 844 */
838 845 if (ae != 0) {
839 846 if (!vp) {
840 847 ae = ar & (FATTR4_RDATTR_ERROR_MASK |
841 848 FATTR4_MOUNTED_ON_FILEID_MASK);
842 849 } else {
843 850 va.va_mask = AT_ALL;
844 851 rddirattr_error =
845 852 VOP_GETATTR(vp, &va, 0, cs->cr, NULL);
846 853 if (rddirattr_error) {
847 854 ae = ar & (FATTR4_RDATTR_ERROR_MASK |
848 855 FATTR4_MOUNTED_ON_FILEID_MASK);
849 856 } else {
850 857 /*
851 858 * We may lie about the object
852 859 * type for a referral
853 860 */
854 861 if (vn_is_nfs_reparse(vp, cs->cr) &&
855 862 client_is_downrev(req))
856 863 va.va_type = VLNK;
857 864 }
858 865 }
859 866 }
860 867
861 868 /* START OF ATTRIBUTE ENCODING */
862 869
863 870 /* encode the LENGTH of the BITMAP4 array */
864 871 IXDR_PUT_U_INT32(ptr, 2);
865 872 /* encode the BITMAP4 */
866 873 attrmask_ptr = ptr;
867 874 IXDR_PUT_HYPER(ptr, ae);
868 875 attr_offset_ptr = ptr;
869 876 /* encode the default LENGTH of the attributes for entry */
870 877 IXDR_PUT_U_INT32(ptr, 0);
871 878
872 879 if (ptr > ptr_redzone) {
873 880 no_space = TRUE;
874 881 continue;
875 882 }
876 883
877 884 /* Check if any of the first 32 attributes are being encoded */
878 885 if (ae & 0xffffffff00000000) {
879 886 /*
880 887 * Redzone check is done at the end of this section.
881 888 * This particular section will encode a maximum of
882 889 * 18 * BYTES_PER_XDR_UNIT of data
883 890 */
884 891 if (ae &
885 892 (FATTR4_SUPPORTED_ATTRS_MASK |
886 893 FATTR4_TYPE_MASK |
887 894 FATTR4_FH_EXPIRE_TYPE_MASK |
888 895 FATTR4_CHANGE_MASK |
889 896 FATTR4_SIZE_MASK |
890 897 FATTR4_LINK_SUPPORT_MASK |
891 898 FATTR4_SYMLINK_SUPPORT_MASK |
892 899 FATTR4_NAMED_ATTR_MASK |
893 900 FATTR4_FSID_MASK |
894 901 FATTR4_UNIQUE_HANDLES_MASK |
895 902 FATTR4_LEASE_TIME_MASK |
896 903 FATTR4_RDATTR_ERROR_MASK)) {
897 904
898 905 if (ae & FATTR4_SUPPORTED_ATTRS_MASK) {
899 906 IXDR_PUT_INT32(ptr, 2);
900 907 IXDR_PUT_HYPER(ptr,
901 908 rfs4_supported_attrs);
902 909 }
903 910 if (ae & FATTR4_TYPE_MASK) {
904 911 uint_t ftype = vt_to_nf4[va.va_type];
905 912 if (dvp->v_flag & V_XATTRDIR) {
906 913 if (va.va_type == VDIR)
907 914 ftype = NF4ATTRDIR;
908 915 else
909 916 ftype = NF4NAMEDATTR;
910 917 }
911 918 IXDR_PUT_U_INT32(ptr, ftype);
912 919 }
913 920 if (ae & FATTR4_FH_EXPIRE_TYPE_MASK) {
914 921 uint_t expire_type = FH4_PERSISTENT;
915 922 IXDR_PUT_U_INT32(ptr, expire_type);
916 923 }
917 924 if (ae & FATTR4_CHANGE_MASK) {
918 925 u_longlong_t change;
919 926 NFS4_SET_FATTR4_CHANGE(change,
920 927 va.va_ctime);
921 928 if (visp != NULL) {
922 929 u_longlong_t visch;
923 930 NFS4_SET_FATTR4_CHANGE(visch,
924 931 visp->vis_change);
925 932 if (visch > change)
926 933 change = visch;
927 934 }
928 935 IXDR_PUT_HYPER(ptr, change);
929 936 }
930 937 if (ae & FATTR4_SIZE_MASK) {
931 938 u_longlong_t size = va.va_size;
932 939 IXDR_PUT_HYPER(ptr, size);
933 940 }
934 941 if (ae & FATTR4_LINK_SUPPORT_MASK) {
935 942 IXDR_PUT_U_INT32(ptr, true);
936 943 }
937 944 if (ae & FATTR4_SYMLINK_SUPPORT_MASK) {
938 945 IXDR_PUT_U_INT32(ptr, true);
939 946 }
940 947 if (ae & FATTR4_NAMED_ATTR_MASK) {
941 948 uint_t isit;
942 949 pc_val = FALSE;
943 950 int sattr_error;
944 951
945 952 if (!(vp->v_vfsp->vfs_flag &
946 953 VFS_XATTR)) {
947 954 isit = FALSE;
948 955 } else {
949 956 sattr_error = VOP_PATHCONF(vp,
950 957 _PC_SATTR_EXISTS,
951 958 &pc_val, cs->cr, NULL);
952 959 if (sattr_error || pc_val == 0)
953 960 (void) VOP_PATHCONF(vp,
954 961 _PC_XATTR_EXISTS,
955 962 &pc_val,
956 963 cs->cr, NULL);
957 964 }
958 965 isit = (pc_val ? TRUE : FALSE);
959 966 IXDR_PUT_U_INT32(ptr, isit);
960 967 }
961 968 if (ae & FATTR4_FSID_MASK) {
962 969 u_longlong_t major, minor;
963 970 struct exportinfo *exi;
964 971
965 972 exi = newexi ? newexi : cs->exi;
966 973 if (exi->exi_volatile_dev) {
967 974 int *pmaj = (int *)&major;
968 975
969 976 pmaj[0] = exi->exi_fsid.val[0];
970 977 pmaj[1] = exi->exi_fsid.val[1];
971 978 minor = 0;
972 979 } else {
973 980 major = getmajor(va.va_fsid);
974 981 minor = getminor(va.va_fsid);
975 982 }
976 983 IXDR_PUT_HYPER(ptr, major);
977 984 IXDR_PUT_HYPER(ptr, minor);
978 985 }
979 986 if (ae & FATTR4_UNIQUE_HANDLES_MASK) {
980 987 IXDR_PUT_U_INT32(ptr, false);
981 988 }
982 989 if (ae & FATTR4_LEASE_TIME_MASK) {
983 990 uint_t lt = rfs4_lease_time;
984 991 IXDR_PUT_U_INT32(ptr, lt);
985 992 }
986 993 if (ae & FATTR4_RDATTR_ERROR_MASK) {
987 994 rddirattr_error =
988 995 (rddirattr_error == 0 ?
989 996 0 : puterrno4(rddirattr_error));
990 997 IXDR_PUT_U_INT32(ptr, rddirattr_error);
991 998 }
992 999
993 1000 /* Check the redzone boundary */
994 1001 if (ptr > ptr_redzone) {
995 1002 if (nents || IS_MIN_ATTR_MASK(ar)) {
996 1003 no_space = TRUE;
997 1004 continue;
998 1005 }
999 1006 MINIMIZE_ATTR_MASK(ar);
1000 1007 ae = ar;
1001 1008 ptr = lastentry_ptr;
1002 1009 goto reencode_attrs;
1003 1010 }
1004 1011 }
1005 1012 /*
1006 1013 * Redzone check is done at the end of this section.
1007 1014 * This particular section will encode a maximum of
1008 1015 * 4 * BYTES_PER_XDR_UNIT of data.
1009 1016 * NOTE: that if ACLs are supported that the
1010 1017 * redzone calculations will need to change.
1011 1018 */
1012 1019 if (ae &
1013 1020 (FATTR4_ACL_MASK |
1014 1021 FATTR4_ACLSUPPORT_MASK |
1015 1022 FATTR4_ARCHIVE_MASK |
1016 1023 FATTR4_CANSETTIME_MASK |
1017 1024 FATTR4_CASE_INSENSITIVE_MASK |
1018 1025 FATTR4_CASE_PRESERVING_MASK |
1019 1026 FATTR4_CHOWN_RESTRICTED_MASK)) {
1020 1027
1021 1028 if (ae & FATTR4_ACL_MASK) {
1022 1029 ASSERT(0);
1023 1030 }
1024 1031 if (ae & FATTR4_ACLSUPPORT_MASK) {
1025 1032 ASSERT(0);
1026 1033 }
1027 1034 if (ae & FATTR4_ARCHIVE_MASK) {
1028 1035 ASSERT(0);
1029 1036 }
1030 1037 if (ae & FATTR4_CANSETTIME_MASK) {
1031 1038 IXDR_PUT_U_INT32(ptr, true);
1032 1039 }
1033 1040 if (ae & FATTR4_CASE_INSENSITIVE_MASK) {
1034 1041 IXDR_PUT_U_INT32(ptr, false);
1035 1042 }
1036 1043 if (ae & FATTR4_CASE_PRESERVING_MASK) {
1037 1044 IXDR_PUT_U_INT32(ptr, true);
1038 1045 }
1039 1046 if (ae & FATTR4_CHOWN_RESTRICTED_MASK) {
1040 1047 uint_t isit;
1041 1048 pc_val = FALSE;
1042 1049 (void) VOP_PATHCONF(vp,
1043 1050 _PC_CHOWN_RESTRICTED,
1044 1051 &pc_val, cs->cr, NULL);
1045 1052 isit = (pc_val ? TRUE : FALSE);
1046 1053 IXDR_PUT_U_INT32(ptr, isit);
1047 1054 }
1048 1055 /* Check the redzone boundary */
1049 1056 if (ptr > ptr_redzone) {
1050 1057 if (nents || IS_MIN_ATTR_MASK(ar)) {
1051 1058 no_space = TRUE;
1052 1059 continue;
1053 1060 }
1054 1061 MINIMIZE_ATTR_MASK(ar);
1055 1062 ae = ar;
1056 1063 ptr = lastentry_ptr;
1057 1064 goto reencode_attrs;
1058 1065 }
1059 1066 }
1060 1067 /*
1061 1068 * Redzone check is done before the filehandle
1062 1069 * is encoded.
1063 1070 */
1064 1071 if (ae &
1065 1072 (FATTR4_FILEHANDLE_MASK |
1066 1073 FATTR4_FILEID_MASK)) {
1067 1074
1068 1075 if (ae & FATTR4_FILEHANDLE_MASK) {
1069 1076 struct {
1070 1077 uint_t len;
1071 1078 char *val;
1072 1079 char fh[NFS_FH4_LEN];
1073 1080 } fh;
1074 1081 fh.len = 0;
1075 1082 fh.val = fh.fh;
1076 1083 (void) makefh4((nfs_fh4 *)&fh, vp,
1077 1084 (newexi ? newexi : cs->exi));
1078 1085
1079 1086 if (dvp->v_flag & V_XATTRDIR)
1080 1087 set_fh4_flag((nfs_fh4 *)&fh,
1081 1088 FH4_NAMEDATTR);
1082 1089
1083 1090 if (!xdr_inline_encode_nfs_fh4(
1084 1091 &ptr, ptr_redzone,
1085 1092 (nfs_fh4_fmt_t *)fh.val)) {
1086 1093 if (nents ||
1087 1094 IS_MIN_ATTR_MASK(ar)) {
1088 1095 no_space = TRUE;
1089 1096 continue;
1090 1097 }
1091 1098 MINIMIZE_ATTR_MASK(ar);
1092 1099 ae = ar;
1093 1100 ptr = lastentry_ptr;
1094 1101 goto reencode_attrs;
1095 1102 }
1096 1103 }
1097 1104 if (ae & FATTR4_FILEID_MASK) {
1098 1105 IXDR_PUT_HYPER(ptr, va.va_nodeid);
1099 1106 }
1100 1107 /* Check the redzone boundary */
1101 1108 if (ptr > ptr_redzone) {
1102 1109 if (nents || IS_MIN_ATTR_MASK(ar)) {
1103 1110 no_space = TRUE;
1104 1111 continue;
1105 1112 }
1106 1113 MINIMIZE_ATTR_MASK(ar);
1107 1114 ae = ar;
1108 1115 ptr = lastentry_ptr;
1109 1116 goto reencode_attrs;
1110 1117 }
1111 1118 }
1112 1119 /*
1113 1120 * Redzone check is done at the end of this section.
1114 1121 * This particular section will encode a maximum of
1115 1122 * 15 * BYTES_PER_XDR_UNIT of data.
1116 1123 */
1117 1124 if (ae &
1118 1125 (FATTR4_FILES_AVAIL_MASK |
1119 1126 FATTR4_FILES_FREE_MASK |
1120 1127 FATTR4_FILES_TOTAL_MASK |
1121 1128 FATTR4_FS_LOCATIONS_MASK |
1122 1129 FATTR4_HIDDEN_MASK |
1123 1130 FATTR4_HOMOGENEOUS_MASK |
1124 1131 FATTR4_MAXFILESIZE_MASK |
1125 1132 FATTR4_MAXLINK_MASK |
1126 1133 FATTR4_MAXNAME_MASK |
1127 1134 FATTR4_MAXREAD_MASK |
1128 1135 FATTR4_MAXWRITE_MASK)) {
1129 1136
1130 1137 if (ae & FATTR4_FILES_AVAIL_MASK) {
1131 1138 IXDR_PUT_HYPER(ptr, sbe.fa);
1132 1139 }
1133 1140 if (ae & FATTR4_FILES_FREE_MASK) {
1134 1141 IXDR_PUT_HYPER(ptr, sbe.ff);
1135 1142 }
1136 1143 if (ae & FATTR4_FILES_TOTAL_MASK) {
1137 1144 IXDR_PUT_HYPER(ptr, sbe.ft);
1138 1145 }
1139 1146 if (ae & FATTR4_FS_LOCATIONS_MASK) {
1140 1147 ASSERT(0);
1141 1148 }
1142 1149 if (ae & FATTR4_HIDDEN_MASK) {
1143 1150 ASSERT(0);
1144 1151 }
1145 1152 if (ae & FATTR4_HOMOGENEOUS_MASK) {
1146 1153 IXDR_PUT_U_INT32(ptr, true);
1147 1154 }
1148 1155 if (ae & FATTR4_MAXFILESIZE_MASK) {
1149 1156 IXDR_PUT_HYPER(ptr, pce.maxfilesize);
1150 1157 }
1151 1158 if (ae & FATTR4_MAXLINK_MASK) {
1152 1159 IXDR_PUT_U_INT32(ptr, pce.maxlink);
1153 1160 }
1154 1161 if (ae & FATTR4_MAXNAME_MASK) {
1155 1162 IXDR_PUT_U_INT32(ptr, pce.maxname);
1156 1163 }
1157 1164 if (ae & FATTR4_MAXREAD_MASK) {
1158 1165 IXDR_PUT_HYPER(ptr, maxread);
1159 1166 }
1160 1167 if (ae & FATTR4_MAXWRITE_MASK) {
1161 1168 IXDR_PUT_HYPER(ptr, maxwrite);
1162 1169 }
1163 1170 /* Check the redzone boundary */
1164 1171 if (ptr > ptr_redzone) {
1165 1172 if (nents || IS_MIN_ATTR_MASK(ar)) {
1166 1173 no_space = TRUE;
1167 1174 continue;
1168 1175 }
1169 1176 MINIMIZE_ATTR_MASK(ar);
1170 1177 ae = ar;
1171 1178 ptr = lastentry_ptr;
1172 1179 goto reencode_attrs;
1173 1180 }
1174 1181 }
1175 1182 }
1176 1183 if (ae & 0x00000000ffffffff) {
1177 1184 /*
1178 1185 * Redzone check is done at the end of this section.
1179 1186 * This particular section will encode a maximum of
1180 1187 * 3 * BYTES_PER_XDR_UNIT of data.
1181 1188 */
1182 1189 if (ae &
1183 1190 (FATTR4_MIMETYPE_MASK |
1184 1191 FATTR4_MODE_MASK |
1185 1192 FATTR4_NO_TRUNC_MASK |
1186 1193 FATTR4_NUMLINKS_MASK)) {
1187 1194
1188 1195 if (ae & FATTR4_MIMETYPE_MASK) {
1189 1196 ASSERT(0);
1190 1197 }
1191 1198 if (ae & FATTR4_MODE_MASK) {
1192 1199 uint_t m = va.va_mode;
1193 1200 IXDR_PUT_U_INT32(ptr, m);
1194 1201 }
1195 1202 if (ae & FATTR4_NO_TRUNC_MASK) {
1196 1203 IXDR_PUT_U_INT32(ptr, true);
1197 1204 }
1198 1205 if (ae & FATTR4_NUMLINKS_MASK) {
1199 1206 IXDR_PUT_U_INT32(ptr, va.va_nlink);
1200 1207 }
1201 1208 /* Check the redzone boundary */
1202 1209 if (ptr > ptr_redzone) {
1203 1210 if (nents || IS_MIN_ATTR_MASK(ar)) {
1204 1211 no_space = TRUE;
1205 1212 continue;
1206 1213 }
1207 1214 MINIMIZE_ATTR_MASK(ar);
1208 1215 ae = ar;
1209 1216 ptr = lastentry_ptr;
1210 1217 goto reencode_attrs;
1211 1218 }
1212 1219 }
1213 1220 /*
1214 1221 * Redzone check is done before the encoding of the
1215 1222 * owner string since the length is indeterminate.
1216 1223 */
1217 1224 if (ae & FATTR4_OWNER_MASK) {
1218 1225 if (!lu_set) {
1219 1226 owner_error = nfs_idmap_uid_str(
1220 1227 va.va_uid, &owner, TRUE);
1221 1228 if (!owner_error) {
1222 1229 lu_set = TRUE;
1223 1230 lastuid = va.va_uid;
1224 1231 }
1225 1232 } else if (va.va_uid != lastuid) {
1226 1233 if (owner.utf8string_len != 0) {
1227 1234 kmem_free(owner.utf8string_val,
1228 1235 owner.utf8string_len);
1229 1236 owner.utf8string_len = 0;
1230 1237 owner.utf8string_val = NULL;
1231 1238 }
1232 1239 owner_error = nfs_idmap_uid_str(
1233 1240 va.va_uid, &owner, TRUE);
1234 1241 if (!owner_error) {
1235 1242 lastuid = va.va_uid;
1236 1243 } else {
1237 1244 lu_set = FALSE;
1238 1245 }
1239 1246 }
1240 1247 if (!owner_error) {
1241 1248 if ((ptr +
1242 1249 (owner.utf8string_len /
1243 1250 BYTES_PER_XDR_UNIT)
1244 1251 + 2) > ptr_redzone) {
1245 1252 if (nents ||
1246 1253 IS_MIN_ATTR_MASK(ar)) {
1247 1254 no_space = TRUE;
1248 1255 continue;
1249 1256 }
1250 1257 MINIMIZE_ATTR_MASK(ar);
1251 1258 ae = ar;
1252 1259 ptr = lastentry_ptr;
1253 1260 goto reencode_attrs;
1254 1261 }
1255 1262 /* encode the LENGTH of owner string */
1256 1263 IXDR_PUT_U_INT32(ptr,
1257 1264 owner.utf8string_len);
1258 1265 /* encode the RNDUP FILL first */
1259 1266 rndup = RNDUP(owner.utf8string_len) /
1260 1267 BYTES_PER_XDR_UNIT;
1261 1268 ptr[rndup - 1] = 0;
1262 1269 /* encode the OWNER */
1263 1270 bcopy(owner.utf8string_val, ptr,
1264 1271 owner.utf8string_len);
1265 1272 ptr += rndup;
1266 1273 }
1267 1274 }
1268 1275 /*
1269 1276 * Redzone check is done before the encoding of the
1270 1277 * group string since the length is indeterminate.
1271 1278 */
1272 1279 if (ae & FATTR4_OWNER_GROUP_MASK) {
1273 1280 if (!lg_set) {
1274 1281 group_error =
1275 1282 nfs_idmap_gid_str(va.va_gid,
1276 1283 &group, TRUE);
1277 1284 if (!group_error) {
1278 1285 lg_set = TRUE;
1279 1286 lastgid = va.va_gid;
1280 1287 }
1281 1288 } else if (va.va_gid != lastgid) {
1282 1289 if (group.utf8string_len != 0) {
1283 1290 kmem_free(
1284 1291 group.utf8string_val,
1285 1292 group.utf8string_len);
1286 1293 group.utf8string_len = 0;
1287 1294 group.utf8string_val = NULL;
1288 1295 }
1289 1296 group_error =
1290 1297 nfs_idmap_gid_str(va.va_gid,
1291 1298 &group, TRUE);
1292 1299 if (!group_error)
1293 1300 lastgid = va.va_gid;
1294 1301 else
1295 1302 lg_set = FALSE;
1296 1303 }
1297 1304 if (!group_error) {
1298 1305 if ((ptr +
1299 1306 (group.utf8string_len /
1300 1307 BYTES_PER_XDR_UNIT)
1301 1308 + 2) > ptr_redzone) {
1302 1309 if (nents ||
1303 1310 IS_MIN_ATTR_MASK(ar)) {
1304 1311 no_space = TRUE;
1305 1312 continue;
1306 1313 }
1307 1314 MINIMIZE_ATTR_MASK(ar);
1308 1315 ae = ar;
1309 1316 ptr = lastentry_ptr;
1310 1317 goto reencode_attrs;
1311 1318 }
1312 1319 /* encode the LENGTH of owner string */
1313 1320 IXDR_PUT_U_INT32(ptr,
1314 1321 group.utf8string_len);
1315 1322 /* encode the RNDUP FILL first */
1316 1323 rndup = RNDUP(group.utf8string_len) /
1317 1324 BYTES_PER_XDR_UNIT;
1318 1325 ptr[rndup - 1] = 0;
1319 1326 /* encode the OWNER */
1320 1327 bcopy(group.utf8string_val, ptr,
1321 1328 group.utf8string_len);
1322 1329 ptr += rndup;
1323 1330 }
1324 1331 }
1325 1332 if (ae &
1326 1333 (FATTR4_QUOTA_AVAIL_HARD_MASK |
1327 1334 FATTR4_QUOTA_AVAIL_SOFT_MASK |
1328 1335 FATTR4_QUOTA_USED_MASK)) {
1329 1336 if (ae & FATTR4_QUOTA_AVAIL_HARD_MASK) {
1330 1337 ASSERT(0);
1331 1338 }
1332 1339 if (ae & FATTR4_QUOTA_AVAIL_SOFT_MASK) {
1333 1340 ASSERT(0);
1334 1341 }
1335 1342 if (ae & FATTR4_QUOTA_USED_MASK) {
1336 1343 ASSERT(0);
1337 1344 }
1338 1345 }
1339 1346 /*
1340 1347 * Redzone check is done at the end of this section.
1341 1348 * This particular section will encode a maximum of
1342 1349 * 10 * BYTES_PER_XDR_UNIT of data.
1343 1350 */
1344 1351 if (ae &
1345 1352 (FATTR4_RAWDEV_MASK |
1346 1353 FATTR4_SPACE_AVAIL_MASK |
1347 1354 FATTR4_SPACE_FREE_MASK |
1348 1355 FATTR4_SPACE_TOTAL_MASK |
1349 1356 FATTR4_SPACE_USED_MASK |
1350 1357 FATTR4_SYSTEM_MASK)) {
1351 1358
1352 1359 if (ae & FATTR4_RAWDEV_MASK) {
1353 1360 fattr4_rawdev rd;
1354 1361 rd.specdata1 =
1355 1362 (uint32)getmajor(va.va_rdev);
1356 1363 rd.specdata2 =
1357 1364 (uint32)getminor(va.va_rdev);
1358 1365 IXDR_PUT_U_INT32(ptr, rd.specdata1);
1359 1366 IXDR_PUT_U_INT32(ptr, rd.specdata2);
1360 1367 }
1361 1368 if (ae & FATTR4_SPACE_AVAIL_MASK) {
1362 1369 IXDR_PUT_HYPER(ptr, sbe.space_avail);
1363 1370 }
1364 1371 if (ae & FATTR4_SPACE_FREE_MASK) {
1365 1372 IXDR_PUT_HYPER(ptr, sbe.space_free);
1366 1373 }
1367 1374 if (ae & FATTR4_SPACE_TOTAL_MASK) {
1368 1375 IXDR_PUT_HYPER(ptr, sbe.space_total);
1369 1376 }
1370 1377 if (ae & FATTR4_SPACE_USED_MASK) {
1371 1378 u_longlong_t su;
1372 1379 su = (fattr4_space_used) DEV_BSIZE *
1373 1380 (fattr4_space_used) va.va_nblocks;
1374 1381 IXDR_PUT_HYPER(ptr, su);
1375 1382 }
1376 1383 if (ae & FATTR4_SYSTEM_MASK) {
1377 1384 ASSERT(0);
1378 1385 }
1379 1386 /* Check the redzone boundary */
1380 1387 if (ptr > ptr_redzone) {
1381 1388 if (nents || IS_MIN_ATTR_MASK(ar)) {
1382 1389 no_space = TRUE;
1383 1390 continue;
1384 1391 }
1385 1392 MINIMIZE_ATTR_MASK(ar);
1386 1393 ae = ar;
1387 1394 ptr = lastentry_ptr;
1388 1395 goto reencode_attrs;
1389 1396 }
1390 1397 }
1391 1398 /*
1392 1399 * Redzone check is done at the end of this section.
1393 1400 * This particular section will encode a maximum of
1394 1401 * 14 * BYTES_PER_XDR_UNIT of data.
1395 1402 */
1396 1403 if (ae &
1397 1404 (FATTR4_TIME_ACCESS_MASK |
1398 1405 FATTR4_TIME_ACCESS_SET_MASK |
1399 1406 FATTR4_TIME_BACKUP_MASK |
1400 1407 FATTR4_TIME_CREATE_MASK |
1401 1408 FATTR4_TIME_DELTA_MASK |
1402 1409 FATTR4_TIME_METADATA_MASK |
1403 1410 FATTR4_TIME_MODIFY_MASK |
1404 1411 FATTR4_TIME_MODIFY_SET_MASK |
1405 1412 FATTR4_MOUNTED_ON_FILEID_MASK)) {
1406 1413
1407 1414 if (ae & FATTR4_TIME_ACCESS_MASK) {
1408 1415 u_longlong_t sec =
1409 1416 (u_longlong_t)va.va_atime.tv_sec;
1410 1417 uint_t nsec =
1411 1418 (uint_t)va.va_atime.tv_nsec;
1412 1419 IXDR_PUT_HYPER(ptr, sec);
1413 1420 IXDR_PUT_INT32(ptr, nsec);
1414 1421 }
1415 1422 if (ae & FATTR4_TIME_ACCESS_SET_MASK) {
1416 1423 ASSERT(0);
1417 1424 }
1418 1425 if (ae & FATTR4_TIME_BACKUP_MASK) {
1419 1426 ASSERT(0);
1420 1427 }
1421 1428 if (ae & FATTR4_TIME_CREATE_MASK) {
1422 1429 ASSERT(0);
1423 1430 }
1424 1431 if (ae & FATTR4_TIME_DELTA_MASK) {
1425 1432 u_longlong_t sec = 0;
1426 1433 uint_t nsec = 1000;
1427 1434 IXDR_PUT_HYPER(ptr, sec);
1428 1435 IXDR_PUT_INT32(ptr, nsec);
1429 1436 }
1430 1437 if (ae & FATTR4_TIME_METADATA_MASK) {
1431 1438 u_longlong_t sec =
1432 1439 (u_longlong_t)va.va_ctime.tv_sec;
1433 1440 uint_t nsec =
1434 1441 (uint_t)va.va_ctime.tv_nsec;
1435 1442 IXDR_PUT_HYPER(ptr, sec);
1436 1443 IXDR_PUT_INT32(ptr, nsec);
1437 1444 }
1438 1445 if (ae & FATTR4_TIME_MODIFY_MASK) {
1439 1446 u_longlong_t sec =
1440 1447 (u_longlong_t)va.va_mtime.tv_sec;
1441 1448 uint_t nsec =
1442 1449 (uint_t)va.va_mtime.tv_nsec;
1443 1450 IXDR_PUT_HYPER(ptr, sec);
1444 1451 IXDR_PUT_INT32(ptr, nsec);
1445 1452 }
1446 1453 if (ae & FATTR4_TIME_MODIFY_SET_MASK) {
1447 1454 ASSERT(0);
1448 1455 }
1449 1456 if (ae & FATTR4_MOUNTED_ON_FILEID_MASK) {
1450 1457 IXDR_PUT_HYPER(ptr, dp->d_ino);
1451 1458 }
1452 1459 /* Check the redzone boundary */
1453 1460 if (ptr > ptr_redzone) {
1454 1461 if (nents || IS_MIN_ATTR_MASK(ar)) {
1455 1462 no_space = TRUE;
1456 1463 continue;
1457 1464 }
1458 1465 MINIMIZE_ATTR_MASK(ar);
1459 1466 ae = ar;
1460 1467 ptr = lastentry_ptr;
1461 1468 goto reencode_attrs;
1462 1469 }
1463 1470 }
1464 1471 }
1465 1472
1466 1473 /* Reset to directory's vfs info when encoding complete */
1467 1474 if (vfs_different) {
1468 1475 dsbe = sbe;
1469 1476 dpce = pce;
1470 1477 vfs_different = 0;
1471 1478 }
1472 1479
1473 1480 /* "go back" and encode the attributes' length */
1474 1481 attr_length =
1475 1482 (char *)ptr -
1476 1483 (char *)attr_offset_ptr -
1477 1484 BYTES_PER_XDR_UNIT;
1478 1485 IXDR_PUT_U_INT32(attr_offset_ptr, attr_length);
1479 1486
1480 1487 /*
1481 1488 * If there was trouble obtaining a mapping for either
1482 1489 * the owner or group attributes, then remove them from
1483 1490 * bitmap4 for this entry and reset the bitmap value
1484 1491 * in the data stream.
1485 1492 */
1486 1493 if (owner_error || group_error) {
1487 1494 if (owner_error)
1488 1495 ae &= ~FATTR4_OWNER_MASK;
1489 1496 if (group_error)
1490 1497 ae &= ~FATTR4_OWNER_GROUP_MASK;
1491 1498 IXDR_PUT_HYPER(attrmask_ptr, ae);
1492 1499 }
1493 1500
1494 1501 /* END OF ATTRIBUTE ENCODING */
1495 1502
1496 1503 lastentry_ptr = ptr;
1497 1504 nents++;
1498 1505 rddir_next_offset = dp->d_off;
1499 1506 }
1500 1507
1501 1508 /*
1502 1509 * Check for the case that another VOP_READDIR() has to be done.
1503 1510 * - no space encoding error
1504 1511 * - no entry successfully encoded
1505 1512 * - still more directory to read
1506 1513 */
1507 1514 if (!no_space && nents == 0 && !iseofdir)
1508 1515 goto readagain;
1509 1516
1510 1517 *cs->statusp = resp->status = NFS4_OK;
1511 1518
1512 1519 /*
1513 1520 * If no_space is set then we terminated prematurely,
1514 1521 * rewind to the last entry and this can never be EOF.
1515 1522 */
1516 1523 if (no_space) {
1517 1524 ptr = lastentry_ptr;
1518 1525 eof = FALSE; /* ended encoded prematurely */
1519 1526 } else {
1520 1527 eof = (iseofdir ? TRUE : FALSE);
1521 1528 }
1522 1529
1523 1530 /*
1524 1531 * If we have entries, always return them, otherwise only error
1525 1532 * if we ran out of space.
1526 1533 */
1527 1534 if (nents || !no_space) {
1528 1535 ASSERT(ptr != NULL);
1529 1536 /* encode the BOOLEAN marking no further entries */
1530 1537 IXDR_PUT_U_INT32(ptr, false);
1531 1538 /* encode the BOOLEAN signifying end of directory */
1532 1539 IXDR_PUT_U_INT32(ptr, eof);
1533 1540
1534 1541 resp->data_len = (char *)ptr - (char *)beginning_ptr;
1535 1542 resp->mblk->b_wptr += resp->data_len;
1536 1543 } else {
1537 1544 freeb(mp);
1538 1545 resp->mblk = NULL;
1539 1546 resp->data_len = 0;
1540 1547 *cs->statusp = resp->status = NFS4ERR_TOOSMALL;
1541 1548 }
1542 1549
1543 1550 kmem_free((caddr_t)rddir_data, rddir_data_len);
1544 1551 if (vp)
1545 1552 VN_RELE(vp);
1546 1553 if (owner.utf8string_len != 0)
1547 1554 kmem_free(owner.utf8string_val, owner.utf8string_len);
1548 1555 if (group.utf8string_len != 0)
1549 1556 kmem_free(group.utf8string_val, group.utf8string_len);
1550 1557
1551 1558 out:
1552 1559 DTRACE_NFSV4_2(op__readdir__done, struct compound_state *, cs,
1553 1560 READDIR4res *, resp);
1554 1561 }
|
↓ open down ↓ |
718 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX