On 3/4/20 12:28 PM, Jeff Layton wrote: > On Wed, 2020-03-04 at 12:10 -0700, Jens Axboe wrote: >> On 3/4/20 12:03 PM, Josh Triplett wrote: >>> On Wed, Mar 04, 2020 at 11:00:10AM -0700, Jens Axboe wrote: >>>> One of the fabled features with chains has long been the desire to >>>> support things like: >>>> >>>> <open fileX><read from fileX><close fileX> >>>> >>>> in a single chain. This currently doesn't work, since the read/close >>>> depends on what file descriptor we get on open. >>>> >>>> The original attempt at solving this provided a means to pass >>>> descriptors between chains in a link, this version takes a different >>>> route. Based on Josh's support for O_SPECIFIC_FD, we can instead control >>>> what fd value we're going to get out of open (or accept). With that in >>>> place, we don't need to do any magic to make this work. The above chain >>>> then becomes: >>>> >>>> <open fileX with fd Y><read from fd Y><close fd Y> >>>> >>>> which is a lot more useful, and allows any sort of weird chains without >>>> needing to nest "last open" file descriptors. >>>> >>>> Updated the test program to use this approach: >>>> >>>> https://git.kernel.dk/cgit/liburing/plain/test/orc.c?h=fd-select >>>> >>>> which forces the use of fd==89 for the open, and then uses that for the >>>> read and close. >>>> >>>> Outside of this adaptation, fixed a few bugs and cleaned things up. >>> >>> I posted one comment about an issue in patch 6. >>> >>> Patches 2-5 look great; for those: >>> Reviewed-by: Josh Triplett <josh@xxxxxxxxxxxxxxxx> >>> >>> Thanks for picking this up and running with it! >> >> Thanks for doing the prep work! I think it turned out that much better >> for it. >> >> Are you going to post your series for general review? I just stole >> your 1 patch that was needed for me. >> > > This does seem like a better approach overall. > > How should userland programs pick fds to use for this though? Should you > just start with some reasonably high number that you don't expect to > have been used by the current process or is there some more reliable way > to do it? If you look at Josh's separate posting, he has a patch that sets the min_fd for the normal dynamic allocations. With that, you could set that to eg 1000, and then know that anything below that would be fair game to use for the selectable fd values. -- Jens Axboe