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