Commit Graph

5702 Commits

Author SHA1 Message Date
Andrea Bolognani
63d5a597ea tests/domaincaps: Don't mess with test name
Requiring the user to provide the final string themselves will
make subsequent changes easier to implement.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2019-10-24 17:21:20 +02:00
Andrea Bolognani
fa20e7b1bc tests: Rename domaincapsschemadata/ -> domaincapsdata/
The usual convention is to use ${foo}test.c for the test program
itself and either ${foo}data/ or ${foo}outdata/, depending on
whether it contains both input and output files or only the latter,
for the corresponding data directory.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2019-10-24 17:21:16 +02:00
Andrea Bolognani
c4d6465aa7 tests: testQemuCapsIterate: Pass prefix and version to callback
Right now we're passing a "base" string that contains both,
separated by an underscore. Some changes that we're going to
introduce later will require us to have the version number on its
own, and instead of delegating the task of splitting the two apart
to the callback it make more sense to perform it upfront.

This change results in quite a bit of churn because we're now
using the version number only, without the prefix, to calculate
the dummy microcodeVersion.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2019-10-24 17:21:14 +02:00
Andrea Bolognani
5a45ed9c96 tests: testQemuCapsIterate: Pass suffix to callback
Right now users need to hardcode the suffix, which is not a big
deal since they're the ones who passed it to testQemuCapsIterate()
in the first place; however, since we're already passing most of
the information to the callback and we're going to add more later
on, it makes sense to be consistent and pass the suffix too.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2019-10-24 17:21:12 +02:00
Andrea Bolognani
51495a4d73 tests: testQemuCapsIterate: Pass inputDir to callback
Right now users need to know input file live inside
TEST_QEMU_CAPS_PATH, which is bad layering.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2019-10-24 17:21:10 +02:00
Andrea Bolognani
29795544fd tests: testQemuCapsIterate: Validate suffix
We're going to depend on the fact that the suffix starts with a
dot later on, so we better ensure that it does.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2019-10-24 17:21:08 +02:00
Andrea Bolognani
85394f676d tests: testQemuCapsIterate: Don't ignore malformed file names
If files whose name doesn't follow the expected format are added
to the repository, it's better to make the test suite fail than to
silently ignore them.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2019-10-24 17:21:05 +02:00
Andrea Bolognani
dea6c10946 tests/qemucapabilities: Separate inputDir and outputDir
We'll need this later.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2019-10-24 17:20:49 +02:00
Michal Privoznik
3b4df5d350 Drop needless ret variable
In few places we have the following code pattern:

  int ret;
  ... /* @ret is not accessed here */
  ret = f(...);
  return ret;

This pattern can be written less verbose:

  ...
  return f(...);

This patch was generated with following coccinelle spatch:

  @@
  type T;
  constant C;
  expression f;
  identifier ret;
  @@
  -T ret = C;
   ... when != ret
  -ret = f;
  -return ret;
  +return f;

Afterwards I needed to fix a few places, e.g. comment in
virDomainNetIPParseXML() was removed too because coccinelle
thinks it refers to @ret while in fact it doesn't. Also in few
places it replaced @ret declaration with a few spaces instead of
removing the line. But nothing terribly wrong.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2019-10-24 08:10:37 +02:00
Pavel Hrdina
5f92046b77 m4: virt-selinux: remove obsolete checks
All OSes that we support have libselinux >= 2.5 except for Ubuntu 16.04
where the version is 2.4.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-10-23 14:30:50 +02:00
Peter Krempa
08e0ffe8f5 qemu: domain: Remove pointless return value in qemuDomainPrepareDiskSourceData
The function does not do anything that could fail. Remove the return
value.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2019-10-21 16:29:05 +02:00
Peter Krempa
aef87271be qemu: domain: Split out setup of virStorageSource from qemu driver config
qemuDomainPrepareDiskSourceData historically prepared everything but
we've split out the majority of the functionality so that it sets up
predominately only according to the configuration of the disk. There
was one leftover bit of setting the gluster debug level from the config.

Split this out into a separate function so that
qemuDomainPrepareDiskSourceData only prepares based on the disk.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
ACKed-by: Eric Blake <eblake@redhat.com>
2019-10-21 16:28:02 +02:00
Peter Krempa
e1b5a7b383 tests: Add test case for empty 'network' cdrom
We don't allow such config in the schema but the code can handle that so
add a test case supporting it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-21 15:59:52 +02:00
Peter Krempa
2c37dc7bda conf: Reset disk type if <source> element is completely missing
The disk type is not part of source and thus it's parsed earlier. This
bypasses the checks when parsing a disk type='network' if it's
completely missing the source.

Since there are possible active users of this (it was reported as a
problem with openstack) fix it by resetting the disk type to '_FILE' for
an empty cdrom which is handled correctly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-21 15:59:52 +02:00
Ján Tomko
29b1e859e3 tests: use g_strdup instead of VIR_STRDUP
Replace all occurrences of
  if (VIR_STRDUP(a, b) < 0)
     /* effectively dead code */
with:
  a = g_strdup(b);

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-21 12:51:59 +02:00
Ján Tomko
7b48bb8ca0 Use g_strdup to fill in default values
Replace:
  if (!s && VIR_STRDUP(s, str) < 0)
    goto;
with:
  if (!s)
    s = g_strdup(str);

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-21 12:51:55 +02:00
Ján Tomko
3cbd4351de Use g_strdup where VIR_STRDUP's return value was propagated
All the callers of these functions only check for a negative
return value.

However, virNetDevOpenvswitchGetVhostuserIfname is documented
as returning 1 for openvswitch interfaces so preserve that.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-21 12:51:55 +02:00
Ján Tomko
ea5bb994cb Use g_strdup instead of ignoring VIR_STRDUP_QUIET's value
Replace all the occurrences of
  ignore_value(VIR_STRDUP_QUIET(a, b));
with
  a = g_strdup(b);

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-21 12:51:55 +02:00
Ján Tomko
64023f6d21 Use g_strdup instead of ignoring VIR_STRDUP's value
Replace all the occurrences of
  ignore_value(VIR_STRDUP(a, b));
with
  a = g_strdup(b);

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-21 12:51:55 +02:00
Malina Salina
313a71ee7b network: allow DHCP/DNS/TFTP explicitly in OUTPUT rules
While the default iptables setup used by Fedora/RHEL distros
only restricts traffic on the INPUT and/or FORWARD rules,
some users might have custom firewalls that restrict the
OUTPUT rules too.

These can prevent DHCP/DNS/TFTP responses from dnsmasq
from reaching the guest VMs. We should thus whitelist
these protocols in the OUTPUT chain, as well as the
INPUT chain.

Signed-off-by: Malina Salina <malina.salina@protonmail.com>

Initial patch then modified to add unit tests and IPv6
support

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-10-18 18:49:54 +01:00
Daniel P. Berrangé
5722e26ec5 util: drop logging filter/output flags
With the removal of support for log message stack traces, there is
nothing using the logging filter/output flags and they can be removed.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-10-18 16:25:17 +01:00
Daniel P. Berrangé
9b80e0c12a util: drop support for stack traces with logging
The log filters have supported the use of a "+" before the source match
string to request that a stack trace be emitted for every log message:

  commit 548563956e
  Author: Daniel P. Berrange <berrange@redhat.com>
  Date:   Wed May 9 15:18:56 2012 +0100

    Allow stack traces to be included with log messages

    Sometimes it is useful to see the callpath for log messages.
    This change enhances the log filter syntax so that stack traces
    can be show by setting '1:+NAME' instead of '1:NAME'.

