[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[PATCH 12/17] qemu: domain: Extract preparation of hostdev specific data to a separate function



Historically we've prepared secrets for all objects in one place. This
doesn't make much sense and it's semantically more appealing to prepare
everything for a single device type in one place.

Move the setup of the (iSCSI|SCSI) hostdev secrets into a new function
which will be used to setup other things as well in the future.

This is a similar approach we do for disks.

Signed-off-by: Peter Krempa <pkrempa redhat com>
---
 src/qemu/qemu_domain.c  | 59 ++++++++++++++++++++++++++++++++++++-----
 src/qemu/qemu_domain.h  |  4 +++
 src/qemu/qemu_hotplug.c |  2 +-
 src/qemu/qemu_process.c | 21 +++++++++++++++
 4 files changed, 78 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 89f2c2c09b..1289201764 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1596,13 +1596,7 @@ qemuDomainSecretPrepare(virQEMUDriverPtr driver,
     g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
     size_t i;

-    /* disk secrets are prepared when preparing disks */
-
-    for (i = 0; i < vm->def->nhostdevs; i++) {
-        if (qemuDomainSecretHostdevPrepare(priv,
-                                           vm->def->hostdevs[i]) < 0)
-            return -1;
-    }
+    /* disk and hostdev secrets are prepared when preparing internal data */

     for (i = 0; i < vm->def->nserials; i++) {
         if (qemuDomainSecretChardevPrepare(cfg, priv,
@@ -10455,6 +10449,57 @@ qemuDomainPrepareDiskSource(virDomainDiskDefPtr disk,
 }


+int
+qemuDomainPrepareHostdev(virDomainHostdevDefPtr hostdev,
+                         qemuDomainObjPrivatePtr priv)
+{
+    if (virHostdevIsSCSIDevice(hostdev)) {
+        virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi;
+        virStorageSourcePtr src = NULL;
+
+        switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) {
+        case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE:
+            break;
+
+        case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI:
+            src = scsisrc->u.iscsi.src;
+            break;
+
+        case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_LAST:
+        default:
+            virReportEnumRangeError(virDomainHostdevSCSIProtocolType, scsisrc->protocol);
+            return -1;
+        }
+
+        if (src) {
+            if (src->auth) {
+                bool iscsiHasPS = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_ISCSI_PASSWORD_SECRET);
+                virSecretUsageType usageType = VIR_SECRET_USAGE_TYPE_ISCSI;
+                qemuDomainStorageSourcePrivatePtr srcPriv = qemuDomainStorageSourcePrivateFetch(src);
+
+                if (!qemuDomainSupportsEncryptedSecret(priv) || !iscsiHasPS) {
+                    srcPriv->secinfo = qemuDomainSecretInfoNewPlain(usageType,
+                                                                    src->auth->username,
+                                                                    &src->auth->seclookupdef);
+                } else {
+                    srcPriv->secinfo = qemuDomainSecretAESSetupFromSecret(priv,
+                                                                          hostdev->info->alias,
+                                                                          NULL,
+                                                                          usageType,
+                                                                          src->auth->username,
+                                                                          &src->auth->seclookupdef);
+                }
+
+                if (!srcPriv->secinfo)
+                    return -1;
+            }
+        }
+    }
+
+    return 0;
+}
+
+
 /**
  * qemuDomainDiskCachemodeFlags:
  *
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index adba79aded..6abd896119 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -970,6 +970,10 @@ qemuDomainDiskCachemodeFlags(int cachemode,
                              bool *direct,
                              bool *noflush);

+int
+qemuDomainPrepareHostdev(virDomainHostdevDefPtr hostdev,
+                         qemuDomainObjPrivatePtr priv);
+
 char * qemuDomainGetManagedPRSocketPath(qemuDomainObjPrivatePtr priv);

 bool qemuDomainDefHasManagedPR(virDomainObjPtr vm);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index e2c6e14c2e..f20b8e9a56 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2604,7 +2604,7 @@ qemuDomainAttachHostSCSIDevice(virQEMUDriverPtr driver,
     if (qemuAssignDeviceHostdevAlias(vm->def, &hostdev->info->alias, -1) < 0)
         goto cleanup;

-    if (qemuDomainSecretHostdevPrepare(priv, hostdev) < 0)
+    if (qemuDomainPrepareHostdev(hostdev, priv) < 0)
         goto cleanup;

     if (!(data = qemuBuildHostdevSCSIAttachPrepare(hostdev, &backendalias,
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index dd60fb0ddf..79e72aaf2a 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6213,6 +6213,23 @@ qemuProcessPrepareDomainStorage(virQEMUDriverPtr driver,
 }


+static int
+qemuProcessPrepareDomainHostdevs(virDomainObjPtr vm,
+                                 qemuDomainObjPrivatePtr priv)
+{
+    size_t i;
+
+    for (i = 0; i < vm->def->nhostdevs; i++) {
+        virDomainHostdevDefPtr hostdev = vm->def->hostdevs[i];
+
+        if (qemuDomainPrepareHostdev(hostdev, priv) < 0)
+            return -1;
+    }
+
+    return 0;
+}
+
+
 static void
 qemuProcessPrepareAllowReboot(virDomainObjPtr vm)
 {
@@ -6315,6 +6332,10 @@ qemuProcessPrepareDomain(virQEMUDriverPtr driver,
     if (qemuProcessPrepareDomainStorage(driver, vm, priv, cfg, flags) < 0)
         return -1;

+    VIR_DEBUG("Setting up host devices");
+    if (qemuProcessPrepareDomainHostdevs(vm, priv) < 0)
+        return -1;
+
     VIR_DEBUG("Prepare chardev source backends for TLS");
     qemuDomainPrepareChardevSource(vm->def, cfg);

-- 
2.26.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]