From patchwork Fri Dec 30 22:19:36 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: 13085661 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 E5259C4332F for ; Sat, 31 Dec 2022 02:27:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236067AbiLaC1E (ORCPT ); Fri, 30 Dec 2022 21:27:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231503AbiLaC06 (ORCPT ); Fri, 30 Dec 2022 21:26:58 -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 4701E1C921 for ; Fri, 30 Dec 2022 18:26:57 -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 D8C9C61CD2 for ; Sat, 31 Dec 2022 02:26:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 457CDC433D2; Sat, 31 Dec 2022 02:26:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453616; bh=FgZzFCVbjpTjqVno40eR9F5ceUXXCnEZMjTysDFIrzE=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=WQUzRZMy6vT0vWz2TBPuORMECB/koZ9QktXFxCjo1KHpr7Bd/ww3lOFEv1/LxMi8t NrI/5VCd03D5zTidw/+aIXf3p1vwHVAaD3Rfpw3MROgFBktVJU6gMCf3CrTOt0r8nx LkR6T5QnBJWPIA8YRfbPIpe8gKP22qC4mN138bRXOvfo8128/thVb3O+RLcWxsUGiF KtEwvy/RYnWldTXRpuqd/wjrBv6HBH02sy6SLgtosZP9+S+IEq+ipP533HzdzW7rTn IFl5Ej72As3rdive8C2VxJjoGrIewID1mQT2TF+0R5Hc/3z6WeArZFNCbKhCD67uHa ROn6R7glDlT0g== Subject: [PATCH 1/8] xfs_db: support passing the realtime device to the debugger From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:36 -0800 Message-ID: <167243877625.728317.12185309289237271664.stgit@magnolia> In-Reply-To: <167243877610.728317.12510123562097453242.stgit@magnolia> References: <167243877610.728317.12510123562097453242.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 a new -R flag so that sysadmins can pass the realtime device to the xfs debugger. Since we can now have superblocks on the rt device, we need this to be able to inspect/dump/etc. Signed-off-by: Darrick J. Wong --- db/init.c | 7 +++++-- db/io.c | 43 +++++++++++++++++++++++++++++++++++++------ db/io.h | 2 ++ db/xfs_admin.sh | 5 +++-- man/man8/xfs_db.8 | 13 +++++++++++++ 5 files changed, 60 insertions(+), 10 deletions(-) diff --git a/db/init.c b/db/init.c index 9f045d27076..fc3bc403ea1 100644 --- a/db/init.c +++ b/db/init.c @@ -33,7 +33,7 @@ static void usage(void) { fprintf(stderr, _( - "Usage: %s [-ifFrxV] [-p prog] [-l logdev] [-c cmd]... device\n" + "Usage: %s [-ifFrxV] [-p prog] [-l logdev] [-R rtdev] [-c cmd]... device\n" ), progname); exit(1); } @@ -54,7 +54,7 @@ init( textdomain(PACKAGE); progname = basename(argv[0]); - while ((c = getopt(argc, argv, "c:fFip:rxVl:")) != EOF) { + while ((c = getopt(argc, argv, "c:fFip:rR:xVl:")) != EOF) { switch (c) { case 'c': cmdline = xrealloc(cmdline, (ncmdline+1)*sizeof(char*)); @@ -75,6 +75,9 @@ init( case 'r': x.isreadonly = LIBXFS_ISREADONLY; break; + case 'R': + x.rtname = optarg; + break; case 'l': x.logname = optarg; break; diff --git a/db/io.c b/db/io.c index 3d2572364d3..8688ee8e9c0 100644 --- a/db/io.c +++ b/db/io.c @@ -429,6 +429,7 @@ ring_add(void) static void write_cur_buf(void) { + struct xfs_buftarg *btp = iocur_top->bp->b_target; int ret; ret = -libxfs_bwrite(iocur_top->bp); @@ -436,7 +437,7 @@ write_cur_buf(void) dbprintf(_("write error: %s\n"), strerror(ret)); /* re-read buffer from disk */ - ret = -libxfs_readbufr(mp->m_ddev_targp, iocur_top->bb, iocur_top->bp, + ret = -libxfs_readbufr(btp, iocur_top->bb, iocur_top->bp, iocur_top->blen, 0); if (ret != 0) dbprintf(_("read error: %s\n"), strerror(ret)); @@ -445,6 +446,7 @@ write_cur_buf(void) static void write_cur_bbs(void) { + struct xfs_buftarg *btp = iocur_top->bp->b_target; int ret; ret = -libxfs_bwrite(iocur_top->bp); @@ -453,7 +455,7 @@ write_cur_bbs(void) /* re-read buffer from disk */ - ret = -libxfs_readbufr_map(mp->m_ddev_targp, iocur_top->bp, 0); + ret = -libxfs_readbufr_map(btp, iocur_top->bp, 0); if (ret != 0) dbprintf(_("read error: %s\n"), strerror(ret)); } @@ -508,8 +510,9 @@ write_cur(void) } -void -set_cur( +static void +__set_cur( + struct xfs_buftarg *btp, const typ_t *type, xfs_daddr_t blknum, int len, @@ -548,11 +551,11 @@ set_cur( if (!iocur_top->bbmap) return; memcpy(iocur_top->bbmap, bbmap, sizeof(struct bbmap)); - error = -libxfs_buf_read_map(mp->m_ddev_targp, bbmap->b, + error = -libxfs_buf_read_map(btp, bbmap->b, bbmap->nmaps, LIBXFS_READBUF_SALVAGE, &bp, ops); } else { - error = -libxfs_buf_read(mp->m_ddev_targp, blknum, len, + error = -libxfs_buf_read(btp, blknum, len, LIBXFS_READBUF_SALVAGE, &bp, ops); iocur_top->bbmap = NULL; } @@ -589,6 +592,34 @@ set_cur( ring_add(); } +void +set_cur( + const typ_t *type, + xfs_daddr_t blknum, + int len, + int ring_flag, + bbmap_t *bbmap) +{ + __set_cur(mp->m_ddev_targp, type, blknum, len, ring_flag, bbmap); +} + +int +set_rt_cur( + const typ_t *type, + xfs_daddr_t blknum, + int len, + int ring_flag, + bbmap_t *bbmap) +{ + if (!mp->m_rtdev_targp->bt_bdev) { + printf(_("realtime device not loaded, use -R.\n")); + return ENODEV; + } + + __set_cur(mp->m_rtdev_targp, type, blknum, len, ring_flag, bbmap); + return 0; +} + void set_iocur_type( const typ_t *type) diff --git a/db/io.h b/db/io.h index c29a7488198..29b22037bd6 100644 --- a/db/io.h +++ b/db/io.h @@ -49,6 +49,8 @@ extern void push_cur_and_set_type(void); extern void write_cur(void); extern void set_cur(const struct typ *type, xfs_daddr_t blknum, int len, int ring_add, bbmap_t *bbmap); +extern int set_rt_cur(const struct typ *type, xfs_daddr_t blknum, + int len, int ring_add, bbmap_t *bbmap); extern void ring_add(void); extern void set_iocur_type(const struct typ *type); extern void xfs_dummy_verify(struct xfs_buf *bp); diff --git a/db/xfs_admin.sh b/db/xfs_admin.sh index 409975b2228..a45a75bc9a6 100755 --- a/db/xfs_admin.sh +++ b/db/xfs_admin.sh @@ -6,6 +6,7 @@ status=0 DB_OPTS="" +DB_DEV_OPTS="" REPAIR_OPTS="" REPAIR_DEV_OPTS="" LOG_OPTS="" @@ -22,7 +23,7 @@ do L) DB_OPTS=$DB_OPTS" -c 'label "$OPTARG"'";; O) REPAIR_OPTS=$REPAIR_OPTS" -c $OPTARG";; p) DB_OPTS=$DB_OPTS" -c 'version projid32bit'";; - r) REPAIR_DEV_OPTS=" -r '$OPTARG'";; + r) REPAIR_DEV_OPTS=" -r '$OPTARG'"; DB_DEV_OPTS=" -R '$OPTARG'";; u) DB_OPTS=$DB_OPTS" -r -c uuid";; U) DB_OPTS=$DB_OPTS" -c 'uuid "$OPTARG"'";; V) xfs_db -p xfs_admin -V @@ -45,7 +46,7 @@ case $# in if [ -n "$DB_OPTS" ] then - eval xfs_db -x -p xfs_admin $LOG_OPTS $DB_OPTS "$1" + eval xfs_db -x -p xfs_admin $LOG_OPTS $DB_DEV_OPTS $DB_OPTS "$1" status=$? fi if [ -n "$REPAIR_OPTS" ] diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8 index a7e42e1a333..593b8037251 100644 --- a/man/man8/xfs_db.8 +++ b/man/man8/xfs_db.8 @@ -14,6 +14,9 @@ xfs_db \- debug an XFS filesystem .B \-l .I logdev ] [ +.B \-R +.I rtdev +] [ .B \-p .I progname ] @@ -80,6 +83,16 @@ Set the program name to for prompts and some error messages, the default value is .BR xfs_db . .TP +.B -R +.I rtdev +Specifies the device where the realtime data resides. +This is only relevant for filesystems that have a realtime section. +See the +.BR mkfs.xfs "(8) " \-r +option, and refer to +.BR xfs (5) +for a detailed description of the XFS realtime section. +.TP .B -r Open .I device From patchwork Fri Dec 30 22:19:36 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: 13085662 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 B4F86C4332F for ; Sat, 31 Dec 2022 02:27:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231503AbiLaC1W (ORCPT ); Fri, 30 Dec 2022 21:27:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236134AbiLaC1Q (ORCPT ); Fri, 30 Dec 2022 21:27:16 -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 64FBF1C921 for ; Fri, 30 Dec 2022 18:27: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 1C564B81E67 for ; Sat, 31 Dec 2022 02:27:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2D80C433F0; Sat, 31 Dec 2022 02:27:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453631; bh=ZjDnWwPn+h/VHJn3uoqvAmXCAD6ovoR5HLQb45r5RcM=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=LGiOh3SV/JVXvKOHdUa3Ur1VJKD12uqHaQvBvD6pi+T/OLQjYEtbK2bTv6L7+AF99 YENK268as2FJF0P1xTWY2A0CgFDw3bQDG1nbwUBgK5V7s9g+X3rmx9iVsyOJH3wdRj mWDuREXUrmueXIIohKRtIM3yEP+/3XGokkcfoHLxH609jpYtDsl3rcXgyUOcyGRxeg CKVbyDbXmCfECZ5SCyLBdP7ZOJuKqUj6Y4p0vHFKD84pA1+vjsrm5NeuKhRtRGEeS4 RBTWPHoy8k5RxjJM6w1KZIbHe8+Anwk3ZyyKW3pLoM0qZH2QxVgLbJqK+pQC9vzDHB /Fy0R4Nlh8Vrw== Subject: [PATCH 2/8] xfs_db: report the device associated with each io cursor From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:36 -0800 Message-ID: <167243877638.728317.344770129451526584.stgit@magnolia> In-Reply-To: <167243877610.728317.12510123562097453242.stgit@magnolia> References: <167243877610.728317.12510123562097453242.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 db is reporting on an io cursor, have it print out the device that the cursor is pointing to. Signed-off-by: Darrick J. Wong --- db/block.c | 16 +++++++++++++++- db/io.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- db/io.h | 4 ++++ 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/db/block.c b/db/block.c index 788337d3709..b2b5edf9385 100644 --- a/db/block.c +++ b/db/block.c @@ -126,7 +126,17 @@ daddr_f( char *p; if (argc == 1) { - dbprintf(_("current daddr is %lld\n"), iocur_top->off >> BBSHIFT); + xfs_daddr_t daddr = iocur_top->off >> BBSHIFT; + + if (iocur_is_ddev(iocur_top)) + dbprintf(_("datadev daddr is %lld\n"), daddr); + else if (iocur_is_extlogdev(iocur_top)) + dbprintf(_("logdev daddr is %lld\n"), daddr); + else if (iocur_is_rtdev(iocur_top)) + dbprintf(_("rtdev daddr is %lld\n"), daddr); + else + dbprintf(_("current daddr is %lld\n"), daddr); + return 0; } d = (int64_t)strtoull(argv[1], &p, 0); @@ -220,6 +230,10 @@ fsblock_f( char *p; if (argc == 1) { + if (!iocur_is_ddev(iocur_top)) { + dbprintf(_("cursor does not point to data device\n")); + return 0; + } dbprintf(_("current fsblock is %lld\n"), XFS_DADDR_TO_FSB(mp, iocur_top->off >> BBSHIFT)); return 0; diff --git a/db/io.c b/db/io.c index 8688ee8e9c0..00eb5e98dc2 100644 --- a/db/io.c +++ b/db/io.c @@ -137,18 +137,58 @@ pop_help(void) )); } +bool +iocur_is_ddev(const struct iocur *ioc) +{ + if (!ioc->bp) + return false; + + return ioc->bp->b_target == ioc->bp->b_mount->m_ddev_targp; +} + +bool +iocur_is_extlogdev(const struct iocur *ioc) +{ + struct xfs_buf *bp = ioc->bp; + + if (!bp) + return false; + if (bp->b_mount->m_logdev_targp == bp->b_mount->m_ddev_targp) + return false; + + return bp->b_target == bp->b_mount->m_logdev_targp; +} + +bool +iocur_is_rtdev(const struct iocur *ioc) +{ + if (!ioc->bp) + return false; + + return ioc->bp->b_target == ioc->bp->b_mount->m_rtdev_targp; +} + void print_iocur( char *tag, iocur_t *ioc) { + const char *block_unit = "fsbno?"; int i; + if (iocur_is_ddev(ioc)) + block_unit = "fsbno"; + else if (iocur_is_extlogdev(ioc)) + block_unit = "logbno"; + else if (iocur_is_rtdev(ioc)) + block_unit = "rtbno"; + dbprintf("%s\n", tag); dbprintf(_("\tbyte offset %lld, length %d\n"), ioc->off, ioc->len); - dbprintf(_("\tbuffer block %lld (fsbno %lld), %d bb%s\n"), ioc->bb, - (xfs_fsblock_t)XFS_DADDR_TO_FSB(mp, ioc->bb), ioc->blen, - ioc->blen == 1 ? "" : "s"); + dbprintf(_("\tbuffer block %lld (%s %lld), %d bb%s\n"), ioc->bb, + block_unit, + (xfs_fsblock_t)XFS_DADDR_TO_FSB(mp, ioc->bb), + ioc->blen, ioc->blen == 1 ? "" : "s"); if (ioc->bbmap) { dbprintf(_("\tblock map")); for (i = 0; i < ioc->bbmap->nmaps; i++) diff --git a/db/io.h b/db/io.h index 29b22037bd6..1a37ee78c72 100644 --- a/db/io.h +++ b/db/io.h @@ -56,6 +56,10 @@ extern void set_iocur_type(const struct typ *type); extern void xfs_dummy_verify(struct xfs_buf *bp); extern void xfs_verify_recalc_crc(struct xfs_buf *bp); +bool iocur_is_ddev(const struct iocur *ioc); +bool iocur_is_extlogdev(const struct iocur *ioc); +bool iocur_is_rtdev(const struct iocur *ioc); + /* * returns -1 for unchecked, 0 for bad and 1 for good */ From patchwork Fri Dec 30 22:19:36 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: 13085663 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 BB0C5C4332F for ; Sat, 31 Dec 2022 02:27:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236134AbiLaC13 (ORCPT ); Fri, 30 Dec 2022 21:27:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236094AbiLaC13 (ORCPT ); Fri, 30 Dec 2022 21:27:29 -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 537801C921 for ; Fri, 30 Dec 2022 18:27:28 -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 E615161CD4 for ; Sat, 31 Dec 2022 02:27:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4EDC0C433EF; Sat, 31 Dec 2022 02:27:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453647; bh=gu26SK12RLpjM6eDb3gNwBu0aZO/krySyWCN1OYkbQA=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=I5B9uwHgLplxXA1hkbsBMBqZzLc+Uor+RkGh6KJ+LC+Ys+G8mrY3v1ElnmWYqYttb JQxrXx03jDOpTCr9DsGM7wO5yOh+pCBlf0r8yycq50859YjIvZDXLxRup2GH1rERC4 6yT0ZlsbQfGmaZJTxCQXnJGMv4kt8/dAJs9ZPdDZSTd/vB3nRcrlv9lfF3uo1bzWgT Y89pugDyzu80gNV8cgeEwjlHLq2vZ16Bmiamt7/Z/Y2R/19DH6eudFA9eKTAdSLNTI U1SP1T7ylpKUtntLa1jhhVZ4ojfghHXJ/lCajHz4wLlZKOR93WXcATK0EfjjLljjsr Gw/q13xquU80Q== Subject: [PATCH 3/8] xfs_db: make the daddr command target the 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:36 -0800 Message-ID: <167243877651.728317.312052597903660667.stgit@magnolia> In-Reply-To: <167243877610.728317.12510123562097453242.stgit@magnolia> References: <167243877610.728317.12510123562097453242.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 it so that users can issue the command "daddr -r XXX" to select disk block XXX on the realtime device. Signed-off-by: Darrick J. Wong --- db/block.c | 43 ++++++++++++++++++++++++++++++++++++++----- man/man8/xfs_db.8 | 6 +++++- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/db/block.c b/db/block.c index b2b5edf9385..d064fbed5aa 100644 --- a/db/block.c +++ b/db/block.c @@ -31,7 +31,7 @@ static const cmdinfo_t ablock_cmd = { "ablock", NULL, ablock_f, 1, 1, 1, N_("filoff"), N_("set address to file offset (attr fork)"), ablock_help }; static const cmdinfo_t daddr_cmd = - { "daddr", NULL, daddr_f, 0, 1, 1, N_("[d]"), + { "daddr", NULL, daddr_f, 0, -1, 1, N_("[d]"), N_("set address to daddr value"), daddr_help }; static const cmdinfo_t dblock_cmd = { "dblock", NULL, dblock_f, 1, 1, 1, N_("filoff"), @@ -117,6 +117,11 @@ daddr_help(void) )); } +enum daddr_target { + DT_DATA, + DT_RT, +}; + static int daddr_f( int argc, @@ -124,8 +129,23 @@ daddr_f( { int64_t d; char *p; + int c; + xfs_rfsblock_t max_daddrs = mp->m_sb.sb_dblocks; + enum daddr_target tgt = DT_DATA; - if (argc == 1) { + while ((c = getopt(argc, argv, "r")) != -1) { + switch (c) { + case 'r': + tgt = DT_RT; + max_daddrs = mp->m_sb.sb_rblocks; + break; + default: + daddr_help(); + return 0; + } + } + + if (optind == argc) { xfs_daddr_t daddr = iocur_top->off >> BBSHIFT; if (iocur_is_ddev(iocur_top)) @@ -139,14 +159,27 @@ daddr_f( return 0; } - d = (int64_t)strtoull(argv[1], &p, 0); + + if (optind != argc - 1) { + daddr_help(); + return 0; + } + + d = (int64_t)strtoull(argv[optind], &p, 0); if (*p != '\0' || - d >= mp->m_sb.sb_dblocks << (mp->m_sb.sb_blocklog - BBSHIFT)) { + d >= max_daddrs << (mp->m_sb.sb_blocklog - BBSHIFT)) { dbprintf(_("bad daddr %s\n"), argv[1]); return 0; } ASSERT(typtab[TYP_DATA].typnm == TYP_DATA); - set_cur(&typtab[TYP_DATA], d, 1, DB_RING_ADD, NULL); + switch (tgt) { + case DT_DATA: + set_cur(&typtab[TYP_DATA], d, 1, DB_RING_ADD, NULL); + break; + case DT_RT: + set_rt_cur(&typtab[TYP_DATA], d, 1, DB_RING_ADD, NULL); + break; + } return 0; } diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8 index 593b8037251..aa097a13b27 100644 --- a/man/man8/xfs_db.8 +++ b/man/man8/xfs_db.8 @@ -590,7 +590,7 @@ Recalculate the current structure's correct CRC value, and write it to disk. Validate and display the current value and state of the structure's CRC. .RE .TP -.BI "daddr [" d ] +.BI "daddr [" -r "] [" d ] Set current address to the daddr (512 byte block) given by .IR d . If no value for @@ -599,6 +599,10 @@ is given, the current address is printed, expressed as a daddr. The type is set to .B data (uninterpreted). + +If an address and the +.B \-r +option are specified, the current address is set to the realtime device. .TP .BI dblock " filoff" Set current address to the offset From patchwork Fri Dec 30 22:19:36 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: 13085664 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 42794C4332F for ; Sat, 31 Dec 2022 02:27:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236006AbiLaC1p (ORCPT ); Fri, 30 Dec 2022 21:27:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231466AbiLaC1o (ORCPT ); Fri, 30 Dec 2022 21:27: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 D2B4D1C921 for ; Fri, 30 Dec 2022 18:27: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 6F45E61CC6 for ; Sat, 31 Dec 2022 02:27:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0B30C433EF; Sat, 31 Dec 2022 02:27:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453662; bh=0V1mRCQ+Bkkeq+VSeGRgrm1lRnbR85uvxH1EhYSQawc=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=O3tqzLCOwCzR4SUCoQJQgHe8ZHRVY7WufzEBbE8DM1+M+2OSHTk/cJ6dg2lZpCVTt HmDCCqbf03Y521cUHj1GSzP+/jHC29NULvliTv/cOSVX5TkGF+e6TgSFRCO+XTgsWk 0Df1jxGFRDzA3XVuiueWcpL2MmYgzz6eeCSjrp5JX/vhejFigG9oPKB1X0VvDDwsOj vgJi09eYac0t27o4Uo+9rMuZkCjXXCpbJW2ABn7Zq5yurqWEiINz3C//yFcsF/yYTb OTeilvCPzi4RMEcXxzjKLvC7D0uI3YhByBd5dk7+qHLBPTt3nZEgo93SGX/OI3rkgs GJADjfIh36DLQ== Subject: [PATCH 4/8] xfs_db: access realtime file 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:36 -0800 Message-ID: <167243877664.728317.4712975169277704547.stgit@magnolia> In-Reply-To: <167243877610.728317.12510123562097453242.stgit@magnolia> References: <167243877610.728317.12510123562097453242.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 we have the ability to point the io cursor at the realtime device, let's make it so that the "dblock" command can walk the contents of realtime files. Signed-off-by: Darrick J. Wong --- db/block.c | 17 +++++++++++++++-- db/faddr.c | 4 +++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/db/block.c b/db/block.c index d064fbed5aa..ae8744685b0 100644 --- a/db/block.c +++ b/db/block.c @@ -195,6 +195,13 @@ dblock_help(void) )); } +static inline bool +is_rtfile( + struct xfs_dinode *dip) +{ + return dip->di_flags & cpu_to_be16(XFS_DIFLAG_REALTIME); +} + static int dblock_f( int argc, @@ -234,8 +241,14 @@ dblock_f( ASSERT(typtab[type].typnm == type); if (nex > 1) make_bbmap(&bbmap, nex, bmp); - set_cur(&typtab[type], (int64_t)XFS_FSB_TO_DADDR(mp, dfsbno), - nb * blkbb, DB_RING_ADD, nex > 1 ? &bbmap : NULL); + if (is_rtfile(iocur_top->data)) + set_rt_cur(&typtab[type], (int64_t)XFS_FSB_TO_DADDR(mp, dfsbno), + nb * blkbb, DB_RING_ADD, + nex > 1 ? &bbmap : NULL); + else + set_cur(&typtab[type], (int64_t)XFS_FSB_TO_DADDR(mp, dfsbno), + nb * blkbb, DB_RING_ADD, + nex > 1 ? &bbmap : NULL); free(bmp); return 0; } diff --git a/db/faddr.c b/db/faddr.c index ec4aae68bb5..fd65b86b5e9 100644 --- a/db/faddr.c +++ b/db/faddr.c @@ -323,7 +323,9 @@ fa_drtbno( dbprintf(_("null block number, cannot set new addr\n")); return; } - /* need set_cur to understand rt subvolume */ + + set_rt_cur(&typtab[next], (int64_t)XFS_FSB_TO_BB(mp, bno), blkbb, + DB_RING_ADD, NULL); } /*ARGSUSED*/ From patchwork Fri Dec 30 22:19:36 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: 13085665 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 2CA9AC4332F for ; Sat, 31 Dec 2022 02:28:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236094AbiLaC2D (ORCPT ); Fri, 30 Dec 2022 21:28:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231466AbiLaC2C (ORCPT ); Fri, 30 Dec 2022 21:28:02 -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 0197F1C921 for ; Fri, 30 Dec 2022 18:28:01 -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 AE594B81E69 for ; Sat, 31 Dec 2022 02:27:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AA2DC433EF; Sat, 31 Dec 2022 02:27:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453678; bh=wpEKgu8nv5+BbbpNI42msFc4rs+zeuF5M7bSifakpHA=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=MtMjaW8AxOsD01/LQNbcPrILOWyxCbQtqynh8yl9HuOwexGM+9eV1hkMBvzvF2PG4 iFT6MBpEEj6lfDH8bswwTodZcdq4HMLVuRWcIvtU9yCJk0/lcYsyFfXA1ZpmHDPy6c lfxsRJELFJMju+ox4h59L/HhpRRfZ7h8BrcVwh5Uk10tqFg0yUQ+4RLnXN06oTLK3Q yJcQ0kR5uTYf5oCS5WOZa9MfgusWSc6iF4u9k6PWu44wAfTHhXuE7zMzynMtfTGmFn 0wF0Ew1RaGN9lA1incCXYqcrzTPwjFCzhhYNyVQ4/4zf2aCBZ/Lh2Daxm6LTzpKkNT UbUelI5TzQHmw== Subject: [PATCH 5/8] xfs_db: access arbitrary realtime blocks and extents From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:36 -0800 Message-ID: <167243877678.728317.13782091019281270247.stgit@magnolia> In-Reply-To: <167243877610.728317.12510123562097453242.stgit@magnolia> References: <167243877610.728317.12510123562097453242.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 two commands to xfs_db so that we can point ourselves at any arbitrary realtime block or extent. Signed-off-by: Darrick J. Wong --- db/block.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++ man/man8/xfs_db.8 | 20 ++++++++++ 2 files changed, 127 insertions(+) diff --git a/db/block.c b/db/block.c index ae8744685b0..1afe201d0b2 100644 --- a/db/block.c +++ b/db/block.c @@ -25,6 +25,10 @@ static int dblock_f(int argc, char **argv); static void dblock_help(void); static int fsblock_f(int argc, char **argv); static void fsblock_help(void); +static int rtblock_f(int argc, char **argv); +static void rtblock_help(void); +static int rtextent_f(int argc, char **argv); +static void rtextent_help(void); static void print_rawdata(void *data, int len); static const cmdinfo_t ablock_cmd = @@ -39,6 +43,12 @@ static const cmdinfo_t dblock_cmd = static const cmdinfo_t fsblock_cmd = { "fsblock", "fsb", fsblock_f, 0, 1, 1, N_("[fsb]"), N_("set address to fsblock value"), fsblock_help }; +static const cmdinfo_t rtblock_cmd = + { "rtblock", "rtbno", rtblock_f, 0, 1, 1, N_("[rtbno]"), + N_("set address to rtblock value"), rtblock_help }; +static const cmdinfo_t rtextent_cmd = + { "rtextent", "rtx", rtextent_f, 0, 1, 1, N_("[rtxno]"), + N_("set address to rtextent value"), rtextent_help }; static void ablock_help(void) @@ -104,6 +114,8 @@ block_init(void) add_command(&daddr_cmd); add_command(&dblock_cmd); add_command(&fsblock_cmd); + add_command(&rtblock_cmd); + add_command(&rtextent_cmd); } static void @@ -301,6 +313,101 @@ fsblock_f( return 0; } +static void +rtblock_help(void) +{ + dbprintf(_( +"\n Example:\n" +"\n" +" 'rtblock 1023' - sets the file position to the 1023rd block on the realtime\n" +" volume. The filesystem block size is specified in the superblock and set\n" +" during mkfs time.\n\n" +)); +} + +static int +rtblock_f( + int argc, + char **argv) +{ + xfs_rtblock_t rtbno; + char *p; + + if (argc == 1) { + if (!iocur_is_rtdev(iocur_top)) { + dbprintf(_("cursor does not point to rt device\n")); + return 0; + } + dbprintf(_("current rtblock is %lld\n"), + XFS_BB_TO_FSB(mp, iocur_top->off >> BBSHIFT)); + return 0; + } + rtbno = strtoull(argv[1], &p, 0); + if (*p != '\0') { + dbprintf(_("bad rtblock %s\n"), argv[1]); + return 0; + } + if (rtbno >= mp->m_sb.sb_rblocks) { + dbprintf(_("bad rtblock %s\n"), argv[1]); + return 0; + } + ASSERT(typtab[TYP_DATA].typnm == TYP_DATA); + set_rt_cur(&typtab[TYP_DATA], XFS_FSB_TO_BB(mp, rtbno), blkbb, + DB_RING_ADD, NULL); + return 0; +} + +static void +rtextent_help(void) +{ + dbprintf(_( +"\n Example:\n" +"\n" +" 'rtextent 10' - sets the file position to the 10th extent on the realtime\n" +" volume. The realtime extent size is specified in the superblock and set\n" +" during mkfs or growfs time.\n\n" +)); +} + +static int +rtextent_f( + int argc, + char **argv) +{ + xfs_rtblock_t rtbno; + xfs_rtxnum_t rtx; + char *p; + + if (argc == 1) { + xfs_extlen_t dontcare; + + if (!iocur_is_rtdev(iocur_top)) { + dbprintf(_("cursor does not point to rt device\n")); + return 0; + } + + rtbno = XFS_BB_TO_FSB(mp, iocur_top->off >> BBSHIFT); + dbprintf(_("current rtextent is %lld\n"), + xfs_rtb_to_rtx(mp, rtbno, &dontcare)); + return 0; + } + rtx = strtoull(argv[1], &p, 0); + if (*p != '\0') { + dbprintf(_("bad rtextent %s\n"), argv[1]); + return 0; + } + if (rtx >= mp->m_sb.sb_rextents) { + dbprintf(_("bad rtextent %s\n"), argv[1]); + return 0; + } + + rtbno = xfs_rtx_to_rtb(mp, rtx); + ASSERT(typtab[TYP_DATA].typnm == TYP_DATA); + set_rt_cur(&typtab[TYP_DATA], XFS_FSB_TO_BB(mp, rtbno), + mp->m_sb.sb_rextsize * blkbb, DB_RING_ADD, NULL); + return 0; +} + void print_block( const field_t *fields, diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8 index aa097a13b27..de30fbc6230 100644 --- a/man/man8/xfs_db.8 +++ b/man/man8/xfs_db.8 @@ -927,6 +927,26 @@ command. Exit .BR xfs_db . .TP +.BI "rtblock [" rtbno ] +Set current address to the rtblock value given by +.IR rtbno . +If no value for +.I rtbno +is given the current address is printed, expressed as an rtbno. +The type is set to +.B data +(uninterpreted). +.TP +.BI "rtextent [" rtxno ] +Set current address to the rtextent value given by +.IR rtextent . +If no value for +.I rtextent +is given the current address is printed, expressed as an rtextent. +The type is set to +.B data +(uninterpreted). +.TP .BI "ring [" index ] Show position ring (if no .I index From patchwork Fri Dec 30 22:19:36 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: 13085666 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 0D875C4332F for ; Sat, 31 Dec 2022 02:28:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236113AbiLaC2Q (ORCPT ); Fri, 30 Dec 2022 21:28:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231466AbiLaC2Q (ORCPT ); Fri, 30 Dec 2022 21:28:16 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0254E1C921 for ; Fri, 30 Dec 2022 18:28:15 -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 840A061CE2 for ; Sat, 31 Dec 2022 02:28:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E215CC433D2; Sat, 31 Dec 2022 02:28:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453693; bh=4ptemph1CydKmZjDjOv/OW9shJu3GwRcoxn5WqJU9Xo=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=nFj9E9DUsjW9vSEbOiXiw72ka61MAp3Nk52sjp2E//wKU37M2BOH8PON69S2cRCDU OucmuF4coBHJD9D+y8Q9oHpRrXuDqpGAPvUNS6NFDI8jQ8skkhaJwM1T01Kj2BtPsd M5NdeCb+zBTdwbwTp2Pmcei0BJvf1Y0CU+flTK6rfpsh5S54LM5078L4OOOGfytwCi jmC1+CW4r3/FNeXSeyAwMC8gTgZMzKCiePyQo3i8awqv3dITjCedm1gZigq02WkgSs zBFZ/s3vsS9aUuRVoYvlZ59d4a9ScI6FD9GmEroPvpUHcJ6TJrd0vRP5MVEGzSE0a2 eGENh3EWplonw== Subject: [PATCH 6/8] 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:36 -0800 Message-ID: <167243877691.728317.7025789109983906968.stgit@magnolia> In-Reply-To: <167243877610.728317.12510123562097453242.stgit@magnolia> References: <167243877610.728317.12510123562097453242.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 rt extents, rt block numbers, and how to compute offsets within the rt bitmap and summary files. Signed-off-by: Darrick J. Wong --- db/convert.c | 232 ++++++++++++++++++++++++++++++++++++++++++++++++----- man/man8/xfs_db.8 | 51 ++++++++++++ 2 files changed, 260 insertions(+), 23 deletions(-) diff --git a/db/convert.c b/db/convert.c index e1466057031..811bac00f71 100644 --- a/db/convert.c +++ b/db/convert.c @@ -26,6 +26,10 @@ agino_to_bytes(XFS_INO_TO_AGINO(mp, (x)))) #define inoidx_to_bytes(x) \ ((uint64_t)(x) << mp->m_sb.sb_inodelog) +#define rtblock_to_bytes(x) \ + ((uint64_t)(x) << mp->m_sb.sb_blocklog) +#define rtx_to_rtblock(x) \ + ((uint64_t)(x) * mp->m_sb.sb_rextsize) typedef enum { CT_NONE = -1, @@ -40,11 +44,12 @@ typedef enum { CT_INO, /* xfs_ino_t */ CT_INOIDX, /* index of inode in fsblock */ CT_INOOFF, /* byte offset in inode */ + CT_RTBLOCK, /* realtime block */ + CT_RTX, /* realtime extent */ NCTS } ctype_t; typedef struct ctydesc { - ctype_t ctype; int allowed; const char **names; } ctydesc_t; @@ -61,12 +66,16 @@ typedef union { xfs_ino_t ino; int inoidx; int inooff; + xfs_rtblock_t rtblock; + xfs_rtblock_t rtx; } cval_t; static uint64_t bytevalue(ctype_t ctype, cval_t *val); +static int rtconvert_f(int argc, char **argv); static int convert_f(int argc, char **argv); static int getvalue(char *s, ctype_t ctype, cval_t *val); -static ctype_t lookupcty(char *ctyname); +static ctype_t lookupcty(const struct ctydesc *descs, + const char *ctyname); static const char *agblock_names[] = { "agblock", "agbno", NULL }; static const char *agino_names[] = { "agino", "aginode", NULL }; @@ -74,6 +83,8 @@ 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", + NULL }; static const char *byte_names[] = { "byte", "fsbyte", NULL }; static const char *daddr_names[] = { "daddr", "bb", NULL }; static const char *fsblock_names[] = { "fsblock", "fsb", "fsbno", NULL }; @@ -81,30 +92,91 @@ static const char *ino_names[] = { "ino", "inode", NULL }; static const char *inoidx_names[] = { "inoidx", "offset", NULL }; static const char *inooff_names[] = { "inooff", "inodeoff", NULL }; +static const char *rtblock_names[] = { "rtblock", "rtb", "rtbno", NULL }; +static const char *rtx_names[] = { "rtx", "rtextent", NULL }; + static const ctydesc_t ctydescs[NCTS] = { - { CT_AGBLOCK, M(AGNUMBER)|M(BBOFF)|M(BLKOFF)|M(INOIDX)|M(INOOFF), - agblock_names }, - { CT_AGINO, M(AGNUMBER)|M(INOOFF), agino_names }, - { CT_AGNUMBER, - M(AGBLOCK)|M(AGINO)|M(BBOFF)|M(BLKOFF)|M(INOIDX)|M(INOOFF), - agnumber_names }, - { CT_BBOFF, M(AGBLOCK)|M(AGNUMBER)|M(DADDR)|M(FSBLOCK), bboff_names }, - { CT_BLKOFF, M(AGBLOCK)|M(AGNUMBER)|M(FSBLOCK), blkoff_names }, - { CT_BYTE, 0, byte_names }, - { CT_DADDR, M(BBOFF), daddr_names }, - { CT_FSBLOCK, M(BBOFF)|M(BLKOFF)|M(INOIDX), fsblock_names }, - { CT_INO, M(INOOFF), ino_names }, - { CT_INOIDX, M(AGBLOCK)|M(AGNUMBER)|M(FSBLOCK)|M(INOOFF), - inoidx_names }, - { CT_INOOFF, - M(AGBLOCK)|M(AGINO)|M(AGNUMBER)|M(FSBLOCK)|M(INO)|M(INOIDX), - inooff_names }, + [CT_AGBLOCK] = { + .allowed = M(AGNUMBER)|M(BBOFF)|M(BLKOFF)|M(INOIDX)|M(INOOFF), + .names = agblock_names, + }, + [CT_AGINO] = { + .allowed = M(AGNUMBER)|M(INOOFF), + .names = agino_names, + }, + [CT_AGNUMBER] = { + .allowed = M(AGBLOCK)|M(AGINO)|M(BBOFF)|M(BLKOFF)|M(INOIDX)|M(INOOFF), + .names = agnumber_names, + }, + [CT_BBOFF] = { + .allowed = M(AGBLOCK)|M(AGNUMBER)|M(DADDR)|M(FSBLOCK), + .names = bboff_names, + }, + [CT_BLKOFF] = { + .allowed = M(AGBLOCK)|M(AGNUMBER)|M(FSBLOCK), + .names = blkoff_names, + }, + [CT_BYTE] = { + .allowed = 0, + .names = byte_names, + }, + [CT_DADDR] = { + .allowed = M(BBOFF), + .names = daddr_names, + }, + [CT_FSBLOCK] = { + .allowed = M(BBOFF)|M(BLKOFF)|M(INOIDX), + .names = fsblock_names, + }, + [CT_INO] = { + .allowed = M(INOOFF), + .names = ino_names, + }, + [CT_INOIDX] = { + .allowed = M(AGBLOCK)|M(AGNUMBER)|M(FSBLOCK)|M(INOOFF), + .names = inoidx_names, + }, + [CT_INOOFF] = { + .allowed = M(AGBLOCK)|M(AGINO)|M(AGNUMBER)|M(FSBLOCK)|M(INO)|M(INOIDX), + .names = inooff_names, + }, +}; + +static const ctydesc_t ctydescs_rt[NCTS] = { + [CT_BBOFF] = { + .allowed = M(DADDR)|M(RTBLOCK), + .names = bboff_names, + }, + [CT_BLKOFF] = { + .allowed = M(RTBLOCK), + .names = rtblkoff_names, + }, + [CT_BYTE] = { + .allowed = 0, + .names = byte_names, + }, + [CT_DADDR] = { + .allowed = M(BBOFF), + .names = daddr_names, + }, + [CT_RTBLOCK] = { + .allowed = M(BBOFF)|M(BLKOFF), + .names = rtblock_names, + }, + [CT_RTX] = { + .allowed = M(BBOFF)|M(BLKOFF), + .names = rtx_names, + }, }; static const cmdinfo_t convert_cmd = { "convert", NULL, convert_f, 3, 9, 0, "type num [type num]... type", "convert from one address form to another", NULL }; +static const cmdinfo_t rtconvert_cmd = + { "rtconvert", NULL, rtconvert_f, 3, 9, 0, "type num [type num]... type", + "convert from one realtime address form to another", NULL }; + static uint64_t bytevalue(ctype_t ctype, cval_t *val) { @@ -131,6 +203,10 @@ bytevalue(ctype_t ctype, cval_t *val) return inoidx_to_bytes(val->inoidx); case CT_INOOFF: return (uint64_t)val->inooff; + case CT_RTBLOCK: + return rtblock_to_bytes(val->rtblock); + case CT_RTX: + return rtblock_to_bytes(rtx_to_rtblock(val->rtx)); case CT_NONE: case NCTS: break; @@ -159,13 +235,13 @@ convert_f(int argc, char **argv) "arguments\n"), argc); return 0; } - if ((wtype = lookupcty(argv[argc - 1])) == CT_NONE) { + if ((wtype = lookupcty(ctydescs, argv[argc - 1])) == CT_NONE) { dbprintf(_("unknown conversion type %s\n"), argv[argc - 1]); return 0; } for (i = mask = conmask = 0; i < (argc - 1) / 2; i++) { - c = lookupcty(argv[i * 2]); + c = lookupcty(ctydescs, argv[i * 2]); if (c == CT_NONE) { dbprintf(_("unknown conversion type %s\n"), argv[i * 2]); return 0; @@ -230,6 +306,107 @@ convert_f(int argc, char **argv) case CT_INOOFF: v &= mp->m_sb.sb_inodesize - 1; break; + case CT_RTBLOCK: + case CT_RTX: + /* shouldn't get here */ + ASSERT(0); + break; + case CT_NONE: + case NCTS: + /* NOTREACHED */ + break; + } + dbprintf("0x%llx (%llu)\n", v, v); + 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 int +rtconvert_f(int argc, char **argv) +{ + ctype_t c; + int conmask; + cval_t cvals[NCTS] = {}; + int i; + int mask; + uint64_t v; + ctype_t wtype; + + /* move past the "rtconvert" command */ + argc--; + argv++; + + if ((argc % 2) != 1) { + dbprintf(_("bad argument count %d to rtconvert, expected 3,5,7,9 " + "arguments\n"), argc); + return 0; + } + if ((wtype = lookupcty(ctydescs_rt, argv[argc - 1])) == CT_NONE) { + dbprintf(_("unknown conversion type %s\n"), argv[argc - 1]); + return 0; + } + + for (i = mask = conmask = 0; i < (argc - 1) / 2; i++) { + c = lookupcty(ctydescs_rt, argv[i * 2]); + if (c == CT_NONE) { + dbprintf(_("unknown conversion type %s\n"), argv[i * 2]); + return 0; + } + if (c == wtype) { + dbprintf(_("result type same as argument\n")); + return 0; + } + if (conmask & (1 << c)) { + dbprintf(_("conflicting conversion type %s\n"), + argv[i * 2]); + return 0; + } + if (!getvalue(argv[i * 2 + 1], c, &cvals[c])) + return 0; + mask |= 1 << c; + conmask |= ~ctydescs_rt[c].allowed; + } + v = 0; + for (c = (ctype_t)0; c < NCTS; c++) { + if (!(mask & (1 << c))) + continue; + v += bytevalue(c, &cvals[c]); + } + switch (wtype) { + case CT_BBOFF: + v &= BBMASK; + break; + case CT_BLKOFF: + v &= mp->m_blockmask; + break; + case CT_BYTE: + break; + case CT_DADDR: + v >>= BBSHIFT; + break; + case CT_RTBLOCK: + v = xfs_daddr_to_rtb(mp, v >> BBSHIFT); + break; + case CT_RTX: + v = xfs_daddr_to_rtb(mp, v >> BBSHIFT) / mp->m_sb.sb_rextsize; + break; + case CT_AGBLOCK: + case CT_AGINO: + case CT_AGNUMBER: + case CT_FSBLOCK: + case CT_INO: + case CT_INOIDX: + case CT_INOOFF: + /* shouldn't get here */ + ASSERT(0); + break; case CT_NONE: case NCTS: /* NOTREACHED */ @@ -243,6 +420,7 @@ void convert_init(void) { add_command(&convert_cmd); + add_command(&rtconvert_cmd); } static int @@ -290,6 +468,12 @@ getvalue(char *s, ctype_t ctype, cval_t *val) case CT_INOOFF: val->inooff = (int)v; break; + case CT_RTBLOCK: + val->rtblock = (xfs_rtblock_t)v; + break; + case CT_RTX: + val->rtx = (xfs_rtblock_t)v; + break; case CT_NONE: case NCTS: /* NOTREACHED */ @@ -299,13 +483,15 @@ getvalue(char *s, ctype_t ctype, cval_t *val) } static ctype_t -lookupcty(char *ctyname) +lookupcty( + const struct ctydesc *descs, + const char *ctyname) { ctype_t cty; const char **name; for (cty = (ctype_t)0; cty < NCTS; cty++) { - for (name = ctydescs[cty].names; *name; name++) { + for (name = descs[cty].names; name && *name; name++) { if (strcmp(ctyname, *name) == 0) return cty; } diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8 index de30fbc6230..40ff7de335e 100644 --- a/man/man8/xfs_db.8 +++ b/man/man8/xfs_db.8 @@ -953,6 +953,57 @@ Show position ring (if no argument is given), or move to a specific entry in the position ring given by .IR index . .TP +.BI "rtconvert " "type number" " [" "type number" "] ... " type +Convert from one address form to another for realtime section addresses. +The known +.IR type s, +with alternate names, are: +.RS 1.0i +.PD 0 +.HP +.B bboff +or +.B daddroff +(byte offset in a +.BR daddr ) +.HP +.B blkoff +or +.B fsboff or +.B rtboff +(byte offset in a +.B rtblock +or +.BR rtextent ) +.HP +.B byte +or +.B fsbyte +(byte address in filesystem) +.HP +.B daddr +or +.B bb +(disk address, 512-byte blocks) +.HP +.B rtblock +or +.B rtb +or +.B rtbno +(realtime filesystem block, see the +.B fsblock +command) +.HP +.B rtx +or +.B rtextent +(realtime extent) +.PD +.RE +.IP +Only conversions that "make sense" are allowed. +.TP .BI "sb [" agno ] Set current address to SB header in allocation group .IR agno . From patchwork Fri Dec 30 22:19:37 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: 13085667 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 7ECE0C4332F for ; Sat, 31 Dec 2022 02:28:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236130AbiLaC2b (ORCPT ); Fri, 30 Dec 2022 21:28:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231466AbiLaC2b (ORCPT ); Fri, 30 Dec 2022 21:28:31 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A30E1C921 for ; Fri, 30 Dec 2022 18:28: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 dfw.source.kernel.org (Postfix) with ESMTPS id 17ABB61CF1 for ; Sat, 31 Dec 2022 02:28:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79AF3C433D2; Sat, 31 Dec 2022 02:28:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453709; bh=7ZXxazAzlRZ6QluoLdP5vO8nVDRlvTiPh1Ry2ROZMTQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=DJkq219So7ZOML/q72/poi+SWvbGg3gkB6UbYqArDyue3MXfGUUiB/L1gnP4LUf43 KYHpmGB2Lb6Eq64ITgF87N7iNV6sXSSkSxusI9RXpWzd3o4r+71XBSpiQDmBF8x4qj d/cksHJND5IaITw0I7yQ+DjKtYao1fr4yUYSrCpNejvKMZP0aeFEmJftDaLMgkVCqs 6RbV+4rLN5kqrlPQ6RH7qHQ0hNoRvQD4Qbse16y1pbaLJBQ3KEKcuWQbZy5cUAWwgx tusYJwAK+hAmV3IR3ABMPk+qFN4SeMXhdq0zOz1uGljl4q3X6tp1Qr+SIklxBwcMlS 7buBlLOiPFcjQ== Subject: [PATCH 7/8] xfs_db: convert rtbitmap geometry From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:37 -0800 Message-ID: <167243877705.728317.14956604988449250736.stgit@magnolia> In-Reply-To: <167243877610.728317.12510123562097453242.stgit@magnolia> References: <167243877610.728317.12510123562097453242.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 rtconvert command to be able to convert realtime blocks and extents to locations within the rt bitmap. Signed-off-by: Darrick J. Wong --- db/convert.c | 38 ++++++++++++++++++++++++++++++++++++++ man/man8/xfs_db.8 | 10 ++++++++++ 2 files changed, 48 insertions(+) diff --git a/db/convert.c b/db/convert.c index 811bac00f71..691361604ee 100644 --- a/db/convert.c +++ b/db/convert.c @@ -30,6 +30,10 @@ ((uint64_t)(x) << mp->m_sb.sb_blocklog) #define rtx_to_rtblock(x) \ ((uint64_t)(x) * mp->m_sb.sb_rextsize) +#define rbmblock_to_bytes(x) \ + 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)) typedef enum { CT_NONE = -1, @@ -46,6 +50,8 @@ typedef enum { CT_INOOFF, /* byte offset in inode */ CT_RTBLOCK, /* realtime block */ CT_RTX, /* realtime extent */ + CT_RBMBLOCK, /* block within rt bitmap */ + CT_RBMWORD, /* word within rt bitmap */ NCTS } ctype_t; @@ -68,6 +74,8 @@ typedef union { int inooff; xfs_rtblock_t rtblock; xfs_rtblock_t rtx; + xfs_fileoff_t rbmblock; + unsigned int rbmword; } cval_t; static uint64_t bytevalue(ctype_t ctype, cval_t *val); @@ -94,6 +102,8 @@ static const char *inooff_names[] = { "inooff", "inodeoff", NULL }; static const char *rtblock_names[] = { "rtblock", "rtb", "rtbno", NULL }; static const char *rtx_names[] = { "rtx", "rtextent", NULL }; +static const char *rbmblock_names[] = { "rbmblock", "rbmb", NULL }; +static const char *rbmword_names[] = { "rbmword", "rbmw", NULL }; static const ctydesc_t ctydescs[NCTS] = { [CT_AGBLOCK] = { @@ -167,6 +177,14 @@ static const ctydesc_t ctydescs_rt[NCTS] = { .allowed = M(BBOFF)|M(BLKOFF), .names = rtx_names, }, + [CT_RBMBLOCK] = { + .allowed = M(RBMWORD), + .names = rbmblock_names, + }, + [CT_RBMWORD] = { + .allowed = M(RBMBLOCK), + .names = rbmword_names, + }, }; static const cmdinfo_t convert_cmd = @@ -207,6 +225,10 @@ bytevalue(ctype_t ctype, cval_t *val) return rtblock_to_bytes(val->rtblock); case CT_RTX: return rtblock_to_bytes(rtx_to_rtblock(val->rtx)); + case CT_RBMBLOCK: + return rbmblock_to_bytes(val->rbmblock); + case CT_RBMWORD: + return rbmword_to_bytes(val->rbmword); case CT_NONE: case NCTS: break; @@ -308,6 +330,8 @@ convert_f(int argc, char **argv) break; case CT_RTBLOCK: case CT_RTX: + case CT_RBMBLOCK: + case CT_RBMWORD: /* shouldn't get here */ ASSERT(0); break; @@ -397,6 +421,14 @@ rtconvert_f(int argc, char **argv) case CT_RTX: v = xfs_daddr_to_rtb(mp, v >> BBSHIFT) / mp->m_sb.sb_rextsize; break; + case CT_RBMBLOCK: + v = xfs_rtx_to_rbmblock(mp, xfs_rtb_to_rtxt(mp, + xfs_daddr_to_rtb(mp, v >> BBSHIFT))); + break; + case CT_RBMWORD: + v = xfs_rtx_to_rbmword(mp, xfs_rtb_to_rtxt(mp, + xfs_daddr_to_rtb(mp, v >> BBSHIFT))); + break; case CT_AGBLOCK: case CT_AGINO: case CT_AGNUMBER: @@ -474,6 +506,12 @@ getvalue(char *s, ctype_t ctype, cval_t *val) case CT_RTX: val->rtx = (xfs_rtblock_t)v; break; + case CT_RBMBLOCK: + val->rbmblock = (xfs_fileoff_t)v; + break; + case CT_RBMWORD: + val->rbmword = (unsigned int)v; + break; case CT_NONE: case NCTS: /* NOTREACHED */ diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8 index 40ff7de335e..65d1a65b75f 100644 --- a/man/man8/xfs_db.8 +++ b/man/man8/xfs_db.8 @@ -999,6 +999,16 @@ command) or .B rtextent (realtime extent) +.HP +.B rbmblock +or +.B rbmb +(realtime bitmap block) +.HP +.B rbmword +or +.B rbmw +(32-bit word within a realtime bitmap block) .PD .RE .IP From patchwork Fri Dec 30 22:19:37 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: 13085668 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 C024CC4332F for ; Sat, 31 Dec 2022 02:28:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236139AbiLaC2s (ORCPT ); Fri, 30 Dec 2022 21:28:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231466AbiLaC2r (ORCPT ); Fri, 30 Dec 2022 21:28:47 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1866E1C921 for ; Fri, 30 Dec 2022 18:28:46 -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 9A14261CFE for ; Sat, 31 Dec 2022 02:28:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 067D5C433EF; Sat, 31 Dec 2022 02:28:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672453725; bh=8E7DZQFc8dmmvXphGRNfpgXkiqGlJoc64k50uSkpOKA=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=oPTd7Npk2L2VIP9FUFxESeA+T38ENMRoa15sCyZTkgSDzTHlV52wZI1raRm+RCVbD QZ5617IjHHdSECsvMj4UCF7ezo+Ne/VWcVx/YzgJ3zowxh3Qa530oYOKUaE0rhf9sh JUdGb0lFf8SW1pfemL8J3R7ybMBZ7yUZy0FAK0VfTxm4A01KzdzDR3jgbv5bRAvAfu Gr6it8rfdrfIMAfRNb6KNnLT3Sat+f/boKsi5an5yfOYr052/Gvmcn54XQTR0m1GNw YA0R9GWTaPPuCbkqx6Osvyr6cqGC/n4IGEzGElJn+Ld73PV3EOL6IPLUT5zbdxVB2a S0qgjr2HD7Aew== Subject: [PATCH 8/8] xfs_db: convert rtsummary geometry From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:19:37 -0800 Message-ID: <167243877718.728317.7495027757328955619.stgit@magnolia> In-Reply-To: <167243877610.728317.12510123562097453242.stgit@magnolia> References: <167243877610.728317.12510123562097453242.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 rtconvert command to be able to convert realtime blocks and extents to locations within the rt summary. Signed-off-by: Darrick J. Wong --- db/convert.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++--- man/man8/xfs_db.8 | 29 +++++++++++ 2 files changed, 162 insertions(+), 8 deletions(-) diff --git a/db/convert.c b/db/convert.c index 691361604ee..0aed1437dc4 100644 --- a/db/convert.c +++ b/db/convert.c @@ -52,6 +52,9 @@ typedef enum { CT_RTX, /* realtime extent */ CT_RBMBLOCK, /* block within rt bitmap */ CT_RBMWORD, /* word within rt bitmap */ + CT_RSUMBLOCK, /* block within rt summary */ + CT_RSUMLOG, /* log level for rtsummary computations */ + CT_RSUMINFO, /* info word within rt summary */ NCTS } ctype_t; @@ -76,6 +79,7 @@ typedef union { xfs_rtblock_t rtx; xfs_fileoff_t rbmblock; unsigned int rbmword; + xfs_fileoff_t rsumblock; } cval_t; static uint64_t bytevalue(ctype_t ctype, cval_t *val); @@ -104,6 +108,12 @@ static const char *rtblock_names[] = { "rtblock", "rtb", "rtbno", NULL }; static const char *rtx_names[] = { "rtx", "rtextent", NULL }; static const char *rbmblock_names[] = { "rbmblock", "rbmb", NULL }; 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 int rsuminfo; +static int rsumlog; static const ctydesc_t ctydescs[NCTS] = { [CT_AGBLOCK] = { @@ -154,37 +164,50 @@ static const ctydesc_t ctydescs[NCTS] = { static const ctydesc_t ctydescs_rt[NCTS] = { [CT_BBOFF] = { - .allowed = M(DADDR)|M(RTBLOCK), + .allowed = M(DADDR)|M(RTBLOCK)|M(RSUMLOG), .names = bboff_names, }, [CT_BLKOFF] = { - .allowed = M(RTBLOCK), + .allowed = M(RTBLOCK)|M(RSUMLOG), .names = rtblkoff_names, }, [CT_BYTE] = { - .allowed = 0, + .allowed = 0|M(RSUMLOG), .names = byte_names, }, [CT_DADDR] = { - .allowed = M(BBOFF), + .allowed = M(BBOFF)|M(RSUMLOG), .names = daddr_names, }, [CT_RTBLOCK] = { - .allowed = M(BBOFF)|M(BLKOFF), + .allowed = M(BBOFF)|M(BLKOFF)|M(RSUMLOG), .names = rtblock_names, }, [CT_RTX] = { - .allowed = M(BBOFF)|M(BLKOFF), + .allowed = M(BBOFF)|M(BLKOFF)|M(RSUMLOG), .names = rtx_names, }, [CT_RBMBLOCK] = { - .allowed = M(RBMWORD), + .allowed = M(RBMWORD)|M(RSUMLOG), .names = rbmblock_names, }, [CT_RBMWORD] = { - .allowed = M(RBMBLOCK), + .allowed = M(RBMBLOCK)|M(RSUMLOG), .names = rbmword_names, }, + /* must be specified in order rsumlog -> rsuminfo -> rsumblock */ + [CT_RSUMBLOCK] = { + .allowed = 0, + .names = rsumblock_names, + }, + [CT_RSUMLOG] = { + .allowed = M(RSUMINFO)|M(RSUMBLOCK), + .names = rsumlog_names, + }, + [CT_RSUMINFO] = { + .allowed = M(RSUMBLOCK), + .names = rsumword_names, + }, }; static const cmdinfo_t convert_cmd = @@ -195,6 +218,39 @@ static const cmdinfo_t rtconvert_cmd = { "rtconvert", NULL, rtconvert_f, 3, 9, 0, "type num [type num]... type", "convert from one realtime address form to another", NULL }; +static inline uint64_t +rsumblock_to_bytes( + xfs_fileoff_t rsumblock) +{ + /* + * We compute the rt summary file block with this formula: + * sumoffs = (log2len * sb_rbmblocks) + rbmblock; + * sumblock = sumoffs / blockwsize; + * + * Hence the return value is the inverse of this: + * sumoffs = (rsumblock * blockwsize) + rsuminfo; + * rbmblock = sumoffs % (log2len * sb_rbmblocks); + */ + xfs_rtsumoff_t sumoff; + xfs_fileoff_t rbmblock; + + if (rsumlog < 0) { + dbprintf(_("need to set rsumlog\n")); + return 0; + } + if (rsuminfo < 0) { + dbprintf(_("need to set rsuminfo\n")); + return 0; + } + + sumoff = rsuminfo + (rsumblock * mp->m_blockwsize); + if (rsumlog) + rbmblock = sumoff % (rsumlog * mp->m_sb.sb_rbmblocks); + else + rbmblock = sumoff; + return rbmblock_to_bytes(rbmblock); +} + static uint64_t bytevalue(ctype_t ctype, cval_t *val) { @@ -229,6 +285,16 @@ bytevalue(ctype_t ctype, cval_t *val) return rbmblock_to_bytes(val->rbmblock); case CT_RBMWORD: return rbmword_to_bytes(val->rbmword); + case CT_RSUMBLOCK: + return rsumblock_to_bytes(val->rbmblock); + case CT_RSUMLOG: + case CT_RSUMINFO: + /* + * These have to specified before rsumblock, and are stored in + * global variables. Hence they do not adjust the disk address + * value. + */ + return 0; case CT_NONE: case NCTS: break; @@ -332,6 +398,9 @@ convert_f(int argc, char **argv) case CT_RTX: case CT_RBMBLOCK: case CT_RBMWORD: + case CT_RSUMBLOCK: + case CT_RSUMLOG: + case CT_RSUMINFO: /* shouldn't get here */ ASSERT(0); break; @@ -352,6 +421,40 @@ xfs_daddr_to_rtb( return daddr >> mp->m_blkbb_log; } +static inline uint64_t +rt_daddr_to_rsumblock( + struct xfs_mount *mp, + uint64_t input) +{ + xfs_fileoff_t rbmblock; + + if (rsumlog < 0) { + dbprintf(_("need to set rsumlog\n")); + return 0; + } + + rbmblock = xfs_rtx_to_rbmblock(mp, xfs_rtb_to_rtxt(mp, + xfs_daddr_to_rtb(mp, input >> BBSHIFT))); + return xfs_rtsumoffs_to_block(mp, xfs_rtsumoffs(mp, rsumlog, rbmblock)); +} + +static inline uint64_t +rt_daddr_to_rsuminfo( + struct xfs_mount *mp, + uint64_t input) +{ + xfs_fileoff_t rbmblock; + + if (rsumlog < 0) { + dbprintf(_("need to set rsumlog\n")); + return 0; + } + + rbmblock = xfs_rtx_to_rbmblock(mp, xfs_rtb_to_rtxt(mp, + xfs_daddr_to_rtb(mp, input >> BBSHIFT))); + return xfs_rtsumoffs_to_infoword(mp, xfs_rtsumoffs(mp, rsumlog, rbmblock)); +} + static int rtconvert_f(int argc, char **argv) { @@ -363,6 +466,9 @@ rtconvert_f(int argc, char **argv) uint64_t v; ctype_t wtype; + rsumlog = -1; + rsuminfo = -1; + /* move past the "rtconvert" command */ argc--; argv++; @@ -429,6 +535,16 @@ rtconvert_f(int argc, char **argv) v = xfs_rtx_to_rbmword(mp, xfs_rtb_to_rtxt(mp, xfs_daddr_to_rtb(mp, v >> BBSHIFT))); break; + case CT_RSUMBLOCK: + v = rt_daddr_to_rsumblock(mp, v); + break; + case CT_RSUMLOG: + dbprintf(_("cannot convert to rsumlog\n")); + return 0; + break; + case CT_RSUMINFO: + v = rt_daddr_to_rsuminfo(mp, v); + break; case CT_AGBLOCK: case CT_AGINO: case CT_AGNUMBER: @@ -512,6 +628,15 @@ getvalue(char *s, ctype_t ctype, cval_t *val) case CT_RBMWORD: val->rbmword = (unsigned int)v; break; + case CT_RSUMBLOCK: + val->rsumblock = (xfs_fileoff_t)v; + break; + case CT_RSUMLOG: + rsumlog = (unsigned int)v; + break; + case CT_RSUMINFO: + rsuminfo = (unsigned int)v; + break; case CT_NONE: case NCTS: /* NOTREACHED */ diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8 index 65d1a65b75f..1246eb6327c 100644 --- a/man/man8/xfs_db.8 +++ b/man/man8/xfs_db.8 @@ -1009,10 +1009,39 @@ or or .B rbmw (32-bit word within a realtime bitmap block) +.HP +.B rsumblock +or +.B rsmb +(realtime summary file block) +.HP +.B rsuminfo +or +.B rsmi +(32-bit counter within a realtime summary block) +.HP +.B rsumlog +or +.B rsml +(log2len parameter used for summary file offset computations) .PD .RE .IP Only conversions that "make sense" are allowed. + +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 +given log2(length) that start in a given rt bitmap block. + +To compute summary file location information for a given rt bitmap block, a +log2(extent length) must be specified as the last type/number pair before the +conversion type, and the type must be +.BR rsumlog . + +To compute the rt bitmap block from summary file location, the type/number pairs +must be specified exactly in the order +.BR rsumlog ", " rsuminfo ", " rsumblock . + .TP .BI "sb [" agno ] Set current address to SB header in allocation group