Commit Graph

2227 Commits

Author SHA1 Message Date
Cole Robinson
1d31526b52 Always put _LAST enums on second line of VIR_ENUM_IMPL
Standardize on putting the _LAST enum value on the second line
of VIR_ENUM_IMPL invocations. Later patches that add string labels
to VIR_ENUM_IMPL will push most of these to the second line anyways,
so this saves some noise.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2019-04-11 12:47:23 -04:00
Michal Privoznik
c14b5694b7 virsh: Add virshDomainShutdownModeCompleter
This completer is used to offer shutdown/reboot modes.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-04-11 08:54:34 +02:00
Peter Krempa
285c5f28c4 util: Move enum convertors into virenum.(c|h)
virutil.(c|h) is a very gross collection of random code. Remove the enum
handlers from there so we can limit the scope where virtutil.h is used.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-10 09:12:04 +02:00
Nikolay Shirokovskiy
29f2b5248c tools: console: pass stream/fd errors to user
If the console was disconnected due to a connection problem or a problem on the
server side it is convinient to provide the cause to the user. If the error
come from the API then the error is saved in a virsh global variable. However,
since success is returned from virshRunConsole after we reach the waiting stage,
then the error is never reported. Let's track the error in the event loop.

Next after failure we do a cleanup and this cleanup can overwrite
root cause. Thus let's save root cause immediately and then set it to
virsh error after all cleanup is done.

Since we'll be sending the error to the consumer, each failure path from
the event handlers needs to be augmented to provide what error generated
the failure.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2019-04-04 10:36:04 +03:00
Nikolay Shirokovskiy
4525de7356 tools: console: check if console was shutdown in callbacks
On error in main thread virConsoleShutdown is called which
deletes fd watches/stream callback and yet callbacks can
be called after. Thus we can incorrectly allocate
terminalToStream.data memory and get memory leak for example.
Let's check if console was shutdown in the very beginning of
callbacks.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2019-04-04 10:36:04 +03:00
Nikolay Shirokovskiy
cb7c1cddc5 tools: console: add missing locks in callbacks
Stream/fd callbacks accessing console object are called from the
event loop thread and the console object is also accessed from
the main thread so we are better add locking to handlers.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2019-04-04 10:36:04 +03:00
Nikolay Shirokovskiy
cbd9e3624d tools: console: cleanup console on errors in main thread
We only check now for virObjectWait failures in virshRunConsole but
we'd better check and for other failures too. And we need to shutdown
console on error in the main thread.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2019-04-04 10:36:04 +03:00
Nikolay Shirokovskiy
98361cc3b9 tools: console: make console virLockableObject
We need to turn console into virObject object because stream/fd callbacks
can be called from the event loop thread after freeing console
in main thread. It is convinient to turn into virLockableObject as
we have mutex in console object.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2019-04-04 10:36:04 +03:00
Han Han
fe34bf3a62 virsh.pod: Improve native configuration format doc
Add native guest format of BSD hypervisor and VMware/ESX. Quote native
guest format of domxml-from-native for domxml-to-native.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Han Han <hhan@redhat.com>
2019-04-03 13:55:59 -04:00
Peter Krempa
fb59497484 Use VIR_AUTODISPOSE_STR instead of VIR_DISPOSE_STRING where possible
Refactor code paths which clear strings on cleanup paths to use the
automatic helper.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:10 +02:00
Ján Tomko
cbc6ee722b virsh-completer: introduce virshPagesizeNodeToString
A helper function that takes a XML node with a "size"
and "unit" attributes and converts it into a human-readable string.

Reduce the size and number of variables in the parent function.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 10:29:15 +02:00
Ján Tomko
b0325e07e6 virsh-completer: remove excessive labels
Now that we have a shared cleanup section everywhere,
delete all the 'error' labels which all contain just 'goto cleanup'
anyway.

