Commit Graph

3278 Commits

Author SHA1 Message Date
Martin Kletzander
d6e582da80 util: Clear unused part of the map in virBitmapShrink
Some of the other functions depend on the fact that unused bits and longs are
always zero and it's less error-prone to clear it than fix the other functions.
It's enough to zero out one piece of the map since we're calling realloc() to
get rid of the rest (and updating map_len).

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-02-02 14:51:32 +01:00
Chen Hanxiao
126db34a81 qemu: Use VIR_ERR_DEVICE_MISSING for various hotplug messages
Modify OPERATION_FAILED and INTERNAL_ERROR error codes to
use DEVICE_MISSING instead for failures associated with the
inability to find the device. This makes it easier for consumers
to key off the error code rather than the error message.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-02-01 07:17:01 -05:00
Andrea Bolognani
90161710b9 conf: Small indentation and coding style fixes
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2018-02-01 10:34:41 +01:00
John Ferlan
d1b59c6214 conf: Allow configuration of implicit controller model
When an implicit controller is added, the model is defined as -1
(IOW: undefined). So, if an implicit SCSI controller was added,
can set the model to the default value if the underlying hypervisor
supports it.
2018-01-31 11:32:04 -05:00
John Ferlan
932862b8bf conf: Rework and rename virDomainDeviceFindControllerModel
As it turns out virDomainDeviceFindControllerModel was only ever
called for SCSI controllers using VIR_DOMAIN_CONTROLLER_TYPE_SCSI
as a parameter.

So rename to virDomainDeviceFindSCSIController and rather than
return a model, let's return a virDomainControllerDefPtr to let
the caller reference whatever it wants.
2018-01-31 11:32:04 -05:00
Andrea Bolognani
c7f6d4d010 conf: Use correct attribute name in error message
The <capabilities> feature has an attribute named 'policy', but the
error message mentioned the non-existing 'state' attribute instead.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2018-01-30 18:44:11 +01:00
Erik Skultety
b7a7912411 build: Fix broken build on FreeBSD and OSX after recent nodedev series
Commits f83c7c88 and 6eb1f2b9 broke the build on FreeBSD and OSX because
of symbols being undefined for those platforms.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 17:53:13 +01:00
Erik Skultety
75dbb27b10 conf: nodedev: Update PCI mdev capabilities dynamically
Just like SRIOV, a PCI device is only capable of the mediated devices
framework when it's bound to the vendor native driver, thus if a driver
change occurs, e.g. vendor_native->vfio, we need to refresh some of the
device's capabilities to reflect the reality, mdev included.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Suggested-by: Wu Zongyong <cordius.wu@huawei.com>
Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
882fd7a13c conf: Replace usage of virNodeDevCapMdevType with virMediatedDeviceType
Now that we have all the building blocks in place, switch the nodedev
driver to use the "new" virMediatedDeviceType type instead of the "old"
virNodeDevCapMdevType one.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
d18feadc0c conf: nodedev: Refresh capabilities before touching them
Most of them are static, however in case of PCI and SCSI_HOST devices,
the nested capabilities can change dynamically, e.g. due to a driver
change (from host_pci_driver -> vfio_pci).

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Suggested-by: Wu Zongyong <cordius.wu@huawei.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
36546e3cdb nodedev: Introduce virNodeDeviceCapsListExport
Whether asking for a number of capabilities supported by a device or
listing them, it's handled essentially by a copy-paste code, so extract
the common stuff into this new helper which also updates all
capabilities just before touching them.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
349dda1fc8 nodedev: Export nodeDeviceUpdateCaps from node_device_conf.c
Since we moved the helpers from nodedev driver to src/conf, the actual
'update' function using those helpers should be moved as well so that we
don't need to call back into the driver.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
f83c7c88c5 nodedev: Move the sysfs-related cap handling to node_device_conf.c
The capabilities are defined/parsed/formatted/queried from this module,
no reason for 'update' not being part of the module as well. This also
involves some module-specific prefix changes.
This patch also drops the node_device_linux_sysfs module from the repo
since:
a) it only contained the capability handlers we just moved
b) it's only linked with the driver (by design) and thus unreachable to
other modules
c) we touch sysfs across all the src/util modules so the module being
deleted hasn't been serving its original intention for some time already.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
d1860140cc nodedev: Drop the nodeDeviceSysfsGetSCSIHostCaps wrapper
We can call directly the virNodeDeviceGetSCSIHostCaps helper instead.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
b20ec49e57 conf: nodedev: Convert virNodeDevObjHasCapStr to a simple wrapper
This patch drops the capability matching redundancy by simply converting
the string input to our internal types which are then in turn used for
the actual capability matching.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
54cab10518 conf: nodedev: Rename virNodeDeviceCapMatch to virNodeDevObjHasCap
We currently have 2 methods that do the capability matching. This should
be condensed to a single function and all the derivates should just call
into that using a proper type conversion.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
1cbaeda707 conf: nodedev: Rename virNodeDevObjHasCap to virNodeDevObjHasCapStr
We currently have 2 methods that do the capability matching. This should
be condensed to a single function and all the derivates should just call
into that using a proper type conversion.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
ZhiPeng Lu
614be3b882 vhost-user: add support reconnect for vhost-user ports
For vhost-user ports, Open vSwitch acts as the server and QEMU the client.
When OVS crashes or restarts, the QEMU process should be reconnected to
OVS.

