From patchwork Fri Jan 24 19:19:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13949886 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 12009C0218B for ; Fri, 24 Jan 2025 19:20:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EEC9C280099; Fri, 24 Jan 2025 14:19:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E9C3D280092; Fri, 24 Jan 2025 14:19:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1717280099; Fri, 24 Jan 2025 14:19:58 -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 AC75B280092 for ; Fri, 24 Jan 2025 14:19:58 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 5D1491C8FD0 for ; Fri, 24 Jan 2025 19:19:58 +0000 (UTC) X-FDA: 83043310476.16.56A3C66 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf26.hostedemail.com (Postfix) with ESMTP id 9230214000B for ; Fri, 24 Jan 2025 19:19:56 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Bw2F45L6; spf=pass (imf26.hostedemail.com: domain of cel@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cel@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737746396; 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=KIIV21lLVO3g9WZ61MfwaYlRfGjTNt4sT2ieQbcpK+A=; b=EkG34PaLhKde2ggAsD+tXrUxR3N7DLsJsyA8aA/wzQk+/KOX/C2iA7h+eYv4ASoJGhHfXw 9pxlxdDFlO2x/HkLL7uHc6PEdHYuA2vc83YvHxUeIYer3n0vYKP0HGCeSwBCkgOSEI+L7C UZoaCkJFaBklkZfITsqyJ/gWV3ntY28= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Bw2F45L6; spf=pass (imf26.hostedemail.com: domain of cel@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cel@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737746396; a=rsa-sha256; cv=none; b=3w4dazxMuXMSWwkZ8PckfzxgoUljbiOuo91HVKQ4stDhaHrKSjhjoLvHIFADIcl4gwuVyg O6h1EEfapW39POXTLY47E9I2ZLl1wK7gqWhGC0KRdowP8kCLR5OtBvC2yNQelArYZTLsi5 mn0Aq25JR7IRevUoC4Hmi90ZJnqiqEM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 679FE5C6195; Fri, 24 Jan 2025 19:19:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55E93C4CED2; Fri, 24 Jan 2025 19:19:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737746395; bh=S3TpyVqlQ6GbQ6WEv5W4bM5DS5m/bnNZcBueUm6fZKc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bw2F45L6uyN95VvlhmGZ+g4u/m5LECYA5/LAsY1EmhxFlU2jq6MfD+cMGacR+Ld2v p0aTtj40pSk6001/wmYSKhZDxqdzalUgg29lktQoX7WM/It7P5JeL0DDTbi2BgarK1 aqg3rsJYNXlDSgEfdlA9HPITqPGdQ7b6a5B9okkPLIl12h8XQFGY32nmKeBdFDlJR/ eeS/6GfYh+zNGGZkiMitIsaKbpA9TBHhGrY0MZt6ziQZlAFXK7Qx27N/G5+G3q8TDh MFhqHTARUZwQCvDprCMXDiIXPzmJ/nbhOrwDP/bJk9U/7jIRCPya2sMAV9/1DS3yvb HfkpCW6XtoGBg== From: cel@kernel.org To: Hugh Dickins , Andrew Morten , Christian Brauner , Al Viro , Greg Kroah-Hartman , Sasha Levin Cc: , , , yukuai3@huawei.com, yangerkun@huawei.com, Chuck Lever Subject: [RFC PATCH v6.6 04/10] libfs: Fix simple_offset_rename_exchange() Date: Fri, 24 Jan 2025 14:19:39 -0500 Message-ID: <20250124191946.22308-5-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250124191946.22308-1-cel@kernel.org> References: <20250124191946.22308-1-cel@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 9230214000B X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: m9dgrfh5yjho5yitrx1k3hta9auaf79o X-HE-Tag: 1737746396-627233 X-HE-Meta: U2FsdGVkX19xKf1Pn92Ynq1oMH0YY6GoGYr7k3C43u0vQV3ungeXeCaLh6cSuLGe1kARXT3FwO0Ub4GH11TSlxHxsJeDPJJp+R9zajDZtXk5zjTDbNbTxbzGOevW1Xie1QtW3jaIgaPdaXPt3Q/IVmEYtmzFynAumpNkytUwXKfzFEnaEkVJB33EQSNWFyCaHwRCA1IrkXYkCKVV2fUsAps86pPrLKcTltEjsvvG/ywe0EGIdA2rAroWjmQ+ZAz5/OIrPAAhVcbO8soCywD4dc85A232uf64WF7lJ9sfhlHe5Kne6Rv7+E7UQQYQkhPyzWh++HCSCL3CveHMmczX8IW4NUJ3oNkdmrHTfstFQ/UPT/TeUvGc4SQifZt5ApRF+Bb7OmYf7jXLF7O0zsp2fCVBpZaeSvxQtG7rCxXyx1Zo9/kRwIiPFhQg9FiPwm9cLsqwLooVPGK6QSqdZlMXQHTb3SzaOK3MFX8pR+dOSl08+uI7zsch4rcMgS3KdzrcW30he/20IjJ1IpAny0qAfb6mSsyw0go/p0Nw3IDlAOR0PHFvNEOygojwXExLZSCXMmYgujxCNHYczs+3pyZG/2Z4qOGgVx8YUcDaiArUDYf5hV5GkSA/Z8mItIsYp7yKKOH9WhMHU7Tb7Uq+EW+ZHS3Ec/I3OIUu8bTKYxbSCSmNF+phEk1wREz5SwNTb4Juwhdx5Y19uJ2kr6nze85yis4YJPEcEQPTGnF6bvRTjw4sDZO1QUZiEgx/Lvz3ijdvb4BdsXs3MlqDjZ8LsjcXTDUfKMfMg0WW48pecjIjGNq0Qo1hZCBpuDvx350ZkW+94EHdtROmHdtE5DRWaWJSKzG93itcq6dkylDdj1luxyQsRPexasEW4zn5aGvFUg6RcGpazFymti3PEz5F1j+T9nRz608czbwCCO4C0p1/+sbyb2xhRIb3xkZImbvrSIZfFKsCy3vDSSNHtK/MJMl v2hsmaEA z8Se2KfBRgL210hFWr4sP4bNGdcSBmwx4Y5vUpohQEFajuR0pesl7mEyCug/ivjihOipGaKDMLgiZ8X0fCJZMBavfFgx2wek/BnlpAb6xpKzTZ3S4119a516BnD3+DaqVHo4cn4VQOck5y6ujlbHY/CXuHZZaNiKAGmdvU7pmcIYD08f9aXmbzr3sWmuwjcr90UoryLrTrGWmGPgx8F8bkJ3NIPECsJHC7wORwGVM2hsblXDP1neLcdNwo3mrZaeXJ1VtjtiJaaKfx/Y0VCB6aEk6YMobaBS5uFxTf+vyeRFRIvA2iTrcD/hgIQ== 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 [ Upstream commit 23cdd0eed3f1fff3af323092b0b88945a7950d8e ] User space expects the replacement (old) directory entry to have the same directory offset after the rename. Suggested-by: Christian Brauner Fixes: a2e459555c5f ("shmem: stable directory offsets") Signed-off-by: Chuck Lever Link: https://lore.kernel.org/r/20240415152057.4605-2-cel@kernel.org Signed-off-by: Christian Brauner [ cel: adjusted to apply to origin/linux-6.6.y ] Signed-off-by: Chuck Lever --- fs/libfs.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index d7b901cb9af4..2029cb6a0e15 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -294,6 +294,18 @@ int simple_offset_add(struct offset_ctx *octx, struct dentry *dentry) return 0; } +static int simple_offset_replace(struct offset_ctx *octx, struct dentry *dentry, + long offset) +{ + void *ret; + + ret = xa_store(&octx->xa, offset, dentry, GFP_KERNEL); + if (xa_is_err(ret)) + return xa_err(ret); + offset_set(dentry, offset); + return 0; +} + /** * simple_offset_remove - Remove an entry to a directory's offset map * @octx: directory offset ctx to be updated @@ -351,6 +363,9 @@ int simple_offset_empty(struct dentry *dentry) * @new_dir: destination parent * @new_dentry: destination dentry * + * This API preserves the directory offset values. Caller provides + * appropriate serialization. + * * Returns zero on success. Otherwise a negative errno is returned and the * rename is rolled back. */ @@ -368,11 +383,11 @@ int simple_offset_rename_exchange(struct inode *old_dir, simple_offset_remove(old_ctx, old_dentry); simple_offset_remove(new_ctx, new_dentry); - ret = simple_offset_add(new_ctx, old_dentry); + ret = simple_offset_replace(new_ctx, old_dentry, new_index); if (ret) goto out_restore; - ret = simple_offset_add(old_ctx, new_dentry); + ret = simple_offset_replace(old_ctx, new_dentry, old_index); if (ret) { simple_offset_remove(new_ctx, old_dentry); goto out_restore; @@ -387,10 +402,8 @@ int simple_offset_rename_exchange(struct inode *old_dir, return 0; out_restore: - offset_set(old_dentry, old_index); - xa_store(&old_ctx->xa, old_index, old_dentry, GFP_KERNEL); - offset_set(new_dentry, new_index); - xa_store(&new_ctx->xa, new_index, new_dentry, GFP_KERNEL); + (void)simple_offset_replace(old_ctx, old_dentry, old_index); + (void)simple_offset_replace(new_ctx, new_dentry, new_index); return ret; }