]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
5 years agobootstrap.conf: remove usage of snprintf gnulib module
Pavel Hrdina [Wed, 13 Nov 2019 16:33:25 +0000 (17:33 +0100)]
bootstrap.conf: remove usage of snprintf gnulib module

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agognulib: remove use of 'vsnprintf' module
Ján Tomko [Wed, 13 Nov 2019 13:18:18 +0000 (14:18 +0100)]
gnulib: remove use of 'vsnprintf' module

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agognulib: remove use of 'byteswap' module
Ján Tomko [Wed, 13 Nov 2019 13:17:31 +0000 (14:17 +0100)]
gnulib: remove use of 'byteswap' module

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agognulib: remove 'areadlink' module
Peter Krempa [Wed, 13 Nov 2019 13:16:42 +0000 (14:16 +0100)]
gnulib: remove 'areadlink' module

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: monitor: Remove non-transaction based dirty bitmap APIs
Peter Krempa [Thu, 26 Sep 2019 15:00:44 +0000 (17:00 +0200)]
qemu: monitor: Remove non-transaction based dirty bitmap APIs

We replaced them by use of transaction to simplify possible failure
scenarios.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: checkpoint: Fix rollback and access to unlocked 'vm' when deleting checkpoints
Peter Krempa [Thu, 26 Sep 2019 14:56:16 +0000 (16:56 +0200)]
qemu: checkpoint: Fix rollback and access to unlocked 'vm' when deleting checkpoints

Delete/merge bitmaps when deleting checkpoints using a 'transaction' so
that we don't have to deal with halfway-failed scenarios and also fix
access to 'vm' while in the monitor lock.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agotests: virschema: Propagate errors from directory traversal in testSchemaDir
Peter Krempa [Tue, 19 Nov 2019 10:55:05 +0000 (11:55 +0100)]
tests: virschema: Propagate errors from directory traversal in testSchemaDir

testSchemaDir is a helper which invokes the schema test using virTestRun
on all schema files. Since the function itself is not called inside
virTestRun any helper function call is not dispatched to the user and
thus it's hard to debug the test. Propagate errors from the directory
traversal.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: utils: Introduce helper for dispatching libvirt errors
Peter Krempa [Tue, 19 Nov 2019 10:52:40 +0000 (11:52 +0100)]
tests: utils: Introduce helper for dispatching libvirt errors

In cases when we call a libvirt helper which reports an error the error
would be hidden unless libvirt library debug is on. This produces a lot
of output and is hard to debug.

The helper provides a way to dispatch the libvirt error in specific
cases sice we do already dispatch it in case when virTestRun is used.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: schema: Simplify memory handling using g_autofree
Peter Krempa [Tue, 19 Nov 2019 10:16:34 +0000 (11:16 +0100)]
tests: schema: Simplify memory handling using g_autofree

Refactor various functions to avoid multiple freeing function calls.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agolib: fix documentation typo in virDomainGetGuestInfo()
Jonathon Jongsma [Tue, 19 Nov 2019 19:59:06 +0000 (13:59 -0600)]
lib: fix documentation typo in virDomainGetGuestInfo()

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
5 years agoremote_daemon_stream: Fix @client locking in daemonStreamFilter()
LanceLiu [Tue, 19 Nov 2019 11:39:50 +0000 (19:39 +0800)]
remote_daemon_stream: Fix @client locking in daemonStreamFilter()

When dispatching a message read from client it is first passed
through registered filters. If one of the filters consumes the
message no further processing of the message is done. However,
the filter callbacks are called with the client object locked.
This breaks lock ordering in case of virStream filter, we always
acquire stream private data lock without the client object
locked. In other words, the daemonStreamFilter() does not follow
the lock ordering.

Signed-off-by: LanceLiu <liu.lance.89@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: remove unneeded cleanup labels
Daniel Henrique Barboza [Tue, 12 Nov 2019 20:46:29 +0000 (17:46 -0300)]
tests: remove unneeded cleanup labels

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agovbox: remove unneeded cleanup labels
Daniel Henrique Barboza [Tue, 12 Nov 2019 20:46:28 +0000 (17:46 -0300)]
vbox: remove unneeded cleanup labels

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: remove unneeded cleanup labels
Daniel Henrique Barboza [Tue, 12 Nov 2019 20:46:27 +0000 (17:46 -0300)]
qemu: remove unneeded cleanup labels

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agonetwork: Check for QOS before blindly using it
John Ferlan [Tue, 12 Nov 2019 23:36:22 +0000 (18:36 -0500)]
network: Check for QOS before blindly using it

If networkAllocatePort calls networkPlugBandwidth eventually the
port->bandwidth would be passed to virNetDevBandwidthPlug which
requires that the parameter is non-NULL.  Coverity additionally
notes that since (!port->bandwidth) is checked earlier in the
networkAllocatePort method that the subsequent call to blindly
use if for a function that requires it needs to check.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agonetwork: Use local variables in networkUpdatePortBandwidth
John Ferlan [Tue, 12 Nov 2019 21:15:04 +0000 (16:15 -0500)]
network: Use local variables in networkUpdatePortBandwidth

