Hi, this is the commit to introduce the function to create new character device definition for the domain as advices by Cole Robinson <crobinso@xxxxxxxxxx>. The function is used on the relevant places and the make, make check and make syntax-check all passed. Michal Signed-off-by: Michal Novotny <minovotn@xxxxxxxxxx> Signed-off-by: Michal Novotny <mignov@xxxxxxxxx> --- src/conf/domain_conf.c | 20 +++++++++++++++++--- src/conf/domain_conf.h | 2 ++ src/libvirt_private.syms | 1 + src/qemu/qemu_command.c | 3 ++- src/xenxs/xen_xm.c | 3 ++- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 90a1317..a80719c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3212,6 +3212,22 @@ error: goto cleanup; } +/* Create a new character device definition and set + * default port. + */ +virDomainChrDefPtr +virDomainChrDefNew(void) { + virDomainChrDefPtr def = NULL; + + if (VIR_ALLOC(def) < 0) { + virReportOOMError(); + return NULL; + } + + def->target.port = -1; + return def; +} + /* Parse the XML definition for a character device * @param node XML nodeset to parse for net definition * @@ -3260,10 +3276,8 @@ virDomainChrDefParseXML(virCapsPtr caps, virDomainChrDefPtr def; int remaining; - if (VIR_ALLOC(def) < 0) { - virReportOOMError(); + if (!(def = virDomainChrDefNew())) return NULL; - } type = virXMLPropString(node, "type"); if (type == NULL) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 95bd11e..ecf44ca 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1229,6 +1229,8 @@ void virDomainObjRef(virDomainObjPtr vm); /* Returns 1 if the object was freed, 0 if more refs exist */ int virDomainObjUnref(virDomainObjPtr vm) ATTRIBUTE_RETURN_CHECK; +virDomainChrDefPtr virDomainChrDefNew(void); + /* live == true means def describes an active domain (being migrated or * restored) as opposed to a new persistent configuration of the domain */ virDomainObjPtr virDomainAssignDef(virCapsPtr caps, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 54e4482..c13e416 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -333,6 +333,7 @@ virDomainWatchdogActionTypeFromString; virDomainWatchdogActionTypeToString; virDomainWatchdogModelTypeFromString; virDomainWatchdogModelTypeToString; +virDomainChrDefNew; # domain_event.h diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index fea0068..d258712 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -36,6 +36,7 @@ #include "c-ctype.h" #include "domain_nwfilter.h" #include "qemu_audit.h" +#include "domain_conf.h" #include <sys/utsname.h> #include <sys/stat.h> @@ -5315,7 +5316,7 @@ qemuParseCommandLineChr(const char *val) { virDomainChrDefPtr def; - if (VIR_ALLOC(def) < 0) + if (!(def = virDomainChrDefNew())) goto no_memory; if (STREQ(val, "null")) { diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 22ad788..0b47f1f 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -36,6 +36,7 @@ #include "xenxs_private.h" #include "xen_xm.h" #include "xen_sxpr.h" +#include "domain_conf.h" /* Convenience method to grab a int from the config file object */ static int xenXMConfigGetBool(virConfPtr conf, @@ -981,7 +982,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, continue; } - if (VIR_ALLOC(chr) < 0) + if (!(chr = virDomainChrDefNew())) goto no_memory; if (!(chr = xenParseSxprChar(port, NULL))) goto cleanup; -- 1.7.3.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list