Skip to contentSkip to conversation

Move some declarations around in the QEMU CharDriver code

PATCH In review Anthony Liguori 4 participants 6 messages Oct 23, 2008 – Oct 27, 2008 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Move some declarations around in the QEMU CharDriver code

The goal of this series is to move the CharDriverState code out of vl.c and into its own file, qemu-char.c. This patch moves around some declarations so the next patch can be pure code motion.

qemu-char.h +2 -0
index 05d6899..701884e 100644
@@ -73,6 +73,8 @@ int qemu_chr_can_read(CharDriverState *s);
 void qemu_chr_read(CharDriverState *s, uint8_t *buf, int len);
 void qemu_chr_accept_input(CharDriverState *s);
 
+extern int term_escape_char;
+
 /* async I/O support */
 
 int qemu_set_fd_handler2(int fd,
qemu_socket.h +6 -0
index f8817bf..18488dd 100644
@@ -28,9 +28,15 @@ int inet_aton(const char *cp, struct in_addr *ia);
 #define socket_error() errno
 #define closesocket(s) close(s)
 
+int parse_unix_path(struct sockaddr_un *uaddr, const char *str);
+
 #endif /* !_WIN32 */
 
 void socket_set_nonblock(int fd);
 int parse_host_port(struct sockaddr_in *saddr, const char *str);
+int parse_host_src_port(struct sockaddr_in *haddr,
+                        struct sockaddr_in *saddr,
+                        const char *str);
+int send_all(int fd, const uint8_t *buf, int len1);
 
 #endif /* QEMU_SOCKET_H */
sysemu.h +3 -1
index 57ba19e..ff0144b 100644
@@ -98,7 +98,7 @@ extern int no_quit;
 extern int semihosting_enabled;
 extern int old_param;
 extern const char *bootp_filename;
-
+extern DisplayState display_state;
 
 #ifdef USE_KQEMU
 extern int kqemu_allowed;
@@ -155,6 +155,8 @@ extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
 
 extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
 
+#define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
+
 #ifdef NEED_CPU_H
 /* loader.c */
 int get_image_size(const char *filename);
vl.c +8 -17
index c0e43ac..34513ff 100644
@@ -179,7 +179,7 @@ int nb_drives;
 static BlockDriverState *bs_snapshots;
 static int vga_ram_size;
 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
-static DisplayState display_state;
+DisplayState display_state;
 int nographic;
 static int curses;
 const char* keyboard_layout = NULL;
@@ -252,8 +252,6 @@ static QEMUTimer *icount_vm_timer;
 
 uint8_t qemu_uuid[16];
 
-#define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
-
 /***********************************************************/
 /* x86 ISA bus support */
 
@@ -1877,7 +1875,7 @@ static int mux_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
                 int64_t ti;
                 int secs;
 
-                ti = get_clock();
+                ti = qemu_get_clock(rt_clock);
                 if (term_timestamps_start == -1)
                     term_timestamps_start = ti;
                 ti -= term_timestamps_start;
@@ -1906,7 +1904,7 @@ static const char * const mux_help[] = {
     NULL
 };
 
-static int term_escape_char = 0x01; /* ctrl-a is used for escape */
+int term_escape_char = 0x01; /* ctrl-a is used for escape */
 static void mux_print_help(CharDriverState *chr)
 {
     int i, j;
@@ -2105,7 +2103,7 @@ static int socket_init(void)
     return 0;
 }
 
-static int send_all(int fd, const uint8_t *buf, int len1)
+int send_all(int fd, const uint8_t *buf, int len1)
 {
     int ret, len;
 
@@ -2150,7 +2148,7 @@ static int unix_write(int fd, const uint8_t *buf, int len1)
     return len1 - len;
 }
 
-static inline int send_all(int fd, const uint8_t *buf, int len1)
+inline int send_all(int fd, const uint8_t *buf, int len1)
 {
     return unix_write(fd, buf, len1);
 }
@@ -2169,7 +2167,7 @@ static int stdio_nb_clients = 0;
 static int fd_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
 {
     FDCharDriver *s = chr->opaque;
-    return unix_write(s->fd_out, buf, len);
+    return send_all(s->fd_out, buf, len);
 }
 
 static int fd_chr_read_poll(void *opaque)
@@ -2476,7 +2474,7 @@ static int pty_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
         pty_chr_update_read_handler(chr);
         return 0;
     }
-    return unix_write(s->fd, buf, len);
+    return send_all(s->fd, buf, len);
 }
 
 static int pty_chr_read_poll(void *opaque)
@@ -3365,13 +3363,6 @@ static void udp_chr_update_read_handler(CharDriverState *chr)
     }
 }
 
