QEMU 'blockdev-add' and 'blockdev-backup' tests =============================================== Notes ----- We're testing *two* cases: (1) 'blockdev-backup' with target as device ID (e.g. 'drive-ide2-0-0') (2) 'blockdev-backup' with target as node name (e.g. 'node-backup2') Using QMP connection over UNIX socket. 'blockdev-backup'. BDSs are called as "nodes" (as they are nodes in the BDS graph). [jsnow] I am not aware of any use cases targeting a node that isn't the root node directly under a BB (BlockBackend). [mreitz] - We like to call BDSs (BlockDriverState) "nodes" (as they are nodes in the BDS graph). And you can give each BDS a name, which then is a node name. So you can not just target a device, but basically any BDS in the graph. Normally you'd use that for targeting root BDSs in a tree, so you add a BDS tree via 'blockdev-add', then you can target it via 'blockdev-mirror' or 'blockdev-backup' or whatever, and then you can do with the BDS tree whatever you like -- maybe you'd like to drop it again via 'x-blockdev-del', maybe you'd like to attach it to a device. Setup: QEMU command-line used to invoke QMP server -------------------------------------------------- #!/bin/bash /usr/bin/qemu-system-x86_64 \ -machine accel=kvm \ -name cirrvm \ -S \ -machine pc-i440fx-2.1,accel=kvm,usb=off \ -cpu SandyBridge \ -m 977 \ -realtime mlock=off \ -smp 1,sockets=1,cores=1,threads=1 \ -uuid ec9714ed-b23b-4580-99c6-b2862a5bea21 \ -nographic \ -no-user-config \ -nodefaults \ -chardev socket,id=charmonitor,path=/var/tmp/cirrvm.monitor,server,nowait \ -mon chardev=charmonitor,id=monitor,mode=control \ -rtc base=utc,driftfix=slew \ -global kvm-pit.lost_tick_policy=discard \ -no-hpet \ -no-shutdown \ -boot strict=on \ -device ich9-usb-ehci1,id=usb,bus=pci.0,addr=0x3.0x7 \ -drive file=./cirros-0.3.3.qcow2,if=none,id=drive-ide0-0-0,driver=qcow2 \ -device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \ -chardev pty,id=charserial0 \ -device isa-serial,chardev=charserial0,id=serial0 \ -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4 \ -msg timestamp=on \ -qmp unix:./qmp-sock,server --monitor stdio ----------------------------------------------------- Case-1: 'blockdev-backup' with target as device ID (e.g. 'drive-ide2-0-0') ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ----------------------------------------------------- # (1) Create the backup qcow2 file $ qemu-img create -f qcow2 backup1.qcow2 1G Formatting 'backup1.qcow2', fmt=qcow2 size=1073741824 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16 $ file backup1.qcow2 backup1.qcow2: QEMU QCOW Image (v3), 1073741824 bytes ----------------------------------------------------- # (2) Connect to the QMP server $ socat UNIX:/export/qemu-backup-tests/qmp-sock READLINE,history=$HOME/.qmp_history,prompt='QMP> ' {"QMP": {"version": {"qemu": {"micro": 0, "minor": 6, "major": 2}, "package": " (qemu-2.6.0-3.fc24)"}, "capabilities": []}} QMP> ----------------------------------------------------- # (2.1) Execute the QMP capabilities QMP> {"execute":"qmp_capabilities"} {"return": {}} ----------------------------------------------------- # (3) Add the block device: QMP> { "execute": "blockdev-add", "arguments": { "options" : { "driver": "qcow2", "id": "drive-ide2-0-0", "file": { "driver": "file", "filename": "/export/backup1.qcow2"} } } } ----------------------------------------------------- # (4) Perform 'blockdev-backup' to the target $ socat UNIX:/export/qemu-backup-tests/qmp-sock READLINE,history=$HOME/.qmp_history,prompt='QMP> ' {"QMP": {"version": {"qemu": {"micro": 0, "minor": 6, "major": 2}, "package": " (qemu-2.6.0-3.fc24)"}, "capabilities": []}} QMP> {"execute":"qmp_capabilities"} {"return": {}} QMP> { "execute": "blockdev-backup", "arguments": { "device": "drive-ide0-0-0", "target": "drive-ide2-0-0", "sync": "full" } } ----------------------------------------------------- # (5) Result of 'blockdev-backup' invocation QMP> {"execute":"qmp_capabilities"} {"return": {}} QMP> { "execute": "blockdev-backup", QMP> "arguments": { QMP> "device": "drive-ide0-0-0", QMP> "target": "drive-ide2-0-0", QMP> "sync": "full" QMP> } QMP> } {"return": {}} {"timestamp": {"seconds": 1466158164, "microseconds": 695444}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "drive-ide0-0-0", "len": 41126400, "offset": 41126400, "speed": 0, "type": "backup"}} QMP> ----------------------------------------------------- Case-2: 'blockdev-backup' with target as node-name (e.g. 'node-backup2') ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ NOTE: We're continuing on the same QMP connection from Case-1, where 'qmp_capabilities' was already executed. ----------------------------------------------------- # (1) Create the backup file $ qemu-img create -f qcow2 backup2.qcow2 1G Formatting 'backup2.qcow2', fmt=qcow2 size=1073741824 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16 $ file backup2.qcow2 backup2.qcow2: QEMU QCOW Image (v3), 1073741824 bytes ----------------------------------------------------- # (2) Invocation of 'blockdev-add' [ensure that 'node-name' is # under the root ('options'), rather than nesting _inside_ 'file'.] QMP> { "execute": "blockdev-add", "arguments": { "options" : { "driver": "qcow2", "id": "drive-ide2-0-0", "node-name": "node-backup2", "file": { "driver": "file", "filename": "/export/backup2.qcow2"} } } } ----------------------------------------------------- # (3) Result of 'blockdev-add' QMP> { "execute": "blockdev-add", QMP> "arguments": { "options" : { "driver": "qcow2", QMP> "id": "drive-ide2-0-0", QMP> "node-name": "node-backup2", QMP> "file": { "driver": "file", QMP> "filename": "/export/backup2.qcow2"} } } } {"return": {}} ----------------------------------------------------- # (4) Invocation of 'blockdev-backup' with target as 'node-name' QMP> { "execute": "blockdev-backup", "arguments": { "device": "drive-ide0-0-0", "target": "node-backup2", "sync": "full" }} ----------------------------------------------------- # (5) Result of 'blockdev-backup' QMP> { "execute": "blockdev-backup", QMP> "arguments": { QMP> "device": "drive-ide0-0-0", QMP> "target": "node-backup2", QMP> "sync": "full" }} {"return": {}} {"timestamp": {"seconds": 1466161195, "microseconds": 268589}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "drive-ide0-0-0", "len": 41126400, "offset": 41126400, "speed": 0, "type": "backup"}} ----------------------------------------------------- # (6) On the QEMU (HMP) monitor (qemu) info block drive-ide0-0-0 (#block190): ./cirros-0.3.3.qcow2 (qcow2) Cache mode: writeback drive-ide2-0-0 (node-backup2): /export/backup2.qcow2 (qcow2) Removable device: not locked, tray closed Cache mode: writeback (qemu) ----------------------------------------------------- * * * To delete the block device (NB: The 'x' indicates it is experimental.): QMP> {'execute':'x-blockdev-del', 'arguments': { 'id': 'drive-ide2-0-0'}} {"return": {}}