1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-25 01:34:11 +03:00

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.
This commit is contained in:
Peter Krempa 2015-02-16 15:58:13 +01:00
parent 121cde4726
commit 61e43ce9df
6 changed files with 29 additions and 15 deletions

View File

@ -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) {

View File

@ -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),

View File

@ -204,6 +204,7 @@ virDomainDefMaybeAddController;
virDomainDefMaybeAddInput;
virDomainDefNeedsPlacementAdvice;
virDomainDefNew;
virDomainDefNewFull;
virDomainDefParseFile;
virDomainDefParseNode;
virDomainDefParseString;

View File

@ -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);

View File

@ -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;

View File

@ -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);