1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

qemu: hotplug: Refactor qemuHotplugPrepareDiskAccess to work on virStorageSource

Rather than passing in a virStorageSource which would override the
originally passed disk->src we can now drop passing in a disk completely
as all functions called inside here require a virStorageSource.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
Peter Krempa 2019-01-23 14:28:31 +01:00
parent 083b74cd20
commit 9b197f0e36

View File

@ -68,37 +68,29 @@ unsigned long long qemuDomainRemoveDeviceWaitTime = 1000ull * 5;
/** /**
* qemuHotplugPrepareDiskAccess: * qemuHotplugPrepareDiskSourceAccess:
* @driver: qemu driver struct * @driver: qemu driver struct
* @vm: domain object * @vm: domain object
* @disk: disk to prepare * @src: Source to prepare
* @overridesrc: Source different than @disk->src when necessary * @teardown: Teardown the access to @src instead of adding it to a vm
* @teardown: Teardown the disk instead of adding it to a vm
* *
* Setup the locks, cgroups and security permissions on a disk of a VM. * Setup the locks, cgroups and security permissions on a disk source and its
* If @overridesrc is specified the source struct is used instead of the * backing chain. If @teardown is true, then the labels and cgroups are removed
* one present in @disk. If @teardown is true, then the labels and cgroups * instead.
* are removed instead.
* *
* Returns 0 on success and -1 on error. Reports libvirt error. * Returns 0 on success and -1 on error. Reports libvirt error.
*/ */
static int static int
qemuHotplugPrepareDiskAccess(virQEMUDriverPtr driver, qemuHotplugPrepareDiskSourceAccess(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
virDomainDiskDefPtr disk, virStorageSourcePtr src,
virStorageSourcePtr overridesrc,
bool teardown) bool teardown)
{ {
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
const char *srcstr = NULLSTR(src->path);
int ret = -1; int ret = -1;
virStorageSourcePtr origsrc = NULL;
virErrorPtr orig_err = NULL; virErrorPtr orig_err = NULL;
if (overridesrc) {
origsrc = disk->src;
disk->src = overridesrc;
}
/* just tear down the disk access */ /* just tear down the disk access */
if (teardown) { if (teardown) {
virErrorPreserveLast(&orig_err); virErrorPreserveLast(&orig_err);
@ -106,47 +98,38 @@ qemuHotplugPrepareDiskAccess(virQEMUDriverPtr driver,
goto rollback_cgroup; goto rollback_cgroup;
} }
if (virDomainLockImageAttach(driver->lockManager, cfg->uri, if (virDomainLockImageAttach(driver->lockManager, cfg->uri, vm, src) < 0)
vm, disk->src) < 0)
goto cleanup; goto cleanup;
if (qemuDomainNamespaceSetupDisk(vm, disk->src) < 0) if (qemuDomainNamespaceSetupDisk(vm, src) < 0)
goto rollback_lock; goto rollback_lock;
if (qemuSecuritySetImageLabel(driver, vm, disk->src, true) < 0) if (qemuSecuritySetImageLabel(driver, vm, src, true) < 0)
goto rollback_namespace; goto rollback_namespace;
if (qemuSetupImageChainCgroup(vm, disk->src) < 0) if (qemuSetupImageChainCgroup(vm, src) < 0)
goto rollback_label; goto rollback_label;
ret = 0; ret = 0;
goto cleanup; goto cleanup;
rollback_cgroup: rollback_cgroup:
if (qemuTeardownImageChainCgroup(vm, disk->src) < 0) if (qemuTeardownImageChainCgroup(vm, src) < 0)
VIR_WARN("Unable to tear down cgroup access on %s", VIR_WARN("Unable to tear down cgroup access on %s", srcstr);
NULLSTR(virDomainDiskGetSource(disk)));
rollback_label: rollback_label:
if (qemuSecurityRestoreImageLabel(driver, vm, disk->src, true) < 0) if (qemuSecurityRestoreImageLabel(driver, vm, src, true) < 0)
VIR_WARN("Unable to restore security label on %s", VIR_WARN("Unable to restore security label on %s", srcstr);
NULLSTR(virDomainDiskGetSource(disk)));
rollback_namespace: rollback_namespace:
if (qemuDomainNamespaceTeardownDisk(vm, disk->src) < 0) if (qemuDomainNamespaceTeardownDisk(vm, src) < 0)
VIR_WARN("Unable to remove /dev entry for %s", VIR_WARN("Unable to remove /dev entry for %s", srcstr);
NULLSTR(virDomainDiskGetSource(disk)));
rollback_lock: rollback_lock:
if (virDomainLockImageDetach(driver->lockManager, vm, disk->src) < 0) if (virDomainLockImageDetach(driver->lockManager, vm, src) < 0)
VIR_WARN("Unable to release lock on %s", VIR_WARN("Unable to release lock on %s", srcstr);
NULLSTR(virDomainDiskGetSource(disk)));
cleanup: cleanup:
if (origsrc)
disk->src = origsrc;
virErrorRestore(&orig_err); virErrorRestore(&orig_err);
virObjectUnref(cfg); virObjectUnref(cfg);
return ret; return ret;
@ -826,7 +809,7 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
if (qemuDomainPrepareDiskSource(disk, priv, cfg) < 0) if (qemuDomainPrepareDiskSource(disk, priv, cfg) < 0)
goto cleanup; goto cleanup;
if (qemuHotplugPrepareDiskAccess(driver, vm, disk, newsrc, false) < 0) if (qemuHotplugPrepareDiskSourceAccess(driver, vm, newsrc, false) < 0)
goto cleanup; goto cleanup;
if (qemuHotplugAttachManagedPR(driver, vm, newsrc, QEMU_ASYNC_JOB_NONE) < 0) if (qemuHotplugAttachManagedPR(driver, vm, newsrc, QEMU_ASYNC_JOB_NONE) < 0)
@ -845,7 +828,7 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
/* remove the old source from shared device list */ /* remove the old source from shared device list */
disk->src = oldsrc; disk->src = oldsrc;
ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name)); ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name));
ignore_value(qemuHotplugPrepareDiskAccess(driver, vm, disk, oldsrc, true)); ignore_value(qemuHotplugPrepareDiskSourceAccess(driver, vm, oldsrc, true));
/* media was changed, so we can remove the old media definition now */ /* media was changed, so we can remove the old media definition now */
virStorageSourceFree(oldsrc); virStorageSourceFree(oldsrc);
@ -860,7 +843,7 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
if (sharedAdded) if (sharedAdded)
ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name)); ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name));
ignore_value(qemuHotplugPrepareDiskAccess(driver, vm, disk, newsrc, true)); ignore_value(qemuHotplugPrepareDiskSourceAccess(driver, vm, newsrc, true));
} }
/* remove PR manager object if unneeded */ /* remove PR manager object if unneeded */
@ -891,7 +874,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
char *devstr = NULL; char *devstr = NULL;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
if (qemuHotplugPrepareDiskAccess(driver, vm, disk, NULL, false) < 0) if (qemuHotplugPrepareDiskSourceAccess(driver, vm, disk->src, false) < 0)
goto cleanup; goto cleanup;
if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0) if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0)
@ -954,7 +937,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
virDomainAuditDisk(vm, NULL, disk->src, "attach", false); virDomainAuditDisk(vm, NULL, disk->src, "attach", false);
error: error:
ignore_value(qemuHotplugPrepareDiskAccess(driver, vm, disk, NULL, true)); ignore_value(qemuHotplugPrepareDiskSourceAccess(driver, vm, disk->src, true));
goto cleanup; goto cleanup;
} }
@ -4377,7 +4360,7 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
qemuDomainReleaseDeviceAddress(vm, &disk->info, virDomainDiskGetSource(disk)); qemuDomainReleaseDeviceAddress(vm, &disk->info, virDomainDiskGetSource(disk));
/* tear down disk security access */ /* tear down disk security access */
qemuHotplugPrepareDiskAccess(driver, vm, disk, NULL, true); qemuHotplugPrepareDiskSourceAccess(driver, vm, disk->src, true);
dev.type = VIR_DOMAIN_DEVICE_DISK; dev.type = VIR_DOMAIN_DEVICE_DISK;
dev.data.disk = disk; dev.data.disk = disk;