Source-Changes-HG archive

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

[src/netbsd-7]: src Pull up following revision(s) (requested by hannken in ti...



details:   https://anonhg.NetBSD.org/src/rev/c9c63f6c5d9d
branches:  netbsd-7
changeset: 798259:c9c63f6c5d9d
user:      riz <riz%NetBSD.org@localhost>
date:      Sun Aug 17 03:34:02 2014 +0000

description:
Pull up following revision(s) (requested by hannken in ticket #29):
        sbin/mount_ptyfs/mount_ptyfs.8: revision 1.14
        sys/fs/ptyfs/ptyfs_vnops.c: revision 1.48
        sys/fs/ptyfs/ptyfs_vnops.c: revision 1.49
        sys/fs/ptyfs/ptyfs_subr.c: revision 1.30
        sys/fs/ptyfs/ptyfs_subr.c: revision 1.31
        sys/fs/ptyfs/ptyfs_vfsops.c: revision 1.51
        sys/fs/ptyfs/ptyfs_subr.c: revision 1.32
        sys/fs/ptyfs/ptyfs_vfsops.c: revision 1.52
        sys/fs/ptyfs/ptyfs_vfsops.c: revision 1.53
        sys/fs/ptyfs/ptyfs.h: revision 1.13
        sys/fs/ptyfs/ptyfs.h: revision 1.14
Needs HASH_SLIST, not HASH_LIST.
Change ptyfs to vcache.
- Use (type, minor) as key.
- Change ptyfs_allocvp to return a referenced vnode and lock where needed.
- Remove unneeded vnode backpointer ptyfs_vnode.
- Keep a single hashlist for pty nodes to make their attributes persistent.
OK: Christos Zoulas
Overflow if *data_len == OSIZE and args->version >= PTYFS_ARGSVERSION.
Sent on tech-kern@, ok christos@
Adapt to reality -- already open BSD style nodes do not appear on
ptyfs mounts (this changed some months ago).
- Add a map of active controlling ptys per mount and no longer abuse
  the vnode lifecycle.
- No longer set "recycle" on VOP_INACTIVE().
- Make ptyfs_used_get() private to ptyfs_subr.c
- Stop copying device attributes from traditional ptys on first allocation.
- Remove unneeded argument "lwp" from ptyfs_allocvp() and ptyfs_free_get().
OK: Christos Zoulas

diffstat:

 sbin/mount_ptyfs/mount_ptyfs.8 |    7 +-
 sys/fs/ptyfs/ptyfs.h           |   28 +-
 sys/fs/ptyfs/ptyfs_subr.c      |  370 +++++++++++-----------------------------
 sys/fs/ptyfs/ptyfs_vfsops.c    |   89 ++++++++-
 sys/fs/ptyfs/ptyfs_vnops.c     |   59 ++---
 5 files changed, 228 insertions(+), 325 deletions(-)

diffs (truncated from 855 to 300 lines):

diff -r 0e78ef778de1 -r c9c63f6c5d9d sbin/mount_ptyfs/mount_ptyfs.8
--- a/sbin/mount_ptyfs/mount_ptyfs.8    Sun Aug 17 03:26:51 2014 +0000
+++ b/sbin/mount_ptyfs/mount_ptyfs.8    Sun Aug 17 03:34:02 2014 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: mount_ptyfs.8,v 1.13 2014/04/04 21:19:35 christos Exp $
+.\"    $NetBSD: mount_ptyfs.8,v 1.13.4.1 2014/08/17 03:34:02 riz Exp $
 .\"
 .\"
 .\" Copyright (c) 2004, 2014 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd April 4, 2014
+.Dd August 13, 2014
 .Dt MOUNT_PTYFS 8
 .Os
 .Sh NAME
@@ -57,8 +57,7 @@
 .Pp
 The filesystem contains pseudo-terminal slave device nodes which are
 allocated dynamically via
-.Xr ptm 4 ,
-or they are already open via traditional BSD style ptys.
+.Xr ptm 4 .
 .Pp
 The options are as follows:
 .Bl -tag -width indent
diff -r 0e78ef778de1 -r c9c63f6c5d9d sys/fs/ptyfs/ptyfs.h
--- a/sys/fs/ptyfs/ptyfs.h      Sun Aug 17 03:26:51 2014 +0000
+++ b/sys/fs/ptyfs/ptyfs.h      Sun Aug 17 03:34:02 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ptyfs.h,v 1.12 2014/04/04 18:10:29 christos Exp $      */
+/*     $NetBSD: ptyfs.h,v 1.12.4.1 2014/08/17 03:34:02 riz Exp $       */
 
 /*
  * Copyright (c) 1993
@@ -87,11 +87,15 @@
 /*
  * control data for the proc file system.
  */
+struct ptyfskey {
+       ptyfstype       ptk_type;       /* type of ptyfs node */
+       int             ptk_pty;        /* the pty index */
+};
 struct ptyfsnode {
-       LIST_ENTRY(ptyfsnode) ptyfs_hash;       /* hash chain */
-       struct vnode    *ptyfs_vnode;   /* vnode associated with this ptyfsnode */
-       ptyfstype       ptyfs_type;     /* type of ptyfs node */
-       int             ptyfs_pty;      /* the pty index */
+       SLIST_ENTRY(ptyfsnode) ptyfs_hash;      /* hash chain */
+       struct ptyfskey ptyfs_key;
+#define ptyfs_type     ptyfs_key.ptk_type
+#define ptyfs_pty      ptyfs_key.ptk_pty
        u_long          ptyfs_fileno;   /* unique file id */
        int             ptyfs_status;   /* status flag for times */
 #define        PTYFS_ACCESS    1
@@ -106,11 +110,14 @@
 };
 
 struct ptyfsmount {
+       kmutex_t pmnt_lock;
        TAILQ_ENTRY(ptyfsmount) pmnt_le;
        struct mount *pmnt_mp;
        gid_t pmnt_gid;
        mode_t pmnt_mode;
        int pmnt_flags;
+       int pmnt_bitmap_size;
+       uint8_t *pmnt_bitmap;
 };
 
 #define VFSTOPTY(mp)   ((struct ptyfsmount *)(mp)->mnt_data)
@@ -147,15 +154,14 @@
  * Convert between ptyfsnode vnode
  */
 #define VTOPTYFS(vp)   ((struct ptyfsnode *)(vp)->v_data)
-#define PTYFSTOV(ptyfs)        ((ptyfs)->ptyfs_vnode)
 
-int ptyfs_freevp(struct vnode *);
-struct vnode *ptyfs_used_get(ptyfstype, int, struct mount *, int);
-int ptyfs_allocvp(struct mount *, struct vnode **, ptyfstype, int,
-    struct lwp *);
+void ptyfs_set_active(struct mount *, int);
+void ptyfs_clr_active(struct mount *, int);
+int ptyfs_next_active(struct mount *, int);
+int ptyfs_allocvp(struct mount *, struct vnode **, ptyfstype, int);
 void ptyfs_hashinit(void);
-void ptyfs_hashreinit(void);
 void ptyfs_hashdone(void);
+struct ptyfsnode *ptyfs_get_node(ptyfstype, int);
 void ptyfs_itimes(struct ptyfsnode *, const struct timespec *,
     const struct timespec *, const struct timespec *);
 
diff -r 0e78ef778de1 -r c9c63f6c5d9d sys/fs/ptyfs/ptyfs_subr.c
--- a/sys/fs/ptyfs/ptyfs_subr.c Sun Aug 17 03:26:51 2014 +0000
+++ b/sys/fs/ptyfs/ptyfs_subr.c Sun Aug 17 03:34:02 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ptyfs_subr.c,v 1.29 2014/03/27 17:31:56 christos Exp $ */
+/*     $NetBSD: ptyfs_subr.c,v 1.29.4.1 2014/08/17 03:34:02 riz Exp $  */
 
 /*
  * Copyright (c) 1993
@@ -73,7 +73,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ptyfs_subr.c,v 1.29 2014/03/27 17:31:56 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ptyfs_subr.c,v 1.29.4.1 2014/08/17 03:34:02 riz Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -92,180 +92,29 @@
 #include <sys/lwp.h>
 
 #include <fs/ptyfs/ptyfs.h>
-#include <miscfs/specfs/specdev.h>
 
 static kmutex_t ptyfs_hashlock;
 
-static LIST_HEAD(ptyfs_hashhead, ptyfsnode) *ptyfs_used_tbl, *ptyfs_free_tbl;
-static u_long ptyfs_used_mask, ptyfs_free_mask; /* size of hash table - 1 */
-static kmutex_t ptyfs_used_slock, ptyfs_free_slock;
-
-static void ptyfs_getinfo(struct ptyfsnode *, struct lwp *);
-
-static void ptyfs_hashins(struct ptyfsnode *);
-static void ptyfs_hashrem(struct ptyfsnode *);
-
-static struct ptyfsnode *ptyfs_free_get(ptyfstype, int, struct lwp *);
-
-static void ptyfs_rehash(kmutex_t *, struct ptyfs_hashhead **,
-    u_long *);
-
-#define PTYHASH(type, pty, mask) (PTYFS_FILENO(type, pty) % (mask + 1))
-
-
-static void
-ptyfs_getinfo(struct ptyfsnode *ptyfs, struct lwp *l)
-{
-       extern struct ptm_pty *ptyfs_save_ptm;
-
-       if (ptyfs->ptyfs_type == PTYFSroot) {
-               ptyfs->ptyfs_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|
-                   S_IROTH|S_IXOTH;
-               goto out;
-       } else
-               ptyfs->ptyfs_mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|
-                   S_IROTH|S_IWOTH;
-
-       if (ptyfs_save_ptm != NULL) {
-               int error;
-               struct pathbuf *pb;
-               struct nameidata nd;
-               char ttyname[64];
-               kauth_cred_t cred;
-               struct vattr va;
-
-               /*
-                * We support traditional ptys, so we copy the info
-                * from the inode
-                */
-               if ((error = (*ptyfs_save_ptm->makename)(
-                       NULL, l, ttyname, sizeof(ttyname),
-                       ptyfs->ptyfs_pty, ptyfs->ptyfs_type == PTYFSpts ? 't'
-                       : 'p')) != 0)
-                               goto out;
-               pb = pathbuf_create(ttyname);
-               if (pb == NULL) {
-                       error = ENOMEM;
-                       goto out;
-               }
-               NDINIT(&nd, LOOKUP, NOFOLLOW|LOCKLEAF, pb);
-               if ((error = namei(&nd)) != 0) {
-                       pathbuf_destroy(pb);
-                       goto out;
-               }
-               cred = kauth_cred_alloc();
-               error = VOP_GETATTR(nd.ni_vp, &va, cred);
-               kauth_cred_free(cred);
-               VOP_UNLOCK(nd.ni_vp);
-               vrele(nd.ni_vp);
-               pathbuf_destroy(pb);
-               if (error)
-                       goto out;
-               ptyfs->ptyfs_uid = va.va_uid;
-               ptyfs->ptyfs_gid = va.va_gid;
-               ptyfs->ptyfs_mode = va.va_mode;
-               ptyfs->ptyfs_flags = va.va_flags;
-               ptyfs->ptyfs_birthtime = va.va_birthtime;
-               ptyfs->ptyfs_ctime = va.va_ctime;
-               ptyfs->ptyfs_mtime = va.va_mtime;
-               ptyfs->ptyfs_atime = va.va_atime;
-               return;
-       }
-out:
-       ptyfs->ptyfs_uid = ptyfs->ptyfs_gid = 0;
-       ptyfs->ptyfs_status |= PTYFS_CHANGE;
-       PTYFS_ITIMES(ptyfs, NULL, NULL, NULL);
-       ptyfs->ptyfs_birthtime = ptyfs->ptyfs_mtime =
-           ptyfs->ptyfs_atime = ptyfs->ptyfs_ctime;
-       ptyfs->ptyfs_flags = 0;
-}
-
+static SLIST_HEAD(ptyfs_hashhead, ptyfsnode) *ptyfs_node_tbl;
+static u_long ptyfs_node_mask; /* size of hash table - 1 */
 
 /*
- * allocate a ptyfsnode/vnode pair.  the vnode is
- * referenced, and locked.
+ * allocate a ptyfsnode/vnode pair.  the vnode is referenced.
  *
  * the pty, ptyfs_type, and mount point uniquely
  * identify a ptyfsnode.  the mount point is needed
  * because someone might mount this filesystem
  * twice.
- *
- * all ptyfsnodes are maintained on a singly-linked
- * list.  new nodes are only allocated when they cannot
- * be found on this list.  entries on the list are
- * removed when the vfs reclaim entry is called.
- *
- * a single lock is kept for the entire list.  this is
- * needed because the getnewvnode() function can block
- * waiting for a vnode to become free, in which case there
- * may be more than one ptyess trying to get the same
- * vnode.  this lock is only taken if we are going to
- * call getnewvnode, since the kernel itself is single-threaded.
- *
- * if an entry is found on the list, then call vget() to
- * take a reference.  this is done because there may be
- * zero references to it and so it needs to removed from
- * the vnode free list.
  */
 int
-ptyfs_allocvp(struct mount *mp, struct vnode **vpp, ptyfstype type, int pty,
-    struct lwp *l)
+ptyfs_allocvp(struct mount *mp, struct vnode **vpp, ptyfstype type, int pty)
 {
-       struct ptyfsnode *ptyfs;
-       struct vnode *vp;
-       int error;
-
- retry:
-       if ((*vpp = ptyfs_used_get(type, pty, mp, LK_EXCLUSIVE)) != NULL)
-               return 0;
-
-       error = getnewvnode(VT_PTYFS, mp, ptyfs_vnodeop_p, NULL, &vp);
-       if (error) {
-               *vpp = NULL;
-               return error;
-       }
-
-       mutex_enter(&ptyfs_hashlock);
-       if (ptyfs_used_get(type, pty, mp, 0) != NULL) {
-               mutex_exit(&ptyfs_hashlock);
-               ungetnewvnode(vp);
-               goto retry;
-       }
-
-       vp->v_data = ptyfs = ptyfs_free_get(type, pty, l);
-       ptyfs->ptyfs_vnode = vp;
+       struct ptyfskey key;
 
-       switch (type) {
-       case PTYFSroot: /* /pts = dr-xr-xr-x */
-               vp->v_type = VDIR;
-               vp->v_vflag = VV_ROOT;
-               break;
-
-       case PTYFSpts:  /* /pts/N = cxxxxxxxxx */
-       case PTYFSptc:  /* controlling side = cxxxxxxxxx */
-               vp->v_type = VCHR;
-               spec_node_init(vp, PTYFS_MAKEDEV(ptyfs));
-               break;
-       default:
-               panic("ptyfs_allocvp");
-       }
-
-       ptyfs_hashins(ptyfs);
-       uvm_vnp_setsize(vp, 0);
-       mutex_exit(&ptyfs_hashlock);
-
-       *vpp = vp;
-       return 0;
-}
-
-int
-ptyfs_freevp(struct vnode *vp)
-{
-       struct ptyfsnode *ptyfs = VTOPTYFS(vp);
-
-       ptyfs_hashrem(ptyfs);
-       vp->v_data = NULL;
-       return 0;
+       memset(&key, 0, sizeof(key));
+       key.ptk_pty = pty;
+       key.ptk_type = type;
+       return vcache_get(mp, &key, sizeof(key), vpp);
 }
 



Home | Main Index | Thread Index | Old Index