Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/sys/miscfs/procfs Pull up revisions 1.74-1.76 (via patc...



details:   https://anonhg.NetBSD.org/src/rev/87c8b7201823
branches:  netbsd-1-5
changeset: 491013:87c8b7201823
user:      he <he%NetBSD.org@localhost>
date:      Fri Mar 30 21:50:16 2001 +0000

description:
Pull up revisions 1.74-1.76 (via patch, requested by fvdl):
  Add some required Linux emulation bits to support the Linux
  version of VMware.

diffstat:

 sys/miscfs/procfs/procfs_vnops.c |  111 ++++++++++++++++++++++++++++++++++----
 1 files changed, 97 insertions(+), 14 deletions(-)

diffs (235 lines):

diff -r 67eec3439ea8 -r 87c8b7201823 sys/miscfs/procfs/procfs_vnops.c
--- a/sys/miscfs/procfs/procfs_vnops.c  Fri Mar 30 21:49:49 2001 +0000
+++ b/sys/miscfs/procfs/procfs_vnops.c  Fri Mar 30 21:50:16 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_vnops.c,v 1.70 2000/03/30 02:20:14 simonb Exp $ */
+/*     $NetBSD: procfs_vnops.c,v 1.70.4.1 2001/03/30 21:50:16 he Exp $ */
 
 /*
  * Copyright (c) 1993 Jan-Simon Pendry
@@ -52,6 +52,7 @@
 #include <sys/vnode.h>
 #include <sys/namei.h>
 #include <sys/malloc.h>
+#include <sys/mount.h>
 #include <sys/dirent.h>
 #include <sys/resourcevar.h>
 #include <sys/ptrace.h>
@@ -69,6 +70,8 @@
  *
  */
 
+static int procfs_validfile_linux __P((struct proc *, struct mount *));
+
 /*
  * This is a list of the valid names in the
  * process-specific sub-directories.  It is
@@ -79,7 +82,7 @@
        u_char  pt_namlen;
        char    *pt_name;
        pfstype pt_pfstype;
-       int     (*pt_valid) __P((struct proc *p));
+       int     (*pt_valid) __P((struct proc *, struct mount *));
 } proc_targets[] = {
 #define N(s) sizeof(s)-1, s
        /*        name          type            validp */
@@ -95,10 +98,27 @@
        { DT_REG, N("notepg"),  Pnotepg,        NULL },
        { DT_REG, N("map"),     Pmap,           procfs_validmap },
        { DT_REG, N("cmdline"), Pcmdline,       NULL },
+       { DT_REG, N("exe"),     Pfile,          procfs_validfile_linux },
 #undef N
 };
 static int nproc_targets = sizeof(proc_targets) / sizeof(proc_targets[0]);
 
+/*
+ * List of files in the root directory. Note: the validate function will
+ * be called with p == NULL for these ones.
+ */
+struct proc_target proc_root_targets[] = {
+#define N(s) sizeof(s)-1, s
+       /*        name              type            validp */
+       { DT_REG, N("meminfo"),     Pmeminfo,        procfs_validfile_linux },
+       { DT_REG, N("cpuinfo"),     Pcpuinfo,        procfs_validfile_linux },
+#undef N
+};
+static int nproc_root_targets =
+    sizeof(proc_root_targets) / sizeof(proc_root_targets[0]);
+
+
+
 int    procfs_lookup   __P((void *));
 #define        procfs_create   genfs_eopnotsupp_rele
 #define        procfs_mknod    genfs_eopnotsupp_rele
@@ -539,6 +559,11 @@
                vap->va_uid = procp->p_ucred->cr_uid;
                vap->va_gid = procp->p_ucred->cr_gid;
                break;
+       case Pmeminfo:
+       case Pcpuinfo:
+               vap->va_nlink = 1;
+               vap->va_uid = vap->va_gid = 0;
+               break;
 
        default:
                break;
@@ -618,6 +643,8 @@
        case Pnotepg:
        case Pmap:
        case Pcmdline:
+       case Pmeminfo:
+       case Pcpuinfo:
                vap->va_bytes = vap->va_size = 0;
                break;
 
@@ -707,11 +734,11 @@
        struct vnode **vpp = ap->a_vpp;
        struct vnode *dvp = ap->a_dvp;
        const char *pname = cnp->cn_nameptr;
-       struct proc_target *pt;
+       struct proc_target *pt = NULL;
        struct vnode *fvp;
        pid_t pid;
        struct pfsnode *pfs;
-       struct proc *p;
+       struct proc *p = NULL;
        int i, error, wantpunlock, iscurproc = 0, isself = 0;
 
        *vpp = NULL;
@@ -749,6 +776,25 @@
                        return (error);
                }
 
