]> git.proxmox.com Git - pve-qemu.git/blob - debian/patches/pve/0022-PVE-vma-add-throttling-options-to-drive-mapping-fifo.patch
update patches for v4.0.0
[pve-qemu.git] / debian / patches / pve / 0022-PVE-vma-add-throttling-options-to-drive-mapping-fifo.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Wolfgang Bumiller <w.bumiller@proxmox.com>
3 Date: Thu, 15 Feb 2018 11:07:56 +0100
4 Subject: [PATCH] PVE: vma: add throttling options to drive mapping fifo
5 protocol
6
7 We now need to call initialize the qom module as well.
8
9 Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
10 Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
11 ---
12 vma.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++--------
13 1 file changed, 76 insertions(+), 12 deletions(-)
14
15 diff --git a/vma.c b/vma.c
16 index 1b59fd1555..f9f5c308fe 100644
17 --- a/vma.c
18 +++ b/vma.c
19 @@ -18,7 +18,8 @@
20 #include "qemu-common.h"
21 #include "qemu/error-report.h"
22 #include "qemu/main-loop.h"
23 -#include "qapi/qmp/qstring.h"
24 +#include "qemu/cutils.h"
25 +#include "qapi/qmp/qdict.h"
26 #include "sysemu/block-backend.h"
27
28 static void help(void)
29 @@ -132,9 +133,39 @@ typedef struct RestoreMap {
30 char *devname;
31 char *path;
32 char *format;
33 + uint64_t throttling_bps;
34 + char *throttling_group;
35 bool write_zero;
36 } RestoreMap;
37
38 +static bool try_parse_option(char **line, const char *optname, char **out, const char *inbuf) {
39 + size_t optlen = strlen(optname);
40 + if (strncmp(*line, optname, optlen) != 0 || (*line)[optlen] != '=') {
41 + return false;
42 + }
43 + if (*out) {
44 + g_error("read map failed - duplicate value for option '%s'", optname);
45 + }
46 + char *value = (*line) + optlen + 1; /* including a '=' */
47 + char *colon = strchr(value, ':');
48 + if (!colon) {
49 + g_error("read map failed - option '%s' not terminated ('%s')",
50 + optname, inbuf);
51 + }
52 + *line = colon+1;
53 + *out = g_strndup(value, colon - value);
54 + return true;
55 +}
56 +
57 +static uint64_t verify_u64(const char *text) {
58 + uint64_t value;
59 + const char *endptr = NULL;
60 + if (qemu_strtou64(text, &endptr, 0, &value) != 0 || !endptr || *endptr) {
61 + g_error("read map failed - not a number: %s", text);
62 + }
63 + return value;
64 +}
65 +
66 static int extract_content(int argc, char **argv)
67 {
68 int c, ret = 0;
69 @@ -208,6 +239,9 @@ static int extract_content(int argc, char **argv)
70 while (1) {
71 char inbuf[8192];
72 char *line = fgets(inbuf, sizeof(inbuf), map);
73 + char *format = NULL;
74 + char *bps = NULL;
75 + char *group = NULL;
76 if (!line || line[0] == '\0' || !strcmp(line, "done\n")) {
77 break;
78 }
79 @@ -219,15 +253,19 @@ static int extract_content(int argc, char **argv)
80 }
81 }
82
83 - char *format = NULL;
84 - if (strncmp(line, "format=", sizeof("format=")-1) == 0) {
85 - format = line + sizeof("format=")-1;
86 - char *colon = strchr(format, ':');
87 - if (!colon) {
88 - g_error("read map failed - found only a format ('%s')", inbuf);
89 + while (1) {
90 + if (!try_parse_option(&line, "format", &format, inbuf) &&
91 + !try_parse_option(&line, "throttling.bps", &bps, inbuf) &&
92 + !try_parse_option(&line, "throttling.group", &group, inbuf))
93 + {
94 + break;
95 }
96 - format = g_strndup(format, colon - format);
97 - line = colon+1;
98 + }
99 +
100 + uint64_t bps_value = 0;
101 + if (bps) {
102 + bps_value = verify_u64(bps);
103 + g_free(bps);
104 }
105
106 const char *path;
107 @@ -253,6 +291,8 @@ static int extract_content(int argc, char **argv)
108 map->devname = g_strdup(devname);
109 map->path = g_strdup(path);
110 map->format = format;
111 + map->throttling_bps = bps_value;
112 + map->throttling_group = group;
113 map->write_zero = write_zero;
114
115 g_hash_table_insert(devmap, map->devname, map);
116 @@ -280,6 +320,8 @@ static int extract_content(int argc, char **argv)
117 } else if (di) {
118 char *devfn = NULL;
119 const char *format = NULL;
120 + uint64_t throttling_bps = 0;
121 + const char *throttling_group = NULL;
122 int flags = BDRV_O_RDWR | BDRV_O_NO_FLUSH;
123 bool write_zero = true;
124
125 @@ -291,6 +333,8 @@ static int extract_content(int argc, char **argv)
126 }
127 devfn = map->path;
128 format = map->format;
129 + throttling_bps = map->throttling_bps;
130 + throttling_group = map->throttling_group;
131 write_zero = map->write_zero;
132 } else {
133 devfn = g_strdup_printf("%s/tmp-disk-%s.raw",
134 @@ -315,7 +359,7 @@ static int extract_content(int argc, char **argv)
135 if (format) {
136 /* explicit format from commandline */
137 options = qdict_new();
138 - qdict_put(options, "driver", qstring_from_str(format));
139 + qdict_put_str(options, "driver", format);
140 } else if ((devlen > 4 && strcmp(devfn+devlen-4, ".raw") == 0) ||
141 strncmp(devfn, "/dev/", 5) == 0)
142 {
143 @@ -324,15 +368,34 @@ static int extract_content(int argc, char **argv)
144 */
145 /* explicit raw format */
146 options = qdict_new();
147 - qdict_put(options, "driver", qstring_from_str("raw"));
148 + qdict_put_str(options, "driver", "raw");
149 }
150
151 -
152 if (errp || !(blk = blk_new_open(devfn, NULL, options, flags, &errp))) {
153 g_error("can't open file %s - %s", devfn,
154 error_get_pretty(errp));
155 }
156
157 + if (throttling_group) {
158 + blk_io_limits_enable(blk, throttling_group);
159 + }
160 +
161 + if (throttling_bps) {
162 + if (!throttling_group) {
163 + blk_io_limits_enable(blk, devfn);
164 + }
165 +
166 + ThrottleConfig cfg;
167 + throttle_config_init(&cfg);
168 + cfg.buckets[THROTTLE_BPS_WRITE].avg = throttling_bps;
169 + Error *err = NULL;
170 + if (!throttle_is_valid(&cfg, &err)) {
171 + error_report_err(err);
172 + g_error("failed to apply throttling");
173 + }
174 + blk_set_io_limits(blk, &cfg);
175 + }
176 +
177 if (vma_reader_register_bs(vmar, i, blk, write_zero, &errp) < 0) {
178 g_error("%s", error_get_pretty(errp));
179 }
180 @@ -730,6 +793,7 @@ int main(int argc, char **argv)
181 }
182
183 bdrv_init();
184 + module_call_init(MODULE_INIT_QOM);
185
186 if (argc < 2) {
187 help();
188 --
189 2.20.1
190