Skip to contentSkip to conversation

qmp_device_add() ret_data argument

Qemu-devel Programmingkid 3 participants 3 messages Sep 10, 2015

lore
Share & tools
lore
#0 lore raw

What does the function qmp_device_add() have a ret_data argument if it isn't used? This function is located in qdev-monitor.c.

#1 lore raw
Quoted 1 line · Programmingkid

What does the function qmp_device_add() have a ret_data argument if it isn't used? This function is located in qdev-monitor.c.

[meta-comment - can you teach your mailer to wrap long lines? It's a pain to reply to something that scrolls off the screen]

Because the function is installed as a command handler callback, and all command handler callbacks must have the same signature (QDict *, QObject **, Error **).

Most qapi-fied commands install a generated handler named qmp_marshal_*() with the requisite signature, that then parses the QDict
* into a nicer breakdown of C parameters to the real handler, then collect the returned struct back into the QObject for return. So if you want to know how to manipulate QDict/QObject directly, look at the generated qmp-marshal.c for inspiration.

Meanwhile, device_add has not yet been fully qapi-fied.

I'm about to post a series that completes the qapi-fication of netdev_add, which is somewhat similar to device_add; if you want to look at that for ideas of what is involved, be my guest (netdev_add had an incomplete qapi-fication in qapi-schema.json; device_add isn't even listed there yet so it is even further behind).

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
In reply to Programmingkid
Quoted 2 lines · Programmingkid

What does the function qmp_device_add() have a ret_data argument if it isn't used? This function is located in qdev-monitor.c.

QMP command handlers all implement the same interface:

        void (*cmd_new)(QDict *params, QObject **ret_data, Error **errp);

Handlers of commands returning a value store the value to *ret_data. Handlers of commands not returning a value (such as device_add) leave ret_data alone.

We could require them to store NULL, but that would be easy to forget, and usually catastrophic, so we don't.