+               for (i = 0; i < nproc_root_targets; i++) {
+                       pt = &proc_root_targets[i];
+                       if (cnp->cn_namelen == pt->pt_namlen &&
+                           memcmp(pt->pt_name, pname, cnp->cn_namelen) == 0 &&
+                           (pt->pt_valid == NULL ||
+                            (*pt->pt_valid)(p, dvp->v_mount)))
+                               break;
+               }
+
+               if (i != nproc_root_targets) {
+                       error = procfs_allocvp(dvp->v_mount, vpp, 0,
+                           pt->pt_pfstype);
+                       if ((error == 0) && (wantpunlock)) {
+                               VOP_UNLOCK(dvp, 0);
+                               cnp->cn_flags |= PDIRUNLOCK;
+                       }
+                       return (error);
+               }
+
                pid = atopid(pname, cnp->cn_namelen);
                if (pid == NO_PID)
                        break;
@@ -788,14 +834,15 @@
                for (pt = proc_targets, i = 0; i < nproc_targets; pt++, i++) {
                        if (cnp->cn_namelen == pt->pt_namlen &&
                            memcmp(pt->pt_name, pname, cnp->cn_namelen) == 0 &&
-                           (pt->pt_valid == NULL || (*pt->pt_valid)(p)))
+                           (pt->pt_valid == NULL ||
+                            (*pt->pt_valid)(p, dvp->v_mount)))
                                goto found;
                }
                break;
 
        found:
                if (pt->pt_pfstype == Pfile) {
-                       fvp = procfs_findtextvp(p);
+                       fvp = p->p_textvp;
                        /* We already checked that it exists. */
                        VREF(fvp);
                        vn_lock(fvp, LK_EXCLUSIVE | LK_RETRY);
@@ -823,11 +870,23 @@
 }
 
 int
-procfs_validfile(p)
+procfs_validfile(p, mp)
        struct proc *p;
+       struct mount *mp;
 {
+       return (p->p_textvp != NULL);
+}
 
-       return (procfs_findtextvp(p) != NULLVP);
+static int
+procfs_validfile_linux(p, mp)
+       struct proc *p;
+       struct mount *mp;
+{
+       int flags;
+
+       flags = VFSTOPROC(mp)->pmnt_flags;
+       return ((flags & PROCFSMNT_LINUXCOMPAT) &&
+           (p == NULL || procfs_validfile(p, mp)));
 }
 
 /*
@@ -860,9 +919,12 @@
        off_t i;
        int error;
        off_t *cookies = NULL;
-       int ncookies;
+       int ncookies, left, skip, j;
+       struct vnode *vp;
+       struct proc_target *pt;
 
-       pfs = VTOPFS(ap->a_vp);
+       vp = ap->a_vp;
+       pfs = VTOPFS(vp);
 
        if (uio->uio_resid < UIO_MX)
                return (EINVAL);
@@ -883,7 +945,6 @@
         */
        case Pproc: {
                struct proc *p;
-               struct proc_target *pt;
 
                if (i >= nproc_targets)
                        return 0;
@@ -901,7 +962,8 @@
 
                for (pt = &proc_targets[i];
                     uio->uio_resid >= UIO_MX && i < nproc_targets; pt++, i++) {
-                       if (pt->pt_valid && (*pt->pt_valid)(p) == 0)
+                       if (pt->pt_valid &&
+                           (*pt->pt_valid)(p, vp->v_mount) == 0)
                                continue;
                        
                        d.d_fileno = PROCFS_FILENO(pfs->pfs_pid, pt->pt_pfstype);
@@ -1008,10 +1070,31 @@
                        goto again;
 #endif
                proclist_unlock_read();
-               ncookies = nc;
 
+               skip = i - pcnt;
+               if (skip >= nproc_root_targets)
+                       break;
+               left = nproc_root_targets - skip;
+               for (j = 0, pt = &proc_root_targets[0];
+                    uio->uio_resid >= UIO_MX && j < left;
+                    pt++, j++, i++) {
+                       if (pt->pt_valid &&
+                           (*pt->pt_valid)(NULL, vp->v_mount) == 0)
+                               continue;
+                       d.d_fileno = PROCFS_FILENO(0, pt->pt_pfstype);
+                       d.d_namlen = pt->pt_namlen;
+                       memcpy(d.d_name, pt->pt_name, pt->pt_namlen + 1);
+                       d.d_type = pt->pt_type;
+
+                       if ((error = uiomove((caddr_t)&d, UIO_MX, uio)) != 0)
+                               break;
+                       nc++;
+                       if (cookies)
+                               *cookies++ = i + 1;
+               }
+
+               ncookies = nc;
                break;
-
        }
 
        default:



Home | Main Index | Thread Index | Old Index