Detect if the the qemu binary currentely in use suport the bps_max option and thy firends, If yes add it to the commande, if not, just ignore the options.
Signed-off-by: Matthias Gatto <matthias.ga...@outscale.com> --- src/qemu/qemu_monitor_text.c | 75 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index fc54a11..e741d27 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -2994,11 +2994,26 @@ int qemuMonitorTextSetBlockIoThrottle(qemuMonitorPtr mon, /* For the not specified fields, 0 by default */ cmd_name = "block_set_io_throttle"; - if (virAsprintf(&cmd, "%s %s %llu %llu %llu %llu %llu %llu", cmd_name, - device, info->total_bytes_sec, info->read_bytes_sec, - info->write_bytes_sec, info->total_iops_sec, - info->read_iops_sec, info->write_iops_sec) < 0) - goto cleanup; + if (info->suport_max_options) + { + if (virAsprintf(&cmd, "%s %s %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu %llu", cmd_name, + device, info->total_bytes_sec, info->read_bytes_sec, + info->write_bytes_sec, info->total_iops_sec, + info->read_iops_sec, info->write_iops_sec, + info->total_bytes_sec_max, info->read_bytes_sec_max, + info->write_bytes_sec_max, info->total_iops_sec_max, + info->read_iops_sec_max, info->write_iops_sec_max, + info->size_iops_sec) < 0) + goto cleanup; + } + else + { + if (virAsprintf(&cmd, "%s %s %llu %llu %llu %llu %llu %llu", cmd_name, + device, info->total_bytes_sec, info->read_bytes_sec, + info->write_bytes_sec, info->total_iops_sec, + info->read_iops_sec, info->write_iops_sec) < 0) + goto cleanup; + } if (qemuMonitorHMPCommand(mon, cmd, &result) < 0) goto cleanup; @@ -3025,6 +3040,7 @@ qemuMonitorTextParseBlockIoThrottle(const char *result, int ret = -1; const char *p, *eol; int devnamelen = strlen(device); + bool checkBlockInfo; p = result; @@ -3039,31 +3055,78 @@ qemuMonitorTextParseBlockIoThrottle(const char *result, p += devnamelen + 2; /* Skip to first label. */ while (*p) { + checkBlockInfo = false; if (STRPREFIX(p, "bps=")) { p += strlen("bps="); + checkBlockInfo = true; if (virStrToLong_ull(p, &dummy, 10, &reply->total_bytes_sec) == -1) VIR_DEBUG("error reading total_bytes_sec: %s", p); } else if (STRPREFIX(p, "bps_rd=")) { + checkBlockInfo = true; p += strlen("bps_rd="); if (virStrToLong_ull(p, &dummy, 10, &reply->read_bytes_sec) == -1) VIR_DEBUG("error reading read_bytes_sec: %s", p); } else if (STRPREFIX(p, "bps_wr=")) { + checkBlockInfo = true; p += strlen("bps_wr="); if (virStrToLong_ull(p, &dummy, 10, &reply->write_bytes_sec) == -1) VIR_DEBUG("error reading write_bytes_sec: %s", p); } else if (STRPREFIX(p, "iops=")) { + checkBlockInfo = true; p += strlen("iops="); if (virStrToLong_ull(p, &dummy, 10, &reply->total_iops_sec) == -1) VIR_DEBUG("error reading total_iops_sec: %s", p); } else if (STRPREFIX(p, "iops_rd=")) { + checkBlockInfo = true; p += strlen("iops_rd="); if (virStrToLong_ull(p, &dummy, 10, &reply->read_iops_sec) == -1) VIR_DEBUG("error reading read_iops_sec: %s", p); } else if (STRPREFIX(p, "iops_wr=")) { + checkBlockInfo = true; p += strlen("iops_wr="); if (virStrToLong_ull(p, &dummy, 10, &reply->write_iops_sec) == -1) VIR_DEBUG("error reading write_iops_sec: %s", p); - } else { + } + if (reply->suport_max_options) + { + if (STRPREFIX(p, "bps_max=")) { + checkBlockInfo = true; + p += strlen("bps_max="); + if (virStrToLong_ull(p, &dummy, 10, &reply->total_bytes_sec_max) == -1) + VIR_DEBUG("error reading total_bytes_sec_max: %s", p); + } else if (STRPREFIX(p, "bps_wr_max=")) { + checkBlockInfo = true; + p += strlen("bps_wr_max="); + if (virStrToLong_ull(p, &dummy, 10, &reply->write_bytes_sec_max) == -1) + VIR_DEBUG("error reading write_bytes_sec_max: %s", p); + } else if (STRPREFIX(p, "bps_rd_max=")) { + checkBlockInfo = true; + p += strlen("bps_rd_max="); + if (virStrToLong_ull(p, &dummy, 10, &reply->read_bytes_sec_max) == -1) + VIR_DEBUG("error reading read_bytes_sec_max: %s", p); + } else if (STRPREFIX(p, "iops_max=")) { + checkBlockInfo = true; + p += strlen("iops_max="); + if (virStrToLong_ull(p, &dummy, 10, &reply->total_iops_sec_max) == -1) + VIR_DEBUG("error reading total_iops_sec_max: %s", p); + } else if (STRPREFIX(p, "iops_rd_max=")) { + checkBlockInfo = true; + p += strlen("iops_rd_max="); + if (virStrToLong_ull(p, &dummy, 10, &reply->read_iops_sec_max) == -1) + VIR_DEBUG("error reading read_iops_sec_max: %s", p); + } else if (STRPREFIX(p, "iops_wr_max=")) { + checkBlockInfo = true; + p += strlen("iops_wr_max="); + if (virStrToLong_ull(p, &dummy, 10, &reply->write_iops_sec_max) == -1) + VIR_DEBUG("error reading write_iops_sec_max: %s", p); + } else if (STRPREFIX(p, "size_iops=")) { + checkBlockInfo = true; + p += strlen("size_iops="); + if (virStrToLong_ull(p, &dummy, 10, &reply->size_iops_sec) == -1) + VIR_DEBUG("error reading size_iops_sec: %s", p); + } + } + if (!checkBlockInfo) { VIR_DEBUG(" unknown block info %s", p); } -- 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list