[sheepdog] [PATCH stable-0.8 2/3] sheep: clear child vdi for deletion

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Tue Mar 18 08:21:44 CET 2014


From: Liu Yuan <namei.unix at gmail.com>

This will fix a bug that after deletion of clones, we fail to create clones
with the snapshot that we previousy cloned.

Reviewed-by: Robin Dong <sanbai at taobao.com>
Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 sheep/vdi.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/sheep/vdi.c b/sheep/vdi.c
index ec5a55b..4da24db 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -1028,6 +1028,51 @@ static uint64_t get_vdi_root(uint32_t vid, bool *cloned)
 	return vid;
 }
 
+static void clear_parent_child_vdi(uint32_t vid)
+{
+	struct sd_inode * inode = xmalloc(SD_INODE_HEADER_SIZE);
+	uint32_t pvid, i;
+	int ret;
+
+	ret = read_backend_object(vid_to_vdi_oid(vid), (char *)inode,
+				  SD_INODE_HEADER_SIZE, 0);
+	if (ret != SD_RES_SUCCESS) {
+		sd_err("failed to read inode %"PRIx32, vid);
+		goto out;
+	}
+
+	pvid = inode->parent_vdi_id;
+	if (!pvid)
+		goto out;
+	ret = read_backend_object(vid_to_vdi_oid(pvid), (char *)inode,
+				  SD_INODE_HEADER_SIZE, 0);
+	if (ret != SD_RES_SUCCESS) {
+		sd_err("failed to read parent inode %"PRIx32, pvid);
+		goto out;
+	}
+
+	for (i = 0; i < MAX_CHILDREN; i++)
+		if (inode->child_vdi_id[i] == vid) {
+			inode->child_vdi_id[i] = 0;
+			break;
+		}
+
+	if (i == MAX_CHILDREN) {
+		sd_info("failed to find child %"PRIx32, vid);
+		goto out;
+	}
+
+	ret = sd_write_object(vid_to_vdi_oid(pvid), (char *)inode,
+			      SD_INODE_HEADER_SIZE, 0, false);
+	if (ret != SD_RES_SUCCESS) {
+		sd_err("failed to update parent %"PRIx32, pvid);
+		goto out;
+	}
+	sd_debug("parent %"PRIx32, pvid);
+out:
+	free(inode);
+}
+
 static int start_deletion(struct request *req, uint32_t vid)
 {
 	struct deletion_work *dw = NULL;
@@ -1052,6 +1097,8 @@ static int start_deletion(struct request *req, uint32_t vid)
 		goto out;
 	}
 
+	clear_parent_child_vdi(vid);
+
 	ret = fill_delete_vid_array(dw, root_vid);
 	if (ret < 0) {
 		ret = SD_RES_EIO;
-- 
1.8.1.2




More information about the sheepdog mailing list