Commit Graph

448 Commits (master)

Author SHA1 Message Date
David Sterba 485da9d52d btrfs-progs: tests: unmount testing mount point recursively
The test misc-tests/035-receive-common-mount-point-prefix does another
mount inside TEST_MNT but current 'make test-clean' will not properly
undo the nested mount and this will break subsequent tests. The
recursive unmount can handle that.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-05-27 16:08:23 +02:00
David Sterba 936eaf9a36 btrfs-progs: tests: disable misc-tests/035-receive-common-mount-point-prefix
The fix was reverted, skip the test so the testsuite can proceed.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-05-17 13:02:22 +02:00
Qu Wenruo f4be6432c9 btrfs-progs: tests: detecting compressed extent without csum
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-05-17 12:32:38 +02:00
David Sterba 50b9312f3a btrfs-progs: tests: update test number of bad-free-space-cache-inode-mode
There was a duplication, increase the number for patch as they were
merged.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-05-17 12:32:38 +02:00
David Sterba 639d949f9f btrfs-progs: tests: stream dump and max_error counts
The --dump option of receive must also respect the --max-errors
parameter.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-05-17 12:32:38 +02:00
David Sterba 3fe16a10da btrfs-progs: tests: fix misc/026 to run on NFS
The temporary files are not accessible if the testsuite is hosted on
NFS, pre-create them and allow writes.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-05-02 19:14:13 +02:00
Qu Wenruo 2437a88079 btrfs-progs: tests/fsck: Add test image for free space cache mode repair
The image has one free space cache inode with invalid mode (0).
        item 9 key (256 INODE_ITEM 0) itemoff 13702 itemsize 160
                generation 30 transid 30 size 65536 nbytes 1507328
                block group 0 mode 0 links 1 uid 0 gid 0 rdev 0
                sequence 23 flags 0x1b(NODATASUM|NODATACOW|NOCOMPRESS|PREALLOC)
                atime 0.0 (1970-01-01 08:00:00)
                ctime 1553491158.189771625 (2019-03-25 13:19:18)
                mtime 0.0 (1970-01-01 08:00:00)
                otime 0.0 (1970-01-01 08:00:00)

Both lowmem and original mode should be able to detect and fix it.

The extracted test image is pretty big (1G extracted), as kernel won't
cache small chunks.
Even with SSD, such test may still take some seconds just extracting the
image.

Signed-off-by: Qu Wenruo <wqu@suse.com>
2019-04-16 09:04:25 +08:00
Su Yue 84d433d861 btrfs-progs: fsck-test: enable lowmem repair for case 001
Lowmem can repair after commit
       'btrfs-progs: lowmem: move nbytes check before isize check',
so add the beacon file.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
2019-04-16 09:04:25 +08:00
Lu Fengqi 8a3aefc78d btrfs-progs: tests: add case for inode lose one file extent
The missing extent will lead to the existence of the gap between adjacent
extents. The fsck should can detect the gap correctly and repair by punch
a hole.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
2019-04-16 09:04:25 +08:00
David Sterba 2b209f70d0 btrfs-progs: tests: add option coverage for btrfstune
Add tests that exercise all command line options of btrfstune, the valid
and some invalid combinations.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-01-17 01:42:33 +01:00
Filipe Manana ccdd01a404 Btrfs-progs: add test for receive
Add a test for a scenario that used to fail due to find_mount_root()
incorrectly determining the mount point for the receive path due to the
fact that a different mount point with a path that is a prefix of the
receive path exists.

This is fixed by a recent patch titled:

  "Btrfs-progs: fix mount point detection due to partial prefix match"

Reported-by: David Disseldorp <ddiss@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
[ adjustments to make the test work when hosted on NFS ]
Signed-off-by: David Sterba <dsterba@suse.com>
2019-01-15 18:42:14 +01:00
David Sterba 4a654aead4 btrfs-progs: tests: speed up fsck/037 free space tree test
The runtime of the test is over 4 minutes when hosted on NFS, the
fallocate phase takes the most time. As fallocate can't take multiple
arguments, we can't save the overhead by creating the files at once.

Create the files in batches in the background, this improves the runtime
to 2 minutes.

