wrapping wrappers

We went for a longer walk yesterday morning at a local park we hadn't yet explored much. There were a few other dog walkers in the lot when we arrived but we managed to avoid everybody the entire hour and a half we were there.

It finally rained this week. The water level in the creek is still low but high enough for Dany to indulge her inner salamander.

I bought a hammock for the backyard last year and only finally figured out adding netting around it this week. I saw more specially purposed designs, but those don't fit the hammock I have because of course past me had to get something incompatible thank you, manufacturers. The setup is hackish but functional enough, a sheet draped over jute twine strung between the frame. A mosquito tried attacking through the mesh but, ensared in the folds, I had advantage to kill it, which I seized. Take that, Clytemnestra.

Unfortunately the current interface design also kept Teemo from indulging his inner mosquito.

Meanwhile I've been thinking through code-based wrapper interfaces. For the sake of a little POC I built an ext2fs filesystem in a layered qcow2 image that I NBD exported over a domain socket.

$ mke2fs base.img 10M

mke2fs 1.46.5 (30-Dec-2021)
Creating regular file base.img
Creating filesystem with 10240 1k blocks and 2560 inodes
Filesystem UUID: 6a7a69a7-ec27-4ff9-8a2a-2131851bb27a
Superblock backups stored on blocks:
        8193

Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done

$ qemu-img convert \
           -f raw \
           -O qcow2 \
           base.img \
           base.qcow2

$ qemu-img create \
           -F qcow2 \
           -b base.qcow2 \
           -f qcow2 \
           layer.qcow2

Formatting 'layer.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=10485760 backing_file=base.qcow2 backing_fmt=qcow2 lazy_refcounts=off refcount_bits=16

$ qemu-nbd --read-only \
           --socket ${PWD}/nbd.sock \
           --format qcow2 \
           layer.qcow2

I installed libnbd and was able to verify the superblock magic number through python.

import nbd

h = nbd.NBD()
h.connect_uri("nbd+unix:///?socket=nbd.sock")
buf = h.pread(1024, 1024)
bytes(reversed(buf[56:58])) == b"\xef\x53"
h.shutdown()

From here I want to expose the IO manager interface to the pyext2fs library, which presently only supports reading from local raw image files. With that I should be able to implement a thin wrapper that defers to those libnbd calls.