From patchwork Sun Dec 31 20:22:25 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: 13507389 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8034ABA30 for ; Sun, 31 Dec 2023 20:22:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qye/AfOE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBFFEC433C8; Sun, 31 Dec 2023 20:22:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704054145; bh=tj7/I0mk2Nm9v4PcSxgDdzlDPr3p2V5qigdBWpXQZQU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=qye/AfOECO+JPJ1r7jGtbhgRmHT8MOE7kfM+sCN+aneCoFmNP6HihSr9ymqhJqW/l q8gEE328bLBtmTTKm/gr46GS8xBterZmj8QiamuUalXJN3AezxHbOm4Oh3EwqzRWkE nSDlc3LS66hpROUSWJW5EASiuD1hSz4ElczTzWaJ2aPNUSmxtziVZeNy1vNZYtndJ7 rSb8UCpQ/TO7trYjnjxfOJZq/ZURBPIrMMu47C9cFwwH6gLVnx7ANmLOs2DXcBmuaw JUa/YqiqhCPFiMI0MlwxH0iiNkPdHS7lioH5ZBdVpleYP3eCsJUl4+ytcZEM+ZfaWD bWZlYV5kvXCiA== Date: Sun, 31 Dec 2023 12:22:25 -0800 Subject: [PATCH 1/3] xfs: fix xfs_bunmapi to allow unmapping of partial rt extents From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <170404831892.1749931.10507668815062235816.stgit@frogsfrogsfrogs> In-Reply-To: <170404831869.1749931.14460733843503552627.stgit@frogsfrogsfrogs> References: <170404831869.1749931.14460733843503552627.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong When XFS_BMAPI_REMAP is passed to bunmapi, that means that we want to remove part of a block mapping without touching the allocator. For realtime files with rtextsize > 1, that also means that we should skip all the code that changes a partial remove request into an unwritten extent conversion. IOWs, bunmapi in this mode should handle removing the mapping from the rt file and nothing else. Note that XFS_BMAPI_REMAP callers are required to decrement the reference count and/or free the space manually. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_bmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 3df6856cf4872..bf20267cf6378 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -5431,7 +5431,7 @@ __xfs_bunmapi( if (del.br_startoff + del.br_blockcount > end + 1) del.br_blockcount = end + 1 - del.br_startoff; - if (!isrt) + if (!isrt || (flags & XFS_BMAPI_REMAP)) goto delete; mod = xfs_rtb_to_rtxoff(mp, @@ -5449,7 +5449,7 @@ __xfs_bunmapi( * This piece is unwritten, or we're not * using unwritten extents. Skip over it. */ - ASSERT(end >= mod); + ASSERT((flags & XFS_BMAPI_REMAP) || end >= mod); end -= mod > del.br_blockcount ? del.br_blockcount : mod; if (end < got.br_startoff && From patchwork Sun Dec 31 20:22:41 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: 13507390 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A411EBA2B for ; Sun, 31 Dec 2023 20:22:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="piZ2KTa8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71447C433C8; Sun, 31 Dec 2023 20:22:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704054161; bh=S5sTLP1z4LXkTjUU3rHwT5A8Gre0PwCtJH3JVb9XzMg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=piZ2KTa8+dAm6R7ouGA+t5/0TasUllgUlwozvRB7/rUbV6/VJenbQTSJ8yYIwfgcT uZgfp40UCtbzjs3B3eQVkAMZq7dbkxou/8VK0wMafPtpguAWm02XqtAO+s3VE53d9q 3dOGmvhXkntxfLzohS3Aedw7GDMEeejZGxT4EaR53B07Ar/+L1VDpJYf2zAmHv/fHm zsG+TnLsJvwl1dSQTlSTLx2dx3hs2M8xdmiHvUXQpOjMZwCvJHdWZcePBcpMI0PSWT LkWlXmRDbcLmZ+rT7ZpJ4uA3o41z3k5D/JGK/I8nCUasjywfp7V10yFtFUhAdpb0cb Wmb0eVciG8MTg== Date: Sun, 31 Dec 2023 12:22:41 -0800 Subject: [PATCH 2/3] xfs: add a realtime flag to the bmap update log redo items From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <170404831907.1749931.14510682723075122416.stgit@frogsfrogsfrogs> In-Reply-To: <170404831869.1749931.14460733843503552627.stgit@frogsfrogsfrogs> References: <170404831869.1749931.14460733843503552627.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Extend the bmap update (BUI) log items with a new realtime flag that indicates that the updates apply against a realtime file's data fork. We'll wire up the actual code later. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_log_format.h | 4 +++- fs/xfs/xfs_bmap_item.c | 8 ++++++++ fs/xfs/xfs_trace.h | 23 ++++++++++++++++++----- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/fs/xfs/libxfs/xfs_log_format.h b/fs/xfs/libxfs/xfs_log_format.h index 269573c828085..16872972e1e97 100644 --- a/fs/xfs/libxfs/xfs_log_format.h +++ b/fs/xfs/libxfs/xfs_log_format.h @@ -838,10 +838,12 @@ struct xfs_cud_log_format { #define XFS_BMAP_EXTENT_ATTR_FORK (1U << 31) #define XFS_BMAP_EXTENT_UNWRITTEN (1U << 30) +#define XFS_BMAP_EXTENT_REALTIME (1U << 29) #define XFS_BMAP_EXTENT_FLAGS (XFS_BMAP_EXTENT_TYPE_MASK | \ XFS_BMAP_EXTENT_ATTR_FORK | \ - XFS_BMAP_EXTENT_UNWRITTEN) + XFS_BMAP_EXTENT_UNWRITTEN | \ + XFS_BMAP_EXTENT_REALTIME) /* * This is the structure used to lay out an bui log item in the diff --git a/fs/xfs/xfs_bmap_item.c b/fs/xfs/xfs_bmap_item.c index 3315a38f35973..d19f82c367f2b 100644 --- a/fs/xfs/xfs_bmap_item.c +++ b/fs/xfs/xfs_bmap_item.c @@ -275,6 +275,8 @@ xfs_bmap_update_log_item( map->me_flags |= XFS_BMAP_EXTENT_UNWRITTEN; if (bi->bi_whichfork == XFS_ATTR_FORK) map->me_flags |= XFS_BMAP_EXTENT_ATTR_FORK; + if (xfs_ifork_is_realtime(bi->bi_owner, bi->bi_whichfork)) + map->me_flags |= XFS_BMAP_EXTENT_REALTIME; } static struct xfs_log_item * @@ -324,6 +326,9 @@ xfs_bmap_update_get_group( { xfs_agnumber_t agno; + if (xfs_ifork_is_realtime(bi->bi_owner, bi->bi_whichfork)) + return; + agno = XFS_FSB_TO_AGNO(mp, bi->bi_bmap.br_startblock); /* @@ -353,6 +358,9 @@ static inline void xfs_bmap_update_put_group( struct xfs_bmap_intent *bi) { + if (xfs_ifork_is_realtime(bi->bi_owner, bi->bi_whichfork)) + return; + xfs_perag_intent_put(bi->bi_pag); } diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h index 52e54ec267cb8..a36b48432d093 100644 --- a/fs/xfs/xfs_trace.h +++ b/fs/xfs/xfs_trace.h @@ -2958,9 +2958,11 @@ DECLARE_EVENT_CLASS(xfs_bmap_deferred_class, TP_ARGS(bi), TP_STRUCT__entry( __field(dev_t, dev) + __field(dev_t, opdev) __field(xfs_agnumber_t, agno) __field(xfs_ino_t, ino) __field(xfs_agblock_t, agbno) + __field(xfs_fsblock_t, rtbno) __field(int, whichfork) __field(xfs_fileoff_t, l_loff) __field(xfs_filblks_t, l_len) @@ -2971,23 +2973,34 @@ DECLARE_EVENT_CLASS(xfs_bmap_deferred_class, struct xfs_inode *ip = bi->bi_owner; __entry->dev = ip->i_mount->m_super->s_dev; - __entry->agno = XFS_FSB_TO_AGNO(ip->i_mount, - bi->bi_bmap.br_startblock); + if (xfs_ifork_is_realtime(ip, bi->bi_whichfork)) { + __entry->agno = 0; + __entry->agbno = 0; + __entry->rtbno = bi->bi_bmap.br_startblock; + __entry->opdev = ip->i_mount->m_rtdev_targp->bt_dev; + } else { + __entry->agno = XFS_FSB_TO_AGNO(ip->i_mount, + bi->bi_bmap.br_startblock); + __entry->agbno = XFS_FSB_TO_AGBNO(ip->i_mount, + bi->bi_bmap.br_startblock); + __entry->rtbno = 0; + __entry->opdev = __entry->dev; + } __entry->ino = ip->i_ino; - __entry->agbno = XFS_FSB_TO_AGBNO(ip->i_mount, - bi->bi_bmap.br_startblock); __entry->whichfork = bi->bi_whichfork; __entry->l_loff = bi->bi_bmap.br_startoff; __entry->l_len = bi->bi_bmap.br_blockcount; __entry->l_state = bi->bi_bmap.br_state; __entry->op = bi->bi_type; ), - TP_printk("dev %d:%d op %s ino 0x%llx agno 0x%x agbno 0x%x %s fileoff 0x%llx fsbcount 0x%llx state %d", + TP_printk("dev %d:%d op %s opdev %d:%d ino 0x%llx agno 0x%x agbno 0x%x rtbno 0x%llx %s fileoff 0x%llx fsbcount 0x%llx state %d", MAJOR(__entry->dev), MINOR(__entry->dev), __print_symbolic(__entry->op, XFS_BMAP_INTENT_STRINGS), + MAJOR(__entry->opdev), MINOR(__entry->opdev), __entry->ino, __entry->agno, __entry->agbno, + __entry->rtbno, __print_symbolic(__entry->whichfork, XFS_WHICHFORK_STRINGS), __entry->l_loff, __entry->l_len, From patchwork Sun Dec 31 20:22:56 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: 13507391 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B355BA22 for ; Sun, 31 Dec 2023 20:22:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jreWLFSF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 219F4C433C7; Sun, 31 Dec 2023 20:22:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704054177; bh=knDl6xdBeETqOX0DdudIxei9by2QxOZnxFF4aPRwDA0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=jreWLFSFhfFSVngvuekCZGteftVO2lcykIO+cWJGU8gYKHukoVL7wh9A4rJ2Ic/iW eM0Plg//Cb982jFBgX1awM+fwwDaoSzWj06Pxjg6WxOJZrFRN+PgvwfNvTLdMae14d bexgi5hTiupq+gdMrlup+A5jGX1PKHjzIxDjMcpiztn5R9ZKNBcTJfC5JxCDalP7ja pLvIPjdmwCn96143GZ8svgYWsLwSGqHQUQZqXJtJ6AmpUnYn6soXxLk965k/dOA0OU h/Qe+TgyExzKAHBWcp+E3fckgqfhROjOA7ohhH1xT6X2IIKI6iksygU/7xEa7AlUcm 9w027d41QF8Ew== Date: Sun, 31 Dec 2023 12:22:56 -0800 Subject: [PATCH 3/3] xfs: support recovering bmap intent items targetting realtime extents From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <170404831924.1749931.14835443792114657795.stgit@frogsfrogsfrogs> In-Reply-To: <170404831869.1749931.14460733843503552627.stgit@frogsfrogsfrogs> References: <170404831869.1749931.14460733843503552627.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Now that we have reflink on the realtime device, bmap intent items have to support remapping extents on the realtime volume. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_bmap_item.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/xfs/xfs_bmap_item.c b/fs/xfs/xfs_bmap_item.c index d19f82c367f2b..02b872a133104 100644 --- a/fs/xfs/xfs_bmap_item.c +++ b/fs/xfs/xfs_bmap_item.c @@ -435,6 +435,9 @@ xfs_bui_validate( if (!xfs_verify_fileext(mp, map->me_startoff, map->me_len)) return false; + if (map->me_flags & XFS_BMAP_EXTENT_REALTIME) + return xfs_verify_rtbext(mp, map->me_startblock, map->me_len); + return xfs_verify_fsbext(mp, map->me_startblock, map->me_len); } @@ -509,6 +512,12 @@ xfs_bmap_recover_work( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, 0); + if (!!(map->me_flags & XFS_BMAP_EXTENT_REALTIME) != + xfs_ifork_is_realtime(ip, work->bi_whichfork)) { + error = -EFSCORRUPTED; + goto err_cancel; + } + if (work->bi_type == XFS_BMAP_MAP) iext_delta = XFS_IEXT_ADD_NOSPLIT_CNT; else