Revert "Update the atime when mmap'ing a file"
[dragonfly.git] / sys / vm / vm_mmap.c
index 1bbc4a7..d2b93c3 100644 (file)
@@ -39,7 +39,7 @@
  *
  *     @(#)vm_mmap.c   8.4 (Berkeley) 1/12/94
  * $FreeBSD: src/sys/vm/vm_mmap.c,v 1.108.2.6 2002/07/02 20:06:19 dillon Exp $
- * $DragonFly: src/sys/vm/vm_mmap.c,v 1.37 2006/12/28 18:29:08 dillon Exp $
+ * $DragonFly: src/sys/vm/vm_mmap.c,v 1.39 2007/04/30 07:18:57 dillon Exp $
  */
 
 /*
@@ -53,6 +53,7 @@
 #include <sys/filedesc.h>
 #include <sys/kern_syscall.h>
 #include <sys/proc.h>
+#include <sys/priv.h>
 #include <sys/resource.h>
 #include <sys/resourcevar.h>
 #include <sys/vnode.h>
@@ -95,7 +96,7 @@ SYSCTL_INT(_vm, OID_AUTO, vkernel_enable, CTLFLAG_RW, &vkernel_enable, 0, "");
  */
 
 static void vmmapentry_rsrc_init (void *);
-SYSINIT(vmmersrc, SI_SUB_KVM_RSRC, SI_ORDER_FIRST, vmmapentry_rsrc_init, NULL)
+SYSINIT(vmmersrc, SI_BOOT1_POST, SI_ORDER_ANY, vmmapentry_rsrc_init, NULL)
 
 static void
 vmmapentry_rsrc_init(void *dummy)
@@ -229,19 +230,20 @@ kern_mmap(struct vmspace *vms, caddr_t uaddr, size_t ulen,
                        return (EINVAL);
                if (addr + size < addr)
                        return (EINVAL);
+       } else if ((flags & MAP_TRYFIXED) == 0) {
+               /*
+                * XXX for non-fixed mappings where no hint is provided or
+                * the hint would fall in the potential heap space,
+                * place it after the end of the largest possible heap.
+                *
+                * There should really be a pmap call to determine a reasonable
+                * location.
+                */
+               if (addr == 0 ||
+                   (addr >= round_page((vm_offset_t)vms->vm_taddr) &&
+                    addr < round_page((vm_offset_t)vms->vm_daddr + maxdsiz)))
+                       addr = round_page((vm_offset_t)vms->vm_daddr + maxdsiz);
        }
-       /*
-        * XXX for non-fixed mappings where no hint is provided or
-        * the hint would fall in the potential heap space,
-        * place it after the end of the largest possible heap.
-        *
-        * There should really be a pmap call to determine a reasonable
-        * location.
-        */
-       else if (addr == 0 ||
-           (addr >= round_page((vm_offset_t)vms->vm_taddr) &&
-            addr < round_page((vm_offset_t)vms->vm_daddr + maxdsiz)))
-               addr = round_page((vm_offset_t)vms->vm_daddr + maxdsiz);
 
        if (flags & MAP_ANON) {
                /*
@@ -331,7 +333,7 @@ kern_mmap(struct vmspace *vms, caddr_t uaddr, size_t ulen,
                        if (securelevel >= 1)
                                disablexworkaround = 1;
                        else
-                               disablexworkaround = suser(td);
+                               disablexworkaround = priv_check(td, PRIV_ROOT);
                        if (vp->v_type == VCHR && disablexworkaround &&
                            (flags & (MAP_PRIVATE|MAP_COPY))) {
                                error = EINVAL;
@@ -394,7 +396,7 @@ kern_mmap(struct vmspace *vms, caddr_t uaddr, size_t ulen,
         * to make the limit reasonable for threads.
         */
        if (max_proc_mmap && 
-           vms->vm_map.nentries >= max_proc_mmap * vms->vm_refcnt) {
+           vms->vm_map.nentries >= max_proc_mmap * vms->vm_sysref.refcnt) {
                error = ENOMEM;
                goto done;
        }
@@ -908,7 +910,7 @@ sys_mlock(struct mlock_args *uap)
            p->p_rlimit[RLIMIT_MEMLOCK].rlim_cur)
                return (ENOMEM);
 #else
-       error = suser_cred(p->p_ucred, 0);
+       error = priv_check_cred(p->p_ucred, PRIV_ROOT, 0);
        if (error)
                return (error);
 #endif
@@ -960,7 +962,7 @@ sys_munlock(struct munlock_args *uap)
                return (EINVAL);
 
 #ifndef pmap_wired_count
-       error = suser(td);
+       error = priv_check(td, PRIV_ROOT);
        if (error)
                return (error);
 #endif
@@ -982,7 +984,8 @@ vm_mmap(vm_map_t map, vm_offset_t *addr, vm_size_t size, vm_prot_t prot,
 {
        boolean_t fitit;
        vm_object_t object;
-       struct vnode *vp = NULL;
+       struct vnode *vp;
+       struct thread *td = curthread;
        struct proc *p;
        objtype_t type;
        int rv = KERN_SUCCESS;
@@ -1031,10 +1034,11 @@ vm_mmap(vm_map_t map, vm_offset_t *addr, vm_size_t size, vm_prot_t prot,
                /*
                 * Unnamed anonymous regions always start at 0.
                 */
-               if (handle == 0)
+               if (handle == NULL)
                        foff = 0;
+               vp = NULL;
        } else {
-               vp = (struct vnode *) handle;
+               vp = (struct vnode *)handle;
                if (vp->v_type == VCHR) {
                        type = OBJT_DEVICE;
                        handle = (void *)(intptr_t)vp->v_rdev;
@@ -1128,6 +1132,12 @@ vm_mmap(vm_map_t map, vm_offset_t *addr, vm_size_t size, vm_prot_t prot,
                        goto out;
                }
        }
+
+       /*
+        * Set the access time on the vnode
+        */
+       if (vp != NULL)
+               vn_mark_atime(vp, td);
 out:
        switch (rv) {
        case KERN_SUCCESS: