Skip to contentSkip to conversation

mptcp support

PATCH In review Dr. David Alan Gilbert (git) 3 participants 11 messages Apr 21, 2021 – Jun 8, 2021

lore
Share & tools
lore
#0 lore raw

v2 cover mptcp support

From: "Dr. David Alan Gilbert" <[email protected]>

Hi,
This set adds support for multipath TCP (mptcp), and has
been tested for migration and (lightly) for NBD.

Multipath-tcp is a bit like bonding, but at L3; you can use
it to handle failure, but can also use it to split traffic across multiple interfaces.

Using a pair of 10Gb interfaces, I've managed to get 19Gbps
(with the only tuning being using huge pages and turning the MTU up).

It needs a bleeding-edge Linux kernel (in some older ones you get
false accept messages for the subflows), and a C lib that has the constants defined (as current glibc does).

To use it you just need to append ,mptcp to an address; for migration:

-incoming tcp:0:4444,mptcp
migrate -d tcp:192.168.11.20:4444,mptcp

For nbd:

(qemu) nbd_server_start 0.0.0.0:3333,mptcp=on

  -blockdev driver=nbd,server.type=inet,server.host=192.168.11.20,server.port=3333,server.mptcp=on,node-name=nbddisk,export=mydisk \
  -device virtio-blk,drive=nbddisk,id=disk0

(Many of the other NBD address parsers/forms would need extra work)

All comments welcome.

Dave

v2
Use of if defined(...) in the json file based on feedback A few missing ifdef's (from a bsd build test) Added nbd example.

Dr. David Alan Gilbert (5):
channel-socket: Only set CLOEXEC if we have space for fds io/net-listener: Call the notifier during finalize
migration: Add cleanup hook for inwards migration migration/socket: Close the listener at the end
sockets: Support multipath TCP

 io/channel-socket.c   |  8 ++++----
 io/dns-resolver.c     |  4 ++++
 io/net-listener.c     |  3 +++
 migration/migration.c |  3 +++
 migration/migration.h |  4 ++++
 migration/multifd.c   |  5 +++++
 migration/socket.c    | 24 ++++++++++++++++++------
 qapi/sockets.json     |  5 ++++-
 util/qemu-sockets.c   | 23 +++++++++++++++++++++++
 9 files changed, 68 insertions(+), 11 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH v2 1/5 channel-socket: Only set CLOEXEC if we have space for fds

From: "Dr. David Alan Gilbert" <[email protected]>

MSG_CMSG_CLOEXEC cleans up received fd's; it's really only for Unix sockets, but currently we enable it for everything; some socket types (IP_MPTCP) don't like this.

Only enable it when we're giving the recvmsg room to receive fd's anyway.

---
 io/channel-socket.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
io/channel-socket.c +4 -4
index de259f7eed..606ec97cf7 100644
@@ -487,15 +487,15 @@ static ssize_t qio_channel_socket_readv(QIOChannel *ioc,
 
     memset(control, 0, CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS));
 
-#ifdef MSG_CMSG_CLOEXEC
-    sflags |= MSG_CMSG_CLOEXEC;
-#endif
-
     msg.msg_iov = (struct iovec *)iov;
     msg.msg_iovlen = niov;
     if (fds && nfds) {
         msg.msg_control = control;
         msg.msg_controllen = sizeof(control);
+#ifdef MSG_CMSG_CLOEXEC
+        sflags |= MSG_CMSG_CLOEXEC;
+#endif
+
     }
 
  retry:
Signature · 1 line
2.31.1
#2 lore raw

PATCH v2 2/5 io/net-listener: Call the notifier during finalize

In reply to Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

Call the notifier during finalize; it's currently only called if we change it, which is not the intent.

---
 io/net-listener.c | 3 +++
 1 file changed, 3 insertions(+)
io/net-listener.c +3 -0
index 46c2643d00..1c984d69c6 100644
@@ -292,6 +292,9 @@ static void qio_net_listener_finalize(Object *obj)
     QIONetListener *listener = QIO_NET_LISTENER(obj);
     size_t i;
 
