Commit Graph

69 Commits

Author SHA1 Message Date
Peter Krempa
49530d5277 qemuMigrationCookieXMLParse: Avoid VIR_FREE when parsing lockstate
Restructure the control-flow a bit using an temporary variable to avoid
the need to use VIR_FREE.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-10-05 15:58:53 +02:00
Peter Krempa
78d330bde1 qemuMigrationCookieAddCaps: Use 'g_new0' instead of VIR_ALLOC
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-10-05 15:58:53 +02:00
Peter Krempa
83434e5acd qemuMigrationCookieCapsXMLParse: Refactor memory handling
Use modern allocators, automatic memory feeing, and decrease the scope
of some variables to remove the 'cleanup' label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-10-05 15:58:53 +02:00
Peter Krempa
9d7ca30ece qemuMigrationCookieNBDXMLParse: Refactor memory handling
Use modern allocators, automatic memory feeing, and decrease the scope
of some variables to remove the 'error' and 'cleanup' labels.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-10-05 15:58:53 +02:00
Peter Krempa
abfb033ddb qemuMigrationCookieNetworkXMLParse: Refactor memory handling
Use modern allocators, automatic memory feeing, and decrease the scope
of some variables to remove the 'error' label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-10-05 15:58:53 +02:00
Peter Krempa
7dce147544 qemuMigrationCookieXMLFormat: Refactor memory handling
Use automatic memory freeing to get rid of the 'error' label. Since the
'tmp' variable was used only in one instance, rename it appropriately.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-10-05 15:58:53 +02:00
Peter Krempa
dc03248181 qemuMigrationCookieNetworkAlloc: Refactor memory handling
Use modern memory handling approach to simplify the code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-10-05 15:58:53 +02:00
Peter Krempa
f3e087ac9c qemuMigrationCookieGraphicsSpiceAlloc: Refactor memory handling
Use modern memory handling approach to simplify the code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-10-05 15:58:53 +02:00
Peter Krempa
85d6d515ed qemu: migration_cookie: Register 'autoptr' functions for internal types
Register the the cleanup functions for 'qemuMigrationCookieGraphics',
'qemuMigrationCookieNetwork', 'qemuMigrationCookieNBD', and
'qemuMigrationCookieCaps'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-10-05 15:58:53 +02:00
Peter Krempa
a09cf33adf qemuDomainExtractTLSSubject: Refactor memory handling
Switch to automatic memory cleaning, use g_new0 for allocation and get
rid of the 'error' label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-10-05 15:58:53 +02:00
Peter Krempa
518be41aaa qemuMigrationCookieXMLFormat: Extract formatting of NBD
Move the code into 'qemuMigrationCookieNBDXMLFormat' and use modern XML
formatting code patterns.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-10-05 15:58:52 +02:00
Peter Krempa
84589ac004 qemuMigrationCookieNetworkXMLFormat: Refactor XML formatting
Use 'virXMLFormatElement' both for formating the whole <network> element
but also for formatting the <interface> subelements. This alows to
remove the crazy logic which was determining which element was already
formatted.

Additional simplification is achieved by switching to skipping the loop
using 'continue' rather than putting everything in a giant block.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-10-05 15:58:52 +02:00
Peter Krempa
592a9a859a qemuMigrationCookieGraphicsXMLFormat: Use 'virXMLFormatElement'
Switch to the two buffer approach to simplify the logic for terminating
the element.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-10-05 15:58:52 +02:00
Peter Krempa
600c1b5202 qemuMigrationCookieXMLParse: Remove 'error' label
Now it only returns -1 so we can do that directly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-10-05 15:58:52 +02:00
Peter Krempa
8c3f86e290 qemuMigrationCookieXMLParse: Remove comment mentioning that error was already set
Most of our functions report errors so there's no need to mention it
here again.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-10-05 15:58:52 +02:00
Peter Krempa
a9b4e523d7 qemuMigrationCookieXMLParse: Decrease scope of 'nodes' and use automatic freeing
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-10-05 15:58:52 +02:00
Peter Krempa
25b944e067 qemuMigrationCookieXMLParse: Check domain element count more defensively
Make sure that 'virXPathNodeSet' returns '1' as the only expected value
rather than relying on the fact that the previous check for the number
of elements ensures success of the subsequent call.

