Commit Graph

1612 Commits

Author SHA1 Message Date
Pavel Hrdina
4e56a3e793 util: introduce virXMLFormatElement helper
This helper allows you to better structurize the code if some element
may or may not contains attributes and/or child elements.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-28 14:02:44 +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
Peter Krempa
c0ce84ca98 util: string: Introduce virStringHasChars
The helper returns true if a string contains any of the given chars.
virStringHasControlChars can be reimplemented using that helper.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-18 14:20:37 +02:00
Pavel Hrdina
561726cd7f util: introduce virXMLNodeContentString
It's equivalent of calling virXPathString("string(.)", ctxt) but it
doesn't have to use the XPath resolving and parsing.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-17 15:42:23 +02:00
Pavel Hrdina
827cf58d50 util: introduce virXMLPropStringLimit
The virXMLPropStringLimit is an equivalent of virXPathStringLimit
which should be preferred if you already have a XML dom node or
if you need to parse more than one property.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-17 15:42:08 +02:00
John Ferlan
bc9868aaf2 network: Introduce virNetworkObjIsPersistent
In preparation to privatize the virNetworkObj - create an accessor function
to get the current @persistent value.  Also change the value to a bool rather
than an unsigned int (since that's how it's generated anyway).

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-08-16 14:17:57 -04:00
John Ferlan
9e8227d76b network: Introduce virNetworkObj{Is|Set}Active
In order to privatize the virNetworkObj create accessors in virnetworkobj
in order to handle the get/set of the active value.

Also rather than an unsigned int, convert it to a boolean to match other
drivers representation and the reality of what it is.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-08-16 14:17:57 -04:00
John Ferlan
f57d8a7b32 network: Introduce virNetworkObj{Is|Set}Autostart
In preparation for privatizing the virNetworkObj structure, create
accessors for the obj->autostart.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-08-16 14:17:57 -04:00
John Ferlan
db207a6233 network: Add virNetworkObj Get/Set API's for @def and @newDef
In preparation for making the object private, create a couple of API's
to get the obj->def & obj->newDef and set the obj->def.

While altering networkxml2conftest.c to use the virNetworkObjSetDef
API, fix the name of the variable from @dev to @def

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-08-16 14:17:57 -04:00
John Ferlan
062c38ce75 network: Add virNetworkObj Get/Set API's for @floor_sum
In preparation for making the object private, create a couple of API's
to get/set the obj->floor_sum.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-08-16 14:17:57 -04:00
John Ferlan
7435404fd5 network: Introduce virNetworkObjGetClassIdMap
In preparation for privatizing virNetworkObj, create accessor function to
fetch the @classIdMap.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-08-16 14:17:57 -04:00
John Ferlan
8489d31cee network: Add virNetworkObj Get/Set API's for @dnsmasqPid and @radvdPid
In preparation for making the object private, create/use a couple of API's
to get/set the obj->dnsmasqPid and obj->radvdPid.

NB: Since the pid's can sometimes changed based on intervening functions,
be sure to always fetch the latest value.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-08-16 14:17:57 -04:00
John Ferlan
f4adeae09d network: Move macmap mgmt from bridge_driver to virnetworkobj
In preparation for having a private virNetworkObj - let's create/move some
API's that handle the obj->macmap. The API's will be renamed to have a
virNetworkObj prefix to follow conventions and the arguments slightly
modified to accept what's necessary to complete their task.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-08-16 14:17:57 -04:00
John Ferlan
070b6f7f55 network: Move and rename networkMacMgrFileName
Move networkMacMgrFileName into src/util/virmacmap.c and rename to
virMacMapFileName. We're about to move some more MacMgr processing
files into virnetworkobj and it doesn't make sense to have this helper
in the driver or in virnetworkobj.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-08-16 14:17:57 -04:00
John Ferlan
045d712c4b util: Introduce and use virObjectRWUnlock
Rather than overload virObjectUnlock as commit id '77f4593b' has
done, create a separate virObjectRWUnlock API that will force the
consumers to make the proper decision regarding unlocking the
RWLock's. Similar to the RWLockRead and RWLockWrite, use the
virObjectGetRWLockableObj helper. This restores the virObjectUnlock
code to using the virObjectGetLockableObj.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-08-14 21:41:59 -04:00
John Ferlan
908b33644e util: Introduce and use virObjectRWLockWrite
Instead of making virObjectLock be the entry point for two
different types of locks, let's create a virObjectRWLockWrite API
which will only handle the virObjectRWLockableClass objects.

