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