All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vl: transform QemuOpts device to JSON syntax device
@ 2022-02-24  6:06 Zhenzhong Duan
  2022-02-24  9:02 ` Daniel P. Berrangé
  2022-02-24 11:31 ` Kevin Wolf
  0 siblings, 2 replies; 7+ messages in thread
From: Zhenzhong Duan @ 2022-02-24  6:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, pkrempa, mst, lersek, pbonzini, eblake

While there are mixed use of traditional -device option and JSON
syntax option, QEMU reports conflict, e.x:

/usr/libexec/qemu-kvm -nodefaults \
  -device '{"driver":"virtio-scsi-pci","id":"scsi0","bus":"pci.0","addr":"0x02.0"}' \
  -device virtio-scsi-pci,id=scsi1,bus=pci.0

It breaks with:

qemu-kvm: -device {"driver":"virtio-scsi-pci","id":"scsi0","bus":"pci.0","addr":"0x02.0"}: PCI: slot 2 function 0 not available for virtio-scsi-pci, in use by virtio-scsi-pci

But if we reformat first -device same as the second, so only same kind
of option for all the devices, it succeeds, vice versa. e.x:

/usr/libexec/qemu-kvm -nodefaults \
  -device virtio-scsi-pci,id=scsi0,bus=pci.0,addr=02.0 \
  -device virtio-scsi-pci,id=scsi1,bus=pci.0

Succeed!

Because both kind of options are inserted into their own list and
break the order in QEMU command line during BDF auto assign. Fix it
by transform QemuOpts into JSON syntax and insert in JSON device
list, so the order in QEMU command line kept.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
 softmmu/vl.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index 1fe028800fdf..3def40b5405e 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -3394,21 +3394,26 @@ void qemu_init(int argc, char **argv, char **envp)
                 qdict_put_str(machine_opts_dict, "usb", "on");
                 add_device_config(DEV_USB, optarg);
                 break;
-            case QEMU_OPTION_device:
+            case QEMU_OPTION_device: {
+                QObject *obj;
                 if (optarg[0] == '{') {
-                    QObject *obj = qobject_from_json(optarg, &error_fatal);
-                    DeviceOption *opt = g_new0(DeviceOption, 1);
-                    opt->opts = qobject_to(QDict, obj);
-                    loc_save(&opt->loc);
-                    assert(opt->opts != NULL);
-                    QTAILQ_INSERT_TAIL(&device_opts, opt, next);
+                    obj = qobject_from_json(optarg, &error_fatal);
                 } else {
-                    if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
-                                                 optarg, true)) {
+                    opts = qemu_opts_parse_noisily(qemu_find_opts("device"),
+                                                   optarg, true);
+                    if (!opts) {
                         exit(1);
                     }
+                    obj = QOBJECT(qemu_opts_to_qdict(opts, NULL));
+                    qemu_opts_del(opts);
                 }
+                DeviceOption *opt = g_new0(DeviceOption, 1);
+                opt->opts = qobject_to(QDict, obj);
+                loc_save(&opt->loc);
+                assert(opt->opts != NULL);
+                QTAILQ_INSERT_TAIL(&device_opts, opt, next);
                 break;
+            }
             case QEMU_OPTION_smp:
                 machine_parse_property_opt(qemu_find_opts("smp-opts"),
                                            "smp", optarg);
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] vl: transform QemuOpts device to JSON syntax device
  2022-02-24  6:06 [PATCH] vl: transform QemuOpts device to JSON syntax device Zhenzhong Duan
@ 2022-02-24  9:02 ` Daniel P. Berrangé
  2022-02-24  9:09   ` Peter Krempa
  2022-02-24 11:31 ` Kevin Wolf
  1 sibling, 1 reply; 7+ messages in thread
From: Daniel P. Berrangé @ 2022-02-24  9:02 UTC (permalink / raw)
  To: Zhenzhong Duan; +Cc: kwolf, pkrempa, mst, eblake, qemu-devel, pbonzini, lersek

On Thu, Feb 24, 2022 at 02:06:53PM +0800, Zhenzhong Duan wrote:
> While there are mixed use of traditional -device option and JSON
> syntax option, QEMU reports conflict, e.x:
> 
> /usr/libexec/qemu-kvm -nodefaults \
>   -device '{"driver":"virtio-scsi-pci","id":"scsi0","bus":"pci.0","addr":"0x02.0"}' \
>   -device virtio-scsi-pci,id=scsi1,bus=pci.0

Why are you attempting to mix JSON and non-JSON syntax at the same
time ? The expectation is that any mgmt app adopting JSON syntax
will do so universally and not mix old and new syntax. So in practice
the scenario above is not one that QEMU ever intended to have used
by apps.


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] vl: transform QemuOpts device to JSON syntax device
  2022-02-24  9:02 ` Daniel P. Berrangé
