Commit graph

6279 commits

Author SHA1 Message Date
David Sterba 958e2fc442 btrfs-progs: docs: note about read-only mount for send
Clarify that read-only mount is not sufficient.

Issue: #493
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:07 +02:00
Guillaume Legrand f68139dbb5 btrfs-progs: README: update links to manual pages
The online manual pages of the btrfs utilities seem to have been moved to
`readthedocs.io`; update references in the README accordingly.

Author: Guillaume Legrand
Pull-request: #500
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:07 +02:00
Torstein Eide 3f8817de7f btrfs-progs: docs: add a section about troubleshooting swapfile
swapon fails with an unclear error message, add some hints were to look
for more information.

Author: Torstein Eide
Pull-request: #491
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:07 +02:00
Solt Budavári fe7aabafdf btrfs-progs: docs: fix typo in subvolume intro
Author: solt87
Pull-request: #513
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:07 +02:00
AtticFinder65536 f70ca45961 btrfs-progs: docs: update reflink cross-mount constraint
Mention the version support for the cross-mount support, since 5.18.

Author: AtticFinder65536
Pull-request: #480
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:07 +02:00
David Sterba feef6aaaf6 btrfs-progs: kernel-lib: remove radix-tree
The radix-tree is not used in userspace code. In kernel it's for
tracking unpersisted and in-memory structures and has been replaced by
the xarray.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:07 +02:00
David Sterba 7b7492d075 btrfs-progs: remove random-test.c
The random-test exercises the b-tree operations but hasn't been in use
for a long time and we won't probably resurrect it. Also it's the only
user of the radix_tree structures, that are otherwise used in the kernel
code, it needs the kerne-lib radix-tree implementation. Let's remove it
as it's basically dead code.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:07 +02:00
David Sterba 94a04f8c9d btrfs-progs: btrfstune: use message helpers for error messages
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:07 +02:00
David Sterba 3f65090ba9 btrfs-progs: select-super: use message helpers for error messages
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:07 +02:00
David Sterba b959a9a16b btrfs-progs: map-logical: use message helpers for error messages
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:07 +02:00
David Sterba 972156289e btrfs-progs: corrupt-block: use message helpers for error messages
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:07 +02:00
David Sterba b610fc1612 btrfs-progs: convert: use message helpers for error messages
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:07 +02:00
David Sterba b19ab3ba9f btrfs-progs: mkfs: use message helpers for error messages
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:07 +02:00
David Sterba 70a2f5520c libbtrfsutil: update include lists
The tool IWYU (include what you use) suggests to remove and add some
includes. Update the includes of implementation files only.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:07 +02:00
David Sterba 4f23f0e711 btrfs-progs: use warning helper for multiple profile messages
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:07 +02:00
David Sterba 0e38e1c4f2 btrfs-progs: use error helper for messages in non-kernel code
Lots of code still uses fprintf(stderr, "...") that should be the
error() helper. The kernel-shared code is left out of the conversion for
now.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:07 +02:00
David Sterba b5aac254c7 btrfs-progs: common: update include lists, part 1
The tool IWYU (include what you use) suggests to remove and add some
includes. This is only partial to avoid accidental build breakage, the
includes are entangled and will have to be cleaned in the future again.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:08:07 +02:00
David Sterba 40c4ba74ec btrfs-progs: cmds: update include lists
The tool IWYU (include what you use) suggests to remove and add some
includes.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:07:59 +02:00
David Sterba dda894259f btrfs-progs: libbtrfs: update include lists
The tool IWYU (include what you use) suggests to remove and add some
includes.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:13 +02:00
David Sterba d04a1fa10e btrfs-progs: factor filesystem helpers out of utils.c
Group helpers that retrieve information from the filesystem out of
utils.c.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:13 +02:00
David Sterba eac3cb577c btrfs-progs: move parse_qgroupid_or_path to parse-utils
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:13 +02:00
David Sterba 6edd4b2121 btrfs-progs: factor string helpers out of utils.c
Utils is the catch-all file, we can now separate some string utility
functions.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:13 +02:00
David Sterba 466e025c74 btrfs-progs: ci: fix image updater script
There's a typo in the way how parameter is passed and is a syntax error
for docker.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:13 +02:00
David Sterba 8d8f8c7f73 btrfs-progs: prepare merging compat feature lists
The features are split to -O and -R but it does not make much sense from
user POV, there are different levels of compatibility but it does not
need to be selected that way. Merge the tables into one but hide it
behind experimental build until the conversion is complete.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:13 +02:00
David Sterba 20496884a9 btrfs-progs: tests: detect send stream version in misc/053
The encoded stream is supported since protocol version 2, detect
support.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:13 +02:00
David Sterba 7d06a7e561 btrfs-progs: tests: use _mktemp_local for temporary files
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:13 +02:00
David Sterba caa57c1689 btrfs-progs: tests: use _mktemp for creating files
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:12 +02:00
David Sterba 500f826f31 btrfs-progs: tests: add helper for creating local temporary file
Some tests don't use the /tmp temporary files and store it locally in
the test directory. To support NFS this needs to be created by a few
commands. To avoid accidental breakage add a convenience helper.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:12 +02:00
David Sterba bd94a00de0 btrfs-progs: check: update include lists
The tool IWYU (include what you use) suggests to remove and add some
includes.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:12 +02:00
David Sterba 0f03da53cc btrfs-progs: mkfs: update include lists
The tool IWYU (include what you use) suggests to remove and add some
includes.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:12 +02:00
David Sterba ec55de0ac5 btrfs-progs: convert: update include lists
The tool IWYU (include what you use) suggests to remove and add some
includes.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:12 +02:00
David Sterba 6d9b3835a6 btrfs-progs: image: update include lists
The tool IWYU (include what you use) suggests to remove and add some
includes.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:12 +02:00
David Sterba 288f8cb78f btrfs-progs: update include list in standalone tools
The tool IWYU (include what you use) suggests to remove and add some
includes.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:12 +02:00
David Sterba 384bc17f63 btrfs-progs: reorder includes in standalone tools
The preferred order:
- system headers
- standard headers
- libraries
- kernel library
- kernel shared
- common headers
- other tools
- own headers

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:12 +02:00
David Sterba b121ac4404 btrfs-progs: fix path to internal libbtrfsutil includes
All files include the <btrfsutil.h> which could be confused with the
system-wide installation. Drop the -I path from build and use full path
for any libbtrfsutil headers.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:12 +02:00
David Sterba 3df6617b9b btrfs-progs: cmds: reorder includes
The preferred order:
- system headers
- standard headers
- libraries
- kernel library
- kernel shared
- common headers
- other tools
- own headers

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:12 +02:00
David Sterba 7ab0c46a81 btrfs-progs: fi usage: fix unallocated and print total and slack
The size reported as Unallocated in the table was different that the one
in the listing, calculated differently. The values should reflect the
unallocated area available for the filesystem - not necessarily the
total size of the device. If there's such slack space it's reported
separately.

