Implement qemuDomainGetDirtyRateInfo:
using flags to control behaviors -- calculate and/or query dirtyrate.
Signed-off-by: Hao Wang <wanghao232(a)huawei.com>
Reviewed-by: Chuan Zheng <zhengchuan(a)huawei.com>
---
include/libvirt/libvirt-domain.h | 11 +++++++
src/qemu/qemu_driver.c | 51 ++++++++++++++++++++++++++++++--
2 files changed, 60 insertions(+), 2 deletions(-)
diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 1c63191baa..5801ca0f86 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -5096,6 +5096,17 @@ int virDomainBackupBegin(virDomainPtr domain,
char *virDomainBackupGetXMLDesc(virDomainPtr domain,
unsigned int flags);
+/**
+ * virDomainDirtyRateFlags:
+ *
+ * Details on the flags used by getdirtyrate api.
+ */
+
+typedef enum {
+ VIR_DOMAIN_DIRTYRATE_CALC = 1 << 0, /* calculate domain's dirtyrate */
+ VIR_DOMAIN_DIRTYRATE_QUERY = 1 << 1, /* query domain's dirtyrate */
+} virDomainDirtyRateFlags;
+
/**
* virDomainDirtyRateInfo:
*
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 513290c934..a93f99f28a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -20123,14 +20123,61 @@ qemuDomainAgentSetResponseTimeout(virDomainPtr dom,
}
+#define MIN_DIRTYRATE_CALCULATION_PERIOD 1 /* 1s */
+#define MAX_DIRTYRATE_CALCULATION_PERIOD 60 /* 60s */
+
static int
qemuDomainGetDirtyRateInfo(virDomainPtr dom,
virDomainDirtyRateInfoPtr info,
long long sec,
int flags)
{
- /* TODO */
- return 0;
+ virDomainObjPtr vm = NULL;
+ virQEMUDriverPtr driver = dom->conn->privateData;
+ int ret = -1;
+
+ if (!(vm = qemuDomainObjFromDomain(dom)))
+ return ret;
+
+ if (virDomainGetDirtyRateInfoEnsureACL(dom->conn, vm->def) < 0)
+ goto cleanup;
+
+ if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_QUERY) < 0)
+ goto cleanup;
+
+ if (!qemuMigrationSrcIsAllowed(driver, vm, false, 0))
+ goto endjob;
+
+ if (flags & VIR_DOMAIN_DIRTYRATE_CALC) {
+ if (sec < MIN_DIRTYRATE_CALCULATION_PERIOD || sec >
MAX_DIRTYRATE_CALCULATION_PERIOD) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ "seconds=%lld is invalid, please choose value within [1,
60].", sec);
+ goto endjob;
+ }
+
+ /* TODO: call calc-dirty-rate for dirtyrate calculating */
+ }
+
+ if (flags & VIR_DOMAIN_DIRTYRATE_QUERY) {
+ if (flags & VIR_DOMAIN_DIRTYRATE_CALC) {
+ struct timespec ts = { .tv_sec = sec, .tv_nsec = 50 * 1000 * 1000ull };
+
+ virObjectUnlock(vm);
+ nanosleep(&ts, NULL);
+ virObjectLock(vm);
+ }
+
+ /* TODO: call query-dirty-rate for dirtyrate querying */
+ }
+
+ ret = 0;
+
+ endjob:
+ qemuDomainObjEndJob(driver, vm);
+
+ cleanup:
+ virDomainObjEndAPI(&vm);
+ return ret;
}
--
2.23.0