Commit graph

5668 commits

Author SHA1 Message Date
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
David Sterba f759e9bbad btrfs-progs: introduce a public helper for raid parity
There's a private helper for parity and there are many open coded
calculations of parity for the RAID56 profiles. The helper will be used
to remove that and use the raid table values.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:23 +02:00
David Sterba 447bf2fb37 btrfs-progs: zoned: factor out supported profiles to a helper
The enumeration could get out of date, like fixed in previous commit.
Create a helper that will hide the implementation details.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:23 +02:00
David Sterba 15eb03ca1d btrfs-progs: use raid table for profile names in print-tree.c
Pick the names from the raid table and do the uppercase conversion.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:23 +02:00
David Sterba 80714610f3 btrfs-progs: use raid table for ncopies
There's opencoded value of raid table ncopies in
print_filesystem_usage_overall, add a helper and use it.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:23 +02:00
David Sterba b29f1603b0 btrfs-progs: use raid table for devs_min and replace local helper
Another duplication of the raid table, in this case missing the changes
to raid10 and raid0 minimum devices changed in a177ef7dd4
("btrfs-progs: mkfs: allow degenerate raid0/raid10").

Define and use a helper using the table value.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:23 +02:00
Naohiro Aota e9696b06f0 btrfs-progs: use direct-io for zoned device
We need to use direct-IO for zoned devices to preserve the write
ordering.  Instead of detecting if the device is zoned or not, we simply
use direct-IO for any kind of device (even if emulated zoned mode on a
regular device).

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:23 +02:00
Naohiro Aota 4a8d85f730 btrfs-progs: temporarily set zoned flag for initial tree reading
Functions to read data/metadata e.g. read_extent_from_disk() now depend on
the fs_info->zoned flag to determine if they do direct-IO or not.

The flag (and zone_size) is not known before reading the chunk tree and it
set to 0 while in the initial chunk tree setup process. That will cause
btrfs_pread() to fail because it does not align the buffer.

Use fcntl() to find out the file descriptor is opened with O_DIRECT or not,
and if it is, set the zoned flag to 1 temporally for this initial process.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:23 +02:00
Naohiro Aota ae0dfb246d btrfs-progs: introduce btrfs_pread wrapper for pread
Wrap pread with btrfs_pread as well.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:23 +02:00
Naohiro Aota c821e5545f btrfs-progs: introduce btrfs_pwrite wrapper for pwrite
Wrap pwrite with btrfs_pwrite(). It simply calls pwrite() on non-zoned
btrfs (opened without O_DIRECT). On zoned mode (opened with O_DIRECT),
it allocates an aligned bounce buffer, copies the contents and uses it
for direct-IO writing.

