Commit Graph

3130 Commits

Author SHA1 Message Date
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
5bda835466 util: storage: Fill in default ports for gluster and iscsi
Our documentation provides them, so the helper should return them.
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
Daniel P. Berrange
407a281a8e Revert "Prevent more compiler optimization of mockable functions"
This reverts commit e4b980c853.

When a binary links against a .a archive (as opposed to a shared library),
any symbols which are marked as 'weak' get silently dropped. As a result
when the binary later runs, those 'weak' functions have an address of
0x0 and thus crash when run.

This happened with virtlogd and virtlockd because they don't link to
libvirt.so, but instead just libvirt_util.a and libvirt_rpc.a. The
virRandomBits symbols was weak and so left out of the virtlogd &
virtlockd binaries, despite being required by virHashTable functions.

Various other binaries like libvirt_lxc, libvirt_iohelper, etc also
link directly to .a files instead of libvirt.so, so are potentially
at risk of dropping symbols leading to a later runtime crash.

This is normal linker behaviour because a weak symbol is not treated
as undefined, so nothing forces it to be pulled in from the .a You
have to force the linker to pull in weak symbols using -u$SYMNAME
which is not a practical approach.

This risk is silent bad linkage that affects runtime behaviour is
not acceptable for a fix that was merely trying to fix the test
suite. So stop using __weak__ again.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-07-13 13:07:06 +01:00
Martin Kletzander
1701ba6fdc util: Don't leak linksrc in vircgroup
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2017-07-13 13:14:23 +02:00
Juan Hernandez
dacd160d74 Avoid hidden cgroup mount points
Currently the scan of the /proc/mounts file used to find cgroup mount
points doesn't take into account that mount points may hidden by other
mount points. For, example in certain Kubernetes environments the
/proc/mounts contains the following lines:

  cgroup /sys/fs/cgroup/net_prio,net_cls cgroup ...
  tmpfs /sys/fs/cgroup tmpfs ...
  cgroup /sys/fs/cgroup/net_cls,net_prio cgroup ...

In this particular environment the first mount point is hidden by the
second one. The correct mount point is the third one, but libvirt will
never process it because it only checks the first mount point for each
controller (net_cls in this case). So libvirt will try to use the first
mount point, which doesn't actually exist, and the complete detection
process will fail.

To avoid that issue this patch changes the virCgroupDetectMountsFromFile
function so that when there are duplicates it takes the information from
the last line in /proc/mounts. This requires removing the previous
explicit condition to skip duplicates, and adding code to free the
memory used by the processing of duplicated lines.

Related-To: https://bugzilla.redhat.com/1468214
Related-To: https://github.com/kubevirt/libvirt/issues/4
Signed-off-by: Juan Hernandez <jhernand@redhat.com>
2017-07-13 09:37:52 +02:00
Daniel P. Berrange
e4b980c853 Prevent more compiler optimization of mockable functions
Currently all mockable functions are annotated with the 'noinline'
attribute. This is insufficient to guarantee that a function can
be reliably mocked with an LD_PRELOAD. The C language spec allows
the compiler to assume there is only a single implementation of
each function. It can thus do things like propagating constant
return values into the caller at compile time, or creating
multiple specialized copies of the function body each optimized
for a different caller. To prevent these optimizations we must
also set the 'noclone' and 'weak' attributes.

This fixes the test suite when libvirt.so is built with CLang
with optimization enabled.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-07-11 13:57:12 +01:00
Daniel P. Berrange
d8f8c7a83d Remove network constants out of internal.h
The HOST_NAME_MAX, INET_ADDRSTRLEN and VIR_LOOPBACK_IPV4_ADDR
constants are only used by a handful of files, so are better
kept in virsocketaddr.h or the source file that uses them.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-07-11 13:57:11 +01:00
Peter Krempa
6d7cdec63d util: storage: Always deflatten JSON pseudo-protocol objects
Now that the JSON deflattener is working sanely we can always attempt
the deflattening so that we can then parse the tree as expected.
2017-07-11 14:23:08 +02:00
Peter Krempa
428d175206 util: json: Recursively deflatten objects virJSONValueObjectDeflatten
If a value of the first level object contains more objects needing
deflattening which would be wrapped in an actual object the function
would not recurse into them.

