]> xenbits.xensource.com Git - libvirt.git/commitdiff
Unify domain name shortening
authorMartin Kletzander <mkletzan@redhat.com>
Tue, 26 Apr 2016 06:43:40 +0000 (08:43 +0200)
committerMartin Kletzander <mkletzan@redhat.com>
Wed, 27 Apr 2016 13:07:10 +0000 (15:07 +0200)
Add virDomainObjGetShortName() and use it.  For now that's used in one
place, but we should expose it so that future patches can use it.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
src/conf/domain_conf.c
src/conf/domain_conf.h
src/libvirt_private.syms
src/qemu/qemu_domain.c

index 2c6244aaf39625a0aa63bee0db10fe9cf6784436..b46cd2a64f75b9e1ff64973367412ece87ca80c1 100644 (file)
@@ -24307,3 +24307,23 @@ virDomainDefHasMemballoon(const virDomainDef *def)
     return def->memballoon &&
            def->memballoon->model != VIR_DOMAIN_MEMBALLOON_MODEL_NONE;
 }
+
+
+/**
+ * virDomainObjGetShortName:
+ * @vm: Machine for which to get a name
+ * @unique: Make sure the name is unique (use id as well)
+ *
+ * Shorten domain name to avoid possible path length limitations.
+ */
+char *
+virDomainObjGetShortName(virDomainObjPtr vm)
+{
+    const int dommaxlen = 20;
+    char *ret = NULL;
+
+    ignore_value(virAsprintf(&ret, "%d-%.*s",
+                             vm->def->id, dommaxlen, vm->def->name));
+
+    return ret;
+}
index fd540ed80eb9319e7ee1dd95ce0bf56a3960035b..ee66e6d6aa4571da594b0159cd134eec4e884423 100644 (file)
@@ -3162,4 +3162,6 @@ int virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def,
 
 bool virDomainDefHasMemballoon(const virDomainDef *def) ATTRIBUTE_NONNULL(1);
 
+char *virDomainObjGetShortName(virDomainObjPtr vm);
+
 #endif /* __DOMAIN_CONF_H */
index ad5c3826095c6bd1c1eb49d7cb650ad3513ad30e..0de35efb258528984e3792114091ef2e09708063 100644 (file)
@@ -400,6 +400,7 @@ virDomainObjGetDefs;
 virDomainObjGetMetadata;
 virDomainObjGetOneDef;
 virDomainObjGetPersistentDef;
+virDomainObjGetShortName;
 virDomainObjGetState;
 virDomainObjNew;
 virDomainObjParseNode;
index b95ba7e781136492e805912b3045a01e4541a345..a2f981043915249e7120993b7ad957f8bac8e4ba 100644 (file)
@@ -787,39 +787,31 @@ qemuDomainSetPrivatePathsOld(virQEMUDriverPtr driver,
 }
 
 
-/*
- * The newer version uses a magic number for one reason.  The thing is
- * that we need a bit shorter name in order to be able to connect to
- * it using UNIX sockets which have path length limitation.  Since the
- * length is not guaranteed to be constant and similarly the lib
- * directory is configurable and so on, we need to rather choose an
- * arbitrary maximum length of the domain name that will be used.
- * Thanks to the fact that we are now saving it in the status XML, we
- * can change it later on whenever we feel like so.
- */
 int
 qemuDomainSetPrivatePaths(virQEMUDriverPtr driver,
                           virDomainObjPtr vm)
 {
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     qemuDomainObjPrivatePtr priv = vm->privateData;
-    const int dommaxlen = 20;
+    char *domname = virDomainObjGetShortName(vm);
     int ret = -1;
 
+    if (!domname)
+        goto cleanup;
+
     if (!priv->libDir &&
-        virAsprintf(&priv->libDir, "%s/domain-%d-%.*s",
-                    cfg->libDir, vm->def->id, dommaxlen, vm->def->name) < 0)
+        virAsprintf(&priv->libDir, "%s/domain-%s", cfg->libDir, domname) < 0)
         goto cleanup;
 
     if (!priv->channelTargetDir &&
-        virAsprintf(&priv->channelTargetDir, "%s/domain-%d-%.*s",
-                    cfg->channelTargetDir, vm->def->id,
-                    dommaxlen, vm->def->name) < 0)
+        virAsprintf(&priv->channelTargetDir, "%s/domain-%s",
+                    cfg->channelTargetDir, domname) < 0)
         goto cleanup;
 
     ret = 0;
  cleanup:
     virObjectUnref(cfg);
+    VIR_FREE(domname);
     return ret;
 }