Commit Graph

2920 Commits

Author SHA1 Message Date
Peter Krempa
bf9de8cb51 virshEventPrint: Use automatic memory clearing
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
8500571466 virsh: Use NULLSTR_EMPTY instead of ternary operator
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
34244cc20d virsh: virshVcpuinfoPrintAffinity: Use if-else instead of ternary operator
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
3a00632667 virsh: cmdRestore: Use if-else instead of ternary operator
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
8c383ea960 virsh: doSave: Use if-else instead of ternary operator
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
38b600166f virsh: cmdStart: Rewrite ternary operator use to standard if conditions
Rewrite the invocation of the virDomainCreate(WithFiles/Flags) APIs
based on the arguments into if-else instead of (nested) ternary
operators.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
1cd95f858a virsh: cmdBlockcopy: Use virXMLFormatElement
Rewrite the formatting of the block copy target xml using
virXMLFormatElement.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
44ea7749f8 virsh: Require option name for '--pass-fd' argument of 'qemu-monitor-command'
Require the option name for this argument as otherwise a part of the
'cmd' argument will be claimed.

Fixes: 43edde82af
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2022-03-01 14:29:39 +01:00
Peter Krempa
43edde82af virsh: Implement support for virDomainQemuMonitorCommandWithFiles
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-01 13:29:49 +01:00
Martin Kletzander
4e42686ade Make systemd unit ordering more robust
Since libvirt-guests script/service can operate on various URIs and we do
support both socket activation and traditional services, the ordering should be
specified for all the possible sockets and services.

Also remove the Wants= dependency since do not want to start any service.  We
cannot know which one libvirt-guests is configured, so we'd have to start all
the daemons which would break if unused colliding services are not
masked (libvirtd.service in the modular case and all the modular daemon service
units in the monolithic scenario).  Fortunately we can assume that the system is
configured properly to start services/sockets that are of interest to the user.
That also works with the setup described in https://libvirt.org/daemons.html .

To make it even more robust we add the daemon service into the machine units
created for individual domains as it was missing there.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-22 13:35:47 +01:00
Hyman Huang(黄勇)
72e60ddf1b virsh: Add mode option to domdirtyrate-calc virsh api
Extend domdirtyrate-calc virsh api with mode option, either
of these three options "page-sampling,dirty-bitmap,dirty-ring"
can be specified when calculating dirty page rate.

Signed-off-by: Hyman Huang(黄勇) <huangy81@chinatelecom.cn>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-21 13:34:16 +01:00
Peter Krempa
d2bc5a04c0 virsh-domain: Move and rename cmdStartGetFDs to virshFetchPassFdsList
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-17 15:53:58 +01:00
Peter Krempa
b0015df263 cmdStartGetFDs: Modernize
Calculate the length of the FD list beforehand to avoid multiple
expansions and mainly simplify the code and use automatic freeing to
remove the error code path.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-17 15:53:58 +01:00
Peter Krempa
654486bd57 syntax-check: sc_avoid_write: Don't use blanket file exceptions
Adding an exception for the whole file usually defeats the purpose of a
syntax check and is also likely to get forgotten once the file is
removed.

In case of the suggestion of using 'safewrite' instead of write even the
comment for safewrite states that the function needs to be used only in
certain cases.

Remove the blanket exceptions for files and use an exclude string
instead. The only instance where we keep the full file exception is for
src/libvirt-stream.c as there are multiple uses in example code in
comments where I couldn't find a nicer targetted wapproach.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-15 09:32:23 +01:00
Tim Wiederhake
883cd98498 tools: Use automatic mutex management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 16:03:29 +01:00
Daniel P. Berrangé
7904e521b2 tools: add --reset-nvram arg to several virsh commands
This wires up support for resetting NVRAM for all APIs that allow
this feature.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-02-08 13:04:20 +00:00
Michal Privoznik
87a43a907f lib: Use g_clear_pointer() more
This change was generated using the following spatch:

  @ rule1 @
  expression a;
  identifier f;
  @@
    <...
  - f(*a);
    ... when != a;
  - *a = NULL;
  + g_clear_pointer(a, f);
    ...>

  @ rule2 @
  expression a;
  identifier f;
  @@
    <...
  - f(a);
    ... when != a;
  - a = NULL;
  + g_clear_pointer(&a, f);
    ...>

