Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libbtrfsutil: implement what snapper needs from libbtrfs #218

Open
8 of 16 tasks
kdave opened this issue Oct 24, 2019 · 7 comments
Open
8 of 16 tasks

libbtrfsutil: implement what snapper needs from libbtrfs #218

kdave opened this issue Oct 24, 2019 · 7 comments

Comments

@kdave
Copy link
Owner

kdave commented Oct 24, 2019

The snapper tool was historically first user of the libbtrfs and at the moment is the only known. As libbtrfs needs to be deprecated in favor of libbtrfsutil, we need to implement the missing functinoality.

Check https://github.com/openSUSE/snapper files src/Btrfs*.cc for 'btrfs_*' and 'subvol_uuid_*'.

The used interfaces are stream dump and subvolume enumeration.

  • create subvolume
  • create snapshot
  • check if a directory is a subvolume
  • delete subvolume
  • get default subvolume
  • set defautl subvolume
  • subvolume sync
  • list subvolumes
  • subvolume flags - readonly
  • get root id
  • search subvol by uuid
  • process send stream, callbacks, NO_FILE_DATA flag
  • start send
  • quota related ioctls
  • qgroup related ioctls
  • fs info

Data structures used:

  • btrfs_ioctl_vol_args
  • btrfs_ioctl_vol_args_v2
  • btrfs_qgroup_inherit
  • btrfs_ioctl_search_args
  • btrfs_ioctl_search_key
  • btrfs_ioctl_search_header
  • btrfs_dir_item
  • btrfs_ioctl_ino_lookup_args
  • btrfs_ioctl_quota_ctl_args
  • btrfs_ioctl_quota_rescan_args
  • btrfs_ioctl_qgroup_create_args
  • btrfs_ioctl_qgroup_assign_args
  • btrfs_qgroup_info_item
  • btrfs_send_ops
  • btrfs_ioctl_send_args
  • subvol_uuid_search
  • subvol_info
  • btrfs_ioctl_fs_info_args

Exported functions used:

  • btrfs_subvolid_resolve
  • btrfs_read_and_process_send_stream
  • subvol_uuid_search_init
  • subvol_uuid_search
  • subvol_search_by_path

Exported but not used:

  • btrfs_lookup_uuid_received_subvol_item
  • btrfs_lookup_uuid_subvol_item
  • btrfs_get_subvol
  • radix_*
  • raid*
  • rb_*
  • subvol_uuid_search2
  • subvol_uuid_search_add
  • subvol_uuid_search_finit
  • path_cat_out
  • path_cat3_out
@kdave
Copy link
Owner Author

kdave commented Sep 8, 2021

Hiding symbols via the .sym version script does not work so we'd have to drag all the unused symbols indefinitelly. There are only 4 symbol linked by libsnapper

    89: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND subvol_uuid_search_init@LIBBTRFS_0.1 (21)
   114: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND btrfs_read_and_process_send_stream@LIBBTRFS_0.1 (21)
   132: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND btrfs_subvolid_resolve@LIBBTRFS_0.1 (21)
   348: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND subvol_uuid_search@LIBBTRFS_0.1 (21)

subvol_search_by_path is missing as it's passed as parameter.

Suggested solution, that's kind of brutal and breaking the practices of library and symbol versioning: limit the exports only to the known onse and don't change the version. Snapper would work after rebuild.

Once the number of exports is reduced to minimum, headers can be trimmed down only to structure definitions and declarations of relevant functions. The remaining part of the export would be the ioctl definitions and ctree.h with the structures, plus the helpers around that. To avoid breaking the library, a separate set of files can be created and reduced independently of the standard headers.

@kdave
Copy link
Owner Author

kdave commented Sep 8, 2021

Dependencies verified on openSUSE (zypper se --requires libbtrfs) and debian (apt-cache rdepends libbtrfs0), only snapper. Build verified in OBS with reduced .so exports, running snapper with it also works.

kdave added a commit that referenced this issue Sep 9, 2021
Another step to decommission libbtrfs in favor of libbtrfsutil. Remove
all symbols that are not used by snapper, as this is the only known
widely distributed tool that uses some of the librarized functionality,
apart from the ioctls.

The symbol versioning does not allow to remove once exported symbol so
this is a dirty trick that works only in this situation. The unused
symbols are not exported anymore BUT the library has the same version.
This would be normally an ABI violation, but there's no change for
snapper (build and runtime verified on version 0.9.0).

The known used symbols are preserved.

* btrfs_subvolid_resolve
* btrfs_read_and_process_send_stream
* subvol_uuid_search_init
* subvol_uuid_search

Issue: #218
Signed-off-by: David Sterba <[email protected]>
lansuse pushed a commit to lansuse/btrfs-progs that referenced this issue Dec 1, 2021
Another step to decommission libbtrfs in favor of libbtrfsutil. Remove
all symbols that are not used by snapper, as this is the only known
widely distributed tool that uses some of the librarized functionality,
apart from the ioctls.

The symbol versioning does not allow to remove once exported symbol so
this is a dirty trick that works only in this situation. The unused
symbols are not exported anymore BUT the library has the same version.
This would be normally an ABI violation, but there's no change for
snapper (build and runtime verified on version 0.9.0).

The known used symbols are preserved.

* btrfs_subvolid_resolve
* btrfs_read_and_process_send_stream
* subvol_uuid_search_init
* subvol_uuid_search

Issue: kdave#218
Signed-off-by: David Sterba <[email protected]>
@kdave
Copy link
Owner Author

kdave commented Jan 6, 2023

Initial support for libbtrfsutil about to land in snapper openSUSE/snapper#767

@kdave
Copy link
Owner Author

kdave commented Jan 13, 2023

The PR got merged and the todo list updated.

@kdave
Copy link
Owner Author

kdave commented Oct 17, 2023

Get subvolume id also imlemented openSUSE/snapper#832 .

@kdave
Copy link
Owner Author

kdave commented Oct 17, 2023

Find subvolume by id openSUSE/snapper#771 .

@kdave
Copy link
Owner Author

kdave commented Apr 30, 2024

The library interface has been updated to 0.1.3 and can be now extended with new ioctl wrappers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant