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(a)redhat.com>
---
src/conf/domain_conf.c | 20 ++++++++++++++++++++
src/conf/domain_conf.h | 2 ++
src/libvirt_private.syms | 1 +
src/qemu/qemu_domain.c | 24 ++++++++----------------
4 files changed, 31 insertions(+), 16 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 055791253c50..d39f666df17f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -24318,3 +24318,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;
+}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index fd540ed80eb9..ee66e6d6aa45 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3162,4 +3162,6 @@ int virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def,
bool virDomainDefHasMemballoon(const virDomainDef *def) ATTRIBUTE_NONNULL(1);
+char *virDomainObjGetShortName(virDomainObjPtr vm);
+
#endif /* __DOMAIN_CONF_H */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index ad5c3826095c..0de35efb2585 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -400,6 +400,7 @@ virDomainObjGetDefs;
virDomainObjGetMetadata;
virDomainObjGetOneDef;
virDomainObjGetPersistentDef;
+virDomainObjGetShortName;
virDomainObjGetState;
virDomainObjNew;
virDomainObjParseNode;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 51d4830a77bb..3b152893a23a 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -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;
}
--
2.8.1