We go through the trouble of checking {old|new}Bandwidth[->in] and
storing the result in local @old_floor and @new_floor, but then
we don't use them. Instead we make derefs to the longer name. This
caused Coverity to note dereferencing newBandwidth->in without first
checking @newBandwidth like was done for new_floor could cause a
NULL dereference.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoutil: Remove unnecessary check in virFileRewrite
John Ferlan [Tue, 12 Nov 2019 21:10:12 +0000 (16:10 -0500)]
util: Remove unnecessary check in virFileRewrite

Since g_strdup_printf will abort, we know @newfile won't be NULL.

Found by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemuProcessStop: Set @def early
Michal Privoznik [Mon, 18 Nov 2019 16:39:46 +0000 (17:39 +0100)]
qemuProcessStop: Set @def early

The @def variable holds pointer to the domain defintion, but is
set only somewhere in the middle of the function. This is
suboptimal.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agoAdd news for virDomainAgentSetResponseTimeout()
Jonathon Jongsma [Mon, 18 Nov 2019 22:38:49 +0000 (16:38 -0600)]
Add news for virDomainAgentSetResponseTimeout()

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agog_mkstemp_full: pass O_RDWR
Ján Tomko [Mon, 18 Nov 2019 16:45:54 +0000 (17:45 +0100)]
g_mkstemp_full: pass O_RDWR

This flag is not implied by g_mkstemp_full, only by g_mkstemp.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reported-by: Bjoern Walk <bwalk@linux.ibm.com>
Fixes: 4ac47730408eaf91683f6502ec10541f4f711a5c
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agobuild-aux: rewrite duplicate header checker in Python
Daniel P. Berrangé [Fri, 30 Aug 2019 12:22:54 +0000 (13:22 +0100)]
build-aux: rewrite duplicate header checker in Python

As part of an goal to eliminate Perl from libvirt build tools,
rewrite the prohibit-duplicate-header.pl tool in Python.

This was a straight conversion, manually going line-by-line to
change the syntax from Perl to Python. Thus the overall structure
of the file and approach is the same.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: Fix NULL ptr dereference caused by qemuDomainDefFormatBufInternal
Erik Skultety [Mon, 18 Nov 2019 12:46:14 +0000 (13:46 +0100)]
qemu: Fix NULL ptr dereference caused by qemuDomainDefFormatBufInternal

qemuDomainDefFormatBufInternal function wasn't testing whether the CPU
was actually defined in the XML and saving such a domain resulted in the
following backtrace:

0 in qemuDomainMakeCPUMigratable (cpu=0x0)
1 in qemuDomainDefFormatBufInternal()
2 in qemuDomainDefFormatXMLInternal()
3 in qemuDomainDefFormatLive()
4 in qemuDomainSaveInternal()
5 in qemuDomainSaveFlags()
6 in qemuDomainSave()
7 in virDomainSave()

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu_process: fix starting VMs if machine group has limited cpuset.cpus
Pavel Hrdina [Thu, 7 Nov 2019 21:23:04 +0000 (22:23 +0100)]
qemu_process: fix starting VMs if machine group has limited cpuset.cpus

Commit <f136b83139c63f20de0df3285d9e82df2fb97bfc> reworked process
affinity setting but did not take cgroups into account which introduced
an issue when starting VM with custom cpuset.cpus for the whole machine
group.

If the machine group is limited to some pCPUs libvirt should not try to
set a VM to run on all pCPUs as it will result in permission denied when
writing to cpuset.cpus.

To fix this the affinity has to be set separately from cgroups cpuset.

Resolves: <https://bugzilla.redhat.com/show_bug.cgi?id=1746517>

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agovirbpf: Fix typecast to __aligned_u64 type
Michal Privoznik [Mon, 18 Nov 2019 07:33:40 +0000 (08:33 +0100)]
virbpf: Fix typecast to __aligned_u64 type

In functions implemented here we fill this attr union (type of
bpf_attr) and just pass it to syscall(2). Thing is that some of
the union members are type of __aligned_u64. This is not regular
uint64_t. This one is explicitly aligned to 8 bytes, while
uint64_t can be aligned to 4 bytes (on 32 bits). We've used
explicit typecast to uint64_t to shut compiler which would
otherwise complain of assigning a pointer into an integer. Well,
we have uintptr_t just for that.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5 years agovircgroupv2devices: Fix format string for size_t variable
Michal Privoznik [Mon, 18 Nov 2019 07:10:15 +0000 (08:10 +0100)]
vircgroupv2devices: Fix format string for size_t variable

In virCgroupV2DevicesReallocMap() we are debug printing both
arguments passed to the function. However, the @size argument is
type of size_t but '%lu' is used to format it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5 years agonews: mention 'ramfb' mdev attribute
Jonathon Jongsma [Fri, 15 Nov 2019 15:58:52 +0000 (09:58 -0600)]
news: mention 'ramfb' mdev attribute

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
5 years agovirbpf: Check if syscall() is available
Michal Privoznik [Fri, 15 Nov 2019 15:08:51 +0000 (16:08 +0100)]
virbpf: Check if syscall() is available

