diff --git a/sbin/hastd/activemap.c b/sbin/hastd/activemap.c index 127b2c89e96d..e388bb2eea34 100644 --- a/sbin/hastd/activemap.c +++ b/sbin/hastd/activemap.c @@ -33,7 +33,6 @@ __FBSDID("$FreeBSD$"); #include /* powerof2() */ #include -#include #include #include #include @@ -41,7 +40,14 @@ __FBSDID("$FreeBSD$"); #include #include -#include +#include + +#include "activemap.h" + +#ifndef PJDLOG_ASSERT +#include +#define PJDLOG_ASSERT(...) assert(__VA_ARGS__) +#endif #define ACTIVEMAP_MAGIC 0xac71e4 struct activemap { @@ -93,9 +99,9 @@ off2ext(const struct activemap *amp, off_t offset) { int extent; - assert(offset >= 0 && offset < amp->am_mediasize); + PJDLOG_ASSERT(offset >= 0 && offset < amp->am_mediasize); extent = (offset >> amp->am_extentshift); - assert(extent >= 0 && extent < amp->am_nextents); + PJDLOG_ASSERT(extent >= 0 && extent < amp->am_nextents); return (extent); } @@ -104,9 +110,9 @@ ext2off(const struct activemap *amp, int extent) { off_t offset; - assert(extent >= 0 && extent < amp->am_nextents); + PJDLOG_ASSERT(extent >= 0 && extent < amp->am_nextents); offset = ((off_t)extent << amp->am_extentshift); - assert(offset >= 0 && offset < amp->am_mediasize); + PJDLOG_ASSERT(offset >= 0 && offset < amp->am_mediasize); return (offset); } @@ -122,7 +128,7 @@ ext2reqs(const struct activemap *amp, int ext) if (ext < amp->am_nextents - 1) return (((amp->am_extentsize - 1) / MAXPHYS) + 1); - assert(ext == amp->am_nextents - 1); + PJDLOG_ASSERT(ext == amp->am_nextents - 1); left = amp->am_mediasize % amp->am_extentsize; if (left == 0) left = amp->am_extentsize; @@ -139,13 +145,13 @@ activemap_init(struct activemap **ampp, uint64_t mediasize, uint32_t extentsize, { struct activemap *amp; - assert(ampp != NULL); - assert(mediasize > 0); - assert(extentsize > 0); - assert(powerof2(extentsize)); - assert(sectorsize > 0); - assert(powerof2(sectorsize)); - assert(keepdirty > 0); + PJDLOG_ASSERT(ampp != NULL); + PJDLOG_ASSERT(mediasize > 0); + PJDLOG_ASSERT(extentsize > 0); + PJDLOG_ASSERT(powerof2(extentsize)); + PJDLOG_ASSERT(sectorsize > 0); + PJDLOG_ASSERT(powerof2(sectorsize)); + PJDLOG_ASSERT(keepdirty > 0); amp = malloc(sizeof(*amp)); if (amp == NULL) @@ -225,10 +231,10 @@ keepdirty_add(struct activemap *amp, int extent) */ if (amp->am_nkeepdirty >= amp->am_nkeepdirty_limit) { kd = TAILQ_LAST(&->am_keepdirty, skeepdirty); - assert(kd != NULL); + PJDLOG_ASSERT(kd != NULL); TAILQ_REMOVE(&->am_keepdirty, kd, kd_next); amp->am_nkeepdirty--; - assert(amp->am_nkeepdirty > 0); + PJDLOG_ASSERT(amp->am_nkeepdirty > 0); } if (kd == NULL) kd = malloc(sizeof(*kd)); @@ -261,7 +267,7 @@ keepdirty_free(struct activemap *amp) amp->am_nkeepdirty--; free(kd); } - assert(amp->am_nkeepdirty == 0); + PJDLOG_ASSERT(amp->am_nkeepdirty == 0); } /* @@ -271,7 +277,7 @@ void activemap_free(struct activemap *amp) { - assert(amp->am_magic == ACTIVEMAP_MAGIC); + PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC); amp->am_magic = 0; @@ -293,8 +299,8 @@ activemap_write_start(struct activemap *amp, off_t offset, off_t length) off_t end; int ext; - assert(amp->am_magic == ACTIVEMAP_MAGIC); - assert(length > 0); + PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC); + PJDLOG_ASSERT(length > 0); modified = false; end = offset + length - 1; @@ -307,7 +313,7 @@ activemap_write_start(struct activemap *amp, off_t offset, off_t length) * was modified and has to be flushed to disk. */ if (amp->am_memtab[ext]++ == 0) { - assert(!bit_test(amp->am_memmap, ext)); + PJDLOG_ASSERT(!bit_test(amp->am_memmap, ext)); bit_set(amp->am_memmap, ext); amp->am_ndirty++; } @@ -329,8 +335,8 @@ activemap_write_complete(struct activemap *amp, off_t offset, off_t length) off_t end; int ext; - assert(amp->am_magic == ACTIVEMAP_MAGIC); - assert(length > 0); + PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC); + PJDLOG_ASSERT(length > 0); modified = false; end = offset + length - 1; @@ -342,8 +348,8 @@ activemap_write_complete(struct activemap *amp, off_t offset, off_t length) * By returning true we inform the caller that on-disk bitmap * was modified and has to be flushed to disk. */ - assert(amp->am_memtab[ext] > 0); - assert(bit_test(amp->am_memmap, ext)); + PJDLOG_ASSERT(amp->am_memtab[ext] > 0); + PJDLOG_ASSERT(bit_test(amp->am_memmap, ext)); if (--amp->am_memtab[ext] == 0) { bit_clear(amp->am_memmap, ext); amp->am_ndirty--; @@ -365,15 +371,15 @@ activemap_extent_complete(struct activemap *amp, int extent) bool modified; int reqs; - assert(amp->am_magic == ACTIVEMAP_MAGIC); - assert(extent >= 0 && extent < amp->am_nextents); + PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC); + PJDLOG_ASSERT(extent >= 0 && extent < amp->am_nextents); modified = false; reqs = ext2reqs(amp, extent); - assert(amp->am_memtab[extent] >= reqs); + PJDLOG_ASSERT(amp->am_memtab[extent] >= reqs); amp->am_memtab[extent] -= reqs; - assert(bit_test(amp->am_memmap, extent)); + PJDLOG_ASSERT(bit_test(amp->am_memmap, extent)); if (amp->am_memtab[extent] == 0) { bit_clear(amp->am_memmap, extent); amp->am_ndirty--; @@ -390,7 +396,7 @@ uint64_t activemap_ndirty(const struct activemap *amp) { - assert(amp->am_magic == ACTIVEMAP_MAGIC); + PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC); return (amp->am_ndirty); } @@ -403,7 +409,7 @@ bool activemap_differ(const struct activemap *amp) { - assert(amp->am_magic == ACTIVEMAP_MAGIC); + PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC); return (memcmp(amp->am_diskmap, amp->am_memmap, amp->am_mapsize) != 0); @@ -416,7 +422,7 @@ size_t activemap_size(const struct activemap *amp) { - assert(amp->am_magic == ACTIVEMAP_MAGIC); + PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC); return (amp->am_mapsize); } @@ -429,7 +435,7 @@ size_t activemap_ondisk_size(const struct activemap *amp) { - assert(amp->am_magic == ACTIVEMAP_MAGIC); + PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC); return (amp->am_diskmapsize); } @@ -442,8 +448,8 @@ activemap_copyin(struct activemap *amp, const unsigned char *buf, size_t size) { int ext; - assert(amp->am_magic == ACTIVEMAP_MAGIC); - assert(size >= amp->am_mapsize); + PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC); + PJDLOG_ASSERT(size >= amp->am_mapsize); memcpy(amp->am_diskmap, buf, amp->am_mapsize); memcpy(amp->am_memmap, buf, amp->am_mapsize); @@ -481,8 +487,8 @@ activemap_merge(struct activemap *amp, const unsigned char *buf, size_t size) bitstr_t *remmap = __DECONST(bitstr_t *, buf); int ext; - assert(amp->am_magic == ACTIVEMAP_MAGIC); - assert(size >= amp->am_mapsize); + PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC); + PJDLOG_ASSERT(size >= amp->am_mapsize); bit_ffs(remmap, amp->am_nextents, &ext); if (ext == -1) { @@ -521,7 +527,7 @@ const unsigned char * activemap_bitmap(struct activemap *amp, size_t *sizep) { - assert(amp->am_magic == ACTIVEMAP_MAGIC); + PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC); if (sizep != NULL) *sizep = amp->am_diskmapsize; @@ -539,11 +545,11 @@ activemap_calc_ondisk_size(uint64_t mediasize, uint32_t extentsize, { uint64_t nextents, mapsize; - assert(mediasize > 0); - assert(extentsize > 0); - assert(powerof2(extentsize)); - assert(sectorsize > 0); - assert(powerof2(sectorsize)); + PJDLOG_ASSERT(mediasize > 0); + PJDLOG_ASSERT(extentsize > 0); + PJDLOG_ASSERT(powerof2(extentsize)); + PJDLOG_ASSERT(sectorsize > 0); + PJDLOG_ASSERT(powerof2(sectorsize)); nextents = ((mediasize - 1) / extentsize) + 1; mapsize = sizeof(bitstr_t) * bitstr_size(nextents); @@ -558,7 +564,7 @@ activemap_sync_rewind(struct activemap *amp) { int ext; - assert(amp->am_magic == ACTIVEMAP_MAGIC); + PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC); bit_ffs(amp->am_syncmap, amp->am_nextents, &ext); if (ext == -1) { @@ -581,9 +587,9 @@ activemap_sync_offset(struct activemap *amp, off_t *lengthp, int *syncextp) off_t syncoff, left; int ext; - assert(amp->am_magic == ACTIVEMAP_MAGIC); - assert(lengthp != NULL); - assert(syncextp != NULL); + PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC); + PJDLOG_ASSERT(lengthp != NULL); + PJDLOG_ASSERT(syncextp != NULL); *syncextp = -1; @@ -632,9 +638,10 @@ activemap_sync_offset(struct activemap *amp, off_t *lengthp, int *syncextp) if (left > MAXPHYS) left = MAXPHYS; - assert(left >= 0 && left <= MAXPHYS); - assert(syncoff >= 0 && syncoff < amp->am_mediasize); - assert(syncoff + left >= 0 && syncoff + left <= amp->am_mediasize); + PJDLOG_ASSERT(left >= 0 && left <= MAXPHYS); + PJDLOG_ASSERT(syncoff >= 0 && syncoff < amp->am_mediasize); + PJDLOG_ASSERT(syncoff + left >= 0 && + syncoff + left <= amp->am_mediasize); *lengthp = left; return (syncoff); @@ -651,7 +658,7 @@ activemap_need_sync(struct activemap *amp, off_t offset, off_t length) off_t end; int ext; - assert(amp->am_magic == ACTIVEMAP_MAGIC); + PJDLOG_ASSERT(amp->am_magic == ACTIVEMAP_MAGIC); modified = false; end = offset + length - 1; @@ -659,7 +666,7 @@ activemap_need_sync(struct activemap *amp, off_t offset, off_t length) for (ext = off2ext(amp, offset); ext <= off2ext(amp, end); ext++) { if (bit_test(amp->am_syncmap, ext)) { /* Already marked for synchronization. */ - assert(bit_test(amp->am_memmap, ext)); + PJDLOG_ASSERT(bit_test(amp->am_memmap, ext)); continue; } bit_set(amp->am_syncmap, ext); diff --git a/sbin/hastd/ebuf.c b/sbin/hastd/ebuf.c index 0bccd181cc35..f5908a41a92b 100644 --- a/sbin/hastd/ebuf.c +++ b/sbin/hastd/ebuf.c @@ -32,15 +32,21 @@ __FBSDID("$FreeBSD$"); #include -#include #include #include #include #include #include +#include + #include "ebuf.h" +#ifndef PJDLOG_ASSERT +#include +#define PJDLOG_ASSERT(...) assert(__VA_ARGS__) +#endif + #define EBUF_MAGIC 0xeb0f41c struct ebuf { /* Magic to assert the caller uses valid structure. */ @@ -91,7 +97,7 @@ void ebuf_free(struct ebuf *eb) { - assert(eb != NULL && eb->eb_magic == EBUF_MAGIC); + PJDLOG_ASSERT(eb != NULL && eb->eb_magic == EBUF_MAGIC); eb->eb_magic = 0; @@ -103,7 +109,7 @@ int ebuf_add_head(struct ebuf *eb, const void *data, size_t size) { - assert(eb != NULL && eb->eb_magic == EBUF_MAGIC); + PJDLOG_ASSERT(eb != NULL && eb->eb_magic == EBUF_MAGIC); if (size > (size_t)(eb->eb_used - eb->eb_start)) { /* @@ -113,7 +119,7 @@ ebuf_add_head(struct ebuf *eb, const void *data, size_t size) if (ebuf_head_extend(eb, size) < 0) return (-1); } - assert(size <= (size_t)(eb->eb_used - eb->eb_start)); + PJDLOG_ASSERT(size <= (size_t)(eb->eb_used - eb->eb_start)); eb->eb_size += size; eb->eb_used -= size; @@ -130,7 +136,7 @@ int ebuf_add_tail(struct ebuf *eb, const void *data, size_t size) { - assert(eb != NULL && eb->eb_magic == EBUF_MAGIC); + PJDLOG_ASSERT(eb != NULL && eb->eb_magic == EBUF_MAGIC); if (size > (size_t)(eb->eb_end - (eb->eb_used + eb->eb_size))) { /* @@ -140,7 +146,8 @@ ebuf_add_tail(struct ebuf *eb, const void *data, size_t size) if (ebuf_tail_extend(eb, size) < 0) return (-1); } - assert(size <= (size_t)(eb->eb_end - (eb->eb_used + eb->eb_size))); + PJDLOG_ASSERT(size <= + (size_t)(eb->eb_end - (eb->eb_used + eb->eb_size))); /* * If data is NULL the caller just wants to reserve space. @@ -156,8 +163,8 @@ void ebuf_del_head(struct ebuf *eb, size_t size) { - assert(eb != NULL && eb->eb_magic == EBUF_MAGIC); - assert(size <= eb->eb_size); + PJDLOG_ASSERT(eb != NULL && eb->eb_magic == EBUF_MAGIC); + PJDLOG_ASSERT(size <= eb->eb_size); eb->eb_used += size; eb->eb_size -= size; @@ -167,8 +174,8 @@ void ebuf_del_tail(struct ebuf *eb, size_t size) { - assert(eb != NULL && eb->eb_magic == EBUF_MAGIC); - assert(size <= eb->eb_size); + PJDLOG_ASSERT(eb != NULL && eb->eb_magic == EBUF_MAGIC); + PJDLOG_ASSERT(size <= eb->eb_size); eb->eb_size -= size; } @@ -180,7 +187,7 @@ void * ebuf_data(struct ebuf *eb, size_t *sizep) { - assert(eb != NULL && eb->eb_magic == EBUF_MAGIC); + PJDLOG_ASSERT(eb != NULL && eb->eb_magic == EBUF_MAGIC); if (sizep != NULL) *sizep = eb->eb_size; @@ -194,7 +201,7 @@ size_t ebuf_size(struct ebuf *eb) { - assert(eb != NULL && eb->eb_magic == EBUF_MAGIC); + PJDLOG_ASSERT(eb != NULL && eb->eb_magic == EBUF_MAGIC); return (eb->eb_size); } @@ -208,7 +215,7 @@ ebuf_head_extend(struct ebuf *eb, size_t size) unsigned char *newstart, *newused; size_t newsize; - assert(eb != NULL && eb->eb_magic == EBUF_MAGIC); + PJDLOG_ASSERT(eb != NULL && eb->eb_magic == EBUF_MAGIC); newsize = eb->eb_end - eb->eb_start + (PAGE_SIZE / 4) + size; @@ -236,7 +243,7 @@ ebuf_tail_extend(struct ebuf *eb, size_t size) unsigned char *newstart; size_t newsize; - assert(eb != NULL && eb->eb_magic == EBUF_MAGIC); + PJDLOG_ASSERT(eb != NULL && eb->eb_magic == EBUF_MAGIC); newsize = eb->eb_end - eb->eb_start + size + ((3 * PAGE_SIZE) / 4); diff --git a/sbin/hastd/event.c b/sbin/hastd/event.c index d772f692ba2e..d895f670177a 100644 --- a/sbin/hastd/event.c +++ b/sbin/hastd/event.c @@ -27,7 +27,6 @@ #include __FBSDID("$FreeBSD$"); -#include #include #include "hast.h" @@ -46,8 +45,8 @@ event_send(const struct hast_resource *res, int event) struct nv *nvin, *nvout; int error; - assert(res != NULL); - assert(event >= EVENT_MIN && event <= EVENT_MAX); + PJDLOG_ASSERT(res != NULL); + PJDLOG_ASSERT(event >= EVENT_MIN && event <= EVENT_MAX); nvin = nvout = NULL; @@ -89,7 +88,7 @@ event_recv(const struct hast_resource *res) uint8_t event; int error; - assert(res != NULL); + PJDLOG_ASSERT(res != NULL); nvin = nvout = NULL; diff --git a/sbin/hastd/hast_proto.c b/sbin/hastd/hast_proto.c index 89568914f5f7..439b0f31940f 100644 --- a/sbin/hastd/hast_proto.c +++ b/sbin/hastd/hast_proto.c @@ -33,7 +33,6 @@ __FBSDID("$FreeBSD$"); #include -#include #include #include @@ -158,7 +157,7 @@ hast_proto_recv_hdr(const struct proto_conn *conn, struct nv **nvp) if (ebuf_add_tail(eb, NULL, hdr.size) < 0) goto fail; hptr = ebuf_data(eb, NULL); - assert(hptr != NULL); + PJDLOG_ASSERT(hptr != NULL); if (proto_recv(conn, hptr, hdr.size) < 0) goto fail; nv = nv_ntoh(eb); @@ -183,8 +182,8 @@ hast_proto_recv_data(const struct hast_resource *res, struct proto_conn *conn, void *dptr; int ret; - assert(data != NULL); - assert(size > 0); + PJDLOG_ASSERT(data != NULL); + PJDLOG_ASSERT(size > 0); ret = -1; freedata = false; diff --git a/sbin/hastd/hooks.c b/sbin/hastd/hooks.c index b161c0c0442b..60d48d1384fd 100644 --- a/sbin/hastd/hooks.c +++ b/sbin/hastd/hooks.c @@ -35,7 +35,6 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include #include #include @@ -138,7 +137,7 @@ void hook_init(void) { - assert(!hooks_initialized); + PJDLOG_ASSERT(!hooks_initialized); mtx_init(&hookprocs_lock); TAILQ_INIT(&hookprocs); @@ -150,12 +149,12 @@ hook_fini(void) { struct hookproc *hp; - assert(hooks_initialized); + PJDLOG_ASSERT(hooks_initialized); mtx_lock(&hookprocs_lock); while ((hp = TAILQ_FIRST(&hookprocs)) != NULL) { - assert(hp->hp_magic == HOOKPROC_MAGIC_ONLIST); - assert(hp->hp_pid > 0); + PJDLOG_ASSERT(hp->hp_magic == HOOKPROC_MAGIC_ONLIST); + PJDLOG_ASSERT(hp->hp_pid > 0); hook_remove(hp); hook_free(hp); @@ -201,8 +200,8 @@ static void hook_add(struct hookproc *hp, pid_t pid) { - assert(hp->hp_magic == HOOKPROC_MAGIC_ALLOCATED); - assert(hp->hp_pid == 0); + PJDLOG_ASSERT(hp->hp_magic == HOOKPROC_MAGIC_ALLOCATED); + PJDLOG_ASSERT(hp->hp_pid == 0); hp->hp_pid = pid; mtx_lock(&hookprocs_lock); @@ -215,9 +214,9 @@ static void hook_remove(struct hookproc *hp) { - assert(hp->hp_magic == HOOKPROC_MAGIC_ONLIST); - assert(hp->hp_pid > 0); - assert(mtx_owned(&hookprocs_lock)); + PJDLOG_ASSERT(hp->hp_magic == HOOKPROC_MAGIC_ONLIST); + PJDLOG_ASSERT(hp->hp_pid > 0); + PJDLOG_ASSERT(mtx_owned(&hookprocs_lock)); TAILQ_REMOVE(&hookprocs, hp, hp_next); hp->hp_magic = HOOKPROC_MAGIC_ALLOCATED; @@ -227,8 +226,8 @@ static void hook_free(struct hookproc *hp) { - assert(hp->hp_magic == HOOKPROC_MAGIC_ALLOCATED); - assert(hp->hp_pid > 0); + PJDLOG_ASSERT(hp->hp_magic == HOOKPROC_MAGIC_ALLOCATED); + PJDLOG_ASSERT(hp->hp_pid > 0); hp->hp_magic = 0; free(hp); @@ -239,11 +238,11 @@ hook_find(pid_t pid) { struct hookproc *hp; - assert(mtx_owned(&hookprocs_lock)); + PJDLOG_ASSERT(mtx_owned(&hookprocs_lock)); TAILQ_FOREACH(hp, &hookprocs, hp_next) { - assert(hp->hp_magic == HOOKPROC_MAGIC_ONLIST); - assert(hp->hp_pid > 0); + PJDLOG_ASSERT(hp->hp_magic == HOOKPROC_MAGIC_ONLIST); + PJDLOG_ASSERT(hp->hp_pid > 0); if (hp->hp_pid == pid) break; @@ -286,7 +285,7 @@ hook_check(void) struct hookproc *hp, *hp2; time_t now; - assert(hooks_initialized); + PJDLOG_ASSERT(hooks_initialized); pjdlog_debug(2, "Checking hooks."); @@ -296,8 +295,8 @@ hook_check(void) now = time(NULL); mtx_lock(&hookprocs_lock); TAILQ_FOREACH_SAFE(hp, &hookprocs, hp_next, hp2) { - assert(hp->hp_magic == HOOKPROC_MAGIC_ONLIST); - assert(hp->hp_pid > 0); + PJDLOG_ASSERT(hp->hp_magic == HOOKPROC_MAGIC_ONLIST); + PJDLOG_ASSERT(hp->hp_pid > 0); /* * If process doesn't exists we somehow missed it. @@ -347,7 +346,7 @@ hook_execv(const char *path, va_list ap) sigset_t mask; pid_t pid; - assert(hooks_initialized); + PJDLOG_ASSERT(hooks_initialized); if (path == NULL || path[0] == '\0') return; @@ -359,7 +358,7 @@ hook_execv(const char *path, va_list ap) if (args[ii] == NULL) break; } - assert(ii < sizeof(args) / sizeof(args[0])); + PJDLOG_ASSERT(ii < sizeof(args) / sizeof(args[0])); hp = hook_alloc(path, args); if (hp == NULL) diff --git a/sbin/hastd/metadata.c b/sbin/hastd/metadata.c index de21b53ef50d..ad6c75bbd3c8 100644 --- a/sbin/hastd/metadata.c +++ b/sbin/hastd/metadata.c @@ -30,7 +30,6 @@ #include __FBSDID("$FreeBSD$"); -#include #include #include #include @@ -100,7 +99,7 @@ metadata_read(struct hast_resource *res, bool openrw) goto fail; } buf = ebuf_data(eb, NULL); - assert(buf != NULL); + PJDLOG_ASSERT(buf != NULL); done = pread(res->hr_localfd, buf, METADATA_SIZE, 0); if (done < 0 || done != METADATA_SIZE) { rerrno = errno; @@ -197,7 +196,7 @@ metadata_write(struct hast_resource *res) nv_add_uint64(nv, res->hr_primary_localcnt, "localcnt"); nv_add_uint64(nv, res->hr_primary_remotecnt, "remotecnt"); } else /* if (res->hr_role == HAST_ROLE_SECONDARY) */ { - assert(res->hr_role == HAST_ROLE_SECONDARY); + PJDLOG_ASSERT(res->hr_role == HAST_ROLE_SECONDARY); nv_add_uint64(nv, res->hr_secondary_localcnt, "localcnt"); nv_add_uint64(nv, res->hr_secondary_remotecnt, "remotecnt"); } @@ -208,10 +207,10 @@ metadata_write(struct hast_resource *res) } res->hr_previous_role = res->hr_role; eb = nv_hton(nv); - assert(eb != NULL); + PJDLOG_ASSERT(eb != NULL); ptr = ebuf_data(eb, &size); - assert(ptr != NULL); - assert(size < METADATA_SIZE); + PJDLOG_ASSERT(ptr != NULL); + PJDLOG_ASSERT(size < METADATA_SIZE); bcopy(ptr, buf, size); done = pwrite(res->hr_localfd, buf, METADATA_SIZE, 0); if (done < 0 || done != METADATA_SIZE) { diff --git a/sbin/hastd/nv.c b/sbin/hastd/nv.c index 1f994ee8b901..89c174ace0c4 100644 --- a/sbin/hastd/nv.c +++ b/sbin/hastd/nv.c @@ -33,7 +33,6 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include #include #include @@ -44,7 +43,17 @@ __FBSDID("$FreeBSD$"); #include #include -#include +#include + +#include "nv.h" + +#ifndef PJDLOG_ASSERT +#include +#define PJDLOG_ASSERT(...) assert(__VA_ARGS__) +#endif +#ifndef PJDLOG_ABORT +#define PJDLOG_ABORT(...) abort() +#endif #define NV_TYPE_NONE 0 @@ -98,8 +107,8 @@ struct nvhdr { #define NVH_SIZE(nvh) (NVH_HSIZE(nvh) + roundup2(NVH_DSIZE(nvh), 8)) #define NV_CHECK(nv) do { \ - assert((nv) != NULL); \ - assert((nv)->nv_magic == NV_MAGIC); \ + PJDLOG_ASSERT((nv) != NULL); \ + PJDLOG_ASSERT((nv)->nv_magic == NV_MAGIC); \ } while (0) static void nv_add(struct nv *nv, const unsigned char *value, size_t vsize, @@ -200,7 +209,7 @@ nv_validate(struct nv *nv, size_t *extrap) } NV_CHECK(nv); - assert(nv->nv_error == 0); + PJDLOG_ASSERT(nv->nv_error == 0); /* TODO: Check that names are unique? */ @@ -308,7 +317,7 @@ nv_validate(struct nv *nv, size_t *extrap) } break; default: - assert(!"invalid condition"); + PJDLOG_ABORT("invalid condition"); } if (error != 0) break; @@ -338,7 +347,7 @@ nv_hton(struct nv *nv) size_t size; NV_CHECK(nv); - assert(nv->nv_error == 0); + PJDLOG_ASSERT(nv->nv_error == 0); ptr = ebuf_data(nv->nv_ebuf, &size); while (size > 0) { @@ -346,9 +355,9 @@ nv_hton(struct nv *nv) * Minimum size at this point is size of nvhdr structure, * one character long name plus terminating '\0'. */ - assert(size >= sizeof(*nvh) + 2); + PJDLOG_ASSERT(size >= sizeof(*nvh) + 2); nvh = (struct nvhdr *)ptr; - assert(NVH_SIZE(nvh) <= size); + PJDLOG_ASSERT(NVH_SIZE(nvh) <= size); nv_swap(nvh, false); ptr += NVH_SIZE(nvh); size -= NVH_SIZE(nvh); @@ -367,7 +376,7 @@ nv_ntoh(struct ebuf *eb) size_t extra; int rerrno; - assert(eb != NULL); + PJDLOG_ASSERT(eb != NULL); nv = malloc(sizeof(*nv)); if (nv == NULL) @@ -494,8 +503,8 @@ nv_get_##type(struct nv *nv, const char *namefmt, ...) \ va_end(nameap); \ if (nvh == NULL) \ return (0); \ - assert((nvh->nvh_type & NV_ORDER_MASK) == NV_ORDER_HOST); \ - assert(sizeof(value) == nvh->nvh_dsize); \ + PJDLOG_ASSERT((nvh->nvh_type & NV_ORDER_MASK) == NV_ORDER_HOST);\ + PJDLOG_ASSERT(sizeof(value) == nvh->nvh_dsize); \ bcopy(NVH_DATA(nvh), &value, sizeof(value)); \ \ return (value); \ @@ -525,8 +534,8 @@ nv_get_##type##_array(struct nv *nv, size_t *sizep, \ va_end(nameap); \ if (nvh == NULL) \ return (NULL); \ - assert((nvh->nvh_type & NV_ORDER_MASK) == NV_ORDER_HOST); \ - assert((nvh->nvh_dsize % sizeof(type##_t)) == 0); \ + PJDLOG_ASSERT((nvh->nvh_type & NV_ORDER_MASK) == NV_ORDER_HOST);\ + PJDLOG_ASSERT((nvh->nvh_dsize % sizeof(type##_t)) == 0); \ if (sizep != NULL) \ *sizep = nvh->nvh_dsize / sizeof(type##_t); \ return ((type##_t *)(void *)NVH_DATA(nvh)); \ @@ -555,11 +564,11 @@ nv_get_string(struct nv *nv, const char *namefmt, ...) va_end(nameap); if (nvh == NULL) return (NULL); - assert((nvh->nvh_type & NV_ORDER_MASK) == NV_ORDER_HOST); - assert(nvh->nvh_dsize >= 1); + PJDLOG_ASSERT((nvh->nvh_type & NV_ORDER_MASK) == NV_ORDER_HOST); + PJDLOG_ASSERT(nvh->nvh_dsize >= 1); str = NVH_DATA(nvh); - assert(str[nvh->nvh_dsize - 1] == '\0'); - assert(strlen(str) == nvh->nvh_dsize - 1); + PJDLOG_ASSERT(str[nvh->nvh_dsize - 1] == '\0'); + PJDLOG_ASSERT(strlen(str) == nvh->nvh_dsize - 1); return (str); } @@ -602,7 +611,7 @@ nv_assert(struct nv *nv, const char *namefmt, ...) va_list nameap; va_start(nameap, namefmt); - assert(nv_vexists(nv, namefmt, nameap)); + PJDLOG_ASSERT(nv_vexists(nv, namefmt, nameap)); va_end(nameap); } @@ -624,13 +633,13 @@ nv_dump(struct nv *nv) } NV_CHECK(nv); - assert(nv->nv_error == 0); + PJDLOG_ASSERT(nv->nv_error == 0); ptr = ebuf_data(nv->nv_ebuf, &size); while (size > 0) { - assert(size >= sizeof(*nvh) + 2); + PJDLOG_ASSERT(size >= sizeof(*nvh) + 2); nvh = (struct nvhdr *)ptr; - assert(size >= NVH_SIZE(nvh)); + PJDLOG_ASSERT(size >= NVH_SIZE(nvh)); swap = ((nvh->nvh_type & NV_ORDER_MASK) == NV_ORDER_NETWORK); dsize = NVH_DSIZE(nvh); data = NVH_DATA(nvh); @@ -734,7 +743,7 @@ nv_dump(struct nv *nv) printf("(string): %s", (char *)data); break; default: - assert(!"invalid condition"); + PJDLOG_ABORT("invalid condition"); } printf("\n"); ptr += NVH_SIZE(nvh); @@ -776,7 +785,7 @@ nv_add(struct nv *nv, const unsigned char *value, size_t vsize, int type, /* Add header first. */ if (ebuf_add_tail(nv->nv_ebuf, nvh, NVH_HSIZE(nvh)) < 0) { - assert(errno != 0); + PJDLOG_ASSERT(errno != 0); if (nv->nv_error == 0) nv->nv_error = errno; free(nvh); @@ -785,7 +794,7 @@ nv_add(struct nv *nv, const unsigned char *value, size_t vsize, int type, free(nvh); /* Add the actual data. */ if (ebuf_add_tail(nv->nv_ebuf, value, vsize) < 0) { - assert(errno != 0); + PJDLOG_ASSERT(errno != 0); if (nv->nv_error == 0) nv->nv_error = errno; return; @@ -794,9 +803,9 @@ nv_add(struct nv *nv, const unsigned char *value, size_t vsize, int type, vsize = roundup2(vsize, 8) - vsize; if (vsize == 0) return; - assert(vsize > 0 && vsize <= sizeof(align)); + PJDLOG_ASSERT(vsize > 0 && vsize <= sizeof(align)); if (ebuf_add_tail(nv->nv_ebuf, align, vsize) < 0) { - assert(errno != 0); + PJDLOG_ASSERT(errno != 0); if (nv->nv_error == 0) nv->nv_error = errno; return; @@ -811,7 +820,7 @@ nv_addv(struct nv *nv, const unsigned char *value, size_t vsize, int type, size_t namesize; namesize = vsnprintf(name, sizeof(name), namefmt, nameap); - assert(namesize > 0 && namesize < sizeof(name)); + PJDLOG_ASSERT(namesize > 0 && namesize < sizeof(name)); nv_add(nv, value, vsize, type, name); } @@ -832,14 +841,14 @@ nv_find(struct nv *nv, int type, const char *namefmt, va_list nameap) NV_CHECK(nv); namesize = vsnprintf(name, sizeof(name), namefmt, nameap); - assert(namesize > 0 && namesize < sizeof(name)); + PJDLOG_ASSERT(namesize > 0 && namesize < sizeof(name)); namesize++; ptr = ebuf_data(nv->nv_ebuf, &size); while (size > 0) { - assert(size >= sizeof(*nvh) + 2); + PJDLOG_ASSERT(size >= sizeof(*nvh) + 2); nvh = (struct nvhdr *)ptr; - assert(size >= NVH_SIZE(nvh)); + PJDLOG_ASSERT(size >= NVH_SIZE(nvh)); nv_swap(nvh, true); if (strcmp(nvh->nvh_name, name) == 0) { if (type != NV_TYPE_NONE && @@ -927,7 +936,7 @@ nv_swap(struct nvhdr *nvh, bool tohost) le64toh(*(uint64_t *)(void *)p); break; default: - assert(!"invalid condition"); + PJDLOG_ABORT("invalid condition"); } } else { switch (vsize) { @@ -944,7 +953,7 @@ nv_swap(struct nvhdr *nvh, bool tohost) htole64(*(uint64_t *)(void *)p); break; default: - assert(!"invalid condition"); + PJDLOG_ABORT("invalid condition"); } } } @@ -952,6 +961,6 @@ nv_swap(struct nvhdr *nvh, bool tohost) case NV_TYPE_STRING: break; default: - assert(!"unrecognized type"); + PJDLOG_ABORT("unrecognized type"); } } diff --git a/sbin/hastd/rangelock.c b/sbin/hastd/rangelock.c index 02247d6e3b41..5ff1f19daeeb 100644 --- a/sbin/hastd/rangelock.c +++ b/sbin/hastd/rangelock.c @@ -32,13 +32,19 @@ __FBSDID("$FreeBSD$"); #include -#include #include #include #include +#include + #include "rangelock.h" +#ifndef PJDLOG_ASSERT +#include +#define PJDLOG_ASSERT(...) assert(__VA_ARGS__) +#endif + #define RANGELOCKS_MAGIC 0x94310c struct rangelocks { int rls_magic; /* Magic value. */ @@ -56,7 +62,7 @@ rangelock_init(struct rangelocks **rlsp) { struct rangelocks *rls; - assert(rlsp != NULL); + PJDLOG_ASSERT(rlsp != NULL); rls = malloc(sizeof(*rls)); if (rls == NULL) @@ -75,7 +81,7 @@ rangelock_free(struct rangelocks *rls) { struct rlock *rl; - assert(rls->rls_magic == RANGELOCKS_MAGIC); + PJDLOG_ASSERT(rls->rls_magic == RANGELOCKS_MAGIC); rls->rls_magic = 0; @@ -91,7 +97,7 @@ rangelock_add(struct rangelocks *rls, off_t offset, off_t length) { struct rlock *rl; - assert(rls->rls_magic == RANGELOCKS_MAGIC); + PJDLOG_ASSERT(rls->rls_magic == RANGELOCKS_MAGIC); rl = malloc(sizeof(*rl)); if (rl == NULL) @@ -107,13 +113,13 @@ rangelock_del(struct rangelocks *rls, off_t offset, off_t length) { struct rlock *rl; - assert(rls->rls_magic == RANGELOCKS_MAGIC); + PJDLOG_ASSERT(rls->rls_magic == RANGELOCKS_MAGIC); TAILQ_FOREACH(rl, &rls->rls_locks, rl_next) { if (rl->rl_start == offset && rl->rl_end == offset + length) break; } - assert(rl != NULL); + PJDLOG_ASSERT(rl != NULL); TAILQ_REMOVE(&rls->rls_locks, rl, rl_next); free(rl); } @@ -123,7 +129,7 @@ rangelock_islocked(struct rangelocks *rls, off_t offset, off_t length) { struct rlock *rl; - assert(rls->rls_magic == RANGELOCKS_MAGIC); + PJDLOG_ASSERT(rls->rls_magic == RANGELOCKS_MAGIC); TAILQ_FOREACH(rl, &rls->rls_locks, rl_next) { if (rl->rl_start >= offset && rl->rl_start < offset + length) diff --git a/sbin/hastd/synch.h b/sbin/hastd/synch.h index cf388d7d0cd6..36e19278921d 100644 --- a/sbin/hastd/synch.h +++ b/sbin/hastd/synch.h @@ -32,20 +32,26 @@ #ifndef _SYNCH_H_ #define _SYNCH_H_ -#include #include #include #include #include #include +#include + +#ifndef PJDLOG_ASSERT +#include +#define PJDLOG_ASSERT(...) assert(__VA_ARGS__) +#endif + static __inline void mtx_init(pthread_mutex_t *lock) { int error; error = pthread_mutex_init(lock, NULL); - assert(error == 0); + PJDLOG_ASSERT(error == 0); } static __inline void mtx_destroy(pthread_mutex_t *lock) @@ -53,7 +59,7 @@ mtx_destroy(pthread_mutex_t *lock) int error; error = pthread_mutex_destroy(lock); - assert(error == 0); + PJDLOG_ASSERT(error == 0); } static __inline void mtx_lock(pthread_mutex_t *lock) @@ -61,7 +67,7 @@ mtx_lock(pthread_mutex_t *lock) int error; error = pthread_mutex_lock(lock); - assert(error == 0); + PJDLOG_ASSERT(error == 0); } static __inline bool mtx_trylock(pthread_mutex_t *lock) @@ -69,7 +75,7 @@ mtx_trylock(pthread_mutex_t *lock) int error; error = pthread_mutex_trylock(lock); - assert(error == 0 || error == EBUSY); + PJDLOG_ASSERT(error == 0 || error == EBUSY); return (error == 0); } static __inline void @@ -78,7 +84,7 @@ mtx_unlock(pthread_mutex_t *lock) int error; error = pthread_mutex_unlock(lock); - assert(error == 0); + PJDLOG_ASSERT(error == 0); } static __inline bool mtx_owned(pthread_mutex_t *lock) @@ -93,7 +99,7 @@ rw_init(pthread_rwlock_t *lock) int error; error = pthread_rwlock_init(lock, NULL); - assert(error == 0); + PJDLOG_ASSERT(error == 0); } static __inline void rw_destroy(pthread_rwlock_t *lock) @@ -101,7 +107,7 @@ rw_destroy(pthread_rwlock_t *lock) int error; error = pthread_rwlock_destroy(lock); - assert(error == 0); + PJDLOG_ASSERT(error == 0); } static __inline void rw_rlock(pthread_rwlock_t *lock) @@ -109,7 +115,7 @@ rw_rlock(pthread_rwlock_t *lock) int error; error = pthread_rwlock_rdlock(lock); - assert(error == 0); + PJDLOG_ASSERT(error == 0); } static __inline void rw_wlock(pthread_rwlock_t *lock) @@ -117,7 +123,7 @@ rw_wlock(pthread_rwlock_t *lock) int error; error = pthread_rwlock_wrlock(lock); - assert(error == 0); + PJDLOG_ASSERT(error == 0); } static __inline void rw_unlock(pthread_rwlock_t *lock) @@ -125,7 +131,7 @@ rw_unlock(pthread_rwlock_t *lock) int error; error = pthread_rwlock_unlock(lock); - assert(error == 0); + PJDLOG_ASSERT(error == 0); } static __inline void @@ -135,13 +141,13 @@ cv_init(pthread_cond_t *cv) int error; error = pthread_condattr_init(&attr); - assert(error == 0); + PJDLOG_ASSERT(error == 0); error = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC); - assert(error == 0); + PJDLOG_ASSERT(error == 0); error = pthread_cond_init(cv, &attr); - assert(error == 0); + PJDLOG_ASSERT(error == 0); error = pthread_condattr_destroy(&attr); - assert(error == 0); + PJDLOG_ASSERT(error == 0); } static __inline void cv_wait(pthread_cond_t *cv, pthread_mutex_t *lock) @@ -149,7 +155,7 @@ cv_wait(pthread_cond_t *cv, pthread_mutex_t *lock) int error; error = pthread_cond_wait(cv, lock); - assert(error == 0); + PJDLOG_ASSERT(error == 0); } static __inline bool cv_timedwait(pthread_cond_t *cv, pthread_mutex_t *lock, int timeout) @@ -163,10 +169,10 @@ cv_timedwait(pthread_cond_t *cv, pthread_mutex_t *lock, int timeout) } error = clock_gettime(CLOCK_MONOTONIC, &ts); - assert(error == 0); + PJDLOG_ASSERT(error == 0); ts.tv_sec += timeout; error = pthread_cond_timedwait(cv, lock, &ts); - assert(error == 0 || error == ETIMEDOUT); + PJDLOG_ASSERT(error == 0 || error == ETIMEDOUT); return (error == ETIMEDOUT); } static __inline void @@ -175,7 +181,7 @@ cv_signal(pthread_cond_t *cv) int error; error = pthread_cond_signal(cv); - assert(error == 0); + PJDLOG_ASSERT(error == 0); } static __inline void cv_broadcast(pthread_cond_t *cv) @@ -183,6 +189,6 @@ cv_broadcast(pthread_cond_t *cv) int error; error = pthread_cond_broadcast(cv); - assert(error == 0); + PJDLOG_ASSERT(error == 0); } #endif /* !_SYNCH_H_ */