Commit Graph

3238 Commits

Author SHA1 Message Date
John Ferlan
37537a7c64 conf: Add/Allow parsing the encryption in the disk source
Since the virStorageEncryptionPtr encryption; is a member of
 _virStorageSource it really should be allowed to be a subelement
of the disk <source> for various disk formats:

   Source{File|Dir|Block|Volume}
   SourceProtocol{RBD|ISCSI|NBD|Gluster|Simple|HTTP}

NB: Simple includes sheepdog, ftp, ftps, tftp

That way we can set up to allow the <encryption> element to be
formatted within the disk source, but we still need to be wary
from whence the element was read - see keep track and when it
comes to format the data, ensure it's written in the correct place.

Modify the qemuxml2argvtest to add a parse failure when there is an
<encryption> as a child of <disk> *and* an <encryption> as a child
of <source>.

The virschematest will read the new test files and validate from a
RNG viewpoint things are fine.
2017-10-19 15:32:50 -04:00
John Ferlan
8002d3cb1b conf: Add/Allow parsing the auth in the disk source
Since the virStorageAuthDefPtr auth; is a member of _virStorageSource
it really should be allowed to be a subelement of the disk <source>
for the RBD and iSCSI prototcols. That way we can set up to allow
the <auth> element to be formatted within the disk source.

Since we've allowed the <auth> to be a child of <disk>, we'll need
to keep track of how it was read so that when writing out we'll know
whether to format as child of <disk> or <source>. For the argv2xml
parsing, let's format under <source> as a preference. Do not allow
<auth> to be both a child of <disk> and <source>.

Modify the qemuxml2argvtest to add a parse failure when there is an
<auth> as a child of <disk> *and* an <auth> as a child of <source>.

Add tests to validate that if the <auth> was found in <source>, then
the resulting xml2xml and xml2arg works just fine.  The two new .args
file are exact copies of the non "-source" version of the file.

The virschematest will read the new test files and validate from a
RNG viewpoint things are fine

Update the virstoragefile, virstoragetest, and args2xml file to show
the "preference" to place <auth> as a child of <source>.
2017-10-19 15:26:49 -04:00
Michal Privoznik
eebfdcb41e conf: Pass xmlopt down to virDomainDeviceInfoParseXML
This function is going to make decisions based on the features
set per each driver. For that we need the virDomainXMLOption
object.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-10-19 17:33:29 +02:00
Michal Privoznik
93ef9cf21d virDomainObjGetOneDefState: Fix error message
It looks like the error message was copied from virsh, because
that's where we have @ctl. Nevertheless, it's @flags which is
invalid, not @ctl.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-10-19 17:28:56 +02:00
Peter Krempa
a4bac46c96 qemu: address: Remove dead code when un-reserving PCI address
The code can't fail so having error handling is pointless.
2017-10-19 14:50:50 +02:00
Ján Tomko
513a8d4588 qemu: allow cold unplugging of input devices
https://bugzilla.redhat.com/show_bug.cgi?id=1379603
2017-10-19 14:42:10 +02:00
Ján Tomko
2690b5b930 conf: audit passthrough input devices at domain startup
Introduce virDomainAuditInput and use it to log the evdev passed
to the guest.
2017-10-19 14:34:21 +02:00
Pavel Hrdina
d66fc71d31 qemu: implement virDomainSetLifecycleAction() API
There is one limitation for using this API, when the guest is started
with all actions set to "destroy" we put "-no-reboot" on the QEMU
command line.  That cannot be changed while QEMU is running and
the QEMU process is always terminated no matter what is configured
for any action.

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

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 11:52:38 +02:00
Pavel Hrdina
1a2f34e363 lib: introduce virDomainSetLifecycleAction() API
Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 11:52:26 +02:00
Pavel Hrdina
8c85b1ed4a conf: merge virDomainLifecycleCrashAction with virDomainLifecycleAction
There is no need to have two different enums where one has the same
values as the other one with some additions.

Currently for on_poweroff and on_reboot we allow only subset of actions
that are allowed for on_crash.  This was covered in parse time using
two different enums.  Now to make sure that we don't allow setting
actions that are not supported we need to check it while validating
domain config.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 11:52:09 +02:00
Pavel Hrdina
1ccf35b4f2 conf: introduce virDomainLifecycle enum to list all lifecycle types
Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 11:52:06 +02:00
Pavel Hrdina
55c63295b2 conf: rename virDomainLifecycleAction enum functions
Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 11:52:04 +02:00
Pavel Hrdina
21068580d6 conf: rename lifecycle enum values to correspond with typedef keyword
Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 11:51:53 +02:00
Erik Skultety
643c74abff nodedev: Move privileged flag from udev private data to driver's state
Even though hal doesn't make use of it, the privileged flag is related
to the daemon/driver rather than the backend actually used.
While at it, get rid of some tab indentation in the driver state struct.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2017-10-19 08:54:52 +02:00
Erik Skultety
b08017ca54 maint: Replace tabs with spaces in all source files in repo
So we have a syntax-check rule to catch all tab indents but it naturally
can't catch tab spacing, i.e. as a delimiter. This patch is a result of
running 'vim -en +retab +wq'
(using tabstop=8 softtabstop=4 shiftwidth=4 expandtab) on each file from
a list generated by the following:
find . -regextype gnu-awk \
         -regex ".*\.(rng|syms|html|s?[ch]|py|pl|php(\.code)?)(\.in)?" \
         | xargs git grep -lP "\t"

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2017-10-18 13:25:10 +02:00
Nikolay Shirokovskiy
921d61575d conf: fix use of uninitialized variable
If same boot order is specified twice (or more) in domain xml
we call free for uninitiaziled loadparm on cleanup in virDomainDeviceBootParseXML
and SIGABRT (or similar) as a result.
2017-10-17 15:49:25 -04:00
Jiri Denemark
3276416904 conf: Introduce virCPUDefFindFeature
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-17 15:08:05 +02:00
Peter Krempa
a693fdba01 Terminate backing chains explicitly
Express a properly terminated backing chain by putting a
virStorageSource of type VIR_STORAGE_TYPE_NONE in the chain. The newly
used helpers simplify this greatly.

The change fixes a bug as formatting an incomplete backing chain and
parsing it back would end up in expressing a terminated chain since
src->backingStoreRaw was not populated. By relying on the terminator
object this can be now processed appropriately.
2017-10-17 06:19:18 +02:00
Peter Krempa
0a294a8e28 util: storagefile: Add helpers to check presence of backing store
Add helpers that will simplify checking if a backing file is valid or
whether it has backing store. The helper virStorageSourceIsBacking
returns true if the given virStorageSource is a valid backing store
member. virStorageSourceHasBacking returns true if the virStorageSource
has a backing store child.

Adding these functions creates a central points for further refactors.
2017-10-17 06:19:18 +02:00
Peter Krempa
ee4d2df87d storage: Fill in 'type' field for virStorageSource in storage driver
Storage driver uses virStorageSource only partially to store it's
configuration but fully when parsing backing files of storage volumes.
This patch sets the 'type' field to a value other than
VIR_STORAGE_TYPE_NONE so that further patches can add a terminator
element to backing chains without breaking iteration.
2017-10-17 06:19:18 +02:00
Peter Krempa
c6231a6a6c util: storage: Store backing chain index in virStorageSource
The backing store indexes were not bound to the storage sources in any
way. To allow us to bind a given alias to a given storage source we need
to save the index in virStorageSource. The backing store ids are now
generated when detecting the backing chain.

