qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael R. Hines" <mrhines@linux.vnet.ibm.com>
To: Lei Li <lilei@linux.vnet.ibm.com>
Cc: aarcange@redhat.com, aliguori@us.ibm.com, quintela@redhat.com,
	qemu-devel@nongnu.org, lagarcia@br.ibm.com, pbonzini@redhat.com,
	rcj@linux.vnet.ibm.com
Subject: Re: [Qemu-devel] [PATCH 09/12] migration-local: implementation of outgoing part
Date: Fri, 02 Aug 2013 15:45:11 -0400	[thread overview]
Message-ID: <51FC0C47.3090601@linux.vnet.ibm.com> (raw)
In-Reply-To: <1374783499-2550-10-git-send-email-lilei@linux.vnet.ibm.com>

On 07/25/2013 04:18 PM, Lei Li wrote:
> Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
> ---
>   Makefile.objs                 |    1 +
>   include/migration/migration.h |   15 ++++
>   migration-local.c             |  158 +++++++++++++++++++++++++++++++++++++++++
>   migration-unix.c              |   13 ++++
>   qapi-schema.json              |   14 ++++
>   qmp-commands.hx               |   22 ++++++
>   6 files changed, 223 insertions(+), 0 deletions(-)
>   create mode 100644 migration-local.c
>
> diff --git a/Makefile.objs b/Makefile.objs
> index 5b288ba..2a3d9a5 100644
> --- a/Makefile.objs
> +++ b/Makefile.objs
> @@ -53,6 +53,7 @@ common-obj-$(CONFIG_LINUX) += fsdev/
>   common-obj-y += migration.o migration-tcp.o
>   common-obj-y += qemu-char.o #aio.o
>   common-obj-y += block-migration.o
> +common-obj-y += migration-local.o
>   common-obj-y += page_cache.o xbzrle.o
>
>   common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
> diff --git a/include/migration/migration.h b/include/migration/migration.h
> index a821c80..a690e18 100644
> --- a/include/migration/migration.h
> +++ b/include/migration/migration.h
> @@ -58,6 +58,17 @@ struct MigrationState
>       int64_t xbzrle_cache_size;
>   };
>
> +
> +typedef struct LocalMigState LocalMigState;
> +
> +struct LocalMigState
> +{
> +    int fd;
> +    int state;
> +    QEMUFile *file;
> +    QemuThread thread;
> +};
> +
>   void process_incoming_migration(QEMUFile *f);
>
>   void qemu_start_incoming_migration(const char *uri, Error **errp);
> @@ -80,6 +91,8 @@ void unix_start_incoming_migration(const char *path, Error **errp);
>
>   void unix_start_outgoing_migration(MigrationState *s, const char *path, Error **errp);
>
> +void unix_start_local_outgoing_migration(LocalMigState *s, const char *path, Error **errp);
> +
>   void fd_start_incoming_migration(const char *path, Error **errp);
>
>   void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp);
> @@ -88,6 +101,8 @@ void migrate_fd_error(MigrationState *s);
>
>   void migrate_fd_connect(MigrationState *s);
>
> +void local_migration_fd_connect(LocalMigState *s);
> +
>   int migrate_fd_close(MigrationState *s);
>
>   void add_migration_state_change_notifier(Notifier *notify);
> diff --git a/migration-local.c b/migration-local.c
> new file mode 100644
> index 0000000..5bd1ed0
> --- /dev/null
> +++ b/migration-local.c
> @@ -0,0 +1,158 @@
> +/*
> + * QEMU localhost migration
> + *
> + * Copyright IBM, Corp. 2013
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2.  See
> + * the COPYING file in the top-level directory.
> + *
> + * Contributions are licensed under the terms of the GNU GPL, version 2
> + * or (at your option) any later version.
> + */
> +
> +#include "qemu-common.h"
> +#include "migration/migration.h"
> +#include "monitor/monitor.h"
> +#include "migration/qemu-file.h"
> +#include "sysemu/sysemu.h"
> +#include "block/block.h"
> +#include "qemu/sockets.h"
> +#include "migration/block.h"
> +#include "qemu/thread.h"
> +#include "qmp-commands.h"
> +#include "exec/memory.h"
> +#include "trace.h"
> +#include "qemu/osdep.h"
> +
> +//#define DEBUG_MIGRATION_LOCAL
> +
> +#ifdef DEBUG_MIGRATION_LOCAL
> +#define DPRINTF(fmt, ...) \
> +    do { printf("migration-local: " fmt, ## __VA_ARGS__); } while (0)
> +#else
> +#define DPRINTF(fmt, ...) \
> +    do { } while (0)
> +#endif
> +
> +
> +/************************************************************************
> + * Outgoing part
> + */
> +
> +static LocalMigState *local_migration_init(void)
> +{
> +    LocalMigState *s = g_malloc0(sizeof(*s));
> +
> +    s->state = MIG_STATE_SETUP;
> +    trace_migrate_set_state(MIG_STATE_SETUP);
> +    s->fd = -1;
> +
> +    return s;
> +}
> +
> +static void local_migration_error(LocalMigState *s)
> +{
> +    assert(s->file == NULL);
> +
> +    s->state = MIG_STATE_ERROR;
> +    trace_migrate_set_state(MIG_STATE_ERROR);
> +}
> +
> +static void local_outgoing_completed(LocalMigState *s)
> +{
> +    s->state = MIG_STATE_COMPLETED;
> +    trace_migrate_set_state(MIG_STATE_COMPLETED);
> +}
> +
> +static void *migration_local_thread(void *opaque)
> +{
> +    LocalMigState *s = opaque;
> +    int ret;
> +
> +    DPRINTF("Beginning savevm\n");
> +
> +    while (s->state == MIG_STATE_ACTIVE) {
> +        qemu_mutex_lock_iothread();
> +        ret = qemu_savevm_local(s->file);
> +        qemu_mutex_unlock_iothread();
> +
> +        /* No need to send device states if ram pages fails to to sent. */
> +        if (ret < 0) {
> +            local_migration_error(s);
> +            break;
> +        }
> +
> +        qemu_save_device_state(s->file);
> +        qemu_fclose(s->file);
> +    }
> +
> +    ret = qemu_file_get_error(s->file);
> +    if (ret < 0) {
> +        local_migration_error(s);
> +    } else {
> +        local_outgoing_completed(s);
> +    }
> +
> +    qemu_mutex_lock_iothread();
> +
> +    if (s->state == MIG_STATE_COMPLETED) {
> +        runstate_set(RUN_STATE_POSTMIGRATE);
> +    }
> +
> +    qemu_mutex_unlock_iothread();
> +
> +    return NULL;
> +}
> +
> +void local_migration_fd_connect(LocalMigState *s)
> +{
> +    s->state = MIG_STATE_ACTIVE;
> +    trace_migrate_set_state(MIG_STATE_ACTIVE);
> +
> +    qemu_thread_create(&s->thread, migration_local_thread, s,
> +                       QEMU_THREAD_JOINABLE);
> +}
> +
> +void qmp_localhost_migrate(const char *uri, Error **errp)
> +{
> +    const char *path;
> +    Error *local_err = NULL;
> +    int is_vm_running;
> +    LocalMigState *s;
> +
> +    if (qemu_savevm_state_blocked(errp)) {
> +        return;
> +    }
> +
> +    s = local_migration_init();
> +    bdrv_flush_all();
> +
> +    is_vm_running = runstate_is_running();
> +
> +    /* Stop the VM first */
> +    if (is_vm_running) {
> +        vm_stop(RUN_STATE_SAVE_VM);
> +    }
> +
> +    /* Start outgoing migration by unix socket. */
> +    if (strstart(uri, "unix:", &path)) {
> +        /* XXX. Creat a new unix_start_outgoing_migration_* is not necessary,
> +         * just for the first step. This will be replaced by vmsplice
> +         * mechanism. */
> +        unix_start_local_outgoing_migration(s, path, &local_err);
> +    } else {
> +        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "uri", "a valid migration protocol");
> +        goto fail;
> +    }
> +
> +    if (local_err) {
> +        s->state = MIG_STATE_ERROR;
> +        error_propagate(errp, local_err);
> +        goto fail;
> +    }
> +
> +fail:
> +    if (!is_vm_running) {
> +        vm_start();
> +    }
> +}
> diff --git a/migration-unix.c b/migration-unix.c
> index 94b7022..ec20c45 100644
> --- a/migration-unix.c
> +++ b/migration-unix.c
> @@ -49,6 +49,19 @@ void unix_start_outgoing_migration(MigrationState *s, const char *path, Error **
>       unix_nonblocking_connect(path, unix_wait_for_connect, s, errp);
>   }
>
> +void unix_start_local_outgoing_migration(LocalMigState *s, const char *path, Error **errp)
> +{
> +    s->fd = unix_connect(path, errp);
> +    if (s->fd < 0) {
> +        s->file = NULL;
> +        /* There should be a fd_error_set function */
> +        s->state = MIG_STATE_ERROR;
> +    } else {
> +        s->file = qemu_fopen_socket(s->fd, "wb");
> +        local_migration_fd_connect(s);
> +    }
> +}
> +
>   static void unix_accept_incoming_migration(void *opaque)
>   {
>       struct sockaddr_un addr;
> diff --git a/qapi-schema.json b/qapi-schema.json
> index a80ee40..7431a41 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -2336,6 +2336,20 @@
>   { 'command': 'migrate',
>     'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool', '*detach': 'bool' } }
>
> +##
> +# @localhost-migrate
> +#
> +# Migrates the current running guest to the localhost VM.
> +#
> +# @uri: the Uniform Resource Identifier of the destination VM
> +#
> +# Returns: nothing on success
> +#
> +# Since: 1.7
> +##
> +{ 'command': 'localhost-migrate',
> +  'data': {'uri': 'str'} }
> +
>   # @xen-save-devices-state:
>   #
>   # Save the state of all devices to file. The RAM and the block devices
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index 8cea5e5..aba2327 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -640,6 +640,28 @@ Notes:
>   EQMP
>
>       {
> +        .name      = "localhost-migrate",
> +        .args_type = "uri:s",
> +        .mhandler.cmd_new = qmp_marshal_input_localhost_migrate,
> +    },
> +
> +SQMP
> +localhost-migrate
> +
> +Migrate VM in localhost.
> +
> +Arguments:
> +
> +- "uri": Destination URI (json-string)
> +
> +Example:
> +
> +-> { "execute": "localhost-migrate", "arguments": { "uri": "UNIX-SOCKET" }
> +<- { "return": {} }
> +
> +EQMP
> +
> +    {
>           .name       = "migrate_cancel",
>           .args_type  = "",
>           .mhandler.cmd_new = qmp_marshal_input_migrate_cancel,

Why a separate thread? What's wrong with modifying the existing 
migration_thread() ?

- Michael

  reply	other threads:[~2013-08-02 19:45 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-25 20:18 [Qemu-devel] [PATCH 0/12 RFC v2] Localhost migration Lei Li
2013-07-25 20:18 ` [Qemu-devel] [PATCH 01/12] migration: export MIG_STATE_xxx flags Lei Li
2013-07-25 20:18 ` [Qemu-devel] [PATCH 02/12] savevm: export qemu_save_device_state() Lei Li
2013-07-25 20:18 ` [Qemu-devel] [PATCH 03/12] rename is_active to is_block_active Lei Li
2013-07-25 20:18 ` [Qemu-devel] [PATCH 04/12] arch_init: introduce ram_page_save() Lei Li
2013-08-02 19:40   ` Michael R. Hines
2013-08-05  2:49     ` Lei Li
2013-07-25 20:18 ` [Qemu-devel] [PATCH 05/12] arch_init: introduce ram_save_local() Lei Li
2013-08-02 19:42   ` Michael R. Hines
2013-08-05  3:27     ` Lei Li
2013-07-25 20:18 ` [Qemu-devel] [PATCH 06/12] arch_init: add save_local_setup to savevm_ram_handlers Lei Li
2013-08-02 19:43   ` Michael R. Hines
2013-07-25 20:18 ` [Qemu-devel] [PATCH 07/12] savevm: introduce qemu_savevm_local() Lei Li
2013-08-02 19:48   ` Michael R. Hines
2013-08-05  3:02     ` Lei Li
2013-07-25 20:18 ` [Qemu-devel] [PATCH 08/12] savevm: adjust is_ram check in register_savevm_live() Lei Li
2013-07-25 20:18 ` [Qemu-devel] [PATCH 09/12] migration-local: implementation of outgoing part Lei Li
2013-08-02 19:45   ` Michael R. Hines [this message]
2013-08-05  3:18     ` Lei Li
2013-07-25 20:18 ` [Qemu-devel] [PATCH 10/12] migration-local: implementation of incoming part Lei Li
2013-07-25 20:18 ` [Qemu-devel] [PATCH 11/12] migration-local: add option to commandline for incoming-local Lei Li
2013-08-02 19:46   ` Michael R. Hines
2013-08-05  3:21     ` Lei Li
2013-07-25 20:18 ` [Qemu-devel] [PATCH 12/12] hmp: add hmp_localhost_migration interface Lei Li
2013-08-02 19:47   ` Michael R. Hines
2013-08-05  3:22     ` Lei Li
2013-07-26  9:41 ` [Qemu-devel] [PATCH 0/12 RFC v2] Localhost migration Paolo Bonzini
2013-08-05  8:56   ` Lei Li

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=51FC0C47.3090601@linux.vnet.ibm.com \
    --to=mrhines@linux.vnet.ibm.com \
    --cc=aarcange@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=lagarcia@br.ibm.com \
    --cc=lilei@linux.vnet.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=rcj@linux.vnet.ibm.com \
    /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).