From 61e43ce9df0ec5a9d7b09ebb46caa85576923311 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 16 Feb 2015 15:58:13 +0100 Subject: [PATCH] conf: Separate helper for creating domain objects Move the existing virDomainDefNew to virDomainDefNewFull as it's setting a few things in the conf and re-introduce virDomainDefNew as a function without parameters for common use. --- src/conf/domain_conf.c | 20 ++++++++++++++++---- src/conf/domain_conf.h | 7 ++++--- src/libvirt_private.syms | 1 + src/xen/xen_hypervisor.c | 8 ++++---- src/xen/xend_internal.c | 4 ++-- src/xen/xm_internal.c | 4 ++-- 6 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e399a3301a..dc8cd3a983 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2314,13 +2314,25 @@ virDomainObjNew(virDomainXMLOptionPtr xmlopt) } -virDomainDefPtr virDomainDefNew(const char *name, - const unsigned char *uuid, - int id) +virDomainDefPtr +virDomainDefNew(void) +{ + virDomainDefPtr ret; + + ignore_value(VIR_ALLOC(ret)); + + return ret; +} + + +virDomainDefPtr +virDomainDefNewFull(const char *name, + const unsigned char *uuid, + int id) { virDomainDefPtr def; - if (VIR_ALLOC(def) < 0) + if (!(def = virDomainDefNew())) return NULL; if (VIR_STRDUP(def->name, name) < 0) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 1e04886935..86db2ab9df 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2414,9 +2414,10 @@ void virDomainDefFree(virDomainDefPtr vm); virDomainChrDefPtr virDomainChrDefNew(void); -virDomainDefPtr virDomainDefNew(const char *name, - const unsigned char *uuid, - int id); +virDomainDefPtr virDomainDefNew(void); +virDomainDefPtr virDomainDefNewFull(const char *name, + const unsigned char *uuid, + int id); enum { VIR_DOMAIN_OBJ_LIST_ADD_LIVE = (1 << 0), diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a7465ce610..b145c8b921 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -204,6 +204,7 @@ virDomainDefMaybeAddController; virDomainDefMaybeAddInput; virDomainDefNeedsPlacementAdvice; virDomainDefNew; +virDomainDefNewFull; virDomainDefParseFile; virDomainDefParseNode; virDomainDefParseString; diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c index 31a2a1b6ad..bc498ff91f 100644 --- a/src/xen/xen_hypervisor.c +++ b/src/xen/xen_hypervisor.c @@ -2634,9 +2634,9 @@ xenHypervisorLookupDomainByID(virConnectPtr conn, int id) if (!name) return NULL; - ret = virDomainDefNew(name, - XEN_GETDOMAININFO_UUID(dominfo), - id); + ret = virDomainDefNewFull(name, + XEN_GETDOMAININFO_UUID(dominfo), + id); VIR_FREE(name); return ret; } @@ -2699,7 +2699,7 @@ xenHypervisorLookupDomainByUUID(virConnectPtr conn, const unsigned char *uuid) if (!name) return NULL; - ret = virDomainDefNew(name, uuid, id); + ret = virDomainDefNewFull(name, uuid, id); if (ret) ret->id = id; VIR_FREE(name); diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index c2b90981e9..ab03c1c158 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -1152,7 +1152,7 @@ sexpr_to_domain(virConnectPtr conn, const struct sexpr *root) if (tmp) id = sexpr_int(root, "domain/domid"); - return virDomainDefNew(name, uuid, id); + return virDomainDefNewFull(name, uuid, id); error: virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2117,7 +2117,7 @@ xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char *uuid) if (name == NULL) return NULL; - ret = virDomainDefNew(name, uuid, id); + ret = virDomainDefNewFull(name, uuid, id); VIR_FREE(name); return ret; diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c index dc6f88a94d..354ab3f9de 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -844,7 +844,7 @@ xenXMDomainLookupByName(virConnectPtr conn, const char *domname) if (!(entry = virHashLookup(priv->configCache, filename))) goto cleanup; - ret = virDomainDefNew(domname, entry->def->uuid, -1); + ret = virDomainDefNewFull(domname, entry->def->uuid, -1); cleanup: xenUnifiedUnlock(priv); @@ -887,7 +887,7 @@ xenXMDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) if (!(entry = virHashSearch(priv->configCache, xenXMDomainSearchForUUID, (const void *)uuid))) goto cleanup; - ret = virDomainDefNew(entry->def->name, uuid, -1); + ret = virDomainDefNewFull(entry->def->name, uuid, -1); cleanup: xenUnifiedUnlock(priv);