Module Name:    src
Committed By:   christos
Date:           Thu Mar 27 17:31:56 UTC 2014

Modified Files:
        src/sys/fs/ptyfs: ptyfs_subr.c ptyfs_vfsops.c
        src/sys/kern: tty_bsdpty.c tty_ptm.c tty_pty.c
        src/sys/sys: pty.h

Log Message:
>From Ilya Zykov:
- ifdef out some code that is only used for NO_DEV_PTM
- pass the mountpoint instead of the ptm structure to the implementation
  dependent (ptyfs or bsdpty) functions.
- add a function to return the correct ptyfs mountpoint for the current lwp


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/fs/ptyfs/ptyfs_subr.c
cvs rdiff -u -r1.47 -r1.48 src/sys/fs/ptyfs/ptyfs_vfsops.c
cvs rdiff -u -r1.18 -r1.19 src/sys/kern/tty_bsdpty.c
cvs rdiff -u -r1.30 -r1.31 src/sys/kern/tty_ptm.c
cvs rdiff -u -r1.135 -r1.136 src/sys/kern/tty_pty.c
cvs rdiff -u -r1.8 -r1.9 src/sys/sys/pty.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/fs/ptyfs/ptyfs_subr.c
diff -u src/sys/fs/ptyfs/ptyfs_subr.c:1.28 src/sys/fs/ptyfs/ptyfs_subr.c:1.29
--- src/sys/fs/ptyfs/ptyfs_subr.c:1.28	Wed Mar 26 17:28:48 2014
+++ src/sys/fs/ptyfs/ptyfs_subr.c	Thu Mar 27 13:31:56 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ptyfs_subr.c,v 1.28 2014/03/26 21:28:48 christos Exp $	*/
+/*	$NetBSD: ptyfs_subr.c,v 1.29 2014/03/27 17:31:56 christos Exp $	*/
 
 /*
  * Copyright (c) 1993
@@ -73,7 +73,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ptyfs_subr.c,v 1.28 2014/03/26 21:28:48 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ptyfs_subr.c,v 1.29 2014/03/27 17:31:56 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -139,7 +139,7 @@ ptyfs_getinfo(struct ptyfsnode *ptyfs, s
 		 * from the inode
 		 */
 		if ((error = (*ptyfs_save_ptm->makename)(
-			ptyfs_save_ptm, l, ttyname, sizeof(ttyname),
+			NULL, l, ttyname, sizeof(ttyname),
 			ptyfs->ptyfs_pty, ptyfs->ptyfs_type == PTYFSpts ? 't'
 			: 'p')) != 0)
 				goto out;

Index: src/sys/fs/ptyfs/ptyfs_vfsops.c
diff -u src/sys/fs/ptyfs/ptyfs_vfsops.c:1.47 src/sys/fs/ptyfs/ptyfs_vfsops.c:1.48
--- src/sys/fs/ptyfs/ptyfs_vfsops.c:1.47	Sun Mar 23 11:21:15 2014
+++ src/sys/fs/ptyfs/ptyfs_vfsops.c	Thu Mar 27 13:31:56 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ptyfs_vfsops.c,v 1.47 2014/03/23 15:21:15 hannken Exp $	*/
+/*	$NetBSD: ptyfs_vfsops.c,v 1.48 2014/03/27 17:31:56 christos Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993, 1995
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ptyfs_vfsops.c,v 1.47 2014/03/23 15:21:15 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ptyfs_vfsops.c,v 1.48 2014/03/27 17:31:56 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -72,11 +72,11 @@ VFS_PROTOS(ptyfs);
 
 static struct sysctllog *ptyfs_sysctl_log;
 
-static int ptyfs__allocvp(struct ptm_pty *, struct lwp *, struct vnode **,
+static int ptyfs__allocvp(struct mount *, struct lwp *, struct vnode **,
     dev_t, char);
-static int ptyfs__makename(struct ptm_pty *, struct lwp *, char *, size_t,
+static int ptyfs__makename(struct mount *, struct lwp *, char *, size_t,
     dev_t, char);
-static void ptyfs__getvattr(struct ptm_pty *, struct lwp *, struct vattr *);
+static void ptyfs__getvattr(struct mount *, struct lwp *, struct vattr *);
 
 /*
  * ptm glue: When we mount, we make ptm point to us.
@@ -125,10 +125,9 @@ out:
 }
 
 static int
-ptyfs__makename(struct ptm_pty *pt, struct lwp *l, char *tbuf, size_t bufsiz,
+ptyfs__makename(struct mount *mp, struct lwp *l, char *tbuf, size_t bufsiz,
     dev_t dev, char ms)
 {
-	struct mount *mp = pt->arg;
 	size_t len;
 	const char *np;
 
@@ -154,10 +153,9 @@ ptyfs__makename(struct ptm_pty *pt, stru
 
 static int
 /*ARGSUSED*/
