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