[sheepdog] [PATCH] sheep: write vid back if found vdi_id in hyper volume

Robin Dong robin.k.dong at gmail.com
Fri Jan 3 07:05:05 CET 2014


From: Robin Dong <sanbai at taobao.com>

We forgot to write vid back if it has been found in second level leaf-node
previously, this will cause data lost when doing overwrite for large file.

Signed-off-by: Robin Dong <sanbai at taobao.com>
---
 lib/sd_inode.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/lib/sd_inode.c b/lib/sd_inode.c
index 0043981..da3182e 100644
--- a/lib/sd_inode.c
+++ b/lib/sd_inode.c
@@ -568,6 +568,7 @@ void sd_inode_set_vid(write_node_fn writer, read_node_fn reader,
 {
 	struct sd_extent_header *header;
 	struct find_path path;
+	uint64_t offset;
 	int ret;
 
 	path.p_ext_header = NULL;
@@ -585,6 +586,18 @@ 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 for
+				 * second level leaf-node.
+				 */
+				if (!path.p_ext_header)
+					goto out;
+				offset = (unsigned char *)(path.p_ext) -
+					 (unsigned char *)(path.p_ext_header) +
+					 offsetof(struct sd_extent, vdi_id);
+				writer(path.p_idx->oid, &vdi_id, sizeof(vdi_id),
+				       offset, 0, inode->nr_copies,
+				       inode->copy_policy, false, false);
 				goto out;
 			} else {
 				ret = insert_new_node(writer, reader, inode,
-- 
1.7.12.4




More information about the sheepdog mailing list