|
|
9ae3a8 |
From aa82f406b4d4ff21041ef39547d1b166e9c6ee38 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
Date: Thu, 23 Oct 2014 10:10:10 +0200
|
|
|
9ae3a8 |
Subject: [PATCH 07/19] qemu-img: Avoid duplicate block device IDs
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Message-id: <1414059011-15516-8-git-send-email-kwolf@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 61842
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.1 qemu-kvm PATCH v2 7/8] qemu-img: Avoid duplicate block device IDs
|
|
|
9ae3a8 |
Bugzilla: 1088176
|
|
|
9ae3a8 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
qemu-img used to use "image" as ID for all block devices. This means
|
|
|
9ae3a8 |
that e.g. img_convert() ended up with potentially multiple source images
|
|
|
9ae3a8 |
and one target image, all with the same ID. The next patch will catch
|
|
|
9ae3a8 |
this and fail to open the block device.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
This patch makes sure that qemu-img uses meaningful unique IDs for the
|
|
|
9ae3a8 |
block devices it uses.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit 9ffe333276de8ef463896303fb951f03fd4ffcb4)
|
|
|
9ae3a8 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
qemu-img.c | 38 ++++++++++++++++++++++----------------
|
|
|
9ae3a8 |
1 file changed, 22 insertions(+), 16 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/qemu-img.c b/qemu-img.c
|
|
|
9ae3a8 |
index 5c2f36a..fe0ac65 100644
|
|
|
9ae3a8 |
--- a/qemu-img.c
|
|
|
9ae3a8 |
+++ b/qemu-img.c
|
|
|
9ae3a8 |
@@ -262,7 +262,8 @@ static int print_block_option_help(const char *filename, const char *fmt)
|
|
|
9ae3a8 |
return 0;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-static BlockDriverState *bdrv_new_open(const char *filename,
|
|
|
9ae3a8 |
+static BlockDriverState *bdrv_new_open(const char *id,
|
|
|
9ae3a8 |
+ const char *filename,
|
|
|
9ae3a8 |
const char *fmt,
|
|
|
9ae3a8 |
int flags,
|
|
|
9ae3a8 |
bool require_io,
|
|
|
9ae3a8 |
@@ -274,7 +275,7 @@ static BlockDriverState *bdrv_new_open(const char *filename,
|
|
|
9ae3a8 |
Error *local_err = NULL;
|
|
|
9ae3a8 |
int ret;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- bs = bdrv_new("image", &error_abort);
|
|
|
9ae3a8 |
+ bs = bdrv_new(id, &error_abort);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (fmt) {
|
|
|
9ae3a8 |
drv = bdrv_find_format(fmt);
|
|
|
9ae3a8 |
@@ -616,7 +617,7 @@ static int img_check(int argc, char **argv)
|
|
|
9ae3a8 |
return 1;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- bs = bdrv_new_open(filename, fmt, flags, true, quiet);
|
|
|
9ae3a8 |
+ bs = bdrv_new_open("image", filename, fmt, flags, true, quiet);
|
|
|
9ae3a8 |
if (!bs) {
|
|
|
9ae3a8 |
return 1;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -725,7 +726,7 @@ static int img_commit(int argc, char **argv)
|
|
|
9ae3a8 |
return -1;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- bs = bdrv_new_open(filename, fmt, flags, true, quiet);
|
|
|
9ae3a8 |
+ bs = bdrv_new_open("image", filename, fmt, flags, true, quiet);
|
|
|
9ae3a8 |
if (!bs) {
|
|
|
9ae3a8 |
return 1;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -968,14 +969,14 @@ static int img_compare(int argc, char **argv)
|
|
|
9ae3a8 |
/* Initialize before goto out */
|
|
|
9ae3a8 |
qemu_progress_init(progress, 2.0);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- bs1 = bdrv_new_open(filename1, fmt1, BDRV_O_FLAGS, true, quiet);
|
|
|
9ae3a8 |
+ bs1 = bdrv_new_open("image 1", filename1, fmt1, BDRV_O_FLAGS, true, quiet);
|
|
|
9ae3a8 |
if (!bs1) {
|
|
|
9ae3a8 |
error_report("Can't open file %s", filename1);
|
|
|
9ae3a8 |
ret = 2;
|
|
|
9ae3a8 |
goto out3;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- bs2 = bdrv_new_open(filename2, fmt2, BDRV_O_FLAGS, true, quiet);
|
|
|
9ae3a8 |
+ bs2 = bdrv_new_open("image 2", filename2, fmt2, BDRV_O_FLAGS, true, quiet);
|
|
|
9ae3a8 |
if (!bs2) {
|
|
|
9ae3a8 |
error_report("Can't open file %s", filename2);
|
|
|
9ae3a8 |
ret = 2;
|
|
|
9ae3a8 |
@@ -1280,8 +1281,11 @@ static int img_convert(int argc, char **argv)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
total_sectors = 0;
|
|
|
9ae3a8 |
for (bs_i = 0; bs_i < bs_n; bs_i++) {
|
|
|
9ae3a8 |
- bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt, BDRV_O_FLAGS, true,
|
|
|
9ae3a8 |
- quiet);
|
|
|
9ae3a8 |
+ char *id = bs_n > 1 ? g_strdup_printf("source %d", bs_i)
|
|
|
9ae3a8 |
+ : g_strdup("source");
|
|
|
9ae3a8 |
+ bs[bs_i] = bdrv_new_open(id, argv[optind + bs_i], fmt, BDRV_O_FLAGS,
|
|
|
9ae3a8 |
+ true, quiet);
|
|
|
9ae3a8 |
+ g_free(id);
|
|
|
9ae3a8 |
if (!bs[bs_i]) {
|
|
|
9ae3a8 |
error_report("Could not open '%s'", argv[optind + bs_i]);
|
|
|
9ae3a8 |
ret = -1;
|
|
|
9ae3a8 |
@@ -1395,7 +1399,7 @@ static int img_convert(int argc, char **argv)
|
|
|
9ae3a8 |
return -1;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- out_bs = bdrv_new_open(out_filename, out_fmt, flags, true, quiet);
|
|
|
9ae3a8 |
+ out_bs = bdrv_new_open("target", out_filename, out_fmt, flags, true, quiet);
|
|
|
9ae3a8 |
if (!out_bs) {
|
|
|
9ae3a8 |
ret = -1;
|
|
|
9ae3a8 |
goto out;
|
|
|
9ae3a8 |
@@ -1758,8 +1762,8 @@ static ImageInfoList *collect_image_info_list(const char *filename,
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
g_hash_table_insert(filenames, (gpointer)filename, NULL);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_NO_BACKING,
|
|
|
9ae3a8 |
- false, false);
|
|
|
9ae3a8 |
+ bs = bdrv_new_open("image", filename, fmt,
|
|
|
9ae3a8 |
+ BDRV_O_FLAGS | BDRV_O_NO_BACKING, false, false);
|
|
|
9ae3a8 |
if (!bs) {
|
|
|
9ae3a8 |
goto err;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -2018,7 +2022,7 @@ static int img_map(int argc, char **argv)
|
|
|
9ae3a8 |
return 1;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS, true, false);
|
|
|
9ae3a8 |
+ bs = bdrv_new_open("image", filename, fmt, BDRV_O_FLAGS, true, false);
|
|
|
9ae3a8 |
if (!bs) {
|
|
|
9ae3a8 |
return 1;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -2137,7 +2141,7 @@ static int img_snapshot(int argc, char **argv)
|
|
|
9ae3a8 |
filename = argv[optind++];
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* Open the image */
|
|
|
9ae3a8 |
- bs = bdrv_new_open(filename, NULL, bdrv_oflags, true, quiet);
|
|
|
9ae3a8 |
+ bs = bdrv_new_open("image", filename, NULL, bdrv_oflags, true, quiet);
|
|
|
9ae3a8 |
if (!bs) {
|
|
|
9ae3a8 |
return 1;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -2264,7 +2268,7 @@ static int img_rebase(int argc, char **argv)
|
|
|
9ae3a8 |
* Ignore the old backing file for unsafe rebase in case we want to correct
|
|
|
9ae3a8 |
* the reference to a renamed or moved backing file.
|
|
|
9ae3a8 |
*/
|
|
|
9ae3a8 |
- bs = bdrv_new_open(filename, fmt, flags, true, quiet);
|
|
|
9ae3a8 |
+ bs = bdrv_new_open("image", filename, fmt, flags, true, quiet);
|
|
|
9ae3a8 |
if (!bs) {
|
|
|
9ae3a8 |
return 1;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -2561,7 +2565,8 @@ static int img_resize(int argc, char **argv)
|
|
|
9ae3a8 |
n = qemu_opt_get_size(param, BLOCK_OPT_SIZE, 0);
|
|
|
9ae3a8 |
qemu_opts_del(param);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR, true, quiet);
|
|
|
9ae3a8 |
+ bs = bdrv_new_open("image", filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR,
|
|
|
9ae3a8 |
+ true, quiet);
|
|
|
9ae3a8 |
if (!bs) {
|
|
|
9ae3a8 |
ret = -1;
|
|
|
9ae3a8 |
goto out;
|
|
|
9ae3a8 |
@@ -2662,7 +2667,8 @@ static int img_amend(int argc, char **argv)
|
|
|
9ae3a8 |
help();
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR, true, quiet);
|
|
|
9ae3a8 |
+ bs = bdrv_new_open("image", filename, fmt,
|
|
|
9ae3a8 |
+ BDRV_O_FLAGS | BDRV_O_RDWR, true, quiet);
|
|
|
9ae3a8 |
if (!bs) {
|
|
|
9ae3a8 |
error_report("Could not open image '%s'", filename);
|
|
|
9ae3a8 |
ret = -1;
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.8.3.1
|
|
|
9ae3a8 |
|