Since we don't re-detect the backing chain after snapshots, the
numbering needs to be fixed there.
2017-10-17 06:19:18 +02:00
Peter Krempa
8b13c37f0b conf: domain: Simplify return from backing store parser
Use VIR_STEAL_PTR to remove conditional cleanup.
2017-10-17 06:19:18 +02:00
Jiri Denemark
20664ec779 conf: Introduce virDomainCapsCPUModelsGet
This internal API can be used to find a specific CPU model in
virDomainCapsCPUModels list.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-16 09:23:17 +02:00
Jiri Denemark
0861080f0e conf: Add usability blockers to virDomainCapsCPUModel
When a hypervisor marks a CPU model as unusable on the current host, it
may also give us a list of features which prevent the model from being
usable. Storing this list in virDomainCapsCPUModel will help the CPU
driver with creating a host-model CPU configuration.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-16 09:21:51 +02:00
Michal Privoznik
02555bfe5c virDomainDeviceInfoParseXML: Clear whole @info on failure
Currently, if parsing of device info fails info->alias is freed.
It doesn't make much sense to leave the rest of the struct
behind.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-10-13 17:55:41 -07:00
Michal Privoznik
83a517cfe6 virDomainDeviceInfoParseXML: Separate address parsing into separate func
There's one 'return' in the middle of the function body. It's
very easy to miss and so it makes adding new code harder. Also
the function doesn't follow our style 100%.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-10-13 17:55:41 -07:00
Michal Privoznik
e3909729d2 virDomainNetFind: Report error if no device found
Every caller reports the error themselves. Might as well move it
into the function and thus unify it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-13 13:46:36 -07:00
John Ferlan
d6efd72915 nodedev: Convert virNodeDeviceObjHasCap to bool
It only returns 0 or 1 anyway, let's be realistic

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-10-12 21:36:44 -04:00
John Ferlan
1b4ad370e9 nodedev: Convert virNodeDeviceObjList to use RWObjectLockable
Let's use the RWObjectLockable for the various list lock mgmt.
Only time need Write lock will be for Add/Remove logic.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-10-12 21:36:43 -04:00
John Ferlan
c37efe19e8 secrets: Convert to use ObjectRWLockable
Let's use the ObjectRWLockable for the various list lock mgmt.
Only time need Write lock will be for Add/Remove logic.
2017-10-12 21:30:52 -04:00
John Ferlan
3dcab1de5d network: Convert virNetworkObjList to use RWObjectLockable
Let's use the RWObjectLockable for the various list lock mgmt.
Only time need Write lock will be for Add, Remove, and Prune logic.
2017-10-12 18:30:39 -04:00
Wim ten Have
137391bda7 numa: rename function virDomainNumaDefCPUFormat
Rename virDomainNumaDefCPUFormat to virDomainNumaDefCPUFormatXML,
matching its peer virDomainNumaDefCPUParseXML and the general
vir*{Format,Parse}XML conventions.

Signed-off-by: Wim ten Have <wim.ten.have@oracle.com>
Reviewed-by:   Jim Fehlig <jfehlig@suse.com>
2017-10-06 11:09:49 -06:00
John Ferlan
ee5498304f conf: Fix prototype/definition for virStoragePoolObj get functions
Modify virStoragePoolObjGetAutostartLink and
virStoragePoolObjGetConfigFile to return "const char *"
since that's how both are used and to ensure no one
tries to VIR_FREE the result.
2017-10-06 06:53:05 -04:00
Michal Privoznik
d86fd2402e virNetDevTapInterfaceStats: Allow caller to not swap the statistics
https://bugzilla.redhat.com/show_bug.cgi?id=1497410

The comment in virNetDevTapInterfaceStats() implementation for
Linux states that packets transmitted by domain are received by
the host and vice versa. Well, this is true but not for all types
of interfaces. For instance, for macvtaps when TAP device is
hooked right onto a physical device any packet that domain sends
looks also like a packet sent to the host. Therefore, we should
allow caller to chose if the stats returned should be straight
copy or swapped.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-05 09:16:05 +02:00
Michal Privoznik
784742c762 conf: Introduce virDomainNetFindByName
Small wrapper to lookup interface in domain definition by its
name.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-05 09:16:05 +02:00
Lin Ma
abca72faa4 qemu: Support multiqueue virtio-blk
qemu 2.7.0 introduces multiqueue virtio-blk(commit 2f27059).
This patch introduces a new attribute "queues". An example of
the XML:

<disk type='file' device='disk'>
  <driver name='qemu' type='qcow2' queues='4'/>

The corresponding QEMU command line:

-device virtio-blk-pci,scsi=off,num-queues=4,id=virtio-disk0

Signed-off-by: Lin Ma <lma@suse.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2017-10-04 17:50:53 +02:00
Michal Privoznik
7e9f171d8b virDomainNetFindIdx: Ignore auto generated MAC addresses
When detaching an <interface/> from a domain, the MAC address is
parsed and if not present one is generated. If no corresponding
interface is found in the domain, the following error is
reported:

error: operation failed: no device matching mac address 52:54:00:75:32:5b found

