REF:
Stefan Hajnoczi: Using qemu-img to access vhost-user-blk storage
要求qemu带libblkio支持
root@10-5-245-135:~# /opt/qemu/bin/qemu-system-x86_64 --version
QEMU emulator version 8.2.3
Copyright (c) 2003-2023 Fabrice Bellard and the QEMU Project developers
先用qsd启动一个vhost-user-blk的服务端:
root@10-5-245-135:~# /opt/qemu/bin/qemu-storage-daemon --blockdev file,filename=/var/lib/libvirt/images/test.qcow2,node-name=file --blockdev qcow2,file=file,node-name=qcow2 --export vhost-user-blk,id=exp0,node-name=qcow2,num-queues=1,writable=on,addr.type=unix,addr.path=/tmp/vhost.sock &
qemu-img通过sock访问vhost-user-blk
root@10-5-245-135:~# /opt/qemu/bin/qemu-img info --image-opts driver=virtio-blk-vhost-user,path=/tmp/vhost.sock,cache.direct=on
image: json:{"driver": "virtio-blk-vhost-user"}
file format: virtio-blk-vhost-user
virtual size: 10 GiB (10737418240 bytes)
disk size: unavailable
还能导出
root@10-5-245-135:~# /opt/qemu/bin/qemu-img convert --image-opts driver=virtio-blk-vhost-user,path=/tmp/vhost.sock,cache.direct=on /var/lib/libvirt/images/out.qcow2
或者导出为qcow2:
root@10-5-245-135:~# /opt/qemu/bin/qemu-img convert -O qcow2 --image-opts driver=virtio-blk-vhost-user,path=/tmp/vhost.sock,cache.direct=on /var/lib/libvirt/images/out.qcow2
如果vhost-user-blk后端是spdk的话,会报错,后端不支持所要求的协议特性
root@10-5-245-135:~# /opt/qemu/bin/qemu-img info --image-opts driver=virtio-blk-vhost-user,path=/var/tmp/vhost.1,cache.direct=on
qemu-img: Could not open 'driver=virtio-blk-vhost-user,path=/var/tmp/vhost.1,cache.direct=on': blkio_connect failed: Backend doesn't support required protocol features: Input/output error