* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/
+#include <sys/time.h>
#include <sys/types.h>
#include <stdarg.h>
#include <stdio.h>
#include <getopt.h>
+#include <libgen.h>
#include "qemu-common.h"
#include "block_int.h"
{
size_t *sizes = calloc(nr_iov, sizeof(size_t));
size_t count = 0;
- void *buf, *p;
+ void *buf = NULL;
+ void *p;
int i;
for (i = 0; i < nr_iov; i++) {
len = cvtnum(arg);
if (len < 0) {
printf("non-numeric length argument -- %s\n", arg);
- return NULL;
+ goto fail;
}
/* should be SIZE_T_MAX, but that doesn't exist */
if (len > UINT_MAX) {
printf("too large length argument -- %s\n", arg);
- return NULL;
+ goto fail;
}
if (len & 0x1ff) {
printf("length argument %lld is not sector aligned\n",
len);
- return NULL;
+ goto fail;
}
sizes[i] = len;
p += sizes[i];
}
+fail:
free(sizes);
return buf;
}
}
-static const cmdinfo_t read_cmd;
-
static void
read_help(void)
{
"\n");
}
+static int read_f(int argc, char **argv);
+
+static const cmdinfo_t read_cmd = {
+ .name = "read",
+ .altname = "r",
+ .cfunc = read_f,
+ .argmin = 2,
+ .argmax = -1,
+ .args = "[-abCpqv] [-P pattern [-s off] [-l len]] off len",
+ .oneline = "reads a number of bytes at a specified offset",
+ .help = read_help,
+};
+
static int
read_f(int argc, char **argv)
{
return 0;
}
-static const cmdinfo_t read_cmd = {
- .name = "read",
- .altname = "r",
- .cfunc = read_f,
- .argmin = 2,
- .argmax = -1,
- .args = "[-abCpqv] [-P pattern [-s off] [-l len]] off len",
- .oneline = "reads a number of bytes at a specified offset",
- .help = read_help,
-};
-
-static const cmdinfo_t readv_cmd;
-
static void
readv_help(void)
{
"\n");
}
+static int readv_f(int argc, char **argv);
+
+static const cmdinfo_t readv_cmd = {
+ .name = "readv",
+ .cfunc = readv_f,
+ .argmin = 2,
+ .argmax = -1,
+ .args = "[-Cqv] [-P pattern ] off len [len..]",
+ .oneline = "reads a number of bytes at a specified offset",
+ .help = readv_help,
+};
+
static int
readv_f(int argc, char **argv)
{
int c, cnt;
char *buf;
int64_t offset;
- int total;
+ /* Some compilers get confused and warn if this is not initialized. */
+ int total = 0;
int nr_iov;
QEMUIOVector qiov;
int pattern = 0;
return 0;
}
-static const cmdinfo_t readv_cmd = {
- .name = "readv",
- .cfunc = readv_f,
- .argmin = 2,
- .argmax = -1,
- .args = "[-Cqv] [-P pattern ] off len [len..]",
- .oneline = "reads a number of bytes at a specified offset",
- .help = readv_help,
-};
-
-static const cmdinfo_t write_cmd;
-
static void
write_help(void)
{
"\n");
}
+static int write_f(int argc, char **argv);
+
+static const cmdinfo_t write_cmd = {
+ .name = "write",
+ .altname = "w",
+ .cfunc = write_f,
+ .argmin = 2,
+ .argmax = -1,
+ .args = "[-abCpq] [-P pattern ] off len",
+ .oneline = "writes a number of bytes at a specified offset",
+ .help = write_help,
+};
+
static int
write_f(int argc, char **argv)
{
return 0;
}
-static const cmdinfo_t write_cmd = {
- .name = "write",
- .altname = "w",
- .cfunc = write_f,
- .argmin = 2,
- .argmax = -1,
- .args = "[-abCpq] [-P pattern ] off len",
- .oneline = "writes a number of bytes at a specified offset",
- .help = write_help,
-};
-
-static const cmdinfo_t writev_cmd;
-
static void
writev_help(void)
{
"\n");
}
+static int writev_f(int argc, char **argv);
+
+static const cmdinfo_t writev_cmd = {
+ .name = "writev",
+ .cfunc = writev_f,
+ .argmin = 2,
+ .argmax = -1,
+ .args = "[-Cq] [-P pattern ] off len [len..]",
+ .oneline = "writes a number of bytes at a specified offset",
+ .help = writev_help,
+};
+
static int
writev_f(int argc, char **argv)
{
int c, cnt;
char *buf;
int64_t offset;
- int total;
+ /* Some compilers get confused and warn if this is not initialized. */
+ int total = 0;
int nr_iov;
int pattern = 0xcd;
QEMUIOVector qiov;
return 0;
}
-static const cmdinfo_t writev_cmd = {
- .name = "writev",
- .cfunc = writev_f,
- .argmin = 2,
- .argmax = -1,
- .args = "[-Cq] [-P pattern ] off len [len..]",
- .oneline = "writes a number of bytes at a specified offset",
- .help = writev_help,
-};
-
struct aio_ctx {
QEMUIOVector qiov;
int64_t offset;
free(ctx);
}
-static const cmdinfo_t aio_read_cmd;
-
static void
aio_read_done(void *opaque, int ret)
{
"\n");
}
+static int aio_read_f(int argc, char **argv);
+
+static const cmdinfo_t aio_read_cmd = {
+ .name = "aio_read",
+ .cfunc = aio_read_f,
+ .argmin = 2,
+ .argmax = -1,
+ .args = "[-Cqv] [-P pattern ] off len [len..]",
+ .oneline = "asynchronously reads a number of bytes",
+ .help = aio_read_help,
+};
+
static int
aio_read_f(int argc, char **argv)
{
return 0;
}
-static const cmdinfo_t aio_read_cmd = {
- .name = "aio_read",
- .cfunc = aio_read_f,
- .argmin = 2,
- .argmax = -1,
- .args = "[-Cqv] [-P pattern ] off len [len..]",
- .oneline = "asynchronously reads a number of bytes",
- .help = aio_read_help,
-};
-
-static const cmdinfo_t aio_write_cmd;
-
static void
aio_write_help(void)
{
"\n");
}
+static int aio_write_f(int argc, char **argv);
+
+static const cmdinfo_t aio_write_cmd = {
+ .name = "aio_write",
+ .cfunc = aio_write_f,
+ .argmin = 2,
+ .argmax = -1,
+ .args = "[-Cq] [-P pattern ] off len [len..]",
+ .oneline = "asynchronously writes a number of bytes",
+ .help = aio_write_help,
+};
static int
aio_write_f(int argc, char **argv)
return 0;
}
-static const cmdinfo_t aio_write_cmd = {
- .name = "aio_write",
- .cfunc = aio_write_f,
- .argmin = 2,
- .argmax = -1,
- .args = "[-Cq] [-P pattern ] off len [len..]",
- .oneline = "asynchronously writes a number of bytes",
- .help = aio_write_help,
-};
-
static int
aio_flush_f(int argc, char **argv)
{
" 'open -Cn /tmp/data' - creates/opens data file read-write and uncached\n"
"\n"
" Opens a file for subsequent use by all of the other qemu-io commands.\n"
-" -C, -- create new file if it doesn't exist\n"
" -r, -- open file read-only\n"
" -s, -- use snapshot file\n"
" -n, -- disable host cache\n"
"\n");
}
-static const cmdinfo_t open_cmd;
+static int open_f(int argc, char **argv);
+
+static const cmdinfo_t open_cmd = {
+ .name = "open",
+ .altname = "o",
+ .cfunc = open_f,
+ .argmin = 1,
+ .argmax = -1,
+ .flags = CMD_NOFILE_OK,
+ .args = "[-Crsn] [path]",
+ .oneline = "open the file specified by path",
+ .help = open_help,
+};
static int
open_f(int argc, char **argv)
int growable = 0;
int c;
- while ((c = getopt(argc, argv, "snCrg")) != EOF) {
+ while ((c = getopt(argc, argv, "snrg")) != EOF) {
switch (c) {
case 's':
flags |= BDRV_O_SNAPSHOT;
case 'n':
flags |= BDRV_O_NOCACHE;
break;
- case 'C':
- flags |= BDRV_O_CREAT;
- break;
case 'r':
readonly = 1;
break;
}
}
- if (readonly)
- flags |= BDRV_O_RDONLY;
- else
- flags |= BDRV_O_RDWR;
+ if (!readonly) {
+ flags |= BDRV_O_RDWR;
+ }
if (optind != argc - 1)
return command_usage(&open_cmd);
return openfile(argv[optind], flags, growable);
}
-static const cmdinfo_t open_cmd = {
- .name = "open",
- .altname = "o",
- .cfunc = open_f,
- .argmin = 1,
- .argmax = -1,
- .flags = CMD_NOFILE_OK,
- .args = "[-Crsn] [path]",
- .oneline = "open the file specified by path",
- .help = open_help,
-};
-
static int
init_args_command(
int index)
static void usage(const char *name)
{
printf(
-"Usage: %s [-h] [-V] [-Crsnm] [-c cmd] ... [file]\n"
+"Usage: %s [-h] [-V] [-rsnm] [-c cmd] ... [file]\n"
"QEMU Disk exerciser\n"
"\n"
-" -C, --create create new file if it doesn't exist\n"
" -c, --cmd command to execute\n"
" -r, --read-only export read-only\n"
" -s, --snapshot use snapshot file\n"
{
int readonly = 0;
int growable = 0;
- const char *sopt = "hVc:Crsnmgk";
- struct option lopt[] = {
+ const char *sopt = "hVc:rsnmgk";
+ const struct option lopt[] = {
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'V' },
{ "offset", 1, NULL, 'o' },
{ "cmd", 1, NULL, 'c' },
- { "create", 0, NULL, 'C' },
{ "read-only", 0, NULL, 'r' },
{ "snapshot", 0, NULL, 's' },
{ "nocache", 0, NULL, 'n' },
case 'c':
add_user_command(optarg);
break;
- case 'C':
- flags |= BDRV_O_CREAT;
- break;
case 'r':
readonly = 1;
break;
add_check_command(init_check_command);
/* open the device */
- if (readonly)
- flags |= BDRV_O_RDONLY;
- else
- flags |= BDRV_O_RDWR;
+ if (!readonly) {
+ flags |= BDRV_O_RDWR;
+ }
if ((argc - optind) == 1)
openfile(argv[optind], flags, growable);