where the MAC address is the auto generated one. This might be
very confusing. Solution to this is to ignore auto generated MAC
address when looking up the device.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2017-10-04 17:10:12 +02:00
Peter Krempa
5047524baa conf: Split out parsing of network disk source XML elements
virDomainDiskSourceParse got to the point of being an ugly spaghetti
mess by adding more and more stuff into it. Split out parsing of network
disk information into a separate function so that it stays contained.
2017-10-04 10:38:49 +02:00
John Ferlan
a55eaced60 nwfilter: Don't have virNWFilterIPAddrMapAddIPAddr consume input
On pure success paths, virNWFilterIPAddrMapAddIPAddr was validly
consuming the input @addr; however, on failure paths it was possible
that virNWFilterVarValueCreateSimple succeed, but virNWFilterHashTablePut
failed resulting in virNWFilterVarValueFree being called to clean
up @val which also cleaned up the input @addr. Thus the caller had
no way to determine on failure whether it too should clean up the
passed parameter.

Instead, let's create a copy of the input @addr, then handle that
properly in the API allowing/forcing the caller to free it's own
copy of the input parameter.
2017-10-02 06:14:32 -04:00
John Ferlan
039702174c Revert "nwfilter: Fix possible segfault on sometimes consumed variable"
This reverts commit 6209bb32e5.

This turns out to be the wrong adjustment
2017-10-02 06:14:32 -04:00
Ashish Mittal
f170548502 util: Add TLS attributes to virStorageSource
Add an optional virTristateBool haveTLS to virStorageSource to
manage whether a storage source will be using TLS.

Sample XML for a VxHS disk:

<disk type='network' device='disk'>
  <driver name='qemu' type='raw' cache='none'/>
  <source protocol='vxhs' name='eb90327c-8302-4725-9e1b-4e85ed4dc251' tls='yes'>
    <host name='192.168.0.1' port='9999'/>
  </source>
  <target dev='vda' bus='virtio'/>
</disk>

Additionally add a tlsFromConfig boolean to control whether the TLS
setting was due to domain configuration or qemu.conf global setting
in order to decide whether to Format the haveTLS setting for either
a live or saved domain configuration file.

Update the qemuxml2xmltest in order to add a test to show the proper
parsing.

Also update the docs to describe the tls attribute.

Signed-off-by: Ashish Mittal <Ashish.Mittal@veritas.com>
Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-09-28 09:45:14 -04:00
John Ferlan
6209bb32e5 nwfilter: Fix possible segfault on sometimes consumed variable
The virNWFilterIPAddrMapAddIPAddr code can consume the @addr parameter
on success when the @ifname is found in the ipAddressMap->hashTable
hash table in the call to virNWFilterVarValueAddValue; however, if
not found in the hash table, then @addr is formatted into a @val
which is stored in the table and on return the caller would be
expected to free @addr.

Thus, the caller has no way to determine on success whether @addr was
consumed, so in order to fix this create a @tmp variable which will
be stored/consumed when virNWFilterVarValueAddValue succeeds. That way
the caller can free @addr whether the function returns success or failure.
2017-09-28 06:29:21 -04:00
ZhiPeng Lu
7e20862576 nwfilter: Fix memory leak in virNWFilterIPAddrMapAddIPAddr
If virNWFilterHashTablePut fails, then the @val was leaked.

Signed-off-by: ZhiPeng Lu <lu.zhipeng@zte.com.cn>
2017-09-27 07:23:44 -04:00
Pavel Hrdina
80740d9c66 Revert "vhost-user: add support reconnect for vhost-user ports"
This reverts commit edaf4ebe95.

This uses "reconnect" as attribute for <source> element, but we already
have a <reconnect> element for <source> element for chardev devices.

Since this is the same feature for different device it should be
presented in XML the same way.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-09-27 12:20:24 +02:00
Ján Tomko
fcd5c61cd4 conf: fix formatting of udp chardev attributes
It is possible (although possibly not very useful) to leave out
the service attribute when using <source mode='bind'/>

Fix the formatter bug introduced by commit 4a0da34 and format
the host when its present (checked for non-NULL inside
virBufferEscapeString) instead of basing it on the presence
of the service attribute.

