qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 10/27] block: Fix error handling in bdrv_replace_in_backing_chain()
Date: Tue,  7 Mar 2017 16:40:34 +0100	[thread overview]
Message-ID: <1488901251-16214-11-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1488901251-16214-1-git-send-email-kwolf@redhat.com>

When adding an Error parameter, bdrv_replace_in_backing_chain() would
become nothing more than a wrapper around change_parent_backing_link().
So make the latter public, renamed as bdrv_replace_node(), and remove
bdrv_replace_in_backing_chain().

Most of the callers just remove a node from the graph that they just
inserted, so they can use &error_abort, but completion of a mirror job
with 'replaces' set can actually fail.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 block.c                   | 25 ++++++-------------------
 block/mirror.c            | 15 +++++++++------
 blockdev.c                |  2 +-
 include/block/block.h     |  4 ++--
 include/block/block_int.h |  4 ++--
 5 files changed, 20 insertions(+), 30 deletions(-)

diff --git a/block.c b/block.c
index a310132..dd9ded8 100644
--- a/block.c
+++ b/block.c
@@ -2932,8 +2932,8 @@ static bool should_update_child(BdrvChild *c, BlockDriverState *to)
     return true;
 }
 
-static void change_parent_backing_link(BlockDriverState *from,
-                                       BlockDriverState *to, Error **errp)
+void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to,
+                       Error **errp)
 {
     BdrvChild *c, *next;
     GSList *list = NULL, *p;
@@ -2941,6 +2941,9 @@ static void change_parent_backing_link(BlockDriverState *from,
     uint64_t perm = 0, shared = BLK_PERM_ALL;
     int ret;
 
+    assert(!atomic_read(&from->in_flight));
+    assert(!atomic_read(&to->in_flight));
+
     /* Make sure that @from doesn't go away until we have successfully attached
      * all of its parents to @to. */
     bdrv_ref(from);
@@ -3003,16 +3006,13 @@ void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top,
 {
     Error *local_err = NULL;
 
-    assert(!atomic_read(&bs_top->in_flight));
-    assert(!atomic_read(&bs_new->in_flight));
-
     bdrv_set_backing_hd(bs_new, bs_top, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         goto out;
     }
 
-    change_parent_backing_link(bs_top, bs_new, &local_err);
+    bdrv_replace_node(bs_top, bs_new, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         bdrv_set_backing_hd(bs_new, NULL, &error_abort);
@@ -3025,19 +3025,6 @@ out:
     bdrv_unref(bs_new);
 }
 
-void bdrv_replace_in_backing_chain(BlockDriverState *old, BlockDriverState *new)
-{
-    assert(!bdrv_requests_pending(old));
-    assert(!bdrv_requests_pending(new));
-
-    bdrv_ref(old);
-
-    /* FIXME Proper error handling */
-    change_parent_backing_link(old, new, &error_abort);
-
-    bdrv_unref(old);
-}
-
 static void bdrv_delete(BlockDriverState *bs)
 {
     assert(!bs->job);
diff --git a/block/mirror.c b/block/mirror.c
index f24dc51..a5d30ee 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -550,8 +550,12 @@ static void mirror_exit(BlockJob *job, void *opaque)
         /* The mirror job has no requests in flight any more, but we need to
          * drain potential other users of the BDS before changing the graph. */
         bdrv_drained_begin(target_bs);
-        bdrv_replace_in_backing_chain(to_replace, target_bs);
+        bdrv_replace_node(to_replace, target_bs, &local_err);
         bdrv_drained_end(target_bs);
+        if (local_err) {
+            error_report_err(local_err);
+            data->ret = -EPERM;
+        }
     }
     if (s->to_replace) {
         bdrv_op_unblock_all(s->to_replace, s->replace_blocker);
@@ -570,12 +574,11 @@ static void mirror_exit(BlockJob *job, void *opaque)
      * block the removal. */
     block_job_remove_all_bdrv(job);
     bdrv_child_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL);
-    bdrv_replace_in_backing_chain(mirror_top_bs, backing_bs(mirror_top_bs));
+    bdrv_replace_node(mirror_top_bs, backing_bs(mirror_top_bs), &error_abort);
 
     /* We just changed the BDS the job BB refers to (with either or both of the
-     * bdrv_replace_in_backing_chain() calls), so switch the BB back so the
-     * cleanup does the right thing. We don't need any permissions any more
-     * now. */
+     * bdrv_replace_node() calls), so switch the BB back so the cleanup does
+     * the right thing. We don't need any permissions any more now. */
     blk_remove_bs(job->blk);
     blk_set_perm(job->blk, 0, BLK_PERM_ALL, &error_abort);
     blk_insert_bs(job->blk, mirror_top_bs, &error_abort);
@@ -1234,7 +1237,7 @@ fail:
     }
 
     bdrv_child_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL);
