Convert migrate_set_speed, migrate_set_downtime to QObject
v2 cover Convert migrate_set_speed, migrate_set_downtime to QObject
These conversions take a few extra steps, because do_migrate_set_speed() and do_migrate_set_downtime() interpret their string argument as floating-point number + optional unit suffix. This is quite inappropriate for QMP.
Markus Armbruster (8):
monitor: Document argument type 'M'
QDict: New qdict_get_double()
monitor: New argument type 'b'
monitor: Use argument type 'b' for migrate_set_speed()
monitor: convert do_migrate_set_speed() to QObject
monitor: New argument type 'T'
monitor: Use argument type 'T' for migrate_set_downtime()
monitor: convert do_migrate_set_downtime() to QObject
migration.c | 38 ++++++---------------------- migration.h | 5 ++- monitor.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qdict.c | 15 +++++++++++ qdict.h | 1 + qemu-monitor.hx | 8 +++--- 6 files changed, 105 insertions(+), 36 deletions(-)
PATCH v2 1/8 monitor: Document argument type 'M'
Was forgotten in commit b6e098d7.
--- monitor.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
monitor.c +2 -0
@@ -68,6 +68,8 @@* 's' string (accept optional quote) * 'i' 32 bit integer * 'l' target long (32 or 64 bit) +* 'M' just like 'l', except in user mode the value is +* multiplied by 2^20 (think Mebibyte) * '/' optional gdb-like print format (like "/10x") * * '?' optional type (for all types, except '/')
Signature · 1 line
1.6.6
RE: [Qemu-devel] [PATCH v2 1/8] monitor: Document argument type 'M'
Quoted 22 lines
-----Original Message-----
From:
[email protected] [mailto:[email protected] rg] On Behalf Of Markus Armbruster
Sent: Wednesday, January 20, 2010 10:08 AM
To: [email protected]
Subject: [Qemu-devel] [PATCH v2 1/8] monitor: Document argument type 'M'Was forgotten in commit
b6e098d7.Signed-off-by Markus Armbruster <[email protected]>--- monitor.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)monitor.c +0
-0
monitor.c line 72
Quoted 5 lines
monitor.c +2
-0@@ -68,6 +68,8 @@* 's' string (accept optional quote) * 'i' 32 bit integer * 'l' target long (32 or 64 bit) +* 'M' just like 'l', except in user mode the value is +* multiplied by 2^20 (think Mebibyte)
Hello Markus,
Not sure of the best answer, but thought there should be some discussion.
You mention Mebibyte, which according to the all knowing Wikipedia, is abbreviated Mi.
I understand that if you will only support one, then maybe you don't need to differentiate from Megabyte, but then in a later patch you use m, u, and n for powers of 10. This causes your new double format to use powers of 2 above one and powers of 10 below.
Maybe this is just one of those geek things, powers of 2 for integers, and powers of 10 for fractions.
Good luck.
Chris
Quoted 9 lines
monitor.c +0
-0* '/' optional gdb-like print format (like "/10x") * * '?' optional type (for all types, except '/') Signature · 1 line
1.6.6
Re: [Qemu-devel] [PATCH v2 1/8] monitor: Document argument type 'M'
Quoted 5 lines · Chris
Hello Markus,
Not sure of the best answer, but thought there should be some discussion.
Quoted 7 lines
You mention Mebibyte, which according to the all knowing Wikipedia, is abbreviated Mi.
I understand that if you will only support one, then maybe you don't need to differentiate from Megabyte, but then in a later patch you use m, u, and n for powers of 10. This causes your new double format to use powers of 2 above one and powers of 10 below.
Really?
Argument types M and b use powers of 2.
Argument type T uses powers of 10.
Quoted 4 lines
Maybe this is just one of those geek things, powers of 2 for integers, and powers of 10 for fractions.
Good luck.
I merely reimplemented existing usage in a way that does the right thing for QMP. Can't say I like the ad-hocery there, but improving the (non-QMP) monitor is not my objective right now.
PATCH v2 2/8 QDict: New qdict_get_double()
In reply to Markus ArmbrusterHelper function just like qdict_get_int(), just for QFloat/double.
--- qdict.c | 15 +++++++++++++++ qdict.h | 1 + 2 files changed, 16 insertions(+), 0 deletions(-)
qdict.c +15 -0
@@ -11,6 +11,7 @@*/ #include "qint.h" +#include "qfloat.h" #include "qdict.h" #include "qbool.h" #include "qstring.h"
@@ -175,6 +176,20 @@ static QObject *qdict_get_obj(const QDict *qdict, const char *key, }/** +* qdict_get_double(): Get an number mapped by 'key' +* +* This function assumes that 'key' exists and it stores a +* QFloat object. +* +* Return number mapped by 'key'. +*/ +double qdict_get_double (const QDict *qdict,const char *key) +{ +QObject *obj =qdict_get_obj (qdict, key,QTYPE_QFLOAT ); +return qfloat_get_double (qobject_to_qfloat (obj)); +} + +/** * qdict_get_int(): Get an integer mapped by 'key' * * This function assumes that 'key' exists and it stores a
qdict.h +1 -0
@@ -37,6 +37,7 @@ void qdict_iter(const QDict *qdict,qdict_put_obj (qdict, key,QOBJECT (obj)) /* High level helpers */ +double qdict_get_double (const QDict *qdict,const char *key);int64_t qdict_get_int (const QDict *qdict,const char *key);int qdict_get_bool (const QDict *qdict,const char *key);QList *qdict_get_qlist (const QDict *qdict,const char *key);
Signature · 1 line
1.6.6
PATCH v2 3/8 monitor: New argument type 'b'
In reply to Markus ArmbrusterThis is a double value with optional suffixes G, g, M, m, K, k. We'll need this to get migrate_set_speed() QMP-ready.
--- monitor.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 58 insertions(+), 0 deletions(-)
monitor.c +58 -0
@@ -47,6 +47,7 @@#include "kvm.h" #include "acl.h" #include "qint.h" +#include "qfloat.h" #include "qlist.h" #include "qdict.h" #include "qbool.h"
@@ -70,6 +71,10 @@* '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 +* 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 * '/' optional gdb-like print format (like "/10x") * * '?' optional type (for all types, except '/')
@@ -3181,6 +3186,27 @@ static int get_expr(Monitor *mon, int64_t *pval, const char **pp)return 0 ; } +static int get_double (Monitor *mon,double *pval,const char **pp) +{ +const char *p = *pp; +char *tailp; +double d; + + errno =0 ; + d =strtod (p, &tailp); +if (tailp == p) { +monitor_printf (mon,"Number expected\n" ); +return -1 ; + } +if (errno) { +monitor_printf (mon,"Bad number (%s)\n" ,strerror (errno)); +return -1 ; + } + *pval = d; + *pp = tailp; +return 0 ; +} +static int get_str (char *buf,int buf_size,const char **pp) {const char *p;
@@ -3517,6 +3543,38 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,qdict_put (qdict, key,qint_from_int (val)); }break ; +case 'b' : + { +double val; + +while (qemu_isspace (*p)) + p++; +if (*typestr =='?' ) { + typestr++; +if (*p =='\0' ) { +break ; + } + } +if (get_double (mon, &val, &p) <0 ) { + goto fail; + } +if (*p) { +switch (*p) { +case 'K' :case 'k' : + val *=1 <<10 ; p++;break ; +case 'M' :case 'm' : + val *=1 <<20 ; p++;break ; +case 'G' :case 'g' : + val *=1 <<30 ; p++;break ; + } + } +if (*p && !qemu_isspace (*p)) { +monitor_printf (mon,"Unknown unit suffix\n" ); + goto fail; + } +qdict_put (qdict, key,qfloat_from_double (val)); + } +break ;case '-' : {const char *tmp = p;
Signature · 1 line
1.6.6
Re: [Qemu-devel] [PATCH v2 3/8] monitor: New argument type 'b'
Quoted 2 lines · On Wed, 20 Jan 2010 17:08:17 +0100 Markus Armbruster <[email protected]> wrote:
This is a double value with optional suffixes G, g, M, m, K, k. We'll need this to get
migrate_set_speed()QMP-ready.
Nice, not only good for QMP: we're moving this kind of handling
from the handlers to common code, which is the right thing to do.
The only possible issue is that, if we decide to move all this stuff
to json, such types will make the change complex. But that's something for the future.
Some comments follow.
Quoted 29 lines
Signed-off-by Markus Armbruster <[email protected]>--- monitor.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 58 insertions(+), 0 deletions(-)monitor.c +5
-0@@ -47,6 +47,7 @@#include "kvm.h" #include "acl.h" #include "qint.h" +#include "qfloat.h" #include "qlist.h" #include "qdict.h" #include "qbool.h" @@ -70,6 +71,10 @@* '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 +* 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 * '/' optional gdb-like print format (like "/10x") * * '?' optional type (for all types, except '/')
monitor.c static int get_expr(Monitor *mon, int64_t *pval, const char **pp) · line 3192
Quoted 7 lines
monitor.c +4
-0@@ -3181,6 +3186,27 @@ static int get_expr(Monitor *mon, int64_t *pval, const char **pp)return 0 ; } +static int get_double (Monitor *mon,double *pval,const char **pp) +{ +const char *p = *pp; +char *tailp;
Better to init to NULL?
monitor.c static int get_expr(Monitor *mon, int64_t *pval, const char **pp) · line 3204
Quoted 12 lines
monitor.c +12
-0+double d; + + errno =0 ; + d =strtod (p, &tailp); +if (tailp == p) { +monitor_printf (mon,"Number expected\n" ); +return -1 ; + } +if (errno) { +monitor_printf (mon,"Bad number (%s)\n" ,strerror (errno)); +return -1 ; + }
Should we trust errno this way? The manpage only mentions ERANGE.
Quoted 31 lines
monitor.c +24
-0+ *pval = d; + *pp = tailp; +return 0 ; +} +static int get_str (char *buf,int buf_size,const char **pp) {const char *p;@@ -3517,6 +3543,38 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,qdict_put (qdict, key,qint_from_int (val)); }break ; +case 'b' : + { +double val; + +while (qemu_isspace (*p)) + p++; +if (*typestr =='?' ) { + typestr++; +if (*p =='\0' ) { +break ; + } + } +if (get_double (mon, &val, &p) <0 ) { + goto fail; + } +if (*p) { +switch (*p) { +case 'K' :case 'k' : + val *=1 <<10 ; p++;break ;
monitor.c static const mon_cmd_t *monitor_parse_command(Monitor *mon, · line 3574
Quoted 10 lines
monitor.c +10
-0+case 'M' :case 'm' : + val *=1 <<20 ; p++;break ; +case 'G' :case 'g' : + val *=1 <<30 ; p++;break ; + } + } +if (*p && !qemu_isspace (*p)) { +monitor_printf (mon,"Unknown unit suffix\n" ); + goto fail; + }
A good way to test if 'p' handling is correct, is to write a test
handler which has different types (say, 'foo:b,str:s,bla:i') and print the values to see if they match what we expect or have hardcoded to values in a specific test handler...
Quoted 6 lines
monitor.c +3
-0+qdict_put (qdict, key,qfloat_from_double (val)); + } +break ;case '-' : {const char *tmp = p;
Re: [Qemu-devel] [PATCH v2 3/8] monitor: New argument type 'b'
Quoted 47 lines · Luiz Capitulino
Quoted 2 lines · On Wed, 20 Jan 2010 17:08:17 +0100 Markus Armbruster <[email protected]> wrote:
This is a double value with optional suffixes G, g, M, m, K, k. We'll need this to get
migrate_set_speed()QMP-ready.Nice, not only good for QMP: we're moving this kind of handling
from the handlers to common code, which is the right thing to do.The only possible issue is that, if we decide to move all this stuff
to json, such types will make the change complex. But that's something for the future.Some comments follow.
Quoted 32 lines
Signed-off-by Markus Armbruster <[email protected]>--- monitor.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 58 insertions(+), 0 deletions(-)monitor.c +5
-0@@ -47,6 +47,7 @@#include "kvm.h" #include "acl.h" #include "qint.h" +#include "qfloat.h" #include "qlist.h" #include "qdict.h" #include "qbool.h" @@ -70,6 +71,10 @@* '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 +* 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 * '/' optional gdb-like print format (like "/10x") * * '?' optional type (for all types, except '/') @@ -3181,6 +3186,27 @@ static int get_expr(Monitor *mon, int64_t *pval, const char **pp)return 0 ; }
Quoted 6 lines
monitor.c static int get_expr(Monitor *mon, int64_t *pval, const char **pp) · line 3192
Quoted 4 lines
monitor.c +4
-0+static int get_double (Monitor *mon,double *pval,const char **pp) +{ +const char *p = *pp; +char *tailp;Better to init to NULL?
Not necessary, as strtod() sets tailp unconditionally.
Quoted 13 lines
monitor.c static int get_expr(Monitor *mon, int64_t *pval, const char **pp) · line 3204
Quoted 12 lines
monitor.c +12
-0+double d; + + errno =0 ; + d =strtod (p, &tailp); +if (tailp == p) { +monitor_printf (mon,"Number expected\n" ); +return -1 ; + } +if (errno) { +monitor_printf (mon,"Bad number (%s)\n" ,strerror (errno)); +return -1 ; + }
Quoted 1 line
Should we trust errno this way? The manpage only mentions ERANGE.
Unless we want to ignore errors other than the "Number expected" caught above, we have to check errno. strtod() doesn't have a distinct error value.
I'm not particular about reporting strerror(errno).
Quoted 38 lines
Quoted 38 lines
monitor.c +31
-0+ *pval = d; + *pp = tailp; +return 0 ; +} +static int get_str (char *buf,int buf_size,const char **pp) {const char *p;@@ -3517,6 +3543,38 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,qdict_put (qdict, key,qint_from_int (val)); }break ; +case 'b' : + { +double val; + +while (qemu_isspace (*p)) + p++; +if (*typestr =='?' ) { + typestr++; +if (*p =='\0' ) { +break ; + } + } +if (get_double (mon, &val, &p) <0 ) { + goto fail; + } +if (*p) { +switch (*p) { +case 'K' :case 'k' : + val *=1 <<10 ; p++;break ; +case 'M' :case 'm' : + val *=1 <<20 ; p++;break ; +case 'G' :case 'g' : + val *=1 <<30 ; p++;break ; + } + } +if (*p && !qemu_isspace (*p)) {
Quoted 8 lines
monitor.c static const mon_cmd_t *monitor_parse_command(Monitor *mon, · line 3574
Quoted 3 lines
monitor.c +3
-0+monitor_printf (mon,"Unknown unit suffix\n" ); + goto fail; + }A good way to test if 'p' handling is correct, is to write a test
handler which has different types (say, 'foo:b,str:s,bla:i') and print the values to see if they match what we expect or have hardcoded to values in a specific test handler...
Umm, what do you want me to do here?
Quoted 6 lines
Quoted 6 lines
monitor.c +3
-0+qdict_put (qdict, key,qfloat_from_double (val)); + } +break ;case '-' : {const char *tmp = p;
Re: [Qemu-devel] [PATCH v2 3/8] monitor: New argument type 'b'
Quoted 49 lines · On Thu, 21 Jan 2010 15:04:43 +0100 Markus Armbruster <[email protected]> wrote:
Quoted 47 lines · Luiz Capitulino
Quoted 2 lines · On Wed, 20 Jan 2010 17:08:17 +0100 Markus Armbruster <[email protected]> wrote:
This is a double value with optional suffixes G, g, M, m, K, k. We'll need this to get
migrate_set_speed()QMP-ready.Nice, not only good for QMP: we're moving this kind of handling
from the handlers to common code, which is the right thing to do.The only possible issue is that, if we decide to move all this stuff
to json, such types will make the change complex. But that's something for the future.Some comments follow.
Quoted 32 lines
Signed-off-by Markus Armbruster <[email protected]>--- monitor.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 58 insertions(+), 0 deletions(-)monitor.c +5
-0@@ -47,6 +47,7 @@#include "kvm.h" #include "acl.h" #include "qint.h" +#include "qfloat.h" #include "qlist.h" #include "qdict.h" #include "qbool.h" @@ -70,6 +71,10 @@* '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 +* 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 * '/' optional gdb-like print format (like "/10x") * * '?' optional type (for all types, except '/') @@ -3181,6 +3186,27 @@ static int get_expr(Monitor *mon, int64_t *pval, const char **pp)return 0 ; }
Quoted 8 lines
Quoted 6 lines
monitor.c static int get_expr(Monitor *mon, int64_t *pval, const char **pp) · line 3192
Quoted 4 lines
monitor.c +4
-0+static int get_double (Monitor *mon,double *pval,const char **pp) +{ +const char *p = *pp; +char *tailp;Better to init to NULL?
Not necessary, as
strtod()sets tailp unconditionally.
Ok.
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
monitor.c +12
-0+double d; + + errno =0 ; + d =strtod (p, &tailp); +if (tailp == p) { +monitor_printf (mon,"Number expected\n" ); +return -1 ; + } +if (errno) { +monitor_printf (mon,"Bad number (%s)\n" ,strerror (errno)); +return -1 ; + }
Quoted 7 lines
Quoted 1 line
Should we trust errno this way? The manpage only mentions ERANGE.
Unless we want to ignore errors other than the "Number expected" caught above, we have to check errno.
strtod()doesn't have a distinct error value.I'm not particular about reporting strerror(errno).
Ok, no big deal. I just tend to do strictly what the manpages says.
Quoted 47 lines
Quoted 38 lines
Quoted 38 lines
monitor.c +31
-0+ *pval = d; + *pp = tailp; +return 0 ; +} +static int get_str (char *buf,int buf_size,const char **pp) {const char *p;@@ -3517,6 +3543,38 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,qdict_put (qdict, key,qint_from_int (val)); }break ; +case 'b' : + { +double val; + +while (qemu_isspace (*p)) + p++; +if (*typestr =='?' ) { + typestr++; +if (*p =='\0' ) { +break ; + } + } +if (get_double (mon, &val, &p) <0 ) { + goto fail; + } +if (*p) { +switch (*p) { +case 'K' :case 'k' : + val *=1 <<10 ; p++;break ; +case 'M' :case 'm' : + val *=1 <<20 ; p++;break ; +case 'G' :case 'g' : + val *=1 <<30 ; p++;break ; + } + } +if (*p && !qemu_isspace (*p)) {Quoted 8 lines
monitor.c static const mon_cmd_t *monitor_parse_command(Monitor *mon, · line 3574
Quoted 3 lines
monitor.c +3
-0+monitor_printf (mon,"Unknown unit suffix\n" ); + goto fail; + }A good way to test if 'p' handling is correct, is to write a test
handler which has different types (say, 'foo:b,str:s,bla:i') and print the values to see if they match what we expect or have hardcoded to values in a specific test handler...
Quoted 1 line
Umm, what do you want me to do here?
Just a suggestion on how I would test this stuff.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
monitor.c +3
-0+qdict_put (qdict, key,qfloat_from_double (val)); + } +break ;case '-' : {const char *tmp = p;
Re: [Qemu-devel] [PATCH v2 3/8] monitor: New argument type 'b'
Quoted 78 lines · Luiz Capitulino
Quoted 49 lines · On Thu, 21 Jan 2010 15:04:43 +0100 Markus Armbruster <[email protected]> wrote:
Quoted 47 lines · Luiz Capitulino
Quoted 2 lines · On Wed, 20 Jan 2010 17:08:17 +0100 Markus Armbruster <[email protected]> wrote:
This is a double value with optional suffixes G, g, M, m, K, k. We'll need this to get
migrate_set_speed()QMP-ready.Nice, not only good for QMP: we're moving this kind of handling
from the handlers to common code, which is the right thing to do.The only possible issue is that, if we decide to move all this stuff
to json, such types will make the change complex. But that's something for the future.Some comments follow.
Quoted 32 lines
Signed-off-by Markus Armbruster <[email protected]>--- monitor.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 58 insertions(+), 0 deletions(-)monitor.c +5
-0@@ -47,6 +47,7 @@#include "kvm.h" #include "acl.h" #include "qint.h" +#include "qfloat.h" #include "qlist.h" #include "qdict.h" #include "qbool.h" @@ -70,6 +71,10 @@* '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 +* 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 * '/' optional gdb-like print format (like "/10x") * * '?' optional type (for all types, except '/') @@ -3181,6 +3186,27 @@ static int get_expr(Monitor *mon, int64_t *pval, const char **pp)return 0 ; }Quoted 8 lines
Quoted 6 lines
monitor.c static int get_expr(Monitor *mon, int64_t *pval, const char **pp) · line 3192
Quoted 4 lines
monitor.c +4
-0+static int get_double (Monitor *mon,double *pval,const char **pp) +{ +const char *p = *pp; +char *tailp;Better to init to NULL?
Not necessary, as
strtod()sets tailp unconditionally.Ok.
Quoted 15 lines
Quoted 14 lines
monitor.c static int get_expr(Monitor *mon, int64_t *pval, const char **pp) · line 3204
Quoted 12 lines
monitor.c +12
-0+double d; + + errno =0 ; + d =strtod (p, &tailp); +if (tailp == p) { +monitor_printf (mon,"Number expected\n" ); +return -1 ; + } +if (errno) { +monitor_printf (mon,"Bad number (%s)\n" ,strerror (errno)); +return -1 ; + }Should we trust errno this way? The manpage only mentions ERANGE.
Quoted 7 lines
Quoted 5 lines
Unless we want to ignore errors other than the "Number expected" caught above, we have to check errno.
strtod()doesn't have a distinct error value.I'm not particular about reporting strerror(errno).
Ok, no big deal. I just tend to do strictly what the manpages says.
We might want to ignore underflow silently, and fail loudly for ininity and NaN. Opinions?
[...]
PATCH v2 4/8 monitor: Use argument type 'b' for migrate_set_speed()
In reply to Markus ArmbrusterBefore, it used type 's', which strips quotes and interprets escapes, and is quite inappropriate for QMP.
--- migration.c | 18 +++--------------- qemu-monitor.hx | 2 +- 2 files changed, 4 insertions(+), 16 deletions(-)
migration.c +3 -15
@@ -109,23 +109,11 @@ void do_migrate_cancel(Monitor *mon, const QDict *qdict, QObject **ret_data)void do_migrate_set_speed (Monitor *mon,const QDict *qdict) {double d; -char *ptr;FdMigrationState *s; -const char *value =qdict_get_str (qdict,"value" ); - - d =strtod (value, &ptr); -switch (*ptr) { -case 'G' :case 'g' : - d *=1024 ; -case 'M' :case 'm' : - d *=1024 ; -case 'K' :case 'k' : - d *=1024 ; -default : -break ; - } - max_throttle = (uint32_t )d; + d =qdict_get_double (qdict,"value" ); + d =MAX (0 ,MIN (INT32_MAX , d)); + max_throttle = d; s =migrate_to_fms (current_migration);if (s && s->file) {
qemu-monitor.hx +1 -1
@@ -761,7 +761,7 @@ ETEXI { .name = "migrate_set_speed", - .args_type = "value:s", + .args_type = "value:b", .params = "value", .help = "set maximum speed (in bytes) for migrations", .mhandler.cmd = do_migrate_set_speed,
Signature · 1 line
1.6.6
PATCH v2 5/8 monitor: convert do_migrate_set_speed() to QObject
In reply to Markus Armbruster--- migration.c | 2 +- migration.h | 2 +- qemu-monitor.hx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
migration.c +1 -1
@@ -106,7 +106,7 @@ void do_migrate_cancel(Monitor *mon, const QDict *qdict, QObject **ret_data) s->cancel (s); } -void do_migrate_set_speed (Monitor *mon,const QDict *qdict) +void do_migrate_set_speed (Monitor *mon,const QDict *qdict,QObject **ret_data) {double d;FdMigrationState *s;
migration.h +1 -1
@@ -56,7 +56,7 @@ void do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data);void do_migrate_cancel (Monitor *mon,const QDict *qdict,QObject **ret_data); -void do_migrate_set_speed (Monitor *mon,const QDict *qdict); +void do_migrate_set_speed (Monitor *mon,const QDict *qdict,QObject **ret_data);uint64_t migrate_max_downtime (void );
qemu-monitor.hx +1 -1
@@ -764,7 +764,7 @@ ETEXI .args_type = "value:b", .params = "value", .help = "set maximum speed (in bytes) for migrations", - .mhandler.cmd = do_migrate_set_speed, + .mhandler.cmd_new = do_migrate_set_speed, }, STEXI
Signature · 1 line
1.6.6
PATCH v2 6/8 monitor: New argument type 'T'
In reply to Markus ArmbrusterThis is a double value with optional suffixes ms, us, ns. We'll need this to get migrate_set_downtime() QMP-ready.
--- monitor.c | 16 +++++++++++++++- 1 files changed, 15 insertions(+), 1 deletions(-)
monitor.c +15 -1
@@ -75,6 +75,9 @@* 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 +* 'T' double +* user mode accepts an optional ms, us, ns suffix, +* which divides the value by 1e3, 1e6, 1e9, respectively * '/' optional gdb-like print format (like "/10x") * * '?' optional type (for all types, except '/')
@@ -3544,6 +3547,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, }break ;case 'b' : +case 'T' : {double val;
@@ -3558,7 +3562,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,if (get_double (mon, &val, &p) <0 ) { goto fail; } -if (*p) { +if (c =='b' && *p) {switch (*p) {case 'K' :case 'k' : val *=1 <<10 ; p++;break ;
@@ -3568,6 +3572,16 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, val *=1 <<30 ; p++;break ; } } +if (c =='T' && p[0 ] && p[1 ] =='s' ) { +switch (*p) { +case 'm' : + val /=1e3 ; p +=2 ;break ; +case 'u' : + val /=1e6 ; p +=2 ;break ; +case 'n' : + val /=1e9 ; p +=2 ;break ; + } + }if (*p && !qemu_isspace (*p)) {monitor_printf (mon,"Unknown unit suffix\n" ); goto fail;
Signature · 1 line
1.6.6
Re: [Qemu-devel] [PATCH v2 6/8] monitor: New argument type 'T'
Quoted 40 lines · On Wed, 20 Jan 2010 17:08:20 +0100 Markus Armbruster <[email protected]> wrote:
This is a double value with optional suffixes ms, us, ns. We'll need this to get
migrate_set_downtime()QMP-ready.Signed-off-by Markus Armbruster <[email protected]>--- monitor.c | 16 +++++++++++++++- 1 files changed, 15 insertions(+), 1 deletions(-)monitor.c +5
-1@@ -75,6 +75,9 @@* 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 +* 'T' double +* user mode accepts an optional ms, us, ns suffix, +* which divides the value by 1e3, 1e6, 1e9, respectively * '/' optional gdb-like print format (like "/10x") * * '?' optional type (for all types, except '/') @@ -3544,6 +3547,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, }break ;case 'b' : +case 'T' : {double val;@@ -3558,7 +3562,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,if (get_double (mon, &val, &p) <0 ) { goto fail; } -if (*p) { +if (c =='b' && *p) {switch (*p) {case 'K' :case 'k' : val *=1 <<10 ; p++;break ;
monitor.c static const mon_cmd_t *monitor_parse_command(Monitor *mon, · line 3575
Quoted 4 lines
monitor.c +1
-0@@ -3568,6 +3572,16 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, val *=1 <<30 ; p++;break ; } } +if (c =='T' && p[0 ] && p[1 ] =='s' ) {
Is this indexing of 'p' really correct? What if the value you're interested
is at the of the string? Like:
.args_type = "str:s,value:b"
Quoted 12 lines
monitor.c +9
-0+switch (*p) { +case 'm' : + val /=1e3 ; p +=2 ;break ; +case 'u' : + val /=1e6 ; p +=2 ;break ; +case 'n' : + val /=1e9 ; p +=2 ;break ; + } + }if (*p && !qemu_isspace (*p)) {monitor_printf (mon,"Unknown unit suffix\n" ); goto fail;
Re: [Qemu-devel] [PATCH v2 6/8] monitor: New argument type 'T'
Quoted 51 lines · Luiz Capitulino
Quoted 40 lines · On Wed, 20 Jan 2010 17:08:20 +0100 Markus Armbruster <[email protected]> wrote:
This is a double value with optional suffixes ms, us, ns. We'll need this to get
migrate_set_downtime()QMP-ready.Signed-off-by Markus Armbruster <[email protected]>--- monitor.c | 16 +++++++++++++++- 1 files changed, 15 insertions(+), 1 deletions(-)monitor.c +5
-1@@ -75,6 +75,9 @@* 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 +* 'T' double +* user mode accepts an optional ms, us, ns suffix, +* which divides the value by 1e3, 1e6, 1e9, respectively * '/' optional gdb-like print format (like "/10x") * * '?' optional type (for all types, except '/') @@ -3544,6 +3547,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, }break ;case 'b' : +case 'T' : {double val;@@ -3558,7 +3562,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,if (get_double (mon, &val, &p) <0 ) { goto fail; } -if (*p) { +if (c =='b' && *p) {switch (*p) {case 'K' :case 'k' : val *=1 <<10 ; p++;break ;monitor.c static const mon_cmd_t *monitor_parse_command(Monitor *mon, · line 3575
Quoted 4 lines
monitor.c +1
-0@@ -3568,6 +3572,16 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, val *=1 <<30 ; p++;break ; } } +if (c =='T' && p[0 ] && p[1 ] =='s' ) {Is this indexing of 'p' really correct? What if the value you're interested
is at the of the string? Like:
Quoted 1 line
.args_type = "str:s,value:b"
p points right behind the floating-point number. If no characters follow, it points to the string's terminating zero. If exactly one character follows, it points to that one, and the next one is the terminating zero. If more than one follow, p points to the first one.
"p[0] && p[1] == 's'" is safe, because p[0] is safe, and if p[0] != 0, then p[1] is also safe.
Convinced?
Quoted 12 lines
Quoted 12 lines
monitor.c +9
-0+switch (*p) { +case 'm' : + val /=1e3 ; p +=2 ;break ; +case 'u' : + val /=1e6 ; p +=2 ;break ; +case 'n' : + val /=1e9 ; p +=2 ;break ; + } + }if (*p && !qemu_isspace (*p)) {monitor_printf (mon,"Unknown unit suffix\n" ); goto fail;
Re: [Qemu-devel] [PATCH v2 6/8] monitor: New argument type 'T'
Quoted 60 lines · On Thu, 21 Jan 2010 14:54:51 +0100 Markus Armbruster <[email protected]> wrote:
Quoted 51 lines · Luiz Capitulino
Quoted 40 lines · On Wed, 20 Jan 2010 17:08:20 +0100 Markus Armbruster <[email protected]> wrote:
This is a double value with optional suffixes ms, us, ns. We'll need this to get
migrate_set_downtime()QMP-ready.Signed-off-by Markus Armbruster <[email protected]>--- monitor.c | 16 +++++++++++++++- 1 files changed, 15 insertions(+), 1 deletions(-)monitor.c +5
-1@@ -75,6 +75,9 @@* 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 +* 'T' double +* user mode accepts an optional ms, us, ns suffix, +* which divides the value by 1e3, 1e6, 1e9, respectively * '/' optional gdb-like print format (like "/10x") * * '?' optional type (for all types, except '/') @@ -3544,6 +3547,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, }break ;case 'b' : +case 'T' : {double val;@@ -3558,7 +3562,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,if (get_double (mon, &val, &p) <0 ) { goto fail; } -if (*p) { +if (c =='b' && *p) {switch (*p) {case 'K' :case 'k' : val *=1 <<10 ; p++;break ;monitor.c static const mon_cmd_t *monitor_parse_command(Monitor *mon, · line 3575
Quoted 4 lines
monitor.c +1
-0@@ -3568,6 +3572,16 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon, val *=1 <<30 ; p++;break ; } } +if (c =='T' && p[0 ] && p[1 ] =='s' ) {Is this indexing of 'p' really correct? What if the value you're interested
is at the of the string? Like:Quoted 1 line
.args_type = "str:s,value:b"
p points right behind the floating-point number. If no characters follow, it points to the string's terminating zero. If exactly one character follows, it points to that one, and the next one is the terminating zero. If more than one follow, p points to the first one.
Quoted 4 lines
"p[0] && p[1] == 's'" is safe, because p[0] is safe, and if p[0] != 0, then p[1] is also safe.
Convinced?
Yes, looks fine.
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
monitor.c +9
-0+switch (*p) { +case 'm' : + val /=1e3 ; p +=2 ;break ; +case 'u' : + val /=1e6 ; p +=2 ;break ; +case 'n' : + val /=1e9 ; p +=2 ;break ; + } + }if (*p && !qemu_isspace (*p)) {monitor_printf (mon,"Unknown unit suffix\n" ); goto fail;
PATCH v2 7/8 monitor: Use argument type 'T' for migrate_set_downtime()
In reply to Markus ArmbrusterBefore, it used type 's', which strips quotes and interprets escapes, and is quite inappropriate for QMP.
--- migration.c | 15 ++------------- qemu-monitor.hx | 2 +- 2 files changed, 3 insertions(+), 14 deletions(-)
migration.c +2 -13
@@ -134,21 +134,10 @@ uint64_t migrate_max_downtime(void)void do_migrate_set_downtime (Monitor *mon,const QDict *qdict) { -char *ptr;double d; -const char *value =qdict_get_str (qdict,"value" ); - - d =strtod (value, &ptr); -if (!strcmp (ptr,"ms" )) { - d *=1000000 ; - }else if (!strcmp (ptr,"us" )) { - d *=1000 ; - }else if (!strcmp (ptr,"ns" )) { - }else { -/* all else considered to be seconds */ - d *=1000000000 ; - } + d =qdict_get_double (qdict,"value" ) /1e9 ; + d =MAX (0 ,MIN (UINT64_MAX , d)); max_downtime = (uint64_t )d; }
qemu-monitor.hx +1 -1
@@ -774,7 +774,7 @@ ETEXI { .name = "migrate_set_downtime", - .args_type = "value:s", + .args_type = "value:T", .params = "value", .help = "set maximum tolerated downtime (in seconds) for migrations", .mhandler.cmd = do_migrate_set_downtime,
Signature · 1 line
1.6.6
PATCH v2 8/8 monitor: convert do_migrate_set_downtime() to QObject
In reply to Markus Armbruster--- migration.c | 3 ++- migration.h | 3 ++- qemu-monitor.hx | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-)
migration.c +2 -1
@@ -132,7 +132,8 @@ uint64_t migrate_max_downtime(void)return max_downtime; } -void do_migrate_set_downtime (Monitor *mon,const QDict *qdict) +void do_migrate_set_downtime (Monitor *mon,const QDict *qdict, +QObject **ret_data) {double d;
migration.h +2 -1
@@ -60,7 +60,8 @@ void do_migrate_set_speed(Monitor *mon, const QDict *qdict, QObject **ret_data);uint64_t migrate_max_downtime (void ); -void do_migrate_set_downtime (Monitor *mon,const QDict *qdict); +void do_migrate_set_downtime (Monitor *mon,const QDict *qdict, +QObject **ret_data);void do_info_migrate_print (Monitor *mon,const QObject *data);
qemu-monitor.hx +1 -1
@@ -777,7 +777,7 @@ ETEXI .args_type = "value:T", .params = "value", .help = "set maximum tolerated downtime (in seconds) for migrations", - .mhandler.cmd = do_migrate_set_downtime, + .mhandler.cmd_new = do_migrate_set_downtime, }, STEXI
Signature · 1 line
1.6.6
Please ignore the v2 in the subject, it's an accident.
I'll respin this series.