Similar to the qemuDomainSecretDiskPrepare, generate the secret
for the Hostdev's prior to call qemuProcessLaunch which calls
qemuBuildCommandLine. Additionally, since the secret is not longer
added as part of building the command, the hotplug code will need
to make the call to add the secret in the hostdevPriv.
Since this then is the last requirement to pass a virConnectPtr
to qemuBuildCommandLine, we now can remove that as part of these
changes. That removal has cascading effects through various callers.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/qemu/qemu_command.c | 42 ++++++++++------------------
src/qemu/qemu_command.h | 11 +++-----
src/qemu/qemu_domain.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_domain.h | 7 +++++
src/qemu/qemu_driver.c | 3 +-
src/qemu/qemu_hotplug.c | 31 +++++++++++++--------
src/qemu/qemu_hotplug.h | 3 +-
src/qemu/qemu_process.c | 5 ++--
8 files changed, 122 insertions(+), 53 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index a804987..0726abf 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -50,7 +50,6 @@
#include "secret_conf.h"
#include "network/bridge_driver.h"
#include "virnetdevtap.h"
-#include "secret_util.h"
#include "device_conf.h"
#include "virstoragefile.h"
#include "virtpm.h"
@@ -4412,29 +4411,24 @@ qemuBuildSCSIHostHostdevDrvStr(virDomainHostdevDefPtr dev,
}
static char *
-qemuBuildSCSIiSCSIHostdevDrvStr(virConnectPtr conn,
- virDomainHostdevDefPtr dev)
+qemuBuildSCSIiSCSIHostdevDrvStr(virDomainHostdevDefPtr dev)
{
char *source = NULL;
char *secret = NULL;
char *username = NULL;
virStorageSource src;
+ qemuDomainHostdevPrivatePtr hostdevPriv = QEMU_DOMAIN_HOSTDEV_PRIVATE(dev);
memset(&src, 0, sizeof(src));
virDomainHostdevSubsysSCSIPtr scsisrc = &dev->source.subsys.u.scsi;
virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc = &scsisrc->u.iscsi;
- if (conn && iscsisrc->auth) {
- const char *protocol =
- virStorageNetProtocolTypeToString(VIR_STORAGE_NET_PROTOCOL_ISCSI);
- bool encode = false;
- int secretType = VIR_SECRET_USAGE_TYPE_ISCSI;
+ if (hostdevPriv->secinfo) {
+ qemuDomainSecretInfoPtr secinfo = hostdevPriv->secinfo;
- username = iscsisrc->auth->username;
- if (!(secret = virSecretGetSecretString(conn, protocol, encode,
- iscsisrc->auth, secretType)))
- goto cleanup;
+ username = secinfo->s.plain.username;
+ secret = secinfo->s.plain.secret;
}
src.protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI;
@@ -4445,14 +4439,11 @@ qemuBuildSCSIiSCSIHostdevDrvStr(virConnectPtr conn,
/* Rather than pull what we think we want - use the network disk code */
source = qemuBuildNetworkDriveURI(&src, username, secret);
- cleanup:
- VIR_FREE(secret);
return source;
}
char *
-qemuBuildSCSIHostdevDrvStr(virConnectPtr conn,
- virDomainHostdevDefPtr dev,
+qemuBuildSCSIHostdevDrvStr(virDomainHostdevDefPtr dev,
virQEMUCapsPtr qemuCaps,
qemuBuildCommandLineCallbacksPtr callbacks)
{
@@ -4461,7 +4452,7 @@ qemuBuildSCSIHostdevDrvStr(virConnectPtr conn,
virDomainHostdevSubsysSCSIPtr scsisrc = &dev->source.subsys.u.scsi;
if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) {
- if (!(source = qemuBuildSCSIiSCSIHostdevDrvStr(conn, dev)))
+ if (!(source = qemuBuildSCSIiSCSIHostdevDrvStr(dev)))
goto error;
virBufferAsprintf(&buf, "file=%s,if=none,format=raw", source);
} else {
@@ -4760,7 +4751,6 @@ qemuBuildChrChardevStr(virLogManagerPtr logManager,
static int
qemuBuildHostdevCommandLine(virCommandPtr cmd,
- virConnectPtr conn,
const virDomainDef *def,
virQEMUCapsPtr qemuCaps,
qemuBuildCommandLineCallbacksPtr callbacks,
@@ -4910,8 +4900,8 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
char *drvstr;
virCommandAddArg(cmd, "-drive");
- if (!(drvstr = qemuBuildSCSIHostdevDrvStr(conn, hostdev,
- qemuCaps, callbacks)))
+ if (!(drvstr = qemuBuildSCSIHostdevDrvStr(hostdev, qemuCaps,
+ callbacks)))
return -1;
virCommandAddArg(cmd, drvstr);
VIR_FREE(drvstr);
@@ -9148,13 +9138,9 @@ qemuBuildCommandLineCallbacks buildCommandLineCallbacks = {
/*
* Constructs a argv suitable for launching qemu with config defined
* for a given virtual machine.
- *
- * XXX 'conn' is only required to resolve network -> bridge name
- * figure out how to remove this requirement some day
*/
virCommandPtr
-qemuBuildCommandLine(virConnectPtr conn,
- virQEMUDriverPtr driver,
+qemuBuildCommandLine(virQEMUDriverPtr driver,
virLogManagerPtr logManager,
virDomainDefPtr def,
virDomainChrSourceDefPtr monitor_chr,
@@ -9180,9 +9166,9 @@ qemuBuildCommandLine(virConnectPtr conn,
unsigned int bootHostdevNet = 0;
- VIR_DEBUG("conn=%p driver=%p def=%p mon=%p json=%d "
+ VIR_DEBUG("driver=%p def=%p mon=%p json=%d "
"qemuCaps=%p migrateURI=%s snapshot=%p vmop=%d",
- conn, driver, def, monitor_chr, monitor_json,
+ driver, def, monitor_chr, monitor_json,
qemuCaps, migrateURI, snapshot, vmop);
if (qemuBuildCommandLineValidate(driver, def) < 0)
@@ -9348,7 +9334,7 @@ qemuBuildCommandLine(virConnectPtr conn,
if (qemuBuildRedirdevCommandLine(logManager, cmd, def, qemuCaps) < 0)
goto error;
- if (qemuBuildHostdevCommandLine(cmd, conn, def, qemuCaps, callbacks,
+ if (qemuBuildHostdevCommandLine(cmd, def, qemuCaps, callbacks,
&bootHostdevNet) < 0)
goto error;
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 97cd7c6..056bb08 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -58,8 +58,7 @@ char *qemuBuildObjectCommandlineFromJSON(const char *type,
const char *alias,
virJSONValuePtr props);
-virCommandPtr qemuBuildCommandLine(virConnectPtr conn,
- virQEMUDriverPtr driver,
+virCommandPtr qemuBuildCommandLine(virQEMUDriverPtr driver,
virLogManagerPtr logManager,
virDomainDefPtr def,
virDomainChrSourceDefPtr monitor_chr,
@@ -76,8 +75,7 @@ virCommandPtr qemuBuildCommandLine(virConnectPtr conn,
int **nicindexes,
const char *domainLibDir,
const char *domainChannelTargetDir)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(11)
- ATTRIBUTE_NONNULL(17) ATTRIBUTE_NONNULL(18);
+ ATTRIBUTE_NONNULL(10) ATTRIBUTE_NONNULL(16) ATTRIBUTE_NONNULL(17);
/* Generate '-device' string for chardev device */
int
@@ -179,11 +177,10 @@ char *qemuBuildUSBHostdevDevStr(const virDomainDef *def,
virDomainHostdevDefPtr dev,
virQEMUCapsPtr qemuCaps);
-char *qemuBuildSCSIHostdevDrvStr(virConnectPtr conn,
- virDomainHostdevDefPtr dev,
+char *qemuBuildSCSIHostdevDrvStr(virDomainHostdevDefPtr dev,
virQEMUCapsPtr qemuCaps,
qemuBuildCommandLineCallbacksPtr callbacks)
- ATTRIBUTE_NONNULL(4);
+ ATTRIBUTE_NONNULL(3);
char *qemuBuildSCSIHostdevDevStr(const virDomainDef *def,
virDomainHostdevDefPtr dev,
virQEMUCapsPtr qemuCaps);
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 613bea2..ea5e40f 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -923,6 +923,71 @@ qemuDomainSecretDiskPrepare(virConnectPtr conn,
}
+/* qemuDomainSecretHostdevDestroy:
+ * @disk: Pointer to a hostdev definition
+ *
+ * Clear and destroy memory associated with the secret
+ */
+void
+qemuDomainSecretHostdevDestroy(virDomainHostdevDefPtr hostdev)
+{
+ qemuDomainHostdevPrivatePtr hostdevPriv =
+ QEMU_DOMAIN_HOSTDEV_PRIVATE(hostdev);
+
+ if (!hostdevPriv->secinfo)
+ return;
+
+ qemuDomainSecretInfoFree(&hostdevPriv->secinfo);
+}
+
+
+/* qemuDomainSecretHostdevPrepare:
+ * @conn: Pointer to connection
+ * @hostdev: Pointer to a hostdev definition
+ *
+ * For the right host device, generate the qemuDomainSecretInfo structure.
+ *
+ * Returns 0 on success, -1 on failure
+ */
+int
+qemuDomainSecretHostdevPrepare(virConnectPtr conn,
+ virDomainHostdevDefPtr hostdev)
+{
+ virDomainHostdevSubsysPtr subsys = &hostdev->source.subsys;
+ qemuDomainSecretInfoPtr secinfo = NULL;
+
+ if (conn && hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+ subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) {
+
+ virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi;
+ virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc = &scsisrc->u.iscsi;
+
+ if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI
&&
+ iscsisrc->auth) {
+
+ qemuDomainHostdevPrivatePtr hostdevPriv =
+ QEMU_DOMAIN_HOSTDEV_PRIVATE(hostdev);
+
+ if (VIR_ALLOC(secinfo) < 0)
+ return -1;
+
+ if (qemuDomainSecretPlainSetup(conn, secinfo,
+ VIR_STORAGE_NET_PROTOCOL_ISCSI,
+ iscsisrc->auth) < 0)
+ goto error;
+
+ hostdevPriv->secinfo = secinfo;
+ }
+ }
+
+ return 0;
+
+ error:
+ qemuDomainSecretInfoFree(&secinfo);
+ return -1;
+}
+
+
/* qemuDomainSecretDestroy:
* @vm: Domain object
*
@@ -936,6 +1001,9 @@ qemuDomainSecretDestroy(virDomainObjPtr vm)
for (i = 0; i < vm->def->ndisks; i++)
qemuDomainSecretDiskDestroy(vm->def->disks[i]);
+
+ for (i = 0; i < vm->def->nhostdevs; i++)
+ qemuDomainSecretHostdevDestroy(vm->def->hostdevs[i]);
}
@@ -962,6 +1030,11 @@ qemuDomainSecretPrepare(virConnectPtr conn,
return -1;
}
+ for (i = 0; i < vm->def->nhostdevs; i++) {
+ if (qemuDomainSecretHostdevPrepare(conn, vm->def->hostdevs[i]) < 0)
+ return -1;
+ }
+
return 0;
}
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index f343590..1963c58 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -617,6 +617,13 @@ void qemuDomainSecretDiskDestroy(virDomainDiskDefPtr disk)
int qemuDomainSecretDiskPrepare(virConnectPtr conn, virDomainDiskDefPtr disk)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+void qemuDomainSecretHostdevDestroy(virDomainHostdevDefPtr disk)
+ ATTRIBUTE_NONNULL(1);
+
+int qemuDomainSecretHostdevPrepare(virConnectPtr conn,
+ virDomainHostdevDefPtr hostdev)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+
void qemuDomainSecretDestroy(virDomainObjPtr vm)
ATTRIBUTE_NONNULL(1);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1008e58..6b74dac 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7502,8 +7502,7 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm,
case VIR_DOMAIN_DEVICE_NET:
qemuDomainObjCheckNetTaint(driver, vm,
dev->data.net, NULL);
- ret = qemuDomainAttachNetDevice(dom->conn, driver, vm,
-
dev->data.net);
+ ret = qemuDomainAttachNetDevice(driver, vm,
dev->data.net);
if (!ret) {
alias = dev->data.net->info.alias;
dev->data.net = NULL;
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index cd986f9..05fa787 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -808,11 +808,10 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
}
-/* XXX conn required for network -> bridge resolution */
-int qemuDomainAttachNetDevice(virConnectPtr conn,
- virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- virDomainNetDefPtr net)
+int
+qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virDomainNetDefPtr net)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
char **tapfdName = NULL;
@@ -852,8 +851,11 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
* as a hostdev (the hostdev code will reach over into the
* netdev-specific code as appropriate), then also added to
* the nets list (see cleanup:) if successful.
+ *
+ * qemuDomainAttachHostDevice uses a connection to resolve
+ * a SCSI hostdev secret, which is not this case, so pass NULL.
*/
- ret = qemuDomainAttachHostDevice(conn, driver, vm,
+ ret = qemuDomainAttachHostDevice(NULL, driver, vm,
virDomainNetGetActualHostdev(net));
goto cleanup;
}
@@ -1919,6 +1921,7 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver,
return ret;
}
+
static int
qemuDomainAttachHostSCSIDevice(virConnectPtr conn,
virQEMUDriverPtr driver,
@@ -1974,7 +1977,10 @@ qemuDomainAttachHostSCSIDevice(virConnectPtr conn,
if (qemuAssignDeviceHostdevAlias(vm->def, &hostdev->info->alias, -1)
< 0)
goto cleanup;
- if (!(drvstr = qemuBuildSCSIHostdevDrvStr(conn, hostdev, priv->qemuCaps,
+ if (qemuDomainSecretHostdevPrepare(conn, hostdev) < 0)
+ goto cleanup;
+
+ if (!(drvstr = qemuBuildSCSIHostdevDrvStr(hostdev, priv->qemuCaps,
&buildCommandLineCallbacks)))
goto cleanup;
@@ -2011,6 +2017,7 @@ qemuDomainAttachHostSCSIDevice(virConnectPtr conn,
ret = 0;
cleanup:
+ qemuDomainSecretHostdevDestroy(hostdev);
if (ret < 0) {
qemuHostdevReAttachSCSIDevices(driver, vm->def->name, &hostdev, 1);
if (teardowncgroup && qemuTeardownHostdevCgroup(vm, hostdev) < 0)
@@ -2025,10 +2032,12 @@ qemuDomainAttachHostSCSIDevice(virConnectPtr conn,
return ret;
}
-int qemuDomainAttachHostDevice(virConnectPtr conn,
- virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- virDomainHostdevDefPtr hostdev)
+
+int
+qemuDomainAttachHostDevice(virConnectPtr conn,
+ virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virDomainHostdevDefPtr hostdev)
{
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h
index 3358e7d..f3e51c0 100644
--- a/src/qemu/qemu_hotplug.h
+++ b/src/qemu/qemu_hotplug.h
@@ -43,8 +43,7 @@ int qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainDeviceDefPtr dev);
-int qemuDomainAttachNetDevice(virConnectPtr conn,
- virQEMUDriverPtr driver,
+int qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainNetDefPtr net);
int qemuDomainAttachRedirdevDevice(virQEMUDriverPtr driver,
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index aff6852..f4cbe97 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5230,7 +5230,7 @@ qemuProcessLaunch(virConnectPtr conn,
logfile = qemuDomainLogContextGetWriteFD(logCtxt);
VIR_DEBUG("Building emulator command line");
- if (!(cmd = qemuBuildCommandLine(conn, driver,
+ if (!(cmd = qemuBuildCommandLine(driver,
qemuDomainLogContextGetManager(logCtxt),
vm->def, priv->monConfig,
priv->monJSON, priv->qemuCaps,
@@ -5654,8 +5654,7 @@ qemuProcessCreatePretendCmd(virConnectPtr conn,
goto cleanup;
VIR_DEBUG("Building emulator command line");
- cmd = qemuBuildCommandLine(conn,
- driver,
+ cmd = qemuBuildCommandLine(driver,
NULL,
vm->def,
priv->monConfig,
--
2.5.5