The values in the table mean:

- Unallocated: block device size - slack - allocated
- Total:       block device size - slack
- Slack:       block device size - filesystem

The new columns make the table wider but the values are deemed to be
important by users and for filesystems with normal profiles it fits
under reasonable line width. During balance or with multiple profiles it
can get wider but this should not be a serious problem.

Example output:

Overall:
    Device size:                  13.00GiB
    Device allocated:            536.00MiB
    Device unallocated:           12.48GiB
    Device missing:                  0.00B
    Device slack:                  1.00GiB
    Used:                          2.31MiB
    Free (estimated):             12.48GiB      (min: 6.24GiB)
    Free (statfs, df):            12.48GiB
    Data ratio:                       1.00
    Metadata ratio:                   2.00
    Global reserve:                3.50MiB      (used: 0.00B)
    Multiple profiles:                  no

              Data    Metadata  System
Id Path       single  DUP       DUP      Unallocated Total    Slack
-- ---------- ------- --------- -------- ----------- -------- -------
 1 /dev/loop0 8.00MiB 512.00MiB 16.00MiB     2.48GiB  3.00GiB 1.00GiB
 2 /dev/loop1       -         -        -    10.00GiB 10.00GiB       -
-- ---------- ------- --------- -------- ----------- -------- -------
   Total      8.00MiB 256.00MiB  8.00MiB    12.48GiB 13.00GiB 1.00GiB
   Used       2.00MiB 144.00KiB 16.00KiB

Issue: #508
Pull-request: #509 (partial fix)
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:12 +02:00
David Sterba 1c3ab87c92 btrfs-progs: tests: check that receive --dump escapes target paths
Verify that receive --dump escapes paths for rename, symlink and
hardlink when it's the "dest=" value.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:12 +02:00
David Sterba 2f2473248f btrfs-progs: receive: escape target paths for rename, symlink and hardlink
The stream dump escapes the path on which the operation is done but
there are a some that use another path that's the target. A file with
eg. a newline then does not format properly on one line as expected.

