fbe740
From 1c5d21527ce3cb5182434d206d589a85b1901b42 Mon Sep 17 00:00:00 2001
fbe740
Message-Id: <1c5d21527ce3cb5182434d206d589a85b1901b42@dist-git>
fbe740
From: Peter Krempa <pkrempa@redhat.com>
fbe740
Date: Mon, 16 Mar 2020 22:11:52 +0100
fbe740
Subject: [PATCH] qemu: Split out initialization of secrets for 'iscsi'
fbe740
 hostdevs
fbe740
MIME-Version: 1.0
fbe740
Content-Type: text/plain; charset=UTF-8
fbe740
Content-Transfer-Encoding: 8bit
fbe740
fbe740
Currently we don't have infrastructure to remember the secret aliases
fbe740
for hostdevs. Since an upcoming patch is going to change aliases for
fbe740
the disks, initialize the iscsi hostdevs separately so that we can keep
fbe740
the alias. At the same time let's use qemuAliasForSecret instead of
fbe740
qemuDomainGetSecretAESAlias when unplugging the iscsi hostdev.
fbe740
fbe740
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
(cherry picked from commit 740dd1a4e5ce81e5b0be855dd413dd7eec81ccd3)
fbe740
fbe740
https://bugzilla.redhat.com/show_bug.cgi?id=1804750
fbe740
Message-Id: <f4157def83aa59b7432c6e0714d621ff5b2bed4a.1584391726.git.pkrempa@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
---
fbe740
 src/qemu/qemu_domain.c  | 25 +++++++++++++++++++++++--
fbe740
 src/qemu/qemu_hotplug.c |  2 +-
fbe740
 2 files changed, 24 insertions(+), 3 deletions(-)
fbe740
fbe740
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
fbe740
index 897e21726a..0047a1d316 100644
fbe740
--- a/src/qemu/qemu_domain.c
fbe740
+++ b/src/qemu/qemu_domain.c
fbe740
@@ -1848,8 +1848,29 @@ qemuDomainSecretHostdevPrepare(qemuDomainObjPrivatePtr priv,
fbe740
 
fbe740
         if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI &&
fbe740
             src->auth) {
fbe740
-            if (qemuDomainSecretStorageSourcePrepare(priv, src,
fbe740
-                                                     hostdev->info->alias, NULL) < 0)
fbe740
+            bool iscsiHasPS = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_ISCSI_PASSWORD_SECRET);
fbe740
+            virSecretUsageType usageType = VIR_SECRET_USAGE_TYPE_ISCSI;
fbe740
+            qemuDomainStorageSourcePrivatePtr srcPriv;
fbe740
+
fbe740
+            if (!(src->privateData = qemuDomainStorageSourcePrivateNew()))
fbe740
+                return -1;
fbe740
+
fbe740
+            srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
fbe740
+
fbe740
+            if (!qemuDomainSupportsEncryptedSecret(priv) || !iscsiHasPS) {
fbe740
+                srcPriv->secinfo = qemuDomainSecretInfoNewPlain(usageType,
fbe740
+                                                                src->auth->username,
fbe740
+                                                                &src->auth->seclookupdef);
fbe740
+            } else {
fbe740
+                srcPriv->secinfo = qemuDomainSecretAESSetupFromSecret(priv,
fbe740
+                                                                      hostdev->info->alias,
fbe740
+                                                                      usageType,
fbe740
+                                                                      src->auth->username,
fbe740
+                                                                      &src->auth->seclookupdef,
fbe740
+                                                                      false);
fbe740
+            }
fbe740
+
fbe740
+            if (!srcPriv->secinfo)
fbe740
                 return -1;
fbe740
         }
fbe740
     }
fbe740
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
fbe740
index 12bc1f9dd5..a473bab3e1 100644
fbe740
--- a/src/qemu/qemu_hotplug.c
fbe740
+++ b/src/qemu/qemu_hotplug.c
fbe740
@@ -4438,7 +4438,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
fbe740
         if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI &&
fbe740
             virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_ISCSI_PASSWORD_SECRET) &&
fbe740
             qemuDomainStorageSourceHasAuth(iscsisrc->src)) {
fbe740
-            if (!(objAlias = qemuDomainGetSecretAESAlias(hostdev->info->alias, false)))
fbe740
+            if (!(objAlias = qemuAliasForSecret(hostdev->info->alias, NULL)))
fbe740
                 return -1;
fbe740
         }
fbe740
 
fbe740
-- 
fbe740
2.25.1
fbe740