Commit graph

7068 commits

Author SHA1 Message Date
David Sterba e1e1514a84 btrfs-progs: ci: make box target by default in all images
The 'box' target is not that different from the default one regarding
dependencies so build it as well by default for better coverage.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-04-18 19:16: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
Qu Wenruo 738bb7f0f0 btrfs-progs: tune: properly open zoned devices for RW
[BUG]
There is a report that, for zoned devices btrfstune is unable to convert
it to block group tree.

 # btrfstune /dev/nullb0 --convert-to-block-group-tree
 Error reading 1342193664, -1
 Error reading 1342193664, -1
 ERROR: cannot read chunk root
 ERROR: open ctree failed

[CAUSE]
For read-write opened zoned devices, all the read/write has to be
aligned to its sector size.

However btrfs stores its metadata by extent_buffer::data[], which has
all the structures before it, thus never aligned to zoned device sector
size.

Normally we would require btrfs_pread() and btrfs_pwrite() to do the
extra alignment, but during open_ctree(), we are not aware if a device
is zoned or not.

Thus we rely on if the fd is opened with O_DIRECT flag, if the fd has
O_DIRECT, then we would temporarily set fs_info->zoned for chunk tree
read.

Unforunately not all open_ctree_fd() callers have the flags set
properly, and btrfstune is one of the missing call site.

This makes all the read not properly aligned and cause read failure.

[FIX]
Just manually check if the target device is a zoned one, and set
O_DIRECT accordingly.

Issue: #765
Pull-request: #767
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:00 +02:00
Qu Wenruo 9de25ff2ae btrfs-progs: mkfs: use proper zoned compatible write for bgt feature
[BUG]
There is a bug report that mkfs.btrfs can not specify block-group-tree
feature along with zoned devices:

  # mkfs.btrfs /dev/nullb0 -O block-group-tree,zoned
  btrfs-progs v6.7.1
  See https://btrfs.readthedocs.io for more information.

  Resetting device zones /dev/nullb0 (40 zones) ...
  NOTE: several default settings have changed in version 5.15, please make sure
        this does not affect your deployments:
        - DUP for metadata (-m dup)
        - enabled no-holes (-O no-holes)
        - enabled free-space-tree (-R free-space-tree)

  ERROR: error during mkfs: Invalid argument

[CAUSE]
During mkfs, we need to write all the 7 or 8 tree blocks into the
metadata zone, and since it's zoned device, we need to fulfill all the
requirement for zoned writes, including:

- All writes must be in sequential bytenr
- Buffer must be aligned to sector size

The sequential bytenr requirement is already met by the mkfs design, but
the second requirement on memory alignment is never met for metadata, as
we put the contents of a leaf in extent_buffer::data[], which is after a
lot of small members.

Thus metadata IO buffer would never be aligned to sector size (normally
4K).
And we require btrfs_pwrite() and btrfs_pread() to handle the memory
alignment for us.

However in create_block_group_tree() we didn't use btrfs_pwrite(), but
plain pwrite() call directly, which would lead to -EINVAL error due to
memory alignment problem.

[FIX]
Just call btrfs_pwrite() instead of the plain pwrite() in
create_block_group_tree().

Issue: #765
Pull-request: #767
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:15:43 +02:00
Qu Wenruo b310b231f1 btrfs-progs: tune: add the missing newline for --convert-from-block-group-tree
There is a missing newline for a successful
--convert-from-block-group-tree run, meanwhile
--convert-to-block-group-tree has the correct newline.

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-02 20:49:55 +02:00
David Sterba 3793e987d2
Btrfs progs v6.8
Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-26 15:18:02 +01:00
David Sterba e3d46ed9d5 btrfs-progs: update CHANGES for 6.8
Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-26 15:17:19 +01:00
David Sterba 5cfa61d6e8 btrfs-progs: docs: update memory related problems
Inspired by https://www.reddit.com/r/btrfs/comments/1bkdewb/btrfs_errors_in_dmesg/ .

