Commit Graph

5705 Commits

Author SHA1 Message Date
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
David Sterba
bc28dc6bea btrfs-progs: introduce helper for striped profiles
There are several profiles like raid0, raid10, raid5 and raid6 that can
span as many devices as possible and need special handling for the
stripe calculations. Provide a helper to identify the profiles in a
simple way.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:24 +02:00
David Sterba
a25a5cc2c0 btrfs-progs: use btrfs_bg_type_to_nparity in btrfs_stripe_length
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:24 +02:00
David Sterba
11fcdbc35e btrfs-progs: introduce helper to get allowed profiles for a given device number
Use the raid table helper to avoid hard coding profiles for the given
number of devices in test_num_disk_vs_raid.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:24 +02:00
David Sterba
86f7cc0ee1 btrfs-progs: fi usage: use btrfs_bg_type_to_sub_stripes in calc_chunk_size
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:24 +02:00
David Sterba
cb0b63cd90 btrfs-progs: use raid table value for sub_stripes in btrfs_check_chunk_valid
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:24 +02:00
David Sterba
4f662d74fd btrfs-progs: export raid table helper for sub_stripes
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:24 +02:00
David Sterba
833ce53872 btrfs-progs: use btrfs_bg_type_to_nparity in calc_stripe_length
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:24 +02:00
David Sterba
e3355b43b4 btrfs-progs: use raid table for min devs in btrfs_check_chunk_valid
Replace the hard coded values with the raid table reference.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:24 +02:00
David Sterba
3d05b20435 btrfs-progs: use btrfs_bg_type_to_nparity in chunk_bytes_by_type
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:23 +02:00
David Sterba
359710d4dd btrfs-progs: use btrfs_bg_type_to_nparity in get_dev_extent_len
Stripe calculation with hard coded parity, use the helper.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:23 +02:00
David Sterba
610a37ed0b btrfs-progs: kernel-lib: simplify raid56_recov
Use raid table helper to find the minimum number of devices instead of
opencoding the values.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:23 +02:00
David Sterba
14d53ce450 btrfs-progs: chunk-recover: use btrfs_bg_type_to_nparity in calc_data_offset
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:23 +02:00
David Sterba
daa08f42c9 btrfs-progs: chunk-recover: use btrfs_bg_type_to_nparity in btrfs_calc_stripe_index
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:23 +02:00
David Sterba
a5d4fff0df btrfs-progs: use btrfs_bg_type_to_nparity in calc_chunk_size
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:23 +02:00
David Sterba
754436f1ea btrfs-progs: use btrfs_bg_type_to_nparity get_raid56_space_info
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:23 +02:00