Blob Blame History Raw
From 45181b943720b46caf3263c2edbc5c0427870369 Mon Sep 17 00:00:00 2001
Message-Id: <45181b943720b46caf3263c2edbc5c0427870369@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Mon, 16 Mar 2020 22:12:04 +0100
Subject: [PATCH] qemu: Handle hotplug and commandline for secret objects for
 http cookies
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Implement both commandline support and hotplug by adding the http cookie
handling to 'qemuBlockStorageSourceAttachData' handling functions for
it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit b512935b17d991dcdd1a14e39e5f13ca828bd416)

https://bugzilla.redhat.com/show_bug.cgi?id=1804750
Message-Id: <40869b86260516bd56253a39e5dfb54519e5313e.1584391727.git.pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/qemu/qemu_block.c   | 13 +++++++++++++
 src/qemu/qemu_block.h   |  3 +++
 src/qemu/qemu_command.c |  5 +++++
 3 files changed, 21 insertions(+)

diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index e60975a142..f07420b6e2 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -1499,11 +1499,13 @@ qemuBlockStorageSourceAttachDataFree(qemuBlockStorageSourceAttachDataPtr data)
     virJSONValueFree(data->formatProps);
     virJSONValueFree(data->prmgrProps);
     virJSONValueFree(data->authsecretProps);
+    virJSONValueFree(data->httpcookiesecretProps);
     virJSONValueFree(data->encryptsecretProps);
     virJSONValueFree(data->tlsProps);
     VIR_FREE(data->tlsAlias);
     VIR_FREE(data->authsecretAlias);
     VIR_FREE(data->encryptsecretAlias);
+    VIR_FREE(data->httpcookiesecretAlias);
     VIR_FREE(data->driveCmd);
     VIR_FREE(data->driveAlias);
     VIR_FREE(data);
@@ -1570,6 +1572,11 @@ qemuBlockStorageSourceAttachApplyStorageDeps(qemuMonitorPtr mon,
                              &data->authsecretAlias) < 0)
         return -1;
 
+    if (data->httpcookiesecretProps &&
+        qemuMonitorAddObject(mon, &data->httpcookiesecretProps,
+                             &data->httpcookiesecretAlias) < 0)
+        return -1;
+
     if (data->tlsProps &&
         qemuMonitorAddObject(mon, &data->tlsProps, &data->tlsAlias) < 0)
         return -1;
@@ -1713,6 +1720,9 @@ qemuBlockStorageSourceAttachRollback(qemuMonitorPtr mon,
     if (data->encryptsecretAlias)
         ignore_value(qemuMonitorDelObject(mon, data->encryptsecretAlias));
 
+    if (data->httpcookiesecretAlias)
+        ignore_value(qemuMonitorDelObject(mon, data->httpcookiesecretAlias));
+
     if (data->tlsAlias)
         ignore_value(qemuMonitorDelObject(mon, data->tlsAlias));
 
@@ -1768,6 +1778,9 @@ qemuBlockStorageSourceDetachPrepare(virStorageSourcePtr src,
 
         if (srcpriv->encinfo && srcpriv->encinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES)
             data->encryptsecretAlias = g_strdup(srcpriv->encinfo->s.aes.alias);
+
+        if (srcpriv->httpcookie)
+            data->httpcookiesecretAlias = g_strdup(srcpriv->httpcookie->s.aes.alias);
     }
 
     return g_steal_pointer(&data);
diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h
index eab0128d5d..197f5dae97 100644
--- a/src/qemu/qemu_block.h
+++ b/src/qemu/qemu_block.h
@@ -100,6 +100,9 @@ struct qemuBlockStorageSourceAttachData {
     virJSONValuePtr encryptsecretProps;
     char *encryptsecretAlias;
 
+    virJSONValuePtr httpcookiesecretProps;
+    char *httpcookiesecretAlias;
+
     virJSONValuePtr tlsProps;
     char *tlsAlias;
 };
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index fc5366d88d..de97504ce1 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2413,6 +2413,7 @@ qemuBuildBlockStorageSourceAttachDataCommandline(virCommandPtr cmd,
     if (qemuBuildObjectCommandline(cmd, data->prmgrProps) < 0 ||
         qemuBuildObjectCommandline(cmd, data->authsecretProps) < 0 ||
         qemuBuildObjectCommandline(cmd, data->encryptsecretProps) < 0 ||
+        qemuBuildObjectCommandline(cmd, data->httpcookiesecretProps) < 0 ||
         qemuBuildObjectCommandline(cmd, data->tlsProps) < 0)
         return -1;
 
@@ -10349,6 +10350,10 @@ qemuBuildStorageSourceAttachPrepareCommon(virStorageSourcePtr src,
         if (srcpriv->encinfo &&
             qemuBuildSecretInfoProps(srcpriv->encinfo, &data->encryptsecretProps) < 0)
             return -1;
+
+        if (srcpriv->httpcookie &&
+            qemuBuildSecretInfoProps(srcpriv->httpcookie, &data->httpcookiesecretProps) < 0)
+            return -1;
     }
 
     if (src->haveTLS == VIR_TRISTATE_BOOL_YES &&
-- 
2.25.1