[PATCH v1 05/10] qemu_monitor: Implement qemuMonitorQueryVcpuDirtyLimit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Hyman Huang(黄勇) <huangy81@xxxxxxxxxxxxxxx>

Implement qemuMonitorQueryVcpuDirtyLimit which query vcpu
dirty limit info by calling qmp 'query-vcpu-dirty-limit'.

Signed-off-by: Hyman Huang(黄勇) <huangy81@xxxxxxxxxxxxxxx>
---
 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 49477ff..ab4ba2f 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4430,3 +4430,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 fade35e..bd5dd2b 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1534,3 +1534,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 68a8ca6..1d4c6f5 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -8704,3 +8704,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 07944c7..388d5b0 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -823,3 +823,7 @@ int
 qemuMonitorJSONSetVcpuDirtyLimit(qemuMonitor *mon,
                                  int vcpu,
                                  unsigned long long rate);
+
+int
+qemuMonitorJSONQueryVcpuDirtyLimit(qemuMonitor *mon,
+                                   qemuMonitorVcpuDirtyLimitInfo *info);
-- 
1.8.3.1





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux