revamp locking to be done at the file table level
authorSam Leffler <sam@ucbvax.Berkeley.EDU>
Tue, 14 Jun 1983 16:37:13 +0000 (08:37 -0800)
committerSam Leffler <sam@ucbvax.Berkeley.EDU>
Tue, 14 Jun 1983 16:37:13 +0000 (08:37 -0800)
SCCS-vsn: sys/kern/kern_descrip.c 5.26
SCCS-vsn: sys/kern/kern_exec.c 4.4
SCCS-vsn: sys/kern/kern_exit.c 4.4
SCCS-vsn: sys/kern/kern_fork.c 4.3

usr/src/sys/kern/kern_descrip.c
usr/src/sys/kern/kern_exec.c
usr/src/sys/kern/kern_exit.c
usr/src/sys/kern/kern_fork.c

index 188d77e..f76b974 100644 (file)
@@ -1,4 +1,4 @@
-/*     kern_descrip.c  5.25    83/06/12        */
+/*     kern_descrip.c  5.26    83/06/14        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -84,30 +84,22 @@ dup2()
        if (u.u_ofile[uap->j]) {
                if (u.u_pofile[uap->j] & UF_MAPPED)
                        munmapfd(uap->j);
        if (u.u_ofile[uap->j]) {
                if (u.u_pofile[uap->j] & UF_MAPPED)
                        munmapfd(uap->j);
-               closef(u.u_ofile[uap->j], u.u_pofile[uap->j]);
+               closef(u.u_ofile[uap->j]);
                if (u.u_error)
                        return;
                if (u.u_error)
                        return;
-               /* u.u_ofile[uap->j] = 0; */
-               /* u.u_pofile[uap->j] = 0; */
        }
        dupit(uap->j, fp, u.u_pofile[uap->i]);
 }
 
        }
        dupit(uap->j, fp, u.u_pofile[uap->i]);
 }
 
-dupit(fd, fp, lockflags)
+dupit(fd, fp, flags)
        int fd;
        register struct file *fp;
        int fd;
        register struct file *fp;
-       register int lockflags;
+       register int flags;
 {
 
        u.u_ofile[fd] = fp;
 {
 
        u.u_ofile[fd] = fp;
-       u.u_pofile[fd] = lockflags;
+       u.u_pofile[fd] = flags;
        fp->f_count++;
        fp->f_count++;
-/* THIS DOESN'T BELONG HERE */
-       if (lockflags&UF_SHLOCK)
-               ((struct inode *)fp->f_data)->i_shlockc++;
-       if (lockflags&UF_EXLOCK)
-               ((struct inode *)fp->f_data)->i_exlockc++;
-/* END DOESN'T BELONG */
 }
 
 /*
 }
 
 /*
@@ -251,8 +243,6 @@ close()
        pf = (u_char *)&u.u_pofile[uap->i];
        if (*pf & UF_MAPPED)
                munmapfd(uap->i);
        pf = (u_char *)&u.u_pofile[uap->i];
        if (*pf & UF_MAPPED)
                munmapfd(uap->i);
-       if (*pf & (UF_SHLOCK|UF_EXLOCK))
-               unlockf(fp, pf);
        closef(fp);
        /* WHAT IF u.u_error ? */
        u.u_ofile[uap->i] = NULL;
        closef(fp);
        /* WHAT IF u.u_error ? */
        u.u_ofile[uap->i] = NULL;
@@ -287,7 +277,8 @@ fstat()
                /*NOTREACHED*/
        }
        if (u.u_error == 0)
                /*NOTREACHED*/
        }
        if (u.u_error == 0)
-               u.u_error = copyout(&ub, uap->sb, sizeof (ub));
+               u.u_error = copyout((caddr_t)&ub, (caddr_t)uap->sb,
+                   sizeof (ub));
 }
 
 /*
 }
 
 /*
@@ -406,59 +397,21 @@ flock()
                int     how;
        } *uap = (struct a *)u.u_ap;
        register struct file *fp;
                int     how;
        } *uap = (struct a *)u.u_ap;
        register struct file *fp;
-       register u_char *pf;
-       int cmd;
 
        fp = getf(uap->fd);
        if (fp == NULL)
                return;
 
        fp = getf(uap->fd);
        if (fp == NULL)
                return;
-       cmd = uap->how;
-       pf = (u_char *)&u.u_pofile[uap->fd];
-       if (cmd & LOCK_UN) {
-               unlockf(fp, pf);
+       if (fp->f_type != DTYPE_INODE) {
+               u.u_error = EOPNOTSUPP;
                return;
        }
                return;
        }
-       /*
-        * No reason to write lock a file we've already
-        * write locked, similarly with a read lock.
-        */
-       if ((*pf & UF_EXLOCK) && (cmd & LOCK_EX) ||
-           (*pf & UF_SHLOCK) && (cmd & LOCK_SH))
+       if (uap->how & LOCK_UN) {
+               ino_unlock(fp, FSHLOCK|FEXLOCK);
                return;
                return;
-       switch (fp->f_type) {
-
-       case DTYPE_INODE:
-               u.u_error = ino_lock((struct inode *)fp->f_data, pf, cmd);
-               break;
-
-       case DTYPE_SOCKET:
-               u.u_error = soo_lock((struct socket *)fp->f_data, pf, cmd);
-               break;
-
-       default:
-               panic("lockf");
        }
        }
