Print this page
7656 unlinking directory on tmpfs can cause kernel panic
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Rich Lowe <richlowe@richlowe.net>
Reviewed by: Vitaliy Gusev <vgusev@racktopsystems.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/tmpfs/tmp_vnops.c
+++ new/usr/src/uts/common/fs/tmpfs/tmp_vnops.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 2009 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 /*
28 28 * Copyright (c) 2015, Joyent, Inc. All rights reserved.
29 29 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
30 30 * Copyright 2016 RackTop Systems.
31 31 */
32 32
33 33 #include <sys/types.h>
34 34 #include <sys/param.h>
35 35 #include <sys/t_lock.h>
36 36 #include <sys/systm.h>
37 37 #include <sys/sysmacros.h>
38 38 #include <sys/user.h>
39 39 #include <sys/time.h>
40 40 #include <sys/vfs.h>
41 41 #include <sys/vfs_opreg.h>
42 42 #include <sys/vnode.h>
43 43 #include <sys/file.h>
44 44 #include <sys/fcntl.h>
45 45 #include <sys/flock.h>
46 46 #include <sys/kmem.h>
47 47 #include <sys/uio.h>
48 48 #include <sys/errno.h>
49 49 #include <sys/stat.h>
50 50 #include <sys/cred.h>
51 51 #include <sys/dirent.h>
52 52 #include <sys/pathname.h>
53 53 #include <sys/vmsystm.h>
54 54 #include <sys/fs/tmp.h>
55 55 #include <sys/fs/tmpnode.h>
56 56 #include <sys/mman.h>
57 57 #include <vm/hat.h>
58 58 #include <vm/seg_vn.h>
59 59 #include <vm/seg_map.h>
60 60 #include <vm/seg.h>
61 61 #include <vm/anon.h>
62 62 #include <vm/as.h>
63 63 #include <vm/page.h>
64 64 #include <vm/pvn.h>
65 65 #include <sys/cmn_err.h>
66 66 #include <sys/debug.h>
67 67 #include <sys/swap.h>
68 68 #include <sys/buf.h>
69 69 #include <sys/vm.h>
70 70 #include <sys/vtrace.h>
71 71 #include <sys/policy.h>
72 72 #include <fs/fs_subr.h>
73 73
74 74 static int tmp_getapage(struct vnode *, u_offset_t, size_t, uint_t *,
75 75 page_t **, size_t, struct seg *, caddr_t, enum seg_rw, struct cred *);
76 76 static int tmp_putapage(struct vnode *, page_t *, u_offset_t *, size_t *,
77 77 int, struct cred *);
78 78
79 79 /* ARGSUSED1 */
80 80 static int
81 81 tmp_open(struct vnode **vpp, int flag, struct cred *cred, caller_context_t *ct)
82 82 {
83 83 /*
84 84 * swapon to a tmpfs file is not supported so access
85 85 * is denied on open if VISSWAP is set.
86 86 */
87 87 if ((*vpp)->v_flag & VISSWAP)
88 88 return (EINVAL);
89 89 return (0);
90 90 }
91 91
92 92 /* ARGSUSED1 */
93 93 static int
94 94 tmp_close(
95 95 struct vnode *vp,
96 96 int flag,
97 97 int count,
98 98 offset_t offset,
99 99 struct cred *cred,
100 100 caller_context_t *ct)
101 101 {
102 102 cleanlocks(vp, ttoproc(curthread)->p_pid, 0);
103 103 cleanshares(vp, ttoproc(curthread)->p_pid);
104 104 return (0);
105 105 }
106 106
107 107 /*
108 108 * wrtmp does the real work of write requests for tmpfs.
109 109 */
110 110 static int
111 111 wrtmp(
112 112 struct tmount *tm,
113 113 struct tmpnode *tp,
114 114 struct uio *uio,
115 115 struct cred *cr,
116 116 struct caller_context *ct)
117 117 {
118 118 pgcnt_t pageoffset; /* offset in pages */
119 119 ulong_t segmap_offset; /* pagesize byte offset into segmap */
120 120 caddr_t base; /* base of segmap */
121 121 ssize_t bytes; /* bytes to uiomove */
122 122 pfn_t pagenumber; /* offset in pages into tmp file */
123 123 struct vnode *vp;
124 124 int error = 0;
125 125 int pagecreate; /* == 1 if we allocated a page */
126 126 int newpage;
127 127 rlim64_t limit = uio->uio_llimit;
128 128 long oresid = uio->uio_resid;
129 129 timestruc_t now;
130 130
131 131 long tn_size_changed = 0;
132 132 long old_tn_size;
133 133 long new_tn_size;
134 134
135 135 vp = TNTOV(tp);
136 136 ASSERT(vp->v_type == VREG);
137 137
138 138 TRACE_1(TR_FAC_TMPFS, TR_TMPFS_RWTMP_START,
139 139 "tmp_wrtmp_start:vp %p", vp);
140 140
141 141 ASSERT(RW_WRITE_HELD(&tp->tn_contents));
142 142 ASSERT(RW_WRITE_HELD(&tp->tn_rwlock));
143 143
144 144 if (MANDLOCK(vp, tp->tn_mode)) {
145 145 rw_exit(&tp->tn_contents);
146 146 /*
147 147 * tmp_getattr ends up being called by chklock
148 148 */
149 149 error = chklock(vp, FWRITE, uio->uio_loffset, uio->uio_resid,
150 150 uio->uio_fmode, ct);
151 151 rw_enter(&tp->tn_contents, RW_WRITER);
152 152 if (error != 0) {
153 153 TRACE_2(TR_FAC_TMPFS, TR_TMPFS_RWTMP_END,
154 154 "tmp_wrtmp_end:vp %p error %d", vp, error);
155 155 return (error);
156 156 }
157 157 }
158 158
159 159 if (uio->uio_loffset < 0)
160 160 return (EINVAL);
161 161
162 162 if (limit == RLIM64_INFINITY || limit > MAXOFFSET_T)
163 163 limit = MAXOFFSET_T;
164 164
165 165 if (uio->uio_loffset >= limit) {
166 166 proc_t *p = ttoproc(curthread);
167 167
168 168 mutex_enter(&p->p_lock);
169 169 (void) rctl_action(rctlproc_legacy[RLIMIT_FSIZE], p->p_rctls,
170 170 p, RCA_UNSAFE_SIGINFO);
171 171 mutex_exit(&p->p_lock);
172 172 return (EFBIG);
173 173 }
174 174
175 175 if (uio->uio_loffset >= MAXOFF_T) {
176 176 TRACE_2(TR_FAC_TMPFS, TR_TMPFS_RWTMP_END,
177 177 "tmp_wrtmp_end:vp %p error %d", vp, EINVAL);
178 178 return (EFBIG);
179 179 }
180 180
181 181 if (uio->uio_resid == 0) {
182 182 TRACE_2(TR_FAC_TMPFS, TR_TMPFS_RWTMP_END,
183 183 "tmp_wrtmp_end:vp %p error %d", vp, 0);
184 184 return (0);
185 185 }
186 186
187 187 if (limit > MAXOFF_T)
188 188 limit = MAXOFF_T;
189 189
190 190 do {
191 191 long offset;
192 192 long delta;
193 193
194 194 offset = (long)uio->uio_offset;
195 195 pageoffset = offset & PAGEOFFSET;
196 196 /*
197 197 * A maximum of PAGESIZE bytes of data is transferred
198 198 * each pass through this loop
199 199 */
200 200 bytes = MIN(PAGESIZE - pageoffset, uio->uio_resid);
201 201
202 202 if (offset + bytes >= limit) {
203 203 if (offset >= limit) {
204 204 error = EFBIG;
205 205 goto out;
206 206 }
207 207 bytes = limit - offset;
208 208 }
209 209 pagenumber = btop(offset);
210 210
211 211 /*
212 212 * delta is the amount of anonymous memory
213 213 * to reserve for the file.
214 214 * We always reserve in pagesize increments so
215 215 * unless we're extending the file into a new page,
216 216 * we don't need to call tmp_resv.
217 217 */
218 218 delta = offset + bytes -
219 219 P2ROUNDUP_TYPED(tp->tn_size, PAGESIZE, u_offset_t);
220 220 if (delta > 0) {
221 221 pagecreate = 1;
222 222 if (tmp_resv(tm, tp, delta, pagecreate)) {
223 223 /*
224 224 * Log file system full in the zone that owns
225 225 * the tmpfs mount, as well as in the global
226 226 * zone if necessary.
227 227 */
228 228 zcmn_err(tm->tm_vfsp->vfs_zone->zone_id,
229 229 CE_WARN, "%s: File system full, "
230 230 "swap space limit exceeded",
231 231 tm->tm_mntpath);
232 232
233 233 if (tm->tm_vfsp->vfs_zone->zone_id !=
234 234 GLOBAL_ZONEID) {
235 235
236 236 vfs_t *vfs = tm->tm_vfsp;
237 237
238 238 zcmn_err(GLOBAL_ZONEID,
239 239 CE_WARN, "%s: File system full, "
240 240 "swap space limit exceeded",
241 241 vfs->vfs_vnodecovered->v_path);
242 242 }
243 243 error = ENOSPC;
244 244 break;
245 245 }
246 246 tmpnode_growmap(tp, (ulong_t)offset + bytes);
247 247 }
248 248 /* grow the file to the new length */
249 249 if (offset + bytes > tp->tn_size) {
250 250 tn_size_changed = 1;
251 251 old_tn_size = tp->tn_size;
252 252 /*
253 253 * Postpone updating tp->tn_size until uiomove() is
254 254 * done.
255 255 */
256 256 new_tn_size = offset + bytes;
257 257 }
258 258 if (bytes == PAGESIZE) {
259 259 /*
260 260 * Writing whole page so reading from disk
261 261 * is a waste
262 262 */
263 263 pagecreate = 1;
264 264 } else {
265 265 pagecreate = 0;
266 266 }
267 267 /*
268 268 * If writing past EOF or filling in a hole
269 269 * we need to allocate an anon slot.
270 270 */
271 271 if (anon_get_ptr(tp->tn_anon, pagenumber) == NULL) {
272 272 (void) anon_set_ptr(tp->tn_anon, pagenumber,
273 273 anon_alloc(vp, ptob(pagenumber)), ANON_SLEEP);
274 274 pagecreate = 1;
275 275 tp->tn_nblocks++;
276 276 }
277 277
278 278 /*
279 279 * We have to drop the contents lock to allow the VM
280 280 * system to reacquire it in tmp_getpage()
281 281 */
282 282 rw_exit(&tp->tn_contents);
283 283
284 284 /*
285 285 * Touch the page and fault it in if it is not in core
286 286 * before segmap_getmapflt or vpm_data_copy can lock it.
287 287 * This is to avoid the deadlock if the buffer is mapped
288 288 * to the same file through mmap which we want to write.
289 289 */
290 290 uio_prefaultpages((long)bytes, uio);
291 291
292 292 newpage = 0;
293 293 if (vpm_enable) {
294 294 /*
295 295 * Copy data. If new pages are created, part of
296 296 * the page that is not written will be initizliazed
297 297 * with zeros.
298 298 */
299 299 error = vpm_data_copy(vp, offset, bytes, uio,
300 300 !pagecreate, &newpage, 1, S_WRITE);
301 301 } else {
302 302 /* Get offset within the segmap mapping */
303 303 segmap_offset = (offset & PAGEMASK) & MAXBOFFSET;
304 304 base = segmap_getmapflt(segkmap, vp,
305 305 (offset & MAXBMASK), PAGESIZE, !pagecreate,
306 306 S_WRITE);
307 307 }
308 308
309 309
310 310 if (!vpm_enable && pagecreate) {
311 311 /*
312 312 * segmap_pagecreate() returns 1 if it calls
313 313 * page_create_va() to allocate any pages.
314 314 */
315 315 newpage = segmap_pagecreate(segkmap,
316 316 base + segmap_offset, (size_t)PAGESIZE, 0);
317 317 /*
318 318 * Clear from the beginning of the page to the starting
319 319 * offset of the data.
320 320 */
321 321 if (pageoffset != 0)
322 322 (void) kzero(base + segmap_offset,
323 323 (size_t)pageoffset);
324 324 }
325 325
326 326 if (!vpm_enable) {
327 327 error = uiomove(base + segmap_offset + pageoffset,
328 328 (long)bytes, UIO_WRITE, uio);
329 329 }
330 330
331 331 if (!vpm_enable && pagecreate &&
332 332 uio->uio_offset < P2ROUNDUP(offset + bytes, PAGESIZE)) {
333 333 long zoffset; /* zero from offset into page */
334 334 /*
335 335 * We created pages w/o initializing them completely,
336 336 * thus we need to zero the part that wasn't set up.
337 337 * This happens on most EOF write cases and if
338 338 * we had some sort of error during the uiomove.
339 339 */
340 340 long nmoved;
341 341
342 342 nmoved = uio->uio_offset - offset;
343 343 ASSERT((nmoved + pageoffset) <= PAGESIZE);
344 344
345 345 /*
346 346 * Zero from the end of data in the page to the
347 347 * end of the page.
348 348 */
349 349 if ((zoffset = pageoffset + nmoved) < PAGESIZE)
350 350 (void) kzero(base + segmap_offset + zoffset,
351 351 (size_t)PAGESIZE - zoffset);
352 352 }
353 353
354 354 /*
355 355 * Unlock the pages which have been allocated by
356 356 * page_create_va() in segmap_pagecreate()
357 357 */
358 358 if (!vpm_enable && newpage) {
359 359 segmap_pageunlock(segkmap, base + segmap_offset,
360 360 (size_t)PAGESIZE, S_WRITE);
361 361 }
362 362
363 363 if (error) {
364 364 /*
365 365 * If we failed on a write, we must
366 366 * be sure to invalidate any pages that may have
367 367 * been allocated.
368 368 */
369 369 if (vpm_enable) {
370 370 (void) vpm_sync_pages(vp, offset, PAGESIZE,
371 371 SM_INVAL);
372 372 } else {
373 373 (void) segmap_release(segkmap, base, SM_INVAL);
374 374 }
375 375 } else {
376 376 if (vpm_enable) {
377 377 error = vpm_sync_pages(vp, offset, PAGESIZE,
378 378 0);
379 379 } else {
380 380 error = segmap_release(segkmap, base, 0);
381 381 }
382 382 }
383 383
384 384 /*
385 385 * Re-acquire contents lock.
386 386 */
387 387 rw_enter(&tp->tn_contents, RW_WRITER);
388 388
389 389 /*
390 390 * Update tn_size.
391 391 */
392 392 if (tn_size_changed)
393 393 tp->tn_size = new_tn_size;
394 394
395 395 /*
396 396 * If the uiomove failed, fix up tn_size.
397 397 */
398 398 if (error) {
399 399 if (tn_size_changed) {
400 400 /*
401 401 * The uiomove failed, and we
402 402 * allocated blocks,so get rid
403 403 * of them.
404 404 */
405 405 (void) tmpnode_trunc(tm, tp,
406 406 (ulong_t)old_tn_size);
407 407 }
408 408 } else {
409 409 /*
410 410 * XXX - Can this be out of the loop?
411 411 */
412 412 if ((tp->tn_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) &&
413 413 (tp->tn_mode & (S_ISUID | S_ISGID)) &&
414 414 secpolicy_vnode_setid_retain(cr,
415 415 (tp->tn_mode & S_ISUID) != 0 && tp->tn_uid == 0)) {
416 416 /*
417 417 * Clear Set-UID & Set-GID bits on
418 418 * successful write if not privileged
419 419 * and at least one of the execute bits
420 420 * is set. If we always clear Set-GID,
421 421 * mandatory file and record locking is
422 422 * unuseable.
423 423 */
424 424 tp->tn_mode &= ~(S_ISUID | S_ISGID);
425 425 }
426 426 gethrestime(&now);
427 427 tp->tn_mtime = now;
428 428 tp->tn_ctime = now;
429 429 }
430 430 } while (error == 0 && uio->uio_resid > 0 && bytes != 0);
431 431
432 432 out:
433 433 /*
434 434 * If we've already done a partial-write, terminate
435 435 * the write but return no error.
436 436 */
437 437 if (oresid != uio->uio_resid)
438 438 error = 0;
439 439 TRACE_2(TR_FAC_TMPFS, TR_TMPFS_RWTMP_END,
440 440 "tmp_wrtmp_end:vp %p error %d", vp, error);
441 441 return (error);
442 442 }
443 443
444 444 /*
445 445 * rdtmp does the real work of read requests for tmpfs.
446 446 */
447 447 static int
448 448 rdtmp(
449 449 struct tmount *tm,
450 450 struct tmpnode *tp,
451 451 struct uio *uio,
452 452 struct caller_context *ct)
453 453 {
454 454 ulong_t pageoffset; /* offset in tmpfs file (uio_offset) */
455 455 ulong_t segmap_offset; /* pagesize byte offset into segmap */
456 456 caddr_t base; /* base of segmap */
457 457 ssize_t bytes; /* bytes to uiomove */
458 458 struct vnode *vp;
459 459 int error;
460 460 long oresid = uio->uio_resid;
461 461
462 462 #if defined(lint)
463 463 tm = tm;
464 464 #endif
465 465 vp = TNTOV(tp);
466 466
467 467 TRACE_1(TR_FAC_TMPFS, TR_TMPFS_RWTMP_START, "tmp_rdtmp_start:vp %p",
468 468 vp);
469 469
470 470 ASSERT(RW_LOCK_HELD(&tp->tn_contents));
471 471
472 472 if (MANDLOCK(vp, tp->tn_mode)) {
473 473 rw_exit(&tp->tn_contents);
474 474 /*
475 475 * tmp_getattr ends up being called by chklock
476 476 */
477 477 error = chklock(vp, FREAD, uio->uio_loffset, uio->uio_resid,
478 478 uio->uio_fmode, ct);
479 479 rw_enter(&tp->tn_contents, RW_READER);
480 480 if (error != 0) {
481 481 TRACE_2(TR_FAC_TMPFS, TR_TMPFS_RWTMP_END,
482 482 "tmp_rdtmp_end:vp %p error %d", vp, error);
483 483 return (error);
484 484 }
485 485 }
486 486 ASSERT(tp->tn_type == VREG);
487 487
488 488 if (uio->uio_loffset >= MAXOFF_T) {
489 489 TRACE_2(TR_FAC_TMPFS, TR_TMPFS_RWTMP_END,
490 490 "tmp_rdtmp_end:vp %p error %d", vp, EINVAL);
491 491 return (0);
492 492 }
493 493 if (uio->uio_loffset < 0)
494 494 return (EINVAL);
495 495 if (uio->uio_resid == 0) {
496 496 TRACE_2(TR_FAC_TMPFS, TR_TMPFS_RWTMP_END,
497 497 "tmp_rdtmp_end:vp %p error %d", vp, 0);
498 498 return (0);
499 499 }
500 500
501 501 vp = TNTOV(tp);
502 502
503 503 do {
504 504 long diff;
505 505 long offset;
506 506
507 507 offset = uio->uio_offset;
508 508 pageoffset = offset & PAGEOFFSET;
509 509 bytes = MIN(PAGESIZE - pageoffset, uio->uio_resid);
510 510
511 511 diff = tp->tn_size - offset;
512 512
513 513 if (diff <= 0) {
514 514 error = 0;
515 515 goto out;
516 516 }
517 517 if (diff < bytes)
518 518 bytes = diff;
519 519
520 520 /*
521 521 * We have to drop the contents lock to allow the VM system
522 522 * to reacquire it in tmp_getpage() should the uiomove cause a
523 523 * pagefault.
524 524 */
525 525 rw_exit(&tp->tn_contents);
526 526
527 527 if (vpm_enable) {
528 528 /*
529 529 * Copy data.
530 530 */
531 531 error = vpm_data_copy(vp, offset, bytes, uio, 1, NULL,
532 532 0, S_READ);
533 533 } else {
534 534 segmap_offset = (offset & PAGEMASK) & MAXBOFFSET;
535 535 base = segmap_getmapflt(segkmap, vp, offset & MAXBMASK,
536 536 bytes, 1, S_READ);
537 537
538 538 error = uiomove(base + segmap_offset + pageoffset,
539 539 (long)bytes, UIO_READ, uio);
540 540 }
541 541
542 542 if (error) {
543 543 if (vpm_enable) {
544 544 (void) vpm_sync_pages(vp, offset, PAGESIZE, 0);
545 545 } else {
546 546 (void) segmap_release(segkmap, base, 0);
547 547 }
548 548 } else {
549 549 if (vpm_enable) {
550 550 error = vpm_sync_pages(vp, offset, PAGESIZE,
551 551 0);
552 552 } else {
553 553 error = segmap_release(segkmap, base, 0);
554 554 }
555 555 }
556 556
557 557 /*
558 558 * Re-acquire contents lock.
559 559 */
560 560 rw_enter(&tp->tn_contents, RW_READER);
561 561
562 562 } while (error == 0 && uio->uio_resid > 0);
563 563
564 564 out:
565 565 gethrestime(&tp->tn_atime);
566 566
567 567 /*
568 568 * If we've already done a partial read, terminate
569 569 * the read but return no error.
570 570 */
571 571 if (oresid != uio->uio_resid)
572 572 error = 0;
573 573
574 574 TRACE_2(TR_FAC_TMPFS, TR_TMPFS_RWTMP_END,
575 575 "tmp_rdtmp_end:vp %x error %d", vp, error);
576 576 return (error);
577 577 }
578 578
579 579 /* ARGSUSED2 */
580 580 static int
581 581 tmp_read(struct vnode *vp, struct uio *uiop, int ioflag, cred_t *cred,
582 582 struct caller_context *ct)
583 583 {
584 584 struct tmpnode *tp = (struct tmpnode *)VTOTN(vp);
585 585 struct tmount *tm = (struct tmount *)VTOTM(vp);
586 586 int error;
587 587
588 588 /*
589 589 * We don't currently support reading non-regular files
590 590 */
591 591 if (vp->v_type == VDIR)
592 592 return (EISDIR);
593 593 if (vp->v_type != VREG)
594 594 return (EINVAL);
595 595 /*
596 596 * tmp_rwlock should have already been called from layers above
597 597 */
598 598 ASSERT(RW_READ_HELD(&tp->tn_rwlock));
599 599
600 600 rw_enter(&tp->tn_contents, RW_READER);
601 601
602 602 error = rdtmp(tm, tp, uiop, ct);
603 603
604 604 rw_exit(&tp->tn_contents);
605 605
606 606 return (error);
607 607 }
608 608
609 609 static int
610 610 tmp_write(struct vnode *vp, struct uio *uiop, int ioflag, struct cred *cred,
611 611 struct caller_context *ct)
612 612 {
613 613 struct tmpnode *tp = (struct tmpnode *)VTOTN(vp);
614 614 struct tmount *tm = (struct tmount *)VTOTM(vp);
615 615 int error;
616 616
617 617 /*
618 618 * We don't currently support writing to non-regular files
619 619 */
620 620 if (vp->v_type != VREG)
621 621 return (EINVAL); /* XXX EISDIR? */
622 622
623 623 /*
624 624 * tmp_rwlock should have already been called from layers above
625 625 */
626 626 ASSERT(RW_WRITE_HELD(&tp->tn_rwlock));
627 627
628 628 rw_enter(&tp->tn_contents, RW_WRITER);
629 629
630 630 if (ioflag & FAPPEND) {
631 631 /*
632 632 * In append mode start at end of file.
633 633 */
634 634 uiop->uio_loffset = tp->tn_size;
635 635 }
636 636
637 637 error = wrtmp(tm, tp, uiop, cred, ct);
638 638
639 639 rw_exit(&tp->tn_contents);
640 640
641 641 return (error);
642 642 }
643 643
644 644 /* ARGSUSED */
645 645 static int
646 646 tmp_ioctl(
647 647 struct vnode *vp,
648 648 int com,
649 649 intptr_t data,
650 650 int flag,
651 651 struct cred *cred,
652 652 int *rvalp,
653 653 caller_context_t *ct)
654 654 {
655 655 return (ENOTTY);
656 656 }
657 657
658 658 /* ARGSUSED2 */
659 659 static int
660 660 tmp_getattr(
661 661 struct vnode *vp,
662 662 struct vattr *vap,
663 663 int flags,
664 664 struct cred *cred,
665 665 caller_context_t *ct)
666 666 {
667 667 struct tmpnode *tp = (struct tmpnode *)VTOTN(vp);
668 668 struct vnode *mvp;
669 669 struct vattr va;
670 670 int attrs = 1;
671 671
672 672 /*
673 673 * A special case to handle the root tnode on a diskless nfs
674 674 * client who may have had its uid and gid inherited
675 675 * from an nfs vnode with nobody ownership. Likely the
676 676 * root filesystem. After nfs is fully functional the uid/gid
677 677 * may be mapable so ask again.
678 678 * vfsp can't get unmounted because we hold vp.
679 679 */
680 680 if (vp->v_flag & VROOT &&
681 681 (mvp = vp->v_vfsp->vfs_vnodecovered) != NULL) {
682 682 mutex_enter(&tp->tn_tlock);
683 683 if (tp->tn_uid == UID_NOBODY || tp->tn_gid == GID_NOBODY) {
684 684 mutex_exit(&tp->tn_tlock);
685 685 bzero(&va, sizeof (struct vattr));
686 686 va.va_mask = AT_UID|AT_GID;
687 687 attrs = VOP_GETATTR(mvp, &va, 0, cred, ct);
688 688 } else {
689 689 mutex_exit(&tp->tn_tlock);
690 690 }
691 691 }
692 692 mutex_enter(&tp->tn_tlock);
693 693 if (attrs == 0) {
694 694 tp->tn_uid = va.va_uid;
695 695 tp->tn_gid = va.va_gid;
696 696 }
697 697 vap->va_type = vp->v_type;
698 698 vap->va_mode = tp->tn_mode & MODEMASK;
699 699 vap->va_uid = tp->tn_uid;
700 700 vap->va_gid = tp->tn_gid;
701 701 vap->va_fsid = tp->tn_fsid;
702 702 vap->va_nodeid = (ino64_t)tp->tn_nodeid;
703 703 vap->va_nlink = tp->tn_nlink;
704 704 vap->va_size = (u_offset_t)tp->tn_size;
705 705 vap->va_atime = tp->tn_atime;
706 706 vap->va_mtime = tp->tn_mtime;
707 707 vap->va_ctime = tp->tn_ctime;
708 708 vap->va_blksize = PAGESIZE;
709 709 vap->va_rdev = tp->tn_rdev;
710 710 vap->va_seq = tp->tn_seq;
711 711
712 712 /*
713 713 * XXX Holes are not taken into account. We could take the time to
714 714 * run through the anon array looking for allocated slots...
715 715 */
716 716 vap->va_nblocks = (fsblkcnt64_t)btodb(ptob(btopr(vap->va_size)));
717 717 mutex_exit(&tp->tn_tlock);
718 718 return (0);
719 719 }
720 720
721 721 /*ARGSUSED4*/
722 722 static int
723 723 tmp_setattr(
724 724 struct vnode *vp,
725 725 struct vattr *vap,
726 726 int flags,
727 727 struct cred *cred,
728 728 caller_context_t *ct)
729 729 {
730 730 struct tmount *tm = (struct tmount *)VTOTM(vp);
731 731 struct tmpnode *tp = (struct tmpnode *)VTOTN(vp);
732 732 int error = 0;
733 733 struct vattr *get;
734 734 long mask;
735 735
736 736 /*
737 737 * Cannot set these attributes
738 738 */
739 739 if ((vap->va_mask & AT_NOSET) || (vap->va_mask & AT_XVATTR))
740 740 return (EINVAL);
741 741
742 742 mutex_enter(&tp->tn_tlock);
743 743
744 744 get = &tp->tn_attr;
745 745 /*
746 746 * Change file access modes. Must be owner or have sufficient
747 747 * privileges.
748 748 */
749 749 error = secpolicy_vnode_setattr(cred, vp, vap, get, flags, tmp_taccess,
750 750 tp);
751 751
752 752 if (error)
753 753 goto out;
754 754
755 755 mask = vap->va_mask;
756 756
757 757 if (mask & AT_MODE) {
758 758 get->va_mode &= S_IFMT;
759 759 get->va_mode |= vap->va_mode & ~S_IFMT;
760 760 }
761 761
762 762 if (mask & AT_UID)
763 763 get->va_uid = vap->va_uid;
764 764 if (mask & AT_GID)
765 765 get->va_gid = vap->va_gid;
766 766 if (mask & AT_ATIME)
767 767 get->va_atime = vap->va_atime;
768 768 if (mask & AT_MTIME)
769 769 get->va_mtime = vap->va_mtime;
770 770
771 771 if (mask & (AT_UID | AT_GID | AT_MODE | AT_MTIME))
772 772 gethrestime(&tp->tn_ctime);
773 773
774 774 if (mask & AT_SIZE) {
775 775 ASSERT(vp->v_type != VDIR);
776 776
777 777 /* Don't support large files. */
778 778 if (vap->va_size > MAXOFF_T) {
779 779 error = EFBIG;
780 780 goto out;
781 781 }
782 782 mutex_exit(&tp->tn_tlock);
783 783
784 784 rw_enter(&tp->tn_rwlock, RW_WRITER);
785 785 rw_enter(&tp->tn_contents, RW_WRITER);
786 786 error = tmpnode_trunc(tm, tp, (ulong_t)vap->va_size);
787 787 rw_exit(&tp->tn_contents);
788 788 rw_exit(&tp->tn_rwlock);
789 789
790 790 if (error == 0 && vap->va_size == 0)
791 791 vnevent_truncate(vp, ct);
792 792
793 793 goto out1;
794 794 }
795 795 out:
796 796 mutex_exit(&tp->tn_tlock);
797 797 out1:
798 798 return (error);
799 799 }
800 800
801 801 /* ARGSUSED2 */
802 802 static int
803 803 tmp_access(
804 804 struct vnode *vp,
805 805 int mode,
806 806 int flags,
807 807 struct cred *cred,
808 808 caller_context_t *ct)
809 809 {
810 810 struct tmpnode *tp = (struct tmpnode *)VTOTN(vp);
811 811 int error;
812 812
813 813 mutex_enter(&tp->tn_tlock);
814 814 error = tmp_taccess(tp, mode, cred);
815 815 mutex_exit(&tp->tn_tlock);
816 816 return (error);
817 817 }
818 818
819 819 /* ARGSUSED3 */
820 820 static int
821 821 tmp_lookup(
822 822 struct vnode *dvp,
823 823 char *nm,
824 824 struct vnode **vpp,
825 825 struct pathname *pnp,
826 826 int flags,
827 827 struct vnode *rdir,
828 828 struct cred *cred,
829 829 caller_context_t *ct,
830 830 int *direntflags,
831 831 pathname_t *realpnp)
832 832 {
833 833 struct tmpnode *tp = (struct tmpnode *)VTOTN(dvp);
834 834 struct tmpnode *ntp = NULL;
835 835 int error;
836 836
837 837
838 838 /* allow cd into @ dir */
839 839 if (flags & LOOKUP_XATTR) {
840 840 struct tmpnode *xdp;
841 841 struct tmount *tm;
842 842
843 843 /*
844 844 * don't allow attributes if not mounted XATTR support
845 845 */
846 846 if (!(dvp->v_vfsp->vfs_flag & VFS_XATTR))
847 847 return (EINVAL);
848 848
849 849 if (tp->tn_flags & ISXATTR)
850 850 /* No attributes on attributes */
851 851 return (EINVAL);
852 852
853 853 rw_enter(&tp->tn_rwlock, RW_WRITER);
854 854 if (tp->tn_xattrdp == NULL) {
855 855 if (!(flags & CREATE_XATTR_DIR)) {
856 856 rw_exit(&tp->tn_rwlock);
857 857 return (ENOENT);
858 858 }
859 859
860 860 /*
861 861 * No attribute directory exists for this
862 862 * node - create the attr dir as a side effect
863 863 * of this lookup.
864 864 */
865 865
866 866 /*
867 867 * Make sure we have adequate permission...
868 868 */
869 869
870 870 if ((error = tmp_taccess(tp, VWRITE, cred)) != 0) {
871 871 rw_exit(&tp->tn_rwlock);
872 872 return (error);
873 873 }
874 874
875 875 xdp = tmp_memalloc(sizeof (struct tmpnode),
876 876 TMP_MUSTHAVE);
877 877 tm = VTOTM(dvp);
878 878 tmpnode_init(tm, xdp, &tp->tn_attr, NULL);
879 879 /*
880 880 * Fix-up fields unique to attribute directories.
881 881 */
882 882 xdp->tn_flags = ISXATTR;
883 883 xdp->tn_type = VDIR;
884 884 if (tp->tn_type == VDIR) {
885 885 xdp->tn_mode = tp->tn_attr.va_mode;
886 886 } else {
887 887 xdp->tn_mode = 0700;
888 888 if (tp->tn_attr.va_mode & 0040)
889 889 xdp->tn_mode |= 0750;
890 890 if (tp->tn_attr.va_mode & 0004)
891 891 xdp->tn_mode |= 0705;
892 892 }
893 893 xdp->tn_vnode->v_type = VDIR;
894 894 xdp->tn_vnode->v_flag |= V_XATTRDIR;
895 895 tdirinit(tp, xdp);
896 896 tp->tn_xattrdp = xdp;
897 897 } else {
898 898 VN_HOLD(tp->tn_xattrdp->tn_vnode);
899 899 }
900 900 *vpp = TNTOV(tp->tn_xattrdp);
901 901 rw_exit(&tp->tn_rwlock);
902 902 return (0);
903 903 }
904 904
905 905 /*
906 906 * Null component name is a synonym for directory being searched.
907 907 */
908 908 if (*nm == '\0') {
909 909 VN_HOLD(dvp);
910 910 *vpp = dvp;
911 911 return (0);
912 912 }
913 913 ASSERT(tp);
914 914
915 915 error = tdirlookup(tp, nm, &ntp, cred);
916 916
917 917 if (error == 0) {
918 918 ASSERT(ntp);
919 919 *vpp = TNTOV(ntp);
920 920 /*
921 921 * If vnode is a device return special vnode instead
922 922 */
923 923 if (IS_DEVVP(*vpp)) {
924 924 struct vnode *newvp;
925 925
926 926 newvp = specvp(*vpp, (*vpp)->v_rdev, (*vpp)->v_type,
927 927 cred);
928 928 VN_RELE(*vpp);
929 929 *vpp = newvp;
930 930 }
931 931 }
932 932 TRACE_4(TR_FAC_TMPFS, TR_TMPFS_LOOKUP,
933 933 "tmpfs lookup:vp %p name %s vpp %p error %d",
934 934 dvp, nm, vpp, error);
935 935 return (error);
936 936 }
937 937
938 938 /*ARGSUSED7*/
939 939 static int
940 940 tmp_create(
941 941 struct vnode *dvp,
942 942 char *nm,
943 943 struct vattr *vap,
944 944 enum vcexcl exclusive,
945 945 int mode,
946 946 struct vnode **vpp,
947 947 struct cred *cred,
948 948 int flag,
949 949 caller_context_t *ct,
950 950 vsecattr_t *vsecp)
951 951 {
952 952 struct tmpnode *parent;
953 953 struct tmount *tm;
954 954 struct tmpnode *self;
955 955 int error;
956 956 struct tmpnode *oldtp;
957 957
958 958 again:
959 959 parent = (struct tmpnode *)VTOTN(dvp);
960 960 tm = (struct tmount *)VTOTM(dvp);
961 961 self = NULL;
962 962 error = 0;
963 963 oldtp = NULL;
964 964
965 965 /* device files not allowed in ext. attr dirs */
966 966 if ((parent->tn_flags & ISXATTR) &&
967 967 (vap->va_type == VBLK || vap->va_type == VCHR ||
968 968 vap->va_type == VFIFO || vap->va_type == VDOOR ||
969 969 vap->va_type == VSOCK || vap->va_type == VPORT))
970 970 return (EINVAL);
971 971
972 972 if (vap->va_type == VREG && (vap->va_mode & VSVTX)) {
973 973 /* Must be privileged to set sticky bit */
974 974 if (secpolicy_vnode_stky_modify(cred))
975 975 vap->va_mode &= ~VSVTX;
976 976 } else if (vap->va_type == VNON) {
977 977 return (EINVAL);
978 978 }
979 979
980 980 /*
981 981 * Null component name is a synonym for directory being searched.
982 982 */
983 983 if (*nm == '\0') {
984 984 VN_HOLD(dvp);
985 985 oldtp = parent;
986 986 } else {
987 987 error = tdirlookup(parent, nm, &oldtp, cred);
988 988 }
989 989
990 990 if (error == 0) { /* name found */
991 991 boolean_t trunc = B_FALSE;
992 992
993 993 ASSERT(oldtp);
994 994
995 995 rw_enter(&oldtp->tn_rwlock, RW_WRITER);
996 996
997 997 /*
998 998 * if create/read-only an existing
999 999 * directory, allow it
1000 1000 */
1001 1001 if (exclusive == EXCL)
1002 1002 error = EEXIST;
1003 1003 else if ((oldtp->tn_type == VDIR) && (mode & VWRITE))
1004 1004 error = EISDIR;
1005 1005 else {
1006 1006 error = tmp_taccess(oldtp, mode, cred);
1007 1007 }
1008 1008
1009 1009 if (error) {
1010 1010 rw_exit(&oldtp->tn_rwlock);
1011 1011 tmpnode_rele(oldtp);
1012 1012 return (error);
1013 1013 }
1014 1014 *vpp = TNTOV(oldtp);
1015 1015 if ((*vpp)->v_type == VREG && (vap->va_mask & AT_SIZE) &&
1016 1016 vap->va_size == 0) {
1017 1017 rw_enter(&oldtp->tn_contents, RW_WRITER);
1018 1018 (void) tmpnode_trunc(tm, oldtp, 0);
1019 1019 rw_exit(&oldtp->tn_contents);
1020 1020 trunc = B_TRUE;
1021 1021 }
1022 1022 rw_exit(&oldtp->tn_rwlock);
1023 1023 if (IS_DEVVP(*vpp)) {
1024 1024 struct vnode *newvp;
1025 1025
1026 1026 newvp = specvp(*vpp, (*vpp)->v_rdev, (*vpp)->v_type,
1027 1027 cred);
1028 1028 VN_RELE(*vpp);
1029 1029 if (newvp == NULL) {
1030 1030 return (ENOSYS);
1031 1031 }
1032 1032 *vpp = newvp;
1033 1033 }
1034 1034
1035 1035 if (trunc)
1036 1036 vnevent_create(*vpp, ct);
1037 1037
1038 1038 return (0);
1039 1039 }
1040 1040
1041 1041 if (error != ENOENT)
1042 1042 return (error);
1043 1043
1044 1044 rw_enter(&parent->tn_rwlock, RW_WRITER);
1045 1045 error = tdirenter(tm, parent, nm, DE_CREATE,
1046 1046 (struct tmpnode *)NULL, (struct tmpnode *)NULL,
1047 1047 vap, &self, cred, ct);
1048 1048 rw_exit(&parent->tn_rwlock);
1049 1049
1050 1050 if (error) {
1051 1051 if (self)
1052 1052 tmpnode_rele(self);
1053 1053
1054 1054 if (error == EEXIST) {
1055 1055 /*
1056 1056 * This means that the file was created sometime
1057 1057 * after we checked and did not find it and when
1058 1058 * we went to create it.
1059 1059 * Since creat() is supposed to truncate a file
1060 1060 * that already exits go back to the begining
1061 1061 * of the function. This time we will find it
1062 1062 * and go down the tmp_trunc() path
1063 1063 */
1064 1064 goto again;
1065 1065 }
1066 1066 return (error);
1067 1067 }
1068 1068
1069 1069 *vpp = TNTOV(self);
1070 1070
1071 1071 if (!error && IS_DEVVP(*vpp)) {
1072 1072 struct vnode *newvp;
1073 1073
1074 1074 newvp = specvp(*vpp, (*vpp)->v_rdev, (*vpp)->v_type, cred);
1075 1075 VN_RELE(*vpp);
1076 1076 if (newvp == NULL)
1077 1077 return (ENOSYS);
1078 1078 *vpp = newvp;
1079 1079 }
1080 1080 TRACE_3(TR_FAC_TMPFS, TR_TMPFS_CREATE,
1081 1081 "tmpfs create:dvp %p nm %s vpp %p", dvp, nm, vpp);
1082 1082 return (0);
1083 1083 }
1084 1084
1085 1085 /* ARGSUSED3 */
1086 1086 static int
1087 1087 tmp_remove(
1088 1088 struct vnode *dvp,
1089 1089 char *nm,
1090 1090 struct cred *cred,
1091 1091 caller_context_t *ct,
1092 1092 int flags)
1093 1093 {
1094 1094 struct tmpnode *parent = (struct tmpnode *)VTOTN(dvp);
1095 1095 int error;
↓ open down ↓ |
1095 lines elided |
↑ open up ↑ |
1096 1096 struct tmpnode *tp = NULL;
1097 1097
1098 1098 error = tdirlookup(parent, nm, &tp, cred);
1099 1099 if (error)
1100 1100 return (error);
1101 1101
1102 1102 ASSERT(tp);
1103 1103 rw_enter(&parent->tn_rwlock, RW_WRITER);
1104 1104 rw_enter(&tp->tn_rwlock, RW_WRITER);
1105 1105
1106 - if (tp->tn_type != VDIR ||
1107 - (error = secpolicy_fs_linkdir(cred, dvp->v_vfsp)) == 0)
1108 - error = tdirdelete(parent, tp, nm, tp->tn_type == VDIR ?
1109 - DR_RMDIR : DR_REMOVE, cred);
1106 + error = tp->tn_type == VDIR ? EPERM :
1107 + tdirdelete(parent, tp, nm, DR_REMOVE, cred);
1110 1108
1111 1109 rw_exit(&tp->tn_rwlock);
1112 1110 rw_exit(&parent->tn_rwlock);
1113 1111 vnevent_remove(TNTOV(tp), dvp, nm, ct);
1114 1112 tmpnode_rele(tp);
1115 1113
1116 1114 TRACE_3(TR_FAC_TMPFS, TR_TMPFS_REMOVE,
1117 1115 "tmpfs remove:dvp %p nm %s error %d", dvp, nm, error);
1118 1116 return (error);
1119 1117 }
1120 1118
1121 1119 /* ARGSUSED4 */
1122 1120 static int
1123 1121 tmp_link(
1124 1122 struct vnode *dvp,
1125 1123 struct vnode *srcvp,
1126 1124 char *tnm,
1127 1125 struct cred *cred,
1128 1126 caller_context_t *ct,
1129 1127 int flags)
1130 1128 {
1131 1129 struct tmpnode *parent;
1132 1130 struct tmpnode *from;
1133 1131 struct tmount *tm = (struct tmount *)VTOTM(dvp);
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
1134 1132 int error;
1135 1133 struct tmpnode *found = NULL;
1136 1134 struct vnode *realvp;
1137 1135
1138 1136 if (VOP_REALVP(srcvp, &realvp, ct) == 0)
1139 1137 srcvp = realvp;
1140 1138
1141 1139 parent = (struct tmpnode *)VTOTN(dvp);
1142 1140 from = (struct tmpnode *)VTOTN(srcvp);
1143 1141
1144 - if ((srcvp->v_type == VDIR &&
1145 - secpolicy_fs_linkdir(cred, dvp->v_vfsp)) ||
1142 + if (srcvp->v_type == VDIR ||
1146 1143 (from->tn_uid != crgetuid(cred) && secpolicy_basic_link(cred)))
1147 1144 return (EPERM);
1148 1145
1149 1146 /*
1150 1147 * Make sure link for extended attributes is valid
1151 1148 * We only support hard linking of xattr's in xattrdir to an xattrdir
1152 1149 */
1153 1150 if ((from->tn_flags & ISXATTR) != (parent->tn_flags & ISXATTR))
1154 1151 return (EINVAL);
1155 1152
1156 1153 error = tdirlookup(parent, tnm, &found, cred);
1157 1154 if (error == 0) {
1158 1155 ASSERT(found);
1159 1156 tmpnode_rele(found);
1160 1157 return (EEXIST);
1161 1158 }
1162 1159
1163 1160 if (error != ENOENT)
1164 1161 return (error);
1165 1162
1166 1163 rw_enter(&parent->tn_rwlock, RW_WRITER);
1167 1164 error = tdirenter(tm, parent, tnm, DE_LINK, (struct tmpnode *)NULL,
1168 1165 from, NULL, (struct tmpnode **)NULL, cred, ct);
1169 1166 rw_exit(&parent->tn_rwlock);
1170 1167 if (error == 0) {
1171 1168 vnevent_link(srcvp, ct);
1172 1169 }
1173 1170 return (error);
1174 1171 }
1175 1172
1176 1173 /* ARGSUSED5 */
1177 1174 static int
1178 1175 tmp_rename(
1179 1176 struct vnode *odvp, /* source parent vnode */
1180 1177 char *onm, /* source name */
1181 1178 struct vnode *ndvp, /* destination parent vnode */
1182 1179 char *nnm, /* destination name */
1183 1180 struct cred *cred,
1184 1181 caller_context_t *ct,
1185 1182 int flags)
1186 1183 {
1187 1184 struct tmpnode *fromparent;
1188 1185 struct tmpnode *toparent;
1189 1186 struct tmpnode *fromtp = NULL; /* source tmpnode */
1190 1187 struct tmpnode *totp; /* target tmpnode */
1191 1188 struct tmount *tm = (struct tmount *)VTOTM(odvp);
1192 1189 int error;
1193 1190 int samedir = 0; /* set if odvp == ndvp */
1194 1191 struct vnode *realvp;
1195 1192
1196 1193 if (VOP_REALVP(ndvp, &realvp, ct) == 0)
1197 1194 ndvp = realvp;
1198 1195
1199 1196 fromparent = (struct tmpnode *)VTOTN(odvp);
1200 1197 toparent = (struct tmpnode *)VTOTN(ndvp);
1201 1198
1202 1199 if ((fromparent->tn_flags & ISXATTR) != (toparent->tn_flags & ISXATTR))
1203 1200 return (EINVAL);
1204 1201
1205 1202 mutex_enter(&tm->tm_renamelck);
1206 1203
1207 1204 /*
1208 1205 * Look up tmpnode of file we're supposed to rename.
1209 1206 */
1210 1207 error = tdirlookup(fromparent, onm, &fromtp, cred);
1211 1208 if (error) {
1212 1209 mutex_exit(&tm->tm_renamelck);
1213 1210 return (error);
1214 1211 }
1215 1212
1216 1213 /*
1217 1214 * Make sure we can delete the old (source) entry. This
1218 1215 * requires write permission on the containing directory. If
1219 1216 * that directory is "sticky" it requires further checks.
1220 1217 */
1221 1218 if (((error = tmp_taccess(fromparent, VWRITE, cred)) != 0) ||
1222 1219 (error = tmp_sticky_remove_access(fromparent, fromtp, cred)) != 0)
1223 1220 goto done;
1224 1221
1225 1222 /*
1226 1223 * Check for renaming to or from '.' or '..' or that
1227 1224 * fromtp == fromparent
1228 1225 */
1229 1226 if ((onm[0] == '.' &&
1230 1227 (onm[1] == '\0' || (onm[1] == '.' && onm[2] == '\0'))) ||
1231 1228 (nnm[0] == '.' &&
1232 1229 (nnm[1] == '\0' || (nnm[1] == '.' && nnm[2] == '\0'))) ||
1233 1230 (fromparent == fromtp)) {
1234 1231 error = EINVAL;
1235 1232 goto done;
1236 1233 }
1237 1234
1238 1235 samedir = (fromparent == toparent);
1239 1236 /*
1240 1237 * Make sure we can search and rename into the new
1241 1238 * (destination) directory.
1242 1239 */
1243 1240 if (!samedir) {
1244 1241 error = tmp_taccess(toparent, VEXEC|VWRITE, cred);
1245 1242 if (error)
1246 1243 goto done;
1247 1244 }
1248 1245
1249 1246 if (tdirlookup(toparent, nnm, &totp, cred) == 0) {
1250 1247 vnevent_pre_rename_dest(TNTOV(totp), ndvp, nnm, ct);
1251 1248 tmpnode_rele(totp);
1252 1249 }
1253 1250
1254 1251 /* Notify the target dir. if not the same as the source dir. */
1255 1252 if (ndvp != odvp) {
1256 1253 vnevent_pre_rename_dest_dir(ndvp, TNTOV(fromtp), nnm, ct);
1257 1254 }
1258 1255
1259 1256 vnevent_pre_rename_src(TNTOV(fromtp), odvp, onm, ct);
1260 1257
1261 1258 /*
1262 1259 * Link source to new target
1263 1260 */
1264 1261 rw_enter(&toparent->tn_rwlock, RW_WRITER);
1265 1262 error = tdirenter(tm, toparent, nnm, DE_RENAME,
1266 1263 fromparent, fromtp, (struct vattr *)NULL,
1267 1264 (struct tmpnode **)NULL, cred, ct);
1268 1265 rw_exit(&toparent->tn_rwlock);
1269 1266
1270 1267 if (error) {
1271 1268 /*
1272 1269 * ESAME isn't really an error; it indicates that the
1273 1270 * operation should not be done because the source and target
1274 1271 * are the same file, but that no error should be reported.
1275 1272 */
1276 1273 if (error == ESAME)
1277 1274 error = 0;
1278 1275 goto done;
1279 1276 }
1280 1277
1281 1278 /*
1282 1279 * Unlink from source.
1283 1280 */
1284 1281 rw_enter(&fromparent->tn_rwlock, RW_WRITER);
1285 1282 rw_enter(&fromtp->tn_rwlock, RW_WRITER);
1286 1283
1287 1284 error = tdirdelete(fromparent, fromtp, onm, DR_RENAME, cred);
1288 1285
1289 1286 /*
1290 1287 * The following handles the case where our source tmpnode was
1291 1288 * removed before we got to it.
1292 1289 *
1293 1290 * XXX We should also cleanup properly in the case where tdirdelete
1294 1291 * fails for some other reason. Currently this case shouldn't happen.
1295 1292 * (see 1184991).
1296 1293 */
1297 1294 if (error == ENOENT)
1298 1295 error = 0;
1299 1296
1300 1297 rw_exit(&fromtp->tn_rwlock);
1301 1298 rw_exit(&fromparent->tn_rwlock);
1302 1299
1303 1300 if (error == 0) {
1304 1301 vnevent_rename_src(TNTOV(fromtp), odvp, onm, ct);
1305 1302 /*
1306 1303 * vnevent_rename_dest is called in tdirenter().
1307 1304 * Notify the target dir if not same as source dir.
1308 1305 */
1309 1306 if (ndvp != odvp)
1310 1307 vnevent_rename_dest_dir(ndvp, ct);
1311 1308 }
1312 1309
1313 1310 done:
1314 1311 tmpnode_rele(fromtp);
1315 1312 mutex_exit(&tm->tm_renamelck);
1316 1313
1317 1314 TRACE_5(TR_FAC_TMPFS, TR_TMPFS_RENAME,
1318 1315 "tmpfs rename:ovp %p onm %s nvp %p nnm %s error %d", odvp, onm,
1319 1316 ndvp, nnm, error);
1320 1317 return (error);
1321 1318 }
1322 1319
1323 1320 /* ARGSUSED5 */
1324 1321 static int
1325 1322 tmp_mkdir(
1326 1323 struct vnode *dvp,
1327 1324 char *nm,
1328 1325 struct vattr *va,
1329 1326 struct vnode **vpp,
1330 1327 struct cred *cred,
1331 1328 caller_context_t *ct,
1332 1329 int flags,
1333 1330 vsecattr_t *vsecp)
1334 1331 {
1335 1332 struct tmpnode *parent = (struct tmpnode *)VTOTN(dvp);
1336 1333 struct tmpnode *self = NULL;
1337 1334 struct tmount *tm = (struct tmount *)VTOTM(dvp);
1338 1335 int error;
1339 1336
1340 1337 /* no new dirs allowed in xattr dirs */
1341 1338 if (parent->tn_flags & ISXATTR)
1342 1339 return (EINVAL);
1343 1340
1344 1341 /*
1345 1342 * Might be dangling directory. Catch it here,
1346 1343 * because a ENOENT return from tdirlookup() is
1347 1344 * an "o.k. return".
1348 1345 */
1349 1346 if (parent->tn_nlink == 0)
1350 1347 return (ENOENT);
1351 1348
1352 1349 error = tdirlookup(parent, nm, &self, cred);
1353 1350 if (error == 0) {
1354 1351 ASSERT(self);
1355 1352 tmpnode_rele(self);
1356 1353 return (EEXIST);
1357 1354 }
1358 1355 if (error != ENOENT)
1359 1356 return (error);
1360 1357
1361 1358 rw_enter(&parent->tn_rwlock, RW_WRITER);
1362 1359 error = tdirenter(tm, parent, nm, DE_MKDIR, (struct tmpnode *)NULL,
1363 1360 (struct tmpnode *)NULL, va, &self, cred, ct);
1364 1361 if (error) {
1365 1362 rw_exit(&parent->tn_rwlock);
1366 1363 if (self)
1367 1364 tmpnode_rele(self);
1368 1365 return (error);
1369 1366 }
1370 1367 rw_exit(&parent->tn_rwlock);
1371 1368 *vpp = TNTOV(self);
1372 1369 return (0);
1373 1370 }
1374 1371
1375 1372 /* ARGSUSED4 */
1376 1373 static int
1377 1374 tmp_rmdir(
1378 1375 struct vnode *dvp,
1379 1376 char *nm,
1380 1377 struct vnode *cdir,
1381 1378 struct cred *cred,
1382 1379 caller_context_t *ct,
1383 1380 int flags)
1384 1381 {
1385 1382 struct tmpnode *parent = (struct tmpnode *)VTOTN(dvp);
1386 1383 struct tmpnode *self = NULL;
1387 1384 struct vnode *vp;
1388 1385 int error = 0;
1389 1386
1390 1387 /*
1391 1388 * Return error when removing . and ..
1392 1389 */
1393 1390 if (strcmp(nm, ".") == 0)
1394 1391 return (EINVAL);
1395 1392 if (strcmp(nm, "..") == 0)
1396 1393 return (EEXIST); /* Should be ENOTEMPTY */
1397 1394 error = tdirlookup(parent, nm, &self, cred);
1398 1395 if (error)
1399 1396 return (error);
1400 1397
1401 1398 rw_enter(&parent->tn_rwlock, RW_WRITER);
1402 1399 rw_enter(&self->tn_rwlock, RW_WRITER);
1403 1400
1404 1401 vp = TNTOV(self);
1405 1402 if (vp == dvp || vp == cdir) {
1406 1403 error = EINVAL;
1407 1404 goto done1;
1408 1405 }
1409 1406 if (self->tn_type != VDIR) {
1410 1407 error = ENOTDIR;
1411 1408 goto done1;
1412 1409 }
1413 1410
1414 1411 mutex_enter(&self->tn_tlock);
1415 1412 if (self->tn_nlink > 2) {
1416 1413 mutex_exit(&self->tn_tlock);
1417 1414 error = EEXIST;
1418 1415 goto done1;
1419 1416 }
1420 1417 mutex_exit(&self->tn_tlock);
1421 1418
1422 1419 if (vn_vfswlock(vp)) {
1423 1420 error = EBUSY;
1424 1421 goto done1;
1425 1422 }
1426 1423 if (vn_mountedvfs(vp) != NULL) {
1427 1424 error = EBUSY;
1428 1425 goto done;
1429 1426 }
1430 1427
1431 1428 /*
1432 1429 * Check for an empty directory
1433 1430 * i.e. only includes entries for "." and ".."
1434 1431 */
1435 1432 if (self->tn_dirents > 2) {
1436 1433 error = EEXIST; /* SIGH should be ENOTEMPTY */
1437 1434 /*
1438 1435 * Update atime because checking tn_dirents is logically
1439 1436 * equivalent to reading the directory
1440 1437 */
1441 1438 gethrestime(&self->tn_atime);
1442 1439 goto done;
1443 1440 }
1444 1441
1445 1442 error = tdirdelete(parent, self, nm, DR_RMDIR, cred);
1446 1443 done:
1447 1444 vn_vfsunlock(vp);
1448 1445 done1:
1449 1446 rw_exit(&self->tn_rwlock);
1450 1447 rw_exit(&parent->tn_rwlock);
1451 1448 vnevent_rmdir(TNTOV(self), dvp, nm, ct);
1452 1449 tmpnode_rele(self);
1453 1450
1454 1451 return (error);
1455 1452 }
1456 1453
1457 1454 /* ARGSUSED2 */
1458 1455 static int
1459 1456 tmp_readdir(
1460 1457 struct vnode *vp,
1461 1458 struct uio *uiop,
1462 1459 struct cred *cred,
1463 1460 int *eofp,
1464 1461 caller_context_t *ct,
1465 1462 int flags)
1466 1463 {
1467 1464 struct tmpnode *tp = (struct tmpnode *)VTOTN(vp);
1468 1465 struct tdirent *tdp;
1469 1466 int error = 0;
1470 1467 size_t namelen;
1471 1468 struct dirent64 *dp;
1472 1469 ulong_t offset;
1473 1470 ulong_t total_bytes_wanted;
1474 1471 long outcount = 0;
1475 1472 long bufsize;
1476 1473 int reclen;
1477 1474 caddr_t outbuf;
1478 1475
1479 1476 if (uiop->uio_loffset >= MAXOFF_T) {
1480 1477 if (eofp)
1481 1478 *eofp = 1;
1482 1479 return (0);
1483 1480 }
1484 1481 /*
1485 1482 * assuming system call has already called tmp_rwlock
1486 1483 */
1487 1484 ASSERT(RW_READ_HELD(&tp->tn_rwlock));
1488 1485
1489 1486 if (uiop->uio_iovcnt != 1)
1490 1487 return (EINVAL);
1491 1488
1492 1489 if (vp->v_type != VDIR)
1493 1490 return (ENOTDIR);
1494 1491
1495 1492 /*
1496 1493 * There's a window here where someone could have removed
1497 1494 * all the entries in the directory after we put a hold on the
1498 1495 * vnode but before we grabbed the rwlock. Just return.
1499 1496 */
1500 1497 if (tp->tn_dir == NULL) {
1501 1498 if (tp->tn_nlink) {
1502 1499 panic("empty directory 0x%p", (void *)tp);
1503 1500 /*NOTREACHED*/
1504 1501 }
1505 1502 return (0);
1506 1503 }
1507 1504
1508 1505 /*
1509 1506 * Get space for multiple directory entries
1510 1507 */
1511 1508 total_bytes_wanted = uiop->uio_iov->iov_len;
1512 1509 bufsize = total_bytes_wanted + sizeof (struct dirent64);
1513 1510 outbuf = kmem_alloc(bufsize, KM_SLEEP);
1514 1511
1515 1512 dp = (struct dirent64 *)outbuf;
1516 1513
1517 1514
1518 1515 offset = 0;
1519 1516 tdp = tp->tn_dir;
1520 1517 while (tdp) {
1521 1518 namelen = strlen(tdp->td_name); /* no +1 needed */
1522 1519 offset = tdp->td_offset;
1523 1520 if (offset >= uiop->uio_offset) {
1524 1521 reclen = (int)DIRENT64_RECLEN(namelen);
1525 1522 if (outcount + reclen > total_bytes_wanted) {
1526 1523 if (!outcount)
1527 1524 /*
1528 1525 * Buffer too small for any entries.
1529 1526 */
1530 1527 error = EINVAL;
1531 1528 break;
1532 1529 }
1533 1530 ASSERT(tdp->td_tmpnode != NULL);
1534 1531
1535 1532 /* use strncpy(9f) to zero out uninitialized bytes */
1536 1533
1537 1534 (void) strncpy(dp->d_name, tdp->td_name,
1538 1535 DIRENT64_NAMELEN(reclen));
1539 1536 dp->d_reclen = (ushort_t)reclen;
1540 1537 dp->d_ino = (ino64_t)tdp->td_tmpnode->tn_nodeid;
1541 1538 dp->d_off = (offset_t)tdp->td_offset + 1;
1542 1539 dp = (struct dirent64 *)
1543 1540 ((uintptr_t)dp + dp->d_reclen);
1544 1541 outcount += reclen;
1545 1542 ASSERT(outcount <= bufsize);
1546 1543 }
1547 1544 tdp = tdp->td_next;
1548 1545 }
1549 1546
1550 1547 if (!error)
1551 1548 error = uiomove(outbuf, outcount, UIO_READ, uiop);
1552 1549
1553 1550 if (!error) {
1554 1551 /* If we reached the end of the list our offset */
1555 1552 /* should now be just past the end. */
1556 1553 if (!tdp) {
1557 1554 offset += 1;
1558 1555 if (eofp)
1559 1556 *eofp = 1;
1560 1557 } else if (eofp)
1561 1558 *eofp = 0;
1562 1559 uiop->uio_offset = offset;
1563 1560 }
1564 1561 gethrestime(&tp->tn_atime);
1565 1562 kmem_free(outbuf, bufsize);
1566 1563 return (error);
1567 1564 }
1568 1565
1569 1566 /* ARGSUSED5 */
1570 1567 static int
1571 1568 tmp_symlink(
1572 1569 struct vnode *dvp,
1573 1570 char *lnm,
1574 1571 struct vattr *tva,
1575 1572 char *tnm,
1576 1573 struct cred *cred,
1577 1574 caller_context_t *ct,
1578 1575 int flags)
1579 1576 {
1580 1577 struct tmpnode *parent = (struct tmpnode *)VTOTN(dvp);
1581 1578 struct tmpnode *self = (struct tmpnode *)NULL;
1582 1579 struct tmount *tm = (struct tmount *)VTOTM(dvp);
1583 1580 char *cp = NULL;
1584 1581 int error;
1585 1582 size_t len;
1586 1583
1587 1584 /* no symlinks allowed to files in xattr dirs */
1588 1585 if (parent->tn_flags & ISXATTR)
1589 1586 return (EINVAL);
1590 1587
1591 1588 error = tdirlookup(parent, lnm, &self, cred);
1592 1589 if (error == 0) {
1593 1590 /*
1594 1591 * The entry already exists
1595 1592 */
1596 1593 tmpnode_rele(self);
1597 1594 return (EEXIST); /* was 0 */
1598 1595 }
1599 1596
1600 1597 if (error != ENOENT) {
1601 1598 if (self != NULL)
1602 1599 tmpnode_rele(self);
1603 1600 return (error);
1604 1601 }
1605 1602
1606 1603 rw_enter(&parent->tn_rwlock, RW_WRITER);
1607 1604 error = tdirenter(tm, parent, lnm, DE_CREATE, (struct tmpnode *)NULL,
1608 1605 (struct tmpnode *)NULL, tva, &self, cred, ct);
1609 1606 rw_exit(&parent->tn_rwlock);
1610 1607
1611 1608 if (error) {
1612 1609 if (self)
1613 1610 tmpnode_rele(self);
1614 1611 return (error);
1615 1612 }
1616 1613 len = strlen(tnm) + 1;
1617 1614 cp = tmp_memalloc(len, 0);
1618 1615 if (cp == NULL) {
1619 1616 tmpnode_rele(self);
1620 1617 return (ENOSPC);
1621 1618 }
1622 1619 (void) strcpy(cp, tnm);
1623 1620
1624 1621 self->tn_symlink = cp;
1625 1622 self->tn_size = len - 1;
1626 1623 tmpnode_rele(self);
1627 1624 return (error);
1628 1625 }
1629 1626
1630 1627 /* ARGSUSED2 */
1631 1628 static int
1632 1629 tmp_readlink(
1633 1630 struct vnode *vp,
1634 1631 struct uio *uiop,
1635 1632 struct cred *cred,
1636 1633 caller_context_t *ct)
1637 1634 {
1638 1635 struct tmpnode *tp = (struct tmpnode *)VTOTN(vp);
1639 1636 int error = 0;
1640 1637
1641 1638 if (vp->v_type != VLNK)
1642 1639 return (EINVAL);
1643 1640
1644 1641 rw_enter(&tp->tn_rwlock, RW_READER);
1645 1642 rw_enter(&tp->tn_contents, RW_READER);
1646 1643 error = uiomove(tp->tn_symlink, tp->tn_size, UIO_READ, uiop);
1647 1644 gethrestime(&tp->tn_atime);
1648 1645 rw_exit(&tp->tn_contents);
1649 1646 rw_exit(&tp->tn_rwlock);
1650 1647 return (error);
1651 1648 }
1652 1649
1653 1650 /* ARGSUSED */
1654 1651 static int
1655 1652 tmp_fsync(
1656 1653 struct vnode *vp,
1657 1654 int syncflag,
1658 1655 struct cred *cred,
1659 1656 caller_context_t *ct)
1660 1657 {
1661 1658 return (0);
1662 1659 }
1663 1660
1664 1661 /* ARGSUSED */
1665 1662 static void
1666 1663 tmp_inactive(struct vnode *vp, struct cred *cred, caller_context_t *ct)
1667 1664 {
1668 1665 struct tmpnode *tp = (struct tmpnode *)VTOTN(vp);
1669 1666 struct tmount *tm = (struct tmount *)VFSTOTM(vp->v_vfsp);
1670 1667
1671 1668 rw_enter(&tp->tn_rwlock, RW_WRITER);
1672 1669 top:
1673 1670 mutex_enter(&tp->tn_tlock);
1674 1671 mutex_enter(&vp->v_lock);
1675 1672 ASSERT(vp->v_count >= 1);
1676 1673
1677 1674 /*
1678 1675 * If we don't have the last hold or the link count is non-zero,
1679 1676 * there's little to do -- just drop our hold.
1680 1677 */
1681 1678 if (vp->v_count > 1 || tp->tn_nlink != 0) {
1682 1679 vp->v_count--;
1683 1680 mutex_exit(&vp->v_lock);
1684 1681 mutex_exit(&tp->tn_tlock);
1685 1682 rw_exit(&tp->tn_rwlock);
1686 1683 return;
1687 1684 }
1688 1685
1689 1686 /*
1690 1687 * We have the last hold *and* the link count is zero, so this
1691 1688 * tmpnode is dead from the filesystem's viewpoint. However,
1692 1689 * if the tmpnode has any pages associated with it (i.e. if it's
1693 1690 * a normal file with non-zero size), the tmpnode can still be
1694 1691 * discovered by pageout or fsflush via the page vnode pointers.
1695 1692 * In this case we must drop all our locks, truncate the tmpnode,
1696 1693 * and try the whole dance again.
1697 1694 */
1698 1695 if (tp->tn_size != 0) {
1699 1696 if (tp->tn_type == VREG) {
1700 1697 mutex_exit(&vp->v_lock);
1701 1698 mutex_exit(&tp->tn_tlock);
1702 1699 rw_enter(&tp->tn_contents, RW_WRITER);
1703 1700 (void) tmpnode_trunc(tm, tp, 0);
1704 1701 rw_exit(&tp->tn_contents);
1705 1702 ASSERT(tp->tn_size == 0);
1706 1703 ASSERT(tp->tn_nblocks == 0);
1707 1704 goto top;
1708 1705 }
1709 1706 if (tp->tn_type == VLNK)
1710 1707 tmp_memfree(tp->tn_symlink, tp->tn_size + 1);
1711 1708 }
1712 1709
1713 1710 /*
1714 1711 * Remove normal file/dir's xattr dir and xattrs.
1715 1712 */
1716 1713 if (tp->tn_xattrdp) {
1717 1714 struct tmpnode *xtp = tp->tn_xattrdp;
1718 1715
1719 1716 ASSERT(xtp->tn_flags & ISXATTR);
1720 1717 tmpnode_hold(xtp);
1721 1718 rw_enter(&xtp->tn_rwlock, RW_WRITER);
1722 1719 tdirtrunc(xtp);
1723 1720 DECR_COUNT(&xtp->tn_nlink, &xtp->tn_tlock);
1724 1721 tp->tn_xattrdp = NULL;
1725 1722 rw_exit(&xtp->tn_rwlock);
1726 1723 tmpnode_rele(xtp);
1727 1724 }
1728 1725
1729 1726 mutex_exit(&vp->v_lock);
1730 1727 mutex_exit(&tp->tn_tlock);
1731 1728 /* Here's our chance to send invalid event while we're between locks */
1732 1729 vn_invalid(TNTOV(tp));
1733 1730 mutex_enter(&tm->tm_contents);
1734 1731 if (tp->tn_forw == NULL)
1735 1732 tm->tm_rootnode->tn_back = tp->tn_back;
1736 1733 else
1737 1734 tp->tn_forw->tn_back = tp->tn_back;
1738 1735 tp->tn_back->tn_forw = tp->tn_forw;
1739 1736 mutex_exit(&tm->tm_contents);
1740 1737 rw_exit(&tp->tn_rwlock);
1741 1738 rw_destroy(&tp->tn_rwlock);
1742 1739 mutex_destroy(&tp->tn_tlock);
1743 1740 vn_free(TNTOV(tp));
1744 1741 tmp_memfree(tp, sizeof (struct tmpnode));
1745 1742 }
1746 1743
1747 1744 /* ARGSUSED2 */
1748 1745 static int
1749 1746 tmp_fid(struct vnode *vp, struct fid *fidp, caller_context_t *ct)
1750 1747 {
1751 1748 struct tmpnode *tp = (struct tmpnode *)VTOTN(vp);
1752 1749 struct tfid *tfid;
1753 1750
1754 1751 if (fidp->fid_len < (sizeof (struct tfid) - sizeof (ushort_t))) {
1755 1752 fidp->fid_len = sizeof (struct tfid) - sizeof (ushort_t);
1756 1753 return (ENOSPC);
1757 1754 }
1758 1755
1759 1756 tfid = (struct tfid *)fidp;
1760 1757 bzero(tfid, sizeof (struct tfid));
1761 1758 tfid->tfid_len = (int)sizeof (struct tfid) - sizeof (ushort_t);
1762 1759
1763 1760 tfid->tfid_ino = tp->tn_nodeid;
1764 1761 tfid->tfid_gen = tp->tn_gen;
1765 1762
1766 1763 return (0);
1767 1764 }
1768 1765
1769 1766
1770 1767 /*
1771 1768 * Return all the pages from [off..off+len] in given file
1772 1769 */
1773 1770 /* ARGSUSED */
1774 1771 static int
1775 1772 tmp_getpage(
1776 1773 struct vnode *vp,
1777 1774 offset_t off,
1778 1775 size_t len,
1779 1776 uint_t *protp,
1780 1777 page_t *pl[],
1781 1778 size_t plsz,
1782 1779 struct seg *seg,
1783 1780 caddr_t addr,
1784 1781 enum seg_rw rw,
1785 1782 struct cred *cr,
1786 1783 caller_context_t *ct)
1787 1784 {
1788 1785 int err = 0;
1789 1786 struct tmpnode *tp = VTOTN(vp);
1790 1787 anoff_t toff = (anoff_t)off;
1791 1788 size_t tlen = len;
1792 1789 u_offset_t tmpoff;
1793 1790 timestruc_t now;
1794 1791
1795 1792 rw_enter(&tp->tn_contents, RW_READER);
1796 1793
1797 1794 if (off + len > tp->tn_size + PAGEOFFSET) {
1798 1795 err = EFAULT;
1799 1796 goto out;
1800 1797 }
1801 1798 /*
1802 1799 * Look for holes (no anon slot) in faulting range. If there are
1803 1800 * holes we have to switch to a write lock and fill them in. Swap
1804 1801 * space for holes was already reserved when the file was grown.
1805 1802 */
1806 1803 tmpoff = toff;
1807 1804 if (non_anon(tp->tn_anon, btop(off), &tmpoff, &tlen)) {
1808 1805 if (!rw_tryupgrade(&tp->tn_contents)) {
1809 1806 rw_exit(&tp->tn_contents);
1810 1807 rw_enter(&tp->tn_contents, RW_WRITER);
1811 1808 /* Size may have changed when lock was dropped */
1812 1809 if (off + len > tp->tn_size + PAGEOFFSET) {
1813 1810 err = EFAULT;
1814 1811 goto out;
1815 1812 }
1816 1813 }
1817 1814 for (toff = (anoff_t)off; toff < (anoff_t)off + len;
1818 1815 toff += PAGESIZE) {
1819 1816 if (anon_get_ptr(tp->tn_anon, btop(toff)) == NULL) {
1820 1817 /* XXX - may allocate mem w. write lock held */
1821 1818 (void) anon_set_ptr(tp->tn_anon, btop(toff),
1822 1819 anon_alloc(vp, toff), ANON_SLEEP);
1823 1820 tp->tn_nblocks++;
1824 1821 }
1825 1822 }
1826 1823 rw_downgrade(&tp->tn_contents);
1827 1824 }
1828 1825
1829 1826
1830 1827 err = pvn_getpages(tmp_getapage, vp, (u_offset_t)off, len, protp,
1831 1828 pl, plsz, seg, addr, rw, cr);
1832 1829
1833 1830 gethrestime(&now);
1834 1831 tp->tn_atime = now;
1835 1832 if (rw == S_WRITE)
1836 1833 tp->tn_mtime = now;
1837 1834
1838 1835 out:
1839 1836 rw_exit(&tp->tn_contents);
1840 1837 return (err);
1841 1838 }
1842 1839
1843 1840 /*
1844 1841 * Called from pvn_getpages to get a particular page.
1845 1842 */
1846 1843 /*ARGSUSED*/
1847 1844 static int
1848 1845 tmp_getapage(
1849 1846 struct vnode *vp,
1850 1847 u_offset_t off,
1851 1848 size_t len,
1852 1849 uint_t *protp,
1853 1850 page_t *pl[],
1854 1851 size_t plsz,
1855 1852 struct seg *seg,
1856 1853 caddr_t addr,
1857 1854 enum seg_rw rw,
1858 1855 struct cred *cr)
1859 1856 {
1860 1857 struct page *pp;
1861 1858 int flags;
1862 1859 int err = 0;
1863 1860 struct vnode *pvp;
1864 1861 u_offset_t poff;
1865 1862
1866 1863 if (protp != NULL)
1867 1864 *protp = PROT_ALL;
1868 1865 again:
1869 1866 if (pp = page_lookup(vp, off, rw == S_CREATE ? SE_EXCL : SE_SHARED)) {
1870 1867 if (pl) {
1871 1868 pl[0] = pp;
1872 1869 pl[1] = NULL;
1873 1870 } else {
1874 1871 page_unlock(pp);
1875 1872 }
1876 1873 } else {
1877 1874 pp = page_create_va(vp, off, PAGESIZE,
1878 1875 PG_WAIT | PG_EXCL, seg, addr);
1879 1876 /*
1880 1877 * Someone raced in and created the page after we did the
1881 1878 * lookup but before we did the create, so go back and
1882 1879 * try to look it up again.
1883 1880 */
1884 1881 if (pp == NULL)
1885 1882 goto again;
1886 1883 /*
1887 1884 * Fill page from backing store, if any. If none, then
1888 1885 * either this is a newly filled hole or page must have
1889 1886 * been unmodified and freed so just zero it out.
1890 1887 */
1891 1888 err = swap_getphysname(vp, off, &pvp, &poff);
1892 1889 if (err) {
1893 1890 panic("tmp_getapage: no anon slot vp %p "
1894 1891 "off %llx pp %p\n", (void *)vp, off, (void *)pp);
1895 1892 }
1896 1893 if (pvp) {
1897 1894 flags = (pl == NULL ? B_ASYNC|B_READ : B_READ);
1898 1895 err = VOP_PAGEIO(pvp, pp, (u_offset_t)poff, PAGESIZE,
1899 1896 flags, cr, NULL);
1900 1897 if (flags & B_ASYNC)
1901 1898 pp = NULL;
1902 1899 } else if (rw != S_CREATE) {
1903 1900 pagezero(pp, 0, PAGESIZE);
1904 1901 }
1905 1902 if (err && pp)
1906 1903 pvn_read_done(pp, B_ERROR);
1907 1904 if (err == 0) {
1908 1905 if (pl)
1909 1906 pvn_plist_init(pp, pl, plsz, off, PAGESIZE, rw);
1910 1907 else
1911 1908 pvn_io_done(pp);
1912 1909 }
1913 1910 }
1914 1911 return (err);
1915 1912 }
1916 1913
1917 1914
1918 1915 /*
1919 1916 * Flags are composed of {B_INVAL, B_DIRTY B_FREE, B_DONTNEED}.
1920 1917 * If len == 0, do from off to EOF.
1921 1918 */
1922 1919 static int tmp_nopage = 0; /* Don't do tmp_putpage's if set */
1923 1920
1924 1921 /* ARGSUSED */
1925 1922 int
1926 1923 tmp_putpage(
1927 1924 register struct vnode *vp,
1928 1925 offset_t off,
1929 1926 size_t len,
1930 1927 int flags,
1931 1928 struct cred *cr,
1932 1929 caller_context_t *ct)
1933 1930 {
1934 1931 register page_t *pp;
1935 1932 u_offset_t io_off;
1936 1933 size_t io_len = 0;
1937 1934 int err = 0;
1938 1935 struct tmpnode *tp = VTOTN(vp);
1939 1936 int dolock;
1940 1937
1941 1938 if (tmp_nopage)
1942 1939 return (0);
1943 1940
1944 1941 ASSERT(vp->v_count != 0);
1945 1942
1946 1943 if (vp->v_flag & VNOMAP)
1947 1944 return (ENOSYS);
1948 1945
1949 1946 /*
1950 1947 * This being tmpfs, we don't ever do i/o unless we really
1951 1948 * have to (when we're low on memory and pageout calls us
1952 1949 * with B_ASYNC | B_FREE or the user explicitly asks for it with
1953 1950 * B_DONTNEED).
1954 1951 * XXX to approximately track the mod time like ufs we should
1955 1952 * update the times here. The problem is, once someone does a
1956 1953 * store we never clear the mod bit and do i/o, thus fsflush
1957 1954 * will keep calling us every 30 seconds to do the i/o and we'll
1958 1955 * continually update the mod time. At least we update the mod
1959 1956 * time on the first store because this results in a call to getpage.
1960 1957 */
1961 1958 if (flags != (B_ASYNC | B_FREE) && (flags & B_INVAL) == 0 &&
1962 1959 (flags & B_DONTNEED) == 0)
1963 1960 return (0);
1964 1961 /*
1965 1962 * If this thread owns the lock, i.e., this thread grabbed it
1966 1963 * as writer somewhere above, then we don't need to grab the
1967 1964 * lock as reader in this routine.
1968 1965 */
1969 1966 dolock = (rw_owner(&tp->tn_contents) != curthread);
1970 1967
1971 1968 /*
1972 1969 * If this is pageout don't block on the lock as you could deadlock
1973 1970 * when freemem == 0 (another thread has the read lock and is blocked
1974 1971 * creating a page, and a third thread is waiting to get the writers
1975 1972 * lock - waiting writers priority blocks us from getting the read
1976 1973 * lock). Of course, if the only freeable pages are on this tmpnode
1977 1974 * we're hosed anyways. A better solution might be a new lock type.
1978 1975 * Note: ufs has the same problem.
1979 1976 */
1980 1977 if (curproc == proc_pageout) {
1981 1978 if (!rw_tryenter(&tp->tn_contents, RW_READER))
1982 1979 return (ENOMEM);
1983 1980 } else if (dolock)
1984 1981 rw_enter(&tp->tn_contents, RW_READER);
1985 1982
1986 1983 if (!vn_has_cached_data(vp))
1987 1984 goto out;
1988 1985
1989 1986 if (len == 0) {
1990 1987 if (curproc == proc_pageout) {
1991 1988 panic("tmp: pageout can't block");
1992 1989 /*NOTREACHED*/
1993 1990 }
1994 1991
1995 1992 /* Search the entire vp list for pages >= off. */
1996 1993 err = pvn_vplist_dirty(vp, (u_offset_t)off, tmp_putapage,
1997 1994 flags, cr);
1998 1995 } else {
1999 1996 u_offset_t eoff;
2000 1997
2001 1998 /*
2002 1999 * Loop over all offsets in the range [off...off + len]
2003 2000 * looking for pages to deal with.
2004 2001 */
2005 2002 eoff = MIN(off + len, tp->tn_size);
2006 2003 for (io_off = off; io_off < eoff; io_off += io_len) {
2007 2004 /*
2008 2005 * If we are not invalidating, synchronously
2009 2006 * freeing or writing pages use the routine
2010 2007 * page_lookup_nowait() to prevent reclaiming
2011 2008 * them from the free list.
2012 2009 */
2013 2010 if ((flags & B_INVAL) || ((flags & B_ASYNC) == 0)) {
2014 2011 pp = page_lookup(vp, io_off,
2015 2012 (flags & (B_INVAL | B_FREE)) ?
2016 2013 SE_EXCL : SE_SHARED);
2017 2014 } else {
2018 2015 pp = page_lookup_nowait(vp, io_off,
2019 2016 (flags & B_FREE) ? SE_EXCL : SE_SHARED);
2020 2017 }
2021 2018
2022 2019 if (pp == NULL || pvn_getdirty(pp, flags) == 0)
2023 2020 io_len = PAGESIZE;
2024 2021 else {
2025 2022 err = tmp_putapage(vp, pp, &io_off, &io_len,
2026 2023 flags, cr);
2027 2024 if (err != 0)
2028 2025 break;
2029 2026 }
2030 2027 }
2031 2028 }
2032 2029 /* If invalidating, verify all pages on vnode list are gone. */
2033 2030 if (err == 0 && off == 0 && len == 0 &&
2034 2031 (flags & B_INVAL) && vn_has_cached_data(vp)) {
2035 2032 panic("tmp_putpage: B_INVAL, pages not gone");
2036 2033 /*NOTREACHED*/
2037 2034 }
2038 2035 out:
2039 2036 if ((curproc == proc_pageout) || dolock)
2040 2037 rw_exit(&tp->tn_contents);
2041 2038 /*
2042 2039 * Only reason putapage is going to give us SE_NOSWAP as error
2043 2040 * is when we ask a page to be written to physical backing store
2044 2041 * and there is none. Ignore this because we might be dealing
2045 2042 * with a swap page which does not have any backing store
2046 2043 * on disk. In any other case we won't get this error over here.
2047 2044 */
2048 2045 if (err == SE_NOSWAP)
2049 2046 err = 0;
2050 2047 return (err);
2051 2048 }
2052 2049
2053 2050 long tmp_putpagecnt, tmp_pagespushed;
2054 2051
2055 2052 /*
2056 2053 * Write out a single page.
2057 2054 * For tmpfs this means choose a physical swap slot and write the page
2058 2055 * out using VOP_PAGEIO. For performance, we attempt to kluster; i.e.,
2059 2056 * we try to find a bunch of other dirty pages adjacent in the file
2060 2057 * and a bunch of contiguous swap slots, and then write all the pages
2061 2058 * out in a single i/o.
2062 2059 */
2063 2060 /*ARGSUSED*/
2064 2061 static int
2065 2062 tmp_putapage(
2066 2063 struct vnode *vp,
2067 2064 page_t *pp,
2068 2065 u_offset_t *offp,
2069 2066 size_t *lenp,
2070 2067 int flags,
2071 2068 struct cred *cr)
2072 2069 {
2073 2070 int err;
2074 2071 ulong_t klstart, kllen;
2075 2072 page_t *pplist, *npplist;
2076 2073 extern int klustsize;
2077 2074 long tmp_klustsize;
2078 2075 struct tmpnode *tp;
2079 2076 size_t pp_off, pp_len;
2080 2077 u_offset_t io_off;
2081 2078 size_t io_len;
2082 2079 struct vnode *pvp;
2083 2080 u_offset_t pstart;
2084 2081 u_offset_t offset;
2085 2082 u_offset_t tmpoff;
2086 2083
2087 2084 ASSERT(PAGE_LOCKED(pp));
2088 2085
2089 2086 /* Kluster in tmp_klustsize chunks */
2090 2087 tp = VTOTN(vp);
2091 2088 tmp_klustsize = klustsize;
2092 2089 offset = pp->p_offset;
2093 2090 klstart = (offset / tmp_klustsize) * tmp_klustsize;
2094 2091 kllen = MIN(tmp_klustsize, tp->tn_size - klstart);
2095 2092
2096 2093 /* Get a kluster of pages */
2097 2094 pplist =
2098 2095 pvn_write_kluster(vp, pp, &tmpoff, &pp_len, klstart, kllen, flags);
2099 2096
2100 2097 pp_off = (size_t)tmpoff;
2101 2098
2102 2099 /*
2103 2100 * Get a cluster of physical offsets for the pages; the amount we
2104 2101 * get may be some subrange of what we ask for (io_off, io_len).
2105 2102 */
2106 2103 io_off = pp_off;
2107 2104 io_len = pp_len;
2108 2105 err = swap_newphysname(vp, offset, &io_off, &io_len, &pvp, &pstart);
2109 2106 ASSERT(err != SE_NOANON); /* anon slot must have been filled */
2110 2107 if (err) {
2111 2108 pvn_write_done(pplist, B_ERROR | B_WRITE | flags);
2112 2109 /*
2113 2110 * If this routine is called as a result of segvn_sync
2114 2111 * operation and we have no physical swap then we can get an
2115 2112 * error here. In such case we would return SE_NOSWAP as error.
2116 2113 * At this point, we expect only SE_NOSWAP.
2117 2114 */
2118 2115 ASSERT(err == SE_NOSWAP);
2119 2116 if (flags & B_INVAL)
2120 2117 err = ENOMEM;
2121 2118 goto out;
2122 2119 }
2123 2120 ASSERT(pp_off <= io_off && io_off + io_len <= pp_off + pp_len);
2124 2121 ASSERT(io_off <= offset && offset < io_off + io_len);
2125 2122
2126 2123 /* Toss pages at front/rear that we couldn't get physical backing for */
2127 2124 if (io_off != pp_off) {
2128 2125 npplist = NULL;
2129 2126 page_list_break(&pplist, &npplist, btop(io_off - pp_off));
2130 2127 ASSERT(pplist->p_offset == pp_off);
2131 2128 ASSERT(pplist->p_prev->p_offset == io_off - PAGESIZE);
2132 2129 pvn_write_done(pplist, B_ERROR | B_WRITE | flags);
2133 2130 pplist = npplist;
2134 2131 }
2135 2132 if (io_off + io_len < pp_off + pp_len) {
2136 2133 npplist = NULL;
2137 2134 page_list_break(&pplist, &npplist, btop(io_len));
2138 2135 ASSERT(npplist->p_offset == io_off + io_len);
2139 2136 ASSERT(npplist->p_prev->p_offset == pp_off + pp_len - PAGESIZE);
2140 2137 pvn_write_done(npplist, B_ERROR | B_WRITE | flags);
2141 2138 }
2142 2139
2143 2140 ASSERT(pplist->p_offset == io_off);
2144 2141 ASSERT(pplist->p_prev->p_offset == io_off + io_len - PAGESIZE);
2145 2142 ASSERT(btopr(io_len) <= btopr(kllen));
2146 2143
2147 2144 /* Do i/o on the remaining kluster */
2148 2145 err = VOP_PAGEIO(pvp, pplist, (u_offset_t)pstart, io_len,
2149 2146 B_WRITE | flags, cr, NULL);
2150 2147
2151 2148 if ((flags & B_ASYNC) == 0) {
2152 2149 pvn_write_done(pplist, ((err) ? B_ERROR : 0) | B_WRITE | flags);
2153 2150 }
2154 2151 out:
2155 2152 if (!err) {
2156 2153 if (offp)
2157 2154 *offp = io_off;
2158 2155 if (lenp)
2159 2156 *lenp = io_len;
2160 2157 tmp_putpagecnt++;
2161 2158 tmp_pagespushed += btop(io_len);
2162 2159 }
2163 2160 if (err && err != ENOMEM && err != SE_NOSWAP)
2164 2161 cmn_err(CE_WARN, "tmp_putapage: err %d\n", err);
2165 2162 return (err);
2166 2163 }
2167 2164
2168 2165 /* ARGSUSED */
2169 2166 static int
2170 2167 tmp_map(
2171 2168 struct vnode *vp,
2172 2169 offset_t off,
2173 2170 struct as *as,
2174 2171 caddr_t *addrp,
2175 2172 size_t len,
2176 2173 uchar_t prot,
2177 2174 uchar_t maxprot,
2178 2175 uint_t flags,
2179 2176 struct cred *cred,
2180 2177 caller_context_t *ct)
2181 2178 {
2182 2179 struct segvn_crargs vn_a;
2183 2180 struct tmpnode *tp = (struct tmpnode *)VTOTN(vp);
2184 2181 int error;
2185 2182
2186 2183 #ifdef _ILP32
2187 2184 if (len > MAXOFF_T)
2188 2185 return (ENOMEM);
2189 2186 #endif
2190 2187
2191 2188 if (vp->v_flag & VNOMAP)
2192 2189 return (ENOSYS);
2193 2190
2194 2191 if (off < 0 || (offset_t)(off + len) < 0 ||
2195 2192 off > MAXOFF_T || (off + len) > MAXOFF_T)
2196 2193 return (ENXIO);
2197 2194
2198 2195 if (vp->v_type != VREG)
2199 2196 return (ENODEV);
2200 2197
2201 2198 /*
2202 2199 * Don't allow mapping to locked file
2203 2200 */
2204 2201 if (vn_has_mandatory_locks(vp, tp->tn_mode)) {
2205 2202 return (EAGAIN);
2206 2203 }
2207 2204
2208 2205 as_rangelock(as);
2209 2206 error = choose_addr(as, addrp, len, off, ADDR_VACALIGN, flags);
2210 2207 if (error != 0) {
2211 2208 as_rangeunlock(as);
2212 2209 return (error);
2213 2210 }
2214 2211
2215 2212 vn_a.vp = vp;
2216 2213 vn_a.offset = (u_offset_t)off;
2217 2214 vn_a.type = flags & MAP_TYPE;
2218 2215 vn_a.prot = prot;
2219 2216 vn_a.maxprot = maxprot;
2220 2217 vn_a.flags = flags & ~MAP_TYPE;
2221 2218 vn_a.cred = cred;
2222 2219 vn_a.amp = NULL;
2223 2220 vn_a.szc = 0;
2224 2221 vn_a.lgrp_mem_policy_flags = 0;
2225 2222
2226 2223 error = as_map(as, *addrp, len, segvn_create, &vn_a);
2227 2224 as_rangeunlock(as);
2228 2225 return (error);
2229 2226 }
2230 2227
2231 2228 /*
2232 2229 * tmp_addmap and tmp_delmap can't be called since the vp
2233 2230 * maintained in the segvn mapping is NULL.
2234 2231 */
2235 2232 /* ARGSUSED */
2236 2233 static int
2237 2234 tmp_addmap(
2238 2235 struct vnode *vp,
2239 2236 offset_t off,
2240 2237 struct as *as,
2241 2238 caddr_t addr,
2242 2239 size_t len,
2243 2240 uchar_t prot,
2244 2241 uchar_t maxprot,
2245 2242 uint_t flags,
2246 2243 struct cred *cred,
2247 2244 caller_context_t *ct)
2248 2245 {
2249 2246 return (0);
2250 2247 }
2251 2248
2252 2249 /* ARGSUSED */
2253 2250 static int
2254 2251 tmp_delmap(
2255 2252 struct vnode *vp,
2256 2253 offset_t off,
2257 2254 struct as *as,
2258 2255 caddr_t addr,
2259 2256 size_t len,
2260 2257 uint_t prot,
2261 2258 uint_t maxprot,
2262 2259 uint_t flags,
2263 2260 struct cred *cred,
2264 2261 caller_context_t *ct)
2265 2262 {
2266 2263 return (0);
2267 2264 }
2268 2265
2269 2266 static int
2270 2267 tmp_freesp(struct vnode *vp, struct flock64 *lp, int flag)
2271 2268 {
2272 2269 register int i;
2273 2270 register struct tmpnode *tp = VTOTN(vp);
2274 2271 int error;
2275 2272
2276 2273 ASSERT(vp->v_type == VREG);
2277 2274 ASSERT(lp->l_start >= 0);
2278 2275
2279 2276 if (lp->l_len != 0)
2280 2277 return (EINVAL);
2281 2278
2282 2279 rw_enter(&tp->tn_rwlock, RW_WRITER);
2283 2280 if (tp->tn_size == lp->l_start) {
2284 2281 rw_exit(&tp->tn_rwlock);
2285 2282 return (0);
2286 2283 }
2287 2284
2288 2285 /*
2289 2286 * Check for any mandatory locks on the range
2290 2287 */
2291 2288 if (MANDLOCK(vp, tp->tn_mode)) {
2292 2289 long save_start;
2293 2290
2294 2291 save_start = lp->l_start;
2295 2292
2296 2293 if (tp->tn_size < lp->l_start) {
2297 2294 /*
2298 2295 * "Truncate up" case: need to make sure there
2299 2296 * is no lock beyond current end-of-file. To
2300 2297 * do so, we need to set l_start to the size
2301 2298 * of the file temporarily.
2302 2299 */
2303 2300 lp->l_start = tp->tn_size;
2304 2301 }
2305 2302 lp->l_type = F_WRLCK;
2306 2303 lp->l_sysid = 0;
2307 2304 lp->l_pid = ttoproc(curthread)->p_pid;
2308 2305 i = (flag & (FNDELAY|FNONBLOCK)) ? 0 : SLPFLCK;
2309 2306 if ((i = reclock(vp, lp, i, 0, lp->l_start, NULL)) != 0 ||
2310 2307 lp->l_type != F_UNLCK) {
2311 2308 rw_exit(&tp->tn_rwlock);
2312 2309 return (i ? i : EAGAIN);
2313 2310 }
2314 2311
2315 2312 lp->l_start = save_start;
2316 2313 }
2317 2314 VFSTOTM(vp->v_vfsp);
2318 2315
2319 2316 rw_enter(&tp->tn_contents, RW_WRITER);
2320 2317 error = tmpnode_trunc((struct tmount *)VFSTOTM(vp->v_vfsp),
2321 2318 tp, (ulong_t)lp->l_start);
2322 2319 rw_exit(&tp->tn_contents);
2323 2320 rw_exit(&tp->tn_rwlock);
2324 2321 return (error);
2325 2322 }
2326 2323
2327 2324 /* ARGSUSED */
2328 2325 static int
2329 2326 tmp_space(
2330 2327 struct vnode *vp,
2331 2328 int cmd,
2332 2329 struct flock64 *bfp,
2333 2330 int flag,
2334 2331 offset_t offset,
2335 2332 cred_t *cred,
2336 2333 caller_context_t *ct)
2337 2334 {
2338 2335 int error;
2339 2336
2340 2337 if (cmd != F_FREESP)
2341 2338 return (EINVAL);
2342 2339 if ((error = convoff(vp, bfp, 0, (offset_t)offset)) == 0) {
2343 2340 if ((bfp->l_start > MAXOFF_T) || (bfp->l_len > MAXOFF_T))
2344 2341 return (EFBIG);
2345 2342 error = tmp_freesp(vp, bfp, flag);
2346 2343
2347 2344 if (error == 0 && bfp->l_start == 0)
2348 2345 vnevent_truncate(vp, ct);
2349 2346 }
2350 2347 return (error);
2351 2348 }
2352 2349
2353 2350 /* ARGSUSED */
2354 2351 static int
2355 2352 tmp_seek(
2356 2353 struct vnode *vp,
2357 2354 offset_t ooff,
2358 2355 offset_t *noffp,
2359 2356 caller_context_t *ct)
2360 2357 {
2361 2358 return ((*noffp < 0 || *noffp > MAXOFFSET_T) ? EINVAL : 0);
2362 2359 }
2363 2360
2364 2361 /* ARGSUSED2 */
2365 2362 static int
2366 2363 tmp_rwlock(struct vnode *vp, int write_lock, caller_context_t *ctp)
2367 2364 {
2368 2365 struct tmpnode *tp = VTOTN(vp);
2369 2366
2370 2367 if (write_lock) {
2371 2368 rw_enter(&tp->tn_rwlock, RW_WRITER);
2372 2369 } else {
2373 2370 rw_enter(&tp->tn_rwlock, RW_READER);
2374 2371 }
2375 2372 return (write_lock);
2376 2373 }
2377 2374
2378 2375 /* ARGSUSED1 */
2379 2376 static void
2380 2377 tmp_rwunlock(struct vnode *vp, int write_lock, caller_context_t *ctp)
2381 2378 {
2382 2379 struct tmpnode *tp = VTOTN(vp);
2383 2380
2384 2381 rw_exit(&tp->tn_rwlock);
2385 2382 }
2386 2383
2387 2384 static int
2388 2385 tmp_pathconf(
2389 2386 struct vnode *vp,
2390 2387 int cmd,
2391 2388 ulong_t *valp,
2392 2389 cred_t *cr,
2393 2390 caller_context_t *ct)
2394 2391 {
2395 2392 struct tmpnode *tp = NULL;
2396 2393 int error;
2397 2394
2398 2395 switch (cmd) {
2399 2396 case _PC_XATTR_EXISTS:
2400 2397 if (vp->v_vfsp->vfs_flag & VFS_XATTR) {
2401 2398 *valp = 0; /* assume no attributes */
2402 2399 error = 0; /* okay to ask */
2403 2400 tp = VTOTN(vp);
2404 2401 rw_enter(&tp->tn_rwlock, RW_READER);
2405 2402 if (tp->tn_xattrdp) {
2406 2403 rw_enter(&tp->tn_xattrdp->tn_rwlock, RW_READER);
2407 2404 /* do not count "." and ".." */
2408 2405 if (tp->tn_xattrdp->tn_dirents > 2)
2409 2406 *valp = 1;
2410 2407 rw_exit(&tp->tn_xattrdp->tn_rwlock);
2411 2408 }
2412 2409 rw_exit(&tp->tn_rwlock);
2413 2410 } else {
2414 2411 error = EINVAL;
2415 2412 }
2416 2413 break;
2417 2414 case _PC_SATTR_ENABLED:
2418 2415 case _PC_SATTR_EXISTS:
2419 2416 *valp = vfs_has_feature(vp->v_vfsp, VFSFT_SYSATTR_VIEWS) &&
2420 2417 (vp->v_type == VREG || vp->v_type == VDIR);
2421 2418 error = 0;
2422 2419 break;
2423 2420 case _PC_TIMESTAMP_RESOLUTION:
2424 2421 /* nanosecond timestamp resolution */
2425 2422 *valp = 1L;
2426 2423 error = 0;
2427 2424 break;
2428 2425 default:
2429 2426 error = fs_pathconf(vp, cmd, valp, cr, ct);
2430 2427 }
2431 2428 return (error);
2432 2429 }
2433 2430
2434 2431
2435 2432 struct vnodeops *tmp_vnodeops;
2436 2433
2437 2434 const fs_operation_def_t tmp_vnodeops_template[] = {
2438 2435 VOPNAME_OPEN, { .vop_open = tmp_open },
2439 2436 VOPNAME_CLOSE, { .vop_close = tmp_close },
2440 2437 VOPNAME_READ, { .vop_read = tmp_read },
2441 2438 VOPNAME_WRITE, { .vop_write = tmp_write },
2442 2439 VOPNAME_IOCTL, { .vop_ioctl = tmp_ioctl },
2443 2440 VOPNAME_GETATTR, { .vop_getattr = tmp_getattr },
2444 2441 VOPNAME_SETATTR, { .vop_setattr = tmp_setattr },
2445 2442 VOPNAME_ACCESS, { .vop_access = tmp_access },
2446 2443 VOPNAME_LOOKUP, { .vop_lookup = tmp_lookup },
2447 2444 VOPNAME_CREATE, { .vop_create = tmp_create },
2448 2445 VOPNAME_REMOVE, { .vop_remove = tmp_remove },
2449 2446 VOPNAME_LINK, { .vop_link = tmp_link },
2450 2447 VOPNAME_RENAME, { .vop_rename = tmp_rename },
2451 2448 VOPNAME_MKDIR, { .vop_mkdir = tmp_mkdir },
2452 2449 VOPNAME_RMDIR, { .vop_rmdir = tmp_rmdir },
2453 2450 VOPNAME_READDIR, { .vop_readdir = tmp_readdir },
2454 2451 VOPNAME_SYMLINK, { .vop_symlink = tmp_symlink },
2455 2452 VOPNAME_READLINK, { .vop_readlink = tmp_readlink },
2456 2453 VOPNAME_FSYNC, { .vop_fsync = tmp_fsync },
2457 2454 VOPNAME_INACTIVE, { .vop_inactive = tmp_inactive },
2458 2455 VOPNAME_FID, { .vop_fid = tmp_fid },
2459 2456 VOPNAME_RWLOCK, { .vop_rwlock = tmp_rwlock },
2460 2457 VOPNAME_RWUNLOCK, { .vop_rwunlock = tmp_rwunlock },
2461 2458 VOPNAME_SEEK, { .vop_seek = tmp_seek },
2462 2459 VOPNAME_SPACE, { .vop_space = tmp_space },
2463 2460 VOPNAME_GETPAGE, { .vop_getpage = tmp_getpage },
2464 2461 VOPNAME_PUTPAGE, { .vop_putpage = tmp_putpage },
2465 2462 VOPNAME_MAP, { .vop_map = tmp_map },
2466 2463 VOPNAME_ADDMAP, { .vop_addmap = tmp_addmap },
2467 2464 VOPNAME_DELMAP, { .vop_delmap = tmp_delmap },
2468 2465 VOPNAME_PATHCONF, { .vop_pathconf = tmp_pathconf },
2469 2466 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
2470 2467 NULL, NULL
2471 2468 };
↓ open down ↓ |
1316 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX