thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
9ae3a8
From bfec9b88263e72c7425df04601bfcae5c06dca23 Mon Sep 17 00:00:00 2001
9ae3a8
From: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Date: Thu, 23 Oct 2014 10:10:06 +0200
9ae3a8
Subject: [PATCH 06/19] block: Add errp to bdrv_new()
9ae3a8
9ae3a8
Message-id: <1414059011-15516-4-git-send-email-kwolf@redhat.com>
9ae3a8
Patchwork-id: 61837
9ae3a8
O-Subject: [RHEL-7.1 qemu-kvm PATCH v2 3/8] block: Add errp to bdrv_new()
9ae3a8
Bugzilla: 1088176
9ae3a8
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
9ae3a8
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
RH-Acked-by: Max Reitz <mreitz@redhat.com>
9ae3a8
9ae3a8
This patch adds an errp parameter to bdrv_new() and updates all its
9ae3a8
callers. The next patches will make use of this in order to check for
9ae3a8
duplicate IDs. Most of the callers know that their ID is fine, so they
9ae3a8
can simply assert that there is no error.
9ae3a8
9ae3a8
Behaviour doesn't change with this patch yet as bdrv_new() doesn't
9ae3a8
actually assign errors to errp.
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Reviewed-by: Eric Blake <eblake@redhat.com>
9ae3a8
(cherry picked from commit 98522f63f40adaebc412481e1d2e9170160d4539)
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
9ae3a8
Conflicts:
9ae3a8
	block.c
9ae3a8
	qemu-img.c
9ae3a8
	qemu-io.c
9ae3a8
9ae3a8
In RHEL 7, we have a different set of bdrv_new() callers. Fortunately,
9ae3a8
the additional ones compared to upstream are trivial: Either we know
9ae3a8
for sure that their name is unique  (e.g. fixed names used in qemu-img)
9ae3a8
and therefore bdrv_new() will never fail even after the final patch of
9ae3a8
this series ('block: Catch duplicate IDs in bdrv_new()'), or they use an
9ae3a8
empty name "" which can't conflict either.
9ae3a8
9ae3a8
This patch leaks local_err in xen_disk, which was fixed in upstream
9ae3a8
commit cedccf13. Downstream, we don't care about Xen, so it will remain
9ae3a8
unfixed.
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
---
9ae3a8
 block.c               | 10 +++++-----
9ae3a8
 block/blkverify.c     |  2 +-
9ae3a8
 block/iscsi.c         |  2 +-
9ae3a8
 block/vmdk.c          |  2 +-
9ae3a8
 block/vvfat.c         |  4 ++--
9ae3a8
 blockdev.c            | 13 +++++++++----
9ae3a8
 hw/block/xen_disk.c   |  7 +++++--
9ae3a8
 include/block/block.h |  2 +-
9ae3a8
 qemu-img.c            |  6 +++---
9ae3a8
 qemu-io.c             |  2 +-
9ae3a8
 qemu-nbd.c            |  3 ++-
9ae3a8
 11 files changed, 31 insertions(+), 22 deletions(-)
9ae3a8
9ae3a8
diff --git a/block.c b/block.c
9ae3a8
index 496eb72..eb0810e 100644
9ae3a8
--- a/block.c
9ae3a8
+++ b/block.c
9ae3a8
@@ -300,7 +300,7 @@ void bdrv_register(BlockDriver *bdrv)
9ae3a8
 }
9ae3a8
 
9ae3a8
 /* create a new block device (by default it is empty) */
9ae3a8
-BlockDriverState *bdrv_new(const char *device_name)
9ae3a8
+BlockDriverState *bdrv_new(const char *device_name, Error **errp)
9ae3a8
 {
9ae3a8
     BlockDriverState *bs;
9ae3a8
 
9ae3a8
@@ -892,7 +892,7 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename,
9ae3a8
         options = qdict_new();
9ae3a8
     }
9ae3a8
 
9ae3a8
-    bs = bdrv_new("");
9ae3a8
+    bs = bdrv_new("", &error_abort);
9ae3a8
     bs->options = options;
9ae3a8
     options = qdict_clone_shallow(options);
9ae3a8
 
9ae3a8
@@ -1014,7 +1014,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
9ae3a8
                                        sizeof(backing_filename));
9ae3a8
     }
9ae3a8
 
