Commit graph

600 commits

Author SHA1 Message Date
Qu Wenruo fbb1170111 btrfs-progs: tests: add test case for degraded raid5
The new test case will make sure btrfs check is fine checking a degraded
raid5 filesystem.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-11-24 17:29:12 +01:00
David Sterba bd2b4158c8 btrfs-progs: tests: update stream version checks in misc/058
The send stream v2 is supported if the file exists and does not contain
"1". The previous fix reversed the condition but this does not work on
kernel with v1 only support.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-11-04 20:23:22 +01:00
Josef Bacik 584b3e1d55 btrfs-progs: properly test for send_stream_version
We want to notrun if this test fails, not if it succeeds.  Additionally
we want -s, as -q will still print an error if it gets ENOENT from the
file we're trying to grep.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-31 15:26:50 +01:00
David Sterba 1414ecbb6f btrfs-progs: replace strerror(errno) with %m in printf formats
We're using the %m format where possible.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-26 09:46:22 +02:00
David Sterba 5b2889853a btrfs-progs: tests: add case for clearing stale qgroups
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-26 09:31:19 +02:00
Qu Wenruo 666f3c971d btrfs-progs: tests: add support check to convert-tests/022
[BUG]
The test case convert/022 will fail if the system doesn't have
reiserfs support nor reiserfs user space tools:

  # make TEST=022\* test-convert
    [TEST]   convert-tests.sh
  WARNING: reiserfs filesystem not listed in /proc/filesystems, some tests might be skipped
    [TEST/conv]   022-reiserfs-parent-ref
  Failed system wide prerequisities: mkreiserfs
  test failed for case 022-reiserfs-parent-ref
  make: *** [Makefile:443: test-convert] Error 1

[CAUSE]
Unlike other test cases, convert/022 doesn't even check if we have
kernel support for it.

[FIX]
Add the proper check before doing system wide prerequisities checks.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:12 +02:00
Qu Wenruo 53b3a947e8 btrfs-progs: tests: fix the wrong kernel version check
[BUG]
After upgrading to kernel v6.0-rc, btrfs-progs selftest mkfs/001 no
longer checks single device RAID0 and other new features introduced in
v5.13:

  # make TEST=001\* test-mkfs
    [TEST]   mkfs-tests.sh
    [TEST/mkfs]   001-basic-profiles
  $ grep -IR "RAID0\/1" tests/mkfs-tests-results.txt
  ^^^ No output

[CAUSE]
The existing check_min_kernel_version() is doing an incorrect check.

The old check looks like this:

	[ "$unamemajor" -lt "$argmajor" ] || return 1
	[ "$unameminor" -lt "$argminor" ] || return 1
	return 0

For 6.0-rc kernels, we have the following values for mkfs/001

 $unamemajor = 6
 $unameminor = 0
 $argmajor   = 5
 $argminor   = 12

The first check doesn't exit immediately, as 6 > 5.
Then we check the minor, which is already incorrect.

If our major is larger than target major, we should exit immediate with
0.

[FIX]
Fix the check and add extra comment.

Personally speaking I'm not a fan or short compare and return, thus all
the checks will explicit "if []; then fi" checks.

Now mkfs/001 works as expected:

  # make TEST=001\* test-mkfs
    [TEST]   mkfs-tests.sh
    [TEST/mkfs]   001-basic-profiles
  $ grep -IR "RAID0\/1" tests/mkfs-tests-results.txt
   Data,RAID0/1:          204.75MiB
   Metadata,RAID0/1:      204.75MiB
   System,RAID0/1:          8.00MiB

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:12 +02:00
David Sterba 163aa3cc62 btrfs-progs: tests: add mkfs/025 to test parallel zone reset
Create a few emulated zoned devices and run mkfs, the zone reset is
expected to be run in parallel. It's using memory-backed devices so it's
too fast to measure the differences and we can't expect availability of
slow zoned devices so this test is very simplistic.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:08 +02:00
David Sterba 6a968e0f55 btrfs-progs: tags: add nullb for testing zoned devices
I've written a simple shell wrapper for null_blk configuration
(https://github.com/kdave/nullb). Make a local copy of version 0.1 to
avoid external dependency for our tests.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:08 +02:00
David Sterba 9cb5b0d058 btrfs-progs: tests: in mkfs/002 use grep -E instead of egrep
The egrep command is deprecated (per manual page of grep) for a long
time and will probably be removed, the replacement is 'grep -E'.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:08 +02:00
David Sterba 20496884a9 btrfs-progs: tests: detect send stream version in misc/053
The encoded stream is supported since protocol version 2, detect
support.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:13 +02:00
David Sterba 7d06a7e561 btrfs-progs: tests: use _mktemp_local for temporary files
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:13 +02:00
David Sterba caa57c1689 btrfs-progs: tests: use _mktemp for creating files
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:12 +02:00
David Sterba 500f826f31 btrfs-progs: tests: add helper for creating local temporary file
Some tests don't use the /tmp temporary files and store it locally in
the test directory. To support NFS this needs to be created by a few
commands. To avoid accidental breakage add a convenience helper.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:12 +02:00
David Sterba 1c3ab87c92 btrfs-progs: tests: check that receive --dump escapes target paths
Verify that receive --dump escapes paths for rename, symlink and
hardlink when it's the "dest=" value.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:12 +02:00
David Sterba cdd74d8ac5 btrfs-progs: tests: fix misc/016 encoded write, permissions of send stream file
To be able to run the test suite on NFS the temporary files need to be
writeable for all, root due to send and owner due to the way it's
created.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-09-12 18:42:21 +02:00
Qu Wenruo 192d436503 btrfs-progs: tests: add test case for shrunk device
Create a filesystem on a file backed loop block device, then shrink the
file (and its loop block device), then make sure btrfs check can detect
such shrunk device.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-09-12 15:31:18 +02:00
David Sterba 8c9bd8e6a8 btrfs-progs: tests: add matching line for extent leaks to scan-results
The extent leaks are detected in debug builds but tests/scan-build.sh
does not look for them, so add the match expression.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-09-12 15:31:13 +02:00
David Sterba e97c158b36 btrfs-progs: tests: fix udev build test option name
Signed-off-by: David Sterba <dsterba@suse.com>
2022-08-16 15:18:12 +02:00
Josef Bacik 06b6ad5e01 btrfs-progs: check: check for invalid free space tree entries
While testing some changes to how we reclaim block groups I started
hitting failures with my TEST_DEV.  This occurred because I had a bug
and failed to properly remove a block groups free space tree entries.
However this wasn't caught in testing when it happened because
btrfs check only checks that the free space cache for the existing block
groups is valid, it doesn't check for free space entries that don't have
a corresponding block group.

Fix this by checking for free space entries that don't have a
corresponding block group.  Additionally add a test image to validate
this fix.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-08-16 15:18:12 +02:00
Chung-Chiang Cheng 91a0881200 btrfs-progs: tests: remove duplicated helper
The helper `check_min_kernel_version` is duplicated and can be removed.

Signed-off-by: Chung-Chiang Cheng <cccheng@synology.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-08-16 15:18:12 +02:00
Mike Fleetwood 7b6922c988 btrfs-progs: dump-super: exit with failure when printing bad superblock
Attempting to dump a bad btrfs superblock returns successful exit status
zero.  According to the manual page non-zero should be returned on
failure.  Fix this.

    $ btrfs inspect-internal dump-super /dev/zero
    superblock: bytenr=65536, device=/dev/zero
    ---------------------------------------------------------
    ERROR: bad magic on superblock on /dev/zero at 65536

    $ echo $?
    0

Signed-off-by: Mike Fleetwood <mike.fleetwood@googlemail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-08-16 15:18:12 +02:00
Nikolay Borisov f4da3ea032 btrfs-progs: tests: add test for fi show and missing device
Add a test to ensure that 'btrfs fi show' on a mounted filesystem, which
has a missing device will explicitly print which device is missing.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-08-16 15:18:11 +02:00
Boris Burkov 4bfdd4eafd btrfs-progs: receive: add tests for basic encoded_write send/receive
Adapt the existing send/receive tests by passing '-o compress-force' to
the mount commands in a new test. After writing a few files in the
various compression formats, send/receive them with and without
--force-decompress to test both the encoded_write path and the fallback
to decode+write.

Signed-off-by: Boris Burkov <boris@bur.io>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-08-16 15:18:09 +02:00
David Sterba 355844f86b btrfs-progs: libbtrfs: move extent-cache.h to ctree.h
Move the remaining structure definitions and prototypes to ctree.h that
is now the only user.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-06-06 15:49:22 +02:00
David Sterba 6b539bbbc4 btrfs-progs: libbtrfs: move extent_io.h to ctree.h
Move the remaining structure definitions and prototypes to ctree.h that
is now the only user.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-06-06 15:49:13 +02:00
David Sterba 02b06b3e8d btrfs-progs: convert: fix self-reference of directory
Creating a simple directory structure leads to the following error:

  $ btrfs check
  Checking filesystem on test.img
  UUID: 8f2292ad-c80e-4ab4-8a72-29aa3a83002c
  [1/7] checking root items
  [2/7] checking extents
  [3/7] checking free space cache
  [4/7] checking fs roots
	  unresolved ref dir 260 index 0 namelen 2 name .. filetype 0 errors 3, no dir item, no dir index
  ERROR: errors found in fs roots
  found 101085184 bytes used, error(s) found
  total csum bytes: 98460
  total tree bytes: 262144
  total fs tree bytes: 49152
  total extent tree bytes: 16384
  btree space waste bytes: 151864
  file data blocks allocated: 167931904
   referenced 167931904

The self-reference should exist for the toplevel directory, where the
parent directory points to itself.

Issue: #453
Author: tyan0
Signed-off-by: David Sterba <dsterba@suse.com>
2022-06-06 15:48:08 +02:00
David Sterba df8519c35f btrfs-progs: tests: remove ext3 tests
The ext3 has been superseded by ext4, we don't need to test it
separately so this reduces the convert tests run time.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-05-24 20:47:55 +02:00
Qu Wenruo 10a7c0eda5 btrfs-progs: tests: make sure we don't create bitmaps for empty fs
Add test case is to make sure on a relative large empty fs, we won't
create bitmaps to unnecessarily increase the size of free space tree.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-05-20 15:54:20 +02:00
Qu Wenruo 2d6acbaee4 btrfs-progs: tests/fsck: add test case for data csum check on raid5
Previously 'btrfs check --check-data-csum' will report tons of false
alerts for RAID56.

Add a test case to make sure with the new RAID56 rebuild ability, there
should be no false alerts.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-04-26 01:14:48 +02:00
Qu Wenruo 013d80648c btrfs-progs: tests: check warning for seed and sprouted filesystems
Previously we had a bug that btrfs check would report false warning for
a sprouted filesystem.

So this patch will add a new test case to make sure neither seed nor
and sprouted filesystem will cause such false warning.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-04-25 19:06:06 +02:00
Qu Wenruo bfe6402026 btrfs-progs: make sure "btrfstune -S1" will reject fs with dirty log
The new test case will have a image file which has dirty log
(btrfs-image supports dumping log tree).

So we can easily check if "btrfstune -S" will reject fs with dirty log.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-04-25 18:30:28 +02:00
Qu Wenruo 35789abef1 btrfs-progs: tests: add test case for super num devs mismatch
The new image has incorrect super num devices (have 8 expect 1).

The image has to be raw format, as btrfs-image restore will reset super
num devices to correct value.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-03-24 00:36:13 +01:00
Josef Bacik babbfa8ac2 btrfs-progs: tests: add a test to check orphaned directories
When adding the GC support I noticed we were failing fsck when we had a
directory that hadn't been cleaned up yet because of rm -rf.  However
this isn't limited to extent-tree-v2, we'll actually fail in the same
way if we were unable to do the evict portion of the deletion and left
the orphan items around for everybody.

This is a valid file system, it'll be cleaned up properly at mount time,
so fsck shouldn't fail in this case.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-03-08 18:47:21 +01:00
Josef Bacik c91d5bf144 btrfs-progs: tests: use --force for --init-csum-tree in 003-multi-check-unmounted
003-multi-check-unmounted was taking a long time, this is because it was
doing the 10 second countdown for each iteration of --init-csum-tree.
Fix this by using --force to bypass the countdown.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-03-08 18:18:00 +01:00
David Sterba 2341d7fb9b btrfs-progs: tests: copy fsstress.c from fstests
The fsstress tool is a useful file generator, pull it from fstests as
it's not packaged as a standalone tool anywhere and the LTP version is
out of date.

The file has been modified to build, some xfs-specific ioctls are not
supported.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-03-08 18:11:40 +01:00
David Sterba 19f0b3dbcd btrfs-progs: tests: sync fssum.c from fstests
The support for xattr has been in the fstests version for some time,
copy it here as well.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-03-08 18:11:40 +01:00
David Sterba 43f18c6776 btrfs-progs: tests: drop 32-on-64bit build support
Building 32bit binaries on 64bit hosts is tedious due to all the
required libraries with the right target, also the static versions.
Limit the build only to the native arch.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-02-16 22:48:01 +01:00
David Sterba f33c0aea67 btrfs-progs: tests: add more configure options for build tests
There are some configure options not covered by build tests, eg. the
--disable-zoned build broke recently.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-02-16 22:48:01 +01:00
Qu Wenruo 2f734d7b2c btrfs-progs: tests/fsck: add test image with invalid metadata backref level
The image has a key in extent tree, (30457856 METADATA_ITEM 256), which
has invalid level (256 > BTRFS_MAX_LEVEL).

Make sure check can at least detect such problem.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-02-01 18:42:02 +01:00
Qu Wenruo f2828ff819 btrfs-progs: tests: add test case for init-csum-tree
This new test script will create a fs with the following situations:

- Preallocated extents (no data csum)
- Nodatasum inodes (no data csum)
- Partially written preallocated extents (no data csum for part of the
  extent)
- Regular data extents (with data csum)
- Regular data extents then hole punched (with data csum)
- Preallocated data, then written, then hole punched (with data csum)
- Compressed extents (with data csum)

And make sure after --init-csum-tree (with or without
--init-extent-tree) the result fs can still pass check.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-02-01 18:41:19 +01:00
Adam Borowski 6da5478a38 btrfs-progs: fix a bunch of typos
These have been detected by lintian and codespell.

Signed-off-by: Adam Borowski <kilobyte@angband.pl>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-02-01 18:40:53 +01:00
Nikolay Borisov 4dac8cd1f2 btrfs-progs: tests: test for btrfs fi usage output
There was a regression in version 5.15 due to changes in how the ratio
for the various raid profiles got calculated and this in turn had a
cascading effect on unallocated/allocated space reported.

Add a test to ensure this regression doesn't occur again.

Issue: #422
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-11-25 15:24:15 +01:00
David Sterba dca6b12f0a btrfs-progs: fix read-write subvol and received_uuid flags check
There's a report that a read-only subvolume with a received_uuid set
emits the warning in command 'btrfs subvolume show', which is obviously
wrong.

The reason is that there are different types of root item flags,
depending on how we read them. The check in cmd_subvol_show uses the
ioctl GET_SUBVOL_INFO and the appropriate flag is raw
BTRFS_ROOT_SUBVOL_RDONLY (0x1), while there's another SUBVOL_GETFLAGS that
maps the flags and the raw value is different (BTRFS_SUBVOL_RDONLY, 0x2).

Due to this the warning was issued. Fix that by using the right flag
constant. The test has been extended to check for all combinations of
read-write and received_uuid.

Issue: #419
Signed-off-by: David Sterba <dsterba@suse.com>
2021-11-04 20:56:42 +01:00
David Sterba 83c0a82289 btrfs-progs: tests: switch mktemp to local helpers
Use the helpers to create temporary files, this save some typing and
we'll have a bit more consistent naming.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:24 +02:00
David Sterba d96d143ef2 btrfs-progs: tests: unify mktemp file name pattern
The file names are build from roughly these components:

- btrfs-progs as prefix
- category (mkfs, convert) or what's the type of the file like 'image'
- the substitution template, XXXXXX

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:24 +02:00
David Sterba ded1e50cd3 btrfs-progs: tests: add helpers for creating temporary file
For convenience add helpers that will create a temporary file in the
$TMPDIR with a given additional tag in the name for later
identification.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:24 +02:00
Qu Wenruo 6e888a7a6c btrfs-progs: tests: make sure mkfs.btrfs cleans up temporary chunks
Since current "btrfs filesystem df" command will warn if there are
multiple profiles of the same type, it's a good way to detect left-over
temporary chunks.

Enhance the existing mkfs-tests/001-basic-profiles test case to also
check for the warning messages, to make sure mkfs.btrfs has properly
cleaned up all temporary chunks.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:24 +02:00
Qu Wenruo db8c9a420c btrfs-progs: tests: make misc/038 more robust when searching backup slots
Test case misc/038 uses hard coded backup slot number, this means if we
change how many transactions we commit during mkfs, it will immediately
break the tests.

Such hard coded tests will be a big pain for later btrfs-progs updates.

Update it with runtime backup slot search.

Such search is done by using current filesystem generation as a search
target and grab the slot number.

By this, no matter how many transactions we commit during mkfs, the test
case should be able to handle it.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:24 +02:00
David Sterba 7ce3ae3966 btrfs-progs: libbtrfs: drop crc32c.h from exported headers
The usage of the crc32 helpers in ctree.h has been removed and there's
no other reason to keep crc32c.h exported.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:46:35 +02:00