-ptyfs__allocvp(struct ptm_pty *pt, struct lwp *l, struct vnode **vpp,
+ptyfs__allocvp(struct mount *mp, struct lwp *l, struct vnode **vpp,
     dev_t dev, char ms)
 {
-	struct mount *mp = pt->arg;
 	ptyfstype type;
 
 	switch (ms) {
@@ -176,9 +174,8 @@ ptyfs__allocvp(struct ptm_pty *pt, struc
 
 
 static void
-ptyfs__getvattr(struct ptm_pty *pt, struct lwp *l, struct vattr *vattr)
+ptyfs__getvattr(struct mount *mp, struct lwp *l, struct vattr *vattr)
 {
-	struct mount *mp = pt->arg;
 	struct ptyfsmount *pmnt = VFSTOPTY(mp);
 	vattr_null(vattr);
 	/* get real uid */

Index: src/sys/kern/tty_bsdpty.c
diff -u src/sys/kern/tty_bsdpty.c:1.18 src/sys/kern/tty_bsdpty.c:1.19
--- src/sys/kern/tty_bsdpty.c:1.18	Wed Mar 26 17:29:54 2014
+++ src/sys/kern/tty_bsdpty.c	Thu Mar 27 13:31:56 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: tty_bsdpty.c,v 1.18 2014/03/26 21:29:54 christos Exp $	*/
+/*	$NetBSD: tty_bsdpty.c,v 1.19 2014/03/27 17:31:56 christos Exp $	*/
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -27,10 +27,11 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tty_bsdpty.c,v 1.18 2014/03/26 21:29:54 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty_bsdpty.c,v 1.19 2014/03/27 17:31:56 christos Exp $");
 
 #include "opt_ptm.h"
 
+#ifndef NO_DEV_PTM
 #ifdef COMPAT_BSDPTY
 /* bsd tty implementation for pty multiplexor driver /dev/ptm{,x} */
 
@@ -68,11 +69,11 @@ __KERNEL_RCSID(0, "$NetBSD: tty_bsdpty.c
 #define TTY_OLD_SUFFIX  "0123456789abcdef"
 #define TTY_NEW_SUFFIX  "ghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
 
-static int pty_makename(struct ptm_pty *, struct lwp *, char *, size_t, dev_t,
+static int pty_makename(struct mount *, struct lwp *, char *, size_t, dev_t,
     char);
-static int pty_allocvp(struct ptm_pty *, struct lwp *, struct vnode **,
+static int pty_allocvp(struct mount *, struct lwp *, struct vnode **,
     dev_t, char);
-static void pty_getvattr(struct ptm_pty *, struct lwp *, struct vattr *);
+static void pty_getvattr(struct mount *, struct lwp *, struct vattr *);
 
 struct ptm_pty ptm_bsdpty = {
 	pty_allocvp,
@@ -83,7 +84,7 @@ struct ptm_pty ptm_bsdpty = {
 
 static int
 /*ARGSUSED*/
-pty_makename(struct ptm_pty *ptm, struct lwp *l, char *bf,
+pty_makename(struct mount *mp, struct lwp *l, char *bf,
     size_t bufsiz, dev_t dev, char c)
 {
 	size_t nt;
@@ -113,7 +114,7 @@ pty_makename(struct ptm_pty *ptm, struct
 
 static int
 /*ARGSUSED*/
-pty_allocvp(struct ptm_pty *ptm, struct lwp *l, struct vnode **vp, dev_t dev,
+pty_allocvp(struct mount *mp, struct lwp *l, struct vnode **vp, dev_t dev,
     char ms)
 {
 	int error;
@@ -121,7 +122,7 @@ pty_allocvp(struct ptm_pty *ptm, struct 
 	struct nameidata nd;
 	char name[TTY_NAMESIZE];
 
-	error = pty_makename(ptm, l, name, sizeof(name), dev, ms);
+	error = pty_makename(NULL, l, name, sizeof(name), dev, ms);
 	if (error)
 		return error;
 
@@ -143,7 +144,7 @@ pty_allocvp(struct ptm_pty *ptm, struct 
 
 static void
 /*ARGSUSED*/
-pty_getvattr(struct ptm_pty *ptm, struct lwp *l, struct vattr *vattr)
+pty_getvattr(struct mount *mp, struct lwp *l, struct vattr *vattr)
 {
 	vattr_null(vattr);
 	/* get real uid */
@@ -151,4 +152,5 @@ pty_getvattr(struct ptm_pty *ptm, struct
 	vattr->va_gid = TTY_GID;
 	vattr->va_mode = TTY_PERM;
 }
-#endif
+#endif /* COMPAT_BSDPTY */
+#endif /* NO_DEV_PTM */

Index: src/sys/kern/tty_ptm.c
diff -u src/sys/kern/tty_ptm.c:1.30 src/sys/kern/tty_ptm.c:1.31
--- src/sys/kern/tty_ptm.c:1.30	Wed Mar 19 14:11:17 2014
+++ src/sys/kern/tty_ptm.c	Thu Mar 27 13:31:56 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: tty_ptm.c,v 1.30 2014/03/19 18:11:17 christos Exp $	*/
+/*	$NetBSD: tty_ptm.c,v 1.31 2014/03/27 17:31:56 christos Exp $	*/
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tty_ptm.c,v 1.30 2014/03/19 18:11:17 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty_ptm.c,v 1.31 2014/03/27 17:31:56 christos Exp $");
 
 #include "opt_compat_netbsd.h"
 #include "opt_ptm.h"
@@ -84,11 +84,39 @@ static struct ptm_pty *ptm;
 int pts_major, ptc_major;
 
 static dev_t pty_getfree(void);
-static int pty_alloc_master(struct lwp *, int *, dev_t *);
-static int pty_alloc_slave(struct lwp *, int *, dev_t);
+static int pty_alloc_master(struct lwp *, int *, dev_t *, struct mount *);
+static int pty_alloc_slave(struct lwp *, int *, dev_t, struct mount *);
 
 void ptmattach(int);
 
+int
+ptyfs_getmp(struct lwp *l, struct mount **mpp) {
+	struct cwdinfo *cwdi = l->l_proc->p_cwdi;
+	struct mount *mp;
+
+	if (ptm == NULL)
+		return EOPNOTSUPP;
+
+	if (ptm->arg == NULL) { /* BSDPTY */
+		*mpp = NULL;
+		return 0;
+	}
+
+	mp = ptm->arg;	/* PTYFS */
+
+	if (cwdi->cwdi_rdir == NULL)
+		goto ok;
+
+	if (vn_isunder(mp->mnt_vnodecovered, cwdi->cwdi_rdir, l))
+		goto ok;
+
+	*mpp = NULL;
+	return EOPNOTSUPP;
+ok:
+	*mpp = mp;
+	return 0;
+}
+
 dev_t
 pty_makedev(char ms, int minor)
 {
@@ -140,7 +168,7 @@ pty_vn_open(struct vnode *vp, struct lwp
 }
 
 static int
-pty_alloc_master(struct lwp *l, int *fd, dev_t *dev)
+pty_alloc_master(struct lwp *l, int *fd, dev_t *dev, struct mount *mp)
 {
 	int error;
 	struct file *fp;
@@ -164,7 +192,7 @@ retry:
 		error = EOPNOTSUPP;
 		goto bad;
 	}
-	if ((error = (*ptm->allocvp)(ptm, l, &vp, *dev, 'p')) != 0) {
+	if ((error = (*ptm->allocvp)(mp, l, &vp, *dev, 'p')) != 0) {
 		DPRINTF(("pty_allocvp %d\n", error));
 		goto bad;
 	}
@@ -197,7 +225,7 @@ bad:
 }
 
 int
-pty_grant_slave(struct lwp *l, dev_t dev)
+pty_grant_slave(struct lwp *l, dev_t dev, struct mount *mp)
 {
 	int error;
 	struct vnode *vp;
@@ -213,12 +241,12 @@ pty_grant_slave(struct lwp *l, dev_t dev
 	 */
 	if (ptm == NULL)
 		return EOPNOTSUPP;
-	if ((error = (*ptm->allocvp)(ptm, l, &vp, dev, 't')) != 0)
+	if ((error = (*ptm->allocvp)(mp, l, &vp, dev, 't')) != 0)
 		return error;
 
 	if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
 		struct vattr vattr;
-		(*ptm->getvattr)(ptm, l, &vattr);
+		(*ptm->getvattr)(mp, l, &vattr);
 		/* Do the VOP_SETATTR() as root. */
 		error = VOP_SETATTR(vp, &vattr, lwp0.l_cred);
 		if (error) {
@@ -239,7 +267,7 @@ pty_grant_slave(struct lwp *l, dev_t dev
 }
 
 static int
-pty_alloc_slave(struct lwp *l, int *fd, dev_t dev)
+pty_alloc_slave(struct lwp *l, int *fd, dev_t dev, struct mount *mp)
 {
 	int error;
 	struct file *fp;
@@ -256,7 +284,7 @@ pty_alloc_slave(struct lwp *l, int *fd, 
 		goto bad;
 	}
 
-	if ((error = (*ptm->allocvp)(ptm, l, &vp, dev, 't')) != 0)
+	if ((error = (*ptm->allocvp)(mp, l, &vp, dev, 't')) != 0)
 		goto bad;
 	if ((error = pty_vn_open(vp, l)) != 0)
 		goto bad;
@@ -282,7 +310,7 @@ pty_sethandler(struct ptm_pty *nptm)
 }
 
 int
-pty_fill_ptmget(struct lwp *l, dev_t dev, int cfd, int sfd, void *data)
+pty_fill_ptmget(struct lwp *l, dev_t dev, int cfd, int sfd, void *data, struct mount *mp)
 {
 	struct ptmget *ptmg = data;
 	int error;
@@ -293,11 +321,11 @@ pty_fill_ptmget(struct lwp *l, dev_t dev
 	ptmg->cfd = cfd == -1 ? minor(dev) : cfd;
 	ptmg->sfd = sfd == -1 ? minor(dev) : sfd;
 
-	error = (*ptm->makename)(ptm, l, ptmg->cn, sizeof(ptmg->cn), dev, 'p');
+	error = (*ptm->makename)(mp, l, ptmg->cn, sizeof(ptmg->cn), dev, 'p');
 	if (error)
 		return error;
 
-	return (*ptm->makename)(ptm, l, ptmg->sn, sizeof(ptmg->sn), dev, 't');
+	return (*ptm->makename)(mp, l, ptmg->sn, sizeof(ptmg->sn), dev, 't');
 }
 
 void
@@ -322,11 +350,14 @@ ptmopen(dev_t dev, int flag, int mode, s
 	int error;
 	int fd;
 	dev_t ttydev;
+	struct mount *mp;
 
 	switch(minor(dev)) {
 	case 0:		/* /dev/ptmx */
 	case 2:		/* /emul/linux/dev/ptmx */
-		if ((error = pty_alloc_master(l, &fd, &ttydev)) != 0)
+		if ((error = ptyfs_getmp(l, &mp)) != 0)
+			return error;
+		if ((error = pty_alloc_master(l, &fd, &ttydev, mp)) != 0)
 			return error;
 		if (minor(dev) == 2) {
 			/*
@@ -334,7 +365,7 @@ ptmopen(dev_t dev, int flag, int mode, s
 			 * Handle this case here, instead of writing
 			 * a new linux module.
 			 */
-			if ((error = pty_grant_slave(l, ttydev)) != 0) {
+			if ((error = pty_grant_slave(l, ttydev, mp)) != 0) {
 				file_t *fp = fd_getfile(fd);
 				if (fp != NULL) {
 					fd_close(fd);
@@ -367,21 +398,25 @@ ptmioctl(dev_t dev, u_long cmd, void *da
 	dev_t newdev;
 	int cfd, sfd;
 	file_t *fp;
+	struct mount *mp;
 
 	error = 0;
 	switch (cmd) {
 	case TIOCPTMGET:
-		if ((error = pty_alloc_master(l, &cfd, &newdev)) != 0)
+		if ((error = ptyfs_getmp(l, &mp)) != 0)
+			return error;
+
+		if ((error = pty_alloc_master(l, &cfd, &newdev, mp)) != 0)
 			return error;
 
-		if ((error = pty_grant_slave(l, newdev)) != 0)
+		if ((error = pty_grant_slave(l, newdev, mp)) != 0)
 			goto bad;
 
-		if ((error = pty_alloc_slave(l, &sfd, newdev)) != 0)
+		if ((error = pty_alloc_slave(l, &sfd, newdev, mp)) != 0)
 			goto bad;
 
 		/* now, put the indices and names into struct ptmget */
-		if ((error = pty_fill_ptmget(l, newdev, cfd, sfd, data)) != 0)
+		if ((error = pty_fill_ptmget(l, newdev, cfd, sfd, data, mp)) != 0)
 			goto bad2;
 		return 0;
 	default:

Index: src/sys/kern/tty_pty.c
diff -u src/sys/kern/tty_pty.c:1.135 src/sys/kern/tty_pty.c:1.136
--- src/sys/kern/tty_pty.c:1.135	Sun Mar 16 01:20:30 2014
+++ src/sys/kern/tty_pty.c	Thu Mar 27 13:31:56 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: tty_pty.c,v 1.135 2014/03/16 05:20:30 dholland Exp $	*/
+/*	$NetBSD: tty_pty.c,v 1.136 2014/03/27 17:31:56 christos Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tty_pty.c,v 1.135 2014/03/16 05:20:30 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty_pty.c,v 1.136 2014/03/27 17:31:56 christos Exp $");
 
 #include "opt_ptm.h"
 
@@ -1041,6 +1041,7 @@ ptyioctl(dev_t dev, u_long cmd, void *da
 	const struct cdevsw *cdev;
 	u_char *cc = tp->t_cc;
 	int stop, error, sig;
+	struct mount *mp;
 
 	/*
 	 * IF CONTROLLER STTY THEN MUST FLUSH TO PREVENT A HANG.
@@ -1071,8 +1072,11 @@ ptyioctl(dev_t dev, u_long cmd, void *da
 
 #ifndef NO_DEV_PTM
 	/* Allow getting the name from either the master or the slave */
-	if (cmd == TIOCPTSNAME)
-		return pty_fill_ptmget(l, dev, -1, -1, data);
+	if (cmd == TIOCPTSNAME) {
+		if ((error = ptyfs_getmp(l, &mp)) != 0)
+			return error;
+		return pty_fill_ptmget(l, dev, -1, -1, data, mp);
+	}
 #endif
 
 	cdev = cdevsw_lookup(dev);
@@ -1080,7 +1084,9 @@ ptyioctl(dev_t dev, u_long cmd, void *da
 		switch (cmd) {
 #ifndef NO_DEV_PTM
 		case TIOCGRANTPT:
-			return pty_grant_slave(l, dev);
+			if ((error = ptyfs_getmp(l, &mp)) != 0)
+				return error;
+			return pty_grant_slave(l, dev, mp);
 #endif
 
 		case TIOCGPGRP:

Index: src/sys/sys/pty.h
diff -u src/sys/sys/pty.h:1.8 src/sys/sys/pty.h:1.9
--- src/sys/sys/pty.h:1.8	Mon Apr 28 16:24:11 2008
+++ src/sys/sys/pty.h	Thu Mar 27 13:31:56 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: pty.h,v 1.8 2008/04/28 20:24:11 martin Exp $	*/
+/*	$NetBSD: pty.h,v 1.9 2014/03/27 17:31:56 christos Exp $	*/
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -36,25 +36,32 @@ int pty_check(int);
 
 #ifndef NO_DEV_PTM
 void ptmattach(int);
-int pty_fill_ptmget(struct lwp *, dev_t, int, int, void *);
-int pty_grant_slave(struct lwp *, dev_t);
+int pty_fill_ptmget(struct lwp *, dev_t, int, int, void *, struct mount *);
+int pty_grant_slave(struct lwp *, dev_t, struct mount *);
 dev_t pty_makedev(char, int);
 int pty_vn_open(struct vnode *, struct lwp *);
 struct ptm_pty *pty_sethandler(struct ptm_pty *);
-#endif
+int ptyfs_getmp(struct lwp *, struct mount **);
 
+/*
+ * Ptm_pty is used for switch ptm{x} driver between BSDPTY, PTYFS.
+ * Functions' argument (struct mount *) is used only PTYFS,
+ * in the case BSDPTY can be NULL, and arg must be NULL.
+ */
 struct ptm_pty {
-	int (*allocvp)(struct ptm_pty *, struct lwp *, struct vnode **, dev_t,
+	int (*allocvp)(struct mount *, struct lwp *, struct vnode **, dev_t,
 	    char);
-	int (*makename)(struct ptm_pty *, struct lwp *, char *, size_t, dev_t, char);
-	void (*getvattr)(struct ptm_pty *, struct lwp *, struct vattr *);
+	int (*makename)(struct mount *, struct lwp *, char *, size_t, dev_t, char);
+	void (*getvattr)(struct mount *, struct lwp *, struct vattr *);
 	void *arg;
 };
 
-extern int npty;
-
 #ifdef COMPAT_BSDPTY
 extern struct ptm_pty ptm_bsdpty;
 #endif
 
+#endif /* NO_DEV_PTM */
+
+extern int npty;
+
 #endif /* _SYS_PTY_H_ */

Reply via email to