cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
0a122b
From 714dfa20586988e535dc7290be0d5d8d6b0853f3 Mon Sep 17 00:00:00 2001
0a122b
From: Kevin Wolf <kwolf@redhat.com>
0a122b
Date: Wed, 15 Jan 2014 15:39:10 +0100
0a122b
Subject: [PATCH 33/37] qemu-io: New command 'sleep'
0a122b
0a122b
Message-id: <1392117622-28812-34-git-send-email-kwolf@redhat.com>
0a122b
Patchwork-id: 57198
0a122b
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 33/37] qemu-io: New command 'sleep'
0a122b
Bugzilla: 748906
0a122b
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
0a122b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
RH-Acked-by: Max Reitz <mreitz@redhat.com>
0a122b
0a122b
There is no easy way to check that a request correctly waits for a
0a122b
different request. With a sleep command we can at least approximate it.
0a122b
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
(cherry picked from commit cd33d02a1012e58ee0d3c8259159e8c60cfa0a4d)
0a122b
0a122b
Conflicts:
0a122b
	qemu-io-cmds.c
0a122b
0a122b
Conflicts because RHEL 7 doesn't have...
0a122b
- ...the qemu-io refactoring for supporting qemu-io from the monitor
0a122b
- ...the new timer API
0a122b
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
---
0a122b
 qemu-io.c | 42 ++++++++++++++++++++++++++++++++++++++++++
0a122b
 1 file changed, 42 insertions(+)
0a122b
---
0a122b
 qemu-io.c |   42 ++++++++++++++++++++++++++++++++++++++++++
0a122b
 1 files changed, 42 insertions(+), 0 deletions(-)
0a122b
0a122b
diff --git a/qemu-io.c b/qemu-io.c
0a122b
index 7e258a5..0959178 100644
0a122b
--- a/qemu-io.c
0a122b
+++ b/qemu-io.c
0a122b
@@ -22,6 +22,7 @@
0a122b
 #include "block/qapi.h"
0a122b
 #include "cmd.h"
0a122b
 #include "trace/control.h"
0a122b
+#include "qemu/timer.h"
0a122b
 
0a122b
 #define VERSION	"0.0.1"
0a122b
 
0a122b
@@ -1773,6 +1774,46 @@ static const cmdinfo_t close_cmd = {
0a122b
     .oneline    = "close the current open file",
0a122b
 };
0a122b
 
0a122b
+static void sleep_cb(void *opaque)
0a122b
+{
0a122b
+    bool *expired = opaque;
0a122b
+    *expired = true;
0a122b
+}
0a122b
+
0a122b
+static int sleep_f(int argc, char **argv)
0a122b
+{
0a122b
+    char *endptr;
0a122b
+    long ms;
0a122b
+    struct QEMUTimer *timer;
0a122b
+    bool expired = false;
0a122b
+
0a122b
+    ms = strtol(argv[1], &endptr, 0);
0a122b
+    if (ms < 0 || *endptr != '\0') {
0a122b
+        printf("%s is not a valid number\n", argv[1]);
0a122b
+        return 0;
0a122b
+    }
0a122b
+
0a122b
+    timer = qemu_new_timer_ns(host_clock, sleep_cb, &expired);
0a122b
+    qemu_mod_timer(timer, qemu_get_clock_ns(host_clock) + SCALE_MS * ms);
0a122b
+
0a122b
+    while (!expired) {
0a122b
+        main_loop_wait(false);
0a122b
+    }
0a122b
+
0a122b
+    qemu_free_timer(timer);
0a122b
+
0a122b
+    return 0;
0a122b
+}
0a122b
+
0a122b
+static const cmdinfo_t sleep_cmd = {
0a122b
+       .name           = "sleep",
0a122b
+       .argmin         = 1,
0a122b
+       .argmax         = 1,
0a122b
+       .cfunc          = sleep_f,
0a122b
+       .flags          = CMD_NOFILE_OK,
0a122b
+       .oneline        = "waits for the given value in milliseconds",
0a122b
+};
0a122b
+
0a122b
 static int openfile(char *name, int flags, int growable, QDict *opts)
0a122b
 {
0a122b
     Error *local_err = NULL;
0a122b
@@ -2052,6 +2093,7 @@ int main(int argc, char **argv)
0a122b
     add_command(&resume_cmd);
0a122b
     add_command(&wait_break_cmd);
0a122b
     add_command(&abort_cmd);
0a122b
+    add_command(&sleep_cmd);
0a122b
 
0a122b
     add_args_command(init_args_command);
0a122b
     add_check_command(init_check_command);
0a122b
-- 
0a122b
1.7.1
0a122b