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

[libvirt] [PATCH 3/4] qemu: Implement note API in qemu driver



This patch adds support for the new api to change domain descriptions to
the qemu driver.
---
 src/qemu/qemu_driver.c |   70 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 70 insertions(+), 0 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 712f1fc..7b935f0 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -11831,6 +11831,75 @@ cleanup:
     return ret;
 }

+static int
+qemuDomainSetDescription(virDomainPtr dom, const char *description,
+                         unsigned int flags)
+{
+    struct qemud_driver *driver = dom->conn->privateData;
+    virDomainObjPtr vm;
+    virDomainDefPtr persistentDef;
+    int ret = -1;
+
+    virCheckFlags(VIR_DOMAIN_DESCRIPTION_CURRENT |
+                  VIR_DOMAIN_DESCRIPTION_LIVE |
+                  VIR_DOMAIN_DESCRIPTION_CONFIG |
+                  VIR_DOMAIN_DESCRIPTION_NOTE, -1);
+
+    bool note = (flags | VIR_DOMAIN_DESCRIPTION_NOTE) > 0;
+
+    qemuDriverLock(driver);
+    vm = virDomainFindByUUID(&driver->domains, dom->uuid);
+    qemuDriverUnlock(driver);
+
+    if (!vm) {
+        char uuidstr[VIR_UUID_STRING_BUFLEN];
+        virUUIDFormat(dom->uuid, uuidstr);
+        qemuReportError(VIR_ERR_NO_DOMAIN,
+                        _("no domain with matching uuid '%s'"), uuidstr);
+        goto cleanup;
+    }
+
+    if (virDomainLiveConfigHelperMethod(driver->caps, vm, &flags,
+                                        &persistentDef) < 0)
+        goto cleanup;
+
+    if (flags | VIR_DOMAIN_DESCRIPTION_LIVE) {
+        if (note) {
+            VIR_FREE(vm->def->note);
+            if (!(vm->def->note = strdup(description)))
+                goto oom;
+        } else {
+            VIR_FREE(vm->def->description);
+            if (!(vm->def->description = strdup(description)))
+                goto oom;
+        }
+    }
+
+    if (flags | VIR_DOMAIN_DESCRIPTION_CONFIG) {
+        if (note) {
+            VIR_FREE(persistentDef->note);
+            if (!(persistentDef->note = strdup(description)))
+                goto oom;
+        } else {
+            VIR_FREE(persistentDef->description);
+            if (!(persistentDef->description = strdup(description)))
+                goto oom;
+        }
+    }
+
+    ret = 0;
+
+cleanup:
+    if (vm)
+        virDomainObjUnlock(vm);
+    return ret;
+oom:
+    if (vm)
+        virDomainObjUnlock(vm);
+    virReportOOMError();
+    return -1;
+}
+
 static virDriver qemuDriver = {
     .no = VIR_DRV_QEMU,
     .name = "QEMU",
@@ -11983,6 +12052,7 @@ static virDriver qemuDriver = {
     .domainGetNumaParameters = qemuDomainGetNumaParameters, /* 0.9.9 */
     .domainGetInterfaceParameters = qemuDomainGetInterfaceParameters, /* 0.9.9 */
     .domainSetInterfaceParameters = qemuDomainSetInterfaceParameters, /* 0.9.9 */
+    .domainSetDescription = qemuDomainSetDescription, /* 0.9.10 */
 };


-- 
1.7.3.4


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