[sheepdog] [PATCH 2/3] collie: add flush command for vdi

Liu Yuan namei.unix at gmail.com
Tue Aug 14 10:20:10 CEST 2012


From: Liu Yuan <tailai.ly at taobao.com>

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 collie/vdi.c         |   28 ++++++++++++++++++++++++++++
 sheep/object_cache.c |    4 +++-
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/collie/vdi.c b/collie/vdi.c
index 2fff634..5781e75 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -1481,6 +1481,32 @@ out:
 	return ret;
 }
 
+static int vdi_flush(int argc, char **argv)
+{
+	char *vdiname = argv[optind++];
+	struct sd_req hdr;
+	uint32_t vid;
+	int ret = EXIT_SUCCESS;
+
+	ret = find_vdi_name(vdiname, 0, "", &vid, 0);
+	if (ret < 0) {
+		fprintf(stderr, "Failed to open VDI %s\n", vdiname);
+		ret = EXIT_FAILURE;
+		goto out;
+	}
+
+	sd_init_req(&hdr, SD_OP_FLUSH_VDI);
+	hdr.obj.oid = vid_to_vdi_oid(vid);
+
+	ret = send_light_req(&hdr, sdhost, sdport);
+	if (ret) {
+		fprintf(stderr, "failed to execute request\n");
+		return EXIT_FAILURE;
+	}
+out:
+	return ret;
+}
+
 static struct subcommand vdi_cmd[] = {
 	{"check", "<vdiname>", "saph", "check and repair image's consistency",
 	 NULL, SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_THIRD_ARG, vdi_check},
@@ -1512,6 +1538,8 @@ static struct subcommand vdi_cmd[] = {
 	 NULL, SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_THIRD_ARG, vdi_read},
 	{"write", "<vdiname> [<offset> [<len>]]", "apCh", "write data to an image",
 	 NULL, SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_THIRD_ARG, vdi_write},
+	{"flush", "<vdiname>", "aph", "flush data to cluster",
+	 NULL, SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_THIRD_ARG, vdi_flush},
 	{NULL,},
 };
 
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index f0210c0..d3fada3 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -1124,8 +1124,10 @@ int object_cache_flush_vdi(struct request *req)
 	struct object_cache *cache;
 
 	cache = find_object_cache(vid, 0);
-	if (!cache)
+	if (!cache) {
+		dprintf("%"PRIX32" not found\n", vid);
 		return SD_RES_SUCCESS;
+	}
 
 	return object_cache_push(cache);
 }
-- 
1.7.10.2




More information about the sheepdog mailing list