https://bugzilla.redhat.com/show_bug.cgi?id=1455825
2017-09-26 13:36:51 +02:00
John Ferlan
2dd024754e util: Move virSecretUsageType to virsecret.h
Move the virSecretUsageType into the util.
2017-09-21 15:46:48 -04:00
Jiri Denemark
43a90eb7e8 conf: Drop unused VIR_DOMAIN_DEF_FORMAT_UPDATE_CPU
The only real usage of this flag was removed by "cpu_conf: Drop
updateCPU from virCPUDefFormat".

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-09-21 15:27:25 +02:00
Jiri Denemark
659a92f2e3 cpu_conf: Simplify formatting of guest CPU attributes
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-09-21 15:23:39 +02:00
Jiri Denemark
4fd179f518 cpu_conf: Drop updateCPU from virCPUDefFormat
In the past we updated host-model CPUs with host CPU data by adding a
model and features, but keeping the host-model mode. And since the CPU
model is not normally formatted for host-model CPU defs, we had to pass
the updateCPU flag to the formatting code to be able to properly output
updated host-model CPUs. Libvirt doesn't do this anymore, host-model
CPUs are turned into custom mode CPUs once updated with host CPU data
and thus there's no reason for keeping the hacks inside CPU XML
formatters.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-09-21 15:23:39 +02:00
ZhiPeng Lu
edaf4ebe95 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 crashed or restart, QEMU shoule be reconnect to OVS.

Signed-off-by: ZhiPeng Lu <lu.zhipeng@zte.com.cn>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-09-20 15:12:40 +02:00
John Ferlan
ccc8c311b2 storage: Internally represent @autostart as bool
Since it's been used that way anyway, let's just convert it to a bool
and only make the external representation be an int.
2017-09-19 08:30:37 -04:00
John Ferlan
5bf9b65501 storage: Introduce APIs to search/scan storage pool volumes list
Introduce virStoragePoolObjForEachVolume to scan each volume
calling the passed callback function until all volumes have been
processed in the storage pool volume list, unless the callback
function returns an error.

Introduce virStoragePoolObjSearchVolume to search each volume
calling the passed callback function until it returns true
indicating that the desired volume was found.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-09-19 08:28:50 -04:00
John Ferlan
40630a8e45 storage: Introduce storage volume add, delete, count APIs
Create/use virStoragePoolObjAddVol in order to add volumes onto list.

Create/use virStoragePoolObjRemoveVol in order to remove volumes from list.

Create/use virStoragePoolObjGetVolumesCount to get count of volumes on list.

For the storage driver, the logic alters when the volumes.obj list grows
to after we've fetched the volobj. This is an optimization of sorts, but
also doesn't "needlessly" grow the volumes.objs list and then just decr
the count if the virGetStorageVol fails.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-09-19 08:28:50 -04:00
John Ferlan
acd9a38069 storage: Fill in storage pool @active properly
It's a bool not an int, so use true/false and not 1/0
2017-09-19 08:28:50 -04:00
John Ferlan
407e6a3678 storage: Introduce virStoragePoolObjNew
Create/use a helper to perform object allocation.

Adjust storagevolxml2argvtest.c in order to use the allocator and
setting of the obj->def.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-09-19 08:28:38 -04:00
John Ferlan
b31982868a storage: Create accessor API's for virStoragePoolObj
In preparation for making a private object, create accessor API's for
consumer storage functions to use:

    virStoragePoolObjGetDef
    virStoragePoolObjSetDef
    virStoragePoolObjGetNewDef
    virStoragePoolObjDefUseNewDef
    virStoragePoolObjGetConfigFile
    virStoragePoolObjSetConfigFile
    virStoragePoolObjGetAutostartLink
    virStoragePoolObjIsActive
    virStoragePoolObjSetActive
    virStoragePoolObjIsAutostart
    virStoragePoolObjSetAutostart
    virStoragePoolObjGetAsyncjobs
    virStoragePoolObjIncrAsyncjobs
    virStoragePoolObjDecrAsyncjobs

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-09-19 07:58:15 -04:00
Jiri Denemark
57f3999d72 cpu_conf: Introduce virCPUDefList{Parse,Free}
For parsing a list of CPU XMLs into a NULL-terminated list of CPU defs.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-09-18 10:40:12 +02:00
John Ferlan
304e0f6d16 conf: Use virXMLFormatElement to format disk source network
Commit id 'e02ff020cac' neglected to use the attrBuf and childBuf
in the virDomainDiskSourceFormatNetwork call.

