Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 21 Jun 2011 14:53:11 +1000
From:      Peter Jeremy <peter.jeremy@alcatel-lucent.com>
To:        "FreeBSD-gnats-submit@FreeBSD.org" <FreeBSD-gnats-submit@FreeBSD.org>, "freebsd-bugs@FreeBSD.org" <freebsd-bugs@FreeBSD.org>
Subject:   Re: kern/152254: [patch] Support ioctl() on TTY control devices
Message-ID:  <20110621045311.GA89428@pjdesk.au.alcatel-lucent.com>
In-Reply-To: <201011150430.oAF4U9A5032767@freefall.freebsd.org>
References:  <201011150428.oAF4SL06037362@www.freebsd.org> <201011150430.oAF4U9A5032767@freefall.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--0eh6TmSyL6TZE2Uz
Content-Type: multipart/mixed; boundary="fdj2RfSjLxBAspz7"
Content-Disposition: inline


--fdj2RfSjLxBAspz7
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

I notice that FreeBSD is entering the 9.0 release cycle.  As Jilles
Tjoelker has noted, my patch changes the KBI.  As a result, I would
like to request that this change be made before the 9.0 freeze.  If
you do not want to commit the change, could you please add some
padding fields to struct ttydevsw to simplify applying the change in
future.

My apologies for the late request but re@ are being very secretive
with dates and I only just found out about the code slush.

An updated version of the patch is attached.  This has undergone
limited testing in both 8-stable and -current annd testing is
continuing.

Note that this PR is a prerequisite for kern/158086

--=20
Peter Jeremy

--fdj2RfSjLxBAspz7
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="152254.patch"
Content-Transfer-Encoding: quoted-printable

Index: sys/kern/tty.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /usr/ncvs/src/sys/kern/tty.c,v
retrieving revision 1.341
diff -u -r1.341 tty.c
--- sys/kern/tty.c	4 Jan 2011 10:59:38 -0000	1.341
+++ sys/kern/tty.c	20 Jun 2011 22:45:20 -0000
@@ -91,7 +91,7 @@
 			HUPCL|CLOCAL|CCTS_OFLOW|CRTS_IFLOW|CDTR_IFLOW|\
 			CDSR_OFLOW|CCAR_OFLOW)
=20
-#define	TTY_CALLOUT(tp,d) ((d) !=3D (tp)->t_dev && (d) !=3D dev_console)
+#define	TTY_CALLOUT(tp,d) (dev2unit(d) & TTYUNIT_CALLOUT)
=20
 /*
  * Set TTY buffer sizes.
@@ -791,7 +791,7 @@
 		bzero(data, sizeof(struct winsize));
 		break;
 	default:
-		error =3D ENOTTY;
+		error =3D ttydevsw_cioctl(tp, dev2unit(dev), cmd, data, td);
 	}
=20
 done:	tty_unlock(tp);
@@ -927,6 +927,13 @@
 	panic("Terminal device freed without a free-handler");
 }
=20
+static int
+ttydevsw_defcioctl(struct tty *tp, int unit, u_long cmd, caddr_t data, str=
uct thread *td)
+{
+
+	return (ENOTTY);
+}
+
 /*
  * TTY allocation and deallocation. TTY devices can be deallocated when
  * the driver doesn't use it anymore, when the TTY isn't a session's
@@ -960,6 +967,7 @@
 	PATCH_FUNC(mmap);
 	PATCH_FUNC(pktnotify);
 	PATCH_FUNC(free);
+	PATCH_FUNC(cioctl);
 #undef PATCH_FUNC
=20
 	tp =3D malloc(sizeof(struct tty), M_TTY, M_WAITOK|M_ZERO);
@@ -1190,13 +1198,13 @@
=20
 	/* Slave call-in devices. */
 	if (tp->t_flags & TF_INITLOCK) {
-		dev =3D make_dev_cred(&ttyil_cdevsw, 0, cred,
+		dev =3D make_dev_cred(&ttyil_cdevsw, TTYUNIT_INIT, cred,
 		    uid, gid, mode, "%s%s.init", prefix, name);
 		dev_depends(tp->t_dev, dev);
 		dev->si_drv1 =3D tp;
 		dev->si_drv2 =3D &tp->t_termios_init_in;
=20
-		dev =3D make_dev_cred(&ttyil_cdevsw, 0, cred,
+		dev =3D make_dev_cred(&ttyil_cdevsw, TTYUNIT_LOCK, cred,
 		    uid, gid, mode, "%s%s.lock", prefix, name);
 		dev_depends(tp->t_dev, dev);
 		dev->si_drv1 =3D tp;
@@ -1205,20 +1213,22 @@
=20
 	/* Call-out devices. */
 	if (tp->t_flags & TF_CALLOUT) {
-		dev =3D make_dev_cred(&ttydev_cdevsw, 0, cred,
+		dev =3D make_dev_cred(&ttydev_cdevsw, TTYUNIT_CALLOUT, cred,
 		    UID_UUCP, GID_DIALER, 0660, "cua%s", name);
 		dev_depends(tp->t_dev, dev);
 		dev->si_drv1 =3D tp;
=20
 		/* Slave call-out devices. */
 		if (tp->t_flags & TF_INITLOCK) {
-			dev =3D make_dev_cred(&ttyil_cdevsw, 0, cred,
+			dev =3D make_dev_cred(&ttyil_cdevsw,=20
+			    TTYUNIT_CALLOUT | TTYUNIT_INIT, cred,
 			    UID_UUCP, GID_DIALER, 0660, "cua%s.init", name);
 			dev_depends(tp->t_dev, dev);
 			dev->si_drv1 =3D tp;
 			dev->si_drv2 =3D &tp->t_termios_init_out;
=20
-			dev =3D make_dev_cred(&ttyil_cdevsw, 0, cred,
+			dev =3D make_dev_cred(&ttyil_cdevsw,
+			    TTYUNIT_CALLOUT | TTYUNIT_LOCK, cred,
 			    UID_UUCP, GID_DIALER, 0660, "cua%s.lock", name);
 			dev_depends(tp->t_dev, dev);
 			dev->si_drv1 =3D tp;
Index: sys/sys/tty.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /usr/ncvs/src/sys/sys/tty.h,v
retrieving revision 1.118
diff -u -r1.118 tty.h
--- sys/sys/tty.h	4 Jan 2010 20:59:52 -0000	1.118
+++ sys/sys/tty.h	20 Jun 2011 22:47:15 -0000
@@ -150,6 +150,11 @@
 	dev_t	xt_dev;		/* Userland device. */
 };
=20
+/* Used to distinguish between normal, callout, lock and init devices */
+#define	TTYUNIT_INIT	0x1
+#define	TTYUNIT_LOCK	0x2
+#define	TTYUNIT_CALLOUT	0x4
+
 #ifdef _KERNEL
=20
 /* Allocation and deallocation. */
Index: sys/sys/ttydevsw.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /usr/ncvs/src/sys/sys/ttydevsw.h,v
retrieving revision 1.5
diff -u -r1.5 ttydevsw.h
--- sys/sys/ttydevsw.h	29 Dec 2009 21:51:28 -0000	1.5
+++ sys/sys/ttydevsw.h	20 Jun 2011 22:47:15 -0000
@@ -52,6 +52,8 @@
     vm_paddr_t * paddr, int nprot, vm_memattr_t *memattr);
 typedef void tsw_pktnotify_t(struct tty *tp, char event);
 typedef void tsw_free_t(void *softc);
+typedef int tsw_cioctl_t(struct tty *tp, int unit, u_long cmd, caddr_t dat=
a,
+    struct thread *td);
=20
 struct ttydevsw {
 	unsigned int	tsw_flags;	/* Default TTY flags. */
@@ -70,6 +72,8 @@
 	tsw_pktnotify_t	*tsw_pktnotify;	/* TIOCPKT events. */
=20
 	tsw_free_t	*tsw_free;	/* Destructor. */
+
+	tsw_cioctl_t	*tsw_cioctl;	/* Ioctl on control devices */
 };
=20
 static __inline int
@@ -167,4 +171,13 @@
 	tp->t_devsw->tsw_free(tty_softc(tp));
 }
=20
+static __inline int
+ttydevsw_cioctl(struct tty *tp, int unit, u_long cmd, caddr_t data, struct=
 thread *td)
+{
+	tty_lock_assert(tp, MA_OWNED);
+	MPASS(!tty_gone(tp));
+
+	return tp->t_devsw->tsw_cioctl(tp, unit, cmd, data, td);
+}
+
 #endif /* !_SYS_TTYDEVSW_H_ */

--fdj2RfSjLxBAspz7--

--0eh6TmSyL6TZE2Uz
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (FreeBSD)

iEYEARECAAYFAk4AI7cACgkQ/opHv/APuIeaRwCdHxcIwrFDi+CpGg1y4V12+4zT
BmIAoIF4i0s5kW/xKaDiaR6aQtNwc7k1
=I3R4
-----END PGP SIGNATURE-----

--0eh6TmSyL6TZE2Uz--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110621045311.GA89428>