On 9/28/22 5:59 AM, Pavel Begunkov wrote: > On 9/28/22 11:55, Ben Noordhuis wrote: >> On Wed, Sep 28, 2022 at 12:02 PM Pavel Begunkov <asml.silence@xxxxxxxxx> wrote: >>> >>> On 9/28/22 10:50, Ben Noordhuis wrote: >>>> I'm trying to chain accept+read but it's not working. >>>> >>>> My code looks like this: >>>> >>>> *sqe1 = (struct io_uring_sqe){ >>>> .opcode = IORING_OP_ACCEPT, >>>> .flags = IOSQE_IO_LINK, >>>> .fd = listenfd, >>>> .file_index = 42, // or 42+1 >>>> }; >>>> *sqe2 = (struct io_uring_sqe){ >>>> .opcode = IORING_OP_READ, >>>> .flags = IOSQE_FIXED_FILE, >>>> .addr = (u64) buf, >>>> .len = len, >>>> .fd = 42, >>>> }; >>>> submit(); >>>> >>>> Both ops fail immediately; accept with -ECANCELED, read with -EBADF, >>>> presumably because fixed fd 42 doesn't exist at the time of submission. >>>> >>>> Would it be possible to support this pattern in io_uring or are there >>>> reasons for why things are the way they are? >>> >>> It should already be supported. And errors look a bit odd, I'd rather >>> expect -EBADF or some other for accept and -ECANCELED for the read. >>> Do you have a test program / reporoducer? Hopefully in C. >> >> Of course, please see below. Error handling elided for brevity. Hope >> I'm not doing anything stupid. > > Perfect thanks > >> For me it immediately prints this: >> >> 0 res=-125 >> 1 res=-9 > > The reason is that in older kernels we're resolving the read's > file not after accept but when assembling the link, which was > specifically fixed a bit later. Right, IORING_FEAT_LINKED_FILE can be checked to see if this is properly supported or not on the host. > Jens, are there any plans to backport it? If I recall I briefly looked at it, but it was a bit more involved that I would've liked. But then it got simplified a bit after the fact, so should probably be doable to get into 5.15-stable at least. Anything earlier than that stable wise is too old anyway. -- Jens Axboe