Skip to content

btrfs-progs: introduce libbtrfsutil, "btrfs-progs as a library"

Omar Sandoval linux-btrfs 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest27 patches 36 repliesIn review
  2. v126 patches 20 repliesSuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/27btrfs-progs: get rid of undocumented qgroup inheritance optionscmds-subvolume.c qgroup.c qgroup.h+2 -670 replies
2/27Add libbtrfsutil.gitignore Makefile Makefile.inc.in +6 more+1100 -212 replies
3/27libbtrfsutil: add Python bindingsINSTALL Makefile Makefile.inc.in +8 more+601 -13 replies
4/27libbtrfsutil: add btrfs_util_is_subvolume() and btrfs_util_subvolume_id()Makefile libbtrfsutil/btrfsutil.h libbtrfsutil/python/btrfsutilpy.h +6 more+373 -13 replies
5/27libbtrfsutil: add qgroup inheritance helpersMakefile libbtrfsutil/btrfsutil.h libbtrfsutil/python/btrfsutilpy.h +5 more+335 -10 replies
6/27libbtrfsutil: add btrfs_util_create_subvolume()libbtrfsutil/btrfsutil.h libbtrfsutil/python/btrfsutilpy.h libbtrfsutil/python/module.c +4 more+245 -12 replies
7/27libbtrfsutil: add btrfs_util_subvolume_path()libbtrfsutil/btrfsutil.h libbtrfsutil/python/btrfsutilpy.h libbtrfsutil/python/module.c +3 more+216 -12 replies
8/27libbtrfsutil: add btrfs_util_subvolume_info()libbtrfsutil/btrfsutil.h libbtrfsutil/python/btrfsutilpy.h libbtrfsutil/python/module.c +3 more+440 -00 replies
9/27libbtrfsutil: add btrfs_util_[gs]et_read_only()libbtrfsutil/btrfsutil.h libbtrfsutil/python/btrfsutilpy.h libbtrfsutil/python/module.c +3 more+186 -00 replies
10/27libbtrfsutil: add btrfs_util_[gs]et_default_subvolume()libbtrfsutil/btrfsutil.h libbtrfsutil/python/btrfsutilpy.h libbtrfsutil/python/module.c +3 more+234 -02 replies
11/27libbtrfsutil: add subvolume iterator helperslibbtrfsutil/btrfsutil.h libbtrfsutil/python/btrfsutilpy.h libbtrfsutil/python/module.c +3 more+690 -02 replies
12/27libbtrfsutil: add btrfs_util_create_snapshot()libbtrfsutil/btrfsutil.h libbtrfsutil/python/btrfsutilpy.h libbtrfsutil/python/module.c +4 more+352 -00 replies
13/27libbtrfsutil: add btrfs_util_delete_subvolume()libbtrfsutil/btrfsutil.h libbtrfsutil/python/btrfsutilpy.h libbtrfsutil/python/module.c +3 more+219 -00 replies
14/27libbtrfsutil: add btrfs_util_deleted_subvolumes()libbtrfsutil/btrfsutil.h libbtrfsutil/python/btrfsutilpy.h libbtrfsutil/python/module.c +4 more+183 -153 replies
15/27libbtrfsutil: add filesystem sync helpersMakefile libbtrfsutil/btrfsutil.h libbtrfsutil/filesystem.c +5 more+341 -20 replies
16/27btrfs-progs: use libbtrfsutil for read-only propertymessages.h props.c+38 -442 replies
17/27btrfs-progs: use libbtrfsutil for sync ioctlscmds-filesystem.c cmds-qgroup.c cmds-subvolume.c+30 -240 replies
18/27btrfs-progs: use libbtrfsutil for set-defaultcmds-subvolume.c+8 -350 replies
19/27btrfs-progs: use libbtrfsutil for get-defaultcmds-subvolume.c+26 -280 replies
20/27btrfs-progs: use libbtrfsutil for subvol create and snapshotcmds-subvolume.c qgroup.c qgroup.h+58 -2330 replies
21/27btrfs-progs: use libbtrfsutil for subvol deletecmds-subvolume.c+8 -140 replies
22/27btrfs-progs: use libbtrfsutil for subvol showcmds-subvolume.c utils.c utils.h+98 -1740 replies
23/27btrfs-progs: use libbtrfsutil for subvol synccmds-subvolume.c+21 -1964 replies
24/27btrfs-progs: replace test_issubvolume() with btrfs_util_is_subvolume()cmds-qgroup.c cmds-subvolume.c utils.c +1 more+12 -440 replies
25/27btrfs-progs: add recursive snapshot/delete using libbtrfsutilDocumentation/btrfs-subvolume.asciidoc cmds-subvolume.c+33 -60 replies
26/27btrfs-progs: use libbtrfsutil for subvolume listbtrfs-list.c btrfs-list.h cmds-subvolume.c+956 -8872 replies
27/27btrfs-progs: deprecate libbtrfs helpersbtrfs-list.c btrfs-list.h cmds-inspect.c +4 more+55 -252 replies

