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 "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");
28 fvd_init_prefetch (bs
);
29 printf ("Prefetching started\n");
32 static void sim_help (void)
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
)
54 if (strcmp (argv
[1], "enable") == 0) {
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");
60 enable_block_sim(1/*print*/, 0 /*no random time*/);
61 printf ("Block device simulation is enabled.\n");
67 fprintf(stderr
, "no file open, try 'help open'\n");
71 if (!bdrv_find_format("blksim")) {
72 printf ("\"sim enable\" must be done before invoking any other sim commands.\n");
76 if (strcmp (argv
[1], "list") == 0) {
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
);
89 sim_set_disk_io_return_code (ret
);
90 sim_task_by_uuid (atoll (argv
[1]));
91 sim_set_disk_io_return_code (0);
97 static const cmdinfo_t sim_cmd
= {
104 .oneline
= "use simulation to control the order of disk I/Os and callbacks",
105 .flags
= CMD_NOFILE_OK
,