By opencoding it in the two callers we can not only simplify the code, but also differenciate the nr_nodes = 0 case where we don't want to read the epoch log from a real error reading the epoch log.
Signed-off-by: Christoph Hellwig <[email protected]> diff --git a/sheep/group.c b/sheep/group.c index 96dea8d..d81454a 100644 --- a/sheep/group.c +++ b/sheep/group.c @@ -797,9 +797,7 @@ enum cluster_join_result sd_check_join_cb(struct sd_node *joining, void *opaque) if (node_eq(joining, &sys->this_node)) { struct sd_node entries[SD_MAX_NODES]; int nr_entries; - uint64_t ctime; uint32_t epoch; - int ret; /* * If I'm the first sheep joins in colosync, I @@ -808,16 +806,20 @@ enum cluster_join_result sd_check_join_cb(struct sd_node *joining, void *opaque) vprintf(SDOG_DEBUG, "%s\n", node_to_str(&sys->this_node)); - nr_entries = ARRAY_SIZE(entries); - ret = read_epoch(&epoch, &ctime, entries, &nr_entries); - if (ret == SD_RES_SUCCESS) { - sys->epoch = epoch; - jm->ctime = ctime; - get_cluster_status(joining, entries, nr_entries, ctime, - epoch, &jm->cluster_status, NULL); - } else + epoch = get_latest_epoch(); + if (!epoch) { jm->cluster_status = SD_STATUS_WAIT_FOR_FORMAT; + return CJ_RES_SUCCESS; + } + + nr_entries = epoch_log_read(epoch, entries, sizeof(entries)); + if (nr_entries == -1) + return CJ_RES_FAIL; + sys->epoch = epoch; + jm->ctime = get_cluster_ctime(); + get_cluster_status(joining, entries, nr_entries, jm->ctime, + epoch, &jm->cluster_status, NULL); return CJ_RES_SUCCESS; } @@ -863,7 +865,7 @@ enum cluster_join_result sd_check_join_cb(struct sd_node *joining, void *opaque) static int send_join_request(struct sd_node *ent) { struct join_message *msg; - int nr_entries, ret; + int ret; msg = zalloc(sizeof(*msg) + SD_MAX_NODES * sizeof(msg->nodes[0])); if (!msg) @@ -873,10 +875,16 @@ static int send_join_request(struct sd_node *ent) get_cluster_copies(&msg->nr_copies); get_cluster_flags(&msg->cluster_flags); - nr_entries = SD_MAX_NODES; - ret = read_epoch(&msg->epoch, &msg->ctime, msg->nodes, &nr_entries); - if (ret == SD_RES_SUCCESS) - msg->nr_nodes = nr_entries; + msg->epoch = get_latest_epoch(); + msg->ctime = get_cluster_ctime(); + + if (msg->epoch) { + msg->nr_nodes = epoch_log_read(msg->epoch, msg->nodes, + sizeof(struct sd_node) * + SD_MAX_NODES); + if (msg->nr_nodes == -1) + return SD_RES_EIO; + } ret = sys->cdrv->join(ent, msg, get_join_message_size(msg)); diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h index 94cf98d..2e04bec 100644 --- a/sheep/sheep_priv.h +++ b/sheep/sheep_priv.h @@ -259,9 +259,6 @@ void do_gateway_request(struct work *work); int forward_write_obj_req(struct request *req); int forward_read_obj_req(struct request *req); -int read_epoch(uint32_t *epoch, uint64_t *ctime, - struct sd_node *entries, int *nr_entries); - int update_epoch_log(uint32_t epoch, struct sd_node *nodes, size_t nr_nodes); int log_current_epoch(void); diff --git a/sheep/store.c b/sheep/store.c index 8f343b4..61f822c 100644 --- a/sheep/store.c +++ b/sheep/store.c @@ -512,26 +512,6 @@ int init_store(const char *d, int enable_write_cache) return ret; } -int read_epoch(uint32_t *epoch, uint64_t *ct, - struct sd_node *entries, int *nr_entries) -{ - int ret; - - *epoch = get_latest_epoch(); - - ret = epoch_log_read(*epoch, entries, *nr_entries * sizeof(*entries)); - if (ret == -1) { - eprintf("failed to read epoch %"PRIu32"\n", *epoch); - *nr_entries = 0; - return SD_RES_EIO; - } - *nr_entries = ret; - - *ct = get_cluster_ctime(); - - return SD_RES_SUCCESS; -} - /* * Write data to both local object cache (if enabled) and backends */ -- sheepdog mailing list [email protected] http://lists.wpkg.org/mailman/listinfo/sheepdog
