[PATCH 5/6] Introduce VIR_CONNECT_NO_REMOTE

Peter Krempa pkrempa at redhat.com
Thu Sep 8 15:15:59 UTC 2022


Introduce a new virConnectFlags flag that will allow to avoid the use of
the 'remote' driver. While this flag itself is not useful for users, in
case when monolithic libvirtd is in use we want to avoid further
delegation of connection, which can happen if libvirtd is not compiled
with the requested driver.

Add and implement the new flag.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 include/libvirt/libvirt-host.h |  2 ++
 src/libvirt.c                  | 38 +++++++++++++++++++++-------------
 2 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/include/libvirt/libvirt-host.h b/include/libvirt/libvirt-host.h
index 3112f2b676..463b3f78af 100644
--- a/include/libvirt/libvirt-host.h
+++ b/include/libvirt/libvirt-host.h
@@ -602,6 +602,8 @@ int virNodeGetSEVInfo (virConnectPtr conn,
 typedef enum {
     VIR_CONNECT_RO         = (1 << 0),  /* A readonly connection (Since: 0.4.1) */
     VIR_CONNECT_NO_ALIASES = (1 << 1),  /* Don't try to resolve URI aliases (Since: 0.9.7) */
+    VIR_CONNECT_NO_REMOTE  = (1 << 2),  /* Avoid use of the remote driver. Users
+                                           should not use this flag. (Since: 8.8.0) */
 } virConnectFlags;

 /**
diff --git a/src/libvirt.c b/src/libvirt.c
index d5ae68d16f..5312265619 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -886,6 +886,9 @@ virConnectOpenInternal(const char *name,
     g_autoptr(virConf) conf = NULL;
     g_autofree char *uristr = NULL;
     bool embed = false;
+    bool no_remote = flags & VIR_CONNECT_NO_REMOTE;
+
+    flags &= ~VIR_CONNECT_NO_REMOTE;

     ret = virGetConnect();
     if (ret == NULL)
@@ -1036,26 +1039,33 @@ virConnectOpenInternal(const char *name,
          * driver then report a useful error, instead of a cryptic one about
          * not being able to connect to libvirtd or not being able to find
          * certificates. */
-        if (STREQ(virConnectDriverTab[i]->hypervisorDriver->name, "remote") &&
-            ret->uri != NULL &&
-            (
+        if (STREQ(virConnectDriverTab[i]->hypervisorDriver->name, "remote")) {
+
+            if (ret->uri != NULL &&
+                (
 #ifndef WITH_ESX
-             STRCASEEQ(ret->uri->scheme, "vpx") ||
-             STRCASEEQ(ret->uri->scheme, "esx") ||
-             STRCASEEQ(ret->uri->scheme, "gsx") ||
+                 STRCASEEQ(ret->uri->scheme, "vpx") ||
+                 STRCASEEQ(ret->uri->scheme, "esx") ||
+                 STRCASEEQ(ret->uri->scheme, "gsx") ||
 #endif
 #ifndef WITH_HYPERV
-             STRCASEEQ(ret->uri->scheme, "hyperv") ||
+                 STRCASEEQ(ret->uri->scheme, "hyperv") ||
 #endif
 #ifndef WITH_VZ
-             STRCASEEQ(ret->uri->scheme, "parallels") ||
+                 STRCASEEQ(ret->uri->scheme, "parallels") ||
 #endif
-             false)) {
-            virReportErrorHelper(VIR_FROM_NONE, VIR_ERR_CONFIG_UNSUPPORTED,
-                                 __FILE__, __FUNCTION__, __LINE__,
-                                 _("libvirt was built without the '%s' driver"),
-                                 ret->uri->scheme);
-            return NULL;
+                 false)) {
+                virReportErrorHelper(VIR_FROM_NONE, VIR_ERR_CONFIG_UNSUPPORTED,
+                                     __FILE__, __FUNCTION__, __LINE__,
+                                     _("libvirt was built without the '%s' driver"),
+                                     ret->uri->scheme);
+                return NULL;
+            }
+
+            if (no_remote) {
+                VIR_DEBUG("skipping 'remote' per VIR_CONNECT_NO_REMOTE");
+                continue;
+            }
         }

         VIR_DEBUG("trying driver %zu (%s) ...",
-- 
2.37.1



More information about the libvir-list mailing list