Skip to contentSkip to conversation

disable shared memory is not available with this QEMU binary

Qemu-devel Tony Krowiak 6 participants 16 messages Mar 31, 2015 – Apr 1, 2015

lore
Share & tools
lore
#0 lore raw

Commit 49d2e648e8087d154d8bf8b91f27c8e05e79d5a6 removed the QemuOptDesc elements from the *desc* field of the *qemu_machine_opts *array defined in vl.c. Since applying that patch to qemu on my system, I can not start a guest from libvirt when certain machine options are configured for the guest domain. For example, if I configure the following for my guest domain:

    <memoryBacking>
        ...
        <nosharepages>
        ...
    </memoryBacking>

I get the following libvirt error when I try to start the guest:

error: unsupported configuration: disable shared memory is not
available with this QEMU binary

The *nosharepages *element generates the *-machine* option *mem-merge=off* on the QEMU command line. The error is thrown by libvirt because the QMP *query-command-line-options* command does not return *mem-merge* in the machine options parameter list. In fact, if I issue the *query-command-line-options* command via virsh as follows:

virsh qemu-monitor-command guest_c2aa '{ "execute":
"query-command-line-options", "arguments": { "option": "machine" } }'

No machine option parameters are returned:

{"return":[{"parameters":[],"option":"machine"}],"id":"libvirt-11"}

I took a look at the *qmp_query_command_line_options* function in *util/qemu-config.c*. The function derives the option parameters to return with the the query response from the QemuOptDesc elements contained in the *desc* field of the *qemu_machine_opts *array defined in vl.c. It appears that removing the QemuOptDesc elements broke the *qmp_query_command_line_options* function. If I restore the QemuOptDesc elements removed by commit 49d2e648e8087d154d8bf8b91f27c8e05e79d5a6, I can start the guest with *nosharepages* configured.

It would appear that a bug was introduced with commit 49d2e648e8087d154d8bf8b91f27c8e05e79d5a6, what say you?

#1 lore raw
Quoted 13 lines · Tony Krowiak

Commit 49d2e648e8087d154d8bf8b91f27c8e05e79d5a6 removed the QemuOptDesc elements from the *desc* field of the *qemu_machine_opts *array defined in vl.c. Since applying that patch to qemu on my system, I can not start a guest from libvirt when certain machine options are configured for the guest domain. For example, if I configure the following for my guest domain:

     <memoryBacking>
         ...
         <nosharepages>
         ...
     </memoryBacking>

I get the following libvirt error when I try to start the guest:

Quoted 8 lines

error: unsupported configuration: disable shared memory is not available with this QEMU binary

The *nosharepages *element generates the *-machine* option *mem-merge=off* on the QEMU command line. The error is thrown by libvirt because the QMP *query-command-line-options* command does not return *mem-merge* in the machine options parameter list. In fact, if I issue the *query-command-line-options* command via virsh as follows:

virsh qemu-monitor-command guest_c2aa '{ "execute": "query-command-line-options", "arguments": { "option": "machine" } }'

Hi Tony,
Thank you for finding this bug.

Quoted 3 lines

No machine option parameters are returned:

{"return":[{"parameters":[],"option":"machine"}],"id":"libvirt-11"}

Indeed, we have a problem here.

