Re: [PATCH v6 1/5] migration/dirtyrate: Introduce virDomainStartDirtyRateCalc API

2021-03-03 Thread Michal Privoznik

On 2/26/21 9:35 AM, Hao Wang wrote:

Introduce virDomainStartDirtyRateCalc API for start calculation of
a domain's memory dirty rate with a specified time.

Signed-off-by: Hao Wang 
---
  include/libvirt/libvirt-domain.h |  4 +++
  src/driver-hypervisor.h  |  6 +
  src/libvirt-domain.c | 44 
  src/libvirt_public.syms  |  5 
  src/remote/remote_driver.c   |  1 +
  src/remote/remote_protocol.x | 14 +-
  src/remote_protocol-structs  |  6 +
  7 files changed, 79 insertions(+), 1 deletion(-)




diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 4af0166872..b1cc2ebbf3 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -13154,3 +13154,47 @@ virDomainGetMessages(virDomainPtr domain,
  virDispatchError(conn);
  return -1;
  }
+
+
+/**
+ * virDomainStartDirtyRateCalc:
+ * @domain: a domain object
+ * @seconds: specified calculating time in seconds
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Calculate the current domain's memory dirty rate in next @seconds.
+ * The calculated dirty rate infomation is available by calling


information


+ * virConnectGetAllDomainStats.
+ *
+ * Returns 0 in case of success, -1 otherwise.
+ */
+int
+virDomainStartDirtyRateCalc(virDomainPtr domain,
+int seconds,
+unsigned int flags)
+{
+virConnectPtr conn;
+
+VIR_DOMAIN_DEBUG(domain, "seconds=%d, flags=0x%x", seconds, flags);
+
+virResetLastError();
+
+virCheckDomainReturn(domain, -1);
+conn = domain->conn;
+
+virCheckReadOnlyGoto(conn->flags, error);
+
+if (conn->driver->domainStartDirtyRateCalc) {
+int ret;
+ret = conn->driver->domainStartDirtyRateCalc(domain, seconds, flags);
+if (ret < 0)
+goto error;
+return ret;
+}
+
+virReportUnsupportedError();
+
+ error:
+virDispatchError(conn);
+return -1;
+}


Michal



[PATCH v6 1/5] migration/dirtyrate: Introduce virDomainStartDirtyRateCalc API

2021-02-26 Thread Hao Wang
Introduce virDomainStartDirtyRateCalc API for start calculation of
a domain's memory dirty rate with a specified time.

Signed-off-by: Hao Wang 
---
 include/libvirt/libvirt-domain.h |  4 +++
 src/driver-hypervisor.h  |  6 +
 src/libvirt-domain.c | 44 
 src/libvirt_public.syms  |  5 
 src/remote/remote_driver.c   |  1 +
 src/remote/remote_protocol.x | 14 +-
 src/remote_protocol-structs  |  6 +
 7 files changed, 79 insertions(+), 1 deletion(-)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 8011cf9fe1..7aa5ef4543 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -5128,4 +5128,8 @@ int virDomainGetMessages(virDomainPtr domain,
  char ***msgs,
  unsigned int flags);
 
+int virDomainStartDirtyRateCalc(virDomainPtr domain,
+int seconds,
+unsigned int flags);
+
 #endif /* LIBVIRT_DOMAIN_H */
diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
index 05d7dfb5c7..2ec7b8b24a 100644
--- a/src/driver-hypervisor.h
+++ b/src/driver-hypervisor.h
@@ -1405,6 +1405,11 @@ typedef int
char ***msgs,
unsigned int flags);
 
+typedef int
+(*virDrvDomainStartDirtyRateCalc)(virDomainPtr domain,
+  int seconds,
+  unsigned int flags);
+
 typedef struct _virHypervisorDriver virHypervisorDriver;
 typedef virHypervisorDriver *virHypervisorDriverPtr;
 
@@ -1671,4 +1676,5 @@ struct _virHypervisorDriver {
 virDrvDomainAuthorizedSSHKeysGet domainAuthorizedSSHKeysGet;
 virDrvDomainAuthorizedSSHKeysSet domainAuthorizedSSHKeysSet;
 virDrvDomainGetMessages domainGetMessages;
+virDrvDomainStartDirtyRateCalc domainStartDirtyRateCalc;
 };
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 4af0166872..b1cc2ebbf3 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -13154,3 +13154,47 @@ virDomainGetMessages(virDomainPtr domain,
 virDispatchError(conn);
 return -1;
 }
+
+
+/**
+ * virDomainStartDirtyRateCalc:
+ * @domain: a domain object
+ * @seconds: specified calculating time in seconds
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Calculate the current domain's memory dirty rate in next @seconds.
+ * The calculated dirty rate infomation is available by calling
+ * virConnectGetAllDomainStats.
+ *
+ * Returns 0 in case of success, -1 otherwise.
+ */
+int
+virDomainStartDirtyRateCalc(virDomainPtr domain,
+int seconds,
+unsigned int flags)
+{
+virConnectPtr conn;
+
+VIR_DOMAIN_DEBUG(domain, "seconds=%d, flags=0x%x", seconds, flags);
+
+virResetLastError();
+
+virCheckDomainReturn(domain, -1);
+conn = domain->conn;
+
+virCheckReadOnlyGoto(conn->flags, error);
+
+if (conn->driver->domainStartDirtyRateCalc) {
+int ret;
+ret = conn->driver->domainStartDirtyRateCalc(domain, seconds, flags);
+if (ret < 0)
+goto error;
+return ret;
+}
+
+virReportUnsupportedError();
+
+ error:
+virDispatchError(conn);
+return -1;
+}
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index d851333eb0..51a3d7265a 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -884,4 +884,9 @@ LIBVIRT_7.1.0 {
 virDomainGetMessages;
 } LIBVIRT_6.10.0;
 
+LIBVIRT_7.2.0 {
+global:
+virDomainStartDirtyRateCalc;
+} LIBVIRT_7.1.0;
+
 #  define new API here using predicted next version number 
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index a83cd866e7..3968472931 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -8575,6 +8575,7 @@ static virHypervisorDriver hypervisor_driver = {
 .domainAuthorizedSSHKeysGet = remoteDomainAuthorizedSSHKeysGet, /* 6.10.0 
*/
 .domainAuthorizedSSHKeysSet = remoteDomainAuthorizedSSHKeysSet, /* 6.10.0 
*/
 .domainGetMessages = remoteDomainGetMessages, /* 7.1.0 */
+.domainStartDirtyRateCalc = remoteDomainStartDirtyRateCalc, /* 7.2.0 */
 };
 
 static virNetworkDriver network_driver = {
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index d3724bc305..7fdc65f029 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -3811,6 +3811,12 @@ struct remote_domain_get_messages_ret {
 remote_nonnull_string msgs;
 };
 
+struct remote_domain_start_dirty_rate_calc_args {
+remote_nonnull_domain dom;
+int seconds;
+unsigned int flags;
+};
+
 
 /*- Protocol. -*/
 
@@ -6733,5 +6739,11 @@ enum remote_procedure {
  * @generate: none
  * @acl: domain:read
  */
-REMOTE_PROC_DOMAIN_GET_MESSAGES = 426
+REMOTE_PROC_DOMAIN_GET_MESSAGES = 426,
+
+