From: Robin Dong <sanbai at taobao.com> Use INODE_SET_VID_RANGE to set vid is more effecient for IO operaion, and, after set vid to zero, we only need to REMOVE_OBJ (not DISCARD_OBJ). Signed-off-by: Robin Dong <sanbai at taobao.com> --- sheep/http/oalloc.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/sheep/http/oalloc.c b/sheep/http/oalloc.c index 55433a0..66d7266 100644 --- a/sheep/http/oalloc.c +++ b/sheep/http/oalloc.c @@ -265,8 +265,28 @@ int oalloc_free(uint32_t vid, uint64_t start, uint64_t count) char *meta = xvalloc(SD_DATA_OBJ_SIZE); struct header *hd; uint64_t oid = vid_to_data_oid(vid, 0), i; + struct sd_inode *inode = xmalloc(sizeof(struct sd_inode)); int ret; + ret = sd_read_object(vid_to_vdi_oid(vid), (char *)inode, + sizeof(*inode), 0); + if (ret != SD_RES_SUCCESS) { + sd_err("failed to read inode, %" PRIx64 ", %s", + vid_to_vdi_oid(vid), sd_strerror(ret)); + goto out; + } + + sd_debug("discard start %"PRIu64" end %"PRIu64, start, + start + count - 1); + INODE_SET_VID_RANGE(inode, start, (start + count - 1), 0); + + ret = sd_inode_write(sheep_bnode_writer, inode, 0, false, false); + if (ret != SD_RES_SUCCESS) { + sd_err("failed to update inode, %" PRIx64", %s", + vid_to_vdi_oid(vid), sd_strerror(ret)); + goto out; + } + ret = sd_read_object(oid, meta, SD_DATA_OBJ_SIZE, 0); if (ret != SD_RES_SUCCESS) { sd_err("failed to read meta %" PRIx64 ", %s", oid, @@ -278,11 +298,11 @@ int oalloc_free(uint32_t vid, uint64_t start, uint64_t count) if (ret != SD_RES_SUCCESS) goto out; - /* XXX use aio to speed up discard of objects */ + /* XXX use aio to speed up remove of objects */ for (i = 0; i < count; i++) { struct sd_req hdr; - sd_init_req(&hdr, SD_OP_DISCARD_OBJ); + sd_init_req(&hdr, SD_OP_REMOVE_OBJ); hdr.obj.oid = vid_to_data_oid(vid, start + i); ret = exec_local_req(&hdr, NULL); if (ret != SD_RES_SUCCESS) @@ -299,5 +319,6 @@ int oalloc_free(uint32_t vid, uint64_t start, uint64_t count) sd_debug("used %"PRIu64", nr_free %"PRIu64, hd->used, hd->nr_free); out: free(meta); + free(inode); return ret; } -- 1.7.12.4 |