Use the new virObjectRWLockWrite for the virdomainobjlist code
in order to handle the Add, Remove, Rename, and Load operations
that need to be very synchronous.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-08-14 21:41:59 -04:00
John Ferlan
99a72b3eb4 util: Rename virObjectLockRead to virObjectRWLockRead
Since the class it represents is based on virObjectRWLockableClass
and in order to make sure we differentiate just in case anyone somehow
believes they could use virObjectLockRead for a virObjectLockableClass,
let's rename the API to use the RW in the name. Besides the RW locks
refer to pthread_rwlock_{init|rdlock|wrlock|unlock|destroy} while the
other locks refer to pthread_mutex_{init|lock|unlock|destroy}.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-08-14 21:41:59 -04:00
Pavel Hrdina
5bd8a1c5d8 util: introduce virXMLNodeNameEqual
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-08-14 14:31:52 +02:00
Martin Kletzander
af4270400a Move resctrl-related code from conf/capabilities to util/virresctrl
It doesn't access anything from conf/ and ti will be needed to use
from other util/ places.  This split makes the separation clearer.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2017-08-14 10:01:12 +02:00
Laine Stump
48f33bb5df util: new function virNetDevGetPhysPortID()
On Linux each network device *can* (but not necessarily *does*) have
an attribute called phys_port_id which can be read from the file of
that name in the netdev's sysfs directory. The examples I've seen have
been a many-digit hexadecimal number (as an ASCII string).

This value can be useful when a single PCI device is associated with
multiple netdevs (e.g a dual port Mellanox SR-IOV NIC - this card has
a single PCI Physical Function (PF), and that PF has two netdevs
associated with it (the "net" subdirectory of the PF in sysfs has two
links rather than the usual single link to a netdev directory). Each
of the PF netdevs has a different phys_port_id. The Virtual Functions
(VF) are similar - the PF (a PCI device) has "n" VFs (also each of
these is a PCI device), each VF has two netdevs, and each of the VF
netdevs points back to the VF PCI device (with the "device" entry in
its sysfs directory) as well as having a phys_port_id matching the PF
netdev it is associated with.

virNetDevGetPhysPortID() simply attempts to read the phys_port_id for
the given netdev and return it to the caller. If this particular
netdev driver doesn't support phys_port_id, it returns NULL (*not* a
NULL-terminated string, but a NULL pointer) but still counts it as a
success.
2017-08-11 18:25:00 -04:00
Ján Tomko
e9f3222705 introduce virConfReadString
Rewrite virConfReadMem to take a null-terminated string.
All the callers were calling strlen on it anyway.
2017-08-08 12:19:17 +02:00
Peter Krempa
0b1ecf7b53 util: hash: Make virHashCodeGen mockable
Export the function from the util module so that dynamic linking can
override it.
2017-08-03 09:49:15 +02:00
Michal Privoznik
d8447faa61 virnetworkobj: Make virNetworkObjFindBy{UUID,Name}Locked() static again
These functions were made exportable back in 3aa3e072 when I was
splitting network code into parsing and list management parts.
Since then the split is finished now and these two functions do
not need to be exported anymore.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-08-02 10:03:23 +02:00
Peter Krempa
3c60388591 util: buffer: Add virBufferStrcatVArgs
Split out the worker loop into a separate function and export it.

Reviewed-by: Eric Blake <eblake@redhat.com>
2017-07-27 09:31:14 +02:00
Pavel Hrdina
ac3eb2ab24 util: introduce virFileCache
The new virFileCache will nicely handle the caching logic for any data
that we would like to cache.  For each type of data we will just need
to implement few handlers that will take care of creating, validating,
loading and saving the cached data.

The cached data must be an instance of virObject.

Currently we cache QEMU capabilities which will start using
virFileCache.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2017-07-26 15:31:25 +02:00
Martin Kletzander
eaf2c9f891 Move machineName generation from virsystemd into domain_conf
It is more related to a domain as we might use it even when there is
no systemd and it does not use any dbus/systemd functions.  In order
not to use code from conf/ in util/ pass machineName in cgroups code
as a parameter.  That also fixes a leak of machineName in the lxc
driver and cleans up and de-duplicates some code.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2017-07-25 17:02:27 +02:00
Michal Privoznik
2d3c7122c8 Revert "virthread: Introduce virRWLockInitPreferWriter"
This reverts commit 328bd24443.

