diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2010-12-13 17:30:12 +0100 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2011-01-24 15:13:54 +0100 |
commit | 600d8eaef659cef6e6073764e56c86d1ac0350f9 (patch) | |
tree | b537aab449052a24a630f90ad3405c0d573644db /migration.c | |
parent | d2829d69d6b052efbea3667f007c286f690307d3 (diff) | |
download | qemu-600d8eaef659cef6e6073764e56c86d1ac0350f9.tar.gz qemu-600d8eaef659cef6e6073764e56c86d1ac0350f9.tar.bz2 qemu-600d8eaef659cef6e6073764e56c86d1ac0350f9.zip |
add migration state change notifiers
This patch adds functions to register and unregister notifiers for
migration state changes and a function to query the migration state.
The notifier is called on every state change. Once after establishing a
new migration object (which is in active state then) and once when the
state changes from active to completed, canceled or error.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'migration.c')
-rw-r--r-- | migration.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/migration.c b/migration.c index d593b1df5d..36125720a4 100644 --- a/migration.c +++ b/migration.c @@ -36,6 +36,9 @@ static int64_t max_throttle = (32 << 20); static MigrationState *current_migration; +static NotifierList migration_state_notifiers = + NOTIFIER_LIST_INITIALIZER(migration_state_notifiers); + int qemu_start_incoming_migration(const char *uri) { const char *p; @@ -121,6 +124,7 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data) } current_migration = s; + notifier_list_notify(&migration_state_notifiers); return 0; } @@ -272,6 +276,7 @@ void migrate_fd_error(FdMigrationState *s) { DPRINTF("setting error state\n"); s->state = MIG_STATE_ERROR; + notifier_list_notify(&migration_state_notifiers); migrate_fd_cleanup(s); } @@ -329,6 +334,7 @@ ssize_t migrate_fd_put_buffer(void *opaque, const void *data, size_t size) monitor_resume(s->mon); } s->state = MIG_STATE_ERROR; + notifier_list_notify(&migration_state_notifiers); } return ret; @@ -389,6 +395,7 @@ void migrate_fd_put_ready(void *opaque) state = MIG_STATE_ERROR; } s->state = state; + notifier_list_notify(&migration_state_notifiers); } } @@ -408,6 +415,7 @@ void migrate_fd_cancel(MigrationState *mig_state) DPRINTF("cancelling migration\n"); s->state = MIG_STATE_CANCELLED; + notifier_list_notify(&migration_state_notifiers); qemu_savevm_state_cancel(s->mon, s->file); migrate_fd_cleanup(s); @@ -421,6 +429,7 @@ void migrate_fd_release(MigrationState *mig_state) if (s->state == MIG_STATE_ACTIVE) { s->state = MIG_STATE_CANCELLED; + notifier_list_notify(&migration_state_notifiers); migrate_fd_cleanup(s); } qemu_free(s); @@ -452,3 +461,22 @@ int migrate_fd_close(void *opaque) qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); return s->close(s); } + +void add_migration_state_change_notifier(Notifier *notify) +{ + notifier_list_add(&migration_state_notifiers, notify); +} + +void remove_migration_state_change_notifier(Notifier *notify) +{ + notifier_list_remove(&migration_state_notifiers, notify); +} + +int get_migration_state(void) +{ + if (current_migration) { + return migrate_fd_get_status(current_migration); + } else { + return MIG_STATE_ERROR; + } +} |