Also remove all the 'cleanup' labels that only 'return ret' - we
can simply return NULL instead of jumping to that label.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 10:24:47 +02:00
Ján Tomko
d41af4b435 virsh-completer: use VIR_AUTOFREE for char* variables
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 10:24:47 +02:00
Ján Tomko
1c1393ed01 virsh-completer: use VIR_AUTOPTR for xml* variables
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 10:24:47 +02:00
Ján Tomko
ab96c35a03 virsh-completer: use VIR_AUTOFREE for xmlNodePtr* variables
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 10:24:47 +02:00
Ján Tomko
d46dd75e3a virsh-completer: use VIR_AUTOSTRINGLIST for tmp
We've been open-coding virStringListFreeCount for cleaning up
the completion list we're building. This had the advantage of
zeoring the pointer afterwards, which is no longer needed
now that we compile the list in 'tmp' instead of 'ret'.

Since all our lists are NULL-terminated anyway, switch to using
virStringListFree via the VIR_AUTOSTRINGLIST macro.

Fixes nearly impossible NULL dereferences in
  virshNWFilterBindingNameCompleter
  virshNWFilterNameCompleter
  virshNodeDeviceNameCompleter
  virshNetworkNameCompleter
  virshInterfaceNameCompleter
  virshStoragePoolNameCompleter
  virshDomainNameCompleter
which jumped on the error label after a failed allocation
and a possible one in
  virshStorageVolNameCompleter
which jumped there when we fail to fetch the list of volumes.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 10:24:06 +02:00
Ján Tomko
81723acebd virsh-completer: unify cleanup of items in name completers
Merge the cleanup of fetched items for the success and the error
paths.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 10:09:54 +02:00
Ján Tomko
3b16c3a10b virsh-completer: add a cleanup label everywhere
Unify the cleanup paths for error and success.
Now that 'ret' is only set (from tmp) on the success path,
it is safe to jump right before 'return ret' after processing
the error block.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 10:09:54 +02:00
Ján Tomko
37e820daea virsh-completer: switch to using tmp instead of ret
Construct the potential return value in an array called 'tmp'
and only assign it to 'ret' if we're going to return it.

This will allow us to unify the error and success paths.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 10:09:54 +02:00
Ján Tomko
080ebb2371 virsh-completer: fix typo
Use the posessive determiner instead of a contracted auxiliary.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 10:07:36 +02:00
Ján Tomko
912513ca7a virsh: fix indentation of info_managed_save_edit
Use four spaces instead of three.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 10:07:36 +02:00
John Ferlan
dab3abfcf5 tools: Tweak wording for iothreadset
Update the wording to note the values for polling are purely dynamic
and won't be saved across domain stop/(re)start or save/restore.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2019-03-30 07:34:34 -04:00
Eric Blake
24b092c404 virsh: Don't infloop on snapshot/storage_vol failure
Most of our completers used the pattern:
if ((nITEM = virITEMListAll()) < 0)
    return NULL;

but the virDomainSnapshot and virStorageVolume completers were instead
using goto error. If the ListAll fails with -1, the cleanup label was
running a loop of 'size_t i < int nITEM', which is an extreme waste of
CPU cycles. Broken since their introduction in v4.1.

Fixes: f81f8b62
Fixes: 4cb4b649
Reported-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2019-03-28 12:40:38 -05:00
Jiri Denemark
5a303994ff virsh: Add options for parallel migration
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-03-27 09:42:50 +01:00
Eric Blake
2efb42e9ac virsh: Add 'echo --err' option
Since test:///default resets state on every connection, writing a test
that covers a sequence of commands must be done from a single
session. But if the test wants to exercise particular failure modes as
well as successes, it can be nice to leave witnesses in the stderr
stream immediately before and after the spot where the expected error
should be, to ensure the rest of the script is not causing errors.

Do this by adding an --err option.

