On Mon, Oct 30, 2023 at 03:26:58PM +0100, Kevin Wolf wrote:
> Until now, array properties are actually implemented with a hack that
> uses multiple properties on the QOM level: a static "foo-len" property
> and after it is set, dynamically created "foo[i]" properties.
> 
> In external interfaces (-device on the command line and device_add in
> QMP), this interface was broken by commit f3558b1b ('qdev: Base object
> creation on QDict rather than QemuOpts') because QDicts are unordered
> and therefore it could happen that QEMU tried to set the indexed
> properties before setting the length, which fails and effectively makes
> array properties inaccessible. In particular, this affects the 'ports'
> property of the 'rocker' device, which used to be configured like this:
> 
> -device rocker,len-ports=2,ports[0]=dev0,ports[1]=dev1

If you tweak the commit message, you might also want to mention that
this form is a shell-glob deathtrap (if you are unlucky enough to have
a file named rocker,len-ports=2,ports0=dev0,ports1=dev1 in the current
directory), and therefore should have used shell quoting...

> 
> This patch reworks the external interface so that instead of using a
> separate top-level property for the length and for each element, we use
> a single true array property that accepts a list value. In the external
> interfaces, this is naturally expressed as a JSON list and makes array
> properties accessible again. The new syntax looks like this:
> 
> -device '{"driver":"rocker","ports":["dev0","dev1"]}'

...at which point, the fact that you HAVE to use shell quoting to get
JSON through the command line is less onerous than if the older syntax
had been safe without quotes.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org


Reply via email to