So make the necessary alterations to allow usage.
2017-09-15 08:17:32 -04:00
John Ferlan
fae7a7354c conf: Move <disk> encryption validation
Rather than checking during XML processing, move the check for
valid <encryption> into virDomainDiskDefParseValidate and alter
the text of the message slightly to be a bit more correct.
2017-09-15 08:12:26 -04:00
John Ferlan
c09c93cf57 conf: Move <disk> authdef validation
Rather than checking during XML processing, move the checks for correct
and valid auth into virDomainDiskDefParseValidate. This will introduce
virDomainDiskSourceDefParseAuthValidate to validate that the authdef
stored for the virStorageSource is valid. This can then be expanded
to service backingStore sources as well.

Alter the message text slightly as well to distinguish between an
unknown name and an incorrectly used name.  Since type is not a
mandatory field, add the NULLSTR() around the output of the unknown
error. NB, a config using unknown formatting would fail virschematest
since it only accepts 'iscsi' and 'ceph' as "valid" types.
2017-09-15 07:52:04 -04:00
John Ferlan
f64f03b5b1 qemu: Provide default LUN=0 for iSCSI if not provided
https://bugzilla.redhat.com/show_bug.cgi?id=1477880

If the "/#" is missing from the provided iSCSI path, then we need
to provide the default LUN of /0; otherwise, QEMU will fail to parse
the URL causing a failure to either create the guest or hotplug
attach the storage.

During post parse, for any iSCSI disk or hostdev, scan the source
path looking for the presence of '/', if found, then we can assume
the LUN is provided.  If not found, alter the input XML to add the
"/0".  This will cause the generated XML to have the generated
value when the domain config is saved after post parse.
2017-09-12 10:33:25 -04:00
Ján Tomko
90cd99a42e conf: validate IOMMU interrupt remapping setting
This option requires:
  <ioapic driver='qemu'/>

Report an error in case someone tries to combine
it with different ioapic setting.

Setting 'eim' on without enabling 'intremap' does not make sense.

https://bugzilla.redhat.com/show_bug.cgi?id=1457610
2017-09-11 14:56:07 +02:00
Ján Tomko
73c336eb46 conf: use virXMLFormatElement for <iommu>
Simplify the formatting function even further.
2017-09-11 09:45:34 +02:00
Ján Tomko
e844b6e12c conf: use virXMLFormatElement for <iommu><driver>
Use the new helper to simplify the code.
This also fixes the bug of not formatting 'eim' in the useless
case if it's the only enabled attribute.
2017-09-11 09:45:34 +02:00
Michal Privoznik
c57f3fd2f8 conf: Validate device on update-device
https://bugzilla.redhat.com/show_bug.cgi?id=1439991

Whenever a device is being updated via
virDomainUpdateDeviceFlags() API, we parse the device XML and
ideally run some generic checks to validate the configuration
(e.g. if device defines per-device boot order but the domain has
os/boot element already). Well, that's the theory - due to a
missing check we've jumped early from that check function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2017-09-06 11:19:30 +02:00
Cole Robinson
ef08a54538 qemu: Set default video type in qemu PostParse
And not generic domain_conf code. We will need qemu private functions
in a bit.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2017-09-05 10:41:32 -04:00
Cole Robinson
29a90f071d conf: domain: move video type validation to DeviceDefValidate
This allows drivers to set their own default. But if a driver neglects
to fill one in, we still error like we previously would at parse time.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2017-09-05 10:41:32 -04:00
Cole Robinson
a2ca7ca52e conf: domain: add VIDEO_TYPE_DEFAULT
Will be needed for future patches to pull the default video type
setting out of XML parsing routines.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2017-09-05 10:41:32 -04:00
Pavel Hrdina
393543910d conf: add reconnect to virDomainChrSourceDef(Copy|IsEqual)
Missed by 9aa72a6dd5.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-30 13:33:30 +02:00
Martin Kletzander
265d0bed0b conf: Clean up and report error in virDomainGenerateMachineName
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2017-08-29 11:17:16 +02:00
Martin Kletzander
2a544e3130 conf: Clean up and report error in virDomainCapsFormat
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2017-08-29 11:17:16 +02:00
Martin Kletzander
5102be52d8 conf: Properly truncate wide character names in virDomainObjGetShortName
We always truncated the name at 20 bytes instead of characters.  In
case 20 bytes were in the middle of a multi-byte character, then the
string became invalid and various parts of the code would error
out (e.g. XML parsing of that string).  Let's instead properly
truncate it after 20 characters instead.

