Deleted Added
full compact
tmpfs_vnops.c (171087) tmpfs_vnops.c (171308)
1/* $NetBSD: tmpfs_vnops.c,v 1.35 2007/01/04 15:42:37 elad Exp $ */
2
3/*
4 * Copyright (c) 2005 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Julio M. Merino Vidal, developed as part of Google's Summer of Code

--- 27 unchanged lines hidden (view full) ---

36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40/*
41 * tmpfs vnode interface.
42 */
43#include <sys/cdefs.h>
1/* $NetBSD: tmpfs_vnops.c,v 1.35 2007/01/04 15:42:37 elad Exp $ */
2
3/*
4 * Copyright (c) 2005 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Julio M. Merino Vidal, developed as part of Google's Summer of Code

--- 27 unchanged lines hidden (view full) ---

36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40/*
41 * tmpfs vnode interface.
42 */
43#include <sys/cdefs.h>
44__FBSDID("$FreeBSD: head/sys/fs/tmpfs/tmpfs_vnops.c 171087 2007-06-29 05:23:15Z delphij $");
44__FBSDID("$FreeBSD: head/sys/fs/tmpfs/tmpfs_vnops.c 171308 2007-07-08 15:56:12Z delphij $");
45
46#include <sys/param.h>
47#include <sys/fcntl.h>
48#include <sys/lockf.h>
49#include <sys/namei.h>
50#include <sys/priv.h>
51#include <sys/proc.h>
52#include <sys/resourcevar.h>

--- 392 unchanged lines hidden (view full) ---