By this simple addition we can fully deflatten the objects.
2017-07-11 14:20:05 +02:00
Peter Krempa
d40f4b3e67 util: json: Properly implement JSON deflattening
As it turns out sometimes users pass in an arbitrarily nested structure
e.g. for the qemu backing chains JSON pseudo protocol. This new
implementation deflattens now a single object fully even with nested
keys.

Additionally it's not necessary now to stick with the "file." prefix for
the properties.
2017-07-11 14:13:35 +02:00
Peter Krempa
f43b7d60d8 util: json: Don't remove the 'file' subobject when deflattening
Currently the function would deflatten the object by dropping the 'file'
prefix from the attributes. This does not really scale well or adhere to
the documentation.

Until we refactor the worker to properly deflatten everything we at
least simulate it by adding the "file" wrapper object back.
2017-07-11 14:10:31 +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
Peter Krempa
cadd96b3ea util: json: Add virJSONValueIsObject
Allows testing whether a virJSONValue is an object.
2017-07-11 14:02:28 +02:00
Cédric Bosdonnat
0980764dee util: share code between virExec and virCommandExec
virCommand is a version of virExec that doesn't fork, however it is
just calling execve and doesn't honors setting uid/gid and pwd.

This commit extrac those pieces from virExec() to a virExecCommon()
function that is called from both virExec() and virCommandExec().
2017-07-11 10:41:24 +02:00
Michal Privoznik
0fe4aa149f fdstream: Report error from the I/O thread
Problem with our error reporting is that the error object is a
thread local variable. That means if there's an error reported
within the I/O thread it gets logged and everything, but later
when the event loop aborts the stream it doesn't see the original
error. So we are left with some generic error. We can do better
if we copy the error message between the threads.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-07-11 08:41:01 +02:00
Michal Privoznik
3a2ca2fbe4 virfdstream: Check for thread error more frequently
When the I/O thread quits (e.g. due to an I/O error, lseek()
error, whatever), any subsequent virFDStream API should return
error too. Moreover, when invoking stream event callback, we must
set the VIR_STREAM_EVENT_ERROR flag so that the callback knows
something bad happened.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-07-11 08:40:13 +02:00
Peter Krempa
d077fbc221 util: netdevbridge: Refactor error handling in virNetDevBridgeCreate
Replace the switch statement with a simpler if statement. This also
removes the fallthrough path that coverity was complaining about.
2017-06-28 15:27:17 +02:00
Martin Kletzander
8110b4e073 util: Extract locale-related fixes into separate functions
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2017-06-26 09:20:08 +02:00
John Ferlan
5431055d2b util: Force reading of meta data to get encryption capacity value
https://bugzilla.redhat.com/show_bug.cgi?id=1371892

As it turns out the volume create, build, and refresh path was not peeking
at the meta data, so immediately after a create operation the value displayed
for capacity was still incorrect. However, if a pool refresh was done the
correct value was fetched as a result of a meta data peek.

The reason is it seems historically if the file type is RAW then peeking
at the file just took the physical value for the capacity. However, since
we know if it's an encrypted file, then peeking at the meta data will be
required in order to get a true capacity value.

So check for encryption in the source and if present, use the meta data
in order to fill in the capacity value and set the payload_offset.
2017-06-24 06:43:25 -04:00
Michal Privoznik
edaf135657 virNetDevOpenvswitchInterfaceStats: Be more forgiving when fetching stats
https://bugzilla.redhat.com/show_bug.cgi?id=1461270

