Commit graph

661 commits

Author SHA1 Message Date
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
David Sterba 2e2c7c0fc6 btrfs-progs: libbtrfs: drop sizes.h from exported headers
The SZ_ macros have been removed from the other exported headers, we can
now safely drop seizes.h too.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:46:35 +02:00
David Sterba 38356d456b btrfs-progs: libbtrfs: drop radix-tree.h from exported headers
The header is only included from ctree.h but not actually used, we can
drop it from the exported files.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:46:35 +02:00
David Sterba cb9bd8e326 btrfs-progs: subvol show: print a warning with rw and receive_uuid
Add a slightly more convenient way to identify the subvolumes with bad
combination of flags and received uuid.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-07 18:40:34 +02:00
David Sterba 287d472b63 btrfs-progs: tests: subvolume ro->rw switch and received_uuid
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-07 18:40:29 +02:00
David Sterba 49bd94cc14 btrfs-progs: tests: make misc/038 work with free-space-tree
The test misc-tests/038-backup-root-corruption expects a particular
layout of the backup roots but this gets slightly changed due to free
space tree.

  $ make TEST=038-backup-root-corruption TEST_ARGS_MKFS='-Rfree-space-tree' TEST_ENABLE_OVERRIDE=true test-misc

Will result in test failure as the expected root is in slot 3 and not 2.
Update the test to try both.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-07 18:40:21 +02:00
David Sterba 27207d651a btrfs-progs: dump-tree: print complete root_item
The output of root_item in the 'inspect dump-tree' command lacks some
items and some of them are printed conditionally. As the dump utility
is for debugging, it's better to print all the items, with names
matching the structure members and order.

Some values will inevitably be all zeros like uuids or various
timestamps, but that's a minor issue and affecting only a few trees.

Example:

  item 0 key (EXTENT_TREE ROOT_ITEM 0) itemoff 15844 itemsize 439
	  generation 5 root_dirid 0 bytenr 30523392 byte_limit 0 bytes_used 16384
	  last_snapshot 0 flags 0x0(none) refs 1
	  drop_progress key (0 UNKNOWN.0 0) drop_level 0
	  level 0 generation_v2 5
	  uuid 00000000-0000-0000-0000-000000000000
	  parent_uuid 00000000-0000-0000-0000-000000000000
	  received_uuid 00000000-0000-0000-0000-000000000000
	  ctransid 0 otransid 0 stransid 0 rtransid 0
	  ctime 0.0 (1970-01-01 01:00:00)
	  otime 0.0 (1970-01-01 01:00:00)
	  stime 0.0 (1970-01-01 01:00:00)
	  rtime 0.0 (1970-01-01 01:00:00)

  item 3 key (FS_TREE ROOT_ITEM 0) itemoff 14949 itemsize 439
	  generation 4 root_dirid 256 bytenr 30408704 byte_limit 0 bytes_used 16384
	  last_snapshot 0 flags 0x0(none) refs 1
	  drop_progress key (0 UNKNOWN.0 0) drop_level 0
	  level 0 generation_v2 4
	  uuid ec4669b6-6d21-46ab-857e-d60cafde45b3
	  parent_uuid 00000000-0000-0000-0000-000000000000
	  received_uuid 00000000-0000-0000-0000-000000000000
	  ctransid 0 otransid 0 stransid 0 rtransid 0
	  ctime 1633021823.0 (2021-09-30 19:10:23)
	  otime 1633021823.0 (2021-09-30 19:10:23)
	  stime 0.0 (1970-01-01 01:00:00)
	  rtime 0.0 (1970-01-01 01:00:00)

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-07 18:39:44 +02:00
David Sterba 6887a3192f btrfs-progs: tests: fix fsck/024 to work with free-space-tree
The test looks for a pattern FREE_SPACE that also matches
FREE_SPACE_TREE when it's enabled. Use word regexp to match the whole
word only.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-06 16:49:25 +02:00
David Sterba 88de623dd2 btrfs-progs: convert: allow to set a duplicate uuid
Relax the condition about a unique uuid for convert, only print a
warning. In case we copy the uuid, it's expected that at the time the
conversion starts the uuid is not unique as it sill exists on the source
filesystem.

In case user sets the uuid manually but it's still the same one as on
the source filesystem we should also allow that, so it warns in this
case as well.

Update the test so it creates a block device where the uuid would be
also cached by blkid and lets the non-unique check succeed.

Issue: #404
Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-20 16:58:13 +02:00
Qu Wenruo 3c7e75eefb btrfs-progs: tests: test case to make sure btrfstune rejects corrupted fs
Although btrfstune will already warn users to make sure the fs is not
corrupted, we can never trust end users.

If the target fs has transid error, btrfstune can cause further damage,
thus we need to make sure btrfstune can safely reject fs with transid
error, other than ignoring the problem.