Signed-off-by: ZhiPeng Lu <lu.zhipeng@zte.com.cn>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-01-26 14:02:46 +01:00
Martin Kletzander
7387e3fea4 conf: Add support for cputune/cachetune
More info in the documentation, this is basically the XML parsing/formatting
support, schemas, tests and documentation for the new cputune/cachetune element
that will get used by following patches.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-25 17:16:08 +01:00
Martin Kletzander
3bbae43d8c conf: Use virResctrlInfo in capabilities
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-25 17:16:08 +01:00
Martin Kletzander
b2211a9e54 Rename virResctrlInfo to virResctrlInfoPerCache
Just to ease the review of following patches.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-25 17:16:08 +01:00
Daniel P. Berrange
68eed56b2d conf: add support for setting OEM strings SMBIOS data fields
The OEM strings table in SMBIOS allows the vendor to pass arbitrary
strings into the guest OS. This can be used as a way to pass data to an
application like cloud-init, or potentially as an alternative to the
kernel command line for OS installers where you can't modify the install
ISO image to change the kernel args.

As an example, consider if cloud-init and anaconda supported OEM strings
you could use something like

    <oemStrings>
      <entry>cloud-init:ds=nocloud-net;s=http://10.10.0.1:8000/</entry>
      <entry>anaconda:method=http://dl.fedoraproject.org/pub/fedora/linux/releases/25/x86_64/os</entry>
    </oemStrings>

use of a application specific prefix as illustrated above is
recommended, but not mandated, so that an app can reliably identify
which of the many OEM strings are targetted at it.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2018-01-25 14:48:56 +00:00
Scott Garfinkle
2d8721e260 domcaps: Treat host models as case-insensitive strings
Qemu 2.11 allows case-insensitive specification of CPU models.
This patch fixes the resulting problems on (at least) POWER
arch machines so that Power8 and POWER8 are not different.

Signed-off-by: Scott Garfinkle <scottgar@linux.vnet.ibm.com>
2018-01-12 06:31:53 -05:00
John Ferlan
be1bb6c95b storage: Complete implementation volume by hash object
Alter the volume logic to use the hash tables instead of forward
linked lists. There are three hash tables to allow for fast lookup
by name, target.path, and key.

Modify the virStoragePoolObjAddVol to place the object in all 3
tables if possible using self locking RWLock on the volumes object.
Conversely when removing the volume, it's a removal of the object
from the various hash tables.

Implement functions to handle remote ForEach and Search Volume
type helpers. These are used by the disk backend in order to
facilitate adding a primary, extended, or logical partition.

