qemu: Use bools rather than labels in qemuDomainStorageSourceAccessModify

Rather than jumping to the correct label use a set of booleans to
determine which operation needs to be rolled back. This will allow more
flexibility when e.g. rollback after a failed operation will not be
necessary/desired.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2019-04-18 16:06:19 +02:00
parent 3bb1423883
commit 657216b60d

View File

@ -9246,6 +9246,10 @@ qemuDomainStorageSourceAccessModify(virQEMUDriverPtr driver,
bool chain = flags & QEMU_DOMAIN_STORAGE_SOURCE_ACCESS_CHAIN; bool chain = flags & QEMU_DOMAIN_STORAGE_SOURCE_ACCESS_CHAIN;
int rc; int rc;
bool was_readonly = src->readonly; bool was_readonly = src->readonly;
bool revoke_cgroup = false;
bool revoke_label = false;
bool revoke_namespace = false;
bool revoke_lockspace = false;
if (flags & QEMU_DOMAIN_STORAGE_SOURCE_ACCESS_READ_ONLY) if (flags & QEMU_DOMAIN_STORAGE_SOURCE_ACCESS_READ_ONLY)
src->readonly = true; src->readonly = true;
@ -9253,18 +9257,28 @@ qemuDomainStorageSourceAccessModify(virQEMUDriverPtr driver,
/* just tear down the disk access */ /* just tear down the disk access */
if (flags & QEMU_DOMAIN_STORAGE_SOURCE_ACCESS_REVOKE) { if (flags & QEMU_DOMAIN_STORAGE_SOURCE_ACCESS_REVOKE) {
virErrorPreserveLast(&orig_err); virErrorPreserveLast(&orig_err);
revoke_cgroup = true;
revoke_label = true;
revoke_namespace = true;
revoke_lockspace = true;
ret = 0; ret = 0;
goto rollback_cgroup; goto revoke;
} }
if (virDomainLockImageAttach(driver->lockManager, cfg->uri, vm, src) < 0) if (virDomainLockImageAttach(driver->lockManager, cfg->uri, vm, src) < 0)
goto cleanup; goto revoke;
revoke_lockspace = true;
if (qemuDomainNamespaceSetupDisk(vm, src) < 0) if (qemuDomainNamespaceSetupDisk(vm, src) < 0)
goto rollback_lock; goto revoke;
revoke_namespace = true;
if (qemuSecuritySetImageLabel(driver, vm, src, chain) < 0) if (qemuSecuritySetImageLabel(driver, vm, src, chain) < 0)
goto rollback_namespace; goto revoke;
revoke_label = true;
if (chain) if (chain)
rc = qemuSetupImageChainCgroup(vm, src); rc = qemuSetupImageChainCgroup(vm, src);
@ -9272,30 +9286,38 @@ qemuDomainStorageSourceAccessModify(virQEMUDriverPtr driver,
rc = qemuSetupImageCgroup(vm, src); rc = qemuSetupImageCgroup(vm, src);
if (rc < 0) if (rc < 0)
goto rollback_label; goto revoke;
revoke_cgroup = true;
ret = 0; ret = 0;
goto cleanup; goto cleanup;
rollback_cgroup: revoke:
if (chain) if (revoke_cgroup) {
rc = qemuTeardownImageChainCgroup(vm, src); if (chain)
else rc = qemuTeardownImageChainCgroup(vm, src);
rc = qemuTeardownImageCgroup(vm, src); else
rc = qemuTeardownImageCgroup(vm, src);
if (rc < 0) if (rc < 0)
VIR_WARN("Unable to tear down cgroup access on %s", srcstr); VIR_WARN("Unable to tear down cgroup access on %s", srcstr);
rollback_label: }
if (qemuSecurityRestoreImageLabel(driver, vm, src, chain) < 0)
VIR_WARN("Unable to restore security label on %s", srcstr);
rollback_namespace: if (revoke_label) {
if (qemuDomainNamespaceTeardownDisk(vm, src) < 0) if (qemuSecurityRestoreImageLabel(driver, vm, src, chain) < 0)
VIR_WARN("Unable to remove /dev entry for %s", srcstr); VIR_WARN("Unable to restore security label on %s", srcstr);
}
rollback_lock: if (revoke_namespace) {
if (virDomainLockImageDetach(driver->lockManager, vm, src) < 0) if (qemuDomainNamespaceTeardownDisk(vm, src) < 0)
VIR_WARN("Unable to release lock on %s", srcstr); VIR_WARN("Unable to remove /dev entry for %s", srcstr);
}
if (revoke_lockspace) {
if (virDomainLockImageDetach(driver->lockManager, vm, src) < 0)
VIR_WARN("Unable to release lock on %s", srcstr);
}
cleanup: cleanup:
src->readonly = was_readonly; src->readonly = was_readonly;