mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-23 04:55:18 +00:00
qemu: Tolerate storage source private data being NULL
In some cases it does not make sense to pursue that the private data will be allocated (especially when we don't need to put anything in it). Ensure that the code works without it. This also fixes few crashes pointed out in https://bugzilla.redhat.com/show_bug.cgi?id=1510323
This commit is contained in:
parent
994c49ac34
commit
8056721cbb
@ -1501,12 +1501,17 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
|
||||
{
|
||||
int actualType = virStorageSourceGetActualType(disk->src);
|
||||
qemuDomainStorageSourcePrivatePtr srcpriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(disk->src);
|
||||
qemuDomainSecretInfoPtr secinfo = srcpriv->secinfo;
|
||||
qemuDomainSecretInfoPtr encinfo = srcpriv->encinfo;
|
||||
qemuDomainSecretInfoPtr secinfo = NULL;
|
||||
qemuDomainSecretInfoPtr encinfo = NULL;
|
||||
virJSONValuePtr srcprops = NULL;
|
||||
char *source = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (srcpriv) {
|
||||
secinfo = srcpriv->secinfo;
|
||||
encinfo = srcpriv->encinfo;
|
||||
}
|
||||
|
||||
if (qemuDiskSourceNeedsProps(disk->src) &&
|
||||
!(srcprops = qemuDiskSourceGetProps(disk->src)))
|
||||
goto cleanup;
|
||||
@ -2191,8 +2196,13 @@ qemuBuildDiskDriveCommandLine(virCommandPtr cmd,
|
||||
bool driveBoot = false;
|
||||
virDomainDiskDefPtr disk = def->disks[i];
|
||||
qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(disk->src);
|
||||
qemuDomainSecretInfoPtr secinfo = srcPriv->secinfo;
|
||||
qemuDomainSecretInfoPtr encinfo = srcPriv->encinfo;
|
||||
qemuDomainSecretInfoPtr secinfo = NULL;
|
||||
qemuDomainSecretInfoPtr encinfo = NULL;
|
||||
|
||||
if (srcPriv) {
|
||||
secinfo = srcPriv->secinfo;
|
||||
encinfo = srcPriv->encinfo;
|
||||
}
|
||||
|
||||
if (disk->info.bootIndex) {
|
||||
bootindex = disk->info.bootIndex;
|
||||
|
@ -259,6 +259,7 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
|
||||
qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(disk->src);
|
||||
qemuDomainSecretInfoPtr secinfo = NULL;
|
||||
const char *format = NULL;
|
||||
char *sourcestr = NULL;
|
||||
|
||||
@ -268,6 +269,9 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (srcPriv)
|
||||
secinfo = srcPriv->secinfo;
|
||||
|
||||
if (disk->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY &&
|
||||
disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
@ -300,7 +304,7 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
|
||||
}
|
||||
|
||||
if (!virStorageSourceIsEmpty(newsrc)) {
|
||||
if (qemuGetDriveSourceString(newsrc, srcPriv->secinfo, &sourcestr) < 0)
|
||||
if (qemuGetDriveSourceString(newsrc, secinfo, &sourcestr) < 0)
|
||||
goto error;
|
||||
|
||||
if (virStorageSourceGetActualType(newsrc) != VIR_STORAGE_TYPE_DIR) {
|
||||
@ -371,8 +375,8 @@ qemuDomainAttachDiskGeneric(virConnectPtr conn,
|
||||
virJSONValuePtr secobjProps = NULL;
|
||||
virJSONValuePtr encobjProps = NULL;
|
||||
qemuDomainStorageSourcePrivatePtr srcPriv;
|
||||
qemuDomainSecretInfoPtr secinfo;
|
||||
qemuDomainSecretInfoPtr encinfo;
|
||||
qemuDomainSecretInfoPtr secinfo = NULL;
|
||||
qemuDomainSecretInfoPtr encinfo = NULL;
|
||||
|
||||
if (qemuDomainPrepareDisk(driver, vm, disk, NULL, false) < 0)
|
||||
goto cleanup;
|
||||
@ -384,13 +388,16 @@ qemuDomainAttachDiskGeneric(virConnectPtr conn,
|
||||
goto error;
|
||||
|
||||
srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(disk->src);
|
||||
if (srcPriv) {
|
||||
secinfo = srcPriv->secinfo;
|
||||
encinfo = srcPriv->encinfo;
|
||||
}
|
||||
|
||||
if (secinfo && secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES) {
|
||||
if (qemuBuildSecretInfoProps(secinfo, &secobjProps) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
encinfo = srcPriv->encinfo;
|
||||
if (encinfo && qemuBuildSecretInfoProps(encinfo, &encobjProps) < 0)
|
||||
goto error;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user