From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06C09EB64D9 for ; Wed, 12 Jul 2023 07:53:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231842AbjGLHxh (ORCPT ); Wed, 12 Jul 2023 03:53:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231797AbjGLHxg (ORCPT ); Wed, 12 Jul 2023 03:53:36 -0400 Received: from out-24.mta0.migadu.com (out-24.mta0.migadu.com [91.218.175.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4073DE77 for ; Wed, 12 Jul 2023 00:53:35 -0700 (PDT) Message-ID: <858c3f16-ffb3-217e-b5d6-fcc63ef9c401@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1689148413; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FC42AF7xix5hDLWrq2t7lf71x97Aeew4iatdDcbvI/k=; b=kuZPChWNeKsG/KDgvuhXuMbYLYihVnXzPB1re2KFiq9BTKXFiU/NkrZtGW/8seNtjL1CDD bpbeaocDtE/qkypWN5rDO6eFejmZpHE7E/ZvaogBBDqQesB0ESGD0FwEKfFWx4Hsa3CYEQ pjhJd/86jh13krreotIQnwrkS5ndPmo= Date: Wed, 12 Jul 2023 15:53:24 +0800 MIME-Version: 1.0 Subject: Re: [PATCH 3/3] io_uring: add support for getdents Content-Language: en-US To: Dominique Martinet Cc: io-uring@vger.kernel.org, Jens Axboe , Pavel Begunkov , Christian Brauner , Alexander Viro , Stefan Roesch , Clay Harris , Dave Chinner , linux-fsdevel@vger.kernel.org, Wanpeng Li References: <20230711114027.59945-1-hao.xu@linux.dev> <20230711114027.59945-4-hao.xu@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Hao Xu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org On 7/11/23 20:15, Dominique Martinet wrote: > Hao Xu wrote on Tue, Jul 11, 2023 at 07:40:27PM +0800: >> diff --git a/io_uring/fs.c b/io_uring/fs.c >> index f6a69a549fd4..77f00577e09c 100644 >> --- a/io_uring/fs.c >> +++ b/io_uring/fs.c >> @@ -291,3 +298,56 @@ void io_link_cleanup(struct io_kiocb *req) >> putname(sl->oldpath); >> putname(sl->newpath); >> } >> + >> +int io_getdents_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) >> +{ >> + struct io_getdents *gd = io_kiocb_to_cmd(req, struct io_getdents); >> + >> + if (READ_ONCE(sqe->off) != 0) >> + return -EINVAL; >> + >> + gd->dirent = u64_to_user_ptr(READ_ONCE(sqe->addr)); >> + gd->count = READ_ONCE(sqe->len); >> + >> + return 0; >> +} >> + >> +int io_getdents(struct io_kiocb *req, unsigned int issue_flags) >> +{ >> + struct io_getdents *gd = io_kiocb_to_cmd(req, struct io_getdents); >> + struct file *file; >> + unsigned long getdents_flags = 0; >> + bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK; >> + bool should_lock = false; >> + int ret; >> + >> + if (force_nonblock) { >> + if (!(req->file->f_mode & FMODE_NOWAIT)) >> + return -EAGAIN; >> + >> + getdents_flags = DIR_CONTEXT_F_NOWAIT; >> + } >> + >> + file = req->file; >> + if (file && (file->f_mode & FMODE_ATOMIC_POS)) { > > If file is NULL here things will just blow up in vfs_getdents anyway, > let's remove the useless check > >> + if (file_count(file) > 1) > > I was curious about this so I found it's basically what __fdget_pos does > before deciding it should take the f_pos_lock, and as such this is > probably correct... But if someone can chime in here: what guarantees > someone else won't __fdget_pos (or equivalent through this) the file > again between this and the vfs_getdents call? > That second get would make file_count > 1 and it would lock, but lock > hadn't been taken here so the other call could get the lock without > waiting and both would process getdents or seek or whatever in > parallel. > Hi Dominique, This file_count(file) is atomic_read, so I believe no race condition here. > > That aside I don't see any obvious problem with this. >