Commit Graph

18750 Commits

Author SHA1 Message Date
Jiri Denemark
14aeba2dfd cpu_x86: Introduce virCPUx86DataAddFeature
The API is useful for creating virCPUData in a hypervisor driver from
data we got by querying the hypervisor.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-02-24 14:10:57 +01:00
Jiri Denemark
8da3ca8419 cpu_x86: Introduce virCPUx86DataSetVendor
The API is useful for creating virCPUData in a hypervisor driver from
data we got by querying the hypervisor.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-02-24 14:10:57 +01:00
Jiri Denemark
f358a75ab3 cpu_x86: Introduce virCPUx86DataSetSignature
The API is useful for creating virCPUData in a hypervisor driver from
data we got by querying the hypervisor.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-02-24 14:10:57 +01:00
Jiri Denemark
d3f831a97a cpu_x86: Make virCPUx86DataAddCPUID work with virCPUDataPtr
The CPU driver provides APIs to create and free virCPUDataPtr. Thus all
APIs exported from the driver should work with that rather than
requiring the caller to pass a pointer to an internal part of the
structure.

In other words

    virCPUx86DataAddCPUID(cpudata, &cpuid)

is much better than the original

    virCPUx86DataAddCPUID(&cpudata->data.x86, &cpuid)

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-02-24 14:10:57 +01:00
Jiri Denemark
f6d55a5f42 cpu: Rework cpuDataFree
The new API is called virCPUDataFree. Individual CPU drivers are no
longer required to implement their own freeing function unless they need
to free architecture specific data from virCPUData.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-02-24 14:10:57 +01:00
Jiri Denemark
5acdd4a6b4 cpu_x86: Make virCPUx86DataClear static
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-02-24 14:10:57 +01:00
Jiri Denemark
035d81b10a cpu_x86: Drop virCPUx86MakeData and use virCPUDataNew
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-02-24 14:10:57 +01:00
Jiri Denemark
390a1e2bfd qemu: Fix CPU model fallback in domain capabilities
Our documentation of the domain capabilities XML says that the fallback
attribute of a CPU model is used to indicate whether the CPU model was
detected by libvirt itself (fallback="allow") or by asking the
hypervisor (fallback="forbid"). We need to properly set
fallback="forbid" when CPU model comes from QEMU to match the
documentation.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-02-24 14:10:57 +01:00
Jiri Denemark
bd440735e3 qemu: Refactor virQEMUCapsInitHostCPUModel
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-02-24 14:10:57 +01:00
Pavel Hrdina
824272cb28 qemu: properly escape socket path for graphics
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1352529

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-02-24 12:58:51 +01:00
Pavel Hrdina
22b02f4492 util: virqemu: introduce virQEMUBuildBufferEscape
This will eventually replace virQEMUBuildBufferEscapeComma, however
it's not possible right now.  Some parts of the code that uses the
old function needs to be refactored.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-02-24 12:58:48 +01:00
Pavel Hrdina
726403461b util: virbuffer: introduce virBufferEscapeN
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-02-24 12:58:23 +01:00
Pavel Hrdina
c23b7b81db qemu_process: spice: don't release used port
The port is stored in graphics configuration and it will
also get released in qemuProcessStop in case of error.

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-02-24 09:58:10 +01:00
Peter Krempa
c3de387380 qemu: Don't update physical storage size of empty drives
Previously the code called virStorageSourceUpdateBlockPhysicalSize which
did not do anything on empty drives since it worked only on block
devices. After the refactor in c5f6151390 it's called for all devices
and thus attempts to deref the NULL path of empty drives.

Add a check that skips the update of the physical size if the storage
source is empty.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1420718
2017-02-24 09:19:54 +01:00
Marc Hartmayer
eca76884ea qemu: Fix incorrect jump labels in error paths
Fix incorrect jump labels in error paths as the stop jump is only
needed if the driver has already changed the state. For example
'virAtomicIntInc(&driver->nactive)' will be 'reverted' in the
qemuProcessStop call.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-02-23 15:32:45 +01:00
Michal Privoznik
3cddd63aec qemu_cgroup: Only try to allow devices if devices CGroup's available
When a domain needs an access to some device (be it a disk, RNG,
chardev, whatever), we have to allow it in the devices CGroup (if
it is available), because by default we disallow all the devices.
But some of the functions that are responsible for setting up
devices CGroup are lacking check whether there is any CGroup
available. Thus users might be unable to hotplug some devices:

  virsh # attach-device fedora rng.xml
  error: Failed to attach device from rng.xml
  error: internal error: Controller 'devices' is not mounted

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-02-23 11:21:26 +01:00
Daniel P. Berrange
5d84f5961b Add ATTRIBUTE_FALLTHROUGH for switch cases without break
In GCC 7 there is a new warning triggered when a switch
case has a conditional statement (eg if ... else...) and
some of the code paths fallthrough to the next switch
statement. e.g.

