[24-FEB-2017] Use case ~~~~~~~~ Provide an NBD export that serves you a (read-only?) point-in-time (PIT) snapshot of a disk. [Also sometimes referred to as "Image Fleecing"] This test uses QEMU block primitives. Tested with QEMU Git: $ git describe pull-block-2017-02-21-81-g612bb5d High level procedure ~~~~~~~~~~~~~~~~~~~~ (1) Create the target image ('target.qcow2') $ qemu-img create -f qcow2 target.qcow2 1G (2) Add the above via `blockdev-add` to the running QEMU instance, with 'base.qcow2' as its backing file. (3) Run `query-named-block-nodes` to find the node name (automatically assigned, if it wasn't specified) of base.qcow2: https://kashyapc.fedorapeople.org/virt/qemu/query-named-block-nodes-QMP-return.txt (4) Take the backup of device 'base.qcow2' into 'target.qcow2' using 'blockdev-backup' (using node names "node-name":"#block197" for base.qcow2; "node1" for target.qcow2) (5) Then, export 'target.qcow2' over NBD with `nbd-server-start`, and `nbd-server-add`. (6) Discard the NBD export at anytime you wish (with 'nbd-server-stop') Test with 'qmp-shell' ~~~~~~~~~~~~~~~~~~~~~ [$ qemu-img create -f qcow2 /export/target.qcow2 1G] (QEMU) blockdev-add driver=qcow2 node-name=node2 file={"driver":"file","filename":"/export/target.qcow2"} backing={"driver":"qcow2","file":{"driver":"file","filename":"/export/base.qcow2"}} (QEMU) query-named-block-nodes (QEMU) blockdev-backup device=#block197 target=node1 sync=none (QEMU) nbd-server-start addr={"type":"unix","data":{"path":"./nbd-sock"}} (QEMU) nbd-server-add device=node1 (QEMU) nbd-server-stop With complete JSON ~~~~~~~~~~~~~~~~~~ Fire up QEMU on shell 1: $ ~/build/qemu-upstream/x86_64-softmmu/qemu-system-x86_64 \ -display none -nodefconfig -nodefaults -m 512 \ -device virtio-scsi-pci,id=scsi -device virtio-serial-pci \ -drive file=./base.qcow2,format=qcow2,if=virtio -monitor stdio \ -qmp unix:./qmp-sock,server,nowait QEMU 2.8.50 monitor - type 'help' for more information (qemu) On shell 2: ------- $ qemu-img create -f qcow2 /export/target.qcow2 1G Formatting '/export/target.qcow2', fmt=qcow2 size=1073741824 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16 ------- $ ~/build/qemu-upstream/x86_64-softmmu/qemu-system-x86_64 --version QEMU emulator version 2.8.50 (v2.8.0-1462-g612bb5d-dirty) Copyright (c) 2003-2016 Fabrice Bellard and the QEMU Project developers ------- $ socat UNIX:/export/qmp-sock READLINE,history=$HOME/.qmp_history,prompt='QMP> ' {"QMP": {"version": {"qemu": {"micro": 50, "minor": 8, "major": 2}, "package": " (v2.8.0-1462-g612bb5d-dirty)"}, "capabilities": []}} QMP> {"execute":"qmp_capabilities"} {"return": {}} ------- { "execute":"blockdev-add", "arguments":{ "driver":"qcow2", "node-name":"node1", "file":{ "driver":"file", "filename":"/export/target.qcow2" }, "backing":{ "driver":"qcow2", "file":{ "driver":"file", "filename":"/export/base.qcow2" } } } } ------- [Run "query-named-block-nodes" and find the node name of 'base.qcow2', which is "#block197" in this case, which was automatically assigned.] https://kashyapc.fedorapeople.org/virt/qemu/query-named-block-nodes-QMP-return.txt ------- { "execute":"blockdev-backup", "arguments":{ "device":"#block197", "target":"node1", "sync":"none" } } ------- QMP> { QMP> "execute":"blockdev-backup", QMP> "arguments":{ QMP> "device":"#block197", QMP> "target":"node1", QMP> "sync":"none" QMP> } QMP> } {"return": {}} ------- { "execute":"nbd-server-start", "arguments":{ "addr":{ "data":{ "path":"./nbd-sock" }, "type":"unix" } } } ------- { "execute":"nbd-server-add", "arguments":{ "device":"node1" } } ------- { "execute":"nbd-server-stop" } ------- * * *