diff options
author | Markus Armbruster <armbru@redhat.com> | 2014-10-07 13:59:03 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2014-10-20 13:41:26 +0200 |
commit | e4e9986b1caebebdbe53d6f9ad5b03d5ba83f4c3 (patch) | |
tree | 5474e234274b093ee621ebc43730bc666b53af4a /block.c | |
parent | ec0de76874462c745a1600911bd81ee0253c0c23 (diff) |
block: Split bdrv_new_root() off bdrv_new()
Creating an anonymous BDS can't fail. Make that obvious.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: BenoƮt Canet <benoit.canet@nodalink.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block.c')
-rw-r--r-- | block.c | 28 |
1 files changed, 19 insertions, 9 deletions
@@ -336,10 +336,11 @@ void bdrv_register(BlockDriver *bdrv) } /* create a new block device (by default it is empty) */ -BlockDriverState *bdrv_new(const char *device_name, Error **errp) +BlockDriverState *bdrv_new_root(const char *device_name, Error **errp) { BlockDriverState *bs; - int i; + + assert(*device_name); if (*device_name && !id_wellformed(device_name)) { error_setg(errp, "Invalid device name"); @@ -358,12 +359,21 @@ BlockDriverState *bdrv_new(const char *device_name, Error **errp) return NULL; } + bs = bdrv_new(); + + pstrcpy(bs->device_name, sizeof(bs->device_name), device_name); + QTAILQ_INSERT_TAIL(&bdrv_states, bs, device_list); + + return bs; +} + +BlockDriverState *bdrv_new(void) +{ + BlockDriverState *bs; + int i; + bs = g_new0(BlockDriverState, 1); QLIST_INIT(&bs->dirty_bitmaps); - pstrcpy(bs->device_name, sizeof(bs->device_name), device_name); - if (device_name[0] != '\0') { - QTAILQ_INSERT_TAIL(&bdrv_states, bs, device_list); - } for (i = 0; i < BLOCK_OP_TYPE_MAX; i++) { QLIST_INIT(&bs->op_blockers[i]); } @@ -1224,7 +1234,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp) goto free_exit; } - backing_hd = bdrv_new("", errp); + backing_hd = bdrv_new(); if (bs->backing_format[0] != '\0') { back_drv = bdrv_find_format(bs->backing_format); @@ -1353,7 +1363,7 @@ int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp) qdict_put(snapshot_options, "file.filename", qstring_from_str(tmp_filename)); - bs_snapshot = bdrv_new("", &error_abort); + bs_snapshot = bdrv_new(); ret = bdrv_open(&bs_snapshot, NULL, NULL, snapshot_options, flags, bdrv_qcow2, &local_err); @@ -1424,7 +1434,7 @@ int bdrv_open(BlockDriverState **pbs, const char *filename, if (*pbs) { bs = *pbs; } else { - bs = bdrv_new("", &error_abort); + bs = bdrv_new(); } /* NULL means an empty set of options */ |