Implement the various VolDefFindBy* helpers as simple (and fast)
hash lookups. The NumOfVolumes, GetNames, and ListExport helpers
are all implemented using standard for each hash table calls.
2018-01-10 08:10:24 -05:00
John Ferlan
f77c898d1e storage: Introduce _virStorageVolObj[List]
Prepare for hash table volume lists by creating the object infrastructure
for a Volume Object and Volume Object List

The _virStorageVolObj will contain just a pointer to the "current"
(and live) volume definition.

The _virStorageVolObjList will contain three hash tables, one for
each of the lookup options allowed for a volume.
2018-01-10 08:10:23 -05:00
John Ferlan
607524af4f conf: Use bool for @check_active parameter
Use a bool as that's how the variable is used in the function.
2018-01-04 10:54:08 -05:00
John Ferlan
c00643f86f conf: Need to unlock pools on object allocation failure
The RW pool could be left locked if allocation fails.
2018-01-04 10:54:08 -05:00
Paolo Bonzini
d2440f3b53 conf: include x86 microcode version in virsh capabilities
A microcode update can cause the CPUID bits to change; an example
from the past was the update that disabled TSX on several Haswell and
Broadwell machines.

In order to track the x86 microcode version in the QEMU capabilities,
we have to fetch it and store it in the host CPU.  This also makes the
version visible in "virsh capabilities", which is a nice side effect.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2018-01-04 16:52:03 +01:00
John Ferlan
8d424f1b23 conf: Fix generating addresses for SCSI hostdev
https://bugzilla.redhat.com/show_bug.cgi?id=1519130

Commit id 'dc692438' reverted the automagic addition of a SCSI
controller attempt during virDomainHostdevAssignAddress; however,
the logic to determine where to place the next_unit depended upon
the "new" controller being added.  Without the new controller the
the next time through the call for the next SCSI hostdev found
would result in the "next_unit" never changing from 0 (zero) and
as a result the addition of the device will fail due to being a
duplicate unit number of the first with the error message:

  virDomainDefCheckDuplicateDriveAddresses:$line : unsupported
      configuration: SCSI host address controller='0' bus='1'
      target='0' unit='0' in use by another SCSI host device

So instead of walking the controller list looking for SCSI
controllers, all we can do is "pretend" that they exist and
allow other code to create them later as necessary.
2018-01-04 10:30:43 -05:00
John Ferlan
c52dbafe9f conf: Use existing SCSI hostdev model to create new
In virDomainDefMaybeAddHostdevSCSIcontroller when we add a new
controller because someone neglected to add one or we're adding
one because the existing one is full, we should copy over the
model number from the existing controller since whatever we
create should at least have the same characteristics as the one
we cannot use because it's full.

NB: This affects the existing hostdev-scsi-autogen-address test
which would add a default ('lsi') SCSI controller for the various
scsi_host's that would create a controller for the hostdev.
2018-01-04 10:30:43 -05:00
Pavel Hrdina
bbf6573e94 conf: honor maxnames in nodeListDevices API
Introduced by commit <4ae9dbea99c>.

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-02 10:28:09 +01:00
Peter Krempa
aed3d038a6 conf: Add infrastructure for disk source private data XML
VM drivers may need to store additional private data to the status XML
so that it can be restored after libvirtd restart. Since not everything
is needed add a callback infrastructure, where VM drivers can add only
stuff they need.

Note that the private data is formatted as a <privateData> sub-element
of the <disk> or <backingStore> <source> sub-element. This is done since
storing it out of band (in the VM private data) would require a complex
matching process to allow to put the data into correct place.
2017-12-14 10:24:36 +01:00
John Ferlan
4b2e0ed6e3 storage: Convert virStoragePoolObjList to use virObjectRWLockable
Now that we have a private storage pool list, we can take the next
step and convert to using objects. In this case, we're going to use
RWLockable objects (just like every other driver) with two hash
tables for lookup by UUID or Name.

Along the way the ForEach and Search API's will be adjusted to use
the related Hash API's and the various FindBy functions altered and
augmented to allow for HashLookup w/ and w/o the pool lock already
taken.

