Commit graph

5720 commits

Author SHA1 Message Date
Qu Wenruo c4ff87c3d1 btrfs-progs: cache csum_size and csum_type in btrfs_fs_info
Just like kernel commit 22b6331d9617 ("btrfs: store precalculated
csum_size in fs_info"), we can cache csum_size and csum_type in
btrfs_fs_info.

Furthermore, there is already a 32 bits hole in btrfs_fs_info, and we
can fit csum_type and csum_size into the hole without increase the size
of btrfs_fs_info.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-11-05 12:50:03 +01:00
Qu Wenruo 636b2e6027 btrfs-progs: remove temporary buffer for super block
There are a lot of call sites where we use the following code snippet:

	u8 super_block_data[BTRFS_SUPER_INFO_SIZE];
	struct btrfs_super_block *sb;
	u64 ret;

	sb = (struct btrfs_super_block *)super_block_data;

The reason for this is, structure btrfs_super_block was smaller than
BTRFS_SUPER_INFO_SIZE.

Thus for anything with csum involved, we have to use a proper 4K buffer.

Since the recent unification of sizeof(struct btrfs_super_block), we no
longer need such workaround, and can use struct btrfs_super_block
directly to do any operation.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-11-05 12:50:03 +01:00
Qu Wenruo 76f1a2ed57 btrfs-progs: unify size of btrfs_super_block and BTRFS_SUPER_INFO_SIZE
Just like kernel change, pad struct btrfs_super_block to 4096 bytes. As
ctree.h is part of public headers, use raw number for the superblock
offset.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-11-05 12:50:03 +01:00
David Sterba c0c307c313 btrfs-progs: fix space_cache generation again when free-space-tree is enabled
In commit a138daac17 ("btrfs-progs: mkfs: set super_cache_generation
to 0 if we're using free space tree") the space cache (v1) generation
was reset to 0 to let kernel know it's not used when the free-space-tree
is enabled.

This got broken again in 5.14 when the free space tree code got
refactored in 4b6cf2a3eb ("btrfs-progs: mkfs: generate free space tree
at make_btrfs() time").

Reset the space cache generation to 0.

Issue: #414
Signed-off-by: David Sterba <dsterba@suse.com>
2021-11-05 12:50:03 +01:00
Wang Yugui e9a7efb1b6 btrfs-progs: fix XX_flags_to_str() to always end with '\0'
[BUG]
We noticed 'btrfs check' outputs something like

  leaf 30408704 flags 0x0(P1逅?) backref revision 1

but we expected:

  leaf 30408704 flags 0x0() backref revision 1

[CAUSE]
Some XX_flags_to_str() failed to make sure the result string always ends
with '\0' in some case.

[FIX]
Reset the buffer at the beginnig.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Wang Yugui (wangyugui@e16-tech.com)
Signed-off-by: David Sterba <dsterba@suse.com>
2021-11-05 12:50:03 +01:00
David Sterba 4882a4f5fa btrfs-porgs: add exception for upper case single profile name
For consistency with older versions switch the case of 'single' to be
lower case again even if it's inconsistent. This could be revisited in
the future.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-11-05 12:50:03 +01:00
Qu Wenruo b1c944657c btrfs-progs: make "btrfs filesystem df" command show upper case profile
[BUG]
Since commit dad03fac3b ("btrfs-progs: switch btrfs_group_profile_str
to use raid table"), fstests/btrfs/023 and btrfs/151 will always fail.

The failure of btrfs/151 explains the reason pretty well:

btrfs/151 1s ... - output mismatch
    --- tests/btrfs/151.out	2019-10-22 15:18:14.068965341 +0800
    +++ ~/xfstests-dev/results//btrfs/151.out.bad	2021-11-02 17:13:43.879999994 +0800
    @@ -1,2 +1,2 @@
     QA output created by 151
    -Data, RAID1
    +Data, raid1
    ...
    (Run 'diff -u ~/xfstests-dev/tests/btrfs/151.out ~/xfstests-dev/results//btrfs/151.out.bad'  to see the entire diff)

[CAUSE]
Commit dad03fac3b ("btrfs-progs: switch btrfs_group_profile_str to use
raid table") will use btrfs_raid_array[index].raid_name, which is all
lower case.

[FIX]
There is no need to bring such output format change.

So here we split the btrfs_raid_attr::raid_name[] into upper_name[] and
lower_name[], and make upper and lower case helpers for callers to use.

Now there are several types of callers referring to lower_name and
upper_name:

- parse_bg_profile()
  It uses strcasecmp(), either case would be fine.

- btrfs_group_profile_str()
  Originally it uses upper case for all profiles except "single".
  Now unified to upper case.

- sprint_profiles()
  It uses lower case.

- bg_flags_to_str()
  It uses upper case.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-11-05 12:50:03 +01:00
Qu Wenruo 5bee5c99bf btrfs-progs: fix printf formats on 32bit x86
When compiling btrfs-progs on 32bit x86 using GCC 11.1.0, there are
several warnings:

  In file included from ./common/utils.h:30,
                   from check/main.c:36:
  check/main.c: In function 'run_next_block':
  ./common/messages.h:42:31: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'u32' {aka 'unsigned int'} [-Wformat=]
     42 |                 __btrfs_error((fmt), ##__VA_ARGS__);                    \
        |                               ^~~~~
  check/main.c:6496:33: note: in expansion of macro 'error'
   6496 |                                 error(
        |                                 ^~~~~

  In file included from ./common/utils.h:30,
                   from kernel-shared/volumes.c:32:
  kernel-shared/volumes.c: In function 'btrfs_check_chunk_valid':
  ./common/messages.h:42:31: warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'u32' {aka 'unsigned int'} [-Wformat=]
     42 |                 __btrfs_error((fmt), ##__VA_ARGS__);                    \
        |                               ^~~~~
  kernel-shared/volumes.c:2052:17: note: in expansion of macro 'error'
   2052 |                 error("invalid chunk item size, have %u expect [%zu, %lu)",
        |                 ^~~~~

  image/main.c: In function 'search_for_chunk_blocks':
  ./common/messages.h:42:31: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'size_t' {aka 'unsigned int'} [-Wformat=]
     42 |                 __btrfs_error((fmt), ##__VA_ARGS__);                    \
        |                               ^~~~~
  image/main.c:2122:33: note: in expansion of macro 'error'
   2122 |                                 error(
        |                                 ^~~~~

There are two types of problems:

- __BTRFS_LEAF_DATA_SIZE()
  This macro has no type definition, making it behaves differently on
  different arches.

  Fix this by following kernel to use inline function to make its return
  value fixed to u32.

- size_t related output
  For x86_64 %lu is OK but not for x86.

  Fix this by using %zu.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-11-05 12:50:03 +01:00
Wang Yugui b1d8f945c9 btrfs-progs: mask out all unwanted profiles in btrfs_group_profile_str
Commit ("btrfs-progs: switch btrfs_group_profile_str to use raid table")
introduced a regression that raid profile of GlobalReserve will be
printed as 'unknown'.

  $ btrfs filesystem df /mnt/test
  Data, single: total=5.02TiB, used=4.98TiB
  System, single: total=4.00MiB, used=624.00KiB
  Metadata, single: total=11.01GiB, used=6.94GiB
  GlobalReserve, unknown: total=512.00MiB, used=0.00B

Fix it by:

- take BTRFS_BLOCK_GROUP_RESERVED into account when masking the block
  group flags
- update the define of BTRFS_BLOCK_GROUP_RESERVED too so it's same as in
  kernel

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Wang Yugui <wangyugui@e16-tech.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-11-05 12:50:03 +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
Qu Wenruo 8f81113021 btrfs-progs: check: fix a lowmem mode crash where fatal error is not properly handled
[BUG]
When a special image (diverted from fsck/012) has its unused slots (slot
number >= nritems) with garbage, lowmem mode btrfs check can crash:

  (gdb) run check --mode=lowmem ~/downloads/good.img.restored
  Starting program: /home/adam/btrfs/btrfs-progs/btrfs check --mode=lowmem ~/downloads/good.img.restored
  ...
  ERROR: root 5 INODE[5044031582654955520] nlink(257228800) not equal to inode_refs(0)
  ERROR: root 5 INODE[5044031582654955520] nbytes 474624 not equal to extent_size 0

  Program received signal SIGSEGV, Segmentation fault.
  0x0000555555639b11 in btrfs_inode_size (eb=0x5555558a7540, s=0x642e6cd1) at ./kernel-shared/ctree.h:1703
  1703	BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
  (gdb) bt
  #0  0x0000555555639b11 in btrfs_inode_size (eb=0x5555558a7540, s=0x642e6cd1) at ./kernel-shared/ctree.h:1703
  #1  0x0000555555641544 in check_inode_item (root=0x5555556c2290, path=0x7fffffffd960) at check/mode-lowmem.c:2628

[CAUSE]
At check_inode_item() we have path->slot[0] at 29, while the tree block
only has 26 items.

This happens because two reasons:

- btrfs_next_item() never reverts its slots
  Even if we failed to read next leaf.

- check_inode_item() doesn't inform the caller that a fatal error
  happened
  In check_inode_item(), if btrfs_next_item() failed, it goes to out
  label, which doesn't really set @err properly.

This means, when check_inode_item() fails at btrfs_next_item(), it will
increase path->slots[0], while it's already beyond current tree block
nritems.

When the slot increases furthermore, and if the unused item slots have
some garbage, we will get invalid btrfs_item_ptr() result, and causing
above segfault.

[FIX]
Fix the problems by two ways:

- Make btrfs_next_item() to revert its path->slots[0] on failure

- Properly detect fatal error from check_inode_item()

By this, we will no longer crash on the crafted image.

Reported-by: Wang Yugui <wangyugui@e16-tech.com>
Issue: #412
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-11-04 20:56:42 +01:00
David Sterba cc8a100c90 btrfs-progs: docs: convert btrfs(5) to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:04 +02:00
David Sterba c52b6d9473 btrfs-progs: docs: convert mkfs.btrfs to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:04 +02:00
David Sterba 2ba78e5ed0 btrfs-progs: docs: convert btrfs(8) to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:04 +02:00
David Sterba 71b1306fda btrfs-progs: docs: convert btrfs-map-logical to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:04 +02:00
David Sterba f03df4f256 btrfs-progs: docs: convert btrfs-subvolume to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:04 +02:00
David Sterba d3e7d66ae4 btrfs-progs: docs: convert btrfs-balance to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:04 +02:00
David Sterba 6b322fd12a btrfs-progs: docs: convert btrfs-check to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:04 +02:00
David Sterba 9111518193 btrfs-progs: docs: convert btrfs-convert to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:04 +02:00
David Sterba 2685136fa1 btrfs-progs: docs: convert btrfs-device to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:04 +02:00
David Sterba 0f6a5c3847 btrfs-progs: docs: convert btrfs-filesystem to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:04 +02:00
David Sterba 48b43e0d3a btrfs-progs: docs: convert btrfs-find-root to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:04 +02:00
David Sterba fb9c88fa93 btrfs-progs: docs: convert btrfs-image to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:04 +02:00
David Sterba 110d2be843 btrfs-progs: docs: convert btrfs-inspect-internal to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:04 +02:00
David Sterba 26a7720748 btrfs-progs: docs: convert btrfs-property to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:03 +02:00
David Sterba 2f947467f6 btrfs-progs: docs: convert btrfs-qgroup to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:03 +02:00
David Sterba 7cd4302a57 btrfs-progs: docs: convert btrfs-quota to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:03 +02:00
David Sterba 964c94fb81 btrfs-progs: docs: convert btrfs-receive to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:03 +02:00
David Sterba 2c7869dc3a btrfs-progs: docs: convert btrfs-replace to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:03 +02:00
David Sterba efaf218a80 btrfs-progs: docs: convert btrfs-rescue to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:03 +02:00
David Sterba 0f4f3b0c72 btrfs-progs: docs: convert btrfs-restore to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:03 +02:00
David Sterba 0360969430 btrfs-progs: docs: convert btrfs-scrub to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:03 +02:00
David Sterba f3b88e6b75 btrfs-progs: docs: convert btrfs-send to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:03 +02:00
David Sterba e508e6707d btrfs-progs: docs: convert fsck.btrfs to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:03 +02:00
David Sterba df04fbceec btrfs-progs: docs: convert btrfstune to rst
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:03 +02:00
David Sterba 4110fbc46f btrfs-progs: docs: add sample RSTified manual page
The asciidoc format needs to be tweaked but otherwise is basically the
same. Changes:

- bold text is ** **
- italics is * *
- NOTE is directive .. note
- definition list is simple indented block after the term
- section NAME in the manual page is generated from date in
  conf.py:man_pages
- new page has to be added to the index

To do:

- references to other manual pages, will be RST native linking once all
  the pages are converted

The output is in Documentation/_build/man and the format is visually not
much different from what is generated by asciidoc.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:03 +02:00
David Sterba 86d3904166 btrfs-progs: docs: add sphinx build support
Add basic config and build files for sphinx. The long term plan is to
convert all asciidoc sources to ReST and host majority of wiki contents,
and maybe more.

Build:

  $ cd Documentation/
  $ make -f Makefile.sphinx html

The result is in Documentation/_build/html.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:30:03 +02:00
David Sterba 17aab2e428 btrfs-progs: receive: add missing unused inode number reads from the stream
Kernel emits inode number for all mkfile/mkdir/... commands but the
receive part does not pass it to the callbacks. At least document that
and read it from the stream in case we'd like to use it in the future.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-29 17:29:57 +02:00
David Sterba 7674317139 btrfs-progs: fi usage: use one formula for chunk size calculation
The profile descriptions allow us to use a single formula to calculate
chunk size. Right now there are no profiles with parity (raid5-like) and
sub_stripes (raid10-like), which makes it easier.

- parity stripes are subtracted from the total count
- then divided by number of sub stripes

Practically speaking, 1:1 copy profiles do not have any adjustments.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:24 +02:00
David Sterba 7d10a07455 btrfs-progs: chunk-recover: use btrfs_bg_type_to_sub_stripes
We should use the raid table value instead of hard coding the value.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:24 +02:00
David Sterba ec6f6c370a libbtrfsutils: update definitions for recently added features
There are missing incompat bits in the util headers:

- metadata_uuid
- raid1c34
- zoned

This does not change library ABI, no version change needed.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:24 +02:00
Qu Wenruo eacdd1606c btrfs-progs: print-tree: fix chunk/block group flags output
[BUG]
Commit ("btrfs-progs: use raid table for profile names in
print-tree.c") introduced one bug in block group and chunk flags output
and changed the behavior:

	item 1 key (FIRST_CHUNK_TREE CHUNK_ITEM 13631488) itemoff 16105 itemsize 80
		length 8388608 owner 2 stripe_len 65536 type SINGLE
		...
	item 2 key (FIRST_CHUNK_TREE CHUNK_ITEM 22020096) itemoff 15993 itemsize 112
		length 8388608 owner 2 stripe_len 65536 type DUP
		...
	item 3 key (FIRST_CHUNK_TREE CHUNK_ITEM 30408704) itemoff 15881 itemsize 112
		length 268435456 owner 2 stripe_len 65536 type DUP
		...

Note that, the flag string only contains the profile (SINGLE/DUP/etc...)
no type (DATA/METADATA/SYSTEM).

And we have new "SINGLE" string, even that profile has no extra bit to
indicate that.

[CAUSE]
The "SINGLE" part is caused by the raid array which has a name for
SINGLE profile, even it doesn't have the corresponding bit.

The missing type string is caused by a code bug:

		strcpy(buf, name);
		while (*tmp) {
			*tmp = toupper(*tmp);
			tmp++;
		}
		strcpy(ret, buf);

The last strcpy() call overrides the existing string in @ret.

[FIX]
- Enhance string handling using strn*()/snprintf()

- Add extra "UKNOWN.0x%llx" output for unknown profiles

- Call proper strncat() to merge type and profile

- Add extra handling for "SINGLE" to keep the old output

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 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 0befc6dce2 btrfs-progs: mkfs: recow all tree blocks properly
[BUG]
Since btrfs-progs v5.14, mkfs.btrfs no longer cleans up the temporary
SINGLE metadata chunks if "-R free-space-tree" is specified:

 $ mkfs.btrfs  -f -R free-space-tree -m dup -d dup /dev/test/test
 $ btrfs ins dump-tree -t chunk /dev/test/test | grep "type METADATA"
		length 8388608 owner 2 stripe_len 65536 type METADATA
		length 268435456 owner 2 stripe_len 65536 type METADATA|DUP

[CAUSE]
Since commit 4b6cf2a3eb ("btrfs-progs: mkfs: generate free space tree
at make_btrfs() time"), free space tree is created when the temporary
btrfs image is created.

This behavior itself has no problem at all.  The problem happens when
"-m DUP -d DUP" (or other profiles) is specified.

This makes btrfs to create extra chunks, enlarging free space tree so
that it can be as high as level 1.

During mkfs, we rely on recow_roots() to re-COW all tree blocks to the
newly allocated chunks.

But __recow_root() can only handle tree root at level 0, as it forces
root node to be COWed, not bothering the children leaves/nodes.

This makes part of the free space cache tree still live on the old
temporary chunks, leaving later cleanup_temp_chunks() unable to delete
temporary SINGLE chunks.

[FIX]
Rework __recow_root() to do a proper COW of the whole tree.

But above rework is not enough, as if a free space tree block is
allocated during current transaction, but before new chunks added.
Then the reworked __recow_root() can't COW it, as btrfs_search_slot()
won't COW a tree block allocated in current transaction.

So this patch will also commit current transaction before calling
recow_roots(), to force us to re-cow all tree blocks.

This shouldn't be a problem, as at the time of calling, we should have
less than a dozen tree blocks, thus there won't be a performance impact.

Reported-by: FireFish5000 <firefish5000@gmail.com>
Fixes: 4b6cf2a3eb ("btrfs-progs: mkfs: generate free space tree at make_btrfs() time")
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 f4c712e024 btrfs-progs: rename data parameter to profile in extent allocation path
In function btrfs_reserve_extent(), we call find_free_extent() passing
"u64 profile" into "int data".

This is definitely a width reduction, but when looking further into the
code, it's more serious than that, in fact the "int data" parameter is
not really to indicate whether it's data extent, but really a block
group profile (with block group type).

This is not only width reduction, but also confusing.

Thankfully so for we don't have any BLOCK_GROUP bits beyond 32 bits, so
the width reduction is not causing a big problem.

This patch will rename the "int data" parameter to a more proper one,
"u64 profile" in all involved call paths.

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 b738de4446 btrfs-progs: use btrfs_bg_type_is_stripey for enumerated lists
The striped profiles covering arbitrary number of devices are often
hardcoded so use the new helper btrfs_bg_type_is_stripey for that.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:24 +02:00