Signed-off-by: David Sterba <dsterba@suse.com>
2019-01-15 18:42:13 +01:00
Qu Wenruo f7f1700b58 btrfs-progs: tests: check: Make 026-bad-dir-item-name verify if btrfs-check can also repair
Just remove the customized 'test.sh', then generic fsck test will do the
check-repair-check.

Signed-off-by: Qu Wenruo <wqu@suse.com>
2019-01-15 18:42:13 +01:00
Qu Wenruo 81275c8bf5 btrfs-progs: tests: Add test image for dev extents beyond device boundary
Now two locations can detect such problem, either by device item
used/total bytes check, or by early dev extents check against device
boundary.

The image is hand-crafted image which uses DATA SINGLE chunk to feed
btrfs check.  As expected, as long as block group item, chunk item,
device used bytes match, older versions check can't detect such problem.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-01-15 18:42:13 +01:00
Nikolay Borisov 0de2e22ad2 btrfs-progs: tests: Add tests for changing fsid feature
Add a bunch of tests exercising the new btrfstune functionality. In
particular check that various restrictions are implemented correctly,
test that btrfs-image works as expected and also test the output of
btrfs inspect-internal dump-super is correct.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-01-15 16:20:09 +01:00
Qu Wenruo 9996feb94d btrfs-progs: misc-tests/021: Do extra btrfs check before mounting
Test case misc/021 is testing if we could mount a single disk btrfs
image recovered from multi disk fs.

The problem is, current kernel has extra check for block group, chunk
and dev extent.  This means no image can pass btrfs check for chunk
tree and the filesystem will not mount.

So do extra btrfs check before mount, this will also help us to locate
the problem in btrfs-image easier.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-12-05 15:47:24 +01:00
Qu Wenruo aedc3389a7 btrfs-progs: fsck-tests: Move reloc tree images to 020-extent-ref-cases
For reloc tree, despite of its short lifespan, it's still the backref,
where reloc tree root backref points back to itself, makes it special.

So it's more approriate to put them into 020-extent-ref-cases.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-12-05 15:46:28 +01:00
Josh Soref 584749488a btrfs-progs: tests: fsck/025, fix typo in helpre name
Generated by https://github.com/jsoref/spelling

Issue: #154
Author: Josh Soref <jsoref@users.noreply.github.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-11-26 17:54:19 +01:00
Josh Soref 0509c05ae6 btrfs-progs: tests: fix typos in test comments
Generated by https://github.com/jsoref/spelling

Issue: #154
Author: Josh Soref <jsoref@users.noreply.github.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-11-26 17:53:43 +01:00
Josh Soref 2e67bf0ed6 btrfs-progs: docs: fix typos in READMEs, INSTALL and CHANGES
Generated by https://github.com/jsoref/spelling

Issue: #154
Author: Josh Soref <jsoref@users.noreply.github.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-11-26 17:47:22 +01:00
Su Yanjun b4843d3669 btrfs-progs: tests: Add the testcase for subvolume name length limit test
Total of three conditions are tested. One for short name, one with
name length 255, the last one with more than 255.

This case should pass after commit
'btrfs-progs: change filename limit to 255 when creating subvolume'.

