Commit Graph

3341 Commits

Author SHA1 Message Date
Andrea Bolognani
96b1ea4032 conf: Remove dubious code from virDomainPCIAddressSetGrow()
I haven't been able to come up with a single scenario in which
the code in question would be executed; even if there was one,
it would be due to the user specifying a *partial* PCI topology
in the guest XML, which is of course entirely unsupportable and
thus providing even the slightest hint that doing so is in any
way a good idea is actively harmful.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-04-09 09:12:21 +02:00
John Ferlan
c534d10ffe conf: Introduce virDomainObjListAddObjLocked
Create a common helper to add an object to the locked domain
objlist hash tables and use it.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2018-04-06 14:14:37 -04:00
John Ferlan
e0f7707cd5 conf: Fix error path logic in virDomainObjListLoadStatus
If the virHashAddEntry fails, then we need to "careful" about
how we free the @obj. When virDomainObjParseFile returns there
is one reference and the object is locked, so use virDomainObjEndAPI
when done.

Add a virObjectRef in the error path for the second virHashAddEntry
call since it doesn't call virObjectRef, but virHashRemoveEntry
will call virObjectUnref because virObjectFreeHashData is called
when the element is removed from the hash table as set up in
virDomainObjListNew.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2018-04-06 14:14:37 -04:00
John Ferlan
2689a922aa conf: Fix error path logic in virDomainObjListAddLocked
If the virHashAddEntry fails, then we need to "careful" about
how we free the @vm. When virDomainObjNew returns there is one
reference and the object is locked, so use virDomainObjEndAPI
when done.

Add a virObjectRef in the error path for the second virHashAddEntry
call since it doesn't call virObjectRef, but virHashRemoveEntry
will call virObjectUnref because virObjectFreeHashData is called
when the element is removed from the hash table as set up in
virDomainObjListNew.

Eventually these paths should goto error and error should be changed
to use EndAPI as well, but that requires more adjustments to other
paths in the code to have a locked and ref counted @vm.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2018-04-06 14:14:31 -04:00
Andrea Bolognani
898edc9617 conf: Prefer pcie-to-pci-bridge to dmi-to-pci-bridge
Both pcie-to-pci-bridge and dmi-to-pci-bridge can be used to
create a traditional PCI topology in a pure PCIe guest such as
those using the x86_64/q35 or aarch64/virt machine type;
however, the former should be preferred, as it doesn't need to
obey limitation of real hardware and is completely
architecture-agnostic.

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

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-04-06 14:12:21 +02:00
Andrea Bolognani
9985bb468a conf: Add virDomainPCIAddressSet.isPCIeToPCIBridgeSupported
Just like the existing areMultipleRootsSupported, this will
allow us to change the results of the driver-agnostic PCI
address allocation logic based on whether the QEMU binary
supports certain features.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-04-06 14:12:19 +02:00
Andrea Bolognani
542f05e775 qemu: Implement pcie-to-pci-bridge controller
The new controller will not yet be used automatically by
libvirt, but at this point it's already possible to configure
a guest to use it.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-04-06 14:12:17 +02:00
Andrea Bolognani
33b2df2795 conf: Rename virDomainPCIAddressSet.areMultipleRootsSupported
We're going to add a similarly-named attribute later, and we'd
like to be consistent.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-04-06 14:12:14 +02:00
Peter Krempa
8fc5e5bfdc conf: Extract logic for updating 'detect_zeroes' mode
For some reason we've decided to silently translate the disk
detect_zeroes mode if it would be invalid. Extract the
logic so that it does not need to be copypasta'd across the code base.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-04-03 15:48:37 +02:00
Peter Krempa
1cb7f41568 conf: Don't require 'def' in virDomainDiskDefParse
In some use cases (mostly in tests) it is not required to check the
seclabel definition validity. Add possibility to call
virDomainDiskDefParse without the domain definition.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-04-03 15:48:37 +02:00
Peter Krempa
295b128e09 conf: Refactor/rename virDomainDiskDefSourceParse
Make the function more usable by returning the full disk definition and
fix the only caller for the new semantics. The new name for the function
is virDomainDiskDefParse.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-04-03 15:48:37 +02:00
Ján Tomko
186412fe76 virDomainDeviceAliasIsUserAlias: tolerate NULL
Do not crash in virDomainDeviceInfoParseXML if someone provides
an 'alias' element without a 'name' attribute.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-26 15:13:26 +02:00
Daniel P. Berrangé
f0fd90d722 conf: avoid reporting errors when network driver is disabled
In previous releases all these methods were a no-op if the network
driver is disabled. These helper methods are called unconditionally for
all types of network interface, so must be no-ops if missing. Other code
will already generate an error if the network driver is disabled and a
NIC with type=network is used.

