Commit graph

31 commits

Author SHA1 Message Date
David Sterba 5fa48a03c5 libbtrfs: fix potentially unaligned access
Same fix a previous commit, unaligned access on strict alignment hosts
could produce wrong results (reported on send/receive and arm5). As
libbtrfs has own copy of the code fix it here too, replacing leXX_to_cpu
with get_unaligned_leXX where appropriate. This means any access to raw
buffers that get cast to a structure.

Issue: #770
Signed-off-by: David Sterba <dsterba@suse.com>
2024-05-25 00:37:52 +02: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 f9b0da8e78 Revert "libbtrfs: remove the support for fs without uuid tree"
This reverts commit 83ab92512e.

The commit removed some old code that seemed to be unused but this
actually broke snapper. Revert the changes completely to the v6.3 ABI
level.

Link: https://bugzilla.opensuse.org/show_bug.cgi?id=1212217
Issue: #672
Signed-off-by: David Sterba <dsterba@suse.com>
2023-09-01 13:58:46 +02:00
Qu Wenruo 83ab92512e libbtrfs: remove the support for fs without uuid tree
Since kernel 3.12, any btrfs mounted by a kernel would have an UUID
tree created, to record all the UUID of its subvolumes.

Without UUID tree, libbtrfs send functionality has to go through all the
subvolumes seen so far, and record those subvolumes' UUID internally so
that libbtrfs send can locate a desired subvolume.

