Module Name: src
Committed By: christos
Date: Fri Apr 4 18:11:58 UTC 2014
Modified Files:
src/sys/kern: tty_bsdpty.c tty_ptm.c tty_pty.c
src/sys/sys: param.h pty.h
Log Message:
Kernel portion of the multiple ptyfs mount support. Protocol changed
between kernel and module, so bump. (Ilya Zykov)
To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/kern/tty_bsdpty.c
cvs rdiff -u -r1.31 -r1.32 src/sys/kern/tty_ptm.c
cvs rdiff -u -r1.137 -r1.138 src/sys/kern/tty_pty.c
cvs rdiff -u -r1.449 -r1.450 src/sys/sys/param.h
cvs rdiff -u -r1.9 -r1.10 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/kern/tty_bsdpty.c
diff -u src/sys/kern/tty_bsdpty.c:1.19 src/sys/kern/tty_bsdpty.c:1.20
--- src/sys/kern/tty_bsdpty.c:1.19 Thu Mar 27 13:31:56 2014
+++ src/sys/kern/tty_bsdpty.c Fri Apr 4 14:11:58 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: tty_bsdpty.c,v 1.19 2014/03/27 17:31:56 christos Exp $ */
+/* $NetBSD: tty_bsdpty.c,v 1.20 2014/04/04 18:11:58 christos Exp $ */
/*-
* Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tty_bsdpty.c,v 1.19 2014/03/27 17:31:56 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty_bsdpty.c,v 1.20 2014/04/04 18:11:58 christos Exp $");
#include "opt_ptm.h"
@@ -74,12 +74,13 @@ static int pty_makename(struct mount *,
static int pty_allocvp(struct mount *, struct lwp *, struct vnode **,
dev_t, char);
static void pty_getvattr(struct mount *, struct lwp *, struct vattr *);
+static int pty__getmp(struct lwp *, struct mount **);
struct ptm_pty ptm_bsdpty = {
pty_allocvp,
pty_makename,
pty_getvattr,
- NULL
+ pty__getmp,
};
static int
@@ -152,5 +153,13 @@ pty_getvattr(struct mount *mp, struct lw
vattr->va_gid = TTY_GID;
vattr->va_mode = TTY_PERM;
}
+
+static int
+pty__getmp(struct lwp *l __unused, struct mount **mpp)
+{
+ *mpp = 0;
+ return 0;
+}
+
#endif /* COMPAT_BSDPTY */
#endif /* NO_DEV_PTM */
Index: src/sys/kern/tty_ptm.c
diff -u src/sys/kern/tty_ptm.c:1.31 src/sys/kern/tty_ptm.c:1.32
--- src/sys/kern/tty_ptm.c:1.31 Thu Mar 27 13:31:56 2014
+++ src/sys/kern/tty_ptm.c Fri Apr 4 14:11:58 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: tty_ptm.c,v 1.31 2014/03/27 17:31:56 christos Exp $ */
+/* $NetBSD: tty_ptm.c,v 1.32 2014/04/04 18:11:58 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.31 2014/03/27 17:31:56 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty_ptm.c,v 1.32 2014/04/04 18:11:58 christos Exp $");
#include "opt_compat_netbsd.h"
#include "opt_ptm.h"
@@ -90,31 +90,12 @@ static int pty_alloc_slave(struct lwp *,
void ptmattach(int);
int
-ptyfs_getmp(struct lwp *l, struct mount **mpp) {
- struct cwdinfo *cwdi = l->l_proc->p_cwdi;
- struct mount *mp;
-
+pty_getmp(struct lwp *l, struct mount **mpp)
+{
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;
+ return (*ptm->getmp)(l, mpp);
}
dev_t
@@ -192,6 +173,22 @@ retry:
error = EOPNOTSUPP;
goto bad;
}
+ /*
+ * XXX Since PTYFS has now multiple instance support, if we mounted
+ * more than one PTYFS we must check here the ptyfs_used_tbl, to find
+ * out if the ptyfsnode is under the appropriate mount and skip the
+ * node if not, because the pty could has been released, but
+ * ptyfs_reclaim didn't get a chance to release the corresponding
+ * node other mount point yet.
+ *
+ * It's important to have only one mount point's ptyfsnode for each
+ * appropriate device in ptyfs_used_tbl, else we will have a security
+ * problem, because every entry will have access to this device.
+ *
+ * Also we will not have not efficient vnode and memory usage.
+ * You can test this by changing a_recycle from true to false
+ * in ptyfs_inactive.
+ */
if ((error = (*ptm->allocvp)(mp, l, &vp, *dev, 'p')) != 0) {
DPRINTF(("pty_allocvp %d\n", error));
goto bad;
@@ -355,7 +352,7 @@ ptmopen(dev_t dev, int flag, int mode, s
switch(minor(dev)) {
case 0: /* /dev/ptmx */
case 2: /* /emul/linux/dev/ptmx */
- if ((error = ptyfs_getmp(l, &mp)) != 0)
+ if ((error = pty_getmp(l, &mp)) != 0)
return error;
if ((error = pty_alloc_master(l, &fd, &ttydev, mp)) != 0)
return error;
@@ -403,7 +400,7 @@ ptmioctl(dev_t dev, u_long cmd, void *da
error = 0;
switch (cmd) {
case TIOCPTMGET:
- if ((error = ptyfs_getmp(l, &mp)) != 0)
+ if ((error = pty_getmp(l, &mp)) != 0)
return error;
if ((error = pty_alloc_master(l, &cfd, &newdev, mp)) != 0)
Index: src/sys/kern/tty_pty.c
diff -u src/sys/kern/tty_pty.c:1.137 src/sys/kern/tty_pty.c:1.138
--- src/sys/kern/tty_pty.c:1.137 Fri Mar 28 07:55:09 2014
+++ src/sys/kern/tty_pty.c Fri Apr 4 14:11:58 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: tty_pty.c,v 1.137 2014/03/28 11:55:09 ozaki-r Exp $ */
+/* $NetBSD: tty_pty.c,v 1.138 2014/04/04 18:11:58 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.137 2014/03/28 11:55:09 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty_pty.c,v 1.138 2014/04/04 18:11:58 christos Exp $");
#include "opt_ptm.h"
@@ -1075,7 +1075,7 @@ 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) {
- if ((error = ptyfs_getmp(l, &mp)) != 0)
+ if ((error = pty_getmp(l, &mp)) != 0)
return error;
return pty_fill_ptmget(l, dev, -1, -1, data, mp);
}
@@ -1086,7 +1086,7 @@ ptyioctl(dev_t dev, u_long cmd, void *da
switch (cmd) {
#ifndef NO_DEV_PTM
case TIOCGRANTPT:
- if ((error = ptyfs_getmp(l, &mp)) != 0)
+ if ((error = pty_getmp(l, &mp)) != 0)
return error;
return pty_grant_slave(l, dev, mp);
#endif
Index: src/sys/sys/param.h
diff -u src/sys/sys/param.h:1.449 src/sys/sys/param.h:1.450
--- src/sys/sys/param.h:1.449 Sat Mar 29 20:13:59 2014
+++ src/sys/sys/param.h Fri Apr 4 14:11:58 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: param.h,v 1.449 2014/03/30 00:13:59 christos Exp $ */
+/* $NetBSD: param.h,v 1.450 2014/04/04 18:11:58 christos Exp $ */
/*-
* Copyright (c) 1982, 1986, 1989, 1993
@@ -63,7 +63,7 @@
* 2.99.9 (299000900)
*/
-#define __NetBSD_Version__ 699003900 /* NetBSD 6.99.39 */
+#define __NetBSD_Version__ 699004000 /* NetBSD 6.99.40 */
#define __NetBSD_Prereq__(M,m,p) (((((M) * 100000000) + \
(m) * 1000000) + (p) * 100) <= __NetBSD_Version__)
Index: src/sys/sys/pty.h
diff -u src/sys/sys/pty.h:1.9 src/sys/sys/pty.h:1.10
--- src/sys/sys/pty.h:1.9 Thu Mar 27 13:31:56 2014
+++ src/sys/sys/pty.h Fri Apr 4 14:11:58 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: pty.h,v 1.9 2014/03/27 17:31:56 christos Exp $ */
+/* $NetBSD: pty.h,v 1.10 2014/04/04 18:11:58 christos Exp $ */
/*-
* Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@ int pty_grant_slave(struct lwp *, dev_t,
dev_t pty_makedev(char, int);
int pty_vn_open(struct vnode *, struct lwp *);
struct ptm_pty *pty_sethandler(struct ptm_pty *);
-int ptyfs_getmp(struct lwp *, struct mount **);
+int pty_getmp(struct lwp *, struct mount **);
/*
* Ptm_pty is used for switch ptm{x} driver between BSDPTY, PTYFS.
@@ -53,7 +53,7 @@ struct ptm_pty {
char);
int (*makename)(struct mount *, struct lwp *, char *, size_t, dev_t, char);
void (*getvattr)(struct mount *, struct lwp *, struct vattr *);
- void *arg;
+ int (*getmp)(struct lwp *, struct mount **);
};
#ifdef COMPAT_BSDPTY