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>
11 vma.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
12 1 file changed, 76 insertions(+), 12 deletions(-)
14 diff --git a/vma.c b/vma.c
15 index 1b59fd1555..f9f5c308fe 100644
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"
27 static void help(void)
28 @@ -132,9 +133,39 @@ typedef struct RestoreMap {
32 + uint64_t throttling_bps;
33 + char *throttling_group;
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] != '=') {
43 + g_error("read map failed - duplicate value for option '%s'", optname);
45 + char *value = (*line) + optlen + 1; /* including a '=' */
46 + char *colon = strchr(value, ':');
48 + g_error("read map failed - option '%s' not terminated ('%s')",
52 + *out = g_strndup(value, colon - value);
56 +static uint64_t verify_u64(const char *text) {
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);
65 static int extract_content(int argc, char **argv)
68 @@ -208,6 +239,9 @@ static int extract_content(int argc, char **argv)
71 char *line = fgets(inbuf, sizeof(inbuf), map);
72 + char *format = NULL;
75 if (!line || line[0] == '\0' || !strcmp(line, "done\n")) {
78 @@ -219,15 +253,19 @@ static int extract_content(int argc, char **argv)
82 - char *format = NULL;
83 - if (strncmp(line, "format=", sizeof("format=")-1) == 0) {
84 - format = line + sizeof("format=")-1;
85 - char *colon = strchr(format, ':');
87 - g_error("read map failed - found only a format ('%s')", inbuf);
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))
95 - format = g_strndup(format, colon - format);
99 + uint64_t bps_value = 0;
101 + bps_value = verify_u64(bps);
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;
114 g_hash_table_insert(devmap, map->devname, map);
115 @@ -280,6 +320,8 @@ static int extract_content(int argc, char **argv)
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;
124 @@ -291,6 +333,8 @@ static int extract_content(int argc, char **argv)
127 format = map->format;
128 + throttling_bps = map->throttling_bps;
129 + throttling_group = map->throttling_group;
130 write_zero = map->write_zero;
132 devfn = g_strdup_printf("%s/tmp-disk-%s.raw",
133 @@ -315,7 +359,7 @@ static int extract_content(int argc, char **argv)
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)
142 @@ -324,15 +368,34 @@ static int extract_content(int argc, char **argv)
144 /* explicit raw format */
145 options = qdict_new();
146 - qdict_put(options, "driver", qstring_from_str("raw"));
147 + qdict_put_str(options, "driver", "raw");
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));
156 + if (throttling_group) {
157 + blk_io_limits_enable(blk, throttling_group);
160 + if (throttling_bps) {
161 + if (!throttling_group) {
162 + blk_io_limits_enable(blk, devfn);
165 + ThrottleConfig cfg;
166 + throttle_config_init(&cfg);
167 + cfg.buckets[THROTTLE_BPS_WRITE].avg = throttling_bps;
169 + if (!throttle_is_valid(&cfg, &err)) {
170 + error_report_err(err);
171 + g_error("failed to apply throttling");
173 + blk_set_io_limits(blk, &cfg);
176 if (vma_reader_register_bs(vmar, i, blk, write_zero, &errp) < 0) {
177 g_error("%s", error_get_pretty(errp));
179 @@ -730,6 +793,7 @@ int main(int argc, char **argv)
183 + module_call_init(MODULE_INIT_QOM);