[Sheepdog] [PATCH 2/5] add a tag option to drive arguments

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Sat Jan 9 15:03:32 CET 2010


You can boot a VM from a snapshot image by the following command:

$ qemu-system-x86_64 --drive format=sheepdog,file=[vdiname],tag=[tag]

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 block.c          |    5 +++++
 block.h          |    1 +
 block/sheepdog.c |    4 ++++
 block_int.h      |    1 +
 qemu-config.c    |    4 ++++
 qemu-options.hx  |    2 +-
 vl.c             |    6 ++++++
 7 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/block.c b/block.c
index aea1fca..c7bb7c2 100644
--- a/block.c
+++ b/block.c
@@ -1438,6 +1438,11 @@ int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
     return drv->bdrv_get_info(bs, bdi);
 }
 
+void bdrv_set_tag(BlockDriverState *bs, const char *tag)
+{
+    pstrcpy(bs->tag, sizeof(bs->tag), tag);
+}
+
 int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf,
                       int64_t pos, int size)
 {
diff --git a/block.h b/block.h
index be6dffe..754a1ee 100644
--- a/block.h
+++ b/block.h
@@ -175,6 +175,7 @@ const char *bdrv_get_device_name(BlockDriverState *bs);
 int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
                           const uint8_t *buf, int nb_sectors);
 int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi);
+void bdrv_set_tag(BlockDriverState *bs, const char *tag);
 
 const char *bdrv_get_encrypted_filename(BlockDriverState *bs);
 void bdrv_get_backing_filename(BlockDriverState *bs,
diff --git a/block/sheepdog.c b/block/sheepdog.c
index 11f50c3..ad3a759 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1344,6 +1344,10 @@ static int sd_open(BlockDriverState *bs, const char *filename, int flags)
 	if (parse_vdiname(filename, vdi, sizeof(vdi), &tag) < 0)
 		goto out;
 
+	tag = strtoull(bs->tag, NULL, 16);
+	if (tag == 0)
+		tag = -1; /* search current vdi */
+
 	ret = find_vdi_name(s, vdi, tag, &oid, for_snapshot, &s->is_current, &epoch);
 	if (ret)
 		goto out;
diff --git a/block_int.h b/block_int.h
index 23db561..ac0e1d4 100644
--- a/block_int.h
+++ b/block_int.h
@@ -142,6 +142,7 @@ struct BlockDriverState {
     void *opaque;
 
     char filename[1024];
+    char tag[1024];
     char backing_file[1024]; /* if non zero, the image is a diff of
                                 this file image */
     char backing_format[16]; /* if non-zero and backing_file exists */
diff --git a/qemu-config.c b/qemu-config.c
index 2caf76c..a9a2888 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -82,6 +82,10 @@ QemuOptsList qemu_drive_opts = {
             .name = "boot",
             .type = QEMU_OPT_BOOL,
             .help = "make this a boot drive",
+        },{
+            .name = "tag",
+            .type = QEMU_OPT_STRING,
+            .help = "tag name of this disk image",
         },
         { /* end if list */ }
     },
diff --git a/qemu-options.hx b/qemu-options.hx
index 812d067..07cc0ce 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -104,7 +104,7 @@ DEF("drive", HAS_ARG, QEMU_OPTION_drive,
     "       [,cyls=c,heads=h,secs=s[,trans=t]][,snapshot=on|off]\n"
     "       [,cache=writethrough|writeback|none][,format=f][,serial=s]\n"
     "       [,addr=A][,id=name][,aio=threads|native]\n"
-    "       [,boot=on|off]\n"
+    "       [,boot=on|off][,tag=t]\n"
     "                use 'file' as a drive image\n")
 DEF("set", HAS_ARG, QEMU_OPTION_set,
     "-set group.id.arg=value\n"
diff --git a/vl.c b/vl.c
index 725285c..fe7212c 100644
--- a/vl.c
+++ b/vl.c
@@ -2125,6 +2125,7 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,
     DriveInfo *dinfo;
     int is_extboot = 0;
     int snapshot = 0;
+    const char *tag;
 
     *fatal_error = 1;
 
@@ -2321,6 +2322,8 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,
         }
     }
 
+    tag = qemu_opt_get(opts, "tag");
+
     /* compute bus and unit according index */
 
     if (index != -1) {
@@ -2468,6 +2471,9 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,
         (void)bdrv_set_read_only(dinfo->bdrv, 1);
     }
 
+    if (tag)
+	    bdrv_set_tag(dinfo->bdrv, tag);
+
     if (bdrv_open2(dinfo->bdrv, file, bdrv_flags, drv) < 0) {
         fprintf(stderr, "qemu: could not open disk image %s: %s\n",
                         file, strerror(errno));
-- 
1.5.6.5




More information about the sheepdog mailing list