586cba
From 828f6c106eedcb7a48e551ffda15af56ff92a899 Mon Sep 17 00:00:00 2001
586cba
From: Leonardo Bras <leobras@redhat.com>
586cba
Date: Fri, 13 May 2022 03:28:34 -0300
586cba
Subject: [PATCH 11/18] migration: Add migrate_use_tls() helper
586cba
MIME-Version: 1.0
586cba
Content-Type: text/plain; charset=UTF-8
586cba
Content-Transfer-Encoding: 8bit
586cba
586cba
RH-Author: Leonardo Brás <leobras@redhat.com>
586cba
RH-MergeRequest: 95: MSG_ZEROCOPY + Multifd
586cba
RH-Commit: [5/11] 06e945297c3b9c0ce5864885aafcdba1e5746bc2 (LeoBras/centos-qemu-kvm)
586cba
RH-Bugzilla: 1968509
586cba
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
586cba
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
586cba
RH-Acked-by: Peter Xu <peterx@redhat.com>
586cba
586cba
A lot of places check parameters.tls_creds in order to evaluate if TLS is
586cba
in use, and sometimes call migrate_get_current() just for that test.
586cba
586cba
Add new helper function migrate_use_tls() in order to simplify testing
586cba
for TLS usage.
586cba
586cba
Signed-off-by: Leonardo Bras <leobras@redhat.com>
586cba
Reviewed-by: Juan Quintela <quintela@redhat.com>
586cba
Reviewed-by: Peter Xu <peterx@redhat.com>
586cba
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
586cba
Message-Id: <20220513062836.965425-6-leobras@redhat.com>
586cba
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
586cba
(cherry picked from commit d2fafb6a6814a8998607d0baf691265032996a0f)
586cba
Signed-off-by: Leonardo Bras <leobras@redhat.com>
586cba
---
586cba
 migration/channel.c   | 3 +--
586cba
 migration/migration.c | 9 +++++++++
586cba
 migration/migration.h | 1 +
586cba
 migration/multifd.c   | 5 +----
586cba
 4 files changed, 12 insertions(+), 6 deletions(-)
586cba
586cba
diff --git a/migration/channel.c b/migration/channel.c
586cba
index c4fc000a1a..086b5c0d8b 100644
586cba
--- a/migration/channel.c
586cba
+++ b/migration/channel.c
586cba
@@ -38,8 +38,7 @@ void migration_channel_process_incoming(QIOChannel *ioc)
586cba
     trace_migration_set_incoming_channel(
586cba
         ioc, object_get_typename(OBJECT(ioc)));
586cba
 
586cba
-    if (s->parameters.tls_creds &&
586cba
-        *s->parameters.tls_creds &&
586cba
+    if (migrate_use_tls() &&
586cba
         !object_dynamic_cast(OBJECT(ioc),
586cba
                              TYPE_QIO_CHANNEL_TLS)) {
586cba
         migration_tls_channel_process_incoming(s, ioc, &local_err);
586cba
diff --git a/migration/migration.c b/migration/migration.c
586cba
index 0a6b3b9f4d..d91efb66fe 100644
586cba
--- a/migration/migration.c
586cba
+++ b/migration/migration.c
586cba
@@ -2582,6 +2582,15 @@ bool migrate_use_zero_copy_send(void)
586cba
 }
586cba
 #endif
586cba
 
586cba
+int migrate_use_tls(void)
586cba
+{
586cba
+    MigrationState *s;
586cba
+
586cba
+    s = migrate_get_current();
586cba
+
586cba
+    return s->parameters.tls_creds && *s->parameters.tls_creds;
586cba
+}
586cba
+
586cba
 int migrate_use_xbzrle(void)
586cba
 {
586cba
     MigrationState *s;
586cba
diff --git a/migration/migration.h b/migration/migration.h
586cba
index 5bcb7628ef..c2cabb8a14 100644
586cba
--- a/migration/migration.h
586cba
+++ b/migration/migration.h
586cba
@@ -381,6 +381,7 @@ bool migrate_use_zero_copy_send(void);
586cba
 #else
586cba
 #define migrate_use_zero_copy_send() (false)
586cba
 #endif
586cba
+int migrate_use_tls(void);
586cba
 int migrate_use_xbzrle(void);
586cba
 uint64_t migrate_xbzrle_cache_size(void);
586cba
 bool migrate_colo_enabled(void);
586cba
diff --git a/migration/multifd.c b/migration/multifd.c
586cba
index 76b57a7177..43998ad117 100644
586cba
--- a/migration/multifd.c
586cba
+++ b/migration/multifd.c
586cba
@@ -784,14 +784,11 @@ static bool multifd_channel_connect(MultiFDSendParams *p,
586cba
                                     QIOChannel *ioc,
586cba
                                     Error *error)
586cba
 {
586cba
-    MigrationState *s = migrate_get_current();
586cba
-
586cba
     trace_multifd_set_outgoing_channel(
586cba
         ioc, object_get_typename(OBJECT(ioc)), p->tls_hostname, error);
586cba
 
586cba
     if (!error) {
586cba
-        if (s->parameters.tls_creds &&
586cba
-            *s->parameters.tls_creds &&
586cba
+        if (migrate_use_tls() &&
586cba
             !object_dynamic_cast(OBJECT(ioc),
586cba
                                  TYPE_QIO_CHANNEL_TLS)) {
586cba
             multifd_tls_channel_connect(p, ioc, &error);
586cba
-- 
586cba
2.35.3
586cba