From: Hyman Huang(黄勇) <yong.huang(a)smartx.com>
Implement qemuMonitorQueryVcpuDirtyLimit which query vcpu
dirty limit info by calling qmp 'query-vcpu-dirty-limit'.
Signed-off-by: Hyman Huang(黄勇) <yong.huang(a)smartx.com>
---
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 90bc0e62c9..9b18b4e46b 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4513,3 +4513,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 07a05365cf..1828bb202a 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1584,3 +1584,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 c8f6069566..8a72abf28d 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -8895,3 +8895,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 89f61b3052..bd8131508b 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -830,3 +830,7 @@ int
qemuMonitorJSONSetVcpuDirtyLimit(qemuMonitor *mon,
int vcpu,
unsigned long long rate);
+
+int
+qemuMonitorJSONQueryVcpuDirtyLimit(qemuMonitor *mon,
+ qemuMonitorVcpuDirtyLimitInfo *info);
--
2.38.5