Extend the printing helpers to skip printing the newline and then print
the escaped path manually.

Issue: #510
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:12 +02:00
David Sterba 272bff8978 btrfs-progs: common: reorder includes
The preferred order:
- system headers
- standard headers
- libraries
- kernel library
- kernel shared
- common headers
- other tools
- own headers

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:12 +02:00
David Sterba 8802a81eb8 btrfs-progs: check: reorder includes
The preferred order:
- system headers
- standard headers
- libraries
- kernel library
- kernel shared
- common headers
- other tools
- own headers

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:12 +02:00
David Sterba fe7a78f5df btrfs-progs: image: reorder includes
The preferred order:
- system headers
- standard headers
- libraries
- kernel library
- kernel shared
- common headers
- other tools
- own headers

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:11 +02:00
David Sterba be6043ecd2 btrfs-progs: convert: reorder includes
The preferred order:
- system headers
- standard headers
- libraries
- kernel library
- kernel shared
- common headers
- other tools
- own headers

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:11 +02:00
David Sterba 61de520917 btrfs-progs: mkfs: reorder includes
The preferred order:
- system headers
- standard headers
- libraries
- kernel library
- kernel shared
- common headers
- other tools
- own headers

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:11 +02:00
David Sterba c33c2c66b3 btrfs-progs: mkfs: duplicate argument for --rootdir path
The source dir points to the argv data, we should make a copy to be sure
it won't change due to further processing.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:11 +02:00
David Sterba 54fe8e648a btrfs-progs: mkfs: open code label parsing helper
The helper parse_label is used only once and is trivial. Open code it in
the argument parsing, also to make the exit() is more visible.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:11 +02:00
David Sterba 74be9f5115 btrfs-progs: mkfs: open code profile parsing helper
There's a helper to parse profile name and exits on error. As this is a
trivial helper we can open code it and adapt the error message to be
more specific what failed.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:11 +02:00
David Sterba e331037d40 btrfs-progs: factor out and export rotational/ssd device helper
The helper belongs to device utils, move it from the mkfs.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:11 +02:00
Qu Wenruo d476b5bc0c btrfs-progs: corrupt-block: re-generate the checksum for generation corruption
[BUG]
If using btrfs-corrupt-block to corrupt the generation of a tree
block (in my example, it's csum root), it will cause csum mismatch other
than the expected transid mismatch:

 # ./btrfs-corrupt-block --metadata-block 30474240 -f generation \
   /dev/test/scratch1
 # btrfs check /dev/test/scratch1
 Opening filesystem to check...
 checksum verify failed on 30474240 wanted 0xb3e8059a found 0xb4a4b45c
 checksum verify failed on 30474240 wanted 0xb3e8059a found 0xb4a4b45c
 checksum verify failed on 30474240 wanted 0xb3e8059a found 0xb4a4b45c
 Csum didn't match
 ERROR: could not setup csum tree
 ERROR: cannot open file system

[CAUSE]
Inside the switch branch BTRFS_METADATA_BLOCK_GENERATION in
corrupt_metadata_block(), we just set the generation and trigger
write_and_map_eb().

However write_and_map_eb() doesn't re-generate the checksum by itself,
thus we make the victim tree block to have a stale checksum.

[FIX]
Just call csum_tree_block_size() before write_and_map_eb().

Now the corrupted fs have the expected corruption pattern now:

 # btrfs check /dev/test/scratch1
 Opening filesystem to check...
 parent transid verify failed on 30474240 wanted 7 found 11814770867473404344
 parent transid verify failed on 30474240 wanted 7 found 11814770867473404344
 parent transid verify failed on 30474240 wanted 7 found 11814770867473404344
 Ignoring transid failure
 ...

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:11 +02:00
Qu Wenruo d8f3355734 btrfs-progs: unexport csum_tree_block()
The function csum_tree_block() is not really utilized by anyone, all
current callers just use csum_tree_block_size().

Furthermore there is a stale definition in common/utils.h which is using
the old "struct btrfs_root" as the first argument, while we have already
migrated to "struct btrfs_fs_info".

So just unexport csum_tree_block() and remove the stale definition.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-11 09:06:11 +02:00