Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7100308rwr; Wed, 10 May 2023 04:02:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Ba7nT8vDapE90IpYWoqnv1Ldd7bYhL7TULXw/lScD13vQTa/DbqiDZQE+h2KSdam4hFW8 X-Received: by 2002:a05:6a20:7487:b0:ee:bd92:4b3b with SMTP id p7-20020a056a20748700b000eebd924b3bmr21701687pzd.19.1683716541827; Wed, 10 May 2023 04:02:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683716541; cv=none; d=google.com; s=arc-20160816; b=SXP47zM60et0OMmanu9zya6G8UEmSRDZZmWW4zHOXTodoWbYseD6pzl3Ort0nI3wWo uM1DZmTDPswhv1Ld5Y4pYs9x2ZVqCXrN2QT0q/eC2ZpRRIVBPhCp9tZJYH6dqiWXXvtW mSWY0VEESbB+1rapB3xJYcoDHXJKtmHuJTjkvsPOzkDU9fZ6nvvZWiYxKTApuLpM7XNc ln3LryMb0wZa9hqGuSsuL+OIkl+c0cOfaH6bz5xFoPFf334y142/sebMoYB9ElTh/0PC 1EXa5QadBtB5B1MGcvwkhk3AiVszbITUJkXJ55uf7QJWqsz9uHLy+lmT12jaX8/yN6RS zAWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature:dkim-signature; bh=yLt30ccVZYSI/65st0oAv5X6KGUwx7EeVr+r1ZsxAqc=; b=qi8HawmA976rj6wdQip3WHmAwvps9nztdblqFt5TegKHCHbPjNercHVhvyRpAEb01w MZk3TpFdVxru7/1wgZOGBen8Ug90xWKnwGrKai7h5R3fgoCtcxkiP17SlhIBwH2b2qYj YfeqsYVj4zG7PEdP6KTrtMVL4gF7NKZn3z9L9/mGCNHuF9pjSaA1+F/yH29JKfPOsCtq nwzblaiwcAImhzNpgJqi+x2Dv8AVwsOY0Q+6aTl1tBIlZjfR/dEwFGyITRClH5ar3k57 UJZvdS5h9UH2Opzg10wNpIdD25In9P1rPot93hcmK1FhesjblKkTeiJRcU5VG7L83x1G kmxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codewreck.org header.s=2 header.b=nobaswzK; dkim=pass header.i=@codewreck.org header.s=2 header.b=EZGCrcnQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codewreck.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j23-20020a637a57000000b00525064abb6csi3461572pgn.240.2023.05.10.04.02.09; Wed, 10 May 2023 04:02:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@codewreck.org header.s=2 header.b=nobaswzK; dkim=pass header.i=@codewreck.org header.s=2 header.b=EZGCrcnQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codewreck.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236612AbjEJKx7 (ORCPT + 99 others); Wed, 10 May 2023 06:53:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236671AbjEJKxc (ORCPT ); Wed, 10 May 2023 06:53:32 -0400 Received: from nautica.notk.org (ipv6.notk.org [IPv6:2001:41d0:1:7a93::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73E417D90; Wed, 10 May 2023 03:53:26 -0700 (PDT) Received: by nautica.notk.org (Postfix, from userid 108) id DCEBEC026; Wed, 10 May 2023 12:53:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1683716004; bh=yLt30ccVZYSI/65st0oAv5X6KGUwx7EeVr+r1ZsxAqc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=nobaswzK0qfQPonWpcsjEiwfLGSAeY/3jSJ2fP8YGX57ybA+L6xdLHkTbU6bAHq+b SFT4kFIn+IYL6yXq53Xp0OgekF4092FihADD55MAE79hT3Vise67ogY2fL6V4CzCet tEBrrkDWDC/xd+ji4PL2+oFhfkGPWLzXtBatLaqcUBlCGxV6E/k9AfraXji8WQ5eky Gw7Q50oxdYUXrrzwqh63c62U08xXhwczsKKe9GVrSnBd6RXY7TvOPtmfZAmJbBsMdj 8rV8qF8Jvat3CvioscCx1sQJdirv5T0cKHhFNVQ4tHEJGNNqwyyM/ii9tHDhNPl8O0 Vk8J9+2GqtkOg== X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from odin.codewreck.org (localhost [127.0.0.1]) by nautica.notk.org (Postfix) with ESMTPS id 6A376C01E; Wed, 10 May 2023 12:53:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1683716003; bh=yLt30ccVZYSI/65st0oAv5X6KGUwx7EeVr+r1ZsxAqc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=EZGCrcnQphjBkKcNP7P612MZj7jJINdX9s/+jITHBbjs+BkUeSU7sH1ufIMokm2u1 thA80G7tsP417bFjDh+D1CPVmisFDeUu4x1HeJVo1j0AcmKskw8GKQGsStv1ZPUL30 8kjELVSkpoYnnQmRWPcj+0viaIfRXh/m6X6eCJcAD0JB4LOHROPeatG3npesCeMI7o 34yQWD1723BHa4FLqdSjvHQRv15bYWZr6ETf0XWzj2yp0HXwGUQehT5XPgrxI56Zzr 91F6JLZIRx9SyS6ab7Kkt3LTmAKNrEARE2E8ZCOnAQHnsgxH5FdWdJVBY9dOWgn+wH 1L4RBtOt/X6iw== Received: from [127.0.0.2] (localhost [::1]) by odin.codewreck.org (OpenSMTPD) with ESMTP id 7b5bfb63; Wed, 10 May 2023 10:53:02 +0000 (UTC) From: Dominique Martinet Date: Wed, 10 May 2023 19:52:52 +0900 Subject: [PATCH v2 4/6] kernfs: implement readdir FMODE_NOWAIT MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230422-uring-getdents-v2-4-2db1e37dc55e@codewreck.org> References: <20230422-uring-getdents-v2-0-2db1e37dc55e@codewreck.org> In-Reply-To: <20230422-uring-getdents-v2-0-2db1e37dc55e@codewreck.org> To: Alexander Viro , Christian Brauner , Jens Axboe , Pavel Begunkov , Stefan Roesch Cc: Clay Harris , Dave Chinner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, Dominique Martinet X-Mailer: b4 0.13-dev-f371f X-Developer-Signature: v=1; a=openpgp-sha256; l=1751; i=asmadeus@codewreck.org; h=from:subject:message-id; bh=wZy/djlXvmoURd9RMjzidbOvF/oy0mSJeWlqAdKVlLs=; b=owEBbQKS/ZANAwAIAatOm+xqmOZwAcsmYgBkW3eOjSYuNu0/+DbVaVJAMlyNeKQRwVDOytJtX K2al+2U3eWJAjMEAAEIAB0WIQT8g9txgG5a3TOhiE6rTpvsapjmcAUCZFt3jgAKCRCrTpvsapjm cHz/EACzgdngFCVzZHoRfItwuuqAMsrGmLCG07aQFKsIX2bDy4EuMQvz252mAWhajgMdRA4lWLJ pFMAzzzgOR0Z5/tyl2ROWfboSWqwo6eNlBc/iMeMUc2oaPw+Ermndd++p3zWDMSlPV8Fw4sW99U 1NKEAY02oT7DqtfbqrKLZ39iNz9AdPc7HKbQevknz6zatsvL0hQvXITzL5FAuLiQ1LxmO0BpTl+ HRbMjIPfNCyMT3VbUvQcBAaaLutQ8QPTgfWvty0Cl4ehyvPmgub5/EdG/Y2XYB/ci2ho96jlpj1 hkB+K//2mlW2yyTbT6buUmg+p0B3BDmoS9KxxsvOTpEspwCNWvFqS0mkeDbnBj5wmjgXh+L+Vlv aKMlVe0Gw9RJm7Hnc3TsoiSAq+QXZyYEWvxRVCK8wcJDxJ4RsDl2WIKqpH/lxb3jf55NAbzlIoH FQNHZwNkXc9t9qRgwobztHeRcqR2EqlQTt+8rbYWf4V1PNxU9b5aZDBbcLY4dTQ3tlcE1PjiEo2 ODBpGlv13ladtn014MvpLnLndyeoIc2klueNdTbTxa3OZaxH1yY3i0LlZu4Gmg87dQjFxn+i49W LI2yEE/p1ow9gPxHLRmOOfE0s7cQYCUb+/rmpxGcuAw864lnKbWPcU7iNSIK96UM07T3MGI3mrv cGheGwzHYpOpL5Q== X-Developer-Key: i=asmadeus@codewreck.org; a=openpgp; fpr=B894379F662089525B3FB1B9333F1F391BBBB00A Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since down_read can block, use the _trylock variant if NOWAIT variant has been requested. (can probably do a little bit better style-wise) Signed-off-by: Dominique Martinet --- fs/kernfs/dir.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index 45b6919903e6..5a5b3e7881bf 100644 --- a/fs/kernfs/dir.c +++ b/fs/kernfs/dir.c @@ -1824,7 +1824,12 @@ static int kernfs_fop_readdir(struct file *file, struct dir_context *ctx) return 0; root = kernfs_root(parent); - down_read(&root->kernfs_rwsem); + if (ctx->flags & DIR_CONTEXT_F_NOWAIT) { + if (!down_read_trylock(&root->kernfs_rwsem)) + return -EAGAIN; + } else { + down_read(&root->kernfs_rwsem); + } if (kernfs_ns_enabled(parent)) ns = kernfs_info(dentry->d_sb)->ns; @@ -1845,6 +1850,12 @@ static int kernfs_fop_readdir(struct file *file, struct dir_context *ctx) if (!dir_emit(ctx, name, len, ino, type)) return 0; down_read(&root->kernfs_rwsem); + if (ctx->flags & DIR_CONTEXT_F_NOWAIT) { + if (!down_read_trylock(&root->kernfs_rwsem)) + return 0; + } else { + down_read(&root->kernfs_rwsem); + } } up_read(&root->kernfs_rwsem); file->private_data = NULL; @@ -1852,7 +1863,14 @@ static int kernfs_fop_readdir(struct file *file, struct dir_context *ctx) return 0; } +static int kernfs_fop_dir_open(struct inode *inode, struct file *file) +{ + file->f_mode |= FMODE_NOWAIT; + return 0; +} + const struct file_operations kernfs_dir_fops = { + .open = kernfs_fop_dir_open, .read = generic_read_dir, .iterate_shared = kernfs_fop_readdir, .release = kernfs_dir_fop_release, -- 2.39.2