btrfs-progs icon indicating copy to clipboard operation
btrfs-progs copied to clipboard

Python lib error: undefined symbol: btrfs_util_subvolume_is_valid

Open mhkarimi1383 opened this issue 6 months ago • 1 comments

Getting

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/rawfile/rawfile.py", line 5, in <module>
    import bd2fs
  File "/rawfile/bd2fs.py", line 24, in <module>
    from filesystem import get_from_device_or_fallback
  File "/rawfile/filesystem/__init__.py", line 4, in <module>
    from .btrfs import BTRFS
  File "/rawfile/filesystem/btrfs.py", line 11, in <module>
    from btrfsutil import (
    ...<6 lines>...
    )
ImportError: /opt/pysetup/.venv/lib/python3.13/site-packages/btrfsutil.cpython-313-x86_64-linux-gnu.so: undefined symbol: btrfs_util_subvolume_is_valid

while using ‍btrfsutil in python

Here is my complete import statement

from btrfsutil import (
    create_subvolume,
    set_default_subvolume,
    get_default_subvolume,
    subvolume_path,
    create_snapshot,
    delete_subvolume,
)

mhkarimi1383 avatar Jun 10 '25 17:06 mhkarimi1383

strings /opt/pysetup/.venv/lib/python3.13/site-packages/btrfsutil.cpython-313-x86_64-linux-gnu.so  | grep btrfs_util_subvolume_is_valid 
btrfs_util_subvolume_is_valid
btrfs_util_subvolume_is_valid_fd
btrfs_util_subvolume_is_valid_fd
btrfs_util_subvolume_is_valid
btrfs_util_subvolume_is_valid
btrfs_util_subvolume_is_valid_fd

shows that btrfs_util_subvolume_is_valid is available but I can't use btrfsutil

mhkarimi1383 avatar Jun 12 '25 11:06 mhkarimi1383

Right, this is a bug in the exported functions from python that do not match the new symbol aliases added in 0.1.3 (27e965f53887697f4a2108b6315ddb3ddb460748, 6.7).

kdave avatar Sep 15 '25 04:09 kdave

The fix is (probably) just mechanical:

  • add aliases to the implementations in libbtrfsutil/python/*.c, eg. for is_subvolume add __attribute__((alias(orig))) subvolume_is_valid
  • copy the entry in libbtrfsutil/python/module.c for each new alias
  • update libbtrfsutil/python/btrfsutilpy.h publich with the new aliases
  • add coverage for the aliases to the tests: replace old names with aliases and add a simple test for the old names only

kdave avatar Sep 15 '25 04:09 kdave

@kdave

We have moved from btrfsutil into using commands since they are more stable and it was a long time since this issue has been created

mhkarimi1383 avatar Sep 15 '25 10:09 mhkarimi1383

Yeah, understandable. Unfortunatelly the util and python library has been neglected, mostly fixups. But you've uncovered a big deficiency in the API, it'll get fixed over time so you might use the bindings again in the future.

kdave avatar Sep 15 '25 20:09 kdave

Fixed in devel.

kdave avatar Nov 07 '25 05:11 kdave