Source-Changes-HG archive

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

[src/trunk]: src/sys Add "use counting" to file entries. When closing a file...



details:   https://anonhg.NetBSD.org/src/rev/ad7ced8a7b79
branches:  trunk
changeset: 472728:ad7ced8a7b79
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Wed May 05 20:01:01 1999 +0000

description:
Add "use counting" to file entries.  When closing a file, and it's reference
count is 0, wait for use count to drain before finishing the close.

This is necessary in order for multiple processes to safely share file
descriptor tables.

diffstat:

 sys/compat/common/vfs_syscalls_12.c    |   11 +-
 sys/compat/common/vfs_syscalls_43.c    |   23 +-
 sys/compat/hpux/hpux_net.c             |   46 +++-
 sys/compat/ibcs2/ibcs2_misc.c          |   30 ++-
 sys/compat/ibcs2/ibcs2_stat.c          |   18 +-
 sys/compat/linux/common/linux_misc.c   |   19 +-
 sys/compat/linux/common/linux_socket.c |    7 +-
 sys/compat/netbsd32/netbsd32_netbsd.c  |   43 +++-
 sys/compat/osf1/osf1_descrip.c         |   10 +-
 sys/compat/osf1/osf1_mount.c           |   11 +-
 sys/compat/ossaudio/ossaudio.c         |  291 ++++++++++++++++-----------
 sys/compat/sunos/sunos_misc.c          |   46 +++-
 sys/compat/svr4/svr4_misc.c            |   32 ++-
 sys/compat/svr4/svr4_net.c             |    5 +-
 sys/compat/ultrix/ultrix_misc.c        |   22 +-
 sys/compat/ultrix/ultrix_pathname.c    |   10 +-
 sys/kern/exec_script.c                 |    4 +-
 sys/kern/kern_descrip.c                |  341 +++++++++++++++++++++++++-------
 sys/kern/kern_ktrace.c                 |    5 +-
 sys/kern/sys_generic.c                 |   98 +++++++--
 sys/kern/uipc_syscalls.c               |  124 +++++++++--
 sys/kern/uipc_usrreq.c                 |   14 +-
 sys/kern/vfs_syscalls.c                |  202 ++++++++++++++-----
 sys/miscfs/portal/portal_vfsops.c      |    5 +-
 sys/nfs/nfs_syscalls.c                 |    9 +-
 sys/sys/file.h                         |   33 +++-
 26 files changed, 1046 insertions(+), 413 deletions(-)

diffs (truncated from 3782 to 300 lines):

diff -r 7dd08bdaa13d -r ad7ced8a7b79 sys/compat/common/vfs_syscalls_12.c
--- a/sys/compat/common/vfs_syscalls_12.c       Wed May 05 19:52:20 1999 +0000
+++ b/sys/compat/common/vfs_syscalls_12.c       Wed May 05 20:01:01 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_syscalls_12.c,v 1.4 1999/03/30 00:13:57 wrstuden Exp $     */
+/*     $NetBSD: vfs_syscalls_12.c,v 1.5 1999/05/05 20:01:01 thorpej Exp $      */
 
 /*
  * Copyright (c) 1989, 1993
@@ -107,10 +107,13 @@
        int error, done;
        long loff;
 
+       /* getvnode() will use the descriptor for us */
        if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
                return error;
-       if ((fp->f_flag & FREAD) == 0)
-               return (EBADF);
+       if ((fp->f_flag & FREAD) == 0) {
+               error = EBADF;
+               goto out;
+       }
 
        loff = fp->f_offset;
 
@@ -119,6 +122,8 @@
 
        error = copyout(&loff, SCARG(uap, basep), sizeof(long));
        *retval = done;
+ out:
+       FILE_UNUSE(fp, p);
        return error;
 }
 
diff -r 7dd08bdaa13d -r ad7ced8a7b79 sys/compat/common/vfs_syscalls_43.c
--- a/sys/compat/common/vfs_syscalls_43.c       Wed May 05 19:52:20 1999 +0000
+++ b/sys/compat/common/vfs_syscalls_43.c       Wed May 05 20:01:01 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_syscalls_43.c,v 1.11 1999/03/30 00:13:57 wrstuden Exp $    */
+/*     $NetBSD: vfs_syscalls_43.c,v 1.12 1999/05/05 20:01:01 thorpej Exp $     */
 
 /*
  * Copyright (c) 1989, 1993
@@ -378,14 +378,19 @@
        int error, eofflag, readcnt;
        long loff;
 
+       /* getvnode() will use the descriptor for us */
        if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
                return (error);