When fetching stats for a vhost-user type of interface, we run
couple of ovs-vsctl commands and parse their output. However, not
all stats exist at all times, for instance "rx_dropped" or
"tx_errors" can be missing. Thing is, we ask for a bulk of
statistics and if one of them is missing an error is reported
instead of returning the rest. Since we ignore errors, we fail to
set statistics. Fix this by asking for each piece alone.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-06-23 11:51:23 +02:00
John Ferlan
10c2bb2b19 util: Introduce virObjectGetLockableObj
Split out the object fetch in virObject{Lock|Unlock} into a helper

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-06-22 09:34:40 -04:00
John Ferlan
209a95e354 util: Formatting cleanups to virobject API
Alter to use more recent formatting guidelines

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-06-22 09:34:40 -04:00
Martin Kletzander
c9d1e5951c util: Move locale.h include from virutil to virstring
Commit 5c54d29aae forgot to do that when moving the only function
using it and it broke the build on some platforms.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2017-06-22 14:30:27 +02:00
Julio Faracco
96a9b9a7f0 util: fix locale problem with virStrToDouble().
This commit fixes a locale problem with locales that use comma as a mantissa
separator. Example: 12.34 en_US = 12,34 pt_BR. Since strtod() is a non-safe
function, virStrToDouble() will have problems to parse double numbers from
kernel settings and other double numbers from static files (XMLs, JSONs, etc).

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

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
2017-06-22 11:30:20 +02:00
Julio Faracco
5c54d29aae util: moving virDoubleToStr() from virutil to virstring.
The function virDoubleToStr() is defined in virutil.* and virStrToDouble() is
defined in virstring.*. Joining both functions into the same file makes more
sense.

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
2017-06-22 11:30:20 +02:00
Peter Krempa
296a53313f util: storage: Make @backingFormat optional in virStorageFileGetMetadataInternal
Some callers don't need to know the backing format. Make the argument
optional by using a dummy int if NULL is passed.
2017-06-20 16:50:26 +02:00
Peter Krempa
e4c3eff70e util: storage: Export virStorageIsRelative 2017-06-20 13:25:55 +02:00
Peter Krempa
b16133b114 util: storage: adapt to changes in JSON format for sheepdog
Since qemu 2.9 the options changed from a monolithic string into fine
grained options for the json pseudo-protocol object.
2017-06-20 08:40:18 +02:00
Peter Krempa
ea2c418ac3 util: storage: adapt to changes in JSON format for ssh
Since qemu 2.9 the options changed from a monolithic string into fine
grained options for the json pseudo-protocol object.
2017-06-20 08:40:18 +02:00
Peter Krempa
4fac5a1935 util: storage: adapt to changes in JSON format for ceph/rbd
Since qemu 2.9 the options changed from a monolithic string into fine
grained options for the json pseudo-protocol object.
2017-06-20 08:40:18 +02:00
Peter Krempa
35d23f90b2 util: storage: adapt to changes in JSON format for NBD
Since 2.9 the host and port for NBD are no longer directly under the
json pseudo-protocol object, but rather belong to a sub-object called
'server'.
2017-06-20 08:40:18 +02:00
Peter Krempa
b24bc54080 util: storage: Add JSON parser for new options in iSCSI protocol
Starting from qemu 2.9, more granular options are supported. Add parser
for the relevant bits.

With this patch libvirt is able to parse the host and target IQN of from
the JSON pseudo-protocol specification.

This corresponds to BlockdevOptionsIscsi in qemu qapi.
2017-06-20 08:40:18 +02:00
Peter Krempa
299aff7e0c util: storage: Report errors when source host data is missing
Merge the reporting of the missing source host data into the parser
functions so that callers don't have to do it separately.
2017-06-20 08:40:18 +02:00
Peter Krempa
49ed98a457 util: storage: Split out parsing of TCP network host from JSON pseudoprotocol
Few backing protocols support only TCP. Split out the function which
will correspond to parsing qemu's InetSocketAddressBase.
2017-06-20 08:40:18 +02:00
Peter Krempa
1f915d40a2 util: storage: Add support for type 'inet' in virStorageSourceParseBackingJSONSocketAddress
'SocketAddress' structure was changed to contain 'inet' instead of
'tcp' since qemu commit c5f1ae3ae7b. Existing entries have a backward
compatibility layer.

