linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Sidong Yang <realwakka@gmail.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: btrfs-progs test error on fsck/012-leaf-corruption
Date: Fri, 19 Feb 2021 17:17:07 +0100	[thread overview]
Message-ID: <20210219161707.GF1993@twin.jikos.cz> (raw)
In-Reply-To: <20210218025614.GA1755@realwakka>

On Thu, Feb 18, 2021 at 02:56:14AM +0000, Sidong Yang wrote:
> I found some error when I run unittest code in btrfs-progs.
> fsck/012-leaf-corruption test corrupt leaf and check that it's recovered.
> but the test was failed and demsg below
> 
> [   47.284095] BTRFS error (device loop5): device total_bytes should be at most 27660288 but found 67108864
> [   47.284207] BTRFS error (device loop5): failed to read chunk tree: -22
> [   47.286465] BTRFS error (device loop5): open_ctree failed
> 
> I'm using kernel version 5.11 and there is no error in old version kernel.
> I traced the kernel code and found the code that prints error message.
> When it tried to mount btrfs, the function read_one_dev() failed.
> I found that code added by the commit 3a160a9331112 cause this problem.
> The unittest in btrfs-progs should be changed or kernel code should be patched?

The kernel check makes sense. The unit test fails because the image is
restored from a dump and not extended to the full size automatically.

After 'extract_image' the image is

-rw-r--r-- 1 root root 27660288 Feb 19 17:47 good.img.restored
-rw-r--r-- 1 root root   186392 Jul 27  2020 good.img.xz
-rwxr-xr-x 1 root root     2788 Feb 19 17:46 test.sh

but with a manual 'truncate -s 67108864 good.img.restored' the test
succeeds.

btrfs-image enlarges the file but it's probably taking the wrong size

2281         dev_size = key.offset + btrfs_dev_extent_length(path.nodes[0], dev_ext);
2282         btrfs_release_path(&path);
2283
2284         btrfs_set_stack_device_total_bytes(dev_item, dev_size);
2285         btrfs_set_stack_device_bytes_used(dev_item, mdres->alloced_chunks);
2286         ret = fstat(out_fd, &buf);
2287         if (ret < 0) {
2288                 error("failed to stat result image: %m");
2289                 return -errno;
2290         }
2291         if (S_ISREG(buf.st_mode)) {
2292                 /* Don't forget to enlarge the real file */
2293                 ret = ftruncate64(out_fd, dev_size);
2294                 if (ret < 0) {
2295                         error("failed to enlarge result image: %m");
2296                         return -errno;
2297                 }
2298         }

here it's the 'dev_size'. In the superblock dump, the sb.total_size and
sb.dev_item.total_size are both 67108864, which is the correct value.

The size as obtained from the device item in the device tree also matches the
right value

        item 6 key (1 DEV_EXTENT 61210624) itemoff 3667 itemsize 48
                dev extent chunk_tree 3
                chunk_objectid 256 chunk_offset 61210624 length 5898240
                chunk_tree_uuid b2834867-4e78-47ee-9877-94d4e39bda43

Which is the key.offset + length = 61210624 + 5898240 = 67108864.

But the code is not called in restore_metadump because of condition
"btrfs_super_num_devices(mdrestore.original_super) != 1"

  reply	other threads:[~2021-02-19 16:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-18  2:56 btrfs-progs test error on fsck/012-leaf-corruption Sidong Yang
2021-02-19 16:17 ` David Sterba [this message]
2021-02-21 14:09   ` Sidong Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210219161707.GF1993@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=realwakka@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).