Then, I left some of the changes out, like tools/nss/ (which
doesn't link with glib) and put back a comment in
qemuBlockJobProcessEventCompletedActiveCommit() which coccinelle
decided to remove (I have no idea why).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-08 08:42:07 +01:00
Ján Tomko
8eb7d869ed virParseVersionString: rename to virStringParseVersion
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2022-02-03 14:10:03 +01:00
Ján Tomko
d248e3dca8 virsh: domsetlaunchsecstate: report error if no options are passed
We already exit if they are not present.

Report an error, but do not mark them as required in case a future
version of this command will want to accept a different set of
parameters.

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

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-01-31 13:38:11 +01:00
Michal Privoznik
ec7fbdef56 virsh-network: Don't check for virshXXXTypeFromString() >= VIR_XXX_LAST
They way our VIR_ENUM_IMPL() and virXXXTypeFromString() work is
that for any string that's not recognized a negative one is
returned. And, since VIR_XXX_LAST is passed to VIR_ENUM_IMPL() we
can be sure that all enum members are covered. Therefore, there
is no way that virXXXTypeFromString() can return a value that's
bigger or equal to VIR_XXX_LAST.

I've noticed two places where such comparison was made, both in
cmdNetworkUpdate(). Drop them.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2022-01-19 16:48:33 +01:00
Michal Privoznik
d724ca8fcd virsh: Introduce net-update --section completer
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-01-19 16:48:33 +01:00
Michal Privoznik
687d6f1d7b virsh: Introduce net-update --command completer
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-01-19 16:48:33 +01:00
Olaf Hering
8eb4461645 remove sysconfig files
sysconfig files are owned by the admin of the host. They have the
liberty to put anything they want into these files. This makes it
difficult to provide different built-in defaults.

Remove the sysconfig file and place the current desired default into
the service file.

Local customizations can now go either into /etc/sysconfig/name
or /etc/systemd/system/name.service.d/my-knobs.conf

Attempt to handle upgrades in libvirt.spec.
Dirty files which are marked as %config will be renamed to file.rpmsave.
To restore them automatically, move stale .rpmsave files away, and
catch any new rpmsave files in %posttrans.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2022-01-17 18:20:59 +01:00
Jim Fehlig
161727417a docs: Add man page for libvirt-guests
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2022-01-17 18:20:55 +01:00
Jim Fehlig
3be5ba11a2 build: Only install libvirt-guests when building libvirtd
libvirt-guests was already moved to the libvirt daemon package in commit
d800c50349. It only needs to be installed when building libvirtd.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2022-01-17 18:20:52 +01:00
Michal Privoznik
364cf32e57 virsh: Remove needless labels
There are few places where a cleanup label contains nothing but a
return statement. Drop such labels and return directly.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-01-17 09:53:45 +01:00
Jim Fehlig
3fc65ae9e2 tools: Add domsetlaunchsecstate virsh command
After attesting a domain with the help of domlaunchsecinfo,
domsetlaunchsecstate can be used to set a secret in the guest
domain's memory prior to running the vcpus.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2022-01-04 10:56:00 -07:00
Boris Fiuczynski
354644feb4 virt-host-validate: Fix IOMMU output on S390
Commit 93e9e92c1e eliminated the option for skipping but left code in
the s390 check which makes use of a skip. This leads to an output
without result destroying the correct format. e.g.

  QEMU: Checking for hardware virtualization                                 : PASS
  QEMU: Checking if device /dev/kvm exists                                   : PASS
  QEMU: Checking if device /dev/kvm is accessible                            : PASS
  QEMU: Checking if device /dev/vhost-net exists                             : PASS
  QEMU: Checking if device /dev/net/tun exists                               : PASS
  QEMU: Checking for cgroup 'cpu' controller support                         : PASS
  QEMU: Checking for cgroup 'cpuacct' controller support                     : PASS
  QEMU: Checking for cgroup 'cpuset' controller support                      : PASS
  QEMU: Checking for cgroup 'memory' controller support                      : PASS
  QEMU: Checking for cgroup 'devices' controller support                     : PASS
  QEMU: Checking for cgroup 'blkio' controller support                       : PASS
  QEMU: Checking for device assignment IOMMU support                         :   QEMU: Checking for secure guest support                                    : PASS

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-12-17 16:34:20 +01:00
Michal Privoznik
5ce184f33c vsh-table: Ensure NULL terminated arguments to vshTable*()
There are two functions that take variable arguments:
vshTableNew() and vshTableRowAppend(). Both expect the list of
arguments to be NULL terminated. Annotate them with
G_GNUC_NULL_TERMINATED to enable compile time check for this.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-12-17 15:05:58 +01:00
Michal Privoznik
2ac0e4c347 vsh-table.h: Modernize declarations
Use modern style of function declarations where the return type
and function name are on two separate lines.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-12-17 15:05:54 +01:00
Michal Privoznik
74c6c8e679 vsh-table: Hide vshTableRow typedef
There's no need for any caller to know vshTableRow typedef.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-12-17 15:05:49 +01:00
Michal Privoznik
dfd1ffc544 virsh-completer: Provide completer for numatune --mode
The completer is trivial, just iterate over
virDomainNumatuneMemMode enum and convert each integer into its
string comrade.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2021-12-17 13:18:42 +01:00
Michal Privoznik
de617ce96b admin: Build only when RPC is available
The admin module is very closely tied to RPC. If we are
building without RPC support there's not much use for the
admin module, in fact it fails to build.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-12-15 12:12:44 +01:00
Daniel P. Berrangé
719bb0bf23 tools: add 'nodesevinfo' virsh command
While some SEV info is reported in the domain capabilities,
for reasons of size, this excludes the certificates. The
nodesevinfo command provides the full set of information.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-12-14 16:04:17 +00:00
Daniel P. Berrangé
ac79e9ff5c tools: add 'domlaunchsecinfo' virsh command
This command reports the launch security parameters for
a guest, allowing an external tool to perform a launch
attestation.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-12-14 16:04:17 +00:00
Andrea Bolognani
00c4dd794a nss: Use shared_library() for nss_libvirt_lib
shared_module() is intended for shared objects that are
loaded at runtime using dlopen() whereas NSS plugins need to
be full-fledged shared libraries with, among other things, a
proper SONAME.

Meson seems to have become more strict about this recently,
because libnss_libvirt.so.2 gets a SONAME when I build it with
Meson 0.59.4 on Fedora 34 but doesn't when I use Meson 0.60.2
on Debian testing instead.

Either way, shared_library() was always the right function
to use for NSS plugins.

Fixes: 36780c9319
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-12-13 14:17:56 +01:00
Peter Krempa
78db8bf006 virt-host-validate-qemu: Use automatic memory freeing for virBitmap
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-12-10 16:37:42 +01:00
Peter Krempa
68919edb3b virt-host-validate-common: Use automatic memory freeing for virBitmap
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-12-10 16:37:42 +01:00
Peter Krempa
33eb88cdc9 virshParseCPUList: Refactor cleanup
Use automatic memory freeing for the temporary bitmap and remove the
pointless 'cleanup' section.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-12-10 16:36:24 +01:00
Peter Krempa
51d1c08fe9 virDomainMigrate: Introduce VIR_MIGRATE_NON_SHARED_SYNCHRONOUS_WRITES flag
Non-shared storage migration of guests which are disk I/O intensive and
have fast local storage may actually never converge if the guest happens
to dirty the disk faster than it can be copied.

This patch introduces a new flag
'VIR_MIGRATE_NON_SHARED_SYNCHRONOUS_WRITES' which will instruct
hypervisors to synchronize local I/O writes with the writes to remote
storage used for migration so that the guest can't overwhelm the
migration. This comes at a cost of decreased local I/O performance for
guests which behave well on average.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-12-07 09:00:39 +01:00
Peter Krempa
b54c313c33 virDomainBlockCopy: Introduce VIR_DOMAIN_BLOCK_COPY_SYNCHRONOUS_WRITES flag
In cases when the destination storage is slower than the normal VM
storage and the VM does intensive I/O to the disk a block copy job may
never converge.

Switching it to synchronous mode will ensure that all writes done by the
guest are propagated to the destination at the cost of slowing down I/O
of the guest to the synchronous speed.

This patch adds the new API flag and implements virsh support.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-12-07 09:00:39 +01:00
Daniel P. Berrangé
e674218dc2 tools: fix iterating over argv when recovering xattr
The libvirt_recover_xattrs.sh tool hangs when run. When no flags
are provided OPTIND is 1, so the loop expands to 'shift 0' which
has not effect. Rewrite to just loop over $@ instead which involves
less cleverness.

Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-11-30 10:45:35 +00:00
Michal Privoznik
010613cfd8 wireshark: Drop needless comment in dissect_xdr_bytes()
In the dissect_xdr_bytes() there's a comment that the string
allocated by xdr_bytes() can't be freed using xdr_free(). Well,
that is expected because xdr_bytes() used plain calloc() AND the
string is not an XDR struct but plain 'char *' type. Passing it
to xdr_free() must result in weird things happening.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2021-11-29 15:05:43 +01:00
Michal Privoznik
7e299ba649 wireshark: Switch to tvb_bytes_to_str()
When the dissector sees a byte sequence that is either an opaque
data (xdr_opaque) or a byte sequence (xdr_bytes) it formats the
bytes as a hex numbers using our own implementation. But
wireshark already provides a function for it: tvb_bytes_to_str().
NB, the reason why it returns a const string is so that callers
don't try to free it - the string is allocated using an allocator
which will decide when to free it.

The wireshark formatter was introduced in wireshark commit of
v1.99.2~479 and thus is present in the version we require at
least (2.6.0).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2021-11-29 15:05:33 +01:00
Ján Tomko
097d3a4f56 tools: virt-host-validate: fix memory leak
virHostValidateGetCPUFlags returns an allocated virBitmap and
it needs to be freed.

Fixes: a0ec7165e3
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Kristína Hanicová <khanicov@redhat.com>
2021-11-23 16:59:36 +01:00
Koichi Murase
097296c30b bash-completion: fix variable leaks of "IFS" and "word"
Signed-off-by: Koichi Murase <myoga.murase@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-11-23 13:35:36 +01:00
Martin Kletzander
0ac13b189f virsh: Do not try connecting first time without polkit agent
Trying to connect once without a polkit agent will generate an error on the
server side which seems too rough given it only serves the purpose of the client
(virsh in this case) to figure out that an agent is needed.  Thankfully we can
just try running the agent.  It does not break anything as we are running it
with `--fallback`, which makes sure it does not replace an existing agent in
case there is one already registered.

The second piece of code trying to start the polkit text agent is kept in order
to _really_ try out starting the agent (and error out when failing to do so)
just in case the agent was not available the first time it was ran.  Even though
it should not happen it avoids a very rare race condition and really does not
add much complexity.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-23 12:51:09 +01:00
Martin Kletzander
e20ad73780 virsh: Remove needless variable
It only redundantly reflects whether pkagent != NULL.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-23 12:51:09 +01:00
Michal Privoznik
784e9e2b62 lib: Drop needless one line labels
In some cases we have a label that contains nothing but a return
statement. The amount of such labels rises as we use automagic
cleanup. Anyway, such labels are pointless and can be dropped.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-22 12:39:59 +01:00
Peter Krempa
813ee9fb62 virsh: domain: Replace virJSONValueObjectCreate by virJSONValueObjectAdd
virJSONValueObjectAdd now works identically to virJSONValueObjectCreate
when used with a NULL argument. Replace all callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-17 12:04:11 +01:00