445 struct uio *uio, vm_object_t uobj)
446{
447 struct sf_buf *sf;
448 vm_pindex_t idx;
449 vm_offset_t d;
450 vm_page_t m;
451 size_t len;
452 int error = 0;
45
46#include <sys/param.h>
47#include <sys/fcntl.h>
48#include <sys/lockf.h>
49#include <sys/namei.h>
50#include <sys/priv.h>
51#include <sys/proc.h>
52#include <sys/resourcevar.h>

--- 392 unchanged lines hidden (view full) ---

445 struct uio *uio, vm_object_t uobj)
446{
447 struct sf_buf *sf;
448 vm_pindex_t idx;
449 vm_offset_t d;
450 vm_page_t m;
451 size_t len;
452 int error = 0;
453 int behind = 0, ahead = 0;
453
454 /* uobj - locked by caller */
455
456 VM_OBJECT_LOCK(uobj);
457 vm_object_pip_add(uobj, 1);
458 while (error == 0 && uio->uio_resid > 0) {
459 if (node->tn_size <= uio->uio_offset)
460 break;
461
462 len = MIN(node->tn_size - uio->uio_offset, uio->uio_resid);
463 if (len == 0)
464 break;
465
466 idx = OFF_TO_IDX(uio->uio_offset);
467 d = uio->uio_offset - IDX_TO_OFF(idx);
468 len = MIN(len, (PAGE_SIZE - d));
469 m = vm_page_grab(uobj, idx, VM_ALLOC_WIRED | VM_ALLOC_ZERO |
470 VM_ALLOC_NORMAL | VM_ALLOC_RETRY);
454
455 /* uobj - locked by caller */
456
457 VM_OBJECT_LOCK(uobj);
458 vm_object_pip_add(uobj, 1);
459 while (error == 0 && uio->uio_resid > 0) {
460 if (node->tn_size <= uio->uio_offset)
461 break;
462
463 len = MIN(node->tn_size - uio->uio_offset, uio->uio_resid);
464 if (len == 0)
465 break;
466
467 idx = OFF_TO_IDX(uio->uio_offset);
468 d = uio->uio_offset - IDX_TO_OFF(idx);
469 len = MIN(len, (PAGE_SIZE - d));
470 m = vm_page_grab(uobj, idx, VM_ALLOC_WIRED | VM_ALLOC_ZERO |
471 VM_ALLOC_NORMAL | VM_ALLOC_RETRY);
471 if (uio->uio_rw == UIO_READ && m->valid != VM_PAGE_BITS_ALL)
472 vm_page_zero_invalid(m, TRUE);
472 if (m->valid != VM_PAGE_BITS_ALL){
473 if (vm_pager_has_page(uobj, idx, &behind, &ahead)){
474 error = vm_pager_get_pages(uobj, &m, 1, 0);
475 if (error == VM_PAGER_ERROR){
476 printf("vm_pager_get_pages error\n");
477 goto out;
478 }
479#ifdef DIAGNOSTIC
480 /* XXX */
481 printf("tmpfs gets page from pager\n");
482#endif
483 } else {
484 vm_page_zero_invalid(m, TRUE);
485 }
486 }
473 VM_OBJECT_UNLOCK(uobj);
474 sched_pin();
475 sf = sf_buf_alloc(m, SFB_CPUPRIVATE);
476 error = uiomove((void *)(sf_buf_kva(sf) + d), len, uio);
477 sf_buf_free(sf);
478 sched_unpin();
479 VM_OBJECT_LOCK(uobj);
480 vm_page_lock_queues();
481 if (error == 0 && uio->uio_rw == UIO_WRITE) {
482 vm_page_set_validclean(m, d, len);
483 vm_page_zero_invalid(m, TRUE);
484 vm_page_dirty(m);
485 }
486 vm_page_unwire(m, 0);
487 vm_page_activate(m);
488 vm_page_wakeup(m);
489 vm_page_unlock_queues();
490 }
487 VM_OBJECT_UNLOCK(uobj);
488 sched_pin();
489 sf = sf_buf_alloc(m, SFB_CPUPRIVATE);
490 error = uiomove((void *)(sf_buf_kva(sf) + d), len, uio);
491 sf_buf_free(sf);
492 sched_unpin();
493 VM_OBJECT_LOCK(uobj);
494 vm_page_lock_queues();
495 if (error == 0 && uio->uio_rw == UIO_WRITE) {
496 vm_page_set_validclean(m, d, len);
497 vm_page_zero_invalid(m, TRUE);
498 vm_page_dirty(m);
499 }
500 vm_page_unwire(m, 0);
501 vm_page_activate(m);
502 vm_page_wakeup(m);
503 vm_page_unlock_queues();
504 }
505out:
491 vm_object_pip_subtract(uobj, 1);
492 VM_OBJECT_UNLOCK(uobj);
493 return error;
494}
495
496static int
497tmpfs_read(struct vop_read_args *v)
498{

--- 176 unchanged lines hidden (view full) ---

675tmpfs_link(struct vop_link_args *v)
676{
677 struct vnode *dvp = v->a_tdvp;
678 struct vnode *vp = v->a_vp;
679 struct componentname *cnp = v->a_cnp;
680
681 int error;
682 struct tmpfs_dirent *de;
506 vm_object_pip_subtract(uobj, 1);
507 VM_OBJECT_UNLOCK(uobj);
508 return error;
509}
510
511static int
512tmpfs_read(struct vop_read_args *v)
513{

--- 176 unchanged lines hidden (view full) ---

690tmpfs_link(struct vop_link_args *v)
691{
692 struct vnode *dvp = v->a_tdvp;
693 struct vnode *vp = v->a_vp;
694 struct componentname *cnp = v->a_cnp;
695
696 int error;
697 struct tmpfs_dirent *de;
683 struct tmpfs_node *dnode;
684 struct tmpfs_node *node;
685
686 MPASS(VOP_ISLOCKED(dvp, cnp->cn_thread));
687 MPASS(cnp->cn_flags & HASBUF);
688 MPASS(dvp != vp); /* XXX When can this be false? */
689
698 struct tmpfs_node *node;
699
700 MPASS(VOP_ISLOCKED(dvp, cnp->cn_thread));
701 MPASS(cnp->cn_flags & HASBUF);
702 MPASS(dvp != vp); /* XXX When can this be false? */
703
690 dnode = VP_TO_TMPFS_DIR(dvp);
691 node = VP_TO_TMPFS_NODE(vp);
692
693 /* XXX: Why aren't the following two tests done by the caller? */
694
695 /* Hard links of directories are forbidden. */
696 if (vp->v_type == VDIR) {
697 error = EPERM;
698 goto out;

--- 49 unchanged lines hidden (view full) ---

748 struct vnode *tdvp = v->a_tdvp;
749 struct vnode *tvp = v->a_tvp;
750 struct componentname *tcnp = v->a_tcnp;
751 struct tmpfs_node *tnode = 0; /* pacify gcc */
752
753 char *newname;
754 int error;
755 struct tmpfs_dirent *de;
704 node = VP_TO_TMPFS_NODE(vp);
705
706 /* XXX: Why aren't the following two tests done by the caller? */
707
708 /* Hard links of directories are forbidden. */
709 if (vp->v_type == VDIR) {
710 error = EPERM;
711 goto out;

--- 49 unchanged lines hidden (view full) ---

761 struct vnode *tdvp = v->a_tdvp;
762 struct vnode *tvp = v->a_tvp;
763 struct componentname *tcnp = v->a_tcnp;
764 struct tmpfs_node *tnode = 0; /* pacify gcc */
765
766 char *newname;
767 int error;
768 struct tmpfs_dirent *de;
756 struct tmpfs_mount *tmp;
757 struct tmpfs_node *fdnode;
758 struct tmpfs_node *fnode;
759 struct tmpfs_node *tdnode;
760
761 MPASS(VOP_ISLOCKED(tdvp, tcnp->cn_thread));
762 MPASS(IMPLIES(tvp != NULL, VOP_ISLOCKED(tvp, tcnp->cn_thread)));
763 MPASS(fcnp->cn_flags & HASBUF);
764 MPASS(tcnp->cn_flags & HASBUF);

--- 5 unchanged lines hidden (view full) ---

770 /* Disallow cross-device renames.
771 * XXX Why isn't this done by the caller? */
772 if (fvp->v_mount != tdvp->v_mount ||
773 (tvp != NULL && fvp->v_mount != tvp->v_mount)) {
774 error = EXDEV;
775 goto out;
776 }
777
769 struct tmpfs_node *fdnode;
770 struct tmpfs_node *fnode;
771 struct tmpfs_node *tdnode;
772
773 MPASS(VOP_ISLOCKED(tdvp, tcnp->cn_thread));
774 MPASS(IMPLIES(tvp != NULL, VOP_ISLOCKED(tvp, tcnp->cn_thread)));
775 MPASS(fcnp->cn_flags & HASBUF);
776 MPASS(tcnp->cn_flags & HASBUF);

--- 5 unchanged lines hidden (view full) ---

782 /* Disallow cross-device renames.
783 * XXX Why isn't this done by the caller? */
784 if (fvp->v_mount != tdvp->v_mount ||
785 (tvp != NULL && fvp->v_mount != tvp->v_mount)) {
786 error = EXDEV;
787 goto out;
788 }
789
778 tmp = VFS_TO_TMPFS(tdvp->v_mount);
779 tdnode = VP_TO_TMPFS_DIR(tdvp);
780
781 /* If source and target are the same file, there is nothing to do. */
782 if (fvp == tvp) {
783 error = 0;
784 goto out;
785 }
786

--- 574 unchanged lines hidden ---
790 tdnode = VP_TO_TMPFS_DIR(tdvp);
791
792 /* If source and target are the same file, there is nothing to do. */
793 if (fvp == tvp) {
794 error = 0;
795 goto out;
796 }
797

--- 574 unchanged lines hidden ---