From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LNYFU-0005xc-CA for qemu-devel@nongnu.org; Thu, 15 Jan 2009 14:51:28 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LNYFT-0005xP-QP for qemu-devel@nongnu.org; Thu, 15 Jan 2009 14:51:28 -0500 Received: from [199.232.76.173] (port=47839 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LNYFT-0005xL-IH for qemu-devel@nongnu.org; Thu, 15 Jan 2009 14:51:27 -0500 Received: from mail-qy0-f20.google.com ([209.85.221.20]:44606) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LNYFT-0007d6-0x for qemu-devel@nongnu.org; Thu, 15 Jan 2009 14:51:27 -0500 Received: by qyk13 with SMTP id 13so1884486qyk.10 for ; Thu, 15 Jan 2009 11:51:25 -0800 (PST) Message-ID: <496F93B1.5090001@codemonkey.ws> Date: Thu, 15 Jan 2009 13:51:13 -0600 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] qemu-img: adding a "-F base_fmt" option to "qemu-img create -b" References: <1231677493-30924-1-git-send-email-uril@redhat.com> In-Reply-To: <1231677493-30924-1-git-send-email-uril@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Uri Lublin uril@redhat.com wrote: > From: Uri Lublin > > 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 fmt:FMT: prefix for backing > filename. > But how does this work in the absence of supporting fmt:FMT? Does this imply that the other patch is needed too? Regards, Anthony Liguori > Suggested by Daniel P. Berrange. > > Signed-off-by: Uri Lublin > --- > qemu-img.c | 31 ++++++++++++++++++++++++++++--- > qemu-img.texi | 4 +++- > 2 files changed, 31 insertions(+), 4 deletions(-) > > diff --git a/qemu-img.c b/qemu-img.c > index 964b28b..02c513f 100644 > --- a/qemu-img.c > +++ b/qemu-img.c > @@ -25,6 +25,7 @@ > #include "osdep.h" > #include "block_int.h" > #include > +#include > > #ifdef _WIN32 > #define WIN32_LEAN_AND_MEAN > @@ -57,7 +58,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" > @@ -215,21 +216,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; > @@ -250,7 +256,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); > @@ -281,8 +295,19 @@ 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 && base_fmt) { > + int len; > + len = snprintf(filename_buff, sizeof(filename_buff), "fmt:%s:%s", > + base_fmt, base_filename); > + if (len < 0) > + error("internal failure: snprintf failed"); > + 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 1c0504b..eaeaf07 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} > @@ -26,6 +26,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: > >