On 9/14/21 4:36 PM, Jens Axboe wrote: > On 9/14/21 9:12 AM, Pavel Begunkov wrote: >> It might be inconvenient that direct open/accept deviates from the >> update semantics and fails if the slot is taken instead of removing a >> file sitting there. Implement this auto-removal. >> >> Note that removal might need to allocate and so may fail. However, if an >> empty slot is specified, it's guaraneed to not fail on the fd >> installation side for valid userspace programs. It's needed for users >> who can't tolerate such failures, e.g. accept where the other end >> never retries. >> >> Suggested-by: Franz-B. Tuneke <franz-bernhard.tuneke@xxxxxxxxxxxxxx> >> Signed-off-by: Pavel Begunkov <asml.silence@xxxxxxxxx> >> --- >> >> v2: simplify io_rsrc_node_switch_start() handling >> >> fs/io_uring.c | 52 +++++++++++++++++++++++++++++++++------------------ >> 1 file changed, 34 insertions(+), 18 deletions(-) >> >> diff --git a/fs/io_uring.c b/fs/io_uring.c >> index a864a94364c6..58c0cbfdd128 100644 >> --- a/fs/io_uring.c >> +++ b/fs/io_uring.c >> @@ -8287,11 +8287,27 @@ static int io_sqe_file_register(struct io_ring_ctx *ctx, struct file *file, >> #endif >> } >> >> +static int io_queue_rsrc_removal(struct io_rsrc_data *data, unsigned idx, >> + struct io_rsrc_node *node, void *rsrc) >> +{ >> + struct io_rsrc_put *prsrc; >> + >> + prsrc = kzalloc(sizeof(*prsrc), GFP_KERNEL); >> + if (!prsrc) >> + return -ENOMEM; >> + >> + prsrc->tag = *io_get_tag_slot(data, idx); >> + prsrc->rsrc = rsrc; >> + list_add(&prsrc->list, &node->rsrc_list); >> + return 0; >> +} > > I know this code is just being moved, but I tend to like making the > expected/fast path inline: I think it's more natural as now, as we always have ret = do_something(); if (ret) return ret; ret = do_something2(); if (ret) goto err; And I remember you telling once "... I tend to like to do the error path like that unless it's a hot path ...". So maybe just add unlikely()? > prsrc = kzalloc(sizeof(*prsrc), GFP_KERNEL); > if (prsrc) { > prsrc->tag = *io_get_tag_slot(data, idx); > prsrc->rsrc = rsrc; > list_add(&prsrc->list, &node->rsrc_list); > return 0; > } > return -ENOMEM; > -- Pavel Begunkov