From: levin li <xingke.lwp at taobao.com> Since we use a local gateway request to replace the old forward_*_obj_req method, it's no need to keep vnode_info and epoch in this api. Signed-off-by: levin li <xingke.lwp at taobao.com> --- sheep/object_cache.c | 19 ++++++++--------- sheep/sheep_priv.h | 15 ++++++-------- sheep/store.c | 15 ++++++-------- sheep/vdi.c | 56 ++++++++++++++++++++------------------------------ 4 files changed, 43 insertions(+), 62 deletions(-) diff --git a/sheep/object_cache.c b/sheep/object_cache.c index e538cda..9942198 100644 --- a/sheep/object_cache.c +++ b/sheep/object_cache.c @@ -549,8 +549,8 @@ static uint64_t idx_to_oid(uint32_t vid, uint32_t idx) return vid_to_data_oid(vid, idx); } -static int push_cache_object(struct vnode_info *vnode_info, uint32_t vid, - uint32_t idx, uint64_t bmap, int create) +static int push_cache_object(uint32_t vid, uint32_t idx, + uint64_t bmap, int create) { struct sd_req hdr; void *buf; @@ -610,8 +610,7 @@ out: } /* Push back all the dirty objects to sheep cluster storage */ -static int object_cache_push(struct vnode_info *vnode_info, - struct object_cache *oc) +static int object_cache_push(struct object_cache *oc) { struct object_cache_entry *entry, *t; struct rb_root *inactive_dirty_tree; @@ -630,7 +629,7 @@ static int object_cache_push(struct vnode_info *vnode_info, * request is issued in one of gateway worker threads * So we need not to protect inactive dirty tree and list */ list_for_each_entry_safe(entry, t, inactive_dirty_list, list) { - ret = push_cache_object(vnode_info, oc->vid, entry->idx, + ret = push_cache_object(oc->vid, entry->idx, entry->bmap, entry->create); if (ret != SD_RES_SUCCESS) goto push_failed; @@ -718,7 +717,7 @@ static int object_cache_flush_and_delete(struct vnode_info *vnode_info, idx = strtoul(d->d_name, NULL, 16); if (idx == ULLONG_MAX) continue; - if (push_cache_object(vnode_info, vid, idx, all, 1) != + if (push_cache_object(vid, idx, all, 1) != SD_RES_SUCCESS) { dprintf("failed to push %"PRIx64"\n", idx_to_oid(vid, idx)); @@ -790,7 +789,7 @@ int object_cache_handle_request(struct request *req) int object_cache_write(uint64_t oid, char *data, unsigned int datalen, uint64_t offset, uint16_t flags, int copies, - uint32_t epoch, int create) + int create) { int ret; struct request *req; @@ -825,7 +824,7 @@ int object_cache_write(uint64_t oid, char *data, unsigned int datalen, } int object_cache_read(uint64_t oid, char *data, unsigned int datalen, - uint64_t offset, int copies, uint32_t epoch) + uint64_t offset, int copies) { int ret; struct request *req; @@ -861,7 +860,7 @@ static void object_cache_flush_vdi_fn(struct work *work) struct flush_work *fw = container_of(work, struct flush_work, work); dprintf("flush vdi %"PRIx32"\n", fw->cache->vid); - if (object_cache_push(fw->vnode_info, fw->cache) != SD_RES_SUCCESS) + if (object_cache_push(fw->cache) != SD_RES_SUCCESS) eprintf("failed to flush vdi %"PRIx32"\n", fw->cache->vid); } @@ -896,7 +895,7 @@ int object_cache_flush_vdi(struct request *req) return SD_RES_SUCCESS; } - return object_cache_push(req->vnodes, cache); + return object_cache_push(cache); } int object_cache_flush_and_del(struct request *req) diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h index 52c4816..2a452b0 100644 --- a/sheep/sheep_priv.h +++ b/sheep/sheep_priv.h @@ -291,14 +291,11 @@ bool oid_in_recovery(uint64_t oid); int is_recovery_init(void); int node_in_recovery(void); -int write_object(struct vnode_info *vnodes, uint32_t node_version, - uint64_t oid, char *data, unsigned int datalen, +int write_object(uint64_t oid, char *data, unsigned int datalen, uint64_t offset, uint16_t flags, int nr, int create); -int read_object(struct vnode_info *vnodes, uint32_t node_version, - uint64_t oid, char *data, unsigned int datalen, +int read_object(uint64_t oid, char *data, unsigned int datalen, uint64_t offset, int nr); -int remove_object(struct vnode_info *vnodes, uint32_t node_version, - uint64_t oid, int nr); +int remove_object(uint64_t oid, int nr); void del_sheep_fd(int fd); int get_sheep_fd(uint8_t *addr, uint16_t port, int node_idx, uint32_t epoch); @@ -404,10 +401,10 @@ int object_is_cached(uint64_t oid); int object_cache_handle_request(struct request *req); int object_cache_write(uint64_t oid, char *data, unsigned int datalen, - uint64_t offset, uint16_t flags, int copies, uint32_t epoch, - int create); + uint64_t offset, uint16_t flags, int copies, + int create); int object_cache_read(uint64_t oid, char *data, unsigned int datalen, - uint64_t offset, int copies, uint32_t epoch); + uint64_t offset, int copies); int object_cache_flush_vdi(struct request *req); int object_cache_flush_and_del(struct request *req); void object_cache_delete(uint32_t vid); diff --git a/sheep/store.c b/sheep/store.c index 3378c86..b4a7f31 100644 --- a/sheep/store.c +++ b/sheep/store.c @@ -513,8 +513,7 @@ int init_store(const char *d, int enable_write_cache) /* * Write data to both local object cache (if enabled) and backends */ -int write_object(struct vnode_info *vnodes, uint32_t epoch, - uint64_t oid, char *data, unsigned int datalen, +int write_object(uint64_t oid, char *data, unsigned int datalen, uint64_t offset, uint16_t flags, int nr_copies, int create) { struct sd_req hdr; @@ -522,7 +521,7 @@ int write_object(struct vnode_info *vnodes, uint32_t epoch, if (sys->enable_write_cache && object_is_cached(oid)) { ret = object_cache_write(oid, data, datalen, offset, - flags, nr_copies, epoch, create); + flags, nr_copies, create); if (ret != 0) { eprintf("write cache failed %"PRIx64" %"PRIx32"\n", oid, ret); @@ -532,7 +531,7 @@ int write_object(struct vnode_info *vnodes, uint32_t epoch, memset(&hdr, 0, sizeof(hdr)); hdr.opcode = create ? SD_OP_CREATE_AND_WRITE_OBJ : SD_OP_WRITE_OBJ; - hdr.flags = SD_FLAG_CMD_WRITE; + hdr.flags = flags | SD_FLAG_CMD_WRITE; hdr.obj.oid = oid; hdr.obj.offset = offset; @@ -549,8 +548,7 @@ int write_object(struct vnode_info *vnodes, uint32_t epoch, * Read data firstly from local object cache(if enabled), if fail, * try read backends */ -int read_object(struct vnode_info *vnodes, uint32_t epoch, - uint64_t oid, char *data, unsigned int datalen, +int read_object(uint64_t oid, char *data, unsigned int datalen, uint64_t offset, int nr_copies) { struct sd_req hdr; @@ -558,7 +556,7 @@ int read_object(struct vnode_info *vnodes, uint32_t epoch, if (sys->enable_write_cache && object_is_cached(oid)) { ret = object_cache_read(oid, data, datalen, offset, - nr_copies, epoch); + nr_copies); if (ret != SD_RES_SUCCESS) { eprintf("try forward read %"PRIx64" %"PRIx32"\n", oid, ret); @@ -581,8 +579,7 @@ forward_read: return ret; } -int remove_object(struct vnode_info *vnodes, uint32_t epoch, - uint64_t oid, int nr) +int remove_object(uint64_t oid, int nr) { struct sd_req hdr; int ret; diff --git a/sheep/vdi.c b/sheep/vdi.c index 76a7128..8ce34ac 100644 --- a/sheep/vdi.c +++ b/sheep/vdi.c @@ -56,8 +56,7 @@ static int create_vdi_obj(struct vnode_info *vnode_info, uint32_t epoch, nr_copies = copies; if (base_vid) { - ret = read_object(vnode_info, epoch, - vid_to_vdi_oid(base_vid), (char *)base, + ret = read_object(vid_to_vdi_oid(base_vid), (char *)base, sizeof(*base), 0, nr_copies); if (ret != SD_RES_SUCCESS) { ret = SD_RES_BASE_VDI_READ; @@ -72,8 +71,7 @@ static int create_vdi_obj(struct vnode_info *vnode_info, uint32_t epoch, vprintf(SDOG_INFO, "tree snapshot %s %" PRIx32 " %" PRIx32 "\n", name, cur_vid, base_vid); - ret = read_object(vnode_info, epoch, - vid_to_vdi_oid(cur_vid), (char *)cur, + ret = read_object(vid_to_vdi_oid(cur_vid), (char *)cur, SD_INODE_HEADER_SIZE, 0, nr_copies); if (ret != SD_RES_SUCCESS) { vprintf(SDOG_ERR, "failed\n"); @@ -115,8 +113,7 @@ static int create_vdi_obj(struct vnode_info *vnode_info, uint32_t epoch, } if (is_snapshot && cur_vid != base_vid) { - ret = write_object(vnode_info, epoch, - vid_to_vdi_oid(cur_vid), (char *)cur, + ret = write_object(vid_to_vdi_oid(cur_vid), (char *)cur, SD_INODE_HEADER_SIZE, 0, 0, nr_copies, 0); if (ret != 0) { vprintf(SDOG_ERR, "failed\n"); @@ -126,8 +123,7 @@ static int create_vdi_obj(struct vnode_info *vnode_info, uint32_t epoch, } if (base_vid) { - ret = write_object(vnode_info, epoch, - vid_to_vdi_oid(base_vid), (char *)base, + ret = write_object(vid_to_vdi_oid(base_vid), (char *)base, SD_INODE_HEADER_SIZE, 0, 0, nr_copies, 0); if (ret != 0) { vprintf(SDOG_ERR, "failed\n"); @@ -136,8 +132,7 @@ static int create_vdi_obj(struct vnode_info *vnode_info, uint32_t epoch, } } - ret = write_object(vnode_info, epoch, - vid_to_vdi_oid(new_vid), (char *)new, sizeof(*new), + ret = write_object(vid_to_vdi_oid(new_vid), (char *)new, sizeof(*new), 0, 0, nr_copies, 1); if (ret != 0) ret = SD_RES_VDI_WRITE; @@ -170,8 +165,7 @@ static int find_first_vdi(struct vnode_info *vnode_info, uint32_t epoch, nr_copies = get_nr_copies(vnode_info); for (i = start; i >= end; i--) { - ret = read_object(vnode_info, epoch, - vid_to_vdi_oid(i), (char *)inode, + ret = read_object(vid_to_vdi_oid(i), (char *)inode, SD_INODE_HEADER_SIZE, 0, nr_copies); if (ret != SD_RES_SUCCESS) { ret = SD_RES_EIO; @@ -406,8 +400,8 @@ static int delete_inode(struct deletion_work *dw) nr_copies = get_nr_copies(dw->vnodes); - ret = read_object(dw->vnodes, dw->epoch, vid_to_vdi_oid(dw->vid), - (char *)inode, SD_INODE_HEADER_SIZE, 0, nr_copies); + ret = read_object(vid_to_vdi_oid(dw->vid), (char *)inode, + SD_INODE_HEADER_SIZE, 0, nr_copies); if (ret != SD_RES_SUCCESS) { ret = SD_RES_EIO; goto out; @@ -415,9 +409,8 @@ static int delete_inode(struct deletion_work *dw) memset(inode->name, 0, sizeof(inode->name)); - ret = write_object(dw->vnodes, dw->epoch, vid_to_vdi_oid(dw->vid), - (char *)inode, SD_INODE_HEADER_SIZE, 0, 0, - nr_copies, 0); + ret = write_object(vid_to_vdi_oid(dw->vid), (char *)inode, + SD_INODE_HEADER_SIZE, 0, 0, nr_copies, 0); if (ret != 0) { ret = SD_RES_EIO; goto out; @@ -447,7 +440,7 @@ static void delete_one(struct work *work) nr_copies = get_nr_copies(dw->vnodes); - ret = read_object(dw->vnodes, dw->epoch, vid_to_vdi_oid(vdi_id), + ret = read_object(vid_to_vdi_oid(vdi_id), (void *)inode, sizeof(*inode), 0, nr_copies); @@ -469,9 +462,8 @@ static void delete_one(struct work *work) continue; } - ret = remove_object(dw->vnodes, dw->epoch, - vid_to_data_oid(inode->data_vdi_id[i], i), - nr_copies); + ret = remove_object(vid_to_data_oid(inode->data_vdi_id[i], i), + nr_copies); if (ret != SD_RES_SUCCESS) dw->delete_error = 1; @@ -486,8 +478,8 @@ static void delete_one(struct work *work) if (!dw->delete_error) memset(inode->name, 0, sizeof(inode->name)); - write_object(dw->vnodes, dw->epoch, vid_to_vdi_oid(vdi_id), - (void *)inode, sizeof(*inode), 0, 0, nr_copies, 0); + write_object(vid_to_vdi_oid(vdi_id), (void *)inode, + sizeof(*inode), 0, 0, nr_copies, 0); out: free(inode); } @@ -535,9 +527,8 @@ static int fill_vdi_list(struct deletion_work *dw, uint32_t root_vid) dw->buf[dw->count++] = root_vid; again: vid = dw->buf[done++]; - ret = read_object(dw->vnodes, dw->epoch, vid_to_vdi_oid(vid), - (char *)inode, SD_INODE_HEADER_SIZE, 0, - nr_copies); + ret = read_object(vid_to_vdi_oid(vid), (char *)inode, + SD_INODE_HEADER_SIZE, 0, nr_copies); if (ret != SD_RES_SUCCESS) { eprintf("cannot find VDI object\n"); @@ -580,7 +571,7 @@ static uint64_t get_vdi_root(struct vnode_info *vnode_info, uint32_t epoch, goto out; } next: - ret = read_object(vnode_info, epoch, vid_to_vdi_oid(vid), (char *)inode, + ret = read_object(vid_to_vdi_oid(vid), (char *)inode, SD_INODE_HEADER_SIZE, 0, nr_copies); if (vid == inode->vdi_id && inode->snap_id == 1 @@ -711,12 +702,11 @@ int get_vdi_attr(struct vnode_info *vnode_info, uint32_t epoch, end = *attrid - 1; while (*attrid != end) { oid = vid_to_attr_oid(vid, *attrid); - ret = read_object(vnode_info, epoch, oid, (char *)&tmp_attr, + ret = read_object(oid, (char *)&tmp_attr, sizeof(tmp_attr), 0, nr_copies); if (ret == SD_RES_NO_OBJ && wr) { - ret = write_object(vnode_info, epoch, oid, - (char *)vattr, data_len, 0, 0, + ret = write_object(oid, (char *)vattr, data_len, 0, 0, nr_copies, 1); if (ret) ret = SD_RES_EIO; @@ -736,8 +726,7 @@ int get_vdi_attr(struct vnode_info *vnode_info, uint32_t epoch, if (excl) ret = SD_RES_VDI_EXIST; else if (delete) { - ret = write_object(vnode_info, - epoch, oid, (char *)"", 1, + ret = write_object(oid, (char *)"", 1, offsetof(struct sheepdog_vdi_attr, name), 0, nr_copies, 0); if (ret) @@ -745,8 +734,7 @@ int get_vdi_attr(struct vnode_info *vnode_info, uint32_t epoch, else ret = SD_RES_SUCCESS; } else if (wr) { - ret = write_object(vnode_info, - epoch, oid, (char *)vattr, + ret = write_object(oid, (char *)vattr, SD_ATTR_OBJ_SIZE, 0, 0, nr_copies, 0); -- 1.7.10 |