Convert memsave, pmemsave, cpu to QObject+QError
cover Convert memsave, pmemsave, cpu to QObject+QError
First patch is cleanup to get rid of an error that can't happen. Rest are straightforward conversions.
Markus Armbruster (6):
monitor: Don't check for mon_get_cpu() failure
QError: New QERR_FOPEN_FAILED
monitor: convert do_memory_save() to QError
monitor: convert do_physical_memory_save() to QError
QError: New QERR_INVALID_CPU_INDEX
monitor: convert do_cpu_set() to QObject, QError
monitor.c | 47 +++++++---------------------------------------- qemu-monitor.hx | 3 ++- qerror.c | 8 ++++++++ qerror.h | 6 ++++++ 4 files changed, 23 insertions(+), 41 deletions(-)
PATCH 4/6 monitor: convert do_physical_memory_save() to QError
--- monitor.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
monitor.c +1 -1
@@ -1333,7 +1333,7 @@ static void do_physical_memory_save(Monitor *mon, const QDict *qdict, f =fopen (filename,"wb" );if (!f) { -monitor_printf (mon,"could not open '%s'\n" , filename); +qemu_error_new (QERR_FOPEN_FAILED , filename);return ; }while (size !=0 ) {
Signature · 1 line
1.6.5.2
PATCH 5/6 QError: New QERR_INVALID_CPU_INDEX
In reply to Markus Armbruster--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
@@ -81,6 +81,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "Invalid block format %(name)", }, { + .error_fmt = QERR_INVALID_CPU_INDEX, + .desc = "Invalid CPU index", + }, + { .error_fmt = QERR_INVALID_PARAMETER, .desc = "Invalid parameter %(name)", },
qerror.h +3 -0
@@ -70,6 +70,9 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_INVALID_BLOCK_FORMAT \ "{ 'class': 'InvalidBlockFormat', 'data': { 'name': %s } }" +#define QERR_INVALID_CPU_INDEX \ + "{ 'class': 'InvalidCPUIndex', 'data': {} }" +#define QERR_INVALID_PARAMETER \ "{ 'class': 'InvalidParameter', 'data': { 'name': %s } }"
Signature · 1 line
1.6.5.2
PATCH 6/6 monitor: convert do_cpu_set() to QObject, QError
In reply to Markus Armbruster--- monitor.c | 4 ++-- qemu-monitor.hx | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-)
monitor.c +2 -2
@@ -797,11 +797,11 @@ static void do_info_cpus(Monitor *mon, QObject **ret_data) *ret_data =QOBJECT (cpu_list); } -static void do_cpu_set (Monitor *mon,const QDict *qdict) +static void do_cpu_set (Monitor *mon,const QDict *qdict,QObject **ret_data) {int index =qdict_get_int (qdict,"index" );if (mon_set_cpu (index) <0 ) -monitor_printf (mon,"Invalid CPU index\n" ); +qemu_error_new (QERR_INVALID_CPU_INDEX ); }static void do_info_jit (Monitor *mon)
qemu-monitor.hx +2 -1
@@ -573,7 +573,8 @@ ETEXI .args_type = "index:i", .params = "index", .help = "set the default CPU", - .mhandler.cmd = do_cpu_set, + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_cpu_set, }, STEXI
Signature · 1 line
1.6.5.2
PATCH 1/6 monitor: Don't check for mon_get_cpu() failure
In reply to Markus Armbrustermon_get_cpu() can't return null pointer, because it passes its return value to cpu_synchronize_state() first, which crashes if its argument is null.
Remove the (pretty cheesy) handling of this non-existing error.
--- monitor.c | 39 +++------------------------------------ 1 files changed, 3 insertions(+), 36 deletions(-)
monitor.c +3 -36
@@ -682,8 +682,6 @@ static void do_info_registers(Monitor *mon) {CPUState *env; env =mon_get_cpu (); -if (!env) -return ;#ifdef TARGET_I386 cpu_dump_state (env, (FILE *)mon, monitor_fprintf,X86_DUMP_FPU );
@@ -1117,7 +1115,7 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize,int flags; flags =0 ; env =mon_get_cpu (); -if (!env && !is_physical) +if (!is_physical)return ;#ifdef TARGET_I386 if (wsize ==2 ) {
@@ -1179,8 +1177,6 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize,cpu_physical_memory_rw (addr, buf, l,0 ); }else { env =mon_get_cpu (); -if (!env) -break ;if (cpu_memory_rw_debug (env, addr, buf, l,0 ) <0 ) {monitor_printf (mon," Cannot access memory\n" );break ;
@@ -1307,8 +1303,6 @@ static void do_memory_save(Monitor *mon, const QDict *qdict, QObject **ret_data)uint8_t buf[1024 ]; env =mon_get_cpu (); -if (!env) -return ; f =fopen (filename,"wb" );if (!f) {
@@ -1743,8 +1737,6 @@ static void tlb_info(Monitor *mon)uint32_t pgd, pde, pte; env =mon_get_cpu (); -if (!env) -return ;if (!(env->cr[0 ] &CR0_PG_MASK )) {monitor_printf (mon,"PG disabled\n" );
@@ -1801,8 +1793,6 @@ static void mem_info(Monitor *mon)uint32_t pgd, pde, pte, start, end; env =mon_get_cpu (); -if (!env) -return ;if (!(env->cr[0 ] &CR0_PG_MASK )) {monitor_printf (mon,"PG disabled\n" );
@@ -2648,8 +2638,6 @@ typedef struct MonitorDef {static target_long monitor_get_pc (const struct MonitorDef *md,int val) {CPUState *env =mon_get_cpu (); -if (!env) -return 0 ;return env->eip + env->segs[R_CS ].base; }#endif
@@ -2661,9 +2649,6 @@ static target_long monitor_get_ccr (const struct MonitorDef *md, int val)unsigned int u;int i; -if (!env) -return 0 ; - u =0 ;for (i =0 ; i <8 ; i++) u |= env->crf[i] << (32 - (4 * i));
@@ -2674,40 +2659,30 @@ static target_long monitor_get_ccr (const struct MonitorDef *md, int val)static target_long monitor_get_msr (const struct MonitorDef *md,int val) {CPUState *env =mon_get_cpu (); -if (!env) -return 0 ;return env->msr; }static target_long monitor_get_xer (const struct MonitorDef *md,int val) {CPUState *env =mon_get_cpu (); -if (!env) -return 0 ;return env->xer; }static target_long monitor_get_decr (const struct MonitorDef *md,int val) {CPUState *env =mon_get_cpu (); -if (!env) -return 0 ;return cpu_ppc_load_decr (env); }static target_long monitor_get_tbu (const struct MonitorDef *md,int val) {CPUState *env =mon_get_cpu (); -if (!env) -return 0 ;return cpu_ppc_load_tbu (env); }static target_long monitor_get_tbl (const struct MonitorDef *md,int val) {CPUState *env =mon_get_cpu (); -if (!env) -return 0 ;return cpu_ppc_load_tbl (env); }#endif
@@ -2717,8 +2692,6 @@ static target_long monitor_get_tbl (const struct MonitorDef *md, int val)static target_long monitor_get_psr (const struct MonitorDef *md,int val) {CPUState *env =mon_get_cpu (); -if (!env) -return 0 ;return GET_PSR (env); }#endif
@@ -2726,8 +2699,6 @@ static target_long monitor_get_psr (const struct MonitorDef *md, int val)static target_long monitor_get_reg (const struct MonitorDef *md,int val) {CPUState *env =mon_get_cpu (); -if (!env) -return 0 ;return env->regwptr[val]; }#endif
@@ -2979,7 +2950,7 @@ static void expr_error(Monitor *mon, const char *msg)longjmp (expr_env,1 ); } -/* return 0 if OK, -1 if not found, -2 if no CPU defined */ +/* return 0 if OK, -1 if not found */ static int get_monitor_def (target_long *pval,const char *name) {const MonitorDef *md;
@@ -2991,8 +2962,6 @@ static int get_monitor_def(target_long *pval, const char *name) *pval = md->get_value (md, md->offset); }else {CPUState *env =mon_get_cpu (); -if (!env) -return -2 ; ptr = (uint8_t *)env + md->offset;switch (md->type) {case MD_I32 :
@@ -3079,10 +3048,8 @@ static int64_t expr_unary(Monitor *mon) pch++; *q =0 ; ret =get_monitor_def (®, buf); -if (ret ==-1 ) +if (ret <0 )expr_error (mon,"unknown register" ); -else if (ret ==-2 ) -expr_error (mon,"no cpu defined" ); n = reg; }break ;
Signature · 1 line
1.6.5.2
PATCH 3/6 monitor: convert do_memory_save() to QError
In reply to Markus Armbruster--- monitor.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
monitor.c +1 -1
@@ -1306,7 +1306,7 @@ static void do_memory_save(Monitor *mon, const QDict *qdict, QObject **ret_data) f =fopen (filename,"wb" );if (!f) { -monitor_printf (mon,"could not open '%s'\n" , filename); +qemu_error_new (QERR_FOPEN_FAILED , filename);return ; }while (size !=0 ) {
Signature · 1 line
1.6.5.2
PATCH 2/6 QError: New QERR_FOPEN_FAILED
In reply to Markus Armbruster--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
@@ -73,6 +73,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "No file descriptor supplied via SCM_RIGHTS", }, { + .error_fmt = QERR_FOPEN_FAILED, + .desc = "Could not open '%{filename}'", + }, + { .error_fmt = QERR_INVALID_BLOCK_FORMAT, .desc = "Invalid block format %(name)", },
qerror.h +3 -0
@@ -64,6 +64,9 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_FD_NOT_SUPPLIED \ "{ 'class': 'FdNotSupplied', 'data': {} }" +#define QERR_FOPEN_FAILED \ + "{ 'class': 'FopenFailed', 'data': { 'filename': %s } }" +#define QERR_INVALID_BLOCK_FORMAT \ "{ 'class': 'InvalidBlockFormat', 'data': { 'name': %s } }"
Signature · 1 line
1.6.5.2
Re: [Qemu-devel] [PATCH 2/6] QError: New QERR_FOPEN_FAILED
Quoted 12 lines · On Fri, 15 Jan 2010 17:25:25 +0100 Markus Armbruster <[email protected]> wrote:
Signed-off-by Markus Armbruster <[email protected]>--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)qerror.c +0
-0
qerror.c static const QErrorStringTable qerror_table[] = { · line 78
Quoted 6 lines
qerror.c +3
-0@@ -73,6 +73,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "No file descriptor supplied via SCM_RIGHTS", }, { + .error_fmt = QERR_FOPEN_FAILED, + .desc = "Could not open '%{filename}'", + },
Shouldn't this be something like QERR_OPEN_FAILED, so that we
can use the same error for all open functions?
Also, we have to think a way to specify the reason from errno.
Re: [Qemu-devel] [PATCH 2/6] QError: New QERR_FOPEN_FAILED
Quoted 10 lines · On Mon, 18 Jan 2010 12:23:28 -0200 Luiz Capitulino <[email protected]>…
Quoted 7 lines · On Fri, 15 Jan 2010 17:25:25 +0100 Markus Armbruster <[email protected]> wrote:
Signed-off-by Markus Armbruster <[email protected]>--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)
Quoted 14 lines
qerror.c static const QErrorStringTable qerror_table[] = { · line 78
Quoted 11 lines
qerror.c +3
-0@@ -73,6 +73,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "No file descriptor supplied via SCM_RIGHTS", }, { + .error_fmt = QERR_FOPEN_FAILED, + .desc = "Could not open '%{filename}'", + },Shouldn't this be something like
QERR_OPEN_FAILED, so that we
can use the same error for all open functions?
Something I forgot to mention, 'FopenFailed' doesn't seem
interesting to clients. Maybe 'OpenFileFailed'?
Re: [Qemu-devel] [PATCH 2/6] QError: New QERR_FOPEN_FAILED
In reply to Luiz CapitulinoQuoted 10 lines · Luiz Capitulino
Quoted 7 lines · On Fri, 15 Jan 2010 17:25:25 +0100 Markus Armbruster <[email protected]> wrote:
Signed-off-by Markus Armbruster <[email protected]>--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)
Quoted 14 lines
qerror.c static const QErrorStringTable qerror_table[] = { · line 78
Quoted 11 lines
qerror.c +3
-0@@ -73,6 +73,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "No file descriptor supplied via SCM_RIGHTS", }, { + .error_fmt = QERR_FOPEN_FAILED, + .desc = "Could not open '%{filename}'", + },Shouldn't this be something like
QERR_OPEN_FAILED, so that we
can use the same error for all open functions?
Whatever name you like best. The intention is certainly to use this for *file* open errors regardless of the precise function used to open.
Quoted 1 line
Also, we have to think a way to specify the reason from errno.
Yes only if client programs use this for handling the error, not just to pass it to a human user.
Although most errors are standardized, their numeric encoding is not, so we can't just transmit errno. strerror() is right out, because that's for humans.
Re: [Qemu-devel] [PATCH 2/6] QError: New QERR_FOPEN_FAILED
Quoted 27 lines · On Mon, 18 Jan 2010 15:52:13 +0100 Markus Armbruster <[email protected]> wrote:
Quoted 10 lines · Luiz Capitulino
Quoted 7 lines · On Fri, 15 Jan 2010 17:25:25 +0100 Markus Armbruster <[email protected]> wrote:
Signed-off-by Markus Armbruster <[email protected]>--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)Quoted 14 lines
qerror.c static const QErrorStringTable qerror_table[] = { · line 78
Quoted 11 lines
qerror.c +3
-0@@ -73,6 +73,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "No file descriptor supplied via SCM_RIGHTS", }, { + .error_fmt = QERR_FOPEN_FAILED, + .desc = "Could not open '%{filename}'", + },Shouldn't this be something like
QERR_OPEN_FAILED, so that we
can use the same error for all open functions?
Quoted 2 lines
Whatever name you like best. The intention is certainly to use this for *file* open errors regardless of the precise function used to open.
Probably OpenFileFailed or CantOpenFile.
Quoted 8 lines
Quoted 1 line
Also, we have to think a way to specify the reason from errno.
Yes only if client programs use this for handling the error, not just to pass it to a human user.
Although most errors are standardized, their numeric encoding is not, so we can't just transmit errno.
strerror()is right out, because that's for humans.
IIRC we had a conversation about this and the conclusion was that we
will need our own qerror_strerror() or something like that.