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

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Thu May 10 20:43:35 CEST 2012


At Thu, 10 May 2012 16:49:31 +0800,
yaohaiting.wujue at gmail.com wrote:
> 
> 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

Applied, thanks.

Note that this doesn't still pass the testcase I posted before:

==
 $ qemu-img convert ~/linux.img sheepdog:linux
 $ collie vdi read linux 0 512 | hd | head -1
 00000000  fa eb 7c 6c 62 61 4c 49  4c 4f 01 00 15 04 09 00  |..|lbaLILO......|
 $ qemu-img snapshot -c snap sheepdog:linux
 $ collie vdi read linux 0 512 | hd | head -1
 00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
==

I guess it is because read_object() doesn't read the cached data.

This is a wrong behavior as a block storage because we need to read
the latest data even if it is not flushed, so I hope it would be fixed
too.

Thanks,

Kazutaka


> 
> 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
> 
> -- 
> sheepdog mailing list
> sheepdog at lists.wpkg.org
> http://lists.wpkg.org/mailman/listinfo/sheepdog



More information about the sheepdog mailing list