[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-25 23:33:25 +01:00
David Sterba 2c99d8078f btrfs-progs: prop set: enhance error message when changing subvolume from ro->rw
The error message for ro->rw is not clear enough, add more context for
the received_uuid and send and point to the manual page that explains
more.

Asked at:
https://www.reddit.com/r/btrfs/comments/1bkqor2/received_uuid_error_after_btrfs_send/

[ci skip]

Issue: #763
Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-25 23:13:46 +01:00
HAN Yuwei f240b9f6d0 btrfs-progs: docs: fix incorrect description about compression with O_DIRECT
It was reported in https://lore.kernel.org/linux-btrfs/e7ce9995-93cb-4904-875c-684d4494765f@web.de/
that compression does not happen on direct io files. This is incorrectly
documented that it works but this is not true. Compression works on
buffered writes and relies on page cache, while direct io avoids that
and takes a different path in code.

[ci skip]

Pull-request: #764
Author: HAN Yuwei <hrx@bupt.moe>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-25 22:57:50 +01:00
Thomas Bertels 41dce59a0f btrfs-progs: docs: fix typo in ch-hardware-considerations
verity -> verify

[ci skip]

Pull-request: #759
Author: Thomas Bertels <3265870+tbertels@users.noreply.github.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-25 22:50:41 +01:00
David Sterba 3172d27fb9 btrfs-progs: mkfs: make transaction start and commit errors verbose
Use the templated error message for transaction failures, use the same
pattern assigning the ret and errno.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-22 01:19:47 +01:00
Boris Burkov 682f676eb3 btrfs-progs: enable send v3 correctly (use EXPERIMENTAL instead of CONFIG_BTRFS_DEBUG)
The send v3 protocol is enabled in kernel by a different config option
than in btrfs-progs to actually work. Now v3 can be tested when
configured and built with --enable-experimental.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Boris Burkov <boris@bur.io>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-18 23:19:52 +01:00
David Sterba 640c4cc3f4 btrfs-progs: check: make all transaction start failures verbose
Use the templated error message for transaction start failures, use the
same pattern assigning the ret and errno.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-16 23:14:02 +01:00
David Sterba f127a1b440 btrfs-progs: check: handle errors in leave_shared_node()
Turn all BUG_ONs to error handling and push it to the caller. The error
conditions are almost certainly corruptions so we can't do anything
about that.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-16 23:14:02 +01:00
David Sterba c9eb2c055a btrfs-progs: check: handle errors in enter_shared_node()
The error values of enter_shared_node() are mixing int and bool, unify
that to be 1 == true, 0 == false, <0 errors. Update callers to handle
errors.

Inline the add_shared_node() helper as it's trivial and makes handling
errors easier. As all errors can be now returned, do proper error
handling instead of all remaining BUG_ONs.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-16 23:14:02 +01:00
David Sterba 672d943e66 btrfs-progs: check: handle errors in splice_shared_node() and push the rest to the callers
Handle the BUG_ONs inside splice_shared_node() and move them to the
callers. As there's a big loop and external tree cache updated there's
not error cleanup done.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-16 23:14:02 +01:00
David Sterba e17038ea9f btrfs-progs: check: handle errors in add_inode_backref() and push the rest to callers
Handle the two BUG_ONs inside add_inode_backref() and move them to the
callers.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-16 23:14:02 +01:00
David Sterba 8591711afb btrfs-progs: check: free memory on failure in get_inode_rec()
Free the newly allocated structures when 'mod' is requests and insertion
fails. All exit paths from the function now don't leave anything to
clean up.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-16 23:14:02 +01:00
David Sterba 054b314fbe btrfs-progs: print error when zeroing device fails in device_zero_blocks()
Use the template to be verbose about device zeroing failure, this can be
called repeatedly.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-16 22:25:50 +01:00
David Sterba 060f7d6c81 btrfs-progs: handle write errors in btrfs_add_to_fsid()
Add template for read/write error messages and use it for write of
superblock when adding a device. sbwrite() is wrapper around write that
makes sure the zoned devices are accessed correctly.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-16 22:25:50 +01:00
David Sterba f3ece218b6 btrfs-progs: unify tree search header access
Use a local copy of the search header for proper aligned access instead
of the unaligned helpers, move the definitions to the closest scope.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-16 18:15:51 +01:00
David Sterba 005aeb8cb0 btrfs-progs: use TREE_SEARCH ioctl wrappers for all non-library code
Use tree search ioctl wrappers for code that is considered internal, ie.
leaving out libbtrfs (legacy), libbtrfsutil (needs own API for that).

Conversion is mostly direct of what the API provides.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-16 18:15:51 +01:00
David Sterba d73e698248 btrfs-progs: temporarily disable usage of v2 of search tree ioctl
For unclear reasons using the v2 ioctl leads to an infinite loop in
'btrfs fi usage' in load_chunk_info() when there's only one valid item
returned and then it keeps looping. Can be reproduced by mkfs-tests/001.

After debugging, from second item in the buffer there's all zeros, while
it's returned nr_items=4. Switching the same code to use v1 makes it
work again. It's puzzling as it's the same code in kernel.

We want to make the switch eventually so only disable the detection so
other code can use the new API.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-16 18:13:04 +01:00
David Sterba a223764093 btrfs-progs: add API for selecting tree search support and ioctl
Add wrappers around v1 and v2 of TREE_SEARCH ioctl so it can be
transparently used by code. The structures partially overlap but due to
the buffer size the v2 is offset and also needs a filler to expand the
flexible buffer.

Usage:

- define struct btrfs_tree_search_args, all zeros
- btrfs_tree_search_sk() reads offset of the search key within the
  structures
- btrfs_tree_search_ioctl() detect support and call the highest
  supported ioctl version, v2 has been supported since 3.14 but we want
  to keep backward compatibility
- btrfs_tree_search_data() read data from the buffer previously filled
  by ioctl, a sequence of (search header, data)

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-16 18:08:38 +01:00
David Sterba 4ab1159db0 btrfs-progs: chunk-recover: proper error handling for cache insertions
Replace BUG_ONs with proper error handling.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-15 01:53:32 +01:00
David Sterba 949eb7599b btrfs-progs: handle internal errors in btrfs_assert_feature_buf_size()
The buffer size check is needed and has already caught problems when
adding the raid-stripe-tree, do a better error reporting.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-15 01:53:32 +01:00
David Sterba dbc7d6aa19 btrfs-progs: handle transaction start failure in set_label_unmounted()
Do proper error handling and use the template error message when setting
the label fails.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-15 01:53:25 +01:00
David Sterba 3b560a6649 btrfs-progs: handle range overlaps in extent-tree-utils.c
Add new error message template and use it to report invalid range
overlaps and do proper error handling.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-15 00:16:32 +01:00
David Sterba bb12921b8a btrfs-progs: handle btfs_del_items() failure in truncate_free_ino_items()
Do proper error handling like in the rest of the function.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-15 00:07:40 +01:00
David Sterba 76c49eb686 btrfs-progs: use unsigned types for bit shifts in configure.ac and docs
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:49 +01: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 2edd439617 btrfs-progs: use unsigned types for bit shifts
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:09 +01:00
David Sterba 85ea79f6b2 libbtrfsutil: use unsigned types for bit shifts
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:04:09 +01:00
David Sterba a0ff3f19af libbtrfs: use unsigned types for bit shifts
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:03:36 +01:00
David Sterba 1c551e22cf btrfs-progs: make all parameters of rb_tree search/insert const
Tree comparators never change parameters, make them all const and also
change the rb-tree prototypes.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-12 21:43:54 +01:00
David Sterba a80d717db2 btrfs-progs: minor source sync with kernel 6.8
Sync a few more file on the source level with kernel 6.8.

- type cleanups
- defines and enums
- comments
- parameter updates
- error handling

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-12 21:22:56 +01:00
David Sterba 60cc6f3fd8 btrfs-progs: docs: add kernel 6.8 changelog
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-11 21:45:31 +01:00
David Sterba 709aeedbc3 btrfs-progs: docs: add 6.8 kernel development statistics
[ci skip]

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-11 21:30:54 +01:00
Termuellinator 4a1133cb60 btrfs-progs: docs: correct systemd-run argument for limiting bandwith
There's an error in resource control command name, the argument is
IOReadBandwidthMax instead of IOBandwidthReadMax.  See
https://www.freedesktop.org/software/systemd/man/latest/systemd.resource-control.html

[ci skip]

Pull-request: #744
Author: Termuellinator <saldorin@web.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-06 20:57:09 +01:00
David Sterba 126049c312 libbtrfsutil: update definitions in btrfs.h
Sync structures definitions and constants from kernel source.

- update btrfs_ioctl_fs_info_args
- update btrfs_ioctl_send_args
- verity, block-group-tree, raid-stripe-tree, simple quota
- ioctl definition updates
- copy comments
- diff minimization (whitespace changes, moved definitions)

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-06 20:53:44 +01:00
David Sterba 30bc34d333 libbtrfsutil: update definitions in btrfs_tree.h
Copy what's in kernel header, new structures and constants.

- raid-stripe-tree
- verity
- simple quota

Deleted:
- btrfs_extent_ref_v0 (obsolete, kernel support removed)

Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-06 20:41:04 +01:00
David Sterba 27e965f538 libbtrfsutil: add aliases for new naming scheme, version 1.3
The initial version of libbtrfsutil did not follow a unified naming
scheme that's usually used for libraries like those provide by
util-linux. Add aliases that are "btrfs_util_" + object + action +
suffix.

The library version changes to 1.3 but there's no new functionality,
only the aliases added. New functions can be added in the future without
possible confusion when the same action could apply to different
objects.

Issue: #574
Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-06 20:24:16 +01:00
Qu Wenruo 5f87b467a9 btrfs-progs: subvolume: output the prompt line only when the ioctl succeeded
[BUG]
With the latest kernel patch to reject invalid qgroupids in
btrfs_qgroup_inherit structure, "btrfs subvolume create" or "btrfs
subvolume snapshot" can lead to the following output:

 # mkfs.btrfs -O quota -f $dev
 # mount $dev $mnt
 # btrfs subvolume create -i 2/0 $mnt/subv1
 Create subvolume '/mnt/btrfs/subv1'
 ERROR: cannot create subvolume: No such file or directory

The "btrfs subvolume" command output the first line, seemingly to
indicate a successful subvolume creation, then followed by an error
message.

This can be a little confusing on whether if the subvolume is created or
not.

[FIX]
Fix the output by only outputting the regular line if the ioctl
succeeded.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-04 22:55:07 +01:00
Qu Wenruo 4da5f22b23 btrfs-progs: qgroups: remove support for num_ref_copies/num_excl_copies
Remove btrfs_qgroup_inherit_add_copy() and the command line interface.

This was designed to add a pair of source/destination qgroups into
btrfs_qgroup_inherit structure, so that rfer/excl numbers would be
copied from the source qgroup into the destination one.

This behavior has been intentionally hidden since 2016, as such copy will
cause qgroup inconsistent immediately and a rescan would reset whatever
numbers copied anyway.

Now we're going to reject the copy behavior from kernel, there is no
need to keep those hidden (and already disabled for "subvolume create")
case.

Remove btrfs_qgroup_inherit_add_copy() call, and cleanup the
undocumented options.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-03-04 22:55:07 +01:00
Martin aba8adabcc btrfs-progs: docs/conf.py: enable navigation_with_keys on RTD
Feature from https://github.com/sphinx-doc/sphinx/pull/2064 enable
navigation to be able to navigate documentation using the arrow keys.

Pull-request: #754
Author: Martin <spleefer90@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-02-29 12:46:55 +01:00
David Sterba 3c8200302b btrfs-progs: rename btrfs_open_fd2() to btrfs_open_path()
Use a more descriptive name, the interface is generic so it should use
the generic term for file/directory.

Signed-off-by: David Sterba <dsterba@suse.com>
2024-02-20 12:59:29 +01:00
David Sterba 7b9a3669e1 btrfs-progs: drop _fd from btrfs_open_file_or_dir_fd()
Signed-off-by: David Sterba <dsterba@suse.com>
2024-02-20 12:58:27 +01:00
David Sterba 1669446fd9 btrfs-progs: drop _fd from btrfs_open_mnt_fd()
Signed-off-by: David Sterba <dsterba@suse.com>
2024-02-20 12:57:50 +01:00