lkml.org 
[lkml]   [2015]   [Apr]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH] usb: gadget: ffs: don't allow to open with O_NONBLOCK flag
Date
On Fri, Apr 03 2015, Robert Baldyga <r.baldyga@samsung.com> wrote:
> Hi Michal,
>
> On 04/01/2015 05:17 PM, Michal Nazarewicz wrote:
>> On Wed, Apr 01 2015, Robert Baldyga <r.baldyga@samsung.com> wrote:
>>> FunctionFS can't support O_NONBLOCK because read/write operatons are
>>> directly translated into USB requests which are asynchoronous, so we
>>> can't know how long we will have to wait for request completion. For
>>> this reason in case of open with O_NONBLOCK flag we return
>>> -EWOULDBLOCK.
>>
>> ‘can’t’ is a bit strong of a word here though. It can, but in a few
>> cases it doesn’t.
>>
>> It kinda saddens me that this undoes all the lines of code that were put
>> into the file to support O_NONBLOCK (e.g. FFS_NO_SETUP path of
>> ffs_ep0_read).
>>
>> I’m also worried this may break existing applications which, for better
>> or worse, open the file with O_NONBLOCK.
>>
>> Most importantly though, this does not stop users from using fcntl to
>> set O_NONBLOCK, so if you really want to stop O_NONBLOCK from being set,
>> that path should be checked as well (if possible).
>
> I want rather to inform users that non-blocking i/o wouldn't work for
> epfiles. Indeed we can handle O_NONBLOCK for ep0 (for the same reason we
> can have poll), but for other epfiles there is no way to check if
> read/write operation can end up in short time.

There is potentially a way to implement O_NONBLOCK for epfiles. This
would require adding a new state property to epfile and moving
completion structure from stack to epfile. In pseudo code we would
have:

epfile->state = FREE

epfile_io(direction)
if epfile->state == FREE
queue(ep->req)
epfile->state = PENDING

if epfile->state == PENDING
if O_NONBLOCK
return -EAGAIN
wait
epfile->state = FINISHED

// epfile->state == FINISHED
copy data
epfile->state = FREE
return

I think this is the only ‘technically correct’ solution, but I dunno if
it is worth implementing especially since AIO is available.

--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michał “mina86” Nazarewicz (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--


\
 
 \ /
  Last update: 2015-04-07 16:21    [W:0.061 / U:0.220 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site