With the huge & ever increasing number of logging statements per file,
this will be incredibly verbose and have a major performance penalty.
This makes the feature impractical to use widely and as such it is not
worth the code maint cost.

Removing this seldom used feature allows us to drop the 'execinfo'
module in gnulib which provides the backtrace() function which doesn't
exist on non-Linux.

Users who want to get stack traces of parts of libvirt can use GDB,
or systemtap for live tracing with minimal perf impact.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-10-18 16:25:17 +01:00
Julio Faracco
71519d4638 qemu: Generate 'xres' and 'yres' for QEMU video devices
This commit let QEMU command line define 'xres' and 'yres' properties
if XML contains both properties from video model: based on resolution
fields 'x' and 'y'. There is a conditional structure inside
qemuDomainDeviceDefValidateVideo() that validates if video model
supports this feature. This commit includes the necessary changes to
cover resolution for 'video-qxl-resolution' test cases too.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
2019-10-17 16:18:34 -04:00
Julio Faracco
7286279797 conf: Add 'x' and 'y' resolution into video XML definition
This commit adds resolution element with parameters 'x' and 'y' into video
XML domain group definition. Both, properties were added into an element
called 'resolution' and it was added inside 'model' element. They are set
as optional. This element does not follow QEMU properties 'xres' and
'yres' format. Both HTML documentation and schema were changed too. This
commit includes a simple test case to cover resolution for QEMU video
models. The new XML format for resolution looks like:

    <model ...>
      <resolution x='800' y='600'/>
    </model>

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
2019-10-17 16:18:34 -04:00
Ján Tomko
b6108a04ea Use g_steal_pointer instead of VIR_STEAL_PTR everywhere
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-16 15:59:42 +02:00
Ján Tomko
68fb03c7c0 Remove virautoclean.h
Now that we no longer use any of the macros from this file, remove it.

This also removes a typo.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-16 12:06:44 +02:00
Ján Tomko
2b390b97b4 Use g_autoptr instead of VIR_AUTOUNREF
Now that all the types using VIR_AUTOUNREF have a cleanup func defined
to virObjectUnref, use g_autoptr instead of VIR_AUTOUNREF.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-16 12:06:44 +02:00
Ján Tomko
45678bd70a Use g_autoptr instead of VIR_AUTOPTR
Since commit 44e7f02915
    util: rewrite auto cleanup macros to use glib's equivalent

VIR_AUTOPTR aliases to g_autoptr. Replace all of its use by the GLib
macro version.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-16 12:06:43 +02:00
Ján Tomko
8334203f91 Use G_DEFINE_AUTOPTR_CLEANUP_FUNC instead of VIR_DEFINE_AUTOPTR_FUNC
Since commit 44e7f02915
    util: rewrite auto cleanup macros to use glib's equivalent

VIR_AUTOPTR aliases to g_autoptr. Replace all uses of VIR_DEFINE_AUTOPTR_FUNC
with G_DEFINE_AUTOPTR_CLEANUP_FUNC in preparation for replacing the
rest.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-16 12:06:43 +02:00
Ján Tomko
1e2ae2e311 Use g_autofree instead of VIR_AUTOFREE
Since commit 44e7f02915
    util: rewrite auto cleanup macros to use glib's equivalent

VIR_AUTOFREE is just an alias for g_autofree. Use the GLib macros
directly instead of our custom aliases.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-16 12:06:43 +02:00
Ján Tomko
2b2c67b401 virbuffer: use g_auto directly for virBuffer
Since commit 44e7f02915
    util: rewrite auto cleanup macros to use glib's equivalent

VIR_AUTOCLEAN is just an alias for g_auto. Use the GLib macros
directly instead of our custom aliases.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-16 12:06:43 +02:00
Ján Tomko
67e72053c1 Use G_N_ELEMENTS instead of ARRAY_CARDINALITY
Prefer the GLib version of the macro.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-15 16:14:19 +02:00
Ján Tomko
da367c0f9b Use G_GNUC_PRINTF instead of ATTRIBUTE_FMT_PRINTF
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-15 16:14:18 +02:00
Ján Tomko
0d94f02455 tests: use G_GNUC_UNUSED
Use G_GNUC_UNUSED from GLib instead of ATTRIBUTE_UNUSED.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-15 11:25:25 +02:00
Ján Tomko
426f396198 use G_GNUC_NULL_TERMINATED instead of ATTRIBUTE_SENTINEL
Prefer G_GNUC_NULL_TERMINATED which was introduced in GLib 2.8.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-15 11:25:22 +02:00
Ján Tomko
5d1c4a35ec use G_GNUC_NORETURN instead of ATTRIBUTE_NORETURN
Remove all usage of ATTRIBUTE_NORETURN in favor of GLib's
G_GNUC_NORETURN.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-15 11:25:22 +02:00
Michal Privoznik
458d0a8c52 security: Pass @migrated to virSecurityManagerSetAllLabel
In upcoming commits, virSecurityManagerSetAllLabel() will perform
rollback in case of failure by calling
virSecurityManagerRestoreAllLabel(). But in order to do that, the
former needs to have @migrated argument so that it can be passed
to the latter.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-10-14 17:14:13 +02:00
Daniel P. Berrangé
27cb4c1a53 build: remove use of usleep gnulib module in favour of g_usleep
The usleep function was missing on older mingw versions, but we can rely
on it existing everywhere these days. It may only support times upto 1
second in duration though, so we'll prefer to use g_usleep instead.

The commandhelper program is not changed since that can't link to glib.
Fortunately it doesn't need to build on Windows platforms either.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-10-14 10:54:42 +01:00
Daniel P. Berrangé
c4d18e8b3e util: replace strerror/strerror_r with g_strerror
g_strerror is offers the safety/correctness benefits of strerror_r, with
the API design convenience of strerror.

Use of virStrerror should be eliminated through the codebase in favour
of g_strerror.

commandhelper.c is a special case as its a tiny single threaded test
program, not linked to glib, so it just uses traditional strerror().

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-10-14 10:54:42 +01:00
Daniel P. Berrangé
16121a88a7 util: convert virIdentity class to use GObject
Converting from virObject to GObject is reasonably straightforward,
as illustrated by this patch for virIdentity

In the header file

 - Remove

     typedef struct _virIdentity virIdentity

 - Add

     #define VIR_TYPE_IDENTITY virIdentity_get_type ()
     G_DECLARE_FINAL_TYPE (virIdentity, vir_identity, VIR, IDENTITY, GObject);

   Which provides the typedef we just removed, and class
   declaration boilerplate and various other constants/macros.

In the source file

 - Change 'virObject parent' to 'GObject parent' in the struct
 - Remove the virClass variable and its initializing call
 - Add

      G_DEFINE_TYPE(virIdentity, vir_identity, G_TYPE_OBJECT)

   which declares the instance & class constructor functions

 - Add an impl of the instance & class constructors
   wiring up the finalize method to point to our dispose impl

In all files

 - Replace VIR_AUTOUNREF(virIdentityPtr) with g_autoptr(virIdentity)

 - Replace virObjectRef/Unref with g_object_ref/unref. Note
   the latter functions do *NOT* accept a NULL object where as
   libvirt's do. If you replace g_object_unref with g_clear_object
   it is NULL safe, but also clears the pointer.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-10-14 10:54:42 +01:00
Daniel P. Berrangé
7c9a1dcba8 rpc: convert methods using virIdentityPtr to auto free macros
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-10-14 10:54:42 +01:00
Daniel P. Berrangé
c6825d8813 util: convert virIdentity implementation and test suite to g_autoptr
To simplify the later conversion from virObject to GObject, introduce
the use of g_autoptr to the virIdentity implementnation and test suite.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-10-14 10:54:42 +01:00
Daniel P. Berrangé
74d9326795 util: convert virSystemdActivation to use VIR_DEFINE_AUTOPTR_FUNC
Using the standard macro will facilitate the conversion to glib's
auto cleanup macros.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-10-14 10:54:42 +01:00
Daniel P. Berrangé
cfbe9f1201 build: link to glib library
Add the main glib.h to internal.h so that all common code can use it.

