diff options
author | Max Reitz <mreitz@redhat.com> | 2018-03-12 17:55:28 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2018-03-19 12:01:39 +0100 |
commit | e38105748f09d6285df54b64f4ca13bd60613e72 (patch) | |
tree | 59d7b3b3d82c6809ea100cb90cefff10d466df6c /block/vdi.c | |
parent | ec73f060713db09623e6d9147b0229df70384dd0 (diff) |
vdi: Implement .bdrv_co_create
Signed-off-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/vdi.c')
-rw-r--r-- | block/vdi.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/block/vdi.c b/block/vdi.c index 2a39b0ac98..8132e3adfe 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -721,9 +721,10 @@ nonallocating_write: return ret; } -static int coroutine_fn vdi_co_do_create(BlockdevCreateOptionsVdi *vdi_opts, +static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_options, size_t block_size, Error **errp) { + BlockdevCreateOptionsVdi *vdi_opts; int ret = 0; uint64_t bytes = 0; uint32_t blocks; @@ -736,6 +737,9 @@ static int coroutine_fn vdi_co_do_create(BlockdevCreateOptionsVdi *vdi_opts, BlockBackend *blk = NULL; uint32_t *bmap = NULL; + assert(create_options->driver == BLOCKDEV_DRIVER_VDI); + vdi_opts = &create_options->u.vdi; + logout("\n"); /* Read out options. */ @@ -856,11 +860,17 @@ exit: return ret; } +static int coroutine_fn vdi_co_create(BlockdevCreateOptions *create_options, + Error **errp) +{ + return vdi_co_do_create(create_options, DEFAULT_CLUSTER_SIZE, errp); +} + static int coroutine_fn vdi_co_create_opts(const char *filename, QemuOpts *opts, Error **errp) { QDict *qdict = NULL; - BlockdevCreateOptionsVdi *create_options = NULL; + BlockdevCreateOptions *create_options = NULL; BlockDriverState *bs_file = NULL; uint64_t block_size = DEFAULT_CLUSTER_SIZE; Visitor *v; @@ -897,11 +907,12 @@ static int coroutine_fn vdi_co_create_opts(const char *filename, QemuOpts *opts, goto done; } + qdict_put_str(qdict, "driver", "vdi"); qdict_put_str(qdict, "file", bs_file->node_name); /* Get the QAPI object */ v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); - visit_type_BlockdevCreateOptionsVdi(v, NULL, &create_options, &local_err); + visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); visit_free(v); if (local_err) { @@ -910,12 +921,14 @@ static int coroutine_fn vdi_co_create_opts(const char *filename, QemuOpts *opts, goto done; } - create_options->size = ROUND_UP(create_options->size, BDRV_SECTOR_SIZE); + assert(create_options->driver == BLOCKDEV_DRIVER_VDI); + create_options->u.vdi.size = ROUND_UP(create_options->u.vdi.size, + BDRV_SECTOR_SIZE); ret = vdi_co_do_create(create_options, block_size, errp); done: QDECREF(qdict); - qapi_free_BlockdevCreateOptionsVdi(create_options); + qapi_free_BlockdevCreateOptions(create_options); bdrv_unref(bs_file); return ret; } @@ -969,6 +982,7 @@ static BlockDriver bdrv_vdi = { .bdrv_reopen_prepare = vdi_reopen_prepare, .bdrv_child_perm = bdrv_format_default_perms, .bdrv_co_create_opts = vdi_co_create_opts, + .bdrv_co_create = vdi_co_create, .bdrv_has_zero_init = bdrv_has_zero_init_1, .bdrv_co_block_status = vdi_co_block_status, .bdrv_make_empty = vdi_make_empty, |