[PATCH v3 5/7] migration/dirtyrate: Implement qemuDomainCalculateDirtyRate

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

 



Implement qemuDomainCalculateDirtyRate which calculates domain's memory
dirty rate calling qmp "calc-dirty-rate".

Signed-off-by: Hao Wang <wanghao232@xxxxxxxxxx>
Signed-off-by: Zhou Yimin <zhouyimin@xxxxxxxxxx>
Reviewed-by: Chuan Zheng <zhengchuan@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c       |  6 +++++-
 src/qemu/qemu_migration.c    | 31 +++++++++++++++++++++++++++++++
 src/qemu/qemu_migration.h    |  5 +++++
 src/qemu/qemu_monitor.c      | 12 ++++++++++++
 src/qemu/qemu_monitor.h      |  4 ++++
 src/qemu/qemu_monitor_json.c | 21 +++++++++++++++++++++
 src/qemu/qemu_monitor_json.h |  4 ++++
 7 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c84bd17b73..3d2a18a21f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -20171,7 +20171,11 @@ qemuDomainGetDirtyRateInfo(virDomainPtr dom,
             virObjectLock(vm);
         }
 
-        /* TODO: call query-dirty-rate for dirtyrate querying */
+        if (qemuDomainQueryDirtyRate(dom, vm, info) < 0) {
+            virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+                           _("can't query domain's dirty rate"));
+            goto endjob;
+        }
     }
 
     ret = 0;
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 8029e24415..3d07ba3ac4 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -5864,3 +5864,34 @@ qemuDomainCalculateDirtyRate(virDomainPtr dom,
 
     return ret;
 }
+
+
+int
+qemuDomainQueryDirtyRate(virDomainPtr dom,
+                         virDomainObjPtr vm,
+                         virDomainDirtyRateInfoPtr info)
+{
+    virQEMUDriverPtr driver = dom->conn->privateData;
+    qemuDomainObjPrivatePtr priv;
+    int ret = -1;
+
+    if (!virDomainObjIsActive(vm)) {
+        virReportError(VIR_ERR_OPERATION_INVALID,
+                       "%s", _("domain is not running"));
+        return ret;
+    }
+
+    priv = vm->privateData;
+
+    qemuDomainObjEnterMonitor(driver, vm);
+
+    ret = qemuMonitorQueryDirtyRate(priv->mon, info);
+    if (ret < 0) {
+        virReportError(VIR_ERR_OPERATION_FAILED,
+                       "%s", _("get vm's dirty rate failed."));
+    }
+    if (qemuDomainObjExitMonitor(driver, vm) < 0)
+        ret = -1;
+
+    return ret;
+}
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index 0522b375c0..8baae512b7 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -263,3 +263,8 @@ int
 qemuDomainCalculateDirtyRate(virDomainPtr dom,
                              virDomainObjPtr vm,
                              long long sec);
+
+int
+qemuDomainQueryDirtyRate(virDomainPtr dom,
+                         virDomainObjPtr vm,
+                         virDomainDirtyRateInfoPtr info);
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 06603b8691..2fa6879467 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4781,3 +4781,15 @@ qemuMonitorCalculateDirtyRate(qemuMonitorPtr mon,
 
     return qemuMonitorJSONCalculateDirtyRate(mon, sec);
 }
+
+
+int
+qemuMonitorQueryDirtyRate(qemuMonitorPtr mon,
+                          virDomainDirtyRateInfoPtr info)
+{
+    VIR_DEBUG("info=%p", info);
+
+    QEMU_CHECK_MONITOR(mon);
+
+    return qemuMonitorJSONQueryDirtyRate(mon, info);
+}
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index afb97780cf..25105c3ad9 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1531,3 +1531,7 @@ qemuMonitorTransactionBackup(virJSONValuePtr actions,
 int
 qemuMonitorCalculateDirtyRate(qemuMonitorPtr mon,
                               long long sec);
+
+int
+qemuMonitorQueryDirtyRate(qemuMonitorPtr mon,
+                          virDomainDirtyRateInfoPtr info);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 65691522fb..a0616eae2c 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -9657,3 +9657,24 @@ qemuMonitorJSONCalculateDirtyRate(qemuMonitorPtr mon,
 
     return 0;
 }
+
+
+int
+qemuMonitorJSONQueryDirtyRate(qemuMonitorPtr mon,
+                              virDomainDirtyRateInfoPtr info)
+{
+    g_autoptr(virJSONValue) cmd = NULL;
+    g_autoptr(virJSONValue) reply = NULL;
+
+    if (!(cmd = qemuMonitorJSONMakeCommand("query-dirty-rate", NULL)))
+        return -1;
+
+    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+        return -1;
+
+    if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+        return -1;
+
+    /* TODO: extract dirtyrate data from reply and store in virDomainDirtyRateInfoPtr */
+    return 0;
+}
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index c9556fc19a..487f2e6e58 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -714,3 +714,7 @@ qemuMonitorJSONGetCPUMigratable(qemuMonitorPtr mon,
 int
 qemuMonitorJSONCalculateDirtyRate(qemuMonitorPtr mon,
                                   long long sec);
+
+int
+qemuMonitorJSONQueryDirtyRate(qemuMonitorPtr mon,
+                              virDomainDirtyRateInfoPtr info);
-- 
2.23.0





[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