Commit Graph

5252 Commits

Author SHA1 Message Date
Marek Behún
08fb534eb7 btrfs-progs: do not fail when offset of a ROOT_ITEM is not -1
When the btrfs_read_fs_root() function is searching a ROOT_ITEM with
location key offset other than -1, it currently fails via BUG_ON.

The offset can have other value than -1, though. This can happen for
example if a subvolume is renamed:

  $ btrfs subvolume create X && sync
  Create subvolume './X'
  $ btrfs inspect-internal dump-tree /dev/root | grep -B 2 'name: X$
        location key (270 ROOT_ITEM 18446744073709551615) type DIR
        transid 283 data_len 0 name_len 1
        name: X
  $ mv X Y && sync
  $ btrfs inspect-internal dump-tree /dev/root | grep -B 2 'name: Y$
        location key (270 ROOT_ITEM 0) type DIR
        transid 285 data_len 0 name_len 1
        name: Y

As can be seen the offset changed from -1ULL to 0.

Do not fail in this case.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
CC: Qu Wenruo <wqu@suse.com>
CC: Tom Rini <trini@konsulko.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-19 15:24:42 +01:00
Nikolay Borisov
3e653e801c btrfs-progs: remove duplicate checks from cmd_filesystem_resize
btrfs_open_dir already has a check whether the passed path is a
directory and if so it returns a specific error code (-3) when such an
error occurs. Use this instead of open-coding the directory check. To
avoid regression in cli/003 test also move directory checks before fs
type in btrfs_open.

Output before this check:

  ERROR: resize works on mounted filesystems and accepts only
  directories as argument. Passing file containing a btrfs image
  would resize the underlying filesystem instead of the image.

After:

  ERROR: not a directory: /root/btrfs-progs/tests/test.img
  ERROR: resize works on mounted filesystems and accepts only
  directories as argument. Passing file containing a btrfs image
  would resize the underlying filesystem instead of the image.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-19 15:24:42 +01:00
Nikolay Borisov
b39d02a0c0 btrfs-progs: tests: cli/003 verify that the path is not an image
Add a test case which ensures that when resize is tried on an image
instead of a directory appropriate warning is produced and the command
fails.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-19 15:24:42 +01:00
David Sterba
07b06ead7e Revert "btrfs-progs: build: add libmount dependency"
This reverts commit 61ecaff036.

