libbtrfsutil + python = UUID confusion?
I wanted to see how much btrfs-progs' python binding likes python-3.9, so that it can be enabled for Gentoo's ebuild. First let's verify that it works correctly with 3.8..
holger>python3.8
Python 3.8.6 (default, Sep 25 2020, 11:47:38)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
import btrfsutil
i=btrfsutil.subvolume_info("/mnt/data1")
i
btrfsutil.SubvolumeInfo(id=5, parent_id=0, dir_id=0, flags=0, uuid=b'S\x98\xa9\xc8\xaa0FX\xb3\xcf\xca\xaf\x03\xe9\xf8S', parent_uuid=b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', received_uuid=b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', generation=8349, ctransid=8349, otransid=0, stransid=0, rtransid=0, ctime=1602972626.0, otime=1566909923.0)
Quoted 1 line
Quoted 1 line
Quoted 1 line
i.uuid
b'S\x98\xa9\xc8\xaa0FX\xb3\xcf\xca\xaf\x03\xe9\xf8S'
Hm, that's unreadable. Let's make a UUID from those bytes:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
import uuid
uuid.UUID(bytes=i.uuid)
UUID('5398a9c8-aa30-4658-b3cf-caaf03e9f853')
Yeah no wait what? The expected fsid of /mnt/data1 is "14831af0-32d2-40b7-98c9-ca5467910a8c".
What do the UUID's bytes look like as hex?
Quoted 1 line
Quoted 1 line
Quoted 1 line
i.uuid.hex()
'5398a9c8aa304658b3cfcaaf03e9f853'
..not helping..
Just for funsies let's see what python-btrfs has to say (since it already works fine with 3.9):
holger>python3.9
Python 3.9.0 (default, Oct 13 2020, 23:55:04)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
import btrfs
btrfs.FileSystem("/mnt/data1").fs_info().fsid
UUID('14831af0-32d2-40b7-98c9-ca5467910a8c')
Looks correct. We need to go deeper!
btrfsutil.h defines the UUID as:
/** @uuid: UUID of this subvolume. */
uint8_t uuid[16];..and indeed the wrong bytes sequence (5398..) has 32 characters aka 16 bytes, so we're not too far off. What should the correct byte representation look like?
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
import uuid u=uuid.UUID('14831af0-32d2-40b7-98c9-ca5467910a8c') u.bytes
b'\x14\x83\x1a\xf02\xd2@\xb7\x98\xc9\xcaTg\x91\n\x8c'
Soo..am I holding it wrong or is this a case of Python-2.7/3.x string-vs-bytes confusion? I see in btrfs-progs/libbtrfsutil/subvolume.c that get_subvolume_info_unprivileged() simply copies the UUID bytes received from the ioctl, but I'm not sure what else can or should happen to them. One suspect (to me) seems the "PyBytes_FromStringAndSize" in:
https://github.com/kdave/btrfs-progs/blob/master/libbtrfsutil/python/subvolume.c#L121
Any other ideas? Should this go into the btrfs-progs bug tracker?
(paging Dr. Sandoval..)
cheers
Holger
Hi,
Quoted 16 lines · Holger Hoffstätte
I wanted to see how much btrfs-progs' python binding likes python-3.9, so that it can be enabled for Gentoo's ebuild. First let's verify that it works correctly with 3.8..
holger>python3.8 Python 3.8.6 (default, Sep 25 2020, 11:47:38) [GCC 10.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import btrfsutil >>> i=btrfsutil.subvolume_info("/mnt/data1") >>> i btrfsutil.SubvolumeInfo(id=5, parent_id=0, dir_id=0, flags=0, uuid=b'S\x98\xa9\xc8\xaa0FX\xb3\xcf\xca\xaf\x03\xe9\xf8S', parent_uuid=b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', received_uuid=b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', generation=8349, ctransid=8349, otransid=0, stransid=0, rtransid=0, ctime=1602972626.0, otime=1566909923.0) >>> i.uuid b'S\x98\xa9\xc8\xaa0FX\xb3\xcf\xca\xaf\x03\xe9\xf8S'
Quoted 8 lines
Hm, that's unreadable. Let's make a UUID from those bytes:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
import uuid
uuid.UUID(bytes=i.uuid)UUID('5398a9c8-aa30-4658-b3cf-caaf03e9f853')
Yeah no wait what? The expected fsid of
/mnt/data1is "14831af0-32d2-40b7-98c9-ca5467910a8c".
A subvolume (actually, the root_item object) also has a uuid field. It's the uuid of the subvolume itself.
Quoted 10 lines
What do the UUID's bytes look like as hex?
Quoted 1 line
Quoted 1 line
Quoted 1 line
i.uuid.hex()'
5398a9c8aa304658b3cfcaaf03e9f853'..not helping..
Just for funsies let's see what python-btrfs has to say (since it already works fine with 3.9):
Quoted 7 lines
holger>python3.9
Python 3.9.0 (default, Oct 13 2020, 23:55:04)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import btrfs
>>> btrfs.FileSystem("/mnt/data1").fs_info().fsid
UUID('14831af0-32d2-40b7-98c9-ca5467910a8c')That's the fsid yes.
Quoted 7 lines
Looks correct. We need to go deeper!
btrfsutil.hdefines the UUID as:/** @uuid: UUID of this subvolume. */ uint8_t uuid[16];
Quoted 7 lines
..and indeed the wrong bytes sequence (5398..) has 32 characters aka 16 bytes, so we're not too far off. What should the correct byte representation look like?
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
import uuid u=uuid.UUID('14831af0-32d2-40b7-98c9-ca5467910a8c') u.bytes
b'\x14\x83\x1a\xf02\xd2@\xb7\x98\xc9\xcaTg\x91\n\x8c'
What if you do btrfs sub show /mnt/data1 and then look at the UUID:
field? Is it 5398a9c8-aa30-4658-b3cf-caaf03e9f853?
Quoted 8 lines
Soo..am I holding it wrong or is this a case of Python-2.7/3.x string-vs-bytes confusion? I see in
btrfs-progs/libbtrfsutil/subvolume.cthatget_subvolume_info_unprivileged()simply copies the UUID bytes received from the ioctl, but I'm not sure what else can or should happen to them. One suspect (to me) seems the "PyBytes_FromStringAndSize" in:
https://github.com/kdave/btrfs-progs/blob/master/libbtrfsutil/python/subvolume.c#L121Any other ideas? Should this go into the btrfs-progs bug tracker?
K
tl;dr: I can't read.
Quoted 7 lines · Hans van Kranenburg
Hi,
Quoted 4 lines · Holger Hoffstätte
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
import uuid
uuid.UUID(bytes=i.uuid)UUID('5398a9c8-aa30-4658-b3cf-caaf03e9f853')
Quoted 5 lines
Quoted 2 lines
Yeah no wait what? The expected fsid of
/mnt/data1is "14831af0-32d2-40b7-98c9-ca5467910a8c".A subvolume (actually, the
root_itemobject) also has a uuid field. It's the uuid of the subvolume itself.
Yes, it has. I swear I had the same thought yesterday, and somehow missed it nevertheless.
Quoted 2 lines
What if you do btrfs sub show
/mnt/data1and then look at the UUID:
field? Is it 5398a9c8-aa30-4658-b3cf-caaf03e9f853?
Yes, of course it is. Thank you.
Holger