Commit Graph

706 Commits

Author SHA1 Message Date
Michal Privoznik
9985f62b51 qemu: Wire up MEMORY_DEVICE_SIZE_CHANGE event
As advertised in previous commit, this event is delivered to us
when virtio-mem module changes the allocation inside the guest.
It comes with one attribute - size - which holds the new size of
the virtio-mem (well, allocated size), in bytes.
Mind you, this is not necessarily the same number as 'requested
size'. It almost certainly will be when sizing the memory up, but
it might not be when sizing the memory down - the guest kernel
might be unable to free some blocks.

This current size is reported in the domain XML as an output
element only.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-10-01 11:04:47 +02:00
Kristina Hanicova
49d74124a5 virsh: domain: remove else branch
I removed else branches after return/break as they are not
necessary and the code looks cleaner without them.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-25 09:30:53 +02:00
Kristina Hanicova
bd82e3d81a virsh: domain: remove 'ret' variable and use 'count' instead
This patch also includes use of an early return in case of an
error. I think the changes make the functions more readable.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-25 09:30:43 +02:00
Kristina Hanicova
24ddb0cdfe virsh: domain: use early return when possible
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-25 09:30:09 +02:00
Kristina Hanicova
6e1cdf928c virsh: domain: remove 'ret' variable, use early return when possible
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-25 09:28:51 +02:00
Kristina Hanicova
9a5db04fe6 virsh: domain: remove 'ret' variable and use direct return when possible
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-25 09:28:45 +02:00
Kristina Hanicova
a1fe822801 virsh: domain: remove nested 'if' in cmdAttachDisk()
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-25 09:27:34 +02:00
Kristina Hanicova
14a804ee67 virsh: domain: use early return in virshDomainDefine()
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-25 09:25:56 +02:00
Kristina Hanicova
bc7b8a34fa virsh: domain: remove unnecessary variable and label in cmdMigrateSetMaxDowntime()
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-25 09:16:30 +02:00
Kristina Hanicova
0987edbedf virsh: domain: fix mistake in cmdMigrateSetMaxDowntime()
If there was added a new return value indicating success to the
function virDomainMigrateSetMaxDowntime() in the future, because
of the way the function is called it would be treated it as an
error state and would return false (indicating failure). This
patch fixes it, so that the call of the function follows the same
pattern as is currently set in libvirt.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-25 09:14:56 +02:00
Kristina Hanicova
ba78db1f73 virsh: domain: refactor cmdLxcEnterNamespace()
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-24 09:52:42 +02:00
Kristina Hanicova
637d98b329 virsh: domain: refactor virshCPUCountCollect()
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-24 09:52:42 +02:00
Kristina Hanicova
e31502544c virsh: domain: refactor cmdSchedinfo()
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-24 09:52:42 +02:00
Michal Privoznik
8eefc7afc8 virsh: Provide local path completer for screenshot --file
The screenshot command takes optional --file argument which can
point to an existing local path (in which case the file is
overwritten). Set the argument's completer so that self-test
doesn't report it as missing.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-09-21 10:20:41 +02:00
Peter Krempa
c580c8db70 virsh-completer: Provide completer for '--top' and '--base' for blockjobs
Complete with the indexed targets (e.g. vda[3]) based on existing
indexes.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-17 09:40:46 +02:00
Peter Krempa
071bab399a virsh: Introduce virshCompleteEmpty and use it for places where we can't suggest anything
For now this serves just as an annotation because readline and also the
bash completion script insist on completing local paths when an empty
list is returned.

This will serve for future reference once we'll be able to properly
refuse to suggest anything.

The completer is used for fields such as names for new objects,
description strings, password strings etc, URIs and hostnames which we
can't feasibly autocomplete.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-17 09:40:46 +02:00
Peter Krempa
2732d81984 virsh: Use 'virshCompletePathLocalExisting' for options reading local files
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-17 09:40:46 +02:00
Peter Krempa
bc4739ed77 virsh: Expand VIRSH_COMMON_OPT_FILE for cases when it's not a local file used by virsh
In cases such as the APIs for managed save management, the file path
provided via the '--file' option is passed to the API.

We'll need to make them distinct from cases for when virsh is using the
file so that different completers can be used.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-17 09:40:46 +02:00
Peter Krempa
119b139c76 virsh: Provide completers for options taking comma separated list of disk targets
'--storage' of the 'undefine' command and '--migrate-disks' of the
'migrate' command take a list of disk targets as an argument.