@ 2022-02-24  9:09   ` Peter Krempa
  2022-02-24  9:13     ` Daniel P. Berrangé
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Krempa @ 2022-02-24  9:09 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: kwolf, mst, Zhenzhong Duan, qemu-devel, eblake, pbonzini, lersek

On Thu, Feb 24, 2022 at 09:02:02 +0000, Daniel P. Berrangé wrote:
> On Thu, Feb 24, 2022 at 02:06:53PM +0800, Zhenzhong Duan wrote:
> > While there are mixed use of traditional -device option and JSON
> > syntax option, QEMU reports conflict, e.x:
> > 
> > /usr/libexec/qemu-kvm -nodefaults \
> >   -device '{"driver":"virtio-scsi-pci","id":"scsi0","bus":"pci.0","addr":"0x02.0"}' \
> >   -device virtio-scsi-pci,id=scsi1,bus=pci.0
> 
> Why are you attempting to mix JSON and non-JSON syntax at the same
> time ? The expectation is that any mgmt app adopting JSON syntax
> will do so universally and not mix old and new syntax. So in practice
> the scenario above is not one that QEMU ever intended to have used
> by apps.

Based on the previous post they are using some 'qemu:commandline'
overrides with the legacy syntax with new libvirt which uses JSON
syntax:

<qemu:commandline>
  <qemu:arg value='-netdev'/>
    <qemu:arg value='user,id=mynet0,hostfwd=tcp::44483-:22'/>
    <qemu:arg value='-device'/>
  <qemu:arg value='virtio-net-pci,netdev=mynet0,mac=00:16:3E:68:00:10,romfile='/>
</qemu:commandline>

I suggested that they should add the required functionality to libvirt
instead of trying to hack qemu:

https://lists.gnu.org/archive/html/qemu-devel/2022-02/msg05068.html



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] vl: transform QemuOpts device to JSON syntax device
  2022-02-24  9:09   ` Peter Krempa
@ 2022-02-24  9:13     ` Daniel P. Berrangé
  2022-02-24 11:19       ` Duan, Zhenzhong
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel P. Berrangé @ 2022-02-24  9:13 UTC (permalink / raw)
  To: Peter Krempa
  Cc: kwolf, mst, Zhenzhong Duan, qemu-devel, eblake, pbonzini, lersek

On Thu, Feb 24, 2022 at 10:09:35AM +0100, Peter Krempa wrote:
> On Thu, Feb 24, 2022 at 09:02:02 +0000, Daniel P. Berrangé wrote:
> > On Thu, Feb 24, 2022 at 02:06:53PM +0800, Zhenzhong Duan wrote:
> > > While there are mixed use of traditional -device option and JSON
> > > syntax option, QEMU reports conflict, e.x:
> > > 
> > > /usr/libexec/qemu-kvm -nodefaults \
> > >   -device '{"driver":"virtio-scsi-pci","id":"scsi0","bus":"pci.0","addr":"0x02.0"}' \
> > >   -device virtio-scsi-pci,id=scsi1,bus=pci.0
> > 
> > Why are you attempting to mix JSON and non-JSON syntax at the same
> > time ? The expectation is that any mgmt app adopting JSON syntax
> > will do so universally and not mix old and new syntax. So in practice
> > the scenario above is not one that QEMU ever intended to have used
> > by apps.
> 
> Based on the previous post they are using some 'qemu:commandline'
> overrides with the legacy syntax with new libvirt which uses JSON
> syntax:
> 
> <qemu:commandline>
>   <qemu:arg value='-netdev'/>
>     <qemu:arg value='user,id=mynet0,hostfwd=tcp::44483-:22'/>
>     <qemu:arg value='-device'/>
>   <qemu:arg value='virtio-net-pci,netdev=mynet0,mac=00:16:3E:68:00:10,romfile='/>
> </qemu:commandline>
> 
> I suggested that they should add the required functionality to libvirt
> instead of trying to hack qemu:
> 
> https://lists.gnu.org/archive/html/qemu-devel/2022-02/msg05068.html

Or the other answer is to switch to use JSON syntax in the above command
line passthrough config.

Or to specify the PCI address so it doesn't clash with other devices
already present.

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH] vl: transform QemuOpts device to JSON syntax device
  2022-02-24  9:13     ` Daniel P. Berrangé
