qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert (git)" <dgilbert@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 11/15] migration: re-active images while migration been canceled after inactive them
Date: Tue, 24 Jan 2017 18:47:38 +0000	[thread overview]
Message-ID: <20170124184742.1639-12-dgilbert@redhat.com> (raw)
In-Reply-To: <20170124184742.1639-1-dgilbert@redhat.com>

From: zhanghailiang <zhang.zhanghailiang@huawei.com>

commit fe904ea8242cbae2d7e69c052c754b8f5f1ba1d6 fixed a case
which migration aborted QEMU because it didn't regain the control
of images while some errors happened.

Actually, there are another two cases can trigger the same error reports:
" bdrv_co_do_pwritev: Assertion `!(bs->open_flags & 0x0800)' failed",

Case 1, codes path:
migration_thread()
    migration_completion()
        bdrv_inactivate_all() ----------------> inactivate images
        qemu_savevm_state_complete_precopy()
            socket_writev_buffer() --------> error because destination fails
                qemu_fflush() ----------------> set error on migration stream
-> qmp_migrate_cancel() ----------------> user cancelled migration concurrently
    -> migrate_set_state() ------------------> set migrate CANCELLIN
    migration_completion() -----------------> go on to fail_invalidate
	if (s->state == MIGRATION_STATUS_ACTIVE) -> Jump this branch

Case 2, codes path:
migration_thread()
    migration_completion()
        bdrv_inactivate_all() ----------------> inactivate images
    migreation_completion() finished
-> qmp_migrate_cancel() ---------------> user cancelled migration concurrently
    qemu_mutex_lock_iothread();
    qemu_bh_schedule (s->cleanup_bh);

As we can see from above, qmp_migrate_cancel can slip in whenever
migration_thread does not hold the global lock. If this happens after
bdrv_inactive_all() been called, the above error reports will appear.

To prevent this, we can call bdrv_invalidate_cache_all() in qmp_migrate_cancel()
directly if we find images become inactive.

Besides, bdrv_invalidate_cache_all() in migration_completion() doesn't have the
protection of big lock, fix it by add the missing qemu_mutex_lock_iothread();

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
Message-Id: <1485244792-11248-1-git-send-email-zhang.zhanghailiang@huawei.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 include/migration/migration.h |  3 +++
 migration/migration.c         | 15 +++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/include/migration/migration.h b/include/migration/migration.h
index 7881e89..af9135f 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -180,6 +180,9 @@ struct MigrationState
     /* Flag set once the migration thread is running (and needs joining) */
     bool migration_thread_running;
 
+    /* Flag set once the migration thread called bdrv_inactivate_all */
+    bool block_inactive;
+
     /* Queue of outstanding page requests from the destination */
     QemuMutex src_page_req_mutex;
     QSIMPLEQ_HEAD(src_page_requests, MigrationSrcPageRequest) src_page_requests;
diff --git a/migration/migration.c b/migration/migration.c
index 7dcb7d7..f8a4500 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1006,6 +1006,16 @@ static void migrate_fd_cancel(MigrationState *s)
     if (s->state == MIGRATION_STATUS_CANCELLING && f) {
         qemu_file_shutdown(f);
     }
+    if (s->state == MIGRATION_STATUS_CANCELLING && s->block_inactive) {
+        Error *local_err = NULL;
+
+        bdrv_invalidate_cache_all(&local_err);
+        if (local_err) {
+            error_report_err(local_err);
+        } else {
+            s->block_inactive = false;
+        }
+    }
 }
 
 void add_migration_state_change_notifier(Notifier *notify)
@@ -1745,6 +1755,7 @@ static void migration_completion(MigrationState *s, int current_active_state,
             if (ret >= 0) {
                 qemu_file_set_rate_limit(s->to_dst_file, INT64_MAX);
                 qemu_savevm_state_complete_precopy(s->to_dst_file, false);
+                s->block_inactive = true;
             }
         }
         qemu_mutex_unlock_iothread();
