lkml.org 
[lkml]   [2004]   [Oct]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    Date
    SubjectRe: [patch rfc] towards supporting O_NONBLOCK on regular files
    ==> Regarding Re: [patch rfc] towards supporting O_NONBLOCK on regular files; Marcelo Tosatti <marcelo.tosatti@cyclades.com> adds:

    marcelo.tosatti> On Fri, Oct 01, 2004 at 04:57:50PM -0400, Jeff Moyer
    marcelo.tosatti> wrote:
    >> 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.

    marcelo.tosatti> Hi Jeff,

    marcelo.tosatti> Curiosity: Is this defined in any UNIX standard?

    marcelo.tosatti> Adv. Programming in the UNIX environment says:

    marcelo.tosatti> 12.2 Nonblocking I/O

    marcelo.tosatti> "Nonblocking I/O lets us issue an I/O operation, such as
    marcelo.tosatti> open, read, or write and not have it block forever. If the
    marcelo.tosatti> operation cannot be completed, return is made immediately
    marcelo.tosatti> with an error noting that the operation would have
    marcelo.tosatti> blocked."

    marcelo.tosatti> He is talking about read's on descriptors (pipe's,
    marcelo.tosatti> devices, etc) which block in case of no data present, not
    marcelo.tosatti> about filesystem IO.

    marcelo.tosatti> But here we create our own semantics of O_NONBLOCK on
    marcelo.tosatti> read() of fs IO. As you say page_cache_readahead can block
    marcelo.tosatti> for one trying to allocate pages, possibly while
    marcelo.tosatti> submitting IO too.

    marcelo.tosatti> The patch is cool - might be nice to check if SuS or
    marcelo.tosatti> someone else specificies behaviour and try to match if so?

    Hi, Marcelo,

    The text below was taken from the following standard:

    IEEE Std 1003.1, 2004 Edition
    The Open Group Technical Standard
    Base Sepcifications, Issue 6
    Includes IEEE Std 1003.1-2001, IEEE Std 1003.1-2001/Cor 1-2002


    open()

    O_NONBLOCK When opening a FIFO with O_RDONLY or O_WRONLY set:
    o If O_NONBLOCK is set, an open( ) for reading-only shall return without
    delay. An open( ) for writing-only shall return an error if no process
    currently has the file open for reading.
    o If O_NONBLOCK is clear, an open( ) for reading-only shall block the
    calling thread until a thread opens the file for writing. An open( ) for
    writing-only shall block the calling thread until a thread opens the file
    for reading.

    When opening a block special or character special file that supports non-
    blocking opens:
    o If O_NONBLOCK is set, the open( ) function shall return without blocking
    for the device to be ready or available. Subsequent behavior of the device
    is device-specific.
    o If O_NONBLOCK is clear, the open( ) function shall block the calling
    thread until the device is ready or available before returning.

    Otherwise, the behavior of O_NONBLOCK is unspecified.

    read()

    When attempting to read a file (other than a pipe or FIFO) that supports
    non-blocking reads and has no data currently available:
    o If O_NONBLOCK is set, read( ) shall return -1 and set errno to [EAGAIN].
    o If O_NONBLOCK is clear, read( ) shall block the calling thread until
    some data becomes available.
    o The use of the O_NONBLOCK flag has no effect if there is some data
    available.

    write()

    When attempting to write to a file descriptor (other than a pipe or FIFO)
    that supports non- blocking writes and cannot accept the data immediately:
    o If the O_NONBLOCK flag is clear, write( ) shall block the calling
    thread until the data can be accepted.
    o If the O_NONBLOCK flag is set, write( ) shall not block the thread. If
    some data can be written without blocking the thread, write( ) shall
    write what it can and return the number of bytes written. Otherwise, it
    shall return -1 and set errno to [EAGAIN].


    Thanks!

    Jeff
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

    \
     
     \ /
      Last update: 2005-03-22 14:06    [W:0.059 / U:90.748 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site