[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH FYI 32/46] migration: split migration hooks out of Q
From: |
Daniel P. Berrange |
Subject: |
[Qemu-devel] [PATCH FYI 32/46] migration: split migration hooks out of QEMUFileOps |
Date: |
Thu, 3 Sep 2015 16:39:14 +0100 |
The QEMUFileOps struct contains the I/O subsystem callbacks
and the migration stage hooks. Split the hooks out into a
separate QEMUFileHooks struct to make it easier to refactor
the I/O side of QEMUFile without affecting the hooks.
Signed-off-by: Daniel P. Berrange <address@hidden>
---
include/migration/qemu-file.h | 8 ++++++--
migration/qemu-file.c | 25 ++++++++++++++++---------
migration/rdma.c | 8 ++++++++
3 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h
index c020b01..f9242e8 100644
--- a/include/migration/qemu-file.h
+++ b/include/migration/qemu-file.h
@@ -102,12 +102,15 @@ typedef struct QEMUFileOps {
QEMUFileCloseFunc *close;
QEMUFileGetFD *get_fd;
QEMUFileWritevBufferFunc *writev_buffer;
+ QEMUFileShutdownFunc *shut_down;
+} QEMUFileOps;
+
+typedef struct QEMUFileHooks {
QEMURamHookFunc *before_ram_iterate;
QEMURamHookFunc *after_ram_iterate;
QEMURamHookFunc *hook_ram_load;
QEMURamSaveFunc *save_page;
- QEMUFileShutdownFunc *shut_down;
-} QEMUFileOps;
+} QEMUFileHooks;
struct QEMUSizedBuffer {
struct iovec *iov;
@@ -121,6 +124,7 @@ QEMUFile *qemu_fopen(const char *filename, const char
*mode);
QEMUFile *qemu_fdopen(int fd, const char *mode);
QEMUFile *qemu_fopen_socket(int fd, const char *mode);
QEMUFile *qemu_popen_cmd(const char *command, const char *mode);
+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);
diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index 3b281b2..d1d2c17 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -36,6 +36,7 @@
struct QEMUFile {
const QEMUFileOps *ops;
+ const QEMUFileHooks *hooks;
void *opaque;
int64_t bytes_xfer;
@@ -88,6 +89,12 @@ QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps
*ops)
return f;
}
+
+void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks)
+{
+ f->hooks = hooks;
+}
+
/*
* Get last error for stream f
*
@@ -149,8 +156,8 @@ void ram_control_before_iterate(QEMUFile *f, uint64_t flags)
{
int ret = 0;
- if (f->ops->before_ram_iterate) {
- ret = f->ops->before_ram_iterate(f, f->opaque, flags, NULL);
+ if (f->hooks && f->hooks->before_ram_iterate) {
+ ret = f->hooks->before_ram_iterate(f, f->opaque, flags, NULL);
if (ret < 0) {
qemu_file_set_error(f, ret);
}
@@ -161,8 +168,8 @@ void ram_control_after_iterate(QEMUFile *f, uint64_t flags)
{
int ret = 0;
- if (f->ops->after_ram_iterate) {
- ret = f->ops->after_ram_iterate(f, f->opaque, flags, NULL);
+ if (f->hooks && f->hooks->after_ram_iterate) {
+ ret = f->hooks->after_ram_iterate(f, f->opaque, flags, NULL);
if (ret < 0) {
qemu_file_set_error(f, ret);
}
@@ -173,8 +180,8 @@ void ram_control_load_hook(QEMUFile *f, uint64_t flags,
void *data)
{
int ret = -EINVAL;
- if (f->ops->hook_ram_load) {
- ret = f->ops->hook_ram_load(f, f->opaque, flags, data);
+ if (f->hooks && f->hooks->hook_ram_load) {
+ ret = f->hooks->hook_ram_load(f, f->opaque, flags, data);
if (ret < 0) {
qemu_file_set_error(f, ret);
}
@@ -193,9 +200,9 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t
block_offset,
ram_addr_t offset, size_t size,
uint64_t *bytes_sent)
{
- if (f->ops->save_page) {
- int ret = f->ops->save_page(f, f->opaque, block_offset,
- offset, size, bytes_sent);
+ if (f->hooks && f->hooks->save_page) {
+ int ret = f->hooks->save_page(f, f->opaque, block_offset,
+ offset, size, bytes_sent);
if (ret != RAM_SAVE_CONTROL_DELAYED) {
if (bytes_sent && *bytes_sent > 0) {
diff --git a/migration/rdma.c b/migration/rdma.c
index 9c64546..ca6b100 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -3380,12 +3380,18 @@ static const QEMUFileOps rdma_read_ops = {
.get_buffer = qemu_rdma_get_buffer,
.get_fd = qemu_rdma_get_fd,
.close = qemu_rdma_close,
+};
+
+static const QEMUFileHooks rdma_read_hooks = {
.hook_ram_load = rdma_load_hook,
};
static const QEMUFileOps rdma_write_ops = {
.put_buffer = qemu_rdma_put_buffer,
.close = qemu_rdma_close,
+};
+
+static const QEMUFileHooks rdma_write_hooks = {
.before_ram_iterate = qemu_rdma_registration_start,
.after_ram_iterate = qemu_rdma_registration_stop,
.save_page = qemu_rdma_save_page,
@@ -3404,8 +3410,10 @@ static void *qemu_fopen_rdma(RDMAContext *rdma, const
char *mode)
if (mode[0] == 'w') {
r->file = qemu_fopen_ops(r, &rdma_write_ops);
+ qemu_file_set_hooks(r->file, &rdma_write_hooks);
} else {
r->file = qemu_fopen_ops(r, &rdma_read_ops);
+ qemu_file_set_hooks(r->file, &rdma_read_hooks);
}
return r->file;
--
2.4.3
- [Qemu-devel] [PATCH FYI 22/46] char: introduce support for TLS encrypted TCP chardev backend, (continued)
- [Qemu-devel] [PATCH FYI 22/46] char: introduce support for TLS encrypted TCP chardev backend, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 20/46] char: convert from GIOChannel to QIOChannel, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 25/46] sockets: remove use of QemuOpts from header file, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 26/46] sockets: remove use of QemuOpts from socket_listen, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 28/46] sockets: remove use of QemuOpts from socket_dgram, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 27/46] sockets: remove use of QemuOpts from socket_connect, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 29/46] migration: remove use of qemu_bufopen from vmstate tests, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 31/46] migration: move definition of struct QEMUFile back into qemu-file.c, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 32/46] migration: split migration hooks out of QEMUFileOps,
Daniel P. Berrange <=
- [Qemu-devel] [PATCH FYI 30/46] migration: remove memory buffer based QEMUFile backend, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 33/46] migration: ensure qemu_fflush() always writes full data amount, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 34/46] migration: introduce qemu_fset_blocking function on QEMUFile, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 36/46] migration: introduce a new QEMUFile impl based on QIOChannel, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 35/46] migration: force QEMUFile to blocking mode for outgoing migration, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 37/46] migration: convert unix socket protocol to use QIOChannel, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 39/46] migration: convert fd socket protocol to use QIOChannel, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 38/46] migration: convert tcp socket protocol to use QIOChannel, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 42/46] migration: convert savevm to use QIOChannel for writing to files, Daniel P. Berrange, 2015/09/03
- [Qemu-devel] [PATCH FYI 40/46] migration: convert exec socket protocol to use QIOChannel, Daniel P. Berrange, 2015/09/03