Commit 86e94dea5b740dad65446c857f6959eae43e0ba6
1 parent
8f28f3fb
Reinitialize monitor upon reconnect, by Anthony Liguori.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2300 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
4 changed files
with
50 additions
and
7 deletions
console.c
| @@ -1086,5 +1086,7 @@ CharDriverState *text_console_init(DisplayState *ds) | @@ -1086,5 +1086,7 @@ CharDriverState *text_console_init(DisplayState *ds) | ||
| 1086 | s->t_attrib = s->t_attrib_default; | 1086 | s->t_attrib = s->t_attrib_default; |
| 1087 | text_console_resize(s); | 1087 | text_console_resize(s); |
| 1088 | 1088 | ||
| 1089 | + qemu_chr_reset(chr); | ||
| 1090 | + | ||
| 1089 | return chr; | 1091 | return chr; |
| 1090 | } | 1092 | } |
monitor.c
| @@ -55,6 +55,7 @@ typedef struct term_cmd_t { | @@ -55,6 +55,7 @@ typedef struct term_cmd_t { | ||
| 55 | } term_cmd_t; | 55 | } term_cmd_t; |
| 56 | 56 | ||
| 57 | static CharDriverState *monitor_hd; | 57 | static CharDriverState *monitor_hd; |
| 58 | +static int hide_banner; | ||
| 58 | 59 | ||
| 59 | static term_cmd_t term_cmds[]; | 60 | static term_cmd_t term_cmds[]; |
| 60 | static term_cmd_t info_cmds[]; | 61 | static term_cmd_t info_cmds[]; |
| @@ -2438,15 +2439,24 @@ static void monitor_start_input(void) | @@ -2438,15 +2439,24 @@ static void monitor_start_input(void) | ||
| 2438 | readline_start("(qemu) ", 0, monitor_handle_command1, NULL); | 2439 | readline_start("(qemu) ", 0, monitor_handle_command1, NULL); |
| 2439 | } | 2440 | } |
| 2440 | 2441 | ||
| 2442 | +static void term_event(void *opaque, int event) | ||
| 2443 | +{ | ||
| 2444 | + if (event != CHR_EVENT_RESET) | ||
| 2445 | + return; | ||
| 2446 | + | ||
| 2447 | + if (!hide_banner) | ||
| 2448 | + term_printf("QEMU %s monitor - type 'help' for more information\n", | ||
| 2449 | + QEMU_VERSION); | ||
| 2450 | + monitor_start_input(); | ||
| 2451 | +} | ||
| 2452 | + | ||
| 2441 | void monitor_init(CharDriverState *hd, int show_banner) | 2453 | void monitor_init(CharDriverState *hd, int show_banner) |
| 2442 | { | 2454 | { |
| 2443 | monitor_hd = hd; | 2455 | monitor_hd = hd; |
| 2444 | - if (show_banner) { | ||
| 2445 | - term_printf("QEMU %s monitor - type 'help' for more information\n", | ||
| 2446 | - QEMU_VERSION); | ||
| 2447 | - } | 2456 | + hide_banner = !show_banner; |
| 2457 | + | ||
| 2448 | qemu_chr_add_read_handler(hd, term_can_read, term_read, NULL); | 2458 | qemu_chr_add_read_handler(hd, term_can_read, term_read, NULL); |
| 2449 | - monitor_start_input(); | 2459 | + qemu_chr_add_event_handler(hd, term_event); |
| 2450 | } | 2460 | } |
| 2451 | 2461 | ||
| 2452 | /* XXX: use threads ? */ | 2462 | /* XXX: use threads ? */ |
vl.c
| @@ -1165,6 +1165,23 @@ void quit_timers(void) | @@ -1165,6 +1165,23 @@ void quit_timers(void) | ||
| 1165 | /***********************************************************/ | 1165 | /***********************************************************/ |
| 1166 | /* character device */ | 1166 | /* character device */ |
| 1167 | 1167 | ||
| 1168 | +static void qemu_chr_reset_bh(void *opaque) | ||
| 1169 | +{ | ||
| 1170 | + CharDriverState *s = opaque; | ||
| 1171 | + if (s->chr_event) | ||
| 1172 | + s->chr_event(s, CHR_EVENT_RESET); | ||
| 1173 | + qemu_bh_delete(s->bh); | ||
| 1174 | + s->bh = NULL; | ||
| 1175 | +} | ||
| 1176 | + | ||
| 1177 | +void qemu_chr_reset(CharDriverState *s) | ||
| 1178 | +{ | ||
| 1179 | + if (s->bh == NULL) { | ||
| 1180 | + s->bh = qemu_bh_new(qemu_chr_reset_bh, s); | ||
| 1181 | + qemu_bh_schedule(s->bh); | ||
| 1182 | + } | ||
| 1183 | +} | ||
| 1184 | + | ||
| 1168 | int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len) | 1185 | int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len) |
| 1169 | { | 1186 | { |
| 1170 | return s->chr_write(s, buf, len); | 1187 | return s->chr_write(s, buf, len); |
| @@ -1402,6 +1419,9 @@ static CharDriverState *qemu_chr_open_fd(int fd_in, int fd_out) | @@ -1402,6 +1419,9 @@ static CharDriverState *qemu_chr_open_fd(int fd_in, int fd_out) | ||
| 1402 | chr->opaque = s; | 1419 | chr->opaque = s; |
| 1403 | chr->chr_write = fd_chr_write; | 1420 | chr->chr_write = fd_chr_write; |
| 1404 | chr->chr_add_read_handler = fd_chr_add_read_handler; | 1421 | chr->chr_add_read_handler = fd_chr_add_read_handler; |
| 1422 | + | ||
| 1423 | + qemu_chr_reset(chr); | ||
| 1424 | + | ||
| 1405 | return chr; | 1425 | return chr; |
| 1406 | } | 1426 | } |
| 1407 | 1427 | ||
| @@ -1819,6 +1839,7 @@ static CharDriverState *qemu_chr_open_tty(const char *filename) | @@ -1819,6 +1839,7 @@ static CharDriverState *qemu_chr_open_tty(const char *filename) | ||
| 1819 | if (!chr) | 1839 | if (!chr) |
| 1820 | return NULL; | 1840 | return NULL; |
| 1821 | chr->chr_ioctl = tty_serial_ioctl; | 1841 | chr->chr_ioctl = tty_serial_ioctl; |
| 1842 | + qemu_chr_reset(chr); | ||
| 1822 | return chr; | 1843 | return chr; |
| 1823 | } | 1844 | } |
| 1824 | 1845 | ||
| @@ -1882,6 +1903,9 @@ static CharDriverState *qemu_chr_open_pp(const char *filename) | @@ -1882,6 +1903,9 @@ static CharDriverState *qemu_chr_open_pp(const char *filename) | ||
| 1882 | chr->chr_write = null_chr_write; | 1903 | chr->chr_write = null_chr_write; |
| 1883 | chr->chr_add_read_handler = null_chr_add_read_handler; | 1904 | chr->chr_add_read_handler = null_chr_add_read_handler; |
| 1884 | chr->chr_ioctl = pp_ioctl; | 1905 | chr->chr_ioctl = pp_ioctl; |
| 1906 | + | ||
| 1907 | + qemu_chr_reset(chr); | ||
| 1908 | + | ||
| 1885 | return chr; | 1909 | return chr; |
| 1886 | } | 1910 | } |
| 1887 | 1911 | ||
| @@ -2127,6 +2151,7 @@ static CharDriverState *qemu_chr_open_win(const char *filename) | @@ -2127,6 +2151,7 @@ static CharDriverState *qemu_chr_open_win(const char *filename) | ||
| 2127 | free(chr); | 2151 | free(chr); |
| 2128 | return NULL; | 2152 | return NULL; |
| 2129 | } | 2153 | } |
| 2154 | + qemu_chr_reset(chr); | ||
| 2130 | return chr; | 2155 | return chr; |
| 2131 | } | 2156 | } |
| 2132 | 2157 | ||
| @@ -2230,6 +2255,7 @@ static CharDriverState *qemu_chr_open_win_pipe(const char *filename) | @@ -2230,6 +2255,7 @@ static CharDriverState *qemu_chr_open_win_pipe(const char *filename) | ||
| 2230 | free(chr); | 2255 | free(chr); |
| 2231 | return NULL; | 2256 | return NULL; |
| 2232 | } | 2257 | } |
| 2258 | + qemu_chr_reset(chr); | ||
| 2233 | return chr; | 2259 | return chr; |
| 2234 | } | 2260 | } |
| 2235 | 2261 | ||
| @@ -2250,6 +2276,7 @@ static CharDriverState *qemu_chr_open_win_file(HANDLE fd_out) | @@ -2250,6 +2276,7 @@ static CharDriverState *qemu_chr_open_win_file(HANDLE fd_out) | ||
| 2250 | chr->opaque = s; | 2276 | chr->opaque = s; |
| 2251 | chr->chr_write = win_chr_write; | 2277 | chr->chr_write = win_chr_write; |
| 2252 | chr->chr_add_read_handler = win_chr_add_read_handler; | 2278 | chr->chr_add_read_handler = win_chr_add_read_handler; |
| 2279 | + qemu_chr_reset(chr); | ||
| 2253 | return chr; | 2280 | return chr; |
| 2254 | } | 2281 | } |
| 2255 | 2282 | ||
| @@ -2537,6 +2564,7 @@ static void tcp_chr_connect(void *opaque) | @@ -2537,6 +2564,7 @@ static void tcp_chr_connect(void *opaque) | ||
| 2537 | s->connected = 1; | 2564 | s->connected = 1; |
| 2538 | qemu_set_fd_handler2(s->fd, tcp_chr_read_poll, | 2565 | qemu_set_fd_handler2(s->fd, tcp_chr_read_poll, |
| 2539 | tcp_chr_read, NULL, chr); | 2566 | tcp_chr_read, NULL, chr); |
| 2567 | + qemu_chr_reset(chr); | ||
| 2540 | } | 2568 | } |
| 2541 | 2569 | ||
| 2542 | #define IACSET(x,a,b,c) x[0] = a; x[1] = b; x[2] = c; | 2570 | #define IACSET(x,a,b,c) x[0] = a; x[1] = b; x[2] = c; |
vl.h
| @@ -260,11 +260,13 @@ int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque); | @@ -260,11 +260,13 @@ int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque); | ||
| 260 | void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque); | 260 | void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque); |
| 261 | #endif | 261 | #endif |
| 262 | 262 | ||
| 263 | +typedef struct QEMUBH QEMUBH; | ||
| 264 | + | ||
| 263 | /* character device */ | 265 | /* character device */ |
| 264 | 266 | ||
| 265 | #define CHR_EVENT_BREAK 0 /* serial break char */ | 267 | #define CHR_EVENT_BREAK 0 /* serial break char */ |
| 266 | #define CHR_EVENT_FOCUS 1 /* focus to this terminal (modal input needed) */ | 268 | #define CHR_EVENT_FOCUS 1 /* focus to this terminal (modal input needed) */ |
| 267 | - | 269 | +#define CHR_EVENT_RESET 2 /* new connection established */ |
| 268 | 270 | ||
| 269 | 271 | ||
| 270 | #define CHR_IOCTL_SERIAL_SET_PARAMS 1 | 272 | #define CHR_IOCTL_SERIAL_SET_PARAMS 1 |
| @@ -295,6 +297,7 @@ typedef struct CharDriverState { | @@ -295,6 +297,7 @@ typedef struct CharDriverState { | ||
| 295 | void (*chr_send_event)(struct CharDriverState *chr, int event); | 297 | void (*chr_send_event)(struct CharDriverState *chr, int event); |
| 296 | void (*chr_close)(struct CharDriverState *chr); | 298 | void (*chr_close)(struct CharDriverState *chr); |
| 297 | void *opaque; | 299 | void *opaque; |
| 300 | + QEMUBH *bh; | ||
| 298 | } CharDriverState; | 301 | } CharDriverState; |
| 299 | 302 | ||
| 300 | void qemu_chr_printf(CharDriverState *s, const char *fmt, ...); | 303 | void qemu_chr_printf(CharDriverState *s, const char *fmt, ...); |
| @@ -305,6 +308,7 @@ void qemu_chr_add_read_handler(CharDriverState *s, | @@ -305,6 +308,7 @@ void qemu_chr_add_read_handler(CharDriverState *s, | ||
| 305 | IOReadHandler *fd_read, void *opaque); | 308 | IOReadHandler *fd_read, void *opaque); |
| 306 | void qemu_chr_add_event_handler(CharDriverState *s, IOEventHandler *chr_event); | 309 | void qemu_chr_add_event_handler(CharDriverState *s, IOEventHandler *chr_event); |
| 307 | int qemu_chr_ioctl(CharDriverState *s, int cmd, void *arg); | 310 | int qemu_chr_ioctl(CharDriverState *s, int cmd, void *arg); |
| 311 | +void qemu_chr_reset(CharDriverState *s); | ||
| 308 | 312 | ||
| 309 | /* consoles */ | 313 | /* consoles */ |
| 310 | 314 | ||
| @@ -513,7 +517,6 @@ void do_delvm(const char *name); | @@ -513,7 +517,6 @@ void do_delvm(const char *name); | ||
| 513 | void do_info_snapshots(void); | 517 | void do_info_snapshots(void); |
| 514 | 518 | ||
| 515 | /* bottom halves */ | 519 | /* bottom halves */ |
| 516 | -typedef struct QEMUBH QEMUBH; | ||
| 517 | typedef void QEMUBHFunc(void *opaque); | 520 | typedef void QEMUBHFunc(void *opaque); |
| 518 | 521 | ||
| 519 | QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque); | 522 | QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque); |