diff options
Diffstat (limited to 'migration')
-rw-r--r-- | migration/qemu-file-internal.h | 1 | ||||
-rw-r--r-- | migration/qemu-file.c | 24 | ||||
-rw-r--r-- | migration/rdma.c | 8 |
3 files changed, 24 insertions, 9 deletions
diff --git a/migration/qemu-file-internal.h b/migration/qemu-file-internal.h index d95e8538e7..8fdfa95234 100644 --- a/migration/qemu-file-internal.h +++ b/migration/qemu-file-internal.h @@ -33,6 +33,7 @@ struct QEMUFile { const QEMUFileOps *ops; + const QEMUFileHooks *hooks; void *opaque; int64_t bytes_xfer; diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 656db4a04c..b480b7270c 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -80,6 +80,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 +155,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 +167,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 +179,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 +199,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 f6a9992b3e..0d067a1a51 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; |