From: Hyman Huang(黄勇) <huangy81(a)chinatelecom.cn>
Implement qemuMonitorQueryVcpuDirtyLimit which query vcpu
dirty limit info by calling qmp 'query-vcpu-dirty-limit'.
Signed-off-by: Hyman Huang(黄勇) <huangy81(a)chinatelecom.cn>
---
src/qemu/qemu_monitor.c | 12 +++++++++
src/qemu/qemu_monitor.h | 17 ++++++++++++
src/qemu/qemu_monitor_json.c | 64 ++++++++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_monitor_json.h | 4 +++
4 files changed, 97 insertions(+)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index dee2904..7480856 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4309,3 +4309,15 @@ qemuMonitorSetVcpuDirtyLimit(qemuMonitor *mon,
return qemuMonitorJSONSetVcpuDirtyLimit(mon, vcpu, rate);
}
+
+
+int
+qemuMonitorQueryVcpuDirtyLimit(qemuMonitor *mon,
+ qemuMonitorVcpuDirtyLimitInfo *info)
+{
+ VIR_DEBUG("info=%p", info);
+
+ QEMU_CHECK_MONITOR(mon);
+
+ return qemuMonitorJSONQueryVcpuDirtyLimit(mon, info);
+}
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 83bcf14..cf76f43 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1486,3 +1486,20 @@ int
qemuMonitorSetVcpuDirtyLimit(qemuMonitor *mon,
int vcpu,
unsigned long long rate);
+
+typedef struct _qemuMonitorVcpuDirtyLimit qemuMonitorVcpuDirtyLimit;
+struct _qemuMonitorVcpuDirtyLimit {
+ int idx; /* virtual cpu index */
+ unsigned long long limit; /* virtual cpu dirty page rate limit in MB/s */
+ unsigned long long current; /* virtual cpu dirty page rate in MB/s */
+};
+
+typedef struct _qemuMonitorVcpuDirtyLimitInfo qemuMonitorVcpuDirtyLimitInfo;
+struct _qemuMonitorVcpuDirtyLimitInfo {
+ size_t nvcpus; /* number of virtual cpu */
+ qemuMonitorVcpuDirtyLimit *limits; /* array of dirty page rate limit */
+};
+
+int
+qemuMonitorQueryVcpuDirtyLimit(qemuMonitor *mon,
+ qemuMonitorVcpuDirtyLimitInfo *info);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index fc50604..4642a2d 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -8612,3 +8612,67 @@ qemuMonitorJSONSetVcpuDirtyLimit(qemuMonitor *mon,
return 0;
}
+
+static int
+qemuMonitorJSONExtractVcpuDirtyLimitInfo(virJSONValue *data,
+ qemuMonitorVcpuDirtyLimitInfo *info)
+{
+ size_t nvcpus;
+ size_t i;
+
+ nvcpus = virJSONValueArraySize(data);
+ info->nvcpus = nvcpus;
+ info->limits = g_new0(qemuMonitorVcpuDirtyLimit, nvcpus);
+
+ for (i = 0; i < nvcpus; i++) {
+ virJSONValue *entry = virJSONValueArrayGet(data, i);
+ if (virJSONValueObjectGetNumberInt(entry, "cpu-index",
+ &info->limits[i].idx) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("query-vcpu-dirty-limit reply was missing
'cpu-index' data"));
+ return -1;
+ }
+
+ if (virJSONValueObjectGetNumberUlong(entry, "limit-rate",
+ &info->limits[i].limit) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("query-vcpu-dirty-limit reply was missing
'limit-rate' data"));
+ return -1;
+ }
+
+ if (virJSONValueObjectGetNumberUlong(entry, "current-rate",
+ &info->limits[i].current) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("query-vcpu-dirty-limit reply was missing
'current-rate' data"));
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+int
+qemuMonitorJSONQueryVcpuDirtyLimit(qemuMonitor *mon,
+ qemuMonitorVcpuDirtyLimitInfo *info)
+{
+ g_autoptr(virJSONValue) cmd = NULL;
+ g_autoptr(virJSONValue) reply = NULL;
+ virJSONValue *data = NULL;
+
+ if (!(cmd = qemuMonitorJSONMakeCommand("query-vcpu-dirty-limit", NULL)))
+ return -1;
+
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ return -1;
+
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ return -1;
+
+ if (!(data = virJSONValueObjectGetArray(reply, "return"))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("query-vcpu-dirty-limit reply was missing 'return'
data"));
+ return -1;
+ }
+
+ return qemuMonitorJSONExtractVcpuDirtyLimitInfo(data, info);
+}
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 7b07428..2852061 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -817,3 +817,7 @@ int
qemuMonitorJSONSetVcpuDirtyLimit(qemuMonitor *mon,
int vcpu,
unsigned long long rate);
+
+int
+qemuMonitorJSONQueryVcpuDirtyLimit(qemuMonitor *mon,
+ qemuMonitorVcpuDirtyLimitInfo *info);
--
1.8.3.1