]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Move virDomainGenerateMachineName to hypervisor/
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 20 Mar 2020 17:14:22 +0000 (18:14 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 7 Apr 2020 13:26:19 +0000 (15:26 +0200)
The virDomainGenerateMachineName() function doesn't belong in
src/conf/ really, because it has nothing to do with domain XML
parsing. It landed there because of lack of better place in the
past. But now that we have src/hypervisor/ the function should
live there. At the same time, the function name is changed to
match new location.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/conf/domain_conf.c
src/conf/domain_conf.h
src/hypervisor/domain_driver.c
src/hypervisor/domain_driver.h
src/libvirt_private.syms
src/lxc/lxc_domain.c
src/qemu/qemu_domain.c
tests/virsystemdtest.c

index 460f8064bea22469c86586ff8b9196eead8e2a4d..6ad7552bdee5b0bbe33c374e399dd1b2d2009ab8 100644 (file)
@@ -62,7 +62,6 @@
 #include "virdomainsnapshotobjlist.h"
 #include "virdomaincheckpointobjlist.h"
 #include "virutil.h"
-#include "vircrypto.h"
 
 #define VIR_FROM_THIS VIR_FROM_DOMAIN
 
@@ -31066,77 +31065,6 @@ virDomainDiskSetBlockIOTune(virDomainDiskDefPtr disk,
     return 0;
 }
 
-#define HOSTNAME_CHARS \
-    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"
-
-static void
-virDomainMachineNameAppendValid(virBufferPtr buf,
-                                const char *name)
-{
-    bool skip = true;
-
-    for (; *name; name++) {
-        if (strlen(virBufferCurrentContent(buf)) >= 64)
-            break;
-
-        if (*name == '.' || *name == '-') {
-            if (!skip)
-                virBufferAddChar(buf, *name);
-            skip = true;
-            continue;
-        }
-
-        skip = false;
-
-        if (!strchr(HOSTNAME_CHARS, *name))
-            continue;
-
-        virBufferAddChar(buf, *name);
-    }
-
-    /* trailing dashes or dots are not allowed */
-    virBufferTrimChars(buf, "-.");
-}
-
-#undef HOSTNAME_CHARS
-
-char *
-virDomainGenerateMachineName(const char *drivername,
-                             const char *root,
-                             int id,
-                             const char *name,
-                             bool privileged)
-{
-    virBuffer buf = VIR_BUFFER_INITIALIZER;
-
-    virBufferAsprintf(&buf, "%s-", drivername);
-
-    if (root) {
-        g_autofree char *hash = NULL;
-
-        /* When two embed drivers start two domains with the same @name and @id
-         * we would generate a non-unique name. Include parts of hashed @root
-         * which guarantees uniqueness. The first 8 characters of SHA256 ought
-         * to be enough for anybody. */
-        if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, root, &hash) < 0)
-            return NULL;
-
-        virBufferAsprintf(&buf, "embed-%.8s-", hash);
-    } else if (!privileged) {
-        g_autofree char *username = NULL;
-        if (!(username = virGetUserName(geteuid()))) {
-            virBufferFreeAndReset(&buf);
-            return NULL;
-        }
-        virBufferAsprintf(&buf, "%s-", username);
-    }
-
-    virBufferAsprintf(&buf, "%d-", id);
-    virDomainMachineNameAppendValid(&buf, name);
-
-    return virBufferContentAndReset(&buf);
-}
-
 
 /**
  * virDomainNetTypeSharesHostView:
index 2038b54c32742f3ba667e308bf385d9e3751c19e..024f692053bd32413cdf95ccd618af9a7484670d 100644 (file)
@@ -3662,13 +3662,6 @@ virDomainGetBlkioParametersAssignFromDef(virDomainDefPtr def,
 int virDomainDiskSetBlockIOTune(virDomainDiskDefPtr disk,
                                 virDomainBlockIoTuneInfo *info);
 
-char *
-virDomainGenerateMachineName(const char *drivername,
-                             const char *root,
-                             int id,
-                             const char *name,
-                             bool privileged);
-
 bool
 virDomainNetTypeSharesHostView(const virDomainNetDef *net);
 
index fc5b6eeefea1d14292fa620043f420e3c2382c89..7bf0fb3f9887831e80d63d492df08f4102531dc6 100644 (file)
 #include "domain_driver.h"
 #include "viralloc.h"
 #include "virstring.h"
+#include "vircrypto.h"
+#include "virutil.h"
 
 #define VIR_FROM_THIS VIR_FROM_DOMAIN
 
 
+#define HOSTNAME_CHARS \
+    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"
+
+static void
+virDomainMachineNameAppendValid(virBufferPtr buf,
+                                const char *name)
+{
+    bool skip = true;
+
+    for (; *name; name++) {
+        if (strlen(virBufferCurrentContent(buf)) >= 64)
+            break;
+
+        if (*name == '.' || *name == '-') {
+            if (!skip)
+                virBufferAddChar(buf, *name);
+            skip = true;
+            continue;
+        }
+
+        skip = false;
+
+        if (!strchr(HOSTNAME_CHARS, *name))
+            continue;
+
+        virBufferAddChar(buf, *name);
+    }
+
+    /* trailing dashes or dots are not allowed */
+    virBufferTrimChars(buf, "-.");
+}
+
+#undef HOSTNAME_CHARS
+
+char *
+virDomainDriverGenerateMachineName(const char *drivername,
+                                   const char *root,
+                                   int id,
+                                   const char *name,
+                                   bool privileged)
+{
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+    virBufferAsprintf(&buf, "%s-", drivername);
+
+    if (root) {
+        g_autofree char *hash = NULL;
+
+        /* When two embed drivers start two domains with the same @name and @id
+         * we would generate a non-unique name. Include parts of hashed @root
+         * which guarantees uniqueness. The first 8 characters of SHA256 ought
+         * to be enough for anybody. */
+        if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, root, &hash) < 0)
+            return NULL;
+
+        virBufferAsprintf(&buf, "embed-%.8s-", hash);
+    } else if (!privileged) {
+        g_autofree char *username = NULL;
+        if (!(username = virGetUserName(geteuid()))) {
+            virBufferFreeAndReset(&buf);
+            return NULL;
+        }
+        virBufferAsprintf(&buf, "%s-", username);
+    }
+
+    virBufferAsprintf(&buf, "%d-", id);
+    virDomainMachineNameAppendValid(&buf, name);
+
+    return virBufferContentAndReset(&buf);
+}
+
+
 /* Modify dest_array to reflect all blkio device changes described in
  * src_array.  */
 int
