linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [2.5] Non-blocking write can block
@ 2003-06-04  0:58 P. Benie
  2003-06-04  5:53 ` Christoph Hellwig
  0 siblings, 1 reply; 53+ messages in thread
From: P. Benie @ 2003-06-04  0:58 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Kernel Mailing List

Non-blocking writes to a tty will block if there is a blocking write
waiting for the atomic_write semaphore.

Peter

--- linux-2.5.70/drivers/char/tty_io.c.orig	2003-06-03 21:34:42.000000000 +0100
+++ linux-2.5.70/drivers/char/tty_io.c	2003-06-04 01:40:33.000000000 +0100
@@ -687,8 +687,13 @@
 {
 	ssize_t ret = 0, written = 0;

-	if (down_interruptible(&tty->atomic_write)) {
-		return -ERESTARTSYS;
+	if (file->f_flags & O_NONBLOCK) {
+		if (down_trylock(&tty->atomic_write))
+			return -EAGAIN;
+	}
+	else {
+		if (down_interruptible(&tty->atomic_write))
+			return -ERESTARTSYS;
 	}
 	if ( test_bit(TTY_NO_WRITE_SPLIT, &tty->flags) ) {
 		lock_kernel();


^ permalink raw reply	[flat|nested] 53+ messages in thread
[parent not found: <20030604172026$296c@gated-at.bofh.it>]
* RE: [PATCH] [2.5] Non-blocking write can block
@ 2003-06-04 19:36 Hua Zhong
  2003-06-04 20:09 ` Hua Zhong
  0 siblings, 1 reply; 53+ messages in thread
From: Hua Zhong @ 2003-06-04 19:36 UTC (permalink / raw)
  To: torvalds; +Cc: linux-kernel

> Do y ou have that other patch handy? It sounds like that is 
> the real cause of the problem, and the patch quoted originally 
> in this thread was a (broken) work-around..
> 
>                Linus
> 

Something like this:

--- n_tty.c.old	2003-06-04 12:28:36.000000000 -0700
+++ n_tty.c	2003-06-04 12:28:51.000000000 -0700
@@ -711,6 +711,23 @@
 	return 0;
 }
 