Reviews trailers per patch

1 of 27 patches has a Reviewed-by or Acked-by.

PatchLiu Bo
1/27
2/27R-b
3/27
4/27
5/27
6/27
7/27
8/27
9/27
10/27
11/27
12/27
13/27
14/27
15/27
16/27
17/27
18/27
19/27
20/27
21/27
22/27
23/27
24/27
25/27
26/27
27/27

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 00/27] btrfs-progs: introduce libbtrfsutil, "btrfs-progs as a library"

From: Omar Sandoval <[email protected]>

Hi,

This is v2 of "btrfs-progs as a library".

Most of the changes since v1 are small:

- Rebased onto v4.15
- Split up btrfs_util_subvolume_path() which was accidentally squashed together with the commit adding btrfs_util_create_subvolume()
- Renamed btrfs_util_f_* functions to btrfs_util_*_fd for clarity
- Added -fvisibility=hidden and a macro for __attribute__((visibility("default")))
- Changed to use semantic versioning
- Fixed missing install of btrfsutil.h
- Documented functions which require root or are non-atomic
- Added a missing license to setup.py

The bigger change is in the last two patches. Dave requested that I get rid of the runtime dependency of libbtrfsutil from libbtrfs. The easiest way to do this was to remove the btrfs_list_subvols_print() implementation from libbtrfs and put it in cmds-subvolume.c (details in patch 26). I'm open to alternatives.

Please share feedback, thanks!

Cover letter from v1:

One of the features requests I get most often is a library to do the sorts of operations that we do with btrfs-progs. We can shell out to btrfs-progs, but the output format isn't always easily parsasble, and shelling out isn't always ideal. There's libbtrfs, but it's very incomplete, doesn't have a well thought out API, and is licensed under the GPL, making it hard to use for many projects.

libbtrfsutil is a new library written from scratch to address these issues. The implementation is completely independent of the existing btrfs-progs code, including kerncompat.h, and has a clean API and naming scheme. It is licensed under the LGPL. It also includes Python bindings by default. I will maintain the library code.

Patch 1 is a preparation cleanup which can go in independently. Patch 2 adds the build system stuff for the library, and patch 3 does the same for the Python bindings. Patches 4-14 implement the library helpers, currently subvolume helpers and the sync ioctls. Patches 15-26 replace the btrfs-progs and libbtrfs code to use libbtrfsutil instead. I took care to preserve backwards-compatibility. btrfs subvol list in particular had some buggy behaviors for -o and -a that I emulated in the new code, see the comments in the code.

These patches are also available on my GitHub:
https://github.com/osandov/btrfs-progs/tree/libbtrfsutil. That branch will rebase as I update this series.

