Commit Graph

682 Commits

Author SHA1 Message Date
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
Peter Krempa
def579e88a virshParseRateStr: Use g_strsplit instead of virStringSplitCount
Count the elements after splitting the string.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-04-12 15:55:09 +02:00
Peter Krempa
d9c3b652ef virshParseRateStr: Refactor cleanup
Use g_auto for the string list and remove 'ret' and 'cleanup'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-04-12 15:55:09 +02:00
Peter Krempa
d7e2bca9b7 virshParseEventStr: Use g_strsplit and automatic memory freeing
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-04-12 15:55:09 +02:00
Michal Privoznik
0c30e7221c lib: Use g_steal_pointer() more
Generated by the following spatch:

  @@
  expression a, b;
  @@

  + b = g_steal_pointer(&a);
  - b = a;
    ... when != a
  - a = NULL;

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2021-03-24 13:57:51 +01:00
Jiri Denemark
7d2fd6ef01 Do not check return value of VIR_EXPAND_N
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2021-03-22 12:44:18 +01:00
Hao Wang
a2ae2dad06 migration/dirtyrate: Introduce domdirtyrate-calc virsh api
Introduce domdirtyrate-calc virsh api to start calculating domain's
memory dirty rate:
	# virsh domdirtyrate-calc <domain> [--seconds <sec>]

Signed-off-by: Hao Wang <wanghao232@huawei.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-03-18 08:50:25 +01:00
Peter Krempa
ec6e2a2c97 util: xml: Add wrapper for 'xmlNewNode'
Add a wrapper that will handle the out of memory condition by abort()
and also prevents callers from having to typecast the argument.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2021-03-02 09:50:19 +01:00
Daniel Henrique Barboza
953be56eea virsh-domain.c: use g_auto* in cmdDetachDevice()
Use g_auto* pointers to avoid the need of a cleanup label. The
type of the pointer 'virDomainPtr dom' was changed to its alias
'virshDomainPtr' to allow the use of g_autoptr().

Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-03-01 12:25:33 -03:00
Kristina Hanicova
155151a3d0 Use g_steal_pointer where possible
Via coccinelle (not the handbag!)
spatches used:
@ rule1 @
identifier a, b;
symbol NULL;
@@

- b = a;
  ... when != a
- a = NULL;
+ b = g_steal_pointer(&a);

@@

- *b = a;
  ... when != a
- a = NULL;
+ *b = g_steal_pointer(&a);

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2021-03-01 15:54:42 +01:00
Kristina Hanicova
b0f4cf25a6 virsh: Add virshKeycodeNameCompleter
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2021-02-19 07:39:56 +01:00
Kristina Hanicova
040a5bc307 virsh: Add virshCodesetNameCompleter
This completer offers completion for --codeset argument of
send-key command.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-02-16 21:26:54 +01:00
Peter Krempa
10157731f4 Replace virStringSplit with g_strsplit
Our implementation was heavily inspired by the glib version so it's a
drop-in replacement.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-02-11 17:05:34 +01:00
Peter Krempa
dcd547aec1 Replace virStringListLength by g_strv_length
The glib implementation doesn't tolerate NULL but in most cases we check
before anyways. The rest of the callers adds a NULL check.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-02-11 17:05:34 +01:00
Laine Stump
6b1595317c tools: replace VIR_FREE with g_free in all vir*Free() functions
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-02-05 00:20:45 -05:00
Tim Wiederhake
4f5c22b27c virsh-domain: Fix error handling of pthread_sigmask
pthread_sigmask() returns 0 on success and "a non-zero value
on failure", but not neccessarily a negative one.

Found by clang-tidy's "bugprone-posix-return" check.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-02-02 15:00:55 +01:00
Michal Privoznik
b5e267e8c5 virsh: Simplify @flags handing in cmdSetmem() and cmdSetmaxmem()
What code tries to achieve is that if no flags were provided to
either 'setmem' or 'setmaxmem' commands then the old (no flags)
API is called to be able to communicate with older daemons.
Well, the code can be simplified a bit.

Note that with this change the old no flag version of APIs is
used more often. Previously if --current argument was given it
resulted in *Flags() version to be called even though it is not
necessary - VIR_DOMAIN_AFFECT_CURRENT is implied.