Signed-off-by: Eric Blake <eblake@redhat.com>
Acked-by: Michal Privoznik <mprivozn@redhat.com>
2019-03-25 09:02:02 -05:00
Eric Blake
4e650259f9 virsh: Treat any command name starting with # as comment
As the previous commit mentioned, argv mode (such as when you feed
virsh via stdin with <<\EOF instead of via a single shell argument)
didn't permit comments. Do this by treating any command name token
that starts with # as a comment which silently eats all remaining
arguments to the next newline or semicolon.

Note that batch mode recognizes unquoted # at the start of any word as
a command as part of the tokenizer, while this patch only treats # at
the start of the command word as a comment (any other # remaining by
the time vshCommandParse() is processing things was already quoted
during the tokenzier, and as such was probably intended as the actual
argument to the command word earlier in the line).

Now I can do something like:

$ virsh -c test:///default <<EOF
  # setup
  snapshot-create-as test s1
  snapshot-create-as test s2
  # check
  snapshot-list test --name
EOF

Signed-off-by: Eric Blake <eblake@redhat.com>
Acked-by: Michal Privoznik <mprivozn@redhat.com>
2019-03-25 09:01:53 -05:00
Eric Blake
834f64ca47 virsh: Parse # comments in batch mode
Continuing from what I did in commit 4817dec0, now I want to write a
sequence that is self-documenting.  So I need comments :)

Now I can do something like:

$ virsh -c test:///default '
  # setup
  snapshot-create-as test s1
  snapshot-create-as test s2
  # check
  snapshot-list test --name
'

Note that this does NOT accept comments in argv mode, another patch
will tackle that.

(If I'm not careful, I might turn virsh into a full-fledged 'sh'
replacement? Here's hoping I don't go that far...)

Signed-off-by: Eric Blake <eblake@redhat.com>
Acked-by: Michal Privoznik <mprivozn@redhat.com>
2019-03-25 09:01:42 -05:00
Eric Blake
de80cdbcc9 snapshot: Refactor list filtering
Separate the algorithm for which list members to vist (which is
generic and can be shared with checkpoints, provided that common
filtering bits are either declared with the same value or have a
mapping from public API to common value) from the decision on which
members to return (which is specific to snapshots).  The typedef for
the callback function feels a bit heavy here, but will make it easier
to move the common portions in a later patch.

As part of the refactoring, note that the macros for selecting filter
bits are specific to listing functionality, so they belong better in
virdomainsnapshotobjlist.h (missed in commit 9b75154c).

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-03-22 01:18:33 -05:00
Peter Krempa
61d1abd5f1 virsh: man: Document asynchronous behaviour of detach-device-alias
This command is fully async. Note that users can use virsh event to be
notified of the guest actually removing the device.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2019-03-18 13:11:29 +01:00
Peter Krempa
e95a66349a virsh: man: Document quirks of device-detach and friends
Mention that successful return does not equal to device being detached
similarly as we do at the API level.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2019-03-18 13:11:29 +01:00
Michal Privoznik
d8b2ec2149 virsh-pool: Offer only active pool for pool-refresh completer
Only active pools can be refreshed. But our completer offers just
all pool, even inactive ones.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2019-03-16 07:50:51 +01:00
Andrea Bolognani
912fe2df9d Drop support for "Red Hat" init scripts
Despite the misleading name, these were supposed to be used
with a System V style init; however, none of the platforms we
target is using that kind of init anymore: almost all Linux
distributions have switched to systemd, those that haven't
(such as Gentoo and Alpine) are mostly using OpenRC with
custom init scripts, and the BSDs have been doing their own
thing all along.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2019-03-15 18:36:19 +01:00
Cole Robinson
f38d553e2d configure: Remove --enable-test-coverage
We provide a custom configure option --enable-test-coverage and
'make cov' target to generate code coverage reports. However gnulib
already provides a 'make coverage' which 'just works' and doesn't
require a special configure option.

