Kernel portion of the multiple ptyfs mount support. Protocol changed

between kernel and module, so bump. (Ilya Zykov)
This commit is contained in:
christos 2014-04-04 18:11:58 +00:00
parent c636575468
commit 6accf143de
5 changed files with 44 additions and 38 deletions

View File

@ -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 *, struct lwp *, char *, size_t, dev_t,
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 lwp *l, struct vattr *vattr)
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 */

View File

@ -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 *, 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;
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, struct lwp *l)
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 *data, int flag, struct lwp *l)
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)

View File

@ -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 *data, int flag, struct lwp *l)
#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 *data, int flag, struct lwp *l)
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

View File

@ -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__)

View File

@ -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, struct mount *);
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