[Sheepdog] [PATCH] sheepdog: implement SD_OP_FLUSH_VDI operation

Liu Yuan namei.unix at gmail.com
Sun Mar 11 13:41:26 CET 2012


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

With this operation implemented, Guest can assure the data that
reach the sheepdog cluster storage by sending flush request.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
Hi Kazum, when you finish the review of this patch, I will send it to
qemu community.

 block/sheepdog.c |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 00276f6f..5e58d70 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -32,6 +32,7 @@
 #define SD_OP_RELEASE_VDI    0x13
 #define SD_OP_GET_VDI_INFO   0x14
 #define SD_OP_READ_VDIS      0x15
+#define SD_OP_FLUSH_VDI      0x16
 
 #define SD_FLAG_CMD_WRITE    0x01
 #define SD_FLAG_CMD_COW      0x02
@@ -1575,6 +1576,39 @@ static coroutine_fn int sd_co_readv(BlockDriverState *bs, int64_t sector_num,
     return acb->ret;
 }
 
+static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs)
+{
+	BDRVSheepdogState *s = bs->opaque;
+	SheepdogObjReq hdr = { 0 };
+	SheepdogObjRsp *rsp = (SheepdogObjRsp *)&hdr;
+	SheepdogInode *inode = &s->inode;
+	int fd, ret;
+	unsigned int wlen = 0, rlen = 0;
+
+	fd = connect_to_sdog(s->addr, s->port);
+	if (fd < 0) {
+		return -1;
+	}
+
+	hdr.opcode = SD_OP_FLUSH_VDI;
+	hdr.oid = vid_to_vdi_oid(inode->vdi_id);
+
+	ret = do_req(fd, (SheepdogReq *)&hdr, NULL, &wlen, &rlen);
+	closesocket(fd);
+	if (ret) {
+		error_report("failed to send a request to the sheep");
+		return -1;
+	}
+
+	switch (rsp->result) {
+		case SD_RES_SUCCESS:
+			return 0;
+		default:
+			error_report("%s", sd_strerror(rsp->result));
+			return -1;
+	}
+}
+
 static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
 {
     BDRVSheepdogState *s = bs->opaque;
@@ -1904,6 +1938,7 @@ BlockDriver bdrv_sheepdog = {
 
     .bdrv_co_readv  = sd_co_readv,
     .bdrv_co_writev = sd_co_writev,
+    .bdrv_co_flush_to_disk  = sd_co_flush_to_disk,
 
     .bdrv_snapshot_create   = sd_snapshot_create,
     .bdrv_snapshot_goto     = sd_snapshot_goto,
-- 
1.7.8.2




More information about the sheepdog mailing list