2 * Copyright (c) 2010-2011 IBM
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.
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 "qemu/osdep.h"
20 #include "block/blksim.h"
22 void fvd_init_prefetch (BlockDriverState
* bs
);
23 static void sim_start_prefetch(BlockDriverState
*bs
)
25 if (!bs
->drv
->format_name
|| !strncmp (bs
->drv
->format_name
, "fvd", 3)) {
26 printf ("This image does not support prefetching.\n");
29 fvd_init_prefetch (bs
);
30 printf ("Prefetching started\n");
33 static void sim_help (void)
36 " sim enable\t\tenable simulation\n"
37 " sim list\t\tlist all simulation tasks\n"
38 " sim <#task> [#ret]\trun a simulation task, optionally uing #ret as the return value of a read/write operation\n"
39 " sim all [#ret]\t\trun all tasks, optionally using #ret as the return value of read/write tasks\n"
40 " sim prefetch\t\tstart prefetching\n");
43 static int sim_f(BlockDriverState
*bs
, int argc
, char **argv
)
55 if (strcmp (argv
[1], "enable") == 0) {
57 printf ("Please close the image first. \"sim enable\" must be done before the\n"
58 "image is opened so that the image is opened with simulation support.\n");
61 enable_block_sim(1/*print*/, 0 /*no random time*/);
62 printf ("Block device simulation is enabled.\n");
68 fprintf(stderr
, "no file open, try 'help open'\n");
72 if (!bdrv_find_format("blksim")) {
73 printf ("\"sim enable\" must be done before invoking any other sim commands.\n");
77 if (strcmp (argv
[1], "list") == 0) {
80 else if (strcmp (argv
[1], "prefetch") == 0) {
81 sim_start_prefetch(bs
);
83 else if (strcmp (argv
[1], "all") == 0) {
84 sim_set_disk_io_return_code (ret
);
85 int n
= sim_all_tasks ();
86 sim_set_disk_io_return_code (0);
87 printf ("Executed %d tasks.\n", n
);
90 sim_set_disk_io_return_code (ret
);
91 sim_task_by_uuid (atoll (argv
[1]));
92 sim_set_disk_io_return_code (0);
98 static const cmdinfo_t sim_cmd
= {
105 .oneline
= "use simulation to control the order of disk I/Os and callbacks",
106 .flags
= CMD_NOFILE_OK
,