[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Does Libvirt's json parser support single quoted string in qmp json string?

On 1/31/20 4:38 AM, Peter Luo wrote:

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

                      (right here) ------^

qemu's QMP language has an extension where it accepts 'string' in addition to the JSON "string". But it uses a hand-rolled parser, so it can do whatever it wants.

But virsh uses a 3rd-party JSON parser. When using 'virsh qemu-monitor-command', your command line argument HAS to be valid JSON, or virsh can't parse it; and if virsh can't parse it, libvirt can't pass it on to qemu (even if qemu would have parsed it as written). To write JSON inside JSON, you have to do things like:


Attempt 2: Single quote with 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

In shell quoting, "\'" and "'" are identical. The \ never reached libvirt. Your choices for proper shell quoting include:

'{"execute":... "base":"json:{\"encrypt.key-secret\":\"vol...
"{\"execute\":... \"base\":\"json:{\\\"encrypt.key-secret\\\":\\\"vol...

or even things like:
"{${q}execute${q}:... ${q}base${q}:${q}json:{${dq}encrypt.key-secret${dq}:${dq}vol...

But as mentioned elsewhere in this thread, embedding nested json via qemu-monitor-command is already a sign that you are using unsupported means, and where newer libvirt supports what you want to do natively, you're better off upgrading to that supported method instead of trying to hack around the command line through an unsupported backdoor.

Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]