Commit Graph

107 Commits

Author SHA1 Message Date
Benoît Canet 901862cbf4 migration: clear BDRV_O_INCOMING flags on end of incoming live migration
Signed-off-by: Benoît Canet <benoit.canet@gmail.com>
Reviewed-by: Stefan Hajnoczi <stefanha@gmail.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-04-05 16:28:49 +02:00
Luiz Capitulino e1c37d0e94 qapi: Convert migrate
The migrate command is one of those commands where HMP and QMP completely
mix up together. This made the conversion to the QAPI (which separates the
command into QMP and HMP parts) a bit difficult.

The first important change to be noticed is that this commit completes the
removal of the Monitor object from migration code, started by the previous
commit.

Another important and tricky change is about supporting the non-detached
mode. That is, if the user doesn't pass '-d' the migrate command will lock
the monitor and will only release it when migration is finished.

To support this in the new HMP command (hmp_migrate()), it is necessary
to create a timer which runs every second and checks if the migration is
still active. If it is, the timer callback will re-schedule itself to run
one second in the future. If the migration has already finished, the
monitor lock is released and the user can use it normally.

All these changes should be transparent to the user.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2012-03-15 10:39:52 -03:00
Luiz Capitulino 539de1246d Purge migration of (almost) everything to do with monitors
The Monitor object is passed back and forth within the migration/savevm
code so that it can print errors and progress to the user.

However, that approach assumes a HMP monitor, being completely invalid
in QMP.

This commit drops almost every single usage of the Monitor object, all
monitor_printf() calls have been converted into DPRINTF() ones.

There are a few remaining Monitor objects, those are going to be dropped
by the next commit.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2012-03-15 10:39:52 -03:00
Paolo Bonzini 31552529a7 notifier: switch to QLIST
Notifiers do not need to access both ends of the list, and using
a QLIST also simplifies the API.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-17 08:33:32 -06:00
Paolo Bonzini 6b620ca3b0 prepare for future GPLv2+ relicensing
All files under GPLv2 will get GPLv2+ changes starting tomorrow.
event_notifier.c and exec-obsolete.h were only ever touched by Red Hat
employees and can be relicensed now.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-01-13 10:55:56 -06:00
Eduardo Habkost a6d34a949c migrate_fd_cleanup: accept any negative qemu_fclose() value as error
Also, we now return the qemu_fclose() value unchanged to the caller. For
reference, the migrate_fd_cleanup() callers are the following:

- migrate_fd_completed(): any negative value is considered an
  error, so the change is OK.
- migrate_fd_error(): doesn't check the migrate_fd_cleanup() return value
- migrate_fd_cancel(): doesn't check the migrate_fd_cleanup() return
  value

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-12-12 11:47:19 -06:00
Luiz Capitulino 3dc853832d qapi: Convert migrate_set_speed
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2011-12-06 11:40:01 -02:00
Luiz Capitulino 4f0a993bf3 qapi: Convert migrate_set_downtime
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2011-12-06 11:40:01 -02:00
Luiz Capitulino 6cdedb075f qapi: Convert migrate_cancel
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2011-12-06 11:40:01 -02:00
Anthony Liguori 0f15423c32 block: allow migration to work with image files (v3)
Image files have two types of data: immutable data that describes things like
image size, backing files, etc. and mutable data that includes offset and
reference count tables.

Today, image formats aggressively cache mutable data to improve performance.  In
some cases, this happens before a guest even starts.  When dealing with live
migration, since a file is open on two machines, the caching of meta data can
lead to data corruption.

This patch addresses this by introducing a mechanism to invalidate any cached
mutable data a block driver may have which is then used by the live migration
code.

NB, this still requires coherent shared storage.  Addressing migration without
coherent shared storage (i.e. NFS) requires additional work.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-11-21 14:58:48 -06:00
Anthony Liguori fa2756b71b migrate: add migration blockers
This lets different subsystems register an Error that is thrown whenever
migration is attempted.  This works nicely because it gracefully supports
things like hotplug.

Right now, if multiple errors are registered, only one of them is reported.
I expect that for 1.1, we'll extend query-migrate to return all of the reasons
why migration is disabled at any given point in time.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-11-21 14:57:22 -06:00
Juan Quintela 1299c63168 migration: fix detached migration with fd
Migration with fd uses s->mon to pass the fd.  But we only assign the
s->mon for !detached migration.  Fix it.  Once there add a comment
indicating that s->mon has two uses.

Bug reported by:  Wen Congyang <wency@cn.fujitsu.com>

Signed-off-by: Juan Quintela <quintela@redhat.com>
CC:  Wen Congyang <wency@cn.fujitsu.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-11-11 12:49:51 -06:00
Luiz Capitulino 1fdc11c369 Fix segfault on migration completion
A simple migration reproduces it:

1. Start the source VM with:

   # qemu [...] -S

2. Start the destination VM with:

   # qemu <source VM cmd-line> -incoming tcp:0:4444

3. In the source VM:

   (qemu) migrate -d tcp:0:4444

4. The source VM will segfault as soon as migration completes (might not
   happen in the first try)

