1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-23 21:34:54 +03:00

qemu: Prepare for 'sd' card use together with blockdev

SD cards need to be instantiated via -drive if=sd. This means that all
cases where we use the blockdev path need to be special-cased for SD
cards.

Note that at this point QEMU_CAPS_BLOCKDEV is still cleared if the VM
config has a SD card.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2020-05-06 13:48:35 +02:00
parent d876a93f05
commit e664abb62e
6 changed files with 23 additions and 9 deletions

View File

@ -2089,7 +2089,8 @@ qemuBuildDiskSourceCommandLine(virCommandPtr cmd,
g_autofree char *copyOnReadPropsStr = NULL; g_autofree char *copyOnReadPropsStr = NULL;
size_t i; size_t i;
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) { if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV) &&
!qemuDiskBusIsSD(disk->bus)) {
if (virStorageSourceIsEmpty(disk->src)) if (virStorageSourceIsEmpty(disk->src))
return 0; return 0;

View File

@ -8212,6 +8212,8 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
virStorageSourcePtr src; /* iterator for the backing chain declared in XML */ virStorageSourcePtr src; /* iterator for the backing chain declared in XML */
virStorageSourcePtr n; /* iterator for the backing chain detected from disk */ virStorageSourcePtr n; /* iterator for the backing chain detected from disk */
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
bool blockdev = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV);
bool isSD = qemuDiskBusIsSD(disk->bus);
uid_t uid; uid_t uid;
gid_t gid; gid_t gid;
@ -8294,13 +8296,14 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
if (n->format == VIR_STORAGE_FILE_ISO) if (n->format == VIR_STORAGE_FILE_ISO)
n->format = VIR_STORAGE_FILE_RAW; n->format = VIR_STORAGE_FILE_RAW;
if (qemuDomainValidateStorageSource(n, priv->qemuCaps, false) < 0) /* mask-out blockdev for 'sd' disks */
if (qemuDomainValidateStorageSource(n, priv->qemuCaps, isSD) < 0)
return -1; return -1;
qemuDomainPrepareStorageSourceConfig(n, cfg, priv->qemuCaps); qemuDomainPrepareStorageSourceConfig(n, cfg, priv->qemuCaps);
qemuDomainPrepareDiskSourceData(disk, n); qemuDomainPrepareDiskSourceData(disk, n);
if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) && if (blockdev && !isSD &&
qemuDomainPrepareStorageSourceBlockdev(disk, n, priv, cfg) < 0) qemuDomainPrepareStorageSourceBlockdev(disk, n, priv, cfg) < 0)
return -1; return -1;
} }
@ -8358,7 +8361,8 @@ qemuDomainDiskGetBackendAlias(virDomainDiskDefPtr disk,
{ {
*backendAlias = NULL; *backendAlias = NULL;
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) { if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV) ||
qemuDiskBusIsSD(disk->bus)) {
if (!(*backendAlias = qemuAliasDiskDriveFromDisk(disk))) if (!(*backendAlias = qemuAliasDiskDriveFromDisk(disk)))
return -1; return -1;
@ -13234,7 +13238,8 @@ qemuDomainPrepareDiskSource(virDomainDiskDefPtr disk,
disk->src->format = VIR_STORAGE_FILE_RAW; disk->src->format = VIR_STORAGE_FILE_RAW;
} }
if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) { if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) &&
!qemuDiskBusIsSD(disk->bus)) {
if (qemuDomainPrepareDiskSourceBlockdev(disk, priv, cfg) < 0) if (qemuDomainPrepareDiskSourceBlockdev(disk, priv, cfg) < 0)
return -1; return -1;
} else { } else {

View File

@ -10808,7 +10808,8 @@ qemuDomainBlockResize(virDomainPtr dom,
disk->src->format == VIR_STORAGE_FILE_QED) disk->src->format == VIR_STORAGE_FILE_QED)
size = VIR_ROUND_UP(size, 512); size = VIR_ROUND_UP(size, 512);
if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) { if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) &&
!qemuDiskBusIsSD(disk->bus)) {
if (virStorageSourceIsEmpty(disk->src) || disk->src->readonly) { if (virStorageSourceIsEmpty(disk->src) || disk->src->readonly) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("can't resize empty or readonly disk '%s'"), _("can't resize empty or readonly disk '%s'"),

View File

@ -4270,7 +4270,8 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
disk->info.alias, vm, vm->def->name); disk->info.alias, vm, vm->def->name);
if (blockdev) { if (blockdev &&
!qemuDiskBusIsSD(disk->bus)) {
corAlias = g_strdup(diskPriv->nodeCopyOnRead); corAlias = g_strdup(diskPriv->nodeCopyOnRead);
if (diskPriv->blockjob) { if (diskPriv->blockjob) {

View File

@ -6405,7 +6405,7 @@ qemuProcessPrepareHostStorage(virQEMUDriverPtr driver,
continue; continue;
/* backing chain needs to be redetected if we aren't using blockdev */ /* backing chain needs to be redetected if we aren't using blockdev */
if (!blockdev) if (!blockdev || qemuDiskBusIsSD(disk->bus))
virStorageSourceBackingStoreClear(disk->src); virStorageSourceBackingStoreClear(disk->src);
/* /*
@ -6634,6 +6634,10 @@ qemuProcessSetupDiskThrottlingBlockdev(virQEMUDriverPtr driver,
virDomainDiskDefPtr disk = vm->def->disks[i]; virDomainDiskDefPtr disk = vm->def->disks[i];
qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk); qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
/* sd-cards are instantiated via -drive */
if (qemuDiskBusIsSD(disk->bus))
continue;
if (!qemuDiskConfigBlkdeviotuneEnabled(disk)) if (!qemuDiskConfigBlkdeviotuneEnabled(disk))
continue; continue;

View File

@ -2259,6 +2259,7 @@ qemuValidateDomainDeviceDefDisk(const virDomainDiskDef *disk,
virQEMUCapsPtr qemuCaps) virQEMUCapsPtr qemuCaps)
{ {
const char *driverName = virDomainDiskGetDriver(disk); const char *driverName = virDomainDiskGetDriver(disk);
bool isSD = qemuDiskBusIsSD(disk->bus);
virStorageSourcePtr n; virStorageSourcePtr n;
int idx; int idx;
int partition; int partition;
@ -2298,7 +2299,8 @@ qemuValidateDomainDeviceDefDisk(const virDomainDiskDef *disk,
} }
for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) { for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
if (qemuDomainValidateStorageSource(n, qemuCaps, false) < 0) /* blockdev support is masked out for 'sd' disks */
if (qemuDomainValidateStorageSource(n, qemuCaps, isSD) < 0)
return -1; return -1;
} }