From 23f2c0ccb0a430518d3e544a451a59b207f003ad Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 22 Feb 2018 16:42:42 +0100 Subject: [PATCH] reapply: vma: add throttling options to drive mapping fifo protocol This one got lost when rebasing Signed-off-by: Wolfgang Bumiller --- ...ng-options-to-drive-mapping-fifo-pro.patch | 173 ++++++++++++++++++ debian/patches/series | 1 + 2 files changed, 174 insertions(+) create mode 100644 debian/patches/pve/0028-vma-add-throttling-options-to-drive-mapping-fifo-pro.patch diff --git a/debian/patches/pve/0028-vma-add-throttling-options-to-drive-mapping-fifo-pro.patch b/debian/patches/pve/0028-vma-add-throttling-options-to-drive-mapping-fifo-pro.patch new file mode 100644 index 0000000..4755355 --- /dev/null +++ b/debian/patches/pve/0028-vma-add-throttling-options-to-drive-mapping-fifo-pro.patch @@ -0,0 +1,173 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Wolfgang Bumiller +Date: Thu, 15 Feb 2018 11:07:56 +0100 +Subject: [PATCH] vma: add throttling options to drive mapping fifo protocol + +We now need to call initialize the qom module as well. + +Signed-off-by: Wolfgang Bumiller +--- + vma.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- + 1 file changed, 73 insertions(+), 9 deletions(-) + +diff --git a/vma.c b/vma.c +index 1b59fd1555..71be120cfc 100644 +--- a/vma.c ++++ b/vma.c +@@ -18,6 +18,7 @@ + #include "qemu-common.h" + #include "qemu/error-report.h" + #include "qemu/main-loop.h" ++#include "qemu/cutils.h" + #include "qapi/qmp/qstring.h" + #include "sysemu/block-backend.h" + +@@ -132,9 +133,39 @@ typedef struct RestoreMap { + char *devname; + char *path; + char *format; ++ uint64_t throttling_bps; ++ char *throttling_group; + bool write_zero; + } RestoreMap; + ++static bool try_parse_option(char **line, const char *optname, char **out, const char *inbuf) { ++ size_t optlen = strlen(optname); ++ if (strncmp(*line, optname, optlen) != 0 || (*line)[optlen] != '=') { ++ return false; ++ } ++ if (*out) { ++ g_error("read map failed - duplicate value for option '%s'", optname); ++ } ++ char *value = (*line) + optlen + 1; /* including a '=' */ ++ char *colon = strchr(value, ':'); ++ if (!colon) { ++ g_error("read map failed - option '%s' not terminated ('%s')", ++ optname, inbuf); ++ } ++ *line = colon+1; ++ *out = g_strndup(value, colon - value); ++ return true; ++} ++ ++static uint64_t verify_u64(const char *text) { ++ uint64_t value; ++ const char *endptr = NULL; ++ if (qemu_strtou64(text, &endptr, 0, &value) != 0 || !endptr || *endptr) { ++ g_error("read map failed - not a number: %s", text); ++ } ++ return value; ++} ++ + static int extract_content(int argc, char **argv) + { + int c, ret = 0; +@@ -208,6 +239,9 @@ static int extract_content(int argc, char **argv) + while (1) { + char inbuf[8192]; + char *line = fgets(inbuf, sizeof(inbuf), map); ++ char *format = NULL; ++ char *bps = NULL; ++ char *group = NULL; + if (!line || line[0] == '\0' || !strcmp(line, "done\n")) { + break; + } +@@ -219,15 +253,19 @@ static int extract_content(int argc, char **argv) + } + } + +- char *format = NULL; +- if (strncmp(line, "format=", sizeof("format=")-1) == 0) { +- format = line + sizeof("format=")-1; +- char *colon = strchr(format, ':'); +- if (!colon) { +- g_error("read map failed - found only a format ('%s')", inbuf); ++ while (1) { ++ if (!try_parse_option(&line, "format", &format, inbuf) && ++ !try_parse_option(&line, "throttling.bps", &bps, inbuf) && ++ !try_parse_option(&line, "throttling.group", &group, inbuf)) ++ { ++ break; + } +- format = g_strndup(format, colon - format); +- line = colon+1; ++ } ++ ++ uint64_t bps_value = 0; ++ if (bps) { ++ bps_value = verify_u64(bps); ++ g_free(bps); + } + + const char *path; +@@ -253,6 +291,8 @@ static int extract_content(int argc, char **argv) + map->devname = g_strdup(devname); + map->path = g_strdup(path); + map->format = format; ++ map->throttling_bps = bps_value; ++ map->throttling_group = group; + map->write_zero = write_zero; + + g_hash_table_insert(devmap, map->devname, map); +@@ -280,6 +320,8 @@ static int extract_content(int argc, char **argv) + } else if (di) { + char *devfn = NULL; + const char *format = NULL; ++ uint64_t throttling_bps = 0; ++ const char *throttling_group = NULL; + int flags = BDRV_O_RDWR | BDRV_O_NO_FLUSH; + bool write_zero = true; + +@@ -291,6 +333,8 @@ static int extract_content(int argc, char **argv) + } + devfn = map->path; + format = map->format; ++ throttling_bps = map->throttling_bps; ++ throttling_group = map->throttling_group; + write_zero = map->write_zero; + } else { + devfn = g_strdup_printf("%s/tmp-disk-%s.raw", +@@ -327,12 +371,31 @@ static int extract_content(int argc, char **argv) + qdict_put(options, "driver", qstring_from_str("raw")); + } + +- + if (errp || !(blk = blk_new_open(devfn, NULL, options, flags, &errp))) { + g_error("can't open file %s - %s", devfn, + error_get_pretty(errp)); + } + ++ if (throttling_group) { ++ blk_io_limits_enable(blk, throttling_group); ++ } ++ ++ if (throttling_bps) { ++ if (!throttling_group) { ++ blk_io_limits_enable(blk, devfn); ++ } ++ ++ ThrottleConfig cfg; ++ throttle_config_init(&cfg); ++ cfg.buckets[THROTTLE_BPS_WRITE].avg = throttling_bps; ++ Error *err = NULL; ++ if (!throttle_is_valid(&cfg, &err)) { ++ error_report_err(err); ++ g_error("failed to apply throttling"); ++ } ++ blk_set_io_limits(blk, &cfg); ++ } ++ + if (vma_reader_register_bs(vmar, i, blk, write_zero, &errp) < 0) { + g_error("%s", error_get_pretty(errp)); + } +@@ -730,6 +793,7 @@ int main(int argc, char **argv) + } + + bdrv_init(); ++ module_call_init(MODULE_INIT_QOM); + + if (argc < 2) { + help(); +-- +2.11.0 + diff --git a/debian/patches/series b/debian/patches/series index 954ea11..c8c3090 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -25,5 +25,6 @@ pve/0024-qemu-img-dd-add-osize-and-read-from-to-stdin-stdout.patch pve/0025-backup-modify-job-api.patch pve/0026-backup-introduce-vma-archive-format.patch pve/0027-adding-old-vma-files.patch +pve/0028-vma-add-throttling-options-to-drive-mapping-fifo-pro.patch extra/0001-Revert-target-i386-disable-LINT0-after-reset.patch extra/0002-ratelimit-don-t-align-wait-time-with-slices.patch -- 2.39.2