int gateway_create_and_write_obj(struct request *req) { if (is_object_cache_enabled() && !req->local && !bypass_object_cache(req)) return object_cache_handle_request(req); return gateway_forward_request(req, false); }
/* * Try our best to read one copy and read local first. * * Return success if any read succeed. We don't call gateway_forward_request() * because we only read once. */ int gateway_read_obj(struct request *req) { int i, ret = SD_RES_SUCCESS; unsigned wlen, rlen; struct sd_req fwd_hdr; struct sd_rsp *rsp = (struct sd_rsp *)&fwd_hdr; struct sd_vnode *v; struct sd_vnode *obj_vnodes[SD_MAX_COPIES]; uint64_t oid = req->rq.obj.oid; int nr_copies, j; if (is_object_cache_enabled() && !req->local && !bypass_object_cache(req)) return object_cache_handle_request(req); nr_copies = get_req_copy_number(req); oid_to_vnodes(req->vinfo->vnodes, req->vinfo->nr_vnodes, oid, nr_copies, obj_vnodes); for (i = 0; i < nr_copies; i++) { v = obj_vnodes[i]; if (!vnode_is_local(v)) continue; ret = peer_read_obj(req); if (ret == SD_RES_SUCCESS) return ret; eprintf("local read fail %x\n", ret); break; } /* * Read random copy from cluster for better load balance, useful for * reading base VM's COW objects */ j = random(); for (i = 0; i < nr_copies; i++) { int idx = (i + j) % nr_copies; v = obj_vnodes[idx]; if (vnode_is_local(v)) continue; /* * We need to re-init it because rsp and req share the same * structure. */ gateway_init_fwd_hdr(&fwd_hdr, &req->rq); wlen = 0; rlen = fwd_hdr.data_length; ret = sheep_exec_req(&v->nid, &fwd_hdr, req->data, &wlen, &rlen); if (ret != SD_RES_SUCCESS) continue; /* Read success */ memcpy(&req->rp, rsp, sizeof(*rsp)); break; } return ret; }
int gateway_create_and_write_obj(struct request *req) { uint64_t oid = req->rq.obj.oid; if (oid_is_readonly(oid)) return SD_RES_READONLY; if (!bypass_object_cache(req)) return object_cache_handle_request(req); return gateway_forward_request(req); }
/* * Try our best to read one copy and read local first. * * Return success if any read succeed. We don't call gateway_forward_request() * because we only read once. */ int gateway_read_obj(struct request *req) { int i, ret = SD_RES_SUCCESS; struct sd_req fwd_hdr; struct sd_rsp *rsp = (struct sd_rsp *)&fwd_hdr; const struct sd_vnode *v; const struct sd_vnode *my_v; const struct sd_vnode *obj_vnodes[SD_MAX_COPIES]; const struct sd_vnode *my_obj_vnodes[SD_MAX_COPIES]; uint64_t oid = req->rq.obj.oid; int nr_copies, j; //PRINT_TO_LOG("WYH\n"); if (sys->enable_object_cache && !req->local && !bypass_object_cache(req)) { ret = object_cache_handle_request(req); goto out; } nr_copies = get_req_copy_number(req); if (nr_copies == 0) { sd_debug("there is no living nodes"); return SD_RES_HALT; } oid_to_vnodes(req->vinfo->vnodes, req->vinfo->nr_vnodes, oid, nr_copies, obj_vnodes); //PRINT_TO_LOG("out:%s\n", addr_to_str(obj_vnodes[0]->nid.addr,obj_vnodes[0]->nid.port)); oid_to_vnodes(req->vinfo->my_vnodes, req->vinfo->my_nr_vnodes, oid, nr_copies, my_obj_vnodes); my_v = my_obj_vnodes[0]; //PRINT_TO_LOG("out:%s\n", addr_to_str(my_v->nid.addr,my_v->nid.port)); for (i = 0; i < nr_copies; i++) { v = obj_vnodes[0]; my_v = my_obj_vnodes[0]; //PRINT_TO_LOG("phy:%s\n", addr_to_str(v->nid.addr,v->nid.port)); //PRINT_TO_LOG("vir:%s\n", addr_to_str(my_v->nid.addr, my_v->nid.port)); //PRINT_TO_LOG("%d,%d\n", req->vinfo->nr_vnodes, req->vinfo->my_nr_vnodes); if (!vnode_is_local(v)) continue; ret = peer_read_obj(req); if (ret == SD_RES_SUCCESS) goto out; sd_err("local read %"PRIx64" failed, %s", oid, sd_strerror(ret)); break; } /* * Read random copy from cluster for better load balance, useful for * reading base VM's COW objects */ j = random(); for (i = 0; i < nr_copies; i++) { int idx = (i + j) % nr_copies; v = obj_vnodes[idx]; if (vnode_is_local(v)) continue; /* * We need to re-init it because rsp and req share the same * structure. */ gateway_init_fwd_hdr(&fwd_hdr, &req->rq); ret = sheep_exec_req(&v->nid, &fwd_hdr, req->data); if (ret != SD_RES_SUCCESS) continue; /* Read success */ memcpy(&req->rp, rsp, sizeof(*rsp)); break; } out: if (ret == SD_RES_SUCCESS && req->rq.proto_ver < SD_PROTO_VER_TRIM_ZERO_SECTORS) { /* the client doesn't support trimming zero bytes */ untrim_zero_blocks(req->data, req->rp.obj.offset, req->rp.data_length, req->rq.data_length); req->rp.data_length = req->rq.data_length; req->rp.obj.offset = 0; } return ret; }