[Sheepdog] [PATCH v2] sheep: update inode cache first

yaohaiting.wujue at gmail.com yaohaiting.wujue at gmail.com
Thu May 10 10:49:31 CEST 2012


From: HaiTing Yao <wujue.yht at taobao.com>

When create snapshot, write inode of base VDI internally without
care of cache. Then the inode in cache may be wrong from disk

Signed-off-by: HaiTing Yao <wujue.yht at taobao.com>
---
 sheep/store.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)

changes from v1

Rebase the v1 patch to codes now

diff --git a/sheep/store.c b/sheep/store.c
index f8bf404..8ca71dc 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -899,6 +899,46 @@ static int write_object_local(uint64_t oid, char *data, unsigned int datalen,
 
 	return ret;
 }
+
+static int write_inode_cache(uint64_t oid, char *data, unsigned int datalen,
+				uint64_t offset, uint16_t flags, int copies,
+				uint32_t epoch, int create)
+{
+	int ret;
+	struct request *req;
+	struct sd_obj_req *hdr;
+	uint32_t vid = oid_to_vid(oid);
+	uint32_t idx = data_oid_to_idx(oid);
+	struct object_cache *cache;
+
+	idx |= 1 << CACHE_VDI_SHIFT;
+
+	cache = find_object_cache(vid, 0);
+
+	req = zalloc(sizeof(*req));
+	if (!req)
+		return SD_RES_NO_MEM;
+	hdr = (struct sd_obj_req *)&req->rq;
+
+	hdr->oid = oid;
+	if (create)
+		hdr->opcode = SD_OP_CREATE_AND_WRITE_OBJ;
+	else
+		hdr->opcode = SD_OP_WRITE_OBJ;
+	hdr->copies = copies;
+	hdr->flags = flags | SD_FLAG_CMD_WRITE;
+	hdr->offset = offset;
+	hdr->data_length = datalen;
+	req->data = data;
+	req->op = get_sd_op(hdr->opcode);
+
+	ret = object_cache_rw(cache, idx, req);
+
+	free(req);
+
+	return ret;
+}
+
 int write_object(struct vnode_info *vnodes, uint32_t node_version,
 		 uint64_t oid, char *data, unsigned int datalen,
 		 uint64_t offset, uint16_t flags, int nr_copies, int create)
@@ -908,6 +948,15 @@ int write_object(struct vnode_info *vnodes, uint32_t node_version,
 	int i, fd, ret;
 	char name[128];
 
+	if (object_is_cached(oid)) {
+		ret = write_inode_cache(oid, data, datalen, offset,
+			flags, nr_copies, node_version, create);
+		if (ret != 0) {
+			eprintf("fail %"PRIx64" %"PRIx32"\n", oid, ret);
+			return -1;
+		}
+	}
+
 	for (i = 0; i < nr_copies; i++) {
 		unsigned rlen = 0, wlen = datalen;
 
-- 
1.7.1




More information about the sheepdog mailing list