diff options
Diffstat (limited to 'migration')
-rw-r--r-- | migration/block.c | 5 | ||||
-rw-r--r-- | migration/block.h | 45 | ||||
-rw-r--r-- | migration/channel.c | 1 | ||||
-rw-r--r-- | migration/colo.c | 4 | ||||
-rw-r--r-- | migration/exec.c | 1 | ||||
-rw-r--r-- | migration/exec.h | 26 | ||||
-rw-r--r-- | migration/fd.c | 1 | ||||
-rw-r--r-- | migration/fd.h | 23 | ||||
-rw-r--r-- | migration/migration.c | 25 | ||||
-rw-r--r-- | migration/postcopy-ram.c | 4 | ||||
-rw-r--r-- | migration/qemu-file-channel.c | 3 | ||||
-rw-r--r-- | migration/qemu-file.c | 2 | ||||
-rw-r--r-- | migration/qemu-file.h | 160 | ||||
-rw-r--r-- | migration/ram.c | 4 | ||||
-rw-r--r-- | migration/ram.h | 70 | ||||
-rw-r--r-- | migration/rdma.c | 5 | ||||
-rw-r--r-- | migration/rdma.h | 25 | ||||
-rw-r--r-- | migration/savevm.c | 71 | ||||
-rw-r--r-- | migration/socket.c | 3 | ||||
-rw-r--r-- | migration/socket.h | 28 | ||||
-rw-r--r-- | migration/tls.c | 1 | ||||
-rw-r--r-- | migration/tls.h | 34 | ||||
-rw-r--r-- | migration/vmstate-types.c | 3 | ||||
-rw-r--r-- | migration/vmstate.c | 2 |
24 files changed, 482 insertions, 64 deletions
diff --git a/migration/block.c b/migration/block.c index 13f90d3f17..4d8c2e94b9 100644 --- a/migration/block.c +++ b/migration/block.c @@ -23,10 +23,11 @@ #include "qemu/cutils.h" #include "qemu/queue.h" #include "qemu/timer.h" -#include "migration/block.h" +#include "block.h" +#include "migration/misc.h" #include "migration/migration.h" #include "sysemu/blockdev.h" -#include "migration/qemu-file.h" +#include "qemu-file.h" #include "migration/vmstate.h" #include "sysemu/block-backend.h" diff --git a/migration/block.h b/migration/block.h new file mode 100644 index 0000000000..22ebe94259 --- /dev/null +++ b/migration/block.h @@ -0,0 +1,45 @@ +/* + * QEMU live block migration + * + * Copyright IBM, Corp. 2009 + * + * Authors: + * Liran Schour <lirans@il.ibm.com> + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + */ + +#ifndef MIGRATION_BLOCK_H +#define MIGRATION_BLOCK_H + +#ifdef CONFIG_LIVE_BLOCK_MIGRATION +int blk_mig_active(void); +uint64_t blk_mig_bytes_transferred(void); +uint64_t blk_mig_bytes_remaining(void); +uint64_t blk_mig_bytes_total(void); + +#else +static inline int blk_mig_active(void) +{ + return false; +} +static inline uint64_t blk_mig_bytes_transferred(void) +{ + return 0; +} + +static inline uint64_t blk_mig_bytes_remaining(void) +{ + return 0; +} + +static inline uint64_t blk_mig_bytes_total(void) +{ + return 0; +} +#endif /* CONFIG_LIVE_BLOCK_MIGRATION */ + +void migrate_set_block_enabled(bool value, Error **errp); +#endif /* MIGRATION_BLOCK_H */ diff --git a/migration/channel.c b/migration/channel.c index 2e78905cc7..eae1d9e28a 100644 --- a/migration/channel.c +++ b/migration/channel.c @@ -12,6 +12,7 @@ #include "qemu/osdep.h" #include "channel.h" +#include "tls.h" #include "migration/migration.h" #include "qemu-file-channel.h" #include "trace.h" diff --git a/migration/colo.c b/migration/colo.c index 3dd1390573..111b715546 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -15,10 +15,10 @@ #include "sysemu/sysemu.h" #include "qemu-file-channel.h" #include "migration/migration.h" -#include "migration/qemu-file.h" +#include "qemu-file.h" #include "savevm.h" #include "migration/colo.h" -#include "migration/block.h" +#include "block.h" #include "io/channel-buffer.h" #include "trace.h" #include "qemu/error-report.h" diff --git a/migration/exec.c b/migration/exec.c index 57a93355d1..9077024286 100644 --- a/migration/exec.c +++ b/migration/exec.c @@ -21,6 +21,7 @@ #include "qapi/error.h" #include "qemu-common.h" #include "channel.h" +#include "exec.h" #include "migration/migration.h" #include "io/channel-command.h" #include "trace.h" diff --git a/migration/exec.h b/migration/exec.h new file mode 100644 index 0000000000..b210ffde7a --- /dev/null +++ b/migration/exec.h @@ -0,0 +1,26 @@ +/* + * QEMU live migration + * + * Copyright IBM, Corp. 2008 + * Copyright Dell MessageOne 2008 + * Copyright Red Hat, Inc. 2015-2016 + * + * Authors: + * Anthony Liguori <aliguori@us.ibm.com> + * Charles Duffy <charles_duffy@messageone.com> + * Daniel P. Berrange <berrange@redhat.com> + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + * Contributions after 2012-01-13 are licensed under the terms of the + * GNU GPL, version 2 or (at your option) any later version. + */ + +#ifndef QEMU_MIGRATION_EXEC_H +#define QEMU_MIGRATION_EXEC_H +void exec_start_incoming_migration(const char *host_port, Error **errp); + +void exec_start_outgoing_migration(MigrationState *s, const char *host_port, + Error **errp); +#endif diff --git a/migration/fd.c b/migration/fd.c index 05e0a5cca8..0077a505a3 100644 --- a/migration/fd.c +++ b/migration/fd.c @@ -18,6 +18,7 @@ #include "qapi/error.h" #include "qemu-common.h" #include "channel.h" +#include "fd.h" #include "migration/migration.h" #include "monitor/monitor.h" #include "io/channel-util.h" diff --git a/migration/fd.h b/migration/fd.h new file mode 100644 index 0000000000..a14a63ce2e --- /dev/null +++ b/migration/fd.h @@ -0,0 +1,23 @@ +/* + * QEMU live migration via generic fd + * + * Copyright Red Hat, Inc. 2009-2016 + * + * Authors: + * Chris Lalancette <clalance@redhat.com> + * Daniel P. Berrange <berrange@redhat.com> + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + * Contributions after 2012-01-13 are licensed under the terms of the + * GNU GPL, version 2 or (at your option) any later version. + */ + +#ifndef QEMU_MIGRATION_FD_H +#define QEMU_MIGRATION_FD_H +void fd_start_incoming_migration(const char *path, Error **errp); + +void fd_start_outgoing_migration(MigrationState *s, const char *fdname, + Error **errp); +#endif diff --git a/migration/migration.c b/migration/migration.c index 7087d1abbb..48c94c9ca1 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -18,10 +18,15 @@ #include "qemu/error-report.h" #include "qemu/main-loop.h" #include "migration/blocker.h" +#include "exec.h" +#include "fd.h" +#include "socket.h" +#include "rdma.h" +#include "ram.h" #include "migration/migration.h" #include "savevm.h" #include "qemu-file-channel.h" -#include "migration/qemu-file.h" +#include "qemu-file.h" #include "migration/vmstate.h" #include "sysemu/sysemu.h" #include "block/block.h" @@ -29,7 +34,7 @@ #include "qapi/util.h" #include "qemu/sockets.h" #include "qemu/rcu.h" -#include "migration/block.h" +#include "block.h" #include "postcopy-ram.h" #include "qemu/thread.h" #include "qmp-commands.h" @@ -40,7 +45,6 @@ #include "exec/address-spaces.h" #include "exec/target_page.h" #include "io/channel-buffer.h" -#include "io/channel-tls.h" #include "migration/colo.h" #define MAX_THROTTLE (32 << 20) /* Migration transfer speed throttling */ @@ -122,7 +126,6 @@ MigrationIncomingState *migration_incoming_get_current(void) if (!once) { mis_current.state = MIGRATION_STATUS_NONE; memset(&mis_current, 0, sizeof(MigrationIncomingState)); - QLIST_INIT(&mis_current.loadvm_handlers); qemu_mutex_init(&mis_current.rp_mutex); qemu_event_init(&mis_current.main_thread_load_event, false); once = true; @@ -134,8 +137,19 @@ void migration_incoming_state_destroy(void) { struct MigrationIncomingState *mis = migration_incoming_get_current(); + if (mis->to_src_file) { + /* Tell source that we are done */ + migrate_send_rp_shut(mis, qemu_file_get_error(mis->from_src_file) != 0); + qemu_fclose(mis->to_src_file); + mis->to_src_file = NULL; + } + + if (mis->from_src_file) { + qemu_fclose(mis->from_src_file); + mis->from_src_file = NULL; + } + qemu_event_destroy(&mis->main_thread_load_event); - loadvm_free_handlers(mis); } @@ -432,7 +446,6 @@ static void process_incoming_migration_co(void *opaque) exit(EXIT_FAILURE); } - qemu_fclose(f); free_xbzrle_decoded_buf(); mis->bh = qemu_bh_new(process_incoming_migration_bh, mis); diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 3f9ae1bff2..9c4188724e 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -21,9 +21,10 @@ #include "qemu-common.h" #include "exec/target_page.h" #include "migration/migration.h" -#include "migration/qemu-file.h" +#include "qemu-file.h" #include "savevm.h" #include "postcopy-ram.h" +#include "ram.h" #include "sysemu/sysemu.h" #include "sysemu/balloon.h" #include "qemu/error-report.h" @@ -333,7 +334,6 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingState *mis) } postcopy_state_set(POSTCOPY_INCOMING_END); - migrate_send_rp_shut(mis, qemu_file_get_error(mis->from_src_file) != 0); if (mis->postcopy_tmp_page) { munmap(mis->postcopy_tmp_page, mis->largest_page_size); diff --git a/migration/qemu-file-channel.c b/migration/qemu-file-channel.c index dc991c9051..e202d73834 100644 --- a/migration/qemu-file-channel.c +++ b/migration/qemu-file-channel.c @@ -24,7 +24,8 @@ #include "qemu/osdep.h" #include "qemu-file-channel.h" -#include "migration/qemu-file.h" +#include "exec/cpu-common.h" +#include "qemu-file.h" #include "io/channel-socket.h" #include "qemu/iov.h" diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 195fa94fcf..ab26f4eea9 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -29,7 +29,7 @@ #include "qemu/sockets.h" #include "qemu/coroutine.h" #include "migration/migration.h" -#include "migration/qemu-file.h" +#include "qemu-file.h" #include "trace.h" #define IO_BUF_SIZE 32768 diff --git a/migration/qemu-file.h b/migration/qemu-file.h new file mode 100644 index 0000000000..49fd6978ac --- /dev/null +++ b/migration/qemu-file.h @@ -0,0 +1,160 @@ +/* + * QEMU System Emulator + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MIGRATION_QEMU_FILE_H +#define MIGRATION_QEMU_FILE_H + +/* Read a chunk of data from a file at the given position. The pos argument + * can be ignored if the file is only be used for streaming. The number of + * bytes actually read should be returned. + */ +typedef ssize_t (QEMUFileGetBufferFunc)(void *opaque, uint8_t *buf, + int64_t pos, size_t size); + +/* Close a file + * + * Return negative error number on error, 0 or positive value on success. + * + * The meaning of return value on success depends on the specific back-end being + * used. + */ +typedef int (QEMUFileCloseFunc)(void *opaque); + +/* Called to return the OS file descriptor associated to the QEMUFile. + */ +typedef int (QEMUFileGetFD)(void *opaque); + +/* Called to change the blocking mode of the file + */ +typedef int (QEMUFileSetBlocking)(void *opaque, bool enabled); + +/* + * This function writes an iovec to file. The handler must write all + * of the data or return a negative errno value. + */ +typedef ssize_t (QEMUFileWritevBufferFunc)(void *opaque, struct iovec *iov, + int iovcnt, int64_t pos); + +/* + * This function provides hooks around different + * stages of RAM migration. + * 'opaque' is the backend specific data in QEMUFile + * 'data' is call specific data associated with the 'flags' value + */ +typedef int (QEMURamHookFunc)(QEMUFile *f, void *opaque, uint64_t flags, + void *data); + +/* + * Constants used by ram_control_* hooks + */ +#define RAM_CONTROL_SETUP 0 +#define RAM_CONTROL_ROUND 1 +#define RAM_CONTROL_HOOK 2 +#define RAM_CONTROL_FINISH 3 +#define RAM_CONTROL_BLOCK_REG 4 + +/* + * This function allows override of where the RAM page + * is saved (such as RDMA, for example.) + */ +typedef size_t (QEMURamSaveFunc)(QEMUFile *f, void *opaque, + ram_addr_t block_offset, + ram_addr_t offset, + size_t size, + uint64_t *bytes_sent); + +/* + * Return a QEMUFile for comms in the opposite direction + */ +typedef QEMUFile *(QEMURetPathFunc)(void *opaque); + +/* + * Stop any read or write (depending on flags) on the underlying + * transport on the QEMUFile. + * Existing blocking reads/writes must be woken + * Returns 0 on success, -err on error + */ +typedef int (QEMUFileShutdownFunc)(void *opaque, bool rd, bool wr); + +typedef struct QEMUFileOps { + QEMUFileGetBufferFunc *get_buffer; + QEMUFileCloseFunc *close; + QEMUFileSetBlocking *set_blocking; + QEMUFileWritevBufferFunc *writev_buffer; + QEMURetPathFunc *get_return_path; + QEMUFileShutdownFunc *shut_down; +} QEMUFileOps; + +typedef struct QEMUFileHooks { + QEMURamHookFunc *before_ram_iterate; + QEMURamHookFunc *after_ram_iterate; + QEMURamHookFunc *hook_ram_load; + QEMURamSaveFunc *save_page; +} QEMUFileHooks; + +QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops); +void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks); +int qemu_get_fd(QEMUFile *f); +int qemu_fclose(QEMUFile *f); +int64_t qemu_ftell(QEMUFile *f); +int64_t qemu_ftell_fast(QEMUFile *f); +/* + * put_buffer without copying the buffer. + * The buffer should be available till it is sent asynchronously. + */ +void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, size_t size, + bool may_free); +bool qemu_file_mode_is_not_valid(const char *mode); +bool qemu_file_is_writable(QEMUFile *f); + +#include "migration/qemu-file-types.h" + +size_t qemu_peek_buffer(QEMUFile *f, uint8_t **buf, size_t size, size_t offset); +size_t qemu_get_buffer_in_place(QEMUFile *f, uint8_t **buf, size_t size); +ssize_t qemu_put_compression_data(QEMUFile *f, const uint8_t *p, size_t size, + int level); +int qemu_put_qemu_file(QEMUFile *f_des, QEMUFile *f_src); + +/* + * Note that you can only peek continuous bytes from where the current pointer + * is; you aren't guaranteed to be able to peak to +n bytes unless you've + * previously peeked +n-1. + */ +int qemu_peek_byte(QEMUFile *f, int offset); +void qemu_file_skip(QEMUFile *f, int size); +void qemu_update_position(QEMUFile *f, size_t size); +void qemu_file_reset_rate_limit(QEMUFile *f); +void qemu_file_set_rate_limit(QEMUFile *f, int64_t new_rate); +int64_t qemu_file_get_rate_limit(QEMUFile *f); +int qemu_file_get_error(QEMUFile *f); +void qemu_file_set_error(QEMUFile *f, int ret); +int qemu_file_shutdown(QEMUFile *f); +QEMUFile *qemu_file_get_return_path(QEMUFile *f); +void qemu_fflush(QEMUFile *f); +void qemu_file_set_blocking(QEMUFile *f, bool block); + +size_t qemu_get_counted_string(QEMUFile *f, char buf[256]); + + +#endif diff --git a/migration/ram.c b/migration/ram.c index 26e03a5dfa..f387e9cc5b 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -36,8 +36,10 @@ #include "qemu/timer.h" #include "qemu/main-loop.h" #include "xbzrle.h" +#include "ram.h" #include "migration/migration.h" -#include "migration/qemu-file.h" +#include "migration/misc.h" +#include "qemu-file.h" #include "migration/vmstate.h" #include "postcopy-ram.h" #include "exec/address-spaces.h" diff --git a/migration/ram.h b/migration/ram.h new file mode 100644 index 0000000000..c9563d10ac --- /dev/null +++ b/migration/ram.h @@ -0,0 +1,70 @@ +/* + * QEMU System Emulator + * + * Copyright (c) 2003-2008 Fabrice Bellard + * Copyright (c) 2011-2015 Red Hat Inc + * + * Authors: + * Juan Quintela <quintela@redhat.com> + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef QEMU_MIGRATION_RAM_H +#define QEMU_MIGRATION_RAM_H + +#include "qemu-common.h" +#include "exec/cpu-common.h" + +int64_t xbzrle_cache_resize(int64_t new_size); +uint64_t dup_mig_pages_transferred(void); +uint64_t norm_mig_pages_transferred(void); +uint64_t xbzrle_mig_bytes_transferred(void); +uint64_t xbzrle_mig_pages_transferred(void); +uint64_t xbzrle_mig_pages_cache_miss(void); +double xbzrle_mig_cache_miss_rate(void); +uint64_t xbzrle_mig_pages_overflow(void); +uint64_t ram_bytes_transferred(void); +uint64_t ram_bytes_remaining(void); +uint64_t ram_dirty_sync_count(void); +uint64_t ram_dirty_pages_rate(void); +uint64_t ram_postcopy_requests(void); +uint64_t ram_bytes_total(void); + +void migrate_compress_threads_create(void); +void migrate_compress_threads_join(void); +void migrate_decompress_threads_create(void); +void migrate_decompress_threads_join(void); + +uint64_t ram_pagesize_summary(void); +void migration_page_queue_free(void); +int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len); +void acct_update_position(QEMUFile *f, size_t size, bool zero); +void free_xbzrle_decoded_buf(void); +void ram_debug_dump_bitmap(unsigned long *todump, bool expected, + unsigned long pages); +void ram_postcopy_migrated_memory_release(MigrationState *ms); +/* For outgoing discard bitmap */ +int ram_postcopy_send_discard_bitmap(MigrationState *ms); +/* For incoming postcopy discard */ +int ram_discard_range(const char *block_name, uint64_t start, size_t length); +int ram_postcopy_incoming_init(MigrationIncomingState *mis); + +void ram_handle_compressed(void *host, uint8_t ch, uint64_t size); +#endif diff --git a/migration/rdma.c b/migration/rdma.c index 166cd60a77..e446c6fd6a 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -17,9 +17,10 @@ #include "qapi/error.h" #include "qemu-common.h" #include "qemu/cutils.h" +#include "rdma.h" #include "migration/migration.h" -#include "migration/qemu-file.h" -#include "exec/cpu-common.h" +#include "qemu-file.h" +#include "ram.h" #include "qemu-file-channel.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" diff --git a/migration/rdma.h b/migration/rdma.h new file mode 100644 index 0000000000..de2ba09dc5 --- /dev/null +++ b/migration/rdma.h @@ -0,0 +1,25 @@ +/* + * RDMA protocol and interfaces + * + * Copyright IBM, Corp. 2010-2013 + * Copyright Red Hat, Inc. 2015-2016 + * + * Authors: + * Michael R. Hines <mrhines@us.ibm.com> + * Jiuxing Liu <jl@us.ibm.com> + * Daniel P. Berrange <berrange@redhat.com> + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + * + */ + +#ifndef QEMU_MIGRATION_RDMA_H +#define QEMU_MIGRATION_RDMA_H + +void rdma_start_outgoing_migration(void *opaque, const char *host_port, + Error **errp); + +void rdma_start_incoming_migration(const char *host_port, Error **errp); + +#endif diff --git a/migration/savevm.c b/migration/savevm.c index a2d4f9c53c..9c320f59d0 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -35,7 +35,10 @@ #include "sysemu/sysemu.h" #include "qemu/timer.h" #include "migration/migration.h" +#include "migration/snapshot.h" +#include "ram.h" #include "qemu-file-channel.h" +#include "qemu-file.h" #include "savevm.h" #include "postcopy-ram.h" #include "qapi/qmp/qerror.h" @@ -272,7 +275,11 @@ typedef struct SaveStateEntry { int instance_id; int alias_id; int version_id; + /* version id read from the stream */ + int load_version_id; int section_id; + /* section id read from the stream */ + int load_section_id; SaveVMHandlers *ops; const VMStateDescription *vmsd; void *opaque; @@ -742,13 +749,13 @@ void vmstate_unregister(DeviceState *dev, const VMStateDescription *vmsd, } } -static int vmstate_load(QEMUFile *f, SaveStateEntry *se, int version_id) +static int vmstate_load(QEMUFile *f, SaveStateEntry *se) { trace_vmstate_load(se->idstr, se->vmsd ? se->vmsd->name : "(old)"); if (!se->vmsd) { /* Old style */ - return se->ops->load_state(f, se->opaque, version_id); + return se->ops->load_state(f, se->opaque, se->load_version_id); } - return vmstate_load_state(f, se->vmsd, se->opaque, version_id); + return vmstate_load_state(f, se->vmsd, se->opaque, se->load_version_id); } static void vmstate_save_old_style(QEMUFile *f, SaveStateEntry *se, QJSON *vmdesc) @@ -1800,20 +1807,13 @@ static int loadvm_process_command(QEMUFile *f) return 0; } -struct LoadStateEntry { - QLIST_ENTRY(LoadStateEntry) entry; - SaveStateEntry *se; - int section_id; - int version_id; -}; - /* * Read a footer off the wire and check that it matches the expected section * * Returns: true if the footer was good * false if there is a problem (and calls error_report to say why) */ -static bool check_section_footer(QEMUFile *f, LoadStateEntry *le) +static bool check_section_footer(QEMUFile *f, SaveStateEntry *se) { uint8_t read_mark; uint32_t read_section_id; @@ -1826,15 +1826,15 @@ static bool check_section_footer(QEMUFile *f, LoadStateEntry *le) read_mark = qemu_get_byte(f); if (read_mark != QEMU_VM_SECTION_FOOTER) { - error_report("Missing section footer for %s", le->se->idstr); + error_report("Missing section footer for %s", se->idstr); return false; } read_section_id = qemu_get_be32(f); - if (read_section_id != le->section_id) { + if (read_section_id != se->load_section_id) { error_report("Mismatched section id in footer for %s -" " read 0x%x expected 0x%x", - le->se->idstr, read_section_id, le->section_id); + se->idstr, read_section_id, se->load_section_id); return false; } @@ -1842,22 +1842,11 @@ static bool check_section_footer(QEMUFile *f, LoadStateEntry *le) return true; } -void loadvm_free_handlers(MigrationIncomingState *mis) -{ - LoadStateEntry *le, *new_le; - - QLIST_FOREACH_SAFE(le, &mis->loadvm_handlers, entry, new_le) { - QLIST_REMOVE(le, entry); - g_free(le); - } -} - static int qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis) { uint32_t instance_id, version_id, section_id; SaveStateEntry *se; - LoadStateEntry *le; char idstr[256]; int ret; @@ -1887,6 +1876,8 @@ qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis) version_id, idstr, se->version_id); return -EINVAL; } + se->load_version_id = version_id; + se->load_section_id = section_id; /* Validate if it is a device's state */ if (xen_enabled() && se->is_ram) { @@ -1894,21 +1885,13 @@ qemu_loadvm_section_start_full(QEMUFile *f, MigrationIncomingState *mis) return -EINVAL; } - /* Add entry */ - le = g_malloc0(sizeof(*le)); - - le->se = se; - le->section_id = section_id; - le->version_id = version_id; - QLIST_INSERT_HEAD(&mis->loadvm_handlers, le, entry); - - ret = vmstate_load(f, le->se, le->version_id); + ret = vmstate_load(f, se); if (ret < 0) { error_report("error while loading state for instance 0x%x of" " device '%s'", instance_id, idstr); return ret; } - if (!check_section_footer(f, le)) { + if (!check_section_footer(f, se)) { return -EINVAL; } @@ -1919,29 +1902,29 @@ static int qemu_loadvm_section_part_end(QEMUFile *f, MigrationIncomingState *mis) { uint32_t section_id; - LoadStateEntry *le; + SaveStateEntry *se; int ret; section_id = qemu_get_be32(f); trace_qemu_loadvm_state_section_partend(section_id); - QLIST_FOREACH(le, &mis->loadvm_handlers, entry) { - if (le->section_id == section_id) { + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + if (se->load_section_id == section_id) { break; } } - if (le == NULL) { + if (se == NULL) { error_report("Unknown savevm section %d", section_id); return -EINVAL; } - ret = vmstate_load(f, le->se, le->version_id); + ret = vmstate_load(f, se); if (ret < 0) { error_report("error while loading state section id %d(%s)", - section_id, le->se->idstr); + section_id, se->idstr); return ret; } - if (!check_section_footer(f, le)) { + if (!check_section_footer(f, se)) { return -EINVAL; } @@ -2086,7 +2069,7 @@ int qemu_loadvm_state(QEMUFile *f) return ret; } -int save_vmstate(const char *name, Error **errp) +int save_snapshot(const char *name, Error **errp) { BlockDriverState *bs, *bs1; QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1; @@ -2243,7 +2226,7 @@ void qmp_xen_load_devices_state(const char *filename, Error **errp) migration_incoming_state_destroy(); } -int load_vmstate(const char *name, Error **errp) +int load_snapshot(const char *name, Error **errp) { BlockDriverState *bs, *bs_vm_state; QEMUSnapshotInfo sn; diff --git a/migration/socket.c b/migration/socket.c index 53f9d61605..85bfdccae1 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -20,8 +20,9 @@ #include "qemu/error-report.h" #include "qapi/error.h" #include "channel.h" +#include "socket.h" #include "migration/migration.h" -#include "migration/qemu-file.h" +#include "qemu-file.h" #include "io/channel-socket.h" #include "trace.h" diff --git a/migration/socket.h b/migration/socket.h new file mode 100644 index 0000000000..6b91e9db38 --- /dev/null +++ b/migration/socket.h @@ -0,0 +1,28 @@ +/* + * QEMU live migration via socket + * + * Copyright Red Hat, Inc. 2009-2016 + * + * Authors: + * Chris Lalancette <clalance@redhat.com> + * Daniel P. Berrange <berrange@redhat.com> + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + * Contributions after 2012-01-13 are licensed under the terms of the + * GNU GPL, version 2 or (at your option) any later version. + */ + +#ifndef QEMU_MIGRATION_SOCKET_H +#define QEMU_MIGRATION_SOCKET_H +void tcp_start_incoming_migration(const char *host_port, Error **errp); + +void tcp_start_outgoing_migration(MigrationState *s, const char *host_port, + Error **errp); + +void unix_start_incoming_migration(const char *path, Error **errp); + +void unix_start_outgoing_migration(MigrationState *s, const char *path, + Error **errp); +#endif diff --git a/migration/tls.c b/migration/tls.c index 34ad121abf..bae9acad6c 100644 --- a/migration/tls.c +++ b/migration/tls.c @@ -21,6 +21,7 @@ #include "qemu/osdep.h" #include "channel.h" #include "migration/migration.h" +#include "tls.h" #include "io/channel-tls.h" #include "crypto/tlscreds.h" #include "qemu/error-report.h" diff --git a/migration/tls.h b/migration/tls.h new file mode 100644 index 0000000000..cdd70001ed --- /dev/null +++ b/migration/tls.h @@ -0,0 +1,34 @@ +/* + * QEMU migration TLS support + * + * Copyright (c) 2015 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see <http://www.gnu.org/licenses/>. + * + */ + +#ifndef QEMU_MIGRATION_TLS_H +#define QEMU_MIGRATION_TLS_H + +#include "io/channel.h" + +void migration_tls_channel_process_incoming(MigrationState *s, + QIOChannel *ioc, + Error **errp); + +void migration_tls_channel_connect(MigrationState *s, + QIOChannel *ioc, + const char *hostname, + Error **errp); +#endif diff --git a/migration/vmstate-types.c b/migration/vmstate-types.c index cc95e47775..7287c6baa6 100644 --- a/migration/vmstate-types.c +++ b/migration/vmstate-types.c @@ -12,8 +12,9 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "exec/cpu-common.h" +#include "qemu-file.h" #include "migration/migration.h" -#include "migration/qemu-file.h" #include "migration/vmstate.h" #include "qemu/error-report.h" #include "qemu/queue.h" diff --git a/migration/vmstate.c b/migration/vmstate.c index ff54531b44..51a19b668a 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -13,8 +13,8 @@ #include "qemu/osdep.h" #include "qemu-common.h" #include "migration/migration.h" -#include "migration/qemu-file.h" #include "migration/vmstate.h" +#include "qemu-file.h" #include "qemu/bitops.h" #include "qemu/error-report.h" #include "trace.h" |