This drops our custom implementation in favor of 'make coverage'.
Reports are now output to cov/index.html

Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
2019-03-14 20:47:15 -04:00
Eric Blake
c615c14246 virsh: Add snapshot-list --topological
For snapshots, virsh already has a (shockingly naive [1]) client-side
topological sorter with the --tree option. But as a series of REDEFINE
calls must be presented in topological order, it's worth letting the
server do the work for us, especially since the server can give us a
topological sorting with less effort than our naive client
reconstruction.

[1] The XXX comment in virshSnapshotListCollect() about --tree being
O(n^3) is telling; https://en.wikipedia.org/wiki/Topological_sorting
is an interesting resource describing Kahn's algorithm and other
approaches for O(n) topological sorting for anyone motivated to use a
more elegant algorithm than brute force - but that doesn't affect this
patch.

For now, I am purposefully NOT implementing virsh fallback code to
provide a topological sort when the flag was rejected as unsupported;
we can worry about that down the road if users actually demonstrate
that they use new virsh but old libvirt to even need the fallback.
(The code we use for --tree could be repurposed to be such a fallback,
whether or not we keep it naive or improve it to be faster - but
again, no one should spend time on a fallback without evidence that we
need it.)

The test driver makes it easy to test:
$ virsh -c test:///default '
snapshot-create-as test a
snapshot-create-as test c
snapshot-create-as test b
snapshot-list test
snapshot-list test --topological
snapshot-list test --descendants a
snapshot-list test --descendants a --topological
snapshot-list test --tree
snapshot-list test --tree --topological
'

Without any flags, virsh does client-side sorting alphabetically, and
lists 'b' before 'c' (even though 'c' is the parent of 'b'); with the
flag, virsh skips sorting, and you can now see that the server handed
back data in a correct ordering. As shown here with a simple linear
chain, there isn't any other possible ordering, so --tree mode doesn't
seem to care whether --topological is used.  But it is possible to
compose more complicated DAGs with multiple children to a parent
(representing reverting back to a snapshot then creating more
snapshots along those divergent execution timelines), where it is then
possible (but not guaranteed) that adding the --topological flag
changes the --tree output (the client-side --tree algorithm breaks
ties based on alphabetical sorting between two nodes that share the
same parent, while the --topological sort skips the client-side
alphabetical sort and ends up exposing the server's internal order for
siblings, whether that be historical creation order or dependent on a
random hash seed).  But even if the results differ, they will still be
topologically correct.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2019-03-12 20:46:09 -05:00
Peter Krempa
eae99ca97e tools: vsh: Don't use assert()
It's meant for testing, not for production builds. Also we have a helper
for reporting OOM errors. Introduced by 23e0bf1c4e

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-03-12 14:17:02 +01:00
Eric Blake
23e0bf1c4e virsh: Make self-test failures noisy
In local testing, I accidentally introduced a self-test failure,
and spent way too much time debugging it. Make sure the testsuite
log includes some hint as to why command option validation failed.
Lone exception: allocation failure is unlikely during self-test,
and if it happens, we are better off asserting (vsh.c can do this,
even if libvirt.so cannot).

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
Acked-by: Peter Krempa <pkrempa@redhat.com>
2019-03-12 06:37:48 -05:00
Thomas Huth
d38d512f4e tools/virt-host-validate: Fix IOMMU check on s390x
When running virt-host-validate on an s390x host, the tool currently warns
that it is "Unknown if this platform has IOMMU support". We can use the
common check for entries in /sys/kernel/iommu_groups here, too, but it only
makes sense to check it if there are also PCI devices available. It's also
common on s390x that there are no PCI devices assigned to the LPAR, and in
that case there is no need for the PCI-related IOMMU, so without PCI devices
we should simply skip this test.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2019-03-08 09:16:00 +01:00
Andrea Bolognani
094f29df07 Use virStringHasSuffix() where possible
When dealing with internal paths we don't need to worry about
whether or not suffixes are lowercase since we have full control
over them, which means we can avoid performing case-insensitive
string comparisons.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
2019-03-07 10:10:49 +01:00
Andrea Bolognani
2de7dcba7e util: Rename virFileHasSuffix() to virStringHasCaseSuffix()
Despite its name, this is really just a general-purpose string
manipulation function, so it should be moved to the virstring
module and renamed accordingly.