The error message no longer mentions the number of <domain> elements in
the cookie, but this is a very unlikely internal error anyways.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-10-05 15:58:52 +02:00
Peter Krempa
4a7dd2780c qemuMigrationCookieXMLParse: Switch to single-purpose temporary variables
Don't reuse 'tmp' over and over, but switch to single use automaticaly
freed variables instead.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-10-05 15:58:52 +02:00
Peter Krempa
dd6f669d2c qemu: migration_cookie: Extract parsing/validation of mandatory features
Move the code into 'qemuMigrationCookieXMLParseMandatoryFeatures' to
simplify 'qemuMigrationCookieXMLParse'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-10-05 15:58:52 +02:00
Peter Krempa
faa88866f5 Don't check return value of virBitmapNewCopy
The function will not fail any more.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-10-05 15:50:45 +02:00
Peter Krempa
cb6fdb0125 virBitmapNew: Don't check return value
Remove return value check from all callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-10-05 15:38:47 +02:00
Peter Krempa
43f0944f66 qemu: migration: Rename qemuMigrationEatCookie to qemuMigrationCookieParse
Use a more descriptive name and move the verb to the end so that the
functions conform with the naming policy.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-10-01 10:01:05 +02:00
Peter Krempa
5b32815d1a qemuMigrationCookieXMLFormatStr: Remove
There is just one caller, inline the code. This also optimizes the code
as we no longer have to calculate length of the output XML as it's
actually stored in the buffer struct.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-10-01 10:01:05 +02:00
Peter Krempa
775296cbd6 qemuMigrationCookieNew: Export
Allow direct use rather than going through qemuMigrationEatCookie with
NULL/0 arguments.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-10-01 10:01:05 +02:00
Peter Krempa
4aef0fe324 qemuMigrationCookieNew: Refactor allocation and cleanup
Move around some code so that we can get rid of the 'cleanup:' label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-10-01 10:01:05 +02:00
Peter Krempa
6c8b68b312 qemu: migration: Rename qemuMigrationBakeCookie to qemuMigrationCookieFormat
Use a more descriptive name and move the verb to the end so that the
functions conform with the naming policy.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-10-01 10:01:05 +02:00
Michal Privoznik
d92c2bbc65 lib: Prefer g_autoptr() declaration of virQEMUDriverConfigPtr
In the past we had to declare @cfg and then explicitly unref it.
But now, with glib we can use g_autoptr() which will do the unref
automatically and thus is more bulletproof.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2020-09-07 10:47:54 +02:00
Ján Tomko
52cd849e62 VIR_XPATH_NODE_AUTORESTORE: remove semicolon from users
Since the macro no longer includes the 'ignore_value'
statement, stop putting another empty statement after it.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-08-25 19:03:12 +02:00
Daniel Henrique Barboza
c54dba525d qemu_migration_cookie.c: modernize qemuMigrationEatCookie()
Use g_autoptr() and remove the obsolete 'error' label.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-07-13 17:18:07 +02:00
Laine Stump
b8b58e22b9 qemu: use g_auto() for all virBuffers
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-08 16:34:02 -04:00
Peter Krempa
72186f9c8c qemu: Add free and copy function for qemuDomainJobInfo and use it
In order to add a string to qemuDomainJobInfo we must ensure that it's
freed and copied properly. Add helpers to copy and free the structure
and adjust the code to use them properly for the new semantics.

Additionally also allocation is changed to g_new0 as it includes the
type and thus it's very easy to grep for all the allocations of a given
type.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
2020-04-24 08:56:57 +02:00
Michal Privoznik
6799b72d92 qemu: Don't compare local and remote hostnames on migration
Libvirt tries to forbid migration onto the same host and it does
that by checking if local and remote hostnames are the same and
whether local and remote UUIDs are the same. Well, the latter
makes sense but the former doesn't really because libvirtd can be
running inside an UTS namespace and hostnames can appear the same
on both sides of migration. On the other hand, host UUIDs are
unique, so rely on them when trying to prevent migration onto the
same host.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1639596

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2020-03-05 10:01:32 +01:00
Peter Krempa
b9e87908db qemuMigrationCookieAddNBD: Fix filling of 'capacity' when blockdev is used
With -blockdev we must look up via the nodename rather than the 'drive'
alias which is not present any more.

This fixes the pre-creation of storage volumes on migration with
non-shared storage.