After virStoragePoolObjRemove we will need to virObjectUnref(obj)
after to indicate the caller is "done" with it's reference. The
Unlock occurs during the Remove.

The NumOf, GetNames, and Export functions all have their own callback
functions to return the required data and the FindDuplicate code
can use the HashSearch function callbacks.
2017-12-13 15:05:10 -05:00
John Ferlan
90e65353a2 storage: Privatize virStoragePoolObjListPtr
Move the structure into virstorageobj.c.

Use the virStoragePoolObjListNew allocator to fill in the @pools for
the storage driver and test driver.
2017-12-13 14:51:30 -05:00
John Ferlan
9f0ccc717b conf: Fix memory leak for distances in virDomainNumaFree
Commit id '74119a03f' neglected to clean up @distances when
the numa definition is cleaned up.
2017-12-01 06:28:24 -05:00
John Ferlan
ac6cc1d822 conf: Clean up virDomainNumaDefCPUFormatXML
Don't use a unary comparison for an int value - compare against zero
directly instead.
2017-12-01 06:28:24 -05:00
John Ferlan
742494eed8 conf: Clean up virDomainNumaDefNodeDistanceParseXML
Clean up the style a bit w/r/t to not using a unary operator on an
integer value that could be zero - compare vs. zero instead.

Set the def->mem_nodes[*].distances to rdist or ldist inside the
if condition - no need to set outside since the value being set
to is what was fetched.

During cleanup, be sure to initialize the ndistances on error and
use the < 0 comparison not the unary one.
2017-12-01 06:28:24 -05:00
Michal Privoznik
0fd85b98ae virDomainDiskBackingStoreParse: Don't leak @idx
==1277== 8 bytes in 4 blocks are definitely lost in loss record 39 of 131
==1277==    at 0x4C2AEDF: malloc (vg_replace_malloc.c:299)
==1277==    by 0x68BBBC8: xmlStrndup (in /usr/lib64/libxml2.so.2.9.4)
==1277==    by 0x53B1DC2: virXMLPropString (virxml.c:510)
==1277==    by 0x53D696A: virDomainDiskBackingStoreParse (domain_conf.c:8639)
==1277==    by 0x53DA684: virDomainDiskDefParseXML (domain_conf.c:9590)
==1277==    by 0x53F619F: virDomainDefParseXML (domain_conf.c:19233)
==1277==    by 0x53F96EE: virDomainDefParseNode (domain_conf.c:20083)
==1277==    by 0x53F9540: virDomainDefParse (domain_conf.c:20027)
==1277==    by 0x53F95E6: virDomainDefParseFile (domain_conf.c:20053)
==1277==    by 0x44D1D4: testCompareDomXML2XMLFiles (testutils.c:1265)
==1277==    by 0x42FC7C: testXML2XMLActive (qemuxml2xmltest.c:71)
==1277==    by 0x44AD20: virTestRun (testutils.c:180)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-12-01 10:06:03 +01:00
Michal Privoznik
7d7c01b458 virDomainDiskSourceNetworkParse: Don't leak @tlsCfg or @haveTLS
==861== 3 bytes in 1 blocks are definitely lost in loss record 3 of 168
==861==    at 0x4C2AEDF: malloc (vg_replace_malloc.c:299)
==861==    by 0x8C7FBC8: xmlStrndup (in /usr/lib64/libxml2.so.2.9.4)
==861==    by 0x5DCCDC2: virXMLPropString (virxml.c:510)
==861==    by 0x5DF1232: virDomainDiskSourceNetworkParse (domain_conf.c:8445)
==861==    by 0x5DF1728: virDomainDiskSourceParse (domain_conf.c:8576)
==861==    by 0x5DF41A5: virDomainDiskDefParseXML (domain_conf.c:9238)
==861==    by 0x5E1119F: virDomainDefParseXML (domain_conf.c:19233)
==861==    by 0x5E146EE: virDomainDefParseNode (domain_conf.c:20083)
==861==    by 0x5E14540: virDomainDefParse (domain_conf.c:20027)
==861==    by 0x5E145E6: virDomainDefParseFile (domain_conf.c:20053)
==861==    by 0x4053CC: testCompareXMLToArgv (qemuxml2argvtest.c:455)
==861==    by 0x41F135: virTestRun (testutils.c:180)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-12-01 10:05:42 +01:00
Pavel Hrdina
cb06ea57ad conf: fix migratable XML for graphics if socket is generated based on config
The graphics code is complex and there are a lot of exceptions and
backward compatible combinations.  One of them is the possibility
to configure "spice_auto_unix_socket" in qemu.conf which will convert
all spice graphics with listen type "address" without any address
specified to listen type "socket" when the guest is started.