What is happening here is that qemu_file_put_notify() can end up closing
's->file' (in which case it's also set to NULL). The call stack is rather
complex, but Eduardo helped tracking it to:

select loop -> migrate_fd_put_notify() -> qemu_file_put_notify() ->
buffered_put_buffer() -> migrate_fd_put_ready() ->
migrate_fd_completed() -> migrate_fd_cleanup().

To be honest, it's not completely clear to me in which cases 's->file'
is not closed (on error maybe)? But I doubt this fix will make anything
worse.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Acked-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-11-01 11:50:12 -05:00
Anthony Liguori 96b3d73f5a Merge remote-tracking branch 'qmp/queue/qmp' into staging
Conflicts:
	ui/spice-core.c
2011-10-31 11:02:29 -05:00
Luiz Capitulino 791e7c820e qapi: Convert query-migrate
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2011-10-27 11:48:46 -02:00
Gerd Hoffmann afe2df69cf migration: add status query functions
Add migration_is_active and migration_has_failed functions
to query migration state.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-10-25 13:59:25 +02:00
Anthony Liguori a6e43daa73 Merge remote-tracking branch 'quintela/migration-pull' into staging 2011-10-20 08:46:55 -05:00
Juan Quintela 7dc688ed71 migration: Make state definitions local
Signed-off-by: Juan Quintela <quintela@redhat.com>
2011-10-20 13:23:54 +02:00
Juan Quintela 7073693bfb migration: Export a function that tells if the migration has finished correctly
This will allow us to hide the state values.

Signed-off-by: Juan Quintela <quintela@redhat.com>
2011-10-20 13:23:54 +02:00
Juan Quintela e0eb7390b0 migration: Pass MigrationState in migration notifiers
Signed-off-by: Juan Quintela <quintela@redhat.com>
2011-10-20 13:23:54 +02:00
Juan Quintela d0ae46c197 migration: Use bandwidth_limit directly
Now that current_migration always exist, there is no reason for
max_throotle variable.

Signed-off-by: Juan Quintela <quintela@redhat.com>
2011-10-20 13:23:54 +02:00
Juan Quintela 17549e84e0 migration: create accessor for current_migration
Signed-off-by: Juan Quintela <quintela@redhat.com>
2011-10-20 13:23:54 +02:00
Juan Quintela cab3014333 migration: Move exported functions to the end of the file
This means we can remove the two forward declarations.

Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
2011-10-20 13:23:54 +02:00
Juan Quintela 767de72258 migration: Remove migration cancel() callback
It is used only in one place

Signed-off-by: Juan Quintela <quintela@redhat.com>
2011-10-20 13:23:54 +02:00
Juan Quintela 48a2f4d6c5 migration: Remove get_status() accessor
It is only used inside migration.c, and fields on that struct are
accessed all around the place on that file.

Signed-off-by: Juan Quintela <quintela@redhat.com>
2011-10-20 13:23:54 +02:00
Juan Quintela 92920cd782 migration: Our release callback was just free
We called it from a single place, and always with state !=
MIG_STATE_ACTIVE.  Just remove the whole callback.  For users of the
notifier, notice that this is exactly the case where they don't care,
we are just freeing the state from previous failed migration (it can't
be a sucessful one, otherwise we would not be running on that machine
in the first place).

Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
2011-10-20 13:23:53 +02:00
Juan Quintela 458cf28e6b migration: Introduce migrate_fd_completed() for consistency
This function is a bit different of the others that change the state,
in the sense that if migrate_fd_cleanup() returns an error, it set the
status to error, not completed.

Signed-off-by: Juan Quintela <quintela@redhat.com>
2011-10-20 13:23:53 +02:00
Juan Quintela 67afff7911 migration: Refactor and simplify error checking in migrate_fd_put_ready
Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
2011-10-20 13:23:53 +02:00
Juan Quintela d5934dde1c migration: Introduce MIG_STATE_SETUP
Use MIG_STATE_ACTIVE only when migration has really started.  Use this
new state to setup migration parameters.  Change defines for an
anonymous struct.

Signed-off-by: Juan Quintela <quintela@redhat.com>
2011-10-20 13:23:53 +02:00
Juan Quintela 07af445291 migration: move migrate_new to do_migrate
Once there, remove all parameters that don't need to be passed to
*start_outgoing_migration() functions

Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
2011-10-20 13:23:53 +02:00
Juan Quintela 8b6b99b356 migration: Make all posible migration functions static
I have to move two functions postions to avoid forward declarations

Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
2011-10-20 13:23:53 +02:00
Juan Quintela 0edda1c42a migration: Refactor MigrationState creation
Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
2011-10-20 13:23:53 +02:00
Juan Quintela 22f00a4445 migration: Rename FdMigrationState MigrationState
Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
2011-10-20 13:23:53 +02:00
Juan Quintela 3f77fc557e migration: Fold MigrationState into FdMigrationState
Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
2011-10-20 13:23:53 +02:00
Juan Quintela dc7acc61b6 migration: Use FdMigrationState instead of MigrationState when possible
Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
2011-10-20 13:23:52 +02:00
Juan Quintela 7be4363a28 migration: Make *start_outgoing_migration return FdMigrationState
Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
2011-10-20 13:23:52 +02:00
Juan Quintela 624b9cc209 migration: rename qemu_file_has_error to qemu_file_get_error
Now the function returned errno, so it is better the new name.

Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
2011-10-20 13:23:52 +02:00
Juan Quintela 3934638539 migration: return real error code
make functions propagate errno, instead of just using -EIO.  Add a
comment about what are the return value of qemu_savevm_state_iterate().

Signed-off-by: Juan Quintela <quintela@redhat.com>
2011-10-20 13:23:52 +02:00
Juan Quintela dcd1d224df migration: change has_error to contain errno values
We normally already have an errno value.  When not, abuse EIO.

Signed-off-by: Juan Quintela <quintela@redhat.com>
2011-10-20 13:23:52 +02:00
Juan Quintela af50945081 migration: set error if select return one error
Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
2011-10-20 13:23:51 +02:00
Juan Quintela fdbecb5d0e migration: don't "write" when migration is not active
If migration is not active, just ignore writes.

Signed-off-by: Juan Quintela <quintela@redhat.com>
2011-10-20 13:23:51 +02:00
Yoshiaki Tamura 2350e13c93 migration: add error handling to migrate_fd_put_notify().
Although migrate_fd_put_buffer() sets MIG_STATE_ERROR if it failed,
since migrate_fd_put_notify() isn't checking error of underlying
QEMUFile, those resources are kept open.  This patch checks it and
calls migrate_fd_error() in case of error.

Signed-off-by: Yoshiaki Tamura <tamura.yoshiaki@lab.ntt.co.jp>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
2011-10-20 13:23:51 +02:00
Juan Quintela e649406169 migration: Check that migration is active before cancel it
Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
2011-10-20 13:23:51 +02:00
Juan Quintela c0b2ba46c5 migration: simplify state assignmente
Once there, make sure that if we already know that there is one error,
just call migration_fd_cleanup() with the ERROR state.

Signed-off-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
2011-10-20 13:23:51 +02:00
Luiz Capitulino 8a9236f1d2 runstate: Allow user to migrate twice
It should be a matter of allowing the transition POSTMIGRATE ->
FINISH_MIGRATE, but it turns out that the VM won't do the
transition the second time because it's already stopped.

So this commit also adds vm_stop_force_state() which performs
the transition even if the VM is already stopped.

While there also allow other states to migrate.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2011-10-19 10:48:57 -02:00
Luiz Capitulino 0461d5a699 RunState: Rename enum values as generated by the QAPI
Next commit will convert the query-status command to use the
RunState type as generated by the QAPI.

In order to "transparently" replace the current enum by the QAPI
one, we have to make some changes to some enum values.

As the changes are simple renames, I'll do them in one shot. The
changes are:

 - Rename the prefix from RSTATE_ to RUN_STATE_
 - RUN_STATE_SAVEVM to RUN_STATE_SAVE_VM
 - RUN_STATE_IN_MIGRATE to RUN_STATE_INMIGRATE
 - RUN_STATE_PANICKED to RUN_STATE_INTERNAL_ERROR
 - RUN_STATE_POST_MIGRATE to RUN_STATE_POSTMIGRATE
 - RUN_STATE_PRE_LAUNCH to RUN_STATE_PRELAUNCH
 - RUN_STATE_PRE_MIGRATE to RUN_STATE_PREMIGRATE
 - RUN_STATE_RESTORE to RUN_STATE_RESTORE_VM
 - RUN_STATE_PRE_MIGRATE to RUN_STATE_FINISH_MIGRATE

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2011-10-04 11:02:57 -03:00
Luiz Capitulino 1354869c38 Drop the vm_running global variable
Use runstate_is_running() instead, which is introduced by this commit.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2011-09-15 16:39:32 -03:00
Luiz Capitulino 1bcef683bf Drop the incoming_expected global variable
Test against RSTATE_IN_MIGRATE instead.

Please, note that the RSTATE_IN_MIGRATE state is only set when all the
initial VM setup is done, while 'incoming_expected' was set right in
the beginning when parsing command-line options. Shouldn't be a problem
as far as I could check.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2011-09-15 16:39:32 -03:00
Luiz Capitulino f5bbfba1eb RunState: Add additional states
Currently, only vm_start() and vm_stop() change the VM state.
That's, the state is only changed when starting or stopping the VM.

This commit adds the runstate_set() function, which makes it possible
to also do state transitions when the VM is stopped or running.

Additional states are also added and the current state is stored.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2011-09-15 16:39:32 -03:00
Luiz Capitulino 1dfb4dd993 Replace the VMSTOP macros with a proper state type
Today, when notifying a VM state change with vm_state_notify(),
we pass a VMSTOP macro as the 'reason' argument. This is not ideal
because the VMSTOP macros tell why qemu stopped and not exactly
what the current VM state is.

One example to demonstrate this problem is that vm_start() calls
vm_state_notify() with reason=0, which turns out to be VMSTOP_USER.

This commit fixes that by replacing the VMSTOP macros with a proper
state type called RunState.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2011-09-15 16:39:32 -03:00