There are some OSes which don't have syscall() nor
<sys/syscall.h>. We already check for the header file in
configure phase, so we just need to add check for
HAVE_SYS_SYSCALL_H to HAVE_DECL_BPF_PROG_QUERY.

While I'm at it, some header files we are including are not
needed, so their includes can be safely dropped.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5 years agospec: Remove build-time list of edk2 firmwares
Jim Fehlig [Thu, 14 Nov 2019 16:06:43 +0000 (09:06 -0700)]
spec: Remove build-time list of edk2 firmwares

Fedora now advertises supported firmwares via descriptor files.
Since the upstream spec file assumes recent Fedora, remove the
build-time list of firmwares, which can produce a warning after
commit 75597f022a.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoconf: validate video resolution
Jonathon Jongsma [Thu, 14 Nov 2019 21:59:17 +0000 (15:59 -0600)]
conf: validate video resolution

Ensure that both x and y are non-zero when resolution is specified for a
video device.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
5 years agoconf: report errors when parsing video acceleration
Jonathon Jongsma [Thu, 14 Nov 2019 21:59:16 +0000 (15:59 -0600)]
conf: report errors when parsing video acceleration

Since this function is now only called when an 'acceleration' element is
present in the xml, any failure to parse the element will be considered
an error.

Previously, we detected some types of errors, but we would only log an
error (virReportError()), but still return a partially-specified accel
object to the caller. This patch returns NULL for all parsing errors and
reports that error back up to the caller.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
5 years agoconf: report errors when parsing video resolution
Jonathon Jongsma [Thu, 14 Nov 2019 21:59:15 +0000 (15:59 -0600)]
conf: report errors when parsing video resolution

The current code doesn't properly handle errors when parsing a video
device's resolution.  We were returning a NULL structure for the case
where 'x' or 'y' were missing. But for the other error cases, we were
logging an error (virReportError()), but still returning an
under-specified structure. That under-specified structure was used by
the calling function rather than properly reporting an error.

This patch changes the parse function to return NULL on any parsing
error and changes the calling function to report an error when NULL is
returned.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
5 years agoconf: iterate video model children in parent function
Jonathon Jongsma [Thu, 14 Nov 2019 21:59:14 +0000 (15:59 -0600)]
conf: iterate video model children in parent function

Previously, we were passing the video "model" node to the "acceleration"
and "resolution" parsing functions and requiring them to iterate over
the children to discover and parse the appropriate node. It makes more
sense to move this responsibility up to the parent function and just
pass these functions the node that needs to be parsed.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
5 years agovircgroup: Ensure /machine group is associated with its parent
Miguel Ángel Arruga Vivas [Mon, 4 Nov 2019 14:55:23 +0000 (15:55 +0100)]
vircgroup: Ensure /machine group is associated with its parent

Call first virCgroupNew on the parent group virCgroupNewPartition if
it is available on before the creation of the child group.  This
ensures that the creation of a first level group on the unified
architecture, as the check at virCgroupV2ParseControllersFile as the
parent file is there.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1760233
Signed-off-by: Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agodoc: cgroups: Remove unwanted references to systemd
Miguel Ángel Arruga Vivas [Mon, 4 Nov 2019 14:55:22 +0000 (15:55 +0100)]
doc: cgroups: Remove unwanted references to systemd

The non-systemd configurations do not create system neither user
control groups.  The title of the diagram referenced systemd too.

Signed-off-by: Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoAllow a zfs pool or dataset as source for zfs storage backend
Gregor Kopka [Thu, 7 Nov 2019 04:03:14 +0000 (04:03 +0000)]
Allow a zfs pool or dataset as source for zfs storage backend

Enables hosting a pool on an existing zfs pool without affecting
other datasets there.
Specify dataset instead of pool as source to use.
Parent of dataset must exist for pool-build to succeed.
Beware that pool-delete destroys the source dataset and all children.

Solves: https://www.redhat.com/archives/libvirt-users/2017-April/msg00041.html

Signed-off-by: Gregor Kopka <gregor@kopka.net>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoreplace use of gnulib snprintf by g_snprintf
Pavel Hrdina [Wed, 13 Nov 2019 13:53:42 +0000 (14:53 +0100)]
replace use of gnulib snprintf by g_snprintf

Glib implementation follows the ISO C99 standard so it's safe to replace
the gnulib implementation.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agovircgroupmock: mock virCgroupV2DevicesAvailable
Pavel Hrdina [Mon, 24 Jun 2019 13:13:37 +0000 (15:13 +0200)]
vircgroupmock: mock virCgroupV2DevicesAvailable

We need to mock virCgroupV2DevicesAvailable() in order to remove any
dependency on kernel as BPF devices might not be available.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: workaround devices in hybrid mode
Pavel Hrdina [Thu, 14 Nov 2019 10:44:42 +0000 (11:44 +0100)]
vircgroup: workaround devices in hybrid mode

So the issue here is that you can end up with configuration where
you have cgroup v1 and v2 enabled at the same time and the devices
controllers is enabled for cgroup v1.

