[libvirt] [PATCH 5/8] lxc: implement description API in LXC driver.

Peter Krempa pkrempa at redhat.com
Wed Jan 18 14:24:02 UTC 2012


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

diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 3baff19..d26bfe9 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -3802,6 +3802,75 @@ cleanup:
 }

 static int
+lxcDomainSetDescription(virDomainPtr dom, const char *description,
+                        unsigned int flags)
+{
+    lxc_driver_t *driver = dom->conn->privateData;
+    virDomainObjPtr vm;
+    virDomainDefPtr persistentDef;
+    int ret = -1;
+
+    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
+                  VIR_DOMAIN_AFFECT_CONFIG |
+                  VIR_DOMAIN_DESCRIPTION_TITLE, -1);
+
+    bool title = (flags & VIR_DOMAIN_DESCRIPTION_TITLE) > 0;
+
+    lxcDriverLock(driver);
+    vm = virDomainFindByUUID(&driver->domains, dom->uuid);
+    lxcDriverUnlock(driver);
+
+    if (!vm) {
+        char uuidstr[VIR_UUID_STRING_BUFLEN];
+        virUUIDFormat(dom->uuid, uuidstr);
+        lxcError(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_AFFECT_LIVE) {
+        if (title) {
+            VIR_FREE(vm->def->title);
+            if (!(vm->def->title = strdup(description)))
+                goto no_memory;
+        } else {
+            VIR_FREE(vm->def->description);
+            if (!(vm->def->description = strdup(description)))
+                goto no_memory;
+        }
+    }
+
+    if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
+        if (title) {
+            VIR_FREE(persistentDef->title);
+            if (!(persistentDef->title = strdup(description)))
+                goto no_memory;
+        } else {
+            VIR_FREE(persistentDef->description);
+            if (!(persistentDef->description = strdup(description)))
+                goto no_memory;
+        }
+
+        if (virDomainSaveConfig(driver->configDir, persistentDef) < 0)
+            goto cleanup;
+    }
+
+    ret = 0;
+
+cleanup:
+    if (vm)
+        virDomainObjUnlock(vm);
+    return ret;
+no_memory:
+    virReportOOMError();
+    goto cleanup;
+}
+
+static int
 lxcVMFilterRebuild(virConnectPtr conn ATTRIBUTE_UNUSED,
                    virHashIterator iter, void *data)
 {
@@ -3891,6 +3960,7 @@ static virDriver lxcDriver = {
     .domainOpenConsole = lxcDomainOpenConsole, /* 0.8.6 */
     .isAlive = lxcIsAlive, /* 0.9.8 */
     .nodeSuspendForDuration = nodeSuspendForDuration, /* 0.9.8 */
+    .domainSetDescription = lxcDomainSetDescription, /* 0.9.10 */
 };

 static virStateDriver lxcStateDriver = {
-- 
1.7.3.4




More information about the libvir-list mailing list