+    if (listener->io_notify) {
+        listener->io_notify(listener->io_data);
+    }
     qio_net_listener_disconnect(listener);
 
     for (i = 0; i < listener->nsioc; i++) {
Signature · 1 line
2.31.1
#3 lore raw

PATCH v2 3/5 migration: Add cleanup hook for inwards migration

In reply to Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

Add a cleanup hook for incoming migration that gets called at the end as a way for a transport to allow cleanup.

---
 migration/migration.c | 3 +++
 migration/migration.h | 4 ++++
 2 files changed, 7 insertions(+)
migration/migration.c +3 -0
index 8ca034136b..d48986fbbb 100644
@@ -279,6 +279,9 @@ void migration_incoming_state_destroy(void)
         g_array_free(mis->postcopy_remote_fds, TRUE);
         mis->postcopy_remote_fds = NULL;
     }
+    if (mis->transport_cleanup) {
+        mis->transport_cleanup(mis->transport_data);
+    }
 
     qemu_event_reset(&mis->main_thread_load_event);
 
migration/migration.h +4 -0
index db6708326b..1b4c5da917 100644
@@ -49,6 +49,10 @@ struct PostcopyBlocktimeContext;
 struct MigrationIncomingState {
     QEMUFile *from_src_file;
 
+    /* A hook to allow cleanup at the end of incoming migration */
+    void *transport_data;
+    void (*transport_cleanup)(void *data);
+
     /*
      * Free at the start of the main state load, set as the main thread finishes
      * loading state.
Signature · 1 line
2.31.1
#4 lore raw

PATCH v2 4/5 migration/socket: Close the listener at the end

In reply to Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

Delay closing the listener until the cleanup hook at the end; mptcp needs the listener to stay open while the other paths come in.

---
 migration/multifd.c |  5 +++++
 migration/socket.c  | 24 ++++++++++++++++++------
 2 files changed, 23 insertions(+), 6 deletions(-)
migration/multifd.c +5 -0
index a6677c45c8..cebd9029b9 100644
@@ -1165,6 +1165,11 @@ bool multifd_recv_all_channels_created(void)
         return true;
     }
 
+    if (!multifd_recv_state) {
+        /* Called before any connections created */
+        return false;
+    }
+
     return thread_count == qatomic_read(&multifd_recv_state->count);
 }
 
migration/socket.c +18 -6
index 6016642e04..05705a32d8 100644
@@ -126,22 +126,31 @@ static void socket_accept_incoming_migration(QIONetListener *listener,
 {
     trace_migration_socket_incoming_accepted();
 
-    qio_channel_set_name(QIO_CHANNEL(cioc), "migration-socket-incoming");
-    migration_channel_process_incoming(QIO_CHANNEL(cioc));
-
     if (migration_has_all_channels()) {
-        /* Close listening socket as its no longer needed */
-        qio_net_listener_disconnect(listener);
-        object_unref(OBJECT(listener));
+        error_report("%s: Extra incoming migration connection; ignoring",
+                     __func__);
+        return;
     }
+
+    qio_channel_set_name(QIO_CHANNEL(cioc), "migration-socket-incoming");
+    migration_channel_process_incoming(QIO_CHANNEL(cioc));
 }
 
+static void
+socket_incoming_migration_end(void *opaque)
+{
+    QIONetListener *listener = opaque;
+
+    qio_net_listener_disconnect(listener);
+    object_unref(OBJECT(listener));
+}
 
 static void
 socket_start_incoming_migration_internal(SocketAddress *saddr,
                                          Error **errp)
 {
     QIONetListener *listener = qio_net_listener_new();
+    MigrationIncomingState *mis = migration_incoming_get_current();
     size_t i;
     int num = 1;
 
@@ -156,6 +165,9 @@ socket_start_incoming_migration_internal(SocketAddress *saddr,
         return;
     }
 
+    mis->transport_data = listener;
+    mis->transport_cleanup = socket_incoming_migration_end;
+
     qio_net_listener_set_client_func_full(listener,
                                           socket_accept_incoming_migration,
                                           NULL, NULL,
Signature · 1 line
2.31.1
#5 lore raw

PATCH v2 5/5 sockets: Support multipath TCP

In reply to Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

Multipath TCP allows combining multiple interfaces/routes into a single socket, with very little work for the user/admin.

It's enabled by 'mptcp' on most socket addresses:

./qemu-system-x86_64 -nographic -incoming tcp:0:4444,mptcp

---
 io/dns-resolver.c   |  4 ++++
 qapi/sockets.json   |  5 ++++-
 util/qemu-sockets.c | 23 +++++++++++++++++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)
io/dns-resolver.c +4 -0
index 743a0efc87..a5946a93bf 100644
@@ -122,6 +122,10 @@ static int qio_dns_resolver_lookup_sync_inet(QIODNSResolver *resolver,
             .ipv4 = iaddr->ipv4,
             .has_ipv6 = iaddr->has_ipv6,
             .ipv6 = iaddr->ipv6,
+#ifdef IPPROTO_MPTCP
+            .has_mptcp = iaddr->has_mptcp,
+            .mptcp = iaddr->mptcp,
+#endif
         };
 
         (*addrs)[i] = newaddr;
qapi/sockets.json +4 -1
index 2e83452797..735eb4abb5 100644
@@ -57,6 +57,8 @@
 # @keep-alive: enable keep-alive when connecting to this socket. Not supported
 #              for passive sockets. (Since 4.2)
 #
+# @mptcp: enable multi-path TCP. (Since 6.1)
+#
 # Since: 1.3
 ##
 { 'struct': 'InetSocketAddress',
@@ -66,7 +68,8 @@
     '*to': 'uint16',
     '*ipv4': 'bool',
     '*ipv6': 'bool',
-    '*keep-alive': 'bool' } }
+    '*keep-alive': 'bool',
+    '*mptcp': { 'type': 'bool', 'if': 'defined(IPPROTO_MPTCP)' } } }
 
 ##
 # @UnixSocketAddress:
