4841a6
From a7c6bc008fe006f005d5c15d3f883572ad5defc5 Mon Sep 17 00:00:00 2001
719b13
From: Leonardo Bras <leobras@redhat.com>
719b13
Date: Wed, 18 May 2022 02:52:25 -0300
4841a6
Subject: [PATCH 20/37] migration: Add migrate_use_tls() helper
719b13
MIME-Version: 1.0
719b13
Content-Type: text/plain; charset=UTF-8
719b13
Content-Transfer-Encoding: 8bit
719b13
719b13
RH-Author: Leonardo Brás <leobras@redhat.com>
4841a6
RH-MergeRequest: 191: MSG_ZEROCOPY + Multifd @ rhel8.7
4841a6
RH-Commit: [20/26] 02afc2e60f1abbf6db45d83e54a18b66dad52426
4841a6
RH-Bugzilla: 2072049
719b13
RH-Acked-by: Peter Xu <peterx@redhat.com>
4841a6
RH-Acked-by: Daniel P. Berrangé <berrange@redhat.com>
4841a6
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
719b13
719b13
A lot of places check parameters.tls_creds in order to evaluate if TLS is
719b13
in use, and sometimes call migrate_get_current() just for that test.
719b13
719b13
Add new helper function migrate_use_tls() in order to simplify testing
719b13
for TLS usage.
719b13
719b13
Signed-off-by: Leonardo Bras <leobras@redhat.com>
719b13
Reviewed-by: Juan Quintela <quintela@redhat.com>
719b13
Reviewed-by: Peter Xu <peterx@redhat.com>
719b13
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
719b13
Message-Id: <20220513062836.965425-6-leobras@redhat.com>
719b13
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
719b13
(cherry picked from commit d2fafb6a6814a8998607d0baf691265032996a0f)
719b13
Signed-off-by: Leonardo Bras <leobras@redhat.com>
719b13
---
719b13
 migration/channel.c   | 3 +--
719b13
 migration/migration.c | 9 +++++++++
719b13
 migration/migration.h | 1 +
719b13
 migration/multifd.c   | 5 +----
719b13
 4 files changed, 12 insertions(+), 6 deletions(-)
719b13
719b13
diff --git a/migration/channel.c b/migration/channel.c
719b13
index c4fc000a1a..086b5c0d8b 100644
719b13
--- a/migration/channel.c
719b13
+++ b/migration/channel.c
719b13
@@ -38,8 +38,7 @@ void migration_channel_process_incoming(QIOChannel *ioc)
719b13
     trace_migration_set_incoming_channel(
719b13
         ioc, object_get_typename(OBJECT(ioc)));
719b13
 
719b13
-    if (s->parameters.tls_creds &&
719b13
-        *s->parameters.tls_creds &&
719b13
+    if (migrate_use_tls() &&
719b13
         !object_dynamic_cast(OBJECT(ioc),
719b13
                              TYPE_QIO_CHANNEL_TLS)) {
719b13
         migration_tls_channel_process_incoming(s, ioc, &local_err);
719b13
diff --git a/migration/migration.c b/migration/migration.c
719b13
index b0fc3f68bd..8e28f2ee41 100644
719b13
--- a/migration/migration.c
719b13
+++ b/migration/migration.c
719b13
@@ -2568,6 +2568,15 @@ bool migrate_use_zero_copy_send(void)
719b13
 }
719b13
 #endif
719b13
 
719b13
+int migrate_use_tls(void)
719b13
+{
719b13
+    MigrationState *s;
719b13
+
719b13
+    s = migrate_get_current();
719b13
+
719b13
+    return s->parameters.tls_creds && *s->parameters.tls_creds;
719b13
+}
719b13
+
719b13
 int migrate_use_xbzrle(void)
719b13
 {
719b13
     MigrationState *s;
719b13
diff --git a/migration/migration.h b/migration/migration.h
719b13
index 908098939f..9396b7e90a 100644
719b13
--- a/migration/migration.h
719b13
+++ b/migration/migration.h
719b13
@@ -344,6 +344,7 @@ bool migrate_use_zero_copy_send(void);
719b13
 #else
719b13
 #define migrate_use_zero_copy_send() (false)
719b13
 #endif
719b13
+int migrate_use_tls(void);
719b13
 int migrate_use_xbzrle(void);
719b13
 uint64_t migrate_xbzrle_cache_size(void);
719b13
 bool migrate_colo_enabled(void);
719b13
diff --git a/migration/multifd.c b/migration/multifd.c
719b13
index 3725226400..e53811f04a 100644
719b13
--- a/migration/multifd.c
719b13
+++ b/migration/multifd.c
719b13
@@ -789,14 +789,11 @@ static bool multifd_channel_connect(MultiFDSendParams *p,
719b13
                                     QIOChannel *ioc,
719b13
                                     Error *error)
719b13
 {
719b13
-    MigrationState *s = migrate_get_current();
719b13
-
719b13
     trace_multifd_set_outgoing_channel(
719b13
         ioc, object_get_typename(OBJECT(ioc)), p->tls_hostname, error);
719b13
 
719b13
     if (!error) {
719b13
-        if (s->parameters.tls_creds &&
719b13
-            *s->parameters.tls_creds &&
719b13
+        if (migrate_use_tls() &&
719b13
             !object_dynamic_cast(OBJECT(ioc),
719b13
                                  TYPE_QIO_CHANNEL_TLS)) {
719b13
             multifd_tls_channel_connect(p, ioc, &error);
719b13
-- 
719b13
2.35.3
719b13