We cannot test this in our test suite because we would need to know
what locales are installed on the system where the tests are ran and
if there is supported one (most probably there will be, but we cannot
be 100% sure), we could initialize gettext in qemuxml2argvtest, but
there would still be a chance of getting two different (both valid,
though) results.

In order to test this it is enough to start a machine with a name for
which trimming it after 20 bytes would create invalid sequence (e.g.
1234567890123456789č where č is any multi-byte character).  Then start
the domain and restart libvirtd.  The domain would disappear because
such illegal sequence will not go through the XML parser.  And that's
not a bug of the parser, it should not be in the XML in the first
place, but since we don't use any sophisticated formatter, just
mash some strings together, the formatting succeeds.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2017-08-29 11:17:16 +02:00
Pavel Hrdina
9aa72a6dd5 conf: introduce reconnect element for chardev source
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-29 10:30:05 +02:00
John Ferlan
5aaa304f8d network: Fix virNetworkObjBridgeInUse return type
Rather than an int, it returns a bool - so let's define it that way

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-08-28 14:02:22 -04:00
John Ferlan
c447086f01 Revert "interface: Consume @def in virInterfaceObjNew"
This reverts commit 92840eb3a7.

More recent reviews/changes don't have the vir*ObjNew APIs
consuming the @def, so remove from Interface as well. Changes
needed to also deal with conflicts from commit id '46f5eca4'.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-08-28 14:02:22 -04:00
Pavel Hrdina
e02ff020ca conf: don't close the source element inside different function
While formatting disk or chardev element they both uses
virDomainDiskSourceDefFormatSeclabel() function which also closes
the source element.  This is not extendable.

Use the new virXMLFormatElement() to properly format the source
element with possible child elements.

As a side effect it fixes a bug in disk source formatting.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-28 14:02:50 +02:00
Pavel Hrdina
ef3ea17f62 util: introduce virBufferSetChildIndent macro
Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-28 14:02:34 +02:00
Cole Robinson
ac87932ee3 conf: add virDomainVideoDefNew
To handle setting a default heads value. Convert callers that were
doing it by hand

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
2017-08-27 09:38:12 -04:00
Ján Tomko
126e6f381a conf: check address type for USB hostdevs
https://bugzilla.redhat.com/show_bug.cgi?id=1225339
2017-08-24 09:28:53 +02:00
Ján Tomko
cdf72e19d9 conf: move hostdev address validation to virDomainHostdevDefValidate
For selected hostdev types, we validate that the address type
matches the subsystem type when parsing the XML.

Move it to the validation phase, to allow extending the checks
to other subsystem types without making existing domains disappear.
2017-08-24 09:28:53 +02:00
Ján Tomko
a530078cd2 conf: do not count per-device boot elements when parsing <os><boot>
When parsing bootable devices, we maintain a bitmap of used
<boot order=""> elements. Use it in the post-parse function
to figure out whether the user tried to mix per-device and
per-domain boot elements.

