On 8/10/20 7:35 AM, Denis V. Lunev wrote:
The problem this patch is trying to address is libguestfs behavior on the appliance startup. It starts supporting to use root=UUID definition in the kernel command line of its root filesystem using file -- /usr/lib64/guestfs/appliance/root This works fine with RAW image, but we are using QCOW2 as a storage to save a bit of file space and in this case we get QEMU QCOW Image (v3), 1610612736 bytes instead of UUID of the root filesystem.The solution is very simple - we should dump first 256k of the image file like the follows qemu-io -c "read -V 0 256k" appliance | file - which will provide correct result for all possible types of the appliance storage.
Is 'appliance' a qcow2 file? If so, another way to accomplish this could include:
nbdkit streaming --run 'qemu-img convert --image-opts driver=raw,size=256,file.driver=qcow2,file.file.driver=file,file.file.filename=appliance "$uri"' | file -
which says to use qemu-img to open a length-limited view of the file, and stream the entire thing to an NBD server, where nbdkit then provides a way to convert that to a pipeline to feed into file (since qemu's NBD server doesn't directly like writing into a pipe).
I'm also wondering if the 'nbdcopy' program (not yet released in a stable version, but available in libnbd.git) could be put to use on this front, with some way to quickly combine it with qemu-nbd serving appliance.qcow2.
Unfortunately, additional option for qemu-io is the only and the simplest solution as '-v' creates very specific output, which requires to be parsed. 'qemu-img dd of=/dev/stdout' does not work and the fix would be much more intrusive.
'qemu-img dd' _should_ be merely syntactic sugar for 'qemu-img convert', but it isn't yet. Until we rectify that feature parity (there are things that dd can't do like better output control and skipping, and there are things that convert can't do like length limiting and offset selection), hacking up 'qemu-io' (which is for debugging use only) is a tolerable short-term solution; but qemu-io was NEVER intended for stable use cases. If adding this makes debugging qemu easier, then go for it; but if the real problem is that qemu-img is missing functionality, we should instead be focusing on fixing qemu-img.
-- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