This is the first object for which QemuOps are defined per sub-type and are not global (if you don't take "object" under consideration). I saw others as well, like netdev, but I am not sure what happens there.

Once the QemuOpts are parsed, the only place we can find those options is the machine object itself (as QOM properties).

I see a few options here:
1. Add a feature to QemuOpts: "Look for options in QOM properties of this obj"
2. Add a callback to QEMU opts that supplies the options (have machine supply the callback)
3. Have the machine object fill in the corresponding QemuOpts on init.

Any thoughts?
Thanks,
Marcel

Quoted 11 lines

I took a look at the *qmp_query_command_line_options* function in *util/qemu-config.c*. The function derives the option parameters to return with the the query response from the QemuOptDesc elements contained in the *desc* field of the *qemu_machine_opts *array defined in vl.c. It appears that removing the QemuOptDesc elements broke the *qmp_query_command_line_options* function. If I restore the QemuOptDesc elements removed by commit 49d2e648e8087d154d8bf8b91f27c8e05e79d5a6, I can start the guest with *nosharepages* configured.

It would appear that a bug was introduced with commit 49d2e648e8087d154d8bf8b91f27c8e05e79d5a6, what say you?

#2 lore raw
Quoted 3 lines · Marcel Apfelbaum

This is the first object for which QemuOps are defined per sub-type and are not global (if you don't take "object" under consideration).

We can return the same QemuOpts that were included before. Per-machine-type options are new and need not be covered by query-command-line-options.

Paolo

Quoted 11 lines

I saw others as well, like netdev, but I am not sure what happens there.

Once the QemuOpts are parsed, the only place we can find those options is the machine object itself (as QOM properties).

I see a few options here:
1. Add a feature to QemuOpts: "Look for options in QOM properties of this obj"
2. Add a callback to QEMU opts that supplies the options (have machine supply the callback)
3. Have the machine object fill in the corresponding QemuOpts on init.

#3 lore raw
Quoted 10 lines · Paolo Bonzini
Quoted 3 lines · Marcel Apfelbaum

This is the first object for which QemuOps are defined per sub-type and are not global (if you don't take "object" under consideration).

We can return the same QemuOpts that were included before. Per-machine-type options are new and need not be covered by query-command-line-options.

OK, we have them under hw/core/machine.c as "base" machine properties. We still need a way to fill them back into QemuOpts right? Maybe return them to the static global list? It seems like a step back, but if there is no better way...

Thanks,
Marcel

Quoted 14 lines

Paolo

Quoted 11 lines

I saw others as well, like netdev, but I am not sure what happens there.

Once the QemuOpts are parsed, the only place we can find those options is the machine object itself (as QOM properties).

I see a few options here:
1. Add a feature to QemuOpts: "Look for options in QOM properties of this obj"
2. Add a callback to QEMU opts that supplies the options (have machine supply the callback)
3. Have the machine object fill in the corresponding QemuOpts on init.

#4 lore raw
Quoted 9 lines · Marcel Apfelbaum
Quoted 4 lines

We can return the same QemuOpts that were included before. Per-machine-type options are new and need not be covered by query-command-line-options.

OK, we have them under hw/core/machine.c as "base" machine properties. We still need a way to fill them back into QemuOpts right? Maybe return them to the static global list? It seems like a step back, but if there is no better way...

Yeah, QemuOpts needs to be enhanced to stop doing checks on -machine.

Paolo

#10 lore raw
In reply to Marcel Apfelbaum
Quoted 16 lines · Marcel Apfelbaum
Quoted 15 lines · Tony Krowiak

Commit 49d2e648e8087d154d8bf8b91f27c8e05e79d5a6 removed the QemuOptDesc elements from the *desc* field of the *qemu_machine_opts *array defined in vl.c. Since applying that patch to qemu on my system, I can not start a guest from libvirt when certain machine options are configured for the guest domain. For example, if I configure the following for my guest domain:

     <memoryBacking>
         ...
         <nosharepages>
         ...
     </memoryBacking>

I get the following libvirt error when I try to start the guest:

error: unsupported configuration: disable shared memory is not available with this QEMU binary

Quoted 8 lines
Quoted 6 lines

The *nosharepages *element generates the *-machine* option *mem-merge=off* on the QEMU command line. The error is thrown by libvirt because the QMP *query-command-line-options* command does not return *mem-merge* in the machine options parameter list. In fact, if I issue the *query-command-line-options* command via virsh as follows:

virsh qemu-monitor-command guest_c2aa '{ "execute": "query-command-line-options", "arguments": { "option": "machine" } }'

Hi Tony,
Thank you for finding this bug.

Sounds like a regression. If it is, we need to decide what to do about it urgently.

Quoted 9 lines
Quoted 3 lines

No machine option parameters are returned:

{"return":[{"parameters":[],"option":"machine"}],"id":"libvirt-11"}

Indeed, we have a problem here.

This is the first object for which QemuOps are defined per sub-type and are not global (if you don't take "object" under consideration). I saw others as well, like netdev, but I am not sure what happens there.

Quoted 5 lines

Once the QemuOpts are parsed, the only place we can find those options is the machine object itself (as QOM properties).

I see a few options here:
1. Add a feature to QemuOpts: "Look for options in QOM properties of this obj"

QemuOpts is an overengineered, self-contained mess. Let's not make it an overengineered mess with complex external dependencies.

Quoted 2 lines

2. Add a callback to QEMU opts that supplies the options (have machine supply the callback)

Keeps QemuOpts and QOM more separated than 1, but still adds external dependencies.

Quoted 1 line

3. Have the machine object fill in the corresponding QemuOpts on init.

Monkey-patching QemuOpts desc[] should be workable in principle.

However, to monkey-patch qemu_machine_opts.desc[], we need the machine object, and to create the machine object, we need to parse machine options. Thus, we'll first parse with an empty desc[], then make one up and monkey-patch it in just for introspection. Nasty.

"Nasty" may well be what we need to fix the regression at this late hour.

Quoted 1 line

Any thoughts?

[...]

Yes, but you may not like them :)

4. Support tagged unions in QemuOpts

QemuOpts supports a single list of typed parameters. Good enough for many options. Certain options, however, additionally take "variant" paramaters depending on the value of a discriminator parameter.

Example: -tpmdev id=ID,type=T,...

type=T selects a TPM backend, which defines additional option parameters.

Current solution: qemu_tpmdev_opts.desc[] is empty. Option parsing accepts arbitrary parameters unchecked in addition to the special parameter id=ID. configure_tpm() gets parameter "type", finds the backend, then passes the backend's QemuOptsDesc[] to qemu_opts_validate() to check parameters.

How configure_tpm() validates parameters is not visible to query-command-line-options, naturally.

Example: -device id=ID,driver=D,bus=B,...

driver=D selects a device model, which defines additional option parameters.

Current solution: the device model defines QOM properties, qemu_device_opts.desc[] is empty. Option parsing accepts arbitrary parameters unchecked in addition to the special parameter id=ID. qdev_device_add() gets parameter "driver" and "bus", finds the driver, then feeds the remaining option parameters to object_property_parse() to check and set them.

How qdev_device_add() validates parameters is not visible to query-command-line-options, naturally. But libvirt knows what it does, and finds the QOM properties elsewhere (QMP command device-list-properties).

Related: QMP command device_add has not been QAPIfied. We'll get back to that in a jiffie.

Example: -netdev id=ID,type=T,...

type=T selects a net backend, which defines additional option parameters.

Current solution: qemu_netdev_opts.desc[] is empty. Option parsing accepts arbitrary parameters unchecked in addition to the special parameter id=ID. The QAPI schema defines type NetClientOptions as a tagged union. net_client_init() uses OptsVisitor to check parameters and create a NetClientOptions object for them.

How net_client_init() validates parameters is not visible to query-command-line-options, naturally.

We could do better in QMP, but we don't: netdev_add doesn't use NetClientOptions, it uses the top type '**', which makes the QMP core accept an arbitrary JSON value. This is then converted to QemuOpts and fed to the machinery described above.

Creating new infrastructure is exciting, converting the first 90% of its users proves its worth, converting the other 90% is boring and hard, so let's create something new and more exciting instead.

The -netdev example shows that the QAPI schema already has what we need. QMP gets it for free, because it's based on QAPI (except the parts we can't be bothered to convert).

We could do the same for command line options. Would additionally get us other QAPI goodies, like a saner type system, and (soon) introspection.

Big job, though.

We could of course hack up QemuOpts some more to make it support tagged unions all by itself, duplicating selected parts of QAPI. Very traditional.

5. Introspect something else

Remember the -device example? There, query-command-line-options is of no help, so we find the information somewhere else.

Adding an ad hoc "somewhere else" just for -machine would also be very traditional.

[...]

#5 lore raw
In reply to Paolo Bonzini
Quoted 8 lines · Paolo Bonzini
Quoted 3 lines · Marcel Apfelbaum

This is the first object for which QemuOps are defined per sub-type and are not global (if you don't take "object" under consideration).

We can return the same QemuOpts that were included before. Per-machine-type options are new and need not be covered by query-command-line-options.

The obvious way to return them is to put them right back in qemu_machine_opts.desc[]. But then -machine rejects machine-specific parameters.

Hack: monkey-patch them in after we're done parsing.

Cleaner: "empty desc[] means accept anything" has always been overly restrictive. Have a flag "accept additional parameters".

We may have to do the former for 2.3, but that's no excuse not to replace it by something less gross in 2.4.

[...]

#6 lore raw
Quoted 11 lines · Markus Armbruster

The obvious way to return them is to put them right back in qemu_machine_opts.desc[]. But then -machine rejects machine-specific parameters.

Hack: monkey-patch them in after we're done parsing.

Cleaner: "empty desc[] means accept anything" has always been overly restrictive. Have a flag "accept additional parameters".

We may have to do the former for 2.3, but that's no excuse not to replace it by something less gross in 2.4.

The latter sounds less intrusive, actually. Could it be as easy as

static bool opts_accepts_any(const QemuOpts *opts) {
- return opts->list->desc[0].name == NULL;
+ return opts->list->desc[0].name == NULL || opts->list->accept_any;
}

?

Paolo

#7 lore raw
Quoted 23 lines · Paolo Bonzini
Quoted 11 lines · Markus Armbruster

The obvious way to return them is to put them right back in qemu_machine_opts.desc[]. But then -machine rejects machine-specific parameters.

Hack: monkey-patch them in after we're done parsing.

Cleaner: "empty desc[] means accept anything" has always been overly restrictive. Have a flag "accept additional parameters".

We may have to do the former for 2.3, but that's no excuse not to replace it by something less gross in 2.4.

The latter sounds less intrusive, actually. Could it be as easy as

  static bool opts_accepts_any(const QemuOpts *opts)
  {
(quoted diff) +1 -1
-    return opts->list->desc[0].name == NULL;
+    return opts->list->desc[0].name == NULL || opts->list->accept_any;
  }
Quoted 1 line

?

This + 'monkey-patch' may be a feasible solution for 2.4

Thanks, I'll give it a try and see how ugly will be Marcel

Quoted 3 lines

Paolo

#8 lore raw
Quoted 1 line · Marcel Apfelbaum

This + 'monkey-patch' may be a feasible solution for 2.4

Why monkey-patch and not just revert?

Paolo

#9 lore raw
Quoted 6 lines · Paolo Bonzini
Quoted 1 line · Marcel Apfelbaum

This + 'monkey-patch' may be a feasible solution for 2.4

Why monkey-patch and not just revert?

There are already several machine sub-types that have their own options, some of the code I think
it was added after the 'dynamic options' patch, so revert will not be enough.
We will need to go over the new options and add them to the global list.

At this point, adding the machine options to the global list during machine init seems to be a less risky and
will also keep options per machine.

Maybe I'll try it and see how it looks.

Thanks,
Marcel

Quoted 3 lines

Paolo

#11 lore raw
In reply to Markus Armbruster
Quoted 22 lines · Markus Armbruster
Quoted 20 lines · Marcel Apfelbaum
Quoted 19 lines · Tony Krowiak

Commit 49d2e648e8087d154d8bf8b91f27c8e05e79d5a6 removed the QemuOptDesc elements from the *desc* field of the *qemu_machine_opts *array defined in vl.c. Since applying that patch to qemu on my system, I can not start a guest from libvirt when certain machine options are configured for the guest domain. For example, if I configure the following for my guest domain:

      <memoryBacking>
          ...
          <nosharepages>
          ...
      </memoryBacking>

I get the following libvirt error when I try to start the guest:

error: unsupported configuration: disable shared memory is not available with this QEMU binary

The *nosharepages *element generates the *-machine* option *mem-merge=off* on the QEMU command line. The error is thrown by libvirt because the QMP *query-command-line-options* command does not return *mem-merge* in the machine options parameter list. In fact, if I issue the *query-command-line-options* command via virsh as follows:

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

virsh qemu-monitor-command guest_c2aa '{ "execute": "query-command-line-options", "arguments": { "option": "machine" } }'

Hi Tony,
Thank you for finding this bug.

Sounds like a regression. If it is, we need to decide what to do about it urgently.

Hi Markus,
This is definitely a regression.

Quoted 25 lines
Quoted 10 lines
Quoted 4 lines

No machine option parameters are returned:

{"return":[{"parameters":[],"option":"machine"}],"id":"libvirt-11"}

Indeed, we have a problem here.

This is the first object for which QemuOps are defined per sub-type and are not global (if you don't take "object" under consideration). I saw others as well, like netdev, but I am not sure what happens there.

Quoted 5 lines

Once the QemuOpts are parsed, the only place we can find those options is the machine object itself (as QOM properties).

I see a few options here:
1. Add a feature to QemuOpts: "Look for options in QOM properties of this obj"

QemuOpts is an overengineered, self-contained mess. Let's not make it an overengineered mess with complex external dependencies.

Quoted 2 lines

2. Add a callback to QEMU opts that supplies the options (have machine supply the callback)

Keeps QemuOpts and QOM more separated than 1, but still adds external dependencies.

Quoted 8 lines
Quoted 1 line

3. Have the machine object fill in the corresponding QemuOpts on init.

Monkey-patching QemuOpts desc[] should be workable in principle.

However, to monkey-patch qemu_machine_opts.desc[], we need the machine object, and to create the machine object, we need to parse machine options. Thus, we'll first parse with an empty desc[], then make one up and monkey-patch it in just for introspection. Nasty.

I noticed something weird. I cannot actually create an instance of machine or get a reference to current_machine in order to query its properties!

It seems that util/qemu-config is used by qemu-img which obviously does not have a current machine nor the means to create it.

So I have no way to create QOM objects for introspection :(.

Quoted 3 lines

"Nasty" may well be what we need to fix the regression at this late hour.

I don't like it either but if 1. and 2. are worse, I posted a patch for 3. ish.

Quoted 5 lines
Quoted 2 lines

Any thoughts?

[...]

Yes, but you may not like them :)

Thanks for the ideas!
Now I'll start reading...

Quoted 68 lines

4. Support tagged unions in QemuOpts

QemuOpts supports a single list of typed parameters. Good enough for many options. Certain options, however, additionally take "variant" paramaters depending on the value of a discriminator parameter.

Example: -tpmdev id=ID,type=T,...

type=T selects a TPM backend, which defines additional option parameters.

Current solution: qemu_tpmdev_opts.desc[] is empty. Option parsing accepts arbitrary parameters unchecked in addition to the special parameter id=ID. configure_tpm() gets parameter "type", finds the backend, then passes the backend's QemuOptsDesc[] to qemu_opts_validate() to check parameters.

How configure_tpm() validates parameters is not visible to query-command-line-options, naturally.

Example: -device id=ID,driver=D,bus=B,...

driver=D selects a device model, which defines additional option parameters.

Current solution: the device model defines QOM properties, qemu_device_opts.desc[] is empty. Option parsing accepts arbitrary parameters unchecked in addition to the special parameter id=ID. qdev_device_add() gets parameter "driver" and "bus", finds the driver, then feeds the remaining option parameters to object_property_parse() to check and set them.

How qdev_device_add() validates parameters is not visible to query-command-line-options, naturally. But libvirt knows what it does, and finds the QOM properties elsewhere (QMP command device-list-properties).

Related: QMP command device_add has not been QAPIfied. We'll get back to that in a jiffie.

Example: -netdev id=ID,type=T,...

type=T selects a net backend, which defines additional option parameters.

Current solution: qemu_netdev_opts.desc[] is empty. Option parsing accepts arbitrary parameters unchecked in addition to the special parameter id=ID. The QAPI schema defines type NetClientOptions as a tagged union. net_client_init() uses OptsVisitor to check parameters and create a NetClientOptions object for them.

How net_client_init() validates parameters is not visible to query-command-line-options, naturally.

We could do better in QMP, but we don't: netdev_add doesn't use NetClientOptions, it uses the top type '**', which makes the QMP core accept an arbitrary JSON value. This is then converted to QemuOpts and fed to the machinery described above.

Creating new infrastructure is exciting, converting the first 90% of its users proves its worth, converting the other 90% is boring and hard, so let's create something new and more exciting instead.

The -netdev example shows that the QAPI schema already has what we need. QMP gets it for free, because it's based on QAPI (except the parts we can't be bothered to convert).

Quoted 5 lines

We could do the same for command line options. Would additionally get us other QAPI goodies, like a saner type system, and (soon) introspection.

Big job, though.

You lost me... you are talking about QAPI that I have no knowledge about, and I still don't see how I can create instances of QOM objects in the context of qemu-config.

Quoted 9 lines

We could of course hack up QemuOpts some more to make it support tagged unions all by itself, duplicating selected parts of QAPI. Very traditional.

5. Introspect something else

Remember the -device example? There, query-command-line-options is of no help, so we find the information somewhere else.

-device is also looking into a static array, no introspection :(

Quoted 3 lines

Adding an ad hoc "somewhere else" just for -machine would also be very traditional.

Thanks for the help!
Marcel

Quoted 3 lines

[...]

#12 lore raw
Quoted 68 lines · Marcel Apfelbaum
Quoted 22 lines · Markus Armbruster
Quoted 20 lines · Marcel Apfelbaum
Quoted 19 lines · Tony Krowiak

Commit 49d2e648e8087d154d8bf8b91f27c8e05e79d5a6 removed the QemuOptDesc elements from the *desc* field of the *qemu_machine_opts *array defined in vl.c. Since applying that patch to qemu on my system, I can not start a guest from libvirt when certain machine options are configured for the guest domain. For example, if I configure the following for my guest domain:

      <memoryBacking>
          ...
          <nosharepages>
          ...
      </memoryBacking>

I get the following libvirt error when I try to start the guest:

error: unsupported configuration: disable shared memory is not available with this QEMU binary

The *nosharepages *element generates the *-machine* option *mem-merge=off* on the QEMU command line. The error is thrown by libvirt because the QMP *query-command-line-options* command does not return *mem-merge* in the machine options parameter list. In fact, if I issue the *query-command-line-options* command via virsh as follows:

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

virsh qemu-monitor-command guest_c2aa '{ "execute": "query-command-line-options", "arguments": { "option": "machine" } }'

Hi Tony,
Thank you for finding this bug.

Sounds like a regression. If it is, we need to decide what to do about it urgently.

Hi Markus,
This is definitely a regression.

Quoted 26 lines
Quoted 10 lines
Quoted 4 lines

No machine option parameters are returned:

{"return":[{"parameters":[],"option":"machine"}],"id":"libvirt-11"}

Indeed, we have a problem here.

This is the first object for which QemuOps are defined per sub-type and are not global (if you don't take "object" under consideration). I saw others as well, like netdev, but I am not sure what happens there.

Quoted 6 lines

Once the QemuOpts are parsed, the only place we can find those options is the machine object itself (as QOM properties).

I see a few options here:
1. Add a feature to QemuOpts: "Look for options in QOM properties of this obj"

QemuOpts is an overengineered, self-contained mess. Let's not make it an overengineered mess with complex external dependencies.

Quoted 2 lines

2. Add a callback to QEMU opts that supplies the options (have machine supply the callback)

Keeps QemuOpts and QOM more separated than 1, but still adds external dependencies.

Quoted 8 lines
Quoted 1 line

3. Have the machine object fill in the corresponding QemuOpts on init.

Monkey-patching QemuOpts desc[] should be workable in principle.

However, to monkey-patch qemu_machine_opts.desc[], we need the machine object, and to create the machine object, we need to parse machine options. Thus, we'll first parse with an empty desc[], then make one up and monkey-patch it in just for introspection. Nasty.

Quoted 7 lines

I noticed something weird. I cannot actually create an instance of machine or get a reference to current_machine in order to query its properties!

It seems that util/qemu-config is used by qemu-img which obviously does not have a current machine nor the means to create it.

So I have no way to create QOM objects for introspection :(.

You'd have to do something like

desc[] = generic entries + the machine's entries

where the latter is empty outside qemu proper.

For 2.3, I recommend to do *only* generic entries. Specifically, *exactly* the entries we had before we cleared out qemu_machine_opts.desc[].

Quoted 82 lines
Quoted 2 lines

"Nasty" may well be what we need to fix the regression at this late hour.

I don't like it either but if 1. and 2. are worse, I posted a patch for 3. ish.

Quoted 5 lines
Quoted 2 lines

Any thoughts?

[...]

Yes, but you may not like them :)

Thanks for the ideas!
Now I'll start reading...

Quoted 68 lines

4. Support tagged unions in QemuOpts

QemuOpts supports a single list of typed parameters. Good enough for many options. Certain options, however, additionally take "variant" paramaters depending on the value of a discriminator parameter.

Example: -tpmdev id=ID,type=T,...

type=T selects a TPM backend, which defines additional option parameters.

Current solution: qemu_tpmdev_opts.desc[] is empty. Option parsing accepts arbitrary parameters unchecked in addition to the special parameter id=ID. configure_tpm() gets parameter "type", finds the backend, then passes the backend's QemuOptsDesc[] to qemu_opts_validate() to check parameters.

How configure_tpm() validates parameters is not visible to query-command-line-options, naturally.

Example: -device id=ID,driver=D,bus=B,...

driver=D selects a device model, which defines additional option parameters.

Current solution: the device model defines QOM properties, qemu_device_opts.desc[] is empty. Option parsing accepts arbitrary parameters unchecked in addition to the special parameter id=ID. qdev_device_add() gets parameter "driver" and "bus", finds the driver, then feeds the remaining option parameters to object_property_parse() to check and set them.

How qdev_device_add() validates parameters is not visible to query-command-line-options, naturally. But libvirt knows what it does, and finds the QOM properties elsewhere (QMP command device-list-properties).

Related: QMP command device_add has not been QAPIfied. We'll get back to that in a jiffie.

Example: -netdev id=ID,type=T,...

type=T selects a net backend, which defines additional option parameters.

Current solution: qemu_netdev_opts.desc[] is empty. Option parsing accepts arbitrary parameters unchecked in addition to the special parameter id=ID. The QAPI schema defines type NetClientOptions as a tagged union. net_client_init() uses OptsVisitor to check parameters and create a NetClientOptions object for them.

How net_client_init() validates parameters is not visible to query-command-line-options, naturally.

We could do better in QMP, but we don't: netdev_add doesn't use NetClientOptions, it uses the top type '**', which makes the QMP core accept an arbitrary JSON value. This is then converted to QemuOpts and fed to the machinery described above.

Creating new infrastructure is exciting, converting the first 90% of its users proves its worth, converting the other 90% is boring and hard, so let's create something new and more exciting instead.

The -netdev example shows that the QAPI schema already has what we need. QMP gets it for free, because it's based on QAPI (except the parts we can't be bothered to convert).

Quoted 8 lines
Quoted 5 lines

We could do the same for command line options. Would additionally get us other QAPI goodies, like a saner type system, and (soon) introspection.

Big job, though.

You lost me... you are talking about QAPI that I have no knowledge about, and I still don't see how I can create instances of QOM objects in the context of qemu-config.

Very high level summary:

0. We use QemuOpts to define our command line. The definition is *incomplete*. The missing parts are left to code. query-command-line-options can't see them.

1. You have a QemuOpts problem that is actually pretty common: how to accept a few fixed parameters plus a bunch of parameters that are specific to the value of one of the fixed parameters (the discriminator, in your case "type").

2. We've solved this in several different ways, and all of them make query-command-line-options useless.

3. Same problem exists in QMP, and we have a decent solution there, based on QAPI.

4. We'll soon have QMP/QAPI introspection.

5. If we used a QAPI schema to define our command line, we could do a more complete job (because it's more expressive), and we'd get introspection basically for free.

6. #5 would be a big job, though.

Less confused now?

Quoted 9 lines
Quoted 8 lines

We could of course hack up QemuOpts some more to make it support tagged unions all by itself, duplicating selected parts of QAPI. Very traditional.

5. Introspect something else

Remember the -device example? There, query-command-line-options is of no help, so we find the information somewhere else.

-device is also looking into a static array, no introspection :(

Let me rephrase:

query-command-line-options comes up empty for -device.

Libvirt knows that -device takes parameters "id", "driver" and driver-specific ones. It further knows how to get the driver-specific
ones: with QMP command device-list-properties. Example:

    { "execute": "device-list-properties", "arguments": { "typename": "usb-mouse" }  }
    {"return": [{"name": "msos-desc", "description": "on/off", "type": "bool"}, {"name": "full-path", "description": "on/off", "type": "bool"}, {"name": "serial", "type": "str"}, {"name": "port", "type": "str"}, {"name": "usb_version", "type": "uint32"}]}
Quoted 8 lines
Quoted 2 lines

Adding an ad hoc "somewhere else" just for -machine would also be very traditional.

Thanks for the help!
Marcel

Quoted 3 lines

[...]

#13 lore raw
Quoted 1 line · Markus Armbruster

Marcel Apfelbaum <[email protected]> writes:

[...]

Quoted 6 lines
Quoted 6 lines

I noticed something weird. I cannot actually create an instance of machine or get a reference to current_machine in order to query its properties!

It seems that util/qemu-config is used by qemu-img which obviously does not have a current machine nor the means to create it.

Quoted 7 lines
Quoted 1 line

So I have no way to create QOM objects for introspection :(.

You'd have to do something like

   desc[] = generic entries + the machine's entries

where the latter is empty outside qemu proper.

Hmm! So I will loose with some dignity.
I'll keep the properties of the base "machine" on a static array and *only* per-machine properties dynamic and I loose them.

Quoted 4 lines

For 2.3, I recommend to do *only* generic entries. Specifically, *exactly* the entries we had before we cleared out qemu_machine_opts.desc[].

I submitted:
[PATCH for-2.3] util/qemu-config" fix regression of qmp_query_command_line_options
which includes both base-machine/per-machine properties.
Is it that bad? qmp can query it and even the new options will work
if qmp decides to set them. Can you have a look?

Quoted 1 line

[...]

Quoted 10 lines
Quoted 4 lines
Quoted 1 line

Big job, though.

You lost me... you are talking about QAPI that I have no knowledge about, and I still don't see how I can create instances of QOM objects in the context of qemu-config.

Very high level summary:

0. We use QemuOpts to define our command line. The definition is *incomplete*. The missing parts are left to code. query-command-line-options can't see them.

OK

Quoted 5 lines

1. You have a QemuOpts problem that is actually pretty common: how to accept a few fixed parameters plus a bunch of parameters that are specific to the value of one of the fixed parameters (the discriminator, in your case "type").

Yes, but is more than that:
per-type properties are not static, you cannot find them before creating an actual QOM object, and that is not possible.

We could have a per-machine static options array that will be loaded at init time into object properties... ugly.

Quoted 3 lines

2. We've solved this in several different ways, and all of them make query-command-line-options useless.

Got it

Quoted 3 lines

3. Same problem exists in QMP, and we have a decent solution there, based on QAPI.

OK

Quoted 2 lines

4. We'll soon have QMP/QAPI introspection.

And then we can query a 'living' object's properties

Quoted 4 lines

5. If we used a QAPI schema to define our command line, we could do a more complete job (because it's more expressive), and we'd get introspection basically for free.

If the QAPI schema will include *all* properties *per* machine type, sure.

Quoted 4 lines

6. #5 would be a big job, though.

Less confused now?

Much better, thanks!
Marcel

Quoted 1 line

[...]

#14 lore raw
Quoted 25 lines · Marcel Apfelbaum
Quoted 1 line · Markus Armbruster

Marcel Apfelbaum <[email protected]> writes:

[...]

Quoted 7 lines
Quoted 7 lines

I noticed something weird. I cannot actually create an instance of machine
or get a reference to current_machine in order to query its properties!

It seems that util/qemu-config is used by qemu-img which obviously does not have a current machine nor the means to create it.

Quoted 7 lines
Quoted 1 line

So I have no way to create QOM objects for introspection :(.

You'd have to do something like

   desc[] = generic entries + the machine's entries

where the latter is empty outside qemu proper.

Hmm! So I will loose with some dignity.
I'll keep the properties of the base "machine" on a static array and *only* per-machine properties dynamic and I loose them.

Quoted 4 lines

For 2.3, I recommend to do *only* generic entries. Specifically, *exactly* the entries we had before we cleared out qemu_machine_opts.desc[].

Quoted 6 lines

I submitted:
[PATCH for-2.3] util/qemu-config" fix regression of
qmp_query_command_line_options
which includes both base-machine/per-machine properties. Is it that bad? qmp can query it and even the new options will work if qmp decides to set them. Can you have a look?

The problem is that the per-machine properties are ALSO advertised even on machines where they do not work, which means you could be lying to libvirt if it needs to know if a specific per-machine option is present.
It would indeed be more conservative for 2.3 to advertise ONLY the
generic options, so even though I already reviewed your patch, you may want to respin to incorporate the more conservative approach by dropping the advertising of any machine-specific option (as that is no worse than what we had before - better to not advertise a feature than to advertise something we don't actually support).

Quoted 10 lines
Quoted 4 lines

1. You have a QemuOpts problem that is actually pretty common: how to accept a few fixed parameters plus a bunch of parameters that are specific to the value of one of the fixed parameters (the discriminator, in your case "type").

Yes, but is more than that:
per-type properties are not static, you cannot find them before creating an actual QOM object, and that is not possible.

We could have a per-machine static options array that will be loaded at init time into object properties... ugly.

But we can avoid worrying about the ugliness or alternatives for solving that until 2.4. For 2.3, all we need to focus on is avoiding the regression.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#15 lore raw
Quoted 33 lines · Eric Blake
Quoted 25 lines · Marcel Apfelbaum
Quoted 1 line · Markus Armbruster

Marcel Apfelbaum <[email protected]> writes:

[...]

Quoted 7 lines
Quoted 7 lines

I noticed something weird. I cannot actually create an instance of machine
or get a reference to current_machine in order to query its properties!

It seems that util/qemu-config is used by qemu-img which obviously does not have a current machine nor the means to create it.

Quoted 7 lines
Quoted 1 line

So I have no way to create QOM objects for introspection :(.

You'd have to do something like

    desc[] = generic entries + the machine's entries

where the latter is empty outside qemu proper.

Hmm! So I will loose with some dignity.
I'll keep the properties of the base "machine" on a static array and *only* per-machine properties dynamic and I loose them.

Quoted 4 lines

For 2.3, I recommend to do *only* generic entries. Specifically, *exactly* the entries we had before we cleared out qemu_machine_opts.desc[].

Quoted 6 lines

I submitted:
[PATCH for-2.3] util/qemu-config" fix regression of
qmp_query_command_line_options
which includes both base-machine/per-machine properties. Is it that bad? qmp can query it and even the new options will work if qmp decides to set them. Can you have a look?

Quoted 9 lines

The problem is that the per-machine properties are ALSO advertised even on machines where they do not work, which means you could be lying to libvirt if it needs to know if a specific per-machine option is present.
It would indeed be more conservative for 2.3 to advertise ONLY the
generic options, so even though I already reviewed your patch, you may want to respin to incorporate the more conservative approach by dropping the advertising of any machine-specific option (as that is no worse than what we had before - better to not advertise a feature than to advertise something we don't actually support).

OK I'll send it shortly

Thanks,
Marcel

Quoted 17 lines
Quoted 6 lines
Quoted 6 lines

1. You have a QemuOpts problem that is actually pretty common: how to accept a few fixed parameters plus a bunch of parameters that are specific to the value of one of the fixed parameters (the discriminator, in your case "type").

Quoted 6 lines

Yes, but is more than that:
per-type properties are not static, you cannot find them before creating an actual QOM object, and that is not possible.

We could have a per-machine static options array that will be loaded at init time into object properties... ugly.

But we can avoid worrying about the ugliness or alternatives for solving that until 2.4. For 2.3, all we need to focus on is avoiding the regression.