[Sheepdog] [PATCH 1/6] sheep: add a helper epoch_log_read_nr()
Liu Yuan
namei.unix at gmail.com
Tue Oct 18 08:46:47 CEST 2011
From: Liu Yuan <tailai.ly at taobao.com>
Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
sheep/group.c | 6 ++----
sheep/sheep_priv.h | 1 +
sheep/store.c | 9 +++++++++
3 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/sheep/group.c b/sheep/group.c
index eb64207..8ad54a3 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -452,8 +452,7 @@ static struct sheepdog_node_list_entry *find_entry_epoch(struct sheepdog_node_li
struct sheepdog_node_list_entry nodes[SD_MAX_NODES];
int nr, i;
- nr = epoch_log_read(epoch, (char *)nodes, sizeof(nodes));
- nr /= sizeof(nodes[0]);
+ nr = epoch_log_read_nr(epoch, (char *)nodes, sizeof(nodes));
for (i = 0; i < nr; i++)
if (node_cmp(&nodes[i], entry) == 0)
@@ -591,9 +590,8 @@ static int get_cluster_status(struct sheepdog_node_list_entry *from,
return SD_RES_NEW_NODE_VER;
}
- nr_local_entries = epoch_log_read(epoch, (char *)local_entries,
+ nr_local_entries = epoch_log_read_nr(epoch, (char *)local_entries,
sizeof(local_entries));
- nr_local_entries /= sizeof(local_entries[0]);
if (nr_entries != nr_local_entries) {
eprintf("joining node has invalid epoch, %"PRIu32" %s\n",
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index a7d5c25..dfc61ad 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -218,6 +218,7 @@ int get_cluster_flags(uint32_t *flags);
int epoch_log_write(uint32_t epoch, char *buf, int len);
int epoch_log_read(uint32_t epoch, char *buf, int len);
+int epoch_log_read_nr(uint32_t epoch, char *buf, int len);
int epoch_log_read_remote(uint32_t epoch, char *buf, int len);
int get_latest_epoch(void);
int remove_epoch(int epoch);
diff --git a/sheep/store.c b/sheep/store.c
index b3aec2b..51eb777 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -872,6 +872,15 @@ out:
return ret;
}
+int epoch_log_read_nr(uint32_t epoch, char *buf, int len)
+{
+ int nr;
+
+ nr = epoch_log_read(epoch, buf, len);
+ nr /= sizeof(struct sheepdog_node_list_entry);
+ return nr;
+}
+
int epoch_log_read(uint32_t epoch, char *buf, int len)
{
int fd;
--
1.7.6.1
More information about the sheepdog
mailing list