Therefore, this change in fact allows virsh to talk with broader
set of daemons. No other user visible changes were made.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-02-02 08:50:11 +01:00
Peter Krempa
781bc9201b virsh-domain: Add quotes around '%s' formatting domain name
Domain name can contain spaces in which case it's not immediately clear
from virsh messages where the boundary of the name is. Enclose all %s
formatters in apostrophes as delimiters.

Done via the following vim regex:

 %s/omain %s/omain '%s'/g

This patch changes:

 $ virsh undefine --snapshots-metadata 'OWASP Broken Web Apps VM v1.2'
 Domain OWASP Broken Web Apps VM v1.2 has been undefined

to:

 $ virsh undefine --snapshots-metadata 'OWASP Broken Web Apps VM v1.2'
 Domain 'OWASP Broken Web Apps VM v1.2' has been undefined

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-01-06 09:25:07 +01:00
Ján Tomko
3d016477cc virsh: virshAddressParse: check for malformed address
The refactor left in the 'if (addr)' check,
but before 'addr' was the return value of strchr
and now it's the return value of virshAddressParse.

Check 'a' instead since that's the return of strchr now.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Fixes: 67bf91e1c3
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-12-10 12:58:54 +01:00
Michal Privoznik
b9dcaede65 virsh: cmdSetUserSSHKeys: Error early if the file doesn't contain any keys
When removing SSH keys via set-user-sshkeys virsh command, then
files to remove are read from passed file. But when
experimenting, I've passed /dev/null as the file which resulted
in API checks which caught that @keys argument of
virDomainAuthorizedSSHKeysSet() can't be NULL. This is because if
the file is empty then its content is an empty string and thus
the buffer the file was read in to is not NULL.

Long story short, error is reported correctly, but it's not
necessary to go through public API to catch it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-12-08 14:39:13 +01:00
Michal Privoznik
22e785b8ef virsh: Fix logical error in cmdSetUserSSHKeys()
In v6.10.0-rc1~104 I've added a virsh command that exposes
virDomainAuthorizedSSHKeysSet() API under "set-user-sshkeys"
command. The command accepts mutually exclusive "--reset" and
"--remove" options (among others). While the former controls the
VIR_DOMAIN_AUTHORIZED_SSH_KEYS_SET_APPEND flag, the latter
controls the VIR_DOMAIN_AUTHORIZED_SSH_KEYS_SET_REMOVE flag.
These flags are also mutually exclusive. But the code that sets
them has a logical error which may result in both flags being
set. In fact, this results in user being not able to set just the
remove flag.

Fixes: 87d12effbe
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1904674
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-12-08 14:39:04 +01:00
Daniel P. Berrangé
d4745bb909 src: use singular form instead of plural, for guest disk info
Existing practice with the filesystem fields reported for the
virDomainGetGuestInfo API is to use the singular form for
field names. Ensure the disk info follows this practice.

Fixes

  commit 05a75ca2ce
  Author: Marc-André Lureau <marcandre.lureau@redhat.com>
  Date:   Fri Nov 20 22:09:46 2020 +0400

    domain: add disk informations to virDomainGetGuestInfo

  commit 0cb2d9f05d
  Author: Marc-André Lureau <marcandre.lureau@redhat.com>
  Date:   Fri Nov 20 22:09:47 2020 +0400

    qemu_driver: report guest disk informations

  commit 172b830435
  Author: Marc-André Lureau <marcandre.lureau@redhat.com>
  Date:   Fri Nov 20 22:09:48 2020 +0400

    virsh: add --disk informations to guestinfo command

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2020-12-03 13:10:29 +00:00
Michal Privoznik
b7d4e6b67e lib: Replace VIR_AUTOSTRINGLIST with GStrv
Glib provides g_auto(GStrv) which is in-place replacement of our
VIR_AUTOSTRINGLIST.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-12-02 15:43:07 +01:00
Marc-André Lureau
172b830435 virsh: add --disk informations to guestinfo command
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Tested-by: Han Han <hhan@redhat.com>
2020-12-01 11:23:52 +01:00
Ryan Gahagan
8d7708ac61 virsh: Added attach-disk support for network disk
Related issue: https://gitlab.com/libvirt/libvirt/-/issues/16
Added in support for the following parameters in attach-disk:
--source-protocol
--source-host-name
--source-host-socket
--source-host-transport

Added documentation to virsh.rst specifying usage.

Signed-off-by: Ryan Gahagan <rgahagan@cs.utexas.edu>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-11-23 14:44:39 +01:00