Writes in device_zero_blocks() and btrfs_wipe_existing_sb() are a little
tricky. We don't have fs_info on our hands, so use zinfo to determine it
is a zoned device or not.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-20 18:59:23 +02:00
Naohiro Aota 2a550d4ccd btrfs-progs: drop ZONED flag from BTRFS_CONVERT_ALLOWED_FEATURES
Since we cannot create ext*/reiserfs on a zoned device, it is useless to
allow ZONED feature when converting a file system. Drop ZONED flag from
BTRFS_CONVERT_ALLOWED_FEATURES.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:04 +02:00
Naohiro Aota 40ab7530df btrfs-progs: set eb::fs_info properly everywhere
Several extent_buffer initializations miss fs_info initialization. This
is OK before the following patch ("btrfs-progs: use direct-io for zoned
device") as eb->fs_info is not always necessary. But, after that patch,
we will use fs_info to determine it is zoned or not and that causes
segfault in such cases.

Properly set fs_info when initializing extent_buffers to fix the issue.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:04 +02:00
Naohiro Aota c9c36aaf5b btrfs-progs: mkfs: do not set zone size on non-zoned mode
Since zone_size() returns an emulated zone size even for non-zoned
device, we cannot use cfg.zone_size to determine the device is zoned or
not. Set zone_size = 0 on non-zoned mode.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:04 +02:00
David Sterba b2dc5d0037 btrfs-progs: remove c++ protection from internal headers
We don't need the c++ name mangling protection in headers that are not
part of libbtrfs.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:04 +02:00
David Sterba 0fc4bb4d91 btrfs-progs: remove unused subvol_uuid_search_add
After removal of the fallback uuid search code the helper is unused in
the internal code.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:04 +02:00
David Sterba ac5954ee36 btrfs-progs: merge subvol_uuid_search helpers
Due to ambiguity of error values in the public API subvol_uuid_search,
there was second version added. There's a separate copy in libbtrfs and
we don't have to distinguish in the internal code. All callers check for
IS_ERR and NULL, so we can safely merge the helpers into one.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:04 +02:00
David Sterba e491d9cf25 btrfs-progs: simplify struct subvol_uuid_search use
After removing uuid search fallback code the structure has become
trivial and copies the fd that all callers have in their context.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:04 +02:00
David Sterba 22f5600649 btrfs-progs: open code subvol_uuid_search_init
The helper is trivial after removing the uuid search fallback code,
open code it.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:04 +02:00
David Sterba f18dbe2bc6 btrfs-progs: remove empty subvol_uuid_search_finit
After the uuid search fallback code has been removed, the finit helper
has become empty and can be removed.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:04 +02:00
David Sterba 522945efc8 btrfs-progs: remove unused prototypes from send-utils.h
The functions are part of path-utils.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:04 +02:00
David Sterba a8dceec381 btrfs-progs: drop slow subvol uuid search
There's a lot of code under BTRFS_COMPAT_SEND_NO_UUID_TREE to support
kernels < 3.12 that don't have uuid tree and the subvolume uuids are
searched in a slow way, building the uuid tree on the userspace side.

As the uuid tree is always created, the fallback code was not exercised
anyway due to 'uuid_tree_existed' check in subvol_uuid_search2.

Delete the code from the internal copy of send-utils. The support still
stays for libbtrfs and will be removed in the future.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:04 +02:00
David Sterba 649ccbfa2e btrfs-progs: subvol list: open code list_subvol_fill_paths in its caller
The helper is quite simple and there's only one caller, so merge them.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:04 +02:00
David Sterba fad9a54f88 btrfs-progs: subvol list: move sort order to the caller
All the comparators switch the result based on is_descending, but that
can be factored to the caller to simplify the comparators.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:04 +02:00
David Sterba 26f8e56194 btrfs-progs: subvol list: constify comparator parameters
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:04 +02:00
David Sterba 92c53aa50f btrfs-progs: subvol list: simplify root lookup structures
The struct root_lookup wraps only the rb-tree node which is pointless
indirection, so replace the type.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:04 +02:00
David Sterba 7e0a8f3401 btrfs-progs: subvol list: merge the rest of btrfs-list.c
The remaining functions are too entangled to be moved separately without
too much churn making them exported and not, so move all the code at
once. No refactoring or coding style fixups.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:03 +02:00
David Sterba 2c63c90517 btrfs-progs: subvol list: copy btrfs_list_alloc_filter_set from btrfs-list.c
There's only one caller of btrfs_list_alloc_filter_set so move it there.
Also move the definitions of BTRFS_LIST_* to the header so they can be
used by both btrfs-list and subvolume.c.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:03 +02:00
David Sterba acefefce61 btrfs-progs: subvol list: copy btrfs_list_alloc_comparer_set from btrfs-list.c
There's only one caller of btrfs_list_alloc_comparer_set so move it
there. Also move the definitions of BTRFS_LIST_* to the header so they
can be used by both btrfs-list and subvolume.c.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:03 +02:00
David Sterba fb0bfb967f btrfs-progs: subvol find-new: copy code from btrfs-list.c
The actual implementation of find-new functionality is outside of
subvolume.c, copy it where it's supposed to be. No reformatting or style
changes.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:03 +02:00
David Sterba d66740eeb5 btrfs-progs: remove unused btrfs_list_get_default_subvolume
It has been replaced by libbtrfsutil function in 9e73a416f0
("btrfs-progs: use libbtrfsutil for get-default").

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:03 +02:00
David Sterba 68b8ea0020 btrfs-progs: remove unused btrfs_list_path_for_root
All users have been converted to use btrfs_subvolid_resolve, we can now
remove btrfs_list_path_for_root.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:03 +02:00
David Sterba d50da1e003 btrfs-progs: remove unused btrfs_get_subvol
Replaced by libbtrfsutil functions in 9005b603d7 ("btrfs-progs: use
libbtrfsutil for subvol show"). Also remove strdup_or_null as it's now
unused too.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:03 +02:00
David Sterba 030caec819 btrfs-progs: remove unused btrfs_get_toplevel_subvol
Replaced by libbtrfsutil functions in 9005b603d7 ("btrfs-progs: use
libbtrfsutil for subvol show").

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:03 +02:00
David Sterba fbd2a3bf9c btrfs-progs: remove unused btrfs_list_get_path_rootid
All callers now use lookup_path_rootid.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:03 +02:00
David Sterba 03650851c5 btrfs-progs: split subvolume list to its own file
The main functionality of subvolume listing is now in btrfs-list.c but
there are no other commands using the API so this will be merged. It's a
lot of code so split it to another file.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:03 +02:00
David Sterba a1f2dd12ad btrfs-progs: use btrfs_subvolid_resolve instead of btrfs_list_path_for_root
The btrfs_list_* functions come with some overhead and for simple path
resolution we can use btrfs_subvolid_resolve.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:03 +02:00
David Sterba 8bb13015bd btrfs-progs: don't include btrfs-list.h unless necessary
We don't need to include this besides btrfs-list.c itself and
subvolume.c that does use the btrfs_list_* API.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:03 +02:00
David Sterba a3efed2adb btrfs-progs: libbtrfs: merge utils-lib.c back to utils.c
The separate file was needed for libbtrfs in the past to avoid pulling
utils.c in, but this is not needed after recent cleanups.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:47:03 +02:00