[Sheepdog] [PATCH 4/5] support snapshot tag string

FUJITA Tomonori fujita.tomonori at lab.ntt.co.jp
Tue Jan 26 05:32:09 CET 2010


fujita at rose:~/git/qemu-kvm$ qemu-img snapshot -c test3 sheepdog:linux

fujita at rose:~/git/qemu-kvm$ qemu-img snapshot -l sheepdog:linux
Snapshot list:
ID        TAG                 VM SIZE                DATE       VMCLOCK
1         test1                     0 2010-01-19 00:09:39   00:00:00.000
2         test2                     0 2010-01-19 00:10:34   00:00:00.000
3         test3                     0 2010-01-19 00:10:43   00:00:00.000

Signed-off-by: FUJITA Tomonori <fujita.tomonori at lab.ntt.co.jp>
---
 block/sheepdog.c |   37 ++++++++++++++++++++-----------------
 1 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index a564738..e353756 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1241,34 +1241,41 @@ out:
 
 #define CHUNK_SIZE (1ULL << 22)
 
-static int do_sd_create(char *filename, int64_t total_sectors,
-			uint64_t base_oid, uint64_t *oid, uint64_t tag,
-			int snapshot)
+static int do_sd_create(char *filename, char *tag, int64_t total_sectors,
+			uint64_t base_oid, uint64_t *oid, int snapshot)
 {
 	struct sd_vdi_req hdr;
 	struct sd_vdi_rsp *rsp = (struct sd_vdi_rsp *)&hdr;
 	int fd, ret;
 	char hostname[] = "localhost";
 	unsigned int wlen, rlen = 0;
+	char buf[SD_MAX_VDI_LEN * 2];
 
 	fd = connect_to_vost(hostname, DOG_PORT);
 	if (fd < 0)
 		return -1;
 
+	memset(buf, 0, sizeof(buf));
+	strncpy(buf, filename, SD_MAX_VDI_LEN);
+	if (tag)
+		strncpy(buf + SD_MAX_VDI_LEN, tag, SD_MAX_VDI_LEN);
+
 	memset(&hdr, 0, sizeof(hdr));
 	hdr.opcode = SD_OP_NEW_VDI;
 	hdr.epoch = s_epoch;
 	hdr.base_oid = base_oid;
 
-	wlen = strlen(filename) + 1;
+	wlen = SD_MAX_VDI_LEN;
+	if (tag)
+		wlen += SD_MAX_VDI_LEN;
+
 	hdr.flags = SD_FLAG_CMD_WRITE;
 	if (snapshot)
 		hdr.flags |= SD_FLAG_CMD_SNAPSHOT;
 	hdr.data_length = wlen;
 	hdr.vdi_size = total_sectors * 512;
-	hdr.tag = tag;
 
-	ret = do_req(fd, (struct sd_req *)&hdr, filename, &wlen, &rlen);
+	ret = do_req(fd, (struct sd_req *)&hdr, buf, &wlen, &rlen);
 
 	close(fd);
 
@@ -1336,7 +1343,7 @@ static int sd_create(const char *filename, QEMUOptionParameter *options)
 			return -1;
 	}
 
-	return do_sd_create((char *)filename, total_sectors, oid, NULL, 0, 0);
+	return do_sd_create((char *)filename, NULL, total_sectors, oid, NULL, 0);
 }
 
 static void sd_close(BlockDriverState *bs)
@@ -1464,7 +1471,6 @@ new_node_list:
 
 static int sd_create_branch(struct bdrv_sd_state *s)
 {
-	struct timeval tv;
 	int ret, copies;
 	uint64_t oid;
 	char *buf;
@@ -1475,9 +1481,8 @@ static int sd_create_branch(struct bdrv_sd_state *s)
 	if (!buf)
 		return -1;
 
-	gettimeofday(&tv, NULL);
-	ret = do_sd_create(s->name, s->inode.vdi_size >> 9,
-			   s->inode.oid, &oid, tv.tv_sec, 0);
+	ret = do_sd_create(s->name, NULL, s->inode.vdi_size >> 9,
+			   s->inode.oid, &oid, 0);
 	if (ret)
 		goto out;
 
@@ -1717,11 +1722,8 @@ static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
 {
 	struct bdrv_sd_state *s = bs->opaque;
 	int ret;
-	struct timeval tv;
-
-	gettimeofday(&tv, NULL);
 
-	dprintf("%s %s %s %d %d\n", sn_info->name, sn_info->id_str,
+	eprintf("%s %s %s %d %d\n", sn_info->name, sn_info->id_str,
 		s->name, sn_info->vm_state_size, s->is_current);
 
 	if (!s->is_current) {
@@ -1734,8 +1736,8 @@ static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
 
 	dprintf("%s %s\n", sn_info->name, sn_info->id_str);
 
-	ret = do_sd_create(s->name, s->inode.vdi_size >> 9,
-			   s->inode.oid, NULL, tv.tv_sec, 1);
+	ret = do_sd_create(s->name, sn_info->name, s->inode.vdi_size >> 9,
+			   s->inode.oid, NULL, 1);
 
 	return ret;
 }
@@ -1849,6 +1851,7 @@ static int sd_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
 
 		snprintf(sn_tab[found].id_str, sizeof(sn_tab[found].id_str), "%u",
 			vi[i].id);
+		strncpy(sn_tab[found].name, vi[i].tag,  sizeof(sn_tab[found].name));
 		found++;
 	}
 out:
-- 
1.5.6.5




More information about the sheepdog mailing list