From 6e31ee3c1323d3a28aff15559fe472287b1ae89c Mon Sep 17 00:00:00 2001 From: Kevin Wolf <kwolf@redhat.com> Date: Wed, 13 Jan 2010 17:38:06 -0200 Subject: [PATCH 5/5] qemu-img: Automatically detect block devices RH-Author: Kevin Wolf <kwolf@redhat.com> Message-id: <1263404286-10561-1-git-send-email-kwolf@redhat.com> Patchwork-id: 6340 O-Subject: [PATCH] qemu-img: Automatically detect block devices Bugzilla: 537655 RH-Acked-by: Juan Quintela <quintela@redhat.com> RH-Acked-by: Markus Armbruster <armbru@redhat.com> RH-Acked-by: Gleb Natapov <gleb@redhat.com> Bugzilla: 537655 Upstream status: Will be solved differently Currently you can't use qemu-img create to "create" raw images on a host device. However, RHEV-M relies in being able to do so. This patch changes qemu-img to retry with 'host_device' if creating with 'raw' has failed. Signed-off-by: Kevin Wolf <kwolf@redhat.com> --- This patch replaces "block-raw-posix: Automatically detect host devices" qemu/qemu-img.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- qemu/qemu-img.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/qemu/qemu-img.c b/qemu/qemu-img.c index 0e54a10..c2d4f72 100644 --- a/qemu/qemu-img.c +++ b/qemu/qemu-img.c @@ -305,6 +305,12 @@ static int img_create(int argc, char **argv) } printf(", size=%" PRIu64 " kB\n", size / 1024); ret = bdrv_create2(drv, filename, size / 512, base_filename, base_fmt, flags); + if (ret < 0 && drv == &bdrv_raw) { + drv = &bdrv_host_device; + fmt = "host_device"; + ret = bdrv_create2(drv, filename, size / 512, base_filename, base_fmt, flags); + } + if (ret < 0) { if (ret == -ENOTSUP) { error("Formatting or formatting option not supported for file format '%s'", fmt); @@ -583,6 +589,12 @@ static int img_convert(int argc, char **argv) error("Compression and encryption not supported at the same time"); ret = bdrv_create(drv, out_filename, total_sectors, out_baseimg, flags); + if (ret < 0 && drv == &bdrv_raw) { + drv = &bdrv_host_device; + out_fmt = "host_device"; + ret = bdrv_create(drv, out_filename, total_sectors, out_baseimg, flags); + } + if (ret < 0) { if (ret == -ENOTSUP) { error("Formatting not supported for file format '%s'", out_fmt); -- 1.6.3.rc4.29.g8146