util/qemu-sockets.c +23 -0
index 8af0278f15..ba7cb1ec4f 100644
@@ -278,6 +278,11 @@ static int inet_listen_saddr(InetSocketAddress *saddr,
 
     /* create socket + bind/listen */
     for (e = res; e != NULL; e = e->ai_next) {
+#ifdef IPPROTO_MPTCP
+        if (saddr->has_mptcp && saddr->mptcp) {
+            e->ai_protocol = IPPROTO_MPTCP;
+        }
+#endif
         getnameinfo((struct sockaddr*)e->ai_addr,e->ai_addrlen,
                         uaddr,INET6_ADDRSTRLEN,uport,32,
                         NI_NUMERICHOST | NI_NUMERICSERV);
@@ -456,6 +461,13 @@ int inet_connect_saddr(InetSocketAddress *saddr, Error **errp)
     for (e = res; e != NULL; e = e->ai_next) {
         error_free(local_err);
         local_err = NULL;
+
+#ifdef IPPROTO_MPTCP
+        if (saddr->has_mptcp && saddr->mptcp) {
+            e->ai_protocol = IPPROTO_MPTCP;
+        }
+#endif
+
         sock = inet_connect_addr(saddr, e, &local_err);
         if (sock >= 0) {
             break;
@@ -687,6 +699,17 @@ int inet_parse(InetSocketAddress *addr, const char *str, Error **errp)
         }
         addr->has_keep_alive = true;
     }
+#ifdef IPPROTO_MPTCP
+    begin = strstr(optstr, ",mptcp");
+    if (begin) {
+        if (inet_parse_flag("mptcp", begin + strlen(",mptcp"),
+                            &addr->mptcp, errp) < 0)
+        {
+            return -1;
+        }
+        addr->has_mptcp = true;
+    }
+#endif
     return 0;
 }
 
Signature · 1 line
2.31.1
Reviewed-by on v2 5/5
#6 lore raw

Re: [PATCH v2 5/5] sockets: Support multipath TCP

Quoted 7 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

Multipath TCP allows combining multiple interfaces/routes into a single socket, with very little work for the user/admin.

It's enabled by 'mptcp' on most socket addresses:

Quoted 8 lines
   ./qemu-system-x86_64 -nographic -incoming tcp:0:4444,mptcp
---
 io/dns-resolver.c   |  4 ++++
 qapi/sockets.json   |  5 ++++-
 util/qemu-sockets.c | 23 +++++++++++++++++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#7 lore raw

Re: [PATCH v2 5/5] sockets: Support multipath TCP

Quoted 10 lines · * Daniel P. Berrangé ([email protected]) wrote:
Quoted 9 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

Multipath TCP allows combining multiple interfaces/routes into a single socket, with very little work for the user/admin.

It's enabled by 'mptcp' on most socket addresses:

   ./qemu-system-x86_64 -nographic -incoming tcp:0:4444,mptcp
Quoted 8 lines
Quoted 6 lines
---
 io/dns-resolver.c   |  4 ++++
 qapi/sockets.json   |  5 ++++-
 util/qemu-sockets.c | 23 +++++++++++++++++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)

