[sheepdog] [PATCH] sheep: clean up node comparison
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Fri May 17 15:56:53 CEST 2013
Use node_is_local() to check that the node is local, use node_eq() to
check two nodes are the same one, and remove unnecessary function
is_myself().
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
sheep/group.c | 14 +++++++-------
sheep/ops.c | 4 ++--
sheep/sheep_priv.h | 11 ++---------
3 files changed, 11 insertions(+), 18 deletions(-)
diff --git a/sheep/group.c b/sheep/group.c
index 700e49f..b6a8d1b 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -296,7 +296,7 @@ bool sd_block_handler(const struct sd_node *sender)
{
struct request *req;
- if (!node_eq(sender, &sys->this_node))
+ if (!node_is_local(sender))
return false;
if (cluster_op_running)
return false;
@@ -686,7 +686,7 @@ static void do_get_vdis(struct work *work)
container_of(work, struct get_vdis_work, work);
int i, ret;
- if (!node_eq(&w->joined, &sys->this_node)) {
+ if (!node_is_local(&w->joined)) {
switch (sys->status) {
case SD_STATUS_OK:
case SD_STATUS_HALT:
@@ -697,7 +697,7 @@ static void do_get_vdis(struct work *work)
for (i = 0; i < w->nr_members; i++) {
/* We should not fetch vdi_bitmap and copy list from myself */
- if (node_eq(&w->members[i], &sys->this_node))
+ if (node_is_local(&w->members[i]))
continue;
ret = get_vdis_from(&w->members[i]);
@@ -992,7 +992,7 @@ enum cluster_join_result sd_check_join_cb(const struct sd_node *joining,
return CJ_RES_FAIL;
}
- if (node_eq(joining, &sys->this_node)) {
+ if (node_is_local(joining)) {
struct sd_node entries[SD_MAX_NODES];
int nr_entries;
uint32_t epoch;
@@ -1114,7 +1114,7 @@ void sd_join_handler(const struct sd_node *joined,
const struct join_message *jm = opaque;
uint32_t le = get_latest_epoch();
- if (node_eq(joined, &sys->this_node)) {
+ if (node_is_local(joined)) {
if (result == CJ_RES_FAIL) {
sd_eprintf("Failed to join, exiting.");
sys->cdrv->leave();
@@ -1136,7 +1136,7 @@ void sd_join_handler(const struct sd_node *joined,
update_cluster_info(jm, joined, members, nr_members);
- if (node_eq(joined, &sys->this_node))
+ if (node_is_local(joined))
/* this output is used for testing */
sd_printf(SDOG_DEBUG, "join Sheepdog cluster");
break;
@@ -1185,7 +1185,7 @@ void sd_join_handler(const struct sd_node *joined,
log_current_epoch();
}
- if (node_eq(joined, &sys->this_node))
+ if (node_is_local(joined))
/* this output is used for testing */
sd_printf(SDOG_DEBUG, "join Sheepdog cluster");
break;
diff --git a/sheep/ops.c b/sheep/ops.c
index 90ec241..6e1caa7 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -687,7 +687,7 @@ static int cluster_recovery_completion(const struct sd_req *req,
* to send notification
*/
for (i = 0; i < nr_recovereds; i++)
- if (!node_cmp(node, recovereds + i)) {
+ if (node_eq(node, recovereds + i)) {
sd_dprintf("duplicate %s", node_to_str(node));
return SD_RES_SUCCESS;
}
@@ -705,7 +705,7 @@ static int cluster_recovery_completion(const struct sd_req *req,
if (vnode_info->nr_nodes == nr_recovereds) {
for (i = 0; i < nr_recovereds; ++i) {
- if (node_cmp(vnode_info->nodes + i, recovereds + i))
+ if (!node_eq(vnode_info->nodes + i, recovereds + i))
break;
}
if (i == nr_recovereds) {
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 173cd55..b66f348 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -334,21 +334,14 @@ int do_process_main(const struct sd_op_template *op, const struct sd_req *req,
int sheep_do_op_work(const struct sd_op_template *op, struct request *req);
int gateway_to_peer_opcode(int opcode);
-static inline bool is_myself(const uint8_t *addr, uint16_t port)
-{
- return (memcmp(addr, sys->this_node.nid.addr,
- sizeof(sys->this_node.nid.addr)) == 0) &&
- port == sys->this_node.nid.port;
-}
-
static inline bool vnode_is_local(const struct sd_vnode *v)
{
- return is_myself(v->nid.addr, v->nid.port);
+ return node_id_cmp(&v->nid, &sys->this_node.nid) == 0;
}
static inline bool node_is_local(const struct sd_node *n)
{
- return is_myself(n->nid.addr, n->nid.port);
+ return node_eq(n, &sys->this_node);
}
/* gateway operations */
--
1.8.1.3.566.gaa39828
More information about the sheepdog
mailing list