Historically glib allowed applications to register an alternative
memory allocator, so mixing g_malloc/g_free with malloc/free was not
safe.

This was feature was dropped in 2.46.0 with:

      commit 3be6ed60aa58095691bd697344765e715a327fc1
      Author: Alexander Larsson <alexl@redhat.com>
      Date:   Sat Jun 27 18:38:42 2015 +0200

        Deprecate and drop support for memory vtables

Applications are still encourged to match g_malloc/g_free, but it is no
longer a mandatory requirement for correctness, just stylistic. This is
explicitly clarified in

    commit 1f24b36607bf708f037396014b2cdbc08d67b275
    Author: Daniel P. Berrangé <berrange@redhat.com>
    Date:   Thu Sep 5 14:37:54 2019 +0100

        gmem: clarify that g_malloc always uses the system allocator

Applications can still use custom allocators in general, but they must
do this by linking to a library that replaces the core malloc/free
implemenentation entirely, instead of via a glib specific call.

This means that libvirt does not need to be concerned about use of
g_malloc/g_free causing an ABI change in the public libary, and can
avoid memory copying when talking to external libraries.

This patch probes for glib, which provides the foundation layer with
a collection of data structures, helper APIs, and platform portability
logic.

Later patches will introduce linkage to gobject which provides the
object type system, built on glib, and gio which providing objects
for various interesting tasks, most notably including DBus client
and server support and portable sockets APIs, but much more too.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-10-14 10:54:42 +01:00
Daniel Henrique Barboza
65ec10e83f tests: add a test for driver.c:virConnectValidateURIPath()
Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2019-10-11 12:20:08 -04:00
Andrea Bolognani
4d95f557d6 tests: Add capabilities for QEMU 4.2.0 on aarch64
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2019-10-11 09:37:33 +02:00
Andrea Bolognani
c5330fcefa tests: Add capabilities for QEMU 4.2.0 on ppc64
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2019-10-11 09:37:25 +02:00
Marek Marczykowski-Górecki
668dc9fe8c libxl: add slic_table <-> acpi_firmware conversion
This isn't exactly equivalent setting (acpi_firmware may point to
non-SLIC ACPI table), but it's the most behavior preserving option.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
2019-10-10 21:02:09 -06:00
Marek Marczykowski-Górecki
f2899e44d9 tests: libxl: ACPI slic table test
Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
2019-10-10 21:02:03 -06:00
Daniel P. Berrangé
fd3b8fe7ad tests: delete objectlocking test code
The object locking test code is not run by any CI tests and has
bitrotted to the point where it isn't worth the effort to try to
fix it.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-10-10 12:49:52 +01:00
Daniel Henrique Barboza
cab3ea2303 qemu: Implement the ccf-assist pSeries feature
This patch adds the implementation of the ccf-assist pSeries
feature, based on the QEMU_CAPS_MACHINE_PSERIES_CAP_CCF_ASSIST
capability that was added in the previous patch.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2019-10-09 17:51:47 -04:00
Daniel Henrique Barboza
86a8e5a84c qemu: Add capability for the ccf-assist pSeries feature
Linux kernel 5.1 added a new PPC KVM capability named
KVM_PPC_CPU_CHAR_BCCTR_FLUSH_ASSIST, which is exposed to the QEMU guest
since QEMU commit 8ff43ee404d under a new sPAPR capability called
SPAPR_CAP_CCF_ASSIST. This cap indicates whether the processor supports
hardware acceleration for the count cache flush workaround, which
is a software workaround that flushes the count cache on context
switch. If the processor has this hardware acceleration, the software
flush can be shortened, resulting in performance gain.

This hardware acceleration is defaulted to 'off' in QEMU. The reason
is that earlier versions of the Power 9 processor didn't support
it (it is available on Power 9 DD2.3 and newer), and defaulting this
option to 'on' would break migration compatibility between the Power 9
processor class.

However, the user running a P9 DD2.3+ hypervisor might want to create
guests with ccf-assist=on, accepting the downside of only being able
to migrate them only between other P9 DD2.3+ hosts running upstream
kernel 5.1+, to get a performance boost.

This patch adds this new capability to Libvirt, with the name of
QEMU_CAPS_MACHINE_PSERIES_CAP_CCF_ASSIST.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2019-10-09 17:45:09 -04:00
Jonathon Jongsma
fd03d0e692 qemu: add a new video device model 'ramfb'
This device is a very simple framebuffer device supported by qemu that
is mostly intended to use as a boot framebuffer in conjunction with a
vgpu. However, there is also a standalone ramfb device that can be used
as a primary display device and is useful for e.g. aarch64 guests where
different memory mappings between the host and guest can prevent use of
other devices with framebuffers such as virtio-vga.

https://bugzilla.redhat.com/show_bug.cgi?id=1679680 describes the
issues in more detail.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-10-09 14:52:49 -04:00
Jonathon Jongsma
9bfcf0f62d qemu: add ramfb capability
Add a qemu capbility to see if the standalone ramfb device is available.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
2019-10-09 14:46:30 -04:00
Michal Privoznik
75dd595861 qemu: Fix @vm locking issue when connecting to the monitor
When connecting to qemu's monitor the @vm object is unlocked.
This is justified - connecting may take a long time and we don't
want to wait with the domain object locked. However, just before
the domain object is locked again, the monitor's FD is registered
in the event loop. Therefore, there is a small window where the
event loop has a chance to call a handler for an event that
occurred on the monitor FD but vm is not initalized properly just
yet (i.e. priv->mon is not set). For instance, if there's an
incoming migration, qemu creates its socket but then fails to
initialize (for various reasons, I'm reproducing this by using
hugepages but leaving the HP pool empty) then the following may
happen:

1) qemuConnectMonitor() unlocks @vm

2) qemuMonitorOpen() connects to the monitor socket and by
   calling qemuMonitorOpenInternal() which subsequently calls
   qemuMonitorRegister() the event handler is installed

3) qemu fails to initialize and exit()-s, which closes the
   monitor

4) The even loop sees EOF on the monitor and the control gets to
   qemuProcessEventHandler() which locks @vm and calls
   processMonitorEOFEvent() which then calls
   qemuMonitorLastError(priv->mon). But priv->mon is not set just
   yet.

5) qemuMonitorLastError() dereferences NULL pointer

The solution is to unlock the domain object for a shorter time
and most importantly, register event handler with domain object
locked so that any possible event processing is done only after
@vm's private data was properly initialized.

This issue is also mentioned in v4.2.0-99-ga5a777a8ba.

