qemu-img: There is more than one host device driver

I haven't heard yet of anyone using qemu-img to copy an image to a real floppy,
but it's a valid use case.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Kevin Wolf 2009-11-30 16:54:15 +01:00 committed by Anthony Liguori
parent 702ef63f3e
commit 12c09b8ce2
3 changed files with 9 additions and 2 deletions

View File

@ -1014,6 +1014,7 @@ static BlockDriver bdrv_host_device = {
.bdrv_close = raw_close, .bdrv_close = raw_close,
.bdrv_create = hdev_create, .bdrv_create = hdev_create,
.create_options = raw_create_options, .create_options = raw_create_options,
.no_zero_init = 1,
.bdrv_flush = raw_flush, .bdrv_flush = raw_flush,
.bdrv_aio_readv = raw_aio_readv, .bdrv_aio_readv = raw_aio_readv,
@ -1110,6 +1111,7 @@ static BlockDriver bdrv_host_floppy = {
.bdrv_close = raw_close, .bdrv_close = raw_close,
.bdrv_create = hdev_create, .bdrv_create = hdev_create,
.create_options = raw_create_options, .create_options = raw_create_options,
.no_zero_init = 1,
.bdrv_flush = raw_flush, .bdrv_flush = raw_flush,
.bdrv_aio_readv = raw_aio_readv, .bdrv_aio_readv = raw_aio_readv,
@ -1192,6 +1194,7 @@ static BlockDriver bdrv_host_cdrom = {
.bdrv_close = raw_close, .bdrv_close = raw_close,
.bdrv_create = hdev_create, .bdrv_create = hdev_create,
.create_options = raw_create_options, .create_options = raw_create_options,
.no_zero_init = 1,
.bdrv_flush = raw_flush, .bdrv_flush = raw_flush,
.bdrv_aio_readv = raw_aio_readv, .bdrv_aio_readv = raw_aio_readv,
@ -1313,6 +1316,7 @@ static BlockDriver bdrv_host_cdrom = {
.bdrv_close = raw_close, .bdrv_close = raw_close,
.bdrv_create = hdev_create, .bdrv_create = hdev_create,
.create_options = raw_create_options, .create_options = raw_create_options,
.no_zero_init = 1,
.bdrv_flush = raw_flush, .bdrv_flush = raw_flush,
.bdrv_aio_readv = raw_aio_readv, .bdrv_aio_readv = raw_aio_readv,

View File

@ -117,6 +117,9 @@ struct BlockDriver {
/* Returns number of errors in image, -errno for internal errors */ /* Returns number of errors in image, -errno for internal errors */
int (*bdrv_check)(BlockDriverState* bs); int (*bdrv_check)(BlockDriverState* bs);
/* Set if newly created images are not guaranteed to contain only zeros */
int no_zero_init;
struct BlockDriver *next; struct BlockDriver *next;
}; };

View File

@ -743,7 +743,7 @@ static int img_convert(int argc, char **argv)
if (n > bs_offset + bs_sectors - sector_num) if (n > bs_offset + bs_sectors - sector_num)
n = bs_offset + bs_sectors - sector_num; n = bs_offset + bs_sectors - sector_num;
if (strcmp(drv->format_name, "host_device")) { if (!drv->no_zero_init) {
/* If the output image is being created as a copy on write image, /* If the output image is being created as a copy on write image,
assume that sectors which are unallocated in the input image assume that sectors which are unallocated in the input image
are present in both the output's and input's base images (no are present in both the output's and input's base images (no
@ -776,7 +776,7 @@ static int img_convert(int argc, char **argv)
If the output is to a host device, we also write out If the output is to a host device, we also write out
sectors that are entirely 0, since whatever data was sectors that are entirely 0, since whatever data was
already there is garbage, not 0s. */ already there is garbage, not 0s. */
if (strcmp(drv->format_name, "host_device") == 0 || out_baseimg || if (drv->no_zero_init || out_baseimg ||
is_allocated_sectors(buf1, n, &n1)) { is_allocated_sectors(buf1, n, &n1)) {
if (bdrv_write(out_bs, sector_num, buf1, n1) < 0) if (bdrv_write(out_bs, sector_num, buf1, n1) < 0)
error("error while writing"); error("error while writing");