Convert migration to QIOChannel & support TLS
v2 cover Convert migration to QIOChannel & support TLS
This is an update of patches that were previously posted
FYI: https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg00829.html
v1: https://lists.gnu.org/archive/html/qemu-devel/2016-01/msg01914.html
The primary goal of this series of patches is to support TLS on the migration data channel. The bulk of the work in this series though, is converting the various QEMUFile implementations to be based on the new QIOChannel framework.
At the end of this current series there is just one remaining impl of QEMUFileOps that is not based on QIOChannel - the one in savevm.c that is using BlockDriverState. It would be possible to create a QIOChannel wrapper around BlockDriverState too, at which point all QEMUFile impls would be QIOChannel based. This would then let us cut out the QEMUFileOps driver callbacks entirely and thus simply code even more. This patch series is already too large, so I left that for now.
The first 6 patchs are some basic clean ups to QEMUFile code
The 7th patch introduces the QIOChannel based QEMUFile impl and the 8th adds helpers for using it to start migrations.
Patch 9 adds very long overdue support for reporting errors during migration back to the management app, which is critical for TLS otherwise it is impossible to debug any failures.
Patches 10-17 convert the various migration protocols to use the QIOChannel based QEMUFile impl. In this refactoring the TCP and UNIX implementations were able to be merged into a generic sockets impl.
Patches 18-21 remove the now unused QEMUFile impls that do not use QIOChanel
Patches 22 & 23 do some more cleanup
Patch 24 defines some new migration parameters which are used to enable use of TLS
Patch 25 actually implements support for TLS with migration, working with tcp, unix, fd and exec migration backend protocols. Only RDMA is unsupported with TLS. The commit message shows the example usage via the HMP
Patches 26 & 27 do some final cleanup.
Overall we have a net win of deleting ~350 lines of code, despite adding more features, which is always nice.
I have been testing the various migration protocols, including RDMA and appear to be still functional.
In terms of performance, I have tested TCP with TLS migration enabled over a 10 Gig-E network interface.
With plain TCP we were able to reach 8500mbs (according to 'info migrate' stats).
With TCP and TLS enabled, we are only able to reach 1800 mbs. IOW, we can max out 1 Gig-E NICs with TLS, but not 10 Gig-E where we only reach 21% of potential plain text throughput.
The source host migration thread is only hitting 60% CPU utilization, but the target host incoming migration thread is hitting 100% CPU.
The source migration thread is dominated solely by GNUTLS AES encryption functions as would be expected.
The target migration thread is dominated by the same GNUTLS AES encryption functions, but also memcpy(). IIUC, the memcpy is QEMU generic migration code copying RAM pages into place.
In talking with Dave Gilbert we thought it might be possible to use two threads for incoming migration on the target host. The first would be responsible for doing network I/O into local buffers, including the TLS decryption. The second would be responsible for processing the data. That way the memcpy() of RAM would move into another thread, allowing the first thread to spend 100% of its time doing TLS decryption.
If we assume the decryption + encryption take equal amounts of time, then it ought to let us raise TLS throughput from 1800 mbs, to approx 3000 mbs. Still a good way off 8500mbs from non-TLS migration, but a worth while improvement none the less.
NB, these TLS migration results were on a CPU with native AES instructionset support. CPUs with AES instructions would be even worse performance.
Changed in v2:
- Switch to setting migration parameters for TLS instead of adding to the URI syntax
- Support TLS over tcp, unix, fd, and socket protocols, not just tcp
- Allow passing in a hostname override for x509 cert checks
- Enable error reporting for outgoing migration problems
- Fix inverted I/O direction in post-copy code
- Use uint8_t / size_t in post-copy conversion instead of casting types
- Merge unix and tcp driver implementations
- Use tracepoints instead of DPRINTF
- Use error_report for incoming migration problems
- Fix broken logic in RDMA read conversion
- Add missing I/O callback & set_blocking API callbacks for RMDA QIOChannel impl
- Moved socket vs file FD detection to QIOChannel common code
Daniel P. Berrange (27):
s390: use FILE instead of QEMUFile for creating text file
migration: remove use of qemu_bufopen from vmstate tests
migration: ensure qemu_fflush() always writes full data amount
migration: split migration hooks out of QEMUFileOps
migration: introduce set_blocking function in QEMUFileOps
migration: force QEMUFile to blocking mode for outgoing migration
migration: introduce a new QEMUFile impl based on QIOChannel
migration: add helpers for creating QEMUFile from a QIOChannel
migration: add reporting of errors for outgoing migration
migration: convert post-copy to use QIOChannelBuffer
migration: convert unix socket protocol to use QIOChannel
migration: rename unix.c to socket.c
migration: convert tcp socket protocol to use QIOChannel
migration: convert fd socket protocol to use QIOChannel
migration: convert exec socket protocol to use QIOChannel
migration: convert RDMA to use QIOChannel interface
migration: convert savevm to use QIOChannel for writing to files
migration: delete QEMUFile buffer implementation
migration: delete QEMUSizedBuffer struct
migration: delete QEMUFile sockets implementation
migration: delete QEMUFile stdio implementation
migration: move definition of struct QEMUFile back into qemu-file.c
migration: don't use an array for storing migrate parameters
migration: define 'tls-creds' and 'tls-hostname' migration parameters
migration: add support for encrypting data with TLS
migration: remove support for non-iovec based write handlers
migration: remove qemu_get_fd method from QEMUFile
docs/migration.txt | 4 +- hmp-commands.hx | 15 ++ hmp.c | 56 +++++ hmp.h | 1 + hw/s390x/s390-skeys.c | 26 +-- include/migration/migration.h | 26 ++- include/migration/qemu-file.h | 57 ++--- include/qapi/error.h | 2 +- include/qemu/typedefs.h | 1 - include/sysemu/sysemu.h | 2 +- migration/Makefile.objs | 7 +- migration/exec.c | 64 +++--- migration/fd.c | 76 +++---- migration/migration.c | 155 +++++++++----- migration/qemu-file-buf.c | 464 ----------------------------------------- migration/qemu-file-channel.c | 202 ++++++++++++++++++ migration/qemu-file-internal.h | 53 ----- migration/qemu-file-stdio.c | 196 ----------------- migration/qemu-file-unix.c | 325 ----------------------------- migration/qemu-file.c | 110 +++++----- migration/ram.c | 6 +- migration/rdma.c | 380 ++++++++++++++++++++++++--------- migration/savevm.c | 63 ++---- migration/socket.c | 182 ++++++++++++++++ migration/tcp.c | 103 --------- migration/tls.c | 160 ++++++++++++++ migration/unix.c | 103 --------- qapi-schema.json | 63 +++++- tests/Makefile | 6 +- tests/test-vmstate.c | 55 ++--- trace-events | 25 ++- util/error.c | 2 +- 32 files changed, 1317 insertions(+), 1673 deletions(-) delete mode 100644 migration/qemu-file-buf.c create mode 100644 migration/qemu-file-channel.c delete mode 100644 migration/qemu-file-internal.h delete mode 100644 migration/qemu-file-stdio.c delete mode 100644 migration/qemu-file-unix.c create mode 100644 migration/socket.c delete mode 100644 migration/tcp.c create mode 100644 migration/tls.c delete mode 100644 migration/unix.c
Signature · 1 line
2.5.0
PATCH v2 1/27 s390: use FILE instead of QEMUFile for creating text file
The s390 skeys monitor command needs to write out a plain text file. Currently it is using the QEMUFile class for this, but work is ongoing to refactor QEMUFile and eliminate much code related to it. The only feature qemu_fopen() gives over fopen() is support for QEMU FD passing, but this can be achieved with qemu_open() + fdopen() too. Switching to regular stdio FILE APIs avoids the need to sprintf via an intermedia buffer which slightly simplifies the code.
--- hw/s390x/s390-skeys.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
hw/s390x/s390-skeys.c +14 -12
@@ -46,15 +46,11 @@ void s390_skeys_init(void)qdev_init_nofail (DEVICE (obj)); } -static void write_keys (QEMUFile *f,uint8_t *keys,uint64_t startgfn, +static void write_keys (FILE *f,uint8_t *keys,uint64_t startgfn,uint64_t count,Error **errp) {uint64_t curpage = startgfn;uint64_t maxpage = curpage + count -1 ; -const char *fmt ="page=%03" PRIx64": key(%d) => ACC=%X, FP=%d, REF=%d," -" ch=%d, reserved=%d\n" ; -char buf[128 ]; -int len;for (; curpage <= maxpage; curpage++) {uint8_t acc = (*keys &0xF0 ) >>4 ;
@@ -63,10 +59,9 @@ static void write_keys(QEMUFile *f, uint8_t *keys, uint64_t startgfn,int ch = (*keys &0x02 );int res = (*keys &0x01 ); - len =snprintf (buf,sizeof (buf), fmt, curpage, - *keys, acc, fp, ref, ch, res); -assert (len <sizeof (buf)); -qemu_put_buffer (f, (uint8_t *)buf, len); +fprintf (f,"page=%03" PRIx64": key(%d) => ACC=%X, FP=%d, REF=%d," +" ch=%d, reserved=%d\n" , + curpage, *keys, acc, fp, ref, ch, res); keys++; } }
@@ -115,7 +110,8 @@ void qmp_dump_skeys(const char *filename, Error **errp)vaddr cur_gfn =0 ;uint8_t *buf;int ret; -QEMUFile *f; +int fd; +FILE *f;/* Quick check to see if guest is using storage keys*/ if (!skeyclass->skeys_enabled (ss)) {
@@ -124,8 +120,14 @@ void qmp_dump_skeys(const char *filename, Error **errp)return ; } - f =qemu_fopen (filename,"wb" ); + fd =qemu_open (filename,O_WRONLY |O_CREAT |O_TRUNC ,0600 ); +if (fd <0 ) { +error_setg_file_open (errp, errno, filename); +return ; + } + f =fdopen (fd,"wb" );if (!f) { +close (fd);error_setg_file_open (errp, errno, filename);return ; }
@@ -161,7 +163,7 @@ out_free:error_propagate (errp, lerr);g_free (buf); out: -qemu_fclose (f); +fclose (f); }static void qemu_s390_skeys_init (Object *obj)
Signature · 1 line
2.5.0
PATCH v2 2/27 migration: remove use of qemu_bufopen from vmstate tests
In reply to Daniel P. BerrangeSome of the test-vmstate.c test cases use a temporary file while others use a memory buffer. To facilitate the future removal of the qemu_bufopen() function, convert all the tests to use a temporary file.
--- tests/Makefile | 2 +- tests/test-vmstate.c | 44 +++++++++++++------------------------------- 2 files changed, 14 insertions(+), 32 deletions(-)
tests/Makefile +1 -1
@@ -422,7 +422,7 @@ tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \ hw/core/fw-path-provider.o \ $(test-qapi-obj-y) tests/test-vmstate$(EXESUF): tests/test-vmstate.o \ - migration/vmstate.o migration/qemu-file.o migration/qemu-file-buf.o \ + migration/vmstate.o migration/qemu-file.o \ migration/qemu-file-unix.o qjson.o \ $(test-qom-obj-y) tests/test-timed-average$(EXESUF): tests/test-timed-average.o qemu-timer.o \
tests/test-vmstate.c +13 -31
115 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v2 3/27 migration: ensure qemu_fflush() always writes full data amount
In reply to Daniel P. BerrangeThe QEMUFile writev_buffer / put_buffer functions are expected to write out the full set of requested data, blocking until complete. The qemu_fflush() caller does not expect to deal with partial writes. Clarify the function comments and add a sanity check to the code to catch mistaken implementations.
--- include/migration/qemu-file.h | 6 ++++-- migration/qemu-file.c | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-)
include/migration/qemu-file.h +4 -2
@@ -29,7 +29,8 @@/* This function writes a chunk of data to a file at the given position. * The pos argument can be ignored if the file is only being used for -* streaming. The handler should try to write all of the data it can. +* streaming. The handler must write all of the data or return a negative +* errno value. */ typedef ssize_t (QEMUFilePutBufferFunc )(void *opaque,const uint8_t *buf,int64_t pos,size_t size);
@@ -55,7 +56,8 @@ typedef int (QEMUFileCloseFunc)(void *opaque);typedef int (QEMUFileGetFD )(void *opaque);/* -* This function writes an iovec to file. +* 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);
migration/qemu-file.c +12 -4
@@ -108,11 +108,13 @@ bool qemu_file_is_writable(QEMUFile *f)* Flushes QEMUFile buffer * * If there is writev_buffer QEMUFileOps it uses it otherwise uses -* put_buffer ops. +* put_buffer ops. This will flush all pending data. If data was +* only partially flushed, it will set an error state. */ void qemu_fflush (QEMUFile *f) {ssize_t ret =0 ; +ssize_t expect =0 ;if (!qemu_file_is_writable (f)) {return ;
@@ -120,21 +122,27 @@ void qemu_fflush(QEMUFile *f)if (f->ops->writev_buffer) {if (f->iovcnt >0 ) { + expect =iov_size (f->iov, f->iovcnt); ret = f->ops->writev_buffer (f->opaque, f->iov, f->iovcnt, f->pos); } }else {if (f->buf_index >0 ) { + expect = f->buf_index; ret = f->ops->put_buffer (f->opaque, f->buf, f->pos, f->buf_index); } } +if (ret >=0 ) { f->pos += ret; } +/* We expect the QEMUFile write impl to send the full +* data set we requested, so sanity check that. +*/ +if (ret != expect) { +qemu_file_set_error (f, ret <0 ? ret : -EIO ); + } f->buf_index =0 ; f->iovcnt =0 ; -if (ret <0 ) { -qemu_file_set_error (f, ret); - } }void ram_control_before_iterate (QEMUFile *f,uint64_t flags)
Signature · 1 line
2.5.0
PATCH v2 4/27 migration: split migration hooks out of QEMUFileOps
In reply to Daniel P. BerrangeThe 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.
--- include/migration/qemu-file.h | 10 +++++++--- migration/qemu-file-internal.h | 1 + migration/qemu-file.c | 24 +++++++++++++++--------- migration/rdma.c | 8 ++++++++ 4 files changed, 31 insertions(+), 12 deletions(-)
include/migration/qemu-file.h +7 -3
@@ -109,13 +109,16 @@ typedef struct QEMUFileOps {QEMUFileCloseFunc *close;QEMUFileGetFD *get_fd;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; -QEMURetPathFunc *get_return_path; -QEMUFileShutdownFunc *shut_down; -} QEMUFileOps; +}QEMUFileHooks ;struct QEMUSizedBuffer {struct iovec *iov;
@@ -130,6 +133,7 @@ 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);QEMUFile *qemu_bufopen (const char *mode,QEMUSizedBuffer *input); +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);
migration/qemu-file-internal.h +1 -0
@@ -33,6 +33,7 @@struct QEMUFile {const QEMUFileOps *ops; +const QEMUFileHooks *hooks;void *opaque;int64_t bytes_xfer;
migration/qemu-file.c +15 -9
@@ -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 ) {
migration/rdma.c +8 -0
@@ -3378,12 +3378,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,
@@ -3402,8 +3408,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;
Signature · 1 line
2.5.0
PATCH v2 5/27 migration: introduce set_blocking function in QEMUFileOps
In reply to Daniel P. BerrangeRemove the assumption that every QEMUFile implementation has a file descriptor available by introducing a new function in QEMUFileOps to change the blocking state of a QEMUFile.
If not set, it will fallback to the original code using the get_fd method.
--- include/migration/qemu-file.h | 5 +++++ migration/migration.c | 4 +--- migration/qemu-file.c | 10 +++++++--- 3 files changed, 13 insertions(+), 6 deletions(-)
include/migration/qemu-file.h +5 -0
@@ -55,6 +55,10 @@ typedef int (QEMUFileCloseFunc)(void *opaque);*/ 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.
@@ -108,6 +112,7 @@ typedef struct QEMUFileOps {QEMUFileGetBufferFunc *get_buffer;QEMUFileCloseFunc *close;QEMUFileGetFD *get_fd; +QEMUFileSetBlocking *set_blocking;QEMUFileWritevBufferFunc *writev_buffer;QEMURetPathFunc *get_return_path;QEMUFileShutdownFunc *shut_down;
migration/migration.c +1 -3
@@ -413,11 +413,9 @@ static void process_incoming_migration_co(void *opaque)void process_incoming_migration (QEMUFile *f) {Coroutine *co =qemu_coroutine_create (process_incoming_migration_co); -int fd =qemu_get_fd (f); -assert (fd !=-1 );migrate_decompress_threads_create (); -qemu_set_nonblock (fd); +qemu_file_set_blocking (f, false);qemu_coroutine_enter (co, f); }
migration/qemu-file.c +7 -3
@@ -684,9 +684,13 @@ size_t qemu_get_counted_string(QEMUFile *f, char buf[256])*/ void qemu_file_set_blocking (QEMUFile *f,bool block) { -if (block) { -qemu_set_block (qemu_get_fd (f)); +if (f->ops->set_blocking) { + f->ops->set_blocking (f->opaque, block); }else { -qemu_set_nonblock (qemu_get_fd (f)); +if (block) { +qemu_set_block (qemu_get_fd (f)); + }else { +qemu_set_nonblock (qemu_get_fd (f)); + } } }
Signature · 1 line
2.5.0
PATCH v2 6/27 migration: force QEMUFile to blocking mode for outgoing migration
In reply to Daniel P. BerrangeInstead of relying on the default QEMUFile I/O blocking flag state, explicitly turn on blocking I/O for outgoing migration since it takes place in a background thread.
--- migration/migration.c | 1 + 1 file changed, 1 insertion(+)
migration/migration.c +1 -0
@@ -1746,6 +1746,7 @@ void migrate_fd_connect(MigrationState *s) s->expected_downtime = max_downtime/1000000 ; s->cleanup_bh =qemu_bh_new (migrate_fd_cleanup, s); +qemu_file_set_blocking (s->to_dst_file, true);qemu_file_set_rate_limit (s->to_dst_file, s->bandwidth_limit /XFER_LIMIT_RATIO );
Signature · 1 line
2.5.0
PATCH v2 7/27 migration: introduce a new QEMUFile impl based on QIOChannel
In reply to Daniel P. BerrangeIntroduce a new QEMUFile implementation that is based on the QIOChannel objects. This impl is different from existing impls in that there is no file descriptor that can be made available, as some channels may be based on higher level protocols such as TLS.
Although the QIOChannel based implementation can trivially provide a bi-directional stream, initially we have separate functions for opening input & output directions to fit with the expectation of the current QEMUFile interface.
--- include/migration/qemu-file.h | 4 + migration/Makefile.objs | 1 + migration/qemu-file-channel.c | 202 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 207 insertions(+) create mode 100644 migration/qemu-file-channel.c
include/migration/qemu-file.h +4 -0
@@ -23,7 +23,9 @@*/ #ifndef QEMU_FILE_H #define QEMU_FILE_H 1 +#include "qemu-common.h" #include "exec/cpu-common.h" +#include "io/channel.h" #include <stdint.h>
@@ -136,6 +138,8 @@ QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops);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_fopen_channel_input (QIOChannel *ioc); +QEMUFile *qemu_fopen_channel_output (QIOChannel *ioc);QEMUFile *qemu_popen_cmd (const char *command,const char *mode);QEMUFile *qemu_bufopen (const char *mode,QEMUSizedBuffer *input);void qemu_file_set_hooks (QEMUFile *f,const QEMUFileHooks *hooks);
migration/Makefile.objs +1 -0
@@ -1,6 +1,7 @@ common-obj-y += migration.o tcp.o common-obj-y += vmstate.o common-obj-y += qemu-file.o qemu-file-buf.o qemu-file-unix.o qemu-file-stdio.o +common-obj-y += qemu-file-channel.o common-obj-y += xbzrle.o postcopy-ram.o common-obj-$(CONFIG_RDMA) += rdma.o
migration/qemu-file-channel.c new file +202 -0
202 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v2 8/27 migration: add helpers for creating QEMUFile from a QIOChannel
In reply to Daniel P. BerrangeCurrently creating a QEMUFile instance from a QIOChannel is quite simple only requiring a single call to qemu_fopen_channel_input or qemu_fopen_channel_output depending on the end of migration connection.
When QEMU gains TLS support, however, there will need to be a TLS negotiation done inbetween creation of the QIOChannel and creation of the final QEMUFile. Introduce some helper methods that will encapsulate this logic, isolating the migration protocol drivers from knowledge about TLS.
--- include/migration/migration.h | 6 ++++++ migration/migration.c | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+)
include/migration/migration.h +6 -0
@@ -176,6 +176,12 @@ void process_incoming_migration(QEMUFile *f);void qemu_start_incoming_migration (const char *uri,Error **errp); +void migration_set_incoming_channel (MigrationState *s, +QIOChannel *ioc); + +void migration_set_outgoing_channel (MigrationState *s, +QIOChannel *ioc); +uint64_t migrate_max_downtime (void );void exec_start_incoming_migration (const char *host_port,Error **errp);
migration/migration.c +21 -0
@@ -419,6 +419,27 @@ void process_incoming_migration(QEMUFile *f)qemu_coroutine_enter (co, f); } + +void migration_set_incoming_channel (MigrationState *s, +QIOChannel *ioc) +{ +QEMUFile *f =qemu_fopen_channel_input (ioc); + +process_incoming_migration (f); +} + + +void migration_set_outgoing_channel (MigrationState *s, +QIOChannel *ioc) +{ +QEMUFile *f =qemu_fopen_channel_output (ioc); + + s->to_dst_file = f; + +migrate_fd_connect (s); +} + +/* * Send a message on the return channel back to the source * of the migration.
Signature · 1 line
2.5.0
PATCH v2 9/27 migration: add reporting of errors for outgoing migration
In reply to Daniel P. BerrangeCurrently if an app initiates an outgoing migration, it may or may not, get an error reported back on failure. If the error occurs synchronously to the 'migrate' command execution, the client app will see the error message. This is the case for DNS lookup failures. If the error occurs asynchronously to the monitor command though, the error will be thrown away and the client left guessing about what went wrong. This is the case for failure to connect to the TCP server (eg due to wrong port, or firewall rules, or other similar errors).
In the future we'll be adding more scope for errors to happen asynchronously with the TLS protocol handshake. TLS errors are hard to diagnose even when they are well reported, so discarding errors entirely will make it impossible to debug TLS connection problems.
Management apps which do migration are already using 'query-migrate' / 'info migrate' to check up on progress of background migration operations and to see their end status. This is a fine place to also include the error message when things go wrong.
This patch thus adds an 'error-desc' field to the MigrationInfo struct, which will be populated when the 'status' is set to 'failed':
(qemu) migrate -d tcp:localhost:9001
(qemu) info migrate
capabilities: xbzrle: off rdma-pin-all: off auto-converge: off zero-blocks: off compress: off events: off x-postcopy-ram: off Migration status: failed
total time: 0 milliseconds
error description: Error connecting to socket: Connection refused
In the HMP, when doing non-detached migration, it is also possible to display this error message directly to the app.
(qemu) migrate tcp:localhost:9001
Error connecting to socket: Connection refused
--- hmp.c | 8 ++++++++ include/migration/migration.h | 5 ++++- include/qapi/error.h | 2 +- migration/migration.c | 12 +++++++++--- migration/rdma.c | 10 +++------- migration/tcp.c | 2 +- migration/unix.c | 2 +- qapi-schema.json | 5 ++++- trace-events | 2 +- util/error.c | 2 +- 10 files changed, 33 insertions(+), 17 deletions(-)
hmp.c +8 -0
@@ -33,6 +33,7 @@#include "ui/console.h" #include "block/qapi.h" #include "qemu-io.h" +#include "qemu/error-report.h" #ifdef CONFIG_SPICE #include <spice/enums.h>
@@ -238,6 +239,10 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict) info->x_cpu_throttle_percentage); } +if (info->has_error_desc) { +monitor_printf (mon,"error description: %s\n" , info->error_desc); + } +qapi_free_MigrationInfo (info);qapi_free_MigrationCapabilityStatusList (caps); }
@@ -1519,6 +1524,9 @@ static void hmp_migrate_status_cb(void *opaque)if (status->is_block_migration) {monitor_printf (status->mon,"\n" ); } +if (info->has_error_desc) { +error_report ("%s" , info->error_desc); + }monitor_resume (status->mon);timer_del (status->timer);g_free (status);
include/migration/migration.h +4 -1
@@ -168,6 +168,9 @@ struct MigrationState QSIMPLEQ_HEAD(src_page_requests, MigrationSrcPageRequest) src_page_requests;/* The RAMBlock used in the last src_page_request */ RAMBlock *last_req_rb; + +/* The last error that occurred */ +Error *error; };void migrate_set_state (int *state,int old_state,int new_state);
@@ -204,7 +207,7 @@ void rdma_start_outgoing_migration(void *opaque, const char *host_port, Error **void rdma_start_incoming_migration (const char *host_port,Error **errp); -void migrate_fd_error (MigrationState *s); +void migrate_fd_error (MigrationState *s,const Error *error);void migrate_fd_connect (MigrationState *s);
include/qapi/error.h +1 -1
@@ -142,7 +142,7 @@ typedef enum ErrorClass {/* * Get @err's human-readable error message. */ -const char *error_get_pretty (Error *err); +const char *error_get_pretty (const Error *err);/* * Get @err's error class.
migration/migration.c +9 -3
@@ -681,6 +681,10 @@ MigrationInfo *qmp_query_migrate(Error **errp)break ;case MIGRATION_STATUS_FAILED : info->has_status = true; +if (s->error) { + info->has_error_desc = true; + info->error_desc =g_strdup (error_get_pretty (s->error)); + }break ;case MIGRATION_STATUS_CANCELLED : info->has_status = true;
@@ -853,12 +857,14 @@ static void migrate_fd_cleanup(void *opaque)notifier_list_notify (&migration_state_notifiers, s); } -void migrate_fd_error (MigrationState *s) +void migrate_fd_error (MigrationState *s,const Error *error) { -trace_migrate_fd_error (); +trace_migrate_fd_error (error ?error_get_pretty (error) :"" );assert (s->to_dst_file ==NULL );migrate_set_state (&s->state,MIGRATION_STATUS_SETUP ,MIGRATION_STATUS_FAILED ); +error_free (s->error); + s->error =error_copy (error);notifier_list_notify (&migration_state_notifiers, s); }
@@ -1051,7 +1057,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, }if (local_err) { -migrate_fd_error (s); +migrate_fd_error (s, local_err);error_propagate (errp, local_err);return ; }
migration/rdma.c +3 -7
@@ -3487,16 +3487,14 @@ void rdma_start_outgoing_migration(void *opaque, const char *host_port, Error **errp) { MigrationState *s = opaque; -Error *local_err =NULL , **temp = &local_err; -RDMAContext *rdma =qemu_rdma_data_init (host_port, &local_err); +RDMAContext *rdma =qemu_rdma_data_init (host_port, errp);int ret =0 ;if (rdma ==NULL ) { -ERROR (temp,"Failed to initialize RDMA data structures! %d" , ret); goto err; } - ret =qemu_rdma_source_init (rdma, &local_err, + ret =qemu_rdma_source_init (rdma, errp, s->enabled_capabilities[MIGRATION_CAPABILITY_RDMA_PIN_ALL ]);if (ret) {
@@ -3504,7 +3502,7 @@ void rdma_start_outgoing_migration(void *opaque, }trace_rdma_start_outgoing_migration_after_rdma_source_init (); - ret =qemu_rdma_connect (rdma, &local_err); + ret =qemu_rdma_connect (rdma, errp);if (ret) { goto err;
@@ -3516,7 +3514,5 @@ void rdma_start_outgoing_migration(void *opaque,migrate_fd_connect (s);return ; err: -error_propagate (errp, local_err);g_free (rdma); -migrate_fd_error (s); }
migration/tcp.c +1 -1
@@ -40,7 +40,7 @@ static void tcp_wait_for_connect(int fd, Error *err, void *opaque)if (fd <0 ) {DPRINTF ("migrate connect error: %s\n" ,error_get_pretty (err)); s->to_dst_file =NULL ; -migrate_fd_error (s); +migrate_fd_error (s, err); }else {DPRINTF ("migrate connect success\n" ); s->to_dst_file =qemu_fopen_socket (fd,"wb" );
migration/unix.c +1 -1
@@ -40,7 +40,7 @@ static void unix_wait_for_connect(int fd, Error *err, void *opaque)if (fd <0 ) {DPRINTF ("migrate connect error: %s\n" ,error_get_pretty (err)); s->to_dst_file =NULL ; -migrate_fd_error (s); +migrate_fd_error (s, err); }else {DPRINTF ("migrate connect success\n" ); s->to_dst_file =qemu_fopen_socket (fd,"wb" );
qapi-schema.json +4 -1
@@ -484,6 +484,8 @@ # throttled during auto-converge. This is only present when auto-converge # has started throttling guest cpus. (Since 2.5) # +# @error-desc: the error description string, when @status == 'failed' (Since 2.6) +# # Since: 0.14.0 ## { 'struct': 'MigrationInfo',
@@ -494,7 +496,8 @@ '*expected-downtime': 'int', '*downtime': 'int', '*setup-time': 'int', - '*x-cpu-throttle-percentage': 'int'} } + '*x-cpu-throttle-percentage': 'int', + '*error-desc': 'str'} } ## # @query-migrate
trace-events +1 -1
@@ -1489,7 +1489,7 @@ await_return_path_close_on_source_close(void) "" await_return_path_close_on_source_joining(void) "" migrate_set_state(int new_state) "new state %d" migrate_fd_cleanup(void) "" -migrate_fd_error(void) "" +migrate_fd_error(const char *error_desc) "error=%s" migrate_fd_cancel(void) "" migrate_handle_rp_req_pages(const char *rbname, size_t start, size_t len) "in %s at %zx len %zx" migrate_pending(uint64_t size, uint64_t max, uint64_t post, uint64_t nonpost) "pending size %" PRIu64 " max %" PRIu64 " (post=%" PRIu64 " nonpost=%" PRIu64 ")"
util/error.c +1 -1
@@ -218,7 +218,7 @@ ErrorClass error_get_class(const Error *err)return err->err_class; } -const char *error_get_pretty (Error *err) +const char *error_get_pretty (const Error *err) {return err->msg; }
Signature · 1 line
2.5.0
PATCH v2 10/27 migration: convert post-copy to use QIOChannelBuffer
In reply to Daniel P. BerrangeThe post-copy code does some I/O to/from an intermediate in-memory buffer rather than direct to the underlying I/O channel. Switch this code to use QIOChannelBuffer instead of QEMUSizedBuffer.
--- docs/migration.txt | 4 ++-- include/sysemu/sysemu.h | 2 +- migration/migration.c | 15 +++++++-------- migration/savevm.c | 47 ++++++++++++++++------------------------------- 4 files changed, 26 insertions(+), 42 deletions(-)
docs/migration.txt +2 -2
@@ -403,8 +403,8 @@ listen thread: --- page -- page -- page -- page -- page -- On receipt of CMD_PACKAGED (1) All the data associated with the package - the ( ... ) section in the -diagram - is read into memory (into a QEMUSizedBuffer), and the main thread -recurses into qemu_loadvm_state_main to process the contents of the package (2) +diagram - is read into memory, and the main thread recurses into +qemu_loadvm_state_main to process the contents of the package (2) which contains commands (3,6) and devices (4...) On receipt of 'postcopy listen' - 3 -(i.e. the 1st command in the package)
include/sysemu/sysemu.h +1 -1
@@ -120,7 +120,7 @@ void qemu_savevm_command_send(QEMUFile *f, enum qemu_vm_cmd command, uint16_t len, uint8_t *data);void qemu_savevm_send_ping (QEMUFile *f,uint32_t value);void qemu_savevm_send_open_return_path (QEMUFile *f); -int qemu_savevm_send_packaged (QEMUFile *f,const QEMUSizedBuffer *qsb); +int qemu_savevm_send_packaged (QEMUFile *f,const uint8_t *buf,size_t len);void qemu_savevm_send_postcopy_advise (QEMUFile *f);void qemu_savevm_send_postcopy_listen (QEMUFile *f);void qemu_savevm_send_postcopy_run (QEMUFile *f);
migration/migration.c +7 -8
@@ -34,6 +34,7 @@#include "qom/cpu.h" #include "exec/memory.h" #include "exec/address-spaces.h" +#include "io/channel-buffer.h" #define MAX_THROTTLE (32 << 20)/* Migration transfer speed throttling */
@@ -1430,7 +1431,8 @@ static int await_return_path_close_on_source(MigrationState *ms)static int postcopy_start (MigrationState *ms,bool *old_vm_running) {int ret; -const QEMUSizedBuffer *qsb; +QIOChannelBuffer *bioc; +QEMUFile *fb;int64_t time_at_stop =qemu_clock_get_ms (QEMU_CLOCK_REALTIME );migrate_set_state (&ms->state,MIGRATION_STATUS_ACTIVE ,MIGRATION_STATUS_POSTCOPY_ACTIVE );
@@ -1489,11 +1491,9 @@ static int postcopy_start(MigrationState *ms, bool *old_vm_running)* So we wrap the device state up in a package with a length at the start; * to do this we use a qemu_buf to hold the whole of the device state. */ -QEMUFile *fb =qemu_bufopen ("w" ,NULL ); -if (!fb) { -error_report ("Failed to create buffered file" ); - goto fail; - } + bioc =qio_channel_buffer_new (4096 ); + fb =qemu_fopen_channel_output (QIO_CHANNEL (bioc)); +object_unref (OBJECT (bioc));/* * Make sure the receiver can get incoming pages before we send the rest
@@ -1507,10 +1507,9 @@ static int postcopy_start(MigrationState *ms, bool *old_vm_running)qemu_savevm_send_postcopy_run (fb);/* <><> end of stuff going into the package */ - qsb =qemu_buf_get (fb);/* Now send that blob */ -if (qemu_savevm_send_packaged (ms->to_dst_file, qsb)) { +if (qemu_savevm_send_packaged (ms->to_dst_file, bioc->data, bioc->usage)) { goto fail_closefb; }qemu_fclose (fb);
migration/savevm.c +16 -31
89 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v2 11/27 migration: convert unix socket protocol to use QIOChannel
In reply to Daniel P. BerrangeConvert the unix socket migration protocol driver to use QIOChannel and QEMUFileChannel, instead of plain sockets APIs. It can be unconditionally built, since the socket impl of QIOChannel will report a suitable error on platforms where UNIX sockets are unavailable.
--- migration/Makefile.objs | 4 +- migration/migration.c | 4 ++ migration/unix.c | 119 +++++++++++++++++++++++++++--------------------- trace-events | 5 ++ 4 files changed, 79 insertions(+), 53 deletions(-)
migration/Makefile.objs +2 -2
@@ -1,11 +1,11 @@ -common-obj-y += migration.o tcp.o +common-obj-y += migration.o tcp.o unix.o common-obj-y += vmstate.o common-obj-y += qemu-file.o qemu-file-buf.o qemu-file-unix.o qemu-file-stdio.o common-obj-y += qemu-file-channel.o common-obj-y += xbzrle.o postcopy-ram.o common-obj-$(CONFIG_RDMA) += rdma.o -common-obj-$(CONFIG_POSIX) += exec.o unix.o fd.o +common-obj-$(CONFIG_POSIX) += exec.o fd.o common-obj-y += block.o
migration/migration.c +4 -0
@@ -314,8 +314,10 @@ void qemu_start_incoming_migration(const char *uri, Error **errp)#if !defined(WIN32 ) } else if (strstart(uri, "exec:", &p)) {exec_start_incoming_migration (p, errp); +#endif }else if (strstart (uri,"unix:" , &p)) {unix_start_incoming_migration (p, errp); +#if !defined(WIN32 ) } else if (strstart(uri, "fd:", &p)) {fd_start_incoming_migration (p, errp);#endif
@@ -1044,8 +1046,10 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,#if !defined(WIN32 ) } else if (strstart(uri, "exec:", &p)) {exec_start_outgoing_migration (s, p, &local_err); +#endif }else if (strstart (uri,"unix:" , &p)) {unix_start_outgoing_migration (s, p, &local_err); +#if !defined(WIN32 ) } else if (strstart(uri, "fd:", &p)) {fd_start_outgoing_migration (s, p, &local_err);#endif
migration/unix.c +68 -51
165 lines not on this page · raw message
trace-events +5 -0
@@ -1603,6 +1603,11 @@ postcopy_ram_incoming_cleanup_entry(void) "" postcopy_ram_incoming_cleanup_exit(void) "" postcopy_ram_incoming_cleanup_join(void) "" +# migration/unix.c +migration_unix_incoming_accepted(void) "" +migration_unix_outgoing_connected(void) "" +migration_unix_outgoing_error(const char *err) "error=%s" + # kvm-all.c kvm_ioctl(int type, void *arg) "type 0x%x, arg %p" kvm_vm_ioctl(int type, void *arg) "type 0x%x, arg %p"
Signature · 1 line
2.5.0
PATCH v2 12/27 migration: rename unix.c to socket.c
In reply to Daniel P. BerrangeThe unix.c file will be nearly the same as the tcp.c file, only differing in the initial SocketAddress creation code. Rename unix.c to socket.c and refactor it a little to prepare for merging the TCP code.
---
migration/Makefile.objs | 2 +-
migration/{unix.c => socket.c} | 53 +++++++++++++++++++++++++-----------------
trace-events | 8 +++----
3 files changed, 37 insertions(+), 26 deletions(-)
rename migration/{unix.c => socket.c} (65%)migration/Makefile.objs +1 -1
@@ -1,4 +1,4 @@ -common-obj-y += migration.o tcp.o unix.o +common-obj-y += migration.o tcp.o socket.o common-obj-y += vmstate.o common-obj-y += qemu-file.o qemu-file-buf.o qemu-file-unix.o qemu-file-stdio.o common-obj-y += qemu-file-channel.o
migration/socket.c renamed from migration/unix.c +32 -21
102 lines not on this page · raw message
trace-events +4 -4
@@ -1603,10 +1603,10 @@ postcopy_ram_incoming_cleanup_entry(void) "" postcopy_ram_incoming_cleanup_exit(void) "" postcopy_ram_incoming_cleanup_join(void) "" -# migration/unix.c -migration_unix_incoming_accepted(void) "" -migration_unix_outgoing_connected(void) "" -migration_unix_outgoing_error(const char *err) "error=%s" +# migration/socket.c +migration_socket_incoming_accepted(void) "" +migration_socket_outgoing_connected(void) "" +migration_socket_outgoing_error(const char *err) "error=%s" # kvm-all.c kvm_ioctl(int type, void *arg) "type 0x%x, arg %p"
Signature · 1 line
2.5.0
PATCH v2 13/27 migration: convert tcp socket protocol to use QIOChannel
In reply to Daniel P. BerrangeDrop the current TCP socket migration driver and extend the new generic socket driver to cope with the TCP address format
--- migration/Makefile.objs | 2 +- migration/socket.c | 31 +++++++++++++++ migration/tcp.c | 103 ------------------------------------------------ 3 files changed, 32 insertions(+), 104 deletions(-) delete mode 100644 migration/tcp.c
migration/Makefile.objs +1 -1
@@ -1,4 +1,4 @@ -common-obj-y += migration.o tcp.o socket.o +common-obj-y += migration.o socket.o common-obj-y += vmstate.o common-obj-y += qemu-file.o qemu-file-buf.o qemu-file-unix.o qemu-file-stdio.o common-obj-y += qemu-file-channel.o
migration/socket.c +31 -0
@@ -24,6 +24,23 @@#include "trace.h" +static SocketAddress *tcp_build_address (const char *host_port,Error **errp) +{ +InetSocketAddress *iaddr =inet_parse (host_port, errp); +SocketAddress *saddr; + +if (!iaddr) { +return NULL ; + } + + saddr =g_new0 (SocketAddress,1 ); + saddr->type =SOCKET_ADDRESS_KIND_INET ; + saddr->u.inet = iaddr; + +return saddr; +} + +static SocketAddress *unix_build_address (const char *path) {SocketAddress *saddr;
@@ -68,6 +85,14 @@ static void socket_start_outgoing_migration(MigrationState *s,qapi_free_SocketAddress (saddr); } +void tcp_start_outgoing_migration (MigrationState *s, +const char *host_port, +Error **errp) +{ +SocketAddress *saddr =tcp_build_address (host_port, errp); +socket_start_outgoing_migration (s, saddr, errp); +} +void unix_start_outgoing_migration (MigrationState *s,const char *path,Error **errp)
@@ -124,6 +149,12 @@ static void socket_start_incoming_migration(SocketAddress *saddr,qapi_free_SocketAddress (saddr); } +void tcp_start_incoming_migration (const char *host_port,Error **errp) +{ +SocketAddress *saddr =tcp_build_address (host_port, errp); +socket_start_incoming_migration (saddr, errp); +} +void unix_start_incoming_migration (const char *path,Error **errp) {SocketAddress *saddr =unix_build_address (path);
migration/tcp.c deleted +0 -103
103 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v2 14/27 migration: convert fd socket protocol to use QIOChannel
In reply to Daniel P. BerrangeConvert the fd socket migration protocol driver to use QIOChannel and QEMUFileChannel, instead of plain sockets APIs. It can be unconditionally built because the QIOChannel APIs it uses will take care to report suitable error messages if needed.
--- migration/Makefile.objs | 4 +-- migration/fd.c | 76 +++++++++++++++++++------------------------------ migration/migration.c | 4 --- trace-events | 4 +++ 4 files changed, 35 insertions(+), 53 deletions(-)
migration/Makefile.objs +2 -2
@@ -1,11 +1,11 @@ -common-obj-y += migration.o socket.o +common-obj-y += migration.o socket.o fd.o common-obj-y += vmstate.o common-obj-y += qemu-file.o qemu-file-buf.o qemu-file-unix.o qemu-file-stdio.o common-obj-y += qemu-file-channel.o common-obj-y += xbzrle.o postcopy-ram.o common-obj-$(CONFIG_RDMA) += rdma.o -common-obj-$(CONFIG_POSIX) += exec.o fd.o +common-obj-$(CONFIG_POSIX) += exec.o common-obj-y += block.o
migration/fd.c +29 -47
115 lines not on this page · raw message
migration/migration.c +0 -4
@@ -317,10 +317,8 @@ void qemu_start_incoming_migration(const char *uri, Error **errp)#endif }else if (strstart (uri,"unix:" , &p)) {unix_start_incoming_migration (p, errp); -#if !defined(WIN32 ) }else if (strstart (uri,"fd:" , &p)) {fd_start_incoming_migration (p, errp); -#endif }else {error_setg (errp,"unknown migration protocol: %s" , uri); }
@@ -1049,10 +1047,8 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,#endif }else if (strstart (uri,"unix:" , &p)) {unix_start_outgoing_migration (s, p, &local_err); -#if !defined(WIN32 ) }else if (strstart (uri,"fd:" , &p)) {fd_start_outgoing_migration (s, p, &local_err); -#endif }else {error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"uri" ,"a valid migration protocol" );
trace-events +4 -0
@@ -1603,6 +1603,10 @@ postcopy_ram_incoming_cleanup_entry(void) "" postcopy_ram_incoming_cleanup_exit(void) "" postcopy_ram_incoming_cleanup_join(void) "" +# migration/fd.c +migration_fd_outgoing(int fd) "fd=%d" +migration_fd_incoming(int fd) "fd=%d" + # migration/socket.c migration_socket_incoming_accepted(void) "" migration_socket_outgoing_connected(void) ""
Signature · 1 line
2.5.0
PATCH v2 15/27 migration: convert exec socket protocol to use QIOChannel
In reply to Daniel P. BerrangeConvert the exec socket migration protocol driver to use QIOChannel and QEMUFileChannel, instead of the stdio popen APIs. It can be unconditionally built because the QIOChannelCommand class can report suitable error messages on platforms which can't fork processes.
--- migration/Makefile.objs | 3 +-- migration/exec.c | 64 ++++++++++++++++++++++++------------------------- migration/migration.c | 4 ---- trace-events | 4 ++++ 4 files changed, 37 insertions(+), 38 deletions(-)
migration/Makefile.objs +1 -2
@@ -1,11 +1,10 @@ -common-obj-y += migration.o socket.o fd.o +common-obj-y += migration.o socket.o fd.o exec.o common-obj-y += vmstate.o common-obj-y += qemu-file.o qemu-file-buf.o qemu-file-unix.o qemu-file-stdio.o common-obj-y += qemu-file-channel.o common-obj-y += xbzrle.o postcopy-ram.o common-obj-$(CONFIG_RDMA) += rdma.o -common-obj-$(CONFIG_POSIX) += exec.o common-obj-y += block.o
migration/exec.c +32 -32
97 lines not on this page · raw message
migration/migration.c +0 -4
@@ -311,10 +311,8 @@ void qemu_start_incoming_migration(const char *uri, Error **errp) } else if (strstart(uri, "rdma:", &p)) {rdma_start_incoming_migration (p, errp);#endif -#if !defined(WIN32 ) }else if (strstart (uri,"exec:" , &p)) {exec_start_incoming_migration (p, errp); -#endif }else if (strstart (uri,"unix:" , &p)) {unix_start_incoming_migration (p, errp); }else if (strstart (uri,"fd:" , &p)) {
@@ -1041,10 +1039,8 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, } else if (strstart(uri, "rdma:", &p)) {rdma_start_outgoing_migration (s, p, &local_err);#endif -#if !defined(WIN32 ) }else if (strstart (uri,"exec:" , &p)) {exec_start_outgoing_migration (s, p, &local_err); -#endif }else if (strstart (uri,"unix:" , &p)) {unix_start_outgoing_migration (s, p, &local_err); }else if (strstart (uri,"fd:" , &p)) {
trace-events +4 -0
@@ -1603,6 +1603,10 @@ postcopy_ram_incoming_cleanup_entry(void) "" postcopy_ram_incoming_cleanup_exit(void) "" postcopy_ram_incoming_cleanup_join(void) "" +# migration/exec.c +migration_exec_outgoing(const char *cmd) "cmd=%s" +migration_exec_incoming(const char *cmd) "cmd=%s" + # migration/fd.c migration_fd_outgoing(int fd) "fd=%d" migration_fd_incoming(int fd) "fd=%d"
Signature · 1 line
2.5.0
PATCH v2 16/27 migration: convert RDMA to use QIOChannel interface
In reply to Daniel P. BerrangeThis converts the RDMA code to provide a subclass of QIOChannel that uses RDMA for the data transport.
This implementation of RDMA does not correctly handle non-blocking mode. Reads might block if there was not already some pending data and writes will block until all data is sent. This flawed behaviour was already present in the existing impl, so appears to not be a critical problem at this time. It should be on the list of things to fix in the future though.
The RDMA code would be much better off it it could be split up in a generic RDMA layer, a QIOChannel impl based on RMDA, and then the RMDA migration glue. This is left as a future exercise for the brave.
--- migration/rdma.c | 374 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 275 insertions(+), 99 deletions(-)
migration/rdma.c +275 -99
@@ -2,10 +2,12 @@* RDMA protocol and interfaces * * Copyright IBM, Corp. 2010-2013 +* Copyright Red Hat, Inc. 2015-2016 * * Authors: * Michael R. Hines <[email protected]> * Jiuxing Liu <[email protected]> +* Daniel P. Berrange <[email protected]> * * This work is licensed under the terms of the GNU GPL, version 2 or * later. See the COPYING file in the top-level directory.
@@ -372,14 +374,20 @@ typedef struct RDMAContext {GHashTable *blockmap; } RDMAContext; -/* -* Interface to the rest of the migration call stack. -*/ -typedef struct QEMUFileRDMA { +#define TYPE_QIO_CHANNEL_RDMA "qio-channel-rdma" +#define QIO_CHANNEL_RDMA (obj) \ + OBJECT_CHECK(QIOChannelRDMA, (obj), TYPE_QIO_CHANNEL_RDMA) + +typedef struct QIOChannelRDMA QIOChannelRDMA ; + + +struct QIOChannelRDMA { +QIOChannel parent;RDMAContext *rdma; +QEMUFile *file;size_t len; -void *file; -}QEMUFileRDMA ; +bool blocking;/* XXX we don't actually honour this yet */ +};/* * Main structure for IB Send/Recv control messages.
@@ -2516,15 +2524,19 @@ static void *qemu_rdma_data_init(const char *host_port, Error **errp)* SEND messages for control only. * VM's ram is handled with regular RDMA messages. */ -static ssize_t qemu_rdma_put_buffer (void *opaque,const uint8_t *buf, -int64_t pos,size_t size) -{ -QEMUFileRDMA *r = opaque; -QEMUFile *f = r->file; -RDMAContext *rdma = r->rdma; -size_t remaining = size; -uint8_t * data = (void *) buf; +static ssize_t qio_channel_rdma_writev (QIOChannel *ioc, +const struct iovec *iov, +size_t niov, +int *fds, +size_t nfds, +Error **errp) +{ +QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (ioc); +QEMUFile *f = rioc->file; +RDMAContext *rdma = rioc->rdma;int ret; +ssize_t done =0 ; +size_t i;CHECK_ERROR_STATE ();
@@ -2538,27 +2550,31 @@ static ssize_t qemu_rdma_put_buffer(void *opaque, const uint8_t *buf,return ret; } -while (remaining) { -RDMAControlHeader head; +for (i =0 ; i < niov; i++) { +size_t remaining = iov[i].iov_len; +uint8_t * data = (void *)iov[i].iov_base; +while (remaining) { +RDMAControlHeader head; - r->len =MIN (remaining,RDMA_SEND_INCREMENT ); - remaining -= r->len; + rioc->len =MIN (remaining,RDMA_SEND_INCREMENT ); + remaining -= rioc->len; -/* Guaranteed to fit due to RDMA_SEND_INCREMENT MIN above */ - head.len = (uint32_t )r->len; - head.type =RDMA_CONTROL_QEMU_FILE ; + head.len = rioc->len; + head.type =RDMA_CONTROL_QEMU_FILE ; - ret =qemu_rdma_exchange_send (rdma, &head, data,NULL ,NULL ,NULL ); + ret =qemu_rdma_exchange_send (rdma, &head, data,NULL ,NULL ,NULL ); -if (ret <0 ) { - rdma->error_state = ret; -return ret; - } +if (ret <0 ) { + rdma->error_state = ret; +return ret; + } - data += r->len; + data += rioc->len; + done += rioc->len; + } } -return size; +return done; } static size_t qemu_rdma_fill(RDMAContext *rdma, uint8_t *buf,
@@ -2583,41 +2599,74 @@ static size_t qemu_rdma_fill(RDMAContext *rdma, uint8_t *buf,* RDMA links don't use bytestreams, so we have to * return bytes to QEMUFile opportunistically. */ -static ssize_t qemu_rdma_get_buffer (void *opaque,uint8_t *buf, -int64_t pos,size_t size) -{ -QEMUFileRDMA *r = opaque; -RDMAContext *rdma = r->rdma; +static ssize_t qio_channel_rdma_readv (QIOChannel *ioc, +const struct iovec *iov, +size_t niov, +int **fds, +size_t *nfds, +Error **errp) +{ +QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (ioc); +RDMAContext *rdma = rioc->rdma;RDMAControlHeader head;int ret =0 ; +ssize_t i; +size_t done =0 ;CHECK_ERROR_STATE (); -/* -* First, we hold on to the last SEND message we -* were given and dish out the bytes until we run -* out of bytes. -*/ - r->len =qemu_rdma_fill (r->rdma, buf, size,0 ); -if (r->len) { -return r->len; - } +for (i =0 ; i < niov; i++) { +size_t want = iov[i].iov_len; +uint8_t *data = (void *)iov[i].iov_base; -/* -* Once we run out, we block and wait for another -* SEND message to arrive. -*/ - ret =qemu_rdma_exchange_recv (rdma, &head,RDMA_CONTROL_QEMU_FILE ); +/* +* First, we hold on to the last SEND message we +* were given and dish out the bytes until we run +* out of bytes. +*/ + ret =qemu_rdma_fill (rioc->rdma, data, want,0 ); + done += ret; + want -= ret; +/* Got what we needed, so go to next iovec */ +if (want ==0 ) { +continue ; + } -if (ret <0 ) { - rdma->error_state = ret; -return ret; - } +/* If we got any data so far, then don't wait +* for more, just return what we have */ +if (done >0 ) { +break ; + } -/* -* SEND was received with new bytes, now try again. -*/ -return qemu_rdma_fill (r->rdma, buf, size,0 ); + +/* We've got nothing at all, so lets wait for +* more to arrive +*/ + ret =qemu_rdma_exchange_recv (rdma, &head,RDMA_CONTROL_QEMU_FILE ); + +if (ret <0 ) { + rdma->error_state = ret; +return ret; + } + +/* +* SEND was received with new bytes, now try again. +*/ + ret =qemu_rdma_fill (rioc->rdma, data, want,0 ); + done += ret; + want -= ret; + +/* Still didn't get enough, so lets just return */ +if (want) { +if (done ==0 ) { +return QIO_CHANNEL_ERR_BLOCK ; + }else { +break ; + } + } + } + rioc->len = done; +return rioc->len; }/*
@@ -2644,15 +2693,122 @@ static int qemu_rdma_drain_cq(QEMUFile *f, RDMAContext *rdma)return 0 ; } -static int qemu_rdma_close (void *opaque) + +static int qio_channel_rdma_set_blocking (QIOChannel *ioc, +bool blocking, +Error **errp) +{ +QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (ioc); +/* XXX we should make readv/writev actually honour this :-) */ + rioc->blocking = blocking; +return 0 ; +} + + +typedef struct QIOChannelRDMASource QIOChannelRDMASource ; +struct QIOChannelRDMASource { +GSource parent; +QIOChannelRDMA *rioc; +GIOCondition condition; +}; + +static gboolean +qio_channel_rdma_source_prepare (GSource *source, +gint *timeout) +{ +QIOChannelRDMASource *rsource = (QIOChannelRDMASource *)source; +RDMAContext *rdma = rsource->rioc->rdma; +GIOCondition cond =0 ; + *timeout =-1 ; + +if (rdma->wr_data[0 ].control_len) { + cond |=G_IO_IN ; + } + cond |=G_IO_OUT ; + +return cond & rsource->condition; +} + +static gboolean +qio_channel_rdma_source_check (GSource *source) +{ +QIOChannelRDMASource *rsource = (QIOChannelRDMASource *)source; +RDMAContext *rdma = rsource->rioc->rdma; +GIOCondition cond =0 ; + +if (rdma->wr_data[0 ].control_len) { + cond |=G_IO_IN ; + } + cond |=G_IO_OUT ; + +return cond & rsource->condition; +} + +static gboolean +qio_channel_rdma_source_dispatch (GSource *source, +GSourceFunc callback, +gpointer user_data) +{ +QIOChannelFunc func = (QIOChannelFunc )callback; +QIOChannelRDMASource *rsource = (QIOChannelRDMASource *)source; +RDMAContext *rdma = rsource->rioc->rdma; +GIOCondition cond =0 ; + +if (rdma->wr_data[0 ].control_len) { + cond |=G_IO_IN ; + } + cond |=G_IO_OUT ; + +return (*func)(QIO_CHANNEL (rsource->rioc), + (cond & rsource->condition), + user_data); +} + +static void +qio_channel_rdma_source_finalize (GSource *source) +{ +QIOChannelRDMASource *ssource = (QIOChannelRDMASource *)source; + +object_unref (OBJECT (ssource->rioc)); +} + +GSourceFuncs qio_channel_rdma_source_funcs = { + qio_channel_rdma_source_prepare, + qio_channel_rdma_source_check, + qio_channel_rdma_source_dispatch, + qio_channel_rdma_source_finalize +}; + +static GSource *qio_channel_rdma_create_watch (QIOChannel *ioc, +GIOCondition condition) { +QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (ioc); +QIOChannelRDMASource *ssource; +GSource *source; + + source =g_source_new (&qio_channel_rdma_source_funcs, +sizeof (QIOChannelRDMASource)); + ssource = (QIOChannelRDMASource *)source; + + ssource->rioc = rioc; +object_ref (OBJECT (rioc)); + + ssource->condition = condition; + +return source; +} + + +static int qio_channel_rdma_close (QIOChannel *ioc, +Error **errp) +{ +QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (ioc);trace_qemu_rdma_close (); -QEMUFileRDMA *r = opaque; -if (r->rdma) { -qemu_rdma_cleanup (r->rdma); -g_free (r->rdma); +if (rioc->rdma) { +qemu_rdma_cleanup (rioc->rdma); +g_free (rioc->rdma); + rioc->rdma =NULL ; } -g_free (r);return 0 ; }
@@ -2694,8 +2850,8 @@ static size_t qemu_rdma_save_page(QEMUFile *f, void *opaque, ram_addr_t block_offset, ram_addr_t offset, size_t size, uint64_t *bytes_sent) { - QEMUFileRDMA *rfile = opaque; -RDMAContext *rdma = rfile->rdma; + QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(opaque); +RDMAContext *rdma = rioc->rdma;int ret;CHECK_ERROR_STATE ();
@@ -2949,8 +3105,8 @@ static int qemu_rdma_registration_handle(QEMUFile *f, void *opaque) };RDMAControlHeader blocks = { .type =RDMA_CONTROL_RAM_BLOCKS_RESULT , .repeat =1 }; -QEMUFileRDMA *rfile = opaque; -RDMAContext *rdma = rfile->rdma; +QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (opaque); +RDMAContext *rdma = rioc->rdma;RDMALocalBlocks *local = &rdma->local_ram_blocks;RDMAControlHeader head;RDMARegister *reg, *registers;
@@ -3205,9 +3361,10 @@ out:* We've already built our local RAMBlock list, but not yet sent the list to * the source. */ -static int rdma_block_notification_handle (QEMUFileRDMA *rfile,const char *name) +static int +rdma_block_notification_handle (QIOChannelRDMA *rioc,const char *name) { -RDMAContext *rdma = rfile->rdma; +RDMAContext *rdma = rioc->rdma;int curr;int found =-1 ;
@@ -3249,8 +3406,8 @@ static int rdma_load_hook(QEMUFile *f, void *opaque, uint64_t flags, void *data)static int qemu_rdma_registration_start (QEMUFile *f,void *opaque,uint64_t flags,void *data) { -QEMUFileRDMA *rfile = opaque; -RDMAContext *rdma = rfile->rdma; +QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (opaque); +RDMAContext *rdma = rioc->rdma;CHECK_ERROR_STATE ();
@@ -3269,8 +3426,8 @@ static int qemu_rdma_registration_stop(QEMUFile *f, void *opaque, uint64_t flags, void *data) { Error *local_err = NULL, **errp = &local_err; -QEMUFileRDMA *rfile = opaque; -RDMAContext *rdma = rfile->rdma; +QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (opaque); +RDMAContext *rdma = rioc->rdma;RDMAControlHeader head = { .len =0 , .repeat =1 };int ret =0 ;
@@ -3366,55 +3523,74 @@ err:return ret; } -static int qemu_rdma_get_fd (void *opaque) -{ -QEMUFileRDMA *rfile = opaque; -RDMAContext *rdma = rfile->rdma; - -return rdma->comp_channel->fd; -} - -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, }; -static void *qemu_fopen_rdma (RDMAContext *rdma,const char *mode) + +static void qio_channel_rdma_finalize (Object *obj) +{ +QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (obj); +if (rioc->rdma) { +qemu_rdma_cleanup (rioc->rdma); +g_free (rioc->rdma); + rioc->rdma =NULL ; + } +} + +static void qio_channel_rdma_class_init (ObjectClass *klass, + void *class_data G_GNUC_UNUSED) +{ +QIOChannelClass *ioc_klass =QIO_CHANNEL_CLASS (klass); + + ioc_klass->io_writev = qio_channel_rdma_writev; + ioc_klass->io_readv = qio_channel_rdma_readv; + ioc_klass->io_set_blocking = qio_channel_rdma_set_blocking; + ioc_klass->io_close = qio_channel_rdma_close; + ioc_klass->io_create_watch = qio_channel_rdma_create_watch; +} + +static const TypeInfo qio_channel_rdma_info = { + .parent =TYPE_QIO_CHANNEL , + .name =TYPE_QIO_CHANNEL_RDMA , + .instance_size =sizeof (QIOChannelRDMA), + .instance_finalize = qio_channel_rdma_finalize, + .class_init = qio_channel_rdma_class_init, +}; + +static void qio_channel_rdma_register_types (void ) +{ +type_register_static (&qio_channel_rdma_info); +} + +type_init (qio_channel_rdma_register_types); + +static QEMUFile *qemu_fopen_rdma (RDMAContext *rdma,const char *mode) { -QEMUFileRDMA *r; +QIOChannelRDMA *rioc;if (qemu_file_mode_is_not_valid (mode)) {return NULL ; } - r =g_new0 (QEMUFileRDMA,1 ); - r->rdma = rdma; + rioc =QIO_CHANNEL_RDMA (object_new (TYPE_QIO_CHANNEL_RDMA )); + rioc->rdma = rdma;if (mode[0 ] =='w' ) { - r->file =qemu_fopen_ops (r, &rdma_write_ops); -qemu_file_set_hooks (r->file, &rdma_write_hooks); + rioc->file =qemu_fopen_channel_output (QIO_CHANNEL (rioc)); +qemu_file_set_hooks (rioc->file, &rdma_write_hooks); }else { - r->file =qemu_fopen_ops (r, &rdma_read_ops); -qemu_file_set_hooks (r->file, &rdma_read_hooks); + rioc->file =qemu_fopen_channel_input (QIO_CHANNEL (rioc)); +qemu_file_set_hooks (rioc->file, &rdma_read_hooks); } -return r->file; +return rioc->file; }static void rdma_accept_incoming_migration (void *opaque)
Signature · 1 line
2.5.0
PATCH v2 17/27 migration: convert savevm to use QIOChannel for writing to files
In reply to Daniel P. BerrangeConvert the exec savevm code to use QIOChannel and QEMUFileChannel, instead of the stdio APIs.
--- migration/savevm.c | 8 +++++--- tests/Makefile | 4 ++-- tests/test-vmstate.c | 11 ++++++++++- 3 files changed, 17 insertions(+), 6 deletions(-)
migration/savevm.c +5 -3
@@ -51,6 +51,7 @@#include "block/snapshot.h" #include "block/qapi.h" #include "io/channel-buffer.h" +#include "io/channel-file.h" #ifndef ETH_P_RARP
@@ -2024,6 +2025,7 @@ void hmp_savevm(Monitor *mon, const QDict *qdict)void qmp_xen_save_devices_state (const char *filename,Error **errp) {QEMUFile *f; +QIOChannelFile *ioc;int saved_vm_running;int ret;
@@ -2031,11 +2033,11 @@ void qmp_xen_save_devices_state(const char *filename, Error **errp)vm_stop (RUN_STATE_SAVE_VM );global_state_store_running (); - f =qemu_fopen (filename,"wb" ); -if (!f) { -error_setg_file_open (errp, errno, filename); + ioc =qio_channel_file_new_path (filename,O_WRONLY |O_CREAT ,0660 , errp); +if (!ioc) { goto the_end; } + f =qemu_fopen_channel_output (QIO_CHANNEL (ioc)); ret =qemu_save_device_state (f);qemu_fclose (f);if (ret <0 ) {
tests/Makefile +2 -2
@@ -423,8 +423,8 @@ tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \ $(test-qapi-obj-y) tests/test-vmstate$(EXESUF): tests/test-vmstate.o \ migration/vmstate.o migration/qemu-file.o \ - migration/qemu-file-unix.o qjson.o \ - $(test-qom-obj-y) + migration/qemu-file-channel.o qjson.o \ + $(test-io-obj-y) tests/test-timed-average$(EXESUF): tests/test-timed-average.o qemu-timer.o \ $(test-util-obj-y) tests/test-base64$(EXESUF): tests/test-base64.o \
tests/test-vmstate.c +10 -1
@@ -28,6 +28,7 @@#include "migration/migration.h" #include "migration/vmstate.h" #include "qemu/coroutine.h" +#include "io/channel-file.h" static char temp_file[] ="/tmp/vmst.test.XXXXXX" ;static int temp_fd;
@@ -48,11 +49,17 @@ void yield_until_fd_readable(int fd)static QEMUFile *open_test_file (bool write) {int fd =dup (temp_fd); +QIOChannel *ioc;lseek (fd,0 ,SEEK_SET );if (write) { g_assert_cmpint(ftruncate(fd, 0), ==, 0); } -return qemu_fdopen (fd, write ?"wb" :"rb" ); + ioc =QIO_CHANNEL (qio_channel_file_new_fd (fd)); +if (write) { +return qemu_fopen_channel_output (ioc); + }else { +return qemu_fopen_channel_input (ioc); + } }#define SUCCESS (val) \
@@ -468,6 +475,8 @@ int main(int argc, char **argv) { temp_fd =mkstemp (temp_file); +module_call_init (MODULE_INIT_QOM ); +g_test_init (&argc, &argv,NULL );g_test_add_func ("/vmstate/simple/primitive" , test_simple_primitive);g_test_add_func ("/vmstate/versioned/load/v1" , test_load_v1);
Signature · 1 line
2.5.0
PATCH v2 18/27 migration: delete QEMUFile buffer implementation
In reply to Daniel P. BerrangeThe qemu_bufopen() method is no longer used, so the memory buffer based QEMUFile backend can be deleted entirely.
--- include/migration/qemu-file.h | 6 --- migration/qemu-file-buf.c | 96 ------------------------------------------- 2 files changed, 102 deletions(-)
include/migration/qemu-file.h +0 -6
@@ -141,7 +141,6 @@ QEMUFile *qemu_fopen_socket(int fd, const char *mode);QEMUFile *qemu_fopen_channel_input (QIOChannel *ioc);QEMUFile *qemu_fopen_channel_output (QIOChannel *ioc);QEMUFile *qemu_popen_cmd (const char *command,const char *mode); -QEMUFile *qemu_bufopen (const char *mode,QEMUSizedBuffer *input);void qemu_file_set_hooks (QEMUFile *f,const QEMUFileHooks *hooks);int qemu_get_fd (QEMUFile *f);int qemu_fclose (QEMUFile *f);
@@ -167,11 +166,6 @@ ssize_t qsb_write_at(QEMUSizedBuffer *qsb, const uint8_t *buf, off_t pos, size_t count); -/* -* For use on files opened with qemu_bufopen -*/ -const QEMUSizedBuffer *qemu_buf_get (QEMUFile *f); -static inline void qemu_put_ubyte (QEMUFile *f,unsigned int v) {qemu_put_byte (f, (int )v);
migration/qemu-file-buf.c +0 -96
99 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v2 19/27 migration: delete QEMUSizedBuffer struct
In reply to Daniel P. BerrangeNow that we don't have have a buffer based QemuFile implementation, the QEMUSizedBuffer code is also unused and can be deleted. A simpler buffer class also exists in util/buffer.c which other code can used as needed.
--- include/migration/qemu-file.h | 16 -- include/qemu/typedefs.h | 1 - migration/Makefile.objs | 2 +- migration/qemu-file-buf.c | 368 ------------------------------------------ 4 files changed, 1 insertion(+), 386 deletions(-) delete mode 100644 migration/qemu-file-buf.c
include/migration/qemu-file.h +0 -16
@@ -127,13 +127,6 @@ typedef struct QEMUFileHooks {QEMURamSaveFunc *save_page; } QEMUFileHooks; -struct QEMUSizedBuffer { -struct iovec *iov; -size_t n_iov; -size_t size;/* total allocated size in all iov's */ -size_t used;/* number of used bytes */ -}; -QEMUFile *qemu_fopen_ops (void *opaque,const QEMUFileOps *ops);QEMUFile *qemu_fopen (const char *filename,const char *mode);QEMUFile *qemu_fdopen (int fd,const char *mode);
@@ -156,15 +149,6 @@ void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, size_t size);bool qemu_file_mode_is_not_valid (const char *mode);bool qemu_file_is_writable (QEMUFile *f); -QEMUSizedBuffer *qsb_create (const uint8_t *buffer,size_t len); -void qsb_free (QEMUSizedBuffer *); -size_t qsb_set_length (QEMUSizedBuffer *qsb,size_t length); -size_t qsb_get_length (const QEMUSizedBuffer *qsb); -ssize_t qsb_get_buffer (const QEMUSizedBuffer *,off_t start,size_t count, -uint8_t *buf); -ssize_t qsb_write_at (QEMUSizedBuffer *qsb,const uint8_t *buf, -off_t pos,size_t count); -static inline void qemu_put_ubyte (QEMUFile *f,unsigned int v) {
include/qemu/typedefs.h +0 -1
@@ -78,7 +78,6 @@ typedef struct QemuOpt QemuOpt;typedef struct QemuOpts QemuOpts ;typedef struct QemuOptsList QemuOptsList ;typedef struct QEMUSGList QEMUSGList ; -typedef struct QEMUSizedBuffer QEMUSizedBuffer ;typedef struct QEMUTimer QEMUTimer ;typedef struct QEMUTimerListGroup QEMUTimerListGroup ;typedef struct QObject QObject ;
migration/Makefile.objs +1 -1
@@ -1,6 +1,6 @@ common-obj-y += migration.o socket.o fd.o exec.o common-obj-y += vmstate.o -common-obj-y += qemu-file.o qemu-file-buf.o qemu-file-unix.o qemu-file-stdio.o +common-obj-y += qemu-file.o qemu-file-unix.o qemu-file-stdio.o common-obj-y += qemu-file-channel.o common-obj-y += xbzrle.o postcopy-ram.o
migration/qemu-file-buf.c deleted +0 -368
368 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v2 20/27 migration: delete QEMUFile sockets implementation
In reply to Daniel P. BerrangeNow that the tcp, unix and fd migration backends have converted to use the QIOChannel based QEMUFile, there is no user remaining for the sockets based QEMUFile impl and it can be deleted.
--- include/migration/qemu-file.h | 2 - migration/Makefile.objs | 2 +- migration/qemu-file-unix.c | 325 ------------------------------------------ 3 files changed, 1 insertion(+), 328 deletions(-) delete mode 100644 migration/qemu-file-unix.c
include/migration/qemu-file.h +0 -2
@@ -129,8 +129,6 @@ typedef struct QEMUFileHooks {QEMUFile *qemu_fopen_ops (void *opaque,const QEMUFileOps *ops);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_fopen_channel_input (QIOChannel *ioc);QEMUFile *qemu_fopen_channel_output (QIOChannel *ioc);QEMUFile *qemu_popen_cmd (const char *command,const char *mode);
migration/Makefile.objs +1 -1
@@ -1,6 +1,6 @@ common-obj-y += migration.o socket.o fd.o exec.o common-obj-y += vmstate.o -common-obj-y += qemu-file.o qemu-file-unix.o qemu-file-stdio.o +common-obj-y += qemu-file.o qemu-file-stdio.o common-obj-y += qemu-file-channel.o common-obj-y += xbzrle.o postcopy-ram.o
migration/qemu-file-unix.c deleted +0 -325
325 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v2 21/27 migration: delete QEMUFile stdio implementation
In reply to Daniel P. BerrangeNow that the exec migration backend and savevm have converted to use the QIOChannel based QEMUFile, there is no user remaining for the stdio based QEMUFile impl and it can be deleted.
--- include/migration/qemu-file.h | 2 - migration/Makefile.objs | 2 +- migration/qemu-file-stdio.c | 196 ------------------------------------------ 3 files changed, 1 insertion(+), 199 deletions(-) delete mode 100644 migration/qemu-file-stdio.c
include/migration/qemu-file.h +0 -2
@@ -128,10 +128,8 @@ typedef struct QEMUFileHooks { } QEMUFileHooks;QEMUFile *qemu_fopen_ops (void *opaque,const QEMUFileOps *ops); -QEMUFile *qemu_fopen (const char *filename,const char *mode);QEMUFile *qemu_fopen_channel_input (QIOChannel *ioc);QEMUFile *qemu_fopen_channel_output (QIOChannel *ioc); -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);
migration/Makefile.objs +1 -1
@@ -1,6 +1,6 @@ common-obj-y += migration.o socket.o fd.o exec.o common-obj-y += vmstate.o -common-obj-y += qemu-file.o qemu-file-stdio.o +common-obj-y += qemu-file.o common-obj-y += qemu-file-channel.o common-obj-y += xbzrle.o postcopy-ram.o
migration/qemu-file-stdio.c deleted +0 -196
196 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v2 22/27 migration: move definition of struct QEMUFile back into qemu-file.c
In reply to Daniel P. BerrangeNow that the memory buffer based QEMUFile impl is gone, there is no need for any backend to be accessing internals of the QEMUFile struct, so it can be moved back into qemu-file.c
--- migration/qemu-file-internal.h | 54 ------------------------------------------ migration/qemu-file.c | 24 ++++++++++++++++++- 2 files changed, 23 insertions(+), 55 deletions(-) delete mode 100644 migration/qemu-file-internal.h
migration/qemu-file-internal.h deleted +0 -54
@@ -1,54 +0,0 @@ -/* -* 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 QEMU_FILE_INTERNAL_H -#define QEMU_FILE_INTERNAL_H 1 - -#include "qemu-common.h" -#include "qemu/iov.h" - -#define IO_BUF_SIZE 32768 -#define MAX_IOV_SIZE MIN(IOV_MAX, 64) - -struct QEMUFile { -const QEMUFileOps *ops; -const QEMUFileHooks *hooks; -void *opaque; - -int64_t bytes_xfer; -int64_t xfer_limit; - -int64_t pos;/* start of buffer when writing, end of buffer -when reading */ -int buf_index; -int buf_size;/* 0 when writing */ -uint8_t buf[IO_BUF_SIZE ]; - -struct iovec iov[MAX_IOV_SIZE ]; -unsigned int iovcnt; - -int last_error; -}; - -#endif
migration/qemu-file.c +23 -1
@@ -30,9 +30,31 @@#include "qemu/coroutine.h" #include "migration/migration.h" #include "migration/qemu-file.h" -#include "migration/qemu-file-internal.h" #include "trace.h" +#define IO_BUF_SIZE 32768 +#define MAX_IOV_SIZE MIN(IOV_MAX, 64) + +struct QEMUFile { +const QEMUFileOps *ops; +const QEMUFileHooks *hooks; +void *opaque; + +int64_t bytes_xfer; +int64_t xfer_limit; + +int64_t pos;/* start of buffer when writing, end of buffer +when reading */ +int buf_index; +int buf_size;/* 0 when writing */ +uint8_t buf[IO_BUF_SIZE ]; + +struct iovec iov[MAX_IOV_SIZE ]; +unsigned int iovcnt; + +int last_error; +}; +/* * Stop a file from being read/written - not all backing files can do this * typically only sockets can.
Signature · 1 line
2.5.0
PATCH v2 23/27 migration: don't use an array for storing migrate parameters
In reply to Daniel P. BerrangeThe MigrateState struct uses an array for storing migration parameters. This presumes that all future parameters will be integers too, which is not going to be the case. There is no functional reason why an array is used, if anything it makes the code less clear. The QAPI schema already defines a struct - MigrationParameters - capable of storing all the individual parameters, so just use that instead of an array.
--- include/migration/migration.h | 5 +++- migration/migration.c | 56 +++++++++++++++++++------------------------ migration/ram.c | 6 ++--- 3 files changed, 30 insertions(+), 37 deletions(-)
include/migration/migration.h +4 -1
@@ -134,9 +134,12 @@ struct MigrationStateQemuThread thread;QEMUBH *cleanup_bh;QEMUFile *to_dst_file; -int parameters[MIGRATION_PARAMETER__MAX ]; + +/* New style params from 'migrate-set-parameters' */ +MigrationParameters parameters;int state; +/* Old style params from 'migrate' command */ MigrationParams params;/* State related to return path */
migration/migration.c +24 -32
109 lines not on this page · raw message
migration/ram.c +2 -4
@@ -426,10 +426,8 @@ static size_t save_page_header(QEMUFile *f, RAMBlock *block, ram_addr_t offset)static void mig_throttle_guest_down (void ) {MigrationState *s =migrate_get_current (); -uint64_t pct_initial = - s->parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INITIAL ]; -uint64_t pct_icrement = - s->parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT ]; +uint64_t pct_initial = s->parameters.x_cpu_throttle_initial; +uint64_t pct_icrement = s->parameters.x_cpu_throttle_increment;/* We have not started throttling yet. Let's start it. */ if (!cpu_throttle_active ()) {
Signature · 1 line
2.5.0
PATCH v2 24/27 migration: define 'tls-creds' and 'tls-hostname' migration parameters
In reply to Daniel P. BerrangeDefine two new migration parameters to be used with TLS encryption. The 'tls-creds' parameter provides the ID of an instance of the 'tls-creds' object type, or rather a subclass such as 'tls-creds-x509'. Providing these credentials will enable use of TLS on the migration data stream.
If using x509 certificates, together with a migration URI that does not include a hostname, the 'tls-hostname' parameter provides the hostname to use when verifying the server's x509 certificate. This allows TLS to be used in combination with fd: and exec: protocols where a TCP connection is established by a 3rd party outside of QEMU.
For the HMP this sadly requires adding a new monitor command 'migration_set_str_parameter', since the existing command 'migration_set_parameter' is fixed to take integer values.
The QMP monitor is fine, since it has the more flexible 'migration_set_parameters' which takes the dict of params of arbitrary types per the QAPI schema.
--- hmp-commands.hx | 15 +++++++++++++ hmp.c | 48 ++++++++++++++++++++++++++++++++++++++++++ hmp.h | 1 + migration/migration.c | 14 +++++++++++++ qapi-schema.json | 58 ++++++++++++++++++++++++++++++++++++++++++++++++--- 5 files changed, 133 insertions(+), 3 deletions(-)
hmp-commands.hx +15 -0
@@ -1022,6 +1022,21 @@ Set the parameter @var{parameter} for migration. ETEXI { + .name = "migrate_set_str_parameter", + .args_type = "parameter:s,value:s", + .params = "parameter value", + .help = "Set the parameter for migration", + .mhandler.cmd = hmp_migrate_set_str_parameter, + .command_completion = migrate_set_parameter_completion, + }, + +STEXI +@item migrate_set_str_parameter @var{parameter} @var{value} +@findex migrate_set_str_parameter +Set the parameter @var{parameter} for migration. +ETEXI + + { .name = "migrate_start_postcopy", .args_type = "", .params = "",
hmp.c +48 -0
60 lines not on this page · raw message
hmp.h +1 -0
@@ -67,6 +67,7 @@ void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict);void hmp_migrate_set_speed (Monitor *mon,const QDict *qdict);void hmp_migrate_set_capability (Monitor *mon,const QDict *qdict);void hmp_migrate_set_parameter (Monitor *mon,const QDict *qdict); +void hmp_migrate_set_str_parameter (Monitor *mon,const QDict *qdict);void hmp_migrate_set_cache_size (Monitor *mon,const QDict *qdict);void hmp_client_migrate_info (Monitor *mon,const QDict *qdict);void hmp_migrate_start_postcopy (Monitor *mon,const QDict *qdict);
migration/migration.c +14 -0
@@ -528,6 +528,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) params->decompress_threads = s->parameters.decompress_threads; params->x_cpu_throttle_initial = s->parameters.x_cpu_throttle_initial; params->x_cpu_throttle_increment = s->parameters.x_cpu_throttle_increment; + params->tls_creds =g_strdup (s->parameters.tls_creds); + params->tls_hostname =g_strdup (s->parameters.tls_hostname);return params; }
@@ -728,6 +730,10 @@ void qmp_migrate_set_parameters(bool has_compress_level,int64_t x_cpu_throttle_initial, bool has_x_cpu_throttle_increment, int64_t x_cpu_throttle_increment, + bool has_tls_creds, + const char *tls_creds, + bool has_tls_hostname, + const char *tls_hostname, Error **errp) { MigrationState *s = migrate_get_current();
@@ -779,6 +785,14 @@ void qmp_migrate_set_parameters(bool has_compress_level,if (has_x_cpu_throttle_increment) { s->parameters.x_cpu_throttle_increment = x_cpu_throttle_increment; } +if (has_tls_creds) { +g_free (s->parameters.tls_creds); + s->parameters.tls_creds =g_strdup (tls_creds); + } +if (has_tls_hostname) { +g_free (s->parameters.tls_hostname); + s->parameters.tls_hostname =g_strdup (tls_hostname); + } }
qapi-schema.json +55 -3
92 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v2 25/27 migration: add support for encrypting data with TLS
In reply to Daniel P. BerrangeThis extends the migration_set_incoming_channel and migration_set_outgoing_channel methods so that they will automatically wrap the QIOChannel in a QIOChannelTLS instance if TLS credentials are configured in the migration parameters.
This allows TLS to work for tcp, unix, fd and exec migration protocols. It does not (currently) work for RDMA since it does not use these APIs, but it is unlikely that TLS would be desired with RDMA anyway since it would degrade the performance to that seen with TCP defeating the purpose of using RDMA.
On the target host, QEMU would be launched with a set of TLS credentials for a server endpoint
$ qemu-system-x86_64 -monitor stdio -incoming defer \
-object tls-creds-x509,dir=/home/berrange/security/qemutls,endpoint=server,id=tls0 \
...other args...To enable incoming TLS migration 2 monitor commands are then used
(qemu) migrate_set_str_parameter tls-creds tls0 (qemu) migrate_incoming tcp:myhostname:9000
On the source host, QEMU is launched in a similar manner but using client endpoint credentials
$ qemu-system-x86_64 -monitor stdio \
-object tls-creds-x509,dir=/home/berrange/security/qemutls,endpoint=client,id=tls0 \
...other args...To enable outgoing TLS migration 2 monitor commands are then used
(qemu) migrate_set_str_parameter tls-creds tls0 (qemu) migrate tcp:otherhostname:9000
Thanks to earlier improvements to error reporting, TLS errors can be seen 'info migrate' when doing a detached migration. For example:
(qemu) info migrate
capabilities: xbzrle: off rdma-pin-all: off auto-converge: off zero-blocks: off compress: off events: off x-postcopy-ram: off Migration status: failed
total time: 0 milliseconds
error description: TLS handshake failed: The TLS connection was non-properly terminated.
Or
(qemu) info migrate
capabilities: xbzrle: off rdma-pin-all: off auto-converge: off zero-blocks: off compress: off events: off x-postcopy-ram: off Migration status: failed
total time: 0 milliseconds
error description: Certificate does not match the hostname localhost
--- include/migration/migration.h | 12 +++- migration/Makefile.objs | 1 + migration/exec.c | 2 +- migration/fd.c | 2 +- migration/migration.c | 40 +++++++++-- migration/socket.c | 34 +++++++-- migration/tls.c | 160 ++++++++++++++++++++++++++++++++++++++++++ trace-events | 12 +++- 8 files changed, 246 insertions(+), 17 deletions(-) create mode 100644 migration/tls.c
include/migration/migration.h +11 -1
@@ -185,8 +185,18 @@ void qemu_start_incoming_migration(const char *uri, Error **errp);void migration_set_incoming_channel (MigrationState *s,QIOChannel *ioc); +void migration_tls_set_incoming_channel (MigrationState *s, +QIOChannel *ioc, +Error **errp); +void migration_set_outgoing_channel (MigrationState *s, -QIOChannel *ioc); +QIOChannel *ioc, +const char *hostname); + +void migration_tls_set_outgoing_channel (MigrationState *s, +QIOChannel *ioc, +const char *hostname, +Error **errp);uint64_t migrate_max_downtime (void );
migration/Makefile.objs +1 -0
@@ -1,4 +1,5 @@ common-obj-y += migration.o socket.o fd.o exec.o +common-obj-y += tls.o common-obj-y += vmstate.o common-obj-y += qemu-file.o common-obj-y += qemu-file-channel.o
migration/exec.c +1 -1
@@ -35,7 +35,7 @@ void exec_start_outgoing_migration(MigrationState *s, const char *command, Errorreturn ; } -migration_set_outgoing_channel (s, ioc); +migration_set_outgoing_channel (s, ioc,NULL );object_unref (OBJECT (ioc)); }
migration/fd.c +1 -1
@@ -36,7 +36,7 @@ void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **return ; } -migration_set_outgoing_channel (s, ioc); +migration_set_outgoing_channel (s, ioc,NULL );object_unref (OBJECT (ioc)); }
migration/migration.c +34 -6
@@ -35,6 +35,7 @@#include "exec/memory.h" #include "exec/address-spaces.h" #include "io/channel-buffer.h" +#include "io/channel-tls.h" #define MAX_THROTTLE (32 << 20)/* Migration transfer speed throttling */
@@ -420,20 +421,47 @@ void process_incoming_migration(QEMUFile *f)void migration_set_incoming_channel (MigrationState *s,QIOChannel *ioc) { -QEMUFile *f =qemu_fopen_channel_input (ioc); +trace_migration_set_incoming_channel ( + ioc,object_get_typename (OBJECT (ioc))); -process_incoming_migration (f); +if (s->parameters.tls_creds && + !object_dynamic_cast (OBJECT (ioc), +TYPE_QIO_CHANNEL_TLS )) { +Error *local_err =NULL ; +migration_tls_set_incoming_channel (s, ioc, &local_err); +if (local_err) { +error_report_err (local_err); + } + }else { +QEMUFile *f =qemu_fopen_channel_input (ioc); +process_incoming_migration (f); + } }void migration_set_outgoing_channel (MigrationState *s, -QIOChannel *ioc) +QIOChannel *ioc, +const char *hostname) { -QEMUFile *f =qemu_fopen_channel_output (ioc); +trace_migration_set_outgoing_channel ( + ioc,object_get_typename (OBJECT (ioc)), hostname); - s->to_dst_file = f; +if (s->parameters.tls_creds && + !object_dynamic_cast (OBJECT (ioc), +TYPE_QIO_CHANNEL_TLS )) { +Error *local_err =NULL ; +migration_tls_set_outgoing_channel (s, ioc, hostname, &local_err); +if (local_err) { +migrate_fd_error (s, local_err); +error_free (local_err); + } + }else { +QEMUFile *f =qemu_fopen_channel_output (ioc); -migrate_fd_connect (s); + s->to_dst_file = f; + +migrate_fd_connect (s); + } }
migration/socket.c +27 -7
@@ -54,20 +54,35 @@ static SocketAddress *unix_build_address(const char *path) } +struct SocketConnectData { +MigrationState *s; +char *hostname; +}; + +static void socket_connect_data_free (void *opaque) +{ +struct SocketConnectData *data = opaque; +if (!data) { +return ; + } +g_free (data->hostname); +g_free (data); +} +static void socket_outgoing_migration (Object *src,Error *err,gpointer opaque) { -MigrationState *s = opaque; +struct SocketConnectData *data = opaque;QIOChannel *sioc =QIO_CHANNEL (src);if (err) {trace_migration_socket_outgoing_error (error_get_pretty (err)); - s->to_dst_file =NULL ; -migrate_fd_error (s, err); + data->s->to_dst_file =NULL ; +migrate_fd_error (data->s, err); }else { -trace_migration_socket_outgoing_connected (); -migration_set_outgoing_channel (s, sioc); +trace_migration_socket_outgoing_connected (data->hostname); +migration_set_outgoing_channel (data->s, sioc, data->hostname); }object_unref (src); }
@@ -77,11 +92,16 @@ static void socket_start_outgoing_migration(MigrationState *s, Error **errp) {QIOChannelSocket *sioc =qio_channel_socket_new (); + struct SocketConnectData *data = g_new0(struct SocketConnectData, 1); + data->s = s; +if (saddr->type ==SOCKET_ADDRESS_KIND_INET ) { + data->hostname =g_strdup (saddr->u.inet->host); + }qio_channel_socket_connect_async (sioc, saddr, socket_outgoing_migration, - s, -NULL ); + data, + socket_connect_data_free);qapi_free_SocketAddress (saddr); }
migration/tls.c new file +160 -0
160 lines not on this page · raw message
trace-events +11 -1
@@ -1519,6 +1519,8 @@ migrate_state_too_big(void) "" migrate_transferred(uint64_t tranferred, uint64_t time_spent, double bandwidth, uint64_t size) "transferred %" PRIu64 " time_spent %" PRIu64 " bandwidth %g max_size %" PRId64 process_incoming_migration_co_end(int ret, int ps) "ret=%d postcopy-state=%d" process_incoming_migration_co_postcopy_end_main(void) "" +migration_set_incoming_channel(void *ioc, const char *ioctype) "ioc=%p ioctype=%s" +migration_set_outgoing_channel(void *ioc, const char *ioctype, const char *hostname) "ioc=%p ioctype=%s hostname=%s" # migration/rdma.c qemu_rdma_accept_incoming_migration(void) ""
@@ -1613,9 +1615,17 @@ migration_fd_incoming(int fd) "fd=%d" # migration/socket.c migration_socket_incoming_accepted(void) "" -migration_socket_outgoing_connected(void) "" +migration_socket_outgoing_connected(const char *hostname) "hostname=%s" migration_socket_outgoing_error(const char *err) "error=%s" +# migration/tls.c +migration_tls_outgoing_handshake_start(const char *hostname) "hostname=%s" +migration_tls_outgoing_handshake_error(const char *err) "err=%s" +migration_tls_outgoing_handshake_complete(void) "" +migration_tls_incoming_handshake_start(void) "" +migration_tls_incoming_handshake_error(const char *err) "err=%s" +migration_tls_incoming_handshake_complete(void) "" + # kvm-all.c kvm_ioctl(int type, void *arg) "type 0x%x, arg %p" kvm_vm_ioctl(int type, void *arg) "type 0x%x, arg %p"
Signature · 1 line
2.5.0
PATCH v2 26/27 migration: remove support for non-iovec based write handlers
In reply to Daniel P. BerrangeAll the remaining QEMUFile implementations provide an iovec based write handler, so the put_buffer callback can be removed to simplify the code.
--- include/migration/qemu-file.h | 9 --------- migration/qemu-file.c | 36 ++++++++---------------------------- migration/savevm.c | 8 -------- 3 files changed, 8 insertions(+), 45 deletions(-)
include/migration/qemu-file.h +0 -9
@@ -29,14 +29,6 @@#include <stdint.h> -/* This function writes a chunk of data to a file at the given position. -* The pos argument can be ignored if the file is only being used for -* streaming. The handler must write all of the data or return a negative -* errno value. -*/ -typedef ssize_t (QEMUFilePutBufferFunc )(void *opaque,const uint8_t *buf, -int64_t pos,size_t size); -/* 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.
@@ -110,7 +102,6 @@ typedef QEMUFile *(QEMURetPathFunc)(void *opaque);typedef int (QEMUFileShutdownFunc )(void *opaque,bool rd,bool wr); typedef struct QEMUFileOps { - QEMUFilePutBufferFunc *put_buffer; QEMUFileGetBufferFunc *get_buffer; QEMUFileCloseFunc *close; QEMUFileGetFD *get_fd;
migration/qemu-file.c +8 -28
@@ -129,7 +129,7 @@ void qemu_file_set_error(QEMUFile *f, int ret)bool qemu_file_is_writable (QEMUFile *f) { -return f->ops->writev_buffer || f->ops->put_buffer; +return f->ops->writev_buffer; }/**
@@ -148,16 +148,9 @@ void qemu_fflush(QEMUFile *f)return ; } -if (f->ops->writev_buffer) { -if (f->iovcnt >0 ) { - expect =iov_size (f->iov, f->iovcnt); - ret = f->ops->writev_buffer (f->opaque, f->iov, f->iovcnt, f->pos); - } - }else { -if (f->buf_index >0 ) { - expect = f->buf_index; - ret = f->ops->put_buffer (f->opaque, f->buf, f->pos, f->buf_index); - } +if (f->iovcnt >0 ) { + expect =iov_size (f->iov, f->iovcnt); + ret = f->ops->writev_buffer (f->opaque, f->iov, f->iovcnt, f->pos); }if (ret >=0 ) {
@@ -337,11 +330,6 @@ static void add_to_iovec(QEMUFile *f, const uint8_t *buf, size_t size)void qemu_put_buffer_async (QEMUFile *f,const uint8_t *buf,size_t size) { -if (!f->ops->writev_buffer) { -qemu_put_buffer (f, buf, size); -return ; - } -if (f->last_error) {return ; }
@@ -365,9 +353,7 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, size_t size) }memcpy (f->buf + f->buf_index, buf, l); f->bytes_xfer += l; -if (f->ops->writev_buffer) { -add_to_iovec (f, f->buf + f->buf_index, l); - } +add_to_iovec (f, f->buf + f->buf_index, l); f->buf_index += l;if (f->buf_index ==IO_BUF_SIZE ) {qemu_fflush (f);
@@ -388,9 +374,7 @@ void qemu_put_byte(QEMUFile *f, int v) f->buf[f->buf_index] = v; f->bytes_xfer++; -if (f->ops->writev_buffer) { -add_to_iovec (f, f->buf + f->buf_index,1 ); - } +add_to_iovec (f, f->buf + f->buf_index,1 ); f->buf_index++;if (f->buf_index ==IO_BUF_SIZE ) {qemu_fflush (f);
@@ -554,12 +538,8 @@ int64_t qemu_ftell_fast(QEMUFile *f)int64_t ret = f->pos;int i; -if (f->ops->writev_buffer) { -for (i =0 ; i < f->iovcnt; i++) { - ret += f->iov[i].iov_len; - } - }else { - ret += f->buf_index; +for (i =0 ; i < f->iovcnt; i++) { + ret += f->iov[i].iov_len; }return ret;
migration/savevm.c +0 -8
@@ -160,13 +160,6 @@ static ssize_t block_writev_buffer(void *opaque, struct iovec *iov, int iovcnt,return qiov.size; } -static ssize_t block_put_buffer (void *opaque,const uint8_t *buf, -int64_t pos,size_t size) -{ -bdrv_save_vmstate (opaque, buf, pos, size); -return size; -} -static ssize_t block_get_buffer (void *opaque,uint8_t *buf,int64_t pos,size_t size) {
@@ -184,7 +177,6 @@ static const QEMUFileOps bdrv_read_ops = { };static const QEMUFileOps bdrv_write_ops = { - .put_buffer = block_put_buffer, .writev_buffer = block_writev_buffer, .close = bdrv_fclose };
Signature · 1 line
2.5.0
PATCH v2 27/27 migration: remove qemu_get_fd method from QEMUFile
In reply to Daniel P. BerrangeNow that there is a set_blocking callback in QEMUFileOps, and all users needing non-blocking support have been converted to QIOChannel, there is no longer any codepath requiring the qemu_get_fd() method for QEMUFile. Remove it to avoid further code being introduced with an expectation of direct file handle access.
--- include/migration/qemu-file.h | 1 - migration/qemu-file.c | 14 -------------- 2 files changed, 15 deletions(-)
include/migration/qemu-file.h +0 -1
@@ -104,7 +104,6 @@ typedef int (QEMUFileShutdownFunc)(void *opaque, bool rd, bool wr); typedef struct QEMUFileOps { QEMUFileGetBufferFunc *get_buffer; QEMUFileCloseFunc *close; - QEMUFileGetFD *get_fd; QEMUFileSetBlocking *set_blocking; QEMUFileWritevBufferFunc *writev_buffer; QEMURetPathFunc *get_return_path;
migration/qemu-file.c +0 -14
@@ -268,14 +268,6 @@ static ssize_t qemu_fill_buffer(QEMUFile *f)return len; } -int qemu_get_fd (QEMUFile *f) -{ -if (f->ops->get_fd) { -return f->ops->get_fd (f->opaque); - } -return -1 ; -} -void qemu_update_position (QEMUFile *f,size_t size) { f->pos += size;
@@ -688,11 +680,5 @@ void qemu_file_set_blocking(QEMUFile *f, bool block) {if (f->ops->set_blocking) { f->ops->set_blocking (f->opaque, block); - }else { -if (block) { -qemu_set_block (qemu_get_fd (f)); - }else { -qemu_set_nonblock (qemu_get_fd (f)); - } } }
Signature · 1 line
2.5.0