Signed-off-by: Su Yanjun <suyj.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-10-25 16:11:40 +02:00
David Sterba 9d3303fa1b btrfs-progs: tests: add runtime check for free-space-tree
The CI hosts have old kernel that does not support the FST, make the
test fail gracefully.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-10-25 16:11:40 +02:00
Nikolay Borisov 1cf5833aa6 btrfs-progs: tests: Test for FST corruption detection/repair
Simple test case which preps a filesystem, then corrupts the FST and
finally repairs it. Tests both extent based and bitmap based FSTs.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-10-25 16:11:40 +02:00
Nikolay Borisov 5950bcd121 btrfs-progs: tests: add test for missing device delete error value
Add a test which ensures the kernel returns the correct error value
when missing device removal is requested. This test verifies that kernel
refactoring didn't break the return value.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-10-23 14:48:39 +02:00
David Sterba b3b0c40465 btrfs-progs: tests: renumber last fsck test to 036-rescan-not-kicked-in
The commit d99615284a ("btrfs-progs:
fsck-tests: Add test image to check if btrfs check reports uninitialized
rescan as error") added test 035, should have been 036.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-10-23 14:48:38 +02:00
Qu Wenruo d99615284a btrfs-progs: fsck-tests: Add test image to check if btrfs check reports uninitialized rescan as error
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-08-06 15:06:32 +02:00
Su Yue e6203e6ff9 btrfs-progs: fsck-tests: add test case with keyed data backref with reloc tree blocks
For trees have been balanced, leaves are with flag BTRFS_HEADER_FLAG_RELOC and
extent data backrefs are shared. Like:
=====================
       item 0 key (11927552 EXTENT_ITEM 524288) itemoff 3932 itemsize 63
                refs 129 gen 7 flags DATA
                shared data backref parent 35897344 count 41
                shared data backref parent 35426304 count 37
                shared data backref parent 35422208 count 51
=====================

Then make the leaf which owns the extent data cowed. The shared data
backref was to transferred to keyed data ref, but remaining backrefs are
still shared. Like:
=====================
        item 0 key (11927552 EXTENT_ITEM 524288) itemoff 3887 itemsize 108
                refs 129 gen 7 flags DATA
                extent data backref root 5 objectid 258 offset 0 count 40
                extent data backref root 5 objectid 257 offset 0 count 1
                shared data backref parent 35426304 count 37
                shared data backref parent 35422208 count 51
=====================

However lowmem mode used to iterate the whole inode to find all
references, and doesn't care if a reference is already counted by the
shared tree block.

Add the test case to check it.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-08-06 15:03:16 +02:00
Qu Wenruo d6f5504239 btrfs-progs: test/fuzz: Add image for BUG_ON() when opening the fs by btrfs check
Link: https://bugzilla.kernel.org/show_bug.cgi?id=199839
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-08-06 15:03:11 +02:00
Qu Wenruo 3fcef50906 btrfs-progs: tests/fuzz: Add fuzzed test image for btrfs check BUG_ON
This fuzzed image will not only cause kernel BUG_ON(), but also btrfs
check BUG_ON() for original mode.

Checking filesystem on /home/adam/btrfs/crafted_images/runtime/0.img
UUID: 3381d111-94a3-4ac7-8f39-611bbbdab7e6
checking extents
check/main.c:3677: check_owner_ref: BUG_ON `rec->is_root` triggered, value 1
btrfs(+0x572c2)[0x562d65da72c2]
btrfs(+0x6098d)[0x562d65db098d]
btrfs(+0x60bb6)[0x562d65db0bb6]
btrfs(+0x6179b)[0x562d65db179b]
btrfs(cmd_check+0x1199)[0x562d65db5589]
btrfs(main+0x88)[0x562d65d62768]
/usr/lib/libc.so.6(__libc_start_main+0xeb)[0x7f4fcbb1b06b]
btrfs(_start+0x2a)[0x562d65d6288a]

Link: https://bugzilla.kernel.org/show_bug.cgi?id=200403
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-08-06 15:03:09 +02:00
Qu Wenruo beb3ede39a btrfs-progs: tests/fuzz: Add image for bko-200409
Reported-by: Xu Wen <wen.xu@gatech.edu>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=200409
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-08-06 15:03:02 +02:00
Qu Wenruo 866740418c btrfs-progs: fsck-tests: Add test case for corrupted inline ram_bytes
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-08-06 15:01:16 +02:00
Qu Wenruo 014a0db6cb btrfs-progs: misc-tests: Fix 029 test cases for sudo test environment
Test misc/029 only works if the test case is executed as root, while for
sudo usage, it doesn't work as initial mkdir and final cleanup doesn't
use $SUDO_HELPER.

Add "run_check $SUDO_HELPER" for such cases to allow it works under sudo
usage.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-08-06 14:59:49 +02:00
David Sterba 8aee4b000d btrfs-progs: tests: add fuzzed image that triggers crash in reloc setup on mount
Reported-by: Wen Xu <wen.xu@gatech.edu>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-08-06 14:59:40 +02:00
David Sterba 686dc0864e btrfs-progs: tests: fix fsck-tests/031 when on NFS
The restore target file does not exist and creating by root does not
work on NFS, so precreating will make that work. Also fix the image name
to be deleted.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-06-07 16:37:40 +02:00
Su Yue 6386ae4d8c btrfs-progs: fsck-tests: add test case to check symlinks with bad flags
There are two bad symlinks in the test case.  One is with immutable
attribute.  Another one is with append attribute.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-06-07 16:37:38 +02:00
Su Yue e2eb6dc4d4 btrfs-progs: tests: test mkfs.btrfs fails on small backing size thin provision device
This tests is most similar to xfstests generic/405.
It calls device mapper to create a thin provision device with small
backing size and big virtual size. mkfs.btrfs should fail on such
devices.

This test should pass after commit e805b143a4fe
("btrfs-progs: mkfs: return nozero value on thin provisioned device").

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-06-07 16:37:36 +02:00
Nikolay Borisov e889fd7c11 btrfs-progs: tests: Add test for collision DIR_ITEM handling
Verify that if we have an otherwise clean filesystem, containging
collided DIR_ITEM, btrfs check lowmem's mode can correctly handle those
and not produce any false positives.

This if fixed by commit titled:

 "btrfs-progs: check: fix DIR_ITEM checking in lowmem"

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-06-07 16:37:33 +02:00
Qu Wenruo 7e0ae73fb4 btrfs-progs: tests: Add test case to ensure btrfs check returns error for corrupted qgroups
Since the test case uses run_mustfail(), which is pretty easy pass due to
other unexpected problems, so here an extra run_check() is added to
ensure we don't only report qgroup error, but also fix it without
problem.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-06-07 16:37:33 +02:00
Lu Fengqi f841497b60 btrfs-progs: tests: check btrfs qgroup parent-child relation output
Since commit aaf2dac5ef ("btrfs-progs: qgroup: split update_qgroup to
reduce arguments") cause qgroup show to output the wrong qgroup
parent-child relationship, in addition to fixing the problem, a test case
is needed to prevent the similar problem in the future.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-06-07 16:37:33 +02:00
Qu Wenruo 0ef6797205 btrfs-progs: tests: Add test case for dump-tree on heavily corrupted leaf
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-06-07 16:37:32 +02:00
David Sterba 402ac7a140 btrfs-progs: tests: update log markers
Use visual markers that separate tests and individual commands run via
the run_* helpers.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-06-07 16:37:32 +02:00
Su Yue bd52df0502 btrfs-progs: tests: add image with no extent with normal device size
This new image misses one extent which leads lowmem mode to allocate new
chunks in repair.

Rename original image to no_extent_bad_dev.img.
Because of its bad used bytes, it should let lowmem mode
exclude blocks in repair.

Due to problems of btrfs-image, choose xz as compression tool.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-06-07 16:37:32 +02:00
Qu Wenruo 5f53c23e76 btrfs-progs: tests/fsck: Add test case to check if btrfs check can skip data csum verfication for metadata dump
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-04-24 13:00:11 +02:00
Nikolay Borisov df9158f20d btrfs-progs: Remove deprecated btrfs-zero-log standalone tool
Its function has been subsumed by "btrfs rescue zero-log". Remove its
source file and adjust make/tests soruces accordingly.

Deprecated since 4.0.

Issue: #97
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-04-24 13:00:10 +02:00
Qu Wenruo a4cd4ae0b3 btrfs-progs: tests: Test if btrfs-image can handle RAID1 missing device
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:55 +02:00
Qu Wenruo 3f42d56fcb btrfs-progs: tests: Test if mkfs.btrfs --rootdir can handle ng symlink
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:55 +02:00
David Sterba dcb174ce2e btrfs-progs: tests: add shell quotes to misc test scripts
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:55 +02:00
David Sterba 3ccad2a644 btrfs-progs: tests: add shell quotes to mkfs test scripts
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:55 +02:00
David Sterba a855717a87 btrfs-progs: tests: remove trivial use of local variables
No need to use a temporary variable if the parameter usage is obvious
from the context.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:55 +02:00
David Sterba a1e21ec5a8 btrfs-progs: tests: add shell quoting to fuzz test scripts
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:55 +02:00
David Sterba a7e56ef21b btrfs-progs: tests: convert/014 use shell builtin for generating content
We can remove dependency on perl and use shell builtin go generate
sequence of bytes.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:55 +02:00
David Sterba acd4df7381 btrfs-progs: tests: update README, images, coding style
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:55 +02:00
David Sterba f3219ad42f btrfs-progs: tests: mkfs fills uuid and otime for FS_TREE
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:54 +02:00
David Sterba 82a1442e9c btrfs-progs: tests: don't use fallocate in mkfs/014-rootdir-inline-extent
If fallocate is not supported, this test fails. Use a shell trick to
fill with given number of bytes.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:54 +02:00
Qu Wenruo 7edeb29c34 btrfs-progs: tests: Add testcase for rootdir inline extent size
Add a test case for mkfs --rootdir, using files with different file
sizes to check if invalid large inline extent could exist.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:54 +02:00
Qu Wenruo b79681fe6d btrfs-progs: test/convert: Add test case for invalid large inline data extent
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:54 +02:00
Filipe Manana 7a8d5d5014 Btrfs-progs: add fsck test for filesystem with shared prealloc extents
Verify that a filesystem check operation (fsck) does not report the
following scenario as an error:

An extent is shared between two inodes, as a result of clone/reflink
operation, and for one of the inodes, lets call it inode A, the extent is
referenced through a file extent item as a prealloc extent, while for the
other inode, call it inode B, the extent is referenced through a regular
file extent item, that is, it was written to. The goal of this test is to
make sure a filesystem check operation will not report "odd csum items"
errors for the prealloc extent at inode A, because this scenario is valid
since the extent was written through inode B and therefore it is expected
to have checksum items in the filesystem's checksum btree for that shared
extent.

Such scenario can be created with the following steps for example:

 mkfs.btrfs -f /dev/sdb
 mount /dev/sdb /mnt

 touch /mnt/foo
 xfs_io -c "falloc 0 256K" /mnt/foo
 sync

 xfs_io -c "pwrite -S 0xab 0 256K" /mnt/foo
 touch /mnt/bar
 xfs_io -c "reflink /mnt/foo 0 0 256K" /mnt/bar
 xfs_io -c "fsync" /mnt/bar

 <power fail>
 mount /dev/sdb /mnt
 umount /mnt

This scenario is fixed by the following patch for the filesystem checker:

 "Btrfs-progs: check, fix false error reports for shared prealloc extents"

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:54 +02:00
David Sterba e875cd98e3 btrfs-progs: tests: fix source path for testsuite
The commit cebf3b3722 ("btrfs-progs: introduce TEST_TOP and
INTERNAL_BIN for tests") did not convert all test paths. This would
break the exported testsutie.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:54 +02:00
Qu Wenruo 546cea6f36 btrfs-progs: tests: Add test case with valid orphan inode
Regression test for false alerts in lowmem mode.

Signed-off-by: Qu Wenruo <wqu@suse.com>
[ update test ]
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:54 +02:00
Lu Fengqi 0155481cc9 btrfs-progs: fsck-tests: Introduce test case with keyed data backref with the extent offset
Add the testcase for false alert of data extent backref lost with the
extent offset.

The image can be reproduced by the following commands:
------
dev=~/test.img
mnt=/mnt/btrfs

umount $mnt &> /dev/null
fallocate -l 128M $dev

mkfs.btrfs $dev
mount $dev $mnt

for i in `seq 1 10`; do
	xfs_io -f -c "pwrite 0 2K" $mnt/file$i
done

xfs_io -f -c "falloc 0 64K" $mnt/file11

for i in `seq 1 32`; do
	xfs_io -f -c "reflink $mnt/file11 0 $(($i * 64))K 64K" $mnt/file11
done

xfs_io -f -c "reflink $mnt/file11 32K $((33 * 64))K 32K" $mnt/file11

btrfs subvolume snapshot $mnt $mnt/snap1

umount $mnt
btrfs-image -c9 $dev extent_data_ref.img
------

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-03-30 22:15:53 +02:00
David Sterba 510bb4ccc4 btrfs-progs: tests: add helper to log pipe stdout
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-19 19:24:07 +01:00
David Sterba ea0956bb2a btrfs-progs: tests: add test for send -p on 2 mont points
Add testcase from issue, use reproducer from Axel Burri.

Issue: #96
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-19 19:07:32 +01:00
David Sterba 9aa0c422b8 btrfs-progs: tests: document exported testsuite
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-13 16:22:55 +01:00
David Sterba dbb8c9d19e btrfs-progs: test: update clean-test.sh after the TEST_TOP update
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-13 16:22:55 +01:00
David Sterba e44f595dd7 btrfs-progs: tests: unify test drivers, make ready for extenral testsuite
Make the TOP variable more configurable, allow to set it to any path
where to find binaries when the testsuite is exported, or fallback to
system binaries.

There's now more code duplication, the logic is now more complex so it's
left open coded for clarity. Further cleanups are possible.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-13 16:19:48 +01:00
David Sterba dd11901dae btrfs-progs: tests: update README.md
Irregular proofreading with adjustments and enhancements.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-13 15:41:32 +01:00
Gu Jinxiang cebf3b3722 btrfs-progs: introduce TEST_TOP and INTERNAL_BIN for tests
Use TEST_TOP as base for tests to reference any files, this will be used
for git and external testsuite.

INTERNAL_BIN is needed for referencing binaries that could reside in
different paths in git vs external testsuite.

Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
[ add quotes around sourced files, update changelog ]
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-13 15:41:32 +01:00
David Sterba 04cd2c0bca btrfs-progs: rework testsuite export
Move the testsuite to tests/ and make the tarball generation more
deterministic. As there could be many random temporary files left in the
test directories, we can't just copy them. Use 'git ls-tree' to
filter just what we want, this needs a slight extension of the file list
specification.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-13 15:41:32 +01:00
Gu Jinxiang eb2fe7d1c4 btrfs-progs: Add make testsuite command for export tests
Export the testsuite files to a separate tar.  Since fsck tests depend
on btrfs-corrupt-block, and misc tests depends on both
btrfs-corrupt-block and fssum, so set it as prerequisites for package
commad.

Because, althougth fssum can be generated by source that are all in
tests directory, and has no rely on the btrfs's structure.  But
btrfs-corrupt-block deeply relys on btrfs's structure.  For consistency,
at the present stage, generete the two when create test tar.

Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
[ applied without changes, the generated tarball will be different from
  the one after the follow up commits ]
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-13 15:41:32 +01:00
Su Yue 03401ccd7c btrfs-progs: tests common: remove meaningless colon in extract_image()
The colon is meaningless so remove it.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-07 15:32:08 +01:00
Qu Wenruo c38425344e btrfs-progs: fsck-tests: Cleanup the restored image for 028
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-06 14:33:20 +01:00
Qu Wenruo 53b8ae1436 btrfs-progs: tests: chang tree-reloc-tree test number from 027 to 015
There are 2 fsck tests with the same number 027:
tree-reloc-tree
bad-extent-inline-ref-type

And we also have a hole in 015, so just rename tree-reloc-tree to 015,
to get rid of the duplicated test number and fill in the hole.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-02-02 16:01:57 +01:00
David Sterba 811303eab2 btrfs-progs: tests: fixup mount tests of fsck/028-unaligned-super-dev-sizes
This test was broken because it tried to mount a different image than
what it had repaired.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-31 15:14:03 +01:00
David Sterba 7de5fafc64 btrfs-progs: tests: enhance common umount helper to take optional paths
The run_check_umount_test_dev umounts the TEST_DEV and also optionally
uses the arguments but this would not work as expected if the TEST_DEV
is not a vald path for umount (eg. a restored image).

Update the helper so it tries to umount all paths, or fallback to
TEST_DEV to keep the current behaviour.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-31 15:14:03 +01:00
David Sterba cda595afa3 btrfs-progs: tests: disable some mkfs/010 testcases inside travis
Node sizes larger than 16k will fail due to enospc in the mount test.
This is likely caused by the kernel. Keep the condition only local to
travis so any other testing environment could see the failure
eventually.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-31 15:14:03 +01:00
Rosen Penev e4df433b8a btrfs-progs: treewide: Replace strerror(errno) with %m.
As btrfs is specific to Linux, %m can be used instead of strerror(errno)
in format strings. This has some size reduction benefits for embedded
systems.

glibc, musl, and uclibc-ng all support %m as a modifier to printf.
A quick glance at the BIONIC libc source indicates that it has
support for %m as well. BSDs and Windows do not but I do believe
them to be beyond the scope of btrfs-progs.

Compiled sizes on Ubuntu 16.04:

Before:
3916512 btrfs
233688  libbtrfs.so.0.1
4899    bcp
2367672 btrfs-convert
2208488 btrfs-corrupt-block
13302   btrfs-debugfs
2152160 btrfs-debug-tree
2136024 btrfs-find-root
2287592 btrfs-image
2144600 btrfs-map-logical
2130760 btrfs-select-super
2152608 btrfstune
2131760 btrfs-zero-log
2277752 mkfs.btrfs
9166    show-blocks

After:
3908744 btrfs
233256  libbtrfs.so.0.1
4899    bcp
2366560 btrfs-convert
2207432 btrfs-corrupt-block
13302   btrfs-debugfs
2151104 btrfs-debug-tree
2134968 btrfs-find-root
2281864 btrfs-image
2143536 btrfs-map-logical
2129704 btrfs-select-super
2151552 btrfstune
2130696 btrfs-zero-log
2276272 mkfs.btrfs
9166    show-blocks

Total savings: 23928 (24 kilo)bytes

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-31 15:14:03 +01:00
David Sterba 81dd246d95 btrfs-progs: tests: truncate test image to 0 first
We use the prepare_test_dev helper to make sure the image has at least
this size. The "at least" part is not desired by some tests as the
device might be larger than the test expects.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-31 15:14:02 +01:00
David Sterba 07eafd93b2 btrfs-progs: tests: add more coverage to mkfs-tests/013-reserved-1M-for-single
Though the newly added mkfs profiles should not be affected, let's add
the remaining valid single device profiles for better coverage.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-31 15:14:02 +01:00
Qu Wenruo 510b140955 btrfs-progs: tests: mkfs: don't overwrite first 1M for single
Add test case to check if the first device extent is occupying reserved
0~1M range.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-31 15:14:02 +01:00
Qu Wenruo e0d081b693 btrfs-progs: tests:mkfs/010: Output minimal device size
To make debugging a little easier.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-31 15:14:02 +01:00
David Sterba de802a47e0 btrfs-progs: tests: 029-super-recovery: cleanup the test
Transform the test to the common helpers and don't manage the loop
devices here. The test category changes from check to misc.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-31 15:14:02 +01:00
Nikolay Borisov e764625f90 btrfs-progs: tests: Add test for super block recovery
This functionality regressed some time ago and it was never caught. Seems no
one complained of that, but to be sure add a regression test to prevent future
regressions.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-31 15:14:01 +01:00
Nikolay Borisov 058fad5b92 btrfs-progs: tests: Explictly state test.sh must be executable
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-31 15:14:01 +01:00
David Sterba 6e8571e2df btrfs-progs: tests: fix typo in error message
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-08 19:50:27 +01:00
Qu Wenruo 0ba347f315 btrfs-progs: tests/mkfs: verify that mkfs.btrfs rootdir+shrink behaves correctly
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-08 18:15:22 +01:00
Qu Wenruo 0ca2f5a724 btrfs-progs: tests/mkfs: Introduce test case to check if mkfs rootdir can create a new file
To test regression 460e93f25754 ("btrfs-progs: mkfs: check the status of
file at mkfs").

Signed-off-by: Qu Wenruo <wqu@suse.com>
[ update test to create a out of /tmp ]
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-08 18:15:18 +01:00
Qu Wenruo 5d0783ad14 btrfs-progs: test/mkfs: Test if the minimal device size is valid
New test case to test if the minimal device size given by "mkfs.btrfs"
failure case is valid.

Signed-off-by: Qu Wenruo <wqu@suse.com>
[ renamed script ]
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-08 18:11:35 +01:00
Qu Wenruo 1f36022071 btrfs-progs: tests/convert: ensure btrfs-convert won't rollback the filesystem after balance
Signed-off-by: Qu Wenruo <wqu@suse.com>
[ add shell quotes, rename test ]
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-03 17:29:19 +01:00
Qu Wenruo 2c2db167c7 btrfs-progs: test/common: Enhance prepare_test_dev to reset device size
So prepare_test_dev() can be called several times in one test case, to
test different device sizes.

Signed-off-by: Qu Wenruo <wqu@suse.com>
[ switch to [ ] ]
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-03 17:10:05 +01:00
Qu Wenruo 2bf30fb3b1 btrfs-progs: test/common: Introduce run_mustfail_stdout
For later test case which needs info from stderr.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-03 17:10:03 +01:00
David Sterba c12a6e4dca btrfs-progs: tests: fix typos in test names
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-03 17:09:59 +01:00
David Sterba dc06cda3d6 btrfs-progs: tests: mkfs/008 mkfs with force
With extended tests in the following patch a file based filesystem image
also needs -f, otherwise it will fail.

Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-03 17:09:54 +01:00
Qu Wenruo 37c737d7cb btrfs-progs: test/fsck/021: Cleanup custom check by overriding check_image
Signed-off-by: Qu Wenruo <wqu@suse.com>
[ update comment ]
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-03 17:09:53 +01:00
Qu Wenruo 17538334e1 btrfs-progs: test/fsck/020: Cleanup custom check function by overriding check_image function
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-03 17:09:49 +01:00
Qu Wenruo 4e4c5d3549 btrfs-progs: test/fsck: Introduce test images containing tree reloc tree
Reloc tree is a special tree with very short life span.  It acts as a
special snapshot for any tree, with related nodes/leaves or EXTENT_DATA
modified to point to new position.

Considering the short life span and its special purpose, it should be
quite reasonable to keep them as both corner case for fsck and
educational dump for anyone interested in relocation.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-03 17:09:42 +01:00
Qu Wenruo 263184c7d2 btrfs-progs: fsck-tests: Introduce test case with keyed data backref with shared tree blocks
For snapshot shared tree blocks with source subvolume, the keyed backref
counter only counts the exclusive owned references.

In the following case, 258 is a snapshot of 257, which inherits all the
reference to this data extent.
------
        item 4 key (12582912 EXTENT_ITEM 524288) itemoff 3741 itemsize 140
                refs 179 gen 9 flags DATA
                extent data backref root 257 objectid 258 offset 0 count 49
                extent data backref root 257 objectid 257 offset 0 count 1
                extent data backref root 256 objectid 258 offset 0 count 128
                extent data backref root 256 objectid 257 offset 0 count 1
------

However lowmem mode used to iterate the whole inode to find all
references, and doesn't care if a reference is already counted by the
shared tree block.

Add the test case to check it.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-03 17:09:27 +01:00
Qu Wenruo 95dd77e2d5 btrfs-progs: fsck-test: Add new image with shared block ref only metadata backref
The image is dumped by modifying kernel to sleep long enough before
merging relocation trees, so we can just copy the whole image to other
place before kernel begins to merge reloc trees.

And the base image is created by the following script to bump metadata
size:
------
dev=~/test.img
mnt=/mnt/btrfs

umount $mnt &> /dev/null
fallocate -l 128M $dev

mkfs.btrfs -f -n 4k -m single -d single $dev
mount $dev $mnt -o nospace_cache,max_inline=2048

btrfs subvolume create $mnt/src
for i in $(seq -w 0 128); do
	xfs_io -f -c "pwrite 0 2k" $mnt/src/file_$i > /dev/null
done
for i in $(seq -w 0 64); do
	btrfs subvolume snapshot $mnt/src/ $mnt/snapshot_$i
	touch $mnt/snapshot_$i/new
done
sync
------

The image triggers several corner cases that the old lowmem mode didn't
consider.

Like metadata backref with FULL_BACKREF flag and only SHARED_BLOCK_REF
backrefs for metadata.  And several tree reloc trees with shared
leaves/nodes to confuse old lowmem mode.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-03 17:09:23 +01:00
Qu Wenruo fe23461921 btrfs-progs: fsck-test: Introduce test case for false data extent backref lost
Introduce a new test image, which has an extent item with no inlined
extent data ref, but all keyed extent data ref.

Only in this case we can trigger fase data extent backref lost bug in
lowmem mode.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2018-01-03 17:09:15 +01:00
Lu Fengqi febfb10263 btrfs-progs: test: Add test image for lowmem mode referencer count mismatch false alert
Add a image which can reproduce the extent item referencer count
mismatch false alert for lowmem mode.

Reported-by: Marc MERLIN <marc@merlins.org>
Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-11-14 15:59:01 +01:00
Lu Fengqi 752f42d2c0 btrfs-progs: test: Add test image for lowmem mode file extent interrupt
Add a image that the inlined extent coexist with the regular extent.

Reported-by: Marc MERLIN <marc@merlins.org>
Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2017-11-14 15:59:01 +01:00