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