[PATCH 2/2] remote: allow migrations with the ext transport

Sergey Dyasli posted 2 patches 2 weeks, 3 days ago
[PATCH 2/2] remote: allow migrations with the ext transport
Posted by Sergey Dyasli 2 weeks, 3 days ago
Add virURICheckExtCommand() in a similar fashion to the existing
virURICheckUnixSocket() and use it for (1) the same host migration check
and (2) in remoteConnectOpen().

This allows to migrate VMs using the ext transport, as the external
command can act as a proxy to the remote libvirt.

Signed-off-by: Sergey Dyasli <sergey.dyasli@nutanix.com>
---
 src/libvirt-domain.c       |  8 +++++---
 src/remote/remote_driver.c |  7 ++++---
 src/util/viruri.c          | 32 ++++++++++++++++++++++++++++++++
 src/util/viruri.h          |  2 ++
 4 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index ca110bdf8585..9d82b711a17c 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -3605,11 +3605,13 @@ virDomainMigrateCheckNotLocal(const char *dconnuri)
         return -1;
 
     /*
-     * If someone migrates explicitly to a unix socket, then they have to know
-     * what they are doing and it most probably was not a mistake.
+     * If someone migrates explicitly to a unix socket or an ext command, then
+     * they have to know what they are doing and it most probably was not
+     * a mistake.
      */
     if ((tempuri->server && STRPREFIX(tempuri->server, "localhost")) ||
-        (!tempuri->server && !virURICheckUnixSocket(tempuri))) {
+        (!tempuri->server && !virURICheckUnixSocket(tempuri) &&
+         !virURICheckExtCommand(tempuri))) {
         virReportInvalidArg(dconnuri, "%s",
                             _("Attempt to migrate guest to the same host"));
         return -1;
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index e5f425da74bf..0e7e8f2eb76b 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -1377,15 +1377,16 @@ remoteConnectOpen(virConnectPtr conn,
             return VIR_DRV_OPEN_DECLINED;
 
         /* Handle deferring to local drivers if we are dealing with a default
-         * local URI. (Unknown local socket paths may be proxied to a remote
-         * host so they are treated as remote too).
+         * local URI. (Unknown local socket paths and commands may be proxied
+         * to a remote host so they are treated as remote too).
          *
          * Deferring to a local driver is needed if:
          * - the driver is registered in the current daemon
          * - if we are running monolithic libvirtd, in which case we consider
          *   even un-registered drivers as local
          */
-        if (!conn->uri->server && !virURICheckUnixSocket(conn->uri)) {
+        if (!conn->uri->server && !virURICheckUnixSocket(conn->uri) &&
+            !virURICheckExtCommand(conn->uri)) {
             if (virHasDriverForURIScheme(driver))
                 return VIR_DRV_OPEN_DECLINED;
 
diff --git a/src/util/viruri.c b/src/util/viruri.c
index 64995da3420d..2e8c0acfb213 100644
--- a/src/util/viruri.c
+++ b/src/util/viruri.c
@@ -421,6 +421,38 @@ virURICheckUnixSocket(virURI *uri)
 }
 
 
+/**
+ * virURICheckExtCommand:
+ * @uri: URI to check
+ *
+ * Check if the URI looks like it refers to a user specified command. In such
+ * scenario the command might do proxying to a remote server even though the URI
+ * looks like it is only local.
+ *
+ * The "command" parameter is looked for in case insensitive manner, by design.
+ *
+ * Returns: true if the URI might be proxied to a remote server
+ */
+bool
+virURICheckExtCommand(virURI *uri)
+{
+    size_t i = 0;
+
+    if (!uri->scheme)
+        return false;
+
+    if (STRNEQ_NULLABLE(strchr(uri->scheme, '+'), "+ext"))
+        return false;
+
+    for (i = 0; i < uri->paramsCount; i++) {
+        if (STRCASEEQ(uri->params[i].name, "command"))
+            return true;
+    }
+
+    return false;
+}
+
+
 void
 virURIParamsSetIgnore(virURI *uri,
                       bool ignore,
diff --git a/src/util/viruri.h b/src/util/viruri.h
index ad00570b7f0d..172314bd1084 100644
--- a/src/util/viruri.h
+++ b/src/util/viruri.h
@@ -61,6 +61,8 @@ const char *virURIGetParam(virURI *uri, const char *name);
 
 bool virURICheckUnixSocket(virURI *uri);
 
+bool virURICheckExtCommand(virURI *uri);
+
 void virURIParamsSetIgnore(virURI *uri, bool ignore, const char *names[]);
 
 #define VIR_URI_SERVER(uri) ((uri) && (uri)->server ? (uri)->server : "localhost")
-- 
2.39.3