The image is copied from fsck-tests/002, just override check_image() to
run "btrfstune -u" instead.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-20 12:26:20 +02:00
David Sterba 7d16785ab4 btrfs-progs: tests: test options for defrag -c
Regression test for "btrfs-progs: fix defrag -c option parsing"

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-20 11:46:24 +02:00
David Sterba 53c9618ce0 btrfs-progs: libbtrfs: drop btrfs-list.h, raid56.h and btrfsck.h
libbtrfs isn't a proper library and exports internal headers that aren't
included from other headers and their use in public API does not make
sense. There are no known applications using them so don't install them.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-08 18:17:29 +02:00
David Sterba 7b2d6cd778 btrfs-progs: tests: add more API coverage to library-test
Update the library test stub to cover all the API functions we care
about (send stream, subvol search) and drop the rootid lookup that's
trivial to do via raw ioctls.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-08 18:16:16 +02:00
David Sterba e86425242f btrfs-progs: move send.h to kernel-shared/
The header contains the protocol definitions and is almost exactly the
same as the kernel version, move it to the proper directory.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 19:26:46 +02:00
David Sterba 9d98ad1db5 btrfs-progs: tests: add templates for most common test types
Create a ready-to-use templates for the most common tests, copied from
readme.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 18:10:56 +02:00
David Sterba 5b0e18ce6c btrfs-progs: tests: properly load dm-thin in mkfs/017
The test started to fail some time ago when dm-thin was changed to
dm-thin-pool that loads 2 targets dm-thin and dm-thin-pool. We can now
properly detect both and run the test.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 16:58:43 +02:00
David Sterba 37e0aa576c btrfs-progs: tests: allow alternate name for dm target detection
Some dm target name and module do not match exacly, extend the helper to
take optional 2nd parameter that will be checked in case loading by the
first parameter fails.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 16:57:06 +02:00
David Sterba 6694fe5de9 btrfs-progs: tests: do dm target detection by one
Switch the helper to take only one parameter, the target name. This can
be used to extend the helper with additional parameters for the target.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-09-07 16:48:42 +02:00
David Sterba 0534441e2e btrfs-progs: tests: add mkfs test for raid0/1 and raid10/2
Extend basic tests with the degenerate raid0 and raid10, coming in 5.15.
Mount of a freshly created filesystem works even on older kernels too.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-08-27 15:40:53 +02:00
Josef Bacik 4d57632e2f btrfs-progs: tests: add image with an invalid super bytes_used
This is used to validate the detection and correction code in both fsck
modes for an invalid bytes_used value in the super block.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-08-25 15:43:13 +02:00
Josef Bacik 71404c50e8 btrfs-progs: tests: fix running check mode lowmem tests
When I added the invalid super image I saw that the lowmem tests were
passing, despite not having the detection code yet.  Turns out this is
because we weren't using a run command helper which does the proper
expansion and adds the --mode=lowmem option.  Fix this to use the proper
handler, and now the lowmem test fails properly without my patch to add
this support to the lowmem mode.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-08-25 15:38:54 +02:00
Josef Bacik 72a37dca27 btrfs-progs: tests: add image with a corrupt block group item
This image has a broken used field of a block group item to validate
fsck does the correct thing.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-08-25 15:38:54 +02:00
Qu Wenruo 9df3619a9d btrfs-progs: require full nodesize alignement for subpage support
For the incoming extra page size support for subpage (sectorsize <
PAGE_SIZE) cases, the support for metadata will be a critical point.

Currently for subpage support, we require 64K page size, so that no
matter whatever the nodesize is, it will be contained inside one page.
And we will reject any tree block which crosses page boundary.

But for other page size, especially 16K page size, we must support
nodesize differently.