https://bugzilla.redhat.com/show_bug.cgi?id=1793263

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-01-31 14:28:29 +01:00
Peter Krempa
d409411213 qemuMigrationCookieAddNBD: Remove 'ret' variable and 'cleanup' label
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-01-31 14:28:29 +01:00
Peter Krempa
45eefb2c78 qemuMigrationCookieAddNBD: Use virHashNew and automatic freeing of virHashTablePtr
Swithc to the helper which doesn't require checking of the return value.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-01-31 14:28:29 +01:00
Peter Krempa
464345e153 qemuMigrationCookieAddNBD: Move monitor call out of the loop
The data is gathered only once so we can move the whole block which
fetches the data out of the loop and get rid of the logic which
prevents multiple calls.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-01-31 14:28:29 +01:00
Peter Krempa
8efeeb59a6 qemuMigrationCookieAddNBD: Use glib memory allocators
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-01-31 14:28:29 +01:00
Peter Krempa
bdff9d4513 qemuMigrationCookieAddNBD: Exit early if there are no disks
Refactor the logic to skip the body of the function if there's nothing
to do.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-01-31 14:28:28 +01:00
Daniel Henrique Barboza
21ad56e932 qemu: remove unneeded labels
Remove unneeded, easy to remove goto labels (cleanup|error|done|...).

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2020-01-07 16:40:41 +01:00
Daniel P. Berrangé
bf9d812956 conf: drop virCapsPtr param from domain parse APIs
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-12-09 10:17:27 +00:00
Laine Stump
fdcd273be2 conf: return a const from virDomainNetGetActualVirtPortProfile
This also isn't required (due to the vportprofile being stored in the
NetDef as a pointer rather than being directly contained), but it
seemed dishonest to not mark it as const (and thus permit users to
modify its contents)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-11-25 15:29:56 -05:00
Jiri Denemark
9cd03f7957 cpu_map: Drop pconfig from Icelake-Server CPU model
The pconfig feature was enabled in QEMU by accident in 3.1.0. All other
newer versions do not support it and it was removed from the
Icelake-Server CPU model in QEMU.

We don't normally change our CPU models even when QEMU does so to avoid
breaking migrations between different versions of libvirt. But we can
safely do so in this specific case. QEMU never supported enabling
pconfig so any domain which was able to start has pconfig disabled.

With a small compatibility hack which explicitly disables pconfig when
CPU model equals Icelake-Server in migratable domain definition, only
one migration scenario stays broken (and there's nothing we can do about
it): from any host to a host with libvirt < 5.10.0 and QEMU > 3.1.0.

https://bugzilla.redhat.com/show_bug.cgi?id=1749672

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2019-11-12 20:14:16 +01:00
Michal Privoznik
d4e5b98330 qemu: Use g_strdup_printf() instead of virAsprintf()
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2019-11-12 16:15:58 +01:00
Peter Krempa
0967708b81 util: buffer: Remove virBufferCheckError
The function now does not return an error so we can drop it fully.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-10-24 19:35:34 +02:00
Ján Tomko
ce36e33c10 qemu: use g_strdup instead of VIR_STRDUP
Replace all occurrences of
  if (VIR_STRDUP(a, b) < 0)
     /* effectively dead code */
with:
  a = g_strdup(b);

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-21 12:51:57 +02:00
Ján Tomko
72a1bb8e4c qemu: use g_steal_pointer instead of VIR_STEAL_PTR
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-16 15:59:42 +02:00
Ján Tomko
ada7596b92 qemu: use G_GNUC_UNUSED
Use G_GNUC_UNUSED from GLib instead of ATTRIBUTE_UNUSED.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-15 11:25:24 +02:00
Jiri Denemark
69b1ecde25 qemu: Fix crash on incoming migration
In the first stage of incoming migration (qemuMigrationDstPrepareAny) we
call qemuMigrationEatCookie when there's no vm object created yet and
thus we don't have any private data to pass.

Broken by me in commit v5.6.0-109-gbf15b145ec.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2019-08-14 09:28:22 +02:00
Jiri Denemark
bf15b145ec qemu: Pass qemuCaps to qemuMigrationCookieXMLParse
Since qemuDomainDefPostParse callback requires qemuCaps, we need to make
sure it gets the capabilities stored in the domain's private data if the
domain is running. Passing NULL may cause QEMU capabilities probing to
be triggered in case QEMU binary changed in the meantime. When this
happens while a running domain object is locked, QMP event delivered to
the domain before QEMU capabilities probing finishes will deadlock the
event loop.

This patch fixes all paths leading to qemuMigrationCookieXMLParse.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-08-09 13:55:54 +02:00
Jiri Denemark
900c595249 qemu: Pass qemuCaps to qemuDomainDefFormatBufInternal
Since qemuDomainDefPostParse callback requires qemuCaps, we need to make
sure it gets the capabilities stored in the domain's private data if the
domain is running. Passing NULL may cause QEMU capabilities probing to
be triggered in case QEMU binary changed in the meantime. When this
happens while a running domain object is locked, QMP event delivered to
the domain before QEMU capabilities probing finishes will deadlock the
event loop.

This patch fixes all paths leading to qemuDomainDefFormatBufInternal.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-08-09 13:55:54 +02:00