From: Liu Yuan <tailai.ly at taobao.com> object cache 'oc' is globally shared by all IO threads, so we cannot use oc->oid without lock. Actually, we don't need it at all. Signed-off-by: Liu Yuan <tailai.ly at taobao.com> --- sheep/object_cache.c | 16 +++++++++------- sheep/sheep_priv.h | 1 - sheep/store.c | 1 - 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sheep/object_cache.c b/sheep/object_cache.c index ed10b86..c1226a4 100644 --- a/sheep/object_cache.c +++ b/sheep/object_cache.c @@ -172,11 +172,11 @@ int object_cache_lookup(struct object_cache *oc, uint32_t idx, int create) if (create) { unsigned data_length; - uint64_t oid = oc->oid; - if (is_vdi_obj(oid)) + if (idx & CACHE_VDI_BIT) data_length = SD_INODE_SIZE; else data_length = SD_DATA_OBJ_SIZE; + ret = prealloc(fd, data_length); if (ret != SD_RES_SUCCESS) ret = -1; @@ -262,7 +262,7 @@ int object_cache_rw(struct object_cache *oc, uint32_t idx, struct request *req) struct sd_obj_rsp *rsp = (struct sd_obj_rsp *)&req->rp; int ret; - dprintf("%"PRIx64", len %"PRIu32", off %"PRIu64"\n", oc->oid, hdr->data_length, hdr->offset); + dprintf("%"PRIx32", len %"PRIu32", off %"PRIu64"\n", idx, hdr->data_length, hdr->offset); if (hdr->flags & SD_FLAG_CMD_WRITE) { ret = write_cache_object(oc->vid, idx, req->data, hdr->data_length, hdr->offset); if (ret != SD_RES_SUCCESS) @@ -314,16 +314,19 @@ int object_cache_pull(struct object_cache *oc, uint32_t idx) { int i, n = 0, fd, ret = SD_RES_NO_MEM; unsigned wlen = 0, rlen, data_length, read_len; - uint64_t oid = oc->oid; + uint64_t oid; struct sd_obj_req hdr = { 0 }; struct sd_obj_rsp *rsp = (struct sd_obj_rsp *)&hdr; struct sd_vnode *vnodes = sys->vnodes; void *buf; - if (is_vdi_obj(oid)) + if (idx & CACHE_VDI_BIT) { + oid = vid_to_vdi_oid(oc->vid); data_length = SD_INODE_SIZE; - else + } else { + oid = vid_to_data_oid(oc->vid, idx); data_length = SD_DATA_OBJ_SIZE; + } buf = valloc(data_length); if (buf == NULL) { @@ -488,7 +491,6 @@ int object_is_cached(uint64_t oid) if (!cache) return 0; - cache->oid = oid; if (object_cache_lookup(cache, idx, 0) < 0) return 0; else diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h index b932e83..98ae0e3 100644 --- a/sheep/sheep_priv.h +++ b/sheep/sheep_priv.h @@ -410,7 +410,6 @@ static inline int sys_can_halt(void) struct object_cache { uint32_t vid; - uint64_t oid; struct list_head dirty_list; struct hlist_node hash; struct rb_root dirty_rb; diff --git a/sheep/store.c b/sheep/store.c index 26b1ee3..a86b80d 100644 --- a/sheep/store.c +++ b/sheep/store.c @@ -821,7 +821,6 @@ static int handle_gateway_request(struct request *req) idx |= 1 << CACHE_VDI_SHIFT; cache = find_object_cache(vid, 1); - cache->oid = oid; if (hdr->opcode == SD_OP_CREATE_AND_WRITE_OBJ) create = 1; -- 1.7.8.2 |