From patchwork Fri Jan 24 19:19:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13949887 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 86FA1C0218B for ; Fri, 24 Jan 2025 19:20:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0208D28009A; Fri, 24 Jan 2025 14:20:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F1389280092; Fri, 24 Jan 2025 14:19:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD95D28009A; Fri, 24 Jan 2025 14:19:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id C12B2280092 for ; Fri, 24 Jan 2025 14:19:59 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6AA9B1409F4 for ; Fri, 24 Jan 2025 19:19:59 +0000 (UTC) X-FDA: 83043310518.24.3F11962 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf20.hostedemail.com (Postfix) with ESMTP id B20EC1C0017 for ; Fri, 24 Jan 2025 19:19:57 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Cv+scLBr; spf=pass (imf20.hostedemail.com: domain of cel@kernel.org designates 147.75.193.91 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=1737746397; 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=uIZgDGTjU47wL9R0w2LhiTH07zjHpzG6QL0BRwCgHJI=; b=FOFFN9hM1W8EbRRAcy9JGeuVDgGSHJk+8whv/vr5A6t/HFJjvKbCX8yAOmNT4gLncwdrWM yV6njPde/sYNjnDOE9MetxR/l3ecWNWOUqWyOHGtGnoeOlxbzLON0Iea484fiKJicYDSoo 0mCNAfkkrisAJ5a2uNBfJcqZRRSrhtE= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Cv+scLBr; spf=pass (imf20.hostedemail.com: domain of cel@kernel.org designates 147.75.193.91 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=1737746397; a=rsa-sha256; cv=none; b=5m3vigL629MP4NKU0gCDWMCaqsxkL9VY4qBxhWjptyD0WmB/S3FEK0gD+yfXJhFlMiAPjK /lnZpp0M2DRpD6JiQDfzLIpPcAMd8UI9DEH+N5Biv/l2PyU9VpBukUbiRfp6y5v8BsNsCO rIdFPUI1JkewUcZsKd62sAS86/qrT3Q= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id BEC93A41DB0; Fri, 24 Jan 2025 19:18:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E72CC4CEE5; Fri, 24 Jan 2025 19:19:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1737746396; bh=zxSHvTXBTLPfQg38mkpreNxvil2Vzc9/HC9eEuTBUzs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cv+scLBrqN+k9/W+qvAwD8sQxTVRLnaM5jdmvabrIKB/9GAQAsSBHaUyeMBWok4SX JcGAbXH636Br7W7QbTZB5O1npwacuax3JCvZ8HD3Vsh4diKEMf/zo0iJlzPaQ7oqh9 rqxvcBOrc9XobhsksfGqQcKnQ75rkDVAFFmIyOdRDHCoI89AUDP/rqWRBZOzm85UO3 hIHijzNeUhk8Aify8yQIke4Gix3/3m6hGBMUeWkWMPWFDnKen/vUt9M6xQxxyZcJv7 Bw1xfRP2jntdXYlZDRJz+8DZoUArKtMzWuXbnIGsDRfHnTu0+mKKj8meHKmCiqoKvk kaFysGbrahW4w== 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 05/10] libfs: Add simple_offset_rename() API Date: Fri, 24 Jan 2025 14:19:40 -0500 Message-ID: <20250124191946.22308-6-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: B20EC1C0017 X-Stat-Signature: bboseefbk55ciy8ibbap43wcgq7kg1ht X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1737746397-915992 X-HE-Meta: U2FsdGVkX1/sqYerzVP4/lHRyNSJKpgDnnI2bygUZG0bbvZb4dLUoT2J5KLcC1hwi2BHg0UIIdkcl4ukpHZNmG9MkkimkgZP3D8l+Axm1hjtEMUQTp0EgVk/UJ2lwQf3UPt41V6Roqx73qJCrjtSUIiMdKIXxBSvtJUkDe16TmpvYQ86IU05Ti+RWh750QLSfFiOuVD5cFChyhtHi0S4SKETJyHnREnl6sjc5y2AUdInGEG2MRfwVc5Zj9NMFAj/KyNgs7voaA3xpNIbLR7L6Hq2TlilNmRbXI64x78vPoFm0taSabn37+AqBTqRdpuNaFmgbAwGWL7baP3HRzpdOWUm8q4WAD3Ojw8sDBmtfSUUxIrTmxoVt/NxZx3g9ZABTqNtBZnO1PuB5oMOHFiqc0KRitcAVCh9hbwmkika+pnVJcRx9+yCNNUU9Hg4WWdSdS890X5A7KtmpHwuETFxI7+r3RJeTHIuNE6k+hxSbvNq/f0xXoSLdvFsyv1jlbmIAVczkQFCQi/R1svO7d60jUVixmCa1ZshBX+VqtwrfNE8Tx1LYy4nHfB5qGuR/2G1L6sf8HfGgnYDeq8Ne3Nwwc/NvJYMGZDE09Yc7ualIodXwYyrOeb2di4pjU0ZFTPX/FANWxivBATMouJZRAM+ZWdeH01oSVqsyr8hQ3rPe0Fqy7SBFy2IvxnoHbz9gIYDFOP/WP1kbPSWhbfJHWt717MyuT3nbmAVLNRCum93mFpj6XdK+yLZO6U+x2E2y88xlx+wchnzM+N876z9A85MqAE+KudDzy0UN8nMBPkGecxMcRE9FpHfMnixSmn0d0rRMfNkJpHnKlvSFsOwYjf//GGs1c/PevWOVoCOfAd02nBkP2q6fLEtKeoDA/3neEmeISBaOsatC1YR6EzcbvMuUvW7ddsArJQE/GdJW6I5kw46xE45TmPePKKmRFHCCkN6YzQ65fVc+7HwEzsgqUE rMTLPsiJ PJ30VpX/1yexWU0gjGiX1UziB/lv6OMB/Ic+Lv53cZj5Igu/cxn4iLX98qusThUZIEiJ7VqugE9So209pdrlWr9YvLoRqfms9JU0qxUHMqbhVgHP4hLbzs4/AemndV6PG8hiVkLsMdoMSMykw5mm2JFbCCDG6lh/+uwYZrTVAHwNcAHCK9T5fQ3aYcJDgAu4xtUP6PKvNt61KynMfX91ym+3TvC/DejRII/PRWzm/eofpgX3loKPxWXkab+Vo+zO1YtuK0rWToC6cFOGX8Ai2TwzWEZh756qqAjK89LNeRXrxYrArAM5QBy9bzQ== 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 5a1a25be995e1014abd01600479915683e356f5c ] I'm about to fix a tmpfs rename bug that requires the use of internal simple_offset helpers that are not available in mm/shmem.c Signed-off-by: Chuck Lever Link: https://lore.kernel.org/r/20240415152057.4605-3-cel@kernel.org Signed-off-by: Christian Brauner Signed-off-by: Chuck Lever --- fs/libfs.c | 21 +++++++++++++++++++++ include/linux/fs.h | 2 ++ mm/shmem.c | 3 +-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index 2029cb6a0e15..15d8c3300dae 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -356,6 +356,27 @@ int simple_offset_empty(struct dentry *dentry) return ret; } +/** + * simple_offset_rename - handle directory offsets for rename + * @old_dir: parent directory of source entry + * @old_dentry: dentry of source entry + * @new_dir: parent_directory of destination entry + * @new_dentry: dentry of destination + * + * Caller provides appropriate serialization. + * + * Returns zero on success, a negative errno value on failure. + */ +int simple_offset_rename(struct inode *old_dir, struct dentry *old_dentry, + struct inode *new_dir, struct dentry *new_dentry) +{ + struct offset_ctx *old_ctx = old_dir->i_op->get_offset_ctx(old_dir); + struct offset_ctx *new_ctx = new_dir->i_op->get_offset_ctx(new_dir); + + simple_offset_remove(old_ctx, old_dentry); + return simple_offset_add(new_ctx, old_dentry); +} + /** * simple_offset_rename_exchange - exchange rename with directory offsets * @old_dir: parent of dentry being moved diff --git a/include/linux/fs.h b/include/linux/fs.h index 5104405ce3e6..e4d139fcaad0 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3198,6 +3198,8 @@ void simple_offset_init(struct offset_ctx *octx); int simple_offset_add(struct offset_ctx *octx, struct dentry *dentry); void simple_offset_remove(struct offset_ctx *octx, struct dentry *dentry); int simple_offset_empty(struct dentry *dentry); +int simple_offset_rename(struct inode *old_dir, struct dentry *old_dentry, + struct inode *new_dir, struct dentry *new_dentry); int simple_offset_rename_exchange(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, diff --git a/mm/shmem.c b/mm/shmem.c index aaf679976f3b..ab2b0e87b051 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3434,8 +3434,7 @@ static int shmem_rename2(struct mnt_idmap *idmap, return error; } - simple_offset_remove(shmem_get_offset_ctx(old_dir), old_dentry); - error = simple_offset_add(shmem_get_offset_ctx(new_dir), old_dentry); + error = simple_offset_rename(old_dir, old_dentry, new_dir, new_dentry); if (error) return error;