qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Uri Lublin <uril@redhat.com>
To: qemu-devel@nongnu.org
Cc: Uri Lublin <uril@redhat.com>
Subject: [Qemu-devel] [PATCH 2/2] qemu-img: adding a "-F base_fmt" option to "qemu-img create -b"
Date: Mon, 26 Jan 2009 20:39:59 +0200	[thread overview]
Message-ID: <1232995199-12086-4-git-send-email-uril@redhat.com> (raw)
In-Reply-To: <1232995199-12086-3-git-send-email-uril@redhat.com>

If the user specifies the backing file format,
then when opening the backing file, there is no need
to probe the (backing file) image to figure out its format.

This follows my previous patch implementing hidden image format
within the backing file name.

Suggested by Daniel P. Berrange.

Signed-off-by: Uri Lublin <uril@redhat.com>
---
 qemu-img.c    |   33 ++++++++++++++++++++++++++++++---
 qemu-img.texi |    4 +++-
 2 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 6b852fb..29e5f45 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -25,6 +25,7 @@
 #include "osdep.h"
 #include "block_int.h"
 #include <assert.h>
+#include <stdio.h>
 
 #ifdef _WIN32
 #define WIN32_LEAN_AND_MEAN
@@ -58,7 +59,7 @@ static void help(void)
            "QEMU disk image utility\n"
            "\n"
            "Command syntax:\n"
-           "  create [-e] [-6] [-b base_image] [-f fmt] filename [size]\n"
+           "  create [-e] [-6] [-F fmt] [-b base_image] [-f fmt] filename [size]\n"
            "  commit [-f fmt] filename\n"
            "  convert [-c] [-e] [-6] [-f fmt] [-O output_fmt] [-B output_base_image] filename [filename2 [...]] output_filename\n"
            "  info [-f fmt] filename\n"
@@ -218,21 +219,26 @@ static int img_create(int argc, char **argv)
 {
     int c, ret, flags;
     const char *fmt = "raw";
+    const char *base_fmt = NULL;
     const char *filename;
     const char *base_filename = NULL;
     uint64_t size;
     const char *p;
     BlockDriver *drv;
+    char filename_buff[1024];
 
     flags = 0;
     for(;;) {
-        c = getopt(argc, argv, "b:f:he6");
+        c = getopt(argc, argv, "F:b:f:he6");
         if (c == -1)
             break;
         switch(c) {
         case 'h':
             help();
             break;
+        case 'F':
+            base_fmt = optarg;
+            break;
         case 'b':
             base_filename = optarg;
             break;
@@ -253,7 +259,15 @@ static int img_create(int argc, char **argv)
     size = 0;
     if (base_filename) {
         BlockDriverState *bs;
-        bs = bdrv_new_open(base_filename, NULL);
+        BlockDriver *base_drv = NULL;
+        
+        if (base_fmt) {
+            base_drv = bdrv_find_format(base_fmt);
+            if (base_drv == NULL)
+                error("Unknown basefile format '%s'", base_fmt);
+        }
+        
+        bs = bdrv_new_open(base_filename, base_fmt);
         bdrv_get_geometry(bs, &size);
         size *= 512;
         bdrv_delete(bs);
@@ -284,8 +298,21 @@ static int img_create(int argc, char **argv)
     if (base_filename) {
         printf(", backing_file=%s",
                base_filename);
+        if (base_fmt)
+            printf(", backing_fmt=%s",
+                   base_fmt);
     }
     printf(", size=%" PRIu64 " kB\n", size / 1024);
+    if (base_filename) {
+        memset(filename_buff, 0, sizeof(filename_buff));
+        pstrcpy(filename_buff, sizeof(filename_buff), base_filename);
+        if (base_fmt) {
+            int len;
+            len = strlen(filename_buff);
+            pstrcat(filename_buff + len + 1, sizeof(filename_buff) - (len + 1), base_fmt);
+        }
+        base_filename = filename_buff;
+    }
     ret = bdrv_create(drv, filename, size / 512, base_filename, flags);
     if (ret < 0) {
         if (ret == -ENOTSUP) {
diff --git a/qemu-img.texi b/qemu-img.texi
index a40f841..deef2ab 100644
--- a/qemu-img.texi
+++ b/qemu-img.texi
@@ -8,7 +8,7 @@ usage: qemu-img command [command options]
 
 The following commands are supported:
 @table @option
-@item create [-e] [-6] [-b @var{base_image}] [-f @var{fmt}] @var{filename} [@var{size}]
+@item create [-e] [-6] [-F @var{base_fmt}] [-b @var{base_image}] [-f @var{fmt}] @var{filename} [@var{size}]
 @item commit [-f @var{fmt}] @var{filename}
 @item convert [-c] [-e] [-6] [-f @var{fmt}] [-O @var{output_fmt}] [-B @var{output_base_image}] @var{filename} [@var{filename2} [...]] @var{output_filename}
 @item info [-f @var{fmt}] @var{filename}
@@ -27,6 +27,8 @@ forces the output image to be created as a copy on write
 image of the specified base image; @code{output_base_image} should have the same
 content as the input's base image, however the path, image format, etc may
 differ
+@item base_fmt
+is the disk image format of @var{base_image}. for more information look at @var{fmt}
 @item fmt
 is the disk image format. It is guessed automatically in most cases. The following formats are supported:
 
-- 
1.6.0.6

  reply	other threads:[~2009-01-26 18:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-26 18:39 [Qemu-devel] [PATCH 0/2] qemu block changes: keep backing file format v2 Uri Lublin
2009-01-26 18:39 ` [Qemu-devel] [PATCH 1/2] Introducing hidden image format in backing file name Uri Lublin
2009-01-26 18:39   ` Uri Lublin
2009-01-26 18:39     ` Uri Lublin [this message]
2009-01-26 21:56 ` [Qemu-devel] [PATCH 0/2] qemu block changes: keep backing file format v2 Jamie Lokier
2009-01-27 13:23   ` Uri Lublin
2009-01-27 21:46     ` Anthony Liguori
2009-01-27 23:11       ` Uri Lublin
  -- strict thread matches above, loose matches on Subject: below --
2009-02-04 16:08 [Qemu-devel] [PATCH For Review 0/2] qemu block changes: keep backing file format v3 Uri Lublin
2009-02-04 16:08 ` Uri Lublin
2009-02-04 16:08   ` [Qemu-devel] [PATCH 1/2] Introducing qcow2 extensions + keep backing file format Uri Lublin
2009-02-04 16:08     ` [Qemu-devel] [PATCH 2/2] qemu-img: adding a "-F base_fmt" option to "qemu-img create -b" Uri Lublin
2009-03-03 14:33 [Qemu-devel] [PATCH 0/2] Introducing qcow2 extensions + keep backing file format Uri Lublin
2009-03-03 14:33 ` [Qemu-devel] [PATCH 1/2] " Uri Lublin
2009-03-03 14:33   ` [Qemu-devel] [PATCH 2/2] qemu-img: adding a "-F base_fmt" option to "qemu-img create -b" Uri Lublin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1232995199-12086-4-git-send-email-uril@redhat.com \
    --to=uril@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).