[pve-devel] [RFC v2 pve-cluster 2/4] clean up some error handling
Thomas Lamprecht
t.lamprecht at proxmox.com
Wed Oct 7 13:34:58 CEST 2015
Does not change functionality, makes some code a bit more readable
and lessens code reuse.
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
data/src/dcdb.c | 6 +++---
data/src/dfsm.c | 21 +++++++++------------
data/src/quorum.c | 23 +++++++++++------------
3 files changed, 23 insertions(+), 27 deletions(-)
diff --git a/data/src/dcdb.c b/data/src/dcdb.c
index 307c7ec..b83caa4 100644
--- a/data/src/dcdb.c
+++ b/data/src/dcdb.c
@@ -918,13 +918,13 @@ ret:
cfs_debug("leave %s (%d)", __func__, res);
return res;
+
+unknown:
+ cfs_critical("received unknown message type (msg_type == %d)", msg_type);
leave:
res = -1;
goto ret;
-unknown:
- cfs_critical("received unknown message type (msg_type == %d)", msg_type);
- goto leave;
};
static dfsm_callbacks_t dcdb_dfsm_callbacks = {
diff --git a/data/src/dfsm.c b/data/src/dfsm.c
index c14564f..bf2d78c 100644
--- a/data/src/dfsm.c
+++ b/data/src/dfsm.c
@@ -1371,13 +1371,12 @@ dfsm_initialize(dfsm_t *dfsm, int *fd)
if (dfsm->cpg_handle == 0) {
if ((result = cpg_initialize(&dfsm->cpg_handle, dfsm->cpg_callbacks)) != CS_OK) {
cfs_dom_critical(dfsm->log_domain, "cpg_initialize failed: %d", result);
- dfsm->cpg_handle = 0;
- goto fail;
+ goto err_no_finalize;
}
if ((result = cpg_local_get(dfsm->cpg_handle, &dfsm->nodeid)) != CS_OK) {
cfs_dom_critical(dfsm->log_domain, "cpg_local_get failed: %d", result);
- goto fail;
+ goto err_finalize;
}
dfsm->pid = getpid();
@@ -1385,21 +1384,21 @@ dfsm_initialize(dfsm_t *dfsm, int *fd)
result = cpg_context_set(dfsm->cpg_handle, dfsm);
if (result != CS_OK) {
cfs_dom_critical(dfsm->log_domain, "cpg_context_set failed: %d", result);
- goto fail;
+ goto err_finalize;
}
}
result = cpg_fd_get(dfsm->cpg_handle, fd);
if (result != CS_OK) {
cfs_dom_critical(dfsm->log_domain, "cpg_fd_get failed: %d", result);
- goto fail;
+ goto err_finalize;
}
return CS_OK;
-fail:
- if (dfsm->cpg_handle)
- cpg_finalize(dfsm->cpg_handle);
+ err_finalize:
+ cpg_finalize(dfsm->cpg_handle);
+ err_no_finalize:
dfsm->cpg_handle = 0;
return result;
}
@@ -1613,13 +1612,11 @@ service_dfsm_dispatch(
return TRUE;
+finalize:
+ dfsm_finalize(dfsm);
fail:
cfs_service_set_restartable(service, dfsm_restartable(dfsm));
return FALSE;
-
-finalize:
- dfsm_finalize(dfsm);
- goto fail;
}
static void
diff --git a/data/src/quorum.c b/data/src/quorum.c
index 983a4da..1c258db 100644
--- a/data/src/quorum.c
+++ b/data/src/quorum.c
@@ -110,23 +110,18 @@ static int service_quorum_initialize(
result = quorum_initialize(&handle, &quorum_callbacks, &quorum_type);
if (result != CS_OK) {
cfs_critical("quorum_initialize failed: %d", result);
- private->handle = 0;
- return -1;
+ goto err_reset_handle;
}
if (quorum_type != QUORUM_SET) {
- cfs_critical("quorum_initialize returned wron quorum_type: %d", quorum_type);
- quorum_finalize(handle);
- private->handle = 0;
- return -1;
+ cfs_critical("quorum_initialize returned wrong quorum_type: %d", quorum_type);
+ goto err_finalize;
}
result = quorum_context_set(handle, private);
if (result != CS_OK) {
cfs_critical("quorum_context_set failed: %d", result);
- quorum_finalize(handle);
- private->handle = 0;
- return -1;
+ goto err_finalize;
}
private->handle = handle;
@@ -136,9 +131,7 @@ static int service_quorum_initialize(
result = quorum_trackstart(handle, CS_TRACK_CHANGES);
if (result == CS_ERR_LIBRARY || result == CS_ERR_BAD_HANDLE) {
cfs_critical("quorum_trackstart failed: %d - closing handle", result);
- quorum_finalize(handle);
- private->handle = 0;
- return -1;
+ goto err_finalize;
} else if (result != CS_OK) {
cfs_critical("quorum_trackstart failed: %d - trying again", result);
return -1;
@@ -151,6 +144,12 @@ static int service_quorum_initialize(
}
return quorum_fd;
+
+ err_finalize:
+ quorum_finalize(handle);
+ err_reset_handle:
+ private->handle = 0;
+ return -1;
}
static gboolean service_quorum_dispatch(
--
2.1.4
More information about the pve-devel
mailing list