Reviewed-by: Laine Stump <laine@laine.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-23 15:32:50 +00:00
Michal Privoznik
630c6e3495 virDomainDeviceDefValidateAliasesIterator: Ignore some hostdevs
https://bugzilla.redhat.com/show_bug.cgi?id=1556828

When defining a domain that has <interface type='hostdev'/> our
parser creates two entries in virDomainDef: one for <interface/>
and one for <hostdev/>. However, some info is shared between the
two which makes user alias validation fail because alias belongs
to the set of shared info.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2018-03-20 15:30:14 +01:00
Peter Krempa
07141541fb conf: Extract parsing of storage source related data
Split out the parser and separate it from the private data part so that
it can be later reused in other parts of the code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-14 12:19:44 +01:00
Peter Krempa
b17573fe09 conf: Parse and validate disk source seclabels together with the source
Since seclabels are formatted along with the source element and will
also make sense to be passed for the backing chain we should parse them
in the place where we parse the disk source. Same applies for
validation.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-14 12:19:44 +01:00
Peter Krempa
3960aeb7a6 conf: Separate seclabel validation from parsing
Rather than checking that the security label is legal when parsing it
move the code into a separate function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-14 12:19:44 +01:00
Peter Krempa
28e1068c4f conf: Validate disk source configuration also for the backing store
Since we already parse the <backingStore> of a disk source, we should
also validate the configuration for the whole backing chain and not only
for the top level image.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-14 12:19:44 +01:00
Peter Krempa
c4e7c1f212 conf: disk: Separate virStorageSource formatting
Move out formatting of 'startuPolicy' which is a property of the disk
out of the <source> element. Extracting the code formating the content
and attributes will also allow reuse in other parts of the code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-14 12:19:44 +01:00
Peter Krempa
2bbbc9798d conf: Refactor formatting of startupPolicy in virDomainDiskSourceFormatInternal
Move it to a single location which also allows to get rid of the
temporrary variable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-14 12:19:44 +01:00
Peter Krempa
8f5138829f conf: Remove virDomainDiskSourceDefFormatSeclabel
The wrapper functionality can be moved to the only user
virDomainDiskSourceFormatInternal. Also removes comment which does not
reflect the truth any more.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-14 12:19:44 +01:00
Peter Krempa
6bec169759 conf: Refactor seclabel formatting in virDomainDiskSourceFormatInternal
Call the formatter function only once.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-14 12:19:44 +01:00
Peter Krempa
bbacd6b113 conf: Remove unnecessary condition from virDomainDiskSourceFormatInternal
Now that the function is using virXMLFormatElement we don't need to
conditionally format anything, since we'll format the element according
to the presence of content.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-14 12:19:44 +01:00
Ján Tomko
c8ab5aeb14 Adjust whitespace in virDomainDefHasUSB prototype
To match the rest of the file.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-13 10:31:56 +01:00
Roman Bogorodskiy
1b6ff36c2f Fix build with clang 6.0.0
Clang 6.0.0 complains when initializing structure with { NULL }:

conf/domain_addr.c:1494:38: error: missing field 'type' initializer [-Werror,-Wmissing-field-initializers]
    virDomainDeviceInfo nfo = { NULL };

Use { 0 } instead to make it happy.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2018-03-12 20:04:08 +04:00
Michal Privoznik
e43263601f conf: Check for user aliases duplicates only
https://bugzilla.redhat.com/show_bug.cgi?id=1553162

When validating a device XML config we check if user provided
alias is unique. We do this by maintaining a hash table of device
aliases as we iterated over all devices defined for the domain.
However, it may happen that what appears as two devices in domain
XML is in fact just one interface in hypervisor.  We can assume
libvirt generated aliases to be unique and thus really check user
provided ones only.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-03-12 13:27:24 +01:00
Michal Privoznik
e5673ed444 virDomainDeviceValidateAliasForHotplug: Use correct domain defintion
https://bugzilla.redhat.com/show_bug.cgi?id=1553075

For some weird reason this function is getting live and
persistent def for domain but then accesses vm->def and
vm->newDef directly. This is rather unsafe as we can be
accessing NULL pointer.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-03-12 13:27:24 +01:00
Ján Tomko
0a12d96c85 maint: use parentheses after if
Some instances of ARCH_IS_PPC64 did not use them.

