1 From 52002e4bb7572662d937de2c20b2110309095f29 Mon Sep 17 00:00:00 2001
2 From: Wolfgang Bumiller <w.bumiller@proxmox.com>
3 Date: Tue, 12 Apr 2016 13:49:44 +0200
4 Subject: [PATCH 45/55] vma: add format option to device mapping
6 The BDRV_O_PROTOCOL option breaks non-raw protocol devices,
7 so we instead now allow the format to be explicitly
8 specified from the outside.
10 In other words we now too deprecate the automatic guessing
11 of raw formats, just like qemu already does, and have to
12 silence the warnings by passing the drive mapping.
14 vma.c | 34 +++++++++++++++++++++++++++-------
15 1 file changed, 27 insertions(+), 7 deletions(-)
17 diff --git a/vma.c b/vma.c
18 index 1c4103f..46ae14b 100644
21 @@ -137,6 +137,7 @@ static int list_content(int argc, char **argv)
22 typedef struct RestoreMap {
29 @@ -224,13 +225,24 @@ static int extract_content(int argc, char **argv)
33 + char *format = NULL;
34 + if (strncmp(line, "format=", sizeof("format=")-1) == 0) {
35 + format = line + sizeof("format=")-1;
36 + char *colon = strchr(format, ':');
38 + g_error("read map failed - found only a format ('%s')", inbuf);
40 + format = g_strndup(format, colon - format);
46 if (line[0] == '0' && line[1] == ':') {
50 } else if (line[0] == '1' && line[1] == ':') {
55 g_error("read map failed - parse error ('%s')", inbuf);
56 @@ -246,6 +258,7 @@ static int extract_content(int argc, char **argv)
57 RestoreMap *map = g_new0(RestoreMap, 1);
58 map->devname = g_strdup(devname);
59 map->path = g_strdup(path);
60 + map->format = format;
61 map->write_zero = write_zero;
63 g_hash_table_insert(devmap, map->devname, map);
64 @@ -270,6 +283,7 @@ static int extract_content(int argc, char **argv)
68 + const char *format = NULL;
69 int flags = BDRV_O_RDWR|BDRV_O_CACHE_WB;
70 bool write_zero = true;
72 @@ -280,6 +294,7 @@ static int extract_content(int argc, char **argv)
73 g_error("no device name mapping for %s", di->devname);
76 + format = map->format;
77 write_zero = map->write_zero;
79 devfn = g_strdup_printf("%s/tmp-disk-%s.raw",
80 @@ -302,15 +317,20 @@ static int extract_content(int argc, char **argv)
81 BlockDriverState *bs = bdrv_new();
83 size_t devlen = strlen(devfn);
84 - bool protocol = path_has_protocol(devfn);
85 QDict *options = NULL;
86 - if (devlen > 4 && strcmp(devfn+devlen-4, ".raw") == 0 && !protocol) {
88 + /* explicit format from commandline */
89 + options = qdict_new();
90 + qdict_put(options, "driver", qstring_from_str(format));
91 + } else if ((devlen > 4 && strcmp(devfn+devlen-4, ".raw") == 0) ||
92 + strncmp(devfn, "/dev/", 5) == 0)
94 + /* This part is now deprecated for PVE as well (just as qemu
95 + * deprecated not specifying an explicit raw format, too.
97 /* explicit raw format */
98 options = qdict_new();
99 qdict_put(options, "driver", qstring_from_str("raw"));
100 - } else if (protocol) {
101 - /* tell bdrv_open to honor the protocol */
102 - flags |= BDRV_O_PROTOCOL;
105 if (errp || bdrv_open(&bs, devfn, NULL, options, flags, &errp)) {