+
+/*
+ * Required for the ptys, serial driver etc. since processes
+ * that attach themselves to the master and rely on ASYNC
+ * IO must be woken up
+ */
+
+static void n_tty_write_wakeup(struct tty_struct *tty)
+{
+	if (tty->fasync)
+	{
+ 		set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
+		kill_fasync(&tty->fasync, SIGIO, POLL_OUT);
+	}
+	return;
+}
+
 static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp,
 			      char *fp, int count)
 {
@@ -1157,6 +1174,8 @@
 			while (nr > 0) {
 				ssize_t num = opost_block(tty, b, nr);
 				if (num < 0) {
+					if (num == -EAGAIN)
+						break;
 					retval = num;
 					goto break_out;
 				}
@@ -1236,6 +1255,6 @@
 	normal_poll,		/* poll */
 	n_tty_receive_buf,	/* receive_buf */
 	n_tty_receive_room,	/* receive_room */
-	0			/* write_wakeup */
+ 	n_tty_write_wakeup 	/* write_wakeup */
 };
 

^ permalink raw reply	[flat|nested] 53+ messages in thread
* RE: [PATCH] [2.5] Non-blocking write can block
@ 2003-06-05  0:04 Ed Vance
  2003-06-05  0:19 ` Davide Libenzi
  0 siblings, 1 reply; 53+ messages in thread
From: Ed Vance @ 2003-06-05  0:04 UTC (permalink / raw)
  To: 'Davide Libenzi'; +Cc: Russell King, Linux Kernel Mailing List

On Wed, June 04, 2003 at 4:47 PM, Davide Libenzi wrote:
> 
> On Thu, 5 Jun 2003, Russell King wrote:
> 
> > On Wed, Jun 04, 2003 at 08:46:51PM +0100, P. Benie wrote:
> > > The problem isn't to do with large writes. It's to do 
> with any sequence of
> > > writes that fills up the receive buffer, which is only 4K 
> for N_TTY. If
> > > the receiving program is suspended, the buffer will fill 
> sooner or later.
> >
> > If the tty drivers buffer fills, we don't sleep in 
> tty->driver->write,
> > but we return zero instead.  If we are in non-blocking mode, and we
> > haven't written any characters, we return -EAGAIN.  If we have, we
> > return the number of characters which the tty driver accepted.
> >
> > However, the problem you are referring to is what happens 
> if you have
> > a blocking process blocked in write_chan() in n_tty.c, and we have
> > a non-blocking process trying to write to the same tty.
> >
> > Reading POSIX, it doesn't seem to be clear about our area 
> of interest,
> > and I'd even say that it seems to be unspecified.
> 
> Given that a problem exist for certain apps, and given that 
> the proposed
> fix will *at least* have existing apps to behave funny, couldn't this
> implemented as a feature of the fd (default off).
> Something like O_REALLYNONBLOCK :)
> 

Davide,

Do you mean something like the separate O_NDELAY flag under Solar*s? IIRC
they also use return code EWOULDBLOCK to differentiate the "could not get
resource" cases from the "no room for more data" cases when O_NONBLOCK is
used.

Cheers,
Ed

^ permalink raw reply	[flat|nested] 53+ messages in thread
* Re: [PATCH] [2.5] Non-blocking write can block
@ 2003-06-06 12:13 Nicholas Berry
  0 siblings, 0 replies; 53+ messages in thread
From: Nicholas Berry @ 2003-06-06 12:13 UTC (permalink / raw)
  To: linux-kernel


>>> "Richard B. Johnson" <root@chaos.analogic.com> 06/05/03 03:15PM
>>>
>On Thu, 5 Jun 2003, Mike Fedyk wrote:

> On Wed, Jun 04, 2003 at 05:19:05PM -0700, Davide Libenzi wrote:
> > Besides the stupid name O_REALLYNONBLOCK, it really should be
different
> > from both O_NONBLOCK and O_NDELAY. Currently in Linux they both map
to the
> > same value, so you really need a new value to not break binary
compatibility.
>
> Hmm, wouldn't that be source and binary compatability?  If an app
used
> O_NDELAY and O_NONBLOCK interchangably, then a change to O_NDELAY
would
> break source compatability too.
>
> Also, what do other UNIX OSes do?  Do they have seperate semantics
for
> O_NONBLOCK and O_NDELAY?  If so, then it would probably be better to
change
> O_NDELAY to be similar and add another feature at the same time as
reducing
> platform specific codeing in userspace.
> -

>My Sun thinks that O_NDELAY = 0x04 and O_NONBLOCK = 0x80, FWIW.

AIX 4.3.3 O_NDELAY = 0x8000 and O_NONBLOCK = 0x04 FWTW.

Nik

>Cheers,
>Dick Johnson
>Penguin : Linux version 2.4.20 on an i686 machine (797.90 BogoMips).
>Why is the government concerned about the lunatic fringe? Think about
it.


^ permalink raw reply	[flat|nested] 53+ messages in thread

end of thread, other threads:[~2003-06-11  0:07 UTC | newest]

Thread overview: 53+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-04  0:58 [PATCH] [2.5] Non-blocking write can block P. Benie
2003-06-04  5:53 ` Christoph Hellwig
2003-06-04 14:35   ` Linus Torvalds
2003-06-04 14:58     ` P. Benie
2003-06-04 16:47     ` Alan Cox
2003-06-04 17:57       ` Linus Torvalds
2003-06-04 19:46         ` P. Benie
2003-06-04 19:56           ` Linus Torvalds
2003-06-04 20:48             ` P. Benie
2003-06-11  0:19               ` Robert White
2003-06-04 20:43           ` Hua Zhong
2003-06-04 23:42           ` Russell King
2003-06-04 23:47             ` Davide Libenzi
2003-06-04 21:29         ` Alan Cox
2003-06-04 17:14     ` Hua Zhong
2003-06-04 17:41       ` Linus Torvalds
2003-06-04 18:44         ` Hua Zhong
2003-06-04 18:47           ` P. Benie
2003-06-04 19:23             ` P. Benie
2003-06-04 19:20           ` Linus Torvalds
2003-06-04 17:53       ` Mike Dresser
2003-06-04 15:21   ` Coding standards. (Was: Re: [PATCH] [2.5] Non-blocking write can block) Timothy Miller
2003-06-07  0:12     ` Greg KH
2003-06-07  0:59       ` Alex Goddard
2003-06-09 16:24       ` Timothy Miller
2003-06-09 16:39         ` Jörn Engel
2003-06-09 17:15           ` Davide Libenzi
2003-06-09 17:33             ` Eli Carter
2003-06-09 17:49               ` Richard B. Johnson
2003-06-09 18:07                 ` Davide Libenzi
2003-06-09 18:22                   ` Jörn Engel
2003-06-09 18:55             ` Timothy Miller
2003-06-09 18:58               ` Davide Libenzi
2003-06-09 21:35                 ` David Schwartz
2003-06-09 22:55                   ` Davide Libenzi
2003-06-09 23:21                     ` Nigel Cunningham
2003-06-09 21:54                 ` Jörn Engel
2003-06-10 18:17                 ` Jesse Pollard
2003-06-10 18:41                   ` Davide Libenzi
2003-06-10 18:14               ` Jesse Pollard
2003-06-09 23:50             ` James Stevenson
2003-06-09 18:44           ` Timothy Miller
2003-06-09 22:00             ` Jörn Engel
     [not found] <20030604172026$296c@gated-at.bofh.it>
     [not found] ` <20030604175013$3a4d@gated-at.bofh.it>
2003-06-04 19:13   ` [PATCH] [2.5] Non-blocking write can block Ben Pfaff
2003-06-04 19:36 Hua Zhong
2003-06-04 20:09 ` Hua Zhong
2003-06-05  0:04 Ed Vance
2003-06-05  0:19 ` Davide Libenzi
2003-06-05 18:34   ` Mike Fedyk
2003-06-05 19:15     ` Richard B. Johnson
2003-06-05 21:46       ` Joe Korty
2003-06-06  0:13     ` Davide Libenzi
2003-06-06 12:13 Nicholas Berry

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).