In cgroup v2 there is no devices controller, the device access is
controlled using BPF and since it is not a cgroup controller both
of them can exists at the same time and both of them are applied while
resolving access to devices.

In order to avoid configuring both BPF and cgroup v1 devices we will
use BPF if possible and otherwise fallback to cgroup v1 devices.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2DenyAllDevices
Pavel Hrdina [Fri, 11 Jan 2019 13:56:48 +0000 (14:56 +0100)]
vircgroup: introduce virCgroupV2DenyAllDevices

If we want to deny all devices we just need to replace any existing
program with new program with empty map.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2AllowAllDevices
Pavel Hrdina [Fri, 11 Jan 2019 13:56:17 +0000 (14:56 +0100)]
vircgroup: introduce virCgroupV2AllowAllDevices

If we want to allow all devices with all permissions we need to replace
any existing program that has any rule configured, otherwise we just
need to add new rule which will for example allow read access to all
devices.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2DenyDevice
Pavel Hrdina [Fri, 11 Jan 2019 13:55:49 +0000 (14:55 +0100)]
vircgroup: introduce virCgroupV2DenyDevice

In order to deny device we need to check if there is any entry in BPF
map and we need to load the current value from map if there is already
entry for that device.  If both values are same we can remove that entry
but if they are different we need to update the entry because we don't
have to deny all access, but for example only write access.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2AllowDevice
Pavel Hrdina [Wed, 24 Apr 2019 10:10:08 +0000 (12:10 +0200)]
vircgroup: introduce virCgroupV2AllowDevice

In order to allow device we need to create key and value which will be
used to update BPF map.  virBPFUpdateElem() can override existing
entries in BPF map so we need to check if that entry exists in order to
track number of entries in our map.

This can add rule for specific device but major and minor can be both
-1 which follows the same behavior as in cgroup v1.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2DevicesGetKey
Pavel Hrdina [Mon, 24 Jun 2019 12:46:53 +0000 (14:46 +0200)]
vircgroup: introduce virCgroupV2DevicesGetKey

Device rules are stored in BPF map that is a hash type, this function
will create a key based on major and minor id of device.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2DeviceGetPerms
Pavel Hrdina [Mon, 24 Jun 2019 12:41:50 +0000 (14:41 +0200)]
vircgroup: introduce virCgroupV2DeviceGetPerms

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2DevicesRemoveProg
Pavel Hrdina [Mon, 24 Jun 2019 12:39:23 +0000 (14:39 +0200)]
vircgroup: introduce virCgroupV2DevicesRemoveProg

We need to close our FD that we have for BPF program and map in order
to let kernel remove all resources once the cgroup is removed as well.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2DevicesPrepareProg
Pavel Hrdina [Mon, 24 Jun 2019 12:34:51 +0000 (14:34 +0200)]
vircgroup: introduce virCgroupV2DevicesPrepareProg

This function will be called for every virCgroup(Allow|Deny)* API in
order to prepare BPF program for guest.  Since libvirtd can be restarted
at any point we will first try to detect existing progam, if there is
none we will create a new empty BPF program and lastly if we don't have
any space left in the existing BPF map we will create a new copy of the
BPF map with more space and attach a new program with that map into the
guest cgroup.

This solution allows us to start with reasonably small BPF map consuming
only small amount of memory and if needed we can easily extend the BPF
map if there is a lot of host devices used in guest or if user wants to
hot-plug a lot of devices once the guest is running.

Since there is no way how to reallocate existing BPF map we need to
create a new copy if we run out of space in current BPF map.

This overcomes all the limitations in BPF:

    - map used in program has to be created before the program is loaded
      into kernel

    - once map is created you cannot change its size

    - you cannot replace map in existing program

    - you cannot use an array of maps because it can store FD to maps
      of one specific size so we would not be able to use it to overcome
      the second issue

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2DevicesCreateProg
Pavel Hrdina [Mon, 24 Jun 2019 12:30:59 +0000 (14:30 +0200)]
vircgroup: introduce virCgroupV2DevicesCreateProg

This function creates new BPF program with new empty BPF map with the
default size and attaches it to the guest cgroup.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2DevicesDetectProg
Pavel Hrdina [Mon, 24 Jun 2019 12:25:04 +0000 (14:25 +0200)]
vircgroup: introduce virCgroupV2DevicesDetectProg

This function will be called if libvirtd was restarted while some
domains were running.  It will try to detect existing programs attached
to the guest cgroup.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2DevicesAttachProg
Pavel Hrdina [Mon, 24 Jun 2019 12:15:31 +0000 (14:15 +0200)]
vircgroup: introduce virCgroupV2DevicesAttachProg

This function loads the BPF prog with prepared map into kernel and
attaches it into guest cgroup.  It can be also used to replace existing
program in the cgroup if we need to resize BPF map to store more rules
for devices. The old program will be closed and removed from kernel.

There are two possible ways how to create BPF program:

    - One way is to write simple C-like code which can by compiled into
      BPF object file which can be loaded into kernel using elfutils.

    - The second way is to define macros which look like assembler
      instructions and can be used directly to create BPF program that
      can be directly loaded into kernel.

