[sheepdog] [PATCH 1/8] add sd_assert()
Liu Yuan
namei.unix at gmail.com
Fri Apr 3 05:20:47 CEST 2015
From: Liu Yuan <liuyuan at cmss.chinamobile.com>
This is a preparation patch to dissociate util.h and utli.c from sheepdog,
in order to be used by shared lib.
Signed-off-by: Liu Yuan <liuyuan at cmss.chinamobile.com>
---
configure.ac | 11 -----------
include/logger.h | 7 +++++++
include/util.h | 17 +----------------
lib/fec.c | 14 +++++++-------
lib/logger.c | 4 ++--
lib/work.c | 2 +-
sheep/cluster/corosync.c | 2 +-
sheep/cluster/shepherd.c | 4 ++--
sheep/cluster/zookeeper.c | 2 +-
sheep/group.c | 6 +++---
sheep/md.c | 4 ++--
sheep/migrate.c | 2 +-
sheep/object_cache.c | 6 +++---
sheep/ops.c | 6 +++---
sheep/plain_store.c | 2 +-
sheep/request.c | 10 +++++-----
sheep/sheep.c | 2 +-
sheep/trace/trace.c | 4 ++--
sheep/vdi.c | 16 ++++++++--------
19 files changed, 51 insertions(+), 70 deletions(-)
diff --git a/configure.ac b/configure.ac
index cece3d8..3635dc8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -206,10 +206,6 @@ AC_ARG_ENABLE([debug],
[ --enable-debug : enable debug build. ],
[ default="no" ])
-AC_ARG_ENABLE([assert],
- [ --enable-assert : enable assert. ],,
- [ enable_assert="yes" ],)
-
AC_ARG_ENABLE([unittest],
[ --enable-unittest : enable unittest. ],
[ default="no" ])
@@ -342,13 +338,6 @@ else
OPT_CFLAGS="-DNDEBUG"
fi
-if test "x${enable_assert}" = xyes; then
- AC_DEFINE_UNQUOTED([ASSERT], [1], [Enabling assert])
- PACKAGE_FEATURES="$PACKAGE_FEATURES assert"
-else
- OPT_CFLAGS="-DNASSERT"
-fi
-
# gdb flags
if test "x${GCC}" = xyes; then
GDB_FLAGS="-ggdb3"
diff --git a/include/logger.h b/include/logger.h
index f360342..df69faf 100644
--- a/include/logger.h
+++ b/include/logger.h
@@ -94,6 +94,13 @@ void sd_backtrace(void);
abort(); \
})
+#define sd_assert(expr) \
+({ \
+ if (!(expr)) { \
+ sd_emerg("Asserting `%s' failed.", #expr); \
+ abort(); \
+ } \
+})
static inline int loglevel_str2num(const char *str)
{
diff --git a/include/util.h b/include/util.h
index c5b5ac9..632a193 100644
--- a/include/util.h
+++ b/include/util.h
@@ -13,6 +13,7 @@
#include <pthread.h>
#include <errno.h>
#include <sys/param.h>
+#include <assert.h>
#include "logger.h"
#include "list.h"
@@ -214,22 +215,6 @@ double get_time_interval(const struct timespec *start,
__removed; \
})
-#ifdef assert
-#error "Don't include assert.h, use util.h for assert()"
-#endif
-
-#ifndef NASSERT
-#define assert(expr) \
-({ \
- if (!(expr)) { \
- sd_emerg("Asserting `%s' failed.", #expr); \
- abort(); \
- } \
-})
-#else
-#define assert(expr) ((void)0)
-#endif /* NASSERT */
-
#define SWAP(a, b) { typeof(a) tmp; tmp = a; a = b; b = tmp; }
/* urcu helpers */
diff --git a/lib/fec.c b/lib/fec.c
index fb40773..268bce6 100644
--- a/lib/fec.c
+++ b/lib/fec.c
@@ -313,7 +313,7 @@ static void _invert_mat(uint8_t *src, unsigned d)
goto found_piv;
}
} else
- assert(ipiv[ix] <= 1);
+ sd_assert(ipiv[ix] <= 1);
}
}
}
@@ -331,7 +331,7 @@ found_piv:
indxc[col] = icol;
pivot_row = &src[icol * d];
c = pivot_row[icol];
- assert(c != 0);
+ sd_assert(c != 0);
if (c != 1) { /* otherwise this is a NOP */
/*
* this is done often , but optimizing is not so
@@ -451,7 +451,7 @@ void init_fec(void)
void fec_free(struct fec *p)
{
- assert(p != NULL && p->magic == (((FEC_MAGIC ^ p->d) ^ p->dp) ^
+ sd_assert(p != NULL && p->magic == (((FEC_MAGIC ^ p->d) ^ p->dp) ^
(unsigned long) (p->enc_matrix)));
free(p->enc_matrix);
if (cpu_has_ssse3)
@@ -528,7 +528,7 @@ void fec_encode(const struct fec *code,
size_t stride = ((sz-d) < STRIDE) ? (sz-d) : STRIDE;
for (i = 0; i < num_block_nums; i++) {
fecnum = block_nums[i];
- assert(fecnum >= code->d);
+ sd_assert(fecnum >= code->d);
memset(fecs[i]+d, 0, stride);
p = &(code->enc_matrix[fecnum * code->d]);
for (j = 0; j < code->d; j++)
@@ -570,7 +570,7 @@ void fec_decode(const struct fec *code,
unsigned char row = 0;
unsigned char col = 0;
- assert(code->d * code->d < 8 * 1024 * 1024);
+ sd_assert(code->d * code->d < 8 * 1024 * 1024);
build_decode_matrix_into_space(code, idx, code->d, m_dec);
for (row = 0; row < code->d; row++) {
@@ -578,7 +578,7 @@ void fec_decode(const struct fec *code,
* If the block whose number is i is present, then it is
* required to be in the i'th element.
*/
- assert((idx[row] >= code->d) || (idx[row] == row));
+ sd_assert((idx[row] >= code->d) || (idx[row] == row));
if (idx[row] >= code->d) {
memset(outpkts[outix], 0, sz);
for (col = 0; col < code->d; col++)
@@ -614,7 +614,7 @@ static inline void decode_prepare(struct fec *ctx, const uint8_t *dp[],
out[i] = dp[i];
outidx[i] = i;
} else {
- assert(p < ctx->dp);
+ sd_assert(p < ctx->dp);
out[i] = dp[p];
outidx[i] = p;
while (++p < ctx->dp && !dp[p])
diff --git a/lib/logger.c b/lib/logger.c
index da0ebac..39d3283 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -214,7 +214,7 @@ static int json_log_formatter(char *buff, size_t size,
char *p = buff;
ssize_t len;
- assert(logger_user_info);
+ sd_assert(logger_user_info);
len = snprintf(p, size, "{ \"user_info\": "
"{\"program_name\": \"%s\", \"port\": %d},"
@@ -854,7 +854,7 @@ fallback:
void set_loglevel(int new_loglevel)
{
- assert(SDOG_EMERG <= new_loglevel && new_loglevel <= SDOG_DEBUG);
+ sd_assert(SDOG_EMERG <= new_loglevel && new_loglevel <= SDOG_DEBUG);
sd_log_level = new_loglevel;
}
diff --git a/lib/work.c b/lib/work.c
index 25260b4..14e3117 100644
--- a/lib/work.c
+++ b/lib/work.c
@@ -133,7 +133,7 @@ static void suspend(int num, siginfo_t *info, void *context)
eventfd_xwrite(ack_efd, 1); /* ack of suspend */
value = eventfd_xread(resume_efd);
- assert(value == 1);
+ sd_assert(value == 1);
eventfd_xwrite(ack_efd, 1); /* ack of resume */
}
diff --git a/sheep/cluster/corosync.c b/sheep/cluster/corosync.c
index b7fc025..ea65603 100644
--- a/sheep/cluster/corosync.c
+++ b/sheep/cluster/corosync.c
@@ -317,7 +317,7 @@ static bool __corosync_dispatch_one(struct corosync_event *cevent)
this_node = cevent->sender;
idx = find_sd_node(cpg_nodes, nr_cpg_nodes, node);
- assert(idx >= 0);
+ sd_assert(idx >= 0);
cpg_nodes[idx].node = *node;
sd_update_node_handler(node);
break;
diff --git a/sheep/cluster/shepherd.c b/sheep/cluster/shepherd.c
index 45a85c1..570bff5 100644
--- a/sheep/cluster/shepherd.c
+++ b/sheep/cluster/shepherd.c
@@ -454,8 +454,8 @@ static void read_msg_from_shepherd(void)
static void shepherd_comm_handler(int fd, int events, void *data)
{
- assert(fd == sph_comm_fd);
- assert(data == NULL);
+ sd_assert(fd == sph_comm_fd);
+ sd_assert(data == NULL);
if (events & EPOLLIN)
read_msg_from_shepherd();
diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
index bf94871..70f87b2 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -1197,7 +1197,7 @@ static void zk_handle_update_node(struct zk_event *ev)
sd_read_lock(&zk_tree_lock);
t = zk_tree_search_nolock(&snode->nid);
- assert(t);
+ sd_assert(t);
t->node = *snode;
build_node_list();
sd_rw_unlock(&zk_tree_lock);
diff --git a/sheep/group.c b/sheep/group.c
index 0fce7c0..7c7cb6d 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -225,7 +225,7 @@ static struct vdi_op_message *prepare_cluster_msg(struct request *req,
/* notify data that was set in process_work */
size = sizeof(*msg) + req->rp.data_length;
- assert(size <= SD_MAX_EVENT_BUF_SIZE);
+ sd_assert(size <= SD_MAX_EVENT_BUF_SIZE);
msg = xzalloc(size);
memcpy(&msg->req, &req->rq, sizeof(struct sd_req));
@@ -745,7 +745,7 @@ static void cinfo_collection_work(struct work *work)
sd_debug("start collection of cinfo...");
- assert(w == collect_work);
+ sd_assert(w == collect_work);
rb_for_each_entry(n, &w->members->nroot, rb) {
if (node_is_local(n))
@@ -786,7 +786,7 @@ static void cinfo_collection_done(struct work *work)
struct cinfo_collection_work *w =
container_of(work, struct cinfo_collection_work, work);
- assert(w == collect_work);
+ sd_assert(w == collect_work);
for (int i = 0; i < w->nr_vdi_states; i++) {
struct vdi_state *vs = &w->result[i];
diff --git a/sheep/md.c b/sheep/md.c
index c00d7a5..bcdfb73 100644
--- a/sheep/md.c
+++ b/sheep/md.c
@@ -119,7 +119,7 @@ static void remove_vdisks(const struct disk *disk)
hval = sd_hash_next(hval);
v = hval_to_vdisk(hval);
- assert(v->hash == hval);
+ sd_assert(v->hash == hval);
vdisk_free(v);
}
@@ -127,7 +127,7 @@ static void remove_vdisks(const struct disk *disk)
static inline void trim_last_slash(char *path)
{
- assert(path[0]);
+ sd_assert(path[0]);
while (path[strlen(path) - 1] == '/')
path[strlen(path) - 1] = '\0';
}
diff --git a/sheep/migrate.c b/sheep/migrate.c
index f01eaf6..2841e87 100644
--- a/sheep/migrate.c
+++ b/sheep/migrate.c
@@ -529,7 +529,7 @@ int sd_migrate_store(int from, int to)
{
int ver, ret;
- assert(to <= sizeof(migrate));
+ sd_assert(to <= sizeof(migrate));
ret = backup_store();
if (ret != 0) {
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index 3794c19..7f626c4 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -319,7 +319,7 @@ static int read_cache_object_noupdate(uint32_t vid, uint64_t idx, void *buf,
vid, idx);
if (sys->object_cache_directio && !idx_has_vdi_bit(idx)) {
- assert(is_aligned_to_pagesize(buf));
+ sd_assert(is_aligned_to_pagesize(buf));
flags |= O_DIRECT;
}
@@ -355,7 +355,7 @@ static int write_cache_object_noupdate(uint32_t vid, uint64_t idx, void *buf,
snprintf(p, sizeof(p), "%s/%06"PRIx32"/%016"PRIx64, object_cache_dir,
vid, idx);
if (sys->object_cache_directio && !idx_has_vdi_bit(idx)) {
- assert(is_aligned_to_pagesize(buf));
+ sd_assert(is_aligned_to_pagesize(buf));
flags |= O_DIRECT;
}
@@ -1323,7 +1323,7 @@ int object_cache_remove(uint64_t oid)
* in the DISCARD context, which means normally no other read/write
* requests.
*/
- assert(refcount_read(&entry->refcnt) == 1);
+ sd_assert(refcount_read(&entry->refcnt) == 1);
ret = remove_cache_object(oc, entry_idx(entry));
if (ret != SD_RES_SUCCESS) {
unlock_cache(oc);
diff --git a/sheep/ops.c b/sheep/ops.c
index 0e5ac64..a63fed7 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -862,7 +862,7 @@ static int local_md_info(struct request *request)
{
struct sd_rsp *rsp = &request->rp;
- assert(request->rq.data_length == sizeof(struct sd_md_info));
+ sd_assert(request->rq.data_length == sizeof(struct sd_md_info));
rsp->data_length = md_get_info((struct sd_md_info *)request->data);
return rsp->data_length ? SD_RES_SUCCESS : SD_RES_UNKNOWN;
@@ -900,7 +900,7 @@ static int local_get_cache_info(struct request *request)
{
struct sd_rsp *rsp = &request->rp;
- assert(request->rq.data_length == sizeof(struct object_cache_info));
+ sd_assert(request->rq.data_length == sizeof(struct object_cache_info));
rsp->data_length = object_cache_get_info((struct object_cache_info *)
request->data);
@@ -2139,6 +2139,6 @@ static int map_table[] = {
int gateway_to_peer_opcode(int opcode)
{
- assert(opcode < ARRAY_SIZE(map_table));
+ sd_assert(opcode < ARRAY_SIZE(map_table));
return map_table[opcode];
}
diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index 4c19832..efbf129 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -599,7 +599,7 @@ static int check_stale_objects(uint64_t oid, const char *wd, uint32_t epoch,
int default_update_epoch(uint32_t epoch)
{
- assert(epoch);
+ sd_assert(epoch);
return for_each_object_in_wd(check_stale_objects, false, &epoch);
}
diff --git a/sheep/request.c b/sheep/request.c
index b826f0f..f12ca6b 100644
--- a/sheep/request.c
+++ b/sheep/request.c
@@ -97,7 +97,7 @@ static void gateway_op_done(struct work *work)
struct request *rq;
sys->nr_ongoing_inode_update_request--;
- assert(0 <= sys->nr_ongoing_inode_update_request);
+ sd_assert(0 <= sys->nr_ongoing_inode_update_request);
sd_debug("a number of ongoing inode update request: %d",
sys->nr_ongoing_inode_update_request);
@@ -235,7 +235,7 @@ void wakeup_requests_on_epoch(void)
* Gateway retries to send the request when
* its epoch changes.
*/
- assert(is_gateway_op(req->op));
+ sd_assert(is_gateway_op(req->op));
sd_debug("gateway %"PRIx64, req->rq.obj.oid);
req->rq.epoch = sys->cinfo.epoch;
del_requeue_request(req);
@@ -245,7 +245,7 @@ void wakeup_requests_on_epoch(void)
* Peer retries the request locally when its epoch
* changes.
*/
- assert(!is_gateway_op(req->op));
+ sd_assert(!is_gateway_op(req->op));
sd_debug("peer %"PRIx64, req->rq.obj.oid);
del_requeue_request(req);
break;
@@ -364,7 +364,7 @@ queue_work:
&sys->prevented_inode_update_request_queue);
return;
} else {
- assert(0 <= sys->nr_ongoing_inode_update_request);
+ sd_assert(0 <= sys->nr_ongoing_inode_update_request);
sys->nr_ongoing_inode_update_request++;
sd_debug("a number of ongoing inode update request: %d",
sys->nr_ongoing_inode_update_request);
@@ -1024,7 +1024,7 @@ static void client_handler(int fd, int events, void *data)
return;
}
- assert(ci->tx_req == NULL);
+ sd_assert(ci->tx_req == NULL);
ci->tx_req = list_first_entry(&ci->done_reqs, struct request,
request_list);
list_del(&ci->tx_req->request_list);
diff --git a/sheep/sheep.c b/sheep/sheep.c
index fc53ec9..2745560 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -240,7 +240,7 @@ static void signal_handler(int listen_fd, int events, void *data)
int uninitialized_var(ret);
ret = read(sigfd, &siginfo, sizeof(siginfo));
- assert(ret == sizeof(siginfo));
+ sd_assert(ret == sizeof(siginfo));
sd_debug("signal %d, ssi pid %d", siginfo.ssi_signo, siginfo.ssi_pid);
switch (siginfo.ssi_signo) {
case SIGTERM:
diff --git a/sheep/trace/trace.c b/sheep/trace/trace.c
index 57c2b4c..60c224d 100644
--- a/sheep/trace/trace.c
+++ b/sheep/trace/trace.c
@@ -111,7 +111,7 @@ void trace_function_enter(unsigned long ip, unsigned long *ret_addr)
return;
in_trace = true;
- assert(ret_stack_index < ARRAY_SIZE(trace_ret_stack));
+ sd_assert(ret_stack_index < ARRAY_SIZE(trace_ret_stack));
caller = trace_lookup_ip(ip);
@@ -136,7 +136,7 @@ unsigned long trace_function_exit(void)
{
struct tracer *tracer;
- assert(!in_trace);
+ sd_assert(!in_trace);
in_trace = true;
ret_stack_index--;
diff --git a/sheep/vdi.c b/sheep/vdi.c
index 8114fb5..6e4fb75 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -479,7 +479,7 @@ static struct vdi_state *fill_vdi_state_list_with_alloc(int *result_nr)
vs[i].participants[j] = entry->participants[j];
}
- assert(i < nr);
+ sd_assert(i < nr);
i++;
}
@@ -562,7 +562,7 @@ static bool add_new_participant(struct vdi_state_entry *entry,
int idx;
if (entry->lock_state == LOCK_STATE_UNLOCKED) {
- assert(!entry->nr_participants);
+ sd_assert(!entry->nr_participants);
sd_debug("%s is first owner of %"PRIx32, node_id_to_str(owner),
entry->vid);
@@ -575,8 +575,8 @@ static bool add_new_participant(struct vdi_state_entry *entry,
return true;
}
- assert(entry->lock_state == LOCK_STATE_SHARED);
- assert(0 < entry->nr_participants);
+ sd_assert(entry->lock_state == LOCK_STATE_SHARED);
+ sd_assert(0 < entry->nr_participants);
if (entry->nr_participants == SD_MAX_COPIES) {
sd_err("VDI: %"PRIx32 " already has SD_MAX_COPIES participants",
@@ -860,7 +860,7 @@ void play_logged_vdi_ops(void)
apply_vdi_lock_state(&entry);
} else {
- assert(op->type == LOCK_TYPE_SHARED);
+ sd_assert(op->type == LOCK_TYPE_SHARED);
apply_vdi_lock_state_shared(op->vid,
op->lock, &op->owner);
@@ -1023,7 +1023,7 @@ main_fn int inode_coherence_update(uint32_t vid, bool validate,
goto out;
}
- assert(entry->lock_state == LOCK_STATE_SHARED);
+ sd_assert(entry->lock_state == LOCK_STATE_SHARED);
if (validate) {
for (int i = 0; i < entry->nr_participants; i++) {
@@ -1100,7 +1100,7 @@ static struct sd_inode *alloc_inode(const struct vdi_iocb *iocb,
sd_inode_init(new->data_vdi_id, 1);
if (gref) {
- assert(data_vdi_id);
+ sd_assert(data_vdi_id);
for (int i = 0; i < SD_INODE_DATA_INDEX; i++) {
if (!data_vdi_id[i])
@@ -1589,7 +1589,7 @@ int vdi_snapshot(const struct vdi_iocb *iocb, uint32_t *new_vid)
return ret;
}
- assert(info.snapid > 0);
+ sd_assert(info.snapid > 0);
*new_vid = info.free_bit;
ret = notify_vdi_add(*new_vid, iocb->nr_copies, info.vid,
iocb->copy_policy, iocb->block_size_shift);
--
1.9.1
More information about the sheepdog
mailing list