From owner-freebsd-emulation@FreeBSD.ORG Fri Oct 26 05:05:21 2012 Return-Path: Delivered-To: freebsd-emulation@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A3CDD260 for ; Fri, 26 Oct 2012 05:05:21 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 336AC8FC08 for ; Fri, 26 Oct 2012 05:05:20 +0000 (UTC) Received: from skuns.kiev.zoral.com.ua (localhost [127.0.0.1]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id q9Q55Ti2057853; Fri, 26 Oct 2012 08:05:29 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5) with ESMTP id q9Q55Hx4046385; Fri, 26 Oct 2012 08:05:17 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5/Submit) id q9Q55HvU046384; Fri, 26 Oct 2012 08:05:17 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Fri, 26 Oct 2012 08:05:17 +0300 From: Konstantin Belousov To: Marcin Mazur Subject: Re: TCSBRK implementation for linux compat Message-ID: <20121026050517.GM35915@deviant.kiev.zoral.com.ua> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="0Oyvl1jN+EoPbLMC" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: freebsd-emulation@freebsd.org X-BeenThere: freebsd-emulation@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Development of Emulators of other operating systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Oct 2012 05:05:21 -0000 --0Oyvl1jN+EoPbLMC Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Oct 25, 2012 at 09:17:39PM +0200, Marcin Mazur wrote: > Hi. >=20 > I needed suport for this feature in FreeBSD linux emulation, because I > have to use precompiled linux library/binary that uses it. There was a > lot of errors in logs like: >=20 >=20 > "... ioctl fd=3D52, cmd=3D0x5409 ('T',9) is not implemented" >=20 > I could not find any help so I had to do that by myself >=20 > I found implementation in NetBSD sources, and just 'translated' it to > the FreeBSD >=20 > There is my work: >=20 > ------------------------- > --- linux_ioctl.orig 2012-08-06 01:54:33.000000000 +0200 > +++ linux_ioctl.c 2012-10-25 13:59:12.000000000 +0200 > @@ -778,8 +778,26 @@ > td)); > break; >=20 > - /* LINUX_TCSBRK */ > - > + case LINUX_TCSBRK: > + if (args->arg) > + { > + args->cmd =3D TIOCDRAIN; > + error =3D (sys_ioctl(td, (struct ioctl_args *)arg= s)); > + break; > + } > + else > + { > + if ((error =3D fo_ioctl(fp, TIOCSBRK, NULL, > td->td_ucred,td)) !=3D 0) > + break; > + error =3D tsleep(&args->arg, PZERO | PCATCH, > "linux_tcsbrk", hz / 4); > + if (error =3D=3D EINTR || error =3D=3D ERESTART) { > + fo_ioctl(fp, TIOCCBRK, NULL, td->td_ucred, td= ); > + error =3D EINTR; > + } else > + error =3D fo_ioctl (fp, TIOCCBRK, NULL, > td->td_ucred, td); > + break; > + } > + > case LINUX_TCXONC: { > switch (args->arg) { > case LINUX_TCOOFF: > -------------------- > Could someone have a look at this if the code is correct? > Sorry but I do not have kernel developing experience and this is my first= patch > I'm testing this patch for over 20 hours now and it seems to work > well. No errors, load average dropped from 2.5 to 0.5 > Please CC me, I'am not on the list. > And sorry for my bad english... This looks good, below is the commit candidate. I did small changes according to style and my taste. The biggest is the removal of PZERO =66rom tsleep flags, which is actually shall not be used, since it changes the thread priority (instead of usual assumption that the value is to preserve the current priority). diff --git a/sys/compat/linux/linux_ioctl.c b/sys/compat/linux/linux_ioctl.c index 0a9cd27..5ebf7ed 100644 --- a/sys/compat/linux/linux_ioctl.c +++ b/sys/compat/linux/linux_ioctl.c @@ -699,7 +699,7 @@ linux_ioctl_termio(struct thread *td, struct linux_ioct= l_args *args) struct linux_termios lios; struct linux_termio lio; struct file *fp; - int error; + int error, error1; =20 if ((error =3D fget(td, args->fd, CAP_IOCTL, &fp)) !=3D 0) return (error); @@ -778,7 +778,27 @@ linux_ioctl_termio(struct thread *td, struct linux_ioc= tl_args *args) td)); break; =20 - /* LINUX_TCSBRK */ + case LINUX_TCSBRK: + /* + * Non-zero argument is interpreted as the request to + * perform tcdrain(). + * Zero argument means tcsendbreak(). + */ + if (args->arg !=3D 0) + error =3D fo_ioctl(fp, TIOCDRAIN, NULL, td->td_ucred, td); + else { + error =3D fo_ioctl(fp, TIOCSBRK, NULL, td->td_ucred, td); + if (error !=3D 0) + break; + error =3D tsleep(&args->arg, PCATCH, "linux_tcsbrk", + hz / 4); + error1 =3D fo_ioctl(fp, TIOCCBRK, NULL, td->td_ucred, td); + if (error =3D=3D EINTR || error =3D=3D ERESTART) + error =3D EINTR; + else + error =3D error1; + } + break; =20 case LINUX_TCXONC: { switch (args->arg) { --0Oyvl1jN+EoPbLMC Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (FreeBSD) iEYEARECAAYFAlCKGgkACgkQC3+MBN1Mb4j6GACdEEvt9MHDvo746/pMnalJFPik f+8AnRimt1agGAy1m/+VeVDjhe9IJZ7n =izFK -----END PGP SIGNATURE----- --0Oyvl1jN+EoPbLMC--