For now we just allocate the object, so the only advantage is
that invocations are shorter and look a bit nicer.
Later on, its introduction will pay off by letting us change
things in a single spot instead of all over the library.
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
src/bhyve/bhyve_firmware.c | 2 +-
src/conf/domain_conf.c | 8 +++++++-
src/conf/domain_conf.h | 1 +
src/libvirt_private.syms | 1 +
src/libxl/libxl_conf.c | 2 +-
src/libxl/xen_xl.c | 4 ++--
src/libxl/xen_xm.c | 2 +-
src/qemu/qemu_firmware.c | 4 ++--
8 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/src/bhyve/bhyve_firmware.c b/src/bhyve/bhyve_firmware.c
index b0f3026c76..cb1b94b4d5 100644
--- a/src/bhyve/bhyve_firmware.c
+++ b/src/bhyve/bhyve_firmware.c
@@ -78,7 +78,7 @@ bhyveFirmwareFillDomain(bhyveConn *driver,
}
if (!def->os.loader)
- def->os.loader = g_new0(virDomainLoaderDef, 1);
+ def->os.loader = virDomainLoaderDefNew();
def->os.loader->type = VIR_DOMAIN_LOADER_TYPE_PFLASH;
def->os.loader->readonly = VIR_TRISTATE_BOOL_YES;
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 74c7889e01..8117cff83e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3714,6 +3714,12 @@ virDomainPanicDefFree(virDomainPanicDef *panic)
g_free(panic);
}
+virDomainLoaderDef *
+virDomainLoaderDefNew(void)
+{
+ return g_new0(virDomainLoaderDef, 1);
+}
+
void
virDomainLoaderDefFree(virDomainLoaderDef *loader)
{
@@ -17236,7 +17242,7 @@ virDomainDefParseBootLoaderOptions(virDomainDef *def,
if (!loaderNode && !nvramNode)
return 0;
- def->os.loader = g_new0(virDomainLoaderDef, 1);
+ def->os.loader = virDomainLoaderDefNew();
if (virDomainLoaderDefParseXML(def->os.loader,
loaderNode, nvramNode, nvramSourceNode,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 62f80d653d..96121220ea 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2317,6 +2317,7 @@ struct _virDomainLoaderDef {
char *nvramTemplate; /* user override of path to master nvram */
};
+virDomainLoaderDef *virDomainLoaderDefNew(void);
void virDomainLoaderDefFree(virDomainLoaderDef *loader);
typedef enum {
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 97c3d86217..e550e7139d 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -507,6 +507,7 @@ virDomainLeaseRemoveAt;
virDomainLifecycleActionTypeFromString;
virDomainLifecycleActionTypeToString;
virDomainLoaderDefFree;
+virDomainLoaderDefNew;
virDomainLoaderTypeFromString;
virDomainLoaderTypeToString;
virDomainLockFailureTypeFromString;
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index cee9f827f7..97c183ebf3 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -643,7 +643,7 @@ libxlMakeDomBuildInfo(virDomainDef *def,
*/
if (def->os.firmware == VIR_DOMAIN_OS_DEF_FIRMWARE_EFI) {
if (def->os.loader == NULL)
- def->os.loader = g_new0(virDomainLoaderDef, 1);
+ def->os.loader = virDomainLoaderDefNew();
if (def->os.loader->path == NULL)
def->os.loader->path = g_strdup(cfg->firmwares[0]->name);
if (def->os.loader->type == VIR_DOMAIN_LOADER_TYPE_NONE)
diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c
index 6919325623..cfd56b3b05 100644
--- a/src/libxl/xen_xl.c
+++ b/src/libxl/xen_xl.c
@@ -111,7 +111,7 @@ xenParseXLOS(virConf *conf, virDomainDef *def, virCaps *caps)
return -1;
if (bios && STREQ(bios, "ovmf")) {
- def->os.loader = g_new0(virDomainLoaderDef, 1);
+ def->os.loader = virDomainLoaderDefNew();
def->os.loader->type = VIR_DOMAIN_LOADER_TYPE_PFLASH;
def->os.loader->readonly = VIR_TRISTATE_BOOL_YES;
@@ -120,7 +120,7 @@ xenParseXLOS(virConf *conf, virDomainDef *def, virCaps *caps)
for (i = 0; i < caps->nguests; i++) {
if (caps->guests[i]->ostype == VIR_DOMAIN_OSTYPE_HVM &&
caps->guests[i]->arch.id == def->os.arch) {
- def->os.loader = g_new0(virDomainLoaderDef, 1);
+ def->os.loader = virDomainLoaderDefNew();
def->os.loader->path =
g_strdup(caps->guests[i]->arch.defaultInfo.loader);
}
}
diff --git a/src/libxl/xen_xm.c b/src/libxl/xen_xm.c
index 081d323c2a..334de071ba 100644
--- a/src/libxl/xen_xm.c
+++ b/src/libxl/xen_xm.c
@@ -42,7 +42,7 @@ xenParseXMOS(virConf *conf, virDomainDef *def)
if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
g_autofree char *boot = NULL;
- def->os.loader = g_new0(virDomainLoaderDef, 1);
+ def->os.loader = virDomainLoaderDefNew();
if (xenConfigCopyString(conf, "kernel",
&def->os.loader->path) < 0)
return -1;
diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c
index eb7abb0b32..98b42bc6fb 100644
--- a/src/qemu/qemu_firmware.c
+++ b/src/qemu/qemu_firmware.c
@@ -1168,7 +1168,7 @@ qemuFirmwareEnableFeatures(virQEMUDriver *driver,
switch (fw->mapping.device) {
case QEMU_FIRMWARE_DEVICE_FLASH:
if (!def->os.loader)
- def->os.loader = g_new0(virDomainLoaderDef, 1);
+ def->os.loader = virDomainLoaderDefNew();
def->os.loader->type = VIR_DOMAIN_LOADER_TYPE_PFLASH;
def->os.loader->readonly = VIR_TRISTATE_BOOL_YES;
@@ -1218,7 +1218,7 @@ qemuFirmwareEnableFeatures(virQEMUDriver *driver,
case QEMU_FIRMWARE_DEVICE_MEMORY:
if (!def->os.loader)
- def->os.loader = g_new0(virDomainLoaderDef, 1);
+ def->os.loader = virDomainLoaderDefNew();
def->os.loader->type = VIR_DOMAIN_LOADER_TYPE_ROM;
def->os.loader->path = g_strdup(memory->filename);
--
2.39.1