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