@@ -1795,10 +1806,14 @@ fail_invalidate:
     if (s->state == MIGRATION_STATUS_ACTIVE) {
         Error *local_err = NULL;
 
+        qemu_mutex_lock_iothread();
         bdrv_invalidate_cache_all(&local_err);
         if (local_err) {
             error_report_err(local_err);
+        } else {
+            s->block_inactive = false;
         }
+        qemu_mutex_unlock_iothread();
     }
 
 fail:
-- 
2.9.3

  parent reply	other threads:[~2017-01-24 18:47 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-24 18:47 [Qemu-devel] [PULL 00/15] migration queue Dr. David Alan Gilbert (git)
2017-01-24 18:47 ` [Qemu-devel] [PULL 01/15] MAINTAINERS: Add myself as a migration submaintainer Dr. David Alan Gilbert (git)
2017-01-24 18:47 ` [Qemu-devel] [PULL 02/15] migration: extend VMStateInfo Dr. David Alan Gilbert (git)
2017-01-25 11:46   ` Fam Zheng
2017-01-25 12:00     ` Dr. David Alan Gilbert
2017-01-25 12:07       ` Cornelia Huck
2017-01-25 12:12       ` Fam Zheng
2017-01-25 12:19       ` Cornelia Huck
2017-01-25 13:22         ` Dr. David Alan Gilbert
2017-01-25 14:20           ` Cornelia Huck
2017-01-25 14:44             ` Dr. David Alan Gilbert
2017-01-26 12:14               ` Cornelia Huck
2017-01-27 18:20                 ` Dr. David Alan Gilbert
2017-02-01 10:18                   ` Cornelia Huck
2017-01-24 18:47 ` [Qemu-devel] [PULL 03/15] migration: migrate QTAILQ Dr. David Alan Gilbert (git)
2017-01-24 18:47 ` [Qemu-devel] [PULL 04/15] tests/migration: Add test for QTAILQ migration Dr. David Alan Gilbert (git)
2017-01-24 18:47 ` [Qemu-devel] [PULL 05/15] migration: add error_report Dr. David Alan Gilbert (git)
2017-01-24 18:47 ` [Qemu-devel] [PULL 06/15] block/vvfat: Remove the undesirable comment Dr. David Alan Gilbert (git)
2017-01-24 18:47 ` [Qemu-devel] [PULL 07/15] migration: Add a new option to enable only-migratable Dr. David Alan Gilbert (git)
2017-01-24 18:47 ` [Qemu-devel] [PULL 08/15] migration: Allow "device add" options to only add migratable devices Dr. David Alan Gilbert (git)
2017-01-24 18:47 ` [Qemu-devel] [PULL 09/15] migration: disallow migrate_add_blocker during migration Dr. David Alan Gilbert (git)
2017-01-24 18:47 ` [Qemu-devel] [PULL 10/15] migration: Fail migration blocker for --only-migratable Dr. David Alan Gilbert (git)
2017-01-24 18:47 ` Dr. David Alan Gilbert (git) [this message]
2017-01-24 18:47 ` [Qemu-devel] [PULL 12/15] migration: Change name of live migration thread Dr. David Alan Gilbert (git)
2017-01-24 18:47 ` [Qemu-devel] [PULL 13/15] PCI/migration merge vmstate_pci_device and vmstate_pcie_device Dr. David Alan Gilbert (git)
2017-01-24 18:47 ` [Qemu-devel] [PULL 14/15] migration: transform remaining DPRINTF into trace_ Dr. David Alan Gilbert (git)
2017-01-24 18:47 ` [Qemu-devel] [PULL 15/15] migration/tracing: Add tracing on save Dr. David Alan Gilbert (git)
2017-01-25 10:41 ` [Qemu-devel] [PULL 00/15] migration queue 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=20170124184742.1639-12-dgilbert@redhat.com \
    --to=dgilbert@redhat.com \
    --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).