This removes the need to count them twice.
2017-08-22 17:47:24 +02:00
Ján Tomko
4b759a4041 conf: create a thin wrapper above virDomainDefPostParse
Rename the original function to virDomainDefPostParseInternal
to allow adding arguments that will be only used by the internal
version.
2017-08-22 17:47:24 +02:00
Ján Tomko
c4480eef08 conf: rename virDomain*PostParseInternal to virDomain*PostParseCommon
These functions contain the post-parse steps common for all drivers.
Rename it to use the 'Common' prefix, instead of the vagueness
of 'Internal', leaving 'Internal' available for other vague uses.
2017-08-22 17:47:23 +02:00
Pavel Hrdina
1e4cc18890 conf: move chardev validation into virDomainDeviceDefValidateInternal
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-22 17:44:36 +02:00
Pavel Hrdina
a4ba59ff4b conf: separate PTY chardev source parsing
There is no reason why to share the same code for PTY and other file
based chardev source types.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-22 17:44:36 +02:00
Pavel Hrdina
9b341bbf41 conf: move FILE chardev source parsing to separate function
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-22 17:44:36 +02:00
Pavel Hrdina
65f4e2ff27 conf: assign parsed strings directly into chardev source definition
Since the source element is parsed only once for these type of
character devices we don't have to use temporary variable and
check whether the variable was already set.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-22 17:44:36 +02:00
Pavel Hrdina
2c9b97d842 conf: move UNIX chardev source parsing to separate function
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-22 17:44:36 +02:00
Pavel Hrdina
34e0eb7dc4 conf: move UDP chardev source parsing to separate function
The extra check whether (connect|bind)(Host|Service) was set is
required because for UDP chardev there can be two source elements.
Without the check there could be a memory leak.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-22 17:44:36 +02:00
Pavel Hrdina
40b0f40b54 conf: move TCP chardev source parsing to separate function
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-22 17:44:36 +02:00
Pavel Hrdina
9ed225e910 conf: move mode parsing of chardev source to separate function
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-22 17:44:36 +02:00
Pavel Hrdina
3672fc99f4 conf: move chardev log parsing to separate function
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-22 17:44:36 +02:00
Pavel Hrdina
f2be5b38f0 conf: move chardev protocol parsing to separate function
In order to ensure that the default protocol is RAW, explicitly
assigning VIR_DOMAIN_CHR_TCP_PROTOCOL_RAW = 0.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-22 17:43:51 +02:00
Pavel Hrdina
209fa11b02 conf: error out for multiple protocol elements while parsing chardev
Remove check whether a variable was already set because the element
is parsed only once now.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-22 17:28:40 +02:00
Pavel Hrdina
23482e4b1e conf: error out for multiple log elements while parsing chardev
Remove check whether a variable was already set because the element
is parsed only once now.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-22 17:28:40 +02:00
Pavel Hrdina
21bfd1e9b9 conf: error out for multiple source elements while parsing chardev
Currently we accept and correctly parse this chardev XML:

  ...
  <channel type='tcp'>
    <source mode='connect'/>
    <source mode='bind' host='localhost'/>
    <source service='4567'/>
    <target type='virtio' name='test'/>
  </channel>
  ...

The parsed formatted XML is:

  ...
  <channel type='tcp'>
    <source mode='connect' host='localhost' service='4567'/>
    <target type='virtio' name='test'/>
  </channel>
  ...

That behavior is super wrong and should not be allowed.  If you notice
the current parse takes the first found attribute and uses that value,
so for example from the "<source mode='bind' host='localhost'/>" only
the "host" attribute is used.  It works the same way for all possible
attributes that we are able to parse for source element.

This patch enforces providing only one source element for all character
devices, only for UDP type we allow to provide two source elements
since you can specify both modes.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-22 17:28:40 +02:00
Pavel Hrdina
7d0ff9430b conf: switch from while to for loop for chardev parsing
This removes one level of indentation.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-22 17:28:40 +02:00
Ján Tomko
bad14fbbed conf: useserial: drop useless check for serial devices
Since its introduction in commit 874e65aa, if someone requests:
<os><bios useserial="yes"/><os/>
we report an error if we cannot successfully count the number
of serial devices via an XPath query.

Instead of fixing the check (and moving it to the validation phase,
to prevent existing domains from disappearing), drop it completely.
For QEMU, the number of serials is checked when building the command
line.
2017-08-22 09:44:28 +02:00
Andrea Bolognani
64357c3f93 conf: Use the correct limit for the number of PHBs
I mistakenly thought pSeries guests supported 32 PHBs,
but it turns out they only support 31. Validate the
target index accordingly.

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

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2017-08-21 13:11:49 +02:00
Andrea Bolognani
c9d75d655a conf: Move target index validation
Validation should happen after parsing, so the proper
location for it is virDomainControllerDefValidate()
rather than virDomainControllerDefParseXML().

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2017-08-21 13:11:48 +02:00