public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [patch rfc] towards supporting O_NONBLOCK on regular files
@ 2004-10-05 13:07 Dan Kegel
  0 siblings, 0 replies; 24+ messages in thread
From: Dan Kegel @ 2004-10-05 13:07 UTC (permalink / raw)
  To: Linux Kernel Mailing List

Marcelo wrote:
 > Curiosity: Is this defined in any UNIX standard?

No.  See
http://www.opengroup.org/onlinepubs/009695399/functions/open.html
which leaves it undefined.

http://www.pasc.org/interps/unofficial/db/p1003.1/pasc-1003.1-71.html
says implementations have to allow setting O_NONBLOCK even if they
ignore it.

http://www.ussg.iu.edu/hypermail/linux/kernel/9911.3/0530.html
claims other Unixes and NT implement it.

There's a thread that discusses this in a bit of detail, and
suggests that older Solaris might implement it:
http://lists.freebsd.org/pipermail/freebsd-arch/2003-April/000132.html
http://lists.freebsd.org/pipermail/freebsd-arch/2003-April/000134.html

Googling for O_NONBLOCK disk seems to be good.  I'd google more
but my baby is calling :-)
- Dan
-- 
My technical stuff: http://kegel.com
My politics: see http://www.misleader.org for examples of why I'm for regime change

^ permalink raw reply	[flat|nested] 24+ messages in thread
* [patch rfc] towards supporting O_NONBLOCK on regular files
@ 2004-10-01 20:57 Jeff Moyer
  2004-10-03 19:48 ` Pavel Machek
                   ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: Jeff Moyer @ 2004-10-01 20:57 UTC (permalink / raw)
  To: linux-kernel; +Cc: mingo, sct

This patch makes an attempt at supporting the O_NONBLOCK flag for regular
files.  It's pretty straight-forward.  One limitation is that we still call
into the readahead code, which I believe can block.  However, if we don't
do this, then an application which only uses non-blocking reads may never
get it's data.

Comments welcome.

-Jeff

--- linux-2.6.8/mm/filemap.c.orig	2004-09-30 16:33:46.881129560 -0400
+++ linux-2.6.8/mm/filemap.c	2004-09-30 16:34:12.109294296 -0400
@@ -720,7 +720,7 @@ void do_generic_mapping_read(struct addr
 	unsigned long index, end_index, offset;
 	loff_t isize;
 	struct page *cached_page;
-	int error;
+	int error, nonblock = filp->f_flags & O_NONBLOCK;
 	struct file_ra_state ra = *_ra;
 
 	cached_page = NULL;
@@ -755,10 +755,20 @@ find_page:
 		page = find_get_page(mapping, index);
 		if (unlikely(page == NULL)) {
 			handle_ra_miss(mapping, &ra, index);
+			if (nonblock) {
+				desc->error = -EWOULDBLOCK;
+				break;
+			}
 			goto no_cached_page;
 		}
-		if (!PageUptodate(page))
+		if (!PageUptodate(page)) {
+			if (nonblock) {
+				page_cache_release(page);
+				desc->error = -EWOULDBLOCK;
+				break;
+			}
 			goto page_not_up_to_date;
+		}
 page_ok:
 
 		/* If users can be writing to this page using arbitrary
@@ -1004,7 +1014,7 @@ __generic_file_aio_read(struct kiocb *io
 			desc.error = 0;
 			do_generic_file_read(filp,ppos,&desc,file_read_actor);
 			retval += desc.written;
-			if (!retval) {
+			if (!retval || desc.error) {
 				retval = desc.error;
 				break;
 			}

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

end of thread, other threads:[~2004-10-21 20:26 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-05 13:07 [patch rfc] towards supporting O_NONBLOCK on regular files Dan Kegel
  -- strict thread matches above, loose matches on Subject: below --
2004-10-01 20:57 Jeff Moyer
2004-10-03 19:48 ` Pavel Machek
2004-10-13 14:28   ` Jeff Moyer
2004-10-14 17:39     ` Pavel Machek
2004-10-05 11:27 ` Marcelo Tosatti
2004-10-06 13:13   ` Jeff Moyer
2004-10-06 12:01     ` Marcelo Tosatti
2004-10-07  3:31       ` Stephen C. Tweedie
2004-10-07 10:12         ` Marcelo Tosatti
2004-10-07 12:30           ` Arjan van de Ven
2004-10-11 18:32           ` Stephen C. Tweedie
2004-10-11 18:58             ` Jeff Moyer
2004-10-11 21:49               ` Stephen C. Tweedie
2004-10-13 14:26                 ` Jeff Moyer
2004-10-15 15:44                   ` Jeff Moyer
2004-10-15 16:19                     ` Stephen C. Tweedie
2004-10-17  7:59                     ` Alexandre Oliva
2004-10-17 11:20                       ` Ingo Molnar
2004-10-17 19:38                         ` Alexandre Oliva
2004-10-18 16:51                           ` Jeff Moyer
2004-10-19  6:04                             ` Alexandre Oliva
2004-10-21 20:14                             ` James Antill
2004-10-05 15:35 ` Rik van Riel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox