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

Peter Luo d8514 at sina.com
Fri Jan 31 11:14:46 UTC 2020


Hi Peter Krempa,

Thanks for your quick response, yes, I know since libvirt 5.8, the -blockdev is used for disk by default. 
However we have to maintain the old releases for the production environment for a while, so I still need use the old way to create the disk. 

    >"base" argument must be a string. this means you need double quotes in
    >JSON ("). You also must properly escape any further JSON. > 
      
    Do you mean the base argument need be formatted like below?
    \"base\":\"json:{\"encrypt.key-secret\":\"vol-38973xjl.secret\",\"driver\":\"qcow2\",\"file\":{\"driver\":\"file\",\"filename\":\"/pitrix/data/container/vol-38973xjl.img\"}}\"

    Please help me to point out where the examples are located? I did take a quick look at those test files, but no one seems to be matched with my case.

Thanks,
Peter Luo

On 31/1/20, 6:52 PM, "Peter Krempa" <pkrempa at redhat.com> wrote:

    
    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 at 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.
    
    
    
    







More information about the libvirt-users mailing list