From patchwork Wed Nov 22 23:06:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13465524 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 3269FC61D97 for ; Wed, 22 Nov 2023 23:06:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231623AbjKVXG7 (ORCPT ); Wed, 22 Nov 2023 18:06:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229879AbjKVXG6 (ORCPT ); Wed, 22 Nov 2023 18:06:58 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA821D8 for ; Wed, 22 Nov 2023 15:06:54 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B0C2C433C7; Wed, 22 Nov 2023 23:06:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700694414; bh=XynHzj6h44ZdsvK8cBT1mwhwTjH+Rk63srZZ6LTyCzk=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=mHYlPh4WYM9fyuEGFzXQJmMdkjBhstIAFD2DwASeufy0X4QQfBysvqpOE9tdfyidk FMXYB1Lcq5LGboPrnopn0G1zfNUaJm5fgWhJynQhrpS/mCImq85rfOHnuWhFQ2N3LE 4GXVx91zKVFUh2ocxeMaPn4fPJ9+JvoaZMpVUO7roYCEeonVNuS4+sIpQH38bbTb6v A9hWhoqzfKE2TidmaL/3mJir5fehJr6rZTr9rsrw4x1P4Uuyj2AMCTjnMDuez5JIAc scDWBTVG/U9UM7cpSrxwFkgDYXQBWHb7Oq1nZPpsdaNhCqd7VGyxnC3sGeBw3h7K8L YhyRoUjaAFZGA== Subject: [PATCH 1/9] libfrog: move 64-bit division wrappers to libfrog From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Wed, 22 Nov 2023 15:06:54 -0800 Message-ID: <170069441404.1865809.15599372422489523965.stgit@frogsfrogsfrogs> In-Reply-To: <170069440815.1865809.15572181471511196657.stgit@frogsfrogsfrogs> References: <170069440815.1865809.15572181471511196657.stgit@frogsfrogsfrogs> 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 We want to keep the rtgroup unit conversion functions as static inlines, so share the div64 functions via libfrog instead of libxfs_priv.h. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Chandan Babu R --- include/libxfs.h | 1 + libfrog/Makefile | 1 + libfrog/div64.h | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++ libxfs/libxfs_priv.h | 77 +--------------------------------------- 4 files changed, 99 insertions(+), 76 deletions(-) create mode 100644 libfrog/div64.h diff --git a/include/libxfs.h b/include/libxfs.h index b28781d19d3..a6a5f66f28d 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -18,6 +18,7 @@ #include "kmem.h" #include "libfrog/radix-tree.h" #include "libfrog/bitmask.h" +#include "libfrog/div64.h" #include "atomic.h" #include "spinlock.h" diff --git a/libfrog/Makefile b/libfrog/Makefile index 8cde97d418f..dcfd1fb8a93 100644 --- a/libfrog/Makefile +++ b/libfrog/Makefile @@ -41,6 +41,7 @@ crc32cselftest.h \ crc32defs.h \ crc32table.h \ dahashselftest.h \ +div64.h \ fsgeom.h \ logging.h \ paths.h \ diff --git a/libfrog/div64.h b/libfrog/div64.h new file mode 100644 index 00000000000..673b01cbab3 --- /dev/null +++ b/libfrog/div64.h @@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2000-2005 Silicon Graphics, Inc. + * All Rights Reserved. + */ +#ifndef LIBFROG_DIV64_H_ +#define LIBFROG_DIV64_H_ + +static inline int __do_div(unsigned long long *n, unsigned base) +{ + int __res; + __res = (int)(((unsigned long) *n) % (unsigned) base); + *n = ((unsigned long) *n) / (unsigned) base; + return __res; +} + +#define do_div(n,base) (__do_div((unsigned long long *)&(n), (base))) +#define do_mod(a, b) ((a) % (b)) +#define rol32(x,y) (((x) << (y)) | ((x) >> (32 - (y)))) + +/** + * div_u64_rem - unsigned 64bit divide with 32bit divisor with remainder + * @dividend: unsigned 64bit dividend + * @divisor: unsigned 32bit divisor + * @remainder: pointer to unsigned 32bit remainder + * + * Return: sets ``*remainder``, then returns dividend / divisor + * + * This is commonly provided by 32bit archs to provide an optimized 64bit + * divide. + */ +static inline uint64_t +div_u64_rem(uint64_t dividend, uint32_t divisor, uint32_t *remainder) +{ + *remainder = dividend % divisor; + return dividend / divisor; +} + +/** + * div_u64 - unsigned 64bit divide with 32bit divisor + * @dividend: unsigned 64bit dividend + * @divisor: unsigned 32bit divisor + * + * This is the most common 64bit divide and should be used if possible, + * as many 32bit archs can optimize this variant better than a full 64bit + * divide. + */ +static inline uint64_t div_u64(uint64_t dividend, uint32_t divisor) +{ + uint32_t remainder; + return div_u64_rem(dividend, divisor, &remainder); +} + +/** + * div64_u64_rem - unsigned 64bit divide with 64bit divisor and remainder + * @dividend: unsigned 64bit dividend + * @divisor: unsigned 64bit divisor + * @remainder: pointer to unsigned 64bit remainder + * + * Return: sets ``*remainder``, then returns dividend / divisor + */ +static inline uint64_t +div64_u64_rem(uint64_t dividend, uint64_t divisor, uint64_t *remainder) +{ + *remainder = dividend % divisor; + return dividend / divisor; +} + +static inline uint64_t rounddown_64(uint64_t x, uint32_t y) +{ + do_div(x, y); + return x * y; +} + +static inline bool isaligned_64(uint64_t x, uint32_t y) +{ + return do_div(x, y) == 0; +} + +static inline uint64_t +roundup_64(uint64_t x, uint32_t y) +{ + x += y - 1; + do_div(x, y); + return x * y; +} + +static inline uint64_t +howmany_64(uint64_t x, uint32_t y) +{ + x += y - 1; + do_div(x, y); + return x; +} + +#endif /* LIBFROG_DIV64_H_ */ diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index 2729241bdaa..5a7decf970e 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -48,6 +48,7 @@ #include "kmem.h" #include "libfrog/radix-tree.h" #include "libfrog/bitmask.h" +#include "libfrog/div64.h" #include "atomic.h" #include "spinlock.h" #include "linux-err.h" @@ -215,66 +216,6 @@ static inline bool WARN_ON(bool expr) { (inode)->i_version = (version); \ } while (0) -static inline int __do_div(unsigned long long *n, unsigned base) -{ - int __res; - __res = (int)(((unsigned long) *n) % (unsigned) base); - *n = ((unsigned long) *n) / (unsigned) base; - return __res; -} - -#define do_div(n,base) (__do_div((unsigned long long *)&(n), (base))) -#define do_mod(a, b) ((a) % (b)) -#define rol32(x,y) (((x) << (y)) | ((x) >> (32 - (y)))) - -/** - * div_u64_rem - unsigned 64bit divide with 32bit divisor with remainder - * @dividend: unsigned 64bit dividend - * @divisor: unsigned 32bit divisor - * @remainder: pointer to unsigned 32bit remainder - * - * Return: sets ``*remainder``, then returns dividend / divisor - * - * This is commonly provided by 32bit archs to provide an optimized 64bit - * divide. - */ -static inline uint64_t -div_u64_rem(uint64_t dividend, uint32_t divisor, uint32_t *remainder) -{ - *remainder = dividend % divisor; - return dividend / divisor; -} - -/** - * div_u64 - unsigned 64bit divide with 32bit divisor - * @dividend: unsigned 64bit dividend - * @divisor: unsigned 32bit divisor - * - * This is the most common 64bit divide and should be used if possible, - * as many 32bit archs can optimize this variant better than a full 64bit - * divide. - */ -static inline uint64_t div_u64(uint64_t dividend, uint32_t divisor) -{ - uint32_t remainder; - return div_u64_rem(dividend, divisor, &remainder); -} - -/** - * div64_u64_rem - unsigned 64bit divide with 64bit divisor and remainder - * @dividend: unsigned 64bit dividend - * @divisor: unsigned 64bit divisor - * @remainder: pointer to unsigned 64bit remainder - * - * Return: sets ``*remainder``, then returns dividend / divisor - */ -static inline uint64_t -div64_u64_rem(uint64_t dividend, uint64_t divisor, uint64_t *remainder) -{ - *remainder = dividend % divisor; - return dividend / divisor; -} - #define min_t(type,x,y) \ ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; }) #define max_t(type,x,y) \ @@ -380,22 +321,6 @@ roundup_pow_of_two(uint v) return 0; } -static inline uint64_t -roundup_64(uint64_t x, uint32_t y) -{ - x += y - 1; - do_div(x, y); - return x * y; -} - -static inline uint64_t -howmany_64(uint64_t x, uint32_t y) -{ - x += y - 1; - do_div(x, y); - return x; -} - /* buffer management */ #define XBF_TRYLOCK 0 #define XBF_UNMAPPED 0 From patchwork Wed Nov 22 23:06:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13465525 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 192E1C61D97 for ; Wed, 22 Nov 2023 23:07:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233574AbjKVXHF (ORCPT ); Wed, 22 Nov 2023 18:07:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229879AbjKVXHE (ORCPT ); Wed, 22 Nov 2023 18:07:04 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9867910E for ; Wed, 22 Nov 2023 15:07:00 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31034C433C8; Wed, 22 Nov 2023 23:07:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700694420; bh=DYzmwUo3DJJMVUy0AY0F0qZ2TlTaf00KTyU2pPyU/FM=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=I4hHaSEKO4Ak9dOQZjFUKrrUgh3UUx0b84EcXZW+rv72OQf0oIw2nghtpjo5MDKpR fP4DVBFps+YZAF0yLkE9WdNQTTueA6gEXRyrNght5BcLjttmxZ5H2TbvAqJW+Ayani J6Y1aSQQ267Yb+UCHQcWbx/Ue1tC/vUY2aQZuJO1WmzIECbobwoUFzQeEw6CV3sEz4 z6bzKl1ha2g+hNgEayKmf9sVc20Qn6ufvLVrnbabGjNizXvLI8l7nAW37GQUzJyOuA /qWEvC/GOTD0gZEaJsYkw7bgo0AHyly7m29R7f/xWP/AJx1R+fCLmS4jO5Vt78mSnu yYw57AEDtqiwA== Subject: [PATCH 2/9] libxfs: don't UAF a requeued EFI From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Wed, 22 Nov 2023 15:06:59 -0800 Message-ID: <170069441966.1865809.4282467818590298794.stgit@frogsfrogsfrogs> In-Reply-To: <170069440815.1865809.15572181471511196657.stgit@frogsfrogsfrogs> References: <170069440815.1865809.15572181471511196657.stgit@frogsfrogsfrogs> 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 In the kernel, commit 8ebbf262d4684 ("xfs: don't block in busy flushing when freeing extents") changed the allocator behavior such that AGFL fixing can return -EAGAIN in response to detection of a deadlock with the transaction busy extent list. If this happens, we're supposed to requeue the EFI so that we can roll the transaction and try the item again. If a requeue happens, we should not free the xefi pointer in xfs_extent_free_finish_item or else the retry will walk off a dangling pointer. There is no extent busy list in userspace so this should never happen, but let's fix the logic bomb anyway. We should have ported kernel commit 0853b5de42b47 ("xfs: allow extent free intents to be retried") to userspace, but neither Carlos nor I noticed this fine detail. :( Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Chandan Babu R --- libxfs/defer_item.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libxfs/defer_item.c b/libxfs/defer_item.c index 3f519252046..8731d1834be 100644 --- a/libxfs/defer_item.c +++ b/libxfs/defer_item.c @@ -115,6 +115,13 @@ xfs_extent_free_finish_item( error = xfs_free_extent(tp, xefi->xefi_pag, agbno, xefi->xefi_blockcount, &oinfo, XFS_AG_RESV_NONE); + /* + * Don't free the XEFI if we need a new transaction to complete + * processing of it. + */ + if (error == -EAGAIN) + return error; + xfs_extent_free_put_group(xefi); kmem_cache_free(xfs_extfree_item_cache, xefi); return error; From patchwork Wed Nov 22 23:07:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13465526 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 8B753C61D97 for ; Wed, 22 Nov 2023 23:07:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229879AbjKVXHL (ORCPT ); Wed, 22 Nov 2023 18:07:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234558AbjKVXHK (ORCPT ); Wed, 22 Nov 2023 18:07:10 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CCAB1AE for ; Wed, 22 Nov 2023 15:07:06 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3857C433C8; Wed, 22 Nov 2023 23:07:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700694425; bh=2yl6rq9YSI9sJXut4EB7KV7Qi6eRm6WvUSm1IemLCgI=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=X+d1sqVeohlybLKoSEIXu4gzlWOhsazxmtF0OpU9WjGhr67lUAANvuCIid8In+NkF J3TXapzpXmbqzPgPPSs4GkAYqFacGUJa5RU8QP8KL7xfdDRmnBhZD7f58xPy0uptNZ 5duanht5Nj7cZmskIcEblk2WhS0xm1+gY6qlVeM5s9RaLmBSBNDqOtgtWqJWgugBIL JeeVMzTOXzaELoJYqtoql9+w9ROplrueIRK34u8woeL+DR+hIbOxzehPwRM3f9I6Hl YRogZeI2f426RCHab6Glt52BV+sStW2obF14Ayp6ptMarqyAWLJ7+bzlJUTEex3btI sItq0o9/sry9A== Subject: [PATCH 3/9] xfs_copy: actually do directio writes to block devices From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Wed, 22 Nov 2023 15:07:05 -0800 Message-ID: <170069442535.1865809.15981356020247666131.stgit@frogsfrogsfrogs> In-Reply-To: <170069440815.1865809.15572181471511196657.stgit@frogsfrogsfrogs> References: <170069440815.1865809.15572181471511196657.stgit@frogsfrogsfrogs> 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 Not sure why block device targets don't get O_DIRECT in !buffered mode, but it's misleading when the copy completes instantly only to stall forever due to fsync-on-close. Adjust the "write last sector" code to allocate a properly aligned buffer. Signed-off-by: Darrick J. Wong --- copy/xfs_copy.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c index 79f65946709..26de6b2ee1c 100644 --- a/copy/xfs_copy.c +++ b/copy/xfs_copy.c @@ -854,6 +854,8 @@ main(int argc, char **argv) progname, target[i].name, progname); exit(1); } + if (!buffered_output) + open_flags |= O_DIRECT; } target[i].fd = open(target[i].name, open_flags, 0644); @@ -887,20 +889,22 @@ main(int argc, char **argv) } } } else { - char *lb[XFS_MAX_SECTORSIZE] = { NULL }; + char *lb = memalign(wbuf_align, XFS_MAX_SECTORSIZE); off64_t off; /* ensure device files are sufficiently large */ + memset(lb, 0, XFS_MAX_SECTORSIZE); off = mp->m_sb.sb_dblocks * source_blocksize; - off -= sizeof(lb); - if (pwrite(target[i].fd, lb, sizeof(lb), off) < 0) { + off -= XFS_MAX_SECTORSIZE; + if (pwrite(target[i].fd, lb, XFS_MAX_SECTORSIZE, off) < 0) { do_log(_("%s: failed to write last block\n"), progname); do_log(_("\tIs target \"%s\" too small?\n"), target[i].name); die_perror(); } + free(lb); } } From patchwork Wed Nov 22 23:07:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13465527 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 101A8C61D97 for ; Wed, 22 Nov 2023 23:07:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232195AbjKVXHQ (ORCPT ); Wed, 22 Nov 2023 18:07:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231952AbjKVXHP (ORCPT ); Wed, 22 Nov 2023 18:07:15 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6007D8 for ; Wed, 22 Nov 2023 15:07:11 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8541EC433C8; Wed, 22 Nov 2023 23:07:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700694431; bh=dhK3q9PbxQv5ehBQjgceYAUCcBZAHPlw+ZJKXeAFQHY=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=a9jDqJAPh5GhcnX9Oin+LpWhRWiWQ4mtNJNBt1roj+WlcuntEEa/DoY9O3yN5UVWb ieo8jaG4MPUPTLR6PYkFcnOW55DWnvPUdwwibzmF8oE+Hzl3D7zxfzOlyVLP5nMmGV oNCIa4rJdtvmhSCSGIcI9n6dagRvBaP/Oq0V57DAPTs9hRSytCdxs1F7QwgO2eYTuu citiNpM5p8X2ODXzDJj6pFM7Pr1VnWIkvW7zAEXT6sWp42GQ6tV5oQNQ+72FHyyBAV Vlmxk5zeLha7e0vSEC+Ca7g0PpJu9RtHhm6GCAMgVoxbODgM9CM8j03HXH/OHLeOhy 4460U+ekswGMg== Subject: [PATCH 4/9] 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: Wed, 22 Nov 2023 15:07:10 -0800 Message-ID: <170069443096.1865809.13119575401747000666.stgit@frogsfrogsfrogs> In-Reply-To: <170069440815.1865809.15572181471511196657.stgit@frogsfrogsfrogs> References: <170069440815.1865809.15572181471511196657.stgit@frogsfrogsfrogs> 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 | 14 +++++++++++++- db/io.c | 35 ++++++++++++++++++++++++++++++++--- db/io.h | 3 +++ 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/db/block.c b/db/block.c index 788337d3709..d730c779671 100644 --- a/db/block.c +++ b/db/block.c @@ -126,7 +126,15 @@ 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 + dbprintf(_("current daddr is %lld\n"), daddr); + return 0; } d = (int64_t)strtoull(argv[1], &p, 0); @@ -220,6 +228,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 5ccfe3b536a..590dd1f82f7 100644 --- a/db/io.c +++ b/db/io.c @@ -137,18 +137,47 @@ 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; +} + 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"; + 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 bd86c31f67e..f48b67b47a2 100644 --- a/db/io.h +++ b/db/io.h @@ -56,6 +56,9 @@ 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); + /* * returns -1 for unchecked, 0 for bad and 1 for good */ From patchwork Wed Nov 22 23:07:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13465528 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 865B1C61D97 for ; Wed, 22 Nov 2023 23:07:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231952AbjKVXHW (ORCPT ); Wed, 22 Nov 2023 18:07:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234580AbjKVXHV (ORCPT ); Wed, 22 Nov 2023 18:07:21 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D52F1AB for ; Wed, 22 Nov 2023 15:07:17 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 311B7C433C7; Wed, 22 Nov 2023 23:07:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700694437; bh=i9tmMkUvnDjPofWgjMT3xzPxJOD2WAZW77uZ00KAIpQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=tVhJa+TXbRfKFc6Pxo5TZXdnmv1rWYgUWIoaxryncCWj9VE3pXD+z3g1phxY/Ir+a D+gp0a+Cmkt0jTdG7JQvQAyXUqCq4ASxRplg0SX3pgNS9XQqIny8BlT82EwDVrpJ40 cvNmega5VOq7rh/lEU9ZEKKLDLYAFOQtq5s4aRHujdui+DlmumT8qIbPVH9WwWWN3u PR/Pajz8RRJd5Wt6GYoxCQIpFS7VRJimhqb0gYkupLa9sK5gfHlYuOZ5b65OMFkNtm 9HhWapmW9BsI8B+E090WNw9mm1gHekl379g1EwvQEJFRQFnxto5BBQVsvzlzoyZqzB XWzi8g/KN8CvQ== Subject: [PATCH 5/9] xfs_metadump.8: update for external log device options From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Wed, 22 Nov 2023 15:07:16 -0800 Message-ID: <170069443670.1865809.2265862857261044359.stgit@frogsfrogsfrogs> In-Reply-To: <170069440815.1865809.15572181471511196657.stgit@frogsfrogsfrogs> References: <170069440815.1865809.15572181471511196657.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Update the documentation to reflect that we can metadump external log device contents. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Chandan Babu R --- man/man8/xfs_mdrestore.8 | 6 +++++- man/man8/xfs_metadump.8 | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/man/man8/xfs_mdrestore.8 b/man/man8/xfs_mdrestore.8 index 6e7457c0445..f60e7b56ebf 100644 --- a/man/man8/xfs_mdrestore.8 +++ b/man/man8/xfs_mdrestore.8 @@ -14,6 +14,10 @@ xfs_mdrestore \- restores an XFS metadump image to a filesystem image .br .B xfs_mdrestore .B \-i +[ +.B \-l +.I logdev +] .I source .br .B xfs_mdrestore \-V @@ -52,7 +56,7 @@ Shows metadump information on stdout. If no is specified, exits after displaying information. Older metadumps man not include any descriptive information. .TP -.B \-l " logdev" +.BI \-l " logdev" Metadump in v2 format can contain metadata dumped from an external log. In such a scenario, the user has to provide a device to which the log device contents from the metadump file are copied. diff --git a/man/man8/xfs_metadump.8 b/man/man8/xfs_metadump.8 index 1732012cd0c..496b5926603 100644 --- a/man/man8/xfs_metadump.8 +++ b/man/man8/xfs_metadump.8 @@ -132,8 +132,11 @@ is stdout. .TP .BI \-l " logdev" For filesystems which use an external log, this specifies the device where the -external log resides. The external log is not copied, only internal logs are -copied. +external log resides. +If the v2 metadump format is selected, the contents of the external log will be +copied to the metadump. +The v2 metadump format will be selected automatically if this option is +specified. .TP .B \-m Set the maximum size of an allowed metadata extent. Extremely large metadata From patchwork Wed Nov 22 23:07:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13465529 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 BD425C61D97 for ; Wed, 22 Nov 2023 23:07:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234509AbjKVXH1 (ORCPT ); Wed, 22 Nov 2023 18:07:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234558AbjKVXH1 (ORCPT ); Wed, 22 Nov 2023 18:07:27 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 405A710E for ; Wed, 22 Nov 2023 15:07:23 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5D8EC433C8; Wed, 22 Nov 2023 23:07:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700694442; bh=Xn/E2etGG5axBFj+fX+s/d2I+9wrBsBCjuj7y9jlTVo=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=DhK7shK7Vjw12It86Rju3SSU9jaSErSemdAQVHBLm3r4ATfhEbL20GWLbjxgpL5Wu 4e6u6MwvQ0OCW5vq4z2a++VoWp8OdQu7LFBuQxRhk5xiU9r79jrjG5xOw954jQgHOj ZYb3I6zG3sP5Cv9uW5jf89R7gAVsWbe06aZSgMWOIhiJGI0eQVV00c7Y6Ahte7YrhR CrVBhqOMm8J0LYGPIJS1GgfUX1xgppdZVZjvU8BdQegQ3YIsi/Vt3iKL1kZga1cpHi O+cEX2PuR8XxKomF4zKSIZlfVCM1aND8B3fL4h4rkktRbyf2JUf9mQR/pFGBIdJ44B k7+1RqwnICjXA== Subject: [PATCH 6/9] xfs_mdrestore: fix uninitialized variables in mdrestore main From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Wed, 22 Nov 2023 15:07:22 -0800 Message-ID: <170069444236.1865809.11643710907133041679.stgit@frogsfrogsfrogs> In-Reply-To: <170069440815.1865809.15572181471511196657.stgit@frogsfrogsfrogs> References: <170069440815.1865809.15572181471511196657.stgit@frogsfrogsfrogs> 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 Coverity complained about the "is fd a file?" flags being uninitialized. Clean this up. Coverity-id: 1554270 Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Chandan Babu R --- mdrestore/xfs_mdrestore.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c index 2de177c6e3f..5dfc423493e 100644 --- a/mdrestore/xfs_mdrestore.c +++ b/mdrestore/xfs_mdrestore.c @@ -472,11 +472,11 @@ main( union mdrestore_headers headers; FILE *src_f; char *logdev = NULL; - int data_dev_fd; - int log_dev_fd; + int data_dev_fd = -1; + int log_dev_fd = -1; int c; - bool is_data_dev_file; - bool is_log_dev_file; + bool is_data_dev_file = false; + bool is_log_dev_file = false; mdrestore.show_progress = false; mdrestore.show_info = false; @@ -561,7 +561,6 @@ main( /* check and open data device */ data_dev_fd = open_device(argv[optind], &is_data_dev_file); - log_dev_fd = -1; if (mdrestore.external_log) /* check and open log device */ log_dev_fd = open_device(logdev, &is_log_dev_file); From patchwork Wed Nov 22 23:07:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13465530 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 5867EC61D97 for ; Wed, 22 Nov 2023 23:07:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235132AbjKVXHc (ORCPT ); Wed, 22 Nov 2023 18:07:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234580AbjKVXHc (ORCPT ); Wed, 22 Nov 2023 18:07:32 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F17B9191 for ; Wed, 22 Nov 2023 15:07:28 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 978F1C433C8; Wed, 22 Nov 2023 23:07:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700694448; bh=MRIgorRgUDLX9ol9c8lAXGp/oz/gULmhipin2mkyD/g=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=H01OIQWThKYnt0Nv5c82TTG1jebyJYCMhmpbfoo94e8YR7IedqkT02nXgLdZXgzzY biqdqahI8CZUOVC/fA88zMHEH2IodRQ+Ql0lm1jW2+kSU9CMRPEHdB6W1mEsLuI0T/ XO4EP2tSpsfjOWGZa3Dnv81qvFsRXfV8Saf35Wh6r6o0BHjWMqphx6hHo6eXs2rOS3 URdI+b4+eWfHsSk2edgb2z2WrgHz7wh4GLoaSo7MvBW869egdpf8uqFCMpHTkUXXBd FHbNuJbFiEzAcAA89WwDIYy2LURCImAKqxbSSnt9AfAwH9QGqfAcjJm8f3FzTAPc3d 2rADvVlH1NxFw== Subject: [PATCH 7/9] xfs_mdrestore: emit newlines for fatal errors From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Wed, 22 Nov 2023 15:07:28 -0800 Message-ID: <170069444804.1865809.10101273264911340367.stgit@frogsfrogsfrogs> In-Reply-To: <170069440815.1865809.15572181471511196657.stgit@frogsfrogsfrogs> References: <170069440815.1865809.15572181471511196657.stgit@frogsfrogsfrogs> 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 Spit out a newline after a fatal error message. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Chandan Babu R --- mdrestore/xfs_mdrestore.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c index 5dfc423493e..3190e07e478 100644 --- a/mdrestore/xfs_mdrestore.c +++ b/mdrestore/xfs_mdrestore.c @@ -275,10 +275,10 @@ read_header_v2( fatal("error reading from metadump file\n"); if (h->v2.xmh_incompat_flags != 0) - fatal("Metadump header has unknown incompat flags set"); + fatal("Metadump header has unknown incompat flags set\n"); if (h->v2.xmh_reserved != 0) - fatal("Metadump header's reserved field has a non-zero value"); + fatal("Metadump header's reserved field has a non-zero value\n"); want_external_log = !!(be32_to_cpu(h->v2.xmh_incompat_flags) & XFS_MD2_COMPAT_EXTERNALLOG); From patchwork Wed Nov 22 23:07:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13465537 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 EE6EAC27C40 for ; Wed, 22 Nov 2023 23:07:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234580AbjKVXHi (ORCPT ); Wed, 22 Nov 2023 18:07:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234558AbjKVXHh (ORCPT ); Wed, 22 Nov 2023 18:07:37 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9623210E for ; Wed, 22 Nov 2023 15:07:34 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36BC1C433C8; Wed, 22 Nov 2023 23:07:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700694454; bh=aAp0AbYIFA+/PzGVeGViTbwLLCKcorrwEymJ3KNHfOI=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=pRzA86+EJEzP5RDjM8QIuUgg0o5Md6Toxt0MqrIFtNC4TQGH7+p37DVmMpAQLAe71 wWBT/s+cIKk/qOGE93Ffn2pf8EWNS4zWrC3u5ZKNWO8520WZe+Dh8c155i2nZn1oJ6 zbntZ0hz9QyCHc4+TGZRXg8o9a/RMr9C/6K6l0X30an4r8KcKLD5LBw54Blyo+9B4C /gpU0O9/OJxTIbqWt/we/QBwdn7gP3JZ3GzUSxDzBw3XJZf4wMvOxHGC9GaR3Hw+3a SulPeC1nllkAzI81CDPMfw5IzKOQCnGUUL15t+ABl3zjI6QH4XwaRwS1UNiyiipQBA EKSfHROtDQJew== Subject: [PATCH 8/9] xfs_mdrestore: EXTERNALLOG is a compat value, not incompat From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Wed, 22 Nov 2023 15:07:33 -0800 Message-ID: <170069445376.1865809.6391643475229742760.stgit@frogsfrogsfrogs> In-Reply-To: <170069440815.1865809.15572181471511196657.stgit@frogsfrogsfrogs> References: <170069440815.1865809.15572181471511196657.stgit@frogsfrogsfrogs> 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 Fix this check to look at the correct header field. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Chandan Babu R --- mdrestore/xfs_mdrestore.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c index 3190e07e478..3f761e8fe8d 100644 --- a/mdrestore/xfs_mdrestore.c +++ b/mdrestore/xfs_mdrestore.c @@ -268,8 +268,6 @@ read_header_v2( union mdrestore_headers *h, FILE *md_fp) { - bool want_external_log; - if (fread((uint8_t *)&(h->v2) + sizeof(h->v2.xmh_magic), sizeof(h->v2) - sizeof(h->v2.xmh_magic), 1, md_fp) != 1) fatal("error reading from metadump file\n"); @@ -280,10 +278,8 @@ read_header_v2( if (h->v2.xmh_reserved != 0) fatal("Metadump header's reserved field has a non-zero value\n"); - want_external_log = !!(be32_to_cpu(h->v2.xmh_incompat_flags) & - XFS_MD2_COMPAT_EXTERNALLOG); - - if (want_external_log && !mdrestore.external_log) + if ((h->v2.xmh_compat_flags & cpu_to_be32(XFS_MD2_COMPAT_EXTERNALLOG)) && + !mdrestore.external_log) fatal("External Log device is required\n"); } From patchwork Wed Nov 22 23:07:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13465538 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 E95EFC27C40 for ; Wed, 22 Nov 2023 23:07:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235163AbjKVXHo (ORCPT ); Wed, 22 Nov 2023 18:07:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234558AbjKVXHo (ORCPT ); Wed, 22 Nov 2023 18:07:44 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E489199 for ; Wed, 22 Nov 2023 15:07:40 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3EBDC433C8; Wed, 22 Nov 2023 23:07:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700694460; bh=opPw3xe+heHZkZZt9ty/PHeu/jcTOfYDGE0iMeC+CR0=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Hx/Rwo1zH3YMRtCVVE8ltKG/1EW+EKfRCjMUxUrlVZ6+w+uc8HjwwRfWwToru9gpc XaUtAgeoIXiuTi596QbCFpGTJd2T7oLiTsHcZz+kMwd16XDXPMyaCY5frituNmJqr2 izrqpasKcy3aVrHm4eRkSeY0xb6eB6mHPCmtqy3TSkmVO1n1m3F9JJRH913bZzGi3H Q0vQHzaUlMREfqcai9iu2VWWh/aDGs0zeUU44QXPbUOe+ZUl+m/h5R/kJwlwgs8Rs8 kpgI8WiH3idRkFpWIpD0uLsCsl1iZi6TIokmD+QVU28ftD0w11Pk71NcauUcd+Ahmu peVCUUPs+I5rQ== Subject: [PATCH 9/9] xfs_mdrestore: fix missed progress reporting From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Date: Wed, 22 Nov 2023 15:07:39 -0800 Message-ID: <170069445938.1865809.2272471874760042809.stgit@frogsfrogsfrogs> In-Reply-To: <170069440815.1865809.15572181471511196657.stgit@frogsfrogsfrogs> References: <170069440815.1865809.15572181471511196657.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Currently, the progress reporting only triggers when the number of bytes read is exactly a multiple of a megabyte. This isn't always guaranteed, since AG headers can be 512 bytes in size. Fix the algorithm by recording the number of megabytes we've reported as being read, and emit a new report any time the bytes_read count, once converted to megabytes, doesn't match. Fix the v2 code to emit one final status message in case the last extent restored is more than a megabyte. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Chandan Babu R --- mdrestore/xfs_mdrestore.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c index 3f761e8fe8d..ab9a44d2118 100644 --- a/mdrestore/xfs_mdrestore.c +++ b/mdrestore/xfs_mdrestore.c @@ -7,6 +7,7 @@ #include "libxfs.h" #include "xfs_metadump.h" #include +#include "libfrog/div64.h" union mdrestore_headers { __be32 magic; @@ -160,6 +161,7 @@ restore_v1( int mb_count; xfs_sb_t sb; int64_t bytes_read; + int64_t mb_read = 0; block_size = 1 << h->v1.mb_blocklog; max_indices = (block_size - sizeof(xfs_metablock_t)) / sizeof(__be64); @@ -208,9 +210,14 @@ restore_v1( bytes_read = 0; for (;;) { - if (mdrestore.show_progress && - (bytes_read & ((1 << 20) - 1)) == 0) - print_progress("%lld MB read", bytes_read >> 20); + if (mdrestore.show_progress) { + int64_t mb_now = bytes_read >> 20; + + if (mb_now != mb_read) { + print_progress("%lld MB read", mb_now); + mb_read = mb_now; + } + } for (cur_index = 0; cur_index < mb_count; cur_index++) { if (pwrite(ddev_fd, &block_buffer[cur_index << @@ -240,6 +247,9 @@ restore_v1( bytes_read += block_size + (mb_count << h->v1.mb_blocklog); } + if (mdrestore.show_progress && bytes_read > (mb_read << 20)) + print_progress("%lld MB read", howmany_64(bytes_read, 1U << 20)); + if (mdrestore.progress_since_warning) putchar('\n'); @@ -340,6 +350,7 @@ restore_v2( struct xfs_sb sb; struct xfs_meta_extent xme; char *block_buffer; + int64_t mb_read = 0; int64_t bytes_read; uint64_t offset; int len; @@ -416,16 +427,18 @@ restore_v2( bytes_read += len; if (mdrestore.show_progress) { - static int64_t mb_read; - int64_t mb_now = bytes_read >> 20; + int64_t mb_now = bytes_read >> 20; if (mb_now != mb_read) { - print_progress("%lld MB read", mb_now); + print_progress("%lld mb read", mb_now); mb_read = mb_now; } } } while (1); + if (mdrestore.show_progress && bytes_read > (mb_read << 20)) + print_progress("%lld mb read", howmany_64(bytes_read, 1U << 20)); + if (mdrestore.progress_since_warning) putchar('\n');