From owner-freebsd-bugs@FreeBSD.ORG Tue Jun 21 05:32:04 2011 Return-Path: Delivered-To: freebsd-bugs@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5FC061065672 for ; Tue, 21 Jun 2011 05:32:04 +0000 (UTC) (envelope-from peter.jeremy@alcatel-lucent.com) Received: from ihemail4.lucent.com (ihemail4.lucent.com [135.245.0.39]) by mx1.freebsd.org (Postfix) with ESMTP id 2132F8FC12 for ; Tue, 21 Jun 2011 05:32:03 +0000 (UTC) Received: from usnavsmail1.ndc.alcatel-lucent.com (usnavsmail1.ndc.alcatel-lucent.com [135.3.39.9]) by ihemail4.lucent.com (8.13.8/IER-o) with ESMTP id p5L50sVN014169 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 21 Jun 2011 00:00:55 -0500 (CDT) Received: from unixmail.au.alcatel-lucent.com (unixmail.au.alcatel-lucent.com [139.188.42.130]) by usnavsmail1.ndc.alcatel-lucent.com (8.14.3/8.14.3/GMO) with ESMTP id p5L50oJO031809 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 21 Jun 2011 00:00:54 -0500 Received: from insmb.au.alcatel-lucent.com (insmb.au.alcatel-lucent.com [139.188.42.184]) by unixmail.au.alcatel-lucent.com (8.13.8+Sun/8.13.3) with ESMTP id p5L50oeb026474; Tue, 21 Jun 2011 15:00:50 +1000 (EST) Received: from pjdesk.au.alcatel-lucent.com (pjdesk.au.alcatel-lucent.com [139.188.2.2]) by insmb.au.alcatel-lucent.com (8.13.8+Sun/8.13.8) with ESMTP id p5L4rKWl000274; Tue, 21 Jun 2011 14:53:20 +1000 (EST) X-Bogosity: Ham, spamicity=0.000000 Received: from pjdesk.au.alcatel-lucent.com (localhost [127.0.0.1]) by pjdesk.au.alcatel-lucent.com (8.14.4/8.14.4) with ESMTP id p5L4rBtA089473; Tue, 21 Jun 2011 14:53:11 +1000 (EST) (envelope-from peter.jeremy@alcatel-lucent.com) Received: (from pjeremy@localhost) by pjdesk.au.alcatel-lucent.com (8.14.4/8.14.4/Submit) id p5L4rBbL089472; Tue, 21 Jun 2011 14:53:11 +1000 (EST) (envelope-from peter.jeremy@alcatel-lucent.com) Date: Tue, 21 Jun 2011 14:53:11 +1000 From: Peter Jeremy To: "FreeBSD-gnats-submit@FreeBSD.org" , "freebsd-bugs@FreeBSD.org" Message-ID: <20110621045311.GA89428@pjdesk.au.alcatel-lucent.com> References: <201011150428.oAF4SL06037362@www.freebsd.org> <201011150430.oAF4U9A5032767@freefall.freebsd.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="0eh6TmSyL6TZE2Uz" Content-Disposition: inline In-Reply-To: <201011150430.oAF4U9A5032767@freefall.freebsd.org> X-PGP-Key: http://members.optusnet.com.au/peterjeremy/pubkey.asc User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.57 on 135.245.2.39 X-Scanned-By: MIMEDefang 2.64 on 135.3.39.9 Cc: Subject: Re: kern/152254: [patch] Support ioctl() on TTY control devices X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Jun 2011 05:32:04 -0000 --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--