@ 2022-02-24 11:19       ` Duan, Zhenzhong
  0 siblings, 0 replies; 7+ messages in thread
From: Duan, Zhenzhong @ 2022-02-24 11:19 UTC (permalink / raw)
  To: Daniel P. Berrangé, Peter Krempa
  Cc: kwolf, mst, eblake, qemu-devel, pbonzini, lersek



>-----Original Message-----
>From: Daniel P. Berrangé <berrange@redhat.com>
>Sent: Thursday, February 24, 2022 5:14 PM
>To: Peter Krempa <pkrempa@redhat.com>
>Cc: Duan, Zhenzhong <zhenzhong.duan@intel.com>; qemu-
>devel@nongnu.org; kwolf@redhat.com; mst@redhat.com;
>lersek@redhat.com; pbonzini@redhat.com; eblake@redhat.com
>Subject: Re: [PATCH] vl: transform QemuOpts device to JSON syntax device
>
>On Thu, Feb 24, 2022 at 10:09:35AM +0100, Peter Krempa wrote:
>> On Thu, Feb 24, 2022 at 09:02:02 +0000, Daniel P. Berrangé wrote:
>> > On Thu, Feb 24, 2022 at 02:06:53PM +0800, Zhenzhong Duan wrote:
>> > > While there are mixed use of traditional -device option and JSON
>> > > syntax option, QEMU reports conflict, e.x:
>> > >
>> > > /usr/libexec/qemu-kvm -nodefaults \
>> > >   -device '{"driver":"virtio-scsi-
>pci","id":"scsi0","bus":"pci.0","addr":"0x02.0"}' \
>> > >   -device virtio-scsi-pci,id=scsi1,bus=pci.0
>> >
>> > Why are you attempting to mix JSON and non-JSON syntax at the same
>> > time ? The expectation is that any mgmt app adopting JSON syntax
>> > will do so universally and not mix old and new syntax. So in
>> > practice the scenario above is not one that QEMU ever intended to
>> > have used by apps.
>>
>> Based on the previous post they are using some 'qemu:commandline'
>> overrides with the legacy syntax with new libvirt which uses JSON
>> syntax:
>>
>> <qemu:commandline>
>>   <qemu:arg value='-netdev'/>
>>     <qemu:arg value='user,id=mynet0,hostfwd=tcp::44483-:22'/>
>>     <qemu:arg value='-device'/>
>>   <qemu:arg
>> value='virtio-net-pci,netdev=mynet0,mac=00:16:3E:68:00:10,romfile='/>
>> </qemu:commandline>
>>
>> I suggested that they should add the required functionality to libvirt
>> instead of trying to hack qemu:
>>
>> https://lists.gnu.org/archive/html/qemu-devel/2022-02/msg05068.html
>
>Or the other answer is to switch to use JSON syntax in the above command
>line passthrough config.
>
>Or to specify the PCI address so it doesn't clash with other devices already
>present.

Thanks Daniel and Peter for comments.
Clear on my side. I'll synchronize your suggestions to my colleague.

Regards
Zhenzhong

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] vl: transform QemuOpts device to JSON syntax device
  2022-02-24  6:06 [PATCH] vl: transform QemuOpts device to JSON syntax device Zhenzhong Duan
  2022-02-24  9:02 ` Daniel P. Berrangé
@ 2022-02-24 11:31 ` Kevin Wolf
  2022-02-25  2:02   ` Duan, Zhenzhong
  1 sibling, 1 reply; 7+ messages in thread
From: Kevin Wolf @ 2022-02-24 11:31 UTC (permalink / raw)
  To: Zhenzhong Duan; +Cc: pkrempa, mst, lersek, qemu-devel, pbonzini, eblake

Am 24.02.2022 um 07:06 hat Zhenzhong Duan geschrieben:
> While there are mixed use of traditional -device option and JSON
> syntax option, QEMU reports conflict, e.x:
> 
> /usr/libexec/qemu-kvm -nodefaults \
>   -device '{"driver":"virtio-scsi-pci","id":"scsi0","bus":"pci.0","addr":"0x02.0"}' \
>   -device virtio-scsi-pci,id=scsi1,bus=pci.0
> 
> It breaks with:
> 
> qemu-kvm: -device {"driver":"virtio-scsi-pci","id":"scsi0","bus":"pci.0","addr":"0x02.0"}: PCI: slot 2 function 0 not available for virtio-scsi-pci, in use by virtio-scsi-pci
> 
> But if we reformat first -device same as the second, so only same kind
> of option for all the devices, it succeeds, vice versa. e.x:
> 
> /usr/libexec/qemu-kvm -nodefaults \
>   -device virtio-scsi-pci,id=scsi0,bus=pci.0,addr=02.0 \
>   -device virtio-scsi-pci,id=scsi1,bus=pci.0
> 
> Succeed!
> 
> Because both kind of options are inserted into their own list and
> break the order in QEMU command line during BDF auto assign. Fix it
> by transform QemuOpts into JSON syntax and insert in JSON device
> list, so the order in QEMU command line kept.
> 
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>

