On Wed, Nov 21, 2018 at 11:33:33AM +0800, Han Han wrote:
Hello, I face a problem on the nbdkit server:
Version-Release number of selected component (if applicable):
nbdkit-v1.9.1
qemu-utils-2.12+dfsg-3+b1
How reproducible:
100%
Steps:
1. Create a qcow2 file
# qemu-img create disk 1G -f qcow2
This creates a 1GB virtual size qcow2 (real size is about 196K):
$ ll disk
-rw-rw-r--. 1 rjones rjones 196624 Nov 21 09:20 disk
$ file disk
disk: QEMU QCOW Image (v3), 1073741824 bytes
2. Export the qcow2 file then try to read it via nbd url
# nbdkit file file=disk -e raw -v
This exports the disk using the export name "raw". However nbdkit
doesn't know anything about qcow2, so this exports bytes of qcow2 data
to the client. The virtual size of the disk will be about 196K, and
it won't be resizable (so you cannot write to it).
Note that the -e (export name) option is not used by nbdkit so you
don't need it.
3. Try to read the file via nbd:
# qemu-img info
nbd://localhost/raw
What precisely happens here is that qemu-img sees a qcow2 file and
tries to read beyond the end of the file:
nbdkit: file.2: error: invalid request: offset and count are out of range: offset=196608
count=512
If you want to export a qcow2 file, then it's better to use qemu-nbd
since it knows about the qcow2 format:
$ qemu-nbd -t disk &
$ qemu-img info nbd://localhost
image: nbd://localhost:10809
file format: raw
virtual size: 1.0G (1073741824 bytes)
disk size: unavailable
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html