Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btrfs inspect-internal tree-stats crash #520

Closed
LaurentBonnaud opened this issue Oct 4, 2022 · 3 comments
Closed

btrfs inspect-internal tree-stats crash #520

LaurentBonnaud opened this issue Oct 4, 2022 · 3 comments
Labels
bug docs Changes in documentation or help text
Milestone

Comments

@LaurentBonnaud
Copy link

Hi,

with those software versions:

# btrfs --version
btrfs-progs v5.16.2
# uname -a
Linux xeelee 5.19.11-051911-generic #202209231341 SMP PREEMPT_DYNAMIC Fri Sep 23 14:11:03 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

I see the following segfault:

# btrfs inspect-internal tree-stats /dev/nvme0n1p2
WARNING: /dev/nvme0n1p2 already mounted, results may be inaccurate
Calculating size of root tree
        Total size: 144.00KiB
                Inline data: 0.00B
        Total seeks: 6
                Forward seeks: 5
                Backward seeks: 1
                Avg seek len: 228.75MiB
        Total clusters: 1
                Avg cluster size: 48.00KiB
                Min cluster size: 48.00KiB
                Max cluster size: 48.00KiB
        Total disk spread: 725.61MiB
        Total read time: 0 s 12 us
        Levels: 2
        Total nodes: 9
                On level 0:        8
                On level 1:        1  (avg fanout 8)
Calculating size of extent tree
Segmentation fault (core dumped)
@LaurentBonnaud
Copy link
Author

Here is a backtrace:

(gdb) bt
#0  calc_root_size.isra.0 (key=key@entry=0x7fffffffe0f7, find_inline=find_inline@entry=0, tree_root=<optimized out>,
    tree_root=<optimized out>) at cmds/inspect-tree-stats.c:337
#1  0x00005555555bee2b in cmd_inspect_tree_stats (cmd=<optimized out>, argc=<optimized out>, argv=<optimized out>)
    at cmds/inspect-tree-stats.c:495
#2  0x000055555556bee8 in main (argc=3, argv=0x7fffffffe2a0) at /build/btrfs-progs-DQquNj/btrfs-progs-5.16.2/btrfs.c:405

@kdave kdave added bug docs Changes in documentation or help text labels Oct 5, 2022
@kdave
Copy link
Owner

kdave commented Oct 5, 2022

There are two things to do here:

  • update the warning that it can also crash, I think similar warning is in mkfs so this can be put to a common warning in case we allow that for more tools
  • add more sanity checks that would at least exit gracefully in case invalid data are read

@kdave
Copy link
Owner

kdave commented Apr 19, 2023

I've changed the message to:

warning("%s already mounted, tree-stats accesses the block devices directly, this may\n"
          "\tresult in inaccurate numbers, various errors or it may crash if the filesystem\n"
          "\tchanges unexpectedly, restart if needed or remount read-only", argv[optind]);

I don't see an immediate things to fix from the stack trace you posted. After some random tries on a filesystem that is under load I see transid errors, no crashes.

@kdave kdave closed this as completed Apr 19, 2023
@kdave kdave added this to the v6.3 milestone Apr 19, 2023
kdave added a commit that referenced this issue Apr 20, 2023
…ed filesystem

Running 'btrfs inspect tree-stats' on a mounted filesystem works though
it reads directly from block devices. This can lead to inconsistent
data, warnings, errors or or a crash. More checks could be added but at
least explain things in more detail.

Issue: #520
Signed-off-by: David Sterba <[email protected]>
kdave added a commit that referenced this issue Apr 25, 2023
…ed filesystem

Running 'btrfs inspect tree-stats' on a mounted filesystem works though
it reads directly from block devices. This can lead to inconsistent
data, warnings, errors or or a crash. More checks could be added but at
least explain things in more detail.

Issue: #520
Signed-off-by: David Sterba <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug docs Changes in documentation or help text
Projects
None yet
Development

No branches or pull requests

2 participants