The new function sd_inode_write_vid_only will only write 'vid' in 'idx' for non-hyper-volume vid. For hyper-volume vdi, we write the 'vid' in function sd_inode_set_vid() only when this 'vid' is exists.
Signed-off-by: Robin Dong <[email protected]> --- include/sheepdog_proto.h | 3 +++ lib/sd_inode.c | 28 ++++++++++++++++++++++++++++ sheep/ops.c | 4 ++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h index 6a7ada7..22d6f73 100644 --- a/include/sheepdog_proto.h +++ b/include/sheepdog_proto.h @@ -282,6 +282,9 @@ extern void sd_inode_set_vid(write_node_fn writer, read_node_fn reader, uint32_t vdi_id); extern int sd_inode_write(write_node_fn writer, struct sd_inode *inode, int flags, bool create, bool direct); +extern int sd_inode_write_vid_only(write_node_fn writer, struct sd_inode *inode, + uint32_t idx, uint32_t vid, int flags, + bool create, bool direct); extern int sd_inode_write_vid(write_node_fn writer, struct sd_inode *inode, uint32_t idx, uint32_t vid, uint32_t value, int flags, bool create, bool direct); diff --git a/lib/sd_inode.c b/lib/sd_inode.c index 0043981..fb689d5 100644 --- a/lib/sd_inode.c +++ b/lib/sd_inode.c @@ -585,6 +585,15 @@ void sd_inode_set_vid(write_node_fn writer, read_node_fn reader, ret = search_whole_btree(reader, inode, idx, &path); if (ret == SD_RES_BTREE_FOUND) { path.p_ext->vdi_id = vdi_id; + /* only write the vdi_id in sd_extent */ + if (path.p_ext_header) + header = path.p_ext_header; + writer(vid_to_vdi_oid(inode->vdi_id), &vdi_id, + sizeof(vdi_id), (char *)(path.p_ext) - + (char *)header + + offsetof(struct sd_extent, vdi_id), 0, + inode->nr_copies, inode->copy_policy, + false, false); goto out; } else { ret = insert_new_node(writer, reader, inode, @@ -661,6 +670,25 @@ out: return ret; } +/* + * Only write the vid for non-hyper-volume vdi. + * For hyper-volume, sd_inode_set_vid() have already wrote the vid when + * search_whole_btree() return SD_RES_BTREE_FOUND. Therefore, this function + * could only be called when vid could be found. + */ +int sd_inode_write_vid_only(write_node_fn writer, struct sd_inode *inode, + uint32_t idx, uint32_t vid, int flags, bool create, + bool direct) +{ + int ret = SD_RES_SUCCESS; + if (inode->store_policy == 0) + ret = writer(vid_to_vdi_oid(vid), &vid, sizeof(vid), + SD_INODE_HEADER_SIZE + sizeof(vid) * idx, + flags, inode->nr_copies, inode->copy_policy, + create, direct); + return ret; +} + /* Write the meta-data of inode out */ int sd_inode_write_vid(write_node_fn writer, struct sd_inode *inode, uint32_t idx, uint32_t vid, uint32_t value, diff --git a/sheep/ops.c b/sheep/ops.c index 1e9bc1e..403dfa2 100644 --- a/sheep/ops.c +++ b/sheep/ops.c @@ -842,8 +842,8 @@ static int local_discard_obj(struct request *req) /* if vid in idx is not exist, we don't need to remove it */ if (tmp_vid) { INODE_SET_VID(inode, idx, 0); - ret = sd_inode_write_vid(sheep_bnode_writer, inode, idx, vid, - 0, 0, false, false); + ret = sd_inode_write_vid_only(sheep_bnode_writer, inode, idx, + vid, 0, false, false); if (ret != SD_RES_SUCCESS) goto out; if (sd_remove_object(oid) != SD_RES_SUCCESS) -- 1.7.9.5 -- sheepdog mailing list [email protected] http://lists.wpkg.org/mailman/listinfo/sheepdog
