The tag number of images created from `qemu-img create` must be zero
but it is confusing. This patch introduces SD_FLAG_CMD_CREATE_VDI and
resolves the problem.

Signed-off-by: MORITA Kazutaka <[email protected]>
---
 block/sheepdog.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 87ea011..11f50c3 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -49,6 +49,7 @@
 
 #define SD_FLAG_CMD_WRITE    0x01
 #define SD_FLAG_CMD_COW      0x02
+#define SD_FLAG_CMD_CREATE_VDI  0x08
 
 #define SD_RES_SUCCESS       0x00 /* Success */
 #define SD_RES_UNKNOWN       0x01 /* Unknown error */
@@ -1377,7 +1378,8 @@ 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)
+                       uint64_t base_oid, uint64_t *oid, uint64_t tag,
+                       int create)
 {
        struct sd_vdi_req hdr;
        struct sd_vdi_rsp *rsp = (struct sd_vdi_rsp *)&hdr;
@@ -1396,6 +1398,8 @@ static int do_sd_create(char *filename, int64_t 
total_sectors,
 
        wlen = strlen(filename) + 1;
        hdr.flags = SD_FLAG_CMD_WRITE;
+       if (create)
+               hdr.flags |= SD_FLAG_CMD_CREATE_VDI;
        hdr.data_length = wlen;
        hdr.vdi_size = total_sectors * 512;
        hdr.tag = tag;
@@ -1424,6 +1428,7 @@ static int sd_create(const char *filename, 
QEMUOptionParameter *options)
        uint64_t oid = 0;
        int64_t total_sectors = 0;
        char *backing_file = NULL;
+       struct timeval tv;
 
        while (options && options->name) {
                if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
@@ -1468,7 +1473,9 @@ static int sd_create(const char *filename, 
QEMUOptionParameter *options)
                        return -1;
        }
 
-       return do_sd_create((char *)filename, total_sectors, oid, NULL, 0);
+       gettimeofday(&tv, NULL);
+       return do_sd_create((char *)filename, total_sectors, oid, NULL,
+                           tv.tv_sec, 1);
 }
 
 static void sd_close(BlockDriverState *bs)
@@ -1625,7 +1632,7 @@ static int sd_create_branch(struct bdrv_sd_state *s)
 
        gettimeofday(&tv, NULL);
        ret = do_sd_create(s->name, s->inode.vdi_size >> 9,
-                          s->inode.oid, &oid, tv.tv_sec);
+                          s->inode.oid, &oid, tv.tv_sec, 0);
        if (ret)
                goto out;
 
@@ -1970,7 +1977,7 @@ 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);
+                          s->inode.oid, NULL, tv.tv_sec, 0);
 
        return ret;
 }
-- 
1.5.6.5

-- 
sheepdog mailing list
[email protected]
http://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to