We can simply combine 'virshDomainDiskTargetCompleter' with
'virshCommaStringListComplete' to provide the completions.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-17 09:40:46 +02:00
Jiri Denemark
88810c5267 virsh: Make code flow in cmdManagedSaveRemove more straightforward
By doing so we can get rid of the code which violates our coding style
guidelines.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
2021-09-16 16:47:54 +02:00
Peter Krempa
eb2e317c65 virshDomainGetVcpuBitmap: Refactor cleanup
Rename the temp variable that is being returned and use automatic
pointer clearing for it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
2021-09-15 15:31:17 +02:00
Peter Krempa
59e74c3193 virshDomainGetVcpuBitmap: Return bitmap when taking the fallback path
In case the specific VCPU states are not present in the XML we were
taking a fallback code path just noting that all cpus of the VM are
enabled.

This was broken by a mistake in a recent refactor where a 'goto cleanup'
was mistakenly replaced by a 'return NULL'. This broke reporting of cpus
and also caused a memory leak.

Return the fallback cpu map.

Fixes: bd1f40fe7d
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2004429
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
2021-09-15 15:31:17 +02:00
Michal Privoznik
868bacd380 virsh: Support vhostuser in attach-interface
Recently, I wanted to attach an vhost-user interface but found
out that attach-interface command doesn't support it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-08-18 14:21:40 +02:00
Ján Tomko
bd1f40fe7d tools: virsh: remove redundant labels
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-08-16 13:10:34 +02:00
Ján Tomko
fba265e2b2 tools: virsh: use g_autofree
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-08-16 13:10:34 +02:00
Ján Tomko
07b40abe0f tools: virsh: use automatic cleanup for char **
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-08-16 13:10:34 +02:00
Ján Tomko
851e66e05d tools: virsh: reduce variable scope to use automatic cleanup
Some variables are used in a loop and only freed in the cleanup
section because we need to be able to jump out of the loop.

Reduce their scope and free them automatically.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-08-16 13:10:34 +02:00
Ján Tomko
4b72960b4e tools: virsh: use automatic cleanup for vshTable
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-08-16 13:10:34 +02:00
Ján Tomko
5f7cdb0efc tools: virsh: use automatic cleanup for xmlDoc
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-08-16 13:10:34 +02:00
Ján Tomko
2a7e5240ff tools: virsh: use automatic cleanup for xmlXPathObject
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-08-16 13:10:34 +02:00
Ján Tomko
be72434d79 tools: virsh: use automatic cleanup for xmlXPathContext
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-08-16 13:10:33 +02:00
Ján Tomko
cf337df3d6 tools: virsh: use automatic cleanup for virDomainObj
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-08-16 13:10:33 +02:00
Ján Tomko
65551e2239 tools: virsh: split variable declarations
One variable per line.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-08-16 13:10:33 +02:00
Peter Krempa
98f6f2081d util: alloc: Reimplement VIR_APPEND_ELEMENT using virAppendElement
Use virAppendElement instead of virInsertElementsN to implement
VIR_APPEND_ELEMENT which allows us to remove error handling as the
only relevant errors were removed when switching to aborting memory
allocation functions.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-08-06 08:53:25 +02:00
Pavel Hrdina
dc721f99df virsh: fix setmem flags logic
When we dropped virDomainSetMemory usage it got kind of tricky to
figure out the flags correctly.

Originally the logic was following:

    no option | --current | --live | --config | --live --config
    ----------+-----------+--------+----------+----------------
       LIVE   |  CURRENT  |  LIVE  |  CONFIG  |  LIVE & CONFIG

But after the commit removing virDomainSetMemory usage it changed to:

    no option | --current | --live |    --config     | --live --config
    ----------+-----------+--------+-----------------+----------------
       LIVE   |  CURRENT  |  LIVE  |  LIVE & CONFIG  |  LIVE & CONFIG

This commit fixes the logic back to the original behavior except for
ESX, HyperV and Virtuozzo drivers where virDomainSetMemory() default
behavior was CURRENT instead of LIVE.

Fixes: ce8138564b
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1980199
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-07-23 11:24:51 +02:00
Peter Krempa
9e7f32790a virsh-domain: Avoid 'vir' prefix for locally declared VIR_ENUM* helpers
Stuff used in virsh should use 'virsh'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-07-23 09:59:12 +02:00
Peter Krempa
cc530c4557 virsh-host: Avoid 'vir' prefix for locally declared VIR_ENUM* helpers
Stuff used in virsh should use 'virsh'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-07-23 09:59:12 +02:00
Han Han
78b1a53df1 virsh: Fix the order of format arguments in doDump
According to definition of virDomainCoreDumpFormat, the "elf" should be
the first argument in VIR_ENUM_*.

