mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 06:50:22 +03:00
storageDriverAutostartCallback: Refactor control flow
Use early returns to decrease the indentation level and make it more obvious that the 'cleanup' path is a noop in those cases. 'virStoragePoolObjSetStarting' was called only when the code wanted to start the pool, so if that was skipped, cleanup is noop as it's conditional on the return value of 'virStoragePoolObjIsStarting'. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
8a80df95ac
commit
a09c5b3cc2
@ -194,38 +194,39 @@ storageDriverAutostartCallback(virStoragePoolObj *obj,
|
||||
{
|
||||
virStoragePoolDef *def = virStoragePoolObjGetDef(obj);
|
||||
virStorageBackend *backend;
|
||||
bool started = false;
|
||||
g_autofree char *stateFile = NULL;
|
||||
|
||||
if (!(backend = virStorageBackendForType(def->type)))
|
||||
return;
|
||||
|
||||
if (virStoragePoolObjIsAutostart(obj) &&
|
||||
!virStoragePoolObjIsActive(obj)) {
|
||||
if (!virStoragePoolObjIsAutostart(obj))
|
||||
return;
|
||||
|
||||
virStoragePoolObjSetStarting(obj, true);
|
||||
if (backend->startPool &&
|
||||
backend->startPool(obj) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to autostart storage pool '%s': %s"),
|
||||
def->name, virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
started = true;
|
||||
if (virStoragePoolObjIsActive(obj))
|
||||
return;
|
||||
|
||||
VIR_DEBUG("autostarting storage pool '%s'", def->name);
|
||||
|
||||
virStoragePoolObjSetStarting(obj, true);
|
||||
|
||||
if (backend->startPool &&
|
||||
backend->startPool(obj) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to autostart storage pool '%s': %s"),
|
||||
def->name, virGetLastErrorMessage());
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (started) {
|
||||
g_autofree char *stateFile = NULL;
|
||||
stateFile = virFileBuildPath(driver->stateDir, def->name, ".xml");
|
||||
|
||||
stateFile = virFileBuildPath(driver->stateDir, def->name, ".xml");
|
||||
if (!stateFile ||
|
||||
virStoragePoolSaveState(stateFile, def) < 0 ||
|
||||
storagePoolRefreshImpl(backend, obj, stateFile) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to autostart storage pool '%s': %s"),
|
||||
def->name, virGetLastErrorMessage());
|
||||
} else {
|
||||
virStoragePoolObjSetActive(obj, true);
|
||||
}
|
||||
if (!stateFile ||
|
||||
virStoragePoolSaveState(stateFile, def) < 0 ||
|
||||
storagePoolRefreshImpl(backend, obj, stateFile) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to autostart storage pool '%s': %s"),
|
||||
def->name, virGetLastErrorMessage());
|
||||
} else {
|
||||
virStoragePoolObjSetActive(obj, true);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
|
Loading…
x
Reference in New Issue
Block a user