conf/domain_conf.c: In function 'virDomainChrEquals':
conf/domain_conf.c:14926:12: error: this statement may fall through [-Werror=implicit-fallthrough=]
         if (src->targetTypeAttr != tgt->targetTypeAttr)
            ^
conf/domain_conf.c:14928:5: note: here
     case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
     ^~~~
conf/domain_conf.c: In function 'virDomainChrDefFormat':
conf/domain_conf.c:22143:12: error: this statement may fall through [-Werror=implicit-fallthrough=]
         if (def->targetTypeAttr) {
            ^
conf/domain_conf.c:22151:5: note: here
     default:
     ^~~~~~~

GCC introduced a __attribute__((fallthrough)) to let you
indicate that this is intentionale behaviour rather than
a bug.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-02-23 10:11:16 +00:00
Daniel P. Berrange
fb52faf8fa qemu: add missing break in qemuDomainDeviceCalculatePCIConnectFlags
One of the conditions in qemuDomainDeviceCalculatePCIConnectFlags
was missing a break that could result it in falling through to
an incorrect codepath.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-02-23 10:11:16 +00:00
Daniel P. Berrange
dd08d9ffe8 libxl: fix empty string check for channel path
The libxl code was checking that a 'char *' was != '\0', instead
of checking the first element in the string

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-02-23 10:11:16 +00:00
Daniel P. Berrange
09db97d3cb Use explicit boolean comparison in OOM check
GCC 7 gets upset by

   if (!tmp && (size * count))

warning

  util/viralloc.c: In function 'virReallocN':
  util/viralloc.c:246:23: error: '*' in boolean context, suggest '&&' instead [-Werror=int-in-bool-context]
     if (!tmp && (size * count)) {
                 ~~~~~~^~~~~~~~

Keep it happy by adding != 0 to the right hand expression
so it realizes we really are wanting to treat the result
of the arithmetic expression as a boolean

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-02-23 10:11:16 +00:00
Nikolay Shirokovskiy
0518aae304 vz: make more accurate closing connection to sdk
Current code for example can call unsubscribe if connection
succeeds but subscribing fails. This will probabaly lead
only to spurious error messages without any actual inconsistencies
but nevertheless.
2017-02-23 10:04:00 +01:00
Andrea Bolognani
011d546504 qemu: Allow multiple bridges when pci-bridges is not available
qemuDomainAssignPCIAddresses() hardcoded the assumption
that the only way to support devices on a non-zero bus is
to add one or more pci-bridges; however, since we now
support a large selection of PCI controllers that can be
used instead, the assumption is no longer true.

Moreover, this check was always redundant, because the
only sensible time to check for the availability of
pci-bridge is when building the QEMU command line, and
such a check is of course already in place.

In fact, there were *two* such checks, but since one of
the two was relying on the incorrect assumption explained
above, and it was redundant anyway, it has been dropped.
2017-02-22 18:55:55 +01:00
Andrea Bolognani
77edbf5127 conf: Make switch statements more strict
When switching over the values in the virDomainControllerModelPCI
enumeration, make sure the proper cast is in place so that the
compiler can warn us when the coverage is not exaustive.

For the same reason, remove the 'default' case from one of the
existing switch statements.
2017-02-22 18:55:55 +01:00
Andrea Bolognani
50d3595390 qemu: Make switch statements more strict
When switching over the values in the virDomainControllerModelPCI
enumeration, make sure the proper cast is in place so that the
compiler can warn us when the coverage is not exaustive.

For the same reason, fold some unstructured checks (performed by
comparing directly against some values in the enumeration) inside
an existing switch statement.
2017-02-22 18:55:55 +01:00
Andrea Bolognani
c6a0fb8e71 conf: Remove dead code
The switch in virDomainPCIControllerModelToConnectType()
had some code that, while techically part of the
_PCIE_SWITCH_DOWNSTREAM_PORT case, was in fact dead due
to the early return.

Get rid of the dead code, and fix the inaccurate function
description while at it.
2017-02-22 18:55:54 +01:00
John Ferlan
75ba06e44a qemu: Rename qemuAliasTLSObjFromChardevAlias
It's not really 'Chardev' specific - we can reuse this for other objects.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-02-22 06:31:40 -05:00
Jiri Denemark
82ddd0b155 cpu: Use virCPUData.arch in cpuDecode
virCPUDef.arch is not required to be filled in for guest CPU
definitions. It doesn't make sense to artificially mandate it to be set
when cpuDecode is called especially when virCPUData.arch passed to
cpuDecode already contains the architecture.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-02-22 12:09:00 +01:00
Jiri Denemark
4cd9545d89 cpu: Introduce virCPUDataNew
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-02-22 12:09:00 +01:00
Jiri Denemark
e2f7138af4 qemu: Introduce virQEMUCapsFormatHostCPUModelInfo
The CPU model info formating code in virQEMUCapsFormatCache will get
more complicated soon. Separating the code in
virQEMUCapsFormatHostCPUModelInfo will make the result easier to read.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-02-22 12:09:00 +01:00
Jiri Denemark
5c6fc9d641 qemu: Skip virQEMUCapsCPUFilterFeatures on non-x86 CPUs
All features the function is currently supposed to filter out are
specific to x86_64. We should avoid removing them on other
architectures. It seems to be quite unlikely other achitectures would
use the same names, but one can never be sure.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-02-22 12:09:00 +01:00
Tomáš Golembiovský
e4c6d4ae55 util: storage: add JSON backing volume parser 'raw' block driver
The 'raw' block driver in Qemu is not directly interesting from
libvirt's perspective, but it can be layered above some other block
drivers and this may be interesting for the user.

The patch adds support for the 'raw' block driver. The driver is treated
simply as a pass-through and child driver in JSON is queried to get the
necessary information.

Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com>
2017-02-22 10:39:57 +01:00
Tomáš Golembiovský
cb4adb43d6 util: storage: split function for JSON backing volume parsing in two
Split virStorageSourceParseBackingJSON into two functions so that the
core can be reused by other functions. The new function called
virStorageSourceParseBackingJSONInternal accepts virJSONValuePtr.

Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com>
2017-02-22 10:39:39 +01:00
Peter Krempa
93a3f516ee tests: drivermodule: Make sure that all compiled storage backends can be loaded
Add a new storage driver registration function that will force the
backend code to fail if any of the storage backend modules can't be
loaded. This will make sure that they work and are present.
2017-02-22 09:31:33 +01:00
Peter Krempa
0a6d3e51b4 storage: Turn storage backends into dynamic modules
If driver modules are enabled turn storage driver backends into
dynamically loadable objects. This will allow greater modularity for
binary distributions, where heavyweight dependencies as rbd and gluster
can be avoided by selecting only a subset of drivers if the rest is not
necessary.

The storage modules are installed into 'LIBDIR/libvirt/storage-backend/'
and users can override the location by using
'LIBVIRT_STORAGE_BACKEND_DIR' environment variable.

rpm based distros will at this point install all the backends when
libvirt-daemon-driver-storage package is installed.
2017-02-22 09:31:33 +01:00
Michal Privoznik
0888cb6ab4 conf: Don't accept dummy values for <memoryBacking/> attributes
Our virSomeEnumTypeFromString() functions return either the value
of item from the enum or -1 on error. Usually however the value 0
means 'this value is not set in the domain XML, use some sensible
default'. Therefore, we don't accept corresponding string in
domain XML, for instance:

<memoryBacking>
  <source mode="none"/>
  <access mode="default"/>
  <allocation mode="none"/>
</memoryBacking>

should be rejected as invalid XML.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-02-22 09:11:33 +01:00
John Ferlan
5ad03b9db2 conf: Fix leak in virNodeDeviceObjListExport
Fix a leak introduced by 4337bc57b when VIR_STRDUP'g the parent.
2017-02-21 10:52:20 -05:00
John Ferlan
0a6cb28b9a conf: Cleanup matchFCHostToSCSIHost
Rather than the inlined VIR_FREE's, use a cleanup: label... Fixes an
issue introduced by 03346def where @name was free'd before usage in
a virAsprintf to format scsi_host_name.
2017-02-21 10:52:20 -05:00
Marc Hartmayer
e22de286b1 qemu: Fix deadlock across fork() in QEMU driver
The functions in virCommand() after fork() must be careful with regard
to accessing any mutexes that may have been locked by other threads in
the parent process. It is possible that another thread in the parent
process holds the lock for the virQEMUDriver while fork() is called.
This leads to a deadlock in the child process when
'virQEMUDriverGetConfig(driver)' is called and therefore the handshake
never completes between the child and the parent process. Ultimately
the virDomainObjectPtr will never be unlocked.

It gets much worse if the other thread of the parent process, that
holds the lock for the virQEMUDriver, tries to lock the already locked
virDomainObject. This leads to a completely unresponsive libvirtd.

It's possible to reproduce this case with calling 'virsh start XXX'
and 'virsh managedsave XXX' in a tight loop for multiple domains.

This commit fixes the deadlock in the same way as it is described in
commit 61b52d2e38.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
2017-02-21 15:47:32 +01:00
Peter Krempa
f557b3351e qemu: Implement individual vcpu hotplug API
Add code that validates user's selection of cores and then uses the
existing code to plug in the vCPU.
2017-02-21 15:27:20 +01:00
Peter Krempa
8f657259bb lib: Add API for specific vCPU hot(un)plug
Similarly to domainSetGuestVcpus this commit adds API which allows to
modify state of individual vcpus rather than just setting the count.

This allows to enable CPUs in specific guest NUMA nodes to achieve any
necessary configuration.
2017-02-21 15:06:59 +01:00
Martin Kletzander
054358e8de qemu: Fix build breaker after incomplete merge
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2017-02-21 14:17:10 +01:00
Martin Kletzander
1c06d0faba qemu: Forbid slashes in shmem name
With that users could access files outside /dev/shm.  That itself
isn't a security problem, but might cause some errors we want to
avoid.  So let's forbid slashes as we do with domain and volume names
and also mention that in the schema.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2017-02-21 12:47:24 +01:00
Peter Krempa
e441de669f storage: Turn storage backends into static modules
Compile the storage driver into modules rather than by compiling all
files together. All modules are still linked together statically.
2017-02-21 09:55:01 +01:00
Peter Krempa
f813fe810f storage: backend: Refactor registration of the backend drivers
Add APIs that allow to dynamically register driver backends so that the
list of available drivers does not need to be known during compile time.

This will allow us to modularize the storage driver on runtime.
2017-02-21 09:34:30 +01:00
Peter Krempa
633b7592d6 daemon: Refactor connection driver module loading
Pass the registration function name to virDriverLoadModule so that we
can later call specific functions if necessary (e.g. for testing
purposes). This gets rid of the rather ugly automatic name generator and
unifies the code to load/initialize the modules.

It's also clear which registration function gets called.
2017-02-21 09:24:33 +01:00
Peter Krempa
0e1404d444 driver: Split/refactor driver module loading
Split the convoluted driver loader function into simpler parts which
will potentially allow reuse.
2017-02-21 08:48:51 +01:00
Daniel P. Berrange
f88b6e4285 Format printf format specifier used with niothreadids
The niothreadids struct field is size_t, so must use %zu not %lu
with printf. While they're identical on some platforms, on others
they are different, causing warnings

conf/domain_conf.c: In function 'virDomainDefCheckABIStabilityFlags':
conf/domain_conf.c:19575:26: error: format '%lu' expects argument of type 'long unsigned int', but argument 7 has type 'size_t {aka unsigned int}' [-Werror=format=]
                        _("Target domain iothreads count %lu does not "
                          ^

conf/domain_conf.c: In function 'virDomainDefFormatInternal':
conf/domain_conf.c:23915:46: error: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'size_t {aka unsigned int}' [-Werror=format=]
         virBufferAsprintf(buf, "<iothreads>%lu</iothreads>\n",
                                              ^

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-02-20 18:24:06 +00:00
Pavel Hrdina
7f602b8291 qemu_driver: move iothread duplicate check into one place
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-02-20 18:44:47 +01:00
Pavel Hrdina
99f00fb8bc qemu_driver: check whether iothread is used by controller
This follows the same check for disk, because we cannot remove iothread
if it's used by disk or by controller.  It could lead to crashing QEMU.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-02-20 18:44:24 +01:00
Pavel Hrdina
c6d2fba69c qemu_driver: move iothread existence check into one place
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-02-20 18:44:02 +01:00