From patchwork Tue Nov 14 15:49:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13455560 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 09DC1C4167D for ; Tue, 14 Nov 2023 15:49:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7474B6B0284; Tue, 14 Nov 2023 10:49:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F6FB6B02DE; Tue, 14 Nov 2023 10:49:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5BE6A6B02DF; Tue, 14 Nov 2023 10:49:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4C68A6B0284 for ; Tue, 14 Nov 2023 10:49:47 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2627B1A02DA for ; Tue, 14 Nov 2023 15:49:47 +0000 (UTC) X-FDA: 81456995214.23.E8BBC87 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf17.hostedemail.com (Postfix) with ESMTP id 9718240015 for ; Tue, 14 Nov 2023 15:49:44 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=QhllcM9A; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf17.hostedemail.com: domain of cel@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=cel@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1699976985; 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-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=fPCjJjIv6dAKXTKMpZeyOsI+bzYH0O4sY4Z5T0ihuI4=; b=Yh1BhU9eLzxi8ncs/7kOr8CwBq0ApdB3vHUyHJ0Svg7dQNW+bHetaez6571HuoieIwm62j iEziQ8lkZ3fmNjroQa2V7zimHXYyLrQnWz2VnbMpBfc1+ule13MyYqgOdVJP3EkBLwTlIX RQx6fs9hq/NlKIAf0Zaa+A+qUbl2n2g= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=QhllcM9A; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf17.hostedemail.com: domain of cel@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=cel@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699976985; a=rsa-sha256; cv=none; b=XoRYaHOUjpDhtZDVXsb7b4rbegbwvYNAWXrJDqbJ1pmm8/1Wo+VE7KH9O1GpzTzgNlRSZs XX42cqxosCMDhS/Ko4ozju6JFwfKcxQUX2rVAaLEfega1h7AvzdEOl7UAomjXjbEw+pCmD gQBf/qRycGPgjAy9woAIroC9nnTjJUw= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id CFD38CE193F; Tue, 14 Nov 2023 15:49:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B326C433C7; Tue, 14 Nov 2023 15:49:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699976978; bh=PC0cKjpERz+TagjktWu/EvkBPPwibYdZVz71N3b40es=; h=Subject:From:To:Cc:Date:From; b=QhllcM9AnKqvPK+R7o97c/OhW+5zpebK4evChLwxYbgcP7RF33rQC28z7WVqv8AZJ kzKU43x/vg/xiOIWyem4E6plvGy73CGFALZs6EexOprewWKzXPjySk/kx+doNMPwVx tJ62tm0kdvSu94uUzpChpDJ4HXpYhplYqqrrKXCNUQHoaUydHlW92HrrcxSEb+A3uq 5w8KPAhJo+ZU+n5H9d8+LHGWmExhAMZJXQMeHv8vXURxB+98L5y0+H+BfO150O/q/r BKhGm7hDlLjL4SBwwJM1quL8rsdEerbhHZ4E11aSLRWKAFcUOW/U9lw9VNvlh+O1jl ZepgcH5dLy7Ig== Subject: [PATCH RFC] libfs: getdents() should return 0 after reaching EOD From: Chuck Lever To: akpm@linux-foundation.org, brauner@kernel.org, hughd@google.com, jlayton@redhat.com, viro@zeniv.linux.org.uk Cc: Tavian Barnes , Chuck Lever , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Date: Tue, 14 Nov 2023 10:49:37 -0500 Message-ID: <169997697704.4588.14555611205729567800.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 X-Rspamd-Queue-Id: 9718240015 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: z1as5pcnkq8ieng713ddcxdbot9o841n X-HE-Tag: 1699976984-725180 X-HE-Meta: U2FsdGVkX1+jPHx1Wy3G2JQ5KgxglxnL2AT1p+i7ClRjb+EWfvgjhHBH3evNHhFS2tGWpAxr8b7PQgSarTQaEIYXR+nrChxKpbdKI0G5FcY3i0yAQ4X8sdttm4Ncm5rNBRjF7/baaw8uqJxwSRhkQKlix0GV0xxIr8atXe4lg5JQh8DEjalnEU1jlM/NVjAX+2N/9fHNptHPgyI2IwFx9oT6kVUisMIm+pRoER9o4tNsY+IJORLsrvtyUiy68HGAyyEr32ivVMAfS/Hu0ReAv0wJ1Lln/StROZMlV53kIiHd198QGXlzTVmDUlzXYVzeKkxNxbDoQq8e48n8/0hl18lYVskgl6yQ0tGFTayNIOoot5HCru53m9xG86dDxopsxvZh4bVUTc3o7LnrfBpvlH4vxQVLjG1kWur8gUM1e37lgP0psA5859LDPw+ErFe7plzTb/3dxndcTF/B3dn40sbaoH5BV9DzOgcXBljixWbJiO5JcomQ8cHB1iwckIzbUPWALuzBW2EUWanX7n39E0yKqdKVjKjoqlpyaXdVNEC9voFZ3Yv0Vpx9J4RE5n9qsOr+B0xVDt5yVES5HK0EDdaclFvC+XrDfqR0MKDzwb082a6vLP1IVbhCHQZC+LLqXiweBENM9HrYHzSWzRhKI18tqwWQ1uVw5SJoWI3zESY+sKafMGcN5/8eX8i8/y6cW8VdYT+5zR0geSOYL4HrRpdkq1ZwUZMXgIqv3NQ5ss2y421ljydcBehVCS2ptuXJQpVfeH9sMas045QXKH63t+hGcVAD9eihKnEKVSo4LO3qQWoXMsAsv+fsmTDOhjVfDpAEu5Vc8+hy1CwHmGbrYGQdGNdGQgUvFN0K4ZqtJ739+dlw3nMjjptCEMoLO59fr9nxemrxx3sn33GBkeFRb/tAZx9WUzY7rlXvz8qDYnhXz9ACqawA3rgrMHFClX93ORExa/j5uHBxVWjbf9w l3JfYc1D vdopRPTgSj7TKA+x0SLkCS167kNvs1tym/qpxze3LzWtzAhcOTTejsUrdZFSyH3c85TKgMb8VQPtfPyIFs3qXolplqS0cSjAnyYWxA3RuKDCinjgQLF9cwcMoCBcxz7qZahNj9/2s1nOHu1JsPVRBuk27noYKMhOjWyFl5QK0a7vMkyfb9fIvQ0l6auQz/qknbr5tmOODh7pwmjpOJTvIh9onJ7+QQETlPSXEpAUaGBIcjkKzbuJ+V6ql1PvDfa6i8N629cs2yIXaKlj+9qzPp90OGQZjaHxOW8X5 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Chuck Lever The new directory offset helpers don't conform with the convention of getdents() returning no more entries once a directory file descriptor has reached the current end-of-directory. To address this, copy the logic from dcache_readdir() to mark the open directory file descriptor once EOD has been reached. Rewinding resets the mark. Reported-by: Tavian Barnes Closes: https://lore.kernel.org/linux-fsdevel/20231113180616.2831430-1-tavianator@tavianator.com/ Fixes: 6faddda69f62 ("libfs: Add directory operations for stable offsets") Signed-off-by: Chuck Lever --- fs/libfs.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index e9440d55073c..1c866b087f0c 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -428,7 +428,7 @@ static bool offset_dir_emit(struct dir_context *ctx, struct dentry *dentry) inode->i_ino, fs_umode_to_dtype(inode->i_mode)); } -static void offset_iterate_dir(struct inode *inode, struct dir_context *ctx) +static void *offset_iterate_dir(struct inode *inode, struct dir_context *ctx) { struct offset_ctx *so_ctx = inode->i_op->get_offset_ctx(inode); XA_STATE(xas, &so_ctx->xa, ctx->pos); @@ -437,7 +437,8 @@ static void offset_iterate_dir(struct inode *inode, struct dir_context *ctx) while (true) { dentry = offset_find_next(&xas); if (!dentry) - break; + /* readdir has reached the current EOD */ + return (void *)0x10; if (!offset_dir_emit(ctx, dentry)) { dput(dentry); @@ -447,6 +448,7 @@ static void offset_iterate_dir(struct inode *inode, struct dir_context *ctx) dput(dentry); ctx->pos = xas.xa_index + 1; } + return NULL; } /** @@ -479,7 +481,12 @@ static int offset_readdir(struct file *file, struct dir_context *ctx) if (!dir_emit_dots(file, ctx)) return 0; - offset_iterate_dir(d_inode(dir), ctx); + if (ctx->pos == 2) + file->private_data = NULL; + else if (file->private_data == (void *)0x10) + return 0; + + file->private_data = offset_iterate_dir(d_inode(dir), ctx); return 0; }