From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, jcody@redhat.com, armbru@redhat.com,
mreitz@redhat.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH v3 1/9] qemu-io: Allow explicitly specifying format
Date: Thu, 20 Nov 2014 16:27:06 +0100 [thread overview]
Message-ID: <1416497234-29880-2-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1416497234-29880-1-git-send-email-kwolf@redhat.com>
This adds a -f option to qemu-io which allows to explicitly specify the
block driver to use for the given image.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
---
qemu-io.c | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git a/qemu-io.c b/qemu-io.c
index 60f84dd..91a445a 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -51,7 +51,8 @@ static const cmdinfo_t close_cmd = {
.oneline = "close the current open file",
};
-static int openfile(char *name, int flags, int growable, QDict *opts)
+static int openfile(char *name, BlockDriver *drv, int flags, int growable,
+ QDict *opts)
{
Error *local_err = NULL;
@@ -68,7 +69,7 @@ static int openfile(char *name, int flags, int growable, QDict *opts)
flags |= BDRV_O_PROTOCOL;
}
- if (bdrv_open(&qemuio_bs, name, NULL, opts, flags, NULL, &local_err) < 0) {
+ if (bdrv_open(&qemuio_bs, name, NULL, opts, flags, drv, &local_err) < 0) {
fprintf(stderr, "%s: can't open%s%s: %s\n", progname,
name ? " device " : "", name ?: "",
error_get_pretty(local_err));
@@ -169,9 +170,9 @@ static int open_f(BlockDriverState *bs, int argc, char **argv)
qemu_opts_reset(&empty_opts);
if (optind == argc - 1) {
- return openfile(argv[optind], flags, growable, opts);
+ return openfile(argv[optind], NULL, flags, growable, opts);
} else if (optind == argc) {
- return openfile(NULL, flags, growable, opts);
+ return openfile(NULL, NULL, flags, growable, opts);
} else {
QDECREF(opts);
return qemuio_command_usage(&open_cmd);
@@ -196,11 +197,12 @@ static const cmdinfo_t quit_cmd = {
static void usage(const char *name)
{
printf(
-"Usage: %s [-h] [-V] [-rsnm] [-c STRING] ... [file]\n"
+"Usage: %s [-h] [-V] [-rsnm] [-f FMT] [-c STRING] ... [file]\n"
"QEMU Disk exerciser\n"
"\n"
" -c, --cmd STRING execute command with its arguments\n"
" from the given string\n"
+" -f, --format FMT specifies the block driver to use\n"
" -r, --read-only export read-only\n"
" -s, --snapshot use snapshot file\n"
" -n, --nocache disable host cache\n"
@@ -364,12 +366,13 @@ int main(int argc, char **argv)
{
int readonly = 0;
int growable = 0;
- const char *sopt = "hVc:d:rsnmgkt:T:";
+ const char *sopt = "hVc:d:f:rsnmgkt:T:";
const struct option lopt[] = {
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'V' },
{ "offset", 1, NULL, 'o' },
{ "cmd", 1, NULL, 'c' },
+ { "format", 1, NULL, 'f' },
{ "read-only", 0, NULL, 'r' },
{ "snapshot", 0, NULL, 's' },
{ "nocache", 0, NULL, 'n' },
@@ -384,6 +387,7 @@ int main(int argc, char **argv)
int c;
int opt_index = 0;
int flags = BDRV_O_UNMAP;
+ BlockDriver *drv = NULL;
Error *local_error = NULL;
#ifdef CONFIG_POSIX
@@ -393,6 +397,8 @@ int main(int argc, char **argv)
progname = basename(argv[0]);
qemu_init_exec_dir(argv[0]);
+ bdrv_init();
+
while ((c = getopt_long(argc, argv, sopt, lopt, &opt_index)) != -1) {
switch (c) {
case 's':
@@ -407,6 +413,13 @@ int main(int argc, char **argv)
exit(1);
}
break;
+ case 'f':
+ drv = bdrv_find_format(optarg);
+ if (!drv) {
+ error_report("Invalid format '%s'", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
case 'c':
add_user_command(optarg);
break;
@@ -455,7 +468,6 @@ int main(int argc, char **argv)
error_free(local_error);
exit(1);
}
- bdrv_init();
/* initialize commands */
qemuio_add_command(&quit_cmd);
@@ -477,7 +489,7 @@ int main(int argc, char **argv)
}
if ((argc - optind) == 1) {
- openfile(argv[optind], flags, growable, NULL);
+ openfile(argv[optind], drv, flags, growable, NULL);
}
command_loop();
--
1.8.3.1
next prev parent reply other threads:[~2014-11-20 15:27 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-20 15:27 [Qemu-devel] [PATCH v3 0/9] raw: Prohibit dangerous writes for probed images Kevin Wolf
2014-11-20 15:27 ` Kevin Wolf [this message]
2014-11-20 15:27 ` [Qemu-devel] [PATCH v3 2/9] qemu-iotests: Use qemu-io -f $IMGFMT Kevin Wolf
2014-11-20 15:27 ` [Qemu-devel] [PATCH v3 3/9] qemu-iotests: Add qemu-io format option in Python tests Kevin Wolf
2014-11-20 15:27 ` [Qemu-devel] [PATCH v3 4/9] qtests: Specify image format explicitly Kevin Wolf
2014-11-20 15:27 ` [Qemu-devel] [PATCH v3 5/9] block: Factor bdrv_probe_all() out of find_image_format() Kevin Wolf
2014-11-20 15:27 ` [Qemu-devel] [PATCH v3 6/9] block: Read only one sector for format probing Kevin Wolf
2014-11-20 15:27 ` [Qemu-devel] [PATCH v3 7/9] raw: Prohibit dangerous writes for probed images Kevin Wolf
2014-11-20 20:08 ` Dr. David Alan Gilbert
2014-11-21 10:15 ` Kevin Wolf
2014-11-21 10:26 ` Dr. David Alan Gilbert
2014-11-25 16:51 ` Stefan Hajnoczi
2014-11-20 15:27 ` [Qemu-devel] [PATCH v3 8/9] qemu-iotests: Fix stderr handling in common.qemu Kevin Wolf
2014-11-20 15:27 ` [Qemu-devel] [PATCH v3 9/9] qemu-iotests: Test writing non-raw image headers to raw image Kevin Wolf
2014-11-20 16:18 ` Max Reitz
2014-11-20 16:29 ` Kevin Wolf
2014-11-26 16:23 ` [Qemu-devel] [PATCH v3 0/9] raw: Prohibit dangerous writes for probed images Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1416497234-29880-2-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=armbru@redhat.com \
--cc=jcody@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).