libbtrfsutil: implement what snapper needs from libbtrfs
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.
- [x] create subvolume
- [x] create snapshot
- [x] check if a directory is a subvolume
- [x] delete subvolume
- [x] get default subvolume
- [x] set defautl subvolume
- [ ] subvolume sync
- [ ] list subvolumes
- [x] subvolume flags - readonly
- [x] 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
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.
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.
Initial support for libbtrfsutil about to land in snapper https://github.com/openSUSE/snapper/pull/767
The PR got merged and the todo list updated.
Get subvolume id also imlemented https://github.com/openSUSE/snapper/pull/832 .
Find subvolume by id https://github.com/openSUSE/snapper/pull/771 .