-#ifndef _WIN32
-static int parse_unix_path(struct sockaddr_un *uaddr, const char *str);
-#endif
-int parse_host_src_port(struct sockaddr_in *haddr,
-                        struct sockaddr_in *saddr,
-                        const char *str);
-
 static CharDriverState *qemu_chr_open_udp(const char *def)
 {
     CharDriverState *chr = NULL;
@@ -4006,7 +3997,7 @@ int parse_host_port(struct sockaddr_in *saddr, const char *str)
 }
 
 #ifndef _WIN32
-static int parse_unix_path(struct sockaddr_un *uaddr, const char *str)
+int parse_unix_path(struct sockaddr_un *uaddr, const char *str)
 {
     const char *p;
     int len;
#1 lore raw

PATCH 2/2 Move CharDriverState code out of vl.c

The motivating goal behind this is to allow other tools to use the CharDriver code. This patch is pure code motion except for the Makefile changes and the copyright/header in qemu-char.c.

Anyone object to this?

 Makefile.target |    2 
 qemu-char.c     | 2195 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 vl.c            | 2107 -----------------------------------------------------
 3 files changed, 2196 insertions(+), 2108 deletions(-)
Makefile.target +1 -1
index e2edf9d..d5e9e59 100644
@@ -474,7 +474,7 @@ endif #CONFIG_DARWIN_USER
 ifndef CONFIG_USER_ONLY
 
 OBJS=vl.o osdep.o monitor.o pci.o loader.o isa_mmio.o machine.o net-checksum.o
-OBJS+=fw_cfg.o aio.o buffered_file.o migration.o migration-tcp.o
+OBJS+=fw_cfg.o aio.o buffered_file.o migration.o migration-tcp.o qemu-char.o
 ifdef CONFIG_WIN32
 OBJS+=block-raw-win32.o
 else
qemu-char.c new file +2195 -0

2,195 lines not on this page · raw message

vl.c +0 -2107

797 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#2 lore raw
In reply to Anthony Liguori
Quoted 3 lines · Anthony Liguori

The goal of this series is to move the CharDriverState code out of vl.c and
into its own file, qemu-char.c. This patch moves around some declarations so the next patch can be pure code motion.

Good idea. Do you plan to do this for other things, for example network code?

Quoted 2 lines

-static inline int send_all(int fd, const uint8_t *buf, int len1) +inline int send_all(int fd, const uint8_t *buf, int len1)

The 'inline' looks a bit odd without 'static'.

#3 lore raw
Quoted 6 lines · Blue Swirl
Quoted 3 lines · Anthony Liguori

The goal of this series is to move the CharDriverState code out of vl.c and
into its own file, qemu-char.c. This patch moves around some declarations so the next patch can be pure code motion.

Good idea. Do you plan to do this for other things, for example network code?

/me just started hacking up a ipv6-aware qemu-inet.c ...

cheers,
Gerd

#4 lore raw
Quoted 4 lines · Gerd Hoffmann
Quoted 2 lines · Blue Swirl

On 10/23/08, Anthony Liguori <[email protected]> wrote:

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

The goal of this series is to move the CharDriverState code out of vl.c and
into its own file, qemu-char.c. This patch moves around some declarations so the next patch can be pure code motion.

Good idea. Do you plan to do this for other things, for example network code?

/me just started hacking up a ipv6-aware qemu-inet.c ...

What's the goal here? Are you talking about ipv6-enabled slirp or is this something more clever?

Regards,

Anthony Liguori

Quoted 7 lines

cheers,
Gerd

#5 lore raw
In reply to Blue Swirl
Quoted 9 lines · Blue Swirl
Quoted 4 lines · Anthony Liguori

The goal of this series is to move the CharDriverState code out of vl.c and
into its own file, qemu-char.c. This patch moves around some declarations so the next patch can be pure code motion.

Good idea. Do you plan to do this for other things, for example network code?

Yes, I have patches in queue to move out the networking code, the timer code, and the main loop. I have two goals here. A lot of the vl.c code is target independent so I'd like to move a lot of that code to be compiled once for all targets. I also want to be able to reuse the main loop in things like qemu-nbd so that it can be fully asychronous without needing to rewrite all of that code.

I'll go ahead and commit the CharDriverState movement and post the next movement patch in a couple days.

Quoted 7 lines
Quoted 4 lines

-static inline int send_all(int fd, const uint8_t *buf, int len1) +inline int send_all(int fd, const uint8_t *buf, int len1)

The 'inline' looks a bit odd without 'static'.

Yeah, I'll fix that. Didn't notice that for whatever reason.

Regards,

Anthony Liguori