summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/guestfs-internal.h5
-rw-r--r--src/launch-appliance.c74
-rw-r--r--src/launch-unix.c3
-rw-r--r--src/launch.c73
4 files changed, 78 insertions, 77 deletions
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index f8ca1b2f..f046ba1d 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -211,6 +211,8 @@ struct guestfs_h
*/
int user_cancel;
+ struct timeval launch_t; /* The time that we called guestfs_launch. */
+
/*** Protocol. ***/
int fd[2]; /* Stdin/stdout of qemu. */
int sock; /* Daemon communications socket. */
@@ -230,8 +232,6 @@ struct guestfs_h
pid_t pid; /* Qemu PID. */
pid_t recoverypid; /* Recovery process PID. */
- struct timeval launch_t; /* The time that we called guestfs_launch. */
-
char *qemu_help; /* Output of qemu -help. */
char *qemu_version; /* Output of qemu -version. */
char *qemu_devices; /* Output of qemu -device ? */
@@ -380,6 +380,7 @@ extern void guestfs___trace (guestfs_h *g, const char *fs, ...)
__attribute__((format (printf,2,3)));
extern const char *guestfs___persistent_tmpdir (void);
extern void guestfs___remove_tmpdir (const char *dir);
+extern int64_t guestfs___timeval_diff (const struct timeval *x, const struct timeval *y);
extern void guestfs___print_timestamped_message (guestfs_h *g, const char *fs, ...);
#if HAVE_FUSE
extern void guestfs___free_fuse (guestfs_h *g);
diff --git a/src/launch-appliance.c b/src/launch-appliance.c
index 64bbebc1..6b4be356 100644
--- a/src/launch-appliance.c
+++ b/src/launch-appliance.c
@@ -36,7 +36,6 @@
#include "guestfs_protocol.h"
static int is_openable (guestfs_h *g, const char *path, int flags);
-static int64_t timeval_diff (const struct timeval *x, const struct timeval *y);
static void print_qemu_command_line (guestfs_h *g, char **argv);
static int qemu_supports (guestfs_h *g, const char *option);
static int qemu_supports_device (guestfs_h *g, const char *device_name);
@@ -159,8 +158,6 @@ guestfs___launch_appliance (guestfs_h *g)
return -1;
}
- /* Start the clock ... */
- gettimeofday (&g->launch_t, NULL);
guestfs___launch_send_progress (g, 0);
TRACE0 (launch_build_appliance_start);
@@ -736,74 +733,6 @@ guestfs___launch_appliance (guestfs_h *g)
return -1;
}
-/* launch (of the appliance) generates approximate progress
- * messages. Currently these are defined as follows:
- *
- * 0 / 12: launch clock starts
- * 3 / 12: appliance created
- * 6 / 12: detected that guest kernel started
- * 9 / 12: detected that /init script is running
- * 12 / 12: launch completed successfully
- *
- * Notes:
- * (1) This is not a documented ABI and the behaviour may be changed
- * or removed in future.
- * (2) Messages are only sent if more than 5 seconds has elapsed
- * since the launch clock started.
- * (3) There is a gross hack in proto.c to make this work.
- */
-void
-guestfs___launch_send_progress (guestfs_h *g, int perdozen)
-{
- struct timeval tv;
-
- gettimeofday (&tv, NULL);
- if (timeval_diff (&g->launch_t, &tv) >= 5000) {
- guestfs_progress progress_message =
- { .proc = 0, .serial = 0, .position = perdozen, .total = 12 };
-
- guestfs___progress_message_callback (g, &progress_message);
- }
-}
-
-/* Compute Y - X and return the result in milliseconds.
- * Approximately the same as this code:
- * http://www.mpp.mpg.de/~huber/util/timevaldiff.c
- */
-static int64_t
-timeval_diff (const struct timeval *x, const struct timeval *y)
-{
- int64_t msec;
-
- msec = (y->tv_sec - x->tv_sec) * 1000;
- msec += (y->tv_usec - x->tv_usec) / 1000;
- return msec;
-}
-
-/* Note that since this calls 'debug' it should only be called
- * from the parent process.
- */
-void
-guestfs___print_timestamped_message (guestfs_h *g, const char *fs, ...)
-{
- va_list args;
- char *msg;
- int err;
- struct timeval tv;
-
- va_start (args, fs);
- err = vasprintf (&msg, fs, args);
- va_end (args);
-
- if (err < 0) return;
-
- gettimeofday (&tv, NULL);
-
- debug (g, "[%05" PRIi64 "ms] %s", timeval_diff (&g->launch_t, &tv), msg);
-
- free (msg);
-}
-
/* This is called from the forked subprocess just before qemu runs, so
* it can just print the message straight to stderr, where it will be
* picked up and funnelled through the usual appliance event API.
@@ -816,7 +745,8 @@ print_qemu_command_line (guestfs_h *g, char **argv)
struct timeval tv;
gettimeofday (&tv, NULL);
- fprintf (stderr, "[%05" PRIi64 "ms] ", timeval_diff (&g->launch_t, &tv));
+ fprintf (stderr, "[%05" PRIi64 "ms] ",
+ guestfs___timeval_diff (&g->launch_t, &tv));
while (argv[i]) {
if (argv[i][0] == '-') /* -option starts a new line */
diff --git a/src/launch-unix.c b/src/launch-unix.c
index a6384dfe..3a4307ab 100644
--- a/src/launch-unix.c
+++ b/src/launch-unix.c
@@ -37,9 +37,6 @@ guestfs___launch_unix (guestfs_h *g, const char *sockpath)
int r;
struct sockaddr_un addr;
- /* Start the clock ... */
- gettimeofday (&g->launch_t, NULL);
-
/* Set these to nothing so we don't try to kill random processes or
* read from random file descriptors.
*/
diff --git a/src/launch.c b/src/launch.c
index 5886b6f6..64c7d14e 100644
--- a/src/launch.c
+++ b/src/launch.c
@@ -20,6 +20,8 @@
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
+#include <inttypes.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
@@ -261,6 +263,8 @@ guestfs__launch (guestfs_h *g)
return -1;
}
+ /* Start the clock ... */
+ gettimeofday (&g->launch_t, NULL);
TRACE0 (launch_start);
/* Make the temporary directory. */
@@ -293,6 +297,75 @@ guestfs__launch (guestfs_h *g)
}
}
+/* launch (of the appliance) generates approximate progress
+ * messages. Currently these are defined as follows:
+ *
+ * 0 / 12: launch clock starts
+ * 3 / 12: appliance created
+ * 6 / 12: detected that guest kernel started
+ * 9 / 12: detected that /init script is running
+ * 12 / 12: launch completed successfully
+ *
+ * Notes:
+ * (1) This is not a documented ABI and the behaviour may be changed
+ * or removed in future.
+ * (2) Messages are only sent if more than 5 seconds has elapsed
+ * since the launch clock started.
+ * (3) There is a gross hack in proto.c to make this work.
+ */
+void
+guestfs___launch_send_progress (guestfs_h *g, int perdozen)
+{
+ struct timeval tv;
+
+ gettimeofday (&tv, NULL);
+ if (guestfs___timeval_diff (&g->launch_t, &tv) >= 5000) {
+ guestfs_progress progress_message =
+ { .proc = 0, .serial = 0, .position = perdozen, .total = 12 };
+
+ guestfs___progress_message_callback (g, &progress_message);
+ }
+}
+
+/* Note that since this calls 'debug' it should only be called
+ * from the parent process.
+ */
+void
+guestfs___print_timestamped_message (guestfs_h *g, const char *fs, ...)
+{
+ va_list args;
+ char *msg;
+ int err;
+ struct timeval tv;
+
+ va_start (args, fs);
+ err = vasprintf (&msg, fs, args);
+ va_end (args);
+
+ if (err < 0) return;
+
+ gettimeofday (&tv, NULL);
+
+ debug (g, "[%05" PRIi64 "ms] %s",
+ guestfs___timeval_diff (&g->launch_t, &tv), msg);
+
+ free (msg);
+}
+
+/* Compute Y - X and return the result in milliseconds.
+ * Approximately the same as this code:
+ * http://www.mpp.mpg.de/~huber/util/timevaldiff.c
+ */
+int64_t
+guestfs___timeval_diff (const struct timeval *x, const struct timeval *y)
+{
+ int64_t msec;
+
+ msec = (y->tv_sec - x->tv_sec) * 1000;
+ msec += (y->tv_usec - x->tv_usec) / 1000;
+ return msec;
+}
+
/* Return the location of the tmpdir (eg. "/tmp") and allow users
* to override it at runtime using $TMPDIR.
* http://www.pathname.com/fhs/pub/fhs-2.3.html#TMPTEMPORARYFILES