Blob Blame History Raw
From 9c171ebceeed9cf28f0e86e0de604805e3669bdf Mon Sep 17 00:00:00 2001
Message-Id: <9c171ebceeed9cf28f0e86e0de604805e3669bdf@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Thu, 22 Jan 2015 15:53:48 +0100
Subject: [PATCH] lxc: Add metadata modification APIs

https://bugzilla.redhat.com/show_bug.cgi?id=1184929

(cherry picked from commit f9c7b32e5de3fb0ccf2e0858716886bdb35a9913)

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/lxc/lxc_driver.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 1aaa6e7..e9f2f51 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -4702,6 +4702,74 @@ lxcNodeSuspendForDuration(virConnectPtr conn,
 }
 
 
+static int
+lxcDomainSetMetadata(virDomainPtr dom,
+                      int type,
+                      const char *metadata,
+                      const char *key,
+                      const char *uri,
+                      unsigned int flags)
+{
+    virLXCDriverPtr driver = dom->conn->privateData;
+    virDomainObjPtr vm;
+    virLXCDriverConfigPtr cfg = NULL;
+    virCapsPtr caps = NULL;
+    int ret = -1;
+
+    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
+                  VIR_DOMAIN_AFFECT_CONFIG, -1);
+
+    if (!(vm = lxcDomObjFromDomain(dom)))
+        return -1;
+
+    cfg = virLXCDriverGetConfig(driver);
+
+    if (virDomainSetMetadataEnsureACL(dom->conn, vm->def, flags) < 0)
+        goto cleanup;
+
+    if (!(caps = virLXCDriverGetCapabilities(driver, false)))
+        goto cleanup;
+
+    ret = virDomainObjSetMetadata(vm, type, metadata, key, uri, caps,
+                                  driver->xmlopt, cfg->configDir, flags);
+
+cleanup:
+    virObjectUnlock(vm);
+    virObjectUnref(caps);
+    virObjectUnref(cfg);
+    return ret;
+}
+
+
+static char *
+lxcDomainGetMetadata(virDomainPtr dom,
+                      int type,
+                      const char *uri,
+                      unsigned int flags)
+{
+    virLXCDriverPtr driver = dom->conn->privateData;
+    virCapsPtr caps = NULL;
+    virDomainObjPtr vm;
+    char *ret = NULL;
+
+    if (!(vm = lxcDomObjFromDomain(dom)))
+        return NULL;
+
+    if (virDomainGetMetadataEnsureACL(dom->conn, vm->def) < 0)
+        goto cleanup;
+
+    if (!(caps = virLXCDriverGetCapabilities(driver, false)))
+        goto cleanup;
+
+    ret = virDomainObjGetMetadata(vm, type, uri, caps, driver->xmlopt, flags);
+
+cleanup:
+    virObjectUnlock(vm);
+    virObjectUnref(caps);
+    return ret;
+}
+
+
 /* Function Tables */
 static virDriver lxcDriver = {
     .no = VIR_DRV_LXC,
@@ -4776,6 +4844,8 @@ static virDriver lxcDriver = {
     .domainOpenConsole = lxcDomainOpenConsole, /* 0.8.6 */
     .connectIsAlive = lxcConnectIsAlive, /* 0.9.8 */
     .nodeSuspendForDuration = lxcNodeSuspendForDuration, /* 0.9.8 */
+    .domainSetMetadata = lxcDomainSetMetadata, /* 1.1.3 */
+    .domainGetMetadata = lxcDomainGetMetadata, /* 1.1.3 */
     .nodeGetMemoryParameters = lxcNodeGetMemoryParameters, /* 0.10.2 */
     .nodeSetMemoryParameters = lxcNodeSetMemoryParameters, /* 0.10.2 */
     .domainSendProcessSignal = lxcDomainSendProcessSignal, /* 1.0.1 */
-- 
2.2.1