Since we are unlocking @vm and locking it back, another thread
might have destroyed the domain meanwhile. Therefore we have to
check if domain is still active, and we have to do it at the
same place where domain lock is acquired back, i.e. in
qemuMonitorOpen(). This creates a small problem for our test
suite which calls qemuMonitorOpen() directly and passes @vm which
has no definition. This makes virDomainObjIsActive() call crash.
Fortunately, allocating empty domain definition is sufficient.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2019-10-09 10:32:13 +02:00
Jiri Denemark
db873ab3bc qemu: Adapt to changed ppc64 CPU model names
QEMU 2.11 for ppc64 changed all CPU model names to lower case. Since
libvirt can't change the model names for compatibility reasons, we need
to translate the matching lower case models to the names known by
libvirt.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-10-09 09:53:41 +02:00
Peter Krempa
2de75faa28 tests: qemuxml2argv: Make use of versioned cpu-tsc-frequency and cpu-host-model-cmt tests
Commit fb973cfbb4 added versioned test outputs for the above mentioned
tests but didn't actually enable them. Fix that mistake and fix the
output of the tsc-frequency test.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-07 13:46:38 +02:00
Peter Krempa
b86946c269 tests: qemuxml2argv: Remove unused output of 'mlock-on' legacy test
The test data was modernized to use actual caps but commit 4dadcaa98e
forgot to delete this test data.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-07 13:46:38 +02:00
Peter Krempa
df24cba98f tests: qemuxml2argv: Remove unused data for s390 keywrap
The last use was removed in 7b604379ba when we deleted the old
commandline parser.

The argv generator tests are provided by:
machine-aeskeywrap-on-caps
machine-aeskeywrap-on-cap
machine-aeskeywrap-off-caps
machine-aeskeywrap-off-cap
machine-deakeywrap-on-caps
machine-deakeywrap-on-cap
machine-deakeywrap-off-caps
machine-deakeywrap-off-cap

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-07 13:46:38 +02:00
Peter Krempa
1c58616b02 tests: qemuxml2argv: Remove unused data for 'pseries-disk'
The last use was removed in 7b604379ba when we deleted the old
commandline parser. The same functionality is tested by many tests for
pseries guests.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-07 13:46:38 +02:00
Peter Krempa
c42a779df8 tests: qemuxml2argv: Remove unused data for 'serial-pty'
The last use was removed in 7b604379ba when we deleted the old
commandline parser. The same functionality is tested by
'serial-pty-chardev'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-07 13:46:37 +02:00
Daniel P. Berrangé
a45fa8000a build: drop the mktempd gnulib module
The mktempd module in gnulib provides an equivalent to 'mktemp -d' on
platforms which lack this shell command. All platforms on which libvirt
runs the affected tests have 'mktemp -d' support, so the gnulib module
is not required.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-10-07 11:34:24 +01:00
Fabiano Fidêncio
371cff5789 qemu: capabilities: Fill in bochs-display info
086c19d69 added bochs-display capability but didn't fill in the info for
domain capabilities.

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-07 11:40:48 +02:00
Collin Walling
adb689bc2a qemu_capabilities: introduce QEMU_CAPS_QUERY_CPU_MODEL_COMPARISON
This capability enables comparison of CPU models via QMP.

Signed-off-by: Collin Walling <walling@linux.ibm.com>
Reviewed-by: Daniel Henrique Barboza <danielh413@gmail.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Message-Id: <1568924706-2311-13-git-send-email-walling@linux.ibm.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2019-10-07 10:10:17 +02:00
Collin Walling
db8bd39f6b qemu_capabilities: introduce QEMU_CAPS_QUERY_CPU_MODEL_BASELINE
This capability enables baselining of CPU models via QMP.

Signed-off-by: Collin Walling <walling@linux.ibm.com>
Reviewed-by: Daniel Henrique Barboza <danielh413@gmail.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Message-Id: <1568924706-2311-9-git-send-email-walling@linux.ibm.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2019-10-07 10:09:49 +02:00
Collin Walling
afd222684e qemu_monitor: allow cpu props to be optional
Some older s390 CPU models (e.g. z900) will not report props as a
response from query-cpu-model-expansion. As such, we should make the
props field optional when parsing the return data from the QMP response.

Signed-off-by: Collin Walling <walling@linux.ibm.com>
Message-Id: <1568924706-2311-6-git-send-email-walling@linux.ibm.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2019-10-07 10:09:49 +02:00
Collin Walling
67a4dcc151 qemu_monitor: use cpu def instead of char for expansion
When expanding a CPU model via query-cpu-model-expansion, any features
that were a part of the original model are discarded. For exmaple,
when expanding modelA with features f1, f2, a full expansion may reveal
feature f3, but the expanded model will not include f1 or f2.

Let's pass a virCPUDefPtr to the expansion function in preparation for
taking features into consideration.

Signed-off-by: Collin Walling <walling@linux.ibm.com>
Message-Id: <1568924706-2311-4-git-send-email-walling@linux.ibm.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2019-10-07 10:09:49 +02:00
Pavel Mores
ca437d0603 qemu: Refuse partitions in disk targets
The way in which the qemu driver generates aliases for disks involves
ignoring the partition number part of a target dev name.  This means that
all partitions of a block device and the device itself all end up with the
same alias.  If multiple such disks are specified in XML, the resulting
name clash makes qemu invocation fail.

Since attaching partitions to qemu VMs doesn't seem to make much sense
anyway, disallow partitions in target specifications altogether.

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

Signed-off-by: Pavel Mores <pmores@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-10-02 13:54:06 +02:00
Daniel P. Berrangé
76d31244c5 rpc: fix escaping of shell path for netcat binary
Consider having a nc binary in the path with a space in its name,
for example '/tmp/fo o/nc'

This results in libvirt running SSH with the following arg value

  "'if ''/tmp/fo o/nc'' -q 2>&1 | grep \"requires
    an argument\" >/dev/null 2>&1; then ARG=-q0;
    else ARG=;fi;''/tmp/fo o/nc'' $ARG -U
    /var/run/libvirt/libvirt-sock'"

The use of the single quote escaping was introduced by

  commit 6ac6238de3
  Author: Guido Günther <agx@sigxcpu.org>
  Date:   Thu Oct 13 21:49:01 2011 +0200

    Use virBufferEscapeShell in virNetSocketNewConnectSSH

    to escape the netcat command since it's passed to the shell. Adjust
    expected test case output accordingly.

While the intention of this change was good, the result is broken as it
is still underquoted.

On the SSH server side, SSH itself runs the command via the shell.
Our command is then invoking the shell again. Thus we see

$ virsh -c qemu+ssh://root@domokun/system?netcat=%2Ftmp%2Ffo%20o%2Fnc list
error: failed to connect to the hypervisor
error: End of file while reading data: sh: /tmp/fo: No such file or directory: Input/output error

With the second level of escaping added we can now successfully use a nc
binary with a space in the path.

The original test case added was misleading as it illustrated using a
binary path of 'nc -4' which is not a path, it is a command with a
separate argument, which is getting interpreted as a path.

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-10-01 12:57:07 +01:00
Daniel P. Berrangé
227925a2e5 qemu: ensure vhostuser FD is initialized to -1
The video private data was not initializing the vhostuser FD
causing us to attempt to close FD 0 many times over.

Fixes

  commit ca60ecfa8c
  Author: Marc-André Lureau <marcandre.lureau@redhat.com>
  Date:   Mon Sep 23 14:44:36 2019 +0400

      qemu: add qemuDomainVideoPrivate

Since the test suite does not invoke qemuExtDevicesStart(), no
vhost_user_fd will be present when generating test XML. To deal
with this we can must a fake FD number. While the current XML
is using FD == 0, we pick a very interesting number that's unlikely
to be a real FD, so that we're more likely to see any mistakes
closing the invalid FD.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-09-30 13:08:43 +01:00
Peter Krempa
bacbd0f2ee tests: qemumonitor: Add testing for the 'transaction' command and generators
Validate all the commands against the schema.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
2019-09-30 13:12:56 +02:00
Peter Krempa
c419a43565 tests: qemucapabilities: Update caps of qemu-4.1 to released version
Now that qemu 4.1 was released we can update the capabilities to the
final form.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2019-09-27 09:43:37 +02:00
Peter Krempa
19898df4a9 tests: add qemu capabilities data for qemu 4.2
Add capabilities test data for upcoming qemu 4.2.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2019-09-27 07:20:14 +02:00
Laine Stump
b6a8d30302 conf: take advantage of VIR_AUTOPTR for virNetworkPortDefPtr
define a VIR_DEFINE_AUTOPTR_FUNC() to autofree virNetworkPortDefs, and
convert all uses of virNetworkPortDefPtr that are appropriate to use
it.