Omar Sandoval (27):
btrfs-progs: get rid of undocumented qgroup inheritance options Add libbtrfsutil
libbtrfsutil: add Python bindings
libbtrfsutil: add btrfs_util_is_subvolume() and
btrfs_util_subvolume_id()
libbtrfsutil: add qgroup inheritance helpers
libbtrfsutil: add btrfs_util_create_subvolume()
libbtrfsutil: add btrfs_util_subvolume_path()
libbtrfsutil: add btrfs_util_subvolume_info()
libbtrfsutil: add btrfs_util_[gs]et_read_only()
libbtrfsutil: add btrfs_util_[gs]et_default_subvolume()
libbtrfsutil: add subvolume iterator helpers
libbtrfsutil: add btrfs_util_create_snapshot()
libbtrfsutil: add btrfs_util_delete_subvolume()
libbtrfsutil: add btrfs_util_deleted_subvolumes()
libbtrfsutil: add filesystem sync helpers
btrfs-progs: use libbtrfsutil for read-only property
btrfs-progs: use libbtrfsutil for sync ioctls
btrfs-progs: use libbtrfsutil for set-default
btrfs-progs: use libbtrfsutil for get-default
btrfs-progs: use libbtrfsutil for subvol create and snapshot
btrfs-progs: use libbtrfsutil for subvol delete
btrfs-progs: use libbtrfsutil for subvol show
btrfs-progs: use libbtrfsutil for subvol sync
btrfs-progs: replace test_issubvolume() with btrfs_util_is_subvolume()
btrfs-progs: add recursive snapshot/delete using libbtrfsutil
btrfs-progs: use libbtrfsutil for subvolume list
btrfs-progs: deprecate libbtrfs helpers

 .gitignore                                   |    2 +
 Documentation/btrfs-subvolume.asciidoc       |   14 +-
 INSTALL                                      |    4 +
 Makefile                                     |  109 +-
 Makefile.inc.in                              |    4 +-
 btrfs-list.c                                 |  810 +----------
 btrfs-list.h                                 |  104 +-
 cmds-filesystem.c                            |   19 +-
 cmds-inspect.c                               |   10 +-
 cmds-qgroup.c                                |   21 +-
 cmds-receive.c                               |   13 +-
 cmds-subvolume.c                             | 1877 ++++++++++++++++++--------
 configure.ac                                 |   15 +
 libbtrfsutil/COPYING                         |  674 +++++++++
 libbtrfsutil/COPYING.LESSER                  |  165 +++
 libbtrfsutil/README.md                       |   38 +
 libbtrfsutil/btrfsutil.h                     |  648 +++++++++
 libbtrfsutil/btrfsutil_internal.h            |   40 +
 libbtrfsutil/errors.c                        |   55 +
 libbtrfsutil/filesystem.c                    |  103 ++
 libbtrfsutil/python/.gitignore               |    7 +
 libbtrfsutil/python/btrfsutilpy.h            |   84 ++
 libbtrfsutil/python/error.c                  |  202 +++
 libbtrfsutil/python/filesystem.c             |   94 ++
 libbtrfsutil/python/module.c                 |  321 +++++
 libbtrfsutil/python/qgroup.c                 |  141 ++
 libbtrfsutil/python/setup.py                 |  111 ++
 libbtrfsutil/python/subvolume.c              |  667 +++++++++
 libbtrfsutil/python/tests/__init__.py        |   66 +
 libbtrfsutil/python/tests/test_filesystem.py |   73 +
 libbtrfsutil/python/tests/test_qgroup.py     |   57 +
 libbtrfsutil/python/tests/test_subvolume.py  |  383 ++++++
 libbtrfsutil/qgroup.c                        |   83 ++
 libbtrfsutil/subvolume.c                     | 1368 +++++++++++++++++++
 messages.h                                   |   13 +
 props.c                                      |   69 +-
 qgroup.c                                     |  106 --
 qgroup.h                                     |    4 -
 send-utils.c                                 |   25 +-
 utils.c                                      |  152 +--
 utils.h                                      |    7 -
 41 files changed, 6899 insertions(+), 1859 deletions(-)
 create mode 100644 libbtrfsutil/COPYING
 create mode 100644 libbtrfsutil/COPYING.LESSER
 create mode 100644 libbtrfsutil/README.md
 create mode 100644 libbtrfsutil/btrfsutil.h
 create mode 100644 libbtrfsutil/btrfsutil_internal.h
 create mode 100644 libbtrfsutil/errors.c
 create mode 100644 libbtrfsutil/filesystem.c
 create mode 100644 libbtrfsutil/python/.gitignore
 create mode 100644 libbtrfsutil/python/btrfsutilpy.h
 create mode 100644 libbtrfsutil/python/error.c
 create mode 100644 libbtrfsutil/python/filesystem.c
 create mode 100644 libbtrfsutil/python/module.c
 create mode 100644 libbtrfsutil/python/qgroup.c
 create mode 100755 libbtrfsutil/python/setup.py
 create mode 100644 libbtrfsutil/python/subvolume.c
 create mode 100644 libbtrfsutil/python/tests/__init__.py
 create mode 100644 libbtrfsutil/python/tests/test_filesystem.py
 create mode 100644 libbtrfsutil/python/tests/test_qgroup.py
 create mode 100644 libbtrfsutil/python/tests/test_subvolume.py
 create mode 100644 libbtrfsutil/qgroup.c
 create mode 100644 libbtrfsutil/subvolume.c
Signature · 1 line
2.16.1