Fix sigsetjmp for w64
[qemu/ar7.git] / qemu-io-sim.c
blobd9a191c1f1a7a24d0926167fb0122c945e3d6b46
1 /*
2 * Copyright (c) 2010-2011 IBM
4 * Authors:
5 * Chunqiang Tang <ctang@us.ibm.com>
7 * This work is licensed under the terms of the GNU GPL, version 2.
8 * See the COPYING file in the top-level directory.
9 */
11 /*=============================================================================
12 * qemu-io-sim works with qemu-io to perform simulated testing. The 'sim'
13 * command allows the user to control the order of disk I/O and callback
14 * activities in order to test rare race conditions. Note that once 'sim
15 * enable' is done, it can only test aio_read and aio_write. See block/sim.c
16 * for the simulated block device driver.
17 *============================================================================*/
19 #include "block/blksim.h"
21 void fvd_init_prefetch (BlockDriverState * bs);
22 static void sim_start_prefetch(BlockDriverState *bs)
24 if (!bs->drv->format_name || !strncmp (bs->drv->format_name, "fvd", 3)) {
25 printf ("This image does not support prefetching.\n");
26 return;
28 fvd_init_prefetch (bs);
29 printf ("Prefetching started\n");
32 static void sim_help (void)
34 printf ("\n"
35 " sim enable\t\tenable simulation\n"
36 " sim list\t\tlist all simulation tasks\n"
37 " sim <#task> [#ret]\trun a simulation task, optionally uing #ret as the return value of a read/write operation\n"
38 " sim all [#ret]\t\trun all tasks, optionally using #ret as the return value of read/write tasks\n"
39 " sim prefetch\t\tstart prefetching\n");
42 static int sim_f(BlockDriverState *bs, int argc, char **argv)
44 int ret = 0;
46 if (argc == 3) {
47 ret = atoi (argv[2]);
49 else if (argc != 2) {
50 sim_help ();
51 return 0;
54 if (strcmp (argv[1], "enable") == 0) {
55 if (bs) {
56 printf ("Please close the image first. \"sim enable\" must be done before the\n"
57 "image is opened so that the image is opened with simulation support.\n");
59 else {
60 enable_block_sim(1/*print*/, 0 /*no random time*/);
61 printf ("Block device simulation is enabled.\n");
63 return 0;
66 if (!bs) {
67 fprintf(stderr, "no file open, try 'help open'\n");
68 return 0;
71 if (!bdrv_find_format("blksim")) {
72 printf ("\"sim enable\" must be done before invoking any other sim commands.\n");
73 return 0;
76 if (strcmp (argv[1], "list") == 0) {
77 sim_list_tasks ();
79 else if (strcmp (argv[1], "prefetch") == 0) {
80 sim_start_prefetch(bs);
82 else if (strcmp (argv[1], "all") == 0) {
83 sim_set_disk_io_return_code (ret);
84 int n = sim_all_tasks ();
85 sim_set_disk_io_return_code (0);
86 printf ("Executed %d tasks.\n", n);
88 else {
89 sim_set_disk_io_return_code (ret);
90 sim_task_by_uuid (atoll (argv[1]));
91 sim_set_disk_io_return_code (0);
94 return 0;
97 static const cmdinfo_t sim_cmd = {
98 .name = "sim",
99 .altname = "s",
100 .cfunc = sim_f,
101 .argmin = 1,
102 .argmax = 2,
103 .args = "",
104 .oneline = "use simulation to control the order of disk I/Os and callbacks",
105 .flags = CMD_NOFILE_OK,
106 .help = sim_help,