[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 91/93] qemu-io: New command 'sleep'
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 91/93] qemu-io: New command 'sleep' |
Date: |
Fri, 24 Jan 2014 18:22:14 +0100 |
There is no easy way to check that a request correctly waits for a
different request. With a sleep command we can at least approximate it.
Signed-off-by: Kevin Wolf <address@hidden>
---
qemu-io-cmds.c | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 6dfb4a5..f1de24c 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -12,6 +12,7 @@
#include "block/block_int.h"
#include "block/qapi.h"
#include "qemu/main-loop.h"
+#include "qemu/timer.h"
#define CMD_NOFILE_OK 0x01
@@ -2053,6 +2054,46 @@ static const cmdinfo_t abort_cmd = {
.oneline = "simulate a program crash using abort(3)",
};
+static void sleep_cb(void *opaque)
+{
+ bool *expired = opaque;
+ *expired = true;
+}
+
+static int sleep_f(BlockDriverState *bs, int argc, char **argv)
+{
+ char *endptr;
+ long ms;
+ struct QEMUTimer *timer;
+ bool expired = false;
+
+ ms = strtol(argv[1], &endptr, 0);
+ if (ms < 0 || *endptr != '\0') {
+ printf("%s is not a valid number\n", argv[1]);
+ return 0;
+ }
+
+ timer = timer_new_ns(QEMU_CLOCK_HOST, sleep_cb, &expired);
+ timer_mod(timer, qemu_clock_get_ns(QEMU_CLOCK_HOST) + SCALE_MS * ms);
+
+ while (!expired) {
+ main_loop_wait(false);
+ }
+
+ timer_free(timer);
+
+ return 0;
+}
+
+static const cmdinfo_t sleep_cmd = {
+ .name = "sleep",
+ .argmin = 1,
+ .argmax = 1,
+ .cfunc = sleep_f,
+ .flags = CMD_NOFILE_OK,
+ .oneline = "waits for the given value in milliseconds",
+};
+
static void help_oneline(const char *cmd, const cmdinfo_t *ct)
{
if (cmd) {
@@ -2166,4 +2207,5 @@ static void __attribute((constructor))
init_qemuio_commands(void)
qemuio_add_command(&resume_cmd);
qemuio_add_command(&wait_break_cmd);
qemuio_add_command(&abort_cmd);
+ qemuio_add_command(&sleep_cmd);
}
--
1.8.1.4
- [Qemu-devel] [PULL 86/93] block: Change coroutine wrapper to byte granularity, (continued)
- [Qemu-devel] [PULL 86/93] block: Change coroutine wrapper to byte granularity, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 87/93] block: Make bdrv_pread() a bdrv_prwv_co() wrapper, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 88/93] block: Make bdrv_pwrite() a bdrv_prwv_co() wrapper, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 89/93] iscsi: Set bs->request_alignment, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 90/93] blkdebug: Make required alignment configurable, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 92/93] qemu-iotests: Test pwritev RMW logic, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 59/93] qmp: Allow to take external snapshots on bs graphs node., Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 93/93] block: Switch bdrv_io_limits_intercept() to byte granularity, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 73/93] block: Introduce bdrv_aligned_preadv(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 74/93] block: Introduce bdrv_co_do_preadv(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 91/93] qemu-io: New command 'sleep',
Kevin Wolf <=
- [Qemu-devel] [PULL 60/93] block/curl: Implement the libcurl timer callback interface, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 55/93] qmp: Add QMP query-named-block-nodes to list the named BlockDriverState nodes., Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 57/93] block: Create authorizations mechanism for external snapshot and resize., Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 75/93] block: Introduce bdrv_aligned_pwritev(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 58/93] qmp: Allow block_resize to manipulate bs graph nodes., Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 56/93] qmp: Allow to change password on named block driver states., Kevin Wolf, 2014/01/24