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
7 We now need to call initialize the qom module as well.
9 Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
10 Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
12 vma.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++--------
13 1 file changed, 76 insertions(+), 12 deletions(-)
15 diff --git a/vma.c b/vma.c
16 index 1b59fd1555..f9f5c308fe 100644
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"
28 static void help(void)
29 @@ -132,9 +133,39 @@ typedef struct RestoreMap {
33 + uint64_t throttling_bps;
34 + char *throttling_group;
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] != '=') {
44 + g_error("read map failed - duplicate value for option '%s'", optname);
46 + char *value = (*line) + optlen + 1; /* including a '=' */
47 + char *colon = strchr(value, ':');
49 + g_error("read map failed - option '%s' not terminated ('%s')",
53 + *out = g_strndup(value, colon - value);
57 +static uint64_t verify_u64(const char *text) {
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);
66 static int extract_content(int argc, char **argv)
69 @@ -208,6 +239,9 @@ static int extract_content(int argc, char **argv)
72 char *line = fgets(inbuf, sizeof(inbuf), map);
73 + char *format = NULL;
76 if (!line || line[0] == '\0' || !strcmp(line, "done\n")) {
79 @@ -219,15 +253,19 @@ static int extract_content(int argc, char **argv)
83 - char *format = NULL;
84 - if (strncmp(line, "format=", sizeof("format=")-1) == 0) {
85 - format = line + sizeof("format=")-1;
86 - char *colon = strchr(format, ':');
88 - g_error("read map failed - found only a format ('%s')", inbuf);
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))
96 - format = g_strndup(format, colon - format);
100 + uint64_t bps_value = 0;
102 + bps_value = verify_u64(bps);
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;
115 g_hash_table_insert(devmap, map->devname, map);
116 @@ -280,6 +320,8 @@ static int extract_content(int argc, char **argv)
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;
125 @@ -291,6 +333,8 @@ static int extract_content(int argc, char **argv)
128 format = map->format;
129 + throttling_bps = map->throttling_bps;
130 + throttling_group = map->throttling_group;
131 write_zero = map->write_zero;
133 devfn = g_strdup_printf("%s/tmp-disk-%s.raw",
134 @@ -315,7 +359,7 @@ static int extract_content(int argc, char **argv)
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)
143 @@ -324,15 +368,34 @@ static int extract_content(int argc, char **argv)
145 /* explicit raw format */
146 options = qdict_new();
147 - qdict_put(options, "driver", qstring_from_str("raw"));
148 + qdict_put_str(options, "driver", "raw");
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));
157 + if (throttling_group) {
158 + blk_io_limits_enable(blk, throttling_group);
161 + if (throttling_bps) {
162 + if (!throttling_group) {
163 + blk_io_limits_enable(blk, devfn);
166 + ThrottleConfig cfg;
167 + throttle_config_init(&cfg);
168 + cfg.buckets[THROTTLE_BPS_WRITE].avg = throttling_bps;
170 + if (!throttle_is_valid(&cfg, &err)) {
171 + error_report_err(err);
172 + g_error("failed to apply throttling");
174 + blk_set_io_limits(blk, &cfg);
177 if (vma_reader_register_bs(vmar, i, blk, write_zero, &errp) < 0) {
178 g_error("%s", error_get_pretty(errp));
180 @@ -730,6 +793,7 @@ int main(int argc, char **argv)
184 + module_call_init(MODULE_INIT_QOM);