From patchwork Tue Oct 29 15:47:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13855111 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 003FE1957E9 for ; Tue, 29 Oct 2024 15:47:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730216878; cv=none; b=k/f4gimB1uX/AUbUG8NXn0h77olvdeLTvg+7nl6XeFCcH5uc3DkTAEZGIaK8xHdwblvqZfOJ5SMvjuBllTET4AIsB/iPdWtZaspVZKk4mofTGpldaHUSroLa0flu+LuoZutVcgwiKmpVp2DqFi6VBgseBmch6CvH3B/gLhi+xMI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730216878; c=relaxed/simple; bh=ur2gudVZzIXpQd8c6rSBo5jZllmdXOFK2Rv3VShCmr8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NdBUwZ3rPRxb3mL/mw30kfH5/FMxtE9AVy+z08uwveaMwq/0GXViway+kLiTAJlo1jCOJ3thxCx9KVAYLZ5vznuDqtaesb2b5LZTR24viH05avTvwrFnJn/U3g53gizZJRZ+9uWYQ7G9yRVfE0cxNo8bx8GS7buxsSikCfiG99s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bqtBHM9J; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bqtBHM9J" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AA21C4CECD; Tue, 29 Oct 2024 15:47:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730216877; bh=ur2gudVZzIXpQd8c6rSBo5jZllmdXOFK2Rv3VShCmr8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=bqtBHM9JGgLIM2rShIZvmyWBJcB/G1drnXJttd5CG/hwnUzvvf+arq33Jkf/lgbcy K5aDxx3EizjG/dhq2A1N4Vx4lIu8NCklUO807avLZ7xtACw72PZQOgdIrvjtEKkfZC vbxa8Drfa+FD1fXoEQ/peu/z3j3oJ1SaRkBh6ofzZoXgFW32n9k0rZ9mj8gHcczBFO bMWI4Zg1S+lv2mNhAPWgHOOkuRtlP1Tir2ZrPBxpEOYT6uZXEcAxt3DOauMtOlVPdV f2QxCykq1IstxZZ5CqB+URcnXP/yLqmdxafbKjCQZl3cFErgfrRIaam49ssYjvbYWH BMmWtsJTXAyvw== Date: Tue, 29 Oct 2024 08:47:56 -0700 Subject: [PATCH 1/8] xfs_db: support passing the realtime device to the debugger From: "Darrick J. Wong" To: aalbersh@kernel.org, cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <173021673250.3128727.4592508216176625209.stgit@frogsfrogsfrogs> In-Reply-To: <173021673227.3128727.17882979358320595734.stgit@frogsfrogsfrogs> References: <173021673227.3128727.17882979358320595734.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Christoph Hellwig --- db/init.c | 7 +++++-- db/io.c | 28 +++++++++++++++++++++++----- db/io.h | 2 ++ db/xfs_admin.sh | 4 +++- man/man8/xfs_db.8 | 13 +++++++++++++ 5 files changed, 46 insertions(+), 8 deletions(-) diff --git a/db/init.c b/db/init.c index cea25ae52bd1b7..17fb094296c2b8 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.flags = LIBXFS_ISREADONLY; break; + case 'R': + x.rt.name = optarg; + break; case 'l': x.log.name = optarg; break; diff --git a/db/io.c b/db/io.c index 9b2c6b4cf7e963..26b8e78c2ebda8 100644 --- a/db/io.c +++ b/db/io.c @@ -458,6 +458,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); @@ -465,7 +466,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)); @@ -474,6 +475,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); @@ -482,7 +484,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)); } @@ -541,9 +543,9 @@ static void __set_cur( struct xfs_buftarg *btargp, const typ_t *type, - xfs_daddr_t blknum, - int len, - int ring_flag, + xfs_daddr_t blknum, + int len, + int ring_flag, bbmap_t *bbmap) { struct xfs_buf *bp; @@ -647,6 +649,22 @@ set_log_cur( __set_cur(mp->m_logdev_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( diff --git a/db/io.h b/db/io.h index f48b67b47a2b55..cece66a1cf825a 100644 --- a/db/io.h +++ b/db/io.h @@ -51,6 +51,8 @@ extern void set_cur(const struct typ *type, xfs_daddr_t blknum, int len, int ring_add, bbmap_t *bbmap); extern void set_log_cur(const struct typ *type, xfs_daddr_t blknum, int len, int ring_add, bbmap_t *bbmap); +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 cc650c4255036b..52a658ba4a540f 100755 --- a/db/xfs_admin.sh +++ b/db/xfs_admin.sh @@ -8,6 +8,7 @@ status=0 require_offline="" require_online="" DB_OPTS="" +DB_DEV_OPTS="" REPAIR_OPTS="" IO_OPTS="" REPAIR_DEV_OPTS="" @@ -42,6 +43,7 @@ do require_offline=1 ;; r) REPAIR_DEV_OPTS=" -r '$OPTARG'" + DB_DEV_OPTS=" -R '$OPTARG'" require_offline=1 ;; u) DB_OPTS=$DB_OPTS" -r -c uuid" @@ -89,7 +91,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 291ec1c5827bfd..5faf8dbb1d679f 100644 --- a/man/man8/xfs_db.8 +++ b/man/man8/xfs_db.8 @@ -14,6 +14,9 @@ .SH SYNOPSIS .B \-l .I logdev ] [ +.B \-R +.I rtdev +] [ .B \-p .I progname ] @@ -80,6 +83,16 @@ .SH OPTIONS 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 Tue Oct 29 15:48:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13855112 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A195196C9C for ; Tue, 29 Oct 2024 15:48:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730216894; cv=none; b=NXkz3Fw0VFLU9sjRDqjoVPe9VCVO2qHOfu6tmpMljxmts/yD+E889WnyObOPPytH0uBKdxgyrZgGwcEcojSzz/vU5Eq+IGoY87MSBTS6x0HIkyXJCTZqlZYED2zD1pLObMw6iNkfPFwyXrOUyrNcaipIkNt0OJkQvcV+Ba0eml8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730216894; c=relaxed/simple; bh=EqnF7CIpRC91gS4sEMx44gI53kQAc3v8T63Dw+Xutbw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=i4wRd1IgbSyod9STTbdwaz0pwXYRzaAy1OsdyKXEsifYP6donCsv3YjQ/ZIXpqFsjmTAX8Z934g+fXmRi69C8UlAQHZzyVwZdFAiVaEiaUs8jtHFkFg0Kt4HXVTjK6gW+NVGGqeQfolT1/GmIFlvMLXSWpkVCbZ9RRk5cQOIhBw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uxBkyKqd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uxBkyKqd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97C3AC4CEE8; Tue, 29 Oct 2024 15:48:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730216893; bh=EqnF7CIpRC91gS4sEMx44gI53kQAc3v8T63Dw+Xutbw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=uxBkyKqdn0vOpdFwpzOdwGbc5YIQYHthzksuwr9X39v+bUTGhvJRAt8Ga3UwA6HE0 gu3RZS6QlUISRm7un1jfpAT2vIyock2Cmypvhlln+lSwy/Ewglp5VSmyBSPEg/7vYk gajcEKAjMM4l2Ao1nsbHq0NXf6LPh7KwhgJgCq9up2wEAsR7CSAfuSa9TAraqSU6xd nx8U0izAryDHNxSzPAdoNnUyPH1kWWHdIMAPgWwodrDaZdravblQlqm4wKloOgCFBK oltKMnqNikvYw0ILJrXBJk7GUzE9gkVRrHcKdkv+j2H1+q+vnPAJ8/SIu5JSm75mJA vg2tsOjuoPvzg== Date: Tue, 29 Oct 2024 08:48:12 -0700 Subject: [PATCH 2/8] xfs_db: report the realtime device when associated with each io cursor From: "Darrick J. Wong" To: aalbersh@kernel.org, cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <173021673265.3128727.15473481352708315057.stgit@frogsfrogsfrogs> In-Reply-To: <173021673227.3128727.17882979358320595734.stgit@frogsfrogsfrogs> References: <173021673227.3128727.17882979358320595734.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong When db is reporting on an io cursor and the cursor points to the realtime device, print that fact. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- db/block.c | 2 ++ db/io.c | 11 +++++++++++ db/io.h | 1 + 3 files changed, 14 insertions(+) diff --git a/db/block.c b/db/block.c index 22930e5a287e8f..bd25cdbe193f4f 100644 --- a/db/block.c +++ b/db/block.c @@ -133,6 +133,8 @@ daddr_f( 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); diff --git a/db/io.c b/db/io.c index 26b8e78c2ebda8..3841c0dcb86ead 100644 --- a/db/io.c +++ b/db/io.c @@ -159,6 +159,15 @@ iocur_is_extlogdev(const struct iocur *ioc) 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, @@ -171,6 +180,8 @@ print_iocur( 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); diff --git a/db/io.h b/db/io.h index cece66a1cf825a..653724e90bd270 100644 --- a/db/io.h +++ b/db/io.h @@ -60,6 +60,7 @@ 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 Tue Oct 29 15:48:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13855113 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2DD4197A7C for ; Tue, 29 Oct 2024 15:48:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730216909; cv=none; b=RWZOxHKooNVBygEZn+P9HwkCg/aMDXQ1XMrQspm5oWWyyxcee8AycnH//K7is3dqh++OmwEzW+P/yxbC2pEYlx+imGmkafAhlYwTEt/87nIICR2UVLEpnSm70+GFrcEsnMfy/PNisk6X3aGRKNs97J0KiWGM+PpuPMF23r1v0Kw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730216909; c=relaxed/simple; bh=BxdhsulxgWizC8PUXkmOJHyz5/y0xgFDBCXZzpumeRs=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hpDmuMoh7Hix6f4o0/nEECrd4UCK32Hs1xa3dQmxNOheEBJDyNtfDY4hRmdffjDDB5sbX8pTq/TRAtr9B1wmvcEGkrsWVhoxyqY/aKxA4r+6PTJAYt9PE+4hB8T3O1etsF+N2jZX7etZmN5UjZjVrXlOUD4sfhHxVe6VS/m0ixs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=szMo/LXo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="szMo/LXo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AE27C4CEE5; Tue, 29 Oct 2024 15:48:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730216909; bh=BxdhsulxgWizC8PUXkmOJHyz5/y0xgFDBCXZzpumeRs=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=szMo/LXo/oF+VbZus5U2DdqL+lxMeZz/ibB9vhJTPX0dbeKBd+DPXZCiDOPvYpi1f rStNc0nsiU9FWZsxufgk233cKlmXkUDxNShR9lfZQ/7V2Y597AueRN3qNSCbLJRhTg fN5OX+UMqG1uRvp2llBzykKybFVaWDxyIk4cBbK3aLaQjpLYau7zlp/rmYV0AdgLcG jRtUSg9IgSDJdyDk7JtHzBG9HEFkPZTjnFQhmlMENGpVPiA3/pKPGdgVPr2FUzhWDl GyIlSM0EI9zJiNQDUjZOEJ2GHWs5t9ddnBDjwKdEsGGnJG5c0638VuvGwUSgFbQQpK cThZxsWUXlhWw== Date: Tue, 29 Oct 2024 08:48:28 -0700 Subject: [PATCH 3/8] xfs_db: make the daddr command target the realtime device From: "Darrick J. Wong" To: aalbersh@kernel.org, cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <173021673280.3128727.10246665487603714123.stgit@frogsfrogsfrogs> In-Reply-To: <173021673227.3128727.17882979358320595734.stgit@frogsfrogsfrogs> References: <173021673227.3128727.17882979358320595734.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Christoph Hellwig --- 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 bd25cdbe193f4f..6ad9f038c6da67 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,16 +117,36 @@ daddr_help(void) )); } +enum daddr_target { + DT_DATA, + DT_RT, +}; + static int daddr_f( int argc, char **argv) { + xfs_rfsblock_t max_daddrs = mp->m_sb.sb_dblocks; int64_t d; char *p; int bb_count = BTOBB(mp->m_sb.sb_sectsize); + int c; + 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)) @@ -140,14 +160,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, bb_count, DB_RING_ADD, NULL); + switch (tgt) { + case DT_DATA: + set_cur(&typtab[TYP_DATA], d, bb_count, DB_RING_ADD, NULL); + break; + case DT_RT: + set_rt_cur(&typtab[TYP_DATA], d, bb_count, DB_RING_ADD, NULL); + break; + } return 0; } diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8 index 5faf8dbb1d679f..f50ac949be0189 100644 --- a/man/man8/xfs_db.8 +++ b/man/man8/xfs_db.8 @@ -671,7 +671,7 @@ .SH COMMANDS 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 @@ -680,6 +680,10 @@ .SH COMMANDS 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 Tue Oct 29 15:48:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13855114 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F1A1198A05 for ; Tue, 29 Oct 2024 15:48:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730216925; cv=none; b=kIalXoea+CKWPAXkiUhClJFBoYBPvcLCwe2pIKhqlnubspEyeDJQODKEPMPQVF4W5bRI0l5Ef1mNATnmdqsw50y0JFgmi87ejoMw3OWZm9vsF6sbxZh2hiEAGtTfzHSShbZ6lxV6ih12XA3/4MkvX1aXgM7HLRMhEPlZSj70Gy0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730216925; c=relaxed/simple; bh=2xYMwkmibIPSZE3hDgfZElun/UslUCuuyF7HCb441to=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=svr9GeQcdAwe/zK6aSmDSH0yws9MoW4Bk15J9Xn5zo+F0wSWCJ9J7CKCXF2VzdpoCjEa2yHcT3fiNgwCx3BJQVcrjpAa9DhdUsNtcgzST/G55WG6IfUwnprzPRxH2HilV7vJTEWK5zLAwa53RZ0mh8lJ3bfMCJqSMjWhZgeNVXE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NI1lZ07b; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NI1lZ07b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A312C4CECD; Tue, 29 Oct 2024 15:48:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730216925; bh=2xYMwkmibIPSZE3hDgfZElun/UslUCuuyF7HCb441to=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=NI1lZ07bz0FW4SsafXfQhKZw/pIXC+cgtP32FJbwRtAsJu9jmCznmWAEgYFfV8lRe +IlcQmg1jG15hrCPbVx0wJ8dRVTW+iHHTgtKvhU1rJTJ61Ugs8/5vV2OFX9oM5dJL+ dB+UX2Yr0cN+LGhyJL4DnU3uINwEQPCUivvr2ejhAxMrdufxwmK9Z95jUC7xoYjRGJ j7/tiy+yKaHChmYByML8H8jwlir8iih0t6lEtv23weDcFaxKTysqvwbX844XWV/Awk 4emSHA9B7ajNPGFapRyPIhBaji9z5C5hl6iEobKi9Dj+NZFCpaXuHt5YhZKZEQzCJK Js1BdN7qvVABQ== Date: Tue, 29 Oct 2024 08:48:44 -0700 Subject: [PATCH 4/8] xfs_db: access realtime file blocks From: "Darrick J. Wong" To: aalbersh@kernel.org, cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <173021673296.3128727.1175236924173292657.stgit@frogsfrogsfrogs> In-Reply-To: <173021673227.3128727.17882979358320595734.stgit@frogsfrogsfrogs> References: <173021673227.3128727.17882979358320595734.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Now that we have 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 Reviewed-by: Christoph Hellwig --- db/block.c | 17 +++++++++++++++-- db/block.h | 20 ++++++++++++++++++++ db/faddr.c | 5 ++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/db/block.c b/db/block.c index 6ad9f038c6da67..87118a4751ef94 100644 --- a/db/block.c +++ b/db/block.c @@ -196,6 +196,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, @@ -235,8 +242,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], xfs_rtb_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/block.h b/db/block.h index 7c4e8cb2acb051..55843a6b521393 100644 --- a/db/block.h +++ b/db/block.h @@ -3,8 +3,28 @@ * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc. * All Rights Reserved. */ +#ifndef __XFS_DB_BLOCK_H +#define __XFS_DB_BLOCK_H struct field; extern void block_init(void); extern void print_block(const struct field *fields, int argc, char **argv); + +static inline xfs_daddr_t +xfs_rtb_to_daddr( + struct xfs_mount *mp, + xfs_rtblock_t rtb) +{ + return rtb << 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; +} + +#endif /* __XFS_DB_BLOCK_H */ diff --git a/db/faddr.c b/db/faddr.c index ec4aae68bb5a81..e2f9587da0a67c 100644 --- a/db/faddr.c +++ b/db/faddr.c @@ -15,6 +15,7 @@ #include "bmap.h" #include "output.h" #include "init.h" +#include "block.h" void fa_agblock( @@ -323,7 +324,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], xfs_rtb_to_daddr(mp, bno), blkbb, + DB_RING_ADD, NULL); } /*ARGSUSED*/ From patchwork Tue Oct 29 15:49:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13855115 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 116AF1957F4 for ; Tue, 29 Oct 2024 15:49:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730216941; cv=none; b=nCf22Uw/BPt5Ybmsj1CMukGBu5JSI8YZBRT1mSr8v03rxpX5Er+3aDnHFICENPGCaWObek2/IPWfxAWmmAzQDLSK3NAKKoOjF2kGv/GCRAMliQr4iYXrPHGs5OiP0qEyrXYvAZD/CeOjV7m/UuFg4ntmU50C1mA4+nEe/J7IksA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730216941; c=relaxed/simple; bh=k26uNBCWTF6ITmIeAt87+NtbWhAcA5pqm/M1tuUsVyw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=i2cUWKDj60lQ99EoPVgmNwSR5Rbii4G+nSjagApYwQDe4/1+78ZOeN8EPBLULeFwnZLYFnnmfkPMJd2mUIQQM7p19mY/rATke1Fc+tbLB3gStloSVSJj2+5cYvk/f4DZBCYCFbw/xlArOJWs1hR0brrc0TNnXrSc1ILmQA9b9z4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W2BKdRsC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="W2BKdRsC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 983ACC4CECD; Tue, 29 Oct 2024 15:49:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730216940; bh=k26uNBCWTF6ITmIeAt87+NtbWhAcA5pqm/M1tuUsVyw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=W2BKdRsC2n2AS/Q7dlSY/vSxoItvmyM211t0B21+W3qQqH5DutlSAqkaUR/QgfbUH esg6zF7hOBBjLhitUNOlv73t54XxBH0cs0WplDKkFXPcKRVL7LzUa2hlByViHly0Es cflir5GKO9H8MdBvWm1EkIr3D1HbsIT2+WPYmP6o6RLv7ChmwqTfuRg6uMAMwdemHK oIRWO4N4cH6YpunKp7FghMnslz4IvTly8n0Z+jDEJRGjOoIyyA/XYV+3ChBacg3lqM YxYyIO9/qlHqMh/laNbt2BYQGn4zPNUkqKMWr3PKMvxYwL5D/XgQe0oZUGICgHI+aY DF9ZFTb+mQFtw== Date: Tue, 29 Oct 2024 08:49:00 -0700 Subject: [PATCH 5/8] xfs_db: access arbitrary realtime blocks and extents From: "Darrick J. Wong" To: aalbersh@kernel.org, cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <173021673311.3128727.237498638164875250.stgit@frogsfrogsfrogs> In-Reply-To: <173021673227.3128727.17882979358320595734.stgit@frogsfrogsfrogs> References: <173021673227.3128727.17882979358320595734.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Christoph Hellwig --- db/block.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++ man/man8/xfs_db.8 | 22 +++++++++++ 2 files changed, 131 insertions(+) diff --git a/db/block.c b/db/block.c index 87118a4751ef94..79ae0ea5802a83 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 @@ -302,6 +314,103 @@ 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_daddr_to_rtb(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_rtb_to_daddr(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" +)); +} + +/* + * Move the cursor to a specific location on the realtime block device given + * a linear address in units of realtime extents. + */ +static int +rtextent_f( + int argc, + char **argv) +{ + xfs_rtblock_t rtbno; + xfs_rtxnum_t rtx; + char *p; + + if (argc == 1) { + if (!iocur_is_rtdev(iocur_top)) { + dbprintf(_("cursor does not point to rt device\n")); + return 0; + } + + rtbno = xfs_daddr_to_rtb(mp, iocur_top->off >> BBSHIFT); + dbprintf(_("current rtextent is %lld\n"), + xfs_rtb_to_rtx(mp, rtbno)); + 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_rtb_to_daddr(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 f50ac949be0189..48afcb6e81787b 100644 --- a/man/man8/xfs_db.8 +++ b/man/man8/xfs_db.8 @@ -1099,6 +1099,28 @@ .SH COMMANDS Exit .BR xfs_db . .TP +.BI "rtblock [" rtbno ] +Set current address to the location on the realtime device given by +.IR rtbno . +This value must be a realtime block number. +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 location on the realtime device given by +.IR rtextent . +This value must be a linear address in units of realtime extents. +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 Tue Oct 29 15:49:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13855116 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCD78194C7A for ; Tue, 29 Oct 2024 15:49:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730216956; cv=none; b=SAivyoels5xrWsYK6/+a4lcn0wZGjdc75KnFlumdCS+4J3XPXThIPN3R2x55dvfwUgT5+P9WmfdTe7yndB0P95/ffqX2mOOnrMzStQeM6Jvo5KrCT5WcegRJdLKO/d6arhT9M/+LvU1bCOTpKbTUJ/dJ0l60reMSAoZW0w1SjA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730216956; c=relaxed/simple; bh=/ERVAbv5qOnpmjz4LXYxFJ+7nRZwdDSvj6Sj3RzwP0s=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kqpy7IkXso7unpBxvzrnUkU8BlWtjPsJ9ykuXERIFmdQwkAGvhF8DCSJjYJjrRUh9k1xL8ozk8Pi+oMlbf6dHACG1AbmmnuNYxpJ+17V9pmS6tD1uzs9Ro/AFdGp0WC/vM6m4v7v1ZFPGFiiWAbjBPIryXj+YNCED6p5pEr2Zws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NeglKQxj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NeglKQxj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54282C4CECD; Tue, 29 Oct 2024 15:49:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730216956; bh=/ERVAbv5qOnpmjz4LXYxFJ+7nRZwdDSvj6Sj3RzwP0s=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=NeglKQxj3JLb219zx+5fv1n99jK8cSJHUMx7MpbkGclAJyCWMA2UTsgV2Ezug8CSk 12WXzJ0knaZ5A1MFSGbJ2h/MUKa/+ffVm5sygZzZHVsjPJDD5zoE44LpG6ZpDqKBav cG0M1QjAziPGPkP7f6zWnszcUje6mSw3K+Z6bZxTsc1N8Ffdqs/mclu87uoQc24+q1 Zi1om4i3z9WjmWD4knAy/L1mkp9Ng0kIlMKTiALH5q2Vo87K09vloNNB5uDiit1USG klZZMK0Q+vCIgEmQN6sGqmoKZ80iKvlyL2ydkmAvv49wN8klHjNCkYHst7RPd8Viof ezBcqjbHFNKEw== Date: Tue, 29 Oct 2024 08:49:15 -0700 Subject: [PATCH 6/8] xfs_db: enable conversion of rt space units From: "Darrick J. Wong" To: aalbersh@kernel.org, cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <173021673326.3128727.9571214053803732449.stgit@frogsfrogsfrogs> In-Reply-To: <173021673227.3128727.17882979358320595734.stgit@frogsfrogsfrogs> References: <173021673227.3128727.17882979358320595734.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Christoph Hellwig --- db/convert.c | 253 ++++++++++++++++++++++++++++++++++++++++++++++++----- man/man8/xfs_db.8 | 51 +++++++++++ 2 files changed, 281 insertions(+), 23 deletions(-) diff --git a/db/convert.c b/db/convert.c index e1466057031da6..4c2ff1c5804c47 100644 --- a/db/convert.c +++ b/db/convert.c @@ -8,6 +8,7 @@ #include "command.h" #include "output.h" #include "init.h" +#include "block.h" #define M(A) (1 << CT_ ## A) #define agblock_to_bytes(x) \ @@ -26,6 +27,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 +45,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 +67,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 +84,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 +93,119 @@ 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 +232,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 +264,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 +335,99 @@ 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 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 +441,7 @@ void convert_init(void) { add_command(&convert_cmd); + add_command(&rtconvert_cmd); } static int @@ -290,6 +489,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 +504,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 48afcb6e81787b..0bf434299a3fb4 100644 --- a/man/man8/xfs_db.8 +++ b/man/man8/xfs_db.8 @@ -1127,6 +1127,57 @@ .SH COMMANDS 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 Tue Oct 29 15:49:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13855117 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 609FB1946C3 for ; Tue, 29 Oct 2024 15:49:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730216972; cv=none; b=rHwY5WLoTXT9YN5YZuFAYeyjHBh4P2E/T61ijZD4fNz1fXgbccWc0E9RH7p7KetTDsUF0dm7JyK3rI1a9iiya01ClyPe2ySOaZI961U/SnXtUHj04mmam2F89dP2GO69ogeZoEdyqOFuTCd0ccCFhOfuVNTBWQ61N4UfUAWldIg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730216972; c=relaxed/simple; bh=3anpG3LeRIqS329po5OC4XLorhYdVJ8rgK5i4BUPD/Y=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iQ6BECVdpSEUeHq2Qnd+idMRTWG9bBs37XpS9RqbMKdUYsUeLOgy6zR//lydFJ63KrHC1lhMPn0N5GENZuFGcq007L6EDgDyyAPfQaZGJMhk/cw3LRAWA8Pw6xV55gAgrr/n0aDxNR6zfauKh3paQm+C2EaGi6eRvSeD1Ntie1E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bFWr8jlA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bFWr8jlA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7209C4CECD; Tue, 29 Oct 2024 15:49:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730216971; bh=3anpG3LeRIqS329po5OC4XLorhYdVJ8rgK5i4BUPD/Y=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=bFWr8jlAEY71qoMQKvudxB9oqJVi084+F6rin6sQ4w/aOpzaFy12nFWldEuOzLa4B Y9ZRq5fSWjS6yKj2io+wqTpsu1PlCcSltdUbV/QONZXrB0+XWxFeyfjx4TkncmqTb4 5mWvJOEpF/BY5fkzABpfGoyXKzqHYAvs4lUtVgECtP0L0zUVIPHVqUxmvlV9isCTOG z8MgeNDhp7QwEloiaYc8euRVLXVGdpkM+95notCEMkb8SmI19McwRkFMq6R+kxMQDP 2af04+gbLW2FPdZksXhxRSSmr6/q7hvXD9dsKNauelBV6stvgegZuXBIAQKCO7PxjZ huRMX5Jn4wlEQ== Date: Tue, 29 Oct 2024 08:49:31 -0700 Subject: [PATCH 7/8] xfs_db: convert rtbitmap geometry From: "Darrick J. Wong" To: aalbersh@kernel.org, cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <173021673341.3128727.12682444981106419639.stgit@frogsfrogsfrogs> In-Reply-To: <173021673227.3128727.17882979358320595734.stgit@frogsfrogsfrogs> References: <173021673227.3128727.17882979358320595734.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Christoph Hellwig --- db/convert.c | 40 ++++++++++++++++++++++++++++++++++++++++ man/man8/xfs_db.8 | 10 ++++++++++ 2 files changed, 50 insertions(+) diff --git a/db/convert.c b/db/convert.c index 4c2ff1c5804c47..7c10690f574f7a 100644 --- a/db/convert.c +++ b/db/convert.c @@ -31,6 +31,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, @@ -47,6 +51,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; @@ -69,6 +75,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); @@ -95,6 +103,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] = { @@ -196,6 +206,14 @@ static const ctydesc_t ctydescs_rt[NCTS] = { 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 = @@ -236,6 +254,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; @@ -337,6 +359,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; @@ -418,6 +442,16 @@ 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_rtx(mp, + xfs_daddr_to_rtb(mp, v >> BBSHIFT))); + break; + case CT_RBMWORD: + v = xfs_rtx_to_rbmword(mp, + xfs_rtb_to_rtx(mp, + xfs_daddr_to_rtb(mp, v >> BBSHIFT))); + break; case CT_AGBLOCK: case CT_AGINO: case CT_AGNUMBER: @@ -495,6 +529,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 0bf434299a3fb4..12fc4f3b51016b 100644 --- a/man/man8/xfs_db.8 +++ b/man/man8/xfs_db.8 @@ -1173,6 +1173,16 @@ .SH COMMANDS 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 Tue Oct 29 15:49:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13855118 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D34CB192D84 for ; Tue, 29 Oct 2024 15:49:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730216987; cv=none; b=U44a1SnhbqjrbgtUIyJ3bWxluTbKYDoLZr0MvYzynSni1dkbp9LoqdtlcM61j951P296/8v6NsNqt+MqmTBrs/s5giS3d2IqpNYDdM/lranAK3baVnWRVuacCc4SwwX4CrfjhHcc4fCynpQz4Bx+Ocp6h/4LPFcQC8zTtTwwpoI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730216987; c=relaxed/simple; bh=To2WTMOlLMOxIpwhvGmWidF/ZbPMofBP3P/EWYt95ng=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SYTuVNcnd/miFrsqedkEJi9bOMCUsHmEb05sqmYGhvmLfIirDWcaGdqxZXUDP0jyPvf+V5cvbrDxOIVjcyNqCEV97jW+kvgEyAa8bS56FrV6ZJHVVzUDKW0uSs3bMpvjtSMGkFTlrLLIWnZws8GaY84qSzqhIJAxjT8UTKpzgJc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=V8G186Gn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="V8G186Gn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C4E0C4CECD; Tue, 29 Oct 2024 15:49:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1730216987; bh=To2WTMOlLMOxIpwhvGmWidF/ZbPMofBP3P/EWYt95ng=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=V8G186Gn8esMgRaqwKZeaYOf1RX9bz4rmh9Zz48eDnBgrYlvZen/rvetEq+abruAc RZnIX6vsIAoR+ADOpXIdf//C/wp3ltYFJiTWavIxH8dXh6r5mnC3YuhDB+ib1p8qM7 RqmrJ+K49asaHk/XKx15wMQBj6aqfB8l1rx63BBqZIimKbfGPADe9dnyygWtzBjgRg hFm8oSsDjsOfWWqwhDsrxhX+Jundiqg287eKW2XecqJUjzVOxezk/WwZ3xcs9lRyIA 0Z17FWckQA1cVhgANbiPZIG+J6QnPdJAgMH5Xg7qB9q3UEei55osIarIZzSWqFc8VM iiWGsBV94gEpg== Date: Tue, 29 Oct 2024 08:49:47 -0700 Subject: [PATCH 8/8] xfs_db: convert rtsummary geometry From: "Darrick J. Wong" To: aalbersh@kernel.org, cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <173021673356.3128727.16741549406108571828.stgit@frogsfrogsfrogs> In-Reply-To: <173021673227.3128727.17882979358320595734.stgit@frogsfrogsfrogs> References: <173021673227.3128727.17882979358320595734.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Christoph Hellwig --- db/convert.c | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++--- man/man8/xfs_db.8 | 29 ++++++++++ 2 files changed, 182 insertions(+), 8 deletions(-) diff --git a/db/convert.c b/db/convert.c index 7c10690f574f7a..3014367e7d7652 100644 --- a/db/convert.c +++ b/db/convert.c @@ -53,6 +53,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; @@ -77,6 +80,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); @@ -105,6 +109,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] = { @@ -181,39 +191,60 @@ static const ctydesc_t ctydescs[NCTS] = { static const ctydesc_t ctydescs_rt[NCTS] = { [CT_BBOFF] = { .allowed = M(DADDR) | - M(RTBLOCK), + 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 = 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), + M(BLKOFF) | + M(RSUMLOG), .names = rtblock_names, }, [CT_RTX] = { .allowed = M(BBOFF) | - M(BLKOFF), + 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 = @@ -224,6 +255,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) { @@ -258,6 +322,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; @@ -361,6 +435,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; @@ -373,6 +450,52 @@ convert_f(int argc, char **argv) return 0; } +static inline uint64_t +rt_daddr_to_rsumblock( + struct xfs_mount *mp, + uint64_t input) +{ + xfs_rtblock_t rtbno; + xfs_rtxnum_t rtx; + xfs_fileoff_t rbmblock; + xfs_rtsumoff_t rsumoff; + + if (rsumlog < 0) { + dbprintf(_("need to set rsumlog\n")); + return 0; + } + + rtbno = xfs_daddr_to_rtb(mp, input >> BBSHIFT); + rtx = xfs_rtb_to_rtx(mp, rtbno); + rbmblock = xfs_rtx_to_rbmblock(mp, rtx); + rsumoff = xfs_rtsumoffs(mp, rsumlog, rbmblock); + + return xfs_rtsumoffs_to_block(mp, rsumoff); +} + +static inline uint64_t +rt_daddr_to_rsuminfo( + struct xfs_mount *mp, + uint64_t input) +{ + xfs_rtblock_t rtbno; + xfs_rtxnum_t rtx; + xfs_fileoff_t rbmblock; + xfs_rtsumoff_t rsumoff; + + if (rsumlog < 0) { + dbprintf(_("need to set rsumlog\n")); + return 0; + } + + rtbno = xfs_daddr_to_rtb(mp, input >> BBSHIFT); + rtx = xfs_rtb_to_rtx(mp, rtbno); + rbmblock = xfs_rtx_to_rbmblock(mp, rtx); + rsumoff = xfs_rtsumoffs(mp, rsumlog, rbmblock); + + return xfs_rtsumoffs_to_infoword(mp, rsumoff); +} + static int rtconvert_f(int argc, char **argv) { @@ -384,6 +507,9 @@ rtconvert_f(int argc, char **argv) uint64_t v; ctype_t wtype; + rsumlog = -1; + rsuminfo = -1; + /* move past the "rtconvert" command */ argc--; argv++; @@ -452,6 +578,16 @@ rtconvert_f(int argc, char **argv) xfs_rtb_to_rtx(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: @@ -535,6 +671,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 12fc4f3b51016b..ffa04879ce76c8 100644 --- a/man/man8/xfs_db.8 +++ b/man/man8/xfs_db.8 @@ -1183,10 +1183,39 @@ .SH COMMANDS 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