diff options
| author | Anthony Liguori <aliguori@amazon.com> | 2014-01-24 15:43:30 -0800 |
|---|---|---|
| committer | Anthony Liguori <aliguori@amazon.com> | 2014-01-24 15:43:30 -0800 |
| commit | 0d688cf7d8d71bce2aab83173552a784e96b6729 (patch) | |
| tree | 543f7cc92a36e0157cf35e474ee4eb74b8f6156e /qemu-io-cmds.c | |
| parent | 732c66ce641c69702a7e7fdb73b68f0c1b583ab5 (diff) | |
| parent | d5103588aa39157c8eea3bb5fb6780bbd8be21b7 (diff) | |
| download | focaccia-qemu-0d688cf7d8d71bce2aab83173552a784e96b6729.tar.gz focaccia-qemu-0d688cf7d8d71bce2aab83173552a784e96b6729.zip | |
Merge remote-tracking branch 'kwolf/tags/for-anthony' into staging
Block patches # gpg: Signature made Fri 24 Jan 2014 08:40:53 AM PST using RSA key ID C88F2FD6 # gpg: Can't check signature: public key not found * kwolf/tags/for-anthony: (93 commits) block: Switch bdrv_io_limits_intercept() to byte granularity qemu-iotests: Test pwritev RMW logic qemu-io: New command 'sleep' blkdebug: Make required alignment configurable iscsi: Set bs->request_alignment block: Make bdrv_pwrite() a bdrv_prwv_co() wrapper block: Make bdrv_pread() a bdrv_prwv_co() wrapper block: Change coroutine wrapper to byte granularity block: Assert serialisation assumptions in pwritev block: Align requests in bdrv_co_do_pwritev() block: Allow wait_serialising_requests() at any point block: Make overlap range for serialisation dynamic block: Generalise and optimise COR serialisation block: Make zero-after-EOF work with larger alignment block: Allow waiting for overlapping requests between begin/end block: Switch BdrvTrackedRequest to byte granularity block: Introduce bdrv_co_do_pwritev() block: write: Handle COR dependency after I/O throttling block: Introduce bdrv_aligned_pwritev() block: Introduce bdrv_co_do_preadv() ... Message-id: 1390584136-24703-1-git-send-email-kwolf@redhat.com Signed-off-by: Anthony Liguori <aliguori@amazon.com>
Diffstat (limited to 'qemu-io-cmds.c')
| -rw-r--r-- | qemu-io-cmds.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 85e4982bd8..f1de24c91c 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 @@ -94,6 +95,21 @@ static const cmdinfo_t *find_command(const char *cmd) return NULL; } +/* Invoke fn() for commands with a matching prefix */ +void qemuio_complete_command(const char *input, + void (*fn)(const char *cmd, void *opaque), + void *opaque) +{ + cmdinfo_t *ct; + size_t input_len = strlen(input); + + for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++) { + if (strncmp(input, ct->name, input_len) == 0) { + fn(ct->name, opaque); + } + } +} + static char **breakline(char *input, int *count) { int c = 0; @@ -2038,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) { @@ -2151,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); } |