Rsocket migration support [incomplete]
PATCH 1/1 Rsocket migration support [incomplete]
From: "Dr. David Alan Gilbert" <[email protected]>
Implement migration over RDMA using the 'rsocket' library, the code appears to work for guests with < 4GB RAM, but is hitting what appears to be internal library limitations above that. (riowrite always returns EAGAIN as soon as I register more RAM). Note also that the library doesn't provide zero copy on the send side.
The code has a few other hacks and incompletenesses, but I thought I'd release the source anyway for anyone else interested in investigating.
Very lightly tested, but it did manage to migrate a 'stressapptest' run on a 3.5GB guest successfully over 10Gb ROCE.
Note it needs the 'qemu_ram_foreach_block: pass up error value, and down the ramblock name' patch from my postcopy world.
--- arch_init.c | 3 +- include/migration/migration.h | 4 + include/qemu/iov.h | 18 +- include/qemu/sockets.h | 4 + migration/Makefile.objs | 2 +- migration/migration.c | 4 + migration/rsocket.c | 964 ++++++++++++++++++++++++++++++++++++++++++ qemu-coroutine-io.c | 3 +- trace-events | 35 ++ util/iov.c | 14 +- util/qemu-sockets.c | 8 +- 11 files changed, 1042 insertions(+), 17 deletions(-) create mode 100644 migration/rsocket.c
arch_init.c +2 -1
@@ -847,10 +847,10 @@ static int ram_save_setup(QEMUFile *f, void *opaque)qemu_put_be64 (f, block->length); } -qemu_mutex_unlock_ramlist ();ram_control_before_iterate (f,RAM_CONTROL_SETUP );ram_control_after_iterate (f,RAM_CONTROL_SETUP ); +qemu_mutex_unlock_ramlist ();qemu_put_be64 (f,RAM_SAVE_FLAG_EOS );
@@ -1103,6 +1103,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) total_ram_bytes -= length; } +ram_control_before_iterate (f,RAM_CONTROL_SETUP );break ;case RAM_SAVE_FLAG_COMPRESS : host =host_from_stream_offset (f, addr, flags);
include/migration/migration.h +4 -0
@@ -94,6 +94,10 @@ void rdma_start_outgoing_migration(void *opaque, const char *host_port, Error **void rdma_start_incoming_migration (const char *host_port,Error **errp); +void rsocket_start_outgoing_migration (MigrationState *s,const char *host_port,Error **errp); + +void rsocket_start_incoming_migration (const char *host_port,Error **errp); +void migrate_fd_error (MigrationState *s);void migrate_fd_connect (MigrationState *s);
include/qemu/iov.h +15 -3
@@ -58,6 +58,17 @@ size_t iov_memset(const struct iovec *iov, const unsigned int iov_cnt, size_t offset, int fillc, size_t bytes);/* +* Helper function for iov_send_recv for standard FDs +*/ +ssize_t iov_send_recv_fd (int sockfd,struct iovec *iov,unsigned iov_cnt, +bool do_send); + +/* +* Type of iov_send_recv_fd and similar helper functions. +*/ +typedef ssize_t (*iov_send_recv_func )(int ,struct iovec *,unsigned ,bool ); + +/* * Send/recv data from/to iovec buffers directly * * `offset' bytes in the beginning of iovec buffer are skipped and
@@ -76,11 +87,12 @@ size_t iov_memset(const struct iovec *iov, const unsigned int iov_cnt,* should be within the iovec, not only beginning of it. */ ssize_t iov_send_recv (int sockfd,struct iovec *iov,unsigned iov_cnt, -size_t offset,size_t bytes,bool do_send); +size_t offset,size_t bytes,bool do_send, +iov_send_recv_func helper);#define iov_recv (sockfd, iov, iov_cnt, offset, bytes) \ - iov_send_recv(sockfd, iov, iov_cnt, offset, bytes, false) + iov_send_recv(sockfd, iov, iov_cnt, offset, bytes, false, iov_send_recv_fd)#define iov_send (sockfd, iov, iov_cnt, offset, bytes) \ - iov_send_recv(sockfd, iov, iov_cnt, offset, bytes, true) + iov_send_recv(sockfd, iov, iov_cnt, offset, bytes, true, iov_send_recv_fd)/** * Produce a text hexdump of iovec `iov' with `iov_cnt' number of elements
include/qemu/sockets.h +4 -0
@@ -60,8 +60,11 @@ int inet_nonblocking_connect(const char *str, NonBlockingConnectHandler *callback, void *opaque, Error **errp); +void inet_addr_to_opts (QemuOpts *opts,const InetSocketAddress *addr);int inet_dgram_opts (QemuOpts *opts,Error **errp);NetworkAddressFamily inet_netfamily (int family); +int inet_getport (struct addrinfo *e); +void inet_setport (struct addrinfo *e,int port);int unix_listen_opts (QemuOpts *opts,Error **errp);int unix_listen (const char *path,char *ostr,int olen,Error **errp);
@@ -71,6 +74,7 @@ int unix_connect(const char *path, Error **errp);int unix_nonblocking_connect (const char *str,NonBlockingConnectHandler *callback,void *opaque,Error **errp); +struct addrinfo *inet_parse_connect_opts (QemuOpts *opts,Error **errp);SocketAddress *socket_parse (const char *str,Error **errp); int socket_connect(SocketAddress *addr, Error **errp,
migration/Makefile.objs +1 -1
@@ -3,7 +3,7 @@ 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 += xbzrle.o -common-obj-$(CONFIG_RDMA) += rdma.o +common-obj-$(CONFIG_RDMA) += rdma.o rsocket.o common-obj-$(CONFIG_POSIX) += exec.o unix.o fd.o common-obj-y += block.o
migration/migration.c +4 -0
@@ -74,6 +74,8 @@ void qemu_start_incoming_migration(const char *uri, Error **errp)#ifdef CONFIG_RDMA else if (strstart(uri, "rdma:", &p)) rdma_start_incoming_migration(p, errp); + else if (strstart(uri, "rsocket:", &p)) + rsocket_start_incoming_migration(p, errp);#endif #if !defined(WIN32 ) else if (strstart(uri, "exec:", &p))
@@ -442,6 +444,8 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, #ifdef CONFIG_RDMA }else if (strstart (uri,"rdma:" , &p)) {rdma_start_outgoing_migration (s, p, &local_err); + }else if (strstart (uri,"rsocket:" , &p)) { +rsocket_start_outgoing_migration (s, p, &local_err);#endif #if !defined(WIN32 ) } else if (strstart(uri, "exec:", &p)) {
migration/rsocket.c new file +964 -0
964 lines not on this page · raw message
qemu-coroutine-io.c +2 -1
@@ -37,7 +37,8 @@ qemu_co_sendv_recvv(int sockfd, struct iovec *iov, unsigned iov_cnt,int err;while (done < bytes) { ret =iov_send_recv (sockfd, iov, iov_cnt, - offset + done, bytes - done, do_send); + offset + done, bytes - done, do_send, + iov_send_recv_fd);if (ret >0 ) { done += ret; }else if (ret <0 ) {
trace-events +35 -0
@@ -1149,6 +1149,41 @@ vmstate_load_field_error(const char *field, int ret) "field \"%s\" load failed, # qemu-file.c qemu_file_fclose(void) "" +rsocket_handler_fdcallback(void) "" +rsocket_handler_thread_top(void) "" +rsocket_handler_thread_after_poll(void) "" +rsocket_set_handler(void) "" +rsocket_wait_for_connect(void) "" +rsocket_inet_connect_addr(void) "" +rsocket_inet_connect_opts(void) "" +rsocket_inet_listen_opts(void) "" +rsocket_inet_listen(void) "" +rsocket_yield_thread_top(void) "" +rsocket_yield_thread_requested_exit(void) "" +rsocket_yield_thread_exit(void) "" +rsocket_set_nonblock(int rfd) "%d" +rsocket_start_yield_thread(void) "" +rsocket_stop_yield_thread(void) "" +rsocket_yield(void) "" +rsocket_send(void) "" +rsocket_writev_buffer(ssize_t size) "%zd" +rsocket_writev_buffer_end(ssize_t size, ssize_t len) "size=%zd / return %zd" +rsocket_get_buffer(int size) "size=%d" +rsocket_get_buffer_exit(int size, ssize_t len) "size=%d return %zd" +rsocket_close(void) "" +qemu_fopen_rsocket(int rfd, const char *mode) "rfd %d mode %s" +rsocket_have_connect(int rfd) "rfd %d" +rsocket_start_outgoing_migration(void) "" +rsocket_accept_incoming_migration(void) "" +rsocket_start_incoming_migration(void) "" +rsocket_dest_ramblock_reg(const char *block_name, uint64_t block_offset, uint64_t rsock_key) "%s %" PRIx64 "->%" PRIx64 +rsocket_source_ramblock_setup(const char *block_name, uint64_t block_offset, uint64_t rsock_key) "%s %" PRIx64 "->%" PRIx64 +rsocket_dest_before_ram_iterate(uint64_t flags) "%" PRIx64 +rsocket_save_page(uint64_t block_offset, uint64_t offset, uint64_t rsocket_key) "block=%" PRIx64 " offset=%" PRIx64 " rsocket_key=%" PRIx64 +rsocket_source_before_ram_iterate(uint64_t flags) "%" PRIx64 +rsocket_close_RAMBlock_func(void *host_addr, bool isSource) "%p %u" +rsocket_save_page_riowrite_eagain(uint64_t offset) "%" PRIx64 + # arch_init.c migration_bitmap_sync_start(void) "" migration_bitmap_sync_end(uint64_t dirty_pages) "dirty_pages %" PRIu64""
util/iov.c +7 -7
@@ -88,9 +88,9 @@ size_t iov_size(const struct iovec *iov, const unsigned int iov_cnt)return len; } -/* helper function for iov_send_recv() */ -static ssize_t -do_send_recv (int sockfd,struct iovec *iov,unsigned iov_cnt,bool do_send) +/* helper function for iov_send_recv() for normal FDs */ +ssize_t iov_send_recv_fd (int sockfd,struct iovec *iov,unsigned iov_cnt, +bool do_send) {#ifdef CONFIG_POSIX ssize_t ret;
@@ -134,8 +134,8 @@ do_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt, bool do_send) }ssize_t iov_send_recv (int sockfd,struct iovec *iov,unsigned iov_cnt, -size_t offset,size_t bytes, -bool do_send) +size_t offset,size_t bytes,bool do_send, +iov_send_recv_func helper) {ssize_t total =0 ;ssize_t ret;
@@ -174,11 +174,11 @@ ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt,assert (iov[niov].iov_len > tail); orig_len = iov[niov].iov_len; iov[niov++].iov_len = tail; - ret =do_send_recv (sockfd, iov, niov, do_send); + ret =helper (sockfd, iov, niov, do_send);/* Undo the changes above before checking for errors */ iov[niov-1 ].iov_len = orig_len; }else { - ret =do_send_recv (sockfd, iov, niov, do_send); + ret =helper (sockfd, iov, niov, do_send); }if (offset) { iov[0 ].iov_base -= offset;
util/qemu-sockets.c +4 -4
@@ -58,7 +58,7 @@ QemuOptsList socket_optslist = { }, }; -static int inet_getport (struct addrinfo *e) +int inet_getport (struct addrinfo *e) {struct sockaddr_in *i4;struct sockaddr_in6 *i6;
@@ -75,7 +75,7 @@ static int inet_getport(struct addrinfo *e) } } -static void inet_setport (struct addrinfo *e,int port) +void inet_setport (struct addrinfo *e,int port) {struct sockaddr_in *i4;struct sockaddr_in6 *i6;
@@ -319,7 +319,7 @@ static int inet_connect_addr(struct addrinfo *addr, bool *in_progress,return sock; } -static struct addrinfo *inet_parse_connect_opts (QemuOpts *opts,Error **errp) +struct addrinfo *inet_parse_connect_opts (QemuOpts *opts,Error **errp) {struct addrinfo ai, *res;int rc;
@@ -574,7 +574,7 @@ fail:return NULL ; } -static void inet_addr_to_opts (QemuOpts *opts,const InetSocketAddress *addr) +void inet_addr_to_opts (QemuOpts *opts,const InetSocketAddress *addr) {bool ipv4 = addr->ipv4 || !addr->has_ipv4;bool ipv6 = addr->ipv6 || !addr->has_ipv6;
Signature · 1 line
2.1.0