Since commit 194b90aa2c ("btrfs-progs: libbtrfs: remove declarations
without exports in send-utils") we're deprecating this old interface
already, meaning deprecated users won't be able to build its own
subvolume list already.

And we received no error report on this so far.  So let's finish the
cleanup by removing the support for fs without an UUID tree.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-05-26 18:02:31 +02:00
Josef Bacik 228aa34f10 btrfs-progs: sync messages.[ch] from the kernel
These are the printk helpers from the kernel.  There were a few
modifications, the hi-lights are

- We do not have fs_info::fs_state, so that needed to be removed.
- We do not have discard.h sync'ed yet, so that dependency was dropped.
- Anything related to struct super_block was commented out.
- The transaction abort had to be modified to fit with the current
  btrfs-progs code.
- Added a btrfs_no_printk() helper to common/messages.* so that the
  print statements still worked.
- The 32bit limit checkers are not needed so are behind __KERNEL__

Additionally there were kerncompat.h changes that needed to be made to
handle the dependencies properly.  Those are easier to spot.

Any function that needed to be modified has a MODIFIED tag in the
comment section with a list of things that were changed.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-05-26 18:02:28 +02:00
Josef Bacik bf0f3db765 btrfs-progs: introduce UASSERT() for purely userspace code
While syncing messages.[ch] I had to back out the ASSERT() code in
kerncompat.h, which means we now rely on the kernel code for ASSERT().
In order to maintain some semblance of separation introduce UASSERT()
and use that in all the purely userspace code.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-05-26 18:02:28 +02:00
Josef Bacik 78e5887fea btrfs-progs: fix kerncompat.h include ordering for libbtrfs
We're keeping a libbtrfs compatible kerncompat.h around to make it
easier to modify the rest of btrfs-progs.  Unfortunately we also use
some of kernel-lib in libbtrfs, and those also include kerncompat.h.
Those getting included first means we'll pull include/kerncompat.h
instead of libbtrfs/kerncompat.h, which will mess things up.

Fix this by making sure we include our local copy of kerncompat.h first
before we include any other header in btrfs-progs.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2023-05-26 18:02:27 +02:00
David Sterba 979fe686d2 btrfs-progs: libbtrfs: own copy of crc32c
The crc32c.c is going to be updated with CPU feature detection from
common/ which is not suitable for libbtrfs, so make own copy of the
file.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-02-28 20:11:22 +01:00
David Sterba d6fc49d1dd btrfs-progs: libbtrfs: move libbtrfs.sym to the directory
The symbol definition is part of the library, move it away from the
toplevel directory.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-01-05 14:23:46 +01:00
David Sterba d4c7f01e37 btrfs-progs: libbtrfs: move version.h to the directory
The header is part of the public API and not used by any other code so
move it to the other files.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-01-05 14:18:07 +01:00
David Sterba e8d8949d38 btrfs-progs: libbtrfs: use own copy of kerncompat.h
Add a copy from v6.0.2 of kerncompat.h for libbtrfs to avoid accidental
build breakage as it's a public header and until now also shared with
the rest of btrfs-progs code.

Signed-off-by: David Sterba <dsterba@suse.com>
2023-01-04 16:52:57 +01:00
David Sterba 27bb4f6819 btrfs-progs: libbtrfs: revert to v6.0.2 ioctl.h
The file ioctl.h has been copied to libbtrfs in 5fc1d0cd64
("btrfs-progs: copy ioctl.h into libbtrfs") but that was after changes
to the btrfs_qgroup_limit in 03451430de ("btrfs-progs: rename qgroup
items to match the kernel naming scheme"). This caused build breakage
but hasn't been fixed in v6.1.1.

Revert the contents of libbtrfs/ioctl.h to be completely just v6.0.2
though the other changes may not be needed, it's the version we know
works.

Issue: #566
Signed-off-by: David Sterba <dsterba@suse.com>
2023-01-04 16:45:23 +01:00
Josef Bacik 5fc1d0cd64 btrfs-progs: copy ioctl.h into libbtrfs
We're going to sync btrfs.h into btrfs-progs from the kernel, however
libbtrfs still needs ioctl.h.  To deal with this copy ioctl.h into
libbtrfs, and update that code to use the local copy and update the
libbtrfs headers list to use this copy.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-11-28 18:57:43 +01:00
Josef Bacik 53f8b8fd01 btrfs-progs: make btrfs_qgroup_level helper match the kernel
We return __u16 in the kernel, as this is actually the size of
btrfs_qgroup_level.  Adjust the existing helpers and update all the
callers to deal with the new size appropriately.  This will make syncing
the kernel code cleaner.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-11-28 18:57:43 +01:00
David Sterba 44efde7fa0 btrfs-progs: unify naming of qgroup subvolid helpers
Kernel function name is btrfs_qgroup_subvolid so rename it in progs. The
libbtrfs can't API be changed without versioning so at least add the new
helper.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-10-26 09:36:44 +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 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 84062449f2 btrfs-progs: libbtrfs: reduce exports from ctree.h
Signed-off-by: David Sterba <dsterba@suse.com>
2022-08-16 15:18:11 +02:00
David Sterba 355844f86b btrfs-progs: libbtrfs: move extent-cache.h to ctree.h
Move the remaining structure definitions and prototypes to ctree.h that
is now the only user.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-06-06 15:49:22 +02:00
David Sterba 6b539bbbc4 btrfs-progs: libbtrfs: move extent_io.h to ctree.h
Move the remaining structure definitions and prototypes to ctree.h that
is now the only user.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-06-06 15:49:13 +02:00
David Sterba ec59b70065 btrfs-progs: libbtrfs: remove declarations without exports in extent-cache.h
The header extent-cache.h is internal and provides only structures defined
in ctree.h, we don't need anything else besides the structures.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-06-06 15:49:08 +02:00
David Sterba 22c842e7e1 btrfs-progs: libbtrfs: remove declarations without exports in extent_io.h
The header extent_io.h is internal and provides only structures defined
in ctree.h, we don't need anything else besides the structures and
declarations used for inline functions in other headers.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-06-06 15:49:06 +02:00
David Sterba 194b90aa2c btrfs-progs: libbtrfs: remove declarations without exports in send-utils
The list of exported functions in libbtrfs.sym defines the ABI so the
headers should match that.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-06-06 15:49:03 +02:00
David Sterba bb7db09e46 btrfs-progs: libbtrfs: use own copy of ctree.h, extent_io.h, send.h and extent-cache.h
Let libbtrfs use own copy of the exported header files to avoid
potential breakage when syncing with kernel headers and also to remove
declarations that are not used by userspace.  The send.h is frozen to
support protocol v1.

Signed-off-by: David Sterba <dsterba@suse.com>
2022-06-06 15:48:46 +02:00
David Sterba f404f14917 btrfs-progs: libbtrfs: copy btrfs_uuid_tree_lookup_any from uuid-tree.c
Copy the lookup helper and switch the API functions using it. We can
drop dependency on kernel-shared/uuid-tree.c after that.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:46:35 +02:00
David Sterba 48be3ad5b3 btrfs-progs: libbtrfs: use btrfs_subvolid_resolve for id->path resolution
There are two functions for resolving subvolume id path, but one is less
convenient and pulls a lot of dependencies. This is
btrfs_list_path_for_root, where the idea is to have the whole tree of
subvolumes and query it as needed.

For simple path resolution we already have btrfs_subvolid_resolve and
it's also in the public API, so we can use it and drop the other one.
This in turn allows to drop btrfs-list.o from build dependencies.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:46:35 +02:00
David Sterba c774b45e22 btrfs-progs: libbtrfs: make own copy of lookup_path_rootid
Remove dependency on utils.h and copy the simple lookup_path_rootid
helper.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:46:35 +02:00
David Sterba d9009ed8ad btrfs-progs: libbtrfs: remove unneeded uuid.h includes
Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:46:35 +02:00
David Sterba 22c2fbd86d btrfs-progs: libbtrfs: switch to bare fprintf for error messages
Don't use the internal message helpers and remove the dependency on
messages.h.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:46:34 +02:00
David Sterba 35882be40a btrfs-progs: remove BTRFS_FLAT_INCLUDES from internal send headers
There's a separate copy of the headers, we can remove the include switch
from the internal copies.

Signed-off-by: David Sterba <dsterba@suse.com>
2021-10-08 20:46:34 +02:00
David Sterba 6b5c089469 btrfs-progs: libbtrfs: make own copy of files implementing the API
The two files send-stream and send-utils contain the implementations of
the exported API, which was just for send stream. This was the original
idea. That libbtrfs contains another 40 files was a result of
unclean/missing library design and had to be done that way to resolve
the symbols due to dependencies.

That the same files have been used for both internal and public library
has prevented refactoring and cleanups and was always a risk of breaking
something.

Make separate copy for libbtrfs utils and allow any cleanups and
reduction of number of build objects. The API hasn't changed since the
beginning so there's low risk of missing some fixes from the internal
code.

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