This coincidentally fixes multiple potential memory leaks (in failure
cases) in networkPortCreateXML()

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-09-26 21:38:48 -04:00
Marc-André Lureau
e636fd94ba tests: add vhost-user-gpu xml2argv tests
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-09-24 13:19:09 -04:00
Marc-André Lureau
e2b709f92e qemu: build vhost-user GPU devices
For each vhost-user GPUs,
- build a socket chardev, and pass the vhost-user socket to it
- build a vhost-user video device and associate it with the chardev

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-09-24 13:19:09 -04:00
Marc-André Lureau
06049e9f73 tests: wrap vhost-user paths in qemuxml2argvtest
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-09-24 13:19:09 -04:00
Marc-André Lureau
ddd40dba12 tests: mock execv/execve
Learn to override the paths to the program to execute (vhost-user
helpers are executed to check for runtime capabilities).

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-09-24 13:19:09 -04:00
Marc-André Lureau
13248e1688 qemu: add vhost-user helpers
Add qemuVhostUserFetchConfigs() to discover vhost-user helpers.

qemuVhostUserFillDomainGPU() will find the first matching GPU helper
with the required capabilities and set the associated
vhost_user_binary.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-09-24 13:19:08 -04:00
Marc-André Lureau
d27abda98d qemu: restrict 'virgl=' option to non-vhostuser video type
vhost-user device doesn't have a virgl option, it is passed to the
vhost-user-gpu helper process instead.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-09-24 12:30:33 -04:00
Marc-André Lureau
c3d0831745 qemu: validate virtio-gpu with vhost-user
Check qemu capability, and accept 3d acceleration. 3d acceleration
support is checked when looking for a suitable vhost-user helper.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-09-24 12:30:02 -04:00
Marc-André Lureau
86e068e5d6 qemu: add vhost-user-gpu capabilities checks
Those new devices are available since QEMU 4.1.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-24 12:29:29 -04:00
Marc-André Lureau
1394bf1091 domain: add rendernode attribute on <accel>
vhost-user-gpu helper takes --render-node option to specify on which
GPU should the renderning be done.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-24 12:17:39 -04:00
Marc-André Lureau
bc1e924cf0 conf: format/parse/rng/docs for video <driver name='qemu|vhostuser'/>
Accept a new driver name attribute to specify usage of helper process, ex:

  <video>
    <driver name='vhostuser'/>
    <model type='virtio'/>
  </video>

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-24 12:17:39 -04:00
Peter Krempa
534daeef82 qemu: monitor: Remove HMP command (un)escaping infrastructure
We don't need to escape the commands any more since we use QMP
passthrough, which means we can delete the functions.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2019-09-20 08:41:50 +02:00
Daniel P. Berrangé
2c535e50f5 util: remove some no-op thread functions
Neither virThreadInitialize or virThreadOnExit do anything since we
dropped the Win32 threads impl, in favour of win-pthreads with:

  commit 0240d94c36
  Author: Daniel P. Berrange <berrange@redhat.com>
  Date:   Wed Jan 22 16:17:10 2014 +0000

      Remove windows thread implementation in favour of pthreads

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-09-19 12:50:21 +01:00
Michal Privoznik
f73e62a17c Revert "qemu: add socket datagram capability"
This reverts commit 0cebb6422a.

This capability is not used anywhere and also it is not contained
in any release so it's safe to just remove it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-19 11:38:44 +02:00
Michal Privoznik
ccf41a4b57 qemu: Enable slirp-helper iff dbus-vmstate present
The fact that qemu is capable -netdev socket is not enough to
start a migratable domain. It also needs dbus-vmstate capability.
Since there are already some qemu releases which have
net-socket-dgram capability and don't have dbus-vmstate we need
to check for dbus-vmstate.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-19 11:36:44 +02:00
Michal Privoznik
c83412bd3c Revert "Temporarily disable bla"
This reverts commit 385543a543.

I've mistakenly pushed wrong branch.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2019-09-19 11:26:56 +02:00
Michal Privoznik
385543a543 Temporarily disable bla
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2019-09-18 17:01:07 +02:00
Daniel P. Berrangé
45b273d981 util: sanitize return values for virIdentity getters
The virIdentity getters are unusual in that they return -1 to indicate
"not found" and don't report any error. Change them to return -1 for
real errors, 0 for not found, and 1 for success.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-09-16 11:25:34 +01:00
Daniel P. Berrangé
f3fa662353 util: removed unused virIdentityIsEqual method
It is simpler to remove this unused method than to rewrite it using
typed parameters in the next patch.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-09-16 11:25:30 +01:00
Daniel P. Berrangé
1bbc53c264 util: make generic identity accessors private
Only expose the type safe getters/setters to other code in preparation
for changing the internal storage of data.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-09-16 11:25:23 +01:00
Daniel P. Berrangé
3caf033916 tests: fix debug messages wrt selinux context when test fails
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-09-16 11:25:17 +01:00
Daniel P. Berrangé
4597a23f50 util: change identity class attribute names
Remove the "UNIX" tag from the names for user name, group name,
process ID and process time, since these attributes are all usable
for non-UNIX platforms like Windows.

User ID and group ID are left with a "UNIX" tag, since there's no
equivalent on Windows. The closest equivalent concept on Windows,
SID, is a struct containing a number of integer fields, which is
commonly represented in string format instead. This would require
a separate attribute, and is left for a future exercise, since
the daemons are not currently built on Windows anyway.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-09-16 11:25:10 +01:00
Peter Krempa
8b2798e395 tests: qemustatusxml2xml: Fix disk target mess
There were accidentally two disks with 'vdc' target with corresponding
blockjobs which made libvirt leak some references as there are not
supposed to be two blockjobs for a single disk. Fix this mess by
renaming some of the disks.

In addition the block job names also didn't correspond to the naming
convetion which also includes the disk target. Fix it as well.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
ACKed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2019-09-16 11:50:28 +02:00
Daniel P. Berrangé
3eca0e300d tests: remove use of virTestOOMActive from bhyve testsuite
The virTestOOMActive method was deleted in

  commit 2c52ecd960
  Author: Daniel P. Berrangé <berrange@redhat.com>
  Date:   Thu Aug 29 13:04:07 2019 +0100

    util: purge all code for testing OOM handling

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-09-13 16:03:18 +01:00
Daniel P. Berrangé
2c52ecd960 util: purge all code for testing OOM handling
The OOM handling requires special build time options which we never
enable in our CI. Even once enabled the tests are incredibly slow and
typically require manual inspection of the results to weed out false
positives.

Since there was previous agreement to switch to abort on OOM in libvirt
code, there's no point continuing to keep the unused OOM testing code.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-09-13 10:05:17 +01:00
Michal Privoznik
5a5b8f74d4 qemufirmwaretest: Test FW path getting through qemuFirmwareGetSupported()
There is one hack hidden here, but since this is in a test, it's
okay. In order to get a list of expected firmwares in
virFirmwarePtr form I'm using virFirmwareParseList(). But
usually, in real life scenario, this function is used only to
parse a list of UEFI images which have NVRAM split out. In other
words, this function expects ${FW}:${NVRAM} pairs. But in this
test, we also want to allow just a single path: ${FW} because
some reported firmwares are just a BIOS image really. To avoid
writing some parser function, let's just pass "NULL" as ${NVRAM}
and fix the result later.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-09-12 12:33:19 +02:00
Michal Privoznik
78f8769a84 qemu_firmware: Extend qemuFirmwareGetSupported to return FW paths
The qemuFirmwareGetSupported() function is called from qemu
driver to generate domain capabilities XML based on FW descriptor
files. However, the function currently reports only some features
from domcapabilities XML and not actual FW image paths. The paths
reported in the domcapabilities XML are still from pre-FW
descriptor era and therefore the XML might be a bit confusing.
For instance, it may say that secure boot is supported but
secboot enabled FW is not in the listed FW image paths.

