From patchwork Thu Feb 16 20:38:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143773 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A21BEC636CC for ; Thu, 16 Feb 2023 20:38:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229536AbjBPUiR (ORCPT ); Thu, 16 Feb 2023 15:38:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229818AbjBPUiQ (ORCPT ); Thu, 16 Feb 2023 15:38:16 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B3FC1ADE6 for ; Thu, 16 Feb 2023 12:38:11 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DA590B829AB for ; Thu, 16 Feb 2023 20:38:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 979B5C433EF; Thu, 16 Feb 2023 20:38:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579888; bh=O91viBnqgRv85OXv+/myTq/Dq25e/lyYESBFLPLkB5E=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=JZzN7VOkDjPm3yVrFYf6XCJ/mce+gPGk3IwIQ9gdrs0BGMCiFJGaPYZHS7jGt/I24 AVfJ5E69er88Xw/YOH29cbEL0/ZCKcILT4jfjq1HAdhl854LUEjWNAc4fHc6cg585v AwnF/pzuBe1hIslBli2Y44w1j5zSWekfc5JzWh0FlMN4UIk/gMNc7+dpOHA15tQP9y JdasitRvYkxivhRpyqYxP+zhkcHoY4iYDZcR6wi8vJ/FqHa0Snew33rv3QG3DuM/Ps WxDktySqlEwLVn5BPLQ1pY+uPKZMOfxK+6dxceCh5vhaCCgf8NZUKrc7+MZ7cqcakw l6kZDIldwoEtQ== Date: Thu, 16 Feb 2023 12:38:08 -0800 Subject: [PATCH 21/28] xfs: Add parent pointers to xfs_cross_rename From: "Darrick J. Wong" To: djwong@kernel.org Cc: Allison Henderson , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872685.3473407.9005998270517975325.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson Cross renames are handled separately from standard renames, and need different handling to update the parent attributes correctly. Signed-off-by: Allison Henderson --- fs/xfs/xfs_inode.c | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index cdbd7df64ff0..6626aa7486f1 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -2749,27 +2749,31 @@ xfs_finish_rename( */ STATIC int xfs_cross_rename( - struct xfs_trans *tp, - struct xfs_inode *dp1, - struct xfs_name *name1, - struct xfs_inode *ip1, - struct xfs_inode *dp2, - struct xfs_name *name2, - struct xfs_inode *ip2, - int spaceres) + struct xfs_trans *tp, + struct xfs_inode *dp1, + struct xfs_name *name1, + struct xfs_inode *ip1, + struct xfs_parent_defer *ip1_pptr, + struct xfs_inode *dp2, + struct xfs_name *name2, + struct xfs_inode *ip2, + struct xfs_parent_defer *ip2_pptr, + int spaceres) { - int error = 0; - int ip1_flags = 0; - int ip2_flags = 0; - int dp2_flags = 0; + struct xfs_mount *mp = dp1->i_mount; + int error = 0; + int ip1_flags = 0; + int ip2_flags = 0; + int dp2_flags = 0; + int new_diroffset, old_diroffset; /* Swap inode number for dirent in first parent */ - error = xfs_dir_replace(tp, dp1, name1, ip2->i_ino, spaceres, NULL); + error = xfs_dir_replace(tp, dp1, name1, ip2->i_ino, spaceres, &old_diroffset); if (error) goto out_trans_abort; /* Swap inode number for dirent in second parent */ - error = xfs_dir_replace(tp, dp2, name2, ip1->i_ino, spaceres, NULL); + error = xfs_dir_replace(tp, dp2, name2, ip1->i_ino, spaceres, &new_diroffset); if (error) goto out_trans_abort; @@ -2830,6 +2834,18 @@ xfs_cross_rename( } } + if (xfs_has_parent(mp)) { + error = xfs_parent_defer_replace(tp, ip1_pptr, dp1, + old_diroffset, name2, dp2, new_diroffset, ip1); + if (error) + goto out_trans_abort; + + error = xfs_parent_defer_replace(tp, ip2_pptr, dp2, + new_diroffset, name1, dp1, old_diroffset, ip2); + if (error) + goto out_trans_abort; + } + if (ip1_flags) { xfs_trans_ichgtime(tp, ip1, ip1_flags); xfs_trans_log_inode(tp, ip1, XFS_ILOG_CORE); @@ -2844,6 +2860,7 @@ xfs_cross_rename( } xfs_trans_ichgtime(tp, dp1, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); xfs_trans_log_inode(tp, dp1, XFS_ILOG_CORE); + return xfs_finish_rename(tp); out_trans_abort: @@ -3060,8 +3077,8 @@ xfs_rename( /* RENAME_EXCHANGE is unique from here on. */ if (flags & RENAME_EXCHANGE) { error = xfs_cross_rename(tp, src_dp, src_name, src_ip, - target_dp, target_name, target_ip, - spaceres); + src_ip_pptr, target_dp, target_name, target_ip, + tgt_ip_pptr, spaceres); goto out_unlock; }