Since the program is not too complex we can use the second option.

If there is no program, all devices are allowed, if there is some
program it is executed and based on the exit status the access is
denied for 0 and allowed for 1.

Our program will follow these rules:

    - first it will try to look for the specific key using major and
      minor to see if there is any rule for that specific device

    - if there is no specific rule it will try to look for any rule that
      matches only major of the device

    - if there is no match with major it will try the same but with
      minor of the device

    - as the last attempt it will try to look for rule for all devices
      and if there is no match it will return 0 to deny that access

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovircgroup: introduce virCgroupV2DevicesAvailable
Pavel Hrdina [Mon, 9 Sep 2019 07:40:06 +0000 (09:40 +0200)]
vircgroup: introduce virCgroupV2DevicesAvailable

There is no exact way how to figure out whether BPF devices support is
compiled into kernel.  One way is to check kernel configure options but
this is not reliable as it may not be available.  Let's try to do
syscall to which will list BPF cgroup device programs.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoutil: introduce virbpf helpers
Pavel Hrdina [Mon, 9 Sep 2019 07:37:32 +0000 (09:37 +0200)]
util: introduce virbpf helpers

In order to implement devices controller with cgroup v2 we need to
add support for BPF programs, cgroup v2 doesn't have devices controller.

This introduces required helpers wrapping linux syscalls.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agotests: Mock access to /dev/kvm
Michal Privoznik [Fri, 15 Nov 2019 10:56:46 +0000 (11:56 +0100)]
tests: Mock access to /dev/kvm

Some of our tests try to validate domain XMLs they are working
with (not intentionally, simply because they call top level
domain XML parse function). Anyway, this implies that we build
domain capabilities also - see
virQEMUDriverGetDomainCapabilities(). And since some domain XMLs
are type of 'kvm' the control gets through
virQEMUCapsFillDomainCaps() and virHostCPUGetKVMMaxVCPUs() to
opening /dev/kvm which may be missing on the machine we're
running 'make check'.

Previously, we did not see this issue, because it was masked. If
building domain capabilities failed for whatever reason, we
ignored the failure. Only v5.9.0-207-gc69e6edea3 uncovered the
problem (it changed reval from 0 to -1 if
virQEMUDriverGetDomainCapabilities() fails). Since the referenced
commit is correct, we need to mock access to /dev/kvm in our
tests.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5 years agovirsh: Fix typo in the man page
Jiri Denemark [Fri, 15 Nov 2019 08:34:20 +0000 (09:34 +0100)]
virsh: Fix typo in the man page

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
5 years agoAdd API to change qemu agent response timeout
Jonathon Jongsma [Wed, 13 Nov 2019 22:06:09 +0000 (16:06 -0600)]
Add API to change qemu agent response timeout

Some layered products such as oVirt have requested a way to avoid being
blocked by guest agent commands when querying a loaded vm. For example,
many guest agent commands are polled periodically to monitor changes,
and rather than blocking the calling process, they'd prefer to simply
time out when an agent query is taking too long.

This patch adds a way for the user to specify a custom agent timeout
that is applied to all agent commands.

One special case to note here is the 'guest-sync' command. 'guest-sync'
is issued internally prior to calling any other command. (For example,
when libvirt wants to call 'guest-get-fsinfo', we first call
'guest-sync' and then call 'guest-get-fsinfo').

Previously, the 'guest-sync' command used a 5-second timeout
(VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT), whereas the actual command that
followed always blocked indefinitely
(VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK). As part of this patch, if a
custom timeout is specified that is shorter than
5 seconds,  this new timeout is also used for 'guest-sync'. If there is
no custom timeout or if the custom timeout is longer than 5 seconds, we
will continue to use the 5-second timeout.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agosyntax-check: prefer g_mkstemp_full and g_mkdtemp
Ján Tomko [Thu, 14 Nov 2019 13:44:24 +0000 (14:44 +0100)]
syntax-check: prefer g_mkstemp_full and g_mkdtemp

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoUse g_mkdtemp instead of mkdtemp
Ján Tomko [Wed, 13 Nov 2019 21:35:47 +0000 (22:35 +0100)]
Use g_mkdtemp instead of mkdtemp

Prefer the GLib version to the one from gnulib.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoUse g_mkstemp_full instead of mkostemp(s)
Ján Tomko [Wed, 13 Nov 2019 21:30:26 +0000 (22:30 +0100)]
Use g_mkstemp_full instead of mkostemp(s)

With g_mkstemp_full, there is no need to distinguish between
mkostemp and mkostemps (no suffix vs. a suffix of a fixed length),
because the GLib function looks for the XXXXXX pattern everywhere
in the string.

