[libvirt] [PATCH] libxl: Implement domain metadata getter/setter

Michal Privoznik posted 1 patch 5 years, 3 months ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/46edf7b92c3e32733c4ee20fab6c07f25b6eacc3.1564995213.git.mprivozn@redhat.com
src/libxl/libxl_driver.c | 67 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
[libvirt] [PATCH] libxl: Implement domain metadata getter/setter
Posted by Michal Privoznik 5 years, 3 months ago
Fortunately, the code that handles metadata getting or setting is
driver agnostic, so all that is needed from individual hypervisor
drivers is to call the right functions.

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

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/libxl/libxl_driver.c | 67 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 492028c487..ca01f620c7 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -6515,6 +6515,70 @@ libxlConnectBaselineCPU(virConnectPtr conn,
     return cpustr;
 }
 
+static int
+libxlDomainSetMetadata(virDomainPtr dom,
+                       int type,
+                       const char *metadata,
+                       const char *key,
+                       const char *uri,
+                       unsigned int flags)
+{
+    libxlDriverPrivatePtr driver = dom->conn->privateData;
+    VIR_AUTOUNREF(libxlDriverConfigPtr) cfg = libxlDriverConfigGet(driver);
+    virDomainObjPtr vm = NULL;
+    int ret = -1;
+
+    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
+                  VIR_DOMAIN_AFFECT_CONFIG, -1);
+
+    if (!(vm = libxlDomObjFromDomain(dom)))
+        return -1;
+
+    if (virDomainSetMetadataEnsureACL(dom->conn, vm->def, flags) < 0)
+        goto cleanup;
+
+    if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
+        goto cleanup;
+
+    ret = virDomainObjSetMetadata(vm, type, metadata, key, uri, cfg->caps,
+                                  driver->xmlopt, cfg->stateDir,
+                                  cfg->configDir, flags);
+
+    if (ret == 0) {
+        virObjectEventPtr ev = NULL;
+        ev = virDomainEventMetadataChangeNewFromObj(vm, type, uri);
+        virObjectEventStateQueue(driver->domainEventState, ev);
+    }
+
+    libxlDomainObjEndJob(driver, vm);
+
+ cleanup:
+    virDomainObjEndAPI(&vm);
+    return ret;
+}
+
+static char *
+libxlDomainGetMetadata(virDomainPtr dom,
+                       int type,
+                       const char *uri,
+                       unsigned int flags)
+{
+    virDomainObjPtr vm;
+    char *ret = NULL;
+
+    if (!(vm = libxlDomObjFromDomain(dom)))
+        return NULL;
+
+    if (virDomainGetMetadataEnsureACL(dom->conn, vm->def) < 0)
+        goto cleanup;
+
+    ret = virDomainObjGetMetadata(vm, type, uri, flags);
+
+ cleanup:
+    virDomainObjEndAPI(&vm);
+    return ret;
+}
+
 static virHypervisorDriver libxlHypervisorDriver = {
     .name = LIBXL_DRIVER_NAME,
     .connectURIProbe = libxlConnectURIProbe,
@@ -6628,6 +6692,9 @@ static virHypervisorDriver libxlHypervisorDriver = {
     .connectGetDomainCapabilities = libxlConnectGetDomainCapabilities, /* 2.0.0 */
     .connectCompareCPU = libxlConnectCompareCPU, /* 2.3.0 */
     .connectBaselineCPU = libxlConnectBaselineCPU, /* 2.3.0 */
+    .domainSetMetadata = libxlDomainSetMetadata, /* 5.7.0 */
+    .domainGetMetadata = libxlDomainGetMetadata, /* 5.7.0 */
+
 };
 
 static virConnectDriver libxlConnectDriver = {
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] libxl: Implement domain metadata getter/setter
Posted by Erik Skultety 5 years, 3 months ago
On Mon, Aug 05, 2019 at 10:53:33AM +0200, Michal Privoznik wrote:
> Fortunately, the code that handles metadata getting or setting is
> driver agnostic, so all that is needed from individual hypervisor
> drivers is to call the right functions.
>
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1732306
>
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list