The past node lists are used to look up objects efficiently Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp> --- collie/collie.h | 6 +++++ collie/group.c | 13 ++++++++++++ collie/store.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 0 deletions(-) diff --git a/collie/collie.h b/collie/collie.h index 3b2d871..f5dc30d 100644 --- a/collie/collie.h +++ b/collie/collie.h @@ -74,6 +74,12 @@ int create_listen_port(int port, void *data); int init_store(char *dir); +int read_node_list(uint32_t epoch, struct sheepdog_node_list_entry *entries, + int nr_nodes); + +int write_node_list(uint32_t epoch, struct sheepdog_node_list_entry *entries, + int nr_nodes); + int add_vdi(struct cluster_info *cluster, char *name, int len, uint64_t size, uint64_t * added_oid, uint64_t base_oid, uint32_t tag); diff --git a/collie/group.c b/collie/group.c index ced0a5e..01f959e 100644 --- a/collie/group.c +++ b/collie/group.c @@ -246,6 +246,8 @@ static void print_node_list(struct cluster_info *ci) static void add_node(struct cluster_info *ci, uint32_t nodeid, uint32_t pid, struct sheepdog_node_list_entry *sd_ent) { + int nr_nodes; + struct sheepdog_node_list_entry entries[SD_MAX_NODES]; struct node *node; node = zalloc(sizeof(*node)); @@ -257,6 +259,10 @@ static void add_node(struct cluster_info *ci, uint32_t nodeid, uint32_t pid, node->pid = pid; node->ent = *sd_ent; list_add_tail(&node->list, &ci->node_list); + + nr_nodes = build_node_list(&ci->node_list, entries); + write_node_list(ci->epoch + 1, entries, nr_nodes); + ci->epoch++; } @@ -528,12 +534,19 @@ static void __sd_confch(struct work *work, int idx) for (i = 0; i < left_list_entries; i++) { list_for_each_entry_safe(node, e, &ci->node_list, list) { + int nr_nodes; + struct sheepdog_node_list_entry entries[SD_MAX_NODES]; + if (node->nodeid != left_list[i].nodeid || node->pid != left_list[i].pid) continue; list_del(&node->list); free(node); + + nr_nodes = build_node_list(&ci->node_list, entries); + write_node_list(ci->epoch + 1, entries, nr_nodes); + ci->epoch++; } } diff --git a/collie/store.c b/collie/store.c index 4e95469..aadddc5 100644 --- a/collie/store.c +++ b/collie/store.c @@ -622,6 +622,7 @@ int init_store(char *dir) struct mntent *mnt; struct stat s, ms; FILE *fp; + char path[PATH_MAX]; ret = stat(dir, &s); if (ret) { @@ -650,6 +651,13 @@ int init_store(char *dir) obj_dir = dir; + strcpy(path, dir); + strcat(path, "/epoch"); + ret = mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | + S_IWGRP | S_IXGRP); + if (ret && errno != EEXIST) + return 1; + fp = setmntent(MOUNTED, "r"); if (!fp) return 1; @@ -673,3 +681,51 @@ int init_store(char *dir) return ret; } + +int read_node_list(uint32_t epoch, struct sheepdog_node_list_entry *entries, + int nr_nodes) +{ + int ret; + int fd; + char path[PATH_MAX]; + + if (epoch <= 0) + return -1; + + snprintf(path, sizeof(path), "%s/epoch/%x", obj_dir, epoch); + fd = open(path, O_RDONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); + if (!fd) + return -1; + + ret = pread64(fd, entries, + nr_nodes * sizeof(struct sheepdog_node_list_entry), 0); + + close(fd); + + return (ret / sizeof(struct sheepdog_node_list_entry)); +} + +int write_node_list(uint32_t epoch, struct sheepdog_node_list_entry *entries, + int nr_nodes) +{ + int ret; + int fd; + char path[PATH_MAX]; + + if (epoch <= 0) + return -1; + + snprintf(path, sizeof(path), "%s/epoch/%x", obj_dir, epoch); + fd = open(path, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); + if (!fd) + return -1; + + ret = pwrite64(fd, entries, + nr_nodes * sizeof(struct sheepdog_node_list_entry), 0); + if (ret != nr_nodes * sizeof(struct sheepdog_node_list_entry)) + return -1; + + close(fd); + + return nr_nodes; +} -- 1.6.5 |