This patch is incorrect and breaks several cases, which are the reason
why the QemuOpts path hasn't been changed yet.

For example, after this patch, help doesn't work any more:

$ build/qemu-system-x86_64 -device help
qemu-system-x86_64: -device help: 'help' is not a valid device model name

Any non-string property doesn't work any more in non-JSON syntax:

$ $ build/qemu-system-x86_64 -blockdev null-co,node-name=disk -device virtio-blk,drive=disk,physical_block_size=4096
qemu-system-x86_64: -device virtio-blk,drive=disk,physical_block_size=4096: Parameter 'physical_block_size' expects uint64

There may be more cases that are broken with this patch.

Kevin



^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH] vl: transform QemuOpts device to JSON syntax device
  2022-02-24 11:31 ` Kevin Wolf
@ 2022-02-25  2:02   ` Duan, Zhenzhong
  0 siblings, 0 replies; 7+ messages in thread
From: Duan, Zhenzhong @ 2022-02-25  2:02 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: pkrempa, mst, lersek, qemu-devel, pbonzini, eblake


>-----Original Message-----
>From: Kevin Wolf <kwolf@redhat.com>
>Sent: Thursday, February 24, 2022 7:31 PM
>To: Duan, Zhenzhong <zhenzhong.duan@intel.com>
>Cc: qemu-devel@nongnu.org; pbonzini@redhat.com; eblake@redhat.com;
>mst@redhat.com; pkrempa@redhat.com; lersek@redhat.com
>Subject: Re: [PATCH] vl: transform QemuOpts device to JSON syntax device
>
>Am 24.02.2022 um 07:06 hat Zhenzhong Duan geschrieben:
>> While there are mixed use of traditional -device option and JSON
>> syntax option, QEMU reports conflict, e.x:
>>
>> /usr/libexec/qemu-kvm -nodefaults \
>>   -device '{"driver":"virtio-scsi-
>pci","id":"scsi0","bus":"pci.0","addr":"0x02.0"}' \
>>   -device virtio-scsi-pci,id=scsi1,bus=pci.0
>>
>> It breaks with:
>>
>> qemu-kvm: -device
>> {"driver":"virtio-scsi-pci","id":"scsi0","bus":"pci.0","addr":"0x02.0"
>> }: PCI: slot 2 function 0 not available for virtio-scsi-pci, in use by
>> virtio-scsi-pci
>>
>> But if we reformat first -device same as the second, so only same kind
>> of option for all the devices, it succeeds, vice versa. e.x:
>>
>> /usr/libexec/qemu-kvm -nodefaults \
>>   -device virtio-scsi-pci,id=scsi0,bus=pci.0,addr=02.0 \
>>   -device virtio-scsi-pci,id=scsi1,bus=pci.0
>>
>> Succeed!
>>
>> Because both kind of options are inserted into their own list and
>> break the order in QEMU command line during BDF auto assign. Fix it by
>> transform QemuOpts into JSON syntax and insert in JSON device list, so
>> the order in QEMU command line kept.
>>
>> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
>
>This patch is incorrect and breaks several cases, which are the reason why the
>QemuOpts path hasn't been changed yet.
>
>For example, after this patch, help doesn't work any more:
>
>$ build/qemu-system-x86_64 -device help
>qemu-system-x86_64: -device help: 'help' is not a valid device model name
>
>Any non-string property doesn't work any more in non-JSON syntax:
>
>$ $ build/qemu-system-x86_64 -blockdev null-co,node-name=disk -device
>virtio-blk,drive=disk,physical_block_size=4096
>qemu-system-x86_64: -device virtio-blk,drive=disk,physical_block_size=4096:
>Parameter 'physical_block_size' expects uint64
>
>There may be more cases that are broken with this patch.

Ah, yes. Thanks for point out. I should have learned more before writing this patch. Sorry for the noise. And we will try the libvirt maintainer suggested way on this issue.

Regards
Zhenzhong


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-02-25  2:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-24  6:06 [PATCH] vl: transform QemuOpts device to JSON syntax device Zhenzhong Duan
2022-02-24  9:02 ` Daniel P. Berrangé
2022-02-24  9:09   ` Peter Krempa
2022-02-24  9:13     ` Daniel P. Berrangé
2022-02-24 11:19       ` Duan, Zhenzhong
2022-02-24 11:31 ` Kevin Wolf
2022-02-25  2:02   ` Duan, Zhenzhong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.