Use S_IRUSR | S_IWUSR for the permissions and do not pass O_RDWR
in flags since it's implied.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agotests: use GRegex in vboxsnapshotxmltest
Ján Tomko [Wed, 13 Nov 2019 15:06:45 +0000 (16:06 +0100)]
tests: use GRegex in vboxsnapshotxmltest

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoutil: use GRegex in virStringMatch
Ján Tomko [Wed, 13 Nov 2019 15:01:19 +0000 (16:01 +0100)]
util: use GRegex in virStringMatch

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoutil: use GRegex in virStringSearch
Ján Tomko [Wed, 13 Nov 2019 14:54:43 +0000 (15:54 +0100)]
util: use GRegex in virStringSearch

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoutil: use GRegex for virLogRegex
Ján Tomko [Wed, 13 Nov 2019 14:38:58 +0000 (15:38 +0100)]
util: use GRegex for virLogRegex

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoutil: use GRegex in virCommandRunRegex
Ján Tomko [Wed, 13 Nov 2019 14:09:28 +0000 (15:09 +0100)]
util: use GRegex in virCommandRunRegex

This saves us from allocating vars upfront, since GLib deals with
that for us.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agostorage: use GRegex virStorageBackendLogicalParseVolExtents
Ján Tomko [Wed, 13 Nov 2019 13:32:19 +0000 (14:32 +0100)]
storage: use GRegex virStorageBackendLogicalParseVolExtents

Using GRegex simplifies the code since g_match_info_fetch will
copy the matched substring for us.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agolibxl: remove 'ret' from xenParseSxprVifRate
Ján Tomko [Wed, 13 Nov 2019 12:09:11 +0000 (13:09 +0100)]
libxl: remove 'ret' from xenParseSxprVifRate

Now that the cleanup section is empty, the ret variable is no longer
necessary.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agolibxl: use GRegex in xenParseSxprVifRate
Ján Tomko [Wed, 13 Nov 2019 12:08:14 +0000 (13:08 +0100)]
libxl: use GRegex in xenParseSxprVifRate

Use GRegex from GLib instead of regcomp.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agolibxl: use g_autofree in xenParseSxprVifRate
Ján Tomko [Wed, 13 Nov 2019 11:59:29 +0000 (12:59 +0100)]
libxl: use g_autofree in xenParseSxprVifRate

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agolibxl: use GRegex in libxlGetAutoballoonConf
Ján Tomko [Wed, 13 Nov 2019 11:59:55 +0000 (12:59 +0100)]
libxl: use GRegex in libxlGetAutoballoonConf

Replace the use of regcomp with GRegex.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoremove unused regex.h includes
Ján Tomko [Wed, 13 Nov 2019 15:10:50 +0000 (16:10 +0100)]
remove unused regex.h includes

The code using regexes got moved, but the include stayed.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agolibxl: do not use G_REGEX_EXTENDED
Ján Tomko [Wed, 13 Nov 2019 15:44:12 +0000 (16:44 +0100)]
libxl: do not use G_REGEX_EXTENDED

This flag is not needed to use extended regular expression syntax
with GRegex and it makes GRegex ignore whitespace in the regex.

Remove the unintended usage, even though it should not matter in this
case.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoqemu: add 'ramfb' attribute for mediated devices
Jonathon Jongsma [Fri, 18 Oct 2019 15:30:17 +0000 (10:30 -0500)]
qemu: add 'ramfb' attribute for mediated devices

The 'ramfb' attribute provides a framebuffer to the guest that can be
used as a boot display for the vgpu

For example, the following configuration can be used to provide a vgpu
with a boot display:

    <hostdev mode='subsystem' type='mdev' model='vfio-pci' display='on' ramfb='on'>
        <source>
            <address uuid='$UUID'/>
        </source>
    </hostdev>

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
5 years agoqemu: use domain caps to validate video device model
Jonathon Jongsma [Fri, 18 Oct 2019 15:30:16 +0000 (10:30 -0500)]
qemu: use domain caps to validate video device model

As suggested by Cole, this patch uses the domain capabilities to
validate the supported video model types. This allows us to remove the
model type validation from qemu_process.c and qemu_domain.c and
consolidates it all in a single place that will automatically adjust
when new domain capabilities are added.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
5 years agoqemu: move validation of video accel to qemu_domain.c
Jonathon Jongsma [Fri, 18 Oct 2019 15:30:15 +0000 (10:30 -0500)]
qemu: move validation of video accel to qemu_domain.c

Continue consolidation of video device validation started in previous
patch.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
5 years agoqemu: validate vhost-user video backend in qemu_domain.c
Jonathon Jongsma [Fri, 18 Oct 2019 15:30:14 +0000 (10:30 -0500)]
qemu: validate vhost-user video backend in qemu_domain.c

The goal is to move all of the video device validation to a single place
and use domain caps to validate the supported video device models. Since
qemuDomainDeviceDefValidateVideo() is called from
qemuProcessStartValidate(), these changes should not change anny
behavior.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
5 years agoqemu: set domain capability for video type "none"
Jonathon Jongsma [Fri, 18 Oct 2019 15:30:13 +0000 (10:30 -0500)]
qemu: set domain capability for video type "none"

In a follow-up commit, we will use the domain capabilities to validate
video device configurations, which means that we also need to make sure
that the domain capabilities include the "none" video device.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
5 years agoqemu: set domain capability for ramfb device
Jonathon Jongsma [Fri, 18 Oct 2019 15:30:12 +0000 (10:30 -0500)]
qemu: set domain capability for ramfb device