Fixes: 84cc4543be

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

Signed-off-by: Han Han <hhan@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-07-13 11:21:23 +02:00
Lin Ma
8cdbca6213 virsh: Add format completion to blockcopy command
Signed-off-by: Lin Ma <lma@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-06-15 10:28:02 +02:00
Lin Ma
8de9a54b9e virsh: Add target completion to dompmsuspend command
Signed-off-by: Lin Ma <lma@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-06-15 10:27:59 +02:00
Lin Ma
b41811b93d virsh: Use VIR_ENUM_* for --target argument in cmdDomPMSuspend
Signed-off-by: Lin Ma <lma@suse.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-06-15 10:27:57 +02:00
Lin Ma
a61a6978d3 virsh: Add comp-methods completion to migrate command
Signed-off-by: Lin Ma <lma@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-06-15 10:27:47 +02:00
Lin Ma
564512e916 virsh: Add coredump format completion to dump command
Signed-off-by: Lin Ma <lma@suse.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-06-07 16:30:59 +02:00
Lin Ma
84cc4543be virsh: Use VIR_ENUM_* for --format argument in doDump
Signed-off-by: Lin Ma <lma@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-06-07 16:30:56 +02:00
Michal Privoznik
ce8138564b virsh-domain: Drop support for old APIs in cmdSetmem and cmdSetmaxmem
Some of our really old APIs are missing @flags argument. We
introduced their variants with "Flags" suffix and wired some
logic into virsh to call the new variant only if necessary. This
enables virsh to talk to older daemon which may be lacking new
APIs.

However, in case of cmdSetmem() we are talking about v0.1.1
(virDomainSetMemory()) vs. v0.9.0 (virDomainSetMemoryFlags()) and
in case of cmdSetmaxmem() we are talking about v0.0.3
(virDomainSetMaxMemory()) vs v0.9.0 (virDomainSetMemoryFlags()).

Libvirt v0.9.0 was released more than 10 years ago and recently
we dropped support for RHEL-7 which has v4.5.0 (released ~3 years
ago). Thus it is not really necessary to have support in virsh
for such old daemons.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-06-02 10:13:50 +02:00
Michal Privoznik
3de70da32d virsh: Expose new win-dmp dump format
In previous commit the virDomainCoreDumpWithFormat() API gained
new format. Expose it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-05-20 16:24:06 +02:00
Michal Privoznik
01a2339e1f virsh-domain: Fix @ret handling in cmdSetmem and cmdSetmaxmem
These functions initialize @ret to true and only after something
fails either they call cleanup code (which consists only from
virshDomainFree()) and return false, or they set ret = false and
carry on (when the failure occurred close to cleanup code).

Switch them to the usual pattern in which ret is initialized to
failure, goto cleanup is used and ret is set to true only after
everything succeeded.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-05-19 15:31:36 +02:00
Michal Privoznik
168190e19c virsh: Fix logic wrt to --current flag in cmdSetmem
In my commit of v7.1.0-rc1~376 I've simplified the logic of
handling @flags. My assumption back then was that calling
virDomainSetMemory() is equivalent to
virDomainSetMemoryFlags(flags = 0). But that is not the case,
because it is equivalent to virDomainSetMemoryFlags(flags =
VIR_DOMAIN_AFFECT_LIVE). Fix the condition that calls the old
API.

Fixes: b5e267e8c5
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1961118
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-05-19 15:31:17 +02:00
Lin Ma
14c36b107d virsh: Add mountpoint completion to domfsfreeze/domfsthaw command
Signed-off-by: Lin Ma <lma@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-04-22 13:46:44 +02:00
Michal Privoznik
c8238579fb lib: Drop internal virXXXPtr typedefs
Historically, we declared pointer type to our types:

  typedef struct _virXXX virXXX;
  typedef virXXX *virXXXPtr;

But usefulness of such declaration is questionable, at best.
Unfortunately, we can't drop every such declaration - we have to
carry some over, because they are part of public API (e.g.
virDomainPtr). But for internal types - we can do drop them and
use what every other C project uses 'virXXX *'.

This change was generated by a very ugly shell script that
generated sed script which was then called over each file in the
repository. For the shell script refer to the cover letter:

https://listman.redhat.com/archives/libvir-list/2021-March/msg00537.html

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-04-13 17:00:38 +02:00