From patchwork Sat Nov 18 19:33:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13460249 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 3CE74C5AE5C for ; Sat, 18 Nov 2023 19:33:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B12636B007E; Sat, 18 Nov 2023 14:33:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AC2646B00B5; Sat, 18 Nov 2023 14:33:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B1106B00BB; Sat, 18 Nov 2023 14:33:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8C38A6B007E for ; Sat, 18 Nov 2023 14:33:25 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 5C206405DF for ; Sat, 18 Nov 2023 19:33:25 +0000 (UTC) X-FDA: 81472073970.01.8F155C6 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf30.hostedemail.com (Postfix) with ESMTP id 7EDE880003 for ; Sat, 18 Nov 2023 19:33:23 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=axpIjEbf; spf=pass (imf30.hostedemail.com: domain of cel@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=cel@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700336003; 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=DVrmI4ex1y/yrVbfQb7JJ5geXApbcYWqLVmGAkpLTDQ=; b=c00EdROXHP9y2o0k1xtvTviULtcwQ+XHV0zcxyU8bQKgDr4yFWL/PE7X1w8iNhC3YV09z2 2bNsZNMF8It7NsTq2o6n5jOMYzaRNaVbs21iOVimHaGQbMog2FLknLM/klnIZTBp9a7M6q hysB+joMfQvFxGEJf21oPrURuTtvwyI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700336003; a=rsa-sha256; cv=none; b=QN/LvSx19EgLAjdZI62+jMxr7eHpuSYpXfkBybQ/w/uuMH21oYAIZ20lm2FdrxhwaQdI8Y i+o7gcCJWhh1OT5Di1WCRAHlRL0/JQ6PCKJcdmfrmL/cxA5OyxlOqiMxdiVqEoVaw4XF0V NbDM1evAiobFYQpaIDjpMtTL3rooEGE= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=axpIjEbf; spf=pass (imf30.hostedemail.com: domain of cel@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=cel@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id BE3B6B81D1C; Sat, 18 Nov 2023 19:33:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24BB3C433CD; Sat, 18 Nov 2023 19:33:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700336000; bh=2u8efAeqRkdyYk6OGbAngLt3+NDkDGes87T6oIEMH54=; h=Subject:From:To:Cc:Date:From; b=axpIjEbffsfxZpVPTIDOskxwgtVAtFbd7tdF2QGFwzvfn8PmN9gqpIALDOS7dzJYh wm74p+fSgyXJhQHd94pfMkB7+FHqHe5b5YBX9NO7L56D/21TS5xyru0qNCMJASLJ+0 XO6mam8c7fIkLMkWAuDa/vbZZQ44ytmuEI5oy/0JPoffyCdipFgwJ5Wi9FBJA02Vmv KKkdXtkN+KnW2qp8uURYYaS8W0tFipP1VRPnHv6HcqlhWfZhNq0r2Us7gaT1yzV6Xi Apb/d33CvlTJ6ku25DMBqmXPQMEqIU92GhnUNgjBjKZJfJf42O1SFkXwpuIWHamNCS aeZgOjKLrD5Dg== Subject: [PATCH v3] 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: Sat, 18 Nov 2023 14:33:19 -0500 Message-ID: <170033563101.235981.14540963282243913866.stgit@bazille.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 X-Stat-Signature: ccg4q1eqmnqri5bxa77kjx1i4aed66dx X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 7EDE880003 X-Rspam-User: X-HE-Tag: 1700336003-850087 X-HE-Meta: U2FsdGVkX19Gnlu00TXk+Y+FdAIOL8J2aGeBO6G7Q8lmMJg4dzz1MkSXq2ioeKHnq6wpVKqxfLqxO3NhFAo4ohweCm3QjoEE4gJ0fdZpAunY5Z/3dZzU3E/biCGL21OODxwDMiyRAIfPSwgWn86CE6PEeb2iE/UkMmmNijEMEAAXtjkTBZRZHDIyeA91ZhQGn2UtgrHiD3Y+OpgZu5vKcgdQ6VIl0HiOI/J4NYLXxDGsPhpZfvy/TL6tKoLt6HgP3vPqUQOG1LSLgntTb709deAzz4+75SgVf7mfmUehvWntuvvJRTpQQeHxMbCwDUzpyOLX0/bGmJpKS09FTVaryr+EMlB424RrcadfVyfKhsrD4E1wWye2zmMVJzyNPDhi+wDlfMjR78KHwkXBh8iq00ZfUsNG2Sv5JJlXyisdJW9DRTdo2SUctB2D7IOH5XUrs9Js/sKO43K2hfBoOlKjZyFSkruSKekmiuSD6+yrtiUq9S6t5rlWrd2dlwuWKbzl2XiFtKQeZIjgq1tpLc0xALYGLQ7T0RD4Ot1Z0PNV/6gQ8FnXGkWxlsKPvVZ7MiDVwlyrGJbZB670sgZGXBBUx/Ip41g9WOzPXHlm6oV/2sLdBNkaRWV6f/CHE+MImnk3xLlQYt88AH0oUoDNBflyplgzz8/hZXLRKCa0OgrhmZrRclmIUiHE38YFK9RhgQVxLqYeUELSe7H269os965jK0pTlP1rz4t6kRDOyiv2nMm1LIKxzrsf81KvYrOfnuv6Ma1vabbEdUSNDlG+3+f8wu38uMKGhpTNHV5hjyKDYyta0xJxHzfZkDbamoADh0RaJc9V+lUanfg26jHjybquNKeMH5V3Ss/qUnEAEni9hpQfwcFbaBvcN+zqa5dDZm3UGvv11TPv70mLkeJ7aJfrswTdeN9aGb19gVCUf9bSVsprUK8Obj+TQZ7vLWEqZ4QE06OD1IuaRPMJ3sNjBDr qfrMKd/J U6e3f1tRc7DDgiWCAFFPncs5h3Mny2Y7S8J+fVf4hHYVnx94qH91aH5/YqN7sd9L/zb8bfBG/bhHXCWZo81A91wtPkHwM5wB16egQwgc8E7YO/arAbOB8xg7hHL+OeHezypL2VUVcF2YuPSbLX5X/YLhe1/ZRTvg3JyYkNsf4972gMi+qdSacWsutgqyXAxHaTkIwXDbItg+5f6hDij5uMxH7D913BIpXc/2fhPWxOR0v48Mo66TwjYK2HlYliAF6oxa4IwoIzN5xhGTSZigNouiqXdzB4CT6aR5O 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 | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) This patch passes Tavian's reproducer. fstests over NFS shows no regression. However, generic/676 fails when running directly against a tmpfs mount: QA output created by 676 -All tests passed +Unexpected EOF while reading dir. I will look into that. Changes since v2: - Go back to marking EOD in file->private_data (with a comment) Changes since RFC: - Keep file->private_data stable while directory descriptor remains open diff --git a/fs/libfs.c b/fs/libfs.c index e9440d55073c..851e29fdd7e7 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,7 @@ static void offset_iterate_dir(struct inode *inode, struct dir_context *ctx) while (true) { dentry = offset_find_next(&xas); if (!dentry) - break; + return ERR_PTR(-ENOENT); if (!offset_dir_emit(ctx, dentry)) { dput(dentry); @@ -447,6 +447,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 +480,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); + /* In this case, ->private_data is protected by f_pos_lock */ + if (ctx->pos == 2) + file->private_data = NULL; + else if (file->private_data == ERR_PTR(-ENOENT)) + return 0; + file->private_data = offset_iterate_dir(d_inode(dir), ctx); return 0; }