Introduced by commits da636d8 and ef08a54

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-08 16:45:54 +01:00
Peter Krempa
6a59d6c103 conf: Replace virDomainDiskSourceEncryptionParse by an XPath query
Remove the rather bulky function in favor of an XPath query.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-08 14:29:50 +01:00
Peter Krempa
1e6e34b144 util: storage: Sanitize parsing of disk encryption XMLs
Pass in the XPath context as we do in all other places rather than
allocating a new one.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-08 14:29:50 +01:00
Peter Krempa
e7c44b3f7c conf: Replace virDomainDiskSourceAuthParse by an XPath query
Remove the rather bulky function in favor of an XPath query.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-08 14:29:49 +01:00
Peter Krempa
183f96314d util: storage: Sanitize parsing of disk auth XMLs
Pass in the XPath context as we do in all other places rather than
allocating a new one.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-08 14:29:49 +01:00
Ján Tomko
1cdc9ecebd qemu: report a nicer error when USB is disabled
If the user tries to define a domain that has

  <controller type='usb' model='none'/>

and also some USB devices, we report an error:
  error: internal error: No free USB ports

Which is technically still correct for a domain with no USB ports.

Change it to:

USB is disabled for this domain, but USB devices are present in the domain XML

https://bugzilla.redhat.com/show_bug.cgi?id=1347550
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-07 14:10:46 +01:00
Daniel P. Berrangé
ed30a13c4b make: split XML conf build rules into conf/Makefile.inc.am
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-03-05 17:12:01 +00:00
Andrea Bolognani
11819aee65 conf: Assign explicit value to VIR_DOMAIN_CONTROLLER_PCI_MODEL_NAME_NONE
Pretty much any reasonable compiler would do this automatically,
but there's no harm in being explicit about it.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2018-03-05 17:29:40 +01:00
Ján Tomko
444f15adb8 conf: set postParseFailed even without ALLOW_POST_PARSE_FAIL
We allow the postParse callbacks to fail for some reasons (missing
emulator binary) when parsing the configs from /etc/libvirt.
In that case, def->postParseFailed is set to true and the post
parse callbacks are re-executed on domain startup.

However this bool was only set when virDomainDefPostParse was called
with the ALLOW_POST_PARSE_FAIL flag set. If the callback failed
again on domain startup, the bool would be reset and subsequent
startups would not attempt to reexecute the callback.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-03-05 13:25:20 +01:00
John Ferlan
5535856f0e conf: Fix crash in virDomainDefCompatibleDevice
Commit id 'edae027c' blindly assumed that the passed @oldDev
parameter would not be NULL when calling virDomainDeviceGetInfo;
however, commit id 'b6a264e8' passed NULL for AttachDevice
callers under the premise that there wouldn't be a device
to check/update against.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2018-03-01 08:05:36 -05:00
Jiri Denemark
edae027cfe qemu: Fix updating device with boot order
Commit v3.7.0-14-gc57f3fd2f8 prevented adding a <boot order='x'/>
element to an inactive domain with global <boot dev='...'/> element.
However, as a result of that change updating any device with boot order
would fail with 'boot order X is already used by another device', where
"another device" is in fact the device which is being updated.

To fix this we have to ignore the device which we're about to update
when checking for boot order conflicts.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2018-02-23 11:52:44 +01:00
Jiri Denemark
b6a264e855 Pass oldDev to virDomainDefCompatibleDevice on device update
When calling virDomainDefCompatibleDevice to check a new device during
device update, we need to pass the original device which is going to be
updated in addition to the new device. Otherwise, the function can
report false conflicts.

The new argument is currently ignored by virDomainDefCompatibleDevice,
but this will change in the following patch.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2018-02-23 11:52:44 +01:00
John Ferlan
c6d483cdc5 conf,qemu: Check for NULL addrs in virDomainUSBAddressEnsure
Rather than having the caller check, if the input @addrs is NULL
(e.g. priv->usbaddrs), then just return 0. This also removes the
need for ATTRIBUTE_NONNULL which only really helped if someone
passed a NULL as a parameter not if the passed parameter is NULL.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2018-02-22 08:13:16 -05:00
John Ferlan
207cece6a3 conf,qemu: Check for NULL addrs in virDomainUSBAddressRelease
Rather than having the caller check, if the input @addrs is NULL
(e.g. priv->usbaddrs), then just return 0. This also removes the
need for ATTRIBUTE_NONNULL which only really helped if someone
passed a NULL as a parameter not if the passed parameter is NULL.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2018-02-22 08:12:57 -05:00
Daniel P. Berrangé
d4bf8f4150 nwfilter: handle missing switch enum cases
Ensure all enum cases are listed in switch statements, or cast away
enum type in places where we don't wish to cover all cases.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-21 16:58:25 +00:00
Daniel P. Berrangé
05b39a6843 conf: handle missing switch enum cases
Ensure all enum cases are listed in switch statements.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-21 16:53:51 +00:00
Daniel P. Berrangé
a302480dcb conf: add enum constants for default controller models
The controller model is slightly unusual in that the default value is
-1, not 0. As a result the default value is not covered by any of the
existing enum cases. This in turn means that any switch() statements
that think they have covered all cases, will in fact not match the
default value at all. In the qemuDomainDeviceCalculatePCIConnectFlags()
method this has caused a serious mistake where we fallthrough from the
SCSI controller case, to the VirtioSerial controller case, and from
the USB controller case to the IDE controller case.