To resolve this problem, change qemuFirmwareGetSupported() so
that it also returns a list of FW images (we have the list
anyway). Luckily, we already have a structure to represent a FW
image - virFirmware.

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

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-09-12 12:31:39 +02:00
Daniel P. Berrangé
b1b878c512 util: activate directory override when used from library
The Perl bindings for libvirt use the test driver for unit tests. This
tries to load the cpu_map/index.xml file, and when run from an
uninstalled build will fail.

The problem is that virFileActivateDirOverride is called by our various
binaries like libvirtd, virsh, but is not called when a 3rd party app
uses libvirt.so

To deal with this we allow the LIBVIRT_DIR_OVERRIDE=1 env variable to be
set and make virInitialize look for this. The 'run' script will set it,
so now build using this script to run against an uninstalled tree we
will correctly resolve files to the source tree.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-09-10 11:03:35 +01:00
Michal Privoznik
5ae24a13c7 Revert "dbus: correctly build reply message"
This reverts commit 39dded7bb6.

This commit broke virpolkittest on Ubuntu 18 which has an old
dbus (v1.12.2). Any other distro with the recent one works
(v1.12.16) which hints its a bug in dbus somewhere. Revert the
commit to stop tickling it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-09-10 09:47:13 +02:00
Michal Privoznik
6bb4242d9f lib: Define and use autofree for virConfPtr
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2019-09-10 09:34:37 +02:00
Laine Stump
7cd0911e1a qemu: support unmanaged target tap dev for <interface type='ethernet'>
If managed='no', then the tap device must already exist, and setting
of MAC address and online status (IFF_UP) is skipped.

NB: we still set IFF_VNET_HDR and IFF_MULTI_QUEUE as appropriate,
because those bits must be properly set in the TUNSETIFF we use to set
the tap device name of the handle we've opened - if IFF_VNET_HDR has
not been set and we set it the request will be honored even when
running libvirtd unprivileged; if IFF_MULTI_QUEUE is requested to be
different than how it was created, that will result in an error from
the kernel. This means that you don't need to pay attention to
IFF_VNET_HDR when creating the tap devices, but you *do* need to set
IFF_MULTI_QUEUE if you're going to use multiple queues for your tap
device.

NB2: /dev/vhost-net normally has permissions 600, so it can't be
opened by an unprivileged process. This would normally cause a warning
message when using a virtio net device from an unprivileged
libvirtd. I've found that setting the permissions for /dev/vhost-net
permits unprivileged libvirtd to use vhost-net for virtio devices, but
have no idea what sort of security implications that has. I haven't
changed libvrit's code to avoid *attempting* to open /dev/vhost-net -
if you are concerned about the security of opening up permissions of
/dev/vhost-net (probably a good idea at least until we ask someone who
knows about the code) then add <driver name='qemu'/> to the interface
definition and you'll avoid the warning message.

Note that virNetDevTapCreate() is the correct function to call in the
case of an existing device, because the same ioctl() that creates a
new tap device will also open an existing tap device.

Resolves: https://bugzilla.redhat.com/1723367 (partially)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2019-09-09 14:38:01 -04:00
Laine Stump
77f72a8615 conf: new "managed" attribute for target dev of <interface type='ethernet'>
Although <interface type='ethernet'> has always been able to use an
existing tap device, this is just a coincidence due to the fact that
the same ioctl is used to create a new tap device or get a handle to
an existing device.

Even then, once we have the handle to the device, we still insist on
doing extra setup to it (setting the MAC address and IFF_UP).  That
*might* be okay if libvirtd is running as a privileged process, but if
libvirtd is running as an unprivileged user, those attempted
modifications to the tap device will fail (yes, even if the tap is set
to be owned by the user running libvirtd). We could avoid this if we
knew that the device already existed, but as stated above, an existing
device and new device are both accessed in the same manner, and
anyway, we need to preserve existing behavior for those who are
already using pre-existing devices with privileged libvirtd (and
allowing/expecting libvirt to configure the pre-existing device).

In order to cleanly support the idea of using a pre-existing and
pre-configured tap device, this patch introduces a new optional
attribute "managed" for the interface <target> element. This
attribute is only valid for <interface type='ethernet'> (since all
other interface types have mandatory config that doesn't apply in the
case where we expect the tap device to be setup before we
get it). The syntax would look something like this:

   <interface type='ethernet'>
      <target dev='mytap0' managed='no'/>
      ...
   </interface>

This patch just adds managed to the grammar and parser for <target>,
but has no functionality behind it.

(NB: when managed='no' (the default when not specified is 'yes'), the
target dev is always a name explicitly provided, so we don't
auto-remove it from the config just because it starts with "vnet"
(VIR_NET_GENERATED_TAP_PREFIX); this makes it possible to use the
same pattern of names that libvirt itself uses when it automatically
creates the tap devices.)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2019-09-09 14:35:54 -04:00
Shivaprasad G Bhat
4ef4ba4974 tests: Add a baseline test for multifunction pci device use case
There are already good number of test cases with hostdevices,
few have multifunction devices but none having more than one
than one multifunction cards.

This patch adds a case where there are two multifunction cards
and two Virtual functions part of the same XML.

0001:01:00.X & 0005:09:00.X - are Multifunction PCI cards.
0000:06:12.[5|6] - are SRIOV Virtual functions

Future commits will improve on automatically detecting the
multifunction cards and auto-assinging the addresses
appropriately.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2019-09-09 16:44:24 +02:00
Daniel Henrique Barboza
2d9b8acf58 virpcimock.c: simplify getrealpath() usage
Previous patch had to add '/sys/kernel/' prefix in opendir() because
the path, which is being mocked, wasn't being considered due to
an 'if SYSFS_PCI_PREFIX' guarding the call to getrealpath().

In fact, all current getrealpath() callers are guarding it with a
conditional to ensure that the function will never be called with
a non-mocked path. In this case, an extra non-NULL verification is
needed for the 'newpath' string to use the variable - which is
counterintuitive, given that getrealpath() will always write the
'newpath' string in any non-error conditon.

However, simply removing the guard of all getrealpath() instances
causes an abort in init_env(). This happens because tests will
execute access() to non-mocked paths even before the
LIBVIRT_FAKE_ROOT_DIR variable is declared in the test files. We
don't need 'fakerootdir' to be created at this point though.

This patch does the following changes to simplify getrealpath()
usage:

- getrealpath() will now guard the init_env() call by checking if
both fakeroot isn't created and the required path is being mocked.
This ensures that we're not failing inside init_env() because
we're too early and LIBVIRT_FAKE_ROOT_DIR wasn't defined yet;

- remove all conditional guards to call getrealpath() from
access(), virMockStatRedirect(), open(), open_2(), opendir()
and virFileCanonicalizePath(). As a bonus, remove all ternary
conditionals with 'newpath';

- a new 'pathPrefixIsMocked()' helper to aggregate all the prefixes
we're mocking, making it easier to add/remove them. If a prefix
is added inside this function, we can be sure that all functions
are mocking them.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-09-09 16:44:24 +02:00
Shivaprasad G Bhat
944a35d7f0 tests: Add test case for QEMU pci-hostdev hotplug
This patch adds hostdev test cases in qemuhotplugtest.c.