In addition to the obvious s/File/String/, also tweak the name
to make it clear that the presence of the suffix is verified
using case-insensitive comparison.

A few trivial whitespace changes are squashed in.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
2019-03-07 10:08:47 +01:00
Michal Privoznik
ab2e90006d Drop some useless comparisons and checks
In these cases the check that is removed has been done a few
lines above already (as can even be seen in the context). Drop
them.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2019-03-07 09:22:47 +01:00
John Ferlan
d9a4115892 virsh: Expose virConnectGetStoragePoolCapabilities
https://bugzilla.redhat.com/show_bug.cgi?id=1581670

Add a new storage pool command "pool-capabilities" to output
the storage pool capabilities.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
2019-03-06 11:12:48 -05:00
Lin Ma
397369853d virsh: Add event name completion to 'network-event' command
Signed-off-by: Lin Ma <lma@suse.com>
2019-03-05 09:09:48 +01:00
Lin Ma
96837ab140 virsh-network: Introduce virshNetworkEventCallback to handle network events
Signed-off-by: Lin Ma <lma@suse.com>
2019-03-05 09:09:48 +01:00
Lin Ma
ab8aa7ccc8 virsh: Add device name completion for target option of detach-disk command
Signed-off-by: Lin Ma <lma@suse.com>
2019-03-05 09:09:48 +01:00
Eric Blake
d152c727c6 snapshots: Avoid term 'checkpoint' for full system snapshot
Upcoming patches plan to introduce virDomainCheckpointPtr as a new
object for use in incremental backups, along with documentation on
how incremental backups differ from snapshots.  But first, we need
to rename any existing mention of a 'system checkpoint' to instead
be a 'full system snapshot', so that we aren't overloading
the term checkpoint.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-02-26 15:48:58 -06:00
Eric Blake
5817dec014 virsh: Elide backslash-newline in batch mode
The previous patch made it possible to split multiple commands by
adding newline, but not to split a long single command. The sequence
backslash-newline was being used as if it were a quoted newline
character, rather than completely elided the way the shell does.

Again, add more tests, although this time it seems more like I am
suffering from a leaning-toothpick syndrome with all the \.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-02-26 15:42:21 -06:00
Eric Blake
fe1b683fd0 virsh: Treat \n like ; in batch mode
I wanted to do a demonstration with virsh batch mode, which
takes multiple commands all packed into a single argument:

$ virsh -c test:///default 'echo a; echo b;'
a
b

but that produced a really long line, so I tried to make it
more legible:

$ virsh -c test:///default '
   echo a;
   echo b;
'
error: unknown command: '
'

Let's be more like the shell, and treat unquoted newline as a
command separator just as we do for semicolon.  In fact, with
that, I can even now mix styles:

$ virsh -c test:///default '
   echo a; echo b
   echo c
'
a
b
c

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2019-02-26 14:16:04 -06:00
Daniel P. Berrangé
e97d7733fe virsh: fix return value in storage vol name completor
The function must return a pointer, not a boolean. Fortunately 'false'
is equivalent to 'NULL' so this bug no had ill effect previously.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-02-19 16:06:46 +00:00
Ján Tomko
d3e5c3605a virsh: fix snapshot list --parent
The root snapshot does not have a parent.
Use NULLSTR_EMPTY to pass an empty string instead of putting
too few columns in the table.

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

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
2019-02-14 16:37:24 +01:00
Ján Tomko
0f110d5ac8 Use NULLSTR_EMPTY
Instead of repetitive:
  s ? s : ""
use NULLSTR_EMPTY.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2019-02-14 14:09:38 +01:00