Skip to content

Commit

Permalink
block: Fix bdrv_has_zero_init
Browse files Browse the repository at this point in the history
Assuming that any image on a block device is not properly zero-initialized is
actually wrong: Only raw images have this problem. Any other image format
shouldn't care about it, they initialize everything properly themselves.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
kevmw committed Aug 3, 2010
1 parent bd0858b commit 336c1c1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
6 changes: 2 additions & 4 deletions block.c
Expand Up @@ -1477,10 +1477,8 @@ int bdrv_has_zero_init(BlockDriverState *bs)
{
assert(bs->drv);

if (bs->drv->no_zero_init) {
return 0;
} else if (bs->file) {
return bdrv_has_zero_init(bs->file);
if (bs->drv->bdrv_has_zero_init) {
return bs->drv->bdrv_has_zero_init(bs);
}

return 1;
Expand Down
13 changes: 9 additions & 4 deletions block/raw-posix.c
Expand Up @@ -993,6 +993,11 @@ static int hdev_create(const char *filename, QEMUOptionParameter *options)
return ret;
}

static int hdev_has_zero_init(BlockDriverState *bs)
{
return 0;
}

static BlockDriver bdrv_host_device = {
.format_name = "host_device",
.protocol_name = "host_device",
Expand All @@ -1002,7 +1007,7 @@ static BlockDriver bdrv_host_device = {
.bdrv_close = raw_close,
.bdrv_create = hdev_create,
.create_options = raw_create_options,
.no_zero_init = 1,
.bdrv_has_zero_init = hdev_has_zero_init,
.bdrv_flush = raw_flush,

.bdrv_aio_readv = raw_aio_readv,
Expand Down Expand Up @@ -1117,7 +1122,7 @@ static BlockDriver bdrv_host_floppy = {
.bdrv_close = raw_close,
.bdrv_create = hdev_create,
.create_options = raw_create_options,
.no_zero_init = 1,
.bdrv_has_zero_init = hdev_has_zero_init,
.bdrv_flush = raw_flush,

.bdrv_aio_readv = raw_aio_readv,
Expand Down Expand Up @@ -1217,7 +1222,7 @@ static BlockDriver bdrv_host_cdrom = {
.bdrv_close = raw_close,
.bdrv_create = hdev_create,
.create_options = raw_create_options,
.no_zero_init = 1,
.bdrv_has_zero_init = hdev_has_zero_init,
.bdrv_flush = raw_flush,

.bdrv_aio_readv = raw_aio_readv,
Expand Down Expand Up @@ -1340,7 +1345,7 @@ static BlockDriver bdrv_host_cdrom = {
.bdrv_close = raw_close,
.bdrv_create = hdev_create,
.create_options = raw_create_options,
.no_zero_init = 1,
.bdrv_has_zero_init = hdev_has_zero_init,
.bdrv_flush = raw_flush,

.bdrv_aio_readv = raw_aio_readv,
Expand Down
6 changes: 6 additions & 0 deletions block/raw-win32.c
Expand Up @@ -394,6 +394,11 @@ static int raw_set_locked(BlockDriverState *bs, int locked)
}
#endif

static int hdev_has_zero_init(BlockDriverState *bs)
{
return 0;
}

static BlockDriver bdrv_host_device = {
.format_name = "host_device",
.protocol_name = "host_device",
Expand All @@ -402,6 +407,7 @@ static BlockDriver bdrv_host_device = {
.bdrv_file_open = hdev_open,
.bdrv_close = raw_close,
.bdrv_flush = raw_flush,
.bdrv_has_zero_init = hdev_has_zero_init,

.bdrv_read = raw_read,
.bdrv_write = raw_write,
Expand Down
6 changes: 6 additions & 0 deletions block/raw.c
Expand Up @@ -237,6 +237,11 @@ static QEMUOptionParameter raw_create_options[] = {
{ NULL }
};

static int raw_has_zero_init(BlockDriverState *bs)
{
return bdrv_has_zero_init(bs->file);
}

static BlockDriver bdrv_raw = {
.format_name = "raw",

Expand Down Expand Up @@ -264,6 +269,7 @@ static BlockDriver bdrv_raw = {

.bdrv_create = raw_create,
.create_options = raw_create_options,
.bdrv_has_zero_init = raw_has_zero_init,
};

static void bdrv_raw_init(void)
Expand Down
7 changes: 5 additions & 2 deletions block_int.h
Expand Up @@ -127,8 +127,11 @@ struct BlockDriver {

void (*bdrv_debug_event)(BlockDriverState *bs, BlkDebugEvent event);

/* Set if newly created images are not guaranteed to contain only zeros */
int no_zero_init;
/*
* Returns 1 if newly created images are guaranteed to contain only
* zeros, 0 otherwise.
*/
int (*bdrv_has_zero_init)(BlockDriverState *bs);

QLIST_ENTRY(BlockDriver) list;
};
Expand Down

0 comments on commit 336c1c1

Please sign in to comment.