]>
Commit | Line | Data |
---|---|---|
87ba737b | 1 | From a61194439318c95dfcb7df973ac961c12937dbcd Mon Sep 17 00:00:00 2001 |
62109fac WB |
2 | From: Wolfgang Bumiller <w.bumiller@proxmox.com> |
3 | Date: Tue, 12 Apr 2016 13:49:44 +0200 | |
adeb0c7a | 4 | Subject: [PATCH 34/48] vma: add format option to device mapping |
62109fac WB |
5 | |
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. | |
9 | ||
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. | |
13 | --- | |
14 | vma.c | 34 +++++++++++++++++++++++++++------- | |
15 | 1 file changed, 27 insertions(+), 7 deletions(-) | |
16 | ||
17 | diff --git a/vma.c b/vma.c | |
1a91ab45 | 18 | index 4903568..f71e5a5 100644 |
62109fac WB |
19 | --- a/vma.c |
20 | +++ b/vma.c | |
1a91ab45 | 21 | @@ -131,6 +131,7 @@ static int list_content(int argc, char **argv) |
62109fac WB |
22 | typedef struct RestoreMap { |
23 | char *devname; | |
24 | char *path; | |
25 | + char *format; | |
26 | bool write_zero; | |
27 | } RestoreMap; | |
28 | ||
1a91ab45 | 29 | @@ -218,13 +219,24 @@ static int extract_content(int argc, char **argv) |
62109fac WB |
30 | } |
31 | } | |
32 | ||
33 | + char *format = NULL; | |
34 | + if (strncmp(line, "format=", sizeof("format=")-1) == 0) { | |
35 | + format = line + sizeof("format=")-1; | |
36 | + char *colon = strchr(format, ':'); | |
37 | + if (!colon) { | |
38 | + g_error("read map failed - found only a format ('%s')", inbuf); | |
39 | + } | |
40 | + format = g_strndup(format, colon - format); | |
41 | + line = colon+1; | |
42 | + } | |
43 | + | |
44 | const char *path; | |
45 | bool write_zero; | |
46 | if (line[0] == '0' && line[1] == ':') { | |
47 | - path = inbuf + 2; | |
48 | + path = line + 2; | |
49 | write_zero = false; | |
50 | } else if (line[0] == '1' && line[1] == ':') { | |
51 | - path = inbuf + 2; | |
52 | + path = line + 2; | |
53 | write_zero = true; | |
54 | } else { | |
55 | g_error("read map failed - parse error ('%s')", inbuf); | |
1a91ab45 | 56 | @@ -240,6 +252,7 @@ static int extract_content(int argc, char **argv) |
62109fac WB |
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; | |
62 | ||
63 | g_hash_table_insert(devmap, map->devname, map); | |
1a91ab45 | 64 | @@ -264,6 +277,7 @@ static int extract_content(int argc, char **argv) |
62109fac WB |
65 | g_free(statefn); |
66 | } else if (di) { | |
67 | char *devfn = NULL; | |
68 | + const char *format = NULL; | |
68a30562 | 69 | int flags = BDRV_O_RDWR; |
62109fac WB |
70 | bool write_zero = true; |
71 | ||
1a91ab45 | 72 | @@ -274,6 +288,7 @@ static int extract_content(int argc, char **argv) |
62109fac WB |
73 | g_error("no device name mapping for %s", di->devname); |
74 | } | |
75 | devfn = map->path; | |
76 | + format = map->format; | |
77 | write_zero = map->write_zero; | |
78 | } else { | |
79 | devfn = g_strdup_printf("%s/tmp-disk-%s.raw", | |
1a91ab45 | 80 | @@ -296,15 +311,20 @@ static int extract_content(int argc, char **argv) |
62109fac WB |
81 | BlockDriverState *bs = bdrv_new(); |
82 | ||
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) { | |
87 | + if (format) { | |
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) | |
93 | + { | |
94 | + /* This part is now deprecated for PVE as well (just as qemu | |
95 | + * deprecated not specifying an explicit raw format, too. | |
96 | + */ | |
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; | |
103 | } | |
104 | ||
105 | if (errp || bdrv_open(&bs, devfn, NULL, options, flags, &errp)) { | |
106 | -- | |
107 | 2.1.4 | |
108 |