Libvirt will parse 'inet' and 'tcp' as equivalents.
2017-06-20 08:40:18 +02:00
Peter Krempa
6402f402d4 util: storage: make virStorageSourceParseBackingJSONGlusterHost universal
The same json strucutre is used for NBD and sheepdog volumes for
specifying of the host. Rename the function and fix up error messages to
be more universal.
2017-06-19 15:50:29 +02:00
Peter Krempa
506b80c84e util: storage: Add missing return to virStorageSourceParseBackingJSONGluster
If the number of servers is not expected the code would report an error
but would not return failure.
2017-06-19 15:50:29 +02:00
Peter Krempa
236e1f7e8c util: storage: Output parsed network backing store string to debug log 2017-06-19 15:50:29 +02:00
Martin Kletzander
307a205e25 qemu: Allow live-updates of coalesce settings
Change the settings from qemuDomainUpdateDeviceLive() as otherwise the
call would succeed even though nothing has changed.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2017-06-16 10:18:35 +02:00
Daniel P. Berrange
5e9ca5508d Use sys/uio.h for writev()
With glibc >= 2.25.90 writev() is only available if you explicitly
include sys/uio.h. This matches the documented requirements, but
older glibc and other *NIX pulled in writev indirectly so the bug
wasn't noticed previously.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-06-14 15:01:42 +01:00
Marc Hartmayer
adf846d3c9 Use ATTRIBUTE_FALLTHROUGH
Use ATTRIBUTE_FALLTHROUGH, introduced by commit
5d84f5961b, instead of comments to
indicate that the fall through is an intentional behavior.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
2017-06-12 19:11:30 -04:00
Pavel Hrdina
9fd816ed33 Revert "util: virqemu: introduce virQEMUBuildBufferEscape"
This reverts commit 22b02f4492.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2017-06-12 12:45:42 +02:00
Michal Privoznik
f3908d8557 virNetDevOpenvswitchGetVhostuserIfname: Fix off by one error
https://bugzilla.redhat.com/show_bug.cgi?id=1459091

We try to get the last element of the passed path by calling
strrch(path, '/'). However, the pointer that strrchr() returns
points at the slash, We want string that starts right after that.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-06-08 15:02:23 +02:00
Michal Privoznik
5004f121bc virFDStreamThread: Make sure we won't exceed @length
There's a problem with current streams after I switched them from
iohelper to thread implementation. Previously, iohelper made sure
not to exceed specified @length resulting in the pipe EOF
appearing at the exact right moment (the pipe was used to tunnel
the data from the iohelper to the daemon). Anyway, when switching
to thread I had to write the I/O code from scratch. Whilst doing
that I took an inspiration from the iohelper code, but since the
usage of pipe switched to slightly different meaning, there was
no 1:1 relationship between the codes.

Moreover, after introducing VIR_FDSTREAM_MSG_TYPE_HOLE, the
condition that should made sure we won't exceed @length was
completely wrong.

The fix is to:

a) account for holes for @length
b) cap not just data sections but holes too (if @length would be
exceeded)

For this purpose, the condition needs to be brought closer to the
code that handles holes and data sections.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-06-05 17:00:48 +02:00
Julio Faracco
4fd5c2fbce util: remove dead code inside virstoragefile
The host address or the socket path have already been checked at the
begining of the function virStorageSourceParseNBDColonString(). So,
when the parameter is not a unix socket, there is no reason to check
the address again because if it does not exists, the logic will fail
in the first IF conditional.

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
2017-06-02 09:39:10 +02:00
Julio Faracco
54aee01d87 util: fix wrong comparison inside virStoragePermsCopy()
VIR_STRDUP returns -1 if the string copy was not successful. So, the
current comparison/logic is throwing an error when VIR_STRDUP() returns
1. Only when source is NULL, it is considering as a success which is
not right.

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
2017-06-02 09:37:44 +02:00
Nitesh Konkar
4ae0f65669 util: hostcpu: Correctly report total number of vcpus in virHostCPUGetMap
Callers expect the return value to be the total number of vcpus in the
host (including offline vcpus). The refactor in c67e04e25f
broke this assumption by using virHostCPUGetOnlineBitmap which only
creates a bitmap long enough to hold the last online vcpu.

Report the full number of host vcpus by returning value from
virHostCPUGetCount().

Signed-off-by: Nitesh Konkar <nitkon12@linux.vnet.ibm.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2017-05-30 10:42:28 +02:00
Roman Bogorodskiy
981e2c7097 util: fix virfcp build on non-Linux
- Include virerror.h for virReportSystemError
 - Rename stub functions to match original function names
2017-05-26 20:00:51 +04:00
Bjoern Walk
c47a3b130d util: helper functions for fibre channel devices
We will need some convenient helper functions for managing sysfs-entries
for fibre channel-backed devices. Let's implement them and make them
available in the private API.

Signed-off-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
2017-05-26 10:44:05 -04:00