From patchwork Wed Dec 20 17:11:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13500392 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 675DD4777A for ; Wed, 20 Dec 2023 17:11:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oluB0Q2S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E09D9C433C7; Wed, 20 Dec 2023 17:11:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703092301; bh=NRvTy90fb0KkN6FPvoZYfxHW1O3HHGQxPz+TfWAXPwE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=oluB0Q2SXpPQ8JGXgRyWApEFydgQU0QeIahh7ombamo0Gkh4hnVvXqzAO4HZuRIbl cwptsAXrFDiSmgGvV918TLiGdNWNyMhLPjsHIfOkQ9/jS7KRwD9XUOLhAwpVN+VkjN t8NS2ltZKcJBp7O7srp2KRq4AcQpKSftX94qqwUSFwoH83G+XUZ1EsooGAZWc8bwY8 1C4jc160yt/j/FgFIBlCksmEt3wxdVz/fiZKcqLFkui1YwJjaYa0d0+59TDXPpT2mY IfToYz65fmZE9iW4b/3EGs4UIFHy03W/vXdJqoe4oOsve9uwB9DzcqcwjhiDQc0IBR /rTKVPhnlg97w== Date: Wed, 20 Dec 2023 09:11:41 -0800 Subject: [PATCH 1/5] libfrog: move 64-bit division wrappers to libfrog From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <170309218377.1607770.12132572713649925666.stgit@frogsfrogsfrogs> In-Reply-To: <170309218362.1607770.1848898546436984000.stgit@frogsfrogsfrogs> References: <170309218362.1607770.1848898546436984000.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong 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 b28781d1..a6a5f66f 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 8cde97d4..dcfd1fb8 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 00000000..673b01cb --- /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 2729241b..5a7decf9 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 Dec 20 17:11:57 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: 13500393 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 C860847A66 for ; Wed, 20 Dec 2023 17:11:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HqDWRMeC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D57AC433CA; Wed, 20 Dec 2023 17:11:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703092317; bh=7G/UL274rtKbAKQhCnbv3dwuC+UcYc752BQy7RrS6mM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=HqDWRMeCrKmjCB1WN3RMfVo9vtXYAO5OPjPyDfiOxB74vTjEWkXDfk/MmLkxfS3Zy yzkbkqfH1kNh6n5lkbsWx9WRwtLyQRJEhkahIP2vteyWsGk9nzfzrNV0bnV9YQ643u GasbvHAoGGiQ76QYpSJTr5G3qJ1OvSmSeBENZScCFJ4lQcFknCkAdJ+I6Mdnk2e6Eu LXetpbRt5GP23RQYJeLli5Z+dOkhQ8WB0r+gfvEEVMGKt629zQozb800GZi331n7Sw rnsVbQQ78i1s1exbbPBReBm68ZXkSztqXdygWasNrdJiLw1Wp/iY3d0o4ajq01DZmU oK4965RLypN3g== Date: Wed, 20 Dec 2023 09:11:57 -0800 Subject: [PATCH 2/5] libxfs: don't UAF a requeued EFI From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , Chandan Babu R , linux-xfs@vger.kernel.org Message-ID: <170309218390.1607770.7016009394079896736.stgit@frogsfrogsfrogs> In-Reply-To: <170309218362.1607770.1848898546436984000.stgit@frogsfrogsfrogs> References: <170309218362.1607770.1848898546436984000.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong 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 3f519252..8731d183 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 Dec 20 17:12:12 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: 13500394 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 BA1D647A46 for ; Wed, 20 Dec 2023 17:12:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hYF+rUy1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EBF2C433C7; Wed, 20 Dec 2023 17:12:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703092333; bh=3QRagIHFiY0eMAPMWTGafvaL+kh6tRwu+n2N9TL9E7o=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=hYF+rUy1/CBwos2qbw1VFpcwIaMC8oIwG5snhWdRiz1h+EE+QT4ukno98iDT5SeWV 860Huuoy5EOjPn8k/ogxBplKBZ+QtOuo5X6ro/NxafQwlCrqV/WyZ2vvrnuR/uK+U+ WB/5Er7pd18KSx3WVdR5MCokMN8BYAPpbt2C9BYqYuLggF7xQAyYtrwmOSTReADETn vqH8r1Pg0wpPjic69QB7kAYEDd8DHLL90vbf6phTOhmp+YZpqR/I8eu+UhAjhyvIZ+ o6BTfytjm+52n+fPWuP72BHNNsGZy6+N2VDewpzYyTSQ/MPuSv8D6hPBrFJP2a5VI5 T6BqPYQMocypQ== Date: Wed, 20 Dec 2023 09:12:12 -0800 Subject: [PATCH 3/5] xfs_copy: distinguish short writes to EOD from runtime errors From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <170309218403.1607770.4299633539281504295.stgit@frogsfrogsfrogs> In-Reply-To: <170309218362.1607770.1848898546436984000.stgit@frogsfrogsfrogs> References: <170309218362.1607770.1848898546436984000.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Detect short writes to the end of the destination device and report them. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- copy/xfs_copy.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c index 79f65946..d9a14a95 100644 --- a/copy/xfs_copy.c +++ b/copy/xfs_copy.c @@ -889,18 +889,28 @@ main(int argc, char **argv) } else { char *lb[XFS_MAX_SECTORSIZE] = { NULL }; off64_t off; + ssize_t len; /* ensure device files are sufficiently large */ off = mp->m_sb.sb_dblocks * source_blocksize; off -= sizeof(lb); - if (pwrite(target[i].fd, lb, sizeof(lb), off) < 0) { + len = pwrite(target[i].fd, lb, XFS_MAX_SECTORSIZE, off); + if (len < 0) { do_log(_("%s: failed to write last block\n"), progname); do_log(_("\tIs target \"%s\" too small?\n"), target[i].name); die_perror(); } + if (len != XFS_MAX_SECTORSIZE) { + do_log( + _("%s: short write to last block: %zd bytes, %zu expected\n"), + progname, len, XFS_MAX_SECTORSIZE); + do_log(_("\tIs target \"%s\" too small?\n"), + target[i].name); + exit(1); + } } } From patchwork Wed Dec 20 17:12: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: 13500395 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 5E40147A42 for ; Wed, 20 Dec 2023 17:12:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="P7KCrRh5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2FE4C433C7; Wed, 20 Dec 2023 17:12:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703092348; bh=FbcUE8+gDuNBRHRx9R5Vy1Xo/ay0HCOuH2HQJQqAHuc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=P7KCrRh5qJ8Dgi3AvNGeJe++9eoaEgLA2cFhynlPGITxHswNI+QipkCGUNQHZGqAI 0JkDlpDmPsoV2AoV8KDV6kn3E+EQlNgoIeqN6eOXeUDCx5+U7CKbwjmOldBB7y8mme qRRB/Z2qaUUtxhCibrg7bhaRXLod8G135XDB62vTSo5ryJTvvkRQNwONlkL4kfhTIB 2eDg4quEpy59aTrTXxt/Z/iYOHP6ihu7/JoRbJRAD8CycHS1CKN4P5ieyszMV4KbMn vNX40Pt14tefL7gt84SkPtM/LFIWCvz7AyQSEZk+zOypSgEj2wiSs6AcZVTuYz4dKy VfuLSuLjHdIrw== Date: Wed, 20 Dec 2023 09:12:28 -0800 Subject: [PATCH 4/5] 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 Message-ID: <170309218416.1607770.6525312328250244890.stgit@frogsfrogsfrogs> In-Reply-To: <170309218362.1607770.1848898546436984000.stgit@frogsfrogsfrogs> References: <170309218362.1607770.1848898546436984000.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong 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. In removing the onstack buffer for EOD writes, this also corrects the buffer being larger than necessary -- the old code declared an array of 32768 pointers, whereas all we really need is an aligned 32768-byte buffer. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- copy/xfs_copy.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c index d9a14a95..bcc807ed 100644 --- a/copy/xfs_copy.c +++ b/copy/xfs_copy.c @@ -832,13 +832,9 @@ main(int argc, char **argv) do_out(_("Creating file %s\n"), target[i].name); open_flags |= O_CREAT; - if (!buffered_output) - open_flags |= O_DIRECT; write_last_block = 1; } else if (S_ISREG(statbuf.st_mode)) { open_flags |= O_TRUNC; - if (!buffered_output) - open_flags |= O_DIRECT; write_last_block = 1; } else { /* @@ -855,6 +851,8 @@ main(int argc, char **argv) exit(1); } } + if (!buffered_output) + open_flags |= O_DIRECT; target[i].fd = open(target[i].name, open_flags, 0644); if (target[i].fd < 0) { @@ -887,14 +885,15 @@ main(int argc, char **argv) } } } else { - char *lb[XFS_MAX_SECTORSIZE] = { NULL }; + char *lb = memalign(wbuf_align, XFS_MAX_SECTORSIZE); off64_t off; ssize_t len; /* ensure device files are sufficiently large */ + memset(lb, 0, XFS_MAX_SECTORSIZE); off = mp->m_sb.sb_dblocks * source_blocksize; - off -= sizeof(lb); + off -= XFS_MAX_SECTORSIZE; len = pwrite(target[i].fd, lb, XFS_MAX_SECTORSIZE, off); if (len < 0) { do_log(_("%s: failed to write last block\n"), @@ -911,6 +910,7 @@ main(int argc, char **argv) target[i].name); exit(1); } + free(lb); } } From patchwork Wed Dec 20 17:12:43 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: 13500396 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 E02694776B for ; Wed, 20 Dec 2023 17:12:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="u4sBn6mJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61636C433C8; Wed, 20 Dec 2023 17:12:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703092364; bh=eN91+4MAgFuMmqb76P1Fwg3iVtpbmfK+GS7guuHN/Yo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=u4sBn6mJ/B8oMUocBmIQQDEZZ+BYHbsuS+FNyVafIAPSg7EC7h1Xqy88q2zQX91b1 wLexndA8YMaIsI+cmV6OPHmMHuHPWG5ToYu/lJ4FRDG4zirRayrg3INmzsE6fnmPVl 7VYa0+1Zz5KbkAtHi+Nj1RLlMAZaI6xEuLbAJD0Eud6as+mobm5RRmhB4/gEcJcxrM YmgHggVwA1VOoGHg2k+w4CothXMMSAk516hHx0+5N9v1oPSH9nlRJ8TNfDttiXxPYs oQ9tv4rB7CMniD2MHbZq0lUbOdUM1kXxs3928RgDDyW95k7V0ytcfPYTpWoEWFXigI KRV5mmLg9LFow== Date: Wed, 20 Dec 2023 09:12:43 -0800 Subject: [PATCH 5/5] 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 Message-ID: <170309218429.1607770.15957197387853311608.stgit@frogsfrogsfrogs> In-Reply-To: <170309218362.1607770.1848898546436984000.stgit@frogsfrogsfrogs> References: <170309218362.1607770.1848898546436984000.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong When 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 Reviewed-by: Christoph Hellwig --- 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 788337d3..d730c779 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 5ccfe3b5..590dd1f8 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 bd86c31f..f48b67b4 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 */