As it turns out, this is not portable and very Linux & glibc
specific. Worse, this may lead to not starving writers on Linux
but everywhere else. Revert this and if the starvation occurs
resolve it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
2017-07-25 10:56:03 +02:00
Andrea Bolognani
bbda2883c4 conf: Rename virDomainControllerIsPCIHostBridge() to IsPSeriesPHB()
The original name didn't hint at the fact that PHBs are
a pSeries-specific concept.

Suggested-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2017-07-25 09:42:38 +02:00
Michal Privoznik
77f4593b09 virobject: Introduce virObjectRWLockable
Up until now we only had virObjectLockable which uses mutexes for
mutually excluding each other in critical section. Well, this is
not enough. Future work will require RW locks so we might as well
have virObjectRWLockable which is introduced here.

Moreover, polymorphism is introduced to our code for the first
time. Yay! More specifically, virObjectLock will grab a write
lock, virObjectLockRead will grab a read lock then (what a
surprise right?). This has great advantage that an object can be
made derived from virObjectRWLockable in a single line and still
continue functioning properly (mutexes can be viewed as grabbing
write locks only). Then just those critical sections that can
grab a read lock need fixing. Therefore the resulting change is
going to be way smaller.

In order to avoid writer starvation, the object initializes RW
lock that prefers writers.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-07-24 15:54:06 +02:00
Michal Privoznik
328bd24443 virthread: Introduce virRWLockInitPreferWriter
We already have virRWLockInit. But this uses pthread defaults
which prefer reader to initialize the RW lock. This may lead to
writer starvation. Therefore we need to have the counterpart that
prefers writers. Now, according to the
pthread_rwlockattr_setkind_np() man page setting
PTHREAD_RWLOCK_PREFER_WRITER_NP attribute is no-op. Therefore we
need to use PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP
attribute. So much for good enum value names.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-07-24 15:54:06 +02:00
Peter Krempa
e8b69016b1 qemu: command: Rename and move qemuNetworkDriveGetPort
Move it to virstring.c and improve it to parse and validate ports. New
name is virStringParsePort.
2017-07-24 10:55:20 +02:00
Andrea Bolognani
66fa0d969a conf: Move some virDomainDeviceInfo functions
The virDomainDeviceInfo struct is defined in device_conf,
so generic functions that operate on it should also be
defined there rather than in domain_conf.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2017-07-21 17:18:40 +02:00
Andrea Bolognani
1d0c6f59b6 conf: Rename virDomainHostdevDefAlloc() to virDomainHostdevDefNew()
All other virDomain*Def follow this naming convention for
their allocation function.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2017-07-21 17:03:43 +02:00
Peter Krempa
a908e9e45e util: bitmap: Modify virBitmapSubtract to virBitmapIntersect
Since virBitmapSubtract is unused modify it to perform bitmap
intersection.
2017-07-20 16:14:50 +02:00
Antoine Millet
e484cb3eca Handle hotplug change on VLAN configuration using OVS
A new function virNetDevOpenvswitchUpdateVlan has been created to instruct
OVS of the changes. qemuDomainChangeNet has been modified to handle the
update of the VLAN configuration for a running guest and rely on
virNetDevOpenvswitchUpdateVlan to do the actual update if needed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-07-20 15:15:03 +02:00
John Ferlan
dae23ec345 nodedev: Convert virNodeDeviceObj to use virObjectLockable
Now that we have a bit more control, let's convert our object into
a lockable object and let that magic handle the create and lock/unlock.

This also involves creating a virNodeDeviceEndAPI in order to handle
the object cleanup for API's that use the Add or Find API's in order
to get a locked/reffed object. The EndAPI will unlock and unref the
object returning NULL to indicate to the caller to not use the obj.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-07-17 10:40:24 -04:00
John Ferlan
1c7bc64ef3 nodedev: Introduce virNodeDeviceObjListFindSCSIHostByWWNs
In an overall effort to privatize access to virNodeDeviceObj and
virNodeDeviceObjList into the virnodedeviceobj module, move the
object list parsing from node_device_driver and replace with a
call to a virnodedeviceobj helper. This follows other similar
APIs/helpers which peruse the object list looking for some specific
data in order to get/return an @device (virNodeDevice) object to
the caller.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-07-17 10:40:24 -04:00
John Ferlan
12fa16eb98 nodedev: Introduce virNodeDeviceGetSCSIHostCaps
We're about to move the call to nodeDeviceSysfsGetSCSIHostCaps from
node_device_driver into virnodedeviceobj, so move the guts of the code
from the driver specific node_device_linux_sysfs into its own API
since virnodedeviceobj cannot callback into the driver.