-    bdrv_replace_in_backing_chain(mirror_top_bs, backing_bs(mirror_top_bs));
+    bdrv_replace_node(mirror_top_bs, backing_bs(mirror_top_bs), &error_abort);
 }
 
 void mirror_start(const char *job_id, BlockDriverState *bs,
diff --git a/blockdev.c b/blockdev.c
index af67ce4..f1f49bd 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1806,7 +1806,7 @@ static void external_snapshot_abort(BlkActionState *common)
                              DO_UPCAST(ExternalSnapshotState, common, common);
     if (state->new_bs) {
         if (state->overlay_appended) {
-            bdrv_replace_in_backing_chain(state->new_bs, state->old_bs);
+            bdrv_replace_node(state->new_bs, state->old_bs, &error_abort);
         }
     }
 }
diff --git a/include/block/block.h b/include/block/block.h
index c7c4a3a..5149260 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -238,8 +238,8 @@ int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp);
 BlockDriverState *bdrv_new(void);
 void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top,
                  Error **errp);
-void bdrv_replace_in_backing_chain(BlockDriverState *old,
-                                   BlockDriverState *new);
+void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to,
+                       Error **errp);
 
 int bdrv_parse_cache_mode(const char *mode, int *flags, bool *writethrough);
 int bdrv_parse_discard_flags(const char *mode, int *flags);
diff --git a/include/block/block_int.h b/include/block/block_int.h
index fc83f7f..6c699ac 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -441,8 +441,8 @@ typedef struct BdrvAioNotifier {
 } BdrvAioNotifier;
 
 struct BdrvChildRole {
-    /* If true, bdrv_replace_in_backing_chain() doesn't change the node this
-     * BdrvChild points to. */
+    /* If true, bdrv_replace_node() doesn't change the node this BdrvChild
+     * points to. */
     bool stay_at_node;
 
     void (*inherit_options)(int *child_flags, QDict *child_options,
-- 
1.8.3.1

  parent reply	other threads:[~2017-03-07 15:41 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-07 15:40 [Qemu-devel] [PULL 00/27] Block layer fixes for 2.9.0-rc0 Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 01/27] commit: Fix error handling Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 02/27] mirror: Fix permission problem with 'replaces' Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 03/27] mirror: Fix permissions for removing mirror_top_bs Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 04/27] mirror: Fix error path for dirty bitmap creation Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 05/27] block: Fix blockdev-snapshot error handling Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 06/27] block: Factor out should_update_child() Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 07/27] block: Factor out bdrv_replace_child_noperm() Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 08/27] block: Ignore multiple children in bdrv_check_update_perm() Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 09/27] block: Handle permission errors in change_parent_backing_link() Kevin Wolf
2017-03-07 15:40 ` Kevin Wolf [this message]
2017-03-07 15:40 ` [Qemu-devel] [PULL 11/27] sheepdog: Defuse time bomb in sd_open() error handling Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 12/27] sheepdog: Fix error handling in sd_snapshot_delete() Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 13/27] sheepdog: Fix error handling sd_create() Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 14/27] sheepdog: Mark sd_snapshot_delete() lossage FIXME Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 15/27] sheepdog: Fix snapshot ID parsing in _open(), _create, _goto() Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 16/27] sheepdog: Don't truncate long VDI name in _open(), _create() Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 17/27] sheepdog: Report errors in pseudo-filename more usefully Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 18/27] sheepdog: Use SocketAddress and socket_connect() Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 19/27] sheepdog: Implement bdrv_parse_filename() Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 20/27] gluster: Drop assumptions on SocketTransport names Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 21/27] gluster: Don't duplicate qapi-util.c's qapi_enum_parse() Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 22/27] gluster: Plug memory leaks in qemu_gluster_parse_json() Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 23/27] qapi-schema: Rename GlusterServer to SocketAddressFlat Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 24/27] qapi-schema: Rename SocketAddressFlat's variant tcp to inet Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 25/27] sheepdog: Support blockdev-add Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 26/27] block: Don't use error_abort in blk_new_open Kevin Wolf
2017-03-07 15:40 ` [Qemu-devel] [PULL 27/27] commit: Don't use error_abort in commit_start Kevin Wolf
2017-03-08 14:49 ` [Qemu-devel] [PULL 00/27] Block layer fixes for 2.9.0-rc0 Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1488901251-16214-11-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).