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