Nothing in the code deals with sysfs anyway, as that's hidden by the
various virSCSIHost* and virVHBA* utility function calls.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-07-17 10:40:24 -04:00
John Ferlan
881a486a7d nodedev: Alter node device obj list function names
Ensure that any function that walks the node device object list is prefixed
by virNodeDeviceObjList.

Also, modify the @filter param name for virNodeDeviceObjListExport to
be @aclfilter.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-07-17 10:40:24 -04:00
John Ferlan
9c5d98fd83 nodedev: Introduce virNodeDeviceObjListNew
In preparation to make things private, make the ->devs be pointers to a
virNodeDeviceObjList and then manage everything inside virnodedeviceobj

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-07-17 10:40:24 -04:00
John Ferlan
87e50c9cea nodedev: Alter virNodeDeviceObjRemove
Rather than passing the object to be removed by reference, pass by value
and then let the caller decide whether or not the object should be free'd
and how to handle the logic afterwards. This includes free'ing the object
and/or setting the local variable to NULL to prevent subsequent unexpected
usage (via something like virNodeDeviceObjRemove in testNodeDeviceDestroy).

For now this function will just handle the remove of the object from the
list for which it was placed during virNodeDeviceObjAssignDef.

This essentially reverts logic from commit id '61148074' that free'd the
device entry on list, set *dev = NULL and returned. Thus fixing a bug in
node_device_hal.c/dev_refresh() which would never call dev_create(udi)
since @dev would have been set to NULL.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-07-17 10:40:24 -04:00
John Ferlan
8a75cc4fcc nwfilter: Introduce virNWFilterObjListFindInstantiateFilter
Create a common API to handle the instantiation path filter lookup.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-07-15 23:00:30 -04:00
Andrea Bolognani
6e42d83f7c qemu: Automatically pick target index and model for pci-root controllers
pSeries guests will soon need the new information; luckily,
we can figure it out automatically most of the time, so
users won't have to worry about it.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2017-07-15 14:50:42 +02:00
Andrea Bolognani
c7af505ace conf: Make virDomainPCIAddressFlagsCompatible() private
There are no external users.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2017-07-15 14:50:42 +02:00
Andrea Bolognani
03776fe0d6 conf: Make virDomainPCIAddressSetGrow() private
There are no external users.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2017-07-15 14:50:42 +02:00
Andrea Bolognani
c79f97c83c conf: Move virDomainPCIAddressBusIsFullyReserved()
This function was private to the QEMU driver and was,
accordingly, called qemuDomainPCIBusFullyReserved().

However the function is really not QEMU-specific at
all, so it makes sense to move it closer to the
virDomainPCIAddressBus struct it operates on.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2017-07-15 14:50:42 +02:00
Peter Krempa
9756884d14 conf: Pre-fill default ports when parsing network disk sources
Fill them in right away rather than having to figure out at runtime
whether they are necessary or not.

virStorageSourceNetworkDefaultPort does not need to be exported any
more.
2017-07-14 16:05:46 +02:00
Peter Krempa
34ffc2ff41 util: Extract helper to retrieve default port for network protocol
Make the stuff hardcoded in qemu a global helper so that other parts of
the code can determine the default port too.
2017-07-14 16:05:46 +02:00
Michal Privoznik
37ef8763c4 conf: Rename and expose virDomainChrSourceDefPath
It comes very handy to have source path for chardevs. We already
have such function: virDomainAuditChardevPath() but it's static
and has name not suitable for exposing. Moreover, while exposing
it change its name slightly to virDomainChrSourceDefGetPath.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-07-11 14:45:15 +02:00
Peter Krempa
de75de7c97 util: Move JSON object deflattening code to json utility file
The code will become more universal so it makes more sense for it to
live with the rest of the JSON functions.
2017-07-11 14:02:28 +02:00