commit 9bfcf0f62d9cf16db526a948242a7409ae883209 added the
QEMU_CAPS_DEVICE_RAMFB capability but did not set the domain capability.
This patch sets the domain capability for the ramfb device and updates
the tests.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
5 years agoqemu: Set capabilities properly for tests
Jonathon Jongsma [Fri, 18 Oct 2019 15:30:11 +0000 (10:30 -0500)]
qemu: Set capabilities properly for tests

Several tests were not specifying the necessary qemu capabilities for
what they were testing. Due to the way that the video devices are
currently validated, this is not causing any problems. But a change to
video device validation in a following patch would have exposed this
issue and resulted in multiple test failures about the domain
configuration not supporting particular video models.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
5 years agoqemu: use g_autoptr in qemuDomainDeviceDefValidate()
Jonathon Jongsma [Fri, 18 Oct 2019 15:30:10 +0000 (10:30 -0500)]
qemu: use g_autoptr in qemuDomainDeviceDefValidate()

This allows us to simplify the function and avoid jumping to 'cleanup'.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
5 years agoqemu: fix domain device validation
Jonathon Jongsma [Fri, 18 Oct 2019 15:30:09 +0000 (10:30 -0500)]
qemu: fix domain device validation

When the virDomainCapsDeviceDefValidate() function returned an error
status (-1), we were aborting the function early, but returning the
default return value (0). This patch properly returns an error in that
case.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
5 years agolibxl: Fix lock manager lock ordering
Jim Fehlig [Mon, 14 Oct 2019 20:01:00 +0000 (14:01 -0600)]
libxl: Fix lock manager lock ordering

The ordering of lock manager locks in the libxl driver has a flaw that was
uncovered by a migration error path. In the perform phase of migration, the
source host calls virDomainLockProcessPause to release the lock before
sending the VM to the destination host. If the send fails an attempt is made
to reacquire the lock with virDomainLockProcessResume, but that too can fail
if the destination host has not finished cleaning up the failed VM and
releasing the lock it acquired when starting to receive the VM.

This change delays calling virDomainLockProcessResume in libxlDomainStart
until the VM is successfully created, but before it is unpaused. A similar
approach is used by the qemu driver, avoiding the need to release the lock
if VM creation fails. In the migration perform phase, releasing the lock
with virDomainLockProcessPause is delayed until the VM is successfully
sent to the destination, which avoids reacquiring the lock if the send
fails.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: hotplug: remove unused cleanup labels
Daniel Henrique Barboza [Thu, 17 Oct 2019 15:44:02 +0000 (12:44 -0300)]
qemu: hotplug: remove unused cleanup labels

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: hotplug: use g_autoptr() with virConnectPtr
Daniel Henrique Barboza [Thu, 17 Oct 2019 15:44:01 +0000 (12:44 -0300)]
qemu: hotplug: use g_autoptr() with virConnectPtr

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agovirhostuptime: Wrap virHostGetBootTimeProcfs() call in an ifdef
Michal Privoznik [Thu, 14 Nov 2019 15:42:51 +0000 (16:42 +0100)]
virhostuptime: Wrap virHostGetBootTimeProcfs() call in an ifdef

The virHostGetBootTimeProcfs() function is defined only for Linux
and therefore it's only call should also be done if we're on
Linux.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: domcaps: Simplify adding new domaincaps based on qemu caps
Peter Krempa [Wed, 30 Oct 2019 15:40:03 +0000 (16:40 +0100)]
qemu: domcaps: Simplify adding new domaincaps based on qemu caps

Add a helper which converts qemu emulator capabilities to the domain
capability XML. This will simplify future additions of new features.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agodomaincaps: Store domain capability features in an array
Peter Krempa [Wed, 13 Nov 2019 15:34:11 +0000 (16:34 +0100)]
domaincaps: Store domain capability features in an array

Declare the capabilities as enum values and store them in an array. This
makes adding new features more straightforward and simplifies the
formatter which now doesn't require changing.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: domcaps: Initialize all features
Peter Krempa [Wed, 13 Nov 2019 15:32:21 +0000 (16:32 +0100)]
qemu: domcaps: Initialize all features

While the qemu driver currently implements all domain capability
features, we should initialize all features using the helper similarly
to how we do it in drivers which don't support any.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agodomcaps: Add function for initializing domain caps as unsupported
Peter Krempa [Wed, 13 Nov 2019 15:10:45 +0000 (16:10 +0100)]
domcaps: Add function for initializing domain caps as unsupported

For future extensions of the domain caps it's useful to have a single
point that initializes all capabilities as unsupported by a driver. The
driver then can enable specific ones.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoconf: domaincaps: Use virXMLFormatElement in virDomainCapsFormatFeatures
Peter Krempa [Wed, 30 Oct 2019 14:01:07 +0000 (15:01 +0100)]
conf: domaincaps: Use virXMLFormatElement in virDomainCapsFormatFeatures

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoconf: domaincaps: Extract formatting of the <features> subelement
Peter Krempa [Wed, 30 Oct 2019 13:58:40 +0000 (14:58 +0100)]
conf: domaincaps: Extract formatting of the <features> subelement