By adding explicit enum constant starting at -1, we can ensure switches
remember to handle the default case.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-20 14:58:39 +00:00
Michal Privoznik
82e43ae164 storage_conf: Make virStorageAuthDefFormat return void
This function returns nothing but zero. Therefore it makes no
sense to have it returning an integer.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-20 13:06:22 +01:00
Michal Privoznik
4e657f2ae2 virDomainDiskSourceFormatInternal: Avoid leaking @childBuf
If formatting of storage encryption or private data fails we must
jump to the error label instead of returning immediately
otherwise @attrBuf and @childBuf might be leaked.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-20 13:06:22 +01:00
Laine Stump
e62cb4a9b7 conf: move 'generated' member from virMacAddr to virDomainNetDef
Commit 7e62c4cd26 (first appearing in libvirt-3.9.0 as a resolution
to rhbz #1343919) added a "generated" attribute to virMacAddr that was
set whenever a mac address was auto-generated by libvirt. This
knowledge was used in a single place - when trying to match a NetDef
from the Domain to Delete with user-provided XML. Since the XML parser
always auto-generates a MAC address for NetDefs when none is provided,
it was previously impossible to make a search where the MAC address
isn't significant, but the addition of the "generated" attribute made
it possible for the search function to ignore auto-generated MACs.

This implementation had a problem though - it was adding a field to a
"low level" struct - virMacAddr - which is used in other places with
the assumption that it contains exactly a 6 byte MAC address and
nothing else. In particular, virNWFilterSnoopEthHdr uses virMacAddr as
part of the definition of an ethernet packet header, whose layout must
of course match an actual ethernet packet. Adding the extra bools into
virNWFilterSnoopEthHdr caused the nwfilter driver's "IP discovery via
DHCP packet snooping" functionality to mysteriously stop working.

In order to fix that behavior, and prevent potential future similar
odd behavior, this patch moves the "generated" member out of
virMacAddr (so that it is again really is just a MAC address) into
virDomainNetDef, and sets it only when virDomainNetGenerateMAC() is
called from virDomainNetDefParseXML() (which is the only time we care
about it).

Resolves: https://bugzilla.redhat.com/1529338

(It should also be applied to any maintenance branch that applies
commit 7e62c4cd26 and friends to resolve
https://bugzilla.redhat.com/1343919)

Signed-off-by: Laine Stump <laine@laine.org>
2018-02-19 13:15:00 -05:00
Daniel P. Berrangé
2d43f0a2dc conf: stop passing virConnectPtr into virDomainDiskTranslateSourcePool
Rather than expecting callers to pass a virConnectPtr into the
virDomainDiskTranslateSourcePool() method, just acquire a connection
to the storage driver when needed.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-19 11:11:47 +00:00
Daniel P. Berrangé
0c63c117a2 conf: reimplement virDomainNetResolveActualType in terms of public API
Now that we have the ability to easily open connections to secondary
drivers, eg network:///system,  it is possible to reimplement the
virDomainNetResolveActualType method in terms of the public API. This
avoids the need to have the network driver provide a callback for it.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-19 11:11:46 +00:00
Zhuang Yanying
c8fec25692 conf: Add support for setting Chassis SMBIOS data fields
This type of information defines attributes of a system
chassis, such as SMBIOS Chassis Asset Tag.

access inside VM (for example)
Linux:   /sys/class/dmi/id/chassis_asset_tag.
Windows: (Get-WmiObject Win32_SystemEnclosure).SMBIOSAssetTag
          wirhin Windows PowerShell.

As an example, add the following to the guest XML

    <chassis>
      <entry name='manufacturer'>Dell Inc.</entry>
      <entry name='version'>2.12</entry>
      <entry name='serial'>65X0XF2</entry>
      <entry name='asset'>40000101</entry>
      <entry name='sku'>Type3Sku1</entry>
    </chassis>

Signed-off-by: Zhuang Yanying <ann.zhuangyanying@huawei.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-02-17 07:36:46 -05:00