qemu: factor out qemuDomainPrepareStorageSource()

This refactoring will simplify next changes.

Signed-off-by: Nikolai Barybin <nikolai.barybin@virtuozzo.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Nikolai Barybin 2024-11-20 18:48:47 +03:00 committed by Peter Krempa
parent 9ba2bef816
commit cb5371a8bd

View File

@ -6114,6 +6114,32 @@ qemuDomainPrepareStorageSourceConfig(virStorageSource *src,
}
static int
qemuDomainPrepareStorageSource(virStorageSource *src,
virDomainObj *vm,
virDomainDiskDef *disk,
virQEMUDriverConfig *cfg)
{
qemuDomainObjPrivate *priv = vm->privateData;
/* convert detected ISO format to 'raw' as qemu would not understand it */
if (src->format == VIR_STORAGE_FILE_ISO)
src->format = VIR_STORAGE_FILE_RAW;
if (qemuDomainValidateStorageSource(src, priv->qemuCaps) < 0)
return -1;
qemuDomainPrepareStorageSourceConfig(src, cfg);
qemuDomainPrepareDiskSourceData(disk, src);
if (!qemuDiskBusIsSD(disk->bus) &&
qemuDomainPrepareStorageSourceBlockdev(disk, src, priv, cfg) < 0)
return -1;
return 0;
}
/**
* qemuDomainDetermineDiskChain:
* @driver: qemu driver object
@ -6134,7 +6160,6 @@ qemuDomainDetermineDiskChain(virQEMUDriver *driver,
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
virStorageSource *src; /* iterator for the backing chain declared in XML */
virStorageSource *n; /* iterator for the backing chain detected from disk */
qemuDomainObjPrivate *priv = vm->privateData;
uid_t uid;
gid_t gid;
@ -6218,18 +6243,7 @@ qemuDomainDetermineDiskChain(virQEMUDriver *driver,
return -1;
for (n = src->backingStore; virStorageSourceIsBacking(n); n = n->backingStore) {
/* convert detected ISO format to 'raw' as qemu would not understand it */
if (n->format == VIR_STORAGE_FILE_ISO)
n->format = VIR_STORAGE_FILE_RAW;
if (qemuDomainValidateStorageSource(n, priv->qemuCaps) < 0)
return -1;
qemuDomainPrepareStorageSourceConfig(n, cfg);
qemuDomainPrepareDiskSourceData(disk, n);
if (!qemuDiskBusIsSD(disk->bus) &&
qemuDomainPrepareStorageSourceBlockdev(disk, n, priv, cfg) < 0)
if (qemuDomainPrepareStorageSource(n, vm, disk, cfg) < 0)
return -1;
}