: QAPI conversions round 4
cover : QAPI conversions round 4
This is the beginning of the not so trivial commands, although most of them are not that complex either.
Please, note the inclusion of the change-vnc-password command. This is needed by the change conversion.
blockdev.c | 129 ++++++++++++++++++++------------------ blockdev.h | 8 +-- console.h | 3 - hmp-commands.hx | 15 ++--- hmp.c | 102 +++++++++++++++++++++++++++++++ hmp.h | 5 ++ monitor.c | 179 +++--------------------------------------------------- monitor.h | 5 ++ qapi-schema.json | 157 +++++++++++++++++++++++++++++++++++++++++++++++ qerror.h | 2 +- qmp-commands.hx | 31 +++------ qmp.c | 155 ++++++++++++++++++++++++++++++++++++++++++++++- ui/vnc.c | 14 +--- 13 files changed, 525 insertions(+), 280 deletions(-)
PATCH 1/10 vnc: Simplify vnc_display_password()
Drop the qerror_report() call from it and let its callers set the error themselves. This also allows for dropping the 'ret' variable.
--- console.h | 1 - monitor.c | 7 ++++++- ui/vnc.c | 14 ++++---------- 3 files changed, 10 insertions(+), 12 deletions(-)
console.h +0 -1
@@ -384,7 +384,6 @@ int vnc_display_pw_expire(DisplayState *ds, time_t expires);#else static inline int vnc_display_password (DisplayState *ds,const char *password) { -qerror_report (QERR_FEATURE_DISABLED ,"vnc" );return -ENODEV ; }static inline int vnc_display_pw_expire (DisplayState *ds,time_t expires)
monitor.c +6 -1
@@ -929,7 +929,12 @@ static int set_password(Monitor *mon, const QDict *qdict, QObject **ret_data) }/* Note that setting an empty password will not disable login through * this interface. */ -return vnc_display_password (NULL , password); + rc =vnc_display_password (NULL , password); +if (rc <0 ) { +qerror_report (QERR_SET_PASSWD_FAILED ); +return -1 ; + } +return 0 ; }qerror_report (QERR_INVALID_PARAMETER ,"protocol" );
ui/vnc.c +4 -10
@@ -2686,19 +2686,16 @@ int vnc_display_disable_login(DisplayState *ds)int vnc_display_password (DisplayState *ds,const char *password) { -int ret =0 ;VncDisplay *vs = ds ? (VncDisplay *)ds->opaque : vnc_display;if (!vs) { - ret = -EINVAL ; - goto out; +return -EINVAL ; }if (!password) {/* This is not the intention of this interface but err on the side of being safe */ - ret =vnc_display_disable_login (ds); - goto out; +return vnc_display_disable_login (ds); }if (vs->password) {
@@ -2707,11 +2704,8 @@ int vnc_display_password(DisplayState *ds, const char *password) } vs->password =g_strdup (password); vs->auth =VNC_AUTH_VNC ; -out: -if (ret !=0 ) { -qerror_report (QERR_SET_PASSWD_FAILED ); - } -return ret; + +return 0 ; }int vnc_display_pw_expire (DisplayState *ds,time_t expires)
Signature · 1 line
1.7.8.2.325.g247f9.dirty
PATCH 2/10 qapi: Convert set_password
In reply to Luiz Capitulino--- hmp-commands.hx | 3 +- hmp.c | 11 ++++++++++ hmp.h | 1 + monitor.c | 57 ------------------------------------------------------ qapi-schema.json | 29 +++++++++++++++++++++++++++ qmp-commands.hx | 5 +--- qmp.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 97 insertions(+), 63 deletions(-)
hmp-commands.hx +1 -2
@@ -1221,8 +1221,7 @@ ETEXI .args_type = "protocol:s,password:s,connected:s?", .params = "protocol password action-if-connected", .help = "set spice/vnc password", - .user_print = monitor_user_noop, - .mhandler.cmd_new = set_password, + .mhandler.cmd = hmp_set_password, }, STEXI
hmp.c +11 -0
@@ -679,3 +679,14 @@ void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)int64_t value =qdict_get_int (qdict,"value" );qmp_migrate_set_speed (value,NULL ); } + +void hmp_set_password (Monitor *mon,const QDict *qdict) +{ +const char *protocol =qdict_get_str (qdict,"protocol" ); +const char *password =qdict_get_str (qdict,"password" ); +const char *connected =qdict_get_try_str (qdict,"connected" ); +Error *err =NULL ; + +qmp_set_password (protocol, password, !!connected, connected, &err); +hmp_handle_error (mon, &err); +}
hmp.h +1 -0
@@ -49,5 +49,6 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict);void hmp_migrate_cancel (Monitor *mon,const QDict *qdict);void hmp_migrate_set_downtime (Monitor *mon,const QDict *qdict);void hmp_migrate_set_speed (Monitor *mon,const QDict *qdict); +void hmp_set_password (Monitor *mon,const QDict *qdict);#endif
monitor.c +0 -57
63 lines not on this page · raw message
qapi-schema.json +29 -0
@@ -1275,3 +1275,32 @@ { 'command': 'qom-set', 'data': { 'path': 'str', 'property': 'str', 'value': 'visitor' }, 'gen': 'no' } + +## +# @set_password: +# +# Sets the password of a remote display session. +# +# @protocol: `vnc' to modify the VNC server password +# `spice' to modify the Spice server password +# +# @password: the new password +# +# @connected: #optional how to handle existing clients when changing the +# password. If nothing is specified, defaults to `keep' +# `fail' to fail the command if clients are connected +# `disconnect' to disconnect existing clients +# `keep' to maintain existing clients +# +# Returns: Nothing on success +# If Spice is not enabled, DeviceNotFound +# If @protocol does not support connected, InvalidParameter +# If @protocol is invalid, InvalidParameter +# If any other error occurs, SetPasswdFailed +# +# Notes: If VNC is not enabled, SetPasswdFailed is returned. +# +# Since: 0.14.0 +## +{ 'command': 'set_password', + 'data': {'protocol': 'str', 'password': 'str', '*connected': 'str'} }
qmp-commands.hx +1 -4
@@ -851,10 +851,7 @@ EQMP { .name = "set_password", .args_type = "protocol:s,password:s,connected:s?", - .params = "protocol password action-if-connected", - .help = "set spice/vnc password", - .user_print = monitor_user_noop, - .mhandler.cmd_new = set_password, + .mhandler.cmd_new = qmp_marshal_input_set_password, }, SQMP
qmp.c +54 -0
63 lines not on this page · raw message
Signature · 1 line
1.7.8.2.325.g247f9.dirty
PATCH 3/10 qapi: Convert expire_password
In reply to Luiz Capitulino--- console.h | 2 -- hmp-commands.hx | 3 +-- hmp.c | 10 ++++++++++ hmp.h | 1 + monitor.c | 39 --------------------------------------- qapi-schema.json | 27 +++++++++++++++++++++++++++ qmp-commands.hx | 5 +---- qmp.c | 40 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 80 insertions(+), 47 deletions(-)
console.h +0 -2
@@ -4,7 +4,6 @@#include "qemu-char.h" #include "qdict.h" #include "notify.h" -#include "qerror.h" #include "monitor.h" /* keyboard/mouse support */
@@ -388,7 +387,6 @@ static inline int vnc_display_password(DisplayState *ds, const char *password) }static inline int vnc_display_pw_expire (DisplayState *ds,time_t expires) { -qerror_report (QERR_FEATURE_DISABLED ,"vnc" );return -ENODEV ; };#endif
hmp-commands.hx +1 -2
@@ -1241,8 +1241,7 @@ ETEXI .args_type = "protocol:s,time:s", .params = "protocol time", .help = "set spice/vnc password expire-time", - .user_print = monitor_user_noop, - .mhandler.cmd_new = expire_password, + .mhandler.cmd = hmp_expire_password, }, STEXI
hmp.c +10 -0
@@ -690,3 +690,13 @@ void hmp_set_password(Monitor *mon, const QDict *qdict)qmp_set_password (protocol, password, !!connected, connected, &err);hmp_handle_error (mon, &err); } + +void hmp_expire_password (Monitor *mon,const QDict *qdict) +{ +const char *protocol =qdict_get_str (qdict,"protocol" ); +const char *whenstr =qdict_get_str (qdict,"time" ); +Error *err =NULL ; + +qmp_expire_password (protocol, whenstr, &err); +hmp_handle_error (mon, &err); +}
hmp.h +1 -0
@@ -50,5 +50,6 @@ void hmp_migrate_cancel(Monitor *mon, const QDict *qdict);void hmp_migrate_set_downtime (Monitor *mon,const QDict *qdict);void hmp_migrate_set_speed (Monitor *mon,const QDict *qdict);void hmp_set_password (Monitor *mon,const QDict *qdict); +void hmp_expire_password (Monitor *mon,const QDict *qdict);#endif
monitor.c +0 -39
@@ -884,45 +884,6 @@ static int do_change(Monitor *mon, const QDict *qdict, QObject **ret_data)return ret; } -static int expire_password (Monitor *mon,const QDict *qdict,QObject **ret_data) -{ -const char *protocol =qdict_get_str (qdict,"protocol" ); -const char *whenstr =qdict_get_str (qdict,"time" ); -time_t when; -int rc; - -if (strcmp (whenstr,"now" ) ==0 ) { - when =0 ; - }else if (strcmp (whenstr,"never" ) ==0 ) { - when =TIME_MAX ; - }else if (whenstr[0 ] =='+' ) { - when =time (NULL ) +strtoull (whenstr+1 ,NULL ,10 ); - }else { - when =strtoull (whenstr,NULL ,10 ); - } - -if (strcmp (protocol,"spice" ) ==0 ) { -if (!using_spice) { -/* correct one? spice isn't a device ,,, */ -qerror_report (QERR_DEVICE_NOT_ACTIVE ,"spice" ); -return -1 ; - } - rc =qemu_spice_set_pw_expire (when); -if (rc !=0 ) { -qerror_report (QERR_SET_PASSWD_FAILED ); -return -1 ; - } -return 0 ; - } - -if (strcmp (protocol,"vnc" ) ==0 ) { -return vnc_display_pw_expire (NULL , when); - } - -qerror_report (QERR_INVALID_PARAMETER ,"protocol" ); -return -1 ; -} -static int add_graphics_client (Monitor *mon,const QDict *qdict,QObject **ret_data) {const char *protocol =qdict_get_str (qdict,"protocol" );
qapi-schema.json +27 -0
@@ -1304,3 +1304,30 @@ ## { 'command': 'set_password', 'data': {'protocol': 'str', 'password': 'str', '*connected': 'str'} } + +## +# @expire_password: +# +# Expire the password of a remote display server. +# +# @protocol: the name of the remote display protocol `vnc' or `spice' +# +# @time: when to expire the password. +# `now' to expire the password immediately +# `never' to cancel password expiration +# `+INT' where INT is the number of seconds from now (integer) +# `INT' where INT is the absolute time in seconds +# +# Returns: Nothing on success +# If @protocol is `spice' and Spice is not active, DeviceNotFound +# If an error occurs setting password expiration, SetPasswdFailed +# If @protocol is not `spice' or 'vnc', InvalidParameter +# +# Since: 0.14.0 +# +# Notes: Time is relative to the server and currently there is no way to +# coordinate server time with client time. It is not recommended to +# use the absolute time version of the @time parameter unless you're +# sure you are on the same machine as the QEMU instance. +## +{ 'command': 'expire_password', 'data': {'protocol': 'str', 'time': 'str'} }
qmp-commands.hx +1 -4
@@ -877,10 +877,7 @@ EQMP { .name = "expire_password", .args_type = "protocol:s,time:s", - .params = "protocol time", - .help = "set spice/vnc password expire-time", - .user_print = monitor_user_noop, - .mhandler.cmd_new = expire_password, + .mhandler.cmd_new = qmp_marshal_input_expire_password, }, SQMP
qmp.c +40 -0
@@ -301,3 +301,43 @@ void qmp_set_password(const char *protocol, const char *password,error_set (errp,QERR_INVALID_PARAMETER ,"protocol" ); } + +void qmp_expire_password (const char *protocol,const char *whenstr, +Error **errp) +{ +time_t when; +int rc; + +if (strcmp (whenstr,"now" ) ==0 ) { + when =0 ; + }else if (strcmp (whenstr,"never" ) ==0 ) { + when =TIME_MAX ; + }else if (whenstr[0 ] =='+' ) { + when =time (NULL ) +strtoull (whenstr+1 ,NULL ,10 ); + }else { + when =strtoull (whenstr,NULL ,10 ); + } + +if (strcmp (protocol,"spice" ) ==0 ) { +if (!using_spice) { +/* correct one? spice isn't a device ,,, */ +error_set (errp,QERR_DEVICE_NOT_ACTIVE ,"spice" ); +return ; + } + rc =qemu_spice_set_pw_expire (when); +if (rc !=0 ) { +error_set (errp,QERR_SET_PASSWD_FAILED ); + } +return ; + } + +if (strcmp (protocol,"vnc" ) ==0 ) { + rc =vnc_display_pw_expire (NULL , when); +if (rc !=0 ) { +error_set (errp,QERR_SET_PASSWD_FAILED ); + } +return ; + } + +error_set (errp,QERR_INVALID_PARAMETER ,"protocol" ); +}
Signature · 1 line
1.7.8.2.325.g247f9.dirty
PATCH 4/10 block: eject_device(): Use error_set()
In reply to Luiz CapitulinoAlso drops the leftover 'mon' argument.
This is a preparation for the next commits which will port the eject and change commands to the QAPI.
--- blockdev.c | 30 ++++++++++++++++++++++-------- 1 files changed, 22 insertions(+), 8 deletions(-)
blockdev.c +22 -8
@@ -665,21 +665,22 @@ void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file, } } -static int eject_device (Monitor *mon,BlockDriverState *bs,int force) +static void eject_device (BlockDriverState *bs,int force,Error **errp) {if (!bdrv_dev_has_removable_media (bs)) { -qerror_report (QERR_DEVICE_NOT_REMOVABLE ,bdrv_get_device_name (bs)); -return -1 ; +error_set (errp,QERR_DEVICE_NOT_REMOVABLE ,bdrv_get_device_name (bs)); +return ; } +if (bdrv_dev_is_medium_locked (bs) && !bdrv_dev_is_tray_open (bs)) {bdrv_dev_eject_request (bs, force);if (!force) { -qerror_report (QERR_DEVICE_LOCKED ,bdrv_get_device_name (bs)); -return -1 ; +error_set (errp,QERR_DEVICE_LOCKED ,bdrv_get_device_name (bs)); +return ; } } +bdrv_close (bs); -return 0 ; }int do_eject (Monitor *mon,const QDict *qdict,QObject **ret_data)
@@ -687,13 +688,22 @@ int do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data)BlockDriverState *bs;int force =qdict_get_try_bool (qdict,"force" ,0 );const char *filename =qdict_get_str (qdict,"device" ); +Error *err =NULL ; bs =bdrv_find (filename);if (!bs) {qerror_report (QERR_DEVICE_NOT_FOUND , filename);return -1 ; } -return eject_device (mon, bs, force); + +eject_device (bs, force, &err); +if (error_is_set (&err)) { +qerror_report_err (err); +error_free (err); +return -1 ; + } + +return 0 ; }void qmp_block_passwd (const char *device,const char *password,Error **errp)
@@ -723,6 +733,7 @@ int do_change_block(Monitor *mon, const char *device,BlockDriverState *bs;BlockDriver *drv =NULL ;int bdrv_flags; +Error *err =NULL ; bs =bdrv_find (device);if (!bs) {
@@ -736,7 +747,10 @@ int do_change_block(Monitor *mon, const char *device,return -1 ; } } -if (eject_device (mon, bs,0 ) <0 ) { +eject_device (bs,0 , &err); +if (error_is_set (&err)) { +qerror_report_err (err); +error_free (err);return -1 ; } bdrv_flags =bdrv_is_read_only (bs) ?0 :BDRV_O_RDWR ;
Signature · 1 line
1.7.8.2.325.g247f9.dirty
PATCH 5/10 qapi: Convert eject
In reply to Luiz Capitulino--- blockdev.c | 20 +++++--------------- blockdev.h | 1 - hmp-commands.hx | 3 +-- hmp.c | 10 ++++++++++ hmp.h | 1 + qapi-schema.json | 21 +++++++++++++++++++++ qmp-commands.hx | 5 +---- 7 files changed, 39 insertions(+), 22 deletions(-)
blockdev.c +5 -15
@@ -683,27 +683,17 @@ static void eject_device(BlockDriverState *bs, int force, Error **errp)bdrv_close (bs); } -int do_eject (Monitor *mon,const QDict *qdict,QObject **ret_data) +void qmp_eject (const char *device,bool has_force,bool force,Error **errp) {BlockDriverState *bs; -int force =qdict_get_try_bool (qdict,"force" ,0 ); -const char *filename =qdict_get_str (qdict,"device" ); -Error *err =NULL ; - bs =bdrv_find (filename); + bs =bdrv_find (device);if (!bs) { -qerror_report (QERR_DEVICE_NOT_FOUND , filename); -return -1 ; - } - -eject_device (bs, force, &err); -if (error_is_set (&err)) { -qerror_report_err (err); -error_free (err); -return -1 ; +error_set (errp,QERR_DEVICE_NOT_FOUND , device); +return ; } -return 0 ; +eject_device (bs, force, errp); }void qmp_block_passwd (const char *device,const char *password,Error **errp)
blockdev.h +0 -1
@@ -58,7 +58,6 @@ DriveInfo *drive_init(QemuOpts *arg, int default_to_scsi);DriveInfo *add_init_drive (const char *opts);void do_commit (Monitor *mon,const QDict *qdict); -int do_eject (Monitor *mon,const QDict *qdict,QObject **ret_data);int do_change_block (Monitor *mon,const char *device,const char *filename,const char *fmt);int do_drive_del (Monitor *mon,const QDict *qdict,QObject **ret_data);
hmp-commands.hx +1 -2
@@ -75,8 +75,7 @@ ETEXI .args_type = "force:-f,device:B", .params = "[-f] device", .help = "eject a removable medium (use -f to force it)", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_eject, + .mhandler.cmd = hmp_eject, }, STEXI
hmp.c +10 -0
@@ -700,3 +700,13 @@ void hmp_expire_password(Monitor *mon, const QDict *qdict)qmp_expire_password (protocol, whenstr, &err);hmp_handle_error (mon, &err); } + +void hmp_eject (Monitor *mon,const QDict *qdict) +{ +int force =qdict_get_try_bool (qdict,"force" ,0 ); +const char *device =qdict_get_str (qdict,"device" ); +Error *err =NULL ; + +qmp_eject (device, true, force, &err); +hmp_handle_error (mon, &err); +}
hmp.h +1 -0
@@ -51,5 +51,6 @@ void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict);void hmp_migrate_set_speed (Monitor *mon,const QDict *qdict);void hmp_set_password (Monitor *mon,const QDict *qdict);void hmp_expire_password (Monitor *mon,const QDict *qdict); +void hmp_eject (Monitor *mon,const QDict *qdict);#endif
qapi-schema.json +21 -0
@@ -1331,3 +1331,24 @@ # sure you are on the same machine as the QEMU instance. ## { 'command': 'expire_password', 'data': {'protocol': 'str', 'time': 'str'} } + +## +# @eject: +# +# Ejects a device from a removable drive. +# +# @device: The name of the device +# +# @force: @optional If true, eject regardless of whether the drive is locked. +# If not specified, the default value is false. +# +# Returns: Nothing on success +# If @device is not a valid block device, DeviceNotFound +# If @device is not removable and @force is false, DeviceNotRemovable +# If @force is false and @device is locked, DeviceLocked +# +# Notes: Ejecting a device will no media results in success +# +# Since: 0.14.0 +## +{ 'command': 'eject', 'data': {'device': 'str', '*force': 'bool'} }
qmp-commands.hx +1 -4
@@ -84,10 +84,7 @@ EQMP { .name = "eject", .args_type = "force:-f,device:B", - .params = "[-f] device", - .help = "eject a removable medium (use -f to force it)", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_eject, + .mhandler.cmd_new = qmp_marshal_input_eject, }, SQMP
Signature · 1 line
1.7.8.2.325.g247f9.dirty
PATCH 6/10 monitor: expose readline state
In reply to Luiz CapitulinoFrom: Anthony Liguori <[email protected]>
HMP is now implemented in terms of QMP. The monitor has a bunch of logic to deal with HMP right now like readline support. Export it from the monitor so we can consume it in hmp.c.
In short time, hmp.c will take over all of the readline bits.
--- monitor.c | 11 ++++++++--- monitor.h | 5 +++++ 2 files changed, 13 insertions(+), 3 deletions(-)
monitor.c +8 -3
@@ -227,7 +227,7 @@ int monitor_cur_is_qmp(void)return cur_mon &&monitor_ctrl_mode (cur_mon); } -static void monitor_read_command (Monitor *mon,int show_prompt) +void monitor_read_command (Monitor *mon,int show_prompt) {if (!mon->rs)return ;
@@ -237,8 +237,8 @@ static void monitor_read_command(Monitor *mon, int show_prompt)readline_show_prompt (mon->rs); } -static int monitor_read_password (Monitor *mon,ReadLineFunc *readline_func, -void *opaque) +int monitor_read_password (Monitor *mon,ReadLineFunc *readline_func, +void *opaque) {if (monitor_ctrl_mode (mon)) {qerror_report (QERR_MISSING_PARAMETER ,"password" );
@@ -4664,6 +4664,11 @@ static void bdrv_password_cb(Monitor *mon, const char *password, void *opaque)monitor_read_command (mon,1 ); } +ReadLineState *monitor_get_rs (Monitor *mon) +{ +return mon->rs; +} +int monitor_read_bdrv_key_start (Monitor *mon,BlockDriverState *bs,BlockDriverCompletionFunc *completion_cb,void *opaque)
monitor.h +5 -0
@@ -6,6 +6,7 @@#include "qerror.h" #include "qdict.h" #include "block.h" +#include "readline.h" extern Monitor *cur_mon;extern Monitor *default_mon;
@@ -66,6 +67,10 @@ int monitor_get_cpu_index(void);typedef void (MonitorCompletion )(void *opaque,QObject *ret_data);void monitor_set_error (Monitor *mon,QError *qerror); +void monitor_read_command (Monitor *mon,int show_prompt); +ReadLineState *monitor_get_rs (Monitor *mon); +int monitor_read_password (Monitor *mon,ReadLineFunc *readline_func, +void *opaque);int qmp_qom_set (Monitor *mon,const QDict *qdict,QObject **ret);
Signature · 1 line
1.7.8.2.325.g247f9.dirty
PATCH 7/10 qapi: Introduce change-vnc-password
In reply to Luiz CapitulinoNew QMP command to change the VNC password.
--- qapi-schema.json | 15 +++++++++++++++ qmp-commands.hx | 6 ++++++ qmp.c | 14 ++++++++++++++ 3 files changed, 35 insertions(+), 0 deletions(-)
qapi-schema.json +15 -0
@@ -1352,3 +1352,18 @@ # Since: 0.14.0 ## { 'command': 'eject', 'data': {'device': 'str', '*force': 'bool'} } + +## +# @change-vnc-password: +# +# Change the VNC server password. +# +# @target: the new password to use with VNC authentication +# +# Since: 1.1 +# +# Notes: An empty password in this command won't allow users to connect until +# the password is set again. Existing clients are unaffected by +# executing this command. +## +{ 'command': 'change-vnc-password', 'data': {'password': 'str'} }
qmp-commands.hx +6 -0
@@ -2018,3 +2018,9 @@ EQMP .args_type = "path:s,property:s", .mhandler.cmd_new = qmp_qom_get, }, + + { + .name = "change-vnc-password", + .args_type = "password:s", + .mhandler.cmd_new = qmp_marshal_input_change_vnc_password, + },
qmp.c +14 -0
@@ -341,3 +341,17 @@ void qmp_expire_password(const char *protocol, const char *whenstr,error_set (errp,QERR_INVALID_PARAMETER ,"protocol" ); } + +void qmp_change_vnc_password (const char *password,Error **errp) +{ +if (!password || !password[0 ]) { +if (vnc_display_disable_login (NULL ) <0 ) { +error_set (errp,QERR_SET_PASSWD_FAILED ); + } +return ; + } + +if (vnc_display_password (NULL , password) <0 ) { +error_set (errp,QERR_SET_PASSWD_FAILED ); + } +}
Signature · 1 line
1.7.8.2.325.g247f9.dirty
PATCH 8/10 qerror: Extend QERR_DEVICE_ENCRYPTED
In reply to Luiz CapitulinoInclude the name of the encrypted file.
--- monitor.c | 3 ++- qerror.h | 2 +- qmp.c | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-)
monitor.c +2 -1
@@ -4682,7 +4682,8 @@ int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, }if (monitor_ctrl_mode (mon)) { -qerror_report (QERR_DEVICE_ENCRYPTED ,bdrv_get_device_name (bs)); +qerror_report (QERR_DEVICE_ENCRYPTED ,bdrv_get_device_name (bs), +bdrv_get_encrypted_filename (bs));return -1 ; }
qerror.h +1 -1
@@ -70,7 +70,7 @@ QError *qobject_to_qerror(const QObject *obj); "{ 'class': 'CommandDisabled', 'data': { 'name': %s } }"#define QERR_DEVICE_ENCRYPTED \ - "{ 'class': 'DeviceEncrypted', 'data': { 'device': %s } }" + "{ 'class': 'DeviceEncrypted', 'data': { 'device': %s, 'filename': %s } }"#define QERR_DEVICE_INIT_FAILED \ "{ 'class': 'DeviceInitFailed', 'data': { 'device': %s } }"
qmp.c +2 -1
@@ -133,7 +133,8 @@ static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs)Error **err = opaque;if (!error_is_set (err) &&bdrv_key_required (bs)) { -error_set (err,QERR_DEVICE_ENCRYPTED ,bdrv_get_device_name (bs)); +error_set (err,QERR_DEVICE_ENCRYPTED ,bdrv_get_device_name (bs), +bdrv_get_encrypted_filename (bs)); } }
Signature · 1 line
1.7.8.2.325.g247f9.dirty
PATCH 9/10 qapi: Convert change
In reply to Luiz Capitulino--- blockdev.c | 54 +++++++++++++++++++++++++++----------- blockdev.h | 5 ++- hmp-commands.hx | 3 +- hmp.c | 57 +++++++++++++++++++++++++++++++++++++++++ hmp.h | 1 + monitor.c | 74 ------------------------------------------------------ qapi-schema.json | 36 ++++++++++++++++++++++++++ qmp-commands.hx | 5 +--- qmp.c | 44 ++++++++++++++++++++++++++++++++ 9 files changed, 181 insertions(+), 98 deletions(-)
blockdev.c +38 -16
@@ -717,8 +717,31 @@ void qmp_block_passwd(const char *device, const char *password, Error **errp) } } -int do_change_block (Monitor *mon,const char *device, -const char *filename,const char *fmt) +static void qmp_bdrv_open_encrypted (BlockDriverState *bs,const char *filename, +int bdrv_flags,BlockDriver *drv, +const char *password,Error **errp) +{ +if (bdrv_open (bs, filename, bdrv_flags, drv) <0 ) { +error_set (errp,QERR_OPEN_FILE_FAILED , filename); +return ; + } + +if (bdrv_key_required (bs)) { +if (password) { +if (bdrv_set_key (bs, password) <0 ) { +error_set (errp,QERR_INVALID_PASSWORD ); + } + }else { +error_set (errp,QERR_DEVICE_ENCRYPTED ,bdrv_get_device_name (bs), +bdrv_get_encrypted_filename (bs)); + } + }else if (password) { +error_set (errp,QERR_DEVICE_NOT_ENCRYPTED ,bdrv_get_device_name (bs)); + } +} + +void qmp_change_blockdev (const char *device,const char *filename, +bool has_format,const char *format,Error **errp) {BlockDriverState *bs;BlockDriver *drv =NULL ;
@@ -727,29 +750,28 @@ int do_change_block(Monitor *mon, const char *device, bs =bdrv_find (device);if (!bs) { -qerror_report (QERR_DEVICE_NOT_FOUND , device); -return -1 ; +error_set (errp,QERR_DEVICE_NOT_FOUND , device); +return ; } -if (fmt) { - drv =bdrv_find_whitelisted_format (fmt); + +if (format) { + drv =bdrv_find_whitelisted_format (format);if (!drv) { -qerror_report (QERR_INVALID_BLOCK_FORMAT , fmt); -return -1 ; +error_set (errp,QERR_INVALID_BLOCK_FORMAT , format); +return ; } } +eject_device (bs,0 , &err);if (error_is_set (&err)) { -qerror_report_err (err); -error_free (err); -return -1 ; +error_propagate (errp, err); +return ; } + bdrv_flags =bdrv_is_read_only (bs) ?0 :BDRV_O_RDWR ; bdrv_flags |=bdrv_is_snapshot (bs) ?BDRV_O_SNAPSHOT :0 ; -if (bdrv_open (bs, filename, bdrv_flags, drv) <0 ) { -qerror_report (QERR_OPEN_FILE_FAILED , filename); -return -1 ; - } -return monitor_read_bdrv_key_start (mon, bs,NULL ,NULL ); + +qmp_bdrv_open_encrypted (bs, filename, bdrv_flags, drv,NULL , errp); }/* throttling disk I/O limits */
blockdev.h +3 -2
@@ -11,6 +11,7 @@#define BLOCKDEV_H #include "block.h" +#include "error.h" #include "qemu-queue.h" void blockdev_mark_auto_del (BlockDriverState *bs);
@@ -57,9 +58,9 @@ DriveInfo *drive_init(QemuOpts *arg, int default_to_scsi);DriveInfo *add_init_drive (const char *opts); +void qmp_change_blockdev (const char *device,const char *filename, +bool has_format,const char *format,Error **errp);void do_commit (Monitor *mon,const QDict *qdict); -int do_change_block (Monitor *mon,const char *device, -const char *filename,const char *fmt);int do_drive_del (Monitor *mon,const QDict *qdict,QObject **ret_data);int do_block_set_io_throttle (Monitor *mon,const QDict *qdict,QObject **ret_data);
hmp-commands.hx +1 -2
@@ -107,8 +107,7 @@ ETEXI .args_type = "device:B,target:F,arg:s?", .params = "device filename [format]", .help = "change a removable medium, optional format", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_change, + .mhandler.cmd = hmp_change, }, STEXI
hmp.c +57 -0
60 lines not on this page · raw message
hmp.h +1 -0
@@ -52,5 +52,6 @@ void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict);void hmp_set_password (Monitor *mon,const QDict *qdict);void hmp_expire_password (Monitor *mon,const QDict *qdict);void hmp_eject (Monitor *mon,const QDict *qdict); +void hmp_change (Monitor *mon,const QDict *qdict);#endif
monitor.c +0 -74
80 lines not on this page · raw message
qapi-schema.json +36 -0
@@ -1367,3 +1367,39 @@ # executing this command. ## { 'command': 'change-vnc-password', 'data': {'password': 'str'} } + +## +# @change: +# +# This command is multiple commands multiplexed together. +# +# @device: This is normally the name of a block device but it may also be 'vnc'. +# when it's 'vnc', then sub command depends on @target +# +# @target: If @device is a block device, then this is the new filename. +# If @device is 'vnc', then if the value 'password' selects the vnc +# change password command. Otherwise, this specifies a new server URI +# address to listen to for VNC connections. +# +# @arg: If @device is a block device, then this is an optional format to open +# the device with. +# If @device is 'vnc' and @target is 'password', this is the new VNC +# password to set. If this argument is an empty string, then no future +# logins will be allowed. +# +# Returns: Nothing on success. +# If @device is not a valid block device, DeviceNotFound +# If @format is not a valid block format, InvalidBlockFormat +# If the new block device is encrypted, DeviceEncrypted. Note that +# if this error is returned, the device has been opened successfully +# and an additional call to @block_passwd is required to set the +# device's password. The behavior of reads and writes to the block +# device between when these calls are executed is undefined. +# +# Notes: It is strongly recommended that this interface is not used especially +# for changing block devices. +# +# Since: 0.14.0 +## +{ 'command': 'change', + 'data': {'device': 'str', 'target': 'str', '*arg': 'str'} }
qmp-commands.hx +1 -4
@@ -110,10 +110,7 @@ EQMP { .name = "change", .args_type = "device:B,target:F,arg:s?", - .params = "device filename [format]", - .help = "change a removable medium, optional format", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_change, + .mhandler.cmd_new = qmp_marshal_input_change, }, SQMP
qmp.c +44 -0
59 lines not on this page · raw message
Signature · 1 line
1.7.8.2.325.g247f9.dirty
PATCH 10/10 qapi: Convert block_set_io_throttle
In reply to Luiz Capitulino--- blockdev.c | 47 ++++++++++++++--------------------------------- blockdev.h | 2 -- hmp-commands.hx | 3 +-- hmp.c | 14 ++++++++++++++ hmp.h | 1 + qapi-schema.json | 29 +++++++++++++++++++++++++++++ qmp-commands.hx | 5 +---- 7 files changed, 60 insertions(+), 41 deletions(-)
blockdev.c +14 -33
@@ -775,46 +775,29 @@ void qmp_change_blockdev(const char *device, const char *filename, }/* throttling disk I/O limits */ -int do_block_set_io_throttle (Monitor *mon, -const QDict *qdict,QObject **ret_data) +void qmp_block_set_io_throttle (const char *device,int64_t bps,int64_t bps_rd, +int64_t bps_wr,int64_t iops,int64_t iops_rd, +int64_t iops_wr,Error **errp) {BlockIOLimit io_limits; -const char *devname =qdict_get_str (qdict,"device" );BlockDriverState *bs; - io_limits.bps[BLOCK_IO_LIMIT_TOTAL ] - =qdict_get_try_int (qdict,"bps" ,-1 ); - io_limits.bps[BLOCK_IO_LIMIT_READ ] - =qdict_get_try_int (qdict,"bps_rd" ,-1 ); - io_limits.bps[BLOCK_IO_LIMIT_WRITE ] - =qdict_get_try_int (qdict,"bps_wr" ,-1 ); - io_limits.iops[BLOCK_IO_LIMIT_TOTAL ] - =qdict_get_try_int (qdict,"iops" ,-1 ); - io_limits.iops[BLOCK_IO_LIMIT_READ ] - =qdict_get_try_int (qdict,"iops_rd" ,-1 ); - io_limits.iops[BLOCK_IO_LIMIT_WRITE ] - =qdict_get_try_int (qdict,"iops_wr" ,-1 ); - - bs =bdrv_find (devname); + bs =bdrv_find (device);if (!bs) { -qerror_report (QERR_DEVICE_NOT_FOUND , devname); -return -1 ; +error_set (errp,QERR_DEVICE_NOT_FOUND , device); +return ; } -if ((io_limits.bps[BLOCK_IO_LIMIT_TOTAL ] ==-1 ) - || (io_limits.bps[BLOCK_IO_LIMIT_READ ] ==-1 ) - || (io_limits.bps[BLOCK_IO_LIMIT_WRITE ] ==-1 ) - || (io_limits.iops[BLOCK_IO_LIMIT_TOTAL ] ==-1 ) - || (io_limits.iops[BLOCK_IO_LIMIT_READ ] ==-1 ) - || (io_limits.iops[BLOCK_IO_LIMIT_WRITE ] ==-1 )) { -qerror_report (QERR_MISSING_PARAMETER , -"bps/bps_rd/bps_wr/iops/iops_rd/iops_wr" ); -return -1 ; - } + io_limits.bps[BLOCK_IO_LIMIT_TOTAL ] = bps; + io_limits.bps[BLOCK_IO_LIMIT_READ ] = bps_rd; + io_limits.bps[BLOCK_IO_LIMIT_WRITE ] = bps_wr; + io_limits.iops[BLOCK_IO_LIMIT_TOTAL ]= iops; + io_limits.iops[BLOCK_IO_LIMIT_READ ] = iops_rd; + io_limits.iops[BLOCK_IO_LIMIT_WRITE ]= iops_wr;if (!do_check_io_limits (&io_limits)) { -qerror_report (QERR_INVALID_PARAMETER_COMBINATION ); -return -1 ; +error_set (errp,QERR_INVALID_PARAMETER_COMBINATION ); +return ; } bs->io_limits = io_limits;
@@ -829,8 +812,6 @@ int do_block_set_io_throttle(Monitor *mon,qemu_mod_timer (bs->block_timer,qemu_get_clock_ns (vm_clock)); } } - -return 0 ; }int do_drive_del (Monitor *mon,const QDict *qdict,QObject **ret_data)
blockdev.h +0 -2
@@ -62,6 +62,4 @@ void qmp_change_blockdev(const char *device, const char *filename, bool has_format, const char *format, Error **errp);void do_commit (Monitor *mon,const QDict *qdict);int do_drive_del (Monitor *mon,const QDict *qdict,QObject **ret_data); -int do_block_set_io_throttle (Monitor *mon, -const QDict *qdict,QObject **ret_data);#endif
hmp-commands.hx +1 -2
@@ -1204,8 +1204,7 @@ ETEXI .args_type = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l", .params = "device bps bps_rd bps_wr iops iops_rd iops_wr", .help = "change I/O throttle limits for a block drive", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_block_set_io_throttle, + .mhandler.cmd = hmp_block_set_io_throttle, }, STEXI
hmp.c +14 -0
@@ -767,3 +767,17 @@ void hmp_change(Monitor *mon, const QDict *qdict) }hmp_handle_error (mon, &err); } + +void hmp_block_set_io_throttle (Monitor *mon,const QDict *qdict) +{ +Error *err =NULL ; + +qmp_block_set_io_throttle (qdict_get_str (qdict,"device" ), +qdict_get_int (qdict,"bps" ), +qdict_get_int (qdict,"bps_rd" ), +qdict_get_int (qdict,"bps_wr" ), +qdict_get_int (qdict,"iops" ), +qdict_get_int (qdict,"iops_rd" ), +qdict_get_int (qdict,"iops_wr" ), &err); +hmp_handle_error (mon, &err); +}
hmp.h +1 -0
@@ -53,5 +53,6 @@ void hmp_set_password(Monitor *mon, const QDict *qdict);void hmp_expire_password (Monitor *mon,const QDict *qdict);void hmp_eject (Monitor *mon,const QDict *qdict);void hmp_change (Monitor *mon,const QDict *qdict); +void hmp_block_set_io_throttle (Monitor *mon,const QDict *qdict);#endif
qapi-schema.json +29 -0
@@ -1403,3 +1403,32 @@ ## { 'command': 'change', 'data': {'device': 'str', 'target': 'str', '*arg': 'str'} } + +## +# @block_set_io_throttle: +# +# Change I/O throttle limits for a block drive. +# +# @device: The name of the device +# +# @bps: total throughput limit in bytes per second +# +# @bps_rd: read throughput limit in bytes per second +# +# @bps_wr: read throughput limit in bytes per second +# +# @iops: total I/O operations per second +# +# @ops_rd: read I/O operations per second +# +# @iops_wr: write I/O operations per second +# +# Returns: Nothing on success +# If @device is not a valid block device, DeviceNotFound +# If the argument combination is invalid, InvalidParameterCombination +# +# Since: 1.1 +## +{ 'command': 'block_set_io_throttle', + 'data': { 'device': 'str', 'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int', + 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int' } }
qmp-commands.hx +1 -4
@@ -807,10 +807,7 @@ EQMP { .name = "block_set_io_throttle", .args_type = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l", - .params = "device bps bps_rd bps_wr iops iops_rd iops_wr", - .help = "change I/O throttle limits for a block drive", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_block_set_io_throttle, + .mhandler.cmd_new = qmp_marshal_input_block_set_io_throttle, }, SQMP
Signature · 1 line
1.7.8.2.325.g247f9.dirty
Re: [Qemu-devel] [PATCH 10/10] qapi: Convert block_set_io_throttle
Quoted 154 lines · Luiz Capitulino
Signed-off-by Luiz Capitulino<[email protected]>--- blockdev.c | 47 ++++++++++++++--------------------------------- blockdev.h | 2 -- hmp-commands.hx | 3 +-- hmp.c | 14 ++++++++++++++ hmp.h | 1 + qapi-schema.json | 29 +++++++++++++++++++++++++++++ qmp-commands.hx | 5 +---- 7 files changed, 60 insertions(+), 41 deletions(-)blockdev.c +14
-33@@ -775,46 +775,29 @@ void qmp_change_blockdev(const char *device, const char *filename, }/* throttling disk I/O limits */ -int do_block_set_io_throttle (Monitor *mon, -const QDict *qdict,QObject **ret_data) +void qmp_block_set_io_throttle (const char *device,int64_t bps,int64_t bps_rd, +int64_t bps_wr,int64_t iops,int64_t iops_rd, +int64_t iops_wr,Error **errp) {BlockIOLimit io_limits; -const char *devname =qdict_get_str (qdict,"device" );BlockDriverState *bs; - io_limits.bps[BLOCK_IO_LIMIT_TOTAL ] - =qdict_get_try_int (qdict,"bps" ,-1 ); - io_limits.bps[BLOCK_IO_LIMIT_READ ] - =qdict_get_try_int (qdict,"bps_rd" ,-1 ); - io_limits.bps[BLOCK_IO_LIMIT_WRITE ] - =qdict_get_try_int (qdict,"bps_wr" ,-1 ); - io_limits.iops[BLOCK_IO_LIMIT_TOTAL ] - =qdict_get_try_int (qdict,"iops" ,-1 ); - io_limits.iops[BLOCK_IO_LIMIT_READ ] - =qdict_get_try_int (qdict,"iops_rd" ,-1 ); - io_limits.iops[BLOCK_IO_LIMIT_WRITE ] - =qdict_get_try_int (qdict,"iops_wr" ,-1 ); - - bs =bdrv_find (devname); + bs =bdrv_find (device);if (!bs) { -qerror_report (QERR_DEVICE_NOT_FOUND , devname); -return -1 ; +error_set (errp,QERR_DEVICE_NOT_FOUND , device); +return ; } -if ((io_limits.bps[BLOCK_IO_LIMIT_TOTAL ] ==-1 ) - || (io_limits.bps[BLOCK_IO_LIMIT_READ ] ==-1 ) - || (io_limits.bps[BLOCK_IO_LIMIT_WRITE ] ==-1 ) - || (io_limits.iops[BLOCK_IO_LIMIT_TOTAL ] ==-1 ) - || (io_limits.iops[BLOCK_IO_LIMIT_READ ] ==-1 ) - || (io_limits.iops[BLOCK_IO_LIMIT_WRITE ] ==-1 )) { -qerror_report (QERR_MISSING_PARAMETER , -"bps/bps_rd/bps_wr/iops/iops_rd/iops_wr" ); -return -1 ; - } + io_limits.bps[BLOCK_IO_LIMIT_TOTAL ] = bps; + io_limits.bps[BLOCK_IO_LIMIT_READ ] = bps_rd; + io_limits.bps[BLOCK_IO_LIMIT_WRITE ] = bps_wr; + io_limits.iops[BLOCK_IO_LIMIT_TOTAL ]= iops; + io_limits.iops[BLOCK_IO_LIMIT_READ ] = iops_rd; + io_limits.iops[BLOCK_IO_LIMIT_WRITE ]= iops_wr;if (!do_check_io_limits (&io_limits)) { -qerror_report (QERR_INVALID_PARAMETER_COMBINATION ); -return -1 ; +error_set (errp,QERR_INVALID_PARAMETER_COMBINATION ); +return ; } bs->io_limits = io_limits;@@ -829,8 +812,6 @@ int do_block_set_io_throttle(Monitor *mon,qemu_mod_timer (bs->block_timer,qemu_get_clock_ns (vm_clock)); } } - -return 0 ; }int do_drive_del (Monitor *mon,const QDict *qdict,QObject **ret_data)blockdev.h +0
-2@@ -62,6 +62,4 @@ void qmp_change_blockdev(const char *device, const char *filename, bool has_format, const char *format, Error **errp);void do_commit (Monitor *mon,const QDict *qdict);int do_drive_del (Monitor *mon,const QDict *qdict,QObject **ret_data); -int do_block_set_io_throttle (Monitor *mon, -const QDict *qdict,QObject **ret_data);#endif hmp-commands.hx +1
-2@@ -1204,8 +1204,7 @@ ETEXI .args_type = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l", .params = "device bps bps_rd bps_wr iops iops_rd iops_wr", .help = "change I/O throttle limits for a block drive", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_block_set_io_throttle, + .mhandler.cmd = hmp_block_set_io_throttle, }, STEXIhmp.c +14
-0@@ -767,3 +767,17 @@ void hmp_change(Monitor *mon, const QDict *qdict) }hmp_handle_error (mon,&err); } + +void hmp_block_set_io_throttle (Monitor *mon,const QDict *qdict) +{ +Error *err =NULL ; + +qmp_block_set_io_throttle (qdict_get_str (qdict,"device" ), +qdict_get_int (qdict,"bps" ), +qdict_get_int (qdict,"bps_rd" ), +qdict_get_int (qdict,"bps_wr" ), +qdict_get_int (qdict,"iops" ), +qdict_get_int (qdict,"iops_rd" ), +qdict_get_int (qdict,"iops_wr" ),&err); +hmp_handle_error (mon,&err); +}hmp.h +1
-0@@ -53,5 +53,6 @@ void hmp_set_password(Monitor *mon, const QDict *qdict);void hmp_expire_password (Monitor *mon,const QDict *qdict);void hmp_eject (Monitor *mon,const QDict *qdict);void hmp_change (Monitor *mon,const QDict *qdict); +void hmp_block_set_io_throttle (Monitor *mon,const QDict *qdict);#endif qapi-schema.json +3
-0@@ -1403,3 +1403,32 @@ ## { 'command': 'change', 'data': {'device': 'str', 'target': 'str', '*arg': 'str'} } + +## +# @block_set_io_throttle:
qapi-schema.json line 1418
Quoted 10 lines
qapi-schema.json +10
-0+# +# Change I/O throttle limits for a block drive. +# +# @device: The name of the device +# +# @bps: total throughput limit in bytes per second +# +# @bps_rd: read throughput limit in bytes per second +# +# @bps_wr: read throughput limit in bytes per second
write throughput.
qapi-schema.json line 1430
Quoted 12 lines
qapi-schema.json +12
-0+# +# @iops: total I/O operations per second +# +# @ops_rd: read I/O operations per second +# +# @iops_wr: write I/O operations per second +# +# Returns: Nothing on success +# If @device is not a valid block device, DeviceNotFound +# If the argument combination is invalid, InvalidParameterCombination +# +# Since: 1.1
Do all of these fields have to be specified? It looks like they were all optional in the previous form of the command so they should probably be optional here too.
Regards,
Anthony Liguori
Quoted 20 lines
qapi-schema.json +4
-0+## +{ 'command': 'block_set_io_throttle', + 'data': { 'device': 'str', 'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int', + 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int' } }qmp-commands.hx +1
-4@@ -807,10 +807,7 @@ EQMP { .name = "block_set_io_throttle", .args_type = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l", - .params = "device bps bps_rd bps_wr iops iops_rd iops_wr", - .help = "change I/O throttle limits for a block drive", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_block_set_io_throttle, + .mhandler.cmd_new = qmp_marshal_input_block_set_io_throttle, }, SQMP
Re: [Qemu-devel] [PATCH 10/10] qapi: Convert block_set_io_throttle
Quoted 159 lines · On Fri, 13 Jan 2012 14:53:19 -0600 Anthony Liguori <[email protected]>…
Quoted 158 lines · Luiz Capitulino
Signed-off-by Luiz Capitulino<[email protected]>--- blockdev.c | 47 ++++++++++++++--------------------------------- blockdev.h | 2 -- hmp-commands.hx | 3 +-- hmp.c | 14 ++++++++++++++ hmp.h | 1 + qapi-schema.json | 29 +++++++++++++++++++++++++++++ qmp-commands.hx | 5 +---- 7 files changed, 60 insertions(+), 41 deletions(-)blockdev.c +14
-33@@ -775,46 +775,29 @@ void qmp_change_blockdev(const char *device, const char *filename, }/* throttling disk I/O limits */ -int do_block_set_io_throttle (Monitor *mon, -const QDict *qdict,QObject **ret_data) +void qmp_block_set_io_throttle (const char *device,int64_t bps,int64_t bps_rd, +int64_t bps_wr,int64_t iops,int64_t iops_rd, +int64_t iops_wr,Error **errp) {BlockIOLimit io_limits; -const char *devname =qdict_get_str (qdict,"device" );BlockDriverState *bs; - io_limits.bps[BLOCK_IO_LIMIT_TOTAL ] - =qdict_get_try_int (qdict,"bps" ,-1 ); - io_limits.bps[BLOCK_IO_LIMIT_READ ] - =qdict_get_try_int (qdict,"bps_rd" ,-1 ); - io_limits.bps[BLOCK_IO_LIMIT_WRITE ] - =qdict_get_try_int (qdict,"bps_wr" ,-1 ); - io_limits.iops[BLOCK_IO_LIMIT_TOTAL ] - =qdict_get_try_int (qdict,"iops" ,-1 ); - io_limits.iops[BLOCK_IO_LIMIT_READ ] - =qdict_get_try_int (qdict,"iops_rd" ,-1 ); - io_limits.iops[BLOCK_IO_LIMIT_WRITE ] - =qdict_get_try_int (qdict,"iops_wr" ,-1 ); - - bs =bdrv_find (devname); + bs =bdrv_find (device);if (!bs) { -qerror_report (QERR_DEVICE_NOT_FOUND , devname); -return -1 ; +error_set (errp,QERR_DEVICE_NOT_FOUND , device); +return ; } -if ((io_limits.bps[BLOCK_IO_LIMIT_TOTAL ] ==-1 ) - || (io_limits.bps[BLOCK_IO_LIMIT_READ ] ==-1 ) - || (io_limits.bps[BLOCK_IO_LIMIT_WRITE ] ==-1 ) - || (io_limits.iops[BLOCK_IO_LIMIT_TOTAL ] ==-1 ) - || (io_limits.iops[BLOCK_IO_LIMIT_READ ] ==-1 ) - || (io_limits.iops[BLOCK_IO_LIMIT_WRITE ] ==-1 )) { -qerror_report (QERR_MISSING_PARAMETER , -"bps/bps_rd/bps_wr/iops/iops_rd/iops_wr" ); -return -1 ; - } + io_limits.bps[BLOCK_IO_LIMIT_TOTAL ] = bps; + io_limits.bps[BLOCK_IO_LIMIT_READ ] = bps_rd; + io_limits.bps[BLOCK_IO_LIMIT_WRITE ] = bps_wr; + io_limits.iops[BLOCK_IO_LIMIT_TOTAL ]= iops; + io_limits.iops[BLOCK_IO_LIMIT_READ ] = iops_rd; + io_limits.iops[BLOCK_IO_LIMIT_WRITE ]= iops_wr;if (!do_check_io_limits (&io_limits)) { -qerror_report (QERR_INVALID_PARAMETER_COMBINATION ); -return -1 ; +error_set (errp,QERR_INVALID_PARAMETER_COMBINATION ); +return ; } bs->io_limits = io_limits;@@ -829,8 +812,6 @@ int do_block_set_io_throttle(Monitor *mon,qemu_mod_timer (bs->block_timer,qemu_get_clock_ns (vm_clock)); } } - -return 0 ; }int do_drive_del (Monitor *mon,const QDict *qdict,QObject **ret_data)blockdev.h +0
-2@@ -62,6 +62,4 @@ void qmp_change_blockdev(const char *device, const char *filename, bool has_format, const char *format, Error **errp);void do_commit (Monitor *mon,const QDict *qdict);int do_drive_del (Monitor *mon,const QDict *qdict,QObject **ret_data); -int do_block_set_io_throttle (Monitor *mon, -const QDict *qdict,QObject **ret_data);#endif hmp-commands.hx +1
-2@@ -1204,8 +1204,7 @@ ETEXI .args_type = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l", .params = "device bps bps_rd bps_wr iops iops_rd iops_wr", .help = "change I/O throttle limits for a block drive", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_block_set_io_throttle, + .mhandler.cmd = hmp_block_set_io_throttle, }, STEXIhmp.c +14
-0@@ -767,3 +767,17 @@ void hmp_change(Monitor *mon, const QDict *qdict) }hmp_handle_error (mon,&err); } + +void hmp_block_set_io_throttle (Monitor *mon,const QDict *qdict) +{ +Error *err =NULL ; + +qmp_block_set_io_throttle (qdict_get_str (qdict,"device" ), +qdict_get_int (qdict,"bps" ), +qdict_get_int (qdict,"bps_rd" ), +qdict_get_int (qdict,"bps_wr" ), +qdict_get_int (qdict,"iops" ), +qdict_get_int (qdict,"iops_rd" ), +qdict_get_int (qdict,"iops_wr" ),&err); +hmp_handle_error (mon,&err); +}hmp.h +1
-0@@ -53,5 +53,6 @@ void hmp_set_password(Monitor *mon, const QDict *qdict);void hmp_expire_password (Monitor *mon,const QDict *qdict);void hmp_eject (Monitor *mon,const QDict *qdict);void hmp_change (Monitor *mon,const QDict *qdict); +void hmp_block_set_io_throttle (Monitor *mon,const QDict *qdict);#endif qapi-schema.json +7
-0@@ -1403,3 +1403,32 @@ ## { 'command': 'change', 'data': {'device': 'str', 'target': 'str', '*arg': 'str'} } + +## +# @block_set_io_throttle: +# +# Change I/O throttle limits for a block drive. +# +# @device: The name of the device
Quoted 8 lines
qapi-schema.json line 1418
Quoted 6 lines
qapi-schema.json +6
-0+# +# @bps: total throughput limit in bytes per second +# +# @bps_rd: read throughput limit in bytes per second +# +# @bps_wr: read throughput limit in bytes per secondwrite throughput.
Fixed.
Quoted 9 lines
Quoted 9 lines
qapi-schema.json +9
-0+# +# @iops: total I/O operations per second +# +# @ops_rd: read I/O operations per second +# +# @iops_wr: write I/O operations per second +# +# Returns: Nothing on success +# If @device is not a valid block device, DeviceNotFound
Quoted 8 lines
qapi-schema.json line 1430
Quoted 3 lines
qapi-schema.json +3
-0+# If the argument combination is invalid, InvalidParameterCombination +# +# Since: 1.1Do all of these fields have to be specified? It looks like they were all optional in the previous form of the command so they should probably be optional here too.
They were required, as it's necessary to use '?' for optionals in the args_type entry:
Quoted 6 lines
qmp-commands.hx EQMP · line 809
Quoted 6 lines
qmp-commands.hx +0
-0@@ -807,10 +807,7 @@ EQMP { .name = "block_set_io_throttle", .args_type = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l",
The implementation also seems to imply they are required because there's an explicit check for it (which can be dropped in the new version...).
Can the author/block guys confirm these parameters are intended to be required?
Re: [Qemu-devel] [PATCH 10/10] qapi: Convert block_set_io_throttle
Quoted 204 lines · Luiz Capitulino
Quoted 159 lines · On Fri, 13 Jan 2012 14:53:19 -0600 Anthony Liguori <[email protected]>…
Quoted 158 lines · Luiz Capitulino
Signed-off-by Luiz Capitulino<[email protected]>---
blockdev.c| 47 ++++++++++++++---------------------------------blockdev.h| 2 --
hmp-commands.hx | 3 +--
hmp.c| 14 ++++++++++++++
hmp.h| 1 +
qapi-schema.json | 29 +++++++++++++++++++++++++++++ qmp-commands.hx | 5 +----7 files changed, 60 insertions(+), 41 deletions(-)blockdev.c +14
-33@@ -775,46 +775,29 @@ void qmp_change_blockdev(const char *device, const char *filename, } /* throttling disk I/O limits */ -int do_block_set_io_throttle (Monitor *mon, - const QDict *qdict, QObject **ret_data) +void qmp_block_set_io_throttle (const char *device,int64_t bps,int64_t bps_rd, + int64_t bps_wr, int64_t iops, int64_t iops_rd, + int64_t iops_wr, Error **errp) { BlockIOLimit io_limits; - const char *devname = qdict_get_str(qdict, "device"); BlockDriverState *bs; - io_limits.bps[BLOCK_IO_LIMIT_TOTAL] - = qdict_get_try_int(qdict, "bps", -1); - io_limits.bps[BLOCK_IO_LIMIT_READ] - = qdict_get_try_int(qdict, "bps_rd", -1); - io_limits.bps[BLOCK_IO_LIMIT_WRITE] - = qdict_get_try_int(qdict, "bps_wr", -1); - io_limits.iops[BLOCK_IO_LIMIT_TOTAL] - = qdict_get_try_int(qdict, "iops", -1); - io_limits.iops[BLOCK_IO_LIMIT_READ] - = qdict_get_try_int(qdict, "iops_rd", -1); - io_limits.iops[BLOCK_IO_LIMIT_WRITE] - = qdict_get_try_int(qdict, "iops_wr", -1); - - bs = bdrv_find(devname); + bs = bdrv_find(device); if (!bs) { - qerror_report(QERR_DEVICE_NOT_FOUND, devname); - return -1; + error_set(errp, QERR_DEVICE_NOT_FOUND, device); + return; } - if ((io_limits.bps[BLOCK_IO_LIMIT_TOTAL] == -1) - || (io_limits.bps[BLOCK_IO_LIMIT_READ] == -1) - || (io_limits.bps[BLOCK_IO_LIMIT_WRITE] == -1) - || (io_limits.iops[BLOCK_IO_LIMIT_TOTAL] == -1) - || (io_limits.iops[BLOCK_IO_LIMIT_READ] == -1) - || (io_limits.iops[BLOCK_IO_LIMIT_WRITE] == -1)) { - qerror_report(QERR_MISSING_PARAMETER, - "bps/bps_rd/bps_wr/iops/iops_rd/iops_wr"); - return -1; - } + io_limits.bps[BLOCK_IO_LIMIT_TOTAL] = bps; + io_limits.bps[BLOCK_IO_LIMIT_READ] = bps_rd; + io_limits.bps[BLOCK_IO_LIMIT_WRITE] = bps_wr; + io_limits.iops[BLOCK_IO_LIMIT_TOTAL]= iops; + io_limits.iops[BLOCK_IO_LIMIT_READ] = iops_rd; + io_limits.iops[BLOCK_IO_LIMIT_WRITE]= iops_wr; if (!do_check_io_limits(&io_limits)) { - qerror_report(QERR_INVALID_PARAMETER_COMBINATION); - return -1; + error_set(errp, QERR_INVALID_PARAMETER_COMBINATION); + return; } bs->io_limits = io_limits;@@ -829,8 +812,6 @@ int do_block_set_io_throttle(Monitor *mon, qemu_mod_timer(bs->block_timer, qemu_get_clock_ns(vm_clock)); } } - - return 0; } int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)blockdev.h +0
-2@@ -62,6 +62,4 @@ void qmp_change_blockdev(const char *device, const char *filename, bool has_format, const char *format, Error **errp); void do_commit(Monitor *mon, const QDict *qdict); int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data); -int do_block_set_io_throttle (Monitor *mon, - const QDict *qdict, QObject **ret_data); #endifhmp-commands.hx +1
-2@@ -1204,8 +1204,7 @@ ETEXI .args_type = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l", .params = "device bps bps_rd bps_wr iops iops_rd iops_wr", .help = "change I/O throttle limits for a block drive", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_block_set_io_throttle, + .mhandler.cmd = hmp_block_set_io_throttle, },STEXI
hmp.c +14
-0@@ -767,3 +767,17 @@ void hmp_change(Monitor *mon, const QDict *qdict) } hmp_handle_error(mon,&err); } + +void hmp_block_set_io_throttle (Monitor *mon,const QDict *qdict) +{ + Error *err = NULL; + + qmp_block_set_io_throttle(qdict_get_str(qdict, "device"), + qdict_get_int(qdict, "bps"), + qdict_get_int(qdict, "bps_rd"), + qdict_get_int(qdict, "bps_wr"), + qdict_get_int(qdict, "iops"), + qdict_get_int(qdict, "iops_rd"), + qdict_get_int(qdict, "iops_wr"),&err); + hmp_handle_error(mon,&err); +}hmp.h +1
-0@@ -53,5 +53,6 @@ void hmp_set_password(Monitor *mon, const QDict *qdict); void hmp_expire_password(Monitor *mon, const QDict *qdict); void hmp_eject(Monitor *mon, const QDict *qdict); void hmp_change(Monitor *mon, const QDict *qdict); +void hmp_block_set_io_throttle (Monitor *mon,const QDict *qdict); #endifqapi-schema.json +7
-0@@ -1403,3 +1403,32 @@ ## { 'command': 'change', 'data': {'device': 'str', 'target': 'str', '*arg': 'str'} } + +## +# @block_set_io_throttle: +# +# Change I/O throttle limits for a block drive. +# +# @device: The name of the deviceQuoted 8 lines
qapi-schema.json line 1418
Quoted 6 lines
qapi-schema.json +6
-0+# +# @bps: total throughput limit in bytes per second +# +# @bps_rd: read throughput limit in bytes per second +# +# @bps_wr: read throughput limit in bytes per secondwrite throughput.
Fixed.
Quoted 9 lines
Quoted 9 lines
qapi-schema.json +9
-0+# +# @iops: total I/O operations per second +# +# @ops_rd: read I/O operations per second +# +# @iops_wr: write I/O operations per second +# +# Returns: Nothing on success +# If @device is not a valid block device, DeviceNotFoundQuoted 8 lines
qapi-schema.json line 1430
Quoted 3 lines
qapi-schema.json +3
-0+# If the argument combination is invalid, InvalidParameterCombination +# +# Since: 1.1Do all of these fields have to be specified? It looks like they were all optional in the previous form of the command so they should probably be optional here too.
They were required, as it's necessary to use '?' for optionals in the
args_typeentry:Quoted 6 lines
qmp-commands.hx EQMP · line 809
Quoted 6 lines
qmp-commands.hx +0
-0@@ -807,10 +807,7 @@ EQMP { .name = "block_set_io_throttle", .args_type = "device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l",The implementation also seems to imply they are required because there's an explicit check for it (which can be dropped in the new version...).
Quoted 2 lines
Can the author/block guys confirm these parameters are intended to be required?
For hmp, they are required, while for qmp, they are optional in theory. In order to two interfaces consistent, these parameters are all required.
Quoted 1 line
Signature · 3 lines
Regards, Zhi Yong Wu