Re: [PATCH 06/28] aio: implement IOCB_CMD_POLL

From: Christoph Hellwig
Date: Fri Mar 23 2018 - 14:05:30 EST


On Thu, Mar 22, 2018 at 06:16:53PM +0000, Al Viro wrote:
> On Thu, Mar 22, 2018 at 06:24:10PM +0100, Christoph Hellwig wrote:
>
> > -static void aio_complete(struct aio_kiocb *iocb, long res, long res2)
> > +static bool aio_complete(struct aio_kiocb *iocb, long res, long res2,
> > + unsigned complete_flags)
>
> Looks like all callers are following that with "if returned true,
> fput(something)". Does it really make any sense to keep that struct
> file * in different fields?

struct kiocb is used not just for aio, but for our normal read/write_iter
APIs, and it is not suitable for poll or fsync. So I can't really find
a good way to keep it common except for duplicating it in struct kiocb
and strut aio_iocb. But maybe we could pass a struct file argument
to aio_complete().

> Wait a sec... What ordering do we want for
> * call(s) of ->ki_complete
> * call (if any) of ->ki_cancel
> * dropping reference to struct file
> and what are the expected call chains for all of those?

fput must be done exactly once from inside ->ki_complete OR ->ki_cancel
in case it did manage to do the actual completion. Reference to struct
file isn't needed in aio_complete, but if aio_complete decided who
won the race we'll have to put after it (or inside it if we want to make
it common)