The number of copies is used when forwarding requests Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp> --- collie/store.c | 29 ++++++++++------------------- lib/net.c | 8 ++++---- shepherd/shepherd.c | 5 ++++- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/collie/store.c b/collie/store.c index aadddc5..7c0f6d1 100644 --- a/collie/store.c +++ b/collie/store.c @@ -66,8 +66,9 @@ static int stat_sheep(uint64_t *store_size, uint64_t *store_free) return SD_RES_SUCCESS; } -static int read_from_one(struct cluster_info *cluster, uint64_t oid, - unsigned *rlen, void *buf, uint64_t offset) +static int read_from_others(struct cluster_info *cluster, uint64_t oid, + unsigned *rlen, void *buf, uint64_t offset, + int copies) { int i, n, nr, fd, ret; unsigned wlen; @@ -80,7 +81,7 @@ static int read_from_one(struct cluster_info *cluster, uint64_t oid, again: nr = build_node_list(&cluster->node_list, e); - for (i = 0; i < nr; i++) { + for (i = 0; i < copies; i++) { n = obj_to_sheep(e, nr, oid, i); snprintf(name, sizeof(name), "%d.%d.%d.%d", @@ -93,6 +94,7 @@ again: memset(&hdr, 0, sizeof(hdr)); hdr.opcode = SD_OP_READ_OBJ; + hdr.copies = copies; hdr.oid = oid; hdr.epoch = cluster->epoch; @@ -124,19 +126,6 @@ again: return -1; } -static int read_from_other_sheeps(struct cluster_info *cluster, - uint64_t oid, char *buf, int copies) -{ - int ret; - unsigned int rlen; - - rlen = SD_DATA_OBJ_SIZE; - - ret = read_from_one(cluster, oid, &rlen, buf, 0); - - return ret; -} - static int check_epoch(struct cluster_info *cluster, struct request *req) { struct sd_req *hdr = (struct sd_req *)&req->rq; @@ -173,6 +162,7 @@ void store_queue_request(struct work *work, int idx) uint32_t req_epoch = hdr->epoch; struct sd_node_rsp *nrsp = (struct sd_node_rsp *)&req->rp; int copies; + unsigned rlen; /* use le_to_cpu */ @@ -239,9 +229,10 @@ void store_queue_request(struct work *work, int idx) if (hdr->flags & SD_FLAG_CMD_COW) { dprintf("%" PRIu64 "\n", hdr->cow_oid); - ret = read_from_other_sheeps(cluster, - hdr->cow_oid, buf, - hdr->copies); + rlen = SD_DATA_OBJ_SIZE; + ret = read_from_others(cluster, hdr->cow_oid, &rlen, buf, + 0, hdr->copies); + if (ret) { ret = 1; goto out; diff --git a/lib/net.c b/lib/net.c index caf592f..17f0fd6 100644 --- a/lib/net.c +++ b/lib/net.c @@ -361,12 +361,11 @@ int write_object(struct sheepdog_node_list_entry *e, memset(&hdr, 0, sizeof(hdr)); hdr.epoch = node_version; - if (create) { + if (create) hdr.opcode = SD_OP_CREATE_AND_WRITE_OBJ; - hdr.copies = nr; - } else + else hdr.opcode = SD_OP_WRITE_OBJ; - + hdr.copies = nr; hdr.oid = oid; hdr.flags = SD_FLAG_CMD_WRITE; @@ -412,6 +411,7 @@ int read_object(struct sheepdog_node_list_entry *e, memset(&hdr, 0, sizeof(hdr)); hdr.epoch = node_version; hdr.opcode = SD_OP_READ_OBJ; + hdr.copies = nr; hdr.oid = oid; hdr.flags = 0; diff --git a/shepherd/shepherd.c b/shepherd/shepherd.c index 9654888..b6129a8 100644 --- a/shepherd/shepherd.c +++ b/shepherd/shepherd.c @@ -396,6 +396,8 @@ int parse_vdi(vdi_parser_func_t func, void *data) return 1; req.opcode = SD_OP_SO_READ_VDIS; + /* TODO: use ANAME_COPIES in the vdi directory */ + req.copies = 3; ret = exec_reqs(node_list_entries, nr_nodes, node_list_version, SD_DIR_OID, (struct sd_req *)&req, buf, 0, DIR_BUF_LEN,nr_nodes); @@ -411,8 +413,9 @@ int parse_vdi(vdi_parser_func_t func, void *data) if (!ent->name_len) break; + /* TODO: use ANAME_COPIES in the vdi directory */ ret = read_object(node_list_entries, nr_nodes, node_list_version, - ent->oid, (void *)&i, sizeof(i), 0, nr_nodes); + ent->oid, (void *)&i, sizeof(i), 0, 3); if (ret == sizeof(i)) func(ent->oid, ent->name, ent->tag, ent->flags, &i, data); -- 1.6.5 |