[Sheepdog] [PATCH] live migration support

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Sat Dec 5 18:04:17 CET 2009


vdi lock is delayed until vm starts by this patch, and
it enables sheepdog to migrate successfully.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 block/sheepdog.c |   61 ++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 53 insertions(+), 8 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index ff19436..b61aa26 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1012,12 +1012,7 @@ static int find_vdi_name(struct bdrv_sd_state *s, char *filename, uint64_t tag,
 		return -1;
 
 	memset(&hdr, 0, sizeof(hdr));
-
-	if (for_snapshot)
-		hdr.opcode = SD_OP_GET_VDI_INFO;
-	else
-		hdr.opcode = SD_OP_LOCK_VDI;
-
+	hdr.opcode = SD_OP_GET_VDI_INFO;
 	wlen = strlen(filename) + 1;
 	hdr.data_length = wlen;
 	hdr.tag = tag;
@@ -1467,6 +1462,56 @@ static int sd_create(const char *filename, QEMUOptionParameter *options)
 static void sd_close(BlockDriverState *bs)
 {
 	struct bdrv_sd_state *s = bs->opaque;
+
+	eprintf("%s\n", s->name);
+
+	free(s->name);
+}
+
+static int sd_claim(BlockDriverState *bs)
+{
+	struct bdrv_sd_state *s = bs->opaque;
+	int ret, fd;
+	struct sd_vdi_req hdr;
+	struct sd_vdi_rsp *rsp = (struct sd_vdi_rsp *)&hdr;
+	char hostname[] = "localhost";
+	unsigned int wlen, rlen = 0;
+
+	eprintf("%s\n", s->name);
+
+	fd = connect_to_vost(hostname, DOG_PORT);
+	if (fd < 0)
+		return -1;
+
+	memset(&hdr, 0, sizeof(hdr));
+	hdr.opcode = SD_OP_LOCK_VDI;
+	wlen = strlen(s->name) + 1;
+	hdr.data_length = wlen;
+	hdr.tag = -1;
+	hdr.flags = SD_FLAG_CMD_WRITE;
+	hdr.epoch = s_epoch;
+
+	ret = do_req(fd, (struct sd_req *)&hdr, s->name, &wlen, &rlen);
+	if (ret) {
+		ret = -1;
+		goto out;
+	}
+
+	if (rsp->result != SD_RES_SUCCESS) {
+		eprintf("%s, %s\n", sd_strerror(rsp->result), s->name);
+		ret = -1;
+		goto out;
+	}
+
+	ret = 0;
+out:
+	close(fd);
+	return ret;
+}
+
+static void sd_release(BlockDriverState *bs)
+{
+	struct bdrv_sd_state *s = bs->opaque;
 	struct sd_vdi_req hdr;
 	struct sd_vdi_rsp *rsp = (struct sd_vdi_rsp *)&hdr;
 	char hostname[] = "localhost";
@@ -1493,8 +1538,6 @@ static void sd_close(BlockDriverState *bs)
 
 	if (!ret && rsp->result != SD_RES_SUCCESS)
 		eprintf("%s, %s\n", sd_strerror(rsp->result), s->name);
-
-	free(s->name);
 }
 
 static inline int nr_chunks(struct sd_aiocb *acb)
@@ -1941,6 +1984,8 @@ BlockDriver bdrv_sheepdog = {
 	.bdrv_open = sd_open,
 	.bdrv_close = sd_close,
 	.bdrv_create = sd_create,
+	.bdrv_claim = sd_claim,
+	.bdrv_release = sd_release,
 
 	.bdrv_aio_readv = sd_aio_readv,
 	.bdrv_aio_writev = sd_aio_writev,
-- 
1.5.6.5




More information about the sheepdog mailing list