libblockdev icon indicating copy to clipboard operation
libblockdev copied to clipboard

RFC: btrfs plugin: use libbtrfsutil

Open jelly opened this issue 1 year ago • 4 comments

This is a quick hack to start off the discussion if libbtrfsutil would be a good fit for extending further features in the btrfs plugin for libblockdev. ( I recall there was a discussion somewhere, but couldn't find the issue)

Some notable things which needs to be verified:

  • [x] License, libbtrfsutil itself is licensed LGPL, is it compatible with libblockdev?
  • [ ] Feature completeness, can everything currently be replaced with libbtrfsutil and what is missing, can it be supported in libbtrfsutil and is upstream willing too?
  • [x] Is libbtrfsutil packaged everywhere libblockdev is at the moment used.

Important note:

libbtrfsutil only includes operations that are done through the filesystem and ioctl interface, not operations that modify the filesystem directly (e.g., mkfs or fsck). This is by design but also a legal necessity, as the filesystem implementation is GPL but libbtrfsutil is LGPL. That is also why the libbtrfsutil code is a reimplementation of the btrfs-progs code rather than a refactoring. Be wary of this when porting functionality.


Porting todo

  • [x] btrfs default subvolume get/set
  • [x] listing subvolumes
  • [x] create subvolume
  • [x] delete subvolume

Missing

  • [ ] volume information (bd_btrfs_filesystem_info) (ideally also RAID/ multi device information which is now lacking (btrfs device usage /))
  • [ ] device add/remove support
  • [ ] set label?
  • [ ] bd_list_devices
  • [ ] create volume

jelly avatar Jan 22 '24 13:01 jelly

Can one of the admins verify this patch?

StorageGhoul avatar Jan 22 '24 13:01 StorageGhoul

This is a quick hack to start off the discussion if libbtrfsutil would be a good fit for extending further features in the btrfs plugin for libblockdev.

Definitely something we'd like to do. Every command call we can replace with a library call is a huge improvement.

( I recall there was a discussion somewhere, but couldn't find the issue)

That would be https://github.com/storaged-project/libblockdev/issues/552

Some notable things which needs to be verified:

* [ ]  License, libbtrfsutil itself is licensed LGPL, is it compatible with libblockdev?

Yes, libblockdev is also licensed under LGPL 2.1 so there shouldn't be a problem.

* [ ]  Feature completeness, can everything currently be replaced with libbtrfsutil and what is missing, can it be supported in libbtrfsutil and is upstream willing too?

It would be great if we could replace everything with libbtrfsutil, but I am ok with replacing only parts of the command calls with the library.

* [ ]  Is libbtrfsutil packaged everywhere libblockdev is at the moment used.

Libblockdev is packaged pretty much everywhere these days, but libbtrfsutil seems to be available in both Fedora and Debian/Ubuntu and that's good enough at least for our CI :)

vojtechtrefny avatar Jan 22 '24 13:01 vojtechtrefny

This is a quick hack to start off the discussion if libbtrfsutil would be a good fit for extending further features in the btrfs plugin for libblockdev.

Definitely something we'd like to do. Every command call we can replace with a library call is a huge improvement.

( I recall there was a discussion somewhere, but couldn't find the issue)

That would be #552

Some notable things which needs to be verified:

* [ ]  License, libbtrfsutil itself is licensed LGPL, is it compatible with libblockdev?

Yes, libblockdev is also licensed under LGPL 2.1 so there shouldn't be a problem.

Nice!

* [ ]  Feature completeness, can everything currently be replaced with libbtrfsutil and what is missing, can it be supported in libbtrfsutil and is upstream willing too?

It would be great if we could replace everything with libbtrfsutil, but I am ok with replacing only parts of the command calls with the library.

So from the LGPL/GPL note in the documentation, I can make up that it is basically everything mkfs, repair and possibly btrfs device add.

* [ ]  Is libbtrfsutil packaged everywhere libblockdev is at the moment used.

Libblockdev is packaged pretty much everywhere these days, but libbtrfsutil seems to be available in both Fedora and Debian/Ubuntu and that's good enough at least for our CI :)

It's also available in Arch Linux. I should add the required CI changes, for Fedora this would mean a dependency on libbtrfsutil which btrfs-progs does not depend on (due to the licensing afaik).

jelly avatar Jan 22 '24 13:01 jelly

I've rebased and ported all functions which can use libbtrfsutil. I haven't managed to land a new feature yet in libbtrfsutil. But I don't think btrfs-progs wants to block new additions to the API.

This is all still a bit WiP, there are some TODO's regarding error checking and one test which cannot be ported as it overrides btrfs subvolume list (The weird docker subvolumes one). But in all it seems to shave off ~ 100 loc.

jelly avatar Mar 06 '24 11:03 jelly