mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-29 20:11:16 +00:00
qemu: Move and rename qemuHotplugPrepareDiskSourceAccess
Move it to qemu_domain.c and call it qemuDomainStorageSourceChainAccessPrepare. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
1a828a578e
commit
3d36d666f8
@ -9211,6 +9211,74 @@ qemuDomainDiskGetBackendAlias(virDomainDiskDefPtr disk,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* qemuDomainStorageSourceChainAccessPrepare:
|
||||
* @driver: qemu driver struct
|
||||
* @vm: domain object
|
||||
* @src: Source to prepare
|
||||
* @teardown: Teardown the access to @src instead of adding it to a vm
|
||||
*
|
||||
* Setup the locks, cgroups and security permissions on a disk source and its
|
||||
* backing chain. If @teardown is true, then the labels and cgroups are removed
|
||||
* instead.
|
||||
*
|
||||
* Returns 0 on success and -1 on error. Reports libvirt error.
|
||||
*/
|
||||
int
|
||||
qemuDomainStorageSourceChainAccessPrepare(virQEMUDriverPtr driver,
|
||||
virDomainObjPtr vm,
|
||||
virStorageSourcePtr src,
|
||||
bool teardown)
|
||||
{
|
||||
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
|
||||
const char *srcstr = NULLSTR(src->path);
|
||||
int ret = -1;
|
||||
virErrorPtr orig_err = NULL;
|
||||
|
||||
/* just tear down the disk access */
|
||||
if (teardown) {
|
||||
virErrorPreserveLast(&orig_err);
|
||||
ret = 0;
|
||||
goto rollback_cgroup;
|
||||
}
|
||||
|
||||
if (virDomainLockImageAttach(driver->lockManager, cfg->uri, vm, src) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuDomainNamespaceSetupDisk(vm, src) < 0)
|
||||
goto rollback_lock;
|
||||
|
||||
if (qemuSecuritySetImageLabel(driver, vm, src, true) < 0)
|
||||
goto rollback_namespace;
|
||||
|
||||
if (qemuSetupImageChainCgroup(vm, src) < 0)
|
||||
goto rollback_label;
|
||||
|
||||
ret = 0;
|
||||
goto cleanup;
|
||||
|
||||
rollback_cgroup:
|
||||
if (qemuTeardownImageChainCgroup(vm, src) < 0)
|
||||
VIR_WARN("Unable to tear down cgroup access on %s", srcstr);
|
||||
rollback_label:
|
||||
if (qemuSecurityRestoreImageLabel(driver, vm, src, true) < 0)
|
||||
VIR_WARN("Unable to restore security label on %s", srcstr);
|
||||
|
||||
rollback_namespace:
|
||||
if (qemuDomainNamespaceTeardownDisk(vm, src) < 0)
|
||||
VIR_WARN("Unable to remove /dev entry for %s", srcstr);
|
||||
|
||||
rollback_lock:
|
||||
if (virDomainLockImageDetach(driver->lockManager, vm, src) < 0)
|
||||
VIR_WARN("Unable to release lock on %s", srcstr);
|
||||
|
||||
cleanup:
|
||||
virErrorRestore(&orig_err);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* qemuDomainStorageSourceAccessRevoke:
|
||||
*
|
||||
|
@ -770,6 +770,11 @@ int qemuDomainDiskGetBackendAlias(virDomainDiskDefPtr disk,
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
|
||||
ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK;
|
||||
|
||||
int qemuDomainStorageSourceChainAccessPrepare(virQEMUDriverPtr driver,
|
||||
virDomainObjPtr vm,
|
||||
virStorageSourcePtr src,
|
||||
bool teardown);
|
||||
|
||||
void qemuDomainStorageSourceAccessRevoke(virQEMUDriverPtr driver,
|
||||
virDomainObjPtr vm,
|
||||
virStorageSourcePtr elem);
|
||||
|
@ -132,74 +132,6 @@ qemuDomainDeleteDevice(virDomainObjPtr vm,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* qemuHotplugPrepareDiskSourceAccess:
|
||||
* @driver: qemu driver struct
|
||||
* @vm: domain object
|
||||
* @src: Source to prepare
|
||||
* @teardown: Teardown the access to @src instead of adding it to a vm
|
||||
*
|
||||
* Setup the locks, cgroups and security permissions on a disk source and its
|
||||
* backing chain. If @teardown is true, then the labels and cgroups are removed
|
||||
* instead.
|
||||
*
|
||||
* Returns 0 on success and -1 on error. Reports libvirt error.
|
||||
*/
|
||||
static int
|
||||
qemuHotplugPrepareDiskSourceAccess(virQEMUDriverPtr driver,
|
||||
virDomainObjPtr vm,
|
||||
virStorageSourcePtr src,
|
||||
bool teardown)
|
||||
{
|
||||
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
|
||||
const char *srcstr = NULLSTR(src->path);
|
||||
int ret = -1;
|
||||
virErrorPtr orig_err = NULL;
|
||||
|
||||
/* just tear down the disk access */
|
||||
if (teardown) {
|
||||
virErrorPreserveLast(&orig_err);
|
||||
ret = 0;
|
||||
goto rollback_cgroup;
|
||||
}
|
||||
|
||||
if (virDomainLockImageAttach(driver->lockManager, cfg->uri, vm, src) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuDomainNamespaceSetupDisk(vm, src) < 0)
|
||||
goto rollback_lock;
|
||||
|
||||
if (qemuSecuritySetImageLabel(driver, vm, src, true) < 0)
|
||||
goto rollback_namespace;
|
||||
|
||||
if (qemuSetupImageChainCgroup(vm, src) < 0)
|
||||
goto rollback_label;
|
||||
|
||||
ret = 0;
|
||||
goto cleanup;
|
||||
|
||||
rollback_cgroup:
|
||||
if (qemuTeardownImageChainCgroup(vm, src) < 0)
|
||||
VIR_WARN("Unable to tear down cgroup access on %s", srcstr);
|
||||
rollback_label:
|
||||
if (qemuSecurityRestoreImageLabel(driver, vm, src, true) < 0)
|
||||
VIR_WARN("Unable to restore security label on %s", srcstr);
|
||||
|
||||
rollback_namespace:
|
||||
if (qemuDomainNamespaceTeardownDisk(vm, src) < 0)
|
||||
VIR_WARN("Unable to remove /dev entry for %s", srcstr);
|
||||
|
||||
rollback_lock:
|
||||
if (virDomainLockImageDetach(driver->lockManager, vm, src) < 0)
|
||||
VIR_WARN("Unable to release lock on %s", srcstr);
|
||||
|
||||
cleanup:
|
||||
virErrorRestore(&orig_err);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
qemuDomainAttachZPCIDevice(qemuMonitorPtr mon,
|
||||
virDomainDeviceInfoPtr info)
|
||||
@ -877,7 +809,7 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
|
||||
if (qemuDomainPrepareDiskSource(disk, priv, cfg) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuHotplugPrepareDiskSourceAccess(driver, vm, newsrc, false) < 0)
|
||||
if (qemuDomainStorageSourceChainAccessPrepare(driver, vm, newsrc, false) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuHotplugAttachManagedPR(driver, vm, newsrc, QEMU_ASYNC_JOB_NONE) < 0)
|
||||
@ -896,7 +828,7 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
|
||||
/* remove the old source from shared device list */
|
||||
disk->src = oldsrc;
|
||||
ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name));
|
||||
ignore_value(qemuHotplugPrepareDiskSourceAccess(driver, vm, oldsrc, true));
|
||||
ignore_value(qemuDomainStorageSourceChainAccessPrepare(driver, vm, oldsrc, true));
|
||||
|
||||
/* media was changed, so we can remove the old media definition now */
|
||||
virObjectUnref(oldsrc);
|
||||
@ -911,7 +843,7 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
|
||||
if (sharedAdded)
|
||||
ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name));
|
||||
|
||||
ignore_value(qemuHotplugPrepareDiskSourceAccess(driver, vm, newsrc, true));
|
||||
ignore_value(qemuDomainStorageSourceChainAccessPrepare(driver, vm, newsrc, true));
|
||||
}
|
||||
|
||||
/* remove PR manager object if unneeded */
|
||||
@ -941,7 +873,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
|
||||
char *devstr = NULL;
|
||||
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
|
||||
|
||||
if (qemuHotplugPrepareDiskSourceAccess(driver, vm, disk->src, false) < 0)
|
||||
if (qemuDomainStorageSourceChainAccessPrepare(driver, vm, disk->src, false) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0)
|
||||
@ -1003,7 +935,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
|
||||
virDomainAuditDisk(vm, NULL, disk->src, "attach", false);
|
||||
|
||||
error:
|
||||
ignore_value(qemuHotplugPrepareDiskSourceAccess(driver, vm, disk->src, true));
|
||||
ignore_value(qemuDomainStorageSourceChainAccessPrepare(driver, vm, disk->src, true));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -4544,7 +4476,7 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
|
||||
qemuDomainReleaseDeviceAddress(vm, &disk->info);
|
||||
|
||||
/* tear down disk security access */
|
||||
qemuHotplugPrepareDiskSourceAccess(driver, vm, disk->src, true);
|
||||
qemuDomainStorageSourceChainAccessPrepare(driver, vm, disk->src, true);
|
||||
|
||||
dev.type = VIR_DOMAIN_DEVICE_DISK;
|
||||
dev.data.disk = disk;
|
||||
|
Loading…
Reference in New Issue
Block a user