From patchwork Fri Aug 25 13:54:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 13365792 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 221C7C71133 for ; Fri, 25 Aug 2023 13:59:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B24CC2800BA; Fri, 25 Aug 2023 09:59:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD66D8E0015; Fri, 25 Aug 2023 09:59:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 99E192800BA; Fri, 25 Aug 2023 09:59:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8AF1A8E0015 for ; Fri, 25 Aug 2023 09:59:17 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 59B79806F6 for ; Fri, 25 Aug 2023 13:59:17 +0000 (UTC) X-FDA: 81162783954.24.F043988 Received: from out-251.mta1.migadu.com (out-251.mta1.migadu.com [95.215.58.251]) by imf23.hostedemail.com (Postfix) with ESMTP id 9E4F8140017 for ; Fri, 25 Aug 2023 13:59:15 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=hhFKi9wh; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf23.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.251 as permitted sender) smtp.mailfrom=hao.xu@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692971955; a=rsa-sha256; cv=none; b=nVRFk0pSY2h4FhuvoJsSfE033ye3WkTDAiwgqtRhchaULrtdioC49QN4M4oeDlQEJctrb5 ShigVzj5vm7vlMkLv0TOQOjZwPqKCyn6+UpGzWVGPBApuben6d3jCgm0jHcXUUTEyDIJBQ OpwrAYWzDPN+279kFyHsp+slR6zEwnc= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=hhFKi9wh; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf23.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.251 as permitted sender) smtp.mailfrom=hao.xu@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692971955; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=X5RgYva0uI/YfpMcRAQXXXC0hBNumZORbEO2XQnoCOE=; b=ot8NNeBudBqt7UhiuNrv31mMbR8cKDKSAMSsu+r+ezKk/yvBLzPaxEni3Uv4SwjpW1dTXr qRv2yUrV2tzYkQR8agkA/7ZVIoPbiEKI0iBPys7W8sUpXch4Prmy7WlntnSQ2FYjQhZTHs T8aJI5erOo5O44Qic76FsiblTxGxFVE= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1692971954; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X5RgYva0uI/YfpMcRAQXXXC0hBNumZORbEO2XQnoCOE=; b=hhFKi9whhR2X2IEmGg/HYYhsZrqTloqAijCXD8QFPZxM06DdOnuDX6HZcxaVx0GnWwP31a M0So32b6G0CBwnmz/554zgdXEAR2EreGyRvroTNj1npSBetZMZwgSp6p2inhLbOwP9M7D3 1+ZqQCM/k54TMM1J4bjoCTeLz5qWIys= From: Hao Xu To: io-uring@vger.kernel.org, Jens Axboe Cc: Dominique Martinet , Pavel Begunkov , Christian Brauner , Alexander Viro , Stefan Roesch , Clay Harris , Dave Chinner , "Darrick J . Wong" , linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-cachefs@redhat.com, ecryptfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-unionfs@vger.kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, codalist@coda.cs.cmu.edu, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, devel@lists.orangefs.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-mtd@lists.infradead.org, Wanpeng Li Subject: [PATCH 09/29] vfs: move file_accessed() to the beginning of iterate_dir() Date: Fri, 25 Aug 2023 21:54:11 +0800 Message-Id: <20230825135431.1317785-10-hao.xu@linux.dev> In-Reply-To: <20230825135431.1317785-1-hao.xu@linux.dev> References: <20230825135431.1317785-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 9E4F8140017 X-Stat-Signature: fyf3ine5n41gutrnqzzfepo5yaqhcn6t X-HE-Tag: 1692971955-767880 X-HE-Meta: U2FsdGVkX18z5jx6XID7lbdWY1TpuBz6EV7N8dbqYVL7Lf8udUO9VP1FdKHmL/OpvVmE5S9UnyFD5rra+MvzntcX0/ycW3nW3ZzsebWszdMDG8l8sAo3N/9qTtnj3DGC/VrTjbMMLu982w8zWRnsQtJLRcpIqH7Nb20nu1AVWDJqnP0g0gPsopPPTMoWoEaEJ+ypEg3oexmQjl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, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Hao Xu Move file_accessed() to the beginning of iterate_dir() so that we don't need to rollback all the work done when file_accessed() returns -EAGAIN at the end of getdents. Signed-off-by: Hao Xu --- fs/readdir.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/readdir.c b/fs/readdir.c index 2f4c9c663a39..6469f076ba6e 100644 --- a/fs/readdir.c +++ b/fs/readdir.c @@ -61,6 +61,10 @@ int iterate_dir(struct file *file, struct dir_context *ctx) res = -ENOENT; if (!IS_DEADDIR(inode)) { + res = file_accessed(file, ctx->flags & DIR_CONTEXT_F_NOWAIT); + if (res == -EAGAIN) + goto out_unlock; + ctx->pos = file->f_pos; if (shared) res = file->f_op->iterate_shared(file, ctx); @@ -68,8 +72,9 @@ int iterate_dir(struct file *file, struct dir_context *ctx) res = file->f_op->iterate(file, ctx); file->f_pos = ctx->pos; fsnotify_access(file); - file_accessed(file, ctx->flags & DIR_CONTEXT_F_NOWAIT); } + +out_unlock: if (shared) inode_unlock_shared(inode); else