-}
-
-unlockf(fp, pf)
-       register struct file *fp;
-       register u_char *pf;
-{
-
-       if ((*pf & (UF_SHLOCK|UF_EXLOCK)) == 0)
+       /* avoid work... */
+       if ((fp->f_flag & FEXLOCK) && (uap->how & LOCK_EX) ||
+           (fp->f_flag & FSHLOCK) && (uap->how & LOCK_SH))
                return;
                return;
-       switch (fp->f_type) {
-
-       case DTYPE_INODE:
-               ino_unlock((struct inode *)fp->f_data, *pf);
-               break;
-
-       case DTYPE_SOCKET:
-               soo_unlock((struct socket *)fp->f_data, *pf);
-               break;
-
-       default:
-               panic("unlockf");
-       }
-       *pf &= ~(UF_SHLOCK|UF_EXLOCK);
+       u.u_error = ino_lock(fp, uap->how);
 }
 }
index bdd3c7d..3d4df75 100644 (file)
@@ -1,4 +1,4 @@
-/*     kern_exec.c     4.3     83/06/12        */
+/*     kern_exec.c     4.4     83/06/14        */
 
 #include "../machine/reg.h"
 #include "../machine/pte.h"
 
 #include "../machine/reg.h"
 #include "../machine/pte.h"
@@ -435,7 +435,7 @@ setregs()
 #endif
        for (i=0; i<NOFILE; i++) {
                if (u.u_pofile[i]&UF_EXCLOSE) {
 #endif
        for (i=0; i<NOFILE; i++) {
                if (u.u_pofile[i]&UF_EXCLOSE) {
-                       closef(u.u_ofile[i], u.u_pofile[i]);
+                       closef(u.u_ofile[i]);
                        u.u_ofile[i] = NULL;
                        u.u_pofile[i] = 0;
                }
                        u.u_ofile[i] = NULL;
                        u.u_pofile[i] = 0;
                }
index b27ca3b..2e84e5e 100644 (file)
@@ -1,4 +1,4 @@
-/*     kern_exit.c     4.3     83/06/02        */
+/*     kern_exit.c     4.4     83/06/14        */
 
 #include "../machine/reg.h"
 #include "../machine/psl.h"
 
 #include "../machine/reg.h"
 #include "../machine/psl.h"
@@ -79,7 +79,7 @@ exit(rv)
                u.u_ofile[i] = NULL;
                po = u.u_pofile[i];
                u.u_pofile[i] = 0;
                u.u_ofile[i] = NULL;
                po = u.u_pofile[i];
                u.u_pofile[i] = 0;
-               closef(f, po);
+               closef(f);
        }
        ilock(u.u_cdir);
        iput(u.u_cdir);
        }
        ilock(u.u_cdir);
        iput(u.u_cdir);
index 9c7fe94..06bf351 100644 (file)
@@ -1,4 +1,4 @@
-/*     kern_fork.c     4.2     83/06/02        */
+/*     kern_fork.c     4.3     83/06/14        */
 
 #include "../machine/reg.h"
 #include "../machine/pte.h"
 
 #include "../machine/reg.h"
 #include "../machine/pte.h"
@@ -188,10 +188,6 @@ retry:
                if (fp == NULL)
                        continue;
                fp->f_count++;
                if (fp == NULL)
                        continue;
                fp->f_count++;
-               if (u.u_pofile[n]&UF_SHLOCK)
-                       ((struct inode *)fp->f_data)->i_shlockc++;
-               if (u.u_pofile[n]&UF_EXLOCK)
-                       ((struct inode *)fp->f_data)->i_exlockc++;
        }
        u.u_cdir->i_count++;
        if (u.u_rdir)
        }
        u.u_cdir->i_count++;
        if (u.u_rdir)