aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2014-10-07 13:59:03 +0200
committerKevin Wolf <kwolf@redhat.com>2014-10-20 13:41:26 +0200
commite4e9986b1caebebdbe53d6f9ad5b03d5ba83f4c3 (patch)
tree5474e234274b093ee621ebc43730bc666b53af4a
parentec0de76874462c745a1600911bd81ee0253c0c23 (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>
-rw-r--r--block.c28
-rw-r--r--block/iscsi.c2
-rw-r--r--block/vvfat.c2
-rw-r--r--blockdev.c2
-rw-r--r--hw/block/xen_disk.c2
-rw-r--r--include/block/block.h3
-rw-r--r--qemu-img.c6
-rw-r--r--qemu-io.c2
-rw-r--r--qemu-nbd.c2
9 files changed, 30 insertions, 19 deletions
diff --git a/block.c b/block.c
index 27533f3a81..42659ecc71 100644
--- a/block.c
+++ b/block.c
@@ -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 */
diff --git a/block/iscsi.c b/block/iscsi.c
index 3a01de0edb..a7fb764e4d 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1519,7 +1519,7 @@ static int iscsi_create(const char *filename, QemuOpts *opts, Error **errp)
IscsiLun *iscsilun = NULL;
QDict *bs_options;
- bs = bdrv_new("", &error_abort);
+ bs = bdrv_new();
/* Read out options */
total_size = DIV_ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
diff --git a/block/vvfat.c b/block/vvfat.c
index 731e591ec1..6c9fde017b 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2939,7 +2939,7 @@ static int enable_write_target(BDRVVVFATState *s, Error **errp)
unlink(s->qcow_filename);
#endif
- bdrv_set_backing_hd(s->bs, bdrv_new("", &error_abort));
+ bdrv_set_backing_hd(s->bs, bdrv_new());
s->bs->backing_hd->drv = &vvfat_write_target;
s->bs->backing_hd->opaque = g_new(void *, 1);
*(void**)s->bs->backing_hd->opaque = s;
diff --git a/blockdev.c b/blockdev.c
index e595910476..7608f469ef 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -523,7 +523,7 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts,
}
/* init */
- bs = bdrv_new(qemu_opts_id(opts), errp);
+ bs = bdrv_new_root(qemu_opts_id(opts), errp);
if (!bs) {
goto early_err;
}
diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
index 0d27ab16a7..7f0f66bc46 100644
--- a/hw/block/xen_disk.c
+++ b/hw/block/xen_disk.c
@@ -858,7 +858,7 @@ static int blk_connect(struct XenDevice *xendev)
/* setup via xenbus -> create new block driver instance */
xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\n");
- blkdev->bs = bdrv_new(blkdev->dev, NULL);
+ blkdev->bs = bdrv_new_root(blkdev->dev, NULL);
if (!blkdev->bs) {
return -1;
}
diff --git a/include/block/block.h b/include/block/block.h
index 3318f0dfbe..a3039ce6f7 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -204,7 +204,8 @@ BlockDriver *bdrv_find_whitelisted_format(const char *format_name,
int bdrv_create(BlockDriver *drv, const char* filename,
QemuOpts *opts, Error **errp);
int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp);
-BlockDriverState *bdrv_new(const char *device_name, Error **errp);
+BlockDriverState *bdrv_new_root(const char *device_name, Error **errp);
+BlockDriverState *bdrv_new(void);
void bdrv_make_anon(BlockDriverState *bs);
void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old);
void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top);
diff --git a/qemu-img.c b/qemu-img.c
index 27b85dbda4..9c77dcc927 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -296,7 +296,7 @@ static BlockDriverState *bdrv_new_open(const char *id,
Error *local_err = NULL;
int ret;
- bs = bdrv_new(id, &error_abort);
+ bs = bdrv_new_root(id, &error_abort);
if (fmt) {
drv = bdrv_find_format(fmt);
@@ -2423,7 +2423,7 @@ static int img_rebase(int argc, char **argv)
if (!unsafe) {
char backing_name[1024];
- bs_old_backing = bdrv_new("old_backing", &error_abort);
+ bs_old_backing = bdrv_new_root("old_backing", &error_abort);
bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name));
ret = bdrv_open(&bs_old_backing, backing_name, NULL, NULL, src_flags,
old_backing_drv, &local_err);
@@ -2434,7 +2434,7 @@ static int img_rebase(int argc, char **argv)
goto out;
}
if (out_baseimg[0]) {
- bs_new_backing = bdrv_new("new_backing", &error_abort);
+ bs_new_backing = bdrv_new_root("new_backing", &error_abort);
ret = bdrv_open(&bs_new_backing, out_baseimg, NULL, NULL, src_flags,
new_backing_drv, &local_err);
if (ret) {
diff --git a/qemu-io.c b/qemu-io.c
index 66cf3ef4be..d131dc5baa 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -58,7 +58,7 @@ static int openfile(char *name, int flags, int growable, QDict *opts)
return 1;
}
- qemuio_bs = bdrv_new("hda", &error_abort);
+ qemuio_bs = bdrv_new_root("hda", &error_abort);
if (growable) {
flags |= BDRV_O_PROTOCOL;
diff --git a/qemu-nbd.c b/qemu-nbd.c
index b524b3420f..d9f1749def 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -691,7 +691,7 @@ int main(int argc, char **argv)
drv = NULL;
}
- bs = bdrv_new("hda", &error_abort);
+ bs = bdrv_new_root("hda", &error_abort);
srcpath = argv[optind];
ret = bdrv_open(&bs, srcpath, NULL, NULL, flags, drv, &local_err);