qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 7/8] block: Make bdrv_open() return a BDS


From: Max Reitz
Subject: [Qemu-devel] [PATCH 7/8] block: Make bdrv_open() return a BDS
Date: Tue, 10 Nov 2015 04:44:22 +0100

There are no callers to bdrv_open() or bdrv_open_inherit() left that
pass a pointer to a non-NULL BDS pointer as the first argument of these
functions, so we can finally drop that parameter and just make them
return the new BDS.

Generally, the following pattern is applied:

    bs = NULL;
    ret = bdrv_open(&bs, ..., &local_err);
    if (ret < 0) {
        error_propagate(errp, local_err);
        ...
    }

by

    bs = bdrv_open(..., errp);
    if (!bs) {
        ret = -EINVAL;
        ...
    }

Of course, there are only a few instances where the pattern is really
pure.

Signed-off-by: Max Reitz <address@hidden>
---
 block.c               | 121 +++++++++++++++++---------------------------------
 block/block-backend.c |   6 +--
 block/parallels.c     |   9 ++--
 block/qcow.c          |   9 ++--
 block/qcow2.c         |  29 +++++-------
 block/qed.c           |  11 ++---
 block/sheepdog.c      |  16 +++----
 block/vdi.c           |   7 ++-
 block/vhdx.c          |   8 ++--
 block/vmdk.c          |  24 +++++-----
 block/vpc.c           |   7 ++-
 block/vvfat.c         |   9 ++--
 blockdev.c            |  38 ++++++----------
 include/block/block.h |   4 +-
 14 files changed, 113 insertions(+), 185 deletions(-)

diff --git a/block.c b/block.c
index 0531992..f258c54 100644
--- a/block.c
+++ b/block.c
@@ -82,10 +82,12 @@ static QTAILQ_HEAD(, BlockDriverState) all_bdrv_states =
 static QLIST_HEAD(, BlockDriver) bdrv_drivers =
     QLIST_HEAD_INITIALIZER(bdrv_drivers);
 
-static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,
-                             const char *reference, QDict *options, int flags,
-                             BlockDriverState *parent,
-                             const BdrvChildRole *child_role, Error **errp);
+static BlockDriverState *bdrv_open_inherit(const char *filename,
+                                           const char *reference,
+                                           QDict *options, int flags,
+                                           BlockDriverState *parent,
+                                           const BdrvChildRole *child_role,
+                                           Error **errp);
 
 static void bdrv_dirty_bitmap_truncate(BlockDriverState *bs);
 static void bdrv_release_all_dirty_bitmaps(BlockDriverState *bs);
@@ -1211,15 +1213,15 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict 
*options, Error **errp)
         qdict_put(options, "driver", qstring_from_str(bs->backing_format));
     }
 