9ae3a8
-    bs->backing_hd = bdrv_new("");
9ae3a8
+    bs->backing_hd = bdrv_new("", &error_abort);
9ae3a8
 
9ae3a8
     if (bs->backing_format[0] != '\0') {
9ae3a8
         back_drv = bdrv_find_format(bs->backing_format);
9ae3a8
@@ -1111,7 +1111,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
9ae3a8
            instead of opening 'filename' directly */
9ae3a8
 
9ae3a8
         /* if there is a backing file, use it */
9ae3a8
-        bs1 = bdrv_new("");
9ae3a8
+        bs1 = bdrv_new("", &error_abort);
9ae3a8
         ret = bdrv_open(bs1, filename, NULL, 0, drv, &local_err);
9ae3a8
         if (ret < 0) {
9ae3a8
             bdrv_unref(bs1);
9ae3a8
@@ -5273,7 +5273,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
9ae3a8
             back_flags =
9ae3a8
                 flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
9ae3a8
 
9ae3a8
-            bs = bdrv_new("");
9ae3a8
+            bs = bdrv_new("", &error_abort);
9ae3a8
 
9ae3a8
             ret = bdrv_open(bs, backing_file->value.s, NULL, back_flags,
9ae3a8
                             backing_drv, &local_err);
9ae3a8
diff --git a/block/blkverify.c b/block/blkverify.c
9ae3a8
index 4ff7688..e623f6e 100644
9ae3a8
--- a/block/blkverify.c
9ae3a8
+++ b/block/blkverify.c
9ae3a8
@@ -155,7 +155,7 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags,
9ae3a8
         goto fail;
9ae3a8
     }
9ae3a8
 
9ae3a8
-    s->test_file = bdrv_new("");
9ae3a8
+    s->test_file = bdrv_new("", &error_abort);
9ae3a8
     ret = bdrv_open(s->test_file, filename, NULL, flags, NULL, &local_err);
9ae3a8
     if (ret < 0) {
9ae3a8
         error_propagate(errp, local_err);
9ae3a8
diff --git a/block/iscsi.c b/block/iscsi.c
9ae3a8
index 9fe3be8..4f42f29 100644
9ae3a8
--- a/block/iscsi.c
9ae3a8
+++ b/block/iscsi.c
9ae3a8
@@ -1576,7 +1576,7 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options,
9ae3a8
     IscsiLun *iscsilun = NULL;
9ae3a8
     QDict *bs_options;
9ae3a8
 
9ae3a8
-    bs = bdrv_new("");
9ae3a8
+    bs = bdrv_new("", &error_abort);
9ae3a8
 
9ae3a8
     /* Read out options */
9ae3a8
     while (options && options->name) {
9ae3a8
diff --git a/block/vmdk.c b/block/vmdk.c
9ae3a8
index eff0663..a5b1f1c 100644
9ae3a8
--- a/block/vmdk.c
9ae3a8
+++ b/block/vmdk.c
9ae3a8
@@ -1745,7 +1745,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
9ae3a8
         goto exit;
9ae3a8
     }
9ae3a8
     if (backing_file) {
9ae3a8
-        BlockDriverState *bs = bdrv_new("");
9ae3a8
+        BlockDriverState *bs = bdrv_new("", &error_abort);
9ae3a8
         ret = bdrv_open(bs, backing_file, NULL, 0, NULL, errp);
9ae3a8
         if (ret != 0) {
9ae3a8
             bdrv_unref(bs);
9ae3a8
diff --git a/block/vvfat.c b/block/vvfat.c
9ae3a8
index 3ddaa0b..6fd52df 100644
9ae3a8
--- a/block/vvfat.c
9ae3a8
+++ b/block/vvfat.c
9ae3a8
@@ -2935,7 +2935,7 @@ static int enable_write_target(BDRVVVFATState *s)
9ae3a8
         goto err;
9ae3a8
     }
9ae3a8
 
9ae3a8
-    s->qcow = bdrv_new("");
9ae3a8
+    s->qcow = bdrv_new("", &error_abort);
9ae3a8
 
9ae3a8
     ret = bdrv_open(s->qcow, s->qcow_filename, NULL,
9ae3a8
             BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, bdrv_qcow,
9ae3a8
@@ -2951,7 +2951,7 @@ static int enable_write_target(BDRVVVFATState *s)
9ae3a8
     unlink(s->qcow_filename);
9ae3a8
 #endif
9ae3a8
 
9ae3a8
-    s->bs->backing_hd = bdrv_new("");
9ae3a8
+    s->bs->backing_hd = bdrv_new("", &error_abort);
9ae3a8
     s->bs->backing_hd->drv = &vvfat_write_target;
9ae3a8
     s->bs->backing_hd->opaque = g_malloc(sizeof(void*));
9ae3a8
     *(void**)s->bs->backing_hd->opaque = s;
9ae3a8
diff --git a/blockdev.c b/blockdev.c
9ae3a8
index 1ac8804..b5792a2 100644
9ae3a8
--- a/blockdev.c
9ae3a8
+++ b/blockdev.c
9ae3a8
@@ -471,7 +471,11 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
9ae3a8
     /* init */
9ae3a8
     dinfo = g_malloc0(sizeof(*dinfo));
9ae3a8
     dinfo->id = g_strdup(qemu_opts_id(opts));
9ae3a8
-    dinfo->bdrv = bdrv_new(dinfo->id);
9ae3a8
+    dinfo->bdrv = bdrv_new(dinfo->id, &error);
9ae3a8
+    if (error) {
9ae3a8
+        error_propagate(errp, error);
9ae3a8
+        goto bdrv_new_err;
9ae3a8
+    }
9ae3a8
     dinfo->bdrv->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0;
9ae3a8
     dinfo->bdrv->read_only = ro;
9ae3a8
     dinfo->type = type;
9ae3a8
@@ -531,8 +535,9 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
9ae3a8
 
9ae3a8
 err:
9ae3a8
     bdrv_unref(dinfo->bdrv);
9ae3a8
-    g_free(dinfo->id);
9ae3a8
     QTAILQ_REMOVE(&drives, dinfo, next);
9ae3a8
+bdrv_new_err:
9ae3a8
+    g_free(dinfo->id);
9ae3a8
     g_free(dinfo);
9ae3a8
 early_err:
9ae3a8
     QDECREF(bs_opts);
9ae3a8
@@ -1056,7 +1061,7 @@ static void external_snapshot_prepare(BlkTransactionStates *common,
9ae3a8
     }
9ae3a8
 
9ae3a8
     /* We will manually add the backing_hd field to the bs later */
9ae3a8
-    states->new_bs = bdrv_new("");
9ae3a8
+    states->new_bs = bdrv_new("", &error_abort);
9ae3a8
     /* TODO Inherit bs->options or only take explicit options with an
9ae3a8
      * extended QMP command? */
9ae3a8
     ret = bdrv_open(states->new_bs, new_image_file, NULL,
9ae3a8
@@ -1678,7 +1683,7 @@ void qmp_drive_mirror(const char *device, const char *target,
9ae3a8
     /* Mirroring takes care of copy-on-write using the source's backing
9ae3a8
      * file.
9ae3a8
      */
9ae3a8
-    target_bs = bdrv_new("");
9ae3a8
+    target_bs = bdrv_new("", &error_abort);
9ae3a8
     ret = bdrv_open(target_bs, target, NULL, flags | BDRV_O_NO_BACKING, drv,
9ae3a8
                     &local_err);
9ae3a8
     if (ret < 0) {
9ae3a8
diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
9ae3a8
index a2653b2..fc45f36 100644
9ae3a8
--- a/hw/block/xen_disk.c
9ae3a8
+++ b/hw/block/xen_disk.c
9ae3a8
@@ -793,11 +793,14 @@ static int blk_connect(struct XenDevice *xendev)
9ae3a8
     index = (blkdev->xendev.dev - 202 * 256) / 16;
9ae3a8
     blkdev->dinfo = drive_get(IF_XEN, 0, index);
9ae3a8
     if (!blkdev->dinfo) {
9ae3a8
+        Error *local_err = NULL;
9ae3a8
         /* setup via xenbus -> create new block driver instance */
9ae3a8
         xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\n");
9ae3a8
-        blkdev->bs = bdrv_new(blkdev->dev);
9ae3a8
+        blkdev->bs = bdrv_new(blkdev->dev, &local_err);
9ae3a8
+        if (local_err) {
9ae3a8
+            blkdev->bs = NULL;
9ae3a8
+        }
9ae3a8
         if (blkdev->bs) {
9ae3a8
-            Error *local_err = NULL;
9ae3a8
             BlockDriver *drv = bdrv_find_whitelisted_format(blkdev->fileproto,
9ae3a8
                                                            readonly);
9ae3a8
             if (bdrv_open(blkdev->bs,
9ae3a8
diff --git a/include/block/block.h b/include/block/block.h
9ae3a8
index 03b7960..3651bd9 100644
9ae3a8
--- a/include/block/block.h
9ae3a8
+++ b/include/block/block.h
9ae3a8
@@ -178,7 +178,7 @@ int bdrv_create(BlockDriver *drv, const char* filename,
9ae3a8
     QEMUOptionParameter *options, Error **errp);
9ae3a8
 int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
9ae3a8
                      Error **errp);
9ae3a8
-BlockDriverState *bdrv_new(const char *device_name);
9ae3a8
+BlockDriverState *bdrv_new(const char *device_name, Error **errp);
9ae3a8
 void bdrv_make_anon(BlockDriverState *bs);
9ae3a8
 void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old);
9ae3a8
 void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top);
9ae3a8
diff --git a/qemu-img.c b/qemu-img.c
9ae3a8
index ed1799c..5c2f36a 100644
9ae3a8
--- a/qemu-img.c
9ae3a8
+++ b/qemu-img.c
9ae3a8
@@ -274,7 +274,7 @@ static BlockDriverState *bdrv_new_open(const char *filename,
9ae3a8
     Error *local_err = NULL;
9ae3a8
     int ret;
9ae3a8
 
9ae3a8
-    bs = bdrv_new("image");
9ae3a8
+    bs = bdrv_new("image", &error_abort);
9ae3a8
 
9ae3a8
     if (fmt) {
9ae3a8
         drv = bdrv_find_format(fmt);
9ae3a8
@@ -2299,7 +2299,7 @@ static int img_rebase(int argc, char **argv)
9ae3a8
     } else {
9ae3a8
         char backing_name[1024];
9ae3a8
 
9ae3a8
-        bs_old_backing = bdrv_new("old_backing");
9ae3a8
+        bs_old_backing = bdrv_new("old_backing", &error_abort);
9ae3a8
         bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name));
9ae3a8
         ret = bdrv_open(bs_old_backing, backing_name, NULL, BDRV_O_FLAGS,
9ae3a8
                         old_backing_drv, &local_err);
9ae3a8
@@ -2310,7 +2310,7 @@ static int img_rebase(int argc, char **argv)
9ae3a8
             goto out;
9ae3a8
         }
9ae3a8
         if (out_baseimg[0]) {
9ae3a8
-            bs_new_backing = bdrv_new("new_backing");
9ae3a8
+            bs_new_backing = bdrv_new("new_backing", &error_abort);
9ae3a8
             ret = bdrv_open(bs_new_backing, out_baseimg, NULL, BDRV_O_FLAGS,
9ae3a8
                         new_backing_drv, &local_err);
9ae3a8
             if (ret) {
9ae3a8
diff --git a/qemu-io.c b/qemu-io.c
9ae3a8
index bbe2518..cc89947 100644
9ae3a8
--- a/qemu-io.c
9ae3a8
+++ b/qemu-io.c
9ae3a8
@@ -1831,7 +1831,7 @@ static int openfile(char *name, int flags, int growable, QDict *opts)
9ae3a8
             return 1;
9ae3a8
         }
9ae3a8
     } else {
9ae3a8
-        bs = bdrv_new("hda");
9ae3a8
+        bs = bdrv_new("hda", &error_abort);
9ae3a8
 
9ae3a8
         if (bdrv_open(bs, name, opts, flags, NULL, &local_err) < 0) {
9ae3a8
             fprintf(stderr, "%s: can't open device %s: %s\n", progname, name,
9ae3a8
diff --git a/qemu-nbd.c b/qemu-nbd.c
9ae3a8
index 207a610..ff792ef 100644
9ae3a8
--- a/qemu-nbd.c
9ae3a8
+++ b/qemu-nbd.c
9ae3a8
@@ -572,7 +572,8 @@ int main(int argc, char **argv)
9ae3a8
         drv = NULL;
9ae3a8
     }
9ae3a8
 
9ae3a8
-    bs = bdrv_new("hda");
9ae3a8
+    bs = bdrv_new("hda", &error_abort);
9ae3a8
+
9ae3a8
     srcpath = argv[optind];
9ae3a8
     ret = bdrv_open(bs, srcpath, NULL, flags, drv, &local_err);
9ae3a8
     if (ret < 0) {
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8