[PATCH 13/24] conf: Separate helper for creating domain objects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 870efc9..420b713 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 1e04886..86db2ab 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 278124c..4ba2142 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 31a2a1b..bc498ff 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 c2b9098..ab03c1c 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 dc6f88a..354ab3f 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);
-- 
2.2.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]