The libmount functionality is not used anymore, we can remove it
entirely.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-19 15:24:42 +01:00
David Sterba
b604e0eda2 btrfs-progs: remove workarounds for libmount and static build
Partial revert of 922eaa7b54 ("btrfs-progs: build: fix linking with
static libmount"), remove the necessary workarounds like the weak
symbols and link time warnings. Symbols renamed not to clash with
libmount (parse_size, canonicalize_path) haven't been reverted because
the new names are acceptable.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-19 15:24:42 +01:00
David Sterba
798d34074c Revert "btrfs-progs: INSTALL: update build dependencies"
This reverts commit 98a88aec64.

The libmount dependency will be dropped so remove it from the
documentation as well.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-19 15:24:42 +01:00
David Sterba
e31679c1ec btrfs-progs: reimplement find_mount_fsroot without libmount
In commit 57cfe29e69 ("btrfs-progs: utils: introduce
find_mount_fsroot") the entries in /proc/self/mountinfo are parsed by a
convenience library libmount, because getmntent does not provide the
information we need to distinguish bind mounts.

Using libmount turned out to be problematic in several ways:

- static build got broken due to clashing symbols, eg. for parsing size
  or path canonicalization (#333)

- long-term distros do not have libmount new enough (2.24+) to provide
  some functions (mnt_table_is_empty, #334)

- libmount internally uses getgrnam_r/mnt_get_uid/... that are not
  static-build friendly, a warning is printed during link time for each
  binary; we don't use any of the functions

- libmount has further library dependencies that we don't need:

  $ ldd /usr/lib64/libmount.so.1
	  linux-vdso.so.1 (0x00007fff4f175000)
	  libc.so.6 => /lib64/libc.so.6 (0x00007f44a1763000)
	  libblkid.so.1 => /usr/lib64/libblkid.so.1 (0x00007f44a1730000)
	  libselinux.so.1 => /usr/lib64/libselinux.so.1 (0x00007f44a1704000)
	  /lib64/ld-linux-x86-64.so.2 (0x00007f44a1998000)
	  libpcre.so.1 => /usr/lib64/libpcre.so.1 (0x00007f44a166c000)
	  libdl.so.2 => /lib64/libdl.so.2 (0x00007f44a1666000)

  namely selinux, pcre and dl.

Summing it up, libmount causes more trouble than it's worth using a
convenience library, we want to keep the dependencies minimal so the
custom mountinfo parser was inevitable.

Issue: #333
Issue: #334
Issue: #336
Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-19 15:24:40 +01:00
Filipe Manana
81d8ea9346 btrfs-progs: receive: remove workaround for setting capabilities
We had a few bugs on the kernel side of send/receive where capabilities
ended up being lost after receiving a send stream. They all stem from the
fact that the kernel used to send all xattrs before issuing the chown
command, and the later clears any existing capabilities in a file or
directory.

Initially a workaround was added to btrfs-progs' receive command, in commit
123a2a0850 ("btrfs-progs: receive: restore capabilities after chown"),
and that fixed some instances of the problem. More recently, other instances
of the problem were found, a proper fix for the kernel was made, which fixes
the root problem by making send always emit the setxattr command for setting
capabilities after issuing a chown command. This was done in kernel commit
89efda52e6b693 ("btrfs: send: emit file capabilities after chown"), which
landed in kernel 5.8.

However, the workaround on the receive command now causes us to incorrectly
set a capability on a file that should not have it, because it assumes all
setxattr commands for a file always comes before a chown.

Example reproducer:

  $ cat send-caps.sh
  #!/bin/bash

  DEV1=/dev/sdh
  DEV2=/dev/sdi

  MNT1=/mnt/sdh
  MNT2=/mnt/sdi

  mkfs.btrfs -f $DEV1 > /dev/null
  mkfs.btrfs -f $DEV2 > /dev/null

  mount $DEV1 $MNT1
  mount $DEV2 $MNT2

  touch $MNT1/foo
  touch $MNT1/bar
  setcap cap_net_raw=p $MNT1/foo

  btrfs subvolume snapshot -r $MNT1 $MNT1/snap1

  btrfs send $MNT1/snap1 | btrfs receive $MNT2

  echo
  echo "capabilities on destination filesystem:"
  echo
  getcap $MNT2/snap1/foo
  getcap $MNT2/snap1/bar

  umount $MNT1
  umount $MNT2

When running the test script, we can see that both files foo and bar get
the capability set, when only file foo should have it:

  $ ./send-caps.sh
  Create a readonly snapshot of '/mnt/sdh' in '/mnt/sdh/snap1'
  At subvol /mnt/sdh/snap1
  At subvol snap1

  capabilities on destination filesystem:

  /mnt/sdi/snap1/foo cap_net_raw=p
  /mnt/sdi/snap1/bar cap_net_raw=p

Since the kernel fix was backported to all currently supported stable
releases (5.10.x, 5.4.x, 4.19.x, 4.14.x, 4.9.x and 4.4.x), remove the
workaround from receive. Having such a workaround relying on the order
of commands in a send stream is always troublesome and doomed to break
one day.

A test case for fstests will come soon.

Issue: #85
Issue: #202
Issue: #292
Reported-by: Richard Brown <rbrown@suse.de>
Reviewed-by: Su Yue <l@damenly.su>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-19 15:18:39 +01:00
David Sterba
2347b34af4 btrfs-progs: fix device mapper path canonicalization
Commit 922eaa7b54 ("btrfs-progs: build: fix linking with static
libmount") broke path canonicalization, that prevented eg 'device add
/dev/dm-0' to properly recognize the device mapper names.

Issue: #339
Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-19 15:18:39 +01:00
David Sterba
1804dcaa4b btrfs-progs: tests: wait for dm device in test mkfs/005
When the test environment is in 'docker', there's some delay before the
device mapper nodes appear in /dev/mapper. Add a delay before the test
continues, usually 1 second was enough but give it more just in case.
Add ad fallback to skip the test if the device node does not show up,
this is a problem in the running environment and the testsuite should
continue.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-19 15:18:39 +01:00
David Sterba
a3aa4c0717 btrfs-progs: tests: randomize device name in mkfs/005-long-device-name-for-ssd
Add some randomization to the long device name in case the testsuite
runs multiple times on the same host.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-05 16:19:24 +01:00
David Sterba
01c1bf8d8e btrfs-progs: tests: replace which by type -p
In some environments the which utility might not be available and the
shell builtin 'type -p' is readily available.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-05 14:23:11 +01:00
David Sterba
f2ffce38b9
Btrfs progs v5.10.1
Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-05 12:18:00 +01:00
David Sterba
d47a50ab20 btrfs-progs: update CHANGES for 5.10.1
Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-05 12:16:41 +01:00
David Sterba
98a88aec64 btrfs-progs: INSTALL: update build dependencies
Add the specific libmount version that has the required functions,
though it still fails to build on CentOS 7 and similar. The libmount
dependency could be dropped in the future but for now at least document
it.

Issue: #334
Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-05 12:03:38 +01:00
David Sterba
b691968d18 btrfs-progs: docs: clarify scrub requiring mounted filesystem
That scrub works only on a mounted filesystem is not clear in connection
with the possibility to start scrub on a given device. Update the manual
page and mention the mount requirement where approrpriate.

Issue: #335
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-29 15:12:34 +01:00
David Sterba
911741e854 btrfs-progs: tests: add support to test the .static binaries
Testing the statically built binaries is not straightforward, add a
convenient way to do that:

  $ make TEST_FLAVOR=static

There should be no difference in the test results.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-29 14:24:33 +01:00
David Sterba
922eaa7b54 btrfs-progs: build: fix linking with static libmount
The libmount dependency has been added in commit 61ecaff036
("btrfs-progs: build: add libmount dependency"), and static build got
broken. There are functions that do basically the same thing and also
share the name, which in turn fails at link time.

  ld: /../lib64/libmount.a(libcommon_la-canonicalize.o): in function `canonicalize_dm_name':
  util-linux-2.34/lib/canonicalize.c:58: multiple definition of `canonicalize_dm_name';
	  common/path-utils.static.o:btrfs-progs/common/path-utils.c:286: first defined here

In case the collision can be resolved by renaming, it's done
(canonicalize_path and parse_size). There are 2 symbols from selinux
that are substituted by a weak aliases during the static build.

There's one new warning due to use of getgrnam_r in libmount that
depends on dynamic linking and may not work properly with static build.
We're not using the related functions directly or indirectly, so it
should be safe to ignore the warnings.

  ld: ../lib64/libmount.a(la-utils.o): in function `mnt_get_gid':
  util-linux-2.34/libmount/src/utils.c:625: warning: Using 'getgrnam_r' in statically linked applications
  +requires at runtime the shared libraries from the glibc version used for linking

Issue: #333
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-25 23:31:56 +01:00
David Sterba
273380d98f
Btrfs progs v5.10
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-18 23:16:14 +01:00
David Sterba
63675d9b7d btrfs-progs: update CHANGES for 5.10
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-18 22:50:51 +01:00
David Sterba
f93d67ece1 btrfs-progs: docs: document command line conventions
First draft of the command line conventions regarding options, wording,
style and formatting.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-18 20:53:23 +01:00
David Sterba
65058429a5 btrfs-progs: ci: temporarily disable gitlab CI
The jobs has been failing for some time due the time limit 1h:

+ qemu-system-x86_64 -m 512 -nographic -kernel /repo/bzImage -drive
  file=/repo/qemu-image.img,index=0,media=disk,format=raw -fsdev
  local,id=btrfs-progs,path=/repo,security_model=mapped -device
  virtio-9p-pci,fsdev=btrfs-progs,mount_tag=btrfs-progs -append
  'console=tty1 root=/dev/sda rw'
  main-loop: WARNING: I/O thread spun for 1000 iterations
  ERROR: Job failed: execution took longer than 1h0m0s seconds

We'd still like to use the qemu test as it could pull the recent
development kernel that the base image does not provide. However the
overall performance is too bad and it does not make sense to waste
GitLab resources.

Also remove the build status badge from README as it changed at some
point and does not render as a SVG image anymore.

Issue: #171
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-18 20:53:23 +01:00
David Sterba
bfc7ab7c39 btrfs-progs: tests: set toplevel subvolume as default when specified as 0
Testcase for commit "btrfs-progs: subvol set-default: change id to 5 if
specified as 0".

Issue: #327
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-18 17:49:23 +01:00
David Sterba
3c49295e8a btrfs-progs: subvol set-default: change id to 5 if specified as 0
The id 0 of the default subvolume is an internal alias for the toplevel
fs tree, kernel does that conversion. Until 2116398b1d ("btrfs-progs:
use libbtrfsutil for set-default") there was no manual conversion and
the value was passed to kernel as-is. With the switch to the
libbtrfsutil API this got broken (4.19).

  $ btrfs subvol set-default 0 /path

In this case the default subvolume would be containing subvolume of
/path instead of the toplevel one.

Fix it by manually switching the 0 to 5 in case user specifies that to
avoid the difference in the API, that we can't change.

Issue: #327
Reported-by: Chris Murphy
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-18 17:49:23 +01:00
Eric Semeniuc
d2316fdfd2 btrfs-progs: docs: grammar and typo fix for btrfs check
Pull-request: #9
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-18 17:49:23 +01:00
Qu Wenruo
501dc44c7f btrfs-progs: check: only warn if clearing v1 cache and v2 found
There are cases where v1 free space cache is still left while user has
already enabled v2 cache.  In that case, we still want to force v1 space
cache cleanup in btrfs-check.

This patch will only warn and not exit if v2 is detected while the user
asked to clear v1.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-18 17:49:23 +01:00
Sheng Mao
9870d504d8 btrfs-progs: align receive buffer to enable fast CRC
To use optimized CRC implementation, the input buffer must be
unsigned long aligned. btrfs receive calculates checksum based on
read_buf, including btrfs_cmd_header (with zeroed CRC field)
and command content.

Reorder the buffer to the beginning of the structure and force the
alignment to 64, this should be cacheline friendly and could speed up
the data transfers.

Interesting parts from the report:

Sending host:
Fedora 33
AMD ThreadRipper 1920X - 128GB RAM
2x10GBit Ethernet, bonded
MegaRaid 9270
6x16TB Seagate Exos in RAID5

Receiving host:
Fedora 33
Intel i3-7300 - HT enabled - 32GB RAM
10GBit Ethernet, single connection
MegaRaid 9260
12x8TB WD NAS drives in RAID5

The 2 hosts are connected to the same 10G switch. The sender could definitely
saturate a 10GBit link. The practically achievable writes on the backup host
would be lower, but still at least 400MB/s. The file system contains mostly
large files of 1GB+, so there is little meta-data.

With btrfs send/receive I'm getting a steady transfer rate of 60MB/s. The copy
has been running for a little over 5 days now, having only transferred some
25TB. This is way too slow for this setup.

Analyzing resource usage, the sender side is fine, both the btrfs send and the
corresponding ssh process only use about 10-10% CPU, which on a 24 threaded
machine is virtually nothing. However, the receiver is running with a load of
~2.6, with the sshd using 30-50% CPU and the btrfs receive a further 60-70%.
The rest of the load comes from IO wait. So the bottleneck is the btrfs receive
clearly.

Issue: #324
Signed-off-by: Sheng Mao <shngmao@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-18 17:49:22 +01:00
Marcos Paulo de Souza
6a6a7c4698 btrfs-progs: tests: test logical-resolve in various scenarios
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-18 17:49:22 +01:00
Marcos Paulo de Souza
6b8fed9e79 btrfs-progs: inspect: use find_mount_fsroot in logical-resolve
By using find_mount_fsroot we ensure that we return a valid path to the
final user, by ensuring that even if we return a bind mount, the
pathname of btrfs used was the same from the original mount.

This for a case when bind mounts and normal mount -o subvol=/path are
mixed.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-18 17:49:22 +01:00
Marcos Paulo de Souza
57cfe29e69 btrfs-progs: utils: introduce find_mount_fsroot
This new function checks for filesystem path name that was mounted, thus
being different from find_mount_root. By using libmount we can easily
parse /proc/self/mountinfo file and check for the pathname field.

The function is useful to filter bind mounts with content different from
the original mount, thus making it safe to assume that the reported path
can be accessed by the user, with the right content.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-18 17:49:22 +01:00
Marcos Paulo de Souza
61ecaff036 btrfs-progs: build: add libmount dependency
API provided by libmount allows to read various information from /proc
files about mount paths.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-18 17:49:19 +01:00
Josef Bacik
3f467adb34 btrfs-progs: check: properly exclude leaves for lowmem mode
The lowmem mode excludes all referenced blocks from the allocator in
order to avoid accidentally overwriting blocks while fixing the file
system.  However for leaves it wouldn't exclude anything, it would just
pin them down, which gets cleaned up on transaction commit.  We're safe
for the first modification, but subsequent modifications could blow up
in our face.  Fix this by properly excluding leaves as well as all of
the nodes.

Reviewed-by: Su Yue <l@damenly.su>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-13 22:33:10 +01:00
Su Yue
be6710f89d btrfs-progs: print bytenr of child eb if mismatched level found in read_node_slot
If btrfs check reported like

  ERROR: child eb corrupted: parent bytenr=178081 item=246 parent level=1 child level=2

It's hard to find which eb is corrupted without bytenr in dump tree
information:

  node 178081 level 1 items 424 free 69 generation 44495 owner EXTENT_TREE
  fs uuid 7d9dbe1b-dea6-4141-807b-026325123ad8
  chunk uuid 97a3e3aa-7105-4101-aaf7-50204a240e69
	  key (16613126144 EXTENT_ITEM 4096) block 177939087360 gen 44433
	  key (16632803328 EXTENT_ITEM 4096) block 177939120128 gen 44433
	  key (16654548992 EXTENT_ITEM 8192) block 177970380800 gen 44336
	  key (16697884672 EXTENT_ITEM 8192) block 177970397184 gen 44336
	  key (16714223616 EXTENT_ITEM 16384) block 177970413568 gen 44336
	  key (16721760256 EXTENT_ITEM 16384) block 177943855104 gen 44436
	  key (16857755648 EXTENT_ITEM 4096) block 177857544192 gen 44416
  ...

For easier lookup, print bytenr of child eb if its level is not equal
to parent's level - 1 in read_node_slot().

Signed-off-by: Su Yue <l@damenly.su>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-13 22:33:10 +01:00
David Sterba
df2bdf97d2 btrfs-progs: tests: test full 64bit timestamp conversion on ext4
Verify that [acm]time are copied from the ext4 source without loss of ns
precision.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-13 22:33:10 +01:00
Jiachen YANG
b3df561fbf btrfs-progs: convert: copy extra timespec on ext4
Currently btrfs-convert only copies ext2 inode timestamps
i_[cma]time from ext4, while filling 0 to nsec and crtime fields.

This change copies nsec and crtime by parsing i_[cma]time_extra fields.

Author: Jiachen YANG <farseerfc@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-13 22:33:10 +01:00
Adam Borowski
c615287cc0 btrfs-progs: a bunch of typo fixes
Signed-off-by: Adam Borowski <kilobyte@angband.pl>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-13 22:33:10 +01:00
David Sterba
bff976753c btrfs-progs: build: add missing gitignore and clean binaries
Ignore built hash-speedtest and btrfs-sb-mod, also clean them with the
rest.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-13 22:33:09 +01:00
David Sterba
9bf6b5c837 btrfs-progs: tests: add json formatter test coverage
Add a simple framework to exercise the json formatter and add testing
target that validates the output.

Run 'make test-json' to execute all available tests, requires 'jq'
utility for validation (https://github.com/stedolan/jq).

Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-13 22:33:09 +01:00
David Sterba
29e2dd7a23 btrfs-progs: initialize formatter context properly
In cases where the compiler does not initialize the formatter context to
all zeros, there could be garbage values left on the depth 0 that is not
explicitly initialized. This could lead to mistakenly printing a ","
separator before the last closing "}", like

{
  "__header": {
    "version": "1"
  },
}

Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-13 22:33:09 +01:00
Omar Sandoval
8b7d1fc918 btrfs-progs: send: fix crash on unknown option
The long options array for send is missing the zero terminator, so
unknown options result in a crash:

  # btrfs send --foo
  Segmentation fault (core dumped)

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-13 22:33:09 +01:00
David Sterba
ce7ab16441 btrfs-progs: tests: add Makefile for testsuite
Add a Makefile so tests can be run the same way from the standalone
testsuite as they are from git. The build dependencies are not checked
and the default path is for the system binaries.

Because of the path auto detection, running 'make' from the tests/
directory now works the same way as from the toplevel git directory.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-01-13 22:33:09 +01:00
Nikolay Borisov
92e15c97de btrfs-progs: tests: test check --clear-ino-cache
Pre-created image contains a subvolume and a snapshot so that cleaning
of multiple roots is also tested. The mount option 'inode_cache' will be
removed so we need the crafted image.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-12-16 17:08:53 +01:00
Nikolay Borisov
04f1977832 btrfs-progs: check: add option to remove ino cache
Inode cache feature is going to be removed in kernel 5.11. After this
kernel version items left on disk by this feature will take some extra
space. Testing showed that the size is actually negligible but for
completeness' sake give ability to users to remove such left-overs.

This is achieved by iterating every fs root and removing respective
items as well as relevant csum extents since the ino cache used the csum
tree for csums.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-12-16 17:08:53 +01:00
Sidong Yang
103d365a8f btrfs-progs: device stats: add json output format
Add support for json formatting. Switch hard coded printing code to
formatted print with output formatter. Json output would be useful for
other programs that parse output of the command.

The plain text format is not changed for backward compatibility but this
requires to do another switch by the output type.

Example text format:

device:                 /dev/vdb
devid			1
write_io_errs:          0
read_io_errs:           0
flush_io_errs:          0
corruption_errs:        0
generation_errs:        0

Example json format:

{
  "__header": {
    "version": "1"
  },
  "device-stats": [
    {
      "device": "/dev/vdb",
      "devid": "1",
      "write_io_errs": "0",
      "read_io_errs": "0",
      "flush_io_errs": "0",
      "corruption_errs": "0",
      "generation_errs": "0"
    }
  ]
}

Issue: #291
Signed-off-by: Sidong Yang <realwakka@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-12-16 17:08:53 +01:00
Sidong Yang
2e8906829a btrfs-progs: extend fmt_print_start_group to handle unnamed group
Extends fmt_print_start_group() so it can handle when name argument is
NULL. It is useful for printing unnamed array or map.

Signed-off-by: Sidong Yang <realwakka@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-12-16 17:08:53 +01:00
Josef Bacik
0c6e59e0b2 btrfs-progs: image: fix invalid size check for extent items
While trying to run down a corruption problem I needed to use
btrfs-image to generate known good states in between tests.  At some
point this started failing with

  either extent tree is corrupted or deprecated extent ref format

This is because the fs had an extent item that was large enough that it
no longer had inline extent references, they were all keyed extent
references.  The check is bogus, we can have extent items that are >=
the extent item size, not just > than the extent item size.  Fix the
check so that we can generate metadata dumps properly.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-12-16 17:08:53 +01:00
Josef Bacik
9cc9c9ab32 btrfs-progs: print the eb flags for nodes as well
While debugging a corruption problem I realized we don't spit out the
flags for nodes, which is needed when debugging relocation problems so
we know which nodes are the RELOC root items and which are the actual fs
tree's items.  Fix this by unifying the header printing helper so both
leaf's and nodes get the same information printed out.

  node 41070940160 level 1 items 34 free space 87 generation 7709536 owner ROOT_TREE
  node 41070940160 flags 0x1(WRITTEN) backref revision 1

Same for leaves:

  leaf 41070944256 items 12 free space 515 generation 7709536 owner ROOT_TREE
  leaf 41070944256 flags 0x1(WRITTEN) backref revision 1

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-12-16 17:08:53 +01:00
Josef Bacik
bc06a75a04 btrfs-progs: only print the parent or ref root for ref mismatches
While debugging some corruption, I got confused because it appeared as
if we had an invalid parent set on a extent reference, because of this
message:

  tree backref 67014213632 parent 5 root 5 not found in extent tree

But it turns out that parent and the root are a union, and we were just
printing it out regardless of the type of backref it was.  Fix the error
message to be consistent with the other mismatch messages, simply print
parent or root, depending on the ref type.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-12-16 17:08:53 +01:00
David Sterba
5f7191135f btrfs-progs: fix short/long unit size options
The two variants of unit options are not suitable for all commands, the
short options could interfere with existing options or limit future
extensions.

In 'filesystem du' the short options are not documented neither in help
text, nor in documentation so fix the code

In 'scrub status' it's the same but the documentation needs to be fixed
as well.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-12-16 17:08:52 +01:00
David Sterba
022168c32d btrfs-progs: subvol show: fix required arguments in help texts
The help text and documentation of the --rootid and --uuid parameters
is wrong as it does not say there's a required parameter. Add it and
enhance the docs to clarify what the options do.

Issue: #317
Signed-off-by: David Sterba <dsterba@suse.com>
2020-12-16 17:08:52 +01:00