After the previous commit, wherever we had:
start_element ("foo") {
string ("bar");
} end_element ();
this can now be replaced by:
single_element ("foo", "bar");
---
lib/launch-libvirt.c | 81 ++++++++++++--------------------------------
p2v/physical-xml.c | 15 +++-----
2 files changed, 25 insertions(+), 71 deletions(-)
diff --git a/lib/launch-libvirt.c b/lib/launch-libvirt.c
index 7b4b9f752..f6ef6bcad 100644
--- a/lib/launch-libvirt.c
+++ b/lib/launch-libvirt.c
@@ -1006,10 +1006,7 @@ construct_libvirt_xml_name (guestfs_h *g,
const struct libvirt_xml_params *params,
xmlTextWriterPtr xo)
{
- start_element ("name") {
- string ("%s", params->data->name);
- } end_element ();
-
+ single_element ("name", "%s", params->data->name);
return 0;
}
@@ -1040,17 +1037,12 @@ construct_libvirt_xml_cpu (guestfs_h *g,
attribute ("fallback", "allow");
} end_element ();
}
- else {
- start_element ("model") {
- string ("%s", cpu_model);
- } end_element ();
- }
+ else
+ single_element ("model", "%s", cpu_model);
} end_element ();
}
- start_element ("vcpu") {
- string ("%d", g->smp);
- } end_element ();
+ single_element ("vcpu", "%d", g->smp);
start_element ("clock") {
attribute ("offset", "utc");
@@ -1111,11 +1103,8 @@ construct_libvirt_xml_boot (guestfs_h *g,
string ("%s", params->data->uefi_code);
} end_element ();
- if (params->data->uefi_vars) {
- start_element ("nvram") {
- string ("%s", params->data->uefi_vars);
- } end_element ();
- }
+ if (params->data->uefi_vars)
+ single_element ("nvram", "%s", params->data->uefi_vars);
}
#ifdef __powerpc64__
@@ -1128,17 +1117,9 @@ construct_libvirt_xml_boot (guestfs_h *g,
}
#endif
- start_element ("kernel") {
- string ("%s", params->kernel);
- } end_element ();
-
- start_element ("initrd") {
- string ("%s", params->initrd);
- } end_element ();
-
- start_element ("cmdline") {
- string ("%s", cmdline);
- } end_element ();
+ single_element ("kernel", "%s", params->kernel);
+ single_element ("initrd", "%s", params->initrd);
+ single_element ("cmdline", "%s", cmdline);
#if defined(__i386__) || defined(__x86_64__)
if (g->verbose) {
@@ -1167,9 +1148,7 @@ construct_libvirt_xml_seclabel (guestfs_h *g,
attribute ("type", "static");
attribute ("model", "dac");
attribute ("relabel", "no");
- start_element ("label") {
- string ("0:0");
- } end_element ();
+ single_element ("label", "0:0");
} end_element ();
}
@@ -1188,12 +1167,8 @@ construct_libvirt_xml_seclabel (guestfs_h *g,
attribute ("type", "static");
attribute ("model", "selinux");
attribute ("relabel", "yes");
- start_element ("label") {
- string ("%s", params->data->selinux_label);
- } end_element ();
- start_element ("imagelabel") {
- string ("%s", params->data->selinux_imagelabel);
- } end_element ();
+ single_element ("label", "%s",
params->data->selinux_label);
+ single_element ("imagelabel", "%s",
params->data->selinux_imagelabel);
} end_element ();
}
@@ -1206,10 +1181,7 @@ construct_libvirt_xml_lifecycle (guestfs_h *g,
const struct libvirt_xml_params *params,
xmlTextWriterPtr xo)
{
- start_element ("on_reboot") {
- string ("destroy");
- } end_element ();
-
+ single_element ("on_reboot", "destroy");
return 0;
}
@@ -1227,20 +1199,14 @@ construct_libvirt_xml_devices (guestfs_h *g,
/* Path to hypervisor. Only write this if the user has changed the
* default, otherwise allow libvirt to choose the best one.
*/
- if (is_custom_hv (g)) {
- start_element ("emulator") {
- string ("%s", g->hv);
- } end_element ();
- }
+ if (is_custom_hv (g))
+ single_element ("emulator", "%s", g->hv);
#if defined(__arm__)
/* Hopefully temporary hack to make ARM work (otherwise libvirt
* chooses to run /usr/bin/qemu-kvm).
*/
- else {
- start_element ("emulator") {
- string ("%s", QEMU);
- } end_element ();
- }
+ else
+ single_element ("emulator", "%s", QEMU);
#endif
/* Add a random number generator (backend for virtio-rng). This
@@ -1511,11 +1477,8 @@ construct_libvirt_xml_disk (guestfs_h *g,
return -1;
}
- if (drv->disk_label) {
- start_element ("serial") {
- string ("%s", drv->disk_label);
- } end_element ();
- }
+ if (drv->disk_label)
+ single_element ("serial", "%s", drv->disk_label);
if (construct_libvirt_xml_disk_address (g, xo, drv_index) == -1)
return -1;
@@ -1764,10 +1727,8 @@ construct_libvirt_xml_secret (guestfs_h *g,
start_element ("secret") {
attribute ("ephemeral", "yes");
attribute ("private", "yes");
- start_element ("description") {
- string ("guestfs secret associated with %s %s",
- data->name, drv->src.u.path);
- } end_element ();
+ single_element ("description", "guestfs secret associated with %s
%s",
+ data->name, drv->src.u.path);
} end_element ();
return 0;
diff --git a/p2v/physical-xml.c b/p2v/physical-xml.c
index 6ac8cc991..ffcb9e24e 100644
--- a/p2v/physical-xml.c
+++ b/p2v/physical-xml.c
@@ -97,9 +97,7 @@ generate_physical_xml (struct config *config, struct data_conn
*data_conns,
start_element ("domain") {
attribute ("type", "physical");
- start_element ("name") {
- string ("%s", config->guestname);
- } end_element ();
+ single_element ("name", "%s", config->guestname);
start_element ("memory") {
attribute ("unit", "KiB");
@@ -111,20 +109,15 @@ generate_physical_xml (struct config *config, struct data_conn
*data_conns,
string ("%" PRIu64, memkb);
} end_element ();
- start_element ("vcpu") {
- string ("%d", config->vcpus);
- } end_element ();
+ single_element ("vcpu", "%d", config->vcpus);
if (config->cpu.vendor || config->cpu.model ||
config->cpu.sockets || config->cpu.cores || config->cpu.threads) {
/*
https://libvirt.org/formatdomain.html#elementsCPU */
start_element ("cpu") {
attribute ("match", "minimum");
- if (config->cpu.vendor) {
- start_element ("vendor") {
- string ("%s", config->cpu.vendor);
- } end_element ();
- }
+ if (config->cpu.vendor)
+ single_element ("vendor", "%s", config->cpu.vendor);
if (config->cpu.model) {
start_element ("model") {
attribute ("fallback", "allow");
--
2.19.0.rc0