Extract it to virDomainCapsFormatFeatures so that the main function does
not get so bloated over time.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoconf: domaincaps: Replace FORMAT_SINGLE macro by a function
Peter Krempa [Wed, 30 Oct 2019 13:53:31 +0000 (14:53 +0100)]
conf: domaincaps: Replace FORMAT_SINGLE macro by a function

Introduce qemuDomainCapsFeatureFormatSimple which does exactly the same
thing but it's a function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoutil: file: Replace use of 'strsep' with virStringSplit
Peter Krempa [Thu, 14 Nov 2019 09:25:31 +0000 (10:25 +0100)]
util: file: Replace use of 'strsep' with virStringSplit

Use our helper instead of the gnulib one.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoutil: file: Use more obvious logic in virFindFileInPath
Peter Krempa [Thu, 14 Nov 2019 09:16:54 +0000 (10:16 +0100)]
util: file: Use more obvious logic in virFindFileInPath

Make it more obvious that the function will return NULL if the file is
not executable and stop reusing variables.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoutil: file: Use g_autofree in virFindFileInPath
Peter Krempa [Thu, 14 Nov 2019 09:05:06 +0000 (10:05 +0100)]
util: file: Use g_autofree in virFindFileInPath

Simplify the final lookup loop by freeing memory automatically and thus
being able to directly return the result.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agorpc: use virStringSplit instead of strsep
Peter Krempa [Thu, 14 Nov 2019 08:59:52 +0000 (09:59 +0100)]
rpc: use virStringSplit instead of strsep

When parsing allowed authentication methods for the native ssh lib
transports we used strsep. Since we have virStringSplit helper let's use
that one.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirhostuptime: Add linux stub for musl
Michal Privoznik [Mon, 14 Oct 2019 14:37:03 +0000 (16:37 +0200)]
virhostuptime: Add linux stub for musl

When we want to know the boot timestamp of the host, we can call
virHostGetBootTime(). Under the hood, it uses getutxid() which is
defined by POSIX and properly check for in configure. However,
musl took a path where it declares the function but instead of
providing any useful implementation it returns NULL meaning "no
record found". If that's the case, use our second best option -
/proc/uptime and a bit of maths.

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

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoconf: Drop nameLen parameter from virDomainCapsCPUModelsAdd
Jiri Denemark [Thu, 19 Sep 2019 14:10:14 +0000 (16:10 +0200)]
conf: Drop nameLen parameter from virDomainCapsCPUModelsAdd

All callers use nameLen == -1 anyway.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoconf: Use VIR_AUTO* in virDomainCapsCPUModelsAdd
Jiri Denemark [Thu, 19 Sep 2019 14:04:56 +0000 (16:04 +0200)]
conf: Use VIR_AUTO* in virDomainCapsCPUModelsAdd

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agodocs: mention lifted vCPUs restriction for esx
Pino Toscano [Wed, 13 Nov 2019 12:57:34 +0000 (13:57 +0100)]
docs: mention lifted vCPUs restriction for esx

It was lifted with c92b6023e8eb670e01571e299a85e9da9bd4844c.

Signed-off-by: Pino Toscano <ptoscano@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: cold-plug of sound
Jidong Xia [Tue, 15 Oct 2019 06:41:27 +0000 (14:41 +0800)]
qemu: cold-plug of sound

With this patch users can cold plug some sound devices.
use "virsh attach-device vm sound.xml --config" command.
Consider the following sound.xml for a domain:
    <sound model='ich6'>
         <address type='pci' domain='0x0000' bus='0x00' slot='xxx' function='0'/>
    </sound>

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jidong Xia <xiajidong@cmss.chinamobile.com>
5 years agoqemu/qemu_migration_params: use virStringParseYesNo helper
Mao Zhongyi [Thu, 17 Oct 2019 03:19:33 +0000 (11:19 +0800)]
qemu/qemu_migration_params: use virStringParseYesNo helper

A function virStringParseYesNo was added to convert
string 'yes' to true and 'no' to false, so use this
helper to replace 'STREQ(.*, \"yes\")' and
'STREQ(.*, \"no\")' as it allows us to drop several
repetitive if-then-else string->bool conversion blocks.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Mao Zhongyi <maozhongyi@cmss.chinamobile.com>
Signed-off-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>
5 years agoconf/network_conf: use virStringParseYesNo helper
Mao Zhongyi [Thu, 17 Oct 2019 03:19:32 +0000 (11:19 +0800)]
conf/network_conf: use virStringParseYesNo helper

A function virStringParseYesNo was added to convert
string 'yes' to true and 'no' to false, so use this
helper to replace 'STREQ(.*, \"yes\")' and
'STREQ(.*, \"no\")' as it allows us to drop several
repetitive if-then-else string->bool conversion blocks.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Mao Zhongyi <maozhongyi@cmss.chinamobile.com>
Signed-off-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>
Acked-by: Michal Privoznik <mprivozn@redhat.com>