We don't format this generated socket into migratable XML to make
migration work with older libvirt.  However, spice has another
exception that if autoport='no' and there is no port configured
it is converted to listen type "none".  Because of this we need
to format autoport='yes' to make sure that the listen type will
be the same as the offline XML.

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

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-30 17:42:02 +01:00
Ján Tomko
309cd46b40 Introduce virDomainDeviceAliasIsUserAlias
Allow parts of code outside domain_conf to decide whether the alias
is user-specified or not.
2017-11-30 16:48:58 +01:00
Pino Toscano
21332bf658 conf: add VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SCLP
Introduce specific a target types with two models for the console
devices (sclp and sclplm) used in s390 and s390x guests, so isa-serial
is no more used for them.

This makes <serial> usable on s390 and s390x guests, with at most only
a single sclpconsole and one sclplmconsole devices usable in a single
guest (due to limitations in QEMU, which will enforce already at
runtime).

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

Signed-off-by: Pino Toscano <ptoscano@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:34 +01:00
Andrea Bolognani
eccdcb81fc conf: Add target type and model for pl011
We can finally introduce a specific target model for the pl011 device
used by mach-virt guests, which means isa-serial will no longer show
up to confuse users.

We make sure migration works in both directions by interpreting the
isa-serial target type, or the lack of target type, appropriately
when parsing the guest XML, and skipping the newly-introduced type
when formatting if for migration. We also verify that pl011 is not
used for non-mach-virt guests and add a bunch of test cases.

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

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:34 +01:00
Andrea Bolognani
c498a8921e conf: Add target type and model for spapr-vty
We can finally introduce a specific target model for the spapr-vty
device used by pSeries guests, which means isa-serial will no longer
show up to confuse users.

We make sure migration works in both directions by interpreting the
isa-serial target type, or the lack of target type, appropriately
when parsing the guest XML, and skipping the newly-introduced type
when formatting if for migration. We also verify that spapr-vty is
not used for non-pSeries guests and add a bunch of test cases.

This commit is best viewed with 'git show -w'.

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

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:33 +01:00
Andrea Bolognani
5ad9d9afd4 conf: Parse and format virDomainChrSerialTargetModel
This information will be used to select, and store in the guest
configuration in order to guarantee ABI stability, the concrete
(hypervisor-specific) model for serial devices.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:33 +01:00
Andrea Bolognani
7983068fa5 conf: Remove ATTRIBUTE_FALLTHROUGH from virDomainChrTargetDefFormat()
Formatting the <target/> element for serial devices will become a
bit more complicated later on, and leaving the fallthrough behavior
there would do nothing but complicate it further.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:32 +01:00
Andrea Bolognani
46084f2aa1 conf: Improve virDomainChrTargetDefFormat()
Make the switch statement type-aware, avoid calling
virDomainChrTargetTypeToString() more than once and check its
return value before using it.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:32 +01:00
Andrea Bolognani
2cd323e382 conf: Check virDomainChrSourceDefFormat() return value
The function can fail, but none of the caller were accounting
for that.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:32 +01:00
Andrea Bolognani
be956c4e38 conf: Improve error handling in virDomainChrDefFormat()
We don't need to store the return value since we never modify it.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:32 +01:00
Andrea Bolognani
00b7f81fa8 conf: Introduce virDomainChrTargetDefFormat()
Move formatting of the <target/> element for char devices out of
virDomainChrDefFormat() and into its own function.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:32 +01:00