optionally specify vm stop message
PATCH 1/1 optionally specify vm stop message
Should be applied on top of ENOSPC series.
gdbstub.c +3 -3
@@ -1928,7 +1928,7 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...) gdb_current_syscall_cb = cb; s->state =RS_SYSCALL ;#ifndef CONFIG_USER_ONLY -vm_stop (EXCP_DEBUG ); +vm_stop (EXCP_DEBUG ,NULL );#endif s->state =RS_IDLE ;va_start (va, fmt);
@@ -2002,7 +2002,7 @@ static void gdb_read_byte(GDBState *s, int ch)if (vm_running) {/* when the CPU is running, we cannot do anything except stop it when receiving a char */ -vm_stop (EXCP_INTERRUPT ); +vm_stop (EXCP_INTERRUPT ,NULL ); } else#endif {
@@ -2253,7 +2253,7 @@ static void gdb_chr_event(void *opaque, int event) {switch (event) {case CHR_EVENT_RESET : -vm_stop (EXCP_INTERRUPT ); +vm_stop (EXCP_INTERRUPT ,NULL ); gdb_has_xml =0 ;break ;default :
hw/ide.c +2 -2
@@ -999,7 +999,7 @@ static void ide_sector_write(IDEState *s)if (ret == -ENOSPC ) { s->bmdma->ide_if = s; s->bmdma->status |=BM_STATUS_PIO_RETRY ; -vm_stop (0 ); +vm_stop (0 ,"No more space on a disk" ); }else ide_rw_error (s);return ;
@@ -1058,7 +1058,7 @@ static void ide_write_dma_cb(void *opaque, int ret)if (ret <0 ) {if (ret == -ENOSPC ) { bm->status |=BM_STATUS_DMA_RETRY ; -vm_stop (0 ); +vm_stop (0 ,"No more space on a disk" ); }else ide_dma_error (s);return ;
migration-exec.c +1 -1
@@ -124,7 +124,7 @@ int exec_start_incoming_migration(const char *command)dprintf ("Unable to apply qemu wrapper to popen file\n" );return -errno; } -vm_stop (0 );/* just in case */ +vm_stop (0 ,NULL );/* just in case */ ret =qemu_loadvm_state (f);if (ret <0 ) {fprintf (stderr,"load of migration failed\n" );
migration-tcp.c +1 -1
@@ -161,7 +161,7 @@ static void tcp_accept_incoming_migration(void *opaque) goto out; } -vm_stop (0 );/* just in case */ +vm_stop (0 ,NULL );/* just in case */ ret =qemu_loadvm_state (f);if (ret <0 ) {fprintf (stderr,"load of migration failed\n" );
migration.c +1 -1
@@ -213,7 +213,7 @@ void migrate_fd_put_ready(void *opaque)dprintf ("iterate\n" );if (qemu_savevm_state_iterate (s->file) ==1 ) {dprintf ("done iterating\n" ); -vm_stop (0 ); +vm_stop (0 ,NULL );bdrv_flush_all ();qemu_savevm_state_complete (s->file);
monitor.c +1 -1
@@ -491,7 +491,7 @@ static void do_log(const char *items)static void do_stop (void ) { -vm_stop (EXCP_INTERRUPT ); +vm_stop (EXCP_INTERRUPT ,NULL ); }static void do_cont (void )
savevm.c +3 -3
@@ -770,7 +770,7 @@ int qemu_savevm_state(QEMUFile *f)int ret; saved_vm_running = vm_running; -vm_stop (0 ); +vm_stop (0 ,NULL );bdrv_flush_all ();
@@ -1037,7 +1037,7 @@ void do_savevm(const char *name)qemu_aio_flush (); saved_vm_running = vm_running; -vm_stop (0 ); +vm_stop (0 ,NULL ); must_delete =0 ;if (name) {
@@ -1133,7 +1133,7 @@ void do_loadvm(const char *name)qemu_aio_flush (); saved_vm_running = vm_running; -vm_stop (0 ); +vm_stop (0 ,NULL );for (i =0 ; i <= nb_drives; i++) { bs1 = drives_table[i].bdrv;
sysemu.h +1 -1
@@ -23,7 +23,7 @@ int qemu_add_vm_stop_handler(VMStopHandler *cb, void *opaque);void qemu_del_vm_stop_handler (VMStopHandler *cb,void *opaque);void vm_start (void ); -void vm_stop (int reason); +void vm_stop (int reason,const char *msg);int64_t cpu_get_ticks (void );void cpu_enable_ticks (void );
vl.c +5 -3
@@ -3438,7 +3438,7 @@ void vm_start(void) } } -void vm_stop (int reason) +void vm_stop (int reason,const char *msg) {if (vm_running) {cpu_disable_ticks ();
@@ -3449,6 +3449,8 @@ void vm_stop(int reason) } }vm_state_notify (0 ); +if (msg) +term_printf ("%s\n" , msg); } }
@@ -3745,7 +3747,7 @@ static int main_loop(void)if (shutdown_requested) { ret =EXCP_INTERRUPT ;if (no_shutdown) { -vm_stop (0 ); +vm_stop (0 ,NULL ); no_shutdown =0 ; }else
@@ -3763,7 +3765,7 @@ static int main_loop(void) }if (unlikely (ret ==EXCP_DEBUG )) {gdb_set_stop_cpu (cur_cpu); -vm_stop (EXCP_DEBUG ); +vm_stop (EXCP_DEBUG ,NULL ); }/* If all cpus are halted then wait until the next IRQ */ /* XXX: use timeout computed from timers */
--
Gleb.
Quoted 2 lines · Gleb Natapov
Should be applied on top of ENOSPC series.
How about just adding a new vm_stop reason? That will work out better when we introduce the improved monitor.
Regards,
Anthony Liguori
Quoted 195 lines
Signed-off-by Gleb Natapov <[email protected]>gdbstub.c +3
-3@@ -1928,7 +1928,7 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...) gdb_current_syscall_cb = cb; s->state =RS_SYSCALL ;#ifndef CONFIG_USER_ONLY -vm_stop (EXCP_DEBUG ); +vm_stop (EXCP_DEBUG ,NULL );#endif s->state =RS_IDLE ;va_start (va, fmt);@@ -2002,7 +2002,7 @@ static void gdb_read_byte(GDBState *s, int ch)if (vm_running) {/* when the CPU is running, we cannot do anything except stop it when receiving a char */ -vm_stop (EXCP_INTERRUPT ); +vm_stop (EXCP_INTERRUPT ,NULL ); } else#endif {@@ -2253,7 +2253,7 @@ static void gdb_chr_event(void *opaque, int event) {switch (event) {case CHR_EVENT_RESET : -vm_stop (EXCP_INTERRUPT ); +vm_stop (EXCP_INTERRUPT ,NULL ); gdb_has_xml =0 ;break ;default :hw/ide.c +2
-2@@ -999,7 +999,7 @@ static void ide_sector_write(IDEState *s)if (ret == -ENOSPC ) { s->bmdma->ide_if = s; s->bmdma->status |=BM_STATUS_PIO_RETRY ; -vm_stop (0 ); +vm_stop (0 ,"No more space on a disk" ); }else ide_rw_error (s);return ;@@ -1058,7 +1058,7 @@ static void ide_write_dma_cb(void *opaque, int ret)if (ret <0 ) {if (ret == -ENOSPC ) { bm->status |=BM_STATUS_DMA_RETRY ; -vm_stop (0 ); +vm_stop (0 ,"No more space on a disk" ); }else ide_dma_error (s);return ;migration-exec.c +1
-1@@ -124,7 +124,7 @@ int exec_start_incoming_migration(const char *command)dprintf ("Unable to apply qemu wrapper to popen file\n" );return -errno; } -vm_stop (0 );/* just in case */ +vm_stop (0 ,NULL );/* just in case */ ret =qemu_loadvm_state (f);if (ret <0 ) {fprintf (stderr,"load of migration failed\n" );migration-tcp.c +1
-1@@ -161,7 +161,7 @@ static void tcp_accept_incoming_migration(void *opaque) goto out; } -vm_stop (0 );/* just in case */ +vm_stop (0 ,NULL );/* just in case */ ret =qemu_loadvm_state (f);if (ret <0 ) {fprintf (stderr,"load of migration failed\n" );migration.c +1
-1@@ -213,7 +213,7 @@ void migrate_fd_put_ready(void *opaque)dprintf ("iterate\n" );if (qemu_savevm_state_iterate (s->file) ==1 ) {dprintf ("done iterating\n" ); -vm_stop (0 ); +vm_stop (0 ,NULL );bdrv_flush_all ();qemu_savevm_state_complete (s->file);monitor.c +1
-1@@ -491,7 +491,7 @@ static void do_log(const char *items)static void do_stop (void ) { -vm_stop (EXCP_INTERRUPT ); +vm_stop (EXCP_INTERRUPT ,NULL ); }static void do_cont (void )savevm.c +3
-3@@ -770,7 +770,7 @@ int qemu_savevm_state(QEMUFile *f)int ret; saved_vm_running = vm_running; -vm_stop (0 ); +vm_stop (0 ,NULL );bdrv_flush_all ();@@ -1037,7 +1037,7 @@ void do_savevm(const char *name)qemu_aio_flush (); saved_vm_running = vm_running; -vm_stop (0 ); +vm_stop (0 ,NULL ); must_delete =0 ;if (name) {@@ -1133,7 +1133,7 @@ void do_loadvm(const char *name)qemu_aio_flush (); saved_vm_running = vm_running; -vm_stop (0 ); +vm_stop (0 ,NULL );for (i =0 ; i <= nb_drives; i++) { bs1 = drives_table[i].bdrv;sysemu.h +1
-1@@ -23,7 +23,7 @@ int qemu_add_vm_stop_handler(VMStopHandler *cb, void *opaque);void qemu_del_vm_stop_handler (VMStopHandler *cb,void *opaque);void vm_start (void ); -void vm_stop (int reason); +void vm_stop (int reason,const char *msg);int64_t cpu_get_ticks (void );void cpu_enable_ticks (void );vl.c +5
-4@@ -3438,7 +3438,7 @@ void vm_start(void) } } -void vm_stop (int reason) +void vm_stop (int reason,const char *msg) {if (vm_running) {cpu_disable_ticks ();@@ -3449,6 +3449,8 @@ void vm_stop(int reason) } }vm_state_notify (0 ); +if (msg) +term_printf ("%s\n" , msg); } }@@ -3745,7 +3747,7 @@ static int main_loop(void)if (shutdown_requested) { ret =EXCP_INTERRUPT ;if (no_shutdown) { -vm_stop (0 ); +vm_stop (0 ,NULL ); no_shutdown =0 ; }else @@ -3763,7 +3765,7 @@ static int main_loop(void) }if (unlikely (ret ==EXCP_DEBUG )) {gdb_set_stop_cpu (cur_cpu); -vm_stop (EXCP_DEBUG ); +vm_stop (EXCP_DEBUG ,NULL ); }/* If all cpus are halted then wait until the next IRQ */ /* XXX: use timeout computed from timers */ --Gleb.
Quoted 7 lines · Anthony Liguori
Quoted 2 lines · Gleb Natapov
Should be applied on top of ENOSPC series.
How about just adding a new
vm_stopreason? That will work out better when we introduce the improved monitor.
We may want to specify different message for the same reason. For instance we may want to print the name of the file we failed to write to. Also non zero reasons a handled differently by vm_stop. Don't know why.
--
Gleb.
Quoted 7 lines · Gleb Natapov
Quoted 5 lines · Anthony Liguori
Quoted 3 lines · Gleb Natapov
Should be applied on top of ENOSPC series.
Quoted 6 lines
Quoted 3 lines
How about just adding a new
vm_stopreason? That will work out better when we introduce the improved monitor.We may want to specify different message for the same reason. For instance we may want to print the name of the file we failed to write to.
I'm thinking about this from a management tool perspective. When we have a better monitor interface, this would generate an async notification. Instead of generating an arbitrary string, it could send a reason code that has a well defined meaning.
For now, within vm_stop, it can say if (reason == VM_STOP_ENOSPC) printf("ran out of space"); or something.
There are other places we stop a vm, like when -no-shutdown is used, where using a reason code would be very useful.
Quoted 3 lines
Also non zero reasons a handled differently by
vm_stop. Don't know
why.
It's an ugly hack for gdbstub. It notifies gdb when a breakpoint occurs. We have far too many state tracking mechanisms. Anyway, gdb can pass something like VM_STOP_BP and that can be used to trigger the callback.
Regards,
Anthony Liguori
Quoted 5 lines
--
Gleb.
Quoted 26 lines · Anthony Liguori
Quoted 6 lines · Gleb Natapov
Quoted 4 lines · Anthony Liguori
Quoted 2 lines · Gleb Natapov
Should be applied on top of ENOSPC series.
Quoted 7 lines
Quoted 4 lines
How about just adding a new
vm_stopreason? That will work out better when we introduce the improved monitor.We may want to specify different message for the same reason. For instance we may want to print the name of the file we failed to write to.
I'm thinking about this from a management tool perspective. When we have a better monitor interface, this would generate an async notification. Instead of generating an arbitrary string, it could send a reason code that has a well defined meaning.
For now, within
vm_stop, it can say if (reason ==VM_STOP_ENOSPC)printf("ran out of space"); or something.There are other places we stop a vm, like when -no-shutdown is used, where using a reason code would be very useful.
Quoted 8 lines
Quoted 3 lines
Also non zero reasons a handled differently by
vm_stop. Don't know
why.It's an ugly hack for gdbstub. It notifies gdb when a breakpoint occurs. We have far too many state tracking mechanisms. Anyway, gdb can pass something like
VM_STOP_BPand that can be used to trigger the callback.
It's not only used for breakpoints but any stop condition that should be reported to the gdb frontend (so far: EXCP_DEBUG and EXCP_INTERRUPT). Not sure, though, how to deal with ENOSPC - it's not a guest fault, it's a host problem. From that POV, gdb should not receive it.
Nevertheless, gdb_vm_stopped should better do the filtering, not the caller of vm_stop by passing 0 for "any other reason gdb should be bothered with".
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 26 Corporate Competence Center Embedded Linux
Quoted 12 lines · Jan Kiszka
Quoted 9 lines · Anthony Liguori
Quoted 4 lines
Also non zero reasons a handled differently by
vm_stop. Don't know
why.It's an ugly hack for gdbstub. It notifies gdb when a breakpoint occurs. We have far too many state tracking mechanisms. Anyway, gdb can pass something like
VM_STOP_BPand that can be used to trigger the callback.
Quoted 5 lines
It's not only used for breakpoints but any stop condition that should be reported to the gdb frontend (so far:
EXCP_DEBUGandEXCP_INTERRUPT). Not sure, though, how to deal with ENOSPC - it's not a guest fault, it's a host problem. From that POV, gdb should not receive it.
We already have a vm_change_state_handler that is invoked whenever a guest starts running or stops running. gdb should be able to use that and look at env->exception_index, no?
Regards,
Anthony Liguori
Quoted 7 lines
Nevertheless,
gdb_vm_stoppedshould better do the filtering, not the caller ofvm_stopby passing 0 for "any other reason gdb should be bothered with".Jan
Quoted 18 lines · Anthony Liguori
Quoted 11 lines · Jan Kiszka
Quoted 8 lines · Anthony Liguori
Quoted 3 lines
Also non zero reasons a handled differently by
vm_stop. Don't know
why.It's an ugly hack for gdbstub. It notifies gdb when a breakpoint occurs. We have far too many state tracking mechanisms. Anyway, gdb can pass something like
VM_STOP_BPand that can be used to trigger the callback.Quoted 5 lines
It's not only used for breakpoints but any stop condition that should be reported to the gdb frontend (so far:
EXCP_DEBUGandEXCP_INTERRUPT). Not sure, though, how to deal with ENOSPC - it's not a guest fault, it's a host problem. From that POV, gdb should not receive it.
Quoted 3 lines
We already have a
vm_change_state_handlerthat is invoked whenever a guest starts running or stops running. gdb should be able to use that and look atenv->exception_index, no?
I don't think env->exception_index is set when you issue "stop" from the monitor, e.g. Moreover, that would be an ugly (out-of-band) API as well.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 26 Corporate Competence Center Embedded Linux
Quoted 17 lines · Jan Kiszka
Quoted 16 lines · Anthony Liguori
Quoted 15 lines · Jan Kiszka
Quoted 8 lines · Anthony Liguori
Quoted 3 lines
Also non zero reasons a handled differently by
vm_stop. Don't know
why.It's an ugly hack for gdbstub. It notifies gdb when a breakpoint occurs. We have far too many state tracking mechanisms. Anyway, gdb can pass something like
VM_STOP_BPand that can be used to trigger the callback.It's not only used for breakpoints but any stop condition that should be reported to the gdb frontend (so far:
EXCP_DEBUGandEXCP_INTERRUPT). Not sure, though, how to deal with ENOSPC - it's not a guest fault, it's a host problem. From that POV, gdb should not receive it.
Quoted 7 lines
Quoted 3 lines
We already have a
vm_change_state_handlerthat is invoked whenever a guest starts running or stops running. gdb should be able to use that and look atenv->exception_index, no?I don't think
env->exception_indexis set when you issue "stop" from the monitor, e.g. Moreover, that would be an ugly (out-of-band) API as well.
The point is that vm_stop can be issued from any context, not just from a vcpu. So there may be no env channel at this point.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 26 Corporate Competence Center Embedded Linux
Quoted 21 lines · Jan Kiszka
Quoted 20 lines · Jan Kiszka
Quoted 19 lines · Anthony Liguori
Quoted 10 lines · Jan Kiszka
Quoted 8 lines · Anthony Liguori
Quoted 3 lines
Also non zero reasons a handled differently by
vm_stop. Don't know
why.It's an ugly hack for gdbstub. It notifies gdb when a breakpoint occurs. We have far too many state tracking mechanisms. Anyway, gdb can pass something like
VM_STOP_BPand that can be used to trigger the callback.Quoted 5 lines
It's not only used for breakpoints but any stop condition that should be reported to the gdb frontend (so far:
EXCP_DEBUGandEXCP_INTERRUPT). Not sure, though, how to deal with ENOSPC - it's not a guest fault, it's a host problem. From that POV, gdb should not receive it.We already have a
vm_change_state_handlerthat is invoked whenever a guest starts running or stops running. gdb should be able to use that and look atenv->exception_index, no?
Quoted 6 lines
Quoted 3 lines
I don't think
env->exception_indexis set when you issue "stop" from the monitor, e.g. Moreover, that would be an ugly (out-of-band) API as well.The point is that
vm_stopcan be issued from any context, not just from a vcpu. So there may be no env channel at this point.
But we could enhance the state-change callback interface.... WARNING, untested quick-hack to overcome vm_stop_cb follows!
Jan
-------->
audio/audio.c +2 -1
@@ -1622,7 +1622,8 @@ static int audio_driver_init (AudioState *s, struct audio_driver *drv) } } -static void audio_vm_change_state_handler (void *opaque,int running) +static void audio_vm_change_state_handler (void *opaque,int running, +int reason) {AudioState *s = opaque;HWVoiceOut *hwo =NULL ;
gdbstub.c +5 -6
@@ -1991,7 +1991,7 @@ void gdb_set_stop_cpu(CPUState *env) }#ifndef CONFIG_USER_ONLY -static void gdb_vm_stopped (void *opaque,int reason) +static void gdb_vm_state_change (void *opaque,int running,int reason) {GDBState *s = gdbserver_state;CPUState *env = s->c_cpu;
@@ -1999,7 +1999,8 @@ static void gdb_vm_stopped(void *opaque, int reason)const char *type;int ret; -if (s->state ==RS_SYSCALL ) +if (running || (reason !=EXCP_DEBUG && reason !=EXCP_INTERRUPT ) || + s->state ==RS_SYSCALL )return ;/* disable single step if it was enable */
@@ -2028,10 +2029,8 @@ static void gdb_vm_stopped(void *opaque, int reason) }tb_flush (env); ret =GDB_SIGNAL_TRAP ; - }else if (reason ==EXCP_INTERRUPT ) { - ret =GDB_SIGNAL_INT ; }else { - ret =0 ; + ret =GDB_SIGNAL_INT ; }snprintf (buf,sizeof (buf),"T%02xthread:%02x;" , ret, env->cpu_index+1 );put_packet (s, buf);
@@ -2424,7 +2423,7 @@ int gdbserver_start(const char *port) gdbserver_state = s;qemu_chr_add_handlers (chr, gdb_chr_can_receive, gdb_chr_receive, gdb_chr_event,NULL ); -qemu_add_vm_stop_handler (gdb_vm_stopped,NULL ); +qemu_add_vm_change_state_handler (gdb_vm_state_change,NULL ); return 0; }#endif
sysemu.h +1 -5
@@ -12,16 +12,12 @@ extern uint8_t qemu_uuid[];#define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"typedef struct vm_change_state_entry VMChangeStateEntry ; -typedef void VMChangeStateHandler (void *opaque,int running); -typedef void VMStopHandler (void *opaque,int reason); +typedef void VMChangeStateHandler (void *opaque,int running,int reason);VMChangeStateEntry *qemu_add_vm_change_state_handler (VMChangeStateHandler *cb,void *opaque);void qemu_del_vm_change_state_handler (VMChangeStateEntry *e); -int qemu_add_vm_stop_handler (VMStopHandler *cb,void *opaque); -void qemu_del_vm_stop_handler (VMStopHandler *cb,void *opaque); -void vm_start (void );void vm_stop (int reason);
vl.c +4 -25
@@ -3404,37 +3404,21 @@ void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)qemu_free (e); } -static void vm_state_notify (int running) +static void vm_state_notify (int running,int reason) {VMChangeStateEntry *e;for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) { - e->cb (e->opaque, running); + e->cb (e->opaque, running, reason); } } -/* XXX: support several handlers */ -static VMStopHandler *vm_stop_cb; -static void *vm_stop_opaque; - -int qemu_add_vm_stop_handler (VMStopHandler *cb,void *opaque) -{ - vm_stop_cb = cb; - vm_stop_opaque = opaque; -return 0 ; -} - -void qemu_del_vm_stop_handler (VMStopHandler *cb,void *opaque) -{ - vm_stop_cb =NULL ; -} -void vm_start (void ) {if (!vm_running) {cpu_enable_ticks (); vm_running =1 ; -vm_state_notify (1 ); +vm_state_notify (1 ,0 );qemu_rearm_alarm_timer (alarm_timer); } }
@@ -3444,12 +3428,7 @@ void vm_stop(int reason)if (vm_running) {cpu_disable_ticks (); vm_running =0 ; -if (reason !=0 ) { -if (vm_stop_cb) { -vm_stop_cb (vm_stop_opaque, reason); - } - } -vm_state_notify (0 ); +vm_state_notify (0 , reason); } }
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 26 Corporate Competence Center Embedded Linux
Quoted 3 lines · Jan Kiszka
But we could enhance the state-change callback interface.... WARNING, untested quick-hack to overcome
vm_stop_cbfollows!
Yes, this would be much better, although having it tested is an obvious prereq :-)
Regards,
Anthony Liguori