Source-Changes-HG archive

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

[src/trunk]: src/sys Break cdir/rdir/cmask info out of struct filedesc, and p...



details:   https://anonhg.NetBSD.org/src/rev/a77041607d3a
branches:  trunk
changeset: 472503:a77041607d3a
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Fri Apr 30 18:42:58 1999 +0000

description:
Break cdir/rdir/cmask info out of struct filedesc, and put it in a new
substructure, `cwdinfo'.  Implement optional sharing of this substructure.

This is required for clone(2).

diffstat:

 sys/kern/init_main.c    |  14 +++++--
 sys/kern/kern_descrip.c |  93 +++++++++++++++++++++++++++++++++++++++++-------
 sys/kern/kern_fork.c    |   4 +-
 sys/kern/kern_sig.c     |   4 +-
 sys/kern/uipc_usrreq.c  |   6 +-
 sys/kern/vfs_getcwd.c   |  20 +++++-----
 sys/kern/vfs_lookup.c   |  10 ++--
 sys/kern/vfs_syscalls.c |  82 ++++++++++++++++++++++--------------------
 sys/sys/filedesc.h      |  20 +++++++--
 9 files changed, 169 insertions(+), 84 deletions(-)

diffs (truncated from 658 to 300 lines):

diff -r 0ed7963408b4 -r a77041607d3a sys/kern/init_main.c
--- a/sys/kern/init_main.c      Fri Apr 30 18:40:05 1999 +0000
+++ b/sys/kern/init_main.c      Fri Apr 30 18:42:58 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init_main.c,v 1.147 1999/04/25 02:56:30 simonb Exp $   */
+/*     $NetBSD: init_main.c,v 1.148 1999/04/30 18:42:59 thorpej Exp $  */
 
 /*
  * Copyright (c) 1995 Christopher G. Demetriou.  All rights reserved.
@@ -115,6 +115,7 @@
 struct proc proc0;
 struct pcred cred0;
 struct filedesc0 filedesc0;
+struct cwdinfo cwdi0;
 struct plimit limit0;
 struct vmspace vmspace0;
 #ifndef curproc
@@ -256,6 +257,11 @@
        p->p_fd = &filedesc0.fd_fd;
        fdinit1(&filedesc0);
 
+       /* Create the CWD info. */
+       p->p_cwdi = &cwdi0;
+       cwdi0.cwdi_cmask = cmask;
+       cwdi0.cwdi_refcnt = 1;
+
        /* Create the limits structures. */
        p->p_limit = &limit0;
        for (i = 0; i < sizeof(p->p_rlimit)/sizeof(p->p_rlimit[0]); i++)
@@ -375,10 +381,10 @@
         */
        if (VFS_ROOT(mountlist.cqh_first, &rootvnode))
                panic("cannot find root vnode");
-       filedesc0.fd_fd.fd_cdir = rootvnode;
-       VREF(filedesc0.fd_fd.fd_cdir);
+       cwdi0.cwdi_cdir = rootvnode;
+       VREF(cwdi0.cwdi_cdir);
        VOP_UNLOCK(rootvnode, 0);
-       filedesc0.fd_fd.fd_rdir = NULL;
+       cwdi0.cwdi_rdir = NULL;
        uvm_swap_init();
 
        /*
diff -r 0ed7963408b4 -r a77041607d3a sys/kern/kern_descrip.c
--- a/sys/kern/kern_descrip.c   Fri Apr 30 18:40:05 1999 +0000
+++ b/sys/kern/kern_descrip.c   Fri Apr 30 18:42:58 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_descrip.c,v 1.57 1999/03/24 05:51:22 mrg Exp $    */
+/*     $NetBSD: kern_descrip.c,v 1.58 1999/04/30 18:42:59 thorpej Exp $        */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1991, 1993
@@ -70,6 +70,7 @@
 struct filelist filehead;      /* head of list of open files */
 int nfiles;                    /* actual number of open files */
 struct pool file_pool;         /* memory pool for file structures */
+struct pool cwdi_pool;         /* memory pool for cwdinfo structures */
 
 static __inline void fd_used __P((struct filedesc *, int));
 static __inline void fd_unused __P((struct filedesc *, int));
@@ -576,6 +577,8 @@
 
        pool_init(&file_pool, sizeof(struct file), 0, 0, 0, "filepl",
            0, pool_page_alloc_nointr, pool_page_free_nointr, M_FILE);
+       pool_init(&cwdi_pool, sizeof(struct cwdinfo), 0, 0, 0, "cwdipl",
+           0, pool_page_alloc_nointr, pool_page_free_nointr, M_FILEDESC);
 }
 
 /*
@@ -639,6 +642,80 @@
 }
 
 /*
+ * Create an initial cwdinfo structure, using the same current and root
+ * directories as p.
+ */
+struct cwdinfo *
+cwdinit(p)
+       struct proc *p;
+{
+       struct cwdinfo *cwdi;
+       extern int cmask;
+
+       cwdi = pool_get(&cwdi_pool, PR_WAITOK);
+
+       cwdi->cwdi_cdir = p->p_cwdi->cwdi_cdir;
+       VREF(cwdi->cwdi_cdir);
+       cwdi->cwdi_rdir = p->p_cwdi->cwdi_rdir;
+       if (cwdi->cwdi_rdir)
+               VREF(cwdi->cwdi_rdir);
+       cwdi->cwdi_cmask = cmask;
+       cwdi->cwdi_refcnt = 1;
+
+       return (cwdi);
+}
+
+/*
+ * Make p2 share p1's cwdinfo.
+ */
+void
+cwdshare(p1, p2)
+       struct proc *p1, *p2;
+{
+
+       p2->p_cwdi = p1->p_cwdi;
+       p1->p_cwdi->cwdi_refcnt++;
+}
+
+/*
+ * Make this process not share its cwdinfo structure, maintaining
+ * all cwdinfo state.
+ */
+void
+cwdunshare(p)
+       struct proc *p;
+{
+       struct cwdinfo *newcwdi;
+
+       if (p->p_cwdi->cwdi_refcnt == 1)
+               return;
+
+       newcwdi = cwdinit(p);
+       cwdfree(p);
+       p->p_cwdi = newcwdi;
+}
+
+/*
+ * Release a cwdinfo structure.
+ */
+void
+cwdfree(p)
+       struct proc *p;
+{
+       struct cwdinfo *cwdi = p->p_cwdi;
+
+       if (--cwdi->cwdi_refcnt > 0)
+               return;
+
+       p->p_cwdi = NULL;
+
+       vrele(cwdi->cwdi_cdir);
+       if (cwdi->cwdi_rdir)
+               vrele(cwdi->cwdi_rdir);
+       pool_put(&cwdi_pool, cwdi);
+}
+
+/*
  * Create an initial filedesc structure, using the same current and root
  * directories as p.
  */
@@ -647,16 +724,10 @@
        struct proc *p;
 {
        struct filedesc0 *newfdp;
-       struct filedesc *fdp = p->p_fd;
 
        MALLOC(newfdp, struct filedesc0 *, sizeof(struct filedesc0),
            M_FILEDESC, M_WAITOK);
        memset(newfdp, 0, sizeof(struct filedesc0));
-       newfdp->fd_fd.fd_cdir = fdp->fd_cdir;
-       VREF(newfdp->fd_fd.fd_cdir);
-       newfdp->fd_fd.fd_rdir = fdp->fd_rdir;
-       if (newfdp->fd_fd.fd_rdir)
-               VREF(newfdp->fd_fd.fd_rdir);
 
        fdinit1(newfdp);
 
@@ -670,10 +741,8 @@
 fdinit1(newfdp)
        struct filedesc0 *newfdp;
 {
-       extern int cmask;               /* init_main.c */
 
        newfdp->fd_fd.fd_refcnt = 1;
-       newfdp->fd_fd.fd_cmask = cmask;
        newfdp->fd_fd.fd_ofiles = newfdp->fd_dfiles;
        newfdp->fd_fd.fd_ofileflags = newfdp->fd_dfileflags;
        newfdp->fd_fd.fd_nfiles = NDFILE;
@@ -737,9 +806,6 @@
        MALLOC(newfdp, struct filedesc *, sizeof(struct filedesc0),
            M_FILEDESC, M_WAITOK);
        memcpy(newfdp, fdp, sizeof(struct filedesc));
-       VREF(newfdp->fd_cdir);
-       if (newfdp->fd_rdir)
-               VREF(newfdp->fd_rdir);
        newfdp->fd_refcnt = 1;
 
        /*
@@ -800,9 +866,6 @@
        p->p_fd = NULL;
        if (fdp->fd_nfiles > NDFILE)
                FREE(fdp->fd_ofiles, M_FILEDESC);
-       vrele(fdp->fd_cdir);
-       if (fdp->fd_rdir)
-               vrele(fdp->fd_rdir);
        FREE(fdp, M_FILEDESC);
 }
 
diff -r 0ed7963408b4 -r a77041607d3a sys/kern/kern_fork.c
--- a/sys/kern/kern_fork.c      Fri Apr 30 18:40:05 1999 +0000
+++ b/sys/kern/kern_fork.c      Fri Apr 30 18:42:58 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_fork.c,v 1.54 1999/03/24 05:51:23 mrg Exp $       */
+/*     $NetBSD: kern_fork.c,v 1.55 1999/04/30 18:42:59 thorpej Exp $   */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1991, 1993
@@ -276,6 +276,8 @@
                VREF(p2->p_textvp);
 
        p2->p_fd = fdcopy(p1);
+       p2->p_cwdi = cwdinit(p1);
+
        /*
         * If p_limit is still copy-on-write, bump refcnt,
         * otherwise get a copy that won't be modified.
diff -r 0ed7963408b4 -r a77041607d3a sys/kern/kern_sig.c
--- a/sys/kern/kern_sig.c       Fri Apr 30 18:40:05 1999 +0000
+++ b/sys/kern/kern_sig.c       Fri Apr 30 18:42:58 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_sig.c,v 1.87 1999/03/24 05:51:23 mrg Exp $        */
+/*     $NetBSD: kern_sig.c,v 1.88 1999/04/30 18:43:00 thorpej Exp $    */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1991, 1993
@@ -1205,7 +1205,7 @@
         * sure that the directory is still there and that the mount flags
         * allow us to write core dumps there.
         */
-       vp = p->p_fd->fd_cdir;
+       vp = p->p_cwdi->cwdi_cdir;
        if (vp->v_mount == NULL ||
            (vp->v_mount->mnt_flag & MNT_NOCOREDUMP) != 0)
                return (EPERM);
diff -r 0ed7963408b4 -r a77041607d3a sys/kern/uipc_usrreq.c
--- a/sys/kern/uipc_usrreq.c    Fri Apr 30 18:40:05 1999 +0000
+++ b/sys/kern/uipc_usrreq.c    Fri Apr 30 18:42:58 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_usrreq.c,v 1.41 1999/04/21 02:37:07 mrg Exp $     */
+/*     $NetBSD: uipc_usrreq.c,v 1.42 1999/04/30 18:43:00 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -810,7 +810,7 @@
        int f, error = 0;
 
        /* Make sure the recipient should be able to see the descriptors.. */
-       if (p->p_fd->fd_rdir != NULL) {
+       if (p->p_cwdi->cwdi_rdir != NULL) {
                rp = (struct file **)ALIGN(cm + 1);
                for (i = 0; i < nfds; i++) {
                        fp = *rp++;
@@ -823,7 +823,7 @@
                        if (fp->f_type == DTYPE_VNODE) {
                                struct vnode *vp = (struct vnode *)fp->f_data;
                                if ((vp->v_type == VDIR) &&
-                                   !vn_isunder(vp, p->p_fd->fd_rdir, p)) {
+                                   !vn_isunder(vp, p->p_cwdi->cwdi_rdir, p)) {
                                        error = EPERM;
                                        break;
                                }
diff -r 0ed7963408b4 -r a77041607d3a sys/kern/vfs_getcwd.c
--- a/sys/kern/vfs_getcwd.c     Fri Apr 30 18:40:05 1999 +0000
+++ b/sys/kern/vfs_getcwd.c     Fri Apr 30 18:42:58 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vfs_getcwd.c,v 1.5 1999/04/26 20:33:18 is Exp $ */
+/* $NetBSD: vfs_getcwd.c,v 1.6 1999/04/30 18:43:00 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -320,13 +320,13 @@
        int flags;
        struct proc *p;
 {
-       struct filedesc *fdp = p->p_fd;
+       struct cwdinfo *cwdi = p->p_cwdi;
        struct vnode *pvp = NULL;
        char *bp = NULL;
        int error;
        
        if (rvp == NULL) {
-               rvp = fdp->fd_rdir;
+               rvp = cwdi->cwdi_rdir;
                if (rvp == NULL)
                        rvp = rootvnode;
        }
@@ -470,9 +470,9 @@
        struct proc *p1;
        struct proc *p2;
 {
-       struct vnode *r1 = p1->p_fd->fd_rdir;
-       struct vnode *r2 = p2->p_fd->fd_rdir;
-       
+       struct vnode *r1 = p1->p_cwdi->cwdi_rdir;
+       struct vnode *r2 = p2->p_cwdi->cwdi_rdir;
+
        if (r1 == NULL)
                return (r2 == NULL);
        else if (r2 == NULL)
@@ -509,7 +509,7 @@



Home | Main Index | Thread Index | Old Index