-    backing_hd = NULL;
-    ret = bdrv_open_inherit(&backing_hd,
-                            *backing_filename ? backing_filename : NULL,
-                            NULL, options, 0, bs, &child_backing, &local_err);
-    if (ret < 0) {
+    backing_hd = bdrv_open_inherit(*backing_filename ? backing_filename : NULL,
+                                   NULL, options, 0, bs, &child_backing,
+                                   &local_err);
+    if (!backing_hd) {
         bs->open_flags |= BDRV_O_NO_BACKING;
         error_setg(errp, "Could not open backing file: %s",
                    error_get_pretty(local_err));
         error_free(local_err);
+        ret = -EINVAL;
         goto free_exit;
     }
 
@@ -1256,7 +1258,6 @@ BdrvChild *bdrv_open_child(const char *filename,
     BdrvChild *c = NULL;
     BlockDriverState *bs;
     QDict *image_options;
-    int ret;
     char *bdref_key_dot;
     const char *reference;
 
@@ -1276,10 +1277,9 @@ BdrvChild *bdrv_open_child(const char *filename,
         goto done;
     }
 
-    bs = NULL;
-    ret = bdrv_open_inherit(&bs, filename, reference, image_options, 0,
-                            parent, child_role, errp);
-    if (ret < 0) {
+    bs = bdrv_open_inherit(filename, reference, image_options, 0,
+                           parent, child_role, errp);
+    if (!bs) {
         goto done;
     }
 
@@ -1342,11 +1342,9 @@ static BlockDriverState 
*bdrv_append_temp_snapshot(BlockDriverState *bs,
     qdict_put(snapshot_options, "driver",
               qstring_from_str("qcow2"));
 
-    bs_snapshot = NULL;
-    ret = bdrv_open(&bs_snapshot, NULL, NULL, snapshot_options,
-                    flags, &local_err);
-    if (ret < 0) {
-        error_propagate(errp, local_err);
+    bs_snapshot = bdrv_open(NULL, NULL, snapshot_options, flags, errp);
+    if (!bs_snapshot) {
+        ret = -EINVAL;
         goto out;
     }
 
@@ -1376,10 +1374,12 @@ out:
  * should be opened. If specified, neither options nor a filename may be given,
  * nor can an existing BDS be reused (that is, *pbs has to be NULL).
  */
-static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,
-                             const char *reference, QDict *options, int flags,
-                             BlockDriverState *parent,
-                             const BdrvChildRole *child_role, Error **errp)
+static BlockDriverState *bdrv_open_inherit(const char *filename,
+                                           const char *reference,
+                                           QDict *options, int flags,
+                                           BlockDriverState *parent,
+                                           const BdrvChildRole *child_role,
+                                           Error **errp)
 {
     int ret;
     BdrvChild *file = NULL;
@@ -1390,7 +1390,6 @@ static int bdrv_open_inherit(BlockDriverState **pbs, 
const char *filename,
     Error *local_err = NULL;
     int snapshot_flags = 0;
 
-    assert(pbs);
     assert(!child_role || !flags);
     assert(!child_role == !parent);
 
@@ -1398,32 +1397,21 @@ static int bdrv_open_inherit(BlockDriverState **pbs, 
const char *filename,
         bool options_non_empty = options ? qdict_size(options) : false;
         QDECREF(options);
 
-        if (*pbs) {
-            error_setg(errp, "Cannot reuse an existing BDS when referencing "
-                       "another block device");
-            return -EINVAL;
-        }
-
         if (filename || options_non_empty) {
             error_setg(errp, "Cannot reference an existing block device with "
                        "additional options or a new filename");
-            return -EINVAL;
+            return NULL;
         }
 
         bs = bdrv_lookup_bs(reference, reference, errp);
         if (!bs) {
-            return -ENODEV;
+            return NULL;
         }
         bdrv_ref(bs);
-        *pbs = bs;
-        return 0;
+        return bs;
     }
 
-    if (*pbs) {
-        bs = *pbs;
-    } else {
-        bs = bdrv_new();
-    }
+    bs = bdrv_new();
 
     /* NULL means an empty set of options */
     if (options == NULL) {
@@ -1447,7 +1435,6 @@ static int bdrv_open_inherit(BlockDriverState **pbs, 
const char *filename,
         qdict_del(options, "driver");
         if (!drv) {
             error_setg(errp, "Unknown driver: '%s'", drvname);
-            ret = -EINVAL;
             goto fail;
         }
     }
@@ -1479,7 +1466,6 @@ static int bdrv_open_inherit(BlockDriverState **pbs, 
const char *filename,
         file = bdrv_open_child(filename, options, "file", bs,
                                &child_file, true, &local_err);
         if (local_err) {
-            ret = -EINVAL;
             goto fail;
         }
     }
@@ -1493,7 +1479,6 @@ static int bdrv_open_inherit(BlockDriverState **pbs, 
const char *filename,
         }
     } else if (!drv) {
         error_setg(errp, "Must specify either driver or file");
-        ret = -EINVAL;
         goto fail;
     }
 
@@ -1539,7 +1524,6 @@ static int bdrv_open_inherit(BlockDriverState **pbs, 
const char *filename,
                        drv->format_name, entry->key);
         }
 
-        ret = -EINVAL;
         goto close_and_fail;
     }
 
@@ -1552,7 +1536,6 @@ static int bdrv_open_inherit(BlockDriverState **pbs, 
const char *filename,
                && !runstate_check(RUN_STATE_PAUSED)) { /* HACK */
         error_setg(errp,
                    "Guest must be stopped for opening of encrypted image");
-        ret = -EBUSY;
         goto close_and_fail;
     }
 
@@ -1564,25 +1547,14 @@ static int bdrv_open_inherit(BlockDriverState **pbs, 
const char *filename,
         BlockDriverState *snapshot_bs;
         snapshot_bs = bdrv_append_temp_snapshot(bs, snapshot_flags, 
&local_err);
         if (local_err) {
-            ret = -EINVAL;
             goto close_and_fail;
         }
-        if (!*pbs) {
-            /* The reference is now held by the overlay BDS */
-            bdrv_unref(bs);
-            bs = snapshot_bs;
-        } else {
-            /* It is still referenced in the same way that *pbs was referenced,
-             * however that may be */
-            bdrv_unref(snapshot_bs);
-        }
-    }
-
-    if (!*pbs) {
-        *pbs = bs;
+        /* The reference is now held by the overlay BDS */
+        bdrv_unref(bs);
+        bs = snapshot_bs;
     }
 
-    return 0;
+    return bs;
 
 fail:
     if (file != NULL) {
@@ -1591,35 +1563,25 @@ fail:
     QDECREF(bs->options);
     QDECREF(options);
     bs->options = NULL;
-    if (!*pbs) {
-        /* If *pbs is NULL, a new BDS has been created in this function and
-           needs to be freed now. Otherwise, it does not need to be closed,
-           since it has not really been opened yet. */
-        bdrv_unref(bs);
-    }
+    bdrv_unref(bs);
     if (local_err) {
         error_propagate(errp, local_err);
     }
-    return ret;
+    return NULL;
 
 close_and_fail:
-    /* See fail path, but now the BDS has to be always closed */
-    if (*pbs) {
-        bdrv_close(bs);
-    } else {
-        bdrv_unref(bs);
-    }
+    bdrv_unref(bs);
     QDECREF(options);
     if (local_err) {
         error_propagate(errp, local_err);
     }
-    return ret;
+    return NULL;
 }
 
-int bdrv_open(BlockDriverState **pbs, const char *filename,
-              const char *reference, QDict *options, int flags, Error **errp)
+BlockDriverState *bdrv_open(const char *filename, const char *reference,
+                            QDict *options, int flags, Error **errp)
 {
-    return bdrv_open_inherit(pbs, filename, reference, options, flags, NULL,
+    return bdrv_open_inherit(filename, reference, options, flags, NULL,
                              NULL, errp);
 }
 
@@ -3636,11 +3598,10 @@ void bdrv_img_create(const char *filename, const char 
*fmt,
                           qstring_from_str(backing_fmt));
             }
 
-            bs = NULL;
-            ret = bdrv_open(&bs, full_backing, NULL, backing_options,
-                            back_flags, &local_err);
+            bs = bdrv_open(full_backing, NULL, backing_options, back_flags,
+                           &local_err);
             g_free(full_backing);
-            if (ret < 0) {
+            if (!bs) {
                 goto out;
             }
             size = bdrv_getlength(bs);
diff --git a/block/block-backend.c b/block/block-backend.c
index 13f5fef..9b674e2 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -131,7 +131,6 @@ BlockBackend *blk_new_open(const char *name, const char 
*filename,
 {
     BlockBackend *blk;
     BlockDriverState *bs;
-    int ret;
 
     blk = blk_new(name, errp);
     if (!blk) {
@@ -139,9 +138,8 @@ BlockBackend *blk_new_open(const char *name, const char 
*filename,
         return NULL;
     }
 
-    bs = NULL;
-    ret = bdrv_open(&bs, filename, reference, options, flags, errp);
-    if (ret < 0) {
+    bs = bdrv_open(filename, reference, options, flags, errp);
+    if (!bs) {
         blk_unref(blk);
         return NULL;
     }
diff --git a/block/parallels.c b/block/parallels.c
index 4f79293..2e358a0 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -475,12 +475,9 @@ static int parallels_create(const char *filename, QemuOpts 
*opts, Error **errp)
         return ret;
     }
 
-    file = NULL;
-    ret = bdrv_open(&file, filename, NULL, NULL,
-                    BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
-    if (ret < 0) {
-        error_propagate(errp, local_err);
-        return ret;
+    file = bdrv_open(filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL, 
errp);
+    if (!file) {
+        return -EINVAL;
     }
     ret = bdrv_truncate(file, 0);
     if (ret < 0) {
diff --git a/block/qcow.c b/block/qcow.c
index 2601954..013590a 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -790,11 +790,10 @@ static int qcow_create(const char *filename, QemuOpts 
*opts, Error **errp)
         goto cleanup;
     }
 
-    qcow_bs = NULL;
-    ret = bdrv_open(&qcow_bs, filename, NULL, NULL,
-                    BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
-    if (ret < 0) {
-        error_propagate(errp, local_err);
+    qcow_bs = bdrv_open(filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL,
+                        errp);
+    if (!qcow_bs) {
+        ret = -EINVAL;
         goto cleanup;
     }
 
diff --git a/block/qcow2.c b/block/qcow2.c
index 88e17aa..7dc5fe0 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2095,12 +2095,9 @@ static int qcow2_create2(const char *filename, int64_t 
total_size,
         return ret;
     }
 
-    bs = NULL;
-    ret = bdrv_open(&bs, filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL,
-                    &local_err);
-    if (ret < 0) {
-        error_propagate(errp, local_err);
-        return ret;
+    bs = bdrv_open(filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL, errp);
+    if (!bs) {
+        return -EINVAL;
     }
 
     /* Write the header */
@@ -2149,7 +2146,6 @@ static int qcow2_create2(const char *filename, int64_t 
total_size,
     }
 
     bdrv_unref(bs);
-    bs = NULL;
 
     /*
      * And now open the image and make it consistent first (i.e. increase the
@@ -2158,11 +2154,10 @@ static int qcow2_create2(const char *filename, int64_t 
total_size,
      */
     options = qdict_new();
     qdict_put(options, "driver", qstring_from_str("qcow2"));
-    ret = bdrv_open(&bs, filename, NULL, options,
-                    BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH,
-                    &local_err);
-    if (ret < 0) {
-        error_propagate(errp, local_err);
+    bs = bdrv_open(filename, NULL, options,
+                   BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, errp);
+    if (!bs) {
+        ret = -EINVAL;
         goto out;
     }
 
@@ -2207,16 +2202,14 @@ static int qcow2_create2(const char *filename, int64_t 
total_size,
     }
 
     bdrv_unref(bs);
-    bs = NULL;
 
     /* Reopen the image without BDRV_O_NO_FLUSH to flush it before returning */
     options = qdict_new();
     qdict_put(options, "driver", qstring_from_str("qcow2"));
-    ret = bdrv_open(&bs, filename, NULL, options,
-                    BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_BACKING,
-                    &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    bs = bdrv_open(filename, NULL, options,
+                   BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_BACKING, errp);
+    if (!bs) {
+        ret = -EINVAL;
         goto out;
     }
 
diff --git a/block/qed.c b/block/qed.c
index c15f0be..60af894 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -572,13 +572,10 @@ static int qed_create(const char *filename, uint32_t 
cluster_size,
         return ret;
     }
 
-    bs = NULL;
-    ret = bdrv_open(&bs, filename, NULL, NULL,
-                    BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
-                    &local_err);
-    if (ret < 0) {
-        error_propagate(errp, local_err);
-        return ret;
+    bs = bdrv_open(filename, NULL, NULL,
+                   BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL, errp);
+    if (!bs) {
+        return -EINVAL;
     }
 
     /* File must start empty and grow, check truncate is supported */
diff --git a/block/sheepdog.c b/block/sheepdog.c
index d80e4ed..24116dc 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1630,18 +1630,18 @@ static int do_sd_create(BDRVSheepdogState *s, uint32_t 
*vdi_id, int snapshot,
 
 static int sd_prealloc(const char *filename, Error **errp)
 {
-    BlockDriverState *bs = NULL;
+    BlockDriverState *bs;
     BDRVSheepdogState *base = NULL;
     unsigned long buf_size;
     uint32_t idx, max_idx;
     uint32_t object_size;
     int64_t vdi_size;
     void *buf = NULL;
-    int ret;
+    int ret = 0;
 
-    ret = bdrv_open(&bs, filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL,
-                    errp);
-    if (ret < 0) {
+    bs = bdrv_open(filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL, errp);
+    if (!bs) {
+        ret = -EINVAL;
         goto out_with_err_set;
     }
 
@@ -1831,9 +1831,9 @@ static int sd_create(const char *filename, QemuOpts *opts,
             goto out;
         }
 
-        bs = NULL;
-        ret = bdrv_open(&bs, backing_file, NULL, NULL, BDRV_O_PROTOCOL, errp);
-        if (ret < 0) {
+        bs = bdrv_open(backing_file, NULL, NULL, BDRV_O_PROTOCOL, errp);
+        if (!bs) {
+            ret = -EINVAL;
             goto out;
         }
 
diff --git a/block/vdi.c b/block/vdi.c
index 17f435f..12c3788 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -764,10 +764,9 @@ static int vdi_create(const char *filename, QemuOpts 
*opts, Error **errp)
         error_propagate(errp, local_err);
         goto exit;
     }
-    ret = bdrv_open(&bs, filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL,
-                    &local_err);
-    if (ret < 0) {
-        error_propagate(errp, local_err);
+    bs = bdrv_open(filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL, errp);
+    if (!bs) {
+        ret = -EINVAL;
         goto exit;
     }
 
diff --git a/block/vhdx.c b/block/vhdx.c
index 2fe9a5e..8ec4b86 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -1842,11 +1842,9 @@ static int vhdx_create(const char *filename, QemuOpts 
*opts, Error **errp)
         goto exit;
     }
 
-    bs = NULL;
-    ret = bdrv_open(&bs, filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL,
-                    &local_err);
-    if (ret < 0) {
-        error_propagate(errp, local_err);
+    bs = bdrv_open(filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL, errp);
+    if (!bs) {
+        ret = -EINVAL;
         goto exit;
     }
 
diff --git a/block/vmdk.c b/block/vmdk.c
index bcce9a7..3c16e6d 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1634,11 +1634,9 @@ static int vmdk_create_extent(const char *filename, 
int64_t filesize,
         goto exit;
     }
 
-    assert(bs == NULL);
-    ret = bdrv_open(&bs, filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL,
-                    &local_err);
-    if (ret < 0) {
-        error_propagate(errp, local_err);
+    bs = bdrv_open(filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL, errp);
+    if (!bs) {
+        ret = -EINVAL;
         goto exit;
     }
 
@@ -1898,7 +1896,7 @@ static int vmdk_create(const char *filename, QemuOpts 
*opts, Error **errp)
         goto exit;
     }
     if (backing_file) {
-        BlockDriverState *bs = NULL;
+        BlockDriverState *bs;
         char *full_backing = g_new0(char, PATH_MAX);
         bdrv_get_full_backing_filename_from_filename(filename, backing_file,
                                                      full_backing, PATH_MAX,
@@ -1909,9 +1907,10 @@ static int vmdk_create(const char *filename, QemuOpts 
*opts, Error **errp)
             ret = -ENOENT;
             goto exit;
         }
-        ret = bdrv_open(&bs, full_backing, NULL, NULL, BDRV_O_NO_BACKING, 
errp);
+        bs = bdrv_open(full_backing, NULL, NULL, BDRV_O_NO_BACKING, errp);
         g_free(full_backing);
-        if (ret != 0) {
+        if (!bs) {
+            ret = -EINVAL;
             goto exit;
         }
         if (strcmp(bs->drv->format_name, "vmdk")) {
@@ -1978,11 +1977,10 @@ static int vmdk_create(const char *filename, QemuOpts 
*opts, Error **errp)
             goto exit;
         }
     }
-    assert(new_bs == NULL);
-    ret = bdrv_open(&new_bs, filename, NULL, NULL,
-                    BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
-    if (ret < 0) {
-        error_propagate(errp, local_err);
+    new_bs = bdrv_open(filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL,
+                       errp);
+    if (!new_bs) {
+        ret = -EINVAL;
         goto exit;
     }
     ret = bdrv_pwrite(new_bs, desc_offset, desc, desc_len);
diff --git a/block/vpc.c b/block/vpc.c
index 299d373..2d2a867 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -795,10 +795,9 @@ static int vpc_create(const char *filename, QemuOpts 
*opts, Error **errp)
         error_propagate(errp, local_err);
         goto out;
     }
-    ret = bdrv_open(&bs, filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL,
-                    &local_err);
-    if (ret < 0) {
-        error_propagate(errp, local_err);
+    bs = bdrv_open(filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL, errp);
+    if (!bs) {
+        ret = -EINVAL;
         goto out;
     }
 
diff --git a/block/vvfat.c b/block/vvfat.c
index b184eca..a656e75 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2952,13 +2952,12 @@ static int enable_write_target(BDRVVVFATState *s, Error 
**errp)
         goto err;
     }
 
-    s->qcow = NULL;
     options = qdict_new();
     qdict_put(options, "driver", qstring_from_str("qcow"));
-    ret = bdrv_open(&s->qcow, s->qcow_filename, NULL, options,
-                    BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH,
-                    errp);
-    if (ret < 0) {
+    s->qcow = bdrv_open(s->qcow_filename, NULL, options,
+                        BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, errp);
+    if (!s->qcow) {
+        ret = -EINVAL;
         goto err;
     }
 
diff --git a/blockdev.c b/blockdev.c
index f9c376f..d900282 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -629,7 +629,6 @@ static BlockDriverState *bds_tree_init(QDict *bs_opts, 
Error **errp)
     QemuOpts *opts;
     Error *local_error = NULL;
     BlockdevDetectZeroesOptions detect_zeroes;
-    int ret;
     int bdrv_flags = 0;
 
     opts = qemu_opts_create(&qemu_root_bds_opts, NULL, 1, errp);
@@ -650,9 +649,8 @@ static BlockDriverState *bds_tree_init(QDict *bs_opts, 
Error **errp)
         goto fail;
     }
 
-    bs = NULL;
-    ret = bdrv_open(&bs, NULL, NULL, bs_opts, bdrv_flags, errp);
-    if (ret < 0) {
+    bs = bdrv_open(NULL, NULL, bs_opts, bdrv_flags, errp);
+    if (!bs) {
         goto fail_no_bs_opts;
     }
 
@@ -1561,7 +1559,7 @@ typedef struct ExternalSnapshotState {
 static void external_snapshot_prepare(BlkTransactionState *common,
                                       Error **errp)
 {
-    int flags = 0, ret;
+    int flags = 0;
     QDict *options = NULL;
     Error *local_err = NULL;
     /* Device and node name of the image to generate the snapshot from */
@@ -1676,11 +1674,10 @@ static void 
external_snapshot_prepare(BlkTransactionState *common,
         flags |= BDRV_O_NO_BACKING;
     }
 
-    assert(state->new_bs == NULL);
-    ret = bdrv_open(&state->new_bs, new_image_file, snapshot_ref, options,
-                    flags, errp);
+    state->new_bs = bdrv_open(new_image_file, snapshot_ref, options, flags,
+                              errp);
     /* We will manually add the backing_hd field to the bs later */
-    if (ret != 0) {
+    if (!state->new_bs) {
         return;
     }
 
@@ -2211,7 +2208,7 @@ void qmp_blockdev_change_medium(const char *device, const 
char *filename,
 {
     BlockBackend *blk;
     BlockDriverState *medium_bs = NULL;
-    int bdrv_flags, ret;
+    int bdrv_flags;
     QDict *options = NULL;
     Error *err = NULL;
 
@@ -2253,9 +2250,8 @@ void qmp_blockdev_change_medium(const char *device, const 
char *filename,
         qdict_put(options, "driver", qstring_from_str(format));
     }
 
-    assert(!medium_bs);
-    ret = bdrv_open(&medium_bs, filename, NULL, options, bdrv_flags, errp);
-    if (ret < 0) {
+    medium_bs = bdrv_open(filename, NULL, options, bdrv_flags, errp);
+    if (!medium_bs) {
         goto fail;
     }
 
@@ -2829,7 +2825,6 @@ void qmp_drive_backup(const char *device, const char 
*target,
     Error *local_err = NULL;
     int flags;
     int64_t size;
-    int ret;
 
     if (!has_speed) {
         speed = 0;
@@ -2913,10 +2908,8 @@ void qmp_drive_backup(const char *device, const char 
*target,
         qdict_put(options, "driver", qstring_from_str(format));
     }
 
-    target_bs = NULL;
-    ret = bdrv_open(&target_bs, target, NULL, options, flags, &local_err);
-    if (ret < 0) {
-        error_propagate(errp, local_err);
+    target_bs = bdrv_open(target, NULL, options, flags, errp);
+    if (!target_bs) {
         goto out;
     }
 
@@ -3035,7 +3028,6 @@ void qmp_drive_mirror(const char *device, const char 
*target,
     QDict *options;
     int flags;
     int64_t size;
-    int ret;
 
     if (!has_speed) {
         speed = 0;
@@ -3178,11 +3170,9 @@ void qmp_drive_mirror(const char *device, const char 
*target,
     /* Mirroring takes care of copy-on-write using the source's backing
      * file.
      */
-    target_bs = NULL;
-    ret = bdrv_open(&target_bs, target, NULL, options,
-                    flags | BDRV_O_NO_BACKING, &local_err);
-    if (ret < 0) {
-        error_propagate(errp, local_err);
+    target_bs = bdrv_open(target, NULL, options, flags | BDRV_O_NO_BACKING,
+                          errp);
+    if (!target_bs) {
         goto out;
     }
 
diff --git a/include/block/block.h b/include/block/block.h
index 6638790..41001a2 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -209,8 +209,8 @@ BdrvChild *bdrv_open_child(const char *filename,
                            bool allow_none, Error **errp);
 void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd);
 int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp);
-int bdrv_open(BlockDriverState **pbs, const char *filename,
-              const char *reference, QDict *options, int flags, Error **errp);
+BlockDriverState *bdrv_open(const char *filename, const char *reference,
+                            QDict *options, int flags, Error **errp);
 BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue,
                                     BlockDriverState *bs,
                                     QDict *options, int flags);
-- 
2.6.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]