On Fri, Jan 31, 2020 at 18:38:33 +0800, Peter Luo wrote:
Hi All,
I’m using qmp command via “virsh qemu-monitor-command” to perform block related jobs.
And in my case, I execute block-commit to commit the changes in the top image to the base
image which is encrypted.
So in the base parameter, I need a json string which is single quoted to support the
encryption parameters.
However, the virsh is failed to parse the whole json qmp command.
None of the above should be required with libvirt-5.10 and later when
using qemu-4.2. Those two versions start using blockdev way of
specifying images and encrypted images are supported.
Please consider using libvirt-6.0 though as there are few fixes for
blockdev.
Attempt 1: Single quote without backflash, failed
root@host:~# virsh qemu-monitor-command i-9wdfw2x8 "{\"execute\":
\"block-commit\", \"arguments\": { \"device\":
\"drive-virtio-disk2\", \"job-id\": \"job100\",
\"base\":'json:{\"encrypt.key-secret\":\"vol-38973xjl.secret\",\"driver\":\"qcow2\",\"file\":{\"driver\":\"file\",\"filename\":\"/pitrix/data/container/vol-38973xjl.img\"}}',
\"top\":
\"/pitrix/data/container/vol-38973xjl_ss-2tw7v0mm.img\"}}"
error: internal error: cannot parse json {"execute": "block-commit",
"arguments": { "device": "drive-virtio-disk2",
"job-id": "job100",
"base":'json:{"encrypt.key-secret":"vol-38973xjl.secret","driver":"qcow2","file":{"driver":"file","filename":"/pitrix/data/container/vol-38973xjl.img"}}',
"top": "/pitrix/data/container/vol-38973xjl_ss-2tw7v0mm.img"}}:
lexical error: invalid char in json text.
, "job-id": "job100",
"base":'json:{"encrypt.key-secret":"vo
"base" argument must be a string. this means you need double quotes in
JSON ("). You also must properly escape any further JSON.
Given that libvirt now supports the operation natively I'll refrain from
elaborating on how to properly escape JSON to contain JSON strings, but
there are few examples in the test suite.
But please use the upstream supported way instead.