: QMP/Monitor queue
Hi Anthony,
I was going to nag you to apply patches from the list, but as I'm maintaining
a QMP/Monitor queue to test them, I thought it would be a good idea to nag you in the form of a git pull :)
All the patches in there have been posted to the list already and, to make it
convenient to review, I'm sending them again in this series (not sure if it's a good idea, though).
The changes (since 116348def2bb446d972bdc2f44bd77ff631f85de) are available in
the following repository:
git://repo.or.cz/qemu/qmp-unstable.git for-anthony
Kevin Wolf (1):
virtio-blk: Fix use after free in error case
Luiz Capitulino (2):
QMP: Improve RTC_CHANGE event description
Monitor: Convert do_screen_dump() to QObject
Markus Armbruster (17):
qdev: Convert qdev_unplug() to QError
monitor: convert do_device_del() to QObject, QError
error: Put error definitions back in alphabetical order
error: New QERR_DUPLICATE_ID
error: Convert qemu_opts_create() to QError
error: New QERR_INVALID_PARAMETER_VALUE
error: Convert qemu_opts_set() to QError
error: Drop extra messages after qemu_opts_set() and qemu_opts_parse()
error: Use QERR_INVALID_PARAMETER_VALUE instead of QERR_INVALID_PARAMETER
error: Convert qemu_opts_validate() to QError
error: Convert net_client_init() to QError
error: New QERR_DEVICE_IN_USE
monitor: New commands netdev_add, netdev_del
monitor: Rename argument type 'b' to 'f'
monitor: New argument type 'b'
monitor: Use argument type 'b' for set_link
monitor: Convert do_set_link() to QObject, QError
Ryan Harper (1):
Add qerror message if the 'change' target filename can't be opened
QMP/qmp-events.txt | 2 +- hw/pci-hotplug.c | 2 - hw/qdev.c | 13 +++--- hw/qdev.h | 2 +- hw/virtio-blk.c | 6 +- monitor.c | 49 +++++++++++++++++++--- net.c | 112 ++++++++++++++++++++++++++++++++++++--------------- net.h | 4 +- qemu-config.c | 1 - qemu-monitor.hx | 49 +++++++++++++++++++---- qemu-option.c | 24 +++++------ qerror.c | 20 ++++++++- qerror.h | 17 ++++++- vl.c | 5 -- 14 files changed, 218 insertions(+), 88 deletions(-)
PATCH 1/21 qdev: Convert qdev_unplug() to QError
From: Markus Armbruster <[email protected]>
Note: our device unplug methods don't need conversion work, because they can't currently fail.
--- hw/qdev.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
hw/qdev.c +1 -2
@@ -287,8 +287,7 @@ int qdev_init(DeviceState *dev)int qdev_unplug (DeviceState *dev) {if (!dev->parent_bus->allow_hotplug) { -error_report ("Bus %s does not support hotplugging" , - dev->parent_bus->name); +qerror_report (QERR_BUS_NO_HOTPLUG , dev->parent_bus->name);return -1 ; }assert (dev->info->unplug !=NULL );
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 2/21 monitor: convert do_device_del() to QObject, QError
In reply to Luiz CapitulinoFrom: Markus Armbruster <[email protected]>
--- hw/qdev.c | 8 ++++---- hw/qdev.h | 2 +- qemu-monitor.hx | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-)
hw/qdev.c +4 -4
@@ -799,15 +799,15 @@ int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data)return 0 ; } -void do_device_del (Monitor *mon,const QDict *qdict) +int do_device_del (Monitor *mon,const QDict *qdict,QObject **ret_data) {const char *id =qdict_get_str (qdict,"id" );DeviceState *dev; dev =qdev_find_recursive (main_system_bus, id);if (NULL == dev) { -error_report ("Device '%s' not found" , id); -return ; +qerror_report (QERR_DEVICE_NOT_FOUND , id); +return -1 ; } -qdev_unplug (dev); +return qdev_unplug (dev); }
hw/qdev.h +1 -1
@@ -176,7 +176,7 @@ void qbus_free(BusState *bus);void do_info_qtree (Monitor *mon);void do_info_qdm (Monitor *mon);int do_device_add (Monitor *mon,const QDict *qdict,QObject **ret_data); -void do_device_del (Monitor *mon,const QDict *qdict); +int do_device_del (Monitor *mon,const QDict *qdict,QObject **ret_data);/*** qdev-properties.c ***/
qemu-monitor.hx +2 -1
@@ -589,7 +589,8 @@ ETEXI .args_type = "id:s", .params = "device", .help = "remove device", - .mhandler.cmd = do_device_del, + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_device_del, }, STEXI
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 3/21 Add qerror message if the 'change' target filename can't be opened
In reply to Luiz CapitulinoFrom: Ryan Harper <[email protected]>
Currently when using the change command to switch the file in the cd drive the command doesn't complain if the file doesn't exit or can't be opened and the drive keeps the existing image. This patch adds a qerror_report call to print a message out indicating the failure. This error message can be used to catch failures.
Current behavior:
QEMU 0.12.50 monitor - type 'help' for more information
(qemu) info block
ide0-hd0: type=hd removable=0 file=/dev/null ro=0 drv=host_device encrypted=0
ide1-cd0: type=cdrom removable=1 locked=0 [not inserted]
floppy0: type=floppy removable=1 locked=0 [not inserted]
sd0: type=floppy removable=1 locked=0 [not inserted]
(qemu) change ide1-cd0 /home/rharper/work/isos/Fedora-9-i386-DVD.iso (qemu) info block
ide0-hd0: type=hd removable=0 file=/dev/null ro=0 drv=host_device encrypted=0
ide1-cd0: type=cdrom removable=1 locked=0 file=/home/rharper/work/isos/Fedora-9-i386-DVD.iso ro=0 drv=raw encrypted=0
floppy0: type=floppy removable=1 locked=0 [not inserted]
sd0: type=floppy removable=1 locked=0 [not inserted]
(qemu) change ide1-cd0 /tmp/non_existent_file.iso
(qemu) info block
ide0-hd0: type=hd removable=0 file=/dev/null ro=0 drv=host_device encrypted=0
ide1-cd0: type=cdrom removable=1 locked=0 [not inserted]
floppy0: type=floppy removable=1 locked=0 [not inserted]
sd0: type=floppy removable=1 locked=0 [not inserted]
(qemu)
With patch:
QEMU 0.12.50 monitor - type 'help' for more information (qemu) change ide1-cd0 /tmp/non_existent_file.iso Could not open '/tmp/non_existent_file.iso' (qemu)
--- monitor.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
monitor.c +1 -0
@@ -1097,6 +1097,7 @@ static int do_change_block(Monitor *mon, const char *device,return -1 ; }if (bdrv_open2 (bs, filename,BDRV_O_RDWR , drv) <0 ) { +qerror_report (QERR_OPEN_FILE_FAILED , filename);return -1 ; }return monitor_read_bdrv_key_start (mon, bs,NULL ,NULL );
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 4/21 error: Put error definitions back in alphabetical order
In reply to Luiz CapitulinoFrom: Markus Armbruster <[email protected]>
Add suitable comments to help keerp them in order.
--- qerror.c | 12 ++++++++---- qerror.h | 8 +++++--- 2 files changed, 13 insertions(+), 7 deletions(-)
qerror.c +8 -4
@@ -38,6 +38,10 @@ static const QType qerror_type = {* for example: * * "running out of foo: %(foo)%%" +* +* Please keep the entries in alphabetical order. +* Use "sed -n '/^static.*qerror_table\[\]/,/^};/s/QERR_/&/gp' qerror.c | sort -c" +* to check. */ static const QErrorStringTable qerror_table[] = { {
@@ -65,10 +69,6 @@ static const QErrorStringTable qerror_table[] = { .desc = "Device '%(device)' could not be initialized", }, { - .error_fmt = QERR_DEVICE_NOT_ENCRYPTED, - .desc = "Device '%(device)' is not encrypted", - }, - { .error_fmt = QERR_DEVICE_LOCKED, .desc = "Device '%(device)' is locked", },
@@ -81,6 +81,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "Device '%(device)' has not been activated by the guest", }, { + .error_fmt = QERR_DEVICE_NOT_ENCRYPTED, + .desc = "Device '%(device)' is not encrypted", + }, + { .error_fmt = QERR_DEVICE_NOT_FOUND, .desc = "Device '%(device)' not found", },
qerror.h +5 -3
@@ -46,6 +46,8 @@ QError *qobject_to_qerror(const QObject *obj);/* * QError class list +* Please keep the definitions in alphabetical order. +* Use "grep '^#define QERR_' qerror.h | sort -c" to check. */ #define QERR_BAD_BUS_FOR_DEVICE \ "{ 'class': 'BadBusForDevice', 'data': { 'device': %s, 'bad_bus_type': %s } }"
@@ -62,9 +64,6 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_DEVICE_ENCRYPTED \ "{ 'class': 'DeviceEncrypted', 'data': { 'device': %s } }" -#define QERR_DEVICE_NOT_ENCRYPTED \ - "{ 'class': 'DeviceNotEncrypted', 'data': { 'device': %s } }" -#define QERR_DEVICE_INIT_FAILED \ "{ 'class': 'DeviceInitFailed', 'data': { 'device': %s } }"
@@ -77,6 +76,9 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_DEVICE_NOT_ACTIVE \ "{ 'class': 'DeviceNotActive', 'data': { 'device': %s } }" +#define QERR_DEVICE_NOT_ENCRYPTED \ + "{ 'class': 'DeviceNotEncrypted', 'data': { 'device': %s } }" +#define QERR_DEVICE_NOT_FOUND \ "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }"
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 5/21 error: New QERR_DUPLICATE_ID
In reply to Luiz CapitulinoFrom: Markus Armbruster <[email protected]>
--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
@@ -97,6 +97,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "Device '%(device)' has no child bus", }, { + .error_fmt = QERR_DUPLICATE_ID, + .desc = "Duplicate ID '%(id)' for %(object)", + }, + { .error_fmt = QERR_FD_NOT_FOUND, .desc = "File descriptor named '%(name)' not found", },
qerror.h +3 -0
@@ -88,6 +88,9 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_DEVICE_NO_BUS \ "{ 'class': 'DeviceNoBus', 'data': { 'device': %s } }" +#define QERR_DUPLICATE_ID \ + "{ 'class': 'DuplicateId', 'data': { 'id': %s, 'object': %s } }" +#define QERR_FD_NOT_FOUND \ "{ 'class': 'FdNotFound', 'data': { 'name': %s } }"
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 6/21 error: Convert qemu_opts_create() to QError
In reply to Luiz CapitulinoFrom: Markus Armbruster <[email protected]>
Fixes device_add to report duplicate ID properly in QMP, as DuplicateId instead of UndefinedError.
--- qemu-option.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
qemu-option.c +2 -2
@@ -30,6 +30,7 @@#include "qemu-error.h" #include "qemu-objects.h" #include "qemu-option.h" +#include "qerror.h" /* * Extracts the name of an option from the parameter string (p points at the
@@ -643,8 +644,7 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, int fail_if_exist opts =qemu_opts_find (list, id);if (opts !=NULL ) {if (fail_if_exists) { -fprintf (stderr,"tried to create id \"%s\" twice for \"%s\"\n" , - id, list->name); +qerror_report (QERR_DUPLICATE_ID , id, list->name);return NULL ; }else {return opts;
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 7/21 error: New QERR_INVALID_PARAMETER_VALUE
In reply to Luiz CapitulinoFrom: Markus Armbruster <[email protected]>
--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
@@ -121,6 +121,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "Invalid parameter type, expected: %(expected)", }, { + .error_fmt = QERR_INVALID_PARAMETER_VALUE, + .desc = "Parameter '%(name)' expects %(expected)", + }, + { .error_fmt = QERR_INVALID_PASSWORD, .desc = "Password incorrect", },
qerror.h +3 -0
@@ -106,6 +106,9 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_INVALID_PARAMETER_TYPE \ "{ 'class': 'InvalidParameterType', 'data': { 'name': %s,'expected': %s } }" +#define QERR_INVALID_PARAMETER_VALUE \ + "{ 'class': 'InvalidParameterValue', 'data': { 'name': %s, 'expected': %s } }" +#define QERR_INVALID_PASSWORD \ "{ 'class': 'InvalidPassword', 'data': {} }"
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 8/21 error: Convert qemu_opts_set() to QError
In reply to Luiz CapitulinoFrom: Markus Armbruster <[email protected]>
--- qemu-option.c | 17 +++++++---------- 1 files changed, 7 insertions(+), 10 deletions(-)
qemu-option.c +7 -10
@@ -176,7 +176,7 @@ static int parse_option_bool(const char *name, const char *value, int *ret) }else if (!strcmp (value,"off" )) { *ret =0 ; }else { -fprintf (stderr,"Option '%s': Use 'on' or 'off'\n" , name); +qerror_report (QERR_INVALID_PARAMETER_VALUE , name,"'on' or 'off'" );return -1 ; } }else {
@@ -193,12 +193,12 @@ static int parse_option_number(const char *name, const char *value, uint64_t *reif (value !=NULL ) { number =strtoull (value, &postfix,0 );if (*postfix !='\0' ) { -fprintf (stderr,"Option '%s' needs a number as parameter\n" , name); +qerror_report (QERR_INVALID_PARAMETER_VALUE , name,"a number" );return -1 ; } *ret = number; }else { -fprintf (stderr,"Option '%s' needs a parameter\n" , name); +qerror_report (QERR_INVALID_PARAMETER_VALUE , name,"a number" );return -1 ; }return 0 ;
@@ -226,13 +226,13 @@ static int parse_option_size(const char *name, const char *value, uint64_t *ret) *ret = (uint64_t ) sizef;break ;default : -fprintf (stderr,"Option '%s' needs size as parameter\n" , name); -fprintf (stderr,"You may use k, M, G or T suffixes for " +qerror_report (QERR_INVALID_PARAMETER_VALUE , name,"a size" ); +error_printf_unless_qmp ("You may use k, M, G or T suffixes for " "kilobytes, megabytes, gigabytes and terabytes.\n" );return -1 ; } }else { -fprintf (stderr,"Option '%s' needs a parameter\n" , name); +qerror_report (QERR_INVALID_PARAMETER_VALUE , name,"a size" );return -1 ; }return 0 ;
@@ -581,8 +581,7 @@ int qemu_opt_set(QemuOpts *opts, const char *name, const char *value)if (i ==0 ) {/* empty list -> allow any */ ; }else { -fprintf (stderr,"option \"%s\" is not valid for %s\n" , - name, opts->list->name); +qerror_report (QERR_INVALID_PARAMETER , name);return -1 ; } }
@@ -598,8 +597,6 @@ int qemu_opt_set(QemuOpts *opts, const char *name, const char *value) opt->str =qemu_strdup (value); }if (qemu_opt_parse (opt) <0 ) { -fprintf (stderr,"Failed to parse \"%s\" for \"%s.%s\"\n" , opt->str, - opts->list->name, opt->name);qemu_opt_del (opt);return -1 ; }
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 9/21 error: Drop extra messages after qemu_opts_set() and qemu_opts_parse()
In reply to Luiz CapitulinoFrom: Markus Armbruster <[email protected]>
Both functions report errors nicely enough now, no need for additional messages.
--- hw/pci-hotplug.c | 2 -- net.c | 2 -- qemu-config.c | 1 - vl.c | 5 ----- 4 files changed, 0 insertions(+), 10 deletions(-)
hw/pci-hotplug.c +0 -2
@@ -56,8 +56,6 @@ static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, opts =qemu_opts_parse (&qemu_net_opts, opts_str ? opts_str :"" ,0 );if (!opts) { -monitor_printf (mon,"parsing network options '%s' failed\n" , - opts_str ? opts_str :"" );return NULL ; }
net.c +0 -2
@@ -1169,8 +1169,6 @@ void net_host_device_add(Monitor *mon, const QDict *qdict) opts =qemu_opts_parse (&qemu_net_opts, opts_str ? opts_str :"" ,0 );if (!opts) { -monitor_printf (mon,"parsing network options '%s' failed\n" , - opts_str ? opts_str :"" );return ; }
qemu-config.c +0 -1
@@ -472,7 +472,6 @@ int qemu_config_parse(FILE *fp, const char *fname) goto out; }if (qemu_opt_set (opts, arg, value) !=0 ) { -error_report ("failed to set \"%s\" for %s" , arg, group); goto out; }continue ;
vl.c +0 -5
@@ -729,8 +729,6 @@ QemuOpts *drive_add(const char *file, const char *fmt, ...) opts =qemu_opts_parse (&qemu_drive_opts, optstr,0 );if (!opts) { -fprintf (stderr,"%s: huh? duplicate? (%s)\n" , - __FUNCTION__, optstr);return NULL ; }if (file)
@@ -3146,7 +3144,6 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_mon: opts =qemu_opts_parse (&qemu_mon_opts, optarg,1 );if (!opts) { -fprintf (stderr,"parse error: %s\n" , optarg);exit (1 ); } default_monitor =0 ;
@@ -3154,7 +3151,6 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_chardev: opts =qemu_opts_parse (&qemu_chardev_opts, optarg,1 );if (!opts) { -fprintf (stderr,"parse error: %s\n" , optarg);exit (1 ); }break ;
@@ -3352,7 +3348,6 @@ int main(int argc, char **argv, char **envp)case QEMU_OPTION_rtc: opts =qemu_opts_parse (&qemu_rtc_opts, optarg,0 );if (!opts) { -fprintf (stderr,"parse error: %s\n" , optarg);exit (1 ); }configure_rtc (opts);
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 10/21 error: Use QERR_INVALID_PARAMETER_VALUE instead of QERR_INVALID_PARAMETER
In reply to Luiz CapitulinoFrom: Markus Armbruster <[email protected]>
--- hw/qdev.c | 2 +- monitor.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-)
hw/qdev.c +1 -1
@@ -207,7 +207,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)/* find driver */ info =qdev_find_info (NULL , driver);if (!info || info->no_user) { -qerror_report (QERR_INVALID_PARAMETER ,"driver" ); +qerror_report (QERR_INVALID_PARAMETER_VALUE ,"driver" ,"a driver name" );error_printf_unless_qmp ("Try with argument '?' for a list.\n" );return NULL ; }
monitor.c +4 -2
@@ -970,7 +970,8 @@ static int do_cpu_set(Monitor *mon, const QDict *qdict, QObject **ret_data) {int index =qdict_get_int (qdict,"index" );if (mon_set_cpu (index) <0 ) { -qerror_report (QERR_INVALID_PARAMETER ,"index" ); +qerror_report (QERR_INVALID_PARAMETER_VALUE ,"index" , +"a CPU number" );return -1 ; }return 0 ;
@@ -2490,7 +2491,8 @@ static int do_getfd(Monitor *mon, const QDict *qdict, QObject **ret_data) }if (qemu_isdigit (fdname[0 ])) { -qerror_report (QERR_INVALID_PARAMETER ,"fdname" ); +qerror_report (QERR_INVALID_PARAMETER_VALUE ,"fdname" , +"a name not starting with a digit" );return -1 ; }
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 11/21 error: Convert qemu_opts_validate() to QError
In reply to Luiz CapitulinoFrom: Markus Armbruster <[email protected]>
--- qemu-option.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
qemu-option.c +1 -2
@@ -877,8 +877,7 @@ int qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc) } }if (desc[i].name ==NULL ) { -fprintf (stderr,"option \"%s\" is not valid for %s\n" , - opt->name, opts->list->name); +qerror_report (QERR_INVALID_PARAMETER , opt->name);return -1 ; }
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 12/21 error: Convert net_client_init() to QError
In reply to Luiz CapitulinoFrom: Markus Armbruster <[email protected]>
The conversion is shallow: client type init() methods aren't converted. Converting them is a big job for relatively little practical benefit, so leave it for later.
--- net.c | 38 ++++++++++++++++++-------------------- 1 files changed, 18 insertions(+), 20 deletions(-)
net.c +18 -20
@@ -1065,18 +1065,12 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev)int i; type =qemu_opt_get (opts,"type" ); +if (!type) { +qerror_report (QERR_MISSING_PARAMETER ,"type" ); +return -1 ; + } -if (!is_netdev) { -if (!type) { -error_report ("No type specified for -net" ); -return -1 ; - } - }else { -if (!type) { -error_report ("No type specified for -netdev" ); -return -1 ; - } - +if (is_netdev) { if (strcmp(type, "tap") != 0 &&#ifdef CONFIG_SLIRP strcmp(type, "user") != 0 &&
@@ -1085,21 +1079,21 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev) strcmp(type, "vde") != 0 && #endif strcmp(type, "socket") != 0) { -error_report ("The '%s' network backend type is not valid with -netdev" , - type); +qerror_report (QERR_INVALID_PARAMETER_VALUE ,"type" , +"a netdev backend type" );return -1 ; }if (qemu_opt_get (opts,"vlan" )) { -error_report ("The 'vlan' parameter is not valid with -netdev" ); +qerror_report (QERR_INVALID_PARAMETER ,"vlan" );return -1 ; }if (qemu_opt_get (opts,"name" )) { -error_report ("The 'name' parameter is not valid with -netdev" ); +qerror_report (QERR_INVALID_PARAMETER ,"name" );return -1 ; }if (!qemu_opts_id (opts)) { -error_report ("The id= parameter is required with -netdev" ); +qerror_report (QERR_MISSING_PARAMETER ,"id" );return -1 ; } }
@@ -1125,14 +1119,18 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev) }if (net_client_types[i].init) { -return net_client_types[i].init (opts, mon, name, vlan); - }else { -return 0 ; +if (net_client_types[i].init (opts, mon, name, vlan) <0 ) { +/* TODO push error reporting into init() methods */ +qerror_report (QERR_DEVICE_INIT_FAILED , type); +return -1 ; + } } +return 0 ; } } -error_report ("Invalid -net type '%s'" , type); +qerror_report (QERR_INVALID_PARAMETER_VALUE ,"type" , +"a network client type" );return -1 ; }
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 13/21 error: New QERR_DEVICE_IN_USE
In reply to Luiz CapitulinoFrom: Markus Armbruster <[email protected]>
--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
@@ -69,6 +69,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "Device '%(device)' could not be initialized", }, { + .error_fmt = QERR_DEVICE_IN_USE, + .desc = "Device '%(device)' is in use", + }, + { .error_fmt = QERR_DEVICE_LOCKED, .desc = "Device '%(device)' is locked", },
qerror.h +3 -0
@@ -67,6 +67,9 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_DEVICE_INIT_FAILED \ "{ 'class': 'DeviceInitFailed', 'data': { 'device': %s } }" +#define QERR_DEVICE_IN_USE \ + "{ 'class': 'DeviceInUse', 'data': { 'device': %s } }" +#define QERR_DEVICE_LOCKED \ "{ 'class': 'DeviceLocked', 'data': { 'device': %s } }"
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 14/21 monitor: New commands netdev_add, netdev_del
In reply to Luiz CapitulinoFrom: Markus Armbruster <[email protected]>
Monitor commands to go with -netdev.
--- net.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ net.h | 2 ++ qemu-monitor.hx | 30 ++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 0 deletions(-)
net.c +55 -0
@@ -1194,6 +1194,61 @@ void net_host_device_remove(Monitor *mon, const QDict *qdict)qemu_del_vlan_client (vc); } +/** +* do_netdev_add(): Add a host network device +* +* Argument qdict contains +* - "type": the device type, "tap", "user", ... +* - "id": the device's ID (must be unique) +* - device options +* +* Example: +* +* { "type": "user", "id": "netdev1", "hostname": "a-guest" } +*/ +int do_netdev_add (Monitor *mon,const QDict *qdict,QObject **ret_data) +{ +QemuOpts *opts; +int res; + + opts =qemu_opts_from_qdict (&qemu_netdev_opts, qdict); +if (!opts) { +return -1 ; + } + + res =net_client_init (mon, opts,1 ); +return res; +} + +/** +* do_netdev_del(): Delete a host network device +* +* Argument qdict contains +* - "id": the device's ID +* +* Example: +* +* { "id": "netdev1" } +*/ +int do_netdev_del (Monitor *mon,const QDict *qdict,QObject **ret_data) +{ +const char *id =qdict_get_str (qdict,"id" ); +VLANClientState *vc; + + vc =qemu_find_netdev (id); +if (!vc || vc->info->type ==NET_CLIENT_TYPE_NIC ) { +qerror_report (QERR_DEVICE_NOT_FOUND , id); +return -1 ; + } +if (vc->peer) { +qerror_report (QERR_DEVICE_IN_USE , id); +return -1 ; + } +qemu_del_vlan_client (vc); +qemu_opts_del (qemu_opts_find (&qemu_netdev_opts, id)); +return 0 ; +} +void net_set_boot_mask (int net_boot_mask) {int i;
net.h +2 -0
@@ -166,6 +166,8 @@ void net_cleanup(void);void net_set_boot_mask (int boot_mask);void net_host_device_add (Monitor *mon,const QDict *qdict);void net_host_device_remove (Monitor *mon,const QDict *qdict); +int do_netdev_add (Monitor *mon,const QDict *qdict,QObject **ret_data); +int do_netdev_del (Monitor *mon,const QDict *qdict,QObject **ret_data);#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
qemu-monitor.hx +30 -0
@@ -914,6 +914,36 @@ STEXI Remove host VLAN client. ETEXI + { + .name = "netdev_add", + .args_type = "netdev:O", + .params = "[user|tap|socket],id=str[,prop=value][,...]", + .help = "add host network device", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_netdev_add, + }, + +STEXI +@item netdev_add +@findex netdev_add +Add host network device. +ETEXI + + { + .name = "netdev_del", + .args_type = "id:s", + .params = "id", + .help = "remove host network device", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_netdev_del, + }, + +STEXI +@item netdev_del +@findex netdev_del +Remove host network device. +ETEXI + #ifdef CONFIG_SLIRP { .name = "hostfwd_add",
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 15/21 monitor: Rename argument type 'b' to 'f'
In reply to Luiz CapitulinoFrom: Markus Armbruster <[email protected]>
To make 'b' available for boolean argument.
--- monitor.c | 8 ++++---- qemu-monitor.hx | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
monitor.c +4 -4
@@ -74,7 +74,7 @@* 'l' target long (32 or 64 bit) * 'M' just like 'l', except in user mode the value is * multiplied by 2^20 (think Mebibyte) -* 'b' double +* 'f' double * user mode accepts an optional G, g, M, m, K, k suffix, * which multiplies the value by 2^30 for suffixes G and * g, 2^20 for M and m, 2^10 for K and k
@@ -3799,7 +3799,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,qdict_put (qdict, key,qint_from_int (val)); }break ; -case 'b' : +case 'f' :case 'T' : {double val;
@@ -3815,7 +3815,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,if (get_double (mon, &val, &p) <0 ) { goto fail; } -if (c =='b' && *p) { +if (c =='f' && *p) {switch (*p) {case 'K' :case 'k' : val *=1 <<10 ; p++;break ;
@@ -4316,7 +4316,7 @@ static int check_arg(const CmdArgs *cmd_args, QDict *args)return -1 ; }break ; -case 'b' : +case 'f' :case 'T' :if (qobject_type (value) !=QTYPE_QINT &&qobject_type (value) !=QTYPE_QFLOAT ) {qerror_report (QERR_INVALID_PARAMETER_TYPE , name,"number" );
qemu-monitor.hx +1 -1
@@ -804,7 +804,7 @@ ETEXI { .name = "migrate_set_speed", - .args_type = "value:b", + .args_type = "value:f", .params = "value", .help = "set maximum speed (in bytes) for migrations", .user_print = monitor_user_noop,
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 16/21 monitor: New argument type 'b'
In reply to Luiz CapitulinoFrom: Markus Armbruster <[email protected]>
This is a boolean value. Human monitor accepts "on" or "off". Consistent with option parsing (see parse_option_bool()).
--- monitor.c | 31 +++++++++++++++++++++++++++++++ 1 files changed, 31 insertions(+), 0 deletions(-)
monitor.c +31 -0
@@ -85,6 +85,8 @@* * '?' optional type (for all types, except '/') * '.' other form of optional type (for 'i' and 'l') +* 'b' boolean +* user mode accepts "on" or "off" * '-' optional parameter (eg. '-f') * */
@@ -3842,6 +3844,29 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,qdict_put (qdict, key,qfloat_from_double (val)); }break ; +case 'b' : + { +const char *beg; +int val; + +while (qemu_isspace (*p)) { + p++; + } + beg = p; +while (qemu_isgraph (*p)) { + p++; + } +if (p - beg ==2 && !memcmp (beg,"on" , p - beg)) { + val =1 ; + }else if (p - beg ==3 && !memcmp (beg,"off" , p - beg)) { + val =0 ; + }else { +monitor_printf (mon,"Expected 'on' or 'off'\n" ); + goto fail; + } +qdict_put (qdict, key,qbool_from_int (val)); + } +break ;case '-' : {const char *tmp = p;
@@ -4323,6 +4348,12 @@ static int check_arg(const CmdArgs *cmd_args, QDict *args)return -1 ; }break ; +case 'b' : +if (qobject_type (value) !=QTYPE_QBOOL ) { +qerror_report (QERR_INVALID_PARAMETER_TYPE , name,"bool" ); +return -1 ; + } +break ;case '-' :if (qobject_type (value) !=QTYPE_QINT &&qobject_type (value) !=QTYPE_QBOOL ) {
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 17/21 monitor: Use argument type 'b' for set_link
In reply to Luiz CapitulinoFrom: Markus Armbruster <[email protected]>
Second argument is now "on" or "off" instead of "up" or "down".
--- net.c | 10 ++-------- qemu-monitor.hx | 8 ++++---- 2 files changed, 6 insertions(+), 12 deletions(-)
net.c +2 -8
@@ -1296,7 +1296,7 @@ void do_set_link(Monitor *mon, const QDict *qdict)VLANState *vlan;VLANClientState *vc =NULL ;const char *name =qdict_get_str (qdict,"name" ); -const char *up_or_down =qdict_get_str (qdict,"up_or_down" ); +int up =qdict_get_bool (qdict,"up" ); QTAILQ_FOREACH(vlan, &vlans, next) { QTAILQ_FOREACH(vc, &vlan->clients, next) {
@@ -1313,13 +1313,7 @@ done:return ; } -if (strcmp (up_or_down,"up" ) ==0 ) - vc->link_down =0 ; -else if (strcmp (up_or_down,"down" ) ==0 ) - vc->link_down =1 ; -else -monitor_printf (mon,"invalid link status '%s'; only 'up' or 'down' " -"valid\n" , up_or_down); + vc->link_down = !up;if (vc->info->link_status_changed) { vc->info->link_status_changed (vc);
qemu-monitor.hx +4 -4
@@ -986,16 +986,16 @@ ETEXI { .name = "set_link", - .args_type = "name:s,up_or_down:s", - .params = "name up|down", + .args_type = "name:s,up:b", + .params = "name on|off", .help = "change the link status of a network adapter", .mhandler.cmd = do_set_link, }, STEXI -@item set_link @var{name} [up|down] +@item set_link @var{name} [on|off] @findex set_link -Set link @var{name} up or down. +Switch link @var{name} on (i.e. up) or off (i.e. down). ETEXI {
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 18/21 monitor: Convert do_set_link() to QObject, QError
In reply to Luiz CapitulinoFrom: Markus Armbruster <[email protected]>
--- net.c | 7 ++++--- net.h | 2 +- qemu-monitor.hx | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-)
net.c +4 -3
@@ -1291,7 +1291,7 @@ void do_info_network(Monitor *mon) } } -void do_set_link (Monitor *mon,const QDict *qdict) +int do_set_link (Monitor *mon,const QDict *qdict,QObject **ret_data) {VLANState *vlan;VLANClientState *vc =NULL ;
@@ -1309,8 +1309,8 @@ void do_set_link(Monitor *mon, const QDict *qdict) done:if (!vc) { -monitor_printf (mon,"could not find network device '%s'\n" , name); -return ; +qerror_report (QERR_DEVICE_NOT_FOUND , name); +return -1 ; } vc->link_down = !up;
@@ -1318,6 +1318,7 @@ done:if (vc->info->link_status_changed) { vc->info->link_status_changed (vc); } +return 0 ; }void net_cleanup (void )
net.h +1 -1
@@ -118,7 +118,7 @@ int qemu_find_nic_model(NICInfo *nd, const char * const *models, const char *default_model);void do_info_network (Monitor *mon); -void do_set_link (Monitor *mon,const QDict *qdict); +int do_set_link (Monitor *mon,const QDict *qdict,QObject **ret_data);/* NIC info */
qemu-monitor.hx +2 -1
@@ -989,7 +989,8 @@ ETEXI .args_type = "name:s,up:b", .params = "name on|off", .help = "change the link status of a network adapter", - .mhandler.cmd = do_set_link, + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_set_link, }, STEXI
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 19/21 virtio-blk: Fix use after free in error case
In reply to Luiz CapitulinoFrom: Kevin Wolf <[email protected]>
virtio_blk_req_complete frees the request, so we can't access it any more when calling bdrv_mon_event. Use the pointer that was copied earlier.
--- hw/virtio-blk.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
hw/virtio-blk.c +3 -3
@@ -65,7 +65,7 @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,VirtIOBlock *s = req->dev;if (action ==BLOCK_ERR_IGNORE ) { -bdrv_mon_event (req->dev->bs,BDRV_ACTION_IGNORE , is_read); +bdrv_mon_event (s->bs,BDRV_ACTION_IGNORE , is_read);return 0 ; }
@@ -73,11 +73,11 @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error, || action == BLOCK_ERR_STOP_ANY) { req->next = s->rq; s->rq = req; - bdrv_mon_event(req->dev->bs, BDRV_ACTION_STOP, is_read); + bdrv_mon_event(s->bs, BDRV_ACTION_STOP, is_read); vm_stop(0); } else {virtio_blk_req_complete (req,VIRTIO_BLK_S_IOERR ); -bdrv_mon_event (req->dev->bs,BDRV_ACTION_REPORT , is_read); +bdrv_mon_event (s->bs,BDRV_ACTION_REPORT , is_read); }return 1 ;
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 20/21 QMP: Improve RTC_CHANGE event description
In reply to Luiz CapitulinoSome people might think that this event is emitted whenever the time changes, be more specific.
--- QMP/qmp-events.txt | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
QMP/qmp-events.txt +1 -1
@@ -41,7 +41,7 @@ Example: RTC_CHANGE ---------- -Emitted when the RTC time changes. +Emitted when the guest changes the RTC time. Data:
Signature · 1 line
1.7.0.4.297.g6555b1
PATCH 21/21 Monitor: Convert do_screen_dump() to QObject
In reply to Luiz CapitulinoTrivial, as it never fails, doesn't have output nor return any data.
Note that it's also available under QMP, as kvm-autotest needs this.
--- monitor.c | 3 ++- qemu-monitor.hx | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
monitor.c +2 -1
@@ -1164,9 +1164,10 @@ static int do_change(Monitor *mon, const QDict *qdict, QObject **ret_data)return ret; } -static void do_screen_dump (Monitor *mon,const QDict *qdict) +static int do_screen_dump (Monitor *mon,const QDict *qdict,QObject **ret_data) {vga_hw_screen_dump (qdict_get_str (qdict,"filename" )); +return 0 ; }static void do_logfile (Monitor *mon,const QDict *qdict)
qemu-monitor.hx +2 -1
@@ -199,7 +199,8 @@ ETEXI .args_type = "filename:F", .params = "filename", .help = "save screen into PPM image 'filename'", - .mhandler.cmd = do_screen_dump, + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_screen_dump, }, STEXI
Signature · 1 line
1.7.0.4.297.g6555b1
Quoted 6 lines · Luiz Capitulino
Hi Anthony,
I was going to nag you to apply patches from the list, but as I'm maintaining
a QMP/Monitor queue to test them, I thought it would be a good idea to nag you in the form of a git pull :)
Quoted 8 lines
All the patches in there have been posted to the list already and, to make it
convenient to review, I'm sending them again in this series (not sure if it's a good idea, though).The changes (since
116348def2bb446d972bdc2f44bd77ff631f85de) are available in
the following repository:
git://repo.or.cz/qemu/qmp-unstable.gitfor-anthony
As Anthony doesn't seem to be available, I have just pulled your tree.
Quoted 47 lines
Kevin Wolf (1):
virtio-blk: Fix use after free in error caseLuiz Capitulino (2):
QMP: ImproveRTC_CHANGEevent description
Monitor: Convertdo_screen_dump()to QObjectMarkus Armbruster (17):
qdev: Convertqdev_unplug()to QError
monitor: convertdo_device_del()to QObject, QError
error: Put error definitions back in alphabetical order
error: NewQERR_DUPLICATE_ID
error: Convertqemu_opts_create()to QError
error: NewQERR_INVALID_PARAMETER_VALUE
error: Convertqemu_opts_set()to QError
error: Drop extra messages afterqemu_opts_set()andqemu_opts_parse()
error: UseQERR_INVALID_PARAMETER_VALUEinstead ofQERR_INVALID_PARAMETER
error: Convertqemu_opts_validate()to QError
error: Convertnet_client_init()to QError
error: NewQERR_DEVICE_IN_USE
monitor: New commandsnetdev_add,netdev_del
monitor: Rename argument type 'b' to 'f'
monitor: New argument type 'b'
monitor: Use argument type 'b' forset_link
monitor: Convertdo_set_link()to QObject, QErrorRyan Harper (1):
Add qerror message if the 'change' target filename can't be openedQMP/qmp-events.txt | 2 +- hw/pci-hotplug.c | 2 - hw/qdev.c | 13 +++--- hw/qdev.h | 2 +- hw/virtio-blk.c | 6 +- monitor.c | 49 +++++++++++++++++++--- net.c | 112 ++++++++++++++++++++++++++++++++++++--------------- net.h | 4 +- qemu-config.c | 1 - qemu-monitor.hx | 49 +++++++++++++++++++---- qemu-option.c | 24 +++++------ qerror.c | 20 ++++++++- qerror.h | 17 ++++++- vl.c | 5 -- 14 files changed, 218 insertions(+), 88 deletions(-)
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net
Quoted 11 lines · On Sun, 18 Apr 2010 23:58:43 +0200 Aurelien Jarno <[email protected]> wrote:
Quoted 10 lines · Luiz Capitulino
Hi Anthony,
I was going to nag you to apply patches from the list, but as I'm maintaining
a QMP/Monitor queue to test them, I thought it would be a good idea to nag you in the form of a git pull :)All the patches in there have been posted to the list already and, to make it
convenient to review, I'm sending them again in this series (not sure if it's a good idea, though).
Quoted 6 lines
Quoted 4 lines
The changes (since
116348def2bb446d972bdc2f44bd77ff631f85de) are available in
the following repository:
git://repo.or.cz/qemu/qmp-unstable.gitfor-anthonyAs Anthony doesn't seem to be available, I have just pulled your tree.
Oh, thank you very much.