X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=src%2Fproto.c;h=63aea68e7cabc94bb64b314cdaf482b32bc2bcf0;hp=cda731e5aa2d7c8d122212b617c08cfac09c5edc;hb=33a2c184e12c0bdbf061a9f36c87d76c28444712;hpb=f4d996fd26762053d68f46de5790aae893f03d38 diff --git a/src/proto.c b/src/proto.c index cda731e..63aea68 100644 --- a/src/proto.c +++ b/src/proto.c @@ -251,8 +251,15 @@ read_log_message_or_eof (guestfs_h *g, int fd, int error_if_eof) /* QEMU's console emulates a 16550A serial port. The real 16550A * device has a small FIFO buffer (16 bytes) which means here we see * lots of small reads of 1-16 bytes in length, usually single - * bytes. + * bytes. Sleeping here for a very brief period groups reads + * together (so we usually get a few lines of output at once) and + * improves overall throughput, as well as making the event + * interface a bit more sane for callers. With a virtio-serial + * based console (not yet implemented) we may be able to remove + * this. XXX */ + usleep (1000); + n = read (fd, buf, sizeof buf); if (n == 0) { /* Hopefully this indicates the qemu child process has died. */ @@ -278,6 +285,24 @@ read_log_message_or_eof (guestfs_h *g, int fd, int error_if_eof) /* It's an actual log message, send it upwards if anyone is listening. */ guestfs___call_callbacks_message (g, GUESTFS_EVENT_APPLIANCE, buf, n); + /* This is a gross hack. See the comment above + * guestfs___launch_send_progress. + */ + if (g->state == LAUNCHING) { + const char *sentinel; + size_t len; + + sentinel = "Linux version"; /* kernel up */ + len = strlen (sentinel); + if (memmem (buf, n, sentinel, len) != NULL) + guestfs___launch_send_progress (g, 6); + + sentinel = "Starting /init script"; /* /init running */ + len = strlen (sentinel); + if (memmem (buf, n, sentinel, len) != NULL) + guestfs___launch_send_progress (g, 9); + } + return 0; } @@ -326,8 +351,10 @@ really_read_from_socket (guestfs_h *g, int sock, char *buf, size_t n) return (ssize_t) got; } -static void -send_progress_message (guestfs_h *g, const guestfs_progress *message) +/* Convenient wrapper to generate a progress message callback. */ +void +guestfs___progress_message_callback (guestfs_h *g, + const guestfs_progress *message) { uint64_t array[4]; @@ -384,7 +411,7 @@ check_for_daemon_cancellation_or_eof (guestfs_h *g, int fd) xdr_guestfs_progress (&xdr, &message); xdr_destroy (&xdr); - send_progress_message (g, &message); + guestfs___progress_message_callback (g, &message); } return 0; @@ -674,7 +701,7 @@ guestfs___recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void **buf_rtn) xdr_guestfs_progress (&xdr, &message); xdr_destroy (&xdr); - send_progress_message (g, &message); + guestfs___progress_message_callback (g, &message); } free (*buf_rtn);