Commit Graph

751 Commits

Author SHA1 Message Date
Mark Harmstone 49c1c212f3 btrfs-progs: tests: add image to fsck-tests/065-valid-log-tree with csum already present
Add a test that btrfs check doesn't report an error because of a missing
csum entry in the log tree, if that csum is already in the normal csum
tree. See commit "btrfs-progs: check: check main csum root if csum not
in log tree".

The checksum tree in already-present.img.xz:

checksum tree key (CSUM_TREE ROOT_ITEM 0)
leaf 5390336 items 1 free space 16254 generation 5 owner CSUM_TREE
leaf 5390336 flags 0x1(WRITTEN) backref revision 1
checksum stored ff20c282
checksum calced ff20c282
fs uuid 70d417f0-0173-49ca-bdf1-b789a798974d
chunk uuid b7ec3806-ea09-4f18-a5ef-126a2d79105e
        item 0 key (EXTENT_CSUM EXTENT_CSUM 13631488) itemoff 16279 itemsize 4
                range start 13631488 end 13635584 length 4096

The log tree in already-present.img.xz:

log tree key (TREE_LOG ROOT_ITEM 5)
leaf 5373952 items 3 free space 15981 generation 7 owner TREE_LOG
leaf 5373952 flags 0x1(WRITTEN) backref revision 1
checksum stored 63afa0e5
checksum calced 63afa0e5
fs uuid 70d417f0-0173-49ca-bdf1-b789a798974d
chunk uuid b7ec3806-ea09-4f18-a5ef-126a2d79105e
        item 0 key (257 INODE_ITEM 0) itemoff 16123 itemsize 160
                generation 7 transid 7 size 4096 nbytes 0
                block group 0 mode 100644 links 1 uid 0 gid 0 rdev 0
                sequence 1 flags 0x0(none)
                atime 1721050040.375996658 (2024-07-15 14:27:20)
                ctime 1721050040.375996658 (2024-07-15 14:27:20)
                mtime 1721050040.375996658 (2024-07-15 14:27:20)
                otime 0.2820488960 (1970-01-01 01:00:00)
        item 1 key (257 INODE_REF 256) itemoff 16109 itemsize 14
                index 2 namelen 4 name: file
        item 2 key (257 EXTENT_DATA 0) itemoff 16056 itemsize 53
                generation 7 type 1 (regular)
                extent data disk byte 13631488 nr 4096
                extent data offset 0 nr 4096 ram 4096
                extent compression 0 (none)

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
[ Move the image to 065-valid-log tree ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-11-08 18:34:37 +01:00
Mark Harmstone 5157e072c8 btrfs-progs: tests: add image with compressed extent to fsck-tests/065-valid-log-tree
Add a test that when checking for missing csums in the log tree, btrfs
check considers the compressed rather than uncompressed size of the
extent. See commit "btrfs-progs: check: handle compressed extents when
checking tree log".

The log tree in compressed.img.xz:

log tree key (TREE_LOG ROOT_ITEM 5)
leaf 5373952 items 4 free space 15952 generation 7 owner TREE_LOG
leaf 5373952 flags 0x1(WRITTEN) backref revision 1
checksum stored 61faf6f2
checksum calced 61faf6f2
fs uuid 70d417f0-0173-49ca-bdf1-b789a798974d
chunk uuid b7ec3806-ea09-4f18-a5ef-126a2d79105e
        item 0 key (257 INODE_ITEM 0) itemoff 16123 itemsize 160
                generation 7 transid 7 size 4096 nbytes 0
                block group 0 mode 100644 links 1 uid 0 gid 0 rdev 0
                sequence 1 flags 0x0(none)
                atime 1721050040.375996658 (2024-07-15 14:27:20)
                ctime 1721050040.375996658 (2024-07-15 14:27:20)
                mtime 1721050040.375996658 (2024-07-15 14:27:20)
                otime 0.2820488960 (1970-01-01 01:00:00)
        item 1 key (257 INODE_REF 256) itemoff 16109 itemsize 14
                index 2 namelen 4 name: file
        item 2 key (257 EXTENT_DATA 0) itemoff 16056 itemsize 53
                generation 7 type 1 (regular)
                extent data disk byte 13631488 nr 4096
                extent data offset 0 nr 8192 ram 8192
                extent compression 1 (zlib)
        item 3 key (EXTENT_CSUM EXTENT_CSUM 13631488) itemoff 16052 itemsize 4
                range start 13631488 end 13635584 length 4096

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
[ Move the image to 065-valid-log tree ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-11-08 18:32:37 +01:00
Mark Harmstone 5b40b2dcac btrfs-progs: tests: add image with explicit hole to fsck-tests/065-valid-log-tree
Add a test that 'btrfs check' doesn't flag a file extent in the log tree
as an error because of no corresponding csum entry, if the file extent
is actually an explicit hole. See commit f6dc0e86.

The log tree in hole.img.xz:

log tree key (TREE_LOG ROOT_ITEM 5)
leaf 5373952 items 3 free space 15981 generation 7 owner TREE_LOG
leaf 5373952 flags 0x1(WRITTEN) backref revision 1
checksum stored 091c2f32
checksum calced 091c2f32
fs uuid 70d417f0-0173-49ca-bdf1-b789a798974d
chunk uuid b7ec3806-ea09-4f18-a5ef-126a2d79105e
        item 0 key (257 INODE_ITEM 0) itemoff 16123 itemsize 160
                generation 7 transid 7 size 4096 nbytes 0
                block group 0 mode 100644 links 1 uid 0 gid 0 rdev 0
                sequence 1 flags 0x0(none)
                atime 1721050040.375996658 (2024-07-15 14:27:20)
                ctime 1721050040.375996658 (2024-07-15 14:27:20)
                mtime 1721050040.375996658 (2024-07-15 14:27:20)
                otime 0.2820488960 (1970-01-01 01:00:00)
        item 1 key (257 INODE_REF 256) itemoff 16109 itemsize 14
                index 2 namelen 4 name: file
        item 2 key (257 EXTENT_DATA 0) itemoff 16056 itemsize 53
                generation 7 type 1 (regular)
                extent data disk byte 0 nr 0
                extent data offset 0 nr 4096 ram 4096
                extent compression 0 (none)

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
[ Move the image to 065-valid-log tree ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-11-08 18:31:55 +01:00
Mark Harmstone 5a0dff507f btrfs-progs: tests: also test --subvol modifiers in mkfs-tests/036-rootdir-subvol
Adds tests to mkfs-tests/036-rootdir-subvol for the modifiers to
mkfs.btrfs --subvol: ro, rw, default, and default-ro.

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
2024-11-08 18:25:24 +01:00
Qu Wenruo 27506f8ac8 btrfs-progs: tests: add hardlink related tests for mkfs --subvol
This introduces two new cases:

- 3 hardlinks without any subvolume
  This should results 3 hard links inside the btrfs.

- 3 hardlinks, but a subvolume will split 2 of them
  Then the 2 inside the same subvolume should still report 2 nlinks,
  but the lone one inside the new subvolume can only report 1 nlink.

Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-11-08 17:00:16 +01:00
Mark Harmstone 9b7859bacc btrfs-progs: mkfs: add new option --subvol
Add a new option --subvol, which tells mkfs.btrfs to create the
specified directories as subvolumes when used with --rootdir.

Given a populated directory dir, the command

  $ mkfs.btrfs --rootdir dir --subvol usr --subvol home --subvol home/username img

will create subvolumes 'usr' and 'home' within the toplevel subvolume,
and subvolume 'username' within the 'home' subvolume. It will fail if
any of the directories do not yet exist.

Pull-request: #868
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Mark Harmstone <maharmstone@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-11-08 17:00:05 +01:00
Qu Wenruo 15e9cac275 btrfs-progs: tests: add case to handle deprecated inode cache in check
The inode_cache and involved on-disk formats are deprecated and will
have no effect since v5.11 kernel.

And in v6.11 kernel, new tree-checker will even reject data extents
belonging to those deprecated inode cache.
Lowmem check can detect such deprecated inode cache from the beginning.

This images are generated by 5.10 LTS kernels with inode cache.

Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-09-17 14:33:22 +02:00
Qu Wenruo 073471fa27 btrfs-progs: tests: add case to verify large symbolic link handling in convert
The new test case will:

- Create a symbolic which contains a 4095 bytes sized target on ext4

- Convert the ext4 to btrfs

- Make sure we can still read the symbolic link
  For unpatched btrfs-convert, the resulted symbolic link will be rejected
  by kernel and fail.

Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-09-17 14:33:22 +02:00
Mark Harmstone af55c52c1b btrfs-progs: check: add rudimentary log checking
Currently the transaction log is more or less ignored by btrfs check,
meaning that it's possible for a FS with a corrupt log to pass btrfs
check, but be immediately corrupted by the kernel when it's mounted.

Adds a check that if there's an inode in the log, any pending
non-inlined csumed writes also have corresponding csum entries.

Pull-request: #879
Signed-off-by: Mark Harmstone <maharmstone@fb.com>
[ Small commit message update. ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-09-17 14:33:22 +02:00
David Sterba 8b36a293f7 btrfs-progs: mkfs: print only first warning when --rootdir finds a hardlink
There's a report that newly added --rootdir print too many warnings for
hardlinks, which is maybe not that uncommon. We still want to let the
user know about that so print it just once and count how many were
found:

  $ mkfs.btrfs --rootdir ...
  WARNING: '/tmp/btrfs-progs-mkfs-rootdir-hardlinks.7RcdfR/rootdir/inside_link' has extra hardlinks, they will be converted into new inodes
  WARNING: 12 hardlinks were detected in /tmp/btrfs-progs-mkfs-rootdir-hardlinks.7RcdfR/rootdir, all converted to new inodes

Link: https://github.com/kdave/btrfs-progs/pull/872#issuecomment-2289096125
Signed-off-by: David Sterba <dsterba@suse.com>
2024-08-15 00:02:39 +02:00
ettavolt 28eb473c51 btrfs-progs: receive: cannot find clone source subvol when receiving in reverse direction
process_clone() only searches the received_uuid, but could exist in an
earlier uuid that isn't the received_uuid.  Mirror what process_snapshot
does and search both the received_uuid and if that fails look up by
normal uuid.

Fixes: https://github.com/kdave/btrfs-progs/issues/606

Issue: #606
Pull-request: #643
Pull-request: #862
Signed-off-by: Arsenii Skvortsov <ettavolt@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-08-14 23:59:44 +02:00
David Sterba 03735ff372 libbtrfs: reduce rbtree includes and ship only rbtree_types.h
None of the public API uses the rb-tree code besides definitions, so
change the includes in ctree.h and drop rbtree.h, this is used only by
internal implementation in send-utils.c. We could remove it in the
future but last time it was not possible due to 3rd party code depending
on it.

Removed in 83ab92512e ("libbtrfs: remove the support for fs without
uuid tree") and reverted again in f9b0da8e78 ("Revert "libbtrfs:
remove the support for fs without uuid tree"")

Signed-off-by: David Sterba <dsterba@suse.com>
2024-08-14 23:59:07 +02:00
David Sterba 674b50c719 libbtrfs: use stub for list_head and drop list.h
The list_head is used in struct definitions but otherwise not at all as
it was copied from kernel code. For ctree.h add stub definition that
won't change the containing structure size.

Drop list.h from libbtrfs. This may break some builds if they used the
header, though this was never meant to be exported.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-08-14 23:59:05 +02:00
David Sterba 2f297355c9 libbtrfs: remove unneeded includes from kerncompat.h
Signed-off-by: David Sterba <dsterba@suse.com>
2024-08-14 23:58:53 +02:00
Qu Wenruo cdb9aaaf03 btrfs-progs: tests: verify cross mount point behavior for rootdir
The new test case creates a special layout like this:

rootdir/	(fs1 ino=256)
|- dir1/	(fs1 ino=257)
|  |- dir1/	(fs2 ino=257)
|  |- dir2/	(fs2 ino=258)
|  |- file1	(fs2 ino=259)
|  |- file2	(fs2 ino=260)
|- dir2/	(fs1 ino=258)
|- file1	(fs1 ino=259)
|- file2	(fs2 ino=259)

This layout intentionally creates inode number conflicts, which will
make the old "mkfs.btrfs --rootdir" to fail.
But newer reworked one will successfully handle them, just leave a test
case to avoid to hit the old bugs.

Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-08-14 23:58:38 +02:00
Qu Wenruo aa5469da9c btrfs-progs: tests: a new test case to verify handling of hard links
The test case will create the following directory layout:

.
|- rootdir/
|  |- inside_link
|- outside_link

Both inside_link and outside_link are hard links of each other.
And use rootdir/ as the rootdir for mkfs.

This is to ensure the nlink of inside_link is correctly set to 1.

Inspired by the recent rework which fixes the handling of hard links.

Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-08-14 23:58:34 +02:00
Qu Wenruo c5ee9301c6 btrfs-progs: tests: use feature output from "btrfs --version"
With the new feature description output in "btrfs --version" there is no
need to do the config.h hack to determine if we have certain feature.
This provides a more reliable way to detect features.

Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-07-30 20:01:05 +02:00
Qu Wenruo 6f99038a5f btrfs-progs: tests: add test case to verify convert rollback output
The new new test case is to make sure the rollback output for a fixed
content converted fs contains the string "ext2_saved/image".

As we have a bug in the past where after the string "ext2_saved", we can
have some unterminated garbage.

Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-07-30 19:59:46 +02:00
Qu Wenruo fbdb8dfdee btrfs-progs: tests: add a test case for filename sanitization
This test case checks:

- If a regular btrfs-image dump has the unsanitized filenames
- If a sanitized btrfs-image dump has filenames properly censored

Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-07-30 19:58:43 +02:00
Qu Wenruo 031282b85a btrfs-progs: tests: add a basic resume test using error injection
The new test case does:

- Make sure the build has error injection support
  This is done by checking "btrfs --version" output.

- Inject error at the last commit transaction of new data csum
  generation

- Resume the csum conversion and make sure it works

Signed-off-by: Qu Wenruo <wqu@suse.com>
2024-07-30 19:58:11 +02:00
Yaroslav Halchenko 16a7cbca91 btrfs-progs: run codespell throughout fixing typos automagically
Spell checking can now run in automated mode.

=== Do not change lines below ===
{
 "chain": [],
 "cmd": "codespell -w",
 "exit": 0,
 "extra_inputs": [],
 "inputs": [],
 "outputs": [],
 "pwd": "."
}
^^^ Do not change lines above ^^^

Author: Yaroslav Halchenko <debian@onerussian.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 19:56:08 +02:00
Yaroslav Halchenko 1de113eb0c btrfs-progs: tests: fix filename typo in fsck/052 compex -> complex
Codespell discovered a typo in tests that's actually a bug in filename
that is supposed to be created and written to.

=== Do not change lines below ===
{
 "chain": [],
 "cmd": "git-sedi compex complex",
 "exit": 0,
 "extra_inputs": [],
 "inputs": [],
 "outputs": [],
 "pwd": "."
}
^^^ Do not change lines above ^^^

Pull-request: #846
Author: Yaroslav Halchenko <debian@onerussian.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-07-30 19:53:33 +02:00
Qu Wenruo 4e95d7d028 btrfs-progs: do not check ram_bytes for non-compressed data extents
This patch reverts the following 3 commits:
d0cc40d23a ("btrfs-progs: tests: add test case for ram_bytes detection and repair")
7313573c19 ("btrfs-progs: check: original, detect and repair ram_bytes mismatch")
97bf7a5969 ("btrfs-progs: check: lowmem, detect and repair mismatched ram_bytes")

The problem with the ram_bytes check is, kernel can handle it without
any problem, and the original objective for this is to detect such
problem as I immaturelly believe the problem is fixed.

But it turns out to be incorrect and this check is already causing
problems.

Fix it by doing a full revert for now.

Pull-request: #828
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-25 17:42:17 +02:00
David Sterba 7e13075c3d btrfs-progs: tests: fix fssum ASAN memory leak reports
Free memory after errors in sum(), this is reported by gcc 13 on the CI.

This was reproduced by:

$ make D=asan TEST=019-receive-clones-on-mounted-subvol test-misc

Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-24 19:20:08 +02:00
Qu Wenruo ca9398c406 btrfs-progs: tests: add test case for basic checksum conversion
Test the following:

- Create a btrfs with crc32c csum
- Populate the filesystem
- Convert the filesystem to the following csums:
  * xxhash
  * blake2
  * sha256
  * crc32c

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-24 19:19:35 +02:00
David Sterba 0e7c5a95e7 btrfs-progs: tests: fix shellcheck reports in cli-tests
- variable quoting
- cd error handling
- `` to $()
- command output instead of command (008-subvolume-get-set-default)

Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-24 19:19:26 +02:00
David Sterba 21a858b2ea btrfs-progs: tests: update misc/054 to test escaping of clone and xattrs
Add cases for clone source path and xattr name and value escapin in
receive dump.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-24 19:18:58 +02:00
Qu Wenruo 99de2438ab btrfs-progs: mkfs-tests: ensure regular builds won't enable rst feature
This test case will check the following behviour:

- Regular zoned supported data/metadata profiles
  Should success

- RST with zoned feature
  Should fail for non-experimental builds

- zoned with data profiles that only RST supports
  Should fail for non-experimental builds.

  Meanwhile for experimental builds it should success and enable RST
  feature automatically (verified in mkfs/030)

Pull-request: #813
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-24 19:18:35 +02:00
Qu Wenruo 7ca1e41093 btrfs-progs: tests: hide RST related mkfs tests behind experimental builds
Currently we unconditionally run mkfs/029 and mkfs/030 as we export
RST feature through mkfs.btrfs as supported features.

But considering the mkfs.btrfs features don't match kernel support (only
a BTRFS_DEBUG kernel can support that), we're going to hide RST behind
experimental builds.

In that case RST related tests cases also need to be behind experimental
builds as regular builds of mkfs.btrfs will no longer support RST
feature.

Introduce two helpers:

- _test_config()
  To verify if certain config is set to 1

- check_experimental_build()
  A wrapper of "_test_config EXPERIMENTAL", and skip the test if
  btrfs-progs has no experimental features.

So that test cases can be skipped for non-experimental builds.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-24 19:18:29 +02:00
Qu Wenruo 285d2cbdf9 btrfs-progs: convert: remove raid-stripe-tree support
The raid-stripe-tree (RST) feature is for zoned devices to support extra
data profiles, and is not yet a stable feature (still requires
CONFIG_BTRFS_DEBUG enabled kernel to support it).

Furthermore the supported filesystems (ext*, reiserfs and ntfs) don't
even support zoned devices, and even we force RST support for
btrfs-convert, we would only create an empty tree for RST, as btrfs
convert would only result SINGLE data profile with SINGLE/DUP metadata
profile, neither needs RST at all.

Enabling RST for btrfs-convert would only cause problems for false test
failures as we incorrectly allow RST feature for btrfs-convert.

Fixes the problem by removing raid-stripe-tree support from
btrfs-convert and remove the test cases support for RST.

This patch is mostly reverting commit 346a381923 ("btrfs-progs:
convert: add raid-stripe-tree to allowed features"), but keeps the test
infrastructure to support bgt features for convert.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-24 19:18:25 +02:00
Qu Wenruo 6df00a69e4 btrfs-progs: tests: dump dmesg if a mount fails
[BUG]
There is a random failure for misc/028 in github CI, but unable to
reproduce locally.

[EXTRA DUMP]
The failure is at mount time, which is mostly out of our control (kernel
is provided by the CI image), but at least we can do extra kernel dump
if a mount fails.

This dump is done inside run_check() where if we detects there is a
"mount" word inside the command string.

The detection is not the best, it may detect other commands that
contains the word "mount", but it should be good enough to detect real
mount failure.

Pull-request: #815
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-24 19:18:22 +02:00
Qu Wenruo 6daf3de34b btrfs-progs: tests: always wait for subvolume cleaning before clear-stale
[BUG]
There is a random chance that misc/055 would fail with stale qgroups
detected.

[CAUSE]
Commit 82f7d6c1d7 ("btrfs-progs: qgroup: handle stale qgroup deletion
more accurately") changed the behavior of "btrfs qgroup clear-stale"
that it will no longer try to remove qgroup under deletion.

And the test case itself relies on the return value of "btrfs qgroup
clear-stale" to do the extra wait for subvolume deletion.

This means after that commit, the test case would skip the wait if there
is a subvolume waiting for cleanup, resulting in a race window where the
subvolume can be dropped and become stale, and eventually trigger the
stale qgroup detection and cause false alerts.

[FIX]
Fix the test case by always wait for the subvolume to be dropped, so
that later "btrfs qgroup clear-stale" can properly remove all stale
qgroups.

Pull-request: #814
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-24 19:18:19 +02:00
David Sterba 9d35464a6d btrfs-progs: tests: fix cleanup step in check/037
The test check/037-freespacetree-repair sometimes fails (does not in the
CI though) that the last unmount does not work due to -EBUSY. This
depends on timing, but what is obviously wrong is the 'rm' before
umount. The quoting of "*" does not remove all the files before
fallocate but is otherwise silent due to '-f'.

Add the run_check so it's recorded in the logs taht it happens and alos
add sudo so it can actually work. This makes the test work more
reliably.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-24 19:18:16 +02:00
David Sterba 9957162313 btrfs-progs: tests: update or fix shell script coding style
Fix the following issues in the test suite:

- lack of quoting for variables
- declare function variables local when missing (prevent accidental
  overwrite of global variables)
- for variables with underscore in the name use plain "$VAR_NAME"
  instead of { } (unless necessary)
- minor style adjustments like moving quotes to the end of the same
  string

Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-24 19:18:08 +02:00
Qu Wenruo 76d2a0e5f9 btrfs-progs: tests: do not use async discard for misc/004
[BUG]
There is a long existing failure in my local VM that with any newer
kernel (6.x) the test case misc/004 would fail with ENOSPC during
balance:

    [TEST]   misc-tests.sh
    [TEST/misc]   004-shrink-fs
 failed: /home/adam/btrfs-progs/btrfs balance start -mconvert=single -sconvert=single -f /home/adam/btrfs-progs/tests/mnt
 test failed for case 004-shrink-fs
 make: *** [Makefile:547: test-misc] Error 1

[CAUSE]
With more testing, it turns out that just before the balance, the
filesystem still have several empty data block groups.

The reason is the new default discard=async behavior, as it also changes
the empty block groups to be async, this leave the empty block groups
there, resulting no extra space for the convert balance.

[FIX]
I do not understand why for loop block devices we also enable
discard, but at least disable discard for the test case so that we can
ensure the empty block groups get cleaned up properly.

Pull-request: #809
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-24 19:17:45 +02:00
Qu Wenruo ff1ff014f0 btrfs-progs: tests: in misc/038 test cases
The test case always fails in my VM, with the following error:

  $ sudo TEST=038\* make test-misc
     [TEST]   misc-tests.sh
     [TEST/misc]   038-backup-root-corruption
  Backup 2 not overwritten
  test failed for case 038-backup-root-corruption

After more debugging, it turns out that there is nothing wrong except
the final check:

  [ "$main_root_ptr" -ne "$backup_new_root_ptr" ] || _fail "Backup 2 not overwritten"

The _fail() is only triggered if the previous check returns false, which
is completely the opposite.

Furthermore on the github CI, the kernel commits 2 instead of 1
transaction, resulting the next slot never to match the current
generation/tree root.

The two bugs combined, github CI always passses the test case, while
for my VM which does the expected one transaction, it would always fail.

Fix it by:

- Use a proper "if [] then; fi" block to check the tree root bytenr
- Use the generation diff to calculate the expected backup root slot
- Log the full super block dump for debug usage

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-05 19:51:18 +02:00
David Sterba 3e7cc11ecb btrfs-progs: tests: add missing protection against running out of test suite
Executing the script inside the directories as './test.sh' is not
supposed to work but could happen accidentally. With an exit after
attempting to source the we can fix that. Not all cases have been fixed
in f6bbe06c08 ("btrfs-progs: tests: add protection against running
out of test suite").

Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-03 22:37:53 +02:00
Qu Wenruo 3c35adb2f7 btrfs-progs: tests: add test case for ext4 unwritten extents
The test case verifies behavior of ext4 unwritten extents:

- Create a unwritten (preallocated) extent on ext4

- Fill the on-disk extent with random garbage
  This is to make sure if btrfs tries to read the on-disk data, it would
  definitely get some garbage.
  As I found sometimes mkfs.ext4 can fill the unused bg with zeros.

- Fill the preallocated file range with some data
  This is to make sure btrfs-convert can handle mixed written and
  unwritten ranges.

- Save the checksum of the file.

- Convert the fs

- Verify the checksum
  For older btrfs-convert, there would be only one regular file extent,
  and reading the file would read out some garbage and cause checksum to
  mismatch.

  For the fixed btrfs-convert, we punch holes for unwritten extents,
  thus only the written part would be read out and match the checksum.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-03 22:11:41 +02:00
Naohiro Aota 04e82d4ce7 btrfs-progs: tests: use nullb helpers in mkfs/031-zoned-bgt
Rewrite 031-zoned-bgt with the nullb helpers.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-03 21:32:52 +02:00
Naohiro Aota 9567d26bbf btrfs-progs: tests: use nullb helper and smaller zone size
With the change of minimal number of zones, mkfs-tests/030-zoned-rst now
fails because the loopback device is 2GB and can contain 8x 256MB zones.

Use the nullb helpers to choose a smaller zone size.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-03 21:31:53 +02:00
Naohiro Aota 275497b4f7 btrfs-progs: tests: add mkfs test for zone resetting
Add test for mkfs.btrfs zone reset behavior to check if

- it resets all the zones without "-b" option
- it detects an active zone outside of the FS range
- it do not reset a zone outside of the range

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-03 21:31:12 +02:00
Naohiro Aota f4d4c58853 btrfs-progs: tests: add nullb setup functions
Add functions to setup, create and remove nullb devices.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-03 21:29:54 +02:00
David Sterba 8da61a0585 btrfs-progs: tests: update misc/055 to handle longer subvolume cleaning
After patch "btrfs-progs: qgroup: handle stale qgroup deletion more
accurately" cleaning stale qgroups may not happen if the subvolume
cleaning is still in progress.  Update the test so it's able to handle
that.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-06-03 20:57:02 +02:00
Qu Wenruo d0cc40d23a btrfs-progs: tests: add test case for ram_bytes detection and repair
The new test case would contain a file system image, with the following
file:

	item 4 key (257 INODE_ITEM 0) itemoff 15883 itemsize 160
		generation 7 transid 8 size 16384 nbytes 16384
		block group 0 mode 100600 links 1 uid 0 gid 0 rdev 0
		sequence 258 flags 0x0(none)
		atime 1714635006.328482575 (2024-05-02 17:00:06)
		ctime 1714635013.394980640 (2024-05-02 17:00:13)
		mtime 1714635013.394980640 (2024-05-02 17:00:13)
		otime 1714635006.328482575 (2024-05-02 17:00:06)
	item 5 key (257 INODE_REF 256) itemoff 15869 itemsize 14
		index 2 namelen 4 name: file
	item 6 key (257 EXTENT_DATA 0) itemoff 15816 itemsize 53
		generation 7 type 1 (regular)
		extent data disk byte 13631488 nr 1048576
		extent data offset 0 nr 16384 ram 16384
		extent compression 0 (none)

Note the ram bytes, which should be 1048576.

Furthermore, the inode size is truncated to 16K (originally 1M), so that
offset + num_bytes would still be no larger than ram_bytes.
So the only error is the mismatch between ram_bytes and disk_num_bytes
for the non-compressed data extent.

The image is hand crafted for now, as btrfs-corrupt-block doesn't not yet
support corrupting the ram_bytes field.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-05-03 15:30:37 +02:00
Qu Wenruo 10da73dcd2 btrfs-progs: tests: remove misc/061-subvol-delete-qgroup test case
The test case relies on `--delete-qgroup` option which has been removed.

The feature needs to be implemented in kernel as it's more complex than
just calling an ioctl.  The test case does not take the complexity of
subvolume dropping into consideration and only tested the simplest
cases.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-04-30 21:49:15 +02:00
Qu Wenruo e0b118e093 btrfs-progs: tests: add a test case to check zoned bgt conversion
Add a new test case to make sure:

- btrfstune can convert a zoned btrfs with extent tree to bgt
- btrfstune can convert a zoned btrfs with bgt back to extent tree

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-04-18 19:16:15 +02:00
Qu Wenruo cce3891cbf btrfs-progs: tests: add test case for zoned block group tree feature
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-04-18 19:16:10 +02:00
David Sterba ca68bab8ab btrfs-progs: tests: use unsigned types for bit shifts in fsstress
Bit shifts should be done on unsigned type as a matter of good practice
to avoid any problems with bit overflowing to the sign bit.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-12 22:05:20 +01:00
David Sterba 0f89b1d098 btrfs-progs: tests: verify filesystem show on a raw device mapper path
Signed-off-by: David Sterba <dsterba@suse.com>
2024-01-31 11:07:57 +01:00
David Sterba 74e57d25dc btrfs-progs: tests: renumber 060-subvol-delete-qgroup
There are now two tests with 060, we'd like to be that a unique number,
rename the one that was added more recently.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-01-31 10:16:16 +01:00