Note: the small tweak inside virpcimock.c was needed because
the new tests added a code path in which virHostHasIOMMU()
(virutil.c) started being called, and the mocked '/sys/kernel/'
prefix that is mocked in virpcimock.c wasn't being considered
in the opendir() mock. An alternative to avoid these situations
in virpcimock.c is implemented in the next patch.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2019-09-09 16:44:24 +02:00
Shivaprasad G Bhat
5a9dc4a50c virpcimock: Mock the SRIOV Virtual functions
The softlink to physfn is the way to know if the device is
VF or not. So, the patch softlinks 'physfn' to the parent function.
The multifunction PCI devices dont have 'physfn' softlinks.

The patch adds few Virtual functions to the mock environment and
changes the existing VFIO test xmls using the VFs to use the newly
added VFs for their use case.

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-09-09 16:44:24 +02:00
Daniel Henrique Barboza
16c9890383 virpcimock.c: mock /dev/vfio
This patch adds mock of the /dev/vfio path, needed for proper
implementation of the support for multifunction/multiple devices
per iommu groups.

To do that, the existing bind and unbind operations were adapted
to operate with the mocked filesystem as well.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-09-09 16:44:24 +02:00
Marc-André Lureau
7d24c8a469 tests: add slirp-helper qemuxml2argv test
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-09-06 12:47:47 +02:00
Marc-André Lureau
0cebb6422a qemu: add socket datagram capability
Datagram socket is available since qemu 4.0, commit
fdec16e3c2a614e2861f3086b05d444b5d8c3406 ("net/socket: learn to talk
with a unix dgram socket").

Required for slirp-helper communication.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-09-06 12:47:47 +02:00
Marc-André Lureau
39dded7bb6 dbus: correctly build reply message
dbus_message_new() does not construct correct replies by itself, it is
recommended to use dbus_message_new_method_return() instead.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-09-06 12:47:46 +02:00
Marc-André Lureau
16e81dd3b3 tests: fix xml2xml tpm-emulator.xml test
It is failing, because it ends up being parsed with version='default'
and expects '1.2' instead.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-09-06 12:47:46 +02:00
Jonathon Jongsma
9f90a4bfb4 qemu: maintain user alias for video type 'none'
After parsing a video device with a model type of
VIR_DOMAIN_VIDEO_TYPE_NONE, all device info is cleared (see
virDomainDefPostParseVideo()) in order to avoid formatting any
auto-generated values for the XML. Subsequently, however, an alias is
generated for the video device (e.g. 'video0'), which results in an
alias property being formatted in the XML output anyway. This creates
confusion if the user has explicitly provided an alias for the video
device since the alias will change.

To avoid this, don't clear the user-defined alias for video devices of
type "none".

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

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2019-09-06 10:22:47 +02:00
Peter Krempa
a7643da82e qemu: block: Explicitly specify backingStore when creating format layer props
Pass in backing store explicitly to qemuBlockStorageSourceGetBlockdevProps
and fix the callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-06 08:12:21 +02:00
Peter Krempa
5dc567f80a tests: qemublock: Use bigger numbers as dummy capacity/physical
Actually test that the full range is available.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-09-04 09:13:49 +02:00
Peter Krempa
c87c42f0eb qemu: command: Use all vCPU properties when creating args for vCPU hotplug
As qemu documents we should use everything in the 'props' sub-object of
the data returned by query-hotpluggable-cpus. Until now we only used
everything we recognized, but that may break in cases when qemu
introduces new fields.

This change requires a fix to the test data as some fields were
reordered.

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-08-29 16:36:26 +02:00
Jonathon Jongsma
a931486a97 qemu: guestinfo: handle unsupported agent commands
When we're collecting guest information, older agents may not support
all agent commands. In the case where the user requested all info
types (i.e. types == 0), ignore unsupported command errors and gather as
much information as possible. If the agent command failed for some other
reason, or if the user explciitly requested a specific info type (i.e.
types != 0), abort on the first error.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-08-29 12:03:23 +02:00
Boris Fiuczynski
0c67a11a4a qemu: support bootindex on vfio-ccw mdev devices
Add support to specify a boot order on vfio-ccw passthrough devices.

Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Bjoern Walk <bwalk@linux.ibm.com>
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2019-08-28 12:26:43 +02:00
Boris Fiuczynski
182659d8bd qemu: move hostdev boot validation into domain validation
Moving the hostdev boot support validation from the command line
generator code into the domain validation code.

Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Bjoern Walk <bwalk@linux.ibm.com>
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2019-08-28 12:22:51 +02:00
Boris Fiuczynski
927d0c3e5c tests: add vhost scsi hostdev boot unsupported test
Adding a failure test for booting from a vhost scsi hostdev device.

Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Bjoern Walk <bwalk@linux.ibm.com>
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2019-08-28 12:21:29 +02:00
Boris Fiuczynski
321c614f72 tests: add vfio-ap mdev tests
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Bjoern Walk <bwalk@linux.ibm.com>
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-28 12:20:11 +02:00
Michal Privoznik
0b8825c7ac virhostdevtest: Reset libvirt error on expected failure
If a libvirt error occurred during a test, then virTestRun()
reports it (regardless of test returning success or failure).
For instance, in this specific case, a hostdev is detached twice
and the second attempt is expected to fail. It does fail and
libvirt error is reported which is then printed onto stderr.
Insert virResetLastError() calls on appropriate places to avoid
that.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-27 16:10:21 +02:00
Michal Privoznik
5ede0b9b41 virhostdevtest: s/VIR_DEBUG/VIR_TEST_DEBUG/
There's no need to have VIR_DEBUG() really.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-27 16:10:21 +02:00
Michal Privoznik
71c5c4d8a2 virhostdevtest: Drop useless VIR_TEST_DEBUG
The virTestRun() already reports the same.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-27 16:10:21 +02:00
Michal Privoznik
50e6688733 virhostdevtest: Drop most of 'cleanup' and 'out' labels
In this test there is this macro CHECK_LIST_COUNT() which checks
if a list of PCI devices contains expected count. If it doesn't
an error is reported and 'goto cleanup' is invoked. There's no
real reason for that as even since its introduction there is no
cleanup done and all 'cleanup' labels contain nothing but
'return'.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-27 16:09:52 +02:00
Michal Privoznik
9409f6b724 virhostdevtest: Check for integer retval in more verbose way
There are few functions called from the test which return an
integer but their retval is compared as if it was a pointer.
Now, there is nothing wrong with that from machine POV, but
from readability perspective it's wrong.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-27 16:00:47 +02:00
Michal Privoznik
76dcc854f9 virhashtest: Drop useless new line
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-27 15:58:51 +02:00
Michal Privoznik
e3511ee5ec tests: Always put '\n' at the end of VIR_TEST_VERBOSE
Similarly to the previous commit, VIR_TEST_VERBOSE should put
'\n' at the end of each call so that the output is not broken.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-27 15:56:17 +02:00
Michal Privoznik
d07ce21610 tests: Always put a '\n' after each debug print
There is an inconsistency with VIR_TEST_DEBUG() calls. One half
(roughly) of calls does have the newline character the other one
doesn't. Well, it doesn't have it because it assumed blindly that
new line will be printed, which is not the case.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-27 15:49:48 +02:00
Jim Fehlig
ecc4d75d01 xenconfig: move contents to libxl driver and remove directory
After the legacy xen driver was removed the libxl driver became
the only consumer of xenconfig. Move the few files in xenconfig
to the libxl driver and remove the directory.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-26 11:06:12 -06:00
Jonathon Jongsma
a68ed9fc42 qemu: add helper for getting full FSInfo
This function adds the complete filesystem information returned by the
qemu agent to an array of typed parameters with field names intended to
to be returned by virDomainGetGuestInfo()

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2019-08-26 17:27:40 +02:00
Jonathon Jongsma
b11f485382 qemu: add helper for querying timezone info
This function queries timezone information within the guest and adds
the information to an array of typed parameters with field names
intended to be returned to virDomainGetGuestInfo()

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2019-08-26 17:27:40 +02:00
Jonathon Jongsma
d5b5a890dd qemu: add helper function for querying OS info
This function queries the guest operating system information and adds
the returned information to an array of typed parameters with field
names intended to be returned in virDomainGetGuestInfo().

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2019-08-26 17:27:40 +02:00
Jonathon Jongsma
1c8113f9c8 qemu: add helper for getting guest users
This function fetches the list of logged-in users from the qemu agent
and adds them to a list of typed parameters so that they can be used
internally in libvirt.

Also add some basic tests for the function.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2019-08-26 17:27:40 +02:00
Peter Krempa
6ff9241058 util: storagefile: Flag backing store strings with authentication
Using inline authentication for storage volumes will not work properly
as libvirt requires use of the secret driver for the auth data and
thus would not be able to represent the passwords stored in the backing
store string.

Make sure that the backing store parsers return 1 which is a sign for
the caller to not use the file in certain cases.

The test data include iscsi via a json pseudo-protocol string and URIs
with the userinfo part being present.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-26 13:49:17 +02:00
Peter Krempa
e1189ae5f3 tests: virstorage: Allow testing return value of virStorageSourceNewFromBackingAbsolute
Modify testBackingParse to allow testing other return values of the
backing store string parser.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-26 13:49:17 +02:00
Peter Krempa
5265743daa util: storagefile: Modify arguments of virStorageSourceNewFromBackingAbsolue
Return the parsed storage source via an pointer in arguments and return
an integer from the function. Describe the semantics with a comment for
the function and adjust callers to the new semantics.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-26 13:49:17 +02:00
Peter Krempa
ffabad7572 tests: storage: Refactor cleanup in testBackingParse
Automatically clean the temporary buffer and get rid of the cleanup
label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-26 13:49:16 +02:00
Peter Krempa
aece36f767 tests: viruri: Add test for password in URI userinfo
While it's a bad idea to use userinfo to pass credentials via a URI add
a test that we at least do the correct thing.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-26 13:49:16 +02:00
Roman Bolshakov
f6d6086dbf tests: Make references to global symbols indirect in test drivers
A library has to be built with -flat_namespace to get all references to
global symbols indirected. That can also be achieved with two-level
namespace interposition but we're not using explicit symbol
interposition since it's more verbose and requires massive changes to
the mocks.

This provides a way to interpose a mock for virQEMUCapsProbeHostCPU from
qemucpumock and fixes domaincapstest on macOS.

Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
2019-08-23 11:26:26 +01:00
Roman Bolshakov
0ae6f5cea5 tests: Avoid gnulib replacements in mocks
gnulib headers change stat, lstat and open to replacement functions,
even for function definitions. This effectively disables standard
library overrides in virfilewrapper and virmockstathelpers since they
are never reached.

Rename the functions and provide a declartion that uses correct
assembler name for the mocks.

This fixes firmware lookup in domaincapstest on macOS.

Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
2019-08-23 11:26:26 +01:00
Roman Bolshakov
fefc4ff4cd tests: Use flat namespace on macOS
Test executables and mocks have assumption that any symbol can be
replaced with LD_PRELOAD. That's not a case for macOS unless flat
namespace is used, because every external symbol reference records the
library to be looked up. And the symbols cannot be replaced unless dyld
interposing is used.

Setting DYLD_FORCE_FLAT_NAMESPACE changes symbol lookup behaviour to be
similar to Linux dynamic linker. It's more lightweight solution than
explicitly decorating all mock symbols as interpositions and building
libvirt as interposable dynamic library.

This fixes vircryptotest and allows to proceed other tests that rely on
mocks a little bit further.

Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
2019-08-23 11:26:26 +01:00
Roman Bolshakov
d6b17edd51 tests: Lookup extended stat/lstat in mocks
macOS syscall interface (/usr/lib/system/libsystem_kernel.dylib) has
three kinds of stat but only one of them can be used to fill
"struct stat": stat$INODE64.

virmockstathelpers looks up regular stat instead of stat$INODE64.  That
causes a failure in qemufirmwaretest because "struct stat" is laid out
differently from the values returned by stat.

Introduce VIR_MOCK_REAL_INIT_ALIASED that can be used to lookup
stat$INODE64 and lstat$INODE64 and use it to setup real functions on
macOS.

Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
2019-08-23 11:26:26 +01:00
Roman Bolshakov
c6b3bf9302 tests: Drop /private CWD prefix in commandhelper
/tmp is a symbolic link to /private/tmp on macOS. That causes failures
in commandtest, because getcwd returns /private/tmp and the expected
output doesn't match to "CWD: /tmp".

Rathern than making a copy of commanddata solely for macOS, the /private
prefix is stripped.

Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
2019-08-23 11:26:26 +01:00
Roman Bolshakov
647c65186a tests: Remove -module flag for mocks
macOS has two kinds of loadable libraries: MH_BUNDLE, and MH_DYLIB.
bundle is used for plugins that are loaded with dlopen/dlsym/dlclose.
And there's no way to preload a bundle into an application. dynamic
linker (dyld) will reject it when finds it in DYLD_INSERT_LIBRARIES.

Unfortunately, a bundle is built if -module flag is provided to libtool.
The flag has been removed to build dylibs with ".dylib" suffix.

Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
2019-08-23 11:26:26 +01:00
Roman Bolshakov
fde361083d tests: Add lib- prefix to all mocks
In preparation libtool "-module" flag removal, add lib prefix to all
mock shared objects.

While at it, introduce VIR_TEST_MOCK macros that makes path out of mock
name to be used with VIR_TEST_PRELOAD or VIR_TEST_MAIN_PRELOAD.  That,
hopefully, improves readability, reduces line length and allows to
tailor VIR_TEST_MOCK for specific platform if it has shared library
suffix different from ".so".

Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
2019-08-23 11:26:26 +01:00
Roman Bolshakov
351492e304 tests: Preload mocks with DYLD_INSERT_LIBRARIES on macOS
LD_PRELOAD has no effect on macOS. Instead, dyld(1) provides a way for
symbol hooking via DYLD_INSERT_LIBRARIES. The variable should contain
colon-separated paths to the dylibs to be inserted.

Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
2019-08-23 11:26:26 +01:00
Roman Bolshakov
dbb5e20ede tests: Avoid IPv4-translated IPv6 address in sockettest
getnameinfo on macOS formats certain IPv6 addresses as IPv4-translated
addresses. The following pattern has been observed:
  ::ffff is formated as ::0.0.255.255
  ::fffe is formated as ::0.0.255.254
  ::ffff:0 is formated as ::255.255.0.0
  ::fffe:0 is formated as ::255.254.0.0
  ::ffff:0:0 is formated as ::ffff:0.0.0.0
  ::fffe:0:0 is formated as ::fffe:0:0
  ::ffff:0:0:0 is formated as ::ffff:0:0:0

The getnameinfo behavior causes a failure for:
  DO_TEST_PARSE_AND_FORMAT("::ffff", AF_UNSPEC, true);

Use non-ambigious IPv6 for parse/format testing.

Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
2019-08-23 11:26:26 +01:00