-       if ((fp->f_flag & FREAD) == 0)
-               return (EBADF);
+       if ((fp->f_flag & FREAD) == 0) {
+               error = EBADF;
+               goto out;
+       }
        vp = (struct vnode *)fp->f_data;
 unionread:
-       if (vp->v_type != VDIR)
-               return (EINVAL);
+       if (vp->v_type != VDIR) {
+               error = EINVAL;
+               goto out;
+       }
        aiov.iov_base = SCARG(uap, buf);
        aiov.iov_len = SCARG(uap, count);
        auio.uio_iov = &aiov;
@@ -449,7 +454,7 @@
        }
        VOP_UNLOCK(vp, 0);
        if (error)
-               return (error);
+               goto out;
 
 #ifdef UNION
 {
@@ -481,13 +486,13 @@
 
                        if (error) {
                                vrele(lvp);
-                               return (error);
+                               goto out;
                        }
                        fp->f_data = (caddr_t) lvp;
                        fp->f_offset = 0;
                        error = vn_close(vp, FREAD, fp->f_cred, p);
                        if (error)
-                               return (error);
+                               goto out;
                        vp = lvp;
                        goto unionread;
                }
@@ -509,5 +514,7 @@
        error = copyout((caddr_t)&loff, (caddr_t)SCARG(uap, basep),
            sizeof(long));
        *retval = SCARG(uap, count) - auio.uio_resid;
+ out:
+       FILE_UNUSE(fp, p);
        return (error);
 }
diff -r 7dd08bdaa13d -r ad7ced8a7b79 sys/compat/hpux/hpux_net.c
--- a/sys/compat/hpux/hpux_net.c        Wed May 05 19:52:20 1999 +0000
+++ b/sys/compat/hpux/hpux_net.c        Wed May 05 20:01:01 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hpux_net.c,v 1.16 1998/10/03 19:47:54 eeh Exp $        */
+/*     $NetBSD: hpux_net.c,v 1.17 1999/05/05 20:01:02 thorpej Exp $    */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -214,16 +214,19 @@
        struct mbuf *m = NULL;
        int tmp, error;
 
+       /* getsock() will use the descriptor for us */
        if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)))
                return (error);
-       if (SCARG(uap, valsize) > MLEN)
-               return (EINVAL);
+       if (SCARG(uap, valsize) > MLEN) {
+               error = EINVAL;
+               goto out;
+       }
        if (SCARG(uap, val)) {
                m = m_get(M_WAIT, MT_SOOPTS);
                if ((error = copyin(SCARG(uap, val), mtod(m, caddr_t),
                    (u_int)SCARG(uap, valsize)))) {
                        (void) m_free(m);
-                       return (error);
+                       goto out;
                }
                if (SCARG(uap, name) == SO_LINGER) {
                        tmp = *mtod(m, int *);
@@ -238,8 +241,12 @@
                mtod(m, struct linger *)->l_onoff = 0;
                m->m_len = sizeof(struct linger);
        }
-       return (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
-           SCARG(uap, name), m));
+
+       error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
+           SCARG(uap, name), m);
+ out:
+       FILE_UNUSE(fp);
+       return (error);
 }
 
 /* ARGSUSED */
@@ -254,21 +261,28 @@
        struct mbuf *m = NULL;
        int error;
 
+       /* getsock() will use the descriptor for us */
        if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)))
                return (error);
-       if (SCARG(uap, valsize) > MLEN)
-               return (EINVAL);
+       if (SCARG(uap, valsize) > MLEN) {
+               error = EINVAL;
+               goto out;
+       }
        if (SCARG(uap, val)) {
                m = m_get(M_WAIT, MT_SOOPTS);
                if ((error = copyin(SCARG(uap, val), mtod(m, caddr_t),
                    (u_int)SCARG(uap, valsize)))) {
                        (void) m_free(m);
-                       return (error);
+                       goto out;
                }
                socksetsize(SCARG(uap, valsize), m);
        }
-       return (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
-           SCARG(uap, name), m));
+
+       error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
+           SCARG(uap, name), m);
+ out:
+       FILE_UNUSE(fp);
+       return (error);
 }
 
 int
@@ -282,12 +296,13 @@
        struct mbuf *m = NULL;
        int valsize, error;
 