Thanks, given this is more socketary than migration code, do you want to take this series via your tree?

Dave

Quoted 7 lines

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Acked-by on v2 5/5
#8 lore raw

Re: [PATCH v2 5/5] sockets: Support multipath TCP

In reply to Dr. David Alan Gilbert (git)
Quoted 10 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

Multipath TCP allows combining multiple interfaces/routes into a single socket, with very little work for the user/admin.

It's enabled by 'mptcp' on most socket addresses:

   ./qemu-system-x86_64 -nographic -incoming tcp:0:4444,mptcp

For the QAPI schema:

Reviewed-by on v2 5/5
#9 lore raw

Re: [PATCH v2 5/5] sockets: Support multipath TCP

In reply to Dr. David Alan Gilbert (git)
Quoted 7 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

Multipath TCP allows combining multiple interfaces/routes into a single socket, with very little work for the user/admin.

It's enabled by 'mptcp' on most socket addresses:

Quoted 8 lines
   ./qemu-system-x86_64 -nographic -incoming tcp:0:4444,mptcp
---
 io/dns-resolver.c   |  4 ++++
 qapi/sockets.json   |  5 ++++-
 util/qemu-sockets.c | 23 +++++++++++++++++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#10 lore raw
In reply to Dr. David Alan Gilbert (git)
Quoted 26 lines · * Dr. David Alan Gilbert (git) ([email protected]) wrote:

From: "Dr. David Alan Gilbert" <[email protected]>

Hi,
This set adds support for multipath TCP (mptcp), and has
been tested for migration and (lightly) for NBD.

Multipath-tcp is a bit like bonding, but at L3; you can use
it to handle failure, but can also use it to split traffic across multiple interfaces.

Using a pair of 10Gb interfaces, I've managed to get 19Gbps
(with the only tuning being using huge pages and turning the MTU up).

It needs a bleeding-edge Linux kernel (in some older ones you get
false accept messages for the subflows), and a C lib that has the constants defined (as current glibc does).

To use it you just need to append ,mptcp to an address; for migration:

-incoming tcp:0:4444,mptcp
migrate -d tcp:192.168.11.20:4444,mptcp

For nbd:

(qemu) nbd_server_start 0.0.0.0:3333,mptcp=on

Quoted 8 lines
  -blockdev driver=nbd,server.type=inet,server.host=192.168.11.20,server.port=3333,server.mptcp=on,node-name=nbddisk,export=mydisk \
  -device virtio-blk,drive=nbddisk,id=disk0

(Many of the other NBD address parsers/forms would need extra work)

All comments welcome.

Dave

Queued

Quoted 29 lines

v2
Use of if defined(...) in the json file based on feedback A few missing ifdef's (from a bsd build test) Added nbd example.

Dr. David Alan Gilbert (5):
channel-socket: Only set CLOEXEC if we have space for fds io/net-listener: Call the notifier during finalize
migration: Add cleanup hook for inwards migration migration/socket: Close the listener at the end
sockets: Support multipath TCP

 io/channel-socket.c   |  8 ++++----
 io/dns-resolver.c     |  4 ++++
 io/net-listener.c     |  3 +++
 migration/migration.c |  3 +++
 migration/migration.h |  4 ++++
 migration/multifd.c   |  5 +++++
 migration/socket.c    | 24 ++++++++++++++++++------
 qapi/sockets.json     |  5 ++++-
 util/qemu-sockets.c   | 23 +++++++++++++++++++++++
 9 files changed, 68 insertions(+), 11 deletions(-)
Signature · 1 line
2.31.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK