[PATCH 14/32] network: use g_auto() for all virBuffers

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 src/network/bridge_driver.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 0f5212ce04..9f37d8f558 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -332,7 +332,7 @@ networkRunHook(virNetworkObjPtr obj,
int sub_op)
 {
 virNetworkDefPtr def;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 char *xml = NULL;
 int hookret;
 int ret = -1;
@@ -370,7 +370,6 @@ networkRunHook(virNetworkObjPtr obj,
 
 ret = 0;
  cleanup:
-virBufferFreeAndReset();
 VIR_FREE(xml);
 return ret;
 }
@@ -1093,7 +1092,7 @@ networkDnsmasqConfContents(virNetworkObjPtr obj,
dnsmasqCapsPtr caps G_GNUC_UNUSED)
 {
 virNetworkDefPtr def = virNetworkObjGetDef(obj);
-virBuffer configbuf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) configbuf = VIR_BUFFER_INITIALIZER;
 int r, ret = -1;
 int nbleases = 0;
 size_t i;
@@ -1577,7 +1576,6 @@ networkDnsmasqConfContents(virNetworkObjPtr obj,
  cleanup:
 VIR_FREE(saddr);
 VIR_FREE(eaddr);
-virBufferFreeAndReset();
 return ret;
 }
 
@@ -1843,7 +1841,7 @@ networkRadvdConfContents(virNetworkObjPtr obj,
  char **configstr)
 {
 virNetworkDefPtr def = virNetworkObjGetDef(obj);
-virBuffer configbuf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) configbuf = VIR_BUFFER_INITIALIZER;
 int ret = -1;
 size_t i;
 virNetworkIPDefPtr ipdef;
@@ -1907,7 +1905,6 @@ networkRadvdConfContents(virNetworkObjPtr obj,
 
 ret = 0;
  cleanup:
-virBufferFreeAndReset();
 return ret;
 }
 
-- 
2.25.4



[PATCH 21/32] conf: eliminate unnecessary labels

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 src/conf/capabilities.c|  5 +--
 src/conf/checkpoint_conf.c |  8 ++--
 src/conf/cpu_conf.c| 18 +++-
 src/conf/domain_conf.c | 88 +++---
 src/conf/network_conf.c|  5 +--
 src/conf/nwfilter_conf.c   |  5 +--
 src/conf/secret_conf.c |  5 +--
 src/conf/snapshot_conf.c   | 11 ++---
 src/conf/storage_conf.c| 17 ++--
 src/conf/virnetworkobj.c   |  7 +--
 src/conf/virsavecookie.c   |  5 +--
 11 files changed, 67 insertions(+), 107 deletions(-)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 6a48af1fca..610e6e8242 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -1340,7 +1340,7 @@ virCapabilitiesFormatXML(virCapsPtr caps)
 virBufferAdjustIndent(, 2);
 
 if (virCapabilitiesFormatHostXML(>host, ) < 0)
-goto error;
+return NULL;
 
 virCapabilitiesFormatGuestXML(caps->guests, caps->nguests, );
 
@@ -1350,9 +1350,6 @@ virCapabilitiesFormatXML(virCapsPtr caps)
 virBufferAddLit(, "\n");
 
 return virBufferContentAndReset();
-
- error:
-return NULL;
 }
 
 /* get the maximum ID of cpus in the host */
diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c
index 41f67bd895..861004801e 100644
--- a/src/conf/checkpoint_conf.c
+++ b/src/conf/checkpoint_conf.c
@@ -476,7 +476,7 @@ virDomainCheckpointDefFormatInternal(virBufferPtr buf,
 for (i = 0; i < def->ndisks; i++) {
 if (virDomainCheckpointDiskDefFormat(buf, >disks[i],
  flags) < 0)
-goto error;
+return -1;
 }
 virBufferAdjustIndent(buf, -2);
 virBufferAddLit(buf, "\n");
@@ -485,17 +485,15 @@ virDomainCheckpointDefFormatInternal(virBufferPtr buf,
 if (!(flags & VIR_DOMAIN_CHECKPOINT_FORMAT_NO_DOMAIN) &&
 virDomainDefFormatInternal(def->parent.dom, xmlopt,
buf, domainflags) < 0)
-goto error;
+return -1;
 
 virBufferAdjustIndent(buf, -2);
 virBufferAddLit(buf, "\n");
 
 return 0;
-
- error:
-return -1;
 }
 
+
 char *
 virDomainCheckpointDefFormat(virDomainCheckpointDefPtr def,
  virDomainXMLOptionPtr xmlopt,
diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index dd3db00bc8..7be108fa63 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -671,12 +671,9 @@ virCPUDefFormat(virCPUDefPtr def,
 g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
 if (virCPUDefFormatBufFull(, def, numa) < 0)
-goto cleanup;
+return NULL;
 
 return virBufferContentAndReset();
-
- cleanup:
-return NULL;
 }
 
 
@@ -685,7 +682,6 @@ virCPUDefFormatBufFull(virBufferPtr buf,
virCPUDefPtr def,
virDomainNumaPtr numa)
 {
-int ret = -1;
 g_auto(virBuffer) attributeBuf = VIR_BUFFER_INITIALIZER;
 g_auto(virBuffer) childrenBuf = VIR_BUFFER_INIT_CHILD(buf);
 
@@ -701,7 +697,7 @@ virCPUDefFormatBufFull(virBufferPtr buf,
 if (!(tmp = virCPUModeTypeToString(def->mode))) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unexpected CPU mode %d"), def->mode);
-goto cleanup;
+return -1;
 }
 virBufferAsprintf(, " mode='%s'", tmp);
 
@@ -710,7 +706,7 @@ virCPUDefFormatBufFull(virBufferPtr buf,
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unexpected CPU match policy %d"),
def->match);
-goto cleanup;
+return -1;
 }
 virBufferAsprintf(, " match='%s'", tmp);
 }
@@ -731,10 +727,10 @@ virCPUDefFormatBufFull(virBufferPtr buf,
 virBufferAsprintf(, "%s\n",
   virArchToString(def->arch));
 if (virCPUDefFormatBuf(, def) < 0)
-goto cleanup;
+return -1;
 
 if (virDomainNumaDefCPUFormatXML(, numa) < 0)
-goto cleanup;
+return -1;
 
 /* Put it all together */
 if (virBufferUse() || virBufferUse()) {
@@ -752,9 +748,7 @@ virCPUDefFormatBufFull(virBufferPtr buf,
 }
 }
 
-ret = 0;
- cleanup:
-return ret;
+return 0;
 }
 
 int
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e5070ed871..706d050f4d 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -29543,7 +29543,7 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr 
def,
 if (!(type = virDomainVirtTypeToString(def->virtType))) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected domain type %d"), def->virtType);
-goto error;
+return -1;
 }
 
 if (def->id == -1)
@@ -29588,13 +29588,13 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr 
def,
 xmlIndentTreeOutput = 1;
 if (!(xmlbuf = xmlBufferCreate())) {
 

[PATCH 31/32] use g_autoptr() for all usages of virFirewallNew/Free

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 src/network/bridge_driver_linux.c | 11 ++---
 src/nwfilter/nwfilter_ebiptables_driver.c | 31 --
 src/util/virebtables.c|  8 +---
 src/util/viriptables.c|  6 +--
 tests/virfirewalltest.c   | 50 +--
 5 files changed, 25 insertions(+), 81 deletions(-)

diff --git a/src/network/bridge_driver_linux.c 
b/src/network/bridge_driver_linux.c
index 30f6aa8fe1..f72f94f38d 100644
--- a/src/network/bridge_driver_linux.c
+++ b/src/network/bridge_driver_linux.c
@@ -838,7 +838,7 @@ int networkAddFirewallRules(virNetworkDefPtr def)
 {
 size_t i;
 virNetworkIPDefPtr ipdef;
-virFirewallPtr fw = NULL;
+g_autoptr(virFirewall) fw = virFirewallNew();
 int ret = -1;
 
 if (virOnce(, networkSetupPrivateChains) < 0)
@@ -925,8 +925,6 @@ int networkAddFirewallRules(virNetworkDefPtr def)
 }
 }
 
-fw = virFirewallNew();
-
 virFirewallStartTransaction(fw, 0);
 
 networkAddGeneralFirewallRules(fw, def);
@@ -956,7 +954,6 @@ int networkAddFirewallRules(virNetworkDefPtr def)
 
 ret = 0;
  cleanup:
-virFirewallFree(fw);
 return ret;
 }
 
@@ -965,9 +962,7 @@ void networkRemoveFirewallRules(virNetworkDefPtr def)
 {
 size_t i;
 virNetworkIPDefPtr ipdef;
-virFirewallPtr fw = NULL;
-
-fw = virFirewallNew();
+g_autoptr(virFirewall) fw = virFirewallNew();
 
 virFirewallStartTransaction(fw, VIR_FIREWALL_TRANSACTION_IGNORE_ERRORS);
 networkRemoveChecksumFirewallRules(fw, def);
@@ -985,5 +980,5 @@ void networkRemoveFirewallRules(virNetworkDefPtr def)
 virFirewallApply(fw);
 
  cleanup:
-virFirewallFree(fw);
+return;
 }
diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c 
b/src/nwfilter/nwfilter_ebiptables_driver.c
index 6cdb3ca45e..2976521e6d 100644
--- a/src/nwfilter/nwfilter_ebiptables_driver.c
+++ b/src/nwfilter/nwfilter_ebiptables_driver.c
@@ -2858,7 +2858,7 @@ static int
 ebtablesApplyBasicRules(const char *ifname,
 const virMacAddr *macaddr)
 {
-virFirewallPtr fw = virFirewallNew();
+g_autoptr(virFirewall) fw = virFirewallNew();
 char chain[MAX_CHAINNAME_LENGTH];
 char chainPrefix = CHAINPREFIX_HOST_IN_TEMP;
 char macaddr_str[VIR_MAC_STRING_BUFLEN];
@@ -2895,13 +2895,11 @@ ebtablesApplyBasicRules(const char *ifname,
 if (virFirewallApply(fw) < 0)
 goto tear_down_tmpebchains;
 
-virFirewallFree(fw);
 return 0;
 
  tear_down_tmpebchains:
 ebtablesCleanAll(ifname);
  error:
-virFirewallFree(fw);
 return -1;
 }
 
@@ -2934,7 +2932,7 @@ ebtablesApplyDHCPOnlyRules(const char *ifname,
 char macaddr_str[VIR_MAC_STRING_BUFLEN];
 unsigned int idx = 0;
 unsigned int num_dhcpsrvrs;
-virFirewallPtr fw = virFirewallNew();
+g_autoptr(virFirewall) fw = virFirewallNew();
 
 virMacAddrFormat(macaddr, macaddr_str);
 
@@ -3014,14 +3012,11 @@ ebtablesApplyDHCPOnlyRules(const char *ifname,
 if (virFirewallApply(fw) < 0)
 goto tear_down_tmpebchains;
 
-virFirewallFree(fw);
-
 return 0;
 
  tear_down_tmpebchains:
 ebtablesCleanAll(ifname);
  error:
-virFirewallFree(fw);
 return -1;
 }
 
@@ -3040,7 +3035,7 @@ ebtablesApplyDropAllRules(const char *ifname)
 {
 char chain_in [MAX_CHAINNAME_LENGTH],
  chain_out[MAX_CHAINNAME_LENGTH];
-virFirewallPtr fw = virFirewallNew();
+g_autoptr(virFirewall) fw = virFirewallNew();
 
 if (ebiptablesAllTeardown(ifname) < 0)
 goto error;
@@ -3069,13 +3064,11 @@ ebtablesApplyDropAllRules(const char *ifname)
 if (virFirewallApply(fw) < 0)
 goto tear_down_tmpebchains;
 
-virFirewallFree(fw);
 return 0;
 
  tear_down_tmpebchains:
 ebtablesCleanAll(ifname);
  error:
-virFirewallFree(fw);
 return -1;
 }
 
@@ -3090,7 +3083,7 @@ ebtablesRemoveBasicRules(const char *ifname)
 static int
 ebtablesCleanAll(const char *ifname)
 {
-virFirewallPtr fw = virFirewallNew();
+g_autoptr(virFirewall) fw = virFirewallNew();
 int ret = -1;
 
 virFirewallStartTransaction(fw, VIR_FIREWALL_TRANSACTION_IGNORE_ERRORS);
@@ -3108,7 +3101,6 @@ ebtablesCleanAll(const char *ifname)
 ebtablesRemoveTmpRootChainFW(fw, false, ifname);
 
 ret = virFirewallApply(fw);
-virFirewallFree(fw);
 return ret;
 }
 
@@ -3357,7 +3349,7 @@ ebiptablesApplyNewRules(const char *ifname,
 size_t nrules)
 {
 size_t i, j;
-virFirewallPtr fw = virFirewallNew();
+g_autoptr(virFirewall) fw = virFirewallNew();
 virHashTablePtr chains_in_set  = virHashCreate(10, NULL);
 virHashTablePtr chains_out_set = virHashCreate(10, NULL);
 bool haveEbtables = false;
@@ -3558,7 +3550,6 @@ ebiptablesApplyNewRules(const char *ifname,
 for (i = 0; i < nsubchains; i++)
 VIR_FREE(subchains[i]);
 VIR_FREE(subchains);
-virFirewallFree(fw);
 virHashFree(chains_in_set);
 virHashFree(chains_out_set);

[PATCH 28/32] esx: eliminate unnecessary labels

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 src/esx/esx_vi.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index d48a24e9d3..71aa3876b3 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -369,7 +369,7 @@ int
 esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char **content,
 unsigned long long offset, unsigned long long *length)
 {
-char *range = NULL;
+g_autofree char *range = NULL;
 g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
 int responseCode = 0;
 
@@ -405,12 +405,12 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url, 
char **content,
 virMutexUnlock(>lock);
 
 if (responseCode < 0) {
-goto cleanup;
+return -1;
 } else if (responseCode != 200 && responseCode != 206) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("HTTP response code %d for download from '%s'"),
responseCode, url);
-goto cleanup;
+return -1;
 }
 
 if (length)
@@ -418,9 +418,6 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char 
**content,
 
 *content = virBufferContentAndReset();
 
- cleanup:
-VIR_FREE(range);
-
 if (!(*content))
 return -1;
 
-- 
2.25.4



[PATCH 12/32] rpc: use g_auto() for all virBuffers

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 src/rpc/virnetclient.c| 4 ++--
 src/rpc/virnetlibsshsession.c | 7 ++-
 src/rpc/virnetsocket.c| 2 +-
 src/rpc/virnetsshsession.c| 2 +-
 4 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 1c5bef86a1..441f1502a6 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -428,7 +428,7 @@ virNetClientPtr virNetClientNewLibSSH2(const char *host,
 {
 virNetSocketPtr sock = NULL;
 
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 g_autofree char *nc = NULL;
 g_autofree char *command = NULL;
 
@@ -518,7 +518,7 @@ virNetClientPtr virNetClientNewLibssh(const char *host,
 {
 virNetSocketPtr sock = NULL;
 
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 g_autofree char *nc = NULL;
 g_autofree char *command = NULL;
 
diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c
index 0a566eaa54..c9b31e9462 100644
--- a/src/rpc/virnetlibsshsession.c
+++ b/src/rpc/virnetlibsshsession.c
@@ -664,7 +664,7 @@ 
virNetLibsshAuthenticateKeyboardInteractive(virNetLibsshSessionPtr sess,
 while (ret == SSH_AUTH_INFO) {
 const char *name, *instruction;
 int nprompts, iprompt;
-virBuffer buff = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buff = VIR_BUFFER_INITIALIZER;
 
 name = ssh_userauth_kbdint_getname(sess->session);
 instruction = ssh_userauth_kbdint_getinstruction(sess->session);
@@ -706,7 +706,7 @@ 
virNetLibsshAuthenticateKeyboardInteractive(virNetLibsshSessionPtr sess,
  * buffer if specified
  */
 if (virBufferUse() > 0) {
-virBuffer prompt_buff = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) prompt_buff = VIR_BUFFER_INITIALIZER;
 
 virBufferAddBuffer(_buff, );
 virBufferAdd(_buff, promptStr, promptStrLen);
@@ -750,12 +750,9 @@ 
virNetLibsshAuthenticateKeyboardInteractive(virNetLibsshSessionPtr sess,
 
  prompt_error:
 VIR_FREE(prompt);
-virBufferFreeAndReset();
 return SSH_AUTH_ERROR;
 }
 
-virBufferFreeAndReset();
-
 ret = ssh_userauth_kbdint(sess->session, NULL, NULL);
 ++try;
 if (ret == SSH_AUTH_DENIED && (priv->tries < 0 || try < priv->tries))
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index 3ea863f625..d1f4c531aa 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -849,7 +849,7 @@ int virNetSocketNewConnectSSH(const char *nodename,
 {
 char *quoted;
 virCommandPtr cmd;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
 *retsock = NULL;
 
diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c
index b4dea15452..490e9d5c5d 100644
--- a/src/rpc/virnetsshsession.c
+++ b/src/rpc/virnetsshsession.c
@@ -287,7 +287,7 @@ virNetSSHCheckHostKey(virNetSSHSessionPtr sess)
 int keyType;
 size_t keyLength;
 char *errmsg;
-virBuffer buff = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buff = VIR_BUFFER_INITIALIZER;
 virConnectCredential askKey;
 struct libssh2_knownhost *knownHostEntry = NULL;
 size_t i;
-- 
2.25.4



[PATCH 10/32] util: use g_auto() for all virBuffers

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 src/util/virbitmap.c  |  4 ++--
 src/util/vircommand.c |  3 +--
 src/util/virconf.c|  5 ++---
 src/util/virdnsmasq.c |  6 ++
 src/util/virfile.c|  2 +-
 src/util/virfilecache.c   |  2 +-
 src/util/virfirewall.c|  2 +-
 src/util/virlog.c |  5 ++---
 src/util/virnetdevip.c|  3 +--
 src/util/virpidfile.c |  2 +-
 src/util/virqemu.c|  3 +--
 src/util/virresctrl.c | 10 +++---
 src/util/virsocketaddr.c  |  3 +--
 src/util/virstoragefile.c |  2 +-
 src/util/virstring.c  |  4 ++--
 src/util/virsysinfo.c |  4 ++--
 src/util/virsystemd.c |  4 ++--
 src/util/viruri.c |  2 +-
 src/util/virxml.c |  3 +--
 19 files changed, 28 insertions(+), 41 deletions(-)

diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c
index d38a2dd7e9..60fd8491dd 100644
--- a/src/util/virbitmap.c
+++ b/src/util/virbitmap.c
@@ -345,7 +345,7 @@ virBitmapToString(virBitmapPtr bitmap,
   bool prefix,
   bool trim)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 size_t sz;
 size_t len;
 size_t diff;
@@ -404,7 +404,7 @@ virBitmapToString(virBitmapPtr bitmap,
 char *
 virBitmapFormat(virBitmapPtr bitmap)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 bool first = true;
 int start, cur, prev;
 
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index aae0ddb730..e21116b232 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -2080,7 +2080,7 @@ char *
 virCommandToString(virCommandPtr cmd, bool linebreaks)
 {
 size_t i;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 bool prevopt = false;
 
 /* Cannot assume virCommandRun will be called; so report the error
@@ -2101,7 +2101,6 @@ virCommandToString(virCommandPtr cmd, bool linebreaks)
 char *eq = strchr(cmd->env[i], '=');
 
 if (!eq) {
-virBufferFreeAndReset();
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("invalid use of command API"));
 return NULL;
diff --git a/src/util/virconf.c b/src/util/virconf.c
index f79024f07a..77ca3f9b79 100644
--- a/src/util/virconf.c
+++ b/src/util/virconf.c
@@ -1419,7 +1419,7 @@ int virConfWalk(virConfPtr conf,
 int
 virConfWriteFile(const char *filename, virConfPtr conf)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 virConfEntryPtr cur;
 int ret;
 int fd;
@@ -1437,7 +1437,6 @@ virConfWriteFile(const char *filename, virConfPtr conf)
 
 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
 if (fd < 0) {
-virBufferFreeAndReset();
 virConfError(NULL, VIR_ERR_WRITE_FAILED, _("failed to open file"));
 return -1;
 }
@@ -1471,7 +1470,7 @@ virConfWriteFile(const char *filename, virConfPtr conf)
 int
 virConfWriteMem(char *memory, int *len, virConfPtr conf)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 virConfEntryPtr cur;
 char *content;
 unsigned int use;
diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c
index 818219fbeb..b22d4622d5 100644
--- a/src/util/virdnsmasq.c
+++ b/src/util/virdnsmasq.c
@@ -139,7 +139,7 @@ addnhostsNew(const char *name,
  const char *config_dir)
 {
 dnsmasqAddnHostsfile *addnhostsfile;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
 if (VIR_ALLOC(addnhostsfile) < 0)
 return NULL;
@@ -157,7 +157,6 @@ addnhostsNew(const char *name,
 return addnhostsfile;
 
  error:
-virBufferFreeAndReset();
 addnhostsFree(addnhostsfile);
 return NULL;
 }
@@ -342,7 +341,7 @@ hostsfileNew(const char *name,
  const char *config_dir)
 {
 dnsmasqHostsfile *hostsfile;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
 if (VIR_ALLOC(hostsfile) < 0)
 return NULL;
@@ -359,7 +358,6 @@ hostsfileNew(const char *name,
 return hostsfile;
 
  error:
-virBufferFreeAndReset();
 hostsfileFree(hostsfile);
 return NULL;
 }
diff --git a/src/util/virfile.c b/src/util/virfile.c
index c034df5931..213acdbcaa 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -1303,7 +1303,7 @@ int
 virBuildPathInternal(char **path, ...)
 {
 char *path_component = NULL;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 va_list ap;
 int ret = 0;
 
diff --git a/src/util/virfilecache.c b/src/util/virfilecache.c
index 2162917b11..195587e6bd 100644
--- a/src/util/virfilecache.c
+++ b/src/util/virfilecache.c
@@ -101,7 +101,7 @@ virFileCacheGetFileName(virFileCachePtr cache,
 const char *name)
 {
   

[PATCH 23/32] util: eliminate unnecessary labels

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 src/util/virqemu.c   |  8 ++--
 src/util/virsocketaddr.c | 22 +++---
 src/util/virxml.c|  8 ++--
 3 files changed, 11 insertions(+), 27 deletions(-)

diff --git a/src/util/virqemu.c b/src/util/virqemu.c
index 52f3a2ca12..486b8e03db 100644
--- a/src/util/virqemu.c
+++ b/src/util/virqemu.c
@@ -361,16 +361,12 @@ char *
 virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr srcdef)
 {
 g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
-char *ret = NULL;
 
 if (virQEMUBuildCommandLineJSON(srcdef, , NULL, false,
 virQEMUBuildCommandLineJSONArrayNumbered) 
< 0)
-goto cleanup;
-
-ret = virBufferContentAndReset();
+return NULL;
 
- cleanup:
-return ret;
+return virBufferContentAndReset();
 }
 
 
diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c
index 0fda8e101b..e0eb76ded3 100644
--- a/src/util/virsocketaddr.c
+++ b/src/util/virsocketaddr.c
@@ -1265,16 +1265,15 @@ virSocketAddrPTRDomain(const virSocketAddr *addr,
 {
 g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 size_t i;
-int ret = -1;
 
 if (VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_INET)) {
 virSocketAddrIPv4 ip;
 
 if (prefix == 0 || prefix >= 32 || prefix % 8 != 0)
-goto unsupported;
+return -2;
 
 if (virSocketAddrGetIPv4Addr(addr, ) < 0)
-goto cleanup;
+return -1;
 
 for (i = prefix / 8; i > 0; i--)
 virBufferAsprintf(, "%u.", ip[i - 1]);
@@ -1284,30 +1283,23 @@ virSocketAddrPTRDomain(const virSocketAddr *addr,
 virSocketAddrIPv6Nibbles ip;
 
 if (prefix == 0 || prefix >= 128 || prefix % 4 != 0)
-goto unsupported;
+return -2;
 
 if (virSocketAddrGetIPv6Nibbles(addr, ) < 0)
-goto cleanup;
+return -1;
 
 for (i = prefix / 4; i > 0; i--)
 virBufferAsprintf(, "%x.", ip[i - 1]);
 
 virBufferAddLit(, VIR_SOCKET_ADDR_IPV6_ARPA);
 } else {
-goto unsupported;
+return -2;
 }
 
 if (!(*ptr = virBufferContentAndReset()))
-goto cleanup;
-
-ret = 0;
-
- cleanup:
-return ret;
+return -1;
 
- unsupported:
-ret = -2;
-goto cleanup;
+return 0;
 }
 
 void
diff --git a/src/util/virxml.c b/src/util/virxml.c
index 56e6f67597..5558b3829f 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -1271,19 +1271,15 @@ int
 virXMLValidatorValidate(virXMLValidatorPtr validator,
 xmlDocPtr doc)
 {
-int ret = -1;
-
 if (xmlRelaxNGValidateDoc(validator->rngValid, doc) != 0) {
 virReportError(VIR_ERR_XML_INVALID_SCHEMA,
_("Unable to validate doc against %s\n%s"),
validator->schemafile,
virBufferCurrentContent(>buf));
-goto cleanup;
+return -1;
 }
 
-ret = 0;
- cleanup:
-return ret;
+return 0;
 }
 
 
-- 
2.25.4



[PATCH 19/32] libxml: eliminate extra copy of string

2020-07-05 Thread Laine Stump
libxlMakeNic was calling g_strdup(virBufferCurrentContent()) to
make a copy of the buffer contents, and then later freeing the buffer
without ever using it again. Instead of this extra strdup, just
transfer ownership of the virBuffer's string with
virBufferContentAndReset(), and be done with it.

Signed-off-by: Laine Stump 
---
 src/libxl/libxl_conf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 124e08d598..fe8ad4a3cb 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1335,7 +1335,7 @@ libxlMakeNic(virDomainDefPtr def,
 }
 }
 }
-x_nic->bridge = g_strdup(virBufferCurrentContent());
+x_nic->bridge = virBufferContentAndReset();
 G_GNUC_FALLTHROUGH;
 case VIR_DOMAIN_NET_TYPE_ETHERNET:
 x_nic->script = g_strdup(script);
-- 
2.25.4



[PATCH 20/32] bhyve: eliminate unnecessary labels

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 src/bhyve/bhyve_command.c | 25 ++---
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index 9649c2d2a2..22d0b24ec4 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -169,7 +169,6 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *def,
 g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 const char *disk_source;
 size_t i;
-int ret = -1;
 
 for (i = 0; i < def->ndisks; i++) {
 g_auto(virBuffer) device = VIR_BUFFER_INITIALIZER;
@@ -187,11 +186,11 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *def,
 (virDomainDiskGetType(disk) != VIR_STORAGE_TYPE_VOLUME)) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("unsupported disk type"));
-goto error;
+return -1;
 }
 
 if (virDomainDiskTranslateSourcePool(disk) < 0)
-goto error;
+return -1;
 
 disk_source = virDomainDiskGetSource(disk);
 
@@ -200,7 +199,7 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *def,
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("cdrom device without source path "
  "not supported"));
-goto error;
+return -1;
 }
 
 switch (disk->device) {
@@ -219,7 +218,7 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *def,
 default:
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("unsupported disk device"));
-goto error;
+return -1;
 }
 virBufferAddBuffer(, );
 }
@@ -229,9 +228,7 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *def,
controller->info.addr.pci.slot,
virBufferCurrentContent());
 
-ret = 0;
- error:
-return ret;
+return 0;
 }
 
 static int
@@ -406,7 +403,7 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
 if (!(glisten = virDomainGraphicsGetListen(graphics, 0))) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Missing listen element"));
-goto error;
+return -1;
 }
 
 virBufferAsprintf(, "%d:%d,fbuf", video->info.addr.pci.slot, 
video->info.addr.pci.function);
@@ -421,13 +418,13 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
  graphics->data.vnc.port > 65535)) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("vnc port must be in range [5900,65535]"));
-goto error;
+return -1;
 }
 
 if (graphics->data.vnc.auth.passwd) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("vnc password auth not supported"));
-goto error;
+return -1;
 } else {
  /* Bhyve doesn't support VNC Auth yet, so print a warning about
   * unauthenticated VNC sessions */
@@ -461,11 +458,11 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
 case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Unsupported listen type"));
-goto error;
+return -1;
 case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
 default:
 virReportEnumRangeError(virDomainGraphicsListenType, glisten->type);
-goto error;
+return -1;
 }
 
 if (video->driver)
@@ -476,8 +473,6 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
 virCommandAddArgBuffer(cmd, );
 return 0;
 
- error:
-return -1;
 }
 
 virCommandPtr
-- 
2.25.4



[PATCH 09/32] conf: use g_auto() for all virBuffers

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 src/conf/capabilities.c  |  8 +++-
 src/conf/checkpoint_conf.c   |  2 +-
 src/conf/cpu_conf.c  |  9 +++--
 src/conf/domain_addr.c   |  2 +-
 src/conf/domain_capabilities.c   |  2 +-
 src/conf/domain_conf.c   | 12 ++--
 src/conf/interface_conf.c|  7 +++
 src/conf/network_conf.c  |  3 +--
 src/conf/node_device_conf.c  |  2 +-
 src/conf/nwfilter_conf.c |  7 +++
 src/conf/secret_conf.c   |  3 +--
 src/conf/snapshot_conf.c |  2 +-
 src/conf/storage_capabilities.c  |  6 ++
 src/conf/storage_conf.c  | 11 ---
 src/conf/virnetworkobj.c |  3 +--
 src/conf/virnetworkportdef.c |  6 ++
 src/conf/virnwfilterbindingdef.c |  6 ++
 src/conf/virnwfilterbindingobj.c |  6 ++
 src/conf/virsavecookie.c |  3 +--
 19 files changed, 39 insertions(+), 61 deletions(-)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 99b69aebb5..6a48af1fca 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -705,7 +705,7 @@ virCapabilitiesDomainDataLookupInternal(virCapsPtr caps,
 
 /* XXX check default_emulator, see how it uses this */
 if (!foundguest) {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 if (ostype)
 virBufferAsprintf(, "ostype=%s ",
   virDomainOSTypeToString(ostype));
@@ -725,7 +725,6 @@ virCapabilitiesDomainDataLookupInternal(virCapsPtr caps,
 virReportError(VIR_ERR_INVALID_ARG,
_("could not find capabilities for %s"),
virBufferCurrentContent());
-virBufferFreeAndReset();
 return ret;
 }
 
@@ -901,7 +900,7 @@ virCapabilitiesFormatResctrlMonitor(virBufferPtr buf,
 virResctrlInfoMonPtr monitor)
 {
 size_t i = 0;
-virBuffer childrenBuf = VIR_BUFFER_INIT_CHILD(buf);
+g_auto(virBuffer) childrenBuf = VIR_BUFFER_INIT_CHILD(buf);
 
 /* monitor not supported, no capability */
 if (!monitor)
@@ -1335,7 +1334,7 @@ virCapabilitiesFormatStoragePoolXML(virCapsStoragePoolPtr 
*pools,
 char *
 virCapabilitiesFormatXML(virCapsPtr caps)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
 virBufferAddLit(, "\n\n");
 virBufferAdjustIndent(, 2);
@@ -1353,7 +1352,6 @@ virCapabilitiesFormatXML(virCapsPtr caps)
 return virBufferContentAndReset();
 
  error:
-virBufferFreeAndReset();
 return NULL;
 }
 
diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c
index d557fada49..e0dce9c2ed 100644
--- a/src/conf/checkpoint_conf.c
+++ b/src/conf/checkpoint_conf.c
@@ -502,7 +502,7 @@ virDomainCheckpointDefFormat(virDomainCheckpointDefPtr def,
  virDomainXMLOptionPtr xmlopt,
  unsigned int flags)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
 virCheckFlags(VIR_DOMAIN_CHECKPOINT_FORMAT_SECURE |
   VIR_DOMAIN_CHECKPOINT_FORMAT_NO_DOMAIN |
diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index e1b0a5653f..dd3db00bc8 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -668,7 +668,7 @@ char *
 virCPUDefFormat(virCPUDefPtr def,
 virDomainNumaPtr numa)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
 if (virCPUDefFormatBufFull(, def, numa) < 0)
 goto cleanup;
@@ -676,7 +676,6 @@ virCPUDefFormat(virCPUDefPtr def,
 return virBufferContentAndReset();
 
  cleanup:
-virBufferFreeAndReset();
 return NULL;
 }
 
@@ -687,8 +686,8 @@ virCPUDefFormatBufFull(virBufferPtr buf,
virDomainNumaPtr numa)
 {
 int ret = -1;
-virBuffer attributeBuf = VIR_BUFFER_INITIALIZER;
-virBuffer childrenBuf = VIR_BUFFER_INIT_CHILD(buf);
+g_auto(virBuffer) attributeBuf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) childrenBuf = VIR_BUFFER_INIT_CHILD(buf);
 
 if (!def)
 return 0;
@@ -755,8 +754,6 @@ virCPUDefFormatBufFull(virBufferPtr buf,
 
 ret = 0;
  cleanup:
-virBufferFreeAndReset();
-virBufferFreeAndReset();
 return ret;
 }
 
diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
index 2f9ff899d7..1068cbf1d2 100644
--- a/src/conf/domain_addr.c
+++ b/src/conf/domain_addr.c
@@ -1941,7 +1941,7 @@ virDomainUSBAddressPortFormatBuf(virBufferPtr buf,
 static char * ATTRIBUTE_NONNULL(1)
 virDomainUSBAddressPortFormat(unsigned int *port)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 virDomainUSBAddressPortFormatBuf(, port);
 return virBufferContentAndReset();
 }
diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c
index 0fa8aee78e..837b004334 100644
--- 

[PATCH 30/32] storage: eliminate unnecessary labels

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 src/storage/storage_util.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index 36b5b21a5b..9f46ea764b 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -749,7 +749,7 @@ 
storageBackendCreateQemuImgOpts(virStorageEncryptionInfoDefPtr encinfo,
_("lazy_refcounts not supported with compat"
  " level %s"),
info->compat);
-goto error;
+return -1;
 }
 virBufferAddLit(, "lazy_refcounts,");
 }
@@ -759,9 +759,6 @@ 
storageBackendCreateQemuImgOpts(virStorageEncryptionInfoDefPtr encinfo,
 
 *opts = virBufferContentAndReset();
 return 0;
-
- error:
-return -1;
 }
 
 
-- 
2.25.4



[PATCH 18/32] remove redundant calls to virBufferFreeAndReset()

2020-07-05 Thread Laine Stump
There are several calls to virBufferFreeAndReset() when functions
encounter an error, but the caller never uses the virBuffer once an
error has been encountered (all callers detect error by looking at the
function return value, not the contents of the virBuffer being
operated on), and now that all virBuffers are auto-freed there is no
reason for the lower level functions like these to spend time freeing
a buffer that is guaranteed to be freed momentarily anyway.

Signed-off-by: Laine Stump 
---
 src/conf/checkpoint_conf.c | 1 -
 src/conf/domain_conf.c | 1 -
 src/conf/snapshot_conf.c   | 1 -
 src/libxl/xen_xl.c | 1 -
 src/util/virsysinfo.c  | 1 -
 src/util/virxml.c  | 1 -
 6 files changed, 6 deletions(-)

diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c
index e0dce9c2ed..41f67bd895 100644
--- a/src/conf/checkpoint_conf.c
+++ b/src/conf/checkpoint_conf.c
@@ -493,7 +493,6 @@ virDomainCheckpointDefFormatInternal(virBufferPtr buf,
 return 0;
 
  error:
-virBufferFreeAndReset(buf);
 return -1;
 }
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 33bf0a1727..e5070ed871 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -30038,7 +30038,6 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr 
def,
 return 0;
 
  error:
-virBufferFreeAndReset(buf);
 return -1;
 }
 
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index 9767592bfc..b7ed3b42df 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -916,7 +916,6 @@ virDomainSnapshotDefFormatInternal(virBufferPtr buf,
 return 0;
 
  error:
-virBufferFreeAndReset(buf);
 return -1;
 }
 
diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c
index ec5e4791a3..4baf5e336e 100644
--- a/src/libxl/xen_xl.c
+++ b/src/libxl/xen_xl.c
@@ -1432,7 +1432,6 @@ xenFormatXLVnode(virConfValuePtr list,
 ret = 0;
 
  cleanup:
-virBufferFreeAndReset(buf);
 return ret;
 }
 
diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c
index dbca99c1ef..e69fc51a1e 100644
--- a/src/util/virsysinfo.c
+++ b/src/util/virsysinfo.c
@@ -1581,7 +1581,6 @@ virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected sysinfo type model %d"),
def->type);
-virBufferFreeAndReset(buf);
 return -1;
 }
 
diff --git a/src/util/virxml.c b/src/util/virxml.c
index e9ea9fe1a4..56e6f67597 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -1283,7 +1283,6 @@ virXMLValidatorValidate(virXMLValidatorPtr validator,
 
 ret = 0;
  cleanup:
-virBufferFreeAndReset(>buf);
 return ret;
 }
 
-- 
2.25.4



[PATCH 25/32] tools: eliminate unnecessary labels

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 tools/virsh-pool.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c
index 885e000ed2..622b1396d0 100644
--- a/tools/virsh-pool.c
+++ b/tools/virsh-pool.c
@@ -330,9 +330,10 @@ virshBuildPoolXML(vshControl *ctl,
 VSH_EXCLUSIVE_OPTIONS("secret-usage", "secret-uuid");
 
 if (vshCommandOptStringReq(ctl, cmd, "name", ) < 0)
-goto cleanup;
+return false;
+
 if (vshCommandOptStringReq(ctl, cmd, "type", ) < 0)
-goto cleanup;
+return false;
 
 if (vshCommandOptStringReq(ctl, cmd, "source-host", ) < 0 ||
 vshCommandOptStringReq(ctl, cmd, "source-path", ) < 0 ||
@@ -351,8 +352,9 @@ virshBuildPoolXML(vshControl *ctl,
 vshCommandOptStringReq(ctl, cmd, "adapter-parent-wwnn", 
) < 0 ||
 vshCommandOptStringReq(ctl, cmd, "adapter-parent-wwpn", 
) < 0 ||
 vshCommandOptStringReq(ctl, cmd, "adapter-parent-fabric-wwn", 
) < 0 ||
-vshCommandOptStringReq(ctl, cmd, "source-protocol-ver", ) < 0)
-goto cleanup;
+vshCommandOptStringReq(ctl, cmd, "source-protocol-ver", ) < 
0) {
+return false;
+}
 
 virBufferAsprintf(, "\n", type);
 virBufferAdjustIndent(, 2);
@@ -419,9 +421,6 @@ virshBuildPoolXML(vshControl *ctl,
 *xml = virBufferContentAndReset();
 *retname = name;
 return true;
-
- cleanup:
-return false;
 }
 
 /*
-- 
2.25.4



[PATCH 16/32] qemu: remove unnecessary virBufferFreeAndReset() after virCommandAddArgBuffer()

2020-07-05 Thread Laine Stump
The latter function is guaranteed to always clear out the virBuffer
anyway, so this is redundant and could add to extra cargo-cult code if
used as an example.

Signed-off-by: Laine Stump 
---
 src/qemu/qemu_command.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 789c5b8f56..73c6997a49 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8913,7 +8913,6 @@ qemuBuldDomainLoaderPflashCommandLine(virCommandPtr cmd,
 virCommandAddArgBuffer(cmd, );
 
 if (loader->nvram) {
-virBufferFreeAndReset();
 virBufferAddLit(, "file=");
 virQEMUBuildBufferEscapeComma(, loader->nvram);
 virBufferAsprintf(, ",if=pflash,format=raw,unit=%d", unit);
-- 
2.25.4



[PATCH 29/32] nwfilter: eliminate unnecessary labels

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 src/nwfilter/nwfilter_ebiptables_driver.c | 89 +++
 1 file changed, 43 insertions(+), 46 deletions(-)

diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c 
b/src/nwfilter/nwfilter_ebiptables_driver.c
index dad631f03b..6cdb3ca45e 100644
--- a/src/nwfilter/nwfilter_ebiptables_driver.c
+++ b/src/nwfilter/nwfilter_ebiptables_driver.c
@@ -1797,7 +1797,6 @@ ebtablesCreateRuleInstance(virFirewallPtr fw,
 const char *target;
 bool hasMask = false;
 virFirewallRulePtr fwrule;
-int ret = -1;
 g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
 if (STREQ(chainSuffix,
@@ -1813,7 +1812,7 @@ ebtablesCreateRuleInstance(virFirewallPtr fw,
 if (printDataType(vars, \
   field, sizeof(field), \
   >p.STRUCT.ITEM) < 0) \
-goto cleanup; \
+return -1; \
 virFirewallRuleAddArg(fw, fwrule, CLI); \
 if (ENTRY_WANT_NEG_SIGN(>p.STRUCT.ITEM)) \
 virFirewallRuleAddArg(fw, fwrule, "!"); \
@@ -1825,7 +1824,7 @@ ebtablesCreateRuleInstance(virFirewallPtr fw,
 if (printDataType(vars, \
   field, sizeof(field), \
   >p.STRUCT.ITEM) < 0) \
-goto cleanup; \
+return -1; \
 virFirewallRuleAddArg(fw, fwrule, CLI); \
 if (ENTRY_WANT_NEG_SIGN(>p.STRUCT.ITEM)) \
 virFirewallRuleAddArg(fw, fwrule, "!"); \
@@ -1833,7 +1832,7 @@ ebtablesCreateRuleInstance(virFirewallPtr fw,
 if (printDataType(vars, \
   fieldalt, sizeof(fieldalt), \
   >p.STRUCT.ITEM_HI) < 0) \
-goto cleanup; \
+return -1; \
 virFirewallRuleAddArgFormat(fw, fwrule, \
 "%s%s%s", field, SEP, fieldalt); \
 } else  { \
@@ -1855,13 +1854,13 @@ ebtablesCreateRuleInstance(virFirewallPtr fw,
  vars,
  >p.ethHdrFilter.ethHdr,
  reverse) < 0)
-goto cleanup;
+return -1;
 
 if (HAS_ENTRY_ITEM(>p.ethHdrFilter.dataProtocolID)) {
 if (printDataTypeAsHex(vars,
number, sizeof(number),
>p.ethHdrFilter.dataProtocolID) < 0)
-goto cleanup;
+return -1;
 virFirewallRuleAddArg(fw, fwrule, "-p");
 if (ENTRY_WANT_NEG_SIGN(>p.ethHdrFilter.dataProtocolID))
 virFirewallRuleAddArg(fw, fwrule, "!");
@@ -1877,7 +1876,7 @@ ebtablesCreateRuleInstance(virFirewallPtr fw,
  vars,
  >p.vlanHdrFilter.ethHdr,
  reverse) < 0)
-goto cleanup;
+return -1;
 
 virFirewallRuleAddArgList(fw, fwrule,
   "-p", "0x8100", NULL);
@@ -1906,7 +1905,7 @@ ebtablesCreateRuleInstance(virFirewallPtr fw,
  vars,
  >p.stpHdrFilter.ethHdr,
  reverse) < 0)
-goto cleanup;
+return -1;
 
 virFirewallRuleAddArgList(fw, fwrule,
   "-d",  NWFILTER_MAC_BGA, NULL);
@@ -1942,7 +1941,7 @@ ebtablesCreateRuleInstance(virFirewallPtr fw,
  vars,
  >p.arpHdrFilter.ethHdr,
  reverse) < 0)
-goto cleanup;
+return -1;
 
 virFirewallRuleAddArg(fw, fwrule, "-p");
 virFirewallRuleAddArgFormat(fw, fwrule, "0x%x",
@@ -1954,7 +1953,7 @@ ebtablesCreateRuleInstance(virFirewallPtr fw,
 if (printDataType(vars,
   number, sizeof(number),
   >p.arpHdrFilter.dataHWType) < 0)
-goto cleanup;
+return -1;
 virFirewallRuleAddArg(fw, fwrule, "--arp-htype");
 if (ENTRY_WANT_NEG_SIGN(>p.arpHdrFilter.dataHWType))
 virFirewallRuleAddArg(fw, fwrule, "!");
@@ -1965,7 +1964,7 @@ ebtablesCreateRuleInstance(virFirewallPtr fw,
 if (printDataType(vars,
   number, sizeof(number),
   >p.arpHdrFilter.dataOpcode) < 0)
-goto cleanup;
+return -1;
 virFirewallRuleAddArg(fw, fwrule, "--arp-opcode");
 if (ENTRY_WANT_NEG_SIGN(>p.arpHdrFilter.dataOpcode))
 virFirewallRuleAddArg(fw, fwrule, "!");
@@ -1976,7 +1975,7 @@ ebtablesCreateRuleInstance(virFirewallPtr fw,
 if (printDataTypeAsHex(vars,
number, sizeof(number),
   

[PATCH 11/32] cpu: use g_auto() for all virBuffers

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 src/cpu/cpu_map.c | 2 +-
 src/cpu/cpu_x86.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c
index 4465ebfa7b..d14488f8aa 100644
--- a/src/cpu/cpu_map.c
+++ b/src/cpu/cpu_map.c
@@ -171,7 +171,7 @@ int cpuMapLoad(const char *arch,
 {
 xmlDocPtr xml = NULL;
 xmlXPathContextPtr ctxt = NULL;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 char *xpath = NULL;
 int ret = -1;
 char *mapfile;
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index bf26cf4e76..1e5cd93abb 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -972,7 +972,7 @@ x86FeatureNames(virCPUx86MapPtr map,
 const char *separator,
 virCPUx86Data *data)
 {
-virBuffer ret = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) ret = VIR_BUFFER_INITIALIZER;
 bool first = true;
 size_t i;
 
@@ -1208,7 +1208,7 @@ virCPUx86SignaturesMatch(virCPUx86SignaturesPtr sigs,
 static char *
 virCPUx86SignaturesFormat(virCPUx86SignaturesPtr sigs)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 size_t i;
 
 if (!sigs)
@@ -1707,7 +1707,7 @@ virCPUx86DataFormat(const virCPUData *data)
 {
 virCPUx86DataIterator iter;
 virCPUx86DataItemPtr item;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
 virCPUx86DataIteratorInit(, >data.x86);
 
-- 
2.25.4



[PATCH 24/32] tests: eliminate unnecessary labels

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 tests/virbuftest.c | 35 ++-
 1 file changed, 14 insertions(+), 21 deletions(-)

diff --git a/tests/virbuftest.c b/tests/virbuftest.c
index 39ae7c2b9d..df341be50c 100644
--- a/tests/virbuftest.c
+++ b/tests/virbuftest.c
@@ -100,7 +100,6 @@ static int testBufTrim(const void *data G_GNUC_UNUSED)
 virBufferPtr buf = NULL;
 g_autofree char *result = NULL;
 const char *expected = "a,b";
-int ret = -1;
 
 virBufferTrim(buf, "");
 buf = 
@@ -120,13 +119,10 @@ static int testBufTrim(const void *data G_GNUC_UNUSED)
 result = virBufferContentAndReset(buf);
 if (!result || STRNEQ(result, expected)) {
 virTestDifference(stderr, expected, result);
-goto cleanup;
+return -1;
 }
 
-ret = 0;
-
- cleanup:
-return ret;
+return 0;
 }
 
 static int
@@ -158,7 +154,6 @@ static int testBufAddBuffer(const void *data G_GNUC_UNUSED)
 g_auto(virBuffer) buf1 = VIR_BUFFER_INITIALIZER;
 g_auto(virBuffer) buf2 = VIR_BUFFER_INITIALIZER;
 g_auto(virBuffer) buf3 = VIR_BUFFER_INITIALIZER;
-int ret = -1;
 g_autofree char *result = NULL;
 const char *expected = \
 "  A long time ago, in a galaxy far,\n" \
@@ -178,17 +173,17 @@ static int testBufAddBuffer(const void *data 
G_GNUC_UNUSED)
 
 if (virBufferUse()) {
 VIR_TEST_DEBUG("buf1 already in use");
-goto cleanup;
+return -1;
 }
 
 if (virBufferUse()) {
 VIR_TEST_DEBUG("buf2 already in use");
-goto cleanup;
+return -1;
 }
 
 if (virBufferUse()) {
 VIR_TEST_DEBUG("buf3 already in use");
-goto cleanup;
+return -1;
 }
 
 virBufferAdjustIndent(, 2);
@@ -213,52 +208,50 @@ static int testBufAddBuffer(const void *data 
G_GNUC_UNUSED)
 
 if (!virBufferUse()) {
 VIR_TEST_DEBUG("Error adding to buf1");
-goto cleanup;
+return -1;
 }
 
 if (!virBufferUse()) {
 VIR_TEST_DEBUG("Error adding to buf2");
-goto cleanup;
+return -1;
 }
 
 if (!virBufferUse()) {
 VIR_TEST_DEBUG("Error adding to buf3");
-goto cleanup;
+return -1;
 }
 
 virBufferAddBuffer(, );
 
 if (!virBufferUse()) {
 VIR_TEST_DEBUG("buf2 cleared mistakenly");
-goto cleanup;
+return -1;
 }
 
 if (virBufferUse()) {
 VIR_TEST_DEBUG("buf3 is not clear even though it should be");
-goto cleanup;
+return -1;
 }
 
 virBufferAddBuffer(, );
 
 if (!virBufferUse()) {
 VIR_TEST_DEBUG("buf1 cleared mistakenly");
-goto cleanup;
+return -1;
 }
 
 if (virBufferUse()) {
 VIR_TEST_DEBUG("buf2 is not clear even though it should be");
-goto cleanup;
+return -1;
 }
 
 result = virBufferContentAndReset();
 if (STRNEQ_NULLABLE(result, expected)) {
 virTestDifference(stderr, expected, result);
-goto cleanup;
+return -1;
 }
 
-ret = 0;
- cleanup:
-return ret;
+return 0;
 }
 
 static int
-- 
2.25.4



[PATCH 04/32] libxl: use g_auto() for all virBuffers

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 src/libxl/libxl_conf.c  |  6 ++
 src/libxl/libxl_driver.c|  2 +-
 src/libxl/libxl_migration.c |  2 +-
 src/libxl/xen_common.c  | 12 +---
 src/libxl/xen_xl.c  | 19 +++
 src/libxl/xen_xm.c  |  3 +--
 6 files changed, 17 insertions(+), 27 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index a0059fc2a7..124e08d598 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -911,7 +911,7 @@ libxlMakeNetworkDiskSrcStr(virStorageSourcePtr src,
const char *secret)
 {
 char *ret = NULL;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 size_t i;
 
 switch ((virStorageNetProtocol) src->protocol) {
@@ -978,7 +978,6 @@ libxlMakeNetworkDiskSrcStr(virStorageSourcePtr src,
 }
 
  cleanup:
-virBufferFreeAndReset();
 return ret;
 }
 
@@ -1241,7 +1240,7 @@ libxlMakeNic(virDomainDefPtr def,
 const virNetDevBandwidth *actual_bw;
 const virNetDevVPortProfile *port_profile;
 const virNetDevVlan *virt_vlan;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 size_t i;
 const char *script = NULL;
 int ret = -1;
@@ -1434,7 +1433,6 @@ libxlMakeNic(virDomainDefPtr def,
 ret = 0;
 
  cleanup:
-virBufferFreeAndReset();
 virObjectUnref(network);
 virObjectUnref(conn);
 
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index a80bc3fe3a..9b9713df2c 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -942,7 +942,7 @@ static char *
 libxlConnectGetSysinfo(virConnectPtr conn, unsigned int flags)
 {
 libxlDriverPrivatePtr driver = conn->privateData;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
 virCheckFlags(0, NULL);
 
diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c
index 9d253346eb..87cd5337ba 100644
--- a/src/libxl/libxl_migration.c
+++ b/src/libxl/libxl_migration.c
@@ -117,7 +117,7 @@ libxlMigrationBakeCookie(libxlMigrationCookiePtr mig,
  char **cookieout,
  int *cookieoutlen)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 char uuidstr[VIR_UUID_STRING_BUFLEN];
 
 if (!cookieout || !cookieoutlen)
diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c
index 5c37e431eb..6b16752c8a 100644
--- a/src/libxl/xen_common.c
+++ b/src/libxl/xen_common.c
@@ -1633,7 +1633,7 @@ xenFormatSxprChr(virDomainChrDefPtr def,
 static int
 xenFormatSerial(virConfValuePtr list, virDomainChrDefPtr serial)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 virConfValuePtr val, tmp;
 int ret;
 
@@ -1661,7 +1661,6 @@ xenFormatSerial(virConfValuePtr list, virDomainChrDefPtr 
serial)
 return 0;
 
  cleanup:
-virBufferFreeAndReset();
 return -1;
 }
 
@@ -1694,7 +1693,7 @@ xenFormatNet(virConnectPtr conn,
  int hvm,
  const char *vif_typename)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 virConfValuePtr val, tmp;
 char macaddr[VIR_MAC_STRING_BUFLEN];
 
@@ -1826,7 +1825,6 @@ xenFormatNet(virConnectPtr conn,
 return 0;
 
  cleanup:
-virBufferFreeAndReset();
 return -1;
 }
 
@@ -2034,7 +2032,7 @@ xenFormatCharDev(virConfPtr conf, virDomainDefPtr def,
 
 if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
 if (def->nparallels) {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 char *str;
 int ret;
 
@@ -2052,7 +2050,7 @@ xenFormatCharDev(virConfPtr conf, virDomainDefPtr def,
 
 if (def->nserials) {
 if ((def->nserials == 1) && (def->serials[0]->target.port == 0)) {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 char *str;
 int ret;
 
@@ -2329,7 +2327,7 @@ xenFormatVfb(virConfPtr conf, virDomainDefPtr def)
 } else {
 virConfValuePtr vfb, disp;
 char *vfbstr = NULL;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
 if (def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) {
 virBufferAddLit(, "type=sdl");
diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c
index d40c2e1d8e..ec5e4791a3 100644
--- a/src/libxl/xen_xl.c
+++ b/src/libxl/xen_xl.c
@@ -1445,7 +1445,7 @@ xenFormatXLVnuma(virConfValuePtr list,
 int ret = -1;
 size_t i;
 
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 virConfValuePtr numaVnode, tmp;
 
 size_t nodeSize = 

[PATCH 07/32] tests: use g_auto for all virBuffers

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 tests/commandtest.c  |  3 +--
 tests/cputest.c  |  2 +-
 tests/networkxml2firewalltest.c  |  3 +--
 tests/nodedevmdevctltest.c   |  6 ++
 tests/nwfilterebiptablestest.c   | 21 +++--
 tests/nwfilterxml2firewalltest.c |  3 +--
 tests/qemublocktest.c|  2 +-
 tests/qemucommandutiltest.c  |  2 +-
 tests/qemumigparamstest.c|  6 ++
 tests/qemumonitorjsontest.c  |  9 -
 tests/qemumonitortestutils.c |  2 +-
 tests/testutils.c|  2 +-
 tests/vboxsnapshotxmltest.c  |  3 +--
 tests/virbuftest.c   | 23 ++-
 tests/vircgrouptest.c|  3 +--
 tests/virfirewalltest.c  | 30 ++
 tests/virhostcputest.c   |  3 +--
 tests/virkmodtest.c  |  4 ++--
 tests/virnetdevbandwidthtest.c   |  3 +--
 19 files changed, 49 insertions(+), 81 deletions(-)

diff --git a/tests/commandtest.c b/tests/commandtest.c
index d5092b7dd0..f0e60ee5fe 100644
--- a/tests/commandtest.c
+++ b/tests/commandtest.c
@@ -390,7 +390,7 @@ static int test9(const void *unused G_GNUC_UNUSED)
 {
 virCommandPtr cmd = virCommandNew(abs_builddir "/commandhelper");
 const char* const args[] = { "arg1", "arg2", NULL };
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
 virCommandAddArg(cmd, "-version");
 virCommandAddArgPair(cmd, "-log", "bar.log");
@@ -402,7 +402,6 @@ static int test9(const void *unused G_GNUC_UNUSED)
 
 if (virBufferUse()) {
 printf("Buffer not transferred\n");
-virBufferFreeAndReset();
 virCommandFree(cmd);
 return -1;
 }
diff --git a/tests/cputest.c b/tests/cputest.c
index 0cf6870574..83d63bf495 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -237,7 +237,7 @@ cpuTestGuestCPU(const void *arg)
 virCPUDefPtr host = NULL;
 virCPUDefPtr cpu = NULL;
 virCPUCompareResult cmpResult;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 char *result = NULL;
 
 if (!(host = cpuTestLoadXML(data->arch, data->host)) ||
diff --git a/tests/networkxml2firewalltest.c b/tests/networkxml2firewalltest.c
index 69fadd55c4..29e7d8bc38 100644
--- a/tests/networkxml2firewalltest.c
+++ b/tests/networkxml2firewalltest.c
@@ -62,7 +62,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
  const char *baseargs)
 {
 char *actualargv = NULL;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 virNetworkDefPtr def = NULL;
 int ret = -1;
 char *actual;
@@ -92,7 +92,6 @@ static int testCompareXMLToArgvFiles(const char *xml,
 ret = 0;
 
  cleanup:
-virBufferFreeAndReset();
 VIR_FREE(actualargv);
 virNetworkDefFree(def);
 return ret;
diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c
index f5bcf5227d..9780553a3a 100644
--- a/tests/nodedevmdevctltest.c
+++ b/tests/nodedevmdevctltest.c
@@ -54,7 +54,7 @@ testMdevctlStart(const char *virt_type,
 {
 g_autoptr(virNodeDeviceDef) def = NULL;
 virNodeDeviceObjPtr obj = NULL;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 const char *actualCmdline = NULL;
 int ret = -1;
 g_autofree char *uuid = NULL;
@@ -87,7 +87,6 @@ testMdevctlStart(const char *virt_type,
 ret = 0;
 
  cleanup:
-virBufferFreeAndReset();
 virCommandSetDryRun(NULL, NULL, NULL);
 virNodeDeviceObjEndAPI();
 return ret;
@@ -114,7 +113,7 @@ static int
 testMdevctlStop(const void *data)
 {
 const char *uuid = data;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 const char *actualCmdline = NULL;
 int ret = -1;
 g_autoptr(virCommand) cmd = NULL;
@@ -140,7 +139,6 @@ testMdevctlStop(const void *data)
 ret = 0;
 
  cleanup:
-virBufferFreeAndReset();
 virCommandSetDryRun(NULL, NULL, NULL);
 return ret;
 }
diff --git a/tests/nwfilterebiptablestest.c b/tests/nwfilterebiptablestest.c
index 3e6c335d4e..4d8791023c 100644
--- a/tests/nwfilterebiptablestest.c
+++ b/tests/nwfilterebiptablestest.c
@@ -68,7 +68,7 @@
 static int
 testNWFilterEBIPTablesAllTeardown(const void *opaque G_GNUC_UNUSED)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 const char *expected =
 VIR_NWFILTER_NEW_RULES_TEARDOWN
 "iptables -D libvirt-out -m physdev --physdev-is-bridged --physdev-out 
vnet0 -g FO-vnet0\n"
@@ -120,7 +120,6 @@ testNWFilterEBIPTablesAllTeardown(const void *opaque 
G_GNUC_UNUSED)
 ret = 0;
  cleanup:
 virCommandSetDryRun(NULL, NULL, NULL);
-virBufferFreeAndReset();
 VIR_FREE(actual);
 return ret;
 }
@@ -129,7 +128,7 @@ testNWFilterEBIPTablesAllTeardown(const void *opaque 

[PATCH 17/32] conf: consistently check for error when calling virSysinfoFormat()

2020-07-05 Thread Laine Stump
Every other caller of this function checks for an error return and
ends their formatting early if there is an error. This function
happily continues on its way.

Signed-off-by: Laine Stump 
---
 src/conf/domain_conf.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c02d1c8bd2..33bf0a1727 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -29649,8 +29649,10 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr 
def,
 if (def->resource)
 virDomainResourceDefFormat(buf, def->resource);
 
-for (i = 0; i < def->nsysinfo; i++)
-virSysinfoFormat(buf, def->sysinfo[i]);
+for (i = 0; i < def->nsysinfo; i++) {
+if (virSysinfoFormat(buf, def->sysinfo[i]) < 0)
+goto error;
+}
 
 if (def->os.bootloader) {
 virBufferEscapeString(buf, "%s\n",
-- 
2.25.4



[PATCH 32/32] eliminate unnecessary labels and ret variables

2020-07-05 Thread Laine Stump
after making all virFirewall objects use g_autoptr().

Signed-off-by: Laine Stump 
---
 src/network/bridge_driver_linux.c | 27 +++
 src/nwfilter/nwfilter_ebiptables_driver.c | 32 +++
 src/util/virebtables.c| 16 ++--
 src/util/viriptables.c|  8 ++
 4 files changed, 22 insertions(+), 61 deletions(-)

diff --git a/src/network/bridge_driver_linux.c 
b/src/network/bridge_driver_linux.c
index f72f94f38d..5fc77785dc 100644
--- a/src/network/bridge_driver_linux.c
+++ b/src/network/bridge_driver_linux.c
@@ -839,7 +839,6 @@ int networkAddFirewallRules(virNetworkDefPtr def)
 size_t i;
 virNetworkIPDefPtr ipdef;
 g_autoptr(virFirewall) fw = virFirewallNew();
-int ret = -1;
 
 if (virOnce(, networkSetupPrivateChains) < 0)
 return -1;
@@ -869,11 +868,11 @@ int networkAddFirewallRules(virNetworkDefPtr def)
_("zone %s requested for network %s "
  "but firewalld is not active"),
def->bridgeZone, def->name);
-goto cleanup;
+return -1;
 }
 
 if (virFirewallDInterfaceSetZone(def->bridge, def->bridgeZone) < 0)
-goto cleanup;
+return -1;
 
 } else {
 
@@ -893,13 +892,13 @@ int networkAddFirewallRules(virNetworkDefPtr def)
  */
 if (virFirewallDZoneExists("libvirt")) {
 if (virFirewallDInterfaceSetZone(def->bridge, "libvirt") < 0)
-goto cleanup;
+return -1;
 } else {
 unsigned long version;
 int vresult = virFirewallDGetVersion();
 
 if (vresult < 0)
-goto cleanup;
+return -1;
 
 /* Support for nftables backend was added in firewalld
  * 0.6.0. Support for rule priorities (required by the
@@ -919,7 +918,7 @@ int networkAddFirewallRules(virNetworkDefPtr def)
  "version supporting rule priorities "
  "(0.7.0+) and/or rebuilding "
  "libvirt with --with-firewalld-zone"));
-goto cleanup;
+return -1;
 }
 }
 }
@@ -933,7 +932,7 @@ int networkAddFirewallRules(virNetworkDefPtr def)
  (ipdef = virNetworkDefGetIPByIndex(def, AF_UNSPEC, i));
  i++) {
 if (networkAddIPSpecificFirewallRules(fw, def, ipdef) < 0)
-goto cleanup;
+return -1;
 }
 
 virFirewallStartRollback(fw, 0);
@@ -942,19 +941,14 @@ int networkAddFirewallRules(virNetworkDefPtr def)
  (ipdef = virNetworkDefGetIPByIndex(def, AF_UNSPEC, i));
  i++) {
 if (networkRemoveIPSpecificFirewallRules(fw, def, ipdef) < 0)
-goto cleanup;
+return -1;
 }
 networkRemoveGeneralFirewallRules(fw, def);
 
 virFirewallStartTransaction(fw, VIR_FIREWALL_TRANSACTION_IGNORE_ERRORS);
 networkAddChecksumFirewallRules(fw, def);
 
-if (virFirewallApply(fw) < 0)
-goto cleanup;
-
-ret = 0;
- cleanup:
-return ret;
+return virFirewallApply(fw);
 }
 
 /* Remove all rules for all ip addresses (and general rules) on a network */
@@ -973,12 +967,9 @@ void networkRemoveFirewallRules(virNetworkDefPtr def)
  (ipdef = virNetworkDefGetIPByIndex(def, AF_UNSPEC, i));
  i++) {
 if (networkRemoveIPSpecificFirewallRules(fw, def, ipdef) < 0)
-goto cleanup;
+return;
 }
 networkRemoveGeneralFirewallRules(fw, def);
 
 virFirewallApply(fw);
-
- cleanup:
-return;
 }
diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c 
b/src/nwfilter/nwfilter_ebiptables_driver.c
index 2976521e6d..78a52408b2 100644
--- a/src/nwfilter/nwfilter_ebiptables_driver.c
+++ b/src/nwfilter/nwfilter_ebiptables_driver.c
@@ -2866,7 +2866,7 @@ ebtablesApplyBasicRules(const char *ifname,
 virMacAddrFormat(macaddr, macaddr_str);
 
 if (ebiptablesAllTeardown(ifname) < 0)
-goto error;
+return -1;
 
 virFirewallStartTransaction(fw, 0);
 
@@ -2899,7 +2899,6 @@ ebtablesApplyBasicRules(const char *ifname,
 
  tear_down_tmpebchains:
 ebtablesCleanAll(ifname);
- error:
 return -1;
 }
 
@@ -2937,7 +2936,7 @@ ebtablesApplyDHCPOnlyRules(const char *ifname,
 virMacAddrFormat(macaddr, macaddr_str);
 
 if (ebiptablesAllTeardown(ifname) < 0)
-goto error;
+return -1;
 
 virFirewallStartTransaction(fw, 0);
 
@@ -3016,7 +3015,6 @@ ebtablesApplyDHCPOnlyRules(const char *ifname,
 
  tear_down_tmpebchains:
 ebtablesCleanAll(ifname);
- error:
 return -1;
 }
 
@@ -3038,7 +3036,7 @@ ebtablesApplyDropAllRules(const char *ifname)
 g_autoptr(virFirewall) fw = virFirewallNew();
 
 if (ebiptablesAllTeardown(ifname) < 0)
-goto error;
+  

[PATCH 13/32] nwfilter: use g_auto() for all virBuffers

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 src/nwfilter/nwfilter_ebiptables_driver.c | 8 +++-
 src/nwfilter/nwfilter_gentech_driver.c| 6 ++
 src/nwfilter/nwfilter_learnipaddr.c   | 2 +-
 3 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c 
b/src/nwfilter/nwfilter_ebiptables_driver.c
index 6fc8044c8d..dad631f03b 100644
--- a/src/nwfilter/nwfilter_ebiptables_driver.c
+++ b/src/nwfilter/nwfilter_ebiptables_driver.c
@@ -190,7 +190,7 @@ _printDataType(virNWFilterVarCombIterPtr vars,
 bool done;
 char *data;
 uint8_t ctr;
-virBuffer vb = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) vb = VIR_BUFFER_INITIALIZER;
 char *flags;
 
 if (printVar(vars, buf, bufsize, item, ) < 0)
@@ -1528,7 +1528,7 @@ _iptablesCreateRuleInstance(virFirewallPtr fw,
 static int
 printStateMatchFlags(int32_t flags, char **bufptr)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 virNWFilterPrintStateMatchFlags(,
 "",
 flags,
@@ -1798,7 +1798,7 @@ ebtablesCreateRuleInstance(virFirewallPtr fw,
 bool hasMask = false;
 virFirewallRulePtr fwrule;
 int ret = -1;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
 if (STREQ(chainSuffix,
   virNWFilterChainSuffixTypeToString(
@@ -2423,8 +2423,6 @@ ebtablesCreateRuleInstance(virFirewallPtr fw,
 
 ret = 0;
  cleanup:
-virBufferFreeAndReset();
-
 return ret;
 }
 
diff --git a/src/nwfilter/nwfilter_gentech_driver.c 
b/src/nwfilter/nwfilter_gentech_driver.c
index 6789a4a3fa..b7633eb10a 100644
--- a/src/nwfilter/nwfilter_gentech_driver.c
+++ b/src/nwfilter/nwfilter_gentech_driver.c
@@ -426,15 +426,13 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr 
filter,
 if (!virNWFilterVarAccessIsAvailable(rule->varAccess[j],
  vars)) {
 char *varAccess;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
 virNWFilterVarAccessPrint(rule->varAccess[j], );
 
 val = virNWFilterVarValueCreateSimpleCopyValue("1");
-if (!val) {
-virBufferFreeAndReset();
+if (!val)
 return -1;
-}
 
 varAccess = virBufferContentAndReset();
 rc = virHashUpdateEntry(missing_vars, varAccess, val);
diff --git a/src/nwfilter/nwfilter_learnipaddr.c 
b/src/nwfilter/nwfilter_learnipaddr.c
index 4ce8d5ba03..14c66cff35 100644
--- a/src/nwfilter/nwfilter_learnipaddr.c
+++ b/src/nwfilter/nwfilter_learnipaddr.c
@@ -397,7 +397,7 @@ learnIPAddressThread(void *arg)
req->binding->portdevname);
 int dhcp_opts_len;
 char macaddr[VIR_MAC_STRING_BUFLEN];
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 char *filter = NULL;
 uint16_t etherType;
 bool showError = true;
-- 
2.25.4



[PATCH 03/32] hyperv: use g_auto() for all virBuffers

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 src/hyperv/hyperv_driver.c | 34 --
 src/hyperv/hyperv_wmi.c| 11 +--
 2 files changed, 21 insertions(+), 24 deletions(-)

diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 4677a25ff8..20d372b274 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -60,7 +60,7 @@ static int
 hypervInitConnection(virConnectPtr conn, hypervPrivate *priv,
  char *username, char *password)
 {
-virBuffer query = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
 hypervWqlQuery wqlQuery = HYPERV_WQL_QUERY_INITIALIZER;
 hypervObject *computerSystem = NULL;
 int ret = -1;
@@ -204,7 +204,7 @@ hypervConnectGetHostname(virConnectPtr conn)
 {
 char *hostname = NULL;
 hypervPrivate *priv = conn->privateData;
-virBuffer query = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
 Win32_ComputerSystem *computerSystem = NULL;
 
 virBufferAddLit(, WIN32_COMPUTERSYSTEM_WQL_SELECT);
@@ -234,7 +234,7 @@ hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info)
 {
 int result = -1;
 hypervPrivate *priv = conn->privateData;
-virBuffer query = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
 Win32_ComputerSystem *computerSystem = NULL;
 Win32_Processor *processorList = NULL;
 Win32_Processor *processor = NULL;
@@ -329,7 +329,7 @@ hypervConnectListDomains(virConnectPtr conn, int *ids, int 
maxids)
 {
 bool success = false;
 hypervPrivate *priv = conn->privateData;
-virBuffer query = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
 Msvm_ComputerSystem *computerSystemList = NULL;
 Msvm_ComputerSystem *computerSystem = NULL;
 int count = 0;
@@ -371,7 +371,7 @@ hypervConnectNumOfDomains(virConnectPtr conn)
 {
 bool success = false;
 hypervPrivate *priv = conn->privateData;
-virBuffer query = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
 Msvm_ComputerSystem *computerSystemList = NULL;
 Msvm_ComputerSystem *computerSystem = NULL;
 int count = 0;
@@ -407,7 +407,7 @@ hypervDomainLookupByID(virConnectPtr conn, int id)
 {
 virDomainPtr domain = NULL;
 hypervPrivate *priv = conn->privateData;
-virBuffer query = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
 Msvm_ComputerSystem *computerSystem = NULL;
 
 virBufferAddLit(, MSVM_COMPUTERSYSTEM_WQL_SELECT);
@@ -439,7 +439,7 @@ hypervDomainLookupByUUID(virConnectPtr conn, const unsigned 
char *uuid)
 virDomainPtr domain = NULL;
 hypervPrivate *priv = conn->privateData;
 char uuid_string[VIR_UUID_STRING_BUFLEN];
-virBuffer query = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
 Msvm_ComputerSystem *computerSystem = NULL;
 
 virUUIDFormat(uuid, uuid_string);
@@ -473,7 +473,7 @@ hypervDomainLookupByName(virConnectPtr conn, const char 
*name)
 {
 virDomainPtr domain = NULL;
 hypervPrivate *priv = conn->privateData;
-virBuffer query = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
 Msvm_ComputerSystem *computerSystem = NULL;
 
 virBufferAddLit(, MSVM_COMPUTERSYSTEM_WQL_SELECT);
@@ -612,7 +612,7 @@ hypervDomainGetInfo(virDomainPtr domain, virDomainInfoPtr 
info)
 int result = -1;
 hypervPrivate *priv = domain->conn->privateData;
 char uuid_string[VIR_UUID_STRING_BUFLEN];
-virBuffer query = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
 Msvm_ComputerSystem *computerSystem = NULL;
 Msvm_VirtualSystemSettingData *virtualSystemSettingData = NULL;
 Msvm_ProcessorSettingData *processorSettingData = NULL;
@@ -746,7 +746,7 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int 
flags)
 hypervPrivate *priv = domain->conn->privateData;
 virDomainDefPtr def = NULL;
 char uuid_string[VIR_UUID_STRING_BUFLEN];
-virBuffer query = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
 Msvm_ComputerSystem *computerSystem = NULL;
 Msvm_VirtualSystemSettingData *virtualSystemSettingData = NULL;
 Msvm_ProcessorSettingData *processorSettingData = NULL;
@@ -851,7 +851,7 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int 
flags)
 } else if (priv->wmiVersion == HYPERV_WMI_VERSION_V2 &&
virtualSystemSettingData->data.v2->Notes.data != NULL) {
 char **notes = (char **)virtualSystemSettingData->data.v2->Notes.data;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 size_t i = 0;
 
 /* in practice Notes has 1 element */
@@ -906,7 +906,7 @@ hypervConnectListDefinedDomains(virConnectPtr conn, char 
**const names, int maxn
 {
 bool success = false;
 

[PATCH 26/32] network: eliminate unnecessary labels

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 src/network/bridge_driver.c | 16 ++--
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 9f37d8f558..713763130b 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -1842,7 +1842,6 @@ networkRadvdConfContents(virNetworkObjPtr obj,
 {
 virNetworkDefPtr def = virNetworkObjGetDef(obj);
 g_auto(virBuffer) configbuf = VIR_BUFFER_INITIALIZER;
-int ret = -1;
 size_t i;
 virNetworkIPDefPtr ipdef;
 bool v6present = false, dhcp6 = false;
@@ -1859,10 +1858,8 @@ networkRadvdConfContents(virNetworkObjPtr obj,
 }
 
 /* If there are no IPv6 addresses, then we are done */
-if (!v6present) {
-ret = 0;
-goto cleanup;
-}
+if (!v6present)
+return 0;
 
 /* create radvd config file appropriate for this network;
  * IgnoreIfMissing allows radvd to start even when the bridge is down
@@ -1887,10 +1884,11 @@ networkRadvdConfContents(virNetworkObjPtr obj,
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("bridge '%s' has an invalid prefix"),
def->bridge);
-goto cleanup;
+return -1;
 }
 if (!(netaddr = virSocketAddrFormat(>address)))
-goto cleanup;
+return -1;
+
 virBufferAsprintf(,
   "  prefix %s/%d\n"
   "  {\n%s  };\n",
@@ -1903,9 +1901,7 @@ networkRadvdConfContents(virNetworkObjPtr obj,
 
 *configstr = virBufferContentAndReset();
 
-ret = 0;
- cleanup:
-return ret;
+return 0;
 }
 
 
-- 
2.25.4



[PATCH 22/32] libxl: eliminate unnecessary labels

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 src/libxl/libxl_conf.c | 11 ---
 src/libxl/xen_common.c | 16 +---
 src/libxl/xen_xl.c | 25 -
 src/libxl/xen_xm.c |  7 ++-
 4 files changed, 19 insertions(+), 40 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index fe8ad4a3cb..02cc5e6f1b 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -910,7 +910,6 @@ libxlMakeNetworkDiskSrcStr(virStorageSourcePtr src,
const char *username,
const char *secret)
 {
-char *ret = NULL;
 g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 size_t i;
 
@@ -931,14 +930,14 @@ libxlMakeNetworkDiskSrcStr(virStorageSourcePtr src,
 virReportError(VIR_ERR_NO_SUPPORT,
_("Unsupported network block protocol '%s'"),
virStorageNetProtocolTypeToString(src->protocol));
-goto cleanup;
+return NULL;
 
 case VIR_STORAGE_NET_PROTOCOL_RBD:
 if (strchr(src->path, ':')) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("':' not allowed in RBD source volume name '%s'"),
src->path);
-goto cleanup;
+return NULL;
 }
 
 virBufferStrcat(, "rbd:", src->volume, "/", src->path, NULL);
@@ -973,12 +972,10 @@ libxlMakeNetworkDiskSrcStr(virStorageSourcePtr src,
 if (src->configFile)
 virBufferEscape(, '\\', ":", ":conf=%s", src->configFile);
 
-ret = virBufferContentAndReset();
-break;
+return virBufferContentAndReset();
 }
 
- cleanup:
-return ret;
+return NULL;
 }
 
 static int
diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c
index 6b16752c8a..475c64f944 100644
--- a/src/libxl/xen_common.c
+++ b/src/libxl/xen_common.c
@@ -1640,13 +1640,13 @@ xenFormatSerial(virConfValuePtr list, 
virDomainChrDefPtr serial)
 if (serial) {
 ret = xenFormatSxprChr(serial, );
 if (ret < 0)
-goto cleanup;
+return -1;
 } else {
 virBufferAddLit(, "none");
 }
 
 if (VIR_ALLOC(val) < 0)
-goto cleanup;
+return -1;
 
 val->type = VIR_CONF_STRING;
 val->str = virBufferContentAndReset();
@@ -1659,9 +1659,6 @@ xenFormatSerial(virConfValuePtr list, virDomainChrDefPtr 
serial)
 list->list = val;
 
 return 0;
-
- cleanup:
-return -1;
 }
 
 char *
@@ -1781,12 +1778,12 @@ xenFormatNet(virConnectPtr conn,
 case VIR_DOMAIN_NET_TYPE_USER:
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported net type 
'%s'"),
virDomainNetTypeToString(net->type));
-goto cleanup;
+return -1;
 
 case VIR_DOMAIN_NET_TYPE_LAST:
 default:
 virReportEnumRangeError(virDomainNetType, net->type);
-goto cleanup;
+return -1;
 }
 
 if (virDomainNetGetModelString(net)) {
@@ -1810,7 +1807,7 @@ xenFormatNet(virConnectPtr conn,
 virBufferAsprintf(, ",rate=%lluKB/s", 
net->bandwidth->out->average);
 
 if (VIR_ALLOC(val) < 0)
-goto cleanup;
+return -1;
 
 val->type = VIR_CONF_STRING;
 val->str = virBufferContentAndReset();
@@ -1823,9 +1820,6 @@ xenFormatNet(virConnectPtr conn,
 list->list = val;
 
 return 0;
-
- cleanup:
-return -1;
 }
 
 
diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c
index 4baf5e336e..b81c5d23ce 100644
--- a/src/libxl/xen_xl.c
+++ b/src/libxl/xen_xl.c
@@ -1412,11 +1412,10 @@ static int
 xenFormatXLVnode(virConfValuePtr list,
  virBufferPtr buf)
 {
-int ret = -1;
 virConfValuePtr numaPnode, tmp;
 
 if (VIR_ALLOC(numaPnode) < 0)
-goto cleanup;
+return -1;
 
 /* Place VNODE directive */
 numaPnode->type = VIR_CONF_STRING;
@@ -1429,10 +1428,8 @@ xenFormatXLVnode(virConfValuePtr list,
 tmp->next = numaPnode;
 else
 list->list = numaPnode;
-ret = 0;
 
- cleanup:
-return ret;
+return 0;
 }
 
 static int
@@ -1561,7 +1558,6 @@ xenFormatXLXenbusLimits(virConfPtr conf, virDomainDefPtr 
def)
 static char *
 xenFormatXLDiskSrcNet(virStorageSourcePtr src)
 {
-char *ret = NULL;
 g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 size_t i;
 
@@ -1582,14 +1578,14 @@ xenFormatXLDiskSrcNet(virStorageSourcePtr src)
 virReportError(VIR_ERR_NO_SUPPORT,
_("Unsupported network block protocol '%s'"),
virStorageNetProtocolTypeToString(src->protocol));
-goto cleanup;
+return NULL;
 
 case VIR_STORAGE_NET_PROTOCOL_RBD:
 if (strchr(src->path, ':')) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("':' not allowed in RBD source volume name '%s'"),
src->path);
-goto cleanup;
+return NULL;
 }
 
 

[PATCH 08/32] tools: use g_auto() for all virBuffers

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 tools/virsh-checkpoint.c |  3 +-
 tools/virsh-domain-monitor.c |  3 +-
 tools/virsh-domain.c | 58 +---
 tools/virsh-pool.c   |  6 ++--
 tools/virsh-secret.c |  2 +-
 tools/virsh-snapshot.c   |  3 +-
 tools/virsh-volume.c |  3 +-
 tools/vsh-table.c|  2 +-
 tools/vsh.c  | 15 --
 9 files changed, 42 insertions(+), 53 deletions(-)

diff --git a/tools/virsh-checkpoint.c b/tools/virsh-checkpoint.c
index 853fe05fc4..821212f86b 100644
--- a/tools/virsh-checkpoint.c
+++ b/tools/virsh-checkpoint.c
@@ -235,7 +235,7 @@ cmdCheckpointCreateAs(vshControl *ctl,
 char *buffer = NULL;
 const char *name = NULL;
 const char *desc = NULL;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 unsigned int flags = 0;
 const vshCmdOpt *opt = NULL;
 
@@ -278,7 +278,6 @@ cmdCheckpointCreateAs(vshControl *ctl,
 ret = virshCheckpointCreate(ctl, dom, buffer, flags, NULL);
 
  cleanup:
-virBufferFreeAndReset();
 VIR_FREE(buffer);
 virshDomainFree(dom);
 
diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 9b8c69fa9d..d8333a2f44 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -2413,7 +2413,7 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd)
 }
 
 for (j = 0; j < iface->naddrs; j++) {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
 switch (iface->addrs[j].type) {
 case VIR_IP_ADDR_TYPE_IPV4:
@@ -2442,7 +2442,6 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd)
 vshPrint(ctl, " %-10s %-17s%s\n",
  "-", "-", ip_addr_str);
 
-virBufferFreeAndReset();
 VIR_FREE(ip_addr_str);
 }
 }
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 085b88b097..f0f3456b77 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -575,7 +575,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
 int ret;
 unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
 const char *stype = NULL;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 char *xml = NULL;
 struct stat st;
 bool current = vshCommandOptBool(cmd, "current");
@@ -778,7 +778,6 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
  cleanup:
 VIR_FREE(xml);
 virshDomainFree(dom);
-virBufferFreeAndReset();
 return functionReturn;
 }
 
@@ -905,7 +904,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
 virDomainNetType typ;
 int ret;
 bool functionReturn = false;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 char *xml = NULL;
 unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
 bool current = vshCommandOptBool(cmd, "current");
@@ -1091,7 +1090,6 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
  cleanup:
 VIR_FREE(xml);
 virshDomainFree(dom);
-virBufferFreeAndReset();
 return functionReturn;
 }
 
@@ -2412,7 +2410,7 @@ cmdBlockcopy(vshControl *ctl, const vshCmd *cmd)
 }
 
 if (!xmlstr) {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 virBufferAsprintf(, "\n",
   blockdev ? "block" : "file");
 virBufferAdjustIndent(, 2);
@@ -8504,7 +8502,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd)
 char *tmp = NULL;
 char *tmpstr;
 const vshCmdOpt *opt = NULL;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 bool ret = false;
 unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
 
@@ -9642,7 +9640,7 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)
 g_autoptr(virJSONValue) resultjson = NULL;
 unsigned int flags = 0;
 const vshCmdOpt *opt = NULL;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 bool pretty = vshCommandOptBool(cmd, "pretty");
 bool returnval = vshCommandOptBool(cmd, "return-value");
 virJSONValuePtr formatjson;
@@ -9956,7 +9954,7 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd)
 int judge = 0;
 unsigned int flags = 0;
 const vshCmdOpt *opt = NULL;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 virJSONValuePtr pretty = NULL;
 
 dom = virshCommandOptDomain(ctl, cmd, NULL);
@@ -11506,7 +11504,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
 xmlDocPtr xml = NULL;
 xmlXPathContextPtr ctxt = NULL;
 virDomainPtr dom;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 bool ret = false;
 char *xpath = NULL;

[PATCH 15/32] use g_auto() for all remaining non-g_auto() virBuffers

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 src/hypervisor/domain_driver.c | 7 +++
 src/locking/lock_driver_sanlock.c  | 2 +-
 src/node_device/node_device_udev.c | 2 +-
 src/openvz/openvz_driver.c | 5 ++---
 src/security/virt-aa-helper.c  | 4 ++--
 src/storage/storage_backend_rbd.c  | 7 ++-
 src/storage/storage_util.c | 9 -
 src/vmx/vmx.c  | 5 +
 src/vz/vz_driver.c | 4 ++--
 9 files changed, 18 insertions(+), 27 deletions(-)

diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c
index 31821fc712..f5f0f6e2e9 100644
--- a/src/hypervisor/domain_driver.c
+++ b/src/hypervisor/domain_driver.c
@@ -86,7 +86,7 @@ virDomainDriverGenerateMachineName(const char *drivername,
const char *name,
bool privileged)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
 if (root) {
 g_autofree char *hash = NULL;
@@ -100,10 +100,9 @@ virDomainDriverGenerateMachineName(const char *drivername,
 if (!privileged) {
 
 g_autofree char *username = NULL;
-if (!(username = virGetUserName(geteuid( {
-virBufferFreeAndReset();
+if (!(username = virGetUserName(geteuid(
 return NULL;
-}
+
 virBufferAsprintf(, "%s-", username);
 }
 }
diff --git a/src/locking/lock_driver_sanlock.c 
b/src/locking/lock_driver_sanlock.c
index 4ebe98e86d..23711a75cb 100644
--- a/src/locking/lock_driver_sanlock.c
+++ b/src/locking/lock_driver_sanlock.c
@@ -825,7 +825,7 @@ virLockManagerSanlockRegisterKillscript(int sock,
 const char *uuidstr,
 virDomainLockFailureAction action)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 char *path;
 char *args = NULL;
 int ret = -1;
diff --git a/src/node_device/node_device_udev.c 
b/src/node_device/node_device_udev.c
index cec99cb898..e389b56302 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -294,7 +294,7 @@ udevGenerateDeviceName(struct udev_device *device,
const char *s)
 {
 size_t i;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
 virBufferAsprintf(, "%s_%s",
   udev_device_get_subsystem(device),
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index 79a100c343..71e270ea09 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -704,7 +704,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char 
*vpsid,
 if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||
 (net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
  net->guestIP.nips == 0)) {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer)buf = VIR_BUFFER_INITIALIZER;
 int veid = openvzGetVEID(vpsid);
 
 /* if net is ethernet and the user has specified guest interface name,
@@ -782,7 +782,7 @@ openvzDomainSetNetworkConfig(virConnectPtr conn,
  virDomainDefPtr def)
 {
 size_t i;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 char *param;
 int first = 1;
 struct openvz_driver *driver =  conn->privateData;
@@ -819,7 +819,6 @@ openvzDomainSetNetworkConfig(virConnectPtr conn,
 return 0;
 
  exit:
-virBufferFreeAndReset();
 return -1;
 }
 
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index 08eb162b8c..dadb9d1614 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -907,7 +907,7 @@ storage_source_add_files(virStorageSourcePtr src,
 static int
 get_files(vahControl * ctl)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 int rc = -1;
 size_t i;
 char *uuid;
@@ -1448,7 +1448,6 @@ int
 main(int argc, char **argv)
 {
 vahControl _ctl, *ctl = &_ctl;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
 int rc = -1;
 char *profile = NULL;
 char *include_file = NULL;
@@ -1496,6 +1495,7 @@ main(int argc, char **argv)
 }
 } else if (ctl->cmd == 'c' || ctl->cmd == 'r') {
 char *included_files = NULL;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
 if (ctl->cmd == 'c' && virFileExists(profile))
 vah_error(ctl, 1, _("profile exists"));
diff --git a/src/storage/storage_backend_rbd.c 
b/src/storage/storage_backend_rbd.c
index f0b7653736..08dc5a19dc 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -190,7 +190,7 @@ 
virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
 unsigned char *secret_value = NULL;
 size_t secret_value_size 

[PATCH 27/32] lxc: eliminate unnecessary labels

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 src/lxc/lxc_controller.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 01cdeb29db..ae6b737b60 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -1380,13 +1380,12 @@ virLXCControllerSetupUsernsMap(virDomainIdMapEntryPtr 
map,
 {
 g_auto(virBuffer) map_value = VIR_BUFFER_INITIALIZER;
 size_t i;
-int ret = -1;
 
 /* The kernel supports up to 340 lines in /proc//{g,u}id_map */
 if (num > 340) {
 virReportError(VIR_ERR_INVALID_ARG, "%s",
_("Too many id mappings defined."));
-goto cleanup;
+return -1;
 }
 
 for (i = 0; i < num; i++)
@@ -1397,12 +1396,10 @@ virLXCControllerSetupUsernsMap(virDomainIdMapEntryPtr 
map,
 
 if (virFileWriteStr(path, virBufferCurrentContent(_value), 0) < 0) {
 virReportSystemError(errno, _("unable write to %s"), path);
-goto cleanup;
+return -1;
 }
 
-ret = 0;
- cleanup:
-return ret;
+return 0;
 }
 
 /**
-- 
2.25.4



[PATCH 06/32] qemu: use g_auto() for all virBuffers

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 src/qemu/qemu_agent.c| 2 +-
 src/qemu/qemu_block.c| 2 +-
 src/qemu/qemu_capabilities.c | 2 +-
 src/qemu/qemu_command.c  | 4 ++--
 src/qemu/qemu_dbus.c | 2 +-
 src/qemu/qemu_domain.c   | 4 ++--
 src/qemu/qemu_driver.c   | 5 ++---
 src/qemu/qemu_migration.c| 2 +-
 src/qemu/qemu_migration_cookie.c | 6 ++
 src/qemu/qemu_monitor.c  | 2 +-
 10 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 6fa48c06e3..37b5451e33 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -155,7 +155,7 @@ static char *
 qemuAgentEscapeNonPrintable(const char *text)
 {
 size_t i;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 for (i = 0; text[i] != '\0'; i++) {
 if (text[i] == '\\')
 virBufferAddLit(, "");
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index b00694c96f..a727366373 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -3271,7 +3271,7 @@ qemuBlockStorageSourceNeedsStorageSliceLayer(const 
virStorageSource *src)
 char *
 qemuBlockStorageSourceGetCookieString(virStorageSourcePtr src)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 size_t i;
 
 for (i = 0; i < src->ncookies; i++) {
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index efc42aac17..0cf9165ecc 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -4602,7 +4602,7 @@ virQEMUCapsFormatSEVInfo(virQEMUCapsPtr qemuCaps, 
virBufferPtr buf)
 char *
 virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 size_t i;
 
 virBufferAddLit(, "\n");
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 6e7fd59561..789c5b8f56 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5477,7 +5477,7 @@ qemuBuildRNGCommandLine(virLogManagerPtr logManager,
 
 for (i = 0; i < def->nrngs; i++) {
 g_autoptr(virJSONValue) props = NULL;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 virDomainRNGDefPtr rng = def->rngs[i];
 g_autofree char *chardev = NULL;
 g_autofree char *devstr = NULL;
@@ -6155,7 +6155,7 @@ qemuBuildBootCommandLine(virCommandPtr cmd,
 if (def->os.dtb)
 virCommandAddArgList(cmd, "-dtb", def->os.dtb, NULL);
 if (def->os.slic_table) {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 virCommandAddArg(cmd, "-acpitable");
 virBufferAddLit(, "sig=SLIC,file=");
 virQEMUBuildBufferEscapeComma(, def->os.slic_table);
diff --git a/src/qemu/qemu_dbus.c b/src/qemu/qemu_dbus.c
index 53f6c45986..51f6c94e3e 100644
--- a/src/qemu/qemu_dbus.c
+++ b/src/qemu/qemu_dbus.c
@@ -100,7 +100,7 @@ qemuDBusGetAddress(virQEMUDriverPtr driver,
 static int
 qemuDBusWriteConfig(const char *filename, const char *path)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 g_autofree char *config = NULL;
 
 virBufferAddLit(, "deviceType != VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL ||
@@ -6001,7 +6001,7 @@ qemuDomainDefFormatXMLInternal(virQEMUDriverPtr driver,
virCPUDefPtr origCPU,
unsigned int flags)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
 if (qemuDomainDefFormatBufInternal(driver, qemuCaps, def, origCPU, flags, 
) < 0)
 return NULL;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a5b38b3d24..247baa9b8d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1272,7 +1272,7 @@ static char *
 qemuConnectGetSysinfo(virConnectPtr conn, unsigned int flags)
 {
 virQEMUDriverPtr driver = conn->privateData;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
 virCheckFlags(0, NULL);
 
@@ -14398,7 +14398,7 @@ 
qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver,
 virBitmapPtr created = NULL;
 g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
 int ret = -1;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 virDomainSnapshotDefPtr snapdef = virDomainSnapshotObjGetDef(snap);
 
 if (!(qemuImgPath = qemuFindQemuImgBinary(driver)))
@@ -14485,7 +14485,6 @@ 
qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver,
 ret = 0;
 
  cleanup:
-virBufferFreeAndReset();
 virCommandFree(cmd);
 
 /* unlink images if creation has failed */
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c

[PATCH 00/32] always use g_auto() for virBuffer and virFirewall objects

2020-07-05 Thread Laine Stump
Like most other things I do, this started as a distraction from
something else. I noticed that a function that took a virBufferPtr as
an argument was clearing that buffer on error, but most (but *not
all*) of its callers (which were the creators/owners of said
virBuffer) were already clearing the buffer object on error
anyway. Here's the original patch resulting from my seeing this in one
place:

  https://www.redhat.com/archives/libvir-list/2020-June/msg01163.html

In the example I saw, eliminating the extra clearing of the virBuffer
in the subordinate function would simplify the error-cleanup code for
that function, but it turned out the calling function *wasn't*
clearing the virBuffer when an error occurred.

Looking further, I saw this same pattern occurred in other places in
the code - a function would create a new buffer (with "virBuffer buf =
VIR_BUFFER_INITIALIZER;"), and clear/free that buffer when it was
finished *unless there was an error*, in which case some functions
would properly clear the buffer, and some would just return, I guess
assuming the caller that generated the error had cleared the buffer.

This not only makes the error cleanup logic in subordinate functions
messier, it seems philosophically wrong to me, it also sounds like a
memory leak just waiting to happen.

So I decided that the way it should more properly work is this:

1) all virBuffers should be declared with g_auto(virBuffer), so that
they are automatically cleared (with virBufferFreeAndReset()) when
that toplevel function declaring/initializing the buffer returns to
its caller.

2) subordinate functions called with the virBuffer object as an arg
should just leave the buffer in whatever state it was when the error
occurred. Since those functions don't use the virBuffer after the
error happens, and the caller doesn't look at anything in the
virBuffer to determine an error has occurred, this is completely safe.

(obvious exceptions to (2) are of course those functions whose main
intent is in fact to consume the virBuffer,
e.g. virBufferContentAndReset(), and virCommandAddArgBuffer())


Patches 01 - 15 handle part (1) - *all* declarations of virBuffer as
an automatic are changed to g_auto(virBuffer), and any
virBufferFreeAndReset() calls in those same functions are removed.

(I have it split into so many patches because virBuffer is used all
over the place, and I figured it would make it easier to backport just
one part of the entire set if needed when backported some unrelated
bugfix that only touched one of the many directories represented
here. I would happily squash together any group of patches anyone
wants, however).

Patches 16 and 17 fix a couple "one-off" anomolies in the code related
to virBuffers.

Patch 18 then takes care of point (2) above, by removing any
extraneous virBufferFreeAndReset() calls in subordinate functions that
are no longer necessary due to the guarantee that the toplevel will
cleanup after error.

Patches 19-30 just eliminate any labels (and associated "ret"
variables and "goto's) that have been rendered pointless by removal of
virBufferFreeAndReset().

Finally Patches 31 and 32 convert all usages of virFirewall to use
g_autoptr(). They are included in this same set because virFirewall
objects are often declared right next to virBuffer objects, so doing
those patches in a different order would have caused merge conflicts..

NB: In many of the cases where "virBuffer" was changed to
"g_auto(virBuffer)", it doesn't actually eliminate any code from the
function, due to the function *always* calling
virBufferContentAndReset() anyway. I considered not changing those
cases, but in the ended decided it was better to add g_auto() even in
those cases for two reasons:

1) consistency makes verification easier, and means someone a year
from now won't come up with the same idea and waste time verifying all
those cases of virBuffer don't need g_auto().

2) if those functions ever change to have an alternate return that
doesn't explicitly call virBufferContentAndReset(), they will still be
safe.

3) the extra overhead is very minimal; a small price to pay for (1)
and (2)


NB2: these patches aren't just academic code churning; they have fixed
some actual (well, theoretically actual) memory leaks, I just haven't
taken the time to try and track all of them down or document them,
because they only occur in error cases which will likely never
happen. One example from my notes:

  virStoragePoolSaveState calls
virStoragePoolDefFormatBuf which calls
  virStoragePoolSourceFormat, which errors, returns
virStoragePoolDefFormatBuf, returns
  virStoragePoolSaveState returns without freeing virBuffer

Laine Stump (32):
  bhyve: use g_auto() for all virBuffers
  esx: use g_auto() for all virBuffers
  hyperv: use g_auto() for all virBuffers
  libxl: use g_auto() for all virBuffers
  lxc: use g_auto() for all virBuffers
  qemu: use g_auto() for all virBuffers
  tests: use g_auto for all virBuffers
  tools: use 

[PATCH 05/32] lxc: use g_auto() for all virBuffers

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 src/lxc/lxc_container.c  | 4 +---
 src/lxc/lxc_controller.c | 3 +--
 src/lxc/lxc_driver.c | 2 +-
 src/lxc/lxc_fuse.c   | 3 +--
 4 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index c22b7b0709..24a3b6d626 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -174,7 +174,7 @@ static virCommandPtr 
lxcContainerBuildInitCmd(virDomainDefPtr vmDef,
 {
 char uuidstr[VIR_UUID_STRING_BUFLEN];
 virCommandPtr cmd;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 size_t i;
 
 /* 'container_ptys' must exclude the PTY associated with
@@ -185,7 +185,6 @@ static virCommandPtr 
lxcContainerBuildInitCmd(virDomainDefPtr vmDef,
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("Expected a /dev path for '%s'"),
ttyPaths[i]);
-virBufferFreeAndReset();
 return NULL;
 }
 virBufferAdd(, ttyPaths[i] + 5, -1);
@@ -219,7 +218,6 @@ static virCommandPtr 
lxcContainerBuildInitCmd(virDomainDefPtr vmDef,
   vmDef->os.initenv[i]->value);
 }
 
-virBufferFreeAndReset();
 return cmd;
 }
 
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 89f9773b2c..01cdeb29db 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -1378,7 +1378,7 @@ virLXCControllerSetupUsernsMap(virDomainIdMapEntryPtr map,
int num,
char *path)
 {
-virBuffer map_value = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) map_value = VIR_BUFFER_INITIALIZER;
 size_t i;
 int ret = -1;
 
@@ -1402,7 +1402,6 @@ virLXCControllerSetupUsernsMap(virDomainIdMapEntryPtr map,
 
 ret = 0;
  cleanup:
-virBufferFreeAndReset(_value);
 return ret;
 }
 
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 46a182be45..1cdd6ee455 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -4618,7 +4618,7 @@ static char *
 lxcConnectGetSysinfo(virConnectPtr conn, unsigned int flags)
 {
 virLXCDriverPtr driver = conn->privateData;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
 virCheckFlags(0, NULL);
 
diff --git a/src/lxc/lxc_fuse.c b/src/lxc/lxc_fuse.c
index 146629f67e..6e23361617 100644
--- a/src/lxc/lxc_fuse.c
+++ b/src/lxc/lxc_fuse.c
@@ -124,7 +124,7 @@ static int lxcProcReadMeminfo(char *hostpath, 
virDomainDefPtr def,
 g_autofree char *line = NULL;
 size_t n;
 struct virLXCMeminfo meminfo;
-virBuffer buffer = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
 virBufferPtr new_meminfo = 
 
 if (virLXCCgroupGetMeminfo() < 0) {
@@ -223,7 +223,6 @@ static int lxcProcReadMeminfo(char *hostpath, 
virDomainDefPtr def,
 memcpy(buf, virBufferCurrentContent(new_meminfo), res);
 
  cleanup:
-virBufferFreeAndReset(new_meminfo);
 VIR_FORCE_FCLOSE(fd);
 return res;
 }
-- 
2.25.4



[PATCH 01/32] bhyve: use g_auto() for all virBuffers

2020-07-05 Thread Laine Stump
In most cases this eliminates one or more calls to
virBufferClearAndReset(), but even when it doesn't it's better because:

1) it makes the code more consistent, making it more likely that new 
contributors who are "learning by example" will to the right thing.

2) it protects against future modifications that might have otherwise
needed to add a virBufferClearAndReset()

3) Currently some functions don't call virBufferClearAndReset() only
because they're relying on some subordinate function to call it for
them (e.g. bhyveConnectGetSysinfo() in this patch relies on
virSysinfoFormat() to clear out the buffer when there is an error). I
think this is sloppy behavior, and that the toplevel function that
defines and initializes the buffer should be the function clearing it
at the end.

Signed-off-by: Laine Stump 
---
 src/bhyve/bhyve_command.c | 15 ++-
 src/bhyve/bhyve_driver.c  |  4 ++--
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index 5b1d80083a..9649c2d2a2 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -166,14 +166,15 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *def,
bhyveConnPtr driver,
virCommandPtr cmd)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
-virBuffer device = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 const char *disk_source;
 size_t i;
 int ret = -1;
 
 for (i = 0; i < def->ndisks; i++) {
+g_auto(virBuffer) device = VIR_BUFFER_INITIALIZER;
 virDomainDiskDefPtr disk = def->disks[i];
+
 if (disk->bus != VIR_DOMAIN_DISK_BUS_SATA)
 continue;
 
@@ -221,7 +222,6 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *def,
 goto error;
 }
 virBufferAddBuffer(, );
-virBufferFreeAndReset();
 }
 
 virCommandAddArg(cmd, "-s");
@@ -231,7 +231,6 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *def,
 
 ret = 0;
  error:
-virBufferFreeAndReset();
 return ret;
 }
 
@@ -378,7 +377,7 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
  virCommandPtr cmd,
  bool dryRun)
 {
-virBuffer opt = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) opt = VIR_BUFFER_INITIALIZER;
 virDomainGraphicsListenDefPtr glisten = NULL;
 bool escapeAddr;
 unsigned short port;
@@ -478,7 +477,6 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
 return 0;
 
  error:
-virBufferFreeAndReset();
 return -1;
 }
 
@@ -765,7 +763,6 @@ virBhyveProcessBuildGrubbhyveCmd(virDomainDefPtr def,
  char **devicesmap_out)
 {
 virDomainDiskDefPtr hdd, cd, userdef, diskdef;
-virBuffer devicemap;
 virCommandPtr cmd;
 unsigned int best_idx = UINT_MAX;
 size_t i;
@@ -773,8 +770,6 @@ virBhyveProcessBuildGrubbhyveCmd(virDomainDefPtr def,
 if (def->os.bootloaderArgs != NULL)
 return virBhyveProcessBuildCustomLoaderCmd(def);
 
-devicemap = (virBuffer)VIR_BUFFER_INITIALIZER;
-
 /* Search disk list for CD or HDD device. We'll respect  if
  * present and otherwise pick the first CD or failing that HDD we come
  * across. */
@@ -809,6 +804,8 @@ virBhyveProcessBuildGrubbhyveCmd(virDomainDefPtr def,
 VIR_DEBUG("grub-bhyve with default arguments");
 
 if (devicesmap_out != NULL) {
+g_auto(virBuffer) devicemap = VIR_BUFFER_INITIALIZER;
+
 /* Grub device.map (just for boot) */
 if (userdef != NULL) {
 virBhyveFormatGrubDevice(, userdef);
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index b6204c7fb9..daa20bad40 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -244,7 +244,7 @@ static char *
 bhyveConnectGetSysinfo(virConnectPtr conn, unsigned int flags)
 {
 bhyveConnPtr privconn = conn->privateData;
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
 virCheckFlags(0, NULL);
 
@@ -678,7 +678,7 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn,
   const char *xmlData,
   unsigned int flags)
 {
-virBuffer buf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 bhyveConnPtr privconn = conn->privateData;
 virDomainDefPtr def = NULL;
 virCommandPtr cmd = NULL, loadcmd = NULL;
-- 
2.25.4



[PATCH 02/32] esx: use g_auto() for all virBuffers

2020-07-05 Thread Laine Stump
Signed-off-by: Laine Stump 
---
 src/esx/esx_driver.c | 19 +--
 src/esx/esx_util.c   |  4 ++--
 src/esx/esx_vi.c | 19 +--
 src/esx/esx_vi_methods.c |  6 +-
 4 files changed, 13 insertions(+), 35 deletions(-)

diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 0ede65279a..3fb7a3b62c 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -275,7 +275,7 @@ esxFormatVMXFileName(const char *fileName, void *opaque)
 esxVI_ObjectContent *datastore = NULL;
 esxVI_DatastoreHostMount *hostMount = NULL;
 char separator = '/';
-virBuffer buffer = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
 char *tmp;
 size_t length;
 
@@ -336,10 +336,8 @@ esxFormatVMXFileName(const char *fileName, void *opaque)
 success = true;
 
  cleanup:
-if (! success) {
-virBufferFreeAndReset();
+if (! success)
 VIR_FREE(result);
-}
 
 VIR_FREE(datastoreName);
 VIR_FREE(directoryAndFileName);
@@ -2359,7 +2357,7 @@ esxDomainScreenshot(virDomainPtr domain, virStreamPtr 
stream,
 esxVI_String *propertyNameList = NULL;
 esxVI_ObjectContent *virtualMachine = NULL;
 esxVI_VirtualMachinePowerState powerState;
-virBuffer buffer = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
 char *url = NULL;
 
 virCheckFlags(0, NULL);
@@ -2413,7 +2411,6 @@ esxDomainScreenshot(virDomainPtr domain, virStreamPtr 
stream,
 }
 
  cleanup:
-virBufferFreeAndReset();
 
 esxVI_String_Free();
 esxVI_ObjectContent_Free();
@@ -2579,7 +2576,7 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int 
flags)
 char *datastoreName = NULL;
 char *directoryName = NULL;
 char *directoryAndFileName = NULL;
-virBuffer buffer = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
 char *url = NULL;
 char *vmx = NULL;
 virVMXContext ctx;
@@ -2653,9 +2650,6 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int 
flags)
 }
 
  cleanup:
-if (!url)
-virBufferFreeAndReset();
-
 esxVI_String_Free();
 esxVI_ObjectContent_Free();
 VIR_FREE(moref);
@@ -2936,7 +2930,7 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char 
*xml, unsigned int flags)
 char *datastoreName = NULL;
 char *directoryName = NULL;
 char *escapedName = NULL;
-virBuffer buffer = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
 char *url = NULL;
 char *datastoreRelatedPath = NULL;
 esxVI_String *propertyNameList = NULL;
@@ -3124,9 +3118,6 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char 
*xml, unsigned int flags)
 /* FIXME: Add proper rollback in case of an error */
 
  cleanup:
-if (!url)
-virBufferFreeAndReset();
-
 virDomainDefFree(def);
 VIR_FREE(vmx);
 VIR_FREE(datastoreName);
diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c
index 89d136248f..11f43acc19 100644
--- a/src/esx/esx_util.c
+++ b/src/esx/esx_util.c
@@ -357,7 +357,7 @@ esxUtil_EscapeBase64(const char *string)
 static const char *base64 =
   "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
 
-virBuffer buffer = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
 const char *tmp1 = string;
 size_t length;
 unsigned char c1, c2, c3;
@@ -456,7 +456,7 @@ esxUtil_EscapeDatastoreItem(const char *string)
 char *
 esxUtil_EscapeForXml(const char *string)
 {
-virBuffer buffer = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
 
 virBufferEscapeString(, "%s", string);
 
diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index 16690edfbe..d48a24e9d3 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -370,7 +370,7 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char 
**content,
 unsigned long long offset, unsigned long long *length)
 {
 char *range = NULL;
-virBuffer buffer = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
 int responseCode = 0;
 
 ESX_VI_CHECK_ARG_LIST(content);
@@ -421,10 +421,8 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url, 
char **content,
  cleanup:
 VIR_FREE(range);
 
-if (!(*content)) {
-virBufferFreeAndReset();
+if (!(*content))
 return -1;
-}
 
 return 0;
 }
@@ -1025,7 +1023,7 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context 
*ctx, const char *path)
 char *saveptr = NULL;
 char *previousItem = NULL;
 char *item = NULL;
-virBuffer buffer = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) buffer = VIR_BUFFER_INITIALIZER;
 esxVI_ManagedObjectReference *root = NULL;
 esxVI_Folder *folder = NULL;
 
@@ -1184,9 +1182,6 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context 
*ctx, const char *path)
 result = 0;
 
  cleanup:
-if (result < 0)
-

[RFC PATCH 1/2] hw/sd/ssi-sd: Deprecate the SPI to SD card 'adapter'

2020-07-05 Thread Philippe Mathieu-Daudé
This device duplicate the SPI mode of the sd-card device. The
SPI protocol is better handler in the sd-card, however as the
TYPE_SSI_SLAVE is not an interface, the sd-card can not implement
it easily to be pluggable on a SPI bus. Meanwhile the ssi-sd
device acts as a bridge, but is bitroting. Deprecate it.

Signed-off-by: Philippe Mathieu-Daudé 
---
 docs/system/deprecated.rst | 5 +
 1 file changed, 5 insertions(+)

diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
index 47f84be8e0..5e67d7f3e0 100644
--- a/docs/system/deprecated.rst
+++ b/docs/system/deprecated.rst
@@ -343,6 +343,11 @@ The 'ide-drive' device is deprecated. Users should use 
'ide-hd' or
 The 'scsi-disk' device is deprecated. Users should use 'scsi-hd' or
 'scsi-cd' as appropriate to get a SCSI hard disk or CD-ROM as needed.
 
+``ssi-sd`` (since 5.1)
+'
+
+The 'ssi-sd' (SSI to SD card adapter) device is deprecated.
+
 System emulator machines
 
 
-- 
2.21.3



[RFC PATCH 2/2] hw/sd/sdcard: Deprecate the SPI mode

2020-07-05 Thread Philippe Mathieu-Daudé
SD cards be used with SPI, SD or MMC protocol.

Unfortunately, maintaining the SPI protocol make improving the
MMC mode very difficult. As of 2020 users are more interested
in using cards with the MMC protocol.

Signed-off-by: Philippe Mathieu-Daudé 
---
 docs/system/deprecated.rst | 5 +
 1 file changed, 5 insertions(+)

diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
index 5e67d7f3e0..01dca3d038 100644
--- a/docs/system/deprecated.rst
+++ b/docs/system/deprecated.rst
@@ -384,6 +384,11 @@ full SCSI support.  Use virtio-scsi instead when SCSI 
passthrough is required.
 Note this also applies to ``-device virtio-blk-pci,scsi=on|off``, which is an
 alias.
 
+``-device sd-card,spi=on`` (since 5.1)
+^^
+
+The SPI mode of the 'sd-card' device is deprecated.
+
 Block device options
 
 
-- 
2.21.3



[RFC PATCH 0/2] hw/sd: Deprecate the SPI mode and the SPI to SD adapter

2020-07-05 Thread Philippe Mathieu-Daudé
I tried to maintain the SPI mode because it is useful in
tiny embedded devices, and thought it would be helpful for
the AVR MCUs.
As AVR was blocked, I thought it was wise to deprecate the
SPI mode as users are interested in the faster MMC mode.
Today Thomas surprised me by posting an update of it!
https://www.mail-archive.com/qemu-devel@nongnu.org/msg720089.html

I'm still posting this as RFC to discuss, but I'm reconsiderating
keeping this mode a bit more.

Philippe Mathieu-Daudé (2):
  hw/sd/ssi-sd: Deprecate the SPI to SD card 'adapter'
  hw/sd/sdcard: Deprecate the SPI mode

 docs/system/deprecated.rst | 10 ++
 1 file changed, 10 insertions(+)

-- 
2.21.3



libvirt-6.5.0 breaks host passthrough migration

2020-07-05 Thread Mark Mielke
Hi all:

With 6.4.0, live migration was working fine with Qemu 5.0. After trying out
6.5.0, migration broke with the following error:

libvirt.libvirtError: internal error: unable to execute QEMU command
'migrate': State blocked by non-migratable CPU device (invtsc flag)


I believe I traced the error back to this commit:

commit 201bd5db639c063862b0c1b1abfab9a9a7c92591
Author: Jiri Denemark 
Date:   Tue Jun 2 15:34:07 2020 +0200

qemu: Fill default value in //cpu/@migratable attribute

Before QEMU introduced migratable CPU property, "-cpu host" included all
features that could be enabled on the host, even those which would block
migration. In other words, the default was equivalent to migratable=off.
When the migratable property was introduced, the default changed to
migratable=on. Let's record the default in domain XML.

Signed-off-by: Jiri Denemark 
Reviewed-by: Michal Privoznik 


Before this change, qemu was still being launched with "-cpu host", which
for any somewhat modern version of qemu, defaults to migratable=on. The
above comment acknowledges this, however, the implementation chooses the
pessimistic and ancient (and no longer applicable!) value of migratable=off:

+if (qemuCaps &&
+def->cpu->mode == VIR_CPU_MODE_HOST_PASSTHROUGH &&
+!def->cpu->migratable) {
+if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_MIGRATABLE))
+def->cpu->migratable = VIR_TRISTATE_SWITCH_ON;

*+else if (ARCH_IS_X86(def->os.arch))+
 def->cpu->migratable = VIR_TRISTATE_SWITCH_OFF;*
+}

Consequently, after live migration qemu is started with "-cpu
host,migratable=off" and this enables invtsc, which then prevents migration
as when invtsc is enabled it activates a migration blocker.

I think this patch should be reverted. If the migratable state cannot be
determined, then it should not be guessed. It should be left as "absent",
just as it has been working fine prior to libvirt-6.5.0. Qemu still knows
what flags are enabled, so Qemu remains the authority on what can be safely
migrated, and what cannot be. I reverted this patch and re-built, and this
seems to clear the migration problems. If the user chooses to explicitly
specify migratable=yes or migratable=no, then this value should be
preserved and passed through to the Qemu "-cpu host,XXX" option.

I think it is not a requirement for "migratable=XXX" to be explicit in
libvirt. However, if there is some reason I am unaware of, and it is
important for libvirt to know, then I think it is important for libvirt to
find out the authoritative state rather than guessing.

Please start by reverting this patch, so that other people do not get
broken in the same way, and I don't need to carry my revert patch.
Personally, I think this is important enough to build a 6.5.1. However,
since I have a local revert patch in place, I am not waiting for this.

Thanks!

-- 
Mark Mielke