From patchwork Fri Dec 30 22:19:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085674 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 03622C4332F for ; Sat, 31 Dec 2022 02:30:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236229AbiLaCaX (ORCPT ); Fri, 30 Dec 2022 21:30:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236141AbiLaCaW (ORCPT ); Fri, 30 Dec 2022 21:30:22 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF5CA1CB17 for ; Fri, 30 Dec 2022 18:30:20 -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 7968EB81E75 for ; Sat, 31 Dec 2022 02:30:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D551C433EF; Sat, 31 Dec 2022 02:30:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453818; bh=YzhS9LNEQGAZivh6crT/ppNewYPKmkgUGgQ4FXEPkWA=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=hgRRziAELhsNNjiT0mDVUeYwaTyO7oGMr4d8HzxD7nd5pXJfPFHBINUgcc8GDAKuU nFTN8UyIbFaMy1SzwJII19cpLVQxafS4ie3+dxxaml/nR+xfc3u1W+cqI9YsfkkVpm 0omvu/C4y8zHDbn27ArcqDp0sCwEaLcrgRReiK2nXeJ6w7XbShGhelGKl6LR6nlM7j hQBWpg2jJs8SfvANsuslHsedqCy5g7x4LXKWcZzedKeT9ZtOzDtgUWLAY7NurB1HP9 Y6gR45hSlC03jPUBH7/+IqA1s46j+mscaU3al23b5CIBAsNv0LnPEwyRTD4vUd5uYV otWiarstrJ66g== Subject: [PATCH 01/45] xfs: create incore realtime group structures From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:43 -0800 Message-ID: <167243878380.731133.6912594788285833701.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Create an incore object that will contain information about a realtime allocation group. This will eventually enable us to shard the realtime section in a similar manner to how we shard the data section. Signed-off-by: Darrick J. Wong --- include/xfs_mount.h | 8 ++ include/xfs_trace.h | 5 + libxfs/Makefile | 2 libxfs/init.c | 21 +++++ libxfs/libxfs_api_defs.h | 2 libxfs/xfs_format.h | 8 ++ libxfs/xfs_rtgroup.c | 212 ++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_rtgroup.h | 121 ++++++++++++++++++++++++++ libxfs/xfs_sb.c | 5 + libxfs/xfs_types.h | 4 + 10 files changed, 388 insertions(+) create mode 100644 libxfs/xfs_rtgroup.c create mode 100644 libxfs/xfs_rtgroup.h diff --git a/include/xfs_mount.h b/include/xfs_mount.h index 6de360d33d3..5987650c639 100644 --- a/include/xfs_mount.h +++ b/include/xfs_mount.h @@ -68,6 +68,7 @@ typedef struct xfs_mount { uint8_t m_sectbb_log; /* sectorlog - BBSHIFT */ uint8_t m_agno_log; /* log #ag's */ int8_t m_rtxblklog; /* log2 of rextsize, if possible */ + int8_t m_rgblklog; /* log2 of rt group sz if possible */ uint m_blockmask; /* sb_blocksize-1 */ uint m_blockwsize; /* sb_blocksize in words */ uint m_blockwmask; /* blockwsize-1 */ @@ -88,8 +89,10 @@ typedef struct xfs_mount { uint m_alloc_set_aside; /* space we can't use */ uint m_ag_max_usable; /* max space per AG */ struct radix_tree_root m_perag_tree; + struct radix_tree_root m_rtgroup_tree; uint64_t m_features; /* active filesystem features */ uint64_t m_rtxblkmask; /* rt extent block mask */ + uint64_t m_rgblkmask; /* rt group block mask */ unsigned long m_opstate; /* dynamic state flags */ bool m_finobt_nores; /* no per-AG finobt resv. */ uint m_qflags; /* quota status flags */ @@ -126,6 +129,7 @@ typedef struct xfs_mount { */ atomic64_t m_allocbt_blks; spinlock_t m_perag_lock; /* lock for m_perag_tree */ + spinlock_t m_rtgroup_lock; /* lock for m_rtgroup_tree */ } xfs_mount_t; @@ -165,6 +169,7 @@ typedef struct xfs_mount { #define XFS_FEAT_NEEDSREPAIR (1ULL << 25) /* needs xfs_repair */ #define XFS_FEAT_NREXT64 (1ULL << 26) /* large extent counters */ #define XFS_FEAT_METADIR (1ULL << 27) /* metadata directory tree */ +#define XFS_FEAT_RTGROUPS (1ULL << 28) /* realtime groups */ #define __XFS_HAS_FEAT(name, NAME) \ static inline bool xfs_has_ ## name (struct xfs_mount *mp) \ @@ -210,6 +215,7 @@ __XFS_HAS_FEAT(bigtime, BIGTIME) __XFS_HAS_FEAT(needsrepair, NEEDSREPAIR) __XFS_HAS_FEAT(large_extent_counts, NREXT64) __XFS_HAS_FEAT(metadir, METADIR) +__XFS_HAS_FEAT(rtgroups, RTGROUPS) /* Kernel mount features that we don't support */ #define __XFS_UNSUPP_FEAT(name) \ @@ -230,6 +236,7 @@ __XFS_UNSUPP_FEAT(grpid) #define XFS_OPSTATE_DEBUGGER 1 /* is this the debugger? */ #define XFS_OPSTATE_REPORT_CORRUPTION 2 /* report buffer corruption? */ #define XFS_OPSTATE_PERAG_DATA_LOADED 3 /* per-AG data initialized? */ +#define XFS_OPSTATE_RTGROUP_DATA_LOADED 4 /* rtgroup data initialized? */ #define __XFS_IS_OPSTATE(name, NAME) \ static inline bool xfs_is_ ## name (struct xfs_mount *mp) \ @@ -255,6 +262,7 @@ __XFS_IS_OPSTATE(inode32, INODE32) __XFS_IS_OPSTATE(debugger, DEBUGGER) __XFS_IS_OPSTATE(reporting_corruption, REPORT_CORRUPTION) __XFS_IS_OPSTATE(perag_data_loaded, PERAG_DATA_LOADED) +__XFS_IS_OPSTATE(rtgroup_data_loaded, RTGROUP_DATA_LOADED) #define __XFS_UNSUPP_OPSTATE(name) \ static inline bool xfs_is_ ## name (struct xfs_mount *mp) \ diff --git a/include/xfs_trace.h b/include/xfs_trace.h index fef869dbea3..4c73f86d8f0 100644 --- a/include/xfs_trace.h +++ b/include/xfs_trace.h @@ -332,6 +332,11 @@ #define trace_xfs_rmap_map_error(...) ((void) 0) #define trace_xfs_rmap_delete_error(...) ((void) 0) +/* set c = c to avoid unused var warnings */ +#define trace_xfs_rtgroup_bump(...) ((void) 0) +#define trace_xfs_rtgroup_get(a,b,c,d) ((c) = (c)) +#define trace_xfs_rtgroup_put(a,b,c,d) ((c) = (c)) + #define trace_xfs_swapext_defer(...) ((void) 0) #define trace_xfs_swapext_delta_nextents(...) ((void) 0) #define trace_xfs_swapext_delta_nextents_step(...) ((void) 0) diff --git a/libxfs/Makefile b/libxfs/Makefile index 5d6e1c7bcc2..1bd8a2ab01d 100644 --- a/libxfs/Makefile +++ b/libxfs/Makefile @@ -57,6 +57,7 @@ HFILES = \ xfs_rmap.h \ xfs_rmap_btree.h \ xfs_rtbitmap.h \ + xfs_rtgroup.h \ xfs_sb.h \ xfs_shared.h \ xfs_swapext.h \ @@ -111,6 +112,7 @@ CFILES = cache.c \ xfs_rmap.c \ xfs_rmap_btree.c \ xfs_rtbitmap.c \ + xfs_rtgroup.c \ xfs_sb.c \ xfs_swapext.c \ xfs_symlink_remote.c \ diff --git a/libxfs/init.c b/libxfs/init.c index a440943cbdb..c7f10823870 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -25,6 +25,7 @@ #include "xfile.h" #include "libxfs.h" /* for now */ +#include "xfs_rtgroup.h" #ifndef HAVE_LIBURCU_ATOMIC64 pthread_mutex_t atomic64_lock = PTHREAD_MUTEX_INITIALIZER; @@ -839,7 +840,9 @@ libxfs_mount( { struct xfs_buf *bp; struct xfs_sb *sbp; + struct xfs_rtgroup *rtg; xfs_daddr_t d; + xfs_rgnumber_t rgno; unsigned int btflags = 0; int error; @@ -857,9 +860,11 @@ libxfs_mount( xfs_set_inode32(mp); mp->m_sb = *sb; INIT_RADIX_TREE(&mp->m_perag_tree, GFP_KERNEL); + INIT_RADIX_TREE(&mp->m_rtgroup_tree, GFP_KERNEL); sbp = &mp->m_sb; spin_lock_init(&mp->m_sb_lock); spin_lock_init(&mp->m_agirotor_lock); + spin_lock_init(&mp->m_rtgroup_lock); xfs_sb_mount_common(mp, sb); @@ -987,6 +992,20 @@ libxfs_mount( libxfs_mountfs_imeta(mp); + error = libxfs_initialize_rtgroups(mp, sbp->sb_rgcount); + if (error) { + fprintf(stderr, _("%s: rtgroup init failed\n"), + progname); + exit(1); + } + + for_each_rtgroup(mp, rgno, rtg) { + rtg->rtg_blockcount = xfs_rtgroup_block_count(mp, + rtg->rtg_rgno); + } + + xfs_set_rtgroup_data_loaded(mp); + return mp; out_da: xfs_da_unmount(mp); @@ -1120,6 +1139,8 @@ libxfs_umount( * Only try to free the per-AG structures if we set them up in the * first place. */ + if (xfs_is_rtgroup_data_loaded(mp)) + xfs_free_rtgroups(mp); if (xfs_is_perag_data_loaded(mp)) libxfs_free_perag(mp); diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index ca9144dd949..7ce9686c00d 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -138,6 +138,7 @@ #define xfs_fixed_inode_reset libxfs_fixed_inode_reset #define xfs_free_extent libxfs_free_extent #define xfs_free_perag libxfs_free_perag +#define xfs_free_rtgroups libxfs_free_rtgroups #define xfs_fs_geometry libxfs_fs_geometry #define xfs_get_projid libxfs_get_projid #define xfs_get_initial_prid libxfs_get_initial_prid @@ -174,6 +175,7 @@ #define xfs_initialize_perag libxfs_initialize_perag #define xfs_initialize_perag_data libxfs_initialize_perag_data +#define xfs_initialize_rtgroups libxfs_initialize_rtgroups #define xfs_init_local_fork libxfs_init_local_fork #define xfs_inobt_maxrecs libxfs_inobt_maxrecs diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index 946870eb492..ca87a3f8704 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -184,6 +184,14 @@ typedef struct xfs_sb { */ xfs_ino_t sb_metadirino; + /* + * Realtime group geometry information. On disk these fields live in + * the rsumino slot, but we cache them separately in the in-core super + * for easy access. + */ + xfs_rgblock_t sb_rgblocks; /* size of a realtime group */ + xfs_rgnumber_t sb_rgcount; /* number of realtime groups */ + /* must be padded to 64 bit alignment */ } xfs_sb_t; diff --git a/libxfs/xfs_rtgroup.c b/libxfs/xfs_rtgroup.c new file mode 100644 index 00000000000..7d26ef76d3e --- /dev/null +++ b/libxfs/xfs_rtgroup.c @@ -0,0 +1,212 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2022 Oracle. All Rights Reserved. + * Author: Darrick J. Wong + */ +#include "libxfs_priv.h" +#include "xfs_fs.h" +#include "xfs_shared.h" +#include "xfs_format.h" +#include "xfs_trans_resv.h" +#include "xfs_bit.h" +#include "xfs_sb.h" +#include "xfs_mount.h" +#include "xfs_btree.h" +#include "xfs_alloc_btree.h" +#include "xfs_rmap_btree.h" +#include "xfs_alloc.h" +#include "xfs_ialloc.h" +#include "xfs_rmap.h" +#include "xfs_ag.h" +#include "xfs_ag_resv.h" +#include "xfs_health.h" +#include "xfs_bmap.h" +#include "xfs_defer.h" +#include "xfs_log_format.h" +#include "xfs_trans.h" +#include "xfs_trace.h" +#include "xfs_inode.h" +#include "xfs_rtgroup.h" +#include "xfs_rtbitmap.h" + +/* + * Passive reference counting access wrappers to the rtgroup structures. If + * the rtgroup structure is to be freed, the freeing code is responsible for + * cleaning up objects with passive references before freeing the structure. + */ +struct xfs_rtgroup * +xfs_rtgroup_get( + struct xfs_mount *mp, + xfs_rgnumber_t rgno) +{ + struct xfs_rtgroup *rtg; + int ref = 0; + + rcu_read_lock(); + rtg = radix_tree_lookup(&mp->m_rtgroup_tree, rgno); + if (rtg) { + ASSERT(atomic_read(&rtg->rtg_ref) >= 0); + ref = atomic_inc_return(&rtg->rtg_ref); + } + rcu_read_unlock(); + trace_xfs_rtgroup_get(mp, rgno, ref, _RET_IP_); + return rtg; +} + +struct xfs_rtgroup * +xfs_rtgroup_bump( + struct xfs_rtgroup *rtg) +{ + if (!atomic_inc_not_zero(&rtg->rtg_ref)) { + ASSERT(0); + return NULL; + } + + trace_xfs_rtgroup_bump(rtg->rtg_mount, rtg->rtg_rgno, + atomic_read(&rtg->rtg_ref), _RET_IP_); + return rtg; +} + +void +xfs_rtgroup_put( + struct xfs_rtgroup *rtg) +{ + int ref; + + ASSERT(atomic_read(&rtg->rtg_ref) > 0); + ref = atomic_dec_return(&rtg->rtg_ref); + trace_xfs_rtgroup_put(rtg->rtg_mount, rtg->rtg_rgno, ref, _RET_IP_); +} + +int +xfs_initialize_rtgroups( + struct xfs_mount *mp, + xfs_rgnumber_t rgcount) +{ + struct xfs_rtgroup *rtg; + xfs_rgnumber_t index; + xfs_rgnumber_t first_initialised = NULLRGNUMBER; + int error; + + if (!xfs_has_rtgroups(mp)) + return 0; + + /* + * Walk the current rtgroup tree so we don't try to initialise rt + * groups that already exist (growfs case). Allocate and insert all the + * rtgroups we don't find ready for initialisation. + */ + for (index = 0; index < rgcount; index++) { + rtg = xfs_rtgroup_get(mp, index); + if (rtg) { + xfs_rtgroup_put(rtg); + continue; + } + + rtg = kmem_zalloc(sizeof(struct xfs_rtgroup), KM_MAYFAIL); + if (!rtg) { + error = -ENOMEM; + goto out_unwind_new_rtgs; + } + rtg->rtg_rgno = index; + rtg->rtg_mount = mp; + + error = radix_tree_preload(GFP_NOFS); + if (error) + goto out_free_rtg; + + spin_lock(&mp->m_rtgroup_lock); + if (radix_tree_insert(&mp->m_rtgroup_tree, index, rtg)) { + WARN_ON_ONCE(1); + spin_unlock(&mp->m_rtgroup_lock); + radix_tree_preload_end(); + error = -EEXIST; + goto out_free_rtg; + } + spin_unlock(&mp->m_rtgroup_lock); + radix_tree_preload_end(); + +#ifdef __KERNEL__ + /* Place kernel structure only init below this point. */ + spin_lock_init(&rtg->rtg_state_lock); +#endif /* __KERNEL__ */ + + /* first new rtg is fully initialized */ + if (first_initialised == NULLRGNUMBER) + first_initialised = index; + } + + return 0; + +out_free_rtg: + kmem_free(rtg); +out_unwind_new_rtgs: + /* unwind any prior newly initialized rtgs */ + for (index = first_initialised; index < rgcount; index++) { + rtg = radix_tree_delete(&mp->m_rtgroup_tree, index); + if (!rtg) + break; + kmem_free(rtg); + } + return error; +} + +STATIC void +__xfs_free_rtgroups( + struct rcu_head *head) +{ + struct xfs_rtgroup *rtg; + + rtg = container_of(head, struct xfs_rtgroup, rcu_head); + kmem_free(rtg); +} + +/* + * Free up the rtgroup resources associated with the mount structure. + */ +void +xfs_free_rtgroups( + struct xfs_mount *mp) +{ + struct xfs_rtgroup *rtg; + xfs_rgnumber_t rgno; + + if (!xfs_has_rtgroups(mp)) + return; + + for (rgno = 0; rgno < mp->m_sb.sb_rgcount; rgno++) { + spin_lock(&mp->m_rtgroup_lock); + rtg = radix_tree_delete(&mp->m_rtgroup_tree, rgno); + spin_unlock(&mp->m_rtgroup_lock); + ASSERT(rtg); + XFS_IS_CORRUPT(rtg->rtg_mount, atomic_read(&rtg->rtg_ref) != 0); + + call_rcu(&rtg->rcu_head, __xfs_free_rtgroups); + } +} + +/* Find the size of the rtgroup, in blocks. */ +static xfs_rgblock_t +__xfs_rtgroup_block_count( + struct xfs_mount *mp, + xfs_rgnumber_t rgno, + xfs_rgnumber_t rgcount, + xfs_rfsblock_t rblocks) +{ + ASSERT(rgno < rgcount); + + if (rgno < rgcount - 1) + return mp->m_sb.sb_rgblocks; + return xfs_rtb_rounddown_rtx(mp, + rblocks - (rgno * mp->m_sb.sb_rgblocks)); +} + +/* Compute the number of blocks in this realtime group. */ +xfs_rgblock_t +xfs_rtgroup_block_count( + struct xfs_mount *mp, + xfs_rgnumber_t rgno) +{ + return __xfs_rtgroup_block_count(mp, rgno, mp->m_sb.sb_rgcount, + mp->m_sb.sb_rblocks); +} diff --git a/libxfs/xfs_rtgroup.h b/libxfs/xfs_rtgroup.h new file mode 100644 index 00000000000..f414218a66f --- /dev/null +++ b/libxfs/xfs_rtgroup.h @@ -0,0 +1,121 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2022 Oracle. All Rights Reserved. + * Author: Darrick J. Wong + */ +#ifndef __LIBXFS_RTGROUP_H +#define __LIBXFS_RTGROUP_H 1 + +struct xfs_mount; +struct xfs_trans; + +/* + * Realtime group incore structure, similar to the per-AG structure. + */ +struct xfs_rtgroup { + struct xfs_mount *rtg_mount; + xfs_rgnumber_t rtg_rgno; + atomic_t rtg_ref; + + /* for rcu-safe freeing */ + struct rcu_head rcu_head; + + /* Number of blocks in this group */ + xfs_rgblock_t rtg_blockcount; + +#ifdef __KERNEL__ + /* -- kernel only structures below this line -- */ + spinlock_t rtg_state_lock; +#endif /* __KERNEL__ */ +}; + +#ifdef CONFIG_XFS_RT +struct xfs_rtgroup *xfs_rtgroup_get(struct xfs_mount *mp, xfs_rgnumber_t rgno); +struct xfs_rtgroup *xfs_rtgroup_bump(struct xfs_rtgroup *rtg); +void xfs_rtgroup_put(struct xfs_rtgroup *rtg); +int xfs_initialize_rtgroups(struct xfs_mount *mp, xfs_rgnumber_t rgcount); +void xfs_free_rtgroups(struct xfs_mount *mp); +#else +static inline struct xfs_rtgroup * +xfs_rtgroup_get( + struct xfs_mount *mp, + xfs_rgnumber_t rgno) +{ + return NULL; +} +static inline struct xfs_rtgroup *xfs_rtgroup_bump(struct xfs_rtgroup *rtg) +{ + ASSERT(rtg == NULL); + return NULL; +} +# define xfs_rtgroup_put(rtg) ((void)0) +# define xfs_initialize_rtgroups(mp, rgcount) (0) +# define xfs_free_rtgroups(mp) ((void)0) +#endif /* CONFIG_XFS_RT */ + +/* + * rt group iteration APIs + */ +static inline struct xfs_rtgroup * +xfs_rtgroup_next( + struct xfs_rtgroup *rtg, + xfs_rgnumber_t *rgno, + xfs_rgnumber_t end_rgno) +{ + struct xfs_mount *mp = rtg->rtg_mount; + + *rgno = rtg->rtg_rgno + 1; + xfs_rtgroup_put(rtg); + if (*rgno > end_rgno) + return NULL; + return xfs_rtgroup_get(mp, *rgno); +} + +#define for_each_rtgroup_range(mp, rgno, end_rgno, rtg) \ + for ((rtg) = xfs_rtgroup_get((mp), (rgno)); \ + (rtg) != NULL; \ + (rtg) = xfs_rtgroup_next((rtg), &(rgno), (end_rgno))) + +#define for_each_rtgroup_from(mp, rgno, rtg) \ + for_each_rtgroup_range((mp), (rgno), (mp)->m_sb.sb_rgcount - 1, (rtg)) + + +#define for_each_rtgroup(mp, rgno, rtg) \ + (rgno) = 0; \ + for_each_rtgroup_from((mp), (rgno), (rtg)) + +static inline bool +xfs_verify_rgbno( + struct xfs_rtgroup *rtg, + xfs_rgblock_t rgbno) +{ + if (rgbno >= rtg->rtg_blockcount) + return false; + if (rgbno < rtg->rtg_mount->m_sb.sb_rextsize) + return false; + return true; +} + +static inline bool +xfs_verify_rgbext( + struct xfs_rtgroup *rtg, + xfs_rgblock_t rgbno, + xfs_rgblock_t len) +{ + if (rgbno + len <= rgbno) + return false; + + if (!xfs_verify_rgbno(rtg, rgbno)) + return false; + + return xfs_verify_rgbno(rtg, rgbno + len - 1); +} + +#ifdef CONFIG_XFS_RT +xfs_rgblock_t xfs_rtgroup_block_count(struct xfs_mount *mp, + xfs_rgnumber_t rgno); +#else +# define xfs_rtgroup_block_count(mp, rgno) (0) +#endif /* CONFIG_XFS_RT */ + +#endif /* __LIBXFS_RTGROUP_H */ diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index 8605c91e212..ac2e9f91989 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -639,6 +639,9 @@ __xfs_sb_from_disk( to->sb_gquotino = NULLFSINO; to->sb_pquotino = NULLFSINO; } + + to->sb_rgcount = 0; + to->sb_rgblocks = 0; } void @@ -952,6 +955,8 @@ xfs_sb_mount_common( mp->m_blockwmask = mp->m_blockwsize - 1; mp->m_rtxblklog = log2_if_power2(sbp->sb_rextsize); mp->m_rtxblkmask = mask64_if_power2(sbp->sb_rextsize); + mp->m_rgblklog = 0; + mp->m_rgblkmask = 0; mp->m_alloc_mxr[0] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 1); mp->m_alloc_mxr[1] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 0); diff --git a/libxfs/xfs_types.h b/libxfs/xfs_types.h index f4615c5be34..c27c84561b5 100644 --- a/libxfs/xfs_types.h +++ b/libxfs/xfs_types.h @@ -9,10 +9,12 @@ typedef uint32_t prid_t; /* project ID */ typedef uint32_t xfs_agblock_t; /* blockno in alloc. group */ +typedef uint32_t xfs_rgblock_t; /* blockno in realtime group */ typedef uint32_t xfs_agino_t; /* inode # within allocation grp */ typedef uint32_t xfs_extlen_t; /* extent length in blocks */ typedef uint32_t xfs_rtxlen_t; /* file extent length in rtextents */ typedef uint32_t xfs_agnumber_t; /* allocation group number */ +typedef uint32_t xfs_rgnumber_t; /* realtime group number */ typedef uint64_t xfs_extnum_t; /* # of extents in a file */ typedef uint32_t xfs_aextnum_t; /* # extents in an attribute fork */ typedef int64_t xfs_fsize_t; /* bytes in a file */ @@ -54,7 +56,9 @@ typedef void * xfs_failaddr_t; #define NULLRTEXTNO ((xfs_rtxnum_t)-1) #define NULLAGBLOCK ((xfs_agblock_t)-1) +#define NULLRGBLOCK ((xfs_rgblock_t)-1) #define NULLAGNUMBER ((xfs_agnumber_t)-1) +#define NULLRGNUMBER ((xfs_rgnumber_t)-1) #define NULLCOMMITLSN ((xfs_lsn_t)-1) From patchwork Fri Dec 30 22:19:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085675 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 999D2C4332F for ; Sat, 31 Dec 2022 02:30:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236231AbiLaCag (ORCPT ); Fri, 30 Dec 2022 21:30:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236141AbiLaCag (ORCPT ); Fri, 30 Dec 2022 21:30:36 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFC501CB19 for ; Fri, 30 Dec 2022 18:30:34 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 5FA7A61D07 for ; Sat, 31 Dec 2022 02:30:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C07D6C433EF; Sat, 31 Dec 2022 02:30:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453833; bh=YZXZR5Ydr9QxZpAW0uT3dcF4YQM0vUa0K/2sKa6JoRQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=bktctW1VTuoVUx8n9+VgohPu42qeAU/eXHXuO068ghxmxpp+2/vYh6iPSBkkPrpdo RJVmuKDwE5uQy/qlTb2kRT6ZXSz7AXhvtwn+6nF2yPqn1NAkQFolMPo4jhWyldonLM 2HCLRBuFn8Cde/CsaIwiA1CWv/ObRyIOlhjohFb/bX1R576Ctljp+hS3ONAwMY3R4r AaI2HzqoypbHx0fu1aDyIZFemfZrQXhijy7HiAIG7k/8ef9UJpJ79Gw5xQ2X6zNFwc LoUDECX2vMD0AA1kVmTpp5pOHA0vlPPdjYFQwkc3pVZmjHnG/2Y18FHwZYUPZwRh5S 3FRtzgmni1KWg== Subject: [PATCH 02/45] xfs: define the format of rt groups From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:43 -0800 Message-ID: <167243878393.731133.11506740935409124234.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Define the ondisk format of realtime group metadata. Signed-off-by: Darrick J. Wong --- db/convert.c | 8 ---- include/libxfs.h | 1 + libfrog/util.c | 14 +++++++ libfrog/util.h | 2 + libxfs/libxfs_priv.h | 19 ++++++++++ libxfs/xfs_format.h | 62 ++++++++++++++++++++++++++++++++- libxfs/xfs_rtgroup.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_rtgroup.h | 83 ++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_sb.c | 86 +++++++++++++++++++++++++++++++++++++++++++-- libxfs/xfs_shared.h | 1 + mkfs/xfs_mkfs.c | 1 + repair/sb.c | 1 + 12 files changed, 360 insertions(+), 13 deletions(-) diff --git a/db/convert.c b/db/convert.c index 0aed1437dc4..072ccc8f6ef 100644 --- a/db/convert.c +++ b/db/convert.c @@ -413,14 +413,6 @@ convert_f(int argc, char **argv) return 0; } -static inline xfs_rtblock_t -xfs_daddr_to_rtb( - struct xfs_mount *mp, - xfs_daddr_t daddr) -{ - return daddr >> mp->m_blkbb_log; -} - static inline uint64_t rt_daddr_to_rsumblock( struct xfs_mount *mp, diff --git a/include/libxfs.h b/include/libxfs.h index 26202dede67..5b58750fcd5 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -86,6 +86,7 @@ struct iomap; #include "xfs_ag_resv.h" #include "xfs_imeta.h" #include "xfs_rtbitmap.h" +#include "xfs_rtgroup.h" #ifndef ARRAY_SIZE #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) diff --git a/libfrog/util.c b/libfrog/util.c index 8fb10cf82f5..46047571a55 100644 --- a/libfrog/util.c +++ b/libfrog/util.c @@ -22,3 +22,17 @@ log2_roundup(unsigned int i) } return rval; } + +void * +memchr_inv(const void *start, int c, size_t bytes) +{ + const unsigned char *p = start; + + while (bytes > 0) { + if (*p != (unsigned char)c) + return (void *)p; + bytes--; + } + + return NULL; +} diff --git a/libfrog/util.h b/libfrog/util.h index 1b97881bf16..ac2f331c93e 100644 --- a/libfrog/util.h +++ b/libfrog/util.h @@ -8,4 +8,6 @@ unsigned int log2_roundup(unsigned int i); +void *memchr_inv(const void *start, int c, size_t bytes); + #endif /* __LIBFROG_UTIL_H__ */ diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index aeb42837af4..57b92ac1b99 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -51,6 +51,7 @@ #include "kmem.h" #include "libfrog/radix-tree.h" #include "libfrog/div64.h" +#include "libfrog/util.h" #include "atomic.h" #include "spinlock.h" #include "linux-err.h" @@ -396,6 +397,24 @@ static inline unsigned long long mask64_if_power2(unsigned long b) return is_power_of_2(b) ? b - 1 : 0; } +/* If @b is a power of 2, return log2(b). Else return zero. */ +static inline unsigned int log2_if_power(unsigned long b) +{ + unsigned long mask = 1; + unsigned int i; + unsigned int ret = 1; + + if (!is_power_of_2(b)) + return 0; + + for (i = 0; i < NBBY * sizeof(unsigned long); i++, mask <<= 1) { + if (b & mask) + ret = i; + } + + return ret; +} + /* buffer management */ #define XBF_TRYLOCK 0 #define XBF_UNMAPPED 0 diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index ca87a3f8704..a38e1499bd4 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -216,7 +216,17 @@ struct xfs_dsb { * pointers are no longer used. */ __be64 sb_rbmino; - __be64 sb_rsumino; /* summary inode for rt bitmap */ + /* + * rtgroups requires metadir, so we reuse the rsumino space to hold + * the rg block count and shift values. + */ + union { + __be64 sb_rsumino; /* summary inode for rt bitmap */ + struct { + __be32 sb_rgcount; /* # of realtime groups */ + __be32 sb_rgblocks; /* rtblocks per group */ + }; + }; __be32 sb_rextsize; /* realtime extent size, blocks */ __be32 sb_agblocks; /* size of an allocation group */ __be32 sb_agcount; /* number of allocation groups */ @@ -397,6 +407,7 @@ xfs_sb_has_ro_compat_feature( #define XFS_SB_FEAT_INCOMPAT_BIGTIME (1 << 3) /* large timestamps */ #define XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR (1 << 4) /* needs xfs_repair */ #define XFS_SB_FEAT_INCOMPAT_NREXT64 (1 << 5) /* large extent counters */ +#define XFS_SB_FEAT_INCOMPAT_RTGROUPS (1 << 30) /* realtime groups */ #define XFS_SB_FEAT_INCOMPAT_METADIR (1U << 31) /* metadata dir tree */ #define XFS_SB_FEAT_INCOMPAT_ALL \ (XFS_SB_FEAT_INCOMPAT_FTYPE| \ @@ -741,6 +752,55 @@ union xfs_suminfo_ondisk { __u32 raw; }; +/* + * Realtime allocation groups break the rt section into multiple pieces that + * could be locked independently. Realtime block group numbers are 32-bit + * quantities. Block numbers within a group are also 32-bit quantities, but + * the upper bit must never be set. + */ +#define XFS_MAX_RGBLOCKS ((xfs_rgblock_t)(1U << 31) - 1) +#define XFS_MAX_RGNUMBER ((xfs_rgnumber_t)(-1U)) + +#define XFS_RTSB_MAGIC 0x58524750 /* 'XRGP' */ + +/* + * Realtime superblock - on disk version. Must be padded to 64 bit alignment. + * The first block of each realtime group contains this superblock; this is + * how we avoid having file data extents cross a group boundary. + */ +struct xfs_rtsb { + __be32 rsb_magicnum; /* magic number == XFS_RTSB_MAGIC */ + __be32 rsb_blocksize; /* logical block size, bytes */ + __be64 rsb_rblocks; /* number of realtime blocks */ + + __be64 rsb_rextents; /* number of realtime extents */ + __be64 rsb_lsn; /* last write sequence */ + + __be32 rsb_rgcount; /* # of realtime groups */ + char rsb_fname[XFSLABEL_MAX]; /* rt volume name */ + + uuid_t rsb_uuid; /* user-visible file system unique id */ + + __be32 rsb_rextsize; /* realtime extent size, blocks */ + __be32 rsb_rbmblocks; /* number of rt bitmap blocks */ + + __be32 rsb_rgblocks; /* rt blocks per group */ + __u8 rsb_blocklog; /* log2 of sb_blocksize */ + __u8 rsb_sectlog; /* log2 of sb_sectsize */ + __u8 rsb_rextslog; /* log2 of sb_rextents */ + __u8 rsb_pad; + + __le32 rsb_crc; /* superblock crc */ + __le32 rsb_pad2; + + uuid_t rsb_meta_uuid; /* metadata file system unique id */ + + /* must be padded to 64 bit alignment */ +}; + +#define XFS_RTSB_CRC_OFF offsetof(struct xfs_rtsb, rsb_crc) +#define XFS_RTSB_DADDR ((xfs_daddr_t)0) /* daddr in rt section */ + /* * XFS Timestamps * ============== diff --git a/libxfs/xfs_rtgroup.c b/libxfs/xfs_rtgroup.c index 7d26ef76d3e..ef1d1f29d64 100644 --- a/libxfs/xfs_rtgroup.c +++ b/libxfs/xfs_rtgroup.c @@ -210,3 +210,98 @@ xfs_rtgroup_block_count( return __xfs_rtgroup_block_count(mp, rgno, mp->m_sb.sb_rgcount, mp->m_sb.sb_rblocks); } + +static xfs_failaddr_t +xfs_rtsb_verify( + struct xfs_buf *bp) +{ + struct xfs_mount *mp = bp->b_mount; + struct xfs_rtsb *rsb = bp->b_addr; + + if (!xfs_verify_magic(bp, rsb->rsb_magicnum)) + return __this_address; + if (be32_to_cpu(rsb->rsb_blocksize) != mp->m_sb.sb_blocksize) + return __this_address; + if (be64_to_cpu(rsb->rsb_rblocks) != mp->m_sb.sb_rblocks) + return __this_address; + + if (be64_to_cpu(rsb->rsb_rextents) != mp->m_sb.sb_rextents) + return __this_address; + + if (!uuid_equal(&rsb->rsb_uuid, &mp->m_sb.sb_uuid)) + return __this_address; + + if (be32_to_cpu(rsb->rsb_rgcount) != mp->m_sb.sb_rgcount) + return __this_address; + + if (be32_to_cpu(rsb->rsb_rextsize) != mp->m_sb.sb_rextsize) + return __this_address; + if (be32_to_cpu(rsb->rsb_rbmblocks) != mp->m_sb.sb_rbmblocks) + return __this_address; + + if (be32_to_cpu(rsb->rsb_rgblocks) != mp->m_sb.sb_rgblocks) + return __this_address; + if (rsb->rsb_blocklog != mp->m_sb.sb_blocklog) + return __this_address; + if (rsb->rsb_sectlog != mp->m_sb.sb_sectlog) + return __this_address; + if (rsb->rsb_rextslog != mp->m_sb.sb_rextslog) + return __this_address; + if (rsb->rsb_pad) + return __this_address; + + if (rsb->rsb_pad2) + return __this_address; + + if (!uuid_equal(&rsb->rsb_meta_uuid, &mp->m_sb.sb_meta_uuid)) + return __this_address; + + /* Everything to the end of the fs block must be zero */ + if (memchr_inv(rsb + 1, 0, BBTOB(bp->b_length) - sizeof(*rsb))) + return __this_address; + + return NULL; +} + +static void +xfs_rtsb_read_verify( + struct xfs_buf *bp) +{ + xfs_failaddr_t fa; + + if (!xfs_buf_verify_cksum(bp, XFS_RTSB_CRC_OFF)) + xfs_verifier_error(bp, -EFSBADCRC, __this_address); + else { + fa = xfs_rtsb_verify(bp); + if (fa) + xfs_verifier_error(bp, -EFSCORRUPTED, fa); + } +} + +static void +xfs_rtsb_write_verify( + struct xfs_buf *bp) +{ + struct xfs_rtsb *rsb = bp->b_addr; + struct xfs_buf_log_item *bip = bp->b_log_item; + xfs_failaddr_t fa; + + fa = xfs_rtsb_verify(bp); + if (fa) { + xfs_verifier_error(bp, -EFSCORRUPTED, fa); + return; + } + + if (bip) + rsb->rsb_lsn = cpu_to_be64(bip->bli_item.li_lsn); + + xfs_buf_update_cksum(bp, XFS_RTSB_CRC_OFF); +} + +const struct xfs_buf_ops xfs_rtsb_buf_ops = { + .name = "xfs_rtsb", + .magic = { 0, cpu_to_be32(XFS_RTSB_MAGIC) }, + .verify_read = xfs_rtsb_read_verify, + .verify_write = xfs_rtsb_write_verify, + .verify_struct = xfs_rtsb_verify, +}; diff --git a/libxfs/xfs_rtgroup.h b/libxfs/xfs_rtgroup.h index f414218a66f..ff9b01d8c50 100644 --- a/libxfs/xfs_rtgroup.h +++ b/libxfs/xfs_rtgroup.h @@ -111,6 +111,89 @@ xfs_verify_rgbext( return xfs_verify_rgbno(rtg, rgbno + len - 1); } +static inline xfs_rtblock_t +xfs_rgbno_to_rtb( + struct xfs_mount *mp, + xfs_rgnumber_t rgno, + xfs_rgblock_t rgbno) +{ + ASSERT(xfs_has_rtgroups(mp)); + + if (mp->m_rgblklog >= 0) + return ((xfs_rtblock_t)rgno << mp->m_rgblklog) | rgbno; + + return ((xfs_rtblock_t)rgno * mp->m_sb.sb_rgblocks) + rgbno; +} + +static inline xfs_rgnumber_t +xfs_rtb_to_rgno( + struct xfs_mount *mp, + xfs_rtblock_t rtbno) +{ + ASSERT(xfs_has_rtgroups(mp)); + + if (mp->m_rgblklog >= 0) + return rtbno >> mp->m_rgblklog; + + return div_u64(rtbno, mp->m_sb.sb_rgblocks); +} + +static inline xfs_rgblock_t +xfs_rtb_to_rgbno( + struct xfs_mount *mp, + xfs_rtblock_t rtbno, + xfs_rgnumber_t *rgno) +{ + uint32_t rem; + + ASSERT(xfs_has_rtgroups(mp)); + + if (mp->m_rgblklog >= 0) { + *rgno = rtbno >> mp->m_rgblklog; + return rtbno & mp->m_rgblkmask; + } + + *rgno = div_u64_rem(rtbno, mp->m_sb.sb_rgblocks, &rem); + return rem; +} + +static inline xfs_daddr_t +xfs_rtb_to_daddr( + struct xfs_mount *mp, + xfs_rtblock_t rtbno) +{ + return rtbno << mp->m_blkbb_log; +} + +static inline xfs_rtblock_t +xfs_daddr_to_rtb( + struct xfs_mount *mp, + xfs_daddr_t daddr) +{ + return daddr >> mp->m_blkbb_log; +} + +static inline xfs_rgnumber_t +xfs_daddr_to_rgno( + struct xfs_mount *mp, + xfs_daddr_t daddr) +{ + xfs_rtblock_t rtb = daddr >> mp->m_blkbb_log; + + return xfs_rtb_to_rgno(mp, rtb); +} + +static inline xfs_rgblock_t +xfs_daddr_to_rgbno( + struct xfs_mount *mp, + xfs_daddr_t daddr) +{ + xfs_rtblock_t rtb = daddr >> mp->m_blkbb_log; + xfs_rgnumber_t rgno; + + return xfs_rtb_to_rgbno(mp, rtb, &rgno); +} + #ifdef CONFIG_XFS_RT xfs_rgblock_t xfs_rtgroup_block_count(struct xfs_mount *mp, xfs_rgnumber_t rgno); diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index ac2e9f91989..aec147fe5f8 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -174,6 +174,8 @@ xfs_sb_version_to_features( features |= XFS_FEAT_NREXT64; if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_METADIR) features |= XFS_FEAT_METADIR; + if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_RTGROUPS) + features |= XFS_FEAT_RTGROUPS; return features; } @@ -300,6 +302,64 @@ xfs_validate_sb_write( return 0; } +static int +xfs_validate_sb_rtgroups( + struct xfs_mount *mp, + struct xfs_sb *sbp) +{ + uint64_t groups; + + if (!(sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_METADIR)) { + xfs_warn(mp, +"Realtime groups require metadata directory tree."); + return -EINVAL; + } + + if (sbp->sb_rgblocks > XFS_MAX_RGBLOCKS) { + xfs_warn(mp, +"Realtime group size (%u) must be less than %u.", + sbp->sb_rgblocks, XFS_MAX_RGBLOCKS); + return -EINVAL; + } + + if (sbp->sb_rextsize == 0) { + xfs_warn(mp, +"Realtime extent size must not be zero."); + return -EINVAL; + } + + if (sbp->sb_rgblocks % sbp->sb_rextsize != 0) { + xfs_warn(mp, +"Realtime group size (%u) must be an even multiple of extent size (%u).", + sbp->sb_rgblocks, sbp->sb_rextsize); + return -EINVAL; + } + + if (sbp->sb_rgblocks < (sbp->sb_rextsize << 1)) { + xfs_warn(mp, +"Realtime group size (%u) must be greater than 1 rt extent.", + sbp->sb_rgblocks); + return -EINVAL; + } + + if (sbp->sb_rgcount > XFS_MAX_RGNUMBER) { + xfs_warn(mp, +"Realtime groups (%u) must be less than %u.", + sbp->sb_rgcount, XFS_MAX_RGNUMBER); + return -EINVAL; + } + + groups = howmany_64(sbp->sb_rblocks, sbp->sb_rgblocks); + if (groups != sbp->sb_rgcount) { + xfs_warn(mp, +"Realtime groups (%u) do not cover the entire rt section; need (%llu) groups.", + sbp->sb_rgcount, groups); + return -EINVAL; + } + + return 0; +} + /* Check the validity of the SB. */ STATIC int xfs_validate_sb_common( @@ -311,6 +371,7 @@ xfs_validate_sb_common( uint32_t agcount = 0; uint32_t rem; bool has_dalign; + int error; if (!xfs_verify_magic(bp, dsb->sb_magicnum)) { xfs_warn(mp, @@ -360,6 +421,12 @@ xfs_validate_sb_common( return -EINVAL; } } + + if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_RTGROUPS) { + error = xfs_validate_sb_rtgroups(mp, sbp); + if (error) + return error; + } } else if (sbp->sb_qflags & (XFS_PQUOTA_ENFD | XFS_GQUOTA_ENFD | XFS_PQUOTA_CHKD | XFS_GQUOTA_CHKD)) { xfs_notice(mp, @@ -640,8 +707,13 @@ __xfs_sb_from_disk( to->sb_pquotino = NULLFSINO; } - to->sb_rgcount = 0; - to->sb_rgblocks = 0; + if (to->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_RTGROUPS) { + to->sb_rgcount = be32_to_cpu(from->sb_rgcount); + to->sb_rgblocks = be32_to_cpu(from->sb_rgblocks); + } else { + to->sb_rgcount = 0; + to->sb_rgblocks = 0; + } } void @@ -801,6 +873,12 @@ xfs_sb_to_disk( to->sb_gquotino = cpu_to_be64(NULLFSINO); to->sb_pquotino = cpu_to_be64(NULLFSINO); } + + if (from->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_RTGROUPS) { + /* must come after setting to_rsumino */ + to->sb_rgcount = cpu_to_be32(from->sb_rgcount); + to->sb_rgblocks = cpu_to_be32(from->sb_rgblocks); + } } /* @@ -955,8 +1033,8 @@ xfs_sb_mount_common( mp->m_blockwmask = mp->m_blockwsize - 1; mp->m_rtxblklog = log2_if_power2(sbp->sb_rextsize); mp->m_rtxblkmask = mask64_if_power2(sbp->sb_rextsize); - mp->m_rgblklog = 0; - mp->m_rgblkmask = 0; + mp->m_rgblklog = log2_if_power2(sbp->sb_rgblocks); + mp->m_rgblkmask = mask64_if_power2(sbp->sb_rgblocks); mp->m_alloc_mxr[0] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 1); mp->m_alloc_mxr[1] = xfs_allocbt_maxrecs(mp, sbp->sb_blocksize, 0); diff --git a/libxfs/xfs_shared.h b/libxfs/xfs_shared.h index 46754fe5736..e76e735b1d0 100644 --- a/libxfs/xfs_shared.h +++ b/libxfs/xfs_shared.h @@ -39,6 +39,7 @@ extern const struct xfs_buf_ops xfs_inode_buf_ra_ops; extern const struct xfs_buf_ops xfs_refcountbt_buf_ops; extern const struct xfs_buf_ops xfs_rmapbt_buf_ops; extern const struct xfs_buf_ops xfs_rtbuf_ops; +extern const struct xfs_buf_ops xfs_rtsb_buf_ops; extern const struct xfs_buf_ops xfs_sb_buf_ops; extern const struct xfs_buf_ops xfs_sb_quiet_buf_ops; extern const struct xfs_buf_ops xfs_symlink_buf_ops; diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index df8acf221ac..0324daaad3a 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -3,6 +3,7 @@ * Copyright (c) 2000-2005 Silicon Graphics, Inc. * All Rights Reserved. */ +#include #include "libfrog/util.h" #include "libxfs.h" #include diff --git a/repair/sb.c b/repair/sb.c index c5dbc6c2062..6e7f448596e 100644 --- a/repair/sb.c +++ b/repair/sb.c @@ -3,6 +3,7 @@ * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc. * All Rights Reserved. */ +#include #include "libfrog/util.h" #include "libxfs.h" #include "libxcmd.h" From patchwork Fri Dec 30 22:19:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085676 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 A5955C4332F for ; Sat, 31 Dec 2022 02:30:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236232AbiLaCaw (ORCPT ); Fri, 30 Dec 2022 21:30:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236141AbiLaCav (ORCPT ); Fri, 30 Dec 2022 21:30:51 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57A19FD39 for ; Fri, 30 Dec 2022 18:30:50 -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 dfw.source.kernel.org (Postfix) with ESMTPS id E993261CD4 for ; Sat, 31 Dec 2022 02:30:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AF31C433EF; Sat, 31 Dec 2022 02:30:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453849; bh=qkiB7nk7CdeuODSrnI1szo/Ry33IQrlLPo1w52ppYD8=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=t2hZ1E5RlwHHdR+DLEnqF1pyEylCHb+kAZ8fnr2F60BCi1Ep1cpGr+2tK/Mal3ETd Ni7z00qF0ysUHGxgQRur534QagN6SthgUV8vNefec7zVGESK1XZQB7ymnYtnXVNk9k EOVjZS+AOSeR/DSmXjkPMv/e+1WWQmkp5UvgAiERE4L+7y/Acy/J8T3NzeOPXNQMtt qt7uTLKmYlyBEDoOpBL+Htc0ZqhISaeVl7gPZNuHy1DNsWHoKHNh6BUI45HHwCt+UL z7LcmcE1yxoRrRz1ZQ9KOInYLcE5fsXCJ2bWhCp8SlR0jznDRx1IFJVQazRTWc2esy QLkU6WCZX4+og== Subject: [PATCH 03/45] xfs: update primary realtime super every time we update the primary fs super From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:44 -0800 Message-ID: <167243878406.731133.6106890863183020755.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Every time we update parts of the primary filesystem superblock that are echoed in the primary rt super, we should update that primary realtime super. Avoid an ondisk log format change by using ordered buffers to write the primary rt super. Signed-off-by: Darrick J. Wong --- include/xfs_trans.h | 1 + libxfs/libxfs_api_defs.h | 1 + libxfs/libxfs_io.h | 1 + libxfs/rdwr.c | 17 +++++++++++ libxfs/trans.c | 29 ++++++++++++++++++ libxfs/xfs_rtgroup.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_rtgroup.h | 6 ++++ libxfs/xfs_sb.c | 13 ++++++++ 8 files changed, 142 insertions(+) diff --git a/include/xfs_trans.h b/include/xfs_trans.h index bfaee7e8fed..0ecf0a95560 100644 --- a/include/xfs_trans.h +++ b/include/xfs_trans.h @@ -98,6 +98,7 @@ int libxfs_trans_reserve_more(struct xfs_trans *tp, uint blocks, void xfs_defer_cancel(struct xfs_trans *); struct xfs_buf *libxfs_trans_getsb(struct xfs_trans *); +struct xfs_buf *libxfs_trans_getrtsb(struct xfs_trans *tp); void libxfs_trans_ijoin(struct xfs_trans *, struct xfs_inode *, uint); void libxfs_trans_log_inode (struct xfs_trans *, struct xfs_inode *, diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 7ce9686c00d..4d9499529c0 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -263,6 +263,7 @@ #define xfs_trans_dirty_buf libxfs_trans_dirty_buf #define xfs_trans_get_buf libxfs_trans_get_buf #define xfs_trans_get_buf_map libxfs_trans_get_buf_map +#define xfs_trans_getrtsb libxfs_trans_getrtsb #define xfs_trans_getsb libxfs_trans_getsb #define xfs_trans_ichgtime libxfs_trans_ichgtime #define xfs_trans_ijoin libxfs_trans_ijoin diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h index fb536c1c3c9..d54258c7355 100644 --- a/libxfs/libxfs_io.h +++ b/libxfs/libxfs_io.h @@ -197,6 +197,7 @@ libxfs_buf_read( int libxfs_readbuf_verify(struct xfs_buf *bp, const struct xfs_buf_ops *ops); struct xfs_buf *libxfs_getsb(struct xfs_mount *mp); +struct xfs_buf *libxfs_getrtsb(struct xfs_mount *mp); extern void libxfs_bcache_purge(struct xfs_mount *mp); extern void libxfs_bcache_free(void); extern void libxfs_bcache_flush(struct xfs_mount *mp); diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c index 2c66b84ff83..1c91f557f41 100644 --- a/libxfs/rdwr.c +++ b/libxfs/rdwr.c @@ -164,6 +164,23 @@ libxfs_getsb( return bp; } +struct xfs_buf * +libxfs_getrtsb( + struct xfs_mount *mp) +{ + struct xfs_buf *bp; + int error; + + if (!mp->m_rtdev_targp->bt_bdev) + return NULL; + + error = libxfs_buf_read_uncached(mp->m_rtdev_targp, XFS_RTSB_DADDR, + XFS_FSB_TO_BB(mp, 1), 0, &bp, &xfs_rtsb_buf_ops); + if (error) + return NULL; + return bp; +} + struct kmem_cache *xfs_buf_cache; static struct cache_mru xfs_buf_freelist = diff --git a/libxfs/trans.c b/libxfs/trans.c index 3120d8b1dea..06d3655c33b 100644 --- a/libxfs/trans.c +++ b/libxfs/trans.c @@ -511,6 +511,35 @@ libxfs_trans_getsb( return bp; } +struct xfs_buf * +libxfs_trans_getrtsb( + struct xfs_trans *tp) +{ + struct xfs_mount *mp = tp->t_mountp; + struct xfs_buf *bp; + struct xfs_buf_log_item *bip; + int len = XFS_FSS_TO_BB(mp, 1); + DEFINE_SINGLE_BUF_MAP(map, XFS_SB_DADDR, len); + + bp = xfs_trans_buf_item_match(tp, mp->m_rtdev, &map, 1); + if (bp != NULL) { + ASSERT(bp->b_transp == tp); + bip = bp->b_log_item; + ASSERT(bip != NULL); + bip->bli_recur++; + trace_xfs_trans_getsb_recur(bip); + return bp; + } + + bp = libxfs_getrtsb(mp); + if (bp == NULL) + return NULL; + + _libxfs_trans_bjoin(tp, bp, 1); + trace_xfs_trans_getsb(bp->b_log_item); + return bp; +} + int libxfs_trans_read_buf_map( struct xfs_mount *mp, diff --git a/libxfs/xfs_rtgroup.c b/libxfs/xfs_rtgroup.c index ef1d1f29d64..a96df704070 100644 --- a/libxfs/xfs_rtgroup.c +++ b/libxfs/xfs_rtgroup.c @@ -305,3 +305,77 @@ const struct xfs_buf_ops xfs_rtsb_buf_ops = { .verify_write = xfs_rtsb_write_verify, .verify_struct = xfs_rtsb_verify, }; + +/* Update a realtime superblock from the primary fs super */ +void +xfs_rtgroup_update_super( + struct xfs_buf *rtsb_bp, + const struct xfs_buf *sb_bp) +{ + const struct xfs_dsb *dsb = sb_bp->b_addr; + struct xfs_rtsb *rsb = rtsb_bp->b_addr; + const uuid_t *meta_uuid; + + rsb->rsb_magicnum = cpu_to_be32(XFS_RTSB_MAGIC); + rsb->rsb_blocksize = dsb->sb_blocksize; + rsb->rsb_rblocks = dsb->sb_rblocks; + + rsb->rsb_rextents = dsb->sb_rextents; + rsb->rsb_lsn = 0; + + memcpy(&rsb->rsb_uuid, &dsb->sb_uuid, sizeof(rsb->rsb_uuid)); + + rsb->rsb_rgcount = dsb->sb_rgcount; + memcpy(&rsb->rsb_fname, &dsb->sb_fname, XFSLABEL_MAX); + + rsb->rsb_rextsize = dsb->sb_rextsize; + rsb->rsb_rbmblocks = dsb->sb_rbmblocks; + + rsb->rsb_rgblocks = dsb->sb_rgblocks; + rsb->rsb_blocklog = dsb->sb_blocklog; + rsb->rsb_sectlog = dsb->sb_sectlog; + rsb->rsb_rextslog = dsb->sb_rextslog; + rsb->rsb_pad = 0; + rsb->rsb_pad2 = 0; + + /* + * The metadata uuid is the fs uuid if the metauuid feature is not + * enabled. + */ + if (dsb->sb_features_incompat & + cpu_to_be32(XFS_SB_FEAT_INCOMPAT_META_UUID)) + meta_uuid = &dsb->sb_meta_uuid; + else + meta_uuid = &dsb->sb_uuid; + memcpy(&rsb->rsb_meta_uuid, meta_uuid, sizeof(rsb->rsb_meta_uuid)); +} + +/* + * Update the primary realtime superblock from a filesystem superblock and + * log it to the given transaction. + */ +void +xfs_rtgroup_log_super( + struct xfs_trans *tp, + const struct xfs_buf *sb_bp) +{ + struct xfs_buf *rtsb_bp; + + if (!xfs_has_rtgroups(tp->t_mountp)) + return; + + rtsb_bp = xfs_trans_getrtsb(tp); + if (!rtsb_bp) { + /* + * It's possible for the rtgroups feature to be enabled but + * there is no incore rt superblock buffer if the rt geometry + * was specified at mkfs time but the rt section has not yet + * been attached. In this case, rblocks must be zero. + */ + ASSERT(tp->t_mountp->m_sb.sb_rblocks == 0); + return; + } + + xfs_rtgroup_update_super(rtsb_bp, sb_bp); + xfs_trans_ordered_buf(tp, rtsb_bp); +} diff --git a/libxfs/xfs_rtgroup.h b/libxfs/xfs_rtgroup.h index ff9b01d8c50..c6db6b0d2ae 100644 --- a/libxfs/xfs_rtgroup.h +++ b/libxfs/xfs_rtgroup.h @@ -197,8 +197,14 @@ xfs_daddr_to_rgbno( #ifdef CONFIG_XFS_RT xfs_rgblock_t xfs_rtgroup_block_count(struct xfs_mount *mp, xfs_rgnumber_t rgno); + +void xfs_rtgroup_update_super(struct xfs_buf *rtsb_bp, + const struct xfs_buf *sb_bp); +void xfs_rtgroup_log_super(struct xfs_trans *tp, const struct xfs_buf *sb_bp); #else # define xfs_rtgroup_block_count(mp, rgno) (0) +# define xfs_rtgroup_update_super(bp, sb_bp) ((void)0) +# define xfs_rtgroup_log_super(tp, sb_bp) ((void)0) #endif /* CONFIG_XFS_RT */ #endif /* __LIBXFS_RTGROUP_H */ diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index aec147fe5f8..7b8baf64e82 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -24,6 +24,7 @@ #include "xfs_health.h" #include "xfs_ag.h" #include "xfs_swapext.h" +#include "xfs_rtgroup.h" /* * Physical superblock buffer manipulations. Shared with libxfs in userspace. @@ -1098,6 +1099,8 @@ xfs_log_sb( xfs_sb_to_disk(bp->b_addr, &mp->m_sb); xfs_trans_buf_set_type(tp, bp, XFS_BLFT_SB_BUF); xfs_trans_log_buf(tp, bp, 0, sizeof(struct xfs_dsb) - 1); + + xfs_rtgroup_log_super(tp, bp); } /* @@ -1214,6 +1217,7 @@ xfs_sync_sb_buf( { struct xfs_trans *tp; struct xfs_buf *bp; + struct xfs_buf *rtsb_bp = NULL; int error; error = xfs_trans_alloc(mp, &M_RES(mp)->tr_sb, 0, 0, 0, &tp); @@ -1223,6 +1227,11 @@ xfs_sync_sb_buf( bp = xfs_trans_getsb(tp); xfs_log_sb(tp); xfs_trans_bhold(tp, bp); + if (xfs_has_rtgroups(mp)) { + rtsb_bp = xfs_trans_getrtsb(tp); + if (rtsb_bp) + xfs_trans_bhold(tp, rtsb_bp); + } xfs_trans_set_sync(tp); error = xfs_trans_commit(tp); if (error) @@ -1231,7 +1240,11 @@ xfs_sync_sb_buf( * write out the sb buffer to get the changes to disk */ error = xfs_bwrite(bp); + if (!error && rtsb_bp) + error = xfs_bwrite(rtsb_bp); out: + if (rtsb_bp) + xfs_buf_relse(rtsb_bp); xfs_buf_relse(bp); return error; } From patchwork Fri Dec 30 22:19:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085677 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 7387BC4332F for ; Sat, 31 Dec 2022 02:31:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236233AbiLaCbK (ORCPT ); Fri, 30 Dec 2022 21:31:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236141AbiLaCbI (ORCPT ); Fri, 30 Dec 2022 21:31:08 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7441926D9 for ; Fri, 30 Dec 2022 18:31:07 -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 30C58B81E74 for ; Sat, 31 Dec 2022 02:31:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6324C433D2; Sat, 31 Dec 2022 02:31:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453864; bh=n36uz5AclnRyiSDn5mnn5ME8LxdDnFV6hoGG+TXRYcI=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=RfzCEVew/x9bv0DCQfDvvimfWQbkRHMGy4lepF8ANU+BiHZDK0Uyne5uNzyM4u51T /YgSpBSWTGAef1xUzsS3yh6prbKzUgSCbKhChHSfYpxVymO8mwvOjdh1rJWSpNjYXr Fv9ShhYY5jn9NE3vgBXo4apr6QAxsW/dqmLuhQuMh+7iPGO++JThq/QVXy3qn5AkaP 8bQvexl6LvnaUlJiTb3FE7WGvWBatCx/IAkeM1In8djoGaLP0YSbQthIzZzM557Bs4 fOjGv5/CYiy/2/ifCvqCNJf5qdH8JwcOgiSS21VbLgccIiRCuYvDu0jtTZxeV92O5k eMsTLl9QybDrw== Subject: [PATCH 04/45] xfs: write secondary realtime superblocks to disk From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:44 -0800 Message-ID: <167243878418.731133.16733075538857636510.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Create some library functions to make it easy to update all the secondary realtime superblocks on disk; this will be used by growfs, xfs_db, mkfs, and xfs_repair. Signed-off-by: Darrick J. Wong --- libxfs/xfs_rtgroup.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_rtgroup.h | 2 + 2 files changed, 119 insertions(+) diff --git a/libxfs/xfs_rtgroup.c b/libxfs/xfs_rtgroup.c index a96df704070..9caf39fd51a 100644 --- a/libxfs/xfs_rtgroup.c +++ b/libxfs/xfs_rtgroup.c @@ -379,3 +379,120 @@ xfs_rtgroup_log_super( xfs_rtgroup_update_super(rtsb_bp, sb_bp); xfs_trans_ordered_buf(tp, rtsb_bp); } + +/* Initialize a secondary realtime superblock. */ +static int +xfs_rtgroup_init_secondary_super( + struct xfs_mount *mp, + xfs_rgnumber_t rgno, + struct xfs_buf **bpp) +{ + struct xfs_buf *bp; + struct xfs_rtsb *rsb; + xfs_rtblock_t rtbno; + int error; + + ASSERT(rgno != 0); + + error = xfs_buf_get_uncached(mp->m_rtdev_targp, XFS_FSB_TO_BB(mp, 1), + 0, &bp); + if (error) + return error; + + rtbno = xfs_rgbno_to_rtb(mp, rgno, 0); + bp->b_maps[0].bm_bn = xfs_rtb_to_daddr(mp, rtbno); + bp->b_ops = &xfs_rtsb_buf_ops; + xfs_buf_zero(bp, 0, BBTOB(bp->b_length)); + + rsb = bp->b_addr; + rsb->rsb_magicnum = cpu_to_be32(XFS_RTSB_MAGIC); + rsb->rsb_blocksize = cpu_to_be32(mp->m_sb.sb_blocksize); + rsb->rsb_rblocks = cpu_to_be64(mp->m_sb.sb_rblocks); + + rsb->rsb_rextents = cpu_to_be64(mp->m_sb.sb_rextents); + + memcpy(&rsb->rsb_uuid, &mp->m_sb.sb_uuid, sizeof(rsb->rsb_uuid)); + + rsb->rsb_rgcount = cpu_to_be32(mp->m_sb.sb_rgcount); + memcpy(&rsb->rsb_fname, &mp->m_sb.sb_fname, XFSLABEL_MAX); + + rsb->rsb_rextsize = cpu_to_be32(mp->m_sb.sb_rextsize); + rsb->rsb_rbmblocks = cpu_to_be32(mp->m_sb.sb_rbmblocks); + + rsb->rsb_rgblocks = cpu_to_be32(mp->m_sb.sb_rgblocks); + rsb->rsb_blocklog = mp->m_sb.sb_blocklog; + rsb->rsb_sectlog = mp->m_sb.sb_sectlog; + rsb->rsb_rextslog = mp->m_sb.sb_rextslog; + + memcpy(&rsb->rsb_meta_uuid, &mp->m_sb.sb_meta_uuid, + sizeof(rsb->rsb_meta_uuid)); + + *bpp = bp; + return 0; +} + +/* + * Update all the realtime superblocks to match the new state of the primary. + * Because we are completely overwriting all the existing fields in the + * secondary superblock buffers, there is no need to read them in from disk. + * Just get a new buffer, stamp it and write it. + * + * The rt super buffers do not need to be kept them in memory once they are + * written so we mark them as a one-shot buffer. + */ +int +xfs_rtgroup_update_secondary_sbs( + struct xfs_mount *mp) +{ + LIST_HEAD (buffer_list); + struct xfs_rtgroup *rtg; + xfs_rgnumber_t start_rgno = 1; + int saved_error = 0; + int error = 0; + + for_each_rtgroup_from(mp, start_rgno, rtg) { + struct xfs_buf *bp; + + error = xfs_rtgroup_init_secondary_super(mp, rtg->rtg_rgno, + &bp); + /* + * If we get an error reading or writing alternate superblocks, + * continue. If we break early, we'll leave more superblocks + * un-updated than updated. + */ + if (error) { + xfs_warn(mp, + "error allocating secondary superblock for rt group %d", + rtg->rtg_rgno); + if (!saved_error) + saved_error = error; + continue; + } + + xfs_buf_oneshot(bp); + xfs_buf_delwri_queue(bp, &buffer_list); + xfs_buf_relse(bp); + + /* don't hold too many buffers at once */ + if (rtg->rtg_rgno % 16) + continue; + + error = xfs_buf_delwri_submit(&buffer_list); + if (error) { + xfs_warn(mp, + "write error %d updating a secondary superblock near rt group %u", + error, rtg->rtg_rgno); + if (!saved_error) + saved_error = error; + continue; + } + } + error = xfs_buf_delwri_submit(&buffer_list); + if (error) { + xfs_warn(mp, + "write error %d updating a secondary superblock near rt group %u", + error, start_rgno); + } + + return saved_error ? saved_error : error; +} diff --git a/libxfs/xfs_rtgroup.h b/libxfs/xfs_rtgroup.h index c6db6b0d2ae..d8723fabeb5 100644 --- a/libxfs/xfs_rtgroup.h +++ b/libxfs/xfs_rtgroup.h @@ -201,10 +201,12 @@ xfs_rgblock_t xfs_rtgroup_block_count(struct xfs_mount *mp, void xfs_rtgroup_update_super(struct xfs_buf *rtsb_bp, const struct xfs_buf *sb_bp); void xfs_rtgroup_log_super(struct xfs_trans *tp, const struct xfs_buf *sb_bp); +int xfs_rtgroup_update_secondary_sbs(struct xfs_mount *mp); #else # define xfs_rtgroup_block_count(mp, rgno) (0) # define xfs_rtgroup_update_super(bp, sb_bp) ((void)0) # define xfs_rtgroup_log_super(tp, sb_bp) ((void)0) +# define xfs_rtgroup_update_secondary_sbs(mp) (0) #endif /* CONFIG_XFS_RT */ #endif /* __LIBXFS_RTGROUP_H */ From patchwork Fri Dec 30 22:19:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085678 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 30217C4332F for ; Sat, 31 Dec 2022 02:31:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236235AbiLaCbX (ORCPT ); Fri, 30 Dec 2022 21:31:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236141AbiLaCbW (ORCPT ); Fri, 30 Dec 2022 21:31:22 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72FC71CB21 for ; Fri, 30 Dec 2022 18:31:21 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 0FC8161CD4 for ; Sat, 31 Dec 2022 02:31:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7368DC433D2; Sat, 31 Dec 2022 02:31:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453880; bh=lvvbPKaUTmphH/AWq+fhzw327SeeM5MTCtYs736SZvs=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=bL6I+8qUNdMWq0hB/FDt/6Mb32aPOW+pbMRBbM0tgC2NV+mT8xOQCeZoqd9bbj3DV WssImQaKjcoUKsvqQ36RRG1/BoeXx1WAp29l9jP8CBYepmA94jPs+VpotAAGPlVZFC TY+lx8MmOqHW/GoyzdkLNsl5vCqcIIOu5W6DmlDbYFmtVMjTZZcWJsaaL8tQXeznwu 55D4NdX3Dp9W/JTcsDVf81CTAae5GNiH4YQBa3chBDdSs5H5Y7hHQlIvkOxY4kW411 INp496g0hGwR08ReUY8GbRPllf5UijpmiCYIetvn5PuMPSvk/X/E4ZKiZYQcntKfSt Lzw3yRa/J79DQ== Subject: [PATCH 05/45] xfs: grow the realtime section when realtime groups are enabled From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:44 -0800 Message-ID: <167243878432.731133.18391590584377747462.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Enable growing the rt section when realtime groups are enabled. Signed-off-by: Darrick J. Wong --- libxfs/xfs_shared.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libxfs/xfs_shared.h b/libxfs/xfs_shared.h index e76e735b1d0..bcdf298889a 100644 --- a/libxfs/xfs_shared.h +++ b/libxfs/xfs_shared.h @@ -111,6 +111,7 @@ void xfs_log_get_max_trans_res(struct xfs_mount *mp, #define XFS_TRANS_SB_RBLOCKS 0x00000800 #define XFS_TRANS_SB_REXTENTS 0x00001000 #define XFS_TRANS_SB_REXTSLOG 0x00002000 +#define XFS_TRANS_SB_RGCOUNT 0x00004000 /* * Here we centralize the specification of XFS meta-data buffer reference count From patchwork Fri Dec 30 22:19:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085679 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 8A181C4332F for ; Sat, 31 Dec 2022 02:31:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236236AbiLaCbj (ORCPT ); Fri, 30 Dec 2022 21:31:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236141AbiLaCbh (ORCPT ); Fri, 30 Dec 2022 21:31:37 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0222326D9 for ; Fri, 30 Dec 2022 18:31:37 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 9263061D07 for ; Sat, 31 Dec 2022 02:31:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 029D9C433EF; Sat, 31 Dec 2022 02:31:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453896; bh=Kucd/I1s2XDOfv2bkCm+nhzsIDA/wiQxRVD46iVhwNk=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Dcx7352OL/7DuENqwXiJcedHBl0SQ3lFY6R1z3bHEKlNKyK4WwzagRzTUfQvvl27E 1jrdZ4+wXq2JeMYJFPCwNo/nNdMdaylAuf2WDrxbImL5DxL8KfGqy8mUNHToxDT8dS g4Wfred/YC9Lf/nnvQ8u5MCmqyzfxhuAbN49CFxUs/TDb1SUSVy1+9cOkeQQtccKai HODidxBU8CAeZJ3Hf11T9eP5EYyljqqR0CXJL5xWsEO33OCwYpjSO6BI1t7xmE2ecN Vw8ensTM6n7eMxNAXAxlf0P1pQrUiBhruR72tZuOwcq1wCecNcIz0FxfMGKwhxGLZo G/J93ahM2ogLQ== Subject: [PATCH 06/45] xfs: export realtime group geometry via XFS_FSOP_GEOM From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:44 -0800 Message-ID: <167243878445.731133.15326238046958531774.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Export the realtime geometry information so that userspace can query it. Signed-off-by: Darrick J. Wong --- libxfs/xfs_fs.h | 4 +++- libxfs/xfs_sb.c | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h index c4995f6557d..ba90649c54e 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -186,7 +186,9 @@ struct xfs_fsop_geom { __u32 logsunit; /* log stripe unit, bytes */ uint32_t sick; /* o: unhealthy fs & rt metadata */ uint32_t checked; /* o: checked fs & rt metadata */ - __u64 reserved[17]; /* reserved space */ + __u32 rgblocks; /* rtblocks in a realtime group */ + __u32 rgcount; /* number of realtime groups */ + __u64 reserved[16]; /* reserved space */ }; #define XFS_FSOP_GEOM_SICK_COUNTERS (1 << 0) /* summary counters */ diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index 7b8baf64e82..0ba9143e7c5 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -1346,6 +1346,11 @@ xfs_fs_geometry( return; geo->version = XFS_FSOP_GEOM_VERSION_V5; + + if (xfs_has_rtgroups(mp)) { + geo->rgcount = sbp->sb_rgcount; + geo->rgblocks = sbp->sb_rgblocks; + } } /* Read a secondary superblock. */ From patchwork Fri Dec 30 22:19:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085680 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 B72CFC4332F for ; Sat, 31 Dec 2022 02:31:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236237AbiLaCbz (ORCPT ); Fri, 30 Dec 2022 21:31:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236141AbiLaCby (ORCPT ); Fri, 30 Dec 2022 21:31:54 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 047EB26D9 for ; Fri, 30 Dec 2022 18:31:54 -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 BA568B81E74 for ; Sat, 31 Dec 2022 02:31:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7DBEDC433D2; Sat, 31 Dec 2022 02:31:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453911; bh=0LhhCwyee2U3iZxGvjHF3U7N5UMf+OjFv/Ws7WWjwas=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=T9skBGFQdHKU1dDiQliYf0DvFyaNjSNzbRf1D/3adMo/us5F48DeQldQLNi3jQQ1j v9ARwmzaApsqqr7JHkglSpLEQqM799W8bDPakZ1cqqk5dYZjeUjme7mhuleWDXe7LH UMMwvrvqA8wxJsvGYg1lQWqNkfuxUEA4iteJND5SqMfjqkpclIbAsXbGV3joKdG871 jEuRdt2Ukz3rQn6nAHdipqg8mnLsIlzRCG83fhW5yLinV8vo9OybSUFci1y7/iH0Sh StyQyUCISvqFLxW31nqKdvATHHQXiO/VTHEgTFbPV/6m7/gKw7qfq+dEgeCrlW34Vf dpuKe7fyltZMA== Subject: [PATCH 07/45] xfs: check that rtblock extents do not overlap with the rt group metadata From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:44 -0800 Message-ID: <167243878459.731133.6551854440644710834.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong The ondisk format specifies that the start of each realtime group must have a superblock so that rt space mappings never cross an rtgroup boundary. Check that rt block pointers obey this. Signed-off-by: Darrick J. Wong --- libxfs/xfs_types.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_types.c b/libxfs/xfs_types.c index f5eab8839e3..6488cda24e8 100644 --- a/libxfs/xfs_types.c +++ b/libxfs/xfs_types.c @@ -13,6 +13,8 @@ #include "xfs_mount.h" #include "xfs_ag.h" #include "xfs_imeta.h" +#include "xfs_rtbitmap.h" +#include "xfs_rtgroup.h" /* @@ -133,6 +135,26 @@ xfs_verify_dir_ino( return xfs_verify_ino(mp, ino); } +/* + * Verify that an rtgroup block number pointer neither points outside the + * rtgroup nor points at static metadata. + */ +static inline bool +xfs_verify_rgno_rgbno( + struct xfs_mount *mp, + xfs_rgnumber_t rgno, + xfs_rgblock_t rgbno) +{ + xfs_rgblock_t eorg; + + eorg = xfs_rtgroup_block_count(mp, rgno); + if (rgbno >= eorg) + return false; + if (rgbno < mp->m_sb.sb_rextsize) + return false; + return true; +} + /* * Verify that an realtime block number pointer doesn't point off the * end of the realtime device. @@ -142,7 +164,20 @@ xfs_verify_rtbno( struct xfs_mount *mp, xfs_rtblock_t rtbno) { - return rtbno < mp->m_sb.sb_rblocks; + xfs_rgnumber_t rgno; + xfs_rgblock_t rgbno; + + if (rtbno >= mp->m_sb.sb_rblocks) + return false; + + if (!xfs_has_rtgroups(mp)) + return true; + + rgbno = xfs_rtb_to_rgbno(mp, rtbno, &rgno); + if (rgno >= mp->m_sb.sb_rgcount) + return false; + + return xfs_verify_rgno_rgbno(mp, rgno, rgbno); } /* Verify that a realtime device extent is fully contained inside the volume. */ @@ -158,7 +193,14 @@ xfs_verify_rtbext( if (!xfs_verify_rtbno(mp, rtbno)) return false; - return xfs_verify_rtbno(mp, rtbno + len - 1); + if (!xfs_verify_rtbno(mp, rtbno + len - 1)) + return false; + + if (xfs_has_rtgroups(mp) && + xfs_rtb_to_rgno(mp, rtbno) != xfs_rtb_to_rgno(mp, rtbno + len - 1)) + return false; + + return true; } /* Calculate the range of valid icount values. */ From patchwork Fri Dec 30 22:19:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085681 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 22091C4332F for ; Sat, 31 Dec 2022 02:32:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236141AbiLaCcJ (ORCPT ); Fri, 30 Dec 2022 21:32:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236239AbiLaCcI (ORCPT ); Fri, 30 Dec 2022 21:32:08 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 221491CB20 for ; Fri, 30 Dec 2022 18:32:08 -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 dfw.source.kernel.org (Postfix) with ESMTPS id A424161D07 for ; Sat, 31 Dec 2022 02:32:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14CC1C433D2; Sat, 31 Dec 2022 02:32:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453927; bh=HuSGGzrdCiZTtDCZ1Edkzx9ZDoKpG/B9Pxdx4dlnQYE=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=qX40RS1dQFD9dsqtXTPiWg1Eaf1DddOBFQpH+cUW/v97X2dzIdvTUvbLSgi7JqzCI FEoDjIbD6LlbzT/CKlJuWe8CxLy9z7UkC/KgzLPpHBqQK0HEDZZJlhn84ClZ/jFXft UhLNVBPG8bGk8oDsWe3Ea9g227it5gggbFFftbMtBBGSeJEGkFBNfOVnfhMP7lW34B 4DefbCQyVv8vqEjy8jzUsoYHbQOzzYH7UzSmlmuCanJx13lzcKHTabiGgID976Xfvx 6GMbptAKq80rZoKmt73uF3fZiryr5aRlH1LIIWV/7bxBhIOIbKdWBamnZy3OfLT0On Fvcza1qOSDE+g== Subject: [PATCH 08/45] xfs: add frextents to the lazysbcounters when rtgroups enabled From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:44 -0800 Message-ID: <167243878471.731133.13678474783101264607.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Make the free rt extent count a part of the lazy sb counters when the realtime groups feature is enabled. This is possible because the patch to recompute frextents from the rtbitmap during log recovery predates the code adding rtgroup support, hence we know that the value will always be correct during runtime. Signed-off-by: Darrick J. Wong --- include/xfs_mount.h | 1 + libxfs/xfs_sb.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/include/xfs_mount.h b/include/xfs_mount.h index 5987650c639..ed19b15fcb5 100644 --- a/include/xfs_mount.h +++ b/include/xfs_mount.h @@ -28,6 +28,7 @@ typedef struct xfs_mount { #define m_icount m_sb.sb_icount #define m_ifree m_sb.sb_ifree #define m_fdblocks m_sb.sb_fdblocks +#define m_frextents m_sb.sb_frextents spinlock_t m_sb_lock; /* diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index 0ba9143e7c5..1bcffb24761 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -1087,6 +1087,9 @@ xfs_log_sb( * sb counters, despite having a percpu counter. It is always kept * consistent with the ondisk rtbitmap by xfs_trans_apply_sb_deltas() * and hence we don't need have to update it here. + * + * sb_frextents was added to the lazy sb counters when the rt groups + * feature was introduced. */ if (xfs_has_lazysbcount(mp)) { mp->m_sb.sb_icount = percpu_counter_sum(&mp->m_icount); @@ -1095,6 +1098,8 @@ xfs_log_sb( mp->m_sb.sb_icount); mp->m_sb.sb_fdblocks = percpu_counter_sum(&mp->m_fdblocks); } + if (xfs_has_rtgroups(mp)) + mp->m_sb.sb_frextents = percpu_counter_sum(&mp->m_frextents); xfs_sb_to_disk(bp->b_addr, &mp->m_sb); xfs_trans_buf_set_type(tp, bp, XFS_BLFT_SB_BUF); From patchwork Fri Dec 30 22:19:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085682 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 08005C4332F for ; Sat, 31 Dec 2022 02:32:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236238AbiLaCc0 (ORCPT ); Fri, 30 Dec 2022 21:32:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236147AbiLaCcY (ORCPT ); Fri, 30 Dec 2022 21:32:24 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B584926D9 for ; Fri, 30 Dec 2022 18:32:23 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 39DFB61D13 for ; Sat, 31 Dec 2022 02:32:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 966E8C433EF; Sat, 31 Dec 2022 02:32:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453942; bh=shbbnvMwfQ1g2b/x0X5SuRE53P/hf8h7ukqJa0GC7L8=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=FZ+puA8SbyfQqPu13HyEBqAahyHeMwMEc7LvEKW3csosx28WWBrzUtOeR2+JrnjG8 ot9w7IEfNSUcKM0mqLRPJYTlGjJAOYEsSiYvwWYE2fB4vm4XREqFXmf7c08x7+4Wdl SMGTvZP4Nw3KlcnL93HqbHwj+OAXQA0PeUK/t06HOjhzLz3Hb9ykmDR4myVNqBgqUA 0FepSK7sRsQEVHhYfY/m1FxmgQlszE9mWshgifRgMwzeI18x8Iv3mIwHVNIGIDvWBc qLO7n0H5OBYu1rBML4yQKghvQvp68W/4fA/9pf8SdUJjCSXtaALuoSJFD0WYWcgIjP QBBSZtP7bFF/Q== Subject: [PATCH 09/45] xfs: record rt group superblock errors in the health system From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:44 -0800 Message-ID: <167243878482.731133.16012297468628814513.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Record the state of per-rtgroup metadata sickness in the rtgroup structure for later reporting. Signed-off-by: Darrick J. Wong --- libxfs/xfs_health.h | 28 +++++++++++++++++++++++++++- libxfs/xfs_rtgroup.h | 8 ++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_health.h b/libxfs/xfs_health.h index 99d53bae9c1..0beb4153a43 100644 --- a/libxfs/xfs_health.h +++ b/libxfs/xfs_health.h @@ -52,6 +52,7 @@ struct xfs_inode; struct xfs_fsop_geom; struct xfs_btree_cur; struct xfs_da_args; +struct xfs_rtgroup; /* Observable health issues for metadata spanning the entire filesystem. */ #define XFS_SICK_FS_COUNTERS (1 << 0) /* summary counters */ @@ -65,6 +66,7 @@ struct xfs_da_args; /* Observable health issues for realtime volume metadata. */ #define XFS_SICK_RT_BITMAP (1 << 0) /* realtime bitmap */ #define XFS_SICK_RT_SUMMARY (1 << 1) /* realtime summary */ +#define XFS_SICK_RT_SUPER (1 << 2) /* rt group superblock */ /* Observable health issues for AG metadata. */ #define XFS_SICK_AG_SB (1 << 0) /* superblock */ @@ -101,7 +103,8 @@ struct xfs_da_args; XFS_SICK_FS_METADIR) #define XFS_SICK_RT_PRIMARY (XFS_SICK_RT_BITMAP | \ - XFS_SICK_RT_SUMMARY) + XFS_SICK_RT_SUMMARY | \ + XFS_SICK_RT_SUPER) #define XFS_SICK_AG_PRIMARY (XFS_SICK_AG_SB | \ XFS_SICK_AG_AGF | \ @@ -176,6 +179,14 @@ void xfs_rt_mark_healthy(struct xfs_mount *mp, unsigned int mask); void xfs_rt_measure_sickness(struct xfs_mount *mp, unsigned int *sick, unsigned int *checked); +void xfs_rgno_mark_sick(struct xfs_mount *mp, xfs_rgnumber_t rgno, + unsigned int mask); +void xfs_rtgroup_mark_sick(struct xfs_rtgroup *rtg, unsigned int mask); +void xfs_rtgroup_mark_checked(struct xfs_rtgroup *rtg, unsigned int mask); +void xfs_rtgroup_mark_healthy(struct xfs_rtgroup *rtg, unsigned int mask); +void xfs_rtgroup_measure_sickness(struct xfs_rtgroup *rtg, unsigned int *sick, + unsigned int *checked); + void xfs_agno_mark_sick(struct xfs_mount *mp, xfs_agnumber_t agno, unsigned int mask); void xfs_ag_mark_sick(struct xfs_perag *pag, unsigned int mask); @@ -225,6 +236,15 @@ xfs_ag_has_sickness(struct xfs_perag *pag, unsigned int mask) return sick & mask; } +static inline bool +xfs_rtgroup_has_sickness(struct xfs_rtgroup *rtg, unsigned int mask) +{ + unsigned int sick, checked; + + xfs_rtgroup_measure_sickness(rtg, &sick, &checked); + return sick & mask; +} + static inline bool xfs_inode_has_sickness(struct xfs_inode *ip, unsigned int mask) { @@ -246,6 +266,12 @@ xfs_rt_is_healthy(struct xfs_mount *mp) return !xfs_rt_has_sickness(mp, -1U); } +static inline bool +xfs_rtgroup_is_healthy(struct xfs_rtgroup *rtg) +{ + return !xfs_rtgroup_has_sickness(rtg, -1U); +} + static inline bool xfs_ag_is_healthy(struct xfs_perag *pag) { diff --git a/libxfs/xfs_rtgroup.h b/libxfs/xfs_rtgroup.h index d8723fabeb5..0e664e2436b 100644 --- a/libxfs/xfs_rtgroup.h +++ b/libxfs/xfs_rtgroup.h @@ -23,6 +23,14 @@ struct xfs_rtgroup { /* Number of blocks in this group */ xfs_rgblock_t rtg_blockcount; + /* + * Bitsets of per-rtgroup metadata that have been checked and/or are + * sick. Callers should hold rtg_state_lock before accessing this + * field. + */ + uint16_t rtg_checked; + uint16_t rtg_sick; + #ifdef __KERNEL__ /* -- kernel only structures below this line -- */ spinlock_t rtg_state_lock; From patchwork Fri Dec 30 22:19:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085683 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 8FA93C4332F for ; Sat, 31 Dec 2022 02:32:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236239AbiLaCcn (ORCPT ); Fri, 30 Dec 2022 21:32:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236147AbiLaCcl (ORCPT ); Fri, 30 Dec 2022 21:32:41 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB42C26D9 for ; Fri, 30 Dec 2022 18:32:40 -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 84B8AB81E74 for ; Sat, 31 Dec 2022 02:32:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37774C433EF; Sat, 31 Dec 2022 02:32:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453958; bh=ZPHwu4sl0M1rgDOeYimx1hAB5SYMdIDjc0j2UnUJ3iM=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=XancCbBi6mXVw1/g8+BUEa+OFwtRAVt6anNUFcs/WocXjz+IV3WPK0dKCPtOaiCiq 9YpbdHDvfz4LWkRIw7iV6GR23uO9h9hu20JEOVhhrO4+EffrKfgEh+q/WSjfeeL2Ex 5zww8x/5EsxNdUrqKO4him4IZe/GA45SaDGlsNqGwETJJHDplLlcXzn3MhZcMFSiq8 lHT2otix3jvY2MPMzEPRddw4FksJFEixch/HbPXHcJKhLnVACGox9KL7w0uppsXUhD BudR9/CYr9UbWH8YEJqWQDvq4ooNadGkiwjgrmZFD+gsNC7ZZMRx1j1tA+qxfb1tlC 1JUV/vU2e6S/Q== Subject: [PATCH 10/45] xfs: define locking primitives for realtime groups From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:44 -0800 Message-ID: <167243878495.731133.7722543578089824290.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Define helper functions to lock all metadata inodes related to a realtime group. There's not much to look at now, but this will become important when we add per-rtgroup metadata files and online fsck code for them. Signed-off-by: Darrick J. Wong --- libxfs/xfs_rtgroup.c | 33 +++++++++++++++++++++++++++++++++ libxfs/xfs_rtgroup.h | 14 ++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/libxfs/xfs_rtgroup.c b/libxfs/xfs_rtgroup.c index 9caf39fd51a..86751cb8d31 100644 --- a/libxfs/xfs_rtgroup.c +++ b/libxfs/xfs_rtgroup.c @@ -496,3 +496,36 @@ xfs_rtgroup_update_secondary_sbs( return saved_error ? saved_error : error; } + +/* Lock metadata inodes associated with this rt group. */ +void +xfs_rtgroup_lock( + struct xfs_trans *tp, + struct xfs_rtgroup *rtg, + unsigned int rtglock_flags) +{ + ASSERT(!(rtglock_flags & ~XFS_RTGLOCK_ALL_FLAGS)); + ASSERT(!(rtglock_flags & XFS_RTGLOCK_BITMAP_SHARED) || + !(rtglock_flags & XFS_RTGLOCK_BITMAP)); + + if (rtglock_flags & XFS_RTGLOCK_BITMAP) + xfs_rtbitmap_lock(tp, rtg->rtg_mount); + else if (rtglock_flags & XFS_RTGLOCK_BITMAP_SHARED) + xfs_rtbitmap_lock_shared(rtg->rtg_mount, XFS_RBMLOCK_BITMAP); +} + +/* Unlock metadata inodes associated with this rt group. */ +void +xfs_rtgroup_unlock( + struct xfs_rtgroup *rtg, + unsigned int rtglock_flags) +{ + ASSERT(!(rtglock_flags & ~XFS_RTGLOCK_ALL_FLAGS)); + ASSERT(!(rtglock_flags & XFS_RTGLOCK_BITMAP_SHARED) || + !(rtglock_flags & XFS_RTGLOCK_BITMAP)); + + if (rtglock_flags & XFS_RTGLOCK_BITMAP) + xfs_rtbitmap_unlock(rtg->rtg_mount); + else if (rtglock_flags & XFS_RTGLOCK_BITMAP_SHARED) + xfs_rtbitmap_unlock_shared(rtg->rtg_mount, XFS_RBMLOCK_BITMAP); +} diff --git a/libxfs/xfs_rtgroup.h b/libxfs/xfs_rtgroup.h index 0e664e2436b..b1e53af5a65 100644 --- a/libxfs/xfs_rtgroup.h +++ b/libxfs/xfs_rtgroup.h @@ -210,11 +210,25 @@ void xfs_rtgroup_update_super(struct xfs_buf *rtsb_bp, const struct xfs_buf *sb_bp); void xfs_rtgroup_log_super(struct xfs_trans *tp, const struct xfs_buf *sb_bp); int xfs_rtgroup_update_secondary_sbs(struct xfs_mount *mp); + +/* Lock the rt bitmap inode in exclusive mode */ +#define XFS_RTGLOCK_BITMAP (1U << 0) +/* Lock the rt bitmap inode in shared mode */ +#define XFS_RTGLOCK_BITMAP_SHARED (1U << 1) + +#define XFS_RTGLOCK_ALL_FLAGS (XFS_RTGLOCK_BITMAP | \ + XFS_RTGLOCK_BITMAP_SHARED) + +void xfs_rtgroup_lock(struct xfs_trans *tp, struct xfs_rtgroup *rtg, + unsigned int rtglock_flags); +void xfs_rtgroup_unlock(struct xfs_rtgroup *rtg, unsigned int rtglock_flags); #else # define xfs_rtgroup_block_count(mp, rgno) (0) # define xfs_rtgroup_update_super(bp, sb_bp) ((void)0) # define xfs_rtgroup_log_super(tp, sb_bp) ((void)0) # define xfs_rtgroup_update_secondary_sbs(mp) (0) +# define xfs_rtgroup_lock(tp, rtg, gf) ((void)0) +# define xfs_rtgroup_unlock(rtg, gf) ((void)0) #endif /* CONFIG_XFS_RT */ #endif /* __LIBXFS_RTGROUP_H */ From patchwork Fri Dec 30 22:19:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085684 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 0E288C4332F for ; Sat, 31 Dec 2022 02:32:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236240AbiLaCc5 (ORCPT ); Fri, 30 Dec 2022 21:32:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236147AbiLaCc5 (ORCPT ); Fri, 30 Dec 2022 21:32:57 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4084D26D9 for ; Fri, 30 Dec 2022 18:32:56 -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 02BB0B81C22 for ; Sat, 31 Dec 2022 02:32:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5D28C433D2; Sat, 31 Dec 2022 02:32:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453973; bh=oxBAP3OPMPA5cfi9ab+wTSvN+iHHUMoDffjO98jW2oo=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=RwzpuOxp5ICtruljzbFRGulDp+eWcHMrsZJBdlZ3hyRjBUzrwOhQKEUA+90bkcEMj 3Sz9QM5ujKo1/swRgTott8OqO5ug4uF16jYDqIQ8V/OE0mThO9E2qUQ6pJh56YX8sv LyjfcKYgmWnyIi7Kj44dXhHgUSK9hwM5MlBEclPfbB4Wr0a/tG5ayCjQlOCpc1kS7S ltWNZ6E31bZvo3rSVmIcFh/f5aVLpsOiicXgMS6HJpkpBypttCYwpQ2+TMLNc29rq+ f19GlCdP4MUeZwuRjXa+x9ExraI5fXixLprr8dyJOU5d950ohWvYZygAmcoSciar+t rUshpw+ptXkEQ== Subject: [PATCH 11/45] xfs: export the geometry of realtime groups to userspace From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:45 -0800 Message-ID: <167243878509.731133.10626383770835296737.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Create an ioctl so that the kernel can report the status of realtime groups to userspace. Signed-off-by: Darrick J. Wong --- libxfs/util.c | 7 +++++++ libxfs/xfs_fs.h | 16 ++++++++++++++++ libxfs/xfs_health.h | 2 ++ libxfs/xfs_rtgroup.c | 14 ++++++++++++++ libxfs/xfs_rtgroup.h | 4 ++++ 5 files changed, 43 insertions(+) diff --git a/libxfs/util.c b/libxfs/util.c index 7b16d30b754..e8397fdc341 100644 --- a/libxfs/util.c +++ b/libxfs/util.c @@ -444,6 +444,13 @@ xfs_fs_mark_healthy( } void xfs_ag_geom_health(struct xfs_perag *pag, struct xfs_ag_geometry *ageo) { } +void +xfs_rtgroup_geom_health( + struct xfs_rtgroup *rtg, + struct xfs_rtgroup_geometry *rgeo) +{ + /* empty */ +} void xfs_fs_mark_sick(struct xfs_mount *mp, unsigned int mask) { } void xfs_agno_mark_sick(struct xfs_mount *mp, xfs_agnumber_t agno, unsigned int mask) { } diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h index ba90649c54e..e3d87665e4a 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -299,6 +299,21 @@ struct xfs_ag_geometry { #define XFS_AG_GEOM_SICK_REFCNTBT (1 << 9) /* reference counts */ #define XFS_AG_GEOM_SICK_INODES (1 << 10) /* bad inodes were seen */ +/* + * Output for XFS_IOC_RTGROUP_GEOMETRY + */ +struct xfs_rtgroup_geometry { + uint32_t rg_number; /* i/o: rtgroup number */ + uint32_t rg_length; /* o: length in blocks */ + uint32_t rg_sick; /* o: sick things in ag */ + uint32_t rg_checked; /* o: checked metadata in ag */ + uint32_t rg_flags; /* i/o: flags for this ag */ + uint32_t rg_pad; /* o: zero */ + uint64_t rg_reserved[13];/* o: zero */ +}; +#define XFS_RTGROUP_GEOM_SICK_SUPER (1 << 0) /* superblock */ +#define XFS_RTGROUP_GEOM_SICK_BITMAP (1 << 1) /* rtbitmap for this group */ + /* * Structures for XFS_IOC_FSGROWFSDATA, XFS_IOC_FSGROWFSLOG & XFS_IOC_FSGROWFSRT */ @@ -819,6 +834,7 @@ struct xfs_scrub_metadata { /* XFS_IOC_GETFSMAP ------ hoisted 59 */ #define XFS_IOC_SCRUB_METADATA _IOWR('X', 60, struct xfs_scrub_metadata) #define XFS_IOC_AG_GEOMETRY _IOWR('X', 61, struct xfs_ag_geometry) +#define XFS_IOC_RTGROUP_GEOMETRY _IOWR('X', 62, struct xfs_rtgroup_geometry) /* * ioctl commands that replace IRIX syssgi()'s diff --git a/libxfs/xfs_health.h b/libxfs/xfs_health.h index 0beb4153a43..44137c4983f 100644 --- a/libxfs/xfs_health.h +++ b/libxfs/xfs_health.h @@ -286,6 +286,8 @@ xfs_inode_is_healthy(struct xfs_inode *ip) void xfs_fsop_geom_health(struct xfs_mount *mp, struct xfs_fsop_geom *geo); void xfs_ag_geom_health(struct xfs_perag *pag, struct xfs_ag_geometry *ageo); +void xfs_rtgroup_geom_health(struct xfs_rtgroup *rtg, + struct xfs_rtgroup_geometry *rgeo); void xfs_bulkstat_health(struct xfs_inode *ip, struct xfs_bulkstat *bs); #define xfs_metadata_is_sick(error) \ diff --git a/libxfs/xfs_rtgroup.c b/libxfs/xfs_rtgroup.c index 86751cb8d31..ebbd0d13a8a 100644 --- a/libxfs/xfs_rtgroup.c +++ b/libxfs/xfs_rtgroup.c @@ -529,3 +529,17 @@ xfs_rtgroup_unlock( else if (rtglock_flags & XFS_RTGLOCK_BITMAP_SHARED) xfs_rtbitmap_unlock_shared(rtg->rtg_mount, XFS_RBMLOCK_BITMAP); } + +/* Retrieve rt group geometry. */ +int +xfs_rtgroup_get_geometry( + struct xfs_rtgroup *rtg, + struct xfs_rtgroup_geometry *rgeo) +{ + /* Fill out form. */ + memset(rgeo, 0, sizeof(*rgeo)); + rgeo->rg_number = rtg->rtg_rgno; + rgeo->rg_length = rtg->rtg_blockcount; + xfs_rtgroup_geom_health(rtg, rgeo); + return 0; +} diff --git a/libxfs/xfs_rtgroup.h b/libxfs/xfs_rtgroup.h index b1e53af5a65..1fec49c496d 100644 --- a/libxfs/xfs_rtgroup.h +++ b/libxfs/xfs_rtgroup.h @@ -222,6 +222,9 @@ int xfs_rtgroup_update_secondary_sbs(struct xfs_mount *mp); void xfs_rtgroup_lock(struct xfs_trans *tp, struct xfs_rtgroup *rtg, unsigned int rtglock_flags); void xfs_rtgroup_unlock(struct xfs_rtgroup *rtg, unsigned int rtglock_flags); + +int xfs_rtgroup_get_geometry(struct xfs_rtgroup *rtg, + struct xfs_rtgroup_geometry *rgeo); #else # define xfs_rtgroup_block_count(mp, rgno) (0) # define xfs_rtgroup_update_super(bp, sb_bp) ((void)0) @@ -229,6 +232,7 @@ void xfs_rtgroup_unlock(struct xfs_rtgroup *rtg, unsigned int rtglock_flags); # define xfs_rtgroup_update_secondary_sbs(mp) (0) # define xfs_rtgroup_lock(tp, rtg, gf) ((void)0) # define xfs_rtgroup_unlock(rtg, gf) ((void)0) +# define xfs_rtgroup_get_geometry(rtg, rgeo) (-EOPNOTSUPP) #endif /* CONFIG_XFS_RT */ #endif /* __LIBXFS_RTGROUP_H */ From patchwork Fri Dec 30 22:19:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085685 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 CDC4FC4332F for ; Sat, 31 Dec 2022 02:33:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236241AbiLaCdM (ORCPT ); Fri, 30 Dec 2022 21:33:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236147AbiLaCdL (ORCPT ); Fri, 30 Dec 2022 21:33:11 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AC0426D9 for ; Fri, 30 Dec 2022 18:33:10 -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 dfw.source.kernel.org (Postfix) with ESMTPS id DD8F861D12 for ; Sat, 31 Dec 2022 02:33:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43431C433EF; Sat, 31 Dec 2022 02:33:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453989; bh=CACEG00g6GqQTFzjjpwlDX9faRW2vViRojHtq4YPNkY=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=UJ5+xdbZvOCcef/S7FZ/x0zg6ufvfbQmaG+4ZZr1nK6c7N885OK5rXl09MMJLsB1P reRkpAmVBfr7KI9IMOiUd85UTnUu9XinsYdeLPz9oMAqWe2KIuadB2VdbRdNzGV+wG jLx2/SqOI9/QYEZfOvqtGI00jg5tppc8YBo1uN4Nz4OYXsofUMKmnmVP7jPrBAhYws 3aJqwrPx8n0EC6HSkNjMPigiu2eCCR/0gqvDKXVAJ/FOYS3FsxfalRKpfCC3fiIQ8l ngDtNltXUwW/GdEhmP6X/FrVeKb1B3cQI57dwh+TL9UUY30/41qnA6KDR7vD75jSeJ bVjgwosU6HyVA== Subject: [PATCH 12/45] xfs: add block headers to realtime bitmap blocks From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:45 -0800 Message-ID: <167243878522.731133.693459915401734066.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Upgrade rtbitmap blocks to have self describing metadata like most every other thing in XFS. Signed-off-by: Darrick J. Wong --- include/xfs_mount.h | 3 +- libxfs/xfs_format.h | 14 +++++++ libxfs/xfs_rtbitmap.c | 98 +++++++++++++++++++++++++++++++++++++++++++++---- libxfs/xfs_rtbitmap.h | 30 +++++++++++++++ libxfs/xfs_sb.c | 18 +++++++-- libxfs/xfs_shared.h | 1 + 6 files changed, 149 insertions(+), 15 deletions(-) diff --git a/include/xfs_mount.h b/include/xfs_mount.h index ed19b15fcb5..040e594f721 100644 --- a/include/xfs_mount.h +++ b/include/xfs_mount.h @@ -72,7 +72,8 @@ typedef struct xfs_mount { int8_t m_rgblklog; /* log2 of rt group sz if possible */ uint m_blockmask; /* sb_blocksize-1 */ uint m_blockwsize; /* sb_blocksize in words */ - uint m_blockwmask; /* blockwsize-1 */ + /* number of rt extents per rt bitmap block if rtgroups enabled */ + unsigned int m_rtx_per_rbmblock; uint m_alloc_mxr[2]; /* XFS_ALLOC_BLOCK_MAXRECS */ uint m_alloc_mnr[2]; /* XFS_ALLOC_BLOCK_MINRECS */ uint m_bmap_dmxr[2]; /* XFS_BMAP_BLOCK_DMAXRECS */ diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index a38e1499bd4..4096d3f069a 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -1284,6 +1284,20 @@ static inline bool xfs_dinode_has_large_extent_counts( /* * RT bit manipulation macros. */ +#define XFS_RTBITMAP_MAGIC 0x424D505A /* BMPZ */ + +struct xfs_rtbuf_blkinfo { + __be32 rt_magic; /* validity check on block */ + __be32 rt_crc; /* CRC of block */ + __be64 rt_owner; /* inode that owns the block */ + __be64 rt_blkno; /* first block of the buffer */ + __be64 rt_lsn; /* sequence number of last write */ + uuid_t rt_uuid; /* filesystem we belong to */ +}; + +#define XFS_RTBUF_CRC_OFF \ + offsetof(struct xfs_rtbuf_blkinfo, rt_crc) + #define XFS_RTMIN(a,b) ((a) < (b) ? (a) : (b)) #define XFS_RTMAX(a,b) ((a) > (b) ? (a) : (b)) diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c index 5d402b250c8..2e286a22196 100644 --- a/libxfs/xfs_rtbitmap.c +++ b/libxfs/xfs_rtbitmap.c @@ -21,23 +21,77 @@ * Realtime allocator bitmap functions shared with userspace. */ -/* - * Real time buffers need verifiers to avoid runtime warnings during IO. - * We don't have anything to verify, however, so these are just dummy - * operations. - */ +static xfs_failaddr_t +xfs_rtbuf_verify( + struct xfs_buf *bp) +{ + struct xfs_mount *mp = bp->b_mount; + struct xfs_rtbuf_blkinfo *hdr = bp->b_addr; + + if (!xfs_verify_magic(bp, hdr->rt_magic)) + return __this_address; + if (!xfs_has_rtgroups(mp)) + return __this_address; + if (!xfs_has_crc(mp)) + return __this_address; + if (!uuid_equal(&hdr->rt_uuid, &mp->m_sb.sb_meta_uuid)) + return __this_address; + if (hdr->rt_blkno != cpu_to_be64(xfs_buf_daddr(bp))) + return __this_address; + return NULL; +} + static void xfs_rtbuf_verify_read( - struct xfs_buf *bp) + struct xfs_buf *bp) { + struct xfs_mount *mp = bp->b_mount; + struct xfs_rtbuf_blkinfo *hdr = bp->b_addr; + xfs_failaddr_t fa; + + if (!xfs_has_rtgroups(mp) || bp->b_ops != &xfs_rtbitmap_buf_ops) + return; + + if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr->rt_lsn))) { + fa = __this_address; + goto fail; + } + + if (!xfs_buf_verify_cksum(bp, XFS_RTBUF_CRC_OFF)) { + fa = __this_address; + goto fail; + } + + fa = xfs_rtbuf_verify(bp); + if (fa) + goto fail; + return; +fail: + xfs_verifier_error(bp, -EFSCORRUPTED, fa); } static void xfs_rtbuf_verify_write( struct xfs_buf *bp) { - return; + struct xfs_mount *mp = bp->b_mount; + struct xfs_rtbuf_blkinfo *hdr = bp->b_addr; + struct xfs_buf_log_item *bip = bp->b_log_item; + xfs_failaddr_t fa; + + if (!xfs_has_rtgroups(mp) || bp->b_ops != &xfs_rtbitmap_buf_ops) + return; + + fa = xfs_rtbuf_verify(bp); + if (fa) { + xfs_verifier_error(bp, -EFSCORRUPTED, fa); + return; + } + + if (bip) + hdr->rt_lsn = cpu_to_be64(bip->bli_item.li_lsn); + xfs_buf_update_cksum(bp, XFS_RTBUF_CRC_OFF); } const struct xfs_buf_ops xfs_rtbuf_ops = { @@ -46,6 +100,14 @@ const struct xfs_buf_ops xfs_rtbuf_ops = { .verify_write = xfs_rtbuf_verify_write, }; +const struct xfs_buf_ops xfs_rtbitmap_buf_ops = { + .name = "xfs_rtbitmap", + .magic = { 0, cpu_to_be32(XFS_RTBITMAP_MAGIC) }, + .verify_read = xfs_rtbuf_verify_read, + .verify_write = xfs_rtbuf_verify_write, + .verify_struct = xfs_rtbuf_verify, +}; + /* * Get a buffer for the bitmap or summary file block specified. * The buffer is returned read and locked. @@ -79,13 +141,26 @@ xfs_rtbuf_get( ASSERT(map.br_startblock != NULLFSBLOCK); error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, XFS_FSB_TO_DADDR(mp, map.br_startblock), - mp->m_bsize, 0, &bp, &xfs_rtbuf_ops); + mp->m_bsize, 0, &bp, + xfs_rtblock_ops(mp, issum)); if (xfs_metadata_is_sick(error)) xfs_rt_mark_sick(mp, issum ? XFS_SICK_RT_SUMMARY : XFS_SICK_RT_BITMAP); if (error) return error; + if (xfs_has_rtgroups(mp) && !issum) { + struct xfs_rtbuf_blkinfo *hdr = bp->b_addr; + + if (hdr->rt_owner != cpu_to_be64(ip->i_ino)) { + xfs_buf_mark_corrupt(bp); + xfs_trans_brelse(tp, bp); + xfs_rt_mark_sick(mp, issum ? XFS_SICK_RT_SUMMARY : + XFS_SICK_RT_BITMAP); + return -EFSCORRUPTED; + } + } + xfs_trans_buf_set_type(tp, bp, issum ? XFS_BLFT_RTSUMMARY_BUF : XFS_BLFT_RTBITMAP_BUF); *bpp = bp; @@ -1203,7 +1278,12 @@ xfs_rtbitmap_blockcount( struct xfs_mount *mp, xfs_rtbxlen_t rtextents) { - return howmany_64(rtextents, NBBY * mp->m_sb.sb_blocksize); + unsigned int rbmblock_bytes = mp->m_sb.sb_blocksize; + + if (xfs_has_rtgroups(mp)) + rbmblock_bytes -= sizeof(struct xfs_rtbuf_blkinfo); + + return howmany_64(rtextents, NBBY * rbmblock_bytes); } /* diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h index f6a2a48973a..c1f740fd27b 100644 --- a/libxfs/xfs_rtbitmap.h +++ b/libxfs/xfs_rtbitmap.h @@ -100,6 +100,9 @@ xfs_rtx_to_rbmblock( struct xfs_mount *mp, xfs_rtxnum_t rtx) { + if (xfs_has_rtgroups(mp)) + return div_u64(rtx, mp->m_rtx_per_rbmblock); + return rtx >> mp->m_blkbit_log; } @@ -109,6 +112,13 @@ xfs_rtx_to_rbmword( struct xfs_mount *mp, xfs_rtxnum_t rtx) { + if (xfs_has_rtgroups(mp)) { + unsigned int mod; + + div_u64_rem(rtx >> XFS_NBWORDLOG, mp->m_blockwsize, &mod); + return mod; + } + return (rtx >> XFS_NBWORDLOG) & (mp->m_blockwsize - 1); } @@ -118,16 +128,24 @@ xfs_rbmblock_to_rtx( struct xfs_mount *mp, xfs_fileoff_t rbmoff) { + if (xfs_has_rtgroups(mp)) + return rbmoff * mp->m_rtx_per_rbmblock; + return rbmoff << mp->m_blkbit_log; } /* Return a pointer to a bitmap word within a rt bitmap block buffer. */ static inline union xfs_rtword_ondisk * xfs_rbmbuf_wordptr( + struct xfs_mount *mp, void *buf, unsigned int rbmword) { union xfs_rtword_ondisk *wordp = buf; + struct xfs_rtbuf_blkinfo *hdr = buf; + + if (xfs_has_rtgroups(mp)) + wordp = (union xfs_rtword_ondisk *)(hdr + 1); return &wordp[rbmword]; } @@ -138,7 +156,7 @@ xfs_rbmblock_wordptr( struct xfs_buf *bp, unsigned int rbmword) { - return xfs_rbmbuf_wordptr(bp->b_addr, rbmword); + return xfs_rbmbuf_wordptr(bp->b_mount, bp->b_addr, rbmword); } /* @@ -200,6 +218,16 @@ xfs_rsumblock_infoptr( return xfs_rsumbuf_infoptr(bp->b_addr, infoword); } +static inline const struct xfs_buf_ops * +xfs_rtblock_ops( + struct xfs_mount *mp, + bool issum) +{ + if (xfs_has_rtgroups(mp) && !issum) + return &xfs_rtbitmap_buf_ops; + return &xfs_rtbuf_ops; +} + /* * Functions for walking free space rtextents in the realtime bitmap. */ diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index 1bcffb24761..94dc93ed5dc 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -516,10 +516,15 @@ xfs_validate_sb_common( } else { uint64_t rexts; uint64_t rbmblocks; + unsigned int rbmblock_bytes = sbp->sb_blocksize; rexts = div_u64(sbp->sb_rblocks, sbp->sb_rextsize); - rbmblocks = howmany_64(sbp->sb_rextents, - NBBY * sbp->sb_blocksize); + + if (xfs_sb_is_v5(sbp) && + (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_RTGROUPS)) + rbmblock_bytes -= sizeof(struct xfs_rtbuf_blkinfo); + + rbmblocks = howmany_64(sbp->sb_rextents, NBBY * rbmblock_bytes); if (sbp->sb_rextents != rexts || sbp->sb_rextslog != xfs_highbit32(sbp->sb_rextents) || @@ -1030,8 +1035,13 @@ xfs_sb_mount_common( mp->m_sectbb_log = sbp->sb_sectlog - BBSHIFT; mp->m_agno_log = xfs_highbit32(sbp->sb_agcount - 1) + 1; mp->m_blockmask = sbp->sb_blocksize - 1; - mp->m_blockwsize = sbp->sb_blocksize >> XFS_WORDLOG; - mp->m_blockwmask = mp->m_blockwsize - 1; + if (xfs_has_rtgroups(mp)) + mp->m_blockwsize = (sbp->sb_blocksize - + sizeof(struct xfs_rtbuf_blkinfo)) >> + XFS_WORDLOG; + else + mp->m_blockwsize = sbp->sb_blocksize >> XFS_WORDLOG; + mp->m_rtx_per_rbmblock = mp->m_blockwsize << XFS_NBWORDLOG; mp->m_rtxblklog = log2_if_power2(sbp->sb_rextsize); mp->m_rtxblkmask = mask64_if_power2(sbp->sb_rextsize); mp->m_rgblklog = log2_if_power2(sbp->sb_rgblocks); diff --git a/libxfs/xfs_shared.h b/libxfs/xfs_shared.h index bcdf298889a..1c86163915c 100644 --- a/libxfs/xfs_shared.h +++ b/libxfs/xfs_shared.h @@ -38,6 +38,7 @@ extern const struct xfs_buf_ops xfs_inode_buf_ops; extern const struct xfs_buf_ops xfs_inode_buf_ra_ops; extern const struct xfs_buf_ops xfs_refcountbt_buf_ops; extern const struct xfs_buf_ops xfs_rmapbt_buf_ops; +extern const struct xfs_buf_ops xfs_rtbitmap_buf_ops; extern const struct xfs_buf_ops xfs_rtbuf_ops; extern const struct xfs_buf_ops xfs_rtsb_buf_ops; extern const struct xfs_buf_ops xfs_sb_buf_ops; From patchwork Fri Dec 30 22:19:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085686 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 4CA99C4332F for ; Sat, 31 Dec 2022 02:33:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236242AbiLaCd3 (ORCPT ); Fri, 30 Dec 2022 21:33:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236147AbiLaCd2 (ORCPT ); Fri, 30 Dec 2022 21:33:28 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CE0826D9 for ; Fri, 30 Dec 2022 18:33:27 -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 28F0DB81DED for ; Sat, 31 Dec 2022 02:33:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1E6AC433EF; Sat, 31 Dec 2022 02:33:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454004; bh=imQubqf5SzMIgHdaO6aurOCUQ48rVrg+xQI1QA8Lkx8=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=BFwme/sDNtit5GiHzLDCGJCM3wqKYBtetVacrhdRzojLdZ5+mOo4BKOmHDumIyejn aeDtkQpO3eWFL80g+eowNwtbP9i9PbKFjPHCBH9ALUSZe6UvnaxFAeR4+a0SwkeowQ YQmCwz4/I2zLF93SqaqrGn0wqITO19uJgb76WyFE613jPFgqoY3W94ztEdLBimUY8I ENtbDD+lknSJoWU039h2o3tcEQwoKgitbeR0VrCfv6kUVmRHjHav4IzFve5dXzljFc 3Ne9tZ2x2+qa5RhrZhTKVZRZbpl+2xJBiP5Q0Q5lt8iQ46znhTAVPu6SnLnspl2fqy 9kzuO+qs4xqZA== Subject: [PATCH 13/45] xfs: encode the rtbitmap in little endian format From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:45 -0800 Message-ID: <167243878535.731133.10030127003706643947.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Currently, the ondisk realtime bitmap file is accessed in units of 32-bit words. There's no endian translation of the contents of this file, which means that the Bad Things Happen(tm) if you go from (say) x86 to powerpc. Since we have a new feature flag, let's take the opportunity to enforce an endianness on the file. The natural format of a bitmap is (IMHO) little endian, because the byte offsets of the bitmap data should always increase in step with the information being indexed. Signed-off-by: Darrick J. Wong --- libxfs/xfs_format.h | 4 +++- libxfs/xfs_rtbitmap.c | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index 4096d3f069a..c7752aaa447 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -738,10 +738,12 @@ struct xfs_agfl { /* * Realtime bitmap information is accessed by the word, which is currently - * stored in host-endian format. + * stored in host-endian format. Starting with the realtime groups feature, + * the words are stored in le32 ondisk. */ union xfs_rtword_ondisk { __u32 raw; + __le32 rtg; }; /* diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c index 2e286a22196..db80f740151 100644 --- a/libxfs/xfs_rtbitmap.c +++ b/libxfs/xfs_rtbitmap.c @@ -173,6 +173,9 @@ xfs_rtbitmap_getword( struct xfs_mount *mp, union xfs_rtword_ondisk *wordptr) { + if (xfs_has_rtgroups(mp)) + return le32_to_cpu(wordptr->rtg); + return wordptr->raw; } @@ -183,7 +186,10 @@ xfs_rtbitmap_setword( union xfs_rtword_ondisk *wordptr, xfs_rtword_t incore) { - wordptr->raw = incore; + if (xfs_has_rtgroups(mp)) + wordptr->rtg = cpu_to_le32(incore); + else + wordptr->raw = incore; } /* From patchwork Fri Dec 30 22:19:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085687 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 876D0C4332F for ; Sat, 31 Dec 2022 02:33:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236147AbiLaCdp (ORCPT ); Fri, 30 Dec 2022 21:33:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236248AbiLaCdn (ORCPT ); Fri, 30 Dec 2022 21:33:43 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEBFD1CB1F for ; Fri, 30 Dec 2022 18:33:42 -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 97F67B81C22 for ; Sat, 31 Dec 2022 02:33:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E2AFC433D2; Sat, 31 Dec 2022 02:33:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454020; bh=yoRJUmyHT3mlr6KKAbAAV9kDUeAV4fmkSljR3RaJH/g=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=qC7eD4jjSki7iEz+6Ep6uuPrDsRx4DvRmK2wIFWD4yERBR6Ui8Xe64BFMCTl4CTyc Ey133k3TPbf77YhTNzC9PdXGhxgjDPREsv+vbNuMeyTVu2sMBk/Q45qyvX+TQDpSsE H2YsukZHCV6LfIaOqLqgw+3GQDlnWK1UuFqCE8gILO0WX+GlQVvNYnhhJBUwzWN6ph thJcTwjmDEJS9tsjOQk/Zc4HxiNe2FAc4y/VHQGvvHwJ879WriwHtjEzdrjUbjhWqY gqcyTCLYbDY2+vze7lDSuTwOybyJInE5Wk+496KHplBm6aIG/7Xa8/m2C5GY5K5GeK wzia4Ojq4La0w== Subject: [PATCH 14/45] xfs: add block headers to realtime summary blocks From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:45 -0800 Message-ID: <167243878549.731133.11237553640942198037.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Upgrade rtsummary blocks to have self describing metadata like most every other thing in XFS. Signed-off-by: Darrick J. Wong --- libxfs/xfs_format.h | 1 + libxfs/xfs_rtbitmap.c | 18 +++++++++++++++--- libxfs/xfs_rtbitmap.h | 18 ++++++++++++++++-- libxfs/xfs_shared.h | 1 + 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index c7752aaa447..47b2e31e256 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -1287,6 +1287,7 @@ static inline bool xfs_dinode_has_large_extent_counts( * RT bit manipulation macros. */ #define XFS_RTBITMAP_MAGIC 0x424D505A /* BMPZ */ +#define XFS_RTSUMMARY_MAGIC 0x53554D59 /* SUMY */ struct xfs_rtbuf_blkinfo { __be32 rt_magic; /* validity check on block */ diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c index db80f740151..4ed3bd261f6 100644 --- a/libxfs/xfs_rtbitmap.c +++ b/libxfs/xfs_rtbitmap.c @@ -49,7 +49,7 @@ xfs_rtbuf_verify_read( struct xfs_rtbuf_blkinfo *hdr = bp->b_addr; xfs_failaddr_t fa; - if (!xfs_has_rtgroups(mp) || bp->b_ops != &xfs_rtbitmap_buf_ops) + if (!xfs_has_rtgroups(mp)) return; if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr->rt_lsn))) { @@ -80,7 +80,7 @@ xfs_rtbuf_verify_write( struct xfs_buf_log_item *bip = bp->b_log_item; xfs_failaddr_t fa; - if (!xfs_has_rtgroups(mp) || bp->b_ops != &xfs_rtbitmap_buf_ops) + if (!xfs_has_rtgroups(mp)) return; fa = xfs_rtbuf_verify(bp); @@ -108,6 +108,14 @@ const struct xfs_buf_ops xfs_rtbitmap_buf_ops = { .verify_struct = xfs_rtbuf_verify, }; +const struct xfs_buf_ops xfs_rtsummary_buf_ops = { + .name = "xfs_rtsummary", + .magic = { 0, cpu_to_be32(XFS_RTSUMMARY_MAGIC) }, + .verify_read = xfs_rtbuf_verify_read, + .verify_write = xfs_rtbuf_verify_write, + .verify_struct = xfs_rtbuf_verify, +}; + /* * Get a buffer for the bitmap or summary file block specified. * The buffer is returned read and locked. @@ -149,7 +157,7 @@ xfs_rtbuf_get( if (error) return error; - if (xfs_has_rtgroups(mp) && !issum) { + if (xfs_has_rtgroups(mp)) { struct xfs_rtbuf_blkinfo *hdr = bp->b_addr; if (hdr->rt_owner != cpu_to_be64(ip->i_ino)) { @@ -1317,6 +1325,10 @@ xfs_rtsummary_blockcount( unsigned long long rsumwords; rsumwords = (unsigned long long)rsumlevels * rbmblocks; + + if (xfs_has_rtgroups(mp)) + return howmany_64(rsumwords, mp->m_blockwsize); + return XFS_B_TO_FSB(mp, rsumwords << XFS_WORDLOG); } diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h index c1f740fd27b..cebbb72c437 100644 --- a/libxfs/xfs_rtbitmap.h +++ b/libxfs/xfs_rtbitmap.h @@ -181,6 +181,9 @@ xfs_rtsumoffs_to_block( struct xfs_mount *mp, xfs_rtsumoff_t rsumoff) { + if (xfs_has_rtgroups(mp)) + return rsumoff / mp->m_blockwsize; + return XFS_B_TO_FSBT(mp, rsumoff * sizeof(xfs_suminfo_t)); } @@ -195,16 +198,24 @@ xfs_rtsumoffs_to_infoword( { unsigned int mask = mp->m_blockmask >> XFS_SUMINFOLOG; + if (xfs_has_rtgroups(mp)) + return rsumoff % mp->m_blockwsize; + return rsumoff & mask; } /* Return a pointer to a summary info word within a rt summary block buffer. */ static inline union xfs_suminfo_ondisk * xfs_rsumbuf_infoptr( + struct xfs_mount *mp, void *buf, unsigned int infoword) { union xfs_suminfo_ondisk *infop = buf; + struct xfs_rtbuf_blkinfo *hdr = buf; + + if (xfs_has_rtgroups(mp)) + infop = (union xfs_suminfo_ondisk *)(hdr + 1); return &infop[infoword]; } @@ -215,7 +226,7 @@ xfs_rsumblock_infoptr( struct xfs_buf *bp, unsigned int infoword) { - return xfs_rsumbuf_infoptr(bp->b_addr, infoword); + return xfs_rsumbuf_infoptr(bp->b_mount, bp->b_addr, infoword); } static inline const struct xfs_buf_ops * @@ -223,8 +234,11 @@ xfs_rtblock_ops( struct xfs_mount *mp, bool issum) { - if (xfs_has_rtgroups(mp) && !issum) + if (xfs_has_rtgroups(mp)) { + if (issum) + return &xfs_rtsummary_buf_ops; return &xfs_rtbitmap_buf_ops; + } return &xfs_rtbuf_ops; } diff --git a/libxfs/xfs_shared.h b/libxfs/xfs_shared.h index 1c86163915c..62839fc87b5 100644 --- a/libxfs/xfs_shared.h +++ b/libxfs/xfs_shared.h @@ -39,6 +39,7 @@ extern const struct xfs_buf_ops xfs_inode_buf_ra_ops; extern const struct xfs_buf_ops xfs_refcountbt_buf_ops; extern const struct xfs_buf_ops xfs_rmapbt_buf_ops; extern const struct xfs_buf_ops xfs_rtbitmap_buf_ops; +extern const struct xfs_buf_ops xfs_rtsummary_buf_ops; extern const struct xfs_buf_ops xfs_rtbuf_ops; extern const struct xfs_buf_ops xfs_rtsb_buf_ops; extern const struct xfs_buf_ops xfs_sb_buf_ops; From patchwork Fri Dec 30 22:19:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085688 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 82BCFC4332F for ; Sat, 31 Dec 2022 02:34:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236244AbiLaCd7 (ORCPT ); Fri, 30 Dec 2022 21:33:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236243AbiLaCd7 (ORCPT ); Fri, 30 Dec 2022 21:33:59 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8363D26D9 for ; Fri, 30 Dec 2022 18:33:58 -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 3ECE4B81DED for ; Sat, 31 Dec 2022 02:33:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2FB0C433D2; Sat, 31 Dec 2022 02:33:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454036; bh=VAhmcfNQEaTNX7DChoQS48AFAvs/CIv/NO9I60W4Q0w=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=iqIzwhfsN0NjErs4YYpId35qr41YFF+mireiwyWJtEg1r/AUx9suPKf/zh+UVED+y XR7emWJ2PNf+mpQcMWeOmPnv8w/GOyIHOhOIauim2PVSJr71Ta7m5VEZ5Qc6bq1JgB Uc0BhXgfKBCft3kCoMIpyestno+Ey+vmxd7zG6MKrmXeSLc2b90NPF3VcnGbxu2NSz X9d5XmFlHrkLkpC50L7vzGg/r+DO/gn4c0BTgwWMvRHcTdn3ZamaE98Zb49VoNOou1 t5YgNcfxagxxoUnFx8vgtkPLo/FYK+JN7N3wHbz0KCvIersBkf4FFOVhAHrFhXZshs axQXm27/pBIJA== Subject: [PATCH 15/45] xfs: encode the rtsummary in big endian format From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:45 -0800 Message-ID: <167243878562.731133.13874280726766187783.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Currently, the ondisk realtime summary file counters are accessed in units of 32-bit words. There's no endian translation of the contents of this file, which means that the Bad Things Happen(tm) if you go from (say) x86 to powerpc. Since we have a new feature flag, let's take the opportunity to enforce an endianness on the file. Encode the summary information in big endian format, like most of the rest of the filesystem. Signed-off-by: Darrick J. Wong --- libxfs/xfs_format.h | 4 +++- libxfs/xfs_rtbitmap.c | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index 47b2e31e256..7e76bedda68 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -748,10 +748,12 @@ union xfs_rtword_ondisk { /* * Realtime summary counts are accessed by the word, which is currently - * stored in host-endian format. + * stored in host-endian format. Starting with the realtime groups feature, + * the words are stored in be32 ondisk. */ union xfs_suminfo_ondisk { __u32 raw; + __be32 rtg; }; /* diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c index 4ed3bd261f6..26428898d60 100644 --- a/libxfs/xfs_rtbitmap.c +++ b/libxfs/xfs_rtbitmap.c @@ -558,6 +558,9 @@ xfs_suminfo_get( struct xfs_mount *mp, union xfs_suminfo_ondisk *infoptr) { + if (xfs_has_rtgroups(mp)) + return be32_to_cpu(infoptr->rtg); + return infoptr->raw; } @@ -567,7 +570,10 @@ xfs_suminfo_add( union xfs_suminfo_ondisk *infoptr, int delta) { - infoptr->raw += delta; + if (xfs_has_rtgroups(mp)) + be32_add_cpu(&infoptr->rtg, delta); + else + infoptr->raw += delta; } /* From patchwork Fri Dec 30 22:19:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085689 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 1C398C4332F for ; Sat, 31 Dec 2022 02:34:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236243AbiLaCeS (ORCPT ); Fri, 30 Dec 2022 21:34:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236245AbiLaCeP (ORCPT ); Fri, 30 Dec 2022 21:34:15 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C4771CB21 for ; Fri, 30 Dec 2022 18:34:14 -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 CCA40B81C22 for ; Sat, 31 Dec 2022 02:34:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C500C433EF; Sat, 31 Dec 2022 02:34:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454051; bh=hslgFdebPew+0RjSKZG69pr4YqNQXM5R/Dsrbuw7Q0w=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=hAT9RjMqBjx/jbZP+UQQ8htDYhtpyRgtywl44SR6VcUUrkVc39+wCaOkjMGRuK/Am w1zOLrlViE6xVDva3xrOaTTYBV86pB0V2Yo7g6wzALuGtYA/VcfkywHJmLsnE67SJg fsfX+gf61DTVPmHZJ7LEWQV16nP0QCInMVT7iTbRRmWtMg9jZStc6cUo13GdTAcddh viygKwKC/HWZqhCA5cN/inDjsmU75VroukT6EXIqTlIEqeOtxAYATXG0dZiCOikEE9 P+ePmsAf+zmtkzy1nDdccKfES3CBJSW/aHBKSWJZUIjTYdNhiPvBWvSk4iW2PAsVgu gj2tV+tuuNqHA== Subject: [PATCH 16/45] xfs: store rtgroup information with a bmap intent From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:45 -0800 Message-ID: <167243878576.731133.2170551438718575869.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Make the bmap intent items take an active reference to the rtgroup containing the space that is being mapped or unmapped. We will need this functionality once we start enabling rmap and reflink on the rt volume. Signed-off-by: Darrick J. Wong --- libxfs/defer_item.c | 17 +++++++++++++++-- libxfs/xfs_bmap.h | 5 ++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/libxfs/defer_item.c b/libxfs/defer_item.c index 316cc87a802..be6ecbc348f 100644 --- a/libxfs/defer_item.c +++ b/libxfs/defer_item.c @@ -479,8 +479,18 @@ xfs_bmap_update_get_group( { xfs_agnumber_t agno; - if (xfs_ifork_is_realtime(bi->bi_owner, bi->bi_whichfork)) + if (xfs_ifork_is_realtime(bi->bi_owner, bi->bi_whichfork)) { + if (xfs_has_rtgroups(mp)) { + xfs_rgnumber_t rgno; + + rgno = xfs_rtb_to_rgno(mp, bi->bi_bmap.br_startblock); + bi->bi_rtg = xfs_rtgroup_get(mp, rgno); + } else { + bi->bi_rtg = NULL; + } + return; + } agno = XFS_FSB_TO_AGNO(mp, bi->bi_bmap.br_startblock); bi->bi_pag = xfs_perag_get(mp, agno); @@ -500,8 +510,11 @@ static inline void xfs_bmap_update_put_group( struct xfs_bmap_intent *bi) { - if (xfs_ifork_is_realtime(bi->bi_owner, bi->bi_whichfork)) + if (xfs_ifork_is_realtime(bi->bi_owner, bi->bi_whichfork)) { + if (xfs_has_rtgroups(bi->bi_owner->i_mount)) + xfs_rtgroup_put(bi->bi_rtg); return; + } xfs_perag_drop_intents(bi->bi_pag); xfs_perag_put(bi->bi_pag); diff --git a/libxfs/xfs_bmap.h b/libxfs/xfs_bmap.h index d870c6a62e4..05097b1d5c7 100644 --- a/libxfs/xfs_bmap.h +++ b/libxfs/xfs_bmap.h @@ -241,7 +241,10 @@ struct xfs_bmap_intent { enum xfs_bmap_intent_type bi_type; int bi_whichfork; struct xfs_inode *bi_owner; - struct xfs_perag *bi_pag; + union { + struct xfs_perag *bi_pag; + struct xfs_rtgroup *bi_rtg; + }; struct xfs_bmbt_irec bi_bmap; }; From patchwork Fri Dec 30 22:19:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085690 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 65935C4332F for ; Sat, 31 Dec 2022 02:34:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236246AbiLaCee (ORCPT ); Fri, 30 Dec 2022 21:34:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236245AbiLaCeb (ORCPT ); Fri, 30 Dec 2022 21:34:31 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 885F826D9 for ; Fri, 30 Dec 2022 18:34:30 -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 sin.source.kernel.org (Postfix) with ESMTPS id E835FCE1926 for ; Sat, 31 Dec 2022 02:34:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20967C433EF; Sat, 31 Dec 2022 02:34:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454067; bh=aMEk3z3oha5Jm0jmAqpy62J7bLJmYD53pzcLrv1EBMo=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=svKY12Yd5BXCsF3P3ZA1/LF5N+e/j3tHcB5JcLKEYmP5+pN/3zODqf/ttkfurYIWy yxAK3K8UW62LHGOftMB3gcYlqYrZHmnMYFq58KAbel6QARvUarfWl/gP4loX9l+4uw KPptHK2SCm6K3TdFy4mvjPoP80F5xiIngK+KD9BSN/Zq91TQDFkS/JsfXBILcKSFja ryE2O/TdNWb1QrIobi2osMDU+zPZrKNGTgd1kP+uw6Dwbabv7QRf41AAnX3Ux2uurY 9SsaKXmCMZNYUjTL8ql+21skWX15e8umCl89q860kPQ/XEMTQqQ2oLiqtkM4+r1OnP o6vJTN2FSowwg== Subject: [PATCH 17/45] xfs: scrub the realtime group superblock From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:45 -0800 Message-ID: <167243878587.731133.13102036028058926154.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Enable scrubbing of realtime group superblocks. Signed-off-by: Darrick J. Wong --- io/scrub.c | 15 +++++++++++++++ libfrog/scrub.c | 5 +++++ libfrog/scrub.h | 1 + libxfs/xfs_fs.h | 3 ++- scrub/repair.c | 2 ++ scrub/scrub.c | 4 ++++ 6 files changed, 29 insertions(+), 1 deletion(-) diff --git a/io/scrub.c b/io/scrub.c index 0ad1b0229cc..d764a5a997b 100644 --- a/io/scrub.c +++ b/io/scrub.c @@ -59,6 +59,7 @@ scrub_ioctl( switch (sc->group) { case XFROG_SCRUB_GROUP_AGHEADER: case XFROG_SCRUB_GROUP_PERAG: + case XFROG_SCRUB_GROUP_RTGROUP: meta.sm_agno = control; break; case XFROG_SCRUB_GROUP_INODE: @@ -178,6 +179,19 @@ parse_args( return 0; } break; + case XFROG_SCRUB_GROUP_RTGROUP: + if (optind != argc - 1) { + fprintf(stderr, + _("Must specify one rtgroup number.\n")); + return 0; + } + control = strtoul(argv[optind], &p, 0); + if (*p != '\0') { + fprintf(stderr, + _("Bad rtgroup number '%s'.\n"), argv[optind]); + return 0; + } + break; default: ASSERT(0); break; @@ -255,6 +269,7 @@ repair_ioctl( switch (sc->group) { case XFROG_SCRUB_GROUP_AGHEADER: case XFROG_SCRUB_GROUP_PERAG: + case XFROG_SCRUB_GROUP_RTGROUP: meta.sm_agno = control; break; case XFROG_SCRUB_GROUP_INODE: diff --git a/libfrog/scrub.c b/libfrog/scrub.c index 3e322b4717d..7d6c9c69e4a 100644 --- a/libfrog/scrub.c +++ b/libfrog/scrub.c @@ -149,6 +149,11 @@ const struct xfrog_scrub_descr xfrog_scrubbers[XFS_SCRUB_TYPE_NR] = { .descr = "retained health records", .group = XFROG_SCRUB_GROUP_NONE, }, + [XFS_SCRUB_TYPE_RGSUPER] = { + .name = "rgsuper", + .descr = "realtime group superblock", + .group = XFROG_SCRUB_GROUP_RTGROUP, + }, }; #undef DEP diff --git a/libfrog/scrub.h b/libfrog/scrub.h index a59371fe141..7155e6a9b0e 100644 --- a/libfrog/scrub.h +++ b/libfrog/scrub.h @@ -15,6 +15,7 @@ enum xfrog_scrub_group { XFROG_SCRUB_GROUP_INODE, /* per-inode metadata */ XFROG_SCRUB_GROUP_ISCAN, /* metadata requiring full inode scan */ XFROG_SCRUB_GROUP_SUMMARY, /* summary metadata */ + XFROG_SCRUB_GROUP_RTGROUP, /* per-rtgroup metadata */ }; /* Catalog of scrub types and names, indexed by XFS_SCRUB_TYPE_* */ diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h index e3d87665e4a..c12be9dbb59 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -741,9 +741,10 @@ struct xfs_scrub_metadata { #define XFS_SCRUB_TYPE_QUOTACHECK 25 /* quota counters */ #define XFS_SCRUB_TYPE_NLINKS 26 /* inode link counts */ #define XFS_SCRUB_TYPE_HEALTHY 27 /* everything checked out ok */ +#define XFS_SCRUB_TYPE_RGSUPER 28 /* realtime superblock */ /* Number of scrub subcommands. */ -#define XFS_SCRUB_TYPE_NR 28 +#define XFS_SCRUB_TYPE_NR 29 /* i: Repair this metadata. */ #define XFS_SCRUB_IFLAG_REPAIR (1u << 0) diff --git a/scrub/repair.c b/scrub/repair.c index 6629125578c..10db103c87f 100644 --- a/scrub/repair.c +++ b/scrub/repair.c @@ -108,6 +108,7 @@ xfs_repair_metadata( switch (xfrog_scrubbers[scrub_type].group) { case XFROG_SCRUB_GROUP_AGHEADER: case XFROG_SCRUB_GROUP_PERAG: + case XFROG_SCRUB_GROUP_RTGROUP: meta.sm_agno = sri->sri_agno; break; case XFROG_SCRUB_GROUP_INODE: @@ -412,6 +413,7 @@ repair_item_difficulty( case XFS_SCRUB_TYPE_REFCNTBT: case XFS_SCRUB_TYPE_RTBITMAP: case XFS_SCRUB_TYPE_RTSUM: + case XFS_SCRUB_TYPE_RGSUPER: ret |= REPAIR_DIFFICULTY_PRIMARY; break; } diff --git a/scrub/scrub.c b/scrub/scrub.c index 19c35bfd907..a6d5ec056c8 100644 --- a/scrub/scrub.c +++ b/scrub/scrub.c @@ -49,6 +49,9 @@ format_scrub_descr( case XFROG_SCRUB_GROUP_ISCAN: case XFROG_SCRUB_GROUP_NONE: return snprintf(buf, buflen, _("%s"), _(sc->descr)); + case XFROG_SCRUB_GROUP_RTGROUP: + return snprintf(buf, buflen, _("rtgroup %u %s"), meta->sm_agno, + _(sc->descr)); } return -1; } @@ -97,6 +100,7 @@ xfs_check_metadata( switch (group) { case XFROG_SCRUB_GROUP_AGHEADER: case XFROG_SCRUB_GROUP_PERAG: + case XFROG_SCRUB_GROUP_RTGROUP: meta.sm_agno = sri->sri_agno; break; case XFROG_SCRUB_GROUP_METAFILES: From patchwork Fri Dec 30 22:19:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085691 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 0C775C4332F for ; Sat, 31 Dec 2022 02:35:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236245AbiLaCfH (ORCPT ); Fri, 30 Dec 2022 21:35:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236278AbiLaCeo (ORCPT ); Fri, 30 Dec 2022 21:34:44 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAADA1CB1F for ; Fri, 30 Dec 2022 18:34:43 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 4A63E61D07 for ; Sat, 31 Dec 2022 02:34:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ACD0AC433D2; Sat, 31 Dec 2022 02:34:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454082; bh=JhU81Rx7BbLmAepDEG6Sau5chDCzGoFUso2n9XV0vmE=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=agimEwh2T8/YkPBZWP61FnPoe+KhaYUwUBUESbrPlvZYFjdFIELSERXOWRO0sGa5V 0pE4M/TKHiS0pgOhK5FijS08QznWBqzkpSzWV19Lv8WnOULhZZni2WWll6TV3lstSO 7CaEYUAz7VUdroM3ESCrUfLx8cNfDXDDBWgzLFZ3AAfmb9QLB6GkHRZBXDY399eow7 a3Zr6jmamxXJbwH9yu7qGAQPUaVZISDWVd/b9647l/suYOZXo5fmFlPYaUEF3T6i/W IThZJyAo4rdRZSw1YaSVDM43qlIJE7hOd8w/y3qGSHzJ6l7dXMoP+MfGWeldSV1TzV E1eDUN3eD/++Q== Subject: [PATCH 18/45] xfs: repair secondary realtime group superblocks From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:46 -0800 Message-ID: <167243878601.731133.11726860471295155355.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Repair secondary realtime group superblocks. They're not critical for anything, but some consistency would be a good idea. Signed-off-by: Darrick J. Wong --- libxfs/xfs_rtgroup.c | 2 +- libxfs/xfs_rtgroup.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_rtgroup.c b/libxfs/xfs_rtgroup.c index ebbd0d13a8a..97643fdcc7c 100644 --- a/libxfs/xfs_rtgroup.c +++ b/libxfs/xfs_rtgroup.c @@ -381,7 +381,7 @@ xfs_rtgroup_log_super( } /* Initialize a secondary realtime superblock. */ -static int +int xfs_rtgroup_init_secondary_super( struct xfs_mount *mp, xfs_rgnumber_t rgno, diff --git a/libxfs/xfs_rtgroup.h b/libxfs/xfs_rtgroup.h index 1fec49c496d..3c9572677f7 100644 --- a/libxfs/xfs_rtgroup.h +++ b/libxfs/xfs_rtgroup.h @@ -210,6 +210,8 @@ void xfs_rtgroup_update_super(struct xfs_buf *rtsb_bp, const struct xfs_buf *sb_bp); void xfs_rtgroup_log_super(struct xfs_trans *tp, const struct xfs_buf *sb_bp); int xfs_rtgroup_update_secondary_sbs(struct xfs_mount *mp); +int xfs_rtgroup_init_secondary_super(struct xfs_mount *mp, xfs_rgnumber_t rgno, + struct xfs_buf **bpp); /* Lock the rt bitmap inode in exclusive mode */ #define XFS_RTGLOCK_BITMAP (1U << 0) @@ -230,6 +232,7 @@ int xfs_rtgroup_get_geometry(struct xfs_rtgroup *rtg, # define xfs_rtgroup_update_super(bp, sb_bp) ((void)0) # define xfs_rtgroup_log_super(tp, sb_bp) ((void)0) # define xfs_rtgroup_update_secondary_sbs(mp) (0) +# define xfs_rtgroup_init_secondary_super(mp, rgno, bpp) (-EOPNOTSUPP) # define xfs_rtgroup_lock(tp, rtg, gf) ((void)0) # define xfs_rtgroup_unlock(rtg, gf) ((void)0) # define xfs_rtgroup_get_geometry(rtg, rgeo) (-EOPNOTSUPP) From patchwork Fri Dec 30 22:19:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085692 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 BD110C3DA7C for ; Sat, 31 Dec 2022 02:35:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236247AbiLaCfH (ORCPT ); Fri, 30 Dec 2022 21:35:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236284AbiLaCe7 (ORCPT ); Fri, 30 Dec 2022 21:34:59 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44F1A1CB26 for ; Fri, 30 Dec 2022 18:34:59 -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 dfw.source.kernel.org (Postfix) with ESMTPS id D661C61D07 for ; Sat, 31 Dec 2022 02:34:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43B4FC433D2; Sat, 31 Dec 2022 02:34:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454098; bh=iQnAKE2TExEqtcf8s79a2JK9sgknTSWJvcKivkWyFmk=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=djGywbHIxCvQ65qGLRmLWvYr2WQYbe0iPS5ZQyNWfJJSmpOKgCAnhfbyTYoBj1oOD 4N9ETwyFAvT5gYBhqBb4iVthNl8LCh1mns0AYvlVEB4/Mk3ovF8PGzxmblfpKKgQHU HVS5Djbhu6zKnWGZ3AO5i8QGLuuZpoZbUt1wAX01edIj3Wz2RLa4R+z6Xh0N1mKcGR 6aLVsUy7xdWQsTlu59suQfCdXx76zBZDuQR4+s/q/19QKu/FU1NTV+z/z9SovbuxR+ e5MsdbRF8E7GuuMvs4gbX+vGtvYtQA+APhITDg6GM2vKaGDGL0cz0br4TXpOP7ZNgU D6mmb6Auab8ew== Subject: [PATCH 19/45] xfs: scrub the rtbitmap by group From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:46 -0800 Message-ID: <167243878615.731133.13852321164499144680.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Reduce the amount of time that the kernel spends with the rtbitmap locked for a scrub by splitting the work by rtgroup. Signed-off-by: Darrick J. Wong --- libfrog/scrub.c | 5 +++++ libxfs/xfs_fs.h | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libfrog/scrub.c b/libfrog/scrub.c index 7d6c9c69e4a..7efb7ecfbd0 100644 --- a/libfrog/scrub.c +++ b/libfrog/scrub.c @@ -154,6 +154,11 @@ const struct xfrog_scrub_descr xfrog_scrubbers[XFS_SCRUB_TYPE_NR] = { .descr = "realtime group superblock", .group = XFROG_SCRUB_GROUP_RTGROUP, }, + [XFS_SCRUB_TYPE_RGBITMAP] = { + .name = "rgbitmap", + .descr = "realtime group bitmap", + .group = XFROG_SCRUB_GROUP_RTGROUP, + }, }; #undef DEP diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h index c12be9dbb59..7e9d7d7bb40 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -742,9 +742,10 @@ struct xfs_scrub_metadata { #define XFS_SCRUB_TYPE_NLINKS 26 /* inode link counts */ #define XFS_SCRUB_TYPE_HEALTHY 27 /* everything checked out ok */ #define XFS_SCRUB_TYPE_RGSUPER 28 /* realtime superblock */ +#define XFS_SCRUB_TYPE_RGBITMAP 29 /* realtime group bitmap */ /* Number of scrub subcommands. */ -#define XFS_SCRUB_TYPE_NR 29 +#define XFS_SCRUB_TYPE_NR 30 /* i: Repair this metadata. */ #define XFS_SCRUB_IFLAG_REPAIR (1u << 0) From patchwork Fri Dec 30 22:19:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085693 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 6F06DC4332F for ; Sat, 31 Dec 2022 02:35:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236207AbiLaCfQ (ORCPT ); Fri, 30 Dec 2022 21:35:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236248AbiLaCfP (ORCPT ); Fri, 30 Dec 2022 21:35:15 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8EA11CB1F for ; Fri, 30 Dec 2022 18:35:14 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 6674761A32 for ; Sat, 31 Dec 2022 02:35:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C83E1C433EF; Sat, 31 Dec 2022 02:35:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454113; bh=Cpdtn+YwVxZiD4sZo/Mo6nxdqUAjt6hlWF8P5YlX0Yk=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=PM/Vkg+il2dLnrUZwKx4iSd87PgHKgZYthbIFhEUfW1dyIdkbyO/7OfpXtDUZXWT9 ZM5PAGzcLsB+K21+0RwzWfbThqvRI4tDjoQkkep2lRztQQoSVyF+6hqzNo8w5YPuPp dSvdlJ5SGMz/pJ3ShW2n7/RZNgXhOKpYy45H6n+Iks+0iEvsFY/+GvVT9kHrc7WIAM slGRNgRtyBeDUIOgpI5JbKwExMeHSiMa2/ovOjvakab6GAmsB7cc1nDsCRTwVHOfrN kXH+7z2lPEKxfOIl9RJP9i4NX9M9FTT+fnzKS/dj/U8KTqaZ234NKENqVHt5AxaETN j39MWSGgnzTgw== Subject: [PATCH 20/45] libfrog: report rt groups in output From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:46 -0800 Message-ID: <167243878628.731133.15946823593658902489.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Report realtime group geometry. Signed-off-by: Darrick J. Wong --- libfrog/fsgeom.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libfrog/fsgeom.c b/libfrog/fsgeom.c index 3f4c38d1e1b..66e813a863f 100644 --- a/libfrog/fsgeom.c +++ b/libfrog/fsgeom.c @@ -63,7 +63,8 @@ xfs_report_geom( "naming =version %-14u bsize=%-6u ascii-ci=%d, ftype=%d\n" "log =%-22s bsize=%-6d blocks=%u, version=%d\n" " =%-22s sectsz=%-5u sunit=%d blks, lazy-count=%d\n" -"realtime =%-22s extsz=%-6d blocks=%lld, rtextents=%lld\n"), +"realtime =%-22s extsz=%-6d blocks=%lld, rtextents=%lld\n" +" =%-22s rgcount=%-4d rgsize=%u blks\n"), mntpoint, geo->inodesize, geo->agcount, geo->agblocks, "", geo->sectsize, attrversion, projid32bit, "", crcs_enabled, finobt_enabled, spinodes, rmapbt_enabled, @@ -78,7 +79,8 @@ xfs_report_geom( "", geo->logsectsize, geo->logsunit / geo->blocksize, lazycount, !geo->rtblocks ? _("none") : rtname ? rtname : _("external"), geo->rtextsize * geo->blocksize, (unsigned long long)geo->rtblocks, - (unsigned long long)geo->rtextents); + (unsigned long long)geo->rtextents, + "", geo->rgcount, geo->rgblocks); } /* Try to obtain the xfs geometry. On error returns a negative error code. */ From patchwork Fri Dec 30 22:19:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085694 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 AD493C4332F for ; Sat, 31 Dec 2022 02:35:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236248AbiLaCfj (ORCPT ); Fri, 30 Dec 2022 21:35:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236250AbiLaCfd (ORCPT ); Fri, 30 Dec 2022 21:35:33 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C51326D9 for ; Fri, 30 Dec 2022 18:35:32 -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 B0DE2B81E03 for ; Sat, 31 Dec 2022 02:35:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 590C5C433D2; Sat, 31 Dec 2022 02:35:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454129; bh=KlCewcb/dQowMGJcSWNVAnrdyJyIeBeth6pa9G1nN9g=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=QJmLgvR+uy0RdgxVW9OvKp8KCIW2jbf/vkHtt2uurmo31jLrgyIIZb4A5D54CMQGL A2Yg/xon3Nrgl/4ba5etjSVrM5+ZIl2LnZUQndFT1sH3UYVlSoCIrEJyrSbYpDQ1fn 1Oc7FismdhG3I3nv93RkuKGWE2V1h8BU3NK265SiSI5bPU+wXwJq8+WeafOC2l1EWT mDS2pRL5oJizPdUx0dY96FdPXlhIF9WChvRMSaD4jrWnZI1FrKMJXO8ooQn7wN7iPl 4QMeva7YIkstg3loFXivIHEUloGpl5qLMPH6xoc/Gp1qGhTToUhcpwZmpKVoQOPNfP qu33YI1dBZspg== Subject: [PATCH 21/45] xfs_repair: support realtime groups From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:46 -0800 Message-ID: <167243878639.731133.5264626503934517536.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Support the realtime group feature. Signed-off-by: Darrick J. Wong --- libxfs/libxfs_api_defs.h | 2 + repair/agheader.c | 2 + repair/incore.c | 22 +++++++++++++++ repair/phase3.c | 3 ++ repair/rt.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++ repair/rt.h | 3 ++ repair/sb.c | 37 +++++++++++++++++++++++++ repair/xfs_repair.c | 11 +++++++ 8 files changed, 149 insertions(+) diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 4d9499529c0..deadfe2c422 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -238,6 +238,8 @@ #define xfs_rtsummary_wordcount libxfs_rtsummary_wordcount #define xfs_rtfree_extent libxfs_rtfree_extent +#define xfs_rtgroup_update_secondary_sbs libxfs_rtgroup_update_secondary_sbs +#define xfs_rtgroup_update_super libxfs_rtgroup_update_super #define xfs_sb_from_disk libxfs_sb_from_disk #define xfs_sb_quota_from_disk libxfs_sb_quota_from_disk #define xfs_sb_read_secondary libxfs_sb_read_secondary diff --git a/repair/agheader.c b/repair/agheader.c index af88802ffdf..076860a4451 100644 --- a/repair/agheader.c +++ b/repair/agheader.c @@ -412,6 +412,8 @@ secondary_sb_whack( * super byte for byte. */ sb->sb_metadirino = mp->m_sb.sb_metadirino; + sb->sb_rgblocks = mp->m_sb.sb_rgblocks; + sb->sb_rgcount = mp->m_sb.sb_rgcount; } else do_warn( _("would zero unused portion of %s superblock (AG #%u)\n"), diff --git a/repair/incore.c b/repair/incore.c index 06edaf0d605..27457a7c17e 100644 --- a/repair/incore.c +++ b/repair/incore.c @@ -195,6 +195,25 @@ set_rtbmap( (((uint64_t) state) << ((rtx % XR_BB_NUM) * XR_BB))); } +static void +rtgroups_init( + struct xfs_mount *mp) +{ + xfs_rgnumber_t rgno; + + if (!xfs_has_rtgroups(mp) || !rt_bmap) + return; + + for (rgno = 0; rgno < mp->m_sb.sb_rgcount; rgno++) { + xfs_rtblock_t start_rtx; + + start_rtx = xfs_rgbno_to_rtb(mp, rgno, 0) / + mp->m_sb.sb_rextsize; + + set_rtbmap(start_rtx, XR_E_INUSE_FS); + } +} + static void reset_rt_bmap(void) { @@ -219,6 +238,8 @@ init_rt_bmap( mp->m_sb.sb_rextents); return; } + + rtgroups_init(mp); } static void @@ -271,6 +292,7 @@ reset_bmaps(xfs_mount_t *mp) } reset_rt_bmap(); + rtgroups_init(mp); } void diff --git a/repair/phase3.c b/repair/phase3.c index ca4dbee4743..19490dbe9bb 100644 --- a/repair/phase3.c +++ b/repair/phase3.c @@ -17,6 +17,7 @@ #include "progress.h" #include "bmap.h" #include "threads.h" +#include "rt.h" static void process_agi_unlinked( @@ -116,6 +117,8 @@ phase3( set_progress_msg(PROG_FMT_AGI_UNLINKED, (uint64_t) glob_agcount); + check_rtsupers(mp); + /* first clear the agi unlinked AGI list */ if (!no_modify) { for (i = 0; i < mp->m_sb.sb_agcount; i++) diff --git a/repair/rt.c b/repair/rt.c index 56a04c3de6e..33bc6836f71 100644 --- a/repair/rt.c +++ b/repair/rt.c @@ -213,3 +213,72 @@ check_rtsummary( check_rtfile_contents(mp, "rtsummary", mp->m_sb.sb_rsumino, sumcompute, XFS_B_TO_FSB(mp, mp->m_rsumsize)); } + +void +check_rtsupers( + struct xfs_mount *mp) +{ + struct xfs_buf *bp; + xfs_rtblock_t rtbno; + xfs_rgnumber_t rgno; + int error; + + if (!xfs_has_rtgroups(mp)) + return; + + for (rgno = 0; rgno < mp->m_sb.sb_rgcount; rgno++) { + rtbno = xfs_rgbno_to_rtb(mp, rgno, 0); + error = -libxfs_buf_read_uncached(mp->m_rtdev_targp, + xfs_rtb_to_daddr(mp, rtbno), + XFS_FSB_TO_BB(mp, 1), 0, &bp, + &xfs_rtsb_buf_ops); + if (!error) { + libxfs_buf_relse(bp); + continue; + } + + if (no_modify) { + do_warn( + _("would rewrite realtime group %u superblock\n"), + rgno); + } else { + do_warn( + _("will rewrite realtime group %u superblock\n"), + rgno); + /* + * Rewrite the primary rt superblock before an update + * to the primary fs superblock trips over the rt super + * being corrupt. + */ + if (rgno == 0) + rewrite_primary_rt_super(mp); + } + } +} + +void +rewrite_primary_rt_super( + struct xfs_mount *mp) +{ + struct xfs_buf *rtsb_bp; + struct xfs_buf *sb_bp = libxfs_getsb(mp); + int error; + + if (!sb_bp) + do_error( + _("couldn't grab primary sb to update rt superblocks\n")); + + error = -libxfs_buf_get_uncached(mp->m_rtdev_targp, + XFS_FSB_TO_BB(mp, 1), 0, &rtsb_bp); + if (error) + do_error( + _("couldn't grab primary rt superblock\n")); + + rtsb_bp->b_maps[0].bm_bn = XFS_RTSB_DADDR; + rtsb_bp->b_ops = &xfs_rtsb_buf_ops; + + libxfs_rtgroup_update_super(rtsb_bp, sb_bp); + libxfs_buf_mark_dirty(rtsb_bp); + libxfs_buf_relse(rtsb_bp); + libxfs_buf_relse(sb_bp); +} diff --git a/repair/rt.h b/repair/rt.h index 16b39c21a67..8e8796aa3c1 100644 --- a/repair/rt.h +++ b/repair/rt.h @@ -16,5 +16,8 @@ int generate_rtinfo(struct xfs_mount *mp, union xfs_rtword_ondisk *words, void check_rtbitmap(struct xfs_mount *mp); void check_rtsummary(struct xfs_mount *mp); +void check_rtsupers(struct xfs_mount *mp); + +void rewrite_primary_rt_super(struct xfs_mount *mp); #endif /* _XFS_REPAIR_RT_H_ */ diff --git a/repair/sb.c b/repair/sb.c index 6e7f448596e..a1cfeff1e91 100644 --- a/repair/sb.c +++ b/repair/sb.c @@ -314,6 +314,37 @@ verify_sb_loginfo( return true; } +static int +verify_sb_rtgroups( + struct xfs_sb *sbp) +{ + uint64_t groups; + + if (!(sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_METADIR)) + return XR_BAD_RT_GEO_DATA; + + if (sbp->sb_rgblocks > XFS_MAX_RGBLOCKS) + return XR_BAD_RT_GEO_DATA; + + if (sbp->sb_rextsize == 0) + return XR_BAD_RT_GEO_DATA; + + if (sbp->sb_rgblocks % sbp->sb_rextsize != 0) + return XR_BAD_RT_GEO_DATA; + + if (sbp->sb_rgblocks < (sbp->sb_rextsize << 1)) + return XR_BAD_RT_GEO_DATA; + + if (sbp->sb_rgcount > XFS_MAX_RGNUMBER) + return XR_BAD_RT_GEO_DATA; + + groups = howmany(sbp->sb_rblocks, sbp->sb_rgblocks); + if (groups != sbp->sb_rgcount) + return XR_BAD_RT_GEO_DATA; + + return 0; +} + /* * verify a superblock -- does not verify root inode # * can only check that geometry info is internally @@ -519,6 +550,12 @@ verify_sb(char *sb_buf, xfs_sb_t *sb, int is_primary_sb) if (sb->sb_blocklog + sb->sb_dirblklog > XFS_MAX_BLOCKSIZE_LOG) return XR_BAD_DIR_SIZE_DATA; + if (sb->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_RTGROUPS) { + int err = verify_sb_rtgroups(sb); + if (err) + return err; + } + return(XR_OK); } diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c index 92dc0fb2d9f..13e1f2deccf 100644 --- a/repair/xfs_repair.c +++ b/repair/xfs_repair.c @@ -27,6 +27,7 @@ #include "bulkload.h" #include "quotacheck.h" #include "rcbag_btree.h" +#include "rt.h" /* * option tables for getsubopt calls @@ -1510,6 +1511,16 @@ _("Note - stripe unit (%d) and width (%d) were copied from a backup superblock.\ XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR; } + /* Always rewrite the realtime superblocks. */ + if (xfs_has_rtgroups(mp)) { + if (mp->m_sb.sb_rgcount > 0) + rewrite_primary_rt_super(mp); + + error = -libxfs_rtgroup_update_secondary_sbs(mp); + if (error) + do_error(_("updating rt superblocks, err %d"), error); + } + /* * Done. Flush all cached buffers and inodes first to ensure all * verifiers are run (where we discover the max metadata LSN), reformat From patchwork Fri Dec 30 22:19:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085695 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 499F8C4332F for ; Sat, 31 Dec 2022 02:35:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236251AbiLaCfr (ORCPT ); Fri, 30 Dec 2022 21:35:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236249AbiLaCfq (ORCPT ); Fri, 30 Dec 2022 21:35:46 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAF87DEC for ; Fri, 30 Dec 2022 18:35:45 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 81EA761CC2 for ; Sat, 31 Dec 2022 02:35:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCF12C433D2; Sat, 31 Dec 2022 02:35:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454144; bh=unpgNZfxjEoyvL5ZlWrJgvV6Ich17jWYciJwAYB2OOc=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=HyWy/1LCmIJOnl9RqLo6x9td5RKtoK3OiJnUQU1NgDsmM8XVJWu+14nXuZsYA5qbg stGenVHawskMSEL/SL5t+stXhPsU/Vka2FF56x4qT13f4qs0XqKu6D3E5lLpNeurSW a51Mdhag4s2FtOdam8WgSqEaIvjX3BbZqGpHr/TWf47ee+x0ycge+q4Rg3/oHpxNji mvl8BovDfFSVdnGQdYgFdw2uO+6fQyLwPL2xMqlMzTETsGsSy3wHD47/0H4ywFuXe6 pqxQPW9gufVDbFSPxJNXSIdVFocAk0FxcEGvgSmqFwwQIlWrA2TVx4K0i7agxRUJzd 1oGANpqGgDQoA== Subject: [PATCH 22/45] xfs_repair: improve rtbitmap discrepancy reporting From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:46 -0800 Message-ID: <167243878653.731133.7580105112892217687.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Improve the reporting of discrepancies in the realtime bitmap and summary files by creating a separate helper function that will pinpoint the exact (word) locations of mismatches. This will help developers to diagnose problems with the rtgroups feature and users to figure out exactly what's bad in a filesystem. Signed-off-by: Darrick J. Wong --- repair/rt.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/repair/rt.c b/repair/rt.c index 33bc6836f71..ed0f744cb9f 100644 --- a/repair/rt.c +++ b/repair/rt.c @@ -124,6 +124,44 @@ generate_rtinfo( return(0); } +static void +check_rtwords( + struct xfs_mount *mp, + const char *filename, + unsigned long long bno, + void *ondisk, + void *incore) +{ + unsigned int wordcnt = mp->m_blockwsize; + union xfs_rtword_ondisk *o = ondisk, *i = incore; + int badstart = -1; + unsigned int j; + + if (memcmp(ondisk, incore, wordcnt << XFS_WORDLOG) == 0) + return; + + for (j = 0; j < wordcnt; j++, o++, i++) { + if (o->raw == i->raw) { + /* Report a range of inconsistency that just ended. */ + if (badstart >= 0) + do_warn( + _("discrepancy in %s at dblock 0x%llx words 0x%x-0x%x/0x%x\n"), + filename, bno, badstart, j - 1, wordcnt); + badstart = -1; + continue; + } + + if (badstart == -1) + badstart = j; + } + + if (badstart >= 0) + do_warn( + _("discrepancy in %s at dblock 0x%llx words 0x%x-0x%x/0x%x\n"), + filename, bno, badstart, wordcnt, + wordcnt); +} + static void check_rtfile_contents( struct xfs_mount *mp, @@ -180,9 +218,7 @@ check_rtfile_contents( break; } - if (memcmp(bp->b_addr, buf, mp->m_blockwsize << XFS_WORDLOG)) - do_warn(_("discrepancy in %s at dblock 0x%llx\n"), - filename, (unsigned long long)bno); + check_rtwords(mp, filename, bno, bp->b_addr, buf); buf += XFS_FSB_TO_B(mp, map.br_blockcount); bno += map.br_blockcount; From patchwork Fri Dec 30 22:19:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085696 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 CC816C4332F for ; Sat, 31 Dec 2022 02:36:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236250AbiLaCgF (ORCPT ); Fri, 30 Dec 2022 21:36:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236249AbiLaCgE (ORCPT ); Fri, 30 Dec 2022 21:36:04 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EEF039F for ; Fri, 30 Dec 2022 18:36:03 -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 CEAA1B81DED for ; Sat, 31 Dec 2022 02:36:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6AAA0C433D2; Sat, 31 Dec 2022 02:36:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454160; bh=wNSjPrgXsfLbhhxGx6xr1U3T7rPZweKhVP9dVZN0Ab4=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=PHOZl6zJRmr2xvohwaEpxlggx6u/gfOl5nnWYyKKoaRKQndtk0lTlw32cSqgdRNJJ 24jZhYAAMce7LQH9zEdDyTgWdcG5OoKzUBXnFc0xmAqUz5yIPRZQZcQZyqS+cC72PY wW1h0l9ySKMOMUX/x4HT09s2qNeaO9tjSdf6NIhB0m1vo2pa3N7MXYm4tOlhSCkepS V/cawEGaGztxMrfJG9IL9Czje38najmgwAdog7letcilKHdlnwwJXcMBsxbdZi5U/n sK09KX29t2MMFZSHjmnEi0yfJFxI3kR8FJ6R6hWCqPPONLpaeV4YE0/53AOhC3Dg5w 66MBeQ9e+nd9A== Subject: [PATCH 23/45] xfs_repair: repair rtbitmap block headers From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:46 -0800 Message-ID: <167243878666.731133.7939249717252358238.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Check and repair the new block headers attached to rtbitmap blocks. Signed-off-by: Darrick J. Wong --- repair/phase6.c | 20 ++++++++++++++++---- repair/rt.c | 42 ++++++++++++++++++++++++++++++------------ repair/sb.c | 8 +++++++- 3 files changed, 53 insertions(+), 17 deletions(-) diff --git a/repair/phase6.c b/repair/phase6.c index 31d42b9306b..ad70b22a953 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -803,6 +803,8 @@ fill_rbmino(xfs_mount_t *mp) } while (bno < mp->m_sb.sb_rbmblocks) { + xfs_daddr_t daddr; + /* * fill the file one block at a time */ @@ -816,11 +818,9 @@ fill_rbmino(xfs_mount_t *mp) ASSERT(map.br_startblock != HOLESTARTBLOCK); - error = -libxfs_trans_read_buf( - mp, tp, mp->m_dev, - XFS_FSB_TO_DADDR(mp, map.br_startblock), + daddr = XFS_FSB_TO_DADDR(mp, map.br_startblock); + error = -libxfs_trans_read_buf(mp, tp, mp->m_dev, daddr, XFS_FSB_TO_BB(mp, 1), 1, &bp, NULL); - if (error) { do_warn( _("can't access block %" PRIu64 " (fsbno %" PRIu64 ") of realtime bitmap inode %" PRIu64 "\n"), @@ -831,6 +831,18 @@ _("can't access block %" PRIu64 " (fsbno %" PRIu64 ") of realtime bitmap inode % memcpy(xfs_rbmblock_wordptr(bp, 0), bmp, mp->m_blockwsize << XFS_WORDLOG); + if (xfs_has_rtgroups(mp)) { + struct xfs_rtbuf_blkinfo *hdr = bp->b_addr; + + bp->b_ops = &xfs_rtbitmap_buf_ops; + hdr->rt_magic = cpu_to_be32(XFS_RTBITMAP_MAGIC); + hdr->rt_owner = cpu_to_be64(ip->i_ino); + hdr->rt_lsn = 0; + hdr->rt_blkno = cpu_to_be64(daddr); + platform_uuid_copy(&hdr->rt_uuid, + &mp->m_sb.sb_meta_uuid); + } + libxfs_trans_log_buf(tp, bp, 0, mp->m_sb.sb_blocksize - 1); bmp += mp->m_blockwsize; diff --git a/repair/rt.c b/repair/rt.c index ed0f744cb9f..e7190383da3 100644 --- a/repair/rt.c +++ b/repair/rt.c @@ -168,11 +168,13 @@ check_rtfile_contents( const char *filename, xfs_ino_t ino, void *buf, - xfs_fileoff_t filelen) + xfs_fileoff_t filelen, + const struct xfs_buf_ops *buf_ops) { struct xfs_bmbt_irec map; struct xfs_buf *bp; struct xfs_inode *ip; + union xfs_rtword_ondisk *words = buf; xfs_fileoff_t bno = 0; int error; @@ -190,12 +192,11 @@ check_rtfile_contents( } while (bno < filelen) { - xfs_filblks_t maplen; + union xfs_rtword_ondisk *ondisk; + xfs_daddr_t daddr; int nmap = 1; - /* Read up to 1MB at a time. */ - maplen = min(filelen - bno, XFS_B_TO_FSBT(mp, 1048576)); - error = -libxfs_bmapi_read(ip, bno, maplen, &map, &nmap, 0); + error = -libxfs_bmapi_read(ip, bno, 1, &map, &nmap, 0); if (error) { do_warn(_("unable to read %s mapping, err %d\n"), filename, error); @@ -208,19 +209,32 @@ check_rtfile_contents( break; } - error = -libxfs_buf_read_uncached(mp->m_dev, - XFS_FSB_TO_DADDR(mp, map.br_startblock), + daddr = XFS_FSB_TO_DADDR(mp, map.br_startblock); + error = -libxfs_buf_read_uncached(mp->m_dev, daddr, XFS_FSB_TO_BB(mp, map.br_blockcount), - 0, &bp, NULL); + 0, &bp, buf_ops); if (error) { do_warn(_("unable to read %s at dblock 0x%llx, err %d\n"), filename, (unsigned long long)bno, error); break; } - check_rtwords(mp, filename, bno, bp->b_addr, buf); + if (buf_ops) { + struct xfs_rtbuf_blkinfo *hdr = bp->b_addr; + + if (hdr->rt_owner != cpu_to_be64(ino)) { + do_warn( + _("corrupt owner in %s at dblock 0x%llx\n"), + filename, (unsigned long long)bno); + } + ondisk = xfs_rbmblock_wordptr(bp, 0); + check_rtwords(mp, filename, bno, ondisk, words); + words += mp->m_blockwsize; + } else { + check_rtwords(mp, filename, bno, bp->b_addr, buf); + buf += XFS_FSB_TO_B(mp, map.br_blockcount); + } - buf += XFS_FSB_TO_B(mp, map.br_blockcount); bno += map.br_blockcount; libxfs_buf_relse(bp); } @@ -232,11 +246,15 @@ void check_rtbitmap( struct xfs_mount *mp) { + const struct xfs_buf_ops *buf_ops = NULL; + if (need_rbmino) return; + if (xfs_has_rtgroups(mp)) + buf_ops = &xfs_rtbitmap_buf_ops; check_rtfile_contents(mp, "rtbitmap", mp->m_sb.sb_rbmino, btmcompute, - mp->m_sb.sb_rbmblocks); + mp->m_sb.sb_rbmblocks, buf_ops); } void @@ -247,7 +265,7 @@ check_rtsummary( return; check_rtfile_contents(mp, "rtsummary", mp->m_sb.sb_rsumino, sumcompute, - XFS_B_TO_FSB(mp, mp->m_rsumsize)); + XFS_B_TO_FSB(mp, mp->m_rsumsize), NULL); } void diff --git a/repair/sb.c b/repair/sb.c index a1cfeff1e91..04b3d8cf9ce 100644 --- a/repair/sb.c +++ b/repair/sb.c @@ -506,6 +506,8 @@ verify_sb(char *sb_buf, xfs_sb_t *sb, int is_primary_sb) if (sb->sb_frextents != 0) return(XR_BAD_RT_GEO_DATA); } else { + unsigned int rbmblock_bytes = sb->sb_blocksize; + /* * if we have a real-time partition, sanity-check geometry */ @@ -516,8 +518,12 @@ verify_sb(char *sb_buf, xfs_sb_t *sb, int is_primary_sb) libxfs_highbit32((unsigned int)sb->sb_rextents)) return(XR_BAD_RT_GEO_DATA); + if (xfs_sb_is_v5(sb) && + (sb->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_RTGROUPS)) + rbmblock_bytes -= sizeof(struct xfs_rtbuf_blkinfo); + if (sb->sb_rbmblocks != (xfs_extlen_t) howmany(sb->sb_rextents, - NBBY * sb->sb_blocksize)) + NBBY * rbmblock_bytes)) return(XR_BAD_RT_GEO_DATA); } From patchwork Fri Dec 30 22:19:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085697 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 5F87BC4332F for ; Sat, 31 Dec 2022 02:36:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236252AbiLaCgU (ORCPT ); Fri, 30 Dec 2022 21:36:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236249AbiLaCgT (ORCPT ); Fri, 30 Dec 2022 21:36:19 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E129BD6 for ; Fri, 30 Dec 2022 18:36:18 -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 4BFF6B81E03 for ; Sat, 31 Dec 2022 02:36:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 117E8C433D2; Sat, 31 Dec 2022 02:36:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454176; bh=UOh8gVVglWhlDKiPwgQg2uDuz6QF0rh4YNhHtY0VabU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=dZfv4RacwIiHF8/VilzBKwKIrOKNzuiPWLx/jqOrOP45EmF1tfzrJbcqQzgtlNVE9 NMjHy6z9421rk6s4GqOM/wX9fON7goYguVsv76+aRi3qV3bul31SEufYh5CGlfAni+ R6AktyUbYmHg+dD0DZdbqySwSAeHfvSvJNgbv12z7vb/zCQWOOg9KnVr6zAUFJvBX/ 1RSeh21ZwyeJD2xdhzTQiOmIOZW8BUNjXpd1KyYSk89u4QABepPQGwNHOy6GLP8ik0 iB+YKOisEFyJT+Vo2d7dyQYiW+S2wK/UyY1vDkAVdz4lALxXGa986/JS9e5UAPU11R cWerNKiaavolQ== Subject: [PATCH 24/45] xfs_repair: repair rtsummary block headers From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:46 -0800 Message-ID: <167243878679.731133.13989206969699276767.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Check and repair the new block headers attached to rtsummary blocks. Signed-off-by: Darrick J. Wong --- repair/phase6.c | 19 ++++++++++++++++--- repair/rt.c | 6 +++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/repair/phase6.c b/repair/phase6.c index ad70b22a953..1dbd600915d 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -886,6 +886,8 @@ fill_rsumino(xfs_mount_t *mp) } while (bno < end_bno) { + xfs_daddr_t daddr; + /* * fill the file one block at a time */ @@ -899,9 +901,8 @@ fill_rsumino(xfs_mount_t *mp) ASSERT(map.br_startblock != HOLESTARTBLOCK); - error = -libxfs_trans_read_buf( - mp, tp, mp->m_dev, - XFS_FSB_TO_DADDR(mp, map.br_startblock), + daddr = XFS_FSB_TO_DADDR(mp, map.br_startblock); + error = -libxfs_trans_read_buf(mp, tp, mp->m_dev, daddr, XFS_FSB_TO_BB(mp, 1), 1, &bp, NULL); if (error) { @@ -915,6 +916,18 @@ _("can't access block %" PRIu64 " (fsbno %" PRIu64 ") of realtime summary inode memcpy(xfs_rsumblock_infoptr(bp, 0), smp, mp->m_blockwsize << XFS_WORDLOG); + if (xfs_has_rtgroups(mp)) { + struct xfs_rtbuf_blkinfo *hdr = bp->b_addr; + + bp->b_ops = &xfs_rtsummary_buf_ops; + hdr->rt_magic = cpu_to_be32(XFS_RTSUMMARY_MAGIC); + hdr->rt_owner = cpu_to_be64(ip->i_ino); + hdr->rt_lsn = 0; + hdr->rt_blkno = cpu_to_be64(daddr); + platform_uuid_copy(&hdr->rt_uuid, + &mp->m_sb.sb_meta_uuid); + } + libxfs_trans_log_buf(tp, bp, 0, mp->m_sb.sb_blocksize - 1); smp += mp->m_blockwsize; diff --git a/repair/rt.c b/repair/rt.c index e7190383da3..33641031731 100644 --- a/repair/rt.c +++ b/repair/rt.c @@ -261,11 +261,15 @@ void check_rtsummary( struct xfs_mount *mp) { + const struct xfs_buf_ops *buf_ops = NULL; + if (need_rsumino) return; + if (xfs_has_rtgroups(mp)) + buf_ops = &xfs_rtsummary_buf_ops; check_rtfile_contents(mp, "rtsummary", mp->m_sb.sb_rsumino, sumcompute, - XFS_B_TO_FSB(mp, mp->m_rsumsize), NULL); + XFS_B_TO_FSB(mp, mp->m_rsumsize), buf_ops); } void From patchwork Fri Dec 30 22:19:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085698 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 DDB05C4332F for ; Sat, 31 Dec 2022 02:36:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236253AbiLaCgd (ORCPT ); Fri, 30 Dec 2022 21:36:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236249AbiLaCgd (ORCPT ); Fri, 30 Dec 2022 21:36:33 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4668BD6 for ; Fri, 30 Dec 2022 18:36:32 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 3FC8661CC2 for ; Sat, 31 Dec 2022 02:36:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97DE4C433D2; Sat, 31 Dec 2022 02:36:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454191; bh=CoLZ5vSgNfPAE/ou3DKvCnnCtz9TbpzKqJPNH5W08Sg=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=GWSaMtaI5sZdVvA4zjD4ZbA3u0k8Rlc/09r/zyE/KW8kiOMy9NCsTXdpmY3vEajsh /ybTk53HrGRaF3G3tDZo34gNOObAXRnqLhKpXsIBU3lmaRRs1uiJhvrn8Dkyu12+hA mfVU7H6SCGJECtQbPmPo/qS2iT+waMJHblVLUvKYF5SbJdxRgszgWT0p+yhk3KoAmj iPhHgTHDboSFWPUPj9FHPYcVGjr2OppyEb2Jj3/+OpHxvYt47tpw3mV9QjxdRS/k+L aUQshZ0FNGBKtt7KoMc+61jI0sl9g8W+sIPxV6ksDQHdh9nt9YtF12O747u/jQ0g69 wQnBUNxZPAypQ== Subject: [PATCH 25/45] xfs_db: listify the definition of enum typnm From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:46 -0800 Message-ID: <167243878691.731133.3678549325865013969.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Convert the enum definition into a list so that future patches adding things to enum typnm don't have to reflow the entire thing. Signed-off-by: Darrick J. Wong --- db/type.h | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/db/type.h b/db/type.h index 411bfe90dbc..397dcf5464c 100644 --- a/db/type.h +++ b/db/type.h @@ -11,11 +11,30 @@ struct field; typedef enum typnm { - TYP_AGF, TYP_AGFL, TYP_AGI, TYP_ATTR, TYP_BMAPBTA, - TYP_BMAPBTD, TYP_BNOBT, TYP_CNTBT, TYP_RMAPBT, TYP_REFCBT, TYP_DATA, - TYP_DIR2, TYP_DQBLK, TYP_INOBT, TYP_INODATA, TYP_INODE, - TYP_LOG, TYP_RTBITMAP, TYP_RTSUMMARY, TYP_SB, TYP_SYMLINK, - TYP_TEXT, TYP_FINOBT, TYP_NONE + TYP_AGF, + TYP_AGFL, + TYP_AGI, + TYP_ATTR, + TYP_BMAPBTA, + TYP_BMAPBTD, + TYP_BNOBT, + TYP_CNTBT, + TYP_RMAPBT, + TYP_REFCBT, + TYP_DATA, + TYP_DIR2, + TYP_DQBLK, + TYP_INOBT, + TYP_INODATA, + TYP_INODE, + TYP_LOG, + TYP_RTBITMAP, + TYP_RTSUMMARY, + TYP_SB, + TYP_SYMLINK, + TYP_TEXT, + TYP_FINOBT, + TYP_NONE } typnm_t; #define DB_FUZZ 2 From patchwork Fri Dec 30 22:19:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085699 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 B052AC4332F for ; Sat, 31 Dec 2022 02:36:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236273AbiLaCgz (ORCPT ); Fri, 30 Dec 2022 21:36:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236261AbiLaCgw (ORCPT ); Fri, 30 Dec 2022 21:36:52 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A9EA2DED for ; Fri, 30 Dec 2022 18:36:50 -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 sin.source.kernel.org (Postfix) with ESMTPS id DA316CE1926 for ; Sat, 31 Dec 2022 02:36:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27CA1C433EF; Sat, 31 Dec 2022 02:36:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454207; bh=/UJAt3aDN+KetsuabRFFYXmajPC0LlxhxZqk9Ju4NW0=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=N7+dgSdHXh8D/YBXvxEom6TtPEzgXvaRTKqswshFAPdLNSZkEtTbPfOece/YRPrJj N+7vP6uRPhhRmVXQ0T2uyMpHKv6HMw75rhLvhyJOFPP/PCh9R2mc2uZjv158X3vi2P IenASN7NGvI/RKJuq7e3ekOXbZGa+qkxA8S/IKVHF2TZX/FEQ+LZavPI85bm8Su0BU IFLMhByVz1P7GhVsf9GVuWjFd8p1BZxtkbtpGHmJMI8PrM6hqPnXXTbOwUrkoI5Cuz CrteltCmzjo+ZniAsWqZhKmyym5f4M45UwgF3G8F9bbwcjfRzTMYOQ0f+YGc1n1nO6 s7rMsNsNw8ooQ== Subject: [PATCH 26/45] xfs_db: support dumping realtime superblocks From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:47 -0800 Message-ID: <167243878702.731133.6316048528860784016.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Allow debugging of realtime superblocks, and add the relevant fields in the fs superblock that point us at the existence and location of the rt supers. Signed-off-by: Darrick J. Wong --- db/Makefile | 2 + db/command.c | 2 + db/field.c | 8 ++++ db/field.h | 4 ++ db/rtgroup.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ db/rtgroup.h | 15 ++++++++ db/sb.c | 15 ++++++++ db/type.c | 6 +++ db/type.h | 1 + 9 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 db/rtgroup.c create mode 100644 db/rtgroup.h diff --git a/db/Makefile b/db/Makefile index dbe79a9a1b1..d22adc2d18d 100644 --- a/db/Makefile +++ b/db/Makefile @@ -13,7 +13,7 @@ HFILES = addr.h agf.h agfl.h agi.h attr.h attrshort.h bit.h block.h bmap.h \ flist.h fprint.h frag.h freesp.h hash.h help.h init.h inode.h input.h \ io.h logformat.h malloc.h metadump.h output.h print.h quit.h sb.h \ sig.h strvec.h text.h type.h write.h attrset.h symlink.h fsmap.h \ - fuzz.h + fuzz.h rtgroup.h CFILES = $(HFILES:.h=.c) btdump.c btheight.c convert.c info.c namei.c \ timelimit.c bmap_inflate.c unlinked.c LSRCFILES = xfs_admin.sh xfs_ncheck.sh xfs_metadump.sh diff --git a/db/command.c b/db/command.c index be6d045a23a..f2b59709848 100644 --- a/db/command.c +++ b/db/command.c @@ -39,6 +39,7 @@ #include "fsmap.h" #include "crc.h" #include "fuzz.h" +#include "rtgroup.h" cmdinfo_t *cmdtab; int ncmds; @@ -135,6 +136,7 @@ init_commands(void) output_init(); print_init(); quit_init(); + rtsb_init(); sb_init(); type_init(); write_init(); diff --git a/db/field.c b/db/field.c index a3e47ee81cc..cee5c661595 100644 --- a/db/field.c +++ b/db/field.c @@ -23,6 +23,7 @@ #include "dir2.h" #include "dir2sf.h" #include "symlink.h" +#include "rtgroup.h" const ftattr_t ftattrtab[] = { { FLDT_AGBLOCK, "agblock", fp_num, "%u", SI(bitsz(xfs_agblock_t)), @@ -44,6 +45,11 @@ const ftattr_t ftattrtab[] = { { FLDT_AGNUMBER, "agnumber", fp_num, "%u", SI(bitsz(xfs_agnumber_t)), FTARG_DONULL, NULL, NULL }, + { FLDT_RGBLOCK, "rgblock", fp_num, "%u", SI(bitsz(xfs_rgblock_t)), + FTARG_DONULL, NULL, NULL }, + { FLDT_RGNUMBER, "rgnumber", fp_num, "%u", SI(bitsz(xfs_rgnumber_t)), + FTARG_DONULL, NULL, NULL }, + /* attr fields */ { FLDT_ATTR, "attr", NULL, (char *)attr_flds, attr_size, FTARG_SIZE, NULL, attr_flds }, @@ -347,6 +353,8 @@ const ftattr_t ftattrtab[] = { NULL, NULL }, { FLDT_SB, "sb", NULL, (char *)sb_flds, sb_size, FTARG_SIZE, NULL, sb_flds }, + { FLDT_RTSB, "rtsb", NULL, (char *)rtsb_flds, rtsb_size, FTARG_SIZE, + NULL, rtsb_flds }, /* CRC enabled symlink */ { FLDT_SYMLINK_CRC, "symlink", NULL, (char *)symlink_crc_flds, diff --git a/db/field.h b/db/field.h index 634742a572c..226753490ad 100644 --- a/db/field.h +++ b/db/field.h @@ -15,6 +15,9 @@ typedef enum fldt { FLDT_AGINONN, FLDT_AGNUMBER, + FLDT_RGBLOCK, + FLDT_RGNUMBER, + /* attr fields */ FLDT_ATTR, FLDT_ATTR_BLKINFO, @@ -166,6 +169,7 @@ typedef enum fldt { FLDT_QCNT, FLDT_QWARNCNT, FLDT_SB, + FLDT_RTSB, /* CRC enabled symlink */ FLDT_SYMLINK_CRC, diff --git a/db/rtgroup.c b/db/rtgroup.c new file mode 100644 index 00000000000..c4debc1d394 --- /dev/null +++ b/db/rtgroup.c @@ -0,0 +1,115 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2022 Oracle. All Rights Reserved. + * Author: Darrick J. Wong + */ +#include "libxfs.h" +#include "libxlog.h" +#include "command.h" +#include "type.h" +#include "faddr.h" +#include "fprint.h" +#include "field.h" +#include "io.h" +#include "sb.h" +#include "bit.h" +#include "output.h" +#include "init.h" +#include "rtgroup.h" + +#define uuid_equal(s,d) (platform_uuid_compare((s),(d)) == 0) + +static int rtsb_f(int argc, char **argv); +static void rtsb_help(void); + +static const cmdinfo_t rtsb_cmd = + { "rtsb", NULL, rtsb_f, 0, 1, 1, N_("[rgno]"), + N_("set current address to realtime sb header"), rtsb_help }; + +void +rtsb_init(void) +{ + if (xfs_has_rtgroups(mp)) + add_command(&rtsb_cmd); +} + +#define OFF(f) bitize(offsetof(struct xfs_rtsb, rsb_ ## f)) +#define SZC(f) szcount(struct xfs_rtsb, rsb_ ## f) +const field_t rtsb_flds[] = { + { "magicnum", FLDT_UINT32X, OI(OFF(magicnum)), C1, 0, TYP_NONE }, + { "blocksize", FLDT_UINT32D, OI(OFF(blocksize)), C1, 0, TYP_NONE }, + { "rblocks", FLDT_DRFSBNO, OI(OFF(rblocks)), C1, 0, TYP_NONE }, + { "rextents", FLDT_DRTBNO, OI(OFF(rextents)), C1, 0, TYP_NONE }, + { "uuid", FLDT_UUID, OI(OFF(uuid)), C1, 0, TYP_NONE }, + { "rextsize", FLDT_AGBLOCK, OI(OFF(rextsize)), C1, 0, TYP_NONE }, + { "rgblocks", FLDT_RGBLOCK, OI(OFF(rgblocks)), C1, 0, TYP_NONE }, + { "rgcount", FLDT_RGNUMBER, OI(OFF(rgcount)), C1, 0, TYP_NONE }, + { "rbmblocks", FLDT_EXTLEN, OI(OFF(rbmblocks)), C1, 0, TYP_NONE }, + { "fname", FLDT_CHARNS, OI(OFF(fname)), CI(SZC(fname)), 0, TYP_NONE }, + { "blocklog", FLDT_UINT8D, OI(OFF(blocklog)), C1, 0, TYP_NONE }, + { "sectlog", FLDT_UINT8D, OI(OFF(sectlog)), C1, 0, TYP_NONE }, + { "rextslog", FLDT_UINT8D, OI(OFF(rextslog)), C1, 0, TYP_NONE }, + { "crc", FLDT_CRC, OI(OFF(crc)), C1, 0, TYP_NONE }, + { "lsn", FLDT_UINT64X, OI(OFF(lsn)), C1, 0, TYP_NONE }, + { "meta_uuid", FLDT_UUID, OI(OFF(meta_uuid)), C1, 0, TYP_NONE }, + { NULL } +}; + +const field_t rtsb_hfld[] = { + { "", FLDT_RTSB, OI(0), C1, 0, TYP_NONE }, + { NULL } +}; + +static void +rtsb_help(void) +{ + dbprintf(_( +"\n" +" set realtime group superblock\n" +"\n" +" Example:\n" +"\n" +" 'rtsb 7' - set location to 7th realtime group superblock, set type to 'rtsb'\n" +"\n" +" Located in the first block of each realtime group, the rt superblock\n" +" contains the base information for the realtime section of a filesystem.\n" +" The superblock in allocation group 0 is the primary. The copies in the\n" +" remaining realtime groups only serve as backup for filesystem recovery.\n" +"\n" +)); +} + +static int +rtsb_f( + int argc, + char **argv) +{ + xfs_rtblock_t rtbno; + xfs_rgnumber_t rgno = 0; + char *p; + + if (argc > 1) { + rgno = (xfs_rgnumber_t)strtoul(argv[1], &p, 0); + if (*p != '\0' || rgno >= mp->m_sb.sb_rgcount) { + dbprintf(_("bad realtime group number %s\n"), argv[1]); + return 0; + } + } + cur_agno = NULLAGNUMBER; + + rtbno = xfs_rgbno_to_rtb(mp, rgno, 0); + + ASSERT(typtab[TYP_RTSB].typnm == TYP_RTSB); + set_rt_cur(&typtab[TYP_RTSB], xfs_rtb_to_daddr(mp, rtbno), + XFS_FSB_TO_BB(mp, 1), DB_RING_ADD, NULL); + return 0; +} + +int +rtsb_size( + void *obj, + int startoff, + int idx) +{ + return bitize(mp->m_sb.sb_blocksize); +} diff --git a/db/rtgroup.h b/db/rtgroup.h new file mode 100644 index 00000000000..49077bee141 --- /dev/null +++ b/db/rtgroup.h @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2022 Oracle. All Rights Reserved. + * Author: Darrick J. Wong + */ +#ifndef DB_RTGROUP_H_ +#define DB_RTGROUP_H_ + +extern const struct field rtsb_flds[]; +extern const struct field rtsb_hfld[]; + +extern void rtsb_init(void); +extern int rtsb_size(void *obj, int startoff, int idx); + +#endif /* DB_RTGROUP_H_ */ diff --git a/db/sb.c b/db/sb.c index d7df55e02e9..fa0706d3676 100644 --- a/db/sb.c +++ b/db/sb.c @@ -74,6 +74,17 @@ rootino_count( return xfs_has_metadir(mp) ? 0 : 1; } +/* + * Counts superblock fields that only exist when realtime groups are enabled. + */ +static int +rtgroups_count( + void *obj, + int startoff) +{ + return xfs_has_rtgroups(mp) ? 1 : 0; +} + #define OFF(f) bitize(offsetof(struct xfs_dsb, sb_ ## f)) #define SZC(f) szcount(struct xfs_dsb, sb_ ## f) const field_t sb_flds[] = { @@ -91,6 +102,10 @@ const field_t sb_flds[] = { TYP_INODE }, { "rsumino", FLDT_INO, OI(OFF(rsumino)), rootino_count, FLD_COUNT, TYP_INODE }, + { "rgblocks", FLDT_RGBLOCK, OI(OFF(rgblocks)), rtgroups_count, + FLD_COUNT, TYP_NONE }, + { "rgcount", FLDT_RGNUMBER, OI(OFF(rgcount)), rtgroups_count, + FLD_COUNT, TYP_NONE }, { "rextsize", FLDT_AGBLOCK, OI(OFF(rextsize)), C1, 0, TYP_NONE }, { "agblocks", FLDT_AGBLOCK, OI(OFF(agblocks)), C1, 0, TYP_NONE }, { "agcount", FLDT_AGNUMBER, OI(OFF(agcount)), C1, 0, TYP_NONE }, diff --git a/db/type.c b/db/type.c index efe7044569d..d875c0c6365 100644 --- a/db/type.c +++ b/db/type.c @@ -28,6 +28,7 @@ #include "text.h" #include "symlink.h" #include "fuzz.h" +#include "rtgroup.h" static const typ_t *findtyp(char *name); static int type_f(int argc, char **argv); @@ -60,6 +61,7 @@ static const typ_t __typtab[] = { { TYP_LOG, "log", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_RTBITMAP, "rtbitmap", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_RTSUMMARY, "rtsummary", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, + { TYP_RTSB, "rtsb", handle_struct, rtsb_hfld, NULL, TYP_F_NO_CRC_OFF }, { TYP_SB, "sb", handle_struct, sb_hfld, NULL, TYP_F_NO_CRC_OFF }, { TYP_SYMLINK, "symlink", handle_string, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_TEXT, "text", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, @@ -102,6 +104,8 @@ static const typ_t __typtab_crc[] = { { TYP_LOG, "log", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_RTBITMAP, "rtbitmap", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_RTSUMMARY, "rtsummary", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, + { TYP_RTSB, "rtsb", handle_struct, rtsb_hfld, &xfs_rtsb_buf_ops, + XFS_SB_CRC_OFF }, { TYP_SB, "sb", handle_struct, sb_hfld, &xfs_sb_buf_ops, XFS_SB_CRC_OFF }, { TYP_SYMLINK, "symlink", handle_struct, symlink_crc_hfld, @@ -146,6 +150,8 @@ static const typ_t __typtab_spcrc[] = { { TYP_LOG, "log", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_RTBITMAP, "rtbitmap", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_RTSUMMARY, "rtsummary", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, + { TYP_RTSB, "rtsb", handle_struct, rtsb_hfld, &xfs_rtsb_buf_ops, + XFS_SB_CRC_OFF }, { TYP_SB, "sb", handle_struct, sb_hfld, &xfs_sb_buf_ops, XFS_SB_CRC_OFF }, { TYP_SYMLINK, "symlink", handle_struct, symlink_crc_hfld, diff --git a/db/type.h b/db/type.h index 397dcf5464c..d4efa4b0fab 100644 --- a/db/type.h +++ b/db/type.h @@ -30,6 +30,7 @@ typedef enum typnm TYP_LOG, TYP_RTBITMAP, TYP_RTSUMMARY, + TYP_RTSB, TYP_SB, TYP_SYMLINK, TYP_TEXT, From patchwork Fri Dec 30 22:19:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085700 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 DE670C4332F for ; Sat, 31 Dec 2022 02:37:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236254AbiLaCh2 (ORCPT ); Fri, 30 Dec 2022 21:37:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236249AbiLaChG (ORCPT ); Fri, 30 Dec 2022 21:37:06 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5167DBC95 for ; Fri, 30 Dec 2022 18:37:05 -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 11831B81E03 for ; Sat, 31 Dec 2022 02:37:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE757C433D2; Sat, 31 Dec 2022 02:37:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454222; bh=wPzUtNnMXSCj6UJqZuRoTvl3tzISHURyMgd05QQ5vMc=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=DAUc8mYxeYkS7OMtev9GcVDAa5yGBE/Cf1wnkY1lT3GkeN2ta/BDbUNtErNcJsMPP RyynX3dNd+tqdYWLRsJTRhke6HDZSxrxpndeLr6utkmLVGM7XTKtfeSvk+xY230Uc8 yPDx65G+8UBCp84vww8AhQDxae5cAs4vJ1rW6z40xBhSVnCYhiPffKkNnW0dF+RG4k 8Xy52AKhQFsdsXFIfcAyoQQctOK283DfHgP/OhevL0UQfi7wA0ZBCOm4c7uE8uMSO8 QTyPg+LY3J43x8XlPW+ncyng2uXyffUpC+W3a8MyLa4wxNuJqanWGV+spZWKt8qji5 UEoqNPuLE5qBA== Subject: [PATCH 27/45] xfs_db: support changing the label and uuid of rt superblocks From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:47 -0800 Message-ID: <167243878716.731133.8733171457425734764.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Update the label and uuid commands to change the rt superblocks along with the filesystem superblocks. Signed-off-by: Darrick J. Wong --- db/sb.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 108 insertions(+), 11 deletions(-) diff --git a/db/sb.c b/db/sb.c index fa0706d3676..36d4c317dba 100644 --- a/db/sb.c +++ b/db/sb.c @@ -27,6 +27,7 @@ static int label_f(int argc, char **argv); static void label_help(void); static int version_f(int argc, char **argv); static void version_help(void); +static size_t check_label(char *label, bool can_warn); static const cmdinfo_t sb_cmd = { "sb", NULL, sb_f, 0, 1, 1, N_("[agno]"), @@ -357,6 +358,77 @@ uuid_help(void) )); } +static bool +check_rtgroup_update_problems( + struct xfs_mount *mp) +{ + int error; + + if (!xfs_has_rtgroups(mp) || mp->m_sb.sb_rgcount == 0) + return false; + + push_cur(); + error = set_rt_cur(&typtab[TYP_RTSB], XFS_RTSB_DADDR, + XFS_FSB_TO_BB(mp, 1), DB_RING_ADD, NULL); + if (error == ENODEV) { + /* no rt dev means we should just bail out */ + pop_cur(); + return true; + } + + pop_cur(); + return false; +} + +static int +update_rt_supers( + struct xfs_mount *mp, + uuid_t *uuid, + char *label) +{ + uuid_t old_uuid; + xfs_rgnumber_t rgno; + int error; + + if (uuid) + memcpy(&old_uuid, &mp->m_sb.sb_uuid, sizeof(uuid_t)); + + for (rgno = 0; rgno < mp->m_sb.sb_rgcount; rgno++) { + struct xfs_rtsb *rsb; + xfs_rtblock_t rtbno; + + push_cur(); + rtbno = xfs_rgbno_to_rtb(mp, rgno, 0); + error = set_rt_cur(&typtab[TYP_RTSB], + xfs_rtb_to_daddr(mp, rtbno), + XFS_FSB_TO_BB(mp, 1), DB_RING_ADD, NULL); + if (error == ENODEV) { + /* no rt dev means we should just bail out */ + exitcode = 1; + pop_cur(); + return 1; + } + + rsb = iocur_top->data; + if (label) { + size_t len = check_label(label, false); + + memset(&rsb->rsb_fname, 0, XFSLABEL_MAX); + memcpy(&rsb->rsb_fname, label, len); + } + if (uuid) { + memcpy(&mp->m_sb.sb_uuid, uuid, sizeof(uuid_t)); + memcpy(&rsb->rsb_uuid, uuid, sizeof(rsb->rsb_uuid)); + } + write_cur(); + if (uuid) + memcpy(&mp->m_sb.sb_uuid, &old_uuid, sizeof(uuid_t)); + pop_cur(); + } + + return 0; +} + static uuid_t * do_uuid(xfs_agnumber_t agno, uuid_t *uuid) { @@ -463,11 +535,18 @@ uuid_f( } } + if (check_rtgroup_update_problems(mp)) { + exitcode = 1; + return 0; + } + /* clear the log (setting uuid) if it's not dirty */ if (!sb_logzero(&uu)) return 0; dbprintf(_("writing all SBs\n")); + if (update_rt_supers(mp, &uu, NULL)) + return 1; for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) if (!do_uuid(agno, &uu)) { dbprintf(_("failed to set UUID in AG %d\n"), agno); @@ -536,6 +615,27 @@ label_help(void) )); } +static size_t +check_label( + char *label, + bool can_warn) +{ + size_t len = strlen(label); + + if (len > XFSLABEL_MAX) { + if (can_warn) + dbprintf(_("%s: truncating label length from %d to %d\n"), + progname, (int)len, XFSLABEL_MAX); + len = XFSLABEL_MAX; + } + if ( len == 2 && + (strcmp(label, "\"\"") == 0 || + strcmp(label, "''") == 0 || + strcmp(label, "--") == 0) ) + label[0] = label[1] = '\0'; + return len; +} + static char * do_label(xfs_agnumber_t agno, char *label) { @@ -554,17 +654,7 @@ do_label(xfs_agnumber_t agno, char *label) return &lbl[0]; } /* set label */ - if ((len = strlen(label)) > sizeof(tsb.sb_fname)) { - if (agno == 0) - dbprintf(_("%s: truncating label length from %d to %d\n"), - progname, (int)len, (int)sizeof(tsb.sb_fname)); - len = sizeof(tsb.sb_fname); - } - if ( len == 2 && - (strcmp(label, "\"\"") == 0 || - strcmp(label, "''") == 0 || - strcmp(label, "--") == 0) ) - label[0] = label[1] = '\0'; + len = check_label(label, agno == 0); memset(&tsb.sb_fname, 0, sizeof(tsb.sb_fname)); memcpy(&tsb.sb_fname, label, len); memcpy(&lbl[0], &tsb.sb_fname, sizeof(tsb.sb_fname)); @@ -601,7 +691,14 @@ label_f( return 0; } + if (check_rtgroup_update_problems(mp)) { + exitcode = 1; + return 0; + } + dbprintf(_("writing all SBs\n")); + if (update_rt_supers(mp, NULL, argv[1])) + return 1; for (ag = 0; ag < mp->m_sb.sb_agcount; ag++) if ((p = do_label(ag, argv[1])) == NULL) { dbprintf(_("failed to set label in AG %d\n"), ag); From patchwork Fri Dec 30 22:19:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085701 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 4D889C4332F for ; Sat, 31 Dec 2022 02:38:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236249AbiLaCh3 (ORCPT ); Fri, 30 Dec 2022 21:37:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236255AbiLaChT (ORCPT ); Fri, 30 Dec 2022 21:37:19 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46B3ABC9C for ; Fri, 30 Dec 2022 18:37:19 -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 dfw.source.kernel.org (Postfix) with ESMTPS id D6A9361CC2 for ; Sat, 31 Dec 2022 02:37:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C6ADC433EF; Sat, 31 Dec 2022 02:37:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454238; bh=C440FqgCAnfJbdzyfvfQmcSNRj96M6QL7F7RJ9fqnn0=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=GotejuvkzXrWiVENpZJFnMboDdi0WjYgj+9d9Bus0kSDUz5npZGxJkiUnN3FynrFk endIT2Vda5izN/ZJJQNYHT133u6q+Rikx5/e05oEEh/thQRpGXNPUg/8tRGVLwqp9p iEPevOlGMT+sn3uOIhjjk05jzc6Af373nNdNQwUdINLtF4EvH/oPktkc0gG72w0S9O DcEwJymezs+XFiizIlYfE8kwENsCeJ6YLb+8EeHz4vr8NMsjyUSrUr234BBfzHfQQd Q6MJlyHdkgoxtdCeJkfrpt6BjPRddO3wAxMRlFwt12h97JY5U4knWbqpD4lZCGjmYb kK4Mn5Ryk7vNw== Subject: [PATCH 28/45] xfs_db: listify the definition of dbm_t From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:47 -0800 Message-ID: <167243878730.731133.15573785425504120020.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Convert this enum definition to a list so that code adding elements to the enum do not have to reflow the whole thing. Signed-off-by: Darrick J. Wong --- db/check.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/db/check.c b/db/check.c index f39d732d04d..4f4bff58e22 100644 --- a/db/check.c +++ b/db/check.c @@ -26,14 +26,36 @@ typedef enum { } qtype_t; typedef enum { - DBM_UNKNOWN, DBM_AGF, DBM_AGFL, DBM_AGI, - DBM_ATTR, DBM_BTBMAPA, DBM_BTBMAPD, DBM_BTBNO, - DBM_BTCNT, DBM_BTINO, DBM_DATA, DBM_DIR, - DBM_FREE1, DBM_FREE2, DBM_FREELIST, DBM_INODE, - DBM_LOG, DBM_MISSING, DBM_QUOTA, DBM_RTBITMAP, - DBM_RTDATA, DBM_RTFREE, DBM_RTSUM, DBM_SB, - DBM_SYMLINK, DBM_BTFINO, DBM_BTRMAP, DBM_BTREFC, - DBM_RLDATA, DBM_COWDATA, + DBM_UNKNOWN, + DBM_AGF, + DBM_AGFL, + DBM_AGI, + DBM_ATTR, + DBM_BTBMAPA, + DBM_BTBMAPD, + DBM_BTBNO, + DBM_BTCNT, + DBM_BTINO, + DBM_DATA, + DBM_DIR, + DBM_FREE1, + DBM_FREE2, + DBM_FREELIST, + DBM_INODE, + DBM_LOG, + DBM_MISSING, + DBM_QUOTA, + DBM_RTBITMAP, + DBM_RTDATA, + DBM_RTFREE, + DBM_RTSUM, + DBM_SB, + DBM_SYMLINK, + DBM_BTFINO, + DBM_BTRMAP, + DBM_BTREFC, + DBM_RLDATA, + DBM_COWDATA, DBM_NDBM } dbm_t; From patchwork Fri Dec 30 22:19:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085703 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 5EC09C4332F for ; Sat, 31 Dec 2022 02:38:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236256AbiLaCiB (ORCPT ); Fri, 30 Dec 2022 21:38:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236255AbiLaChh (ORCPT ); Fri, 30 Dec 2022 21:37:37 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FE57BC95 for ; Fri, 30 Dec 2022 18:37:36 -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 2B370B81C22 for ; Sat, 31 Dec 2022 02:37:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDB14C433EF; Sat, 31 Dec 2022 02:37:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454253; bh=aFf6OOBBrcWaH38lfwNi3I8sVBAnhW0EqEZV6yZVj7E=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=ey1Ao4yQ9mqPAkiZDFDm3XcL0e4WAEtSoSbKI40SObW2DMVwPnjv5VoT2JnlgAYas J+JobLARB54UXw4gv/pjEhZJpSQ+/YIJwSzC5GN9fVrLPp3LzUyVWt1caTru8iyPMv CDV2PHjqqnwSUMIYvT2KSNw7ACMU/OG+GYEaT2QEvHETFJm3EGNcq2KyPxK6YMZCd8 YOU5+z7iKbBVCFLxgq2fklZPGZbInG4Vk+YPaING8Cu64ffIxwtTgnhEb2PgclOraM M2EkY+V6SlpSYYq8VM4OdT5KZnMz4ejjqz5gONlE5C2VAg3LLnG09kel83UIBGa0Yp sRXacHABSwy+g== Subject: [PATCH 29/45] xfs_db: implement check for rt superblocks From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:47 -0800 Message-ID: <167243878744.731133.5132949239718266830.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Implement the bare minimum needed to avoid xfs_check regressions when realtime groups are enabled. Signed-off-by: Darrick J. Wong --- db/check.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/db/check.c b/db/check.c index 4f4bff58e22..d3d22f0531c 100644 --- a/db/check.c +++ b/db/check.c @@ -56,6 +56,7 @@ typedef enum { DBM_BTREFC, DBM_RLDATA, DBM_COWDATA, + DBM_RTSB, DBM_NDBM } dbm_t; @@ -187,6 +188,7 @@ static const char *typename[] = { "btrefcnt", "rldata", "cowdata", + "rtsb", NULL }; @@ -809,6 +811,23 @@ blockfree_f( return 0; } +static void +rtgroups_init( + struct xfs_mount *mp) +{ + xfs_rgnumber_t rgno; + + if (!xfs_has_rtgroups(mp)) + return; + + for (rgno = 0; rgno < mp->m_sb.sb_rgcount; rgno++) { + xfs_rtblock_t rtbno; + + rtbno = xfs_rgbno_to_rtb(mp, rgno, 0); + set_rdbmap(rtbno, mp->m_sb.sb_rextsize, DBM_RTSB); + } +} + /* * Check consistency of xfs filesystem contents. */ @@ -843,6 +862,7 @@ blockget_f( "filesystem.\n")); } } + rtgroups_init(mp); if (blist_size) { xfree(blist); blist = NULL; From patchwork Fri Dec 30 22:19:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085702 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 7E164C3DA7D for ; Sat, 31 Dec 2022 02:38:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236255AbiLaCiB (ORCPT ); Fri, 30 Dec 2022 21:38:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236259AbiLaChw (ORCPT ); Fri, 30 Dec 2022 21:37:52 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07AA8BC9C for ; Fri, 30 Dec 2022 18:37:52 -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 C037EB81DED for ; Sat, 31 Dec 2022 02:37:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69B0CC433EF; Sat, 31 Dec 2022 02:37:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454269; bh=T2rcw9zijVnEhsZ2JOKIJLSqrX3XBWHev44gfq4Jv8Y=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=SXLcYrXgoEfOmT01BlHl9AQ5Lz1RvHTcy1A7nWxvJmIMFzsxaun8PHtxYWvsq8zE5 x62+C/qL/jU/ypeHb/DiiNs8gVHmK9WJpnGIUYx9cBEcZiV0S4bsd0ec/pWFHhuM68 NwZuPJie7/zRyPLtkVnovr6ctzSWd4Z0xQgWSA6EEG7yMqVm6qGxR3YEzE3BwHZfCz ZOP/4LyKmfTjIzO2e0Q/nodZ4mNN2ze3ZQ8v4+G/7a/wqCLRvWtRjCmJTUR/ml+Fef coMgpGrPk4avpeTOjJGqsS2BT/yGbju9HjDV5YzYVsB+bC9jC3fOtYJOVq0tutUGM9 +wROf4twTOWeg== Subject: [PATCH 30/45] xfs_db: enable conversion of rt space units From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:47 -0800 Message-ID: <167243878758.731133.6306481528555037356.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Teach the xfs_db convert function about realtime extents, blocks, and realtime group numbers. Signed-off-by: Darrick J. Wong --- db/convert.c | 38 +++++++++++++++++++++++++++++++++++++- man/man8/xfs_db.8 | 17 +++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/db/convert.c b/db/convert.c index 072ccc8f6ef..2214649650d 100644 --- a/db/convert.c +++ b/db/convert.c @@ -34,6 +34,10 @@ rtblock_to_bytes(rtx_to_rtblock(xfs_rbmblock_to_rtx(mp, (uint64_t)x))) #define rbmword_to_bytes(x) \ rtblock_to_bytes(rtx_to_rtblock((uint64_t)(x) << XFS_NBWORDLOG)) +#define rgblock_to_bytes(x) \ + ((uint64_t)(x) << mp->m_sb.sb_blocklog) +#define rgnumber_to_bytes(x) \ + rgblock_to_bytes((uint64_t)(x) * mp->m_sb.sb_rgblocks) typedef enum { CT_NONE = -1, @@ -55,6 +59,8 @@ typedef enum { CT_RSUMBLOCK, /* block within rt summary */ CT_RSUMLOG, /* log level for rtsummary computations */ CT_RSUMINFO, /* info word within rt summary */ + CT_RGBLOCK, /* xfs_rgblock_t */ + CT_RGNUMBER, /* xfs_rgno_t */ NCTS } ctype_t; @@ -80,6 +86,8 @@ typedef union { xfs_fileoff_t rbmblock; unsigned int rbmword; xfs_fileoff_t rsumblock; + xfs_rgnumber_t rgnumber; + xfs_rgblock_t rgblock; } cval_t; static uint64_t bytevalue(ctype_t ctype, cval_t *val); @@ -95,7 +103,7 @@ static const char *agnumber_names[] = { "agnumber", "agno", NULL }; static const char *bboff_names[] = { "bboff", "daddroff", NULL }; static const char *blkoff_names[] = { "blkoff", "fsboff", "agboff", NULL }; -static const char *rtblkoff_names[] = { "blkoff", "rtboff", +static const char *rtblkoff_names[] = { "blkoff", "rtboff", "rgboff", NULL }; static const char *byte_names[] = { "byte", "fsbyte", NULL }; static const char *daddr_names[] = { "daddr", "bb", NULL }; @@ -111,6 +119,8 @@ static const char *rbmword_names[] = { "rbmword", "rbmw", NULL }; static const char *rsumblock_names[] = { "rsumblock", "rsmb", NULL }; static const char *rsumlog_names[] = { "rsumlog", "rsml", NULL }; static const char *rsumword_names[] = { "rsuminfo", "rsmi", NULL }; +static const char *rgblock_names[] = { "rgblock", "rgbno", NULL }; +static const char *rgnumber_names[] = { "rgnumber", "rgno", NULL }; static int rsuminfo; static int rsumlog; @@ -208,6 +218,14 @@ static const ctydesc_t ctydescs_rt[NCTS] = { .allowed = M(RSUMBLOCK), .names = rsumword_names, }, + [CT_RGBLOCK] = { + .allowed = M(RGNUMBER)|M(BBOFF)|M(BLKOFF)|M(RSUMLOG), + .names = rgblock_names, + }, + [CT_RGNUMBER] = { + .allowed = M(RGBLOCK)|M(BBOFF)|M(BLKOFF)|M(RSUMLOG), + .names = rgnumber_names, + }, }; static const cmdinfo_t convert_cmd = @@ -295,6 +313,10 @@ bytevalue(ctype_t ctype, cval_t *val) * value. */ return 0; + case CT_RGBLOCK: + return rgblock_to_bytes(val->rgblock); + case CT_RGNUMBER: + return rgnumber_to_bytes(val->rgnumber); case CT_NONE: case NCTS: break; @@ -401,6 +423,8 @@ convert_f(int argc, char **argv) case CT_RSUMBLOCK: case CT_RSUMLOG: case CT_RSUMINFO: + case CT_RGBLOCK: + case CT_RGNUMBER: /* shouldn't get here */ ASSERT(0); break; @@ -537,6 +561,12 @@ rtconvert_f(int argc, char **argv) case CT_RSUMINFO: v = rt_daddr_to_rsuminfo(mp, v); break; + case CT_RGBLOCK: + v = xfs_daddr_to_rgbno(mp, v >> BBSHIFT); + break; + case CT_RGNUMBER: + v = xfs_daddr_to_rgno(mp, v >> BBSHIFT); + break; case CT_AGBLOCK: case CT_AGINO: case CT_AGNUMBER: @@ -629,6 +659,12 @@ getvalue(char *s, ctype_t ctype, cval_t *val) case CT_RSUMINFO: rsuminfo = (unsigned int)v; break; + case CT_RGBLOCK: + val->rgblock = (xfs_rgblock_t)v; + break; + case CT_RGNUMBER: + val->rgnumber = (xfs_rgnumber_t)v; + break; case CT_NONE: case NCTS: /* NOTREACHED */ diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8 index 9c1ce5d79cf..bcb4c871827 100644 --- a/man/man8/xfs_db.8 +++ b/man/man8/xfs_db.8 @@ -978,6 +978,16 @@ with alternate names, are: .RS 1.0i .PD 0 .HP +.B rgblock +or +.B rgbno +(realtime block within a realtime group) +.HP +.B rgnumber +or +.B rgno +(realtime group number) +.HP .B bboff or .B daddroff @@ -1045,6 +1055,13 @@ or .RE .IP Only conversions that "make sense" are allowed. +The compound form (with more than three arguments) is useful for +conversions such as +.B convert rgno +.I rg +.B rgbno +.I rgb +.BR rtblock . Realtime summary file location conversions have the following rules: Each info word in the rt summary file counts the number of free extents of a From patchwork Fri Dec 30 22:19:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085705 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 C4FDCC3DA7C for ; Sat, 31 Dec 2022 02:38:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236259AbiLaCid (ORCPT ); Fri, 30 Dec 2022 21:38:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236258AbiLaCiG (ORCPT ); Fri, 30 Dec 2022 21:38:06 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA2B22DED for ; Fri, 30 Dec 2022 18:38:05 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 8A68561CBF for ; Sat, 31 Dec 2022 02:38:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA892C433D2; Sat, 31 Dec 2022 02:38:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454285; bh=SINQRA3kHr1SgQG2ErBULF2vhqum+u7HDbCMXWZi2tY=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=C+A+nu/9yVeb6OI/j+wWb0ci9Zc+oTkZys+pVe3GIYMSUuJcTI4m+bcm+8TkhxcBA tPLCwS2Ko1eaAwcocI77svuQPCaQoPnNn2sNzd89+z2o5ft6/hONklic+D0PzQnJ9X yNal3v9PrvcVo37ZaQjy9ydWiUspF4nLhbejncc8zUQylniNC3nviMoMJqpbUuwvgl HXZnr8ItpqarL2sBDmqaqwQrLbtCpsdgKp0Bi9/yRm0TsL13ECZpf0PKji1A/Zpor8 CyaB0ztzrNCwEIJ9XL2LBuemO603aAWPomjfHvV3fM9AsH1Z1g/x7/3+cRODoogno2 R+4c3Zn2yqY9Q== Subject: [PATCH 31/45] xfs_db: report rtgroups via version command From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:47 -0800 Message-ID: <167243878771.731133.5565215367768506.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Report the rtgroups feature in the version command output. Signed-off-by: Darrick J. Wong --- db/sb.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/sb.c b/db/sb.c index 36d4c317dba..52c5edc065a 100644 --- a/db/sb.c +++ b/db/sb.c @@ -852,6 +852,8 @@ version_string( strcat(s, ",NREXT64"); if (xfs_has_metadir(mp)) strcat(s, ",METADIR"); + if (xfs_has_rtgroups(mp)) + strcat(s, ",RTGROUPS"); return s; } From patchwork Fri Dec 30 22:19:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085704 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 4B868C4708E for ; Sat, 31 Dec 2022 02:38:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236258AbiLaCie (ORCPT ); Fri, 30 Dec 2022 21:38:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236261AbiLaCiY (ORCPT ); Fri, 30 Dec 2022 21:38:24 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BA712DED for ; Fri, 30 Dec 2022 18:38:23 -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 D1105B81DEE for ; Sat, 31 Dec 2022 02:38:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88282C433D2; Sat, 31 Dec 2022 02:38:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454300; bh=fceC9LIb64WvlzguzBanyBZhBUJKwl+GwEkWysD59pc=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Rjdj9kvktXNI4newfmv7Eajinp/bDfrrZySzCsKmpU30jqL1LPR6l4W8Krbfz6jHm 8TGMslSMQxVPeF3dqR4Z8fznCdhVnAE1lkAOFUJq7nvc05MsyUcdEurxU5kUJqF7Rx E9cA5L+wC8pN+H4hfc4noc5x9C2a5mz50O5M6JqcxhG/JLlMy4uhcY9WBdp2HEOUy8 dldfsYoqkMTm8ChX1NoEyLvfl9Ib3C9/Q85EClXoMTMiE+2JrEMER5GWP4KEpB3WiR xK0zN0qulQiH0FRCn2fWbdpk1wBx73fwA8QKEB5wbSJEmzYBm9csnx8ExScbRGePaP JCp/HhavxID0A== Subject: [PATCH 32/45] xfs_db: metadump realtime devices From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:47 -0800 Message-ID: <167243878785.731133.2412483890968401567.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Teach the metadump device to dump the filesystem metadata of a realtime device to the metadump file. Currently, this is limited to the rt group superblocks. Signed-off-by: Darrick J. Wong --- db/metadump.c | 51 +++++++++++++++++++++++++++++++++++++++++++++-- db/xfs_metadump.sh | 5 +++-- man/man8/xfs_metadump.8 | 12 ++++++++++- 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/db/metadump.c b/db/metadump.c index f337493d505..e997c386c0b 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -3070,6 +3070,40 @@ _("Could not discern log; image will contain unobfuscated metadata in log.")); return !write_buf(iocur_top); } +static int +copy_rtsupers(void) +{ + int error; + + if (show_progress) + print_progress("Copying realtime superblocks"); + + xfs_rtblock_t rtbno; + xfs_rgnumber_t rgno = 0; + + for (rgno = 0; rgno < mp->m_sb.sb_rgcount; rgno++) { + rtbno = xfs_rgbno_to_rtb(mp, rgno, 0); + + push_cur(); + error = set_rt_cur(&typtab[TYP_RTSB], + xfs_rtb_to_daddr(mp, rtbno), + XFS_FSB_TO_BB(mp, 1), DB_RING_ADD, NULL); + if (error) + return 0; + if (iocur_top->data == NULL) { + pop_cur(); + print_warning("cannot read rt super %u", rgno); + return !stop_on_read_error; + } + error = write_buf(iocur_top); + pop_cur(); + if (error) + return 0; + } + + return 1; +} + static int metadump_f( int argc, @@ -3145,9 +3179,11 @@ metadump_f( /* * Use the old format if there are no external devices with metadata to - * dump. + * dump. Force the new format if we have realtime group superblocks. */ - if (mp->m_sb.sb_logstart != 0) + if (xfs_has_rtgroups(mp)) + copy_external = true; + else if (mp->m_sb.sb_logstart != 0 /* && !rtgroups */) copy_external = false; metablock = (xfs_metablock_t *)calloc(BBSIZE + 1, BBSIZE); @@ -3276,6 +3312,17 @@ metadump_f( exitcode = write_index() < 0; } + /* write the realtime device, if desired */ + if (!exitcode && xfs_has_rtgroups(mp) && copy_external) { + metablock->mb_info &= ~XFS_METADUMP_LOGDEV; + metablock->mb_info |= XFS_METADUMP_RTDEV; + + if (!copy_rtsupers()) + exitcode = 1; + if (!exitcode) + exitcode = write_index() < 0; + } + if (progress_since_warning) fputc('\n', stdout_metadump ? stderr : stdout); diff --git a/db/xfs_metadump.sh b/db/xfs_metadump.sh index 06bfc4e7bd4..29cced9f302 100755 --- a/db/xfs_metadump.sh +++ b/db/xfs_metadump.sh @@ -6,9 +6,9 @@ OPTS=" " DBOPTS=" " -USAGE="Usage: xfs_metadump [-aefFgoVwx] [-m max_extents] [-l logdev] source target" +USAGE="Usage: xfs_metadump [-aefFgoVwx] [-m max_extents] [-l logdev] [-R rtdev] source target" -while getopts "aefgl:m:owFVx" c +while getopts "aefgl:m:owFVxR:" c do case $c in a) OPTS=$OPTS"-a ";; @@ -25,6 +25,7 @@ do exit $status ;; x) OPTS=$OPTS"-x ";; + R) DBOPTS=$DBOPTS"-R "$OPTARG" ";; \?) echo $USAGE 1>&2 exit 2 ;; diff --git a/man/man8/xfs_metadump.8 b/man/man8/xfs_metadump.8 index b940cb084b5..98e822b39d0 100644 --- a/man/man8/xfs_metadump.8 +++ b/man/man8/xfs_metadump.8 @@ -11,6 +11,9 @@ xfs_metadump \- copy XFS filesystem metadata to a file ] [ .B \-l .I logdev +] [ +.B \-R +.I rtdev ] .I source .I target @@ -136,12 +139,19 @@ this value. The default size is 2097151 blocks. .B \-o Disables obfuscation of file names and extended attributes. .TP +.B \-R +For filesystems that have a realtime section, this specifies the device where +the realtime section resides. +To record the contents of the realtime section in the dump, the +.B \-x +option must also be specified. +.TP .B \-w Prints warnings of inconsistent metadata encountered to stderr. Bad metadata is still copied. .TP .B \-x -Dump the external log device, if present. +Dump the external log and realtime device, if present. The metadump file will not be compatible with older versions of .BR xfs_mdrestore (1). .TP From patchwork Fri Dec 30 22:19:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085706 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 A96E5C3DA7C for ; Sat, 31 Dec 2022 02:38:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236261AbiLaCik (ORCPT ); Fri, 30 Dec 2022 21:38:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236257AbiLaCik (ORCPT ); Fri, 30 Dec 2022 21:38:40 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDE38C760 for ; Fri, 30 Dec 2022 18:38:38 -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 87AD2B81E00 for ; Sat, 31 Dec 2022 02:38:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43ED9C433EF; Sat, 31 Dec 2022 02:38:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454316; bh=98a8o8At1AaincSMyMSjH8g0uUZ5tY4rnV42YUuCVDs=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=KbnuRHazInuaXPTM6p2863CmuBZvvgbLfRbzSTQoqB8K2172rdEbdSdALm5pZlSIL VKkiiAHrX3QF0ouwwxNhpkuZOE/yYUemSY2eJ+1pgv41qEmzmKggmUpH17wsOsyKi6 CxyKoGtna27nQHDloaKzarMaLCDGYSr3s52peLui6Mk8EyJNdfUWbnN+0A5VjLtUoe 6kL3Lhg7PIZbaPKwkea2wrK0M7whFXFzp7Ub2FDgF6nWD7BB2K7jil5kI/LwIfdMkX hyhv/8uyRFJ5N9ahCbYD+0ST2XO4W+TOFtGz53A0+lOzEc5c/C+zRR2sUK6sTIwhs2 XK2ZsbtrBOLog== Subject: [PATCH 33/45] xfs_db: dump rt bitmap blocks From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:48 -0800 Message-ID: <167243878798.731133.13215106479704174262.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Now that rtbitmap blocks have a header, make it so that xfs_db can analyze the structure. Signed-off-by: Darrick J. Wong --- db/bit.c | 24 +++++++++++++++++++----- db/bit.h | 1 + db/field.c | 5 +++++ db/field.h | 4 ++++ db/fprint.c | 11 +++++++++-- db/inode.c | 6 ++++-- db/rtgroup.c | 34 ++++++++++++++++++++++++++++++++++ db/rtgroup.h | 3 +++ db/type.c | 5 +++++ db/type.h | 1 + include/xfs_arch.h | 6 ++++++ 11 files changed, 91 insertions(+), 9 deletions(-) diff --git a/db/bit.c b/db/bit.c index c9bfd2eb025..84f46290b5a 100644 --- a/db/bit.c +++ b/db/bit.c @@ -55,6 +55,7 @@ getbitval( char *p; int64_t rval; int signext; + bool is_le = (flags & BV_LE); int z1, z2, z3, z4; ASSERT(nbits<=64); @@ -63,21 +64,34 @@ getbitval( bit = bitoffs(bitoff); signext = (flags & BVSIGNED) != 0; z4 = ((intptr_t)p & 0xf) == 0 && bit == 0; - if (nbits == 64 && z4) + if (nbits == 64 && z4) { + if (is_le) + return le64_to_cpu(*(__be64 *)p); return be64_to_cpu(*(__be64 *)p); + } z3 = ((intptr_t)p & 0x7) == 0 && bit == 0; if (nbits == 32 && z3) { - if (signext) + if (signext) { + if (is_le) + return (__s32)le32_to_cpu(*(__le32 *)p); return (__s32)be32_to_cpu(*(__be32 *)p); - else + } else { + if (is_le) + return (__u32)le32_to_cpu(*(__le32 *)p); return (__u32)be32_to_cpu(*(__be32 *)p); + } } z2 = ((intptr_t)p & 0x3) == 0 && bit == 0; if (nbits == 16 && z2) { - if (signext) + if (signext) { + if (is_le) + return (__s16)le16_to_cpu(*(__le16 *)p); return (__s16)be16_to_cpu(*(__be16 *)p); - else + } else { + if (is_le) + return (__u16)le16_to_cpu(*(__le16 *)p); return (__u16)be16_to_cpu(*(__be16 *)p); + } } z1 = ((intptr_t)p & 0x1) == 0 && bit == 0; if (nbits == 8 && z1) { diff --git a/db/bit.h b/db/bit.h index 4df86030abc..912283a7348 100644 --- a/db/bit.h +++ b/db/bit.h @@ -13,6 +13,7 @@ #define BVUNSIGNED 0 #define BVSIGNED 1 +#define BV_LE (1U << 1) /* little endian */ extern int64_t getbitval(void *obj, int bitoff, int nbits, int flags); extern void setbitval(void *obuf, int bitoff, int nbits, void *ibuf); diff --git a/db/field.c b/db/field.c index cee5c661595..7dee8c3735c 100644 --- a/db/field.c +++ b/db/field.c @@ -392,6 +392,11 @@ const ftattr_t ftattrtab[] = { { FLDT_UINT8X, "uint8x", fp_num, "%#x", SI(bitsz(uint8_t)), 0, NULL, NULL }, { FLDT_UUID, "uuid", fp_uuid, NULL, SI(bitsz(uuid_t)), 0, NULL, NULL }, + + { FLDT_RTWORD, "rtword", fp_num, "%#x", SI(bitsz(xfs_rtword_t)), + FTARG_LE, NULL, NULL }, + { FLDT_RGBITMAP, "rgbitmap", NULL, (char *)rgbitmap_flds, btblock_size, + FTARG_SIZE, NULL, rgbitmap_flds }, { FLDT_ZZZ, NULL } }; diff --git a/db/field.h b/db/field.h index 226753490ad..ce7e7297afa 100644 --- a/db/field.h +++ b/db/field.h @@ -191,6 +191,9 @@ typedef enum fldt { FLDT_UINT8O, FLDT_UINT8X, FLDT_UUID, + + FLDT_RTWORD, + FLDT_RGBITMAP, FLDT_ZZZ /* mark last entry */ } fldt_t; @@ -246,6 +249,7 @@ extern const ftattr_t ftattrtab[]; #define FTARG_SIZE 16 /* size field is a function */ #define FTARG_SKIPNMS 32 /* skip printing names this time */ #define FTARG_OKEMPTY 64 /* ok if this (union type) is empty */ +#define FTARG_LE (1U << 7) /* little endian */ extern int bitoffset(const field_t *f, void *obj, int startoff, int idx); diff --git a/db/fprint.c b/db/fprint.c index 65accfda3fe..ac916d511e8 100644 --- a/db/fprint.c +++ b/db/fprint.c @@ -68,13 +68,20 @@ fp_num( int bitpos; int i; int isnull; + int bvflags = 0; int64_t val; + if (arg & FTARG_LE) + bvflags |= BV_LE; + if (arg & FTARG_SIGNED) + bvflags |= BVSIGNED; + else + bvflags |= BVUNSIGNED; + for (i = 0, bitpos = bit; i < count && !seenint(); i++, bitpos += size) { - val = getbitval(obj, bitpos, size, - (arg & FTARG_SIGNED) ? BVSIGNED : BVUNSIGNED); + val = getbitval(obj, bitpos, size, bvflags); if ((arg & FTARG_SKIPZERO) && val == 0) continue; isnull = (arg & FTARG_SIGNED) || size == 64 ? diff --git a/db/inode.c b/db/inode.c index 4c2fd19f446..663487f8b14 100644 --- a/db/inode.c +++ b/db/inode.c @@ -642,9 +642,11 @@ inode_next_type(void) case S_IFLNK: return TYP_SYMLINK; case S_IFREG: - if (iocur_top->ino == mp->m_sb.sb_rbmino) + if (iocur_top->ino == mp->m_sb.sb_rbmino) { + if (xfs_has_rtgroups(mp)) + return TYP_RGBITMAP; return TYP_RTBITMAP; - else if (iocur_top->ino == mp->m_sb.sb_rsumino) + } else if (iocur_top->ino == mp->m_sb.sb_rsumino) return TYP_RTSUMMARY; else if (iocur_top->ino == mp->m_sb.sb_uquotino || iocur_top->ino == mp->m_sb.sb_gquotino || diff --git a/db/rtgroup.c b/db/rtgroup.c index c4debc1d394..350677d4687 100644 --- a/db/rtgroup.c +++ b/db/rtgroup.c @@ -54,6 +54,7 @@ const field_t rtsb_flds[] = { { "meta_uuid", FLDT_UUID, OI(OFF(meta_uuid)), C1, 0, TYP_NONE }, { NULL } }; +#undef OFF const field_t rtsb_hfld[] = { { "", FLDT_RTSB, OI(0), C1, 0, TYP_NONE }, @@ -113,3 +114,36 @@ rtsb_size( { return bitize(mp->m_sb.sb_blocksize); } + +static int +rtwords_count( + void *obj, + int startoff) +{ + unsigned int blksz = mp->m_sb.sb_blocksize; + + if (xfs_has_rtgroups(mp)) + blksz -= sizeof(struct xfs_rtbuf_blkinfo); + + return blksz >> XFS_WORDLOG; +} + +#define OFF(f) bitize(offsetof(struct xfs_rtbuf_blkinfo, rt_ ## f)) +const field_t rgbitmap_flds[] = { + { "magicnum", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE }, + { "crc", FLDT_CRC, OI(OFF(crc)), C1, 0, TYP_NONE }, + { "owner", FLDT_INO, OI(OFF(owner)), C1, 0, TYP_NONE }, + { "bno", FLDT_DFSBNO, OI(OFF(blkno)), C1, 0, TYP_BMAPBTD }, + { "lsn", FLDT_UINT64X, OI(OFF(lsn)), C1, 0, TYP_NONE }, + { "uuid", FLDT_UUID, OI(OFF(uuid)), C1, 0, TYP_NONE }, + /* the rtword array is after the actual structure */ + { "rtwords", FLDT_RTWORD, OI(bitize(sizeof(struct xfs_rtbuf_blkinfo))), + rtwords_count, FLD_ARRAY | FLD_COUNT, TYP_DATA }, + { NULL } +}; +#undef OFF + +const field_t rgbitmap_hfld[] = { + { "", FLDT_RGBITMAP, OI(0), C1, 0, TYP_NONE }, + { NULL } +}; diff --git a/db/rtgroup.h b/db/rtgroup.h index 49077bee141..3c9b16146fc 100644 --- a/db/rtgroup.h +++ b/db/rtgroup.h @@ -9,6 +9,9 @@ extern const struct field rtsb_flds[]; extern const struct field rtsb_hfld[]; +extern const struct field rgbitmap_flds[]; +extern const struct field rgbitmap_hfld[]; + extern void rtsb_init(void); extern int rtsb_size(void *obj, int startoff, int idx); diff --git a/db/type.c b/db/type.c index d875c0c6365..65e7b24146f 100644 --- a/db/type.c +++ b/db/type.c @@ -67,6 +67,7 @@ static const typ_t __typtab[] = { { TYP_TEXT, "text", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_FINOBT, "finobt", handle_struct, finobt_hfld, NULL, TYP_F_NO_CRC_OFF }, + { TYP_RGBITMAP, NULL }, { TYP_NONE, NULL } }; @@ -113,6 +114,8 @@ static const typ_t __typtab_crc[] = { { TYP_TEXT, "text", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_FINOBT, "finobt", handle_struct, finobt_crc_hfld, &xfs_finobt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, + { TYP_RGBITMAP, "rgbitmap", handle_struct, rgbitmap_hfld, + &xfs_rtbitmap_buf_ops, XFS_RTBUF_CRC_OFF }, { TYP_NONE, NULL } }; @@ -159,6 +162,8 @@ static const typ_t __typtab_spcrc[] = { { TYP_TEXT, "text", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_FINOBT, "finobt", handle_struct, finobt_spcrc_hfld, &xfs_finobt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, + { TYP_RGBITMAP, "rgbitmap", handle_struct, rgbitmap_hfld, + &xfs_rtbitmap_buf_ops, XFS_RTBUF_CRC_OFF }, { TYP_NONE, NULL } }; diff --git a/db/type.h b/db/type.h index d4efa4b0fab..e2148c6351d 100644 --- a/db/type.h +++ b/db/type.h @@ -35,6 +35,7 @@ typedef enum typnm TYP_SYMLINK, TYP_TEXT, TYP_FINOBT, + TYP_RGBITMAP, TYP_NONE } typnm_t; diff --git a/include/xfs_arch.h b/include/xfs_arch.h index d46ae47094a..6312e62b0a1 100644 --- a/include/xfs_arch.h +++ b/include/xfs_arch.h @@ -200,6 +200,9 @@ static __inline__ void __swab64s(__u64 *addr) ((__force __le32)___constant_swab32((__u32)(val))) #define __constant_cpu_to_be32(val) \ ((__force __be32)(__u32)(val)) + +#define le64_to_cpu(val) (__swab64((__force __u64)(__le64)(val))) +#define le16_to_cpu(val) (__swab16((__force __u16)(__le16)(val))) #else #define cpu_to_be16(val) ((__force __be16)__swab16((__u16)(val))) #define cpu_to_be32(val) ((__force __be32)__swab32((__u32)(val))) @@ -215,6 +218,9 @@ static __inline__ void __swab64s(__u64 *addr) ((__force __le32)(__u32)(val)) #define __constant_cpu_to_be32(val) \ ((__force __be32)___constant_swab32((__u32)(val))) + +#define le64_to_cpu(val) ((__force __u64)(__le64)(val)) +#define le16_to_cpu(val) ((__force __u16)(__le16)(val)) #endif static inline void be16_add_cpu(__be16 *a, __s16 b) From patchwork Fri Dec 30 22:19:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085707 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 54392C4332F for ; Sat, 31 Dec 2022 02:38:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236262AbiLaCi5 (ORCPT ); Fri, 30 Dec 2022 21:38:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236257AbiLaCix (ORCPT ); Fri, 30 Dec 2022 21:38:53 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D22082DED for ; Fri, 30 Dec 2022 18:38:52 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 71CC161CBF for ; Sat, 31 Dec 2022 02:38:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CABB9C433D2; Sat, 31 Dec 2022 02:38:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454331; bh=vH6blYqox946kruNcp57vOlcDZLfgcxfA7k6IFmypg4=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=HsjQ+Xp/hITiYa0DhW1jh/JfES/bKuWn3fad1z8jKoqNOGqKOTAhUa3MR2G3fQT+f ApckbUieRHS06F+sxGHl8qrqnN5HwHTNi6Bvc+XbLfhFmP86rreOdgvNcK0wzIJOE9 ztWRf0qdGie5Ahtj7dRocAvfQZcgTsI1R8nU00tSXWSNZOqBz3bTA7/oVdBMgdSB8D xgMTXmvWYWlP44umq/gM6nDpsuKX/o2GAgDbB+dlV8+DmUpg1VJ+I1ji42/Dme+r55 ZMWSonIojmaerV6dwxZ+HpWxlESdmElXJVA2TAkMJokXlUtEh7PhJK6vW1WDs8kylF Rsjm/2hYRyeig== Subject: [PATCH 34/45] xfs_db: dump rt summary blocks From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:48 -0800 Message-ID: <167243878811.731133.9363750288930278535.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Now that rtsummary blocks have a header, make it so that xfs_db can analyze the structure. Signed-off-by: Darrick J. Wong --- db/field.c | 5 +++++ db/field.h | 3 +++ db/inode.c | 5 ++++- db/rtgroup.c | 20 ++++++++++++++++++++ db/rtgroup.h | 3 +++ db/type.c | 5 +++++ db/type.h | 1 + 7 files changed, 41 insertions(+), 1 deletion(-) diff --git a/db/field.c b/db/field.c index 7dee8c3735c..4a6a4cf51c3 100644 --- a/db/field.c +++ b/db/field.c @@ -397,6 +397,11 @@ const ftattr_t ftattrtab[] = { FTARG_LE, NULL, NULL }, { FLDT_RGBITMAP, "rgbitmap", NULL, (char *)rgbitmap_flds, btblock_size, FTARG_SIZE, NULL, rgbitmap_flds }, + { FLDT_SUMINFO, "suminfo", fp_num, "%u", SI(bitsz(xfs_suminfo_t)), + 0, NULL, NULL }, + { FLDT_RGSUMMARY, "rgsummary", NULL, (char *)rgsummary_flds, + btblock_size, FTARG_SIZE, NULL, rgsummary_flds }, + { FLDT_ZZZ, NULL } }; diff --git a/db/field.h b/db/field.h index ce7e7297afa..e9c6142f282 100644 --- a/db/field.h +++ b/db/field.h @@ -194,6 +194,9 @@ typedef enum fldt { FLDT_RTWORD, FLDT_RGBITMAP, + FLDT_SUMINFO, + FLDT_RGSUMMARY, + FLDT_ZZZ /* mark last entry */ } fldt_t; diff --git a/db/inode.c b/db/inode.c index 663487f8b14..0b9dc617ba9 100644 --- a/db/inode.c +++ b/db/inode.c @@ -646,8 +646,11 @@ inode_next_type(void) if (xfs_has_rtgroups(mp)) return TYP_RGBITMAP; return TYP_RTBITMAP; - } else if (iocur_top->ino == mp->m_sb.sb_rsumino) + } else if (iocur_top->ino == mp->m_sb.sb_rsumino) { + if (xfs_has_rtgroups(mp)) + return TYP_RGSUMMARY; return TYP_RTSUMMARY; + } else if (iocur_top->ino == mp->m_sb.sb_uquotino || iocur_top->ino == mp->m_sb.sb_gquotino || iocur_top->ino == mp->m_sb.sb_pquotino) diff --git a/db/rtgroup.c b/db/rtgroup.c index 350677d4687..db1b9b595d5 100644 --- a/db/rtgroup.c +++ b/db/rtgroup.c @@ -147,3 +147,23 @@ const field_t rgbitmap_hfld[] = { { "", FLDT_RGBITMAP, OI(0), C1, 0, TYP_NONE }, { NULL } }; + +#define OFF(f) bitize(offsetof(struct xfs_rtbuf_blkinfo, rt_ ## f)) +const field_t rgsummary_flds[] = { + { "magicnum", FLDT_UINT32X, OI(OFF(magic)), C1, 0, TYP_NONE }, + { "crc", FLDT_CRC, OI(OFF(crc)), C1, 0, TYP_NONE }, + { "owner", FLDT_INO, OI(OFF(owner)), C1, 0, TYP_NONE }, + { "bno", FLDT_DFSBNO, OI(OFF(blkno)), C1, 0, TYP_BMAPBTD }, + { "lsn", FLDT_UINT64X, OI(OFF(lsn)), C1, 0, TYP_NONE }, + { "uuid", FLDT_UUID, OI(OFF(uuid)), C1, 0, TYP_NONE }, + /* the suminfo array is after the actual structure */ + { "suminfo", FLDT_SUMINFO, OI(bitize(sizeof(struct xfs_rtbuf_blkinfo))), + rtwords_count, FLD_ARRAY | FLD_COUNT, TYP_DATA }, + { NULL } +}; +#undef OFF + +const field_t rgsummary_hfld[] = { + { "", FLDT_RGSUMMARY, OI(0), C1, 0, TYP_NONE }, + { NULL } +}; diff --git a/db/rtgroup.h b/db/rtgroup.h index 3c9b16146fc..2e85d3587fe 100644 --- a/db/rtgroup.h +++ b/db/rtgroup.h @@ -12,6 +12,9 @@ extern const struct field rtsb_hfld[]; extern const struct field rgbitmap_flds[]; extern const struct field rgbitmap_hfld[]; +extern const struct field rgsummary_flds[]; +extern const struct field rgsummary_hfld[]; + extern void rtsb_init(void); extern int rtsb_size(void *obj, int startoff, int idx); diff --git a/db/type.c b/db/type.c index 65e7b24146f..2091b4ac8b1 100644 --- a/db/type.c +++ b/db/type.c @@ -68,6 +68,7 @@ static const typ_t __typtab[] = { { TYP_FINOBT, "finobt", handle_struct, finobt_hfld, NULL, TYP_F_NO_CRC_OFF }, { TYP_RGBITMAP, NULL }, + { TYP_RGSUMMARY, NULL }, { TYP_NONE, NULL } }; @@ -116,6 +117,8 @@ static const typ_t __typtab_crc[] = { &xfs_finobt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, { TYP_RGBITMAP, "rgbitmap", handle_struct, rgbitmap_hfld, &xfs_rtbitmap_buf_ops, XFS_RTBUF_CRC_OFF }, + { TYP_RGSUMMARY, "rgsummary", handle_struct, rgsummary_hfld, + &xfs_rtsummary_buf_ops, XFS_RTBUF_CRC_OFF }, { TYP_NONE, NULL } }; @@ -164,6 +167,8 @@ static const typ_t __typtab_spcrc[] = { &xfs_finobt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, { TYP_RGBITMAP, "rgbitmap", handle_struct, rgbitmap_hfld, &xfs_rtbitmap_buf_ops, XFS_RTBUF_CRC_OFF }, + { TYP_RGSUMMARY, "rgsummary", handle_struct, rgsummary_hfld, + &xfs_rtsummary_buf_ops, XFS_RTBUF_CRC_OFF }, { TYP_NONE, NULL } }; diff --git a/db/type.h b/db/type.h index e2148c6351d..e7f0ecc1768 100644 --- a/db/type.h +++ b/db/type.h @@ -36,6 +36,7 @@ typedef enum typnm TYP_TEXT, TYP_FINOBT, TYP_RGBITMAP, + TYP_RGSUMMARY, TYP_NONE } typnm_t; From patchwork Fri Dec 30 22:19:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085708 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 2EE6FC4332F for ; Sat, 31 Dec 2022 02:39:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236260AbiLaCjK (ORCPT ); Fri, 30 Dec 2022 21:39:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236257AbiLaCjJ (ORCPT ); Fri, 30 Dec 2022 21:39:09 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60C6D2DED for ; Fri, 30 Dec 2022 18:39:08 -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 dfw.source.kernel.org (Postfix) with ESMTPS id F2A1961CBF for ; Sat, 31 Dec 2022 02:39:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 658AEC433D2; Sat, 31 Dec 2022 02:39:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454347; bh=J9RYt16ZmbTbvNEa+O3+ANGGiqe1oWrOIjmuXlMgFkg=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=FjwsCpWgepS4t6jfw6gDwDe0tPcgtg+UA8jf4CHQqZJA+N1BvSHxujAdy6Yvh5YAO YBNw4hHmVdewwjX4/9537SzfmsAc+LhTUNZT9HgdFkKxJixzL1ZvQMxx9znocxD6wq wmaFD5JBmaDD52+Y3E8dMalMuFTgIwokUzgq9ZcgzvtIrydIiKlFOWugJmInUCtYf/ ZBv0d+r+K/5tSDDz77JA2dVaBmkuhPlqyYliFemMAyh/FkHR2aFYEhMkYBoWKauSWZ MK2bRNmE3yAuz/FJauaLIvqaoif5szkI0OR8COJcn2TCic0tpjzPKH8dIfIHhDQxb6 x/K1Qi2mGzQ+A== Subject: [PATCH 35/45] xfs_mdrestore: restore rt group superblocks to realtime device From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:48 -0800 Message-ID: <167243878823.731133.6732858030193291234.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Support restoring realtime device metadata to the realtime device, if the dumped filesystem had one. Signed-off-by: Darrick J. Wong --- man/man8/xfs_mdrestore.8 | 7 +++++++ mdrestore/xfs_mdrestore.c | 30 ++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/man/man8/xfs_mdrestore.8 b/man/man8/xfs_mdrestore.8 index 4626b98e749..4a6b335a380 100644 --- a/man/man8/xfs_mdrestore.8 +++ b/man/man8/xfs_mdrestore.8 @@ -7,6 +7,8 @@ xfs_mdrestore \- restores an XFS metadump image to a filesystem image .B \-gi ] [ .B \-l logdev +] [ +.B \-R rtdev ] .I source .I target @@ -15,6 +17,8 @@ xfs_mdrestore \- restores an XFS metadump image to a filesystem image .B \-i [ .B \-l logdev +] [ +.B \-R rtdev ] .I source .br @@ -57,6 +61,9 @@ Shows metadump information on stdout. If no is specified, exits after displaying information. Older metadumps man not include any descriptive information. .TP +.B \-R +Restore realtime device metadata to this device. +.TP .B \-V Prints the version number and exits. .SH DIAGNOSTICS diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c index 672010bcc6e..b75b30830ea 100644 --- a/mdrestore/xfs_mdrestore.c +++ b/mdrestore/xfs_mdrestore.c @@ -115,7 +115,8 @@ perform_restore( int dst_fd, int is_target_file, const struct xfs_metablock *mbp, - char *log_path) + char *log_path, + char *rtdev_path) { struct xfs_metablock *metablock; /* header + index + blocks */ __be64 *block_index; @@ -127,7 +128,7 @@ perform_restore( xfs_sb_t sb; int64_t bytes_read; int64_t mb_read = 0; - int log_fd = -1; + int log_fd = -1, rtdev_fd = -1; bool is_mdx; is_mdx = mbp->mb_magic == cpu_to_be32(XFS_MDX_MAGIC); @@ -201,9 +202,19 @@ perform_restore( write_fd = log_fd; } if (metablock->mb_info & XFS_METADUMP_RTDEV) { + int rtdev_is_file; + if (!is_mdx) fatal("rtdev set on an old style metadump?\n"); - fatal("rtdev not supported\n"); + if (rtdev_fd == -1) { + if (!rtdev_path) + fatal( + "metadump has rtdev contents but -R was not specified?\n"); + rtdev_fd = open_device(rtdev_path, &rtdev_is_file); + check_dev(rtdev_fd, rtdev_is_file, + sb.sb_rblocks * sb.sb_blocksize); + } + write_fd = rtdev_fd; } if (show_progress) { @@ -267,6 +278,8 @@ perform_restore( if (pwrite(dst_fd, block_buffer, sb.sb_sectsize, 0) < 0) fatal("error writing primary superblock: %s\n", strerror(errno)); + if (rtdev_fd >= 0) + close(rtdev_fd); if (log_fd >= 0) close(log_fd); @@ -276,7 +289,7 @@ perform_restore( static void usage(void) { - fprintf(stderr, "Usage: %s [-V] [-g] [-i] [-l logdev] source target\n", progname); + fprintf(stderr, "Usage: %s [-V] [-g] [-i] [-l logdev] [-R rtdev] source target\n", progname); exit(1); } @@ -286,6 +299,7 @@ main( char **argv) { char *log_path = NULL; + char *rtdev_path = NULL; FILE *src_f; int dst_fd; int c; @@ -294,7 +308,7 @@ main( progname = basename(argv[0]); - while ((c = getopt(argc, argv, "gl:iV")) != EOF) { + while ((c = getopt(argc, argv, "gl:iVR:")) != EOF) { switch (c) { case 'g': show_progress = 1; @@ -308,6 +322,9 @@ main( case 'V': printf("%s version %s\n", progname, VERSION); exit(0); + case 'R': + rtdev_path = optarg; + break; default: usage(); } @@ -363,7 +380,8 @@ main( /* check and open target */ dst_fd = open_device(argv[optind], &is_target_file); - perform_restore(src_f, dst_fd, is_target_file, &mb, log_path); + perform_restore(src_f, dst_fd, is_target_file, &mb, log_path, + rtdev_path); close(dst_fd); if (src_f != stdin) From patchwork Fri Dec 30 22:19:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085709 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 35F74C4332F for ; Sat, 31 Dec 2022 02:39:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236263AbiLaCj1 (ORCPT ); Fri, 30 Dec 2022 21:39:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236257AbiLaCj0 (ORCPT ); Fri, 30 Dec 2022 21:39:26 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84731BC95 for ; Fri, 30 Dec 2022 18:39:25 -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 3AEDFB81E04 for ; Sat, 31 Dec 2022 02:39:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2588C433D2; Sat, 31 Dec 2022 02:39:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454363; bh=TG5EGXuWwqgE0qA/pHaDpR3uRd3djMy9AJeBCDPNK84=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Q+XdMTFKjZDuFuixTh2DMG2sGq2vy0bX/l9OYnUsKn7bXQSAys74eZZ2SqpyQ6CZJ LirTw6T+wgUD8+TqAhbLCkALjN9sH+8OswH0O14KKmE/CuiIohtD6CIWQZDgvwZD/h 98elND7FXi60H5jrP+qr88pxjPd8FBHBCUXDbAceb7dm1T4ng6ru4WN/RrjEqcfYw3 feYCUebH0yCXmDHh/3/+Hedl4hD+ZVXhrpxxY3bqgWX+USyyq3DGHYzLEwYZFOzvP9 PNcDse5UoBREBtBqcvx7hoc/+wZbAxNRP6hEAP/cdwvitcn7PLbSjhza9f9gTHCVnc SvjH0f/QS3MmQ== Subject: [PATCH 36/45] xfs_io: add a command to display allocation group information From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:48 -0800 Message-ID: <167243878834.731133.914666716081594964.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Add a new 'aginfo' command to xfs_io so that we can display allocation group geometry. Signed-off-by: Darrick J. Wong --- io/Makefile | 2 - io/aginfo.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++ io/init.c | 1 io/io.h | 1 man/man8/xfs_io.8 | 12 +++++ 5 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 io/aginfo.c diff --git a/io/Makefile b/io/Makefile index aa0d216b25f..2b7748bfc13 100644 --- a/io/Makefile +++ b/io/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/include/builddefs LTCOMMAND = xfs_io LSRCFILES = xfs_bmap.sh xfs_freeze.sh xfs_mkfile.sh HFILES = init.h io.h -CFILES = init.c \ +CFILES = init.c aginfo.c \ attr.c bmap.c bulkstat.c crc32cselftest.c cowextsize.c encrypt.c \ file.c freeze.c fsync.c getrusage.c imap.c inject.c label.c link.c \ mmap.c open.c parent.c pread.c prealloc.c pwrite.c reflink.c \ diff --git a/io/aginfo.c b/io/aginfo.c new file mode 100644 index 00000000000..06e1cb7ba88 --- /dev/null +++ b/io/aginfo.c @@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2022 Oracle. + * All Rights Reserved. + */ +#include "platform_defs.h" +#include "libxfs.h" +#include "command.h" +#include "input.h" +#include "init.h" +#include "io.h" +#include "libfrog/logging.h" +#include "libfrog/paths.h" +#include "libfrog/fsgeom.h" + +static cmdinfo_t aginfo_cmd; + +static int +report_aginfo( + struct xfs_fd *xfd, + xfs_agnumber_t agno) +{ + struct xfs_ag_geometry ageo = { 0 }; + int ret; + + ret = -xfrog_ag_geometry(xfd->fd, agno, &ageo); + if (ret) { + xfrog_perror(ret, "aginfo"); + return 1; + } + + printf(_("AG: %u\n"), ageo.ag_number); + printf(_("Blocks: %u\n"), ageo.ag_length); + printf(_("Free Blocks: %u\n"), ageo.ag_freeblks); + printf(_("Inodes: %u\n"), ageo.ag_icount); + printf(_("Free Inodes: %u\n"), ageo.ag_ifree); + printf(_("Sick: 0x%x\n"), ageo.ag_sick); + printf(_("Checked: 0x%x\n"), ageo.ag_checked); + printf(_("Flags: 0x%x\n"), ageo.ag_flags); + + return 0; +} + +/* Display AG status. */ +static int +aginfo_f( + int argc, + char **argv) +{ + struct xfs_fd xfd = XFS_FD_INIT(file->fd); + unsigned long long x; + xfs_agnumber_t agno = NULLAGNUMBER; + int c; + int ret = 0; + + ret = -xfd_prepare_geometry(&xfd); + if (ret) { + xfrog_perror(ret, "xfd_prepare_geometry"); + exitcode = 1; + return 1; + } + + while ((c = getopt(argc, argv, "a:")) != EOF) { + switch (c) { + case 'a': + errno = 0; + x = strtoll(optarg, NULL, 10); + if (!errno && x >= NULLAGNUMBER) + errno = ERANGE; + if (errno) { + perror("aginfo"); + return 1; + } + agno = x; + break; + default: + return command_usage(&aginfo_cmd); + } + } + + if (agno != NULLAGNUMBER) { + ret = report_aginfo(&xfd, agno); + } else { + for (agno = 0; !ret && agno < xfd.fsgeom.agcount; agno++) { + ret = report_aginfo(&xfd, agno); + } + } + + return ret; +} + +static void +aginfo_help(void) +{ + printf(_( +"\n" +"Report allocation group geometry.\n" +"\n" +" -a agno -- Report on the given allocation group.\n" +"\n")); + +} + +static cmdinfo_t aginfo_cmd = { + .name = "aginfo", + .cfunc = aginfo_f, + .argmin = 0, + .argmax = -1, + .args = "[-a agno]", + .flags = CMD_NOMAP_OK, + .help = aginfo_help, +}; + +void +aginfo_init(void) +{ + aginfo_cmd.oneline = _("Get XFS allocation group state."); + add_command(&aginfo_cmd); +} diff --git a/io/init.c b/io/init.c index 96536a25a1f..78d7d04e7a6 100644 --- a/io/init.c +++ b/io/init.c @@ -44,6 +44,7 @@ init_cvtnum( static void init_commands(void) { + aginfo_init(); atomicupdate_init(); attr_init(); bmap_init(); diff --git a/io/io.h b/io/io.h index 1cfe8edc2db..77bedf5159d 100644 --- a/io/io.h +++ b/io/io.h @@ -189,3 +189,4 @@ extern void repair_init(void); extern void crc32cselftest_init(void); extern void bulkstat_init(void); extern void atomicupdate_init(void); +extern void aginfo_init(void); diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8 index 0c0b00b5712..95c63f32a2a 100644 --- a/man/man8/xfs_io.8 +++ b/man/man8/xfs_io.8 @@ -1545,7 +1545,17 @@ This option is not compatible with the flag. .RE .PD - +.TP +.BI "aginfo [ \-a " agno " ]" +Show information about or update the state of allocation groups. +.RE +.RS 1.0i +.PD 0 +.TP +.BI \-a +Act only on a specific allocation group. +.PD +.RE .SH OTHER COMMANDS .TP From patchwork Fri Dec 30 22:19:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085710 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 EBAB1C4332F for ; Sat, 31 Dec 2022 02:39:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236257AbiLaCjk (ORCPT ); Fri, 30 Dec 2022 21:39:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236264AbiLaCjk (ORCPT ); Fri, 30 Dec 2022 21:39:40 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F51A2DED for ; Fri, 30 Dec 2022 18:39:39 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 2EA7B61CC2 for ; Sat, 31 Dec 2022 02:39:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 892D2C433D2; Sat, 31 Dec 2022 02:39:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454378; bh=pzTidaFlatay0CJAF24UCRmTVsR6QzSsvS2mb5SwDiI=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=eZxM60SWmWNoTDhDVBEpTZwR+0Y1aXypBsUx0F9T8kr/SVDu9D0BFGpKoVm02xJsp LxJReAPRk2mJK7H95GVAnRZ4dnCAD6m23KRL3fC9eQ1bWen2LR1SE+AifJ0wiY5vBV cIwRGNh8b65NvN1ewbkz5P9JHh0a9n8GlAZyfexxSXQkRGLIRpOCsSQVEiIoq3LpTf St7fOSV8eEa4FTI8OPlulVo0Q9PWk/akus96iHtrNAVAydVPRvbOZwxWauCsxf8UnJ PY7zt1+UOdwVPtiVUKB7Fx3JQgwFDOSYleBKXNzyfXo+qOdFju+d0VuH5QlsdrFBQJ 0KvTNFxjmlM4A== Subject: [PATCH 37/45] xfs_io: add a command to display realtime group information From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:48 -0800 Message-ID: <167243878846.731133.13158073002533445714.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Add a new 'rginfo' command to xfs_io so that we can display realtime group geometry. Signed-off-by: Darrick J. Wong --- io/aginfo.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++ libfrog/fsgeom.c | 18 ++++++++++ libfrog/fsgeom.h | 2 + man/man8/xfs_io.8 | 11 ++++++ 4 files changed, 127 insertions(+) diff --git a/io/aginfo.c b/io/aginfo.c index 06e1cb7ba88..037af54b60c 100644 --- a/io/aginfo.c +++ b/io/aginfo.c @@ -14,6 +14,7 @@ #include "libfrog/fsgeom.h" static cmdinfo_t aginfo_cmd; +static cmdinfo_t rginfo_cmd; static int report_aginfo( @@ -111,9 +112,104 @@ static cmdinfo_t aginfo_cmd = { .help = aginfo_help, }; +static int +report_rginfo( + struct xfs_fd *xfd, + xfs_rgnumber_t rgno) +{ + struct xfs_rtgroup_geometry rgeo = { 0 }; + int ret; + + ret = -xfrog_rtgroup_geometry(xfd->fd, rgno, &rgeo); + if (ret) { + xfrog_perror(ret, "rginfo"); + return 1; + } + + printf(_("RG: %u\n"), rgeo.rg_number); + printf(_("Blocks: %u\n"), rgeo.rg_length); + printf(_("Sick: 0x%x\n"), rgeo.rg_sick); + printf(_("Checked: 0x%x\n"), rgeo.rg_checked); + printf(_("Flags: 0x%x\n"), rgeo.rg_flags); + + return 0; +} + +/* Display rtgroup status. */ +static int +rginfo_f( + int argc, + char **argv) +{ + struct xfs_fd xfd = XFS_FD_INIT(file->fd); + unsigned long long x; + xfs_rgnumber_t rgno = NULLRGNUMBER; + int c; + int ret = 0; + + ret = -xfd_prepare_geometry(&xfd); + if (ret) { + xfrog_perror(ret, "xfd_prepare_geometry"); + exitcode = 1; + return 1; + } + + while ((c = getopt(argc, argv, "r:")) != EOF) { + switch (c) { + case 'r': + errno = 0; + x = strtoll(optarg, NULL, 10); + if (!errno && x >= NULLRGNUMBER) + errno = ERANGE; + if (errno) { + perror("rginfo"); + return 1; + } + rgno = x; + break; + default: + return command_usage(&rginfo_cmd); + } + } + + if (rgno != NULLRGNUMBER) { + ret = report_rginfo(&xfd, rgno); + } else { + for (rgno = 0; !ret && rgno < xfd.fsgeom.rgcount; rgno++) { + ret = report_rginfo(&xfd, rgno); + } + } + + return ret; +} + +static void +rginfo_help(void) +{ + printf(_( +"\n" +"Report realtime group geometry.\n" +"\n" +" -r rgno -- Report on the given realtime group.\n" +"\n")); + +} + +static cmdinfo_t rginfo_cmd = { + .name = "rginfo", + .cfunc = rginfo_f, + .argmin = 0, + .argmax = -1, + .args = "[-r rgno]", + .flags = CMD_NOMAP_OK, + .help = rginfo_help, +}; + void aginfo_init(void) { aginfo_cmd.oneline = _("Get XFS allocation group state."); add_command(&aginfo_cmd); + rginfo_cmd.oneline = _("Get XFS realtime group state."); + add_command(&rginfo_cmd); } diff --git a/libfrog/fsgeom.c b/libfrog/fsgeom.c index 66e813a863f..5a89c3e3ca3 100644 --- a/libfrog/fsgeom.c +++ b/libfrog/fsgeom.c @@ -210,3 +210,21 @@ xfrog_ag_geometry( return -errno; return 0; } + +/* + * Try to obtain a rt group's geometry. Returns zero or a negative error code. + */ +int +xfrog_rtgroup_geometry( + int fd, + unsigned int rgno, + struct xfs_rtgroup_geometry *rgeo) +{ + int ret; + + rgeo->rg_number = rgno; + ret = ioctl(fd, XFS_IOC_RTGROUP_GEOMETRY, rgeo); + if (ret) + return -errno; + return 0; +} diff --git a/libfrog/fsgeom.h b/libfrog/fsgeom.h index bef864fce63..8c21b240bb2 100644 --- a/libfrog/fsgeom.h +++ b/libfrog/fsgeom.h @@ -9,6 +9,8 @@ void xfs_report_geom(struct xfs_fsop_geom *geo, const char *mntpoint, const char *logname, const char *rtname); int xfrog_geometry(int fd, struct xfs_fsop_geom *fsgeo); int xfrog_ag_geometry(int fd, unsigned int agno, struct xfs_ag_geometry *ageo); +int xfrog_rtgroup_geometry(int fd, unsigned int rgno, + struct xfs_rtgroup_geometry *rgeo); /* * Structure for recording whatever observations we want about the level of diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8 index 95c63f32a2a..16768275b5c 100644 --- a/man/man8/xfs_io.8 +++ b/man/man8/xfs_io.8 @@ -1556,6 +1556,17 @@ Show information about or update the state of allocation groups. Act only on a specific allocation group. .PD .RE +.TP +.BI "rginfo [ \-r " rgno " ]" +Show information about or update the state of realtime allocation groups. +.RE +.RS 1.0i +.PD 0 +.TP +.BI \-a +Act only on a specific realtime group. +.PD +.RE .SH OTHER COMMANDS .TP From patchwork Fri Dec 30 22:19:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085711 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 61088C4332F for ; Sat, 31 Dec 2022 02:39:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236264AbiLaCj4 (ORCPT ); Fri, 30 Dec 2022 21:39:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236164AbiLaCjz (ORCPT ); Fri, 30 Dec 2022 21:39:55 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B8182DED for ; Fri, 30 Dec 2022 18:39:55 -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 dfw.source.kernel.org (Postfix) with ESMTPS id AE7FC61CCF for ; Sat, 31 Dec 2022 02:39:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15D31C433D2; Sat, 31 Dec 2022 02:39:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454394; bh=O39Y4n7rhLCTqAdJSyUNYIm0gcM4UcYgZ0SWiCppngI=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=H+Tdu2i3+glfF9PXwamUY9DIpSDPPsNiw0eckUPou9Y+KeVl+5psawTwcjfSHJTQI PmtKgnxR9Y8bXspQJlbdlKVVdqen9oiyiOLb/sFg2EDBENIRUzCp7FbcoFB1BbOKSq wDcbg5c9WeizDBAhax7/q6LICs4chpoPIlTDQa6wYbgd6R4WjLSfSOIb/IJyB2isdy 4aYkwpiQlpX1/UKkereQWunRWOXA/QgAu1uk7Xl5ZrLbN9QFDiamuaBy8aChdyYq45 LvRTnAP9Y1dmzXslt1p1QvzyFLgdddAIrlQ1B0OYHCl7K6wPW81r+d7lq4o+p5aUZW qpC4aUnso8PUg== Subject: [PATCH 38/45] xfs_io: display rt group in verbose bmap output From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:48 -0800 Message-ID: <167243878860.731133.14232316103222149536.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Display the rt group number in the bmap -v output, just like we do for regular data files. Signed-off-by: Darrick J. Wong --- io/bmap.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/io/bmap.c b/io/bmap.c index 27383ca6037..a78e0c65440 100644 --- a/io/bmap.c +++ b/io/bmap.c @@ -264,9 +264,16 @@ bmap_f( foff_w = boff_w = aoff_w = MINRANGE_WIDTH; tot_w = MINTOT_WIDTH; - if (is_rt) - sunit = swidth = bbperag = 0; - else { + if (is_rt) { + if (fsgeo.rgcount == 0) { + bbperag = 0; + } else { + bbperag = (off64_t)fsgeo.rgblocks * + (off64_t)fsgeo.blocksize / BBSIZE; + } + sunit = 0; + swidth = 0; + } else { bbperag = (off64_t)fsgeo.agblocks * (off64_t)fsgeo.blocksize / BBSIZE; sunit = (fsgeo.sunit * fsgeo.blocksize) / BBSIZE; @@ -295,7 +302,7 @@ bmap_f( (long long)(map[i + 1].bmv_block + map[i + 1].bmv_length - 1LL)); boff_w = max(boff_w, strlen(bbuf)); - if (!is_rt) { + if (bbperag > 0) { agno = map[i + 1].bmv_block / bbperag; agoff = map[i + 1].bmv_block - (agno * bbperag); @@ -312,13 +319,20 @@ bmap_f( numlen(map[i+1].bmv_length, 10)); } } - agno_w = is_rt ? 0 : max(MINAG_WIDTH, numlen(fsgeo.agcount, 10)); + if (is_rt) { + if (fsgeo.rgcount > 0) + agno_w = max(MINAG_WIDTH, numlen(fsgeo.rgcount, 10)); + else + agno_w = 0; + } else { + agno_w = max(MINAG_WIDTH, numlen(fsgeo.agcount, 10)); + } printf("%4s: %-*s %-*s %*s %-*s %*s%s\n", _("EXT"), foff_w, _("FILE-OFFSET"), boff_w, is_rt ? _("RT-BLOCK-RANGE") : _("BLOCK-RANGE"), - agno_w, is_rt ? "" : _("AG"), - aoff_w, is_rt ? "" : _("AG-OFFSET"), + agno_w, is_rt ? (fsgeo.rgcount ? _("RG") : "") : _("AG"), + aoff_w, is_rt ? (fsgeo.rgcount ? _("RG-OFFSET") : "") : _("AG-OFFSET"), tot_w, _("TOTAL"), flg ? _(" FLAGS") : ""); for (i = 0; i < egcnt; i++) { @@ -377,7 +391,7 @@ bmap_f( map[i + 1].bmv_length - 1LL)); printf("%4d: %-*s %-*s", i, foff_w, rbuf, boff_w, bbuf); - if (!is_rt) { + if (bbperag > 0) { agno = map[i + 1].bmv_block / bbperag; agoff = map[i + 1].bmv_block - (agno * bbperag); From patchwork Fri Dec 30 22:19:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085712 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 5B46CC4332F for ; Sat, 31 Dec 2022 02:40:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236168AbiLaCkM (ORCPT ); Fri, 30 Dec 2022 21:40:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236164AbiLaCkL (ORCPT ); Fri, 30 Dec 2022 21:40:11 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B11B02DED for ; Fri, 30 Dec 2022 18:40:10 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 4BF8B61CCF for ; Sat, 31 Dec 2022 02:40:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7D47C433D2; Sat, 31 Dec 2022 02:40:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454409; bh=02GBLLvxLye5fdM6Ogk3SxhPv9oIBiNrBLWrwyERkRY=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Qmbiz4MZE9tjKaqV7hZc9UbuHr/AfMIjDc8CdVjAV16Ew+pJY4j3aQ/MYja6u/RMk 7PgD5GiM2a+ESaZ9/rffeOc48DmzzNK+3bw9JXs9eUr4bBc0asSEtMo57UDNHLS9ns xf/28iou07QnzlumctDewjBDWj9Sv3TsWVLE2BdXAw76GrSpsCSnJOB8C7poceovnR cuytYoXEY621T49kgkPPjj0VIHcMtSFfT3WoLLmlD35HR5hrZ97TeHRceixYA3op2D VTxMdUU6IlAh+TAaBK0E1nyUUUyPF+Y0PD0JTEqAkOZkJgmX2sFi1f68ID7y6d/bcb k7FBUV2KbX5XQ== Subject: [PATCH 39/45] xfs_io: display rt group in verbose fsmap output From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:48 -0800 Message-ID: <167243878873.731133.4190432176522703778.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Display the rt group number in the fsmap output, just like we do for regular data files. Signed-off-by: Darrick J. Wong --- io/fsmap.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/io/fsmap.c b/io/fsmap.c index 7db51847e2b..cb70f86cb96 100644 --- a/io/fsmap.c +++ b/io/fsmap.c @@ -14,6 +14,7 @@ static cmdinfo_t fsmap_cmd; static dev_t xfs_data_dev; +static dev_t xfs_rt_dev; static void fsmap_help(void) @@ -170,7 +171,7 @@ dump_map_verbose( unsigned long long i; struct fsmap *p; int agno; - off64_t agoff, bperag; + off64_t agoff, bperag, bperrtg; int foff_w, boff_w, aoff_w, tot_w, agno_w, own_w; int nr_w, dev_w; char rbuf[40], bbuf[40], abuf[40], obuf[40]; @@ -185,6 +186,8 @@ dump_map_verbose( tot_w = MINTOT_WIDTH; bperag = (off64_t)fsgeo->agblocks * (off64_t)fsgeo->blocksize; + bperrtg = (off64_t)fsgeo->rgblocks * + (off64_t)fsgeo->blocksize; sunit = (fsgeo->sunit * fsgeo->blocksize); swidth = (fsgeo->swidth * fsgeo->blocksize); @@ -243,6 +246,13 @@ dump_map_verbose( "(%lld..%lld)", (long long)BTOBBT(agoff), (long long)BTOBBT(agoff + p->fmr_length - 1)); + } else if (p->fmr_device == xfs_rt_dev && fsgeo->rgcount > 0) { + agno = p->fmr_physical / bperrtg; + agoff = p->fmr_physical - (agno * bperrtg); + snprintf(abuf, sizeof(abuf), + "(%lld..%lld)", + (long long)BTOBBT(agoff), + (long long)BTOBBT(agoff + p->fmr_length - 1)); } else abuf[0] = 0; aoff_w = max(aoff_w, strlen(abuf)); @@ -315,6 +325,16 @@ dump_map_verbose( snprintf(gbuf, sizeof(gbuf), "%lld", (long long)agno); + } else if (p->fmr_device == xfs_rt_dev && fsgeo->rgcount > 0) { + agno = p->fmr_physical / bperrtg; + agoff = p->fmr_physical - (agno * bperrtg); + snprintf(abuf, sizeof(abuf), + "(%lld..%lld)", + (long long)BTOBBT(agoff), + (long long)BTOBBT(agoff + p->fmr_length - 1)); + snprintf(gbuf, sizeof(gbuf), + "%lld", + (long long)agno); } else { abuf[0] = 0; gbuf[0] = 0; @@ -501,6 +521,7 @@ fsmap_f( } fs = fs_table_lookup(file->name, FS_MOUNT_POINT); xfs_data_dev = fs ? fs->fs_datadev : 0; + xfs_rt_dev = fs ? fs->fs_rtdev : 0; head->fmh_count = map_size; do { From patchwork Fri Dec 30 22:19:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085713 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 7948BC4332F for ; Sat, 31 Dec 2022 02:40:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236164AbiLaCk3 (ORCPT ); Fri, 30 Dec 2022 21:40:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231522AbiLaCk2 (ORCPT ); Fri, 30 Dec 2022 21:40:28 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE5F92DED for ; Fri, 30 Dec 2022 18:40:27 -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 81C80B81E0C for ; Sat, 31 Dec 2022 02:40:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CE68C433D2; Sat, 31 Dec 2022 02:40:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454425; bh=MWq86jyz4sFGWuwt1u9pH+YewCNsCkr1EPh6kjhrFnE=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=bHtCjIYCy4TSEWO3r3drwHUTJGhjG1x9x2+MNwt2kiTlQkxal6rrBUIPOhbC2Sk7M N8t2/sLaaBWegXklhNb7IzEy8/9YsM/mNQN1gvO/+kO13c5jchUj6ZRtUbdv+Ldfe0 Spji+c3tNR/WUlobM1bU7ZR1Jq2tAn59KozBP2pmVPx2vsaMDkITRwSpIuQWrtNsST tOZcLgijV3yxTo3yjCqK+mlTW1BQf5xFNDbk3RqotATIeMnsBIDAZ8zOZNOJaAjqSz bD0NnBOYJ7VQNnxFM8EbfTOBBA2YnID6p34LmwS6+ZoffxAhIopYOX+Tcwo5JvHr1+ 0Vlij9O5E64PA== Subject: [PATCH 40/45] xfs_spaceman: report on realtime group health From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:48 -0800 Message-ID: <167243878885.731133.6486251123997724666.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Add the realtime group status to the health reporting done by xfs_spaceman. Signed-off-by: Darrick J. Wong --- man/man8/xfs_spaceman.8 | 5 +++- spaceman/health.c | 59 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/man/man8/xfs_spaceman.8 b/man/man8/xfs_spaceman.8 index ece840d7300..837fc497f27 100644 --- a/man/man8/xfs_spaceman.8 +++ b/man/man8/xfs_spaceman.8 @@ -91,7 +91,7 @@ The output will have the same format that .BR "xfs_info" "(8)" prints when querying a filesystem. .TP -.BI "health [ \-a agno] [ \-c ] [ \-f ] [ \-i inum ] [ \-q ] [ paths ]" +.BI "health [ \-a agno] [ \-c ] [ \-f ] [ \-i inum ] [ \-q ] [ \-r rgno ] [ paths ]" Reports the health of the given group of filesystem metadata. .RS 1.0i .PD 0 @@ -114,6 +114,9 @@ Report on the health of a specific inode. .B \-q Report only unhealthy metadata. .TP +.B \-r +Report on the health of the given realtime group. +.TP .B paths Report on the health of the files at the given path. .PD diff --git a/spaceman/health.c b/spaceman/health.c index 12fb67bab28..928d92abb8c 100644 --- a/spaceman/health.c +++ b/spaceman/health.c @@ -134,6 +134,18 @@ static const struct flag_map ag_flags[] = { {0}, }; +static const struct flag_map rtgroup_flags[] = { + { + .mask = XFS_RTGROUP_GEOM_SICK_SUPER, + .descr = "superblock", + }, + { + .mask = XFS_RTGROUP_GEOM_SICK_BITMAP, + .descr = "realtime bitmap", + }, + {0}, +}; + static const struct flag_map inode_flags[] = { { .mask = XFS_BS_SICK_INODE, @@ -214,6 +226,25 @@ report_ag_sick( return 0; } +/* Report on a rt group's health. */ +static int +report_rtgroup_sick( + xfs_rgnumber_t rgno) +{ + struct xfs_rtgroup_geometry rgeo = { 0 }; + char descr[256]; + int ret; + + ret = -xfrog_rtgroup_geometry(file->xfd.fd, rgno, &rgeo); + if (ret) { + xfrog_perror(ret, "rtgroup_geometry"); + return 1; + } + snprintf(descr, sizeof(descr) - 1, _("rtgroup %u"), rgno); + report_sick(descr, rtgroup_flags, rgeo.rg_sick, rgeo.rg_checked); + return 0; +} + /* Report on an inode's health. */ static int report_inode_health( @@ -312,7 +343,7 @@ report_bulkstat_health( return error; } -#define OPT_STRING ("a:cfi:q") +#define OPT_STRING ("a:cfi:qr:") /* Report on health problems in XFS filesystem. */ static int @@ -322,6 +353,7 @@ health_f( { unsigned long long x; xfs_agnumber_t agno; + xfs_rgnumber_t rgno; bool default_report = true; int c; int ret; @@ -365,6 +397,17 @@ health_f( case 'q': quiet = true; break; + case 'r': + default_report = false; + errno = 0; + x = strtoll(optarg, NULL, 10); + if (!errno && x >= NULLRGNUMBER) + errno = ERANGE; + if (errno) { + perror("rtgroup health"); + return 1; + } + break; default: return command_usage(&health_cmd); } @@ -400,6 +443,12 @@ health_f( if (ret) return 1; break; + case 'r': + rgno = strtoll(optarg, NULL, 10); + ret = report_rtgroup_sick(rgno); + if (ret) + return 1; + break; default: break; } @@ -421,6 +470,11 @@ health_f( if (ret) return 1; } + for (rgno = 0; rgno < file->xfd.fsgeom.rgcount; rgno++) { + ret = report_rtgroup_sick(rgno); + if (ret) + return 1; + } if (comprehensive) { ret = report_bulkstat_health(NULLAGNUMBER); if (ret) @@ -450,6 +504,7 @@ health_help(void) " -f -- Report health of the overall filesystem.\n" " -i inum -- Report health of a given inode number.\n" " -q -- Only report unhealthy metadata.\n" +" -r rgno -- Report health of the given realtime group.\n" " paths -- Report health of the given file path.\n" "\n")); @@ -460,7 +515,7 @@ static cmdinfo_t health_cmd = { .cfunc = health_f, .argmin = 0, .argmax = -1, - .args = "[-a agno] [-c] [-f] [-i inum] [-q] [paths]", + .args = "[-a agno] [-c] [-f] [-i inum] [-q] [-r rgno] [paths]", .flags = CMD_FLAG_ONESHOT, .help = health_help, }; From patchwork Fri Dec 30 22:19:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085715 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 BF540C4332F for ; Sat, 31 Dec 2022 02:41:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231494AbiLaClB (ORCPT ); Fri, 30 Dec 2022 21:41:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231522AbiLaCko (ORCPT ); Fri, 30 Dec 2022 21:40:44 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87C82BD4 for ; Fri, 30 Dec 2022 18:40:43 -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 25D16B81E08 for ; Sat, 31 Dec 2022 02:40:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D96ABC433EF; Sat, 31 Dec 2022 02:40:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454440; bh=k1iOpzSfh1AiUNApi+5H7MbtsEZ3IA0yJW2dhzF7NzU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=k+HUJ9XXys/uxIc7u2+PcadVzzjp/KLXAf71mf3KzKCbE6AoJinVWpD/AL+0E2K3G NfBuJifTeqrpGpFqaYD7pSTSwujZJ8BlgfZOwn5PptqAgBg9udrZ1YG4yk0sK1m+vv f3rQSdXGj9a42qRgTM+MOXFeVwvEx8PGx1YBxvGGBvhPh/lTm7SbweScDgp/Pdouwx 82tFl8GCTvv4Ix8MwLtUY7lBLXtO3h/Qg1nmFAAWP/cty3bmtFmFyFaDQQ/9r5TvIW RZnzqNEF4HyJmcbC2K0kU7lehnSSIC4NrUhQNzAWTjD48ztbqTU3wcargeVDKQnecG i8DGqVO4hC9/A== Subject: [PATCH 41/45] xfs_scrub: scrub realtime allocation group metadata From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:49 -0800 Message-ID: <167243878898.731133.9688954837507947732.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Scan realtime group metadata as part of phase 2, just like we do for AG metadata. Signed-off-by: Darrick J. Wong --- scrub/phase2.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- scrub/scrub.h | 9 +++++ 2 files changed, 104 insertions(+), 2 deletions(-) diff --git a/scrub/phase2.c b/scrub/phase2.c index ebe3ad3ad5c..a224af11ed4 100644 --- a/scrub/phase2.c +++ b/scrub/phase2.c @@ -28,6 +28,14 @@ struct scan_ctl { pthread_mutex_t rbm_waitlock; bool rbm_done; + /* + * Control mechanism to signal that each group's scan of the rt bitmap + * file scan is done and wake up any waiters. + */ + pthread_cond_t rbm_group_wait; + pthread_mutex_t rbm_group_waitlock; + unsigned int rbm_group_count; + bool aborted; }; @@ -178,6 +186,48 @@ scan_metafile( } } +/* Scrub each rt group's metadata. */ +static void +scan_rtgroup_metadata( + struct workqueue *wq, + xfs_agnumber_t rgno, + void *arg) +{ + struct scrub_item sri; + struct scrub_ctx *ctx = (struct scrub_ctx *)wq->wq_ctx; + struct scan_ctl *sctl = arg; + char descr[DESCR_BUFSZ]; + int ret; + + if (sctl->aborted) + goto out; + + scrub_item_init_rtgroup(&sri, rgno); + snprintf(descr, DESCR_BUFSZ, _("rtgroup %u"), rgno); + + scrub_item_schedule_group(&sri, XFROG_SCRUB_GROUP_RTGROUP); + ret = scrub_item_check(ctx, &sri); + if (ret) { + sctl->aborted = true; + goto out; + } + + /* Everything else gets fixed during phase 4. */ + ret = defer_fs_repair(ctx, &sri); + if (ret) { + sctl->aborted = true; + goto out; + } + +out: + /* Signal anybody waiting for the group bitmap scan to finish. */ + pthread_mutex_lock(&sctl->rbm_group_waitlock); + sctl->rbm_group_count--; + if (sctl->rbm_group_count == 0) + pthread_cond_broadcast(&sctl->rbm_group_wait); + pthread_mutex_unlock(&sctl->rbm_group_waitlock); +} + /* Scan all filesystem metadata. */ int phase2_func( @@ -191,6 +241,7 @@ phase2_func( struct scrub_item sri; const struct xfrog_scrub_descr *sc = xfrog_scrubbers; xfs_agnumber_t agno; + xfs_rgnumber_t rgno; unsigned int type; int ret, ret2; @@ -256,8 +307,10 @@ phase2_func( goto out_wq; /* - * Wait for the rt bitmap to finish scanning, then scan the rt summary - * since the summary can be regenerated completely from the bitmap. + * Wait for the rt bitmap to finish scanning, then scan the realtime + * group metadata. When rtgroups are enabled, the RTBITMAP scanner + * only checks the inode and fork data of the rt bitmap file, and each + * group checks its own part of the rtbitmap. */ ret = pthread_mutex_lock(&sctl.rbm_waitlock); if (ret) { @@ -274,6 +327,46 @@ phase2_func( } pthread_mutex_unlock(&sctl.rbm_waitlock); + if (sctl.aborted) + goto out_wq; + + for (rgno = 0; + rgno < ctx->mnt.fsgeom.rgcount && !sctl.aborted; + rgno++) { + pthread_mutex_lock(&sctl.rbm_group_waitlock); + sctl.rbm_group_count++; + pthread_mutex_unlock(&sctl.rbm_group_waitlock); + ret = -workqueue_add(&wq, scan_rtgroup_metadata, rgno, &sctl); + if (ret) { + str_liberror(ctx, ret, + _("queueing rtgroup scrub work")); + goto out_wq; + } + } + + if (sctl.aborted) + goto out_wq; + + /* + * Wait for the rtgroups to finish scanning, then scan the rt summary + * since the summary can be regenerated completely from the bitmap. + */ + ret = pthread_mutex_lock(&sctl.rbm_group_waitlock); + if (ret) { + str_liberror(ctx, ret, _("waiting for rtgroup scrubbers")); + goto out_wq; + } + if (sctl.rbm_group_count > 0) { + ret = pthread_cond_wait(&sctl.rbm_group_wait, + &sctl.rbm_group_waitlock); + if (ret) { + str_liberror(ctx, ret, + _("waiting for rtgroup scrubbers")); + goto out_wq; + } + } + pthread_mutex_unlock(&sctl.rbm_group_waitlock); + if (sctl.aborted) goto out_wq; diff --git a/scrub/scrub.h b/scrub/scrub.h index 53354099c81..b7e6173f8fa 100644 --- a/scrub/scrub.h +++ b/scrub/scrub.h @@ -87,6 +87,15 @@ scrub_item_init_ag(struct scrub_item *sri, xfs_agnumber_t agno) sri->sri_gen = -1U; } +static inline void +scrub_item_init_rtgroup(struct scrub_item *sri, xfs_rgnumber_t rgno) +{ + memset(sri, 0, sizeof(*sri)); + sri->sri_agno = rgno; + sri->sri_ino = -1ULL; + sri->sri_gen = -1U; +} + static inline void scrub_item_init_fs(struct scrub_item *sri) { From patchwork Fri Dec 30 22:19:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085714 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 F0AF8C3DA7C for ; Sat, 31 Dec 2022 02:41:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231522AbiLaClD (ORCPT ); Fri, 30 Dec 2022 21:41:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236169AbiLaClB (ORCPT ); Fri, 30 Dec 2022 21:41:01 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDB2D62FD for ; Fri, 30 Dec 2022 18:40:59 -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 sin.source.kernel.org (Postfix) with ESMTPS id 28B88CE1A06 for ; Sat, 31 Dec 2022 02:40:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6634BC433D2; Sat, 31 Dec 2022 02:40:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454456; bh=qBbU7P2UGSbrLYvWzT5xFtb9AgVtPubHpTp9ZhA1g54=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=ulX+7w/VYmnWIzjpaMtDAKB1OegtzNwEMMHtHTMHgwScD+UwuWg6bXwgU3tg1ZFWh xQKhacCCUPeg2zqj8k8AwpRpThhE3YqkP6kgBIm0M4Vb0yJn/peFU1Mpqh5p6YdUIe eGSTm35NYdljr3lqD/74Ylw/eNPOmGLYgOFIVaWMIvCMxba40Ztv22QVeVRK6jUGrY VIMhfjx1Wtv5yjfwLpWMq/wm8swq/gLnB8VQWaJfmKZhYnpUEx9B8nbYldz6axwGod ZCMoU3ewK34ADvx/1IflLgJ1tX8wZCDsmAu6P8Du51MWFKzQ6EyirKlVPC6MhluuaT 2RAVmjBI0jDUA== Subject: [PATCH 42/45] xfs_scrub: fstrim each rtgroup in parallel From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:49 -0800 Message-ID: <167243878911.731133.1130139562119311184.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Signed-off-by: Darrick J. Wong --- libfrog/fsgeom.h | 21 +++++++++++++++++++++ scrub/phase8.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/libfrog/fsgeom.h b/libfrog/fsgeom.h index 8c21b240bb2..6c6d6bb815a 100644 --- a/libfrog/fsgeom.h +++ b/libfrog/fsgeom.h @@ -203,4 +203,25 @@ cvt_b_to_agbno( return cvt_daddr_to_agbno(xfd, cvt_btobbt(byteno)); } +/* Convert rtgroup number and rtgroup block to fs block number */ +static inline uint64_t +cvt_rgbno_to_daddr( + struct xfs_fd *xfd, + uint32_t rgno, + uint32_t rgbno) +{ + return cvt_off_fsb_to_bb(xfd, + (uint64_t)rgno * xfd->fsgeom.rgblocks + rgbno); +} + +/* Convert rtgroup number and rtgroup block to a byte location on disk. */ +static inline uint64_t +cvt_rgbno_to_b( + struct xfs_fd *xfd, + xfs_rgnumber_t rgno, + xfs_rgblock_t rgbno) +{ + return cvt_bbtob(cvt_rgbno_to_daddr(xfd, rgno, rgbno)); +} + #endif /* __LIBFROG_FSGEOM_H__ */ diff --git a/scrub/phase8.c b/scrub/phase8.c index a8ea8db706b..cc4901f8614 100644 --- a/scrub/phase8.c +++ b/scrub/phase8.c @@ -48,6 +48,7 @@ fstrim_ok( struct trim_ctl { uint64_t datadev_end_pos; + uint64_t rtdev_end_pos; bool aborted; }; @@ -80,6 +81,35 @@ trim_ag( progress_add(1); } +/* Trim each rt group. */ +static void +trim_rtgroup( + struct workqueue *wq, + xfs_agnumber_t rgno, + void *arg) +{ + struct scrub_ctx *ctx = (struct scrub_ctx *)wq->wq_ctx; + struct trim_ctl *tctl = arg; + uint64_t pos, len, eortg_pos; + int error; + + pos = cvt_rgbno_to_b(&ctx->mnt, rgno, 0); + eortg_pos = cvt_rgbno_to_b(&ctx->mnt, rgno, ctx->mnt.fsgeom.rgblocks); + len = min(tctl->rtdev_end_pos, eortg_pos) - pos; + + error = fstrim(ctx, pos + tctl->datadev_end_pos, len); + if (error) { + char descr[DESCR_BUFSZ]; + + snprintf(descr, sizeof(descr) - 1, _("fstrim rgno %u"), rgno); + str_liberror(ctx, error, descr); + tctl->aborted = true; + return; + } + + progress_add(1); +} + /* Trim the filesystem, if desired. */ int phase8_func( @@ -97,6 +127,8 @@ phase8_func( tctl.datadev_end_pos = cvt_off_fsb_to_b(&ctx->mnt, ctx->mnt.fsgeom.datablocks); + tctl.rtdev_end_pos = cvt_off_fsb_to_b(&ctx->mnt, + ctx->mnt.fsgeom.rtblocks); error = -workqueue_create(&wq, (struct xfs_mount *)ctx, disk_heads(ctx->datadev)); @@ -117,6 +149,18 @@ phase8_func( } } + /* Trim each rtgroup in parallel. */ + for (agno = 0; + agno < ctx->mnt.fsgeom.rgcount && !tctl.aborted; + agno++) { + error = -workqueue_add(&wq, trim_rtgroup, agno, &tctl); + if (error) { + str_liberror(ctx, error, + _("queueing per-rtgroup fstrim work")); + goto out_wq; + } + } + out_wq: err2 = -workqueue_terminate(&wq); if (err2) { @@ -142,7 +186,7 @@ phase8_estimate( *items = 0; if (fstrim_ok(ctx)) - *items = ctx->mnt.fsgeom.agcount; + *items = ctx->mnt.fsgeom.agcount + ctx->mnt.fsgeom.rgcount; *nr_threads = disk_heads(ctx->datadev); *rshift = 0; From patchwork Fri Dec 30 22:19:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085716 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 D998AC4332F for ; Sat, 31 Dec 2022 02:41:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236169AbiLaClQ (ORCPT ); Fri, 30 Dec 2022 21:41:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236173AbiLaClO (ORCPT ); Fri, 30 Dec 2022 21:41:14 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1D72DF0C for ; Fri, 30 Dec 2022 18:41:12 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 8F7EE61CBF for ; Sat, 31 Dec 2022 02:41:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC259C433D2; Sat, 31 Dec 2022 02:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454472; bh=ckFPZwwSFTTIdeK98JTDtIW3LMR6YBuCnLS4yTXiAOc=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=RBExLAC71ac4W75LYsnJ1BNyUBodck51tDOpgp0mz3rrEZeK+EWoICJ/pHta7MXmr yZy1tsmH814t8KjtzaGp/Zdi5CcWU7MB9AvasQbdcI7EEegrW1TUaWohLVy8vzV10F vBbYhqRiY2u5ytKOlcdODLqUJrMdiED1VTIY3Y1VO415kM+j2hOcIzn6bRKWFn/RmC 4C1TO+/mH04g6tGFYIPvbCDrsczoJewhlAvG1VBhiCpZS5C47HqT1/kSDAXdoK7pYc ujONb76XJIzab9U9dQ62vUv1FfhUkeqCEbxHa3hSeUJ9R0go/KBu+EWYsm62qPhMO7 knDJ4AxkuLgCw== Subject: [PATCH 43/45] mkfs: add headers to realtime bitmap blocks From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:49 -0800 Message-ID: <167243878925.731133.17838280747426031006.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong When the rtgroups feature is enabled, format rtbitmap blocks with the appropriate block headers. Signed-off-by: Darrick J. Wong --- mkfs/proto.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ mkfs/xfs_mkfs.c | 6 +++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/mkfs/proto.c b/mkfs/proto.c index 21fe2c7f972..daf0d419bce 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -813,6 +813,50 @@ rtsummary_create( libxfs_imeta_end_update(mp, &upd, 0); } +/* Initialize block headers of rt free space files. */ +static int +init_rtblock_headers( + struct xfs_inode *ip, + xfs_fileoff_t nrblocks, + const struct xfs_buf_ops *ops, + uint32_t magic) +{ + struct xfs_bmbt_irec map; + struct xfs_mount *mp = ip->i_mount; + struct xfs_rtbuf_blkinfo *hdr; + xfs_fileoff_t off = 0; + int error; + + while (off < nrblocks) { + struct xfs_buf *bp; + xfs_daddr_t daddr; + int nimaps = 1; + + error = -libxfs_bmapi_read(ip, off, 1, &map, &nimaps, 0); + if (error) + return error; + + daddr = XFS_FSB_TO_DADDR(mp, map.br_startblock); + error = -libxfs_buf_get(mp->m_ddev_targp, daddr, + XFS_FSB_TO_BB(mp, map.br_blockcount), &bp); + if (error) + return error; + + bp->b_ops = ops; + hdr = bp->b_addr; + hdr->rt_magic = cpu_to_be32(magic); + hdr->rt_owner = cpu_to_be64(ip->i_ino); + hdr->rt_blkno = cpu_to_be64(daddr); + platform_uuid_copy(&hdr->rt_uuid, &mp->m_sb.sb_meta_uuid); + libxfs_buf_mark_dirty(bp); + libxfs_buf_relse(bp); + + off = map.br_startoff + map.br_blockcount; + } + + return 0; +} + /* Zero the realtime bitmap. */ static void rtbitmap_init( @@ -856,6 +900,13 @@ rtbitmap_init( if (error) fail(_("Block allocation of the realtime bitmap inode failed"), error); + + if (xfs_has_rtgroups(mp)) { + error = init_rtblock_headers(mp->m_rbmip, mp->m_sb.sb_rbmblocks, + &xfs_rtbitmap_buf_ops, XFS_RTBITMAP_MAGIC); + if (error) + fail(_("Initialization of rtbitmap failed"), error); + } } /* Zero the realtime summary file. */ diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 0324daaad3a..826f9e53309 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -870,6 +870,7 @@ struct sb_feat_args { bool nodalign; bool nortalign; bool nrext64; + bool rtgroups; /* XFS_SB_FEAT_COMPAT_RTGROUPS */ }; struct cli_params { @@ -3065,6 +3066,7 @@ validate_rtdev( char **devname) { struct libxfs_xinit *xi = cli->xi; + unsigned int rbmblocksize = cfg->blocksize; *devname = NULL; @@ -3112,8 +3114,10 @@ reported by the device (%u).\n"), } cfg->rtextents = cfg->rtblocks / cfg->rtextblocks; + if (cfg->sb_feat.rtgroups) + rbmblocksize -= sizeof(struct xfs_rtbuf_blkinfo); cfg->rtbmblocks = (xfs_extlen_t)howmany(cfg->rtextents, - NBBY * cfg->blocksize); + NBBY * rbmblocksize); } static bool From patchwork Fri Dec 30 22:19:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085717 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 60F83C3DA7C for ; Sat, 31 Dec 2022 02:41:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236173AbiLaClc (ORCPT ); Fri, 30 Dec 2022 21:41:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236171AbiLaClb (ORCPT ); Fri, 30 Dec 2022 21:41:31 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 080AF2DED for ; Fri, 30 Dec 2022 18:41:31 -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 sin.source.kernel.org (Postfix) with ESMTPS id 4D59ECE1A8E for ; Sat, 31 Dec 2022 02:41:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90EC1C433EF; Sat, 31 Dec 2022 02:41:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454487; bh=Gfb528qmR1QPxoFi0BjY7OD5pFuor8jZpjkLr0UiJ3s=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=BPC6uzfb4GU3uJ8Fb80v2zh186Ck7puV+nH6tlOWS5azc1ZsExNJNRFTt6OpKOxNo jAaf3RR6E1zLxnetPyv0Uf1rWCZXkBO5Uf/roh7fLxxun/NRHxZ7YjOEZeRHQfrrs8 pWLvM0efdu1UJl+MMRQaIKwNfda1164RX2oepx45bDZOuJFuoCmEP5f3mkaOj1BjGN HBbJHVYuLuu5SoZLqkSHR+yLZGqCu8AbLZyMmntMTMFuq2//GAaXqitZxN4/8XsSyL eqq0zamkpdkEqr6c6wA5fId735uMVhpHKdkfCs8zN+zwd0PI4z/OKLyjpt2mOjeOxm bhgR1JRpp7dzw== Subject: [PATCH 44/45] mkfs: add headers to realtime summary blocks From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:49 -0800 Message-ID: <167243878938.731133.3080262804421732994.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong When the rtgroups feature is enabled, format rtsummary blocks with the appropriate block headers. Signed-off-by: Darrick J. Wong --- mkfs/proto.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mkfs/proto.c b/mkfs/proto.c index daf0d419bce..846b48ec789 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -953,6 +953,14 @@ rtsummary_init( if (error) fail(_("Block allocation of the realtime summary inode failed"), error); + + if (xfs_has_rtgroups(mp)) { + error = init_rtblock_headers(mp->m_rsumip, + XFS_B_TO_FSB(mp, mp->m_rsumsize), + &xfs_rtsummary_buf_ops, XFS_RTSUMMARY_MAGIC); + if (error) + fail(_("Initialization of rtsummary failed"), error); + } } /* From patchwork Fri Dec 30 22:19:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085718 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 9EE0AC4332F for ; Sat, 31 Dec 2022 02:41:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236171AbiLaClu (ORCPT ); Fri, 30 Dec 2022 21:41:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236092AbiLaClr (ORCPT ); Fri, 30 Dec 2022 21:41:47 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA0EB2DED for ; Fri, 30 Dec 2022 18:41:45 -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 71AB6B81E11 for ; Sat, 31 Dec 2022 02:41:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29CFCC433EF; Sat, 31 Dec 2022 02:41:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672454503; bh=wWGAc8PwwMhT0LFXrLAVfjSYl0MYX/JYt2sKeU7bLTU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=jl+gAYIfGOQ0EaB3HsXvJ/sE64kSm6bSJoo0xOXtiNAdnozCU/ELUGM+9FIv4fdJ7 dqbyJNMLGq9teNYuMbnUIsva7kINufoO+L70FJ7czql1VxSB558gSo3MiPFR6dHLW8 z7dFOKdV/ReNmMybwInUIBvw1HXFIWWEPq4yDi4lFK+eV5bvyO/vXsipJBSeW/OtH3 Cjvx6z2OWltDBqEz+HT59uA9fOy/N67KR78NnQm+hcfs+Ah/R+xFp7zDtbcOr3+XUk htBCqW0UnmeqSKhrJpW8sZI2JahPxQfR3rWuJPpb501AoBT+t1fbG+Sr26udtOC0Tn cIoRNW8hYWsRw== Subject: [PATCH 45/45] mkfs: format realtime groups From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:49 -0800 Message-ID: <167243878952.731133.10167956328943868756.stgit@magnolia> In-Reply-To: <167243878346.731133.14642166452774753637.stgit@magnolia> References: <167243878346.731133.14642166452774753637.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Create filesystems with the realtime group feature enabled. Signed-off-by: Darrick J. Wong --- libfrog/div64.h | 6 + libfrog/util.c | 12 ++ libfrog/util.h | 1 libxfs/libxfs_api_defs.h | 1 libxfs/libxfs_priv.h | 6 - libxfs/topology.c | 42 +++++++ libxfs/topology.h | 3 + libxfs/xfs_format.h | 1 man/man8/mkfs.xfs.8.in | 44 +++++++ mkfs/proto.c | 45 +++++++- mkfs/xfs_mkfs.c | 272 ++++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 425 insertions(+), 8 deletions(-) diff --git a/libfrog/div64.h b/libfrog/div64.h index 9317b28aad4..0ce8b747938 100644 --- a/libfrog/div64.h +++ b/libfrog/div64.h @@ -80,4 +80,10 @@ roundup_64(uint64_t x, uint32_t y) return x * y; } +static inline __attribute__((const)) +int is_power_of_2(unsigned long n) +{ + return (n != 0 && ((n & (n - 1)) == 0)); +} + #endif /* LIBFROG_DIV64_H_ */ diff --git a/libfrog/util.c b/libfrog/util.c index 46047571a55..4e130c884c1 100644 --- a/libfrog/util.c +++ b/libfrog/util.c @@ -36,3 +36,15 @@ memchr_inv(const void *start, int c, size_t bytes) return NULL; } + +unsigned int +log2_rounddown(unsigned long long i) +{ + int rval; + + for (rval = NBBY * sizeof(i) - 1; rval >= 0; rval--) { + if ((1ULL << rval) < i) + break; + } + return rval; +} diff --git a/libfrog/util.h b/libfrog/util.h index ac2f331c93e..b0715576e8d 100644 --- a/libfrog/util.h +++ b/libfrog/util.h @@ -7,6 +7,7 @@ #define __LIBFROG_UTIL_H__ unsigned int log2_roundup(unsigned int i); +unsigned int log2_rounddown(unsigned long long i); void *memchr_inv(const void *start, int c, size_t bytes); diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index deadfe2c422..715df25f18b 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -73,6 +73,7 @@ #define xfs_btree_update libxfs_btree_update #define xfs_btree_space_to_height libxfs_btree_space_to_height #define xfs_btree_visit_blocks libxfs_btree_visit_blocks +#define xfs_buf_delwri_queue libxfs_buf_delwri_queue #define xfs_buf_delwri_submit libxfs_buf_delwri_submit #define xfs_buf_get libxfs_buf_get #define xfs_buf_get_uncached libxfs_buf_get_uncached diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index 57b92ac1b99..66b9409a0b0 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -334,12 +334,6 @@ find_next_zero_bit(const unsigned long *addr, unsigned long size, } #define find_first_zero_bit(addr, size) find_next_zero_bit((addr), (size), 0) -static inline __attribute__((const)) -int is_power_of_2(unsigned long n) -{ - return (n != 0 && ((n & (n - 1)) == 0)); -} - /* * xfs_iroundup: round up argument to next power of two */ diff --git a/libxfs/topology.c b/libxfs/topology.c index a17c19691a4..75c6164887f 100644 --- a/libxfs/topology.c +++ b/libxfs/topology.c @@ -89,6 +89,48 @@ calc_default_ag_geometry( *agcount = dblocks / blocks + (dblocks % blocks != 0); } +void +calc_default_rtgroup_geometry( + int blocklog, + uint64_t rblocks, + uint64_t *rgsize, + uint64_t *rgcount) +{ + uint64_t blocks = 0; + int shift = 0; + + /* + * For a single underlying storage device over 4TB in size use the + * maximum rtgroup size. Between 128MB and 4TB, just use 4 rtgroups + * and scale up smoothly between min/max rtgroup sizes. + */ + if (rblocks >= TERABYTES(4, blocklog)) { + blocks = XFS_MAX_RGBLOCKS; + goto done; + } + if (rblocks >= MEGABYTES(128, blocklog)) { + shift = XFS_NOMULTIDISK_AGLOG; + goto calc_blocks; + } + + /* + * If rblocks is not evenly divisible by the number of desired rt + * groups, round "blocks" up so we don't lose the last bit of the + * filesystem. The same principle applies to the rt group count, so we + * don't lose the last rt group! + */ +calc_blocks: + ASSERT(shift >= 0 && shift <= XFS_MULTIDISK_AGLOG); + blocks = rblocks >> shift; + if (rblocks & xfs_mask32lo(shift)) { + if (blocks < XFS_MAX_RGBLOCKS) + blocks++; + } +done: + *rgsize = blocks; + *rgcount = rblocks / blocks + (rblocks % blocks != 0); +} + /* * Check for existing filesystem or partition table on device. * Returns: diff --git a/libxfs/topology.h b/libxfs/topology.h index 1a0fe24c09d..81843cbb803 100644 --- a/libxfs/topology.h +++ b/libxfs/topology.h @@ -32,6 +32,9 @@ calc_default_ag_geometry( uint64_t *agsize, uint64_t *agcount); +void calc_default_rtgroup_geometry(int blocklog, uint64_t rblocks, + uint64_t *rgsize, uint64_t *rgcount); + extern int check_overwrite( const char *device); diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index 7e76bedda68..e4f3b2c5c05 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -416,6 +416,7 @@ xfs_sb_has_ro_compat_feature( XFS_SB_FEAT_INCOMPAT_BIGTIME| \ XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR| \ XFS_SB_FEAT_INCOMPAT_NREXT64 | \ + XFS_SB_FEAT_INCOMPAT_RTGROUPS | \ XFS_SB_FEAT_INCOMPAT_METADIR) #define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL diff --git a/man/man8/mkfs.xfs.8.in b/man/man8/mkfs.xfs.8.in index 8cdfe9a7ff1..1735caecca7 100644 --- a/man/man8/mkfs.xfs.8.in +++ b/man/man8/mkfs.xfs.8.in @@ -1083,6 +1083,50 @@ or logical volume containing the section. .BI noalign This option disables stripe size detection, enforcing a realtime device with no stripe geometry. +.TP +.BI rtgroups= value +This feature breaks the realtime section into multiple allocation groups for +improved scalability. +This feature is only available if the metadata directory tree feature is +enabled. +.IP +By default, +.B mkfs.xfs +will not enable this feature. +If the option +.B \-r rtgroups=0 +is used, the rt group feature is not supported and is disabled. +.TP +.BI rgcount= +This is used to specify the number of allocation groups in the realtime +section. +The realtime section of the filesystem can be divided into allocation groups to +improve the performance of XFS. +More allocation groups imply that more parallelism can be achieved when +allocating blocks. +The minimum allocation group size is 2 realtime extents; the maximum size is +2^31 blocks. +The rt section of the filesystem is divided into +.I value +allocation groups (default value is scaled automatically based +on the underlying device size). +.TP +.BI rgsize= value +This is an alternative to using the +.B rgcount +suboption. The +.I value +is the desired size of the realtime allocation group expressed in bytes +(usually using the +.BR m " or " g +suffixes). +This value must be a multiple of the realtime extent size, +must be at least two realtime extents, and no more than 2^31 blocks. +The +.B rgcount +and +.B rgsize +suboptions are mutually exclusive. .RE .PP .PD 0 diff --git a/mkfs/proto.c b/mkfs/proto.c index 846b48ec789..e734269864e 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -963,6 +963,46 @@ rtsummary_init( } } +static void +rtfreesp_init_groups( + struct xfs_mount *mp) +{ + xfs_rgnumber_t rgno; + int error; + + for (rgno = 0; rgno < mp->m_sb.sb_rgcount; rgno++) { + struct xfs_trans *tp; + xfs_rtblock_t rtbno; + xfs_rtxnum_t start_rtx; + xfs_rtxnum_t next_rtx; + + rtbno = xfs_rgbno_to_rtb(mp, rgno, mp->m_sb.sb_rextsize); + start_rtx = xfs_rtb_to_rtxt(mp, rtbno); + + rtbno = xfs_rgbno_to_rtb(mp, rgno + 1, 0); + next_rtx = xfs_rtb_to_rtxt(mp, rtbno); + next_rtx = min(next_rtx, mp->m_sb.sb_rextents); + + error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, + 0, 0, 0, &tp); + if (error) + res_failed(error); + + libxfs_trans_ijoin(tp, mp->m_rbmip, 0); + error = -libxfs_rtfree_extent(tp, start_rtx, + next_rtx - start_rtx); + if (error) { + fail(_("Error initializing the realtime space"), + error); + } + error = -libxfs_trans_commit(tp); + if (error) + fail(_("Initialization of the realtime space failed"), + error); + + } +} + /* * Free the whole realtime area using transactions. * Do one transaction per bitmap block. @@ -1011,7 +1051,10 @@ rtinit( rtbitmap_init(mp); rtsummary_init(mp); - rtfreesp_init(mp); + if (xfs_has_rtgroups(mp)) + rtfreesp_init_groups(mp); + else + rtfreesp_init(mp); } static long diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 826f9e53309..4f96e436d32 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -123,6 +123,9 @@ enum { R_FILE, R_NAME, R_NOALIGN, + R_RTGROUPS, + R_RGCOUNT, + R_RGSIZE, R_MAX_OPTS, }; @@ -679,6 +682,9 @@ static struct opt_params ropts = { [R_FILE] = "file", [R_NAME] = "name", [R_NOALIGN] = "noalign", + [R_RTGROUPS] = "rtgroups", + [R_RGCOUNT] = "rgcount", + [R_RGSIZE] = "rgsize", [R_MAX_OPTS] = NULL, }, .subopt_params = { @@ -718,6 +724,27 @@ static struct opt_params ropts = { .defaultval = 1, .conflicts = { { NULL, LAST_CONFLICT } }, }, + { .index = R_RTGROUPS, + .conflicts = { { NULL, LAST_CONFLICT } }, + .minval = 0, + .maxval = 1, + .defaultval = 1, + }, + { .index = R_RGCOUNT, + .conflicts = { { &dopts, R_RGSIZE }, + { NULL, LAST_CONFLICT } }, + .minval = 1, + .maxval = XFS_MAX_RGNUMBER, + .defaultval = SUBOPT_NEEDS_VAL, + }, + { .index = R_RGSIZE, + .conflicts = { { &dopts, R_RGCOUNT }, + { NULL, LAST_CONFLICT } }, + .convert = true, + .minval = 0, + .maxval = (unsigned long long)XFS_MAX_RGBLOCKS << XFS_MAX_BLOCKSIZE_LOG, + .defaultval = SUBOPT_NEEDS_VAL, + }, }, }; @@ -882,6 +909,7 @@ struct cli_params { /* parameters that depend on sector/block size being validated. */ char *dsize; char *agsize; + char *rgsize; char *dsu; char *dirblocksize; char *logsize; @@ -902,6 +930,7 @@ struct cli_params { /* parameters where 0 is not a valid value */ int64_t agcount; + int64_t rgcount; int inodesize; int inopblock; int imaxpct; @@ -958,6 +987,9 @@ struct mkfs_params { uint64_t agsize; uint64_t agcount; + uint64_t rgsize; + uint64_t rgcount; + int imaxpct; bool loginternal; @@ -1014,7 +1046,8 @@ usage( void ) /* no-op info only */ [-N]\n\ /* prototype file */ [-p fname]\n\ /* quiet */ [-q]\n\ -/* realtime subvol */ [-r extsize=num,size=num,rtdev=xxx]\n\ +/* realtime subvol */ [-r extsize=num,size=num,rtdev=xxx,rtgroups=0|1,\n\ + rgcount=n,rgsize=n]\n\ /* sectorsize */ [-s size=num]\n\ /* version */ [-V]\n\ devicename\n\ @@ -1884,6 +1917,15 @@ rtdev_opts_parser( case R_NOALIGN: cli->sb_feat.nortalign = getnum(value, opts, subopt); break; + case R_RTGROUPS: + cli->sb_feat.rtgroups = getnum(value, opts, subopt); + break; + case R_RGCOUNT: + cli->rgcount = getnum(value, opts, subopt); + break; + case R_RGSIZE: + cli->rgsize = getstr(value, opts, subopt); + break; default: return -EINVAL; } @@ -2365,6 +2407,15 @@ _("cowextsize not supported without reflink support\n")); usage(); } + if (cli->sb_feat.rtgroups && !cli->sb_feat.metadir) { + if (cli_opt_set(&mopts, M_METADIR)) { + fprintf(stderr, +_("realtime groups not supported without metadata directory support\n")); + usage(); + } + cli->sb_feat.metadir = true; + } + /* * Copy features across to config structure now. */ @@ -3362,6 +3413,181 @@ an AG size that is one stripe unit smaller or larger, for example %llu.\n"), cfg->agsize, cfg->agcount); } +static uint64_t +calc_rgsize_extsize_nonpower( + struct mkfs_params *cfg) +{ + uint64_t try_rgsize, rgsize, rgcount; + + /* + * For non-power-of-two rt extent sizes, round the rtgroup size down to + * the nearest extent. + */ + calc_default_rtgroup_geometry(cfg->blocklog, cfg->rtblocks, &rgsize, + &rgcount); + rgsize -= rgsize % cfg->rtextblocks; + rgsize = min(XFS_MAX_RGBLOCKS, rgsize); + + /* + * If we would be left with a too-small rtgroup, increase or decrease + * the size of the group until we have a working geometry. + */ + for (try_rgsize = rgsize; + try_rgsize <= XFS_MAX_RGBLOCKS - cfg->rtextblocks; + try_rgsize += cfg->rtextblocks) { + if (cfg->rtblocks % try_rgsize >= (2 * cfg->rtextblocks)) + return try_rgsize; + } + for (try_rgsize = rgsize; + try_rgsize > (2 * cfg->rtextblocks); + try_rgsize -= cfg->rtextblocks) { + if (cfg->rtblocks % try_rgsize >= (2 * cfg->rtextblocks)) + return try_rgsize; + } + + fprintf(stderr, +_("realtime group size (%llu) not at all congruent with extent size (%llu)\n"), + (unsigned long long)rgsize, + (unsigned long long)cfg->rtextblocks); + usage(); + return 0; +} + +static uint64_t +calc_rgsize_extsize_power( + struct mkfs_params *cfg) +{ + uint64_t try_rgsize, rgsize, rgcount; + unsigned int rgsizelog; + + /* + * Find the rt group size that is both a power of two and yields at + * least as many rt groups as the default geometry specified. + */ + calc_default_rtgroup_geometry(cfg->blocklog, cfg->rtblocks, &rgsize, + &rgcount); + rgsizelog = log2_rounddown(rgsize); + rgsize = min(XFS_MAX_RGBLOCKS, 1U << rgsizelog); + + /* + * If we would be left with a too-small rtgroup, increase or decrease + * the size of the group by powers of 2 until we have a working + * geometry. If that doesn't work, try bumping by the extent size. + */ + for (try_rgsize = rgsize; + try_rgsize <= XFS_MAX_RGBLOCKS - cfg->rtextblocks; + try_rgsize <<= 2) { + if (cfg->rtblocks % try_rgsize >= (2 * cfg->rtextblocks)) + return try_rgsize; + } + for (try_rgsize = rgsize; + try_rgsize > (2 * cfg->rtextblocks); + try_rgsize >>= 2) { + if (cfg->rtblocks % try_rgsize >= (2 * cfg->rtextblocks)) + return try_rgsize; + } + for (try_rgsize = rgsize; + try_rgsize <= XFS_MAX_RGBLOCKS - cfg->rtextblocks; + try_rgsize += cfg->rtextblocks) { + if (cfg->rtblocks % try_rgsize >= (2 * cfg->rtextblocks)) + return try_rgsize; + } + for (try_rgsize = rgsize; + try_rgsize > (2 * cfg->rtextblocks); + try_rgsize -= cfg->rtextblocks) { + if (cfg->rtblocks % try_rgsize >= (2 * cfg->rtextblocks)) + return try_rgsize; + } + + fprintf(stderr, +_("realtime group size (%llu) not at all congruent with extent size (%llu)\n"), + (unsigned long long)rgsize, + (unsigned long long)cfg->rtextblocks); + usage(); + return 0; +} + +static void +calculate_rtgroup_geometry( + struct mkfs_params *cfg, + struct cli_params *cli) +{ + if (!cli->sb_feat.rtgroups) { + cfg->rgcount = 0; + cfg->rgsize = 0; + return; + } + + if (cli->rgsize) { /* User-specified rtgroup size */ + cfg->rgsize = getnum(cli->rgsize, &ropts, R_RGSIZE); + + /* + * Check specified agsize is a multiple of blocksize. + */ + if (cfg->rgsize % cfg->blocksize) { + fprintf(stderr, +_("rgsize (%s) not a multiple of fs blk size (%d)\n"), + cli->rgsize, cfg->blocksize); + usage(); + } + cfg->rgsize /= cfg->blocksize; + cfg->rgcount = cfg->rtblocks / cfg->rgsize + + (cfg->rtblocks % cfg->rgsize != 0); + + } else if (cli->rgcount) { /* User-specified rtgroup count */ + cfg->rgcount = cli->rgcount; + cfg->rgsize = cfg->rtblocks / cfg->rgcount + + (cfg->rtblocks % cfg->rgcount != 0); + } else if (cfg->rtblocks == 0) { + /* + * If nobody specified a realtime device or the rtgroup size, + * try 1TB, rounded down to the nearest rt extent. + */ + cfg->rgsize = TERABYTES(1, cfg->blocklog); + cfg->rgsize -= cfg->rgsize % cfg->rtextblocks; + cfg->rgcount = 0; + } else if (!is_power_of_2(cfg->rtextblocks)) { + cfg->rgsize = calc_rgsize_extsize_nonpower(cfg); + cfg->rgcount = cfg->rtblocks / cfg->rgsize + + (cfg->rtblocks % cfg->rgsize != 0); + } else { + cfg->rgsize = calc_rgsize_extsize_power(cfg); + cfg->rgcount = cfg->rtblocks / cfg->rgsize + + (cfg->rtblocks % cfg->rgsize != 0); + } + + if (cfg->rgsize > XFS_MAX_RGBLOCKS) { + fprintf(stderr, +_("realtime group size (%llu) must be less than the maximum (%u)\n"), + (unsigned long long)cfg->rgsize, + XFS_MAX_RGBLOCKS); + usage(); + } + + if (cfg->rgsize % cfg->rtextblocks != 0) { + fprintf(stderr, +_("realtime group size (%llu) not a multiple of rt extent size (%llu)\n"), + (unsigned long long)cfg->rgsize, + (unsigned long long)cfg->rtextblocks); + usage(); + } + + if (cfg->rgsize <= cfg->rtextblocks) { + fprintf(stderr, +_("realtime group size (%llu) must be at least two realtime extents\n"), + (unsigned long long)cfg->rgsize); + usage(); + } + + if (cfg->rgcount > XFS_MAX_RGNUMBER) { + fprintf(stderr, +_("realtime group count (%llu) must be less than the maximum (%u)\n"), + (unsigned long long)cfg->rgcount, + XFS_MAX_RGNUMBER); + usage(); + } +} + static void calculate_imaxpct( struct mkfs_params *cfg, @@ -3499,6 +3725,12 @@ sb_set_features( if (fp->nrext64) sbp->sb_features_incompat |= XFS_SB_FEAT_INCOMPAT_NREXT64; + + if (fp->rtgroups) { + sbp->sb_features_incompat |= XFS_SB_FEAT_INCOMPAT_RTGROUPS; + sbp->sb_rgcount = cfg->rgcount; + sbp->sb_rgblocks = cfg->rgsize; + } } /* @@ -4274,6 +4506,7 @@ main( char **argv) { xfs_agnumber_t agno; + xfs_rgnumber_t rgno; struct xfs_buf *buf; int c; char *dfile = NULL; @@ -4494,6 +4727,7 @@ main( */ calculate_initial_ag_geometry(&cfg, &cli, &xi); align_ag_geometry(&cfg); + calculate_rtgroup_geometry(&cfg, &cli); calculate_imaxpct(&cfg, &cli); @@ -4587,6 +4821,42 @@ main( exit(1); } + /* Write all the realtime group superblocks. */ + for (rgno = 0; rgno < cfg.rgcount; rgno++) { + struct xfs_buf *rtsb_bp; + struct xfs_buf *sb_bp = libxfs_getsb(mp); + + if (!sb_bp) { + fprintf(stderr, + _("%s: couldn't grab buffers to write primary rt superblock\n"), progname); + exit(1); + } + + error = -libxfs_buf_get_uncached(mp->m_rtdev_targp, + XFS_FSB_TO_BB(mp, 1), 0, + &rtsb_bp); + if (error) { + fprintf(stderr, + _("%s: couldn't grab primary rt superblock\n"), progname); + exit(1); + } + rtsb_bp->b_maps[0].bm_bn = XFS_RTSB_DADDR; + rtsb_bp->b_ops = &xfs_rtsb_buf_ops; + + libxfs_rtgroup_update_super(rtsb_bp, sb_bp); + libxfs_buf_mark_dirty(rtsb_bp); + libxfs_buf_relse(rtsb_bp); + libxfs_buf_relse(sb_bp); + + error = -libxfs_rtgroup_update_secondary_sbs(mp); + if (error) { + fprintf(stderr, + _("%s: writing secondary rtgroup headers failed, err=%d\n"), + progname, error); + exit(1); + } + } + /* * Initialise the freespace freelists (i.e. AGFLs) in each AG. */