+       /* getsock() will use the descriptor for us */
        if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)))
                return (error);
        if (SCARG(uap, val)) {
                if ((error = copyin((caddr_t)SCARG(uap, avalsize),
                    (caddr_t)&valsize, sizeof (valsize))))
-                       return (error);
+                       goto out;
        } else
                valsize = 0;
        if ((error = sogetopt((struct socket *)fp->f_data, SCARG(uap, level),
@@ -296,7 +311,8 @@
        if (SCARG(uap, val) && valsize && m != NULL) {
                if (SCARG(uap, name) == SO_LINGER) {
                        if (mtod(m, struct linger *)->l_onoff)
-                               *mtod(m, int *) = mtod(m, struct linger *)->l_linger;
+                               *mtod(m, int *) =
+                                   mtod(m, struct linger *)->l_linger;
                        else
                                *mtod(m, int *) = 0;
                        m->m_len = sizeof(int);
@@ -309,8 +325,10 @@
                        error = copyout((caddr_t)&valsize,
                            (caddr_t)SCARG(uap, avalsize), sizeof (valsize));
        }
-bad:
+ bad:
        if (m != NULL)
                (void) m_free(m);
+ out:
+       FILE_UNUSE(fp);
        return (error);
 }
diff -r 7dd08bdaa13d -r ad7ced8a7b79 sys/compat/ibcs2/ibcs2_misc.c
--- a/sys/compat/ibcs2/ibcs2_misc.c     Wed May 05 19:52:20 1999 +0000
+++ b/sys/compat/ibcs2/ibcs2_misc.c     Wed May 05 20:01:01 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ibcs2_misc.c,v 1.40 1999/02/09 20:22:37 christos Exp $ */
+/*     $NetBSD: ibcs2_misc.c,v 1.41 1999/05/05 20:01:02 thorpej Exp $  */
 
 /*
  * Copyright (c) 1994, 1995, 1998 Scott Bartram
@@ -368,13 +368,18 @@
        off_t *cookiebuf = NULL, *cookie;
        int ncookies;
 
+       /* getvnode() will use the descriptor for us */
        if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
                return (error);
-       if ((fp->f_flag & FREAD) == 0)
-               return (EBADF);
+       if ((fp->f_flag & FREAD) == 0) {
+               error = EBADF;
+               goto out1;
+       }
        vp = (struct vnode *)fp->f_data;
-       if (vp->v_type != VDIR)
-               return (EINVAL);
+       if (vp->v_type != VDIR) {
+               error = EINVAL;
+               goto out1;
+       }
        buflen = min(MAXBSIZE, SCARG(uap, nbytes));
        buf = malloc(buflen, M_TEMP, M_WAITOK);
        vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
@@ -455,6 +460,8 @@
        if (cookiebuf)
                free(cookiebuf, M_TEMP);
        free(buf, M_TEMP);
+ out1:
+       FILE_UNUSE(fp, p);
        return (error);
 }
 
@@ -487,17 +494,22 @@
        off_t *cookiebuf = NULL, *cookie;
        int ncookies;
 
+       /* getvnode() will use the descriptor for us */
        if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) {
                if (error == EINVAL)
                        return sys_read(p, uap, retval);
                else
                        return error;
        }
-       if ((fp->f_flag & FREAD) == 0)
-               return (EBADF);
+       if ((fp->f_flag & FREAD) == 0) {
+               error = EBADF;
+               goto out1;
+       }
        vp = (struct vnode *)fp->f_data;
-       if (vp->v_type != VDIR)
+       if (vp->v_type != VDIR) {
+               FILE_UNUSE(fp, p);
                return sys_read(p, uap, retval);
+       }
        buflen = min(MAXBSIZE, SCARG(uap, nbytes));
        buf = malloc(buflen, M_TEMP, M_WAITOK);
        vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
@@ -576,6 +588,8 @@
        if (cookiebuf)
                free(cookiebuf, M_TEMP);
        free(buf, M_TEMP);
+ out1:
+       FILE_UNUSE(fp, p);
        return (error);
 }
 
diff -r 7dd08bdaa13d -r ad7ced8a7b79 sys/compat/ibcs2/ibcs2_stat.c
--- a/sys/compat/ibcs2/ibcs2_stat.c     Wed May 05 19:52:20 1999 +0000
+++ b/sys/compat/ibcs2/ibcs2_stat.c     Wed May 05 20:01:01 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ibcs2_stat.c,v 1.11 1999/02/09 20:48:20 christos Exp $ */
+/*     $NetBSD: ibcs2_stat.c,v 1.12 1999/05/05 20:01:03 thorpej Exp $  */



Home | Main Index | Thread Index | Old Index