index b6d5e66bba99b30e59d880b197500ab7c9442e9e..c52e37f0386378cfe6e95c9464a0fe069382081c 100644 (file)
 
 #include "domain_conf.h"
 
+char *
+virDomainDriverGenerateMachineName(const char *drivername,
+                                   const char *root,
+                                   int id,
+                                   const char *name,
+                                   bool privileged);
+
 int virDomainDriverMergeBlkioDevice(virBlkioDevicePtr *dest_array,
                                     size_t *dest_size,
                                     virBlkioDevicePtr src_array,
index e276f55bb1e21ec982aedd686a79d0d30b7b473b..b02b6380ed140ece9292ac1cd7223657f1a3f2fc 100644 (file)
@@ -406,7 +406,6 @@ virDomainFSTypeFromString;
 virDomainFSTypeToString;
 virDomainFSWrpolicyTypeFromString;
 virDomainFSWrpolicyTypeToString;
-virDomainGenerateMachineName;
 virDomainGetBlkioParametersAssignFromDef;
 virDomainGetFilesystemForTarget;
 virDomainGraphicsAuthConnectedTypeFromString;
@@ -1403,6 +1402,7 @@ virDomainCgroupSetupMemtune;
 
 
 # hypervisor/domain_driver.h
+virDomainDriverGenerateMachineName;
 virDomainDriverMergeBlkioDevice;
 virDomainDriverParseBlkioDeviceStr;
 virDomainDriverSetupPersistentDefBlkioParams;
index ebd2c2b56eb6fb431aa018237e4427bd1b9b8bf4..59f803837a6b480185a38d25d5873e2c6bddca31 100644 (file)
@@ -31,6 +31,7 @@
 #include "virtime.h"
 #include "virsystemd.h"
 #include "virinitctl.h"
+#include "domain_driver.h"
 
 #define VIR_FROM_THIS VIR_FROM_LXC
 
@@ -406,7 +407,7 @@ virLXCDomainGetMachineName(virDomainDefPtr def, pid_t pid)
     }
 
     if (!ret)
-        ret = virDomainGenerateMachineName("lxc", NULL, def->id, def->name, true);
+        ret = virDomainDriverGenerateMachineName("lxc", NULL, def->id, def->name, true);
 
     return ret;
 }
index b8f9ee6710a922ef29bd5798daa7d0800017d43b..31a10fd70f5ccdc5e6497f900fbf3511d080431f 100644 (file)
@@ -45,6 +45,7 @@
 #include "virfile.h"
 #include "domain_addr.h"
 #include "domain_capabilities.h"
+#include "domain_driver.h"
 #include "domain_event.h"
 #include "virtime.h"
 #include "virnetdevopenvswitch.h"
@@ -12989,9 +12990,9 @@ qemuDomainGetMachineName(virDomainObjPtr vm)
     }
 
     if (!ret)
-        ret = virDomainGenerateMachineName("qemu", cfg->root,
-                                           vm->def->id, vm->def->name,
-                                           driver->privileged);
+        ret = virDomainDriverGenerateMachineName("qemu", cfg->root,
+                                                 vm->def->id, vm->def->name,
+                                                 driver->privileged);
 
     return ret;
 }
index 050941dce88dca2d17f8997e9af3c85b773fab56..e7dcdea8e934f5e7a830da36aef4c9d00b3fb29d 100644 (file)
@@ -34,6 +34,7 @@
 # include "virlog.h"
 # include "virmock.h"
 # include "rpc/virnetsocket.h"
+# include "domain_driver.h"
 # define VIR_FROM_THIS VIR_FROM_NONE
 
 VIR_LOG_INIT("tests.systemdtest");
@@ -414,8 +415,8 @@ testMachineName(const void *opaque)
     int ret = -1;
     char *actual = NULL;
 
-    if (!(actual = virDomainGenerateMachineName("qemu", data->root,
-                                                data->id, data->name, true)))
+    if (!(actual = virDomainDriverGenerateMachineName("qemu", data->root,
+                                                      data->id, data->name, true)))
         goto cleanup;
 
     if (STRNEQ(actual, data->expected)) {