[Sheepdog] PATCH S005 v2: Replace calls to node_cmp with a typesafe node_eq.

Liu Yuan namei.unix at gmail.com
Fri May 11 04:55:21 CEST 2012


On 05/10/2012 07:24 AM, Shevek wrote:

> Make node_eq typesafe, rather than accepting void *, since C99 will
> allow us to accidentally cast any type pointer to a void * without
> warning.
> 
> Signed-off-by: Shevek <shevek at anarres.org>
> ---
>  include/sheep.h           |    5 +++++
>  sheep/cluster/accord.c    |    2 +-
>  sheep/cluster/local.c     |    4 ++--
>  sheep/cluster/zookeeper.c |   12 ++++++------
>  sheep/group.c             |   18 +++++++++---------
>  5 files changed, 23 insertions(+), 18 deletions(-)
> 
> diff --git a/include/sheep.h b/include/sheep.h
> index 7e287c4..0a47514 100644
> --- a/include/sheep.h
> +++ b/include/sheep.h
> @@ -321,6 +321,11 @@ static inline int node_cmp(const void *a, const
> void *b)
>  	return 0;
>  }
>  
> +static inline int node_eq(const struct sd_node *a, const struct sd_node
> *b)
> +{
> +	return node_cmp(a, b) == 0;
> +}
> +
>  static inline int vnode_cmp(const void *a, const void *b)
>  {
>  	const struct sd_vnode *node1 = a;
> diff --git a/sheep/cluster/accord.c b/sheep/cluster/accord.c
> index 1fdca91..fdce199 100644
> --- a/sheep/cluster/accord.c
> +++ b/sheep/cluster/accord.c
> @@ -575,7 +575,7 @@ static int accord_dispatch(void)
>  	switch (ev.type) {
>  	case EVENT_JOIN:
>  		if (ev.blocked) {
> -			if (node_cmp(&ev.nodes[0], &this_node) == 0) {
> +			if (node_eq(&ev.nodes[0], &this_node)) {
>  				res = sd_check_join_cb(&ev.sender, ev.buf);
>  				ev.join_result = res;
>  				ev.blocked = 0;
> diff --git a/sheep/cluster/local.c b/sheep/cluster/local.c
> index fd84615..8d14004 100644
> --- a/sheep/cluster/local.c
> +++ b/sheep/cluster/local.c
> @@ -403,7 +403,7 @@ static int local_dispatch(void)
>  	switch (ev->type) {
>  	case EVENT_JOIN:
>  		if (ev->blocked) {
> -			if (node_cmp(&ev->nodes[0], &this_node) == 0) {
> +			if (node_eq(&ev->nodes[0], &this_node)) {
>  				res = sd_check_join_cb(&ev->sender, ev->buf);
>  				ev->join_result = res;
>  				ev->blocked = 0;
> @@ -438,7 +438,7 @@ static int local_dispatch(void)
>  		break;
>  	case EVENT_NOTIFY:
>  		if (ev->blocked) {
> -			if (node_cmp(&ev->sender, &this_node) == 0) {
> +			if (node_eq(&ev->sender, &this_node)) {
>  				if (!ev->callbacked) {
>  					queue_work(local_block_wq, &work);
>  
> diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
> index 491056a..52b8313 100644
> --- a/sheep/cluster/zookeeper.c
> +++ b/sheep/cluster/zookeeper.c
> @@ -267,7 +267,7 @@ static int zk_queue_pop(zhandle_t *zh, struct
> zk_event *ev)
>  		len = sizeof(*ev);
>  		sprintf(path, QUEUE_ZNODE "/%010d", queue_pos);
>  		rc = zk_get(zh, path, 1, (char *)ev, &len, NULL);
> -		if (rc == ZOK && node_cmp(&ev->sender.node, &lev->sender.node) == 0
> && ev->blocked) {
> +		if (rc == ZOK && node_eq(&ev->sender.node, &lev->sender.node) &&
> ev->blocked) {
>  			dprintf("this queue_pos:%010d have blocked whole cluster, ignore it
> \n", queue_pos);
>  			queue_pos++;
>  
> @@ -446,7 +446,7 @@ static int is_master(zhandle_t *zh, struct zk_node
> *znode)
>  	}
>  
>  	twalk(zk_node_btroot, node_btree_find_master_fn);
> -	if (node_cmp(&zk_master->node, &znode->node) == 0)
> +	if (node_eq(&zk_master->node, &znode->node))
>  		return 1;
>  
>  	return 0;
> @@ -795,7 +795,7 @@ static int zk_dispatch(void)
>  
>  			goto out;
>  		} else if (is_master(zhandle, &this_node)
> -			&& node_cmp(&ev.sender.node, &this_node.node) != 0) {
> +			&& !node_eq(&ev.sender.node, &this_node.node)) {
>  			/* wait util member have been created */
>  			sprintf(path, MEMBER_ZNODE "/%s", node_to_str(&ev.sender.node));
>  			retry = MEMBER_CREATE_TIMEOUT/MEMBER_CREATE_INTERVAL;
> @@ -810,7 +810,7 @@ static int zk_dispatch(void)
>  			}
>  		}
>  
> -		if (node_cmp(&ev.sender.node, &this_node.node) == 0)
> +		if (node_eq(&ev.sender.node, &this_node.node))
>  			zk_member_init(zhandle);
>  
>  		if (ev.join_result == CJ_RES_MASTER_TRANSFER) {
> @@ -829,7 +829,7 @@ static int zk_dispatch(void)
>  
>  		if (ev.join_result == CJ_RES_SUCCESS) {
>  			sprintf(path, MEMBER_ZNODE "/%s", node_to_str(&ev.sender.node));
> -			if (node_cmp(&ev.sender.node, &this_node.node) == 0) {
> +			if (node_eq(&ev.sender.node, &this_node.node)) {
>  				dprintf("create path:%s\n", path);
>  				rc = zk_create(zhandle, path, (char *)&ev.sender,
> sizeof(ev.sender),
>  					&ZOO_OPEN_ACL_UNSAFE, ZOO_EPHEMERAL, NULL, 0);
> @@ -862,7 +862,7 @@ static int zk_dispatch(void)
>  	case EVENT_NOTIFY:
>  		dprintf("NOTIFY, blocked:%d\n", ev.blocked);
>  		if (ev.blocked) {
> -			if (node_cmp(&ev.sender.node, &this_node.node) == 0 && !
> ev.callbacked) {
> +			if (node_eq(&ev.sender.node, &this_node.node) && !ev.callbacked) {
>  				ev.callbacked = 1;
>  
>  				uatomic_inc(&zk_notify_blocked);
> diff --git a/sheep/group.c b/sheep/group.c
> index c7fd387..83ebc6e 100644
> --- a/sheep/group.c
> +++ b/sheep/group.c
> @@ -305,7 +305,7 @@ static struct sd_node *find_entry_list(struct
> sd_node *entry,
>  {
>  	struct node *n;
>  	list_for_each_entry(n, head, list)
> -		if (node_cmp(&n->ent, entry) == 0)
> +		if (node_eq(&n->ent, entry))
>  			return entry;
>  
>  	return NULL;
> @@ -321,7 +321,7 @@ static struct sd_node *find_entry_epoch(struct
> sd_node *entry,
>  	nr = epoch_log_read_nr(epoch, (char *)nodes, sizeof(nodes));
>  
>  	for (i = 0; i < nr; i++)
> -		if (node_cmp(&nodes[i], entry) == 0)
> +		if (node_eq(&nodes[i], entry))
>  			return entry;
>  
>  	return NULL;
> @@ -420,10 +420,10 @@ static int get_cluster_status(struct sd_node
> *from,
>  		}
>  
>  		for (i = 0; i < nr_local_entries; i++) {
> -			if (node_cmp(local_entries + i, from) == 0)
> +			if (node_eq(local_entries + i, from))
>  				goto next;
>  			for (j = 0; j < sys->nr_nodes; j++) {
> -				if (node_cmp(local_entries + i, sys->nodes + j) == 0)
> +				if (node_eq(local_entries + i, sys->nodes + j))
>  					goto next;
>  			}
>  			break;
> @@ -531,7 +531,7 @@ static void finish_join(struct join_message *msg,
> struct sd_node *joined,
>  
>  	/* add nodes execept for newly joined one */
>  	for (i = 0; i < nr_nodes; i++) {
> -		if (node_cmp(nodes + i, joined) == 0)
> +		if (node_eq(nodes + i, joined))
>  			continue;
>  
>  		sys->nodes[sys->nr_nodes++] = nodes[i];
> @@ -740,7 +740,7 @@ enum cluster_join_result sd_check_join_cb(struct
> sd_node *joining, void *opaque)
>  	struct join_message *jm = opaque;
>  	struct node *node;
>  
> -	if (node_cmp(joining, &sys->this_node) == 0) {
> +	if (node_eq(joining, &sys->this_node)) {
>  		struct sd_node entries[SD_MAX_NODES];
>  		int nr_entries;
>  		uint64_t ctime;
> @@ -845,7 +845,7 @@ static void __sd_join_done(struct event_struct
> *cevent)
>  			sys_stat_set(SD_STATUS_OK);
>  	}
>  
> -	if (node_cmp(&w->joined, &sys->this_node) == 0)
> +	if (node_eq(&w->joined, &sys->this_node))
>  		/* this output is used for testing */
>  		vprintf(SDOG_DEBUG, "join Sheepdog cluster\n");
>  }
> @@ -1102,7 +1102,7 @@ void sd_join_handler(struct sd_node *joined,
> struct sd_node *members,
>  	struct join_message *jm;
>  	uint32_t le = get_latest_epoch();
>  
> -	if (node_cmp(joined, &sys->this_node) == 0) {
> +	if (node_eq(joined, &sys->this_node)) {
>  		if (result == CJ_RES_FAIL) {
>  			eprintf("Fail to join. The joining node has an invalid epoch.\n");
>  			sys->cdrv->leave();
> @@ -1221,7 +1221,7 @@ void sd_join_handler(struct sd_node *joined,
> struct sd_node *members,
>  			update_epoch_store(sys->epoch);
>  		}
>  
> -		if (node_cmp(joined, &sys->this_node) == 0)
> +		if (node_eq(joined, &sys->this_node))
>  			/* this output is used for testing */
>  			vprintf(SDOG_DEBUG, "join Sheepdog cluster\n");
>  		break;


Please run script/checkpatch.pl path-to-your-patch. There is some style
problem with this patch.

Thanks,
Yuan



More information about the sheepdog mailing list