[PATCH v3 2/5] test_driver: Implement virDomainGetJobStats

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

 



Signed-off-by: Luke Yue <lukedyue@xxxxxxxxx>
---
 src/test/test_driver.c | 135 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 131 insertions(+), 4 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index ae6422c955..9899976966 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -384,6 +384,8 @@ struct _testDomainObjPrivate {
     /* used by Job Info APIs */
     unsigned int jobState;
     unsigned int jobOperation;
+    bool hasCompletedJob;
+    unsigned int jobCompleted;
 };
 
 
@@ -402,6 +404,8 @@ testDomainObjPrivateAlloc(void *opaque)
 
     priv->jobState = VIR_DOMAIN_JOB_NONE;
     priv->jobOperation = VIR_DOMAIN_JOB_OPERATION_UNKNOWN;
+    priv->hasCompletedJob = true;
+    priv->jobCompleted = VIR_DOMAIN_JOB_OPERATION_START;
 
     return priv;
 }
@@ -2683,15 +2687,24 @@ testDomainGetOSType(virDomainPtr dom G_GNUC_UNUSED)
 
 static int
 testDomainGetJobInfoImpl(virDomainObj *dom,
-                         virDomainJobInfoPtr info)
+                         virDomainJobInfoPtr info,
+                         bool completed)
 {
     testDomainObjPrivate *priv = dom->privateData;
 
     memset(info, 0, sizeof(*info));
 
-    info->type = priv->jobState;
+    if (completed) {
+        if (priv->hasCompletedJob) {
+            info->type = VIR_DOMAIN_JOB_COMPLETED;
+        } else {
+            info->type = VIR_DOMAIN_JOB_NONE;
+        }
+    } else {
+        info->type = priv->jobState;
+    }
 
-    switch (priv->jobState) {
+    switch (info->type) {
     case VIR_DOMAIN_JOB_NONE:
         break;
 
@@ -2755,13 +2768,126 @@ testDomainGetJobInfo(virDomainPtr dom,
     if (virDomainObjCheckActive(vm) < 0)
         goto cleanup;
 
-    ret = testDomainGetJobInfoImpl(vm, info);
+    ret = testDomainGetJobInfoImpl(vm, info, false);
 
  cleanup:
     virDomainObjEndAPI(&vm);
     return ret;
 }
 
+static int
+testDomainJobInfoToParams(testDomainObjPrivate *priv,
+                          virDomainJobInfoPtr info,
+                          int *type,
+                          bool completed,
+                          virTypedParameterPtr *params,
+                          int *nparams)
+{
+    virTypedParameterPtr par = NULL;
+    int maxpar = 0;
+    int npar = 0;
+    unsigned int operation = VIR_DOMAIN_JOB_OPERATION_UNKNOWN;
+
+    if (completed) {
+        operation = priv->jobCompleted;
+    } else {
+        operation = priv->jobOperation;
+    }
+
+    if (virTypedParamsAddInt(&par, &npar, &maxpar,
+                             VIR_DOMAIN_JOB_OPERATION,
+                             operation) < 0 ||
+        virTypedParamsAddULLong(&par, &npar, &maxpar,
+                                VIR_DOMAIN_JOB_DATA_TOTAL,
+                                info->dataTotal) < 0 ||
+        virTypedParamsAddULLong(&par, &npar, &maxpar,
+                                VIR_DOMAIN_JOB_DATA_PROCESSED,
+                                info->dataProcessed) < 0 ||
+        virTypedParamsAddULLong(&par, &npar, &maxpar,
+                                VIR_DOMAIN_JOB_DATA_REMAINING,
+                                info->dataRemaining) < 0 ||
+        virTypedParamsAddULLong(&par, &npar, &maxpar,
+                                VIR_DOMAIN_JOB_TIME_ELAPSED,
+                                info->timeElapsed) < 0 ||
+        virTypedParamsAddULLong(&par, &npar, &maxpar,
+                                VIR_DOMAIN_JOB_TIME_REMAINING,
+                                info->timeRemaining) < 0 ||
+        virTypedParamsAddULLong(&par, &npar, &maxpar,
+                                VIR_DOMAIN_JOB_MEMORY_TOTAL,
+                                info->memTotal) < 0 ||
+        virTypedParamsAddULLong(&par, &npar, &maxpar,
+                                VIR_DOMAIN_JOB_MEMORY_PROCESSED,
+                                info->memProcessed) < 0 ||
+        virTypedParamsAddULLong(&par, &npar, &maxpar,
+                                VIR_DOMAIN_JOB_MEMORY_REMAINING,
+                                info->memRemaining) < 0 ||
+        virTypedParamsAddULLong(&par, &npar, &maxpar,
+                                VIR_DOMAIN_JOB_DISK_TOTAL,
+                                info->fileTotal) < 0 ||
+        virTypedParamsAddULLong(&par, &npar, &maxpar,
+                                VIR_DOMAIN_JOB_DISK_PROCESSED,
+                                info->fileProcessed) < 0 ||
+        virTypedParamsAddULLong(&par, &npar, &maxpar,
+                                VIR_DOMAIN_JOB_DISK_REMAINING,
+                                info->fileRemaining) < 0)
+        goto error;
+
+    *type = info->type;
+    *params = par;
+    *nparams = npar;
+    return 0;
+
+ error:
+    virTypedParamsFree(par, npar);
+    return -1;
+}
+
+static int
+testDomainGetJobStats(virDomainPtr domain,
+                      int *type,
+                      virTypedParameterPtr *params,
+                      int *nparams,
+                      unsigned int flags)
+{
+    virDomainJobInfo jobInfo;
+    virDomainObj *dom;
+    testDomainObjPrivate *priv;
+    bool completed = flags & VIR_DOMAIN_JOB_STATS_COMPLETED;
+    int ret = -1;
+
+    virCheckFlags(VIR_DOMAIN_JOB_STATS_COMPLETED |
+                  VIR_DOMAIN_JOB_STATS_KEEP_COMPLETED, -1);
+
+    if (!(dom = testDomObjFromDomain(domain)))
+        return -1;
+
+    priv = dom->privateData;
+
+    if (testDomainGetJobInfoImpl(dom, &jobInfo, completed) < 0)
+        goto cleanup;
+
+    if (jobInfo.type == VIR_DOMAIN_JOB_NONE) {
+        *type = VIR_DOMAIN_JOB_NONE;
+        *params = NULL;
+        *nparams = 0;
+        ret = 0;
+        goto cleanup;
+    }
+
+    ret = testDomainJobInfoToParams(priv, &jobInfo, type,
+                                    completed, params, nparams);
+
+    if (completed && ret == 0 &&
+        !(flags & VIR_DOMAIN_JOB_STATS_KEEP_COMPLETED)) {
+        priv->hasCompletedJob = false;
+        priv->jobCompleted = VIR_DOMAIN_JOB_OPERATION_UNKNOWN;
+    }
+
+ cleanup:
+    virDomainObjEndAPI(&dom);
+
+    return ret;
+}
 
 static int
 testDomainGetLaunchSecurityInfo(virDomainPtr domain G_GNUC_UNUSED,
@@ -9665,6 +9791,7 @@ static virHypervisorDriver testHypervisorDriver = {
     .domainGetBlockInfo = testDomainGetBlockInfo, /* 5.7.0 */
     .domainSetLifecycleAction = testDomainSetLifecycleAction, /* 5.7.0 */
     .domainGetJobInfo = testDomainGetJobInfo, /* 7.7.0 */
+    .domainGetJobStats = testDomainGetJobStats, /* 7.7.0 */
 
     .domainSnapshotNum = testDomainSnapshotNum, /* 1.1.4 */
     .domainSnapshotListNames = testDomainSnapshotListNames, /* 1.1.4 */
-- 
2.32.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