qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Lei Li <lilei@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: aarcange@redhat.com, Lei Li <lilei@linux.vnet.ibm.com>,
	quintela@redhat.com, mdroth@linux.vnet.ibm.com,
	mrhines@linux.vnet.ibm.com, anthony@codemonkey.ws,
	lagarcia@br.ibm.com, pbonzini@redhat.com, rcj@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH 1/8] migration-local: add pipe protocol for QEMUFileOps
Date: Wed, 25 Sep 2013 22:32:41 +0800	[thread overview]
Message-ID: <1380119568-5530-2-git-send-email-lilei@linux.vnet.ibm.com> (raw)
In-Reply-To: <1380119568-5530-1-git-send-email-lilei@linux.vnet.ibm.com>

This patch adds QEMUFileOps with pipe protocol, will be used to
transmit RAM for localhost migration. The source process would put
buffer, correspondingly the destination process would get buffer.
The read side of the pipe file descriptor would be passed to destination
process via SCM_RIGHTS.

Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
---
 Makefile.target   |    1 +
 migration-local.c |  114 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 115 insertions(+), 0 deletions(-)
 create mode 100644 migration-local.c

diff --git a/Makefile.target b/Makefile.target
index 9a49852..ae66fef 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -121,6 +121,7 @@ obj-$(CONFIG_KVM) += kvm-all.o
 obj-y += memory.o savevm.o cputlb.o
 obj-y += memory_mapping.o
 obj-y += dump.o
+obj-y += migration-local.o
 LIBS+=$(libs_softmmu)
 
 # xen support
diff --git a/migration-local.c b/migration-local.c
new file mode 100644
index 0000000..1fb62b6
--- /dev/null
+++ b/migration-local.c
@@ -0,0 +1,114 @@
+/*
+ * QEMU localhost live migration
+ *
+ * Copyright IBM, Corp. 2013
+ *
+ * Authors:
+ *   Lei Li   <lilei@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "config-host.h"
+#include "qemu-common.h"
+#include "migration/migration.h"
+#include "exec/cpu-common.h"
+#include "config.h"
+#include "exec/cpu-all.h"
+#include "monitor/monitor.h"
+#include "migration/qemu-file.h"
+#include "qemu/iov.h"
+#include "sysemu/arch_init.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 "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
+
+typedef struct QEMUFilePipe {
+    QEMUFile *file;
+    int pipefd;
+} QEMUFilePipe;
+
+
+static int qemu_local_get_fd(void *opaque)
+{
+    QEMUFilePipe *s = opaque;
+
+    return s->pipefd;
+}
+
+static int qemu_local_get_buffer(void *opaque, uint8_t *buf,
+                                 int64_t pos, int size)
+{
+    QEMUFilePipe *s = opaque;
+    ssize_t len;
+
+    for (;;) {
+        errno = 0;
+
+        len = read(s->pipefd, buf, size);
+        if (len != -1) {
+            break;
+        }
+
+        if (errno == EAGAIN) {
+            yield_until_fd_readable(s->pipefd);
+        } else if (errno != EINTR) {
+            break;
+        }
+    }
+
+    return len;
+}
+
+static int qemu_local_put_buffer(void *opaque, const uint8_t *buf,
+                                 int64_t pos, int size)
+{
+    QEMUFilePipe *s = opaque;
+    ssize_t len;
+
+    len = write(s->pipefd, buf, size);
+    if (len < size) {
+        len = -1;
+    }
+
+    return len;
+}
+
+static int qemu_local_close(void *opaque)
+{
+    QEMUFilePipe *s = opaque;
+
+    close(s->pipefd);
+    g_free(s);
+
+    return 0;
+}
+
+static const QEMUFileOps pipe_read_ops = {
+    .get_fd     = qemu_local_get_fd,
+    .get_buffer = qemu_local_get_buffer,
+    .close      = qemu_local_close
+};
+
+static const QEMUFileOps pipe_write_ops = {
+    .put_buffer = qemu_local_put_buffer,
+    //.save_page  = qemu_local_save_ram,
+    .close      = qemu_local_close
+};
-- 
1.7.7.6

  reply	other threads:[~2013-09-25 14:33 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-25 14:32 [Qemu-devel] [PATCH 0/8 RFC] migration: Introduce side channel for RAM Lei Li
2013-09-25 14:32 ` Lei Li [this message]
2013-09-25 14:32 ` [Qemu-devel] [PATCH 2/8] migration-loca: add qemu_fopen_pipe() Lei Li
2013-09-25 14:32 ` [Qemu-devel] [PATCH 3/8] migration-local: add send_pipefd() Lei Li
2013-09-25 14:32 ` [Qemu-devel] [PATCH 4/8] migration-local: add recv_pipefd() Lei Li
2013-09-25 14:32 ` [Qemu-devel] [PATCH 5/8] QAPI: introduce magration capability unix_page_flipping Lei Li
2013-09-25 14:32 ` [Qemu-devel] [PATCH 6/8] migration: add migrate_unix_page_flipping() Lei Li
2013-09-25 14:32 ` [Qemu-devel] [PATCH 7/8] migration-unix: side channel support on unix outgoing Lei Li
2013-09-25 14:32 ` [Qemu-devel] [PATCH 8/8] migration-unix: side channel support on unix incoming Lei Li
2013-09-25 15:02 ` [Qemu-devel] [PATCH 0/8 RFC] migration: Introduce side channel for RAM Paolo Bonzini
2013-09-26 12:44   ` Lei Li
2013-09-26 12:54     ` Paolo Bonzini
2013-10-03  4:03     ` Lei Li
2013-10-03  8:23       ` Paolo Bonzini
2013-10-03 10:28         ` Lei Li
2013-10-03 10:34           ` Paolo Bonzini
2013-10-03 13:29             ` Lei Li
2013-10-03 13:34               ` Paolo Bonzini
2013-10-03 13:37                 ` 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=1380119568-5530-2-git-send-email-lilei@linux.vnet.ibm.com \
    --to=lilei@linux.vnet.ibm.com \
    --cc=aarcange@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=lagarcia@br.ibm.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=mrhines@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).