For nodesize < PAGE_SIZE, we will have the same requirement (tree blocks
can't cross page boundary).
While for nodesize >= PAGE_SIZE, we will require the tree blocks to be
page aligned.

To support such feature, we will make btrfs-check to reports more
subpage related warnings for metadata.

This patch will report any tree block which is not nodesize aligned as a
warning.

Existing mkfs/convert has already make sure all new tree blocks are
nodesize aligned, this is just for older converted filesystems.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-08-20 14:45:58 +02:00
Qu Wenruo 701c7d58db btrfs-progs: tests: don't check subpage related warnings for simple fsck tests
For fsck tests, we check the subpage warnings for each type 1 test, but
such type 1 tests are mostly read-only tests, and one of the test will
trigger new subpage related warnings (fsck/018).

For subpage related warnings, what we really care are write operations,
including mkfs, btrfs-convert and repair, not those read-only tests.

So skip the subpage warning check for fsck type 1 tests to prevent false
alert of later more strict subpage warnings.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-08-20 14:44:09 +02:00
Qu Wenruo 82e0720312 btrfs-progs: tests: also check subpage warning for check_image cases
There are two types of test cases:

- Type 1 (without test.sh)
- Type 2 (test.sh, mostly will override check_image())

For Type 2 tests, we check subpage related warnings of btrfs-check, but
didn't check it for Type 1 test cases.

In fact, Type 1 test cases are more important, as they involve repair,
which can generate new tree blocks, and we want to make sure such new
tree blocks won't cause subpage related warnings.

This patch will add the extra check for Type 1 test cases.

And it will make sure the subpage related warnings are really from this
test case, to prevent false alerts.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-08-20 14:42:47 +02:00
David Sterba 03a9dbf784 btrfs-progs: tests: add test for convert --uuid option
Signed-off-by: David Sterba <dsterba@suse.com>
2021-08-20 14:24:55 +02:00
Qu Wenruo af62875784 btrfs-progs: tests: check nlinks for directories
Make sure btrfs check can detect such problem.  Right now we have no way
to fix it yet.

Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-07-30 15:52:57 +02:00
David Sterba 1eb7b11303 btrfs-progs: remove stale user transaction ioctl definitions
The user transaction ioctls have been removed in kernel 4.17 by commit
7a5a07a81062 ("btrfs: Remove userspace transaction ioctls"), the
definitions are not relevant and can be removed.

The numbers could be reused in the future, eg. when there are no
maintained LTS kernels older than 4.19.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-06-19 22:07:50 +02:00
Qu Wenruo ab0d369525 btrfs-progs: tests/fsck: add test case to make sure btrfs check can reset btrfs_dev_item::bytes_used
The test image is manually crafted with 1MiB offset in the device item
of devid 1.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-06-19 22:07:49 +02:00
Qu Wenruo 77aca786ba btrfs-progs: tests: add test to ensure the restored image can be mounted
This new test case is to make sure the restored image file has been
properly enlarged so that newer kernel won't complain.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-05-06 16:41:47 +02:00
David Sterba f0d226fa48 btrfs-progs: tests: add missing variable setup to test-console
The paths are not adapted to the TEST_TOP added long time ago in
e44f595dd7 ("btrfs-progs: tests: unify test drivers, make ready for
extenral testsuite").

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-24 22:20:19 +01:00
David Sterba 05a92e6424 btrfs-progs: crypto: add test vectors
Add test vectors, a subset without keys as found in linux kernel sources
in crypto/test-mgr.h for all supported hash algorithms.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-24 22:20:19 +01:00
David Sterba 0c6e50dddd btrfs-progs: tests: verify that ext4 supports extra_isize
To properly check the 64bit timestamp conversion, the filesystem must
support it. Check that a freshly created filesystem contains the
feature.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-23 17:04:22 +01:00
David Sterba 3a22f0b25b btrfs-progs: balance: fix raid56 warning for other profiles
The warning is printed for profiles where it's not intended (like raid0
or raid1c4). Check the correct variable for the target profiles.

Issue: #355
Fixes: 1ed5db8db4 ("btrfs-progs: balance convert: add a warning and countdown for RAID56 conversion")
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-23 17:04:22 +01:00
David Sterba 5d80df6065 btrfs-progs: tests: add crafted image to test needs_recovery
Image of ext4 with needs_recovery incompat bit set. This bit cannot be
set by regular tune2fs so was created on an empty 4M image by patched
tune2fs that set the bit unconditionally (the image still passed e2fsck,
with journal recovery).

Issue: #348
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-23 17:04:21 +01:00
Pierre Labastie ea1e4c8a7b btrfs-progs: tests: fix quoting of sudo helper in misc/046-seed-multi-mount
When running the tests as root SUDO_HELPER is empty, so that
`run_check "" dd ...` is run, and it fails because the empty command is
not found.

Pull-request: #351
Issue: #352
Author: Pierre Labastie <pierre.labastie@neuf.fr>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-15 15:40:54 +01:00
David Sterba 833bf64762 btrfs-progs: tests: extend mkfs/001 to look for warnings after mkfs
Patch "btrfs-progs: fix false alert on tree block crossing 64K page
boundary" fixes a false alert (warning) when 'btrfs check' is called
right after mkfs.

As we have an extensive mkfs coverage in test mkfs/001, add the check for
the warning there instead of a separate test.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-15 15:40:54 +01:00
David Sterba 06bf4d0e8b btrfs-progs: tests: use force when decompressing images
Some tests report that decompressing the image failed, which did not
fail the test but could lead to wrong errors in case the image is not
overwritten and leaves some old state. Use --force parameter.

    [TEST]   fuzz-tests.sh
    [TEST/fuzz]   001-simple-check-unmounted
xz: btrfs-progs/tests/fuzz-tests/images/bko-97021-invalid-chunk-sectorsize.raw: File exists
failed to decompress image btrfs-progs/tests/fuzz-tests/images/bko-97021-invalid-chunk-sectorsize.raw.xz
    [TEST/fuzz]   002-simple-image
xz: btrfs-progs/tests/fuzz-tests/images/bko-97021-invalid-chunk-sectorsize.raw: File exists
failed to decompress image btrfs-progs/tests/fuzz-tests/images/bko-97021-invalid-chunk-sectorsize.raw.xz

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-01 16:47:15 +01:00
David Sterba 464e73ff0d btrfs-progs: tests: add test for seeding device mounts
Test multiple mounts of a single device.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-03-01 16:47:15 +01:00
Boris Burkov feb8f56ba2 btrfs-progs: receive: fix btrfs_mount_root substring bug
The current mount detection code in btrfs receive is not quite perfect.
For example, suppose /tmp is mounted as a tmpfs. In that case,
btrfs receive /tmp2 will find /tmp as the longest mount that matches a
prefix of /tmp2 and blow up because it is not a btrfs filesystem, even
if /tmp2 is just a directory in / mounted as btrfs.

Fix this by replacing the substring check with a dirname recursion to
only check the directories in the path of the dir, rather than every
substring.

Add a new test for this case.

Signed-off-by: Boris Burkov <boris@bur.io>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-02-19 16:29:40 +01:00
Qu Wenruo 5c9a753ba0 btrfs-progs: tests: check the result log for critical warnings
Introduce a new function, check_test_results(), for
misc/fsck/convert/mkfs test cases.

This function is currently to catch warning message for subpage support,
but can be later expanded for other usages.

Signed-off-by: Qu Wenruo <wqu@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 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 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 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
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
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
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 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 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
Qu Wenruo b3417b02aa btrfs-progs: tests: enhance invalid extent item generation test cases
This patch will:

- Add a new test image for fsck/044
  This new image has a corrupted extent item generation for tree block.
  This image can expose a bug in original mode, which can't detect the
  problem.
  This image also utilize the tree block generation detection code,
  which the existing image doesn't.

- Rename the existing image
  To reflect the fact that the existing one is only for data extent.

- Remove the test.sh
  So that the generic path will test both detection and repair.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-12-10 17:10:30 +01:00
David Sterba f1b428ea3b btrfs-progs: tests: add case for send vs subvolume deletion
Subvolumes that are part of send must not be deleted, we can check that
only by the error code EPERM, otherwise it's also in the system log.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-10-02 20:12:08 +02:00
David Sterba 8b4f9546c3 btrfs-progs: tests: add case for deleting default subvolume
Deleting the default subvolume must not succeed and must print a
message to terminal.

Issue: #274
Signed-off-by: David Sterba <dsterba@suse.com>
2020-10-02 20:12:08 +02:00
Boris Burkov 92d92e99b7 btrfs-progs: mkfs: support free space tree as -R option
Add a runtime feature (-R) flag for the free space tree. A filesystem
that is mkfs'd with -R free-space-tree then mounted with no options has
the same contents as one mkfs'd without the option, then mounted with
'-o space_cache=v2'.

The only tricky thing is in exactly how to call the tree creation code.
Using btrfs_create_free_space_tree as is did not quite work, because an
extra reference to the eb (root->commit_root) is leaked, which mkfs
complains about with a warning. I opted to follow how the uuid tree is
created by adding it to the dirty roots list for cleanup by
commit_tree_roots in commit_transaction. As a result,
btrfs_create_free_space_tree no longer exactly matches the version in
the kernel sources.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Boris Burkov <boris@bur.io>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-09-08 22:06:04 +02:00
Qu Wenruo fedc94091f btrfs-progs: tests: add test image to fsck/043 for inode transid repair
The image would contain an inode with invalid transid:

        item 4 key (257 INODE_ITEM 0) itemoff 15881 itemsize 160
                generation 6 transid 134217734 size 131072 nbytes 131072
                block group 0 mode 100600 links 1 uid 0 gid 0 rdev 0

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-31 17:09:55 +02:00
David Sterba abb670f883 btrfs-progs: move ctree.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-31 17:01:05 +02:00
David Sterba 4e49bd703d btrfs-progs: move extent_io.c to kernel-shared/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-31 17:01:04 +02:00
David Sterba cdaf906d68 btrfs-progs: move send-utils.c to common/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-31 17:01:04 +02:00
David Sterba f6009c4cb3 btrfs-progs: move send-stream.c to common/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-31 17:01:04 +02:00
David Sterba a4122790ac btrfs-progs: move extent-cache.c to common/
Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-31 17:01:04 +02:00
David Sterba 33667904dc btrfs-progs: tests: skip cli-tests/014 in travis
The test fails inside travis, check for a multiple-profile detection.
This was verified to work on a proper host so the workaround is in place
let the whole suite pass.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-31 17:01:03 +02:00
Qu Wenruo 1c557766d2 btrfs-progs: tests: add convert test case for multiply overflow
The new test case will test whether btrfs-convert can handle 64G ext*
fs.

This exercise the cctx->total_bytes calculation where multiplying 4K
(unsigned int) and 16777216 (u32) could lead to bit overflow for
unsigned int and got 0, and screw up later free space calculation.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-31 17:01:02 +02:00
David Sterba 7d2abf432d btrfs-progs: tests: fsck/037-freespacetree-repair workaround for missing kernel fix
Kernel patch ff51bf02d107 ("btrfs: block-group: fix free-space bitmap
threshold") is needed to exercise both branches of the test, this can be
detected by lack of the objectid and offset parsed from the dump.

Issue: #288
Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-28 18:30:55 +02:00
David Sterba cd905192b5 btrfs-progs: tests: add helper to print skipped operations
For workarounds or known missing support add helper to print a
notification about that, when _not_run is not suitable.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-08-28 18:30:36 +02:00
David Sterba 56ab36b14a btrfs-progs: tests: rename mkfs/021-rootdir-size to 022
The test got incorrect number by accident, fix it.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-07-21 15:43:23 +02:00
Qu Wenruo 761add2622 btrfs-progs: tests: check that convert does not create extents beyond device boundary
Add a test case to check if the converted fs has device extent beyond
boundary.

The disk layout of source ext4 fs needs some extents to make them
allocated at the very end of the fs.  The script is from the original
reporter.

Also, since the existing convert tests always uses 512M as device size,
which is not suitable for this test case, make it to grab the existing
device size to co-operate with this test case.

Reported-by: Jiachen YANG <farseerfc@gmail.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-29 17:45:39 +02:00
Qu Wenruo 5de63ab1c9 btrfs-progs: mkfs-tests: Add test case to verify the --rootdir size limit
Add a test case to ensure we can create a 350M fs with 128M rootdir.

Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-06-29 17:45:39 +02:00
Qu Wenruo 23bee6a7b5 btrfs-progs: tests: update fsck/035-inline-bad-ram-bytes image
The image used in test case 035 has one problem:

- Bad total_bytes of device item in chunk tree
        item 0 key (DEV_ITEMS DEV_ITEM 1) itemoff 16185 itemsize 98
                devid 1 total_bytes 72564736 bytes_used 92274688
  The total_bytes is even smaller than bytes_used.
  While the dev_item in super block contains the correct value:
    dev_item.total_bytes    134217728
    dev_item.bytes_used     92274688

This patch will update the image, using the correct value in super block
to replace the wrong one in chunk tree.

So that later btrfs-image restore without device/chunk fixup can still
pass fsck-tests.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-29 12:42:49 +02:00
Qu Wenruo 2f8071b6d3 btrfs-progs: tests: update fsck/012-leaf-corruption image
The image used in 012 has several problems:

- Bad dev_item total_bytes in superblock
    dev_item.total_bytes    20918272
    dev_item.bytes_used     67108864

  The fs has 64M chunks allocated, and the original fs is also 64M.
  Thus the total_bytes is completely wrong.

- Bad total_bytes in chunk tree
          item 0 key (DEV_ITEMS DEV_ITEM 1) itemoff 3897 itemsize 98
                devid 1 total_bytes 20918272 bytes_used 67108864
  The same problem as super block.

This problem is covered by btrfs-image, as it will recalculate the
device size.

However if btrfs-image is doing exactly same data replay without any
modification, such bad image would cause test failure, as we're unable
to fix such bad total_bytes.

This patch will update the image to fix such problem.
Also since we're here, there is no need to use custom .tar.gz image, as
we have extra_image() to handle the uncompression.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-29 12:42:49 +02:00
Qu Wenruo 5ba0f70c60 btrfs-progs: tests: add test for quotas and --rootdir
Basic test of mkfs-time enabled quotas and filesystem filled with files.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-29 12:42:48 +02:00
Qu Wenruo 2df82a2da6 btrfs-progs: tests: add test image for overlapping csum item
The image has a csum item overlap with next csum item, make sure btrfs
check can detect it.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-28 19:59:38 +02:00
David Sterba 07e6fa5de9 btrfs-progs: tests: clean loop devices created by tests
Enhance the clean-tests.sh script to detach all loop devices created by
tests, lookup is based on the path prefix. Now 'make test-clean' is
supposed to prepare the environment for next test round.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-05 17:08:20 +02:00
David Sterba 3e6c9bed5c btrfs-progs: adjust multiple block group warning format
Use simpler output format for easier parsing and place each block group
type on a separate line.

Example output:

WARNING: Multiple block group profiles detected, see 'man btrfs(5)'.
WARNING:   Data: single, raid1

Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-04 22:05:43 +02:00
David Sterba 33fc7a13ff btrfs-progs: tests: add coverage for multiple profiles warning
Several commands now warn about multiple profiles as it is considered a
potentially problematic filesystem state that might need user attention.

 - device delete
 - device add
 - balance pause
 - balance cancel
 - filesystem usage

WARNING: Multiple profiles detected.  See 'man btrfs(5)'.
WARNING: data -> [raid1, single]

Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-04 20:49:01 +02:00
David Sterba a7c19b1532 btrfs-progs: tests: enhance README
Add more information about variables, fine tuning, wording, test
templates, etc.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-04 20:49:01 +02:00
Qu Wenruo e445c1c381 btrfs-progs: tests: introduce expand_command() to inject aruguments more accurately
[PROBLEM]
We want to inject $INSTRUMENT (mostly valgrind) before btrfs command but
after root_helper.

Currently we won't inject $INSTRUMENT at all if we are using
root_helper.
This means the coverage is not good enough.

[FIX]
This patch introduce a new function, expand_command(), to handle all
parameter/argument injection, including existing 'btrfs check' inject.

This function will:
- Detect where to inject $INSTRUMENT
  If we have root_helper and the command is target command
  (btrfs/mkfs.btrfs/btrfs-convert), then we inject $INSTRUMENT after
  root_helper.
  If we don't have root_helper, and the command is target command,
  we inject $INSTRUMENT before the command.
  Or we don't inject $INSTRUMENT (it's not the target command).

- Use existing spec facility to inject extra arguments

- Use an array to restore to result
  To avoid bash interpret the IFS inside path/commands.

Now we can make sure no matter if we use root_helper, $INSTRUMENT is
always injected corrected.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-04 20:48:48 +02:00
Qu Wenruo 8c759d5a06 btrfs-progs: tests: filter output for run_check_stdout
Since run_check_stdout() can insert INSTRUMENT for all btrfs related
programs, which could easily pollute the stdout, any caller of
run_check_stdout() should do proper filter.

The following callers are affected:
- misc/004
  Filter the output of "btrfs ins min-dev-size"

- misc/009
- misc/013
- misc/024
  They are all calling "btrfs ins rootid", so introduce get_subvolid()
  function to grab the subvolid properly.

- misc/031
  Loose the filter for "btrfs qgroup show". No need for "tail -n 1".

So we still have the same coverage, but now these tests won't cause
false alert if we insert INSTRUMENT for all btrfs commands.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-04 20:48:42 +02:00
Anand Jain c360199c6c btrfs-progs: tests: drop trailing slash from TEST_TOP path
As the TEST_TOP is often only a base path, the slash gets doubled. This
is not a problem as the slashes are in the middle of the path and cannot
be confused with the initial "//" that gets interpreted as a network
path. Update all the test drivers.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
[ update changelog ]
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-04 20:48:35 +02:00
Marcos Paulo de Souza 2f8aac5375 btrfs-progs: tests: mkfs/018, fix check for truncate command failure
Commit 31f477ee ("btrfs-progs: mkfs-tests: skip test if truncate fails
with EFBIG") tried to detect a failure in truncate command by checking
the $? expecting it to be an errno, when it actually returns 0 or 1.

To fix this test just check if the command failed (returned 1) and look
for the output, skipping the test if the OS cannot create a 6E file.

Fixes: #241
Tested-by: Erhard Furtner <erhard_f@mailbox.org>
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-05-04 20:48:35 +02:00
Adam Borowski 3d379b1341 btrfs-progs: lots of typo fixes (codespell)
Signed-off-by: Adam Borowski <kilobyte@angband.pl>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-31 18:37:38 +02:00
Qu Wenruo e711c843df btrfs-progs: tests/common: Don't call INSTRUMENT on mount command
[BUG]
With INSTRUMENT=valgrind set, some fsck tests will fail, e.g. fsck/013:
  ====== RUN CHECK mount -t btrfs -o loop /home/adam/btrfs/btrfs-progs/tests//test.img /home/adam/btrfs/btrfs-progs/tests//mnt
  ==114106==
  ==114106== Warning: Can't execute setuid/setgid/setcap executable: /usr/bin/mount
  ==114106== Possible workaround: remove --trace-children=yes, if in effect
  ==114106==
  valgrind: /usr/bin/mount: Permission denied
  failed: mount -t btrfs -o loop /home/adam/btrfs/btrfs-progs/tests//test.img /home/adam/btrfs/btrfs-progs/tests//mnt
  test failed for case 013-extent-tree-rebuild

[CAUSE]
Just as stated by valgrind itself, it can't handle program with
setuid/setgid/setcap.

Thankfully in our case it's mount and we don't really care about it at
all.

[FIX]
Although we could use complex skip pattern to skip mount in valgrind, we
don't really want to run valgrind on mount or sudo command anyway.

So here we do extra check if we're running mount command. And if that's
the case, just skip $INSTRUMENT command.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-31 18:37:37 +02:00
David Sterba 1311f1b83a btrfs-progs: misc-tests/039: cleanup test
Cleanups done separately:

* use the default test image, loop devices not needed for the test
* trim TEST_MNT from all paths
* send output is created inside the test filesystem

Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-31 18:37:36 +02:00
Omar Sandoval 25e3e5cb12 btrfs-progs: tests: add test for receiving clone from duplicate subvolume
This test case is the reproducer for the previous fix.

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-31 18:37:36 +02:00
David Sterba f541f59e9a btrfs-progs: tests: check if subvolume delete by id is supported
Skip the test 013-subvolume-delete-by-id if the first valid attempt to
use the ioctl fails with 'Inappropriate ioctl for device'.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-31 18:37:36 +02:00
David Sterba a3b12468c0 btrfs-progs: tests: add run_mayfail_stdout helper
Add a variant of mayfail helper that will duplicate the output to
results log and also provides it to the caller for processing. Can be
used for catching unsupported functionality or other special cases.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-31 18:37:36 +02:00
David Sterba 49fe198218 btrfs-progs: move ioctl-test.c to tests/
Move it out of the top-level directory.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-31 18:37:34 +02:00
David Sterba b147ef8764 btrfs-progs: move library-test.c to tests/
Move it out of the top-level directory.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-31 18:37:34 +02:00
Marcos Paulo de Souza 656e7a839f btrfs-progs: tests: skip tests if dmsetup is not available
Move the check of dmsetup to check_dm_target_support, and adapt the only
two places checking if dmsetup is present in the system. Now we skip the
tests if dmsetup isn't available, instead of marking the test as failed.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-31 18:37:34 +02:00
Marcos Paulo de Souza 47c1630898 btrfs-progs: tests: mkfs/005: check for dm-linear
This way we ensure the linear target is available and skip the test.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-31 18:37:24 +02:00
Marcos Paulo de Souza 1636a6cb36 btrfs-progs: tests: mkfs/017: check dm target support
If dm-thin or dm-linear are not supported, let's skip the test
altogether instead of throwing an error.

Issue: #192
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-20 22:05:28 +01:00
Marcos Paulo de Souza 4e02678c29 btrfs-progs: tests: Add check for dm targets
This function will be used later to test if dm-thin is supported.

Suggested-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-20 22:05:28 +01:00
Su Yue 831b6fb5bd btrfs-progs: misc-tests/034: reload btrfs module before running failure_recovery
One reload_btrfs is lost, add it.

Fixes: 0de2e22ad2 ("btrfs-progs: tests: Add tests for changing fsid feature")
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Su Yue <Damenly_Su@gmx.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-20 22:05:25 +01:00
Marcos Paulo de Souza 640510df83 btrfs-progs: tests: add subvolume delete by id
Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-04 19:21:09 +01:00
Marcos Paulo de Souza 31f477ee20 btrfs-progs: mkfs-tests: skip test if truncate fails with EFBIG
The truncate command can fail in some platforms like PPC32 because it
can't create files up to 6EiB in size. Skip the test if this was the
problem why truncate failed.

Issue: #192
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-03 19:58:55 +01:00
Marcos Paulo de Souza 6ec6c11ba1 btrfs-progs: tests: misc: find-root and select-super are internal commands
Enhance the prerequisite check for internal tools, up to now missing
btrfs-find-root and btrfs-select-super. The correct path in the checks
is INTERNAL_BIN.

The testsuite is now self-contained.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-03 19:58:55 +01:00
Marcos Paulo de Souza 225d66e99b btrfs-progs: Include btrfs-find-root and btrfs-select-super in testsuite
These two binaries are not usually shipped with the package, but they
are used by the testsuite, they need to be included in the exported tar.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-03 19:58:54 +01:00
Marcos Paulo de Souza b20f94e984 btrfs-progs: misc-test: 034: Call "udevmadm settle" before mount
As seem in issue #192, this test can fail from time to time. The
issue happens when a mount is issued before the new device is processed
by systemd-udevd, as we can see by the og bellow:

  [ 2346.028809] BTRFS: device fsid 593e23af-a7e6-4360-b16a-229f415de697 devid 1 transid 6 /dev/loop10 scanned by systemd-udevd (3418)
  [ 2346.265401] BTRFS info (device loop10): found metadata UUID change in progress flag, clearing
  [ 2346.272474] BTRFS info (device loop10): disk space caching is enabled
  [ 2346.277472] BTRFS info (device loop10): has skinny extents
  [ 2346.281840] BTRFS info (device loop10): flagging fs with big metadata feature
  [ 2346.308428] BTRFS error (device loop10): devid 2 uuid cde07de6-db7e-4b34-909e-d3db6e7c0b06 is missing
  [ 2346.315363] BTRFS error (device loop10): failed to read the system array: -2
  [ 2346.329887] BTRFS error (device loop10): open_ctree failed

  failed: mount /dev/loop10 /home/marcos/git/suse/btrfs-progs/tests//mnt
  test failed for case 034-metadata-uuid
  make: *** [Makefile:401: test-misc] Error 1

  [ 2346.666865] BTRFS: device fsid 593e23af-a7e6-4360-b16a-229f415de697 devid 2 transid 5 /dev/loop11 scanned by systemd-udevd (3422)
  [ 2346.853233] BTRFS: device fsid 1c2debeb-e829-4d6b-84df-aa7c5d246fd5 devid 1 transid 7 /dev/loop6 scanned by systemd-udevd (3418)

A few moments after the test failed systemd-udevd processed the new
device (registered the new device under btrfs). This can be tested by
executing a mount after the test failed, resulting in a successful
mount:

  $ mount /dev/loop10 /mnt
  [ 2398.955254] BTRFS info (device loop10): found metadata UUID change in progress flag, clearing
  [ 2398.959416] BTRFS info (device loop10): disk space caching is enabled
  [ 2398.962483] BTRFS info (device loop10): has skinny extents
  [ 2398.965070] BTRFS info (device loop10): flagging fs with big metadata feature
  [ 2399.012617] BTRFS info (device loop10): enabling ssd optimizations
  [ 2399.022375] BTRFS info (device loop10): checking UUID tree

This problem can be avoided is we execute "udevadm settle" before the
mount is executed.

Issue: #192
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Su Yue <Damenly_Su@gmx.com>
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-03 19:58:54 +01:00
Marcos Paulo de Souza da04a62697 btrfs-progs: mkfs-tests: only check supported checksums
Don't hardcode the supported checksums and use the list provided by the
kernel module. The status check of support is moved to the top of the
script so it's more visible.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
[ move checks ]
Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-03 19:58:54 +01:00
Long An bb64c02b90 btrfs-progs: tests: fix path of btrfs-corrupt-block
There are two utilities that are required for the testsuite but not
installed on systems. The path in tests must be INTERNAL_BIN.

Fix this issue for below tests:
 * fsck-tests/013-extent-tree-rebuild
 * fsck-tests/037-freespacetree-repair
 * misc-tests/038-backup-root-corruption

Issue: #198
Signed-off-by: Long An <lan@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-03 19:58:53 +01:00
Nikolay Borisov 82ec6dbd4d btrfs-progs: tests: Extend metadata uuid testcase
This adds cooked images to exercise the case when a filesystem with
metadata uuid incompat flag is switched back to having fsid/metadata
uuid being equal.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-03-03 19:58:53 +01:00
Qu Wenruo d3f7315b3c btrfs-progs: tests: check: detect bad extent item generation
The new image has a bad data extent item generation:

        item 0 key (13631488 EXTENT_ITEM 4096) itemoff 16230 itemsize 53
                refs 1 gen 16384 flags DATA
                extent data backref root FS_TREE objectid 257 offset 0 count 1

Just like what older `btrfs check --init-extent-tree` could cause.

Reviewed-by: Su Yue <Damenly_Su@gmx.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-01-09 14:27:10 +01:00
Su Yue f0c607a137 btrfs-progs: misc-tests/038: fix wrong field filtered under root directory
Ran misc-tests/038 in /root/btrfs-progs:

  make test-misc TEST=038\*
      [TEST]   misc-tests.sh
      [TEST/misc]   038-backup-root-corruption
  ./test.sh: line 33: [: bytenr=65536,: integer expression expected
  Backup slot 2 is not in use
  test failed for case 038-backup-root-corruption
  make: *** [Makefile:401: test-misc] Error 1

It's caused by the wrong line filtered by
$(dump_super | grep root | head -n1 | awk '{print $2}').

The command $(dump-super | grep root) outputs:

  superblock: bytenr=65536, device=/root/btrfs-progs/tests/test.img
  root                    30605312
  chunk_root_generation   5
  root_level              0
  chunk_root              22036480
  chunk_root_level        0
  log_root                0
  log_root_transid        0
  log_root_level          0
  root_dir                6
  backup_roots[4]:

Here
"superblock: bytenr=65536, device=/root/btrfs-progs/tests/test.img" is
selected but not the line "root                    30605312".

Restricting the awk rule can fix it.

Fixes: 78a3831d46 ("btrfs-progs: tests: Test backup root retention logic")
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Su Yue <Damenly_Su@gmx.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-01-09 14:27:10 +01:00
Qu Wenruo 121b9a2e4c btrfs-progs: tests: Add --force for repair command
Since commit e388bf38 ("btrfs-progs: check: warn users about the
possible dangers of --repair") `btrfs check --repair` will wait 10
seconds before really repair the fs.

This hugely slow down the fsck tests. Add --force for check_image()

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-01-09 14:27:09 +01:00
David Sterba 012e51ae6e btrfs-progs: tests: fsck/013: use correct path for btrfs-corrupt-block
All utilities should be found in the $TOP directory, INTERNAL_BIN was
there by accident.

Signed-off-by: David Sterba <dsterba@suse.com>
2020-01-09 14:27:09 +01:00
Long An bbb3d8f6f0 btrfs-progs: tests: mkfs/011: Fix path for rootdir
Documentation folder path is wrong on exported testsutie. Fix this by
replace TOP with INTERNAL_BIN.

Signed-off-by: An Long <lan@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-01-09 14:27:09 +01:00
Marcos Paulo de Souza 4be1b09293 btrfs-progs: tests: mkfs/020: use correct device for mount
It seems to be a typo, since $dev1 was not set, and we are dealing with
TEST_DEV and not with loop devices. As this is now equivalent to the
common mount/umount helpers, use them.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-01-09 14:27:09 +01:00
Marcos Paulo de Souza 8f382bc75e btrfs-progs: tests: mkfs/020: properly set checksum from parameter
The value of checksum was not set making mkfs fail.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-01-09 14:27:09 +01:00
David Sterba 95117cbd4a btrfs-progs: tests: add tests for checksums
Add separate tests for basic coverage of new checksum algorithms. It
comes in two parts to do a full mkfs test and also a condition mount
test.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-22 19:09:51 +01:00
David Sterba b475a46f4d btrfs-progs: tests: add raid1c34 to basic mkfs tests
Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-22 19:09:50 +01:00
Johannes Thumshirn e388bf386b btrfs-progs: check: warn users about the possible dangers of --repair
The manual page of btrfsck clearly states 'btrfs check --repair' is a
dangerous operation.

Although this warning is in place users do not read the manual page
and/or are used to the behaviour of fsck utilities which repair the
filesystem, and thus potentially cause harm.

Similar to 'btrfs balance' without any filters, add a warning and a
countdown, so users can bail out before eventual corrupting the
filesystem more than it already is.

To override the timeout, let --force skip it and continue.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-22 19:07:20 +01:00
David Sterba b9000ce339 btrfs-progs: tests: remove unused variables in common
All the run_* helpers have unused variable cmd, probably a leftover from
debugging the option injection magic.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-22 19:07:16 +01:00
David Sterba 8041a1c229 btrfs-progs: tests: enhance convert option injection
Add support for TEST_ARGS_CONVERT to allow injection of eg. checksum
command for the all tests. Use like

 $ make TEST_ARGS_CONVERT='--csum=xxhash' TEST_ENABLE_OVERRIDE=true test-convert

This affects all btrfs-convert commands that are run by run_check and
other helpers, IOW this affects all tests, not just convert specific ones.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-18 19:21:10 +01:00
David Sterba f24ba8126e btrfs-progs: tests: enhance mkfs option injection
Add support for TEST_ARGS_MKFS to allow injection of eg. checksum
command for the all tests. Use like

 $ make TEST_ARGS_MKFS='--csum=xxhash' TEST_ENABLE_OVERRIDE=true test-mkfs

This affects all mkfs.btrfs commands that are run by run_check and other
helpers, IOW this affects all tests, not just mkfs specific ones.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-18 19:21:09 +01:00
Nikolay Borisov 78a3831d46 btrfs-progs: tests: Test backup root retention logic
This tests ensures that the kernel correctly persists backup roots in
case the filesystem has been mounted from a backup root.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
[ cleanup to use common helpers ]
Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-18 19:21:09 +01:00
Su Yue 011b7e2766 btrfs-progs: mkfs-tests/005: check global prereq for dmsetup
This test uses tool dmsetup so add the global prereq.

Issue: #192
Signed-off-by: Su Yue <Damenly_Su@gmx.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-18 19:21:08 +01:00
Qu Wenruo e56cdab5f1 btrfs-progs: test: tests: Add test image for invalid inode generation repair
The image contains one inode item with invalid generation.  The image
can be crafted by "btrfs-corrupt-block -i 257 -f generation".  It should
emulate the bad inode generation caused by older kernel around 2014.

The image is repairable for both original and lowmem mode.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-18 19:21:07 +01:00
Qu Wenruo 680b5c171f btrfs-progs: tests: Add new images for inode mode repair functionality
Add new test image for imode repair in subvolume trees.

The new test cases including the following cases:

- Regular file with bad imode
  It still has the valid INODE_REF and parent dir has correct DIR_INDEX
  and DIR_ITEM.
  In this case, no matter if the file is empty or not, it should be
  repaired using the info from DIR_INDEX of parent dir.

- Non-empty regular file with bad imode, and without INODE_REF
  The file should be mostly an orphan, so no INODE_REF for imode lookup.
  But it has EXTENT_DATA which should be enough for imode repair.
  The repair also involves moving the orphan to lost+found dir.

- Non-empty dir with bad imode, and without INODE_REF
  Pretty much the same case, but now a directory.
  The repair also involves moving the orphan to lost+found dir.

Also rename the existing test case 039-bad-free-space-cache-inode-mode
to 039-bad-inode-mode, since now we can fix all bad imode.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-18 19:21:07 +01:00
David Sterba 3a73bc1b37 btrfs-progs: move sha256 from tests to crypto/
The SHA256 is going to be used in the future, so this makes it a second
user and we also have the appropriate directory now.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-18 19:20:02 +01:00
Long An c5a202be8f btrfs-progs: testsadd clean-test.sh to testsuite-files
If we generate testsuite tarball by 'make testsuite', there is no
clean-test.sh in it. But some tests need cleanup if a testcase failed.

Signed-off-by: An Long <lan@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-10-14 17:31:11 +02:00
Rosen Penev 5d72055066 btrfs-progs: Fix printf formats
Discovered with cppcheck. Fix signed/unsigned int mismatches, sizeof and
long formats.

Pull-request: #197
Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-10-14 17:31:05 +02:00
Anand Jain 3de68a0e87 btrfs-progs: tests: fix misc/021 when restoring overlapping stale data
As misc-tests/021 image dump is restored on the same original loop
device, this overlaps with the stale data and makes the test pass
falsely.

Fix this by using a new device for restore.

And also, the btrfs-image dump and restore doesn't restore the file
data, so any read on the files should be avoided. So instead of file
data use file stat data for the checksum.

Reported-by: Johannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-10-14 17:28:02 +02:00
Qu Wenruo 7cb441ba56 btrfs-progs: fsck-tests: Add test image for valid half-dropped orphan inode
Btrfs check used to report false alerts on half dropped orphan inodes.
Add test cases to prevent such problem from happening again.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-09-04 16:08:58 +02:00
David Sterba d523a28a15 btrfs-progs: tests: cli/003: add resize checks with 'max'
The 'max' keyword checks were missing. We care about correct parsing,
not necessarily the exact result of the filesystem resize.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-09-04 16:08:46 +02:00
Jeff Mahoney 893934258d btrfs-progs: tests: mkfs and extra large devices
Test case for mkfs to handle if total device size overflows 16EiB. The
device images are created inside temporary btrfs so this works on any
underlying filesystem (unlike NFS or tmpfs).

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
[ split test from original patch and update to work on any filesystem ]
Signed-off-by: David Sterba <dsterba@suse.com>
2019-09-04 16:08:25 +02:00
Qu Wenruo 50d2702e49 btrfs-progs: fsck-tests: Add test case for invalid root generation
The image contains a fs tree whose generation is over 100 larger than
super block generation.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-09-04 16:06:55 +02:00
Vladimir Panteleev f972ef650b btrfs-progs: balance: check for full-balance before background fork
Move the full-balance warning to before the fork, so that the user can
see and react to it.

Notes on test:

- Don't use grep -q, as it causes a SIGPIPE during the countdown, and
  the balance thus doesn't start.

- The "balance cancel" is superfluous as the last command, but it
  provides some idempotence and allows adding more tests below it.

Issue: #168
Signed-off-by: Vladimir Panteleev <git@vladimir.panteleev.md>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-09-04 16:06:42 +02:00
Vladimir Panteleev bbb18c990c btrfs-progs: tests: fix cli-tests/003-fi-resize-args
grep's exit code was never checked (and -o errexit is not in effect),
thus the test was ineffectual and regressed.

Add the missing exit code check, and update the error messages to
make the test pass again.

Signed-off-by: Vladimir Panteleev <git@vladimir.panteleev.md>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-09-04 16:06:40 +02:00
Nikolay Borisov fcebb87f52 btrfs-progs: tests: Check for metadata_uuid feature in misc-tests/034-metadata-uuid
Instead of checking the kernel version, explicitly check for the
presence of metadata_uuid file in sysfs. This allows the test to be run
on older kernels that might have this feature backported.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-09-04 16:06:30 +02:00
David Sterba 4e48f14f8b btrfs-progs: tests: switch messages to _log
The _log helper should be used for test log messages instead of raw echo
to the results file.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-26 17:46:42 +02:00
Qu Wenruo 6f24e7276b btrfs-progs: tests: Avoid debug log populating stdout
When running misc-test/034, we got unexpected log output:
      [TEST/misc]   033-filename-length-limit
      [TEST/misc]   034-metadata-uuid
  Checking btrfstune logic
  Checking dump-super output
  Checking output after fsid change
  Checking for incompat textual representation
  Checking setting fsid back to original
  Testing btrfs-image restore

This is caused by commit 2570cff076 ("btrfs-progs: test: cleanup misc-tests/034")
which uses _log facility which also populates stdout.

Just change _log() to echo "$*" >> "$RESULTS" to fix it.
Unlike the initial commit, there is no other user of _log, so it
shouldn't affect other tests.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-26 17:46:42 +02:00
David Sterba dc6da57e0a btrfs-progs: tests: make test-clean work without built binaries
'make clean' followed by 'make test-clean' will fail due to the sanity
check for 'btrfs' binary. We don't need that for cleaning the test, so
turn the error into a warning.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 15:36:02 +02:00
David Sterba 8dbcf826ca btrfs-progs: tests: request minimum kernel version for misc-tests/034-metadata-uuid
The CI environment has kernel 4.15, the test fails because of the
missing functionality. Skip it.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 15:36:01 +02:00
David Sterba 3a1e12abdc btrfs-progs: tests: add helper to compare kernel versions
Return succcess if runnning kernel >= parameter. Most callers will want
to skip the test.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 15:36:01 +02:00
David Sterba a66d9aa2e3 btrfs-progs: tests: drop keyword function
The shell keyword function is not necessary and not used in many tests,
remove it from the few places that use it right now.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 15:36:01 +02:00
David Sterba 0528d89454 btrfs-progs: tests: common: add shell missing quotes
The loop device helpers lack shell quotes, though not strictly
necessary, add them for consistency.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 15:36:01 +02:00
David Sterba 5d444edcb7 btrfs-progs: tests: use common loop device helpers in misc-tests/021
Signed-off-by: David Sterba <dsterba@suse.com>
2019-07-04 15:36:00 +02:00
David Sterba bd4a386ec5 btrfs-progs: build most common tools into one binary (busybox style)
Build several standalone tools into one binary and switch the function
by name (symlink or hardlink).

* btrfs
* mkfs.btrfs
* btrfs-image
* btrfs-convert
* btrfstune

The static target is also supported. The name of resulting boxed
binaries is btrfs.box and btrfs.box.static . All the binaries can be
built at the same time without prior configuration.

   text    data     bss     dec     hex filename
 822454   27000   19724  869178   d433a btrfs
 927314   28816   20812  976942   ee82e btrfs.box
2067745   58004   44736 2170485  211e75 btrfs.static
2627198   61724   83800 2772722  2a4ef2 btrfs.box.static

File sizes:

  857496  btrfs
  968536  btrfs.box
 2141400  btrfs.static
 2704472  btrfs.box.static

Standalone utilities:

  512504  btrfs-convert
  495960  btrfs-image
  471224  btrfstune
  491864  mkfs.btrfs

 1747720  btrfs-convert.static
 1411416  btrfs-image.static
 1304256  btrfstune.static
 1361696  mkfs.btrfs.static

So the shared 900K binary saves ~2M, or ~5.7M for static build.

Signed-off-by: David Sterba <dsterba@suse.cz>
2019-07-04 15:30:40 +02:00