diff options
author | pjd <pjd@FreeBSD.org> | 2011-01-31 18:32:17 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2011-01-31 18:32:17 +0000 |
commit | d916d2edb510181e3ab25256b84c439c5e1b8498 (patch) | |
tree | f3795a28e12aabbbc327a4d51170b148a1f2dbb2 /sbin/hastd/primary.c | |
parent | 34c6c0a73948c51ae253cd9f5821beeee63cb4ca (diff) | |
download | FreeBSD-src-d916d2edb510181e3ab25256b84c439c5e1b8498.zip FreeBSD-src-d916d2edb510181e3ab25256b84c439c5e1b8498.tar.gz |
- Use pjdlog for assertions and aborts as this will log assert/abort message
to syslog if we run in background.
- Asserts in proto.c that method we want to call is implemented and remove
dummy methods from protocols implementation that are only there to abort
the program with nice message.
MFC after: 1 week
Diffstat (limited to 'sbin/hastd/primary.c')
-rw-r--r-- | sbin/hastd/primary.c | 73 |
1 files changed, 36 insertions, 37 deletions
diff --git a/sbin/hastd/primary.c b/sbin/hastd/primary.c index d701d8e..2190576 100644 --- a/sbin/hastd/primary.c +++ b/sbin/hastd/primary.c @@ -40,7 +40,6 @@ __FBSDID("$FreeBSD$"); #include <geom/gate/g_gate.h> -#include <assert.h> #include <err.h> #include <errno.h> #include <fcntl.h> @@ -266,7 +265,7 @@ primary_exit(int exitcode, const char *fmt, ...) { va_list ap; - assert(exitcode != EX_OK); + PJDLOG_ASSERT(exitcode != EX_OK); va_start(ap, fmt); pjdlogv_errno(LOG_ERR, fmt, ap); va_end(ap); @@ -293,8 +292,8 @@ hast_activemap_flush(struct hast_resource *res) size_t size; buf = activemap_bitmap(res->hr_amp, &size); - assert(buf != NULL); - assert((size % res->hr_local_sectorsize) == 0); + PJDLOG_ASSERT(buf != NULL); + PJDLOG_ASSERT((size % res->hr_local_sectorsize) == 0); if (pwrite(res->hr_localfd, buf, size, METADATA_SIZE) != (ssize_t)size) { KEEP_ERRNO(pjdlog_errno(LOG_ERR, @@ -503,8 +502,8 @@ init_remote(struct hast_resource *res, struct proto_conn **inp, uint32_t mapsize; size_t size; - assert((inp == NULL && outp == NULL) || (inp != NULL && outp != NULL)); - assert(real_remote(res)); + PJDLOG_ASSERT((inp == NULL && outp == NULL) || (inp != NULL && outp != NULL)); + PJDLOG_ASSERT(real_remote(res)); in = out = NULL; errmsg = NULL; @@ -857,7 +856,7 @@ hastd_primary(struct hast_resource *res) * very begining. */ error = pthread_create(&td, NULL, guard_thread, res); - assert(error == 0); + PJDLOG_ASSERT(error == 0); /* * Create the control thread before sending any event to the parent, * as we can deadlock when parent sends control request to worker, @@ -867,19 +866,19 @@ hastd_primary(struct hast_resource *res) * request response. */ error = pthread_create(&td, NULL, ctrl_thread, res); - assert(error == 0); + PJDLOG_ASSERT(error == 0); if (real_remote(res) && init_remote(res, NULL, NULL)) sync_start(); error = pthread_create(&td, NULL, ggate_recv_thread, res); - assert(error == 0); + PJDLOG_ASSERT(error == 0); error = pthread_create(&td, NULL, local_send_thread, res); - assert(error == 0); + PJDLOG_ASSERT(error == 0); error = pthread_create(&td, NULL, remote_send_thread, res); - assert(error == 0); + PJDLOG_ASSERT(error == 0); error = pthread_create(&td, NULL, remote_recv_thread, res); - assert(error == 0); + PJDLOG_ASSERT(error == 0); error = pthread_create(&td, NULL, ggate_send_thread, res); - assert(error == 0); + PJDLOG_ASSERT(error == 0); (void)sync_thread(res); } @@ -932,14 +931,14 @@ remote_close(struct hast_resource *res, int ncomp) * another thread can close connection in-between. */ if (!ISCONNECTED(res, ncomp)) { - assert(res->hr_remotein == NULL); - assert(res->hr_remoteout == NULL); + PJDLOG_ASSERT(res->hr_remotein == NULL); + PJDLOG_ASSERT(res->hr_remoteout == NULL); rw_unlock(&hio_remote_lock[ncomp]); return; } - assert(res->hr_remotein != NULL); - assert(res->hr_remoteout != NULL); + PJDLOG_ASSERT(res->hr_remotein != NULL); + PJDLOG_ASSERT(res->hr_remoteout != NULL); pjdlog_debug(2, "Closing incoming connection to %s.", res->hr_remoteaddr); @@ -1051,7 +1050,7 @@ ggate_recv_thread(void *arg) ncomp = 0; } else /* if (res->hr_syncsrc == HAST_SYNCSRC_SECONDARY) */ { - assert(res->hr_syncsrc == + PJDLOG_ASSERT(res->hr_syncsrc == HAST_SYNCSRC_SECONDARY); /* * This range is out-of-date on local component, @@ -1233,8 +1232,8 @@ keepalive_send(struct hast_resource *res, unsigned int ncomp) if (!ISCONNECTED(res, ncomp)) return; - assert(res->hr_remotein != NULL); - assert(res->hr_remoteout != NULL); + PJDLOG_ASSERT(res->hr_remotein != NULL); + PJDLOG_ASSERT(res->hr_remoteout != NULL); nv = nv_alloc(); nv_add_uint8(nv, HIO_KEEPALIVE, "cmd"); @@ -1317,7 +1316,7 @@ remote_send_thread(void *arg) length = 0; break; default: - assert(!"invalid condition"); + PJDLOG_ASSERT(!"invalid condition"); abort(); } nv = nv_alloc(); @@ -1447,7 +1446,7 @@ remote_recv_thread(void *arg) */ mtx_lock(&hio_recv_list_lock[ncomp]); hio = TAILQ_FIRST(&hio_recv_list[ncomp]); - assert(hio != NULL); + PJDLOG_ASSERT(hio != NULL); TAILQ_REMOVE(&hio_recv_list[ncomp], hio, hio_next[ncomp]); mtx_unlock(&hio_recv_list_lock[ncomp]); @@ -1517,7 +1516,7 @@ remote_recv_thread(void *arg) case BIO_FLUSH: break; default: - assert(!"invalid condition"); + PJDLOG_ASSERT(!"invalid condition"); abort(); } hio->hio_errors[ncomp] = 0; @@ -1769,7 +1768,7 @@ sync_thread(void *arg __unused) /* Local component is 0 for now. */ ncomp = 0; } else /* if (res->hr_syncsrc == HAST_SYNCSRC_SECONDARY) */ { - assert(res->hr_syncsrc == HAST_SYNCSRC_SECONDARY); + PJDLOG_ASSERT(res->hr_syncsrc == HAST_SYNCSRC_SECONDARY); /* * This range is out-of-date on local component, * so send request to the remote node. @@ -1816,7 +1815,7 @@ sync_thread(void *arg __unused) /* Remote component is 1 for now. */ ncomp = 1; } else /* if (res->hr_syncsrc == HAST_SYNCSRC_SECONDARY) */ { - assert(res->hr_syncsrc == HAST_SYNCSRC_SECONDARY); + PJDLOG_ASSERT(res->hr_syncsrc == HAST_SYNCSRC_SECONDARY); /* * This range is out-of-date on local component, * so we update it. @@ -1869,8 +1868,8 @@ primary_config_reload(struct hast_resource *res, struct nv *nv) pjdlog_info("Reloading configuration..."); - assert(res->hr_role == HAST_ROLE_PRIMARY); - assert(gres == res); + PJDLOG_ASSERT(res->hr_role == HAST_ROLE_PRIMARY); + PJDLOG_ASSERT(gres == res); nv_assert(nv, "remoteaddr"); nv_assert(nv, "replication"); nv_assert(nv, "timeout"); @@ -1971,16 +1970,16 @@ guard_one(struct hast_resource *res, unsigned int ncomp) } if (ISCONNECTED(res, ncomp)) { - assert(res->hr_remotein != NULL); - assert(res->hr_remoteout != NULL); + PJDLOG_ASSERT(res->hr_remotein != NULL); + PJDLOG_ASSERT(res->hr_remoteout != NULL); rw_unlock(&hio_remote_lock[ncomp]); pjdlog_debug(2, "remote_guard: Connection to %s is ok.", res->hr_remoteaddr); return; } - assert(res->hr_remotein == NULL); - assert(res->hr_remoteout == NULL); + PJDLOG_ASSERT(res->hr_remotein == NULL); + PJDLOG_ASSERT(res->hr_remoteout == NULL); /* * Upgrade the lock. It doesn't have to be atomic as no other thread * can change connection status from disconnected to connected. @@ -1991,9 +1990,9 @@ guard_one(struct hast_resource *res, unsigned int ncomp) in = out = NULL; if (init_remote(res, &in, &out)) { rw_wlock(&hio_remote_lock[ncomp]); - assert(res->hr_remotein == NULL); - assert(res->hr_remoteout == NULL); - assert(in != NULL && out != NULL); + PJDLOG_ASSERT(res->hr_remotein == NULL); + PJDLOG_ASSERT(res->hr_remoteout == NULL); + PJDLOG_ASSERT(in != NULL && out != NULL); res->hr_remotein = in; res->hr_remoteout = out; rw_unlock(&hio_remote_lock[ncomp]); @@ -2002,9 +2001,9 @@ guard_one(struct hast_resource *res, unsigned int ncomp) sync_start(); } else { /* Both connections should be NULL. */ - assert(res->hr_remotein == NULL); - assert(res->hr_remoteout == NULL); - assert(in == NULL && out == NULL); + PJDLOG_ASSERT(res->hr_remotein == NULL); + PJDLOG_ASSERT(res->hr_remoteout == NULL); + PJDLOG_ASSERT(in == NULL && out == NULL); pjdlog_debug(2, "remote_guard: Reconnect to %s failed.", res->hr_remoteaddr); } |