Commit Graph

21048 Commits

Author SHA1 Message Date
Daniel P. Berrangé
b8eb6194da storage: allow opening with storage:///system and storage:///session URIs
Allow the possibility of opening a connection to only the storage
driver, by defining storage:///system and storage:///session URIs
and registering a fake hypervisor driver that supports them.

The hypervisor drivers can now directly open a storage driver
connection at time of need, instead of having to pass around a
virConnectPtr through many functions. This will facilitate the later
change to support separate daemons for each driver.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-01-31 17:44:43 +00:00
Daniel P. Berrangé
d8924a6408 storage: move driver registration back to end of the file
By convention the last thing in the driver.c files should be the driver
callback table and function to register it.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-01-31 17:40:32 +00:00
Daniel P. Berrange
5315d20698 util: use union for sockaddr structs to avoid aliasing
Some platforms/toolchains will complain about casting
sockaddr_storage to sockaddr_un because it breaks strict
aliasing rule

../../src/util/virutil.c: In function 'virGetUNIXSocketPath':
../../src/util/virutil.c:2005: error: dereferencing pointer 'un' does break strict-aliasing rules [-Wstrict-aliasing]

Change the code to use a union, in the same way that the
virsocketaddr.h header does.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2018-01-31 17:33:08 +00:00
Daniel P. Berrangé
eef9812827 Fixed virGetUNIXSocketPath stub on Win32
The _() macro was not terminated and an argument needs to be marked as
unused.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-01-31 17:10:52 +00:00
John Ferlan
5b5bff35a8 qemu: Update qemuDomainFindSCSIControllerModel return
Now that the controller model is updated during post parse callback,
this code no longer needs to fetch the model based on the capabilities
and can just return the model directly if the controller is found.

Removal of @qemuCaps cascades through various callers which are now
updated to not pass the capabilities.
2018-01-31 11:32:04 -05:00
John Ferlan
de8fac5f21 qemu: Reduce need to call qemuDomainGetSCSIControllerModel
Now that post parse processing handles setting the SCSI controller
model, there's no need to call qemuDomainGetSCSIControllerModel to
get the "default controller" when building the command line controller
string or when assigning the spaprvio address since the controller
model value will already be filled in.
2018-01-31 11:32:04 -05:00
John Ferlan
d1b59c6214 conf: Allow configuration of implicit controller model
When an implicit controller is added, the model is defined as -1
(IOW: undefined). So, if an implicit SCSI controller was added,
can set the model to the default value if the underlying hypervisor
supports it.
2018-01-31 11:32:04 -05:00
John Ferlan
62f8c94732 qemu: Introduce qemuDomainSetSCSIControllerModel
During post parse processing, let's force setting the controller
model to default value if not already set for defined controllers
(e.g. the non implicit ones).
2018-01-31 11:32:04 -05:00
John Ferlan
13d216617d qemu: Fetch/save the default SCSI controller model during hotplug
If we're going to add a controller to the domain, let's set the
default SCSI model value if we cannot find another SCSI controller
already present.

NB: Requires updating the live output test data since the model
will now be formatted.
2018-01-31 11:32:04 -05:00
John Ferlan
fadfb4f9b3 qemu: Introduce qemuDomainGetSCSIControllerModel
Rename and rework qemuDomainSetSCSIControllerModel since we're
really not setting the SCSI controller model. Instead the code
is either returning the existing SCSI controller model value, the
default value based on the capabilities, or -1 with the error set.
2018-01-31 11:32:04 -05:00
John Ferlan
6ae6ffd88e qemu: Introduce qemuDomainFindSCSIControllerModel
Rather than repeat multiple steps in order to find the SCSI
controller model, let's combine them into one helper that will
return either the model from the definition or the default
model based on the capabilities.

This patch adds an extra check/error that the controller
that's being found actually exists. This just clarifies that
the error was because the controller doesn't exist rather
than the more generic error that we were unable to determine
the model from qemuDomainSetSCSIControllerModel when a -1
was passed in and the capabilities were unable to find one.
2018-01-31 11:32:04 -05:00
John Ferlan
932862b8bf conf: Rework and rename virDomainDeviceFindControllerModel
As it turns out virDomainDeviceFindControllerModel was only ever
called for SCSI controllers using VIR_DOMAIN_CONTROLLER_TYPE_SCSI
as a parameter.

So rename to virDomainDeviceFindSCSIController and rather than
return a model, let's return a virDomainControllerDefPtr to let
the caller reference whatever it wants.
2018-01-31 11:32:04 -05:00
John Ferlan
e37540f459 qemu: Split qemuDomainSetSCSIControllerModel
Rather than one function serving two purposes, let's split out the
else condition which is checking whether the model can be used
during command line building based on the capabilities.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2018-01-31 11:32:04 -05:00
Michal Privoznik
7b0ea999fc virUSBDeviceNew: Construct vroot path properly
When starting an LXC container, the /dev entries are created
under temp root (/var/run/libvirt/lxc/$name.dev), relabelled and
then the root is pivoted. However, when it comes to USB devices
which keep path to the device in the structure we need a way to
override the default /dev/usb/... path because we want to work
with the one under temp root. That's what @vroot argument is for
in virUSBDeviceNew. However, what is being passed there is:

  vroot = /var/run/libvirt/lxc/lxc_0.dev/bus/usb

Therefore, constructed path is wrong:

  dev->path = //var/run/libvirt/lxc/lxc_0.dev/bus/usb//dev/bus/usb/002/002

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-01-31 17:10:01 +01:00
Daniel P. Berrangé
12ba706d6d Check for tabs in augeas files
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-01-31 15:19:26 +00:00
Daniel P. Berrange
ce7ae55ea1 lockd: add support for admin protocol in virtlockd
Add a virtlockd-admin-sock can serves the admin protocol for the virtlockd
daemon and define a virtlockd:///{system,session}  URI scheme for
connecting to it.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2018-01-31 15:18:36 +00:00
Daniel P. Berrange
85d45ff05d logd: add support for admin protocol in virtlogd
Add a virtlogd-admin-sock can serves the admin protocol for the virtlogd
daemon and define a virtlogd:///{system,session}  URI scheme for
connecting to it.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2018-01-31 15:17:47 +00:00
Daniel P. Berrange
8aca141081 rpc: refactor virNetServer setup for post-exec restarts
With the current code it is neccessary to call

  virNetDaemonNewPostExecRestart()

and then for each server that needs restarting you are supposed
to call

  virNetDaemonAddSeverPostExecRestart()

This is fine if there's only ever one server, but as soon as you
have two servers it is impossible to use this design. The code
has no idea which servers were recorded in the JSON state doc,
nor in which order the hash table serialized its keys.

So this patch changes things so that we only call

  virNetDaemonNewPostExecRestart()

passing in a callback, which is invoked once for each server
found int he JSON state doc.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2018-01-31 15:17:14 +00:00
Daniel P. Berrange
e72f3e5933 rpc: add method for checking if a named server exists
It is not possible to blindly call virNetDaemonGetServer()
because in a post-exec restart scenario, some servers may
not exist and this method will pollute the error logs.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2018-01-31 15:16:40 +00:00
Daniel P. Berrange
9da0cc9ddb rpc: annotate various parameters as being required to be non-NULL
The server name and client data callbacks need to be non-NULL or the
system will crash at various times. This is particularly bad when some
of the crashes only occur post-exec restart.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2018-01-31 15:16:03 +00:00
Daniel P. Berrange
b41780e47a rpc: pass virNetServer to post-exec restart callback in typesafe manner
The virNetServer class is passing a pointer to itself to the
virNetServerClient as a 'void *' pointer. This is presumably due to fact
that the virnetserverclient.h file doesn't see the virNetServerPtr
typedef. The typedef is easily movable though, which lets us get
typesafe parameter passing, removing the confusion of passing two
distinct 'void *' pointers to one method.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2018-01-31 15:15:25 +00:00
Daniel P. Berrange
2c76fa91d3 rpc: clarify "void *" values passed to client callbacks
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2018-01-31 15:14:47 +00:00
Daniel P. Berrange
9fe6619d4a util: add virGetUNIXSocketPath helper
When receiving multiple socket FDs from systemd, it is critical to know
what socket address each corresponds to so we can setup the right
protocols on each.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2018-01-31 15:12:53 +00:00
Daniel P. Berrange
b42c591fec admin: add support for post-exec restart callbacks
We don't have any per-client private data we need to persist, but the
RPC infrastructure requires that we provide the callbacks and serialize
an empty JSON object. This makes us future proof going forwards.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2018-01-31 15:12:44 +00:00
Daniel P. Berrange
99d69f6925 libvirtd: rename virNetServerClient callback impls to match type names
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2018-01-31 15:12:33 +00:00
Daniel P. Berrange
b1e03dad86 admin: move admins server impl/dispatch into src/admin directory
The admin server functionality is a generic concept that should be wired
up into all libvirt daemons, but is currently integrated with the
libvirtd code. Move it all into the src/admin directory to prepare for
broader reuse.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2018-01-31 15:12:30 +00:00
Martin Kletzander
6c44013b17 qemu: Restore resctrl alloc data after restart
During reconnect we need to reconstruct the paths of all cachetunes so that they
get cleaned up when the domain is stopped.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-31 14:51:34 +01:00
Martin Kletzander
b9ceacba7c util: Extract path formatting into virResctrlAllocDeterminePath
We can use this from more places later, so just a future code de-duplication.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-31 14:51:34 +01:00
Martin Kletzander
272649a1d7 qemu: Restore machinename even without cgroups
The virresctrl will use this as well and we need to have that info after restart
to properly clean up /sys/fs/resctrl.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-31 14:51:34 +01:00
Martin Kletzander
859186091c util: Don't overwrite mask in virResctrlAllocFindUnused
Due to confusing naming the pointer to the mask got copied which must not
happen, so use UpdateMask instead of SetMask.  That also means we can get
completely rid of SetMask.

Also don't clear the free bits since it is not used again (leftover from
previous versions).

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-31 14:51:34 +01:00
Martin Kletzander
c39ce914dd util: Use default group's mask for unspecified resctrl allocations
Introduce virResctrlAllocCopyMasks() and use that to initially copy the default
group schemata to the allocation before reserving any parts of the cache.  The
reason for this is that when new group is created the schemata will have unknown
data in it.  If there was previously group with the same CLoS ID, it will have
the previous valies, if not it will have all bits set.  And we need to set all
unspecified (in the XML) allocations to the same one as the default group.

Some non-Linux functions now need to be made public due to this change.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-31 14:51:34 +01:00
Martin Kletzander
f6199295a9 util: Add helpers for getting resctrl group allocs
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-31 14:51:34 +01:00
Peter Krempa
f46d6e22f2 util: storage: Parse 'lun' for iSCSI protocol from JSON as string or number
While the QEMU QAPI schema describes 'lun' as a number, the code dealing
with JSON strings does not strictly adhere to this schema and thus
formats the number back as a string. Use the new helper to retrieve both
possibilities.

Note that the formatting code is okay and qemu will accept it as an int.

Tweak also one of the test strings to verify that both formats work
with libvirt.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1540290
2018-01-31 12:22:25 +01:00
Peter Krempa
d3da8013cc util: json: Add helper to return string or number properties as string
The helper is useful in cases when the JSON we have to parse may contain
one of the two due to historical reasons and the number value itself
would be stored as a string.
2018-01-31 12:21:39 +01:00
Andrea Bolognani
c7f6d4d010 conf: Use correct attribute name in error message
The <capabilities> feature has an attribute named 'policy', but the
error message mentioned the non-existing 'state' attribute instead.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2018-01-30 18:44:11 +01:00
Peter Krempa
b2c5f28a72 storage: util: Properly ignore errors when backing volume is inaccessible
Commit 000e950455 tried to fix improper bracketing when refreshing disk
volume stats for a backing volume. Unfortunately the condition is still
wrong as in cases as the backing store being inaccessible
storageBackendUpdateVolTargetInfo returns -2 if instructed to ignore
errors. The condition does not take this into account.

Dumping XML of a volume which has inacessible backing store would then
result into:

 # virsh vol-dumpxml http.img --pool default
 error: An error occurred, but the cause is unknown

Properly ignore -2 for backing volumes.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1540022
2018-01-30 11:41:59 +01:00
Martin Kletzander
f2e16994f7 util: Don't check if entries under /sys/fs/resctrl/(info/) are directories
We are skipping non-directories under /sys/fs/resctrl/(info/) since those are not
interesting for us.  However in tests it can sometimes happen that ent->d_type
is 0 instead of 4 (DT_DIR) for directories.

I've seen it fail on two machines.  Different machines, different systems, I
cannot reproduce it even using the same setup.  So one of the ways how to work
around this is call stat() on it.  The other one is not checking if it is a
directory since we'll find out eventually when we want to read some files
underneath it.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-29 21:40:54 +01:00
Martin Kletzander
e28ccd2643 util: Remove unused variable in virResctrlGetInfo
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-29 21:40:54 +01:00
Martin Kletzander
6899118043 util: Make it possible for virResctrlAllocSetMask to replace existing mask
This wil be used in the future, but it makes sense for now as well.  It makes
sure there is no mask leftover that would leak.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-29 21:40:54 +01:00
Martin Kletzander
ebafc603c1 util: Use "resctrl" instead of "resctrlfs" spelling
Pointed out during review on one or two places, but it actually appears in lot
more places.  So let's be consistent.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-29 21:40:54 +01:00
Martin Kletzander
bd5d07425d util: Check for empty allocation instead of just NULL pointer
When working on the CAT series one of the changes was that the pointer got
allocated in another part of the code, even when resctrl was not available on
the host system.  However this one particular place neglected that so it needs
to be fixed in order to get the proper error message when requesting
<cachetune/> on HW with no support for it.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-29 21:40:53 +01:00
Erik Skultety
b7a7912411 build: Fix broken build on FreeBSD and OSX after recent nodedev series
Commits f83c7c88 and 6eb1f2b9 broke the build on FreeBSD and OSX because
of symbols being undefined for those platforms.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 17:53:13 +01:00
John Ferlan
6b7c5c4726 qemu: Fix memory leak in processGuestPanicEvent
After processing the processEvent->data for a qemuProcessEventHandler
callout, it's expected that the called processEvent->eventType helper
will perform the proper free on the data field. In this case it's
a qemuMonitorEventPanicInfoPtr.
2018-01-29 11:44:20 -05:00
Erik Skultety
75dbb27b10 conf: nodedev: Update PCI mdev capabilities dynamically
Just like SRIOV, a PCI device is only capable of the mediated devices
framework when it's bound to the vendor native driver, thus if a driver
change occurs, e.g. vendor_native->vfio, we need to refresh some of the
device's capabilities to reflect the reality, mdev included.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Suggested-by: Wu Zongyong <cordius.wu@huawei.com>
Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
882fd7a13c conf: Replace usage of virNodeDevCapMdevType with virMediatedDeviceType
Now that we have all the building blocks in place, switch the nodedev
driver to use the "new" virMediatedDeviceType type instead of the "old"
virNodeDevCapMdevType one.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
3cbac4dec0 nodedev: udev: Drop the unused mdev type helpers
These are not necessary anymore, since these are going to be shadowed by
the helpers provided by util/virmdev.c module.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
6eb1f2b9d0 util: pci: Introduce virPCIGetMdevTypes helper
This is a replacement for the existing udevPCIGetMdevTypesCap which is
static to the udev backend. This simple helper constructs the sysfs path
from the device's base path for each mdev type and queries the
corresponding attributes of that type.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
3545cbef7f util: mdev: Introduce virMediatedDeviceTypeReadAttrs getter
This should serve as a replacement for the existing udevFillMdevType
which is responsible for fetching the device type's attributes from the
sysfs interface. The problem with the existing solution is that it's
tied to the udev backend.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
c3faa92a1b util: mdev: Introduce virMediatedDeviceType structure
This is later going to replace the existing virNodeDevCapMdevType, since:
1) it's going to couple related stuff in a single module
2) util is supposed to contain helpers that are widely accessible across
the whole repository.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
0674ddd317 util: mdev: Drop some unused symbols/includes from the header
There were some leftovers from early development which never got used.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
d18feadc0c conf: nodedev: Refresh capabilities before touching them
Most of them are static, however in case of PCI and SCSI_HOST devices,
the nested capabilities can change dynamically, e.g. due to a driver
change (from host_pci_driver -> vfio_pci).

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Suggested-by: Wu Zongyong <cordius.wu@huawei.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
36546e3cdb nodedev: Introduce virNodeDeviceCapsListExport
Whether asking for a number of capabilities supported by a device or
listing them, it's handled essentially by a copy-paste code, so extract
the common stuff into this new helper which also updates all
capabilities just before touching them.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
349dda1fc8 nodedev: Export nodeDeviceUpdateCaps from node_device_conf.c
Since we moved the helpers from nodedev driver to src/conf, the actual
'update' function using those helpers should be moved as well so that we
don't need to call back into the driver.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
f83c7c88c5 nodedev: Move the sysfs-related cap handling to node_device_conf.c
The capabilities are defined/parsed/formatted/queried from this module,
no reason for 'update' not being part of the module as well. This also
involves some module-specific prefix changes.
This patch also drops the node_device_linux_sysfs module from the repo
since:
a) it only contained the capability handlers we just moved
b) it's only linked with the driver (by design) and thus unreachable to
other modules
c) we touch sysfs across all the src/util modules so the module being
deleted hasn't been serving its original intention for some time already.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
d1860140cc nodedev: Drop the nodeDeviceSysfsGetSCSIHostCaps wrapper
We can call directly the virNodeDeviceGetSCSIHostCaps helper instead.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
b20ec49e57 conf: nodedev: Convert virNodeDevObjHasCapStr to a simple wrapper
This patch drops the capability matching redundancy by simply converting
the string input to our internal types which are then in turn used for
the actual capability matching.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
54cab10518 conf: nodedev: Rename virNodeDeviceCapMatch to virNodeDevObjHasCap
We currently have 2 methods that do the capability matching. This should
be condensed to a single function and all the derivates should just call
into that using a proper type conversion.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
Erik Skultety
1cbaeda707 conf: nodedev: Rename virNodeDevObjHasCap to virNodeDevObjHasCapStr
We currently have 2 methods that do the capability matching. This should
be condensed to a single function and all the derivates should just call
into that using a proper type conversion.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-29 15:34:30 +01:00
Julio Faracco
3f630aa0e9 test: Implementing testDomainRename().
There is no method to rename inactive domains for test driver.
After this patch, we can rename the domains using 'domrename'.

    virsh# domrename test anothertest
    Domain successfully renamed

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-01-29 09:50:47 +01:00
ZhiPeng Lu
614be3b882 vhost-user: add support reconnect for vhost-user ports
For vhost-user ports, Open vSwitch acts as the server and QEMU the client.
When OVS crashes or restarts, the QEMU process should be reconnected to
OVS.

Signed-off-by: ZhiPeng Lu <lu.zhipeng@zte.com.cn>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-01-26 14:02:46 +01:00
Daniel P. Berrangé
a020ab03fd resctl: stub out functions with Linux-only APIs used
The flock() function and d_type field in struct dirent are not portable
to the mingw platform.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-01-25 17:42:36 +00:00
Daniel P. Berrange
4e13fb02fe rpc: fix race sending and encoding sasl data
The virNetSocketWriteSASL method has to encode the buffer it is given and then
write it to the underlying socket. This write is not guaranteed to send the
full amount of data that was encoded by SASL. We cache the SASL encoded data so
that on the next invocation of virNetSocketWriteSASL we carry on sending it.

The subtle problem is that the 'len' value passed into virNetSocketWriteSASL on
the 2nd call may be larger than the original value. So when we've completed
sending the SASL encoded data we previously cached, we must return the original
length we encoded, not the new length.

This flaw means we could potentially have been discarded queued data without
sending it. This would have exhibited itself as a libvirt client never receiving
the reply to a method it invokes, async events silently going missing, or worse
stream data silently getting dropped.

For this to be a problem libvirtd would have to be queued data to send to the
client, while at the same time the TCP socket send buffer is full (due to a very
slow client). This is quite unlikely so if this bug was ever triggered by a real
world user it would be almost impossible to reproduce or diagnose, if indeed it
was ever noticed at all.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2018-01-25 16:29:24 +00:00
Jim Fehlig
0c710a37ea libxl: resume lock process after failed migration
During migration, the lock process is paused in the perform phase
but not resumed if there is a subsequent failure, leaving the locked
resource unprotected.

The perform phase itself can fail, in which case the lock process
should be resumed before returning from perform. The finish phase
could also fail on the destination host, in which case the migration
is canceled in the confirm phase and the VM is resumed. The lock
process needs to be resumed there as well.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2018-01-25 09:22:14 -07:00
Martin Kletzander
9a2fc2db8f qemu: Add support for resctrl
We've been building up to this.  This adds support for cputune/cachetune
settings for domains in the QEMU driver.  The addition into
qemuProcessSetupVcpu() automatically adds support for hotplug.  For hot-unplug
we need to remove the allocation only if all the vCPUs were unplugged.  But
since the threads are left running, we can't really do much about it now.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-25 17:16:08 +01:00
Martin Kletzander
7387e3fea4 conf: Add support for cputune/cachetune
More info in the documentation, this is basically the XML parsing/formatting
support, schemas, tests and documentation for the new cputune/cachetune element
that will get used by following patches.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-25 17:16:08 +01:00
Martin Kletzander
a64c761c27 resctrl: Add functions to work with resctrl allocations
With this commit we finally have a way to read and manipulate basic resctrl
settings.  Locking is done only on exposed functions that read/write from/to
resctrlfs.  Not in functions that are exposed in virresctrlpriv.h as those are
only supposed to be used from tests.

More information about how resctrl works:

  https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/x86/intel_rdt_ui.txt

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-25 17:16:08 +01:00
Martin Kletzander
434848d7dc fixup_resctrlinfo
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-25 17:16:08 +01:00
Martin Kletzander
6328e48713 util: Remove now-unneeded resctrl functions
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-25 17:16:08 +01:00
Martin Kletzander
3bbae43d8c conf: Use virResctrlInfo in capabilities
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-25 17:16:08 +01:00
Martin Kletzander
cd572df89b util: Add virResctrlInfo
This will make the current functions obsolete and it will provide more
information to the virresctrl module so that it can be used later.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-25 17:16:08 +01:00
Martin Kletzander
b2211a9e54 Rename virResctrlInfo to virResctrlInfoPerCache
Just to ease the review of following patches.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2018-01-25 17:16:08 +01:00
Daniel P. Berrange
7697706135 qemu: add support for generating SMBIOS OEM strings command line
This wires up the previously added OEM strings XML schema to be able to
generate comamnd line args for QEMU. This requires QEMU >= 2.12 release
containing this patch:

  commit 2d6dcbf93fb01b4a7f45a93d276d4d74b16392dd
  Author: Daniel P. Berrange <berrange@redhat.com>
  Date:   Sat Oct 28 21:51:36 2017 +0100

    smbios: support setting OEM strings table

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2018-01-25 14:48:56 +00:00
Daniel P. Berrange
68eed56b2d conf: add support for setting OEM strings SMBIOS data fields
The OEM strings table in SMBIOS allows the vendor to pass arbitrary
strings into the guest OS. This can be used as a way to pass data to an
application like cloud-init, or potentially as an alternative to the
kernel command line for OS installers where you can't modify the install
ISO image to change the kernel args.

As an example, consider if cloud-init and anaconda supported OEM strings
you could use something like

    <oemStrings>
      <entry>cloud-init:ds=nocloud-net;s=http://10.10.0.1:8000/</entry>
      <entry>anaconda:method=http://dl.fedoraproject.org/pub/fedora/linux/releases/25/x86_64/os</entry>
    </oemStrings>

use of a application specific prefix as illustrated above is
recommended, but not mandated, so that an app can reliably identify
which of the many OEM strings are targetted at it.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2018-01-25 14:48:56 +00:00
Shaohe Feng
e7cb9c4e23 cpu: Add support for al57 Intel features
We can start qemu with a "cpu,+la57" to set 57-bit vitrual address
space. So VM can be aware that it need to enable 5-level paging.

Corresponding QEMU commits:
        al57 6c7c3c21f95dd9af8a0691c0dd29b07247984122
2018-01-25 15:30:32 +01:00
Laine Stump
ed2049ea19 qemu: auto-add generic xhci rather than NEC xhci to Q35 domains
We recently added a generic XHCI USB3 controller to QEMU, and libvirt
supports adding that controller rather than the NEC XHCI USB3
controller, but when auto-adding a USB controller to Q35 domains we
were still adding the vendor-specific NEC controller. This patch
changes to add the generic controller instead, if it's available in
the QEMU binary that will be used.

Signed-off-by: Laine Stump <laine@laine.org>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-22 10:13:16 -05:00
Jiri Denemark
ba9ea2ad7d qemu: Don't initialize struct utsname
It breaks the build and it is not really useful for anything.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2018-01-22 14:53:39 +01:00
Jiri Denemark
52b7d910b6 qemu: Refresh caps cache after booting a different kernel
Whenever a different kernel is booted, some capabilities related to KVM
(such as CPUID bits) may change. We need to refresh the cache to see the
changes.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
2018-01-22 14:11:58 +01:00
Laine Stump
7ce8ff0f88 qemu: move qemuDomainDefValidateVideo into qemuDomainDeviceDefValidateVideo
qemuDomainDefValidateVideo() (called from qemuDomainDefValidate()) is
just a loop performing various checks on each video device. Rather
than maintaining this separate function, just fold the validations
into qemuDomainDeviceDefValidateVideo(), which is called once for each
video device.
2018-01-21 11:10:03 -05:00
Laine Stump
18c24bc686 qemu: assign correct type of PCI address for vhost-scsi when using pcie-root
Commit 10c73bf1 fixed a bug that I had introduced back in commit
70249927 - if a vhost-scsi device had no manually assigned PCI
address, one wouldn't be assigned automatically. There was a slight
problem with the logic of the fix though - in the case of domains with
pcie-root (e.g. those with a q35 machinetype),
qemuDomainDeviceCalculatePCIConnectFlags() will attempt to determine
if the host-side PCI device is Express or legacy by examining sysfs
based on the host-side PCI address stored in
hostdev->source.subsys.u.pci.addr, but that part of the union is only
valid for PCI hostdevs, *not* for SCSI hostdevs. So we end up trying
to read sysfs for some probably-non-existent device, which fails, and
the function virPCIDeviceIsPCIExpress() returns failure (-1).

By coincidence, the return value is being examined as a boolean, and
since -1 is true, we still end up assigning the vhost-scsi device to
an Express slot, but that is just by chance (and could fail in the
case that the gibberish in the "hostside PCI address" was the address
of a real device that happened to be legacy PCI).

Since (according to Paolo Bonzini) vhost-scsi devices appear just like
virtio-scsi devices in the guest, they should follow the same rules as
virtio devices when deciding whether they should be placed in an
Express or a legacy slot. That's accomplished in this patch by
returning early with virtioFlags, rather than erroneously using
hostdev->source.subsys.u.pci.addr. It also adds a test case for PCIe
to assure it doesn't get broken in the future.
2018-01-20 22:01:24 -05:00
Jim Fehlig
71d56a3979 nodedev: Fix failing to parse PCI address for non-PCI network devices
Commit 8708ca01c added virNetDevSwitchdevFeature() to check if a network
device has Switchdev capabilities. virNetDevSwitchdevFeature() attempts
to retrieve the PCI device associated with the network device, ignoring
non-PCI devices. It does so via the following call chain

  virNetDevSwitchdevFeature()->virNetDevGetPCIDevice()->
  virPCIGetDeviceAddressFromSysfsLink()

For non-PCI network devices (qeth, Xen vif, etc),
virPCIGetDeviceAddressFromSysfsLink() will report an error when
virPCIDeviceAddressParse() fails. virPCIDeviceAddressParse() also
logs an error. After commit 8708ca01c there are now two errors reported
for each non-PCI network device even though the errors are harmless.

To avoid the errors, introduce virNetDevIsPCIDevice() and use it in
virNetDevGetPCIDevice() before attempting to retrieve the associated
PCI device. virNetDevIsPCIDevice() uses the 'subsystem' property of the
device to determine if it is PCI. See the sysfs rules in kernel
documentation for more details

https://www.kernel.org/doc/html/latest/admin-guide/sysfs-rules.html
2018-01-19 09:53:01 -07:00
Michal Privoznik
72adaf2f10 Revert "qemu: monitor: do not report error on shutdown"
https://bugzilla.redhat.com/show_bug.cgi?id=1536461

This reverts commit aeda1b8c56.

Problem is that we need mon->lastError to be set because it's
used all over the place. Also, there's nothing wrong with
reporting error if one occurred. I mean, if there's a thread
executing an API and which currently is talking on monitor it
definitely wants the error reported.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-01-19 14:31:03 +01:00
Jiri Denemark
bcc5710708 qemu: Fix crash in offline migration
When migrating a shutoff domain (i.e., offline migration), we have no
statistics to report and thus jobInfo will be NULL in
qemuMigrationFinish.

Broken by me in v3.10.0-183-ge8784e7868.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-19 10:51:19 +01:00
Jiri Denemark
6d4a3cd427 cpu: Add EPYC-IBPB CPU model
This is a variant of EPYC with indirect branch prediction protection.
The only difference between EPYC and EPYC-IBPB is the added "ibpb"
feature.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-18 15:04:18 +01:00
Daniel P. Berrange
bc251ea91b qemu: avoid denial of service reading from QEMU monitor (CVE-2018-5748)
We read from QEMU until seeing a \r\n pair to indicate a completed reply
or event. To avoid memory denial-of-service though, we must have a size
limit on amount of data we buffer. 10 MB is large enough that it ought
to cope with normal QEMU replies, and small enough that we're not
consuming unreasonable mem.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2018-01-18 09:04:27 +00:00
Marc Hartmayer
029e024770 qemu: qemuDomainNamespaceUnlinkPaths: Return 0 in case of success
Commit 7a931a4204 refactored the code and probably forgot to add
this line.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
2018-01-17 17:08:53 +01:00
Jiri Denemark
24d504396c cpu: Add Skylake-Server-IBRS CPU model
This is a variant of Skylake-Server with indirect branch prediction
protection. The only difference between Skylake-Server and
Skylake-Server-IBRS is the added "spec-ctrl" feature.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-17 17:07:04 +01:00
Jiri Denemark
b2042020c3 cpu: Add Skylake-Client-IBRS CPU model
This is a variant of Skylake-Client with indirect branch prediction
protection. The only difference between Skylake-Client and
Skylake-Client-IBRS is the added "spec-ctrl" feature.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-17 17:07:04 +01:00
Jiri Denemark
7bb4ce9761 cpu: Add Broadwell-IBRS CPU model
This is a variant of Broadwell with indirect branch prediction
protection. The only difference between Broadwell and Broadwell-IBRS is
the added "spec-ctrl" feature.

The Broadwell-IBRS model in QEMU is a bit different since Broadwell got
several additional features since we added it in cpu_map.xml:
    abm, arat, f16c, rdrand, vme, xsaveopt

Adding them only to the -IBRS variant would confuse our CPU detection
code.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-17 17:07:04 +01:00
Jiri Denemark
49bffcb3cc cpu: Add Broadwell-noTSX-IBRS CPU model
This is a variant of Broadwell-noTSX with indirect branch prediction
protection. The only difference between Broadwell-noTSX and
Broadwell-noTSX-IBRS is the added "spec-ctrl" feature.

The Broadwell-noTSX-IBRS model in QEMU is a bit different since
Broadwell-noTSX got several additional features since we added it in
cpu_map.xml:
    abm, arat, f16c, rdrand, vme, xsaveopt

Adding them only to the -IBRS variant would confuse our CPU detection
code.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-17 17:07:03 +01:00
Jiri Denemark
7f83eefa9e cpu: Add Haswell-IBRS CPU model
This is a variant of Haswell with indirect branch prediction protection.
The only difference between Haswell and Haswell-IBRS is the added
"spec-ctrl" feature.

The Haswell-IBRS model in QEMU is a bit different since Haswell got
several additional features since we added it in cpu_map.xml:
    arat, abm, f16c, rdrand, vme, xsaveopt

Adding them only to the -IBRS variant would confuse our CPU detection
code.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-17 17:07:03 +01:00
Jiri Denemark
7dd85ff62d cpu: Add Haswell-noTSX-IBRS CPU model
This is a variant of Haswell-noTSX with indirect branch prediction
protection. The only difference between Haswell-noTSX and
Haswell-noTSX-IBRS is the added "spec-ctrl" feature.

The Haswell-noTSX-IBRS model in QEMU is a bit different since
Haswell-noTSX got several additional features since we added it in
cpu_map.xml:
    arat, abm, f16c, rdrand, vme, xsaveopt

Adding them only to the -IBRS variant would confuse our CPU detection
code.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-17 17:07:03 +01:00
Jiri Denemark
203c92e9cc cpu: Add IvyBridge-IBRS CPU model
This is a variant of IvyBridge with indirect branch prediction
protection. The only difference between IvyBridge and IvyBridge-IBRS is
the added "spec-ctrl" feature.

The IvyBridge-IBRS model in QEMU is a bit different since IvyBridge got
several additional features since we added it in cpu_map.xml:
    arat, vme, xsaveopt

Adding them only to the -IBRS variant would confuse our CPU detection
code.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-17 17:07:03 +01:00
Jiri Denemark
30b381cfdd cpu: Add SandyBridge-IBRS CPU model
This is a variant of SandyBridge with indirect branch prediction
protection. The only difference between SandyBridge and SandyBridge-IBRS
is the added "spec-ctrl" feature.

The SandyBridge-IBRS model in QEMU is a bit different since SandyBridge
got several additional features since we added it in cpu_map.xml:
    arat, vme, xsaveopt

Adding them only to the -IBRS variant would confuse our CPU detection
code.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-17 17:07:03 +01:00
Jiri Denemark
2e3b220a87 cpu: Add Westmere-IBRS CPU model
This is a variant of Westmere with indirect branch prediction
protection. The only difference between Westmere and Westmere-IBRS is
the added "spec-ctrl" feature.

The Westmere-IBRS model in QEMU is a bit different since Westmere got
several additional features since we added it in cpu_map.xml:
    arat, pclmuldq, vme

Adding them only to the -IBRS variant would confuse our CPU detection
code.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-17 17:07:03 +01:00
Jiri Denemark
6b7e7d1cc2 cpu: Add Nehalem-IBRS CPU model
This is a variant of Nehalem with indirect branch prediction protection.
The only difference between Nehalem and Nehalem-IBRS is the added
"spec-ctrl" feature.

Thus the diff matches QEMU, but the new CPU model itself is different.
The QEMU's versions of both models contain "vme" feature, while this
feature is missing in libvirt's models. While we can't change the
existing Nehalem CPU model, we could add "vme" to Nehalem-IBRS to make
it similar to QEMU, but doing so would fool our CPU detecting code so
that any Nehalem CPU with "vme" feature would be detected as
Nehalem-IBRS CPU without spec-ctrl. Not adding "vme" to Nehalem-IBRS is
safe as QEMU will just provide the feature anyway, which matches what
happens with Nehalem (and new enough machine types).

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-17 17:07:02 +01:00
Paolo Bonzini
8b605530e8 cpu: add CPU features for indirect branch prediction protection
Added in QEMU commits TBD and TBD.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-17 17:07:02 +01:00
Marc Hartmayer
97202988d9 qemu: Fix segmentation fault when attaching a non iSCSI host device
Add a check if it's a iSCSI hostdev and if it's not then don't use the
union member 'iscsi'. The segmentation fault occured when accessing
secinfo->type, but this can vary from case to case.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
2018-01-17 09:57:53 -05:00
Dan Zheng
75cfb8434e nodedev: Add the missing PCI dev checks for 'mdev_types' capability
Similar to commit @f44ec9c1, commit @500cbc06 introduced a new nested
'mdev_types' capability, however the mentioned commit didn't adjust
virNodeDeviceNumOfCaps and virNodeDeviceListCaps functions accordingly
to provide proper support for this capability.

After applying this patch the following python snippet returns the
expected results:
    import libvirt
    conn = libvirt.openReadOnly('qemu:///system')
    devs = conn.listAllDevices()
    for dev in devs:
        if 'mdev_types' in dev.listCaps():
            print dev.name(),dev.numOfCaps(),dev.listCaps()

Signed-off-by: Dan Zheng <dzheng@redhat.com>
Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-16 10:33:25 +01:00
Bjoern Walk
4be9959b41 util: virsysinfo: parse frequency information on S390
Let's also parse the available processor frequency information on S390
so that it can be utilized by virsh sysinfo:

    # virsh sysinfo

    <sysinfo type='smbios'>
      ...
      <processor>
	<entry name='family'>2964</entry>
	<entry name='manufacturer'>IBM/S390</entry>
	<entry name='version'>00</entry>
	<entry name='max_speed'>5000</entry>
	<entry name='serial_number'>145F07</entry>
      </processor>
      ...
    </sysinfo>

Reviewed-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Signed-off-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
2018-01-12 09:21:05 -05:00
Scott Garfinkle
2d8721e260 domcaps: Treat host models as case-insensitive strings
Qemu 2.11 allows case-insensitive specification of CPU models.
This patch fixes the resulting problems on (at least) POWER
arch machines so that Power8 and POWER8 are not different.

Signed-off-by: Scott Garfinkle <scottgar@linux.vnet.ibm.com>
2018-01-12 06:31:53 -05:00
Jiri Denemark
e8784e7868 qemu: Fix type of a completed job
Libvirt 3.7.0 and earlier libvirt reported a migration job as completed
immediately after QEMU finished sending migration data at which point
migration was not really complete yet. Commit v3.7.0-29-g3f2d6d829e
fixed this, but caused a regression in reporting statistics for
completed jobs which started reporting the job as still running. This
happened because the completed job statistics including the job status
are copied from the running job before we finally mark it as completed.

Let's make sure QEMU_DOMAIN_JOB_STATUS_COMPLETED is always set in the
completed job info even when the job has not finished yet.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-12 10:45:31 +01:00
Jiri Denemark
237f045d9a qemu: Ignore fallback CPU attribute on reconnect
When reconnecting to a running domain with host-model CPU started by old
libvirt which did not store the actual CPU in the status XML, we need to
ignore the fallback attribute to make sure we can translate the detected
host CPU model to a model which is supported by the running QEMU.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-12 10:45:31 +01:00
Michal Privoznik
72bf14d345 util: Introduce virStringListMerge
For two string lists merge one into the other one.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-01-11 18:53:04 +01:00
Bjoern Walk
ae68dbffe9 util: virhostcpu: parse frequency information on S390
Since kernel version 4.7, processor frequency information is available
on S390. Let's adjust the parser so this information shows up for virsh
nodeinfo:

    # virsh nodeinfo
    CPU model:           s390x
    CPU(s):              8
    CPU frequency:       5000 MHz
    CPU socket(s):       1
    Core(s) per socket:  8
    Thread(s) per core:  1
    NUMA cell(s):        1
    Memory size:         16273908 KiB

Reviewed-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Signed-off-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
2018-01-10 17:24:11 -05:00
John Ferlan
be1bb6c95b storage: Complete implementation volume by hash object
Alter the volume logic to use the hash tables instead of forward
linked lists. There are three hash tables to allow for fast lookup
by name, target.path, and key.

Modify the virStoragePoolObjAddVol to place the object in all 3
tables if possible using self locking RWLock on the volumes object.
Conversely when removing the volume, it's a removal of the object
from the various hash tables.

Implement functions to handle remote ForEach and Search Volume
type helpers. These are used by the disk backend in order to
facilitate adding a primary, extended, or logical partition.

Implement the various VolDefFindBy* helpers as simple (and fast)
hash lookups. The NumOfVolumes, GetNames, and ListExport helpers
are all implemented using standard for each hash table calls.
2018-01-10 08:10:24 -05:00
John Ferlan
f77c898d1e storage: Introduce _virStorageVolObj[List]
Prepare for hash table volume lists by creating the object infrastructure
for a Volume Object and Volume Object List

The _virStorageVolObj will contain just a pointer to the "current"
(and live) volume definition.

The _virStorageVolObjList will contain three hash tables, one for
each of the lookup options allowed for a volume.
2018-01-10 08:10:23 -05:00
John Ferlan
71d80c9726 storage: Modify virStorageBackendDiskMakeDataVol logic
Alter the logic such that we only add the volume to the pool once
we've filled in all the information and cause failure to go to a
common error: label. Patches to place the @vol into a few hash tables
will soon "require" that at least the keys (name, target.path, and key)
be populated with valid data.
2018-01-10 08:10:23 -05:00
John Ferlan
ec24d2905b storage: When delete volume avoid disk backend removal
For a disk backend, the deleteVol code will clear all the
volumes in the pool and perform a pool refresh, thus the
storageVolDeleteInternal should not use access @voldef
after deleteVol succeeds.
2018-01-10 08:10:23 -05:00
Jiri Denemark
b427cf4831 cpu_x86: Copy CPU signature from ancestor
When specifying a new CPU model in cpu_map.xml as an extension to an
existing model, we forgot to copy the signature (family + model) from
the original CPU model.

We don't use this way of specifying CPU models, but it's still supported
and it becomes useful when someone wants to quickly hack up a CPU model
for testing or when creating additional variants of existing models to
help with fixing some spectral issues.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-10 11:07:23 +01:00
Jiri Denemark
ad80ccd3f9 cpu_x86: Add debug messages to x86DecodeUseCandidate
When translating CPUID data into CPU model + features, the code
sometimes uses an unexpected CPU model. There may be several reasons for
this, starting with wrong expectations and ending with an actual bug in
our code. These debug messages will help determining the reason.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-10 11:07:23 +01:00
Christian Ehrhardt
335ea94e31 apparmor, virt-aa-helper: drop static channel rule
This is now covered by DomainSetPathLabel being implemented in apparmor.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2018-01-09 17:29:52 +01:00
Christian Ehrhardt
14b52bb765 security, apparmor: add (Set|Restore)ChardevLabel
Since 1b4f66e "security: introduce virSecurityManager
(Set|Restore)ChardevLabel" this is a public API of security manager.

Implementing this in apparmor avoids miss any rules that should be
added for devices labeled via these calls.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2018-01-09 17:29:52 +01:00
Christian Ehrhardt
a5486e57f5 security: full path option for DomainSetPathLabel
virSecurityManagerDomainSetPathLabel is used to make a path known
to the security modules, but today is used interchangably for
 - paths to files/dirs to be accessed directly
 - paths to a dir, but the access will actually be to files therein

Depending on the security module it is important to know which of
these types it will be.

The argument allowSubtree augments the call to the implementations of
DomainSetPathLabel that can - per security module - decide if extra
actions shall be taken.

For now dac/selinux handle this as before, but apparmor will make
use of it to add a wildcard to the path that was passed.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-01-09 17:29:52 +01:00
Christian Ehrhardt
f436a78239 security, apparmor: implement domainSetPathLabel
This came up in discussions around huge pages, but it will cover
more per guest paths that should be added to the guests apparmor profile:
 - keys via qemuDomainWriteMasterKeyFile
 - per domain dirs via qemuProcessMakeDir
 - memory backing paths via qemuProcessBuildDestroyMemoryPathsImpl

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2018-01-09 17:29:52 +01:00
Michal Privoznik
058b7fd0fe qemu: Prepare BIOS/UEFI when starting a domain
https://bugzilla.redhat.com/show_bug.cgi?id=1527740

Users might use a block device as UEFI VAR store. Or even have
OVMF stored there. Therefore, when starting a domain and separate
mount namespace is used, we have to create all the /dev entries
that are configured for the domain.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-01-09 08:29:51 +01:00
Chen Hanxiao
91a3234f3a qemu: Add support for hot unplugging redirdev device
Commit id '162efa1a' added support hotplug a redirdev, but
did not add the hot unplug. This patch will add that support
to allow usage of the detach-device --live on the device.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
2018-01-08 11:49:26 -05:00
Andrea Bolognani
a63ea8141b util: Don't report CPU frequency for ARM hosts
Some ARM platforms, such as the original Raspberry Pi, report the
CPU frequency in the BogoMIPS field of /proc/cpuinfo, so libvirt
parsed that field and returned it through its API.

However, not only many more boards don't report any value there,
but several - including ARMv8-based server hardware, and even the
more recent Raspberry Pi 3 - use this field as originally intended:
to report the BogoMIPS value instead of the CPU frequency.

Since we have no way of detecting how the field is being used,
it's better to report no information at all rather than something
ludicrous like "your shiny 96-core aarch64 virtualization host's
CPUs are running at a whopping 100 MHz".

Partially-resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1206353

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-01-08 14:22:53 +01:00
Andrea Bolognani
6512b0ddc1 util: Improve CPU frequency parsing
Make the parser both more strict, by not ignoring errors reported
by virStrToLong_ui(), and more permissive, by not failing due to
unrelated fields which just happen to have a know prefix and
accepting any amount of whitespace before the numeric value.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
2018-01-08 13:48:44 +01:00
Andrea Bolognani
5e07b28a7a util: Print architecture name in /proc/cpuinfo parser
Instead of a generic "your architecture", print the actual
architecture name.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
2018-01-08 13:48:44 +01:00
Bjoern Walk
0764fc8ad1 util: virhostcpu: factor out frequency parsing
All different architectures use the same copy-pasted code to parse
processor frequency information from /proc/cpuinfo. Let's extract that
code into a function to avoid repetition.

We now also tolerate if the parsing of /proc/cpuinfo is not successful
and just report a warning instead of bailing out and abandoning the rest
of the CPU information.

Reviewed-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
2018-01-08 13:48:44 +01:00
Michal Privoznik
db98e7f67e qemuDomainAttachDeviceMknodHelper: Remove symlink before creating it
https://bugzilla.redhat.com/show_bug.cgi?id=1528502

So imagine you have /dev/blah symlink which points to /dev/sda.
You attach /dev/blah as disk to your domain. Libvirt correctly
creates the /dev/blah -> /dev/sda symlink in the qemu namespace.
However, then you detach the disk, change the symlink so that it
points to /dev/sdb and tries to attach the disk again. This time,
however, the attach fails (well, qemu attaches wrong disk)
because the code assumes that symlinks don't change. Well they
do.

This is inspired by test fix written by Eduardo Habkost.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2018-01-08 09:53:48 +01:00
Shivaprasad G Bhat
2b041dc8c7 qemu: Add support for pseries machine's max-cpu-compat= parameter
When the -machine pseries,max-cpu-compat=X is supported use
machine parameter instead of -cpu host,compat=X parameter as
that is deprecated now with qemu >= v2.10.

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

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2018-01-05 17:12:14 +01:00
Shivaprasad G Bhat
524207a5c2 qemu: Add capability for pseries machine's max-cpu-compat= parameter
Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2018-01-05 17:00:58 +01:00
Michal Privoznik
d0204e373d qemuDomainDiskChangeSupported: Forbid alias change
Since we have user aliases it may happen that users want to
change it using 'update-device'. Instead of ignoring it silently,
error out loudly. Note that we don't limit the check just for
"ua-" prefixes because users might try to change libvirt
generated aliases too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-01-05 14:22:45 +01:00
John Ferlan
b372983d14 qemu: Alter dump-guest-memory command generation
The qemuMonitorJSONMakeCommand can properly handle a NULL string
by using the "S:" parameter instead of "s:", so let's use that
of having in if/else condition that only adds the "s:".
2018-01-04 12:15:49 -05:00
John Ferlan
cf8de2442f qemu: Clean up style for the qemuDumpToFd definition
Alter the function definition to follow more recent style
2018-01-04 12:15:49 -05:00
John Ferlan
394eaa6b39 test: Use virStoragePoolObjIsDuplicate for storage define/create
Avoid the chance that there could be a duplicate storage pool UUID
or Name from the test driver storage pool define/create functions.
2018-01-04 10:54:08 -05:00
John Ferlan
607524af4f conf: Use bool for @check_active parameter
Use a bool as that's how the variable is used in the function.
2018-01-04 10:54:08 -05:00
John Ferlan
c00643f86f conf: Need to unlock pools on object allocation failure
The RW pool could be left locked if allocation fails.
2018-01-04 10:54:08 -05:00
Paolo Bonzini
b527589d1f qemu: capabilities: force update if the microcode version does not match
A microcode update can cause the CPUID bits to change; an example
from the past was the update that disabled TSX on several Haswell
and Broadwell machines.

Therefore, place microcode version in the virQEMUCaps struct and
XML, and rebuild the cache if the versions do not match.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2018-01-04 16:52:03 +01:00
Paolo Bonzini
d2440f3b53 conf: include x86 microcode version in virsh capabilities
A microcode update can cause the CPUID bits to change; an example
from the past was the update that disabled TSX on several Haswell and
Broadwell machines.

In order to track the x86 microcode version in the QEMU capabilities,
we have to fetch it and store it in the host CPU.  This also makes the
version visible in "virsh capabilities", which is a nice side effect.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2018-01-04 16:52:03 +01:00
Jiri Denemark
bd874d9ff1 cpu_x86: Rename virCPUx86MapInitialize
The function will be used to initialize internal data of the x86 CPU
driver (including the CPU map).

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2018-01-04 16:52:03 +01:00
Paolo Bonzini
04502fd54f util: introduce virHostCPUGetMicrocodeVersion
This new API reads host's CPU microcode version from /proc/cpuinfo.

Unfortunately, there is no other way of reading microcode version which
would be usable from both system and session daemon.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2018-01-04 16:52:03 +01:00
Paolo Bonzini
40fc85e796 util: add virFileReadHeaderQuiet wrapper around virFileReadHeaderFD
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2018-01-04 16:52:03 +01:00
John Ferlan
8d424f1b23 conf: Fix generating addresses for SCSI hostdev
https://bugzilla.redhat.com/show_bug.cgi?id=1519130

Commit id 'dc692438' reverted the automagic addition of a SCSI
controller attempt during virDomainHostdevAssignAddress; however,
the logic to determine where to place the next_unit depended upon
the "new" controller being added.  Without the new controller the
the next time through the call for the next SCSI hostdev found
would result in the "next_unit" never changing from 0 (zero) and
as a result the addition of the device will fail due to being a
duplicate unit number of the first with the error message:

  virDomainDefCheckDuplicateDriveAddresses:$line : unsupported
      configuration: SCSI host address controller='0' bus='1'
      target='0' unit='0' in use by another SCSI host device

So instead of walking the controller list looking for SCSI
controllers, all we can do is "pretend" that they exist and
allow other code to create them later as necessary.
2018-01-04 10:30:43 -05:00
John Ferlan
c52dbafe9f conf: Use existing SCSI hostdev model to create new
In virDomainDefMaybeAddHostdevSCSIcontroller when we add a new
controller because someone neglected to add one or we're adding
one because the existing one is full, we should copy over the
model number from the existing controller since whatever we
create should at least have the same characteristics as the one
we cannot use because it's full.

NB: This affects the existing hostdev-scsi-autogen-address test
which would add a default ('lsi') SCSI controller for the various
scsi_host's that would create a controller for the hostdev.
2018-01-04 10:30:43 -05:00
John Ferlan
07beea6ca2 qemu: Use same model when adding hostdev SCSI controller
When qemuDomainFindOrCreateSCSIDiskController adds a controller,
let's use the same model as a currently found controller under the
assumption that the reason to add the controller in hotplug is
because virDomainHostdevAssignAddress determined that there were
too many devices on the existing controller, but only assigned a
new controller index and did not add a new controller and we
desire to use the same controller model as any existing controller
and not take a chance that qemuDomainSetSCSIControllerModel would
use a default that may be incompatible.
2018-01-04 10:30:43 -05:00
Pavel Hrdina
fae22fced4 rpc: remove redundant logic
Introduced by commit <0eaa59dce1>.  That comparison already returns
true or false.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-04 14:22:49 +01:00
John Ferlan
9f0ae0b18e nodedev: Move device enumumeration out of nodeStateInitialize
Let's move the udevEnumerateDevices into a thread to "speed
up" the initialization process. If the enumeration fails we
can set the Quit flag to ensure that udevEventHandleCallback
will not run.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2018-01-04 07:13:55 -05:00
Marc Hartmayer
68cdad8785 rpc: Replace virNetServerClientNeedAuth with virNetServerClientIsAuthenticated
Replace virNetServerClientNeedAuth with
virNetServerClientIsAuthenticated because it makes it clearer what it
means.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: Stefan Zimmermann <stzi@linux.vnet.ibm.com>
2018-01-04 06:55:31 -05:00
Marc Hartmayer
4f6a654e95 rpc: Remove virNetServerClientNeedAuthLocked
'Squash' virNetServerClientNeedAuthLocked into
virNetServerClientNeedAuth and remove virNetServerClientNeedAuthLocked
as it's not longer needed.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: Stefan Zimmermann <stzi@linux.vnet.ibm.com>
2018-01-04 06:55:31 -05:00
Marc Hartmayer
94bbbcee1f rpc: virnetserver: Fix race on srv->nclients_unauth
There is a race between virNetServerProcessClients (main thread) and
remoteDispatchAuthList/remoteDispatchAuthPolkit/remoteSASLFinish (worker
thread) that can lead to decrementing srv->nclients_unauth when it's
zero. Since virNetServerCheckLimits relies on the value
srv->nclients_unauth the underrun causes libvirtd to stop accepting
new connections forever.

Example race scenario (assuming libvirtd is using policykit and the
client is privileged):
  1. The client calls the RPC remoteDispatchAuthList =>
     remoteDispatchAuthList is executed on a worker thread (Thread
     T1). We're assuming now the execution stops for some time before
     the line 'virNetServerClientSetAuth(client, 0)'
  2. The client closes the connection irregularly. This causes the
     event loop to wake up and virNetServerProcessClient to be
     called (on the main thread T0). During the
     virNetServerProcessClients the srv lock is hold. The condition
     virNetServerClientNeedAuth(client) will be checked and as the
     authentication is not finished right now
     virNetServerTrackCompletedAuthLocked(srv) will be called =>
     --srv->nclients_unauth => 0
  3. The Thread T1 continues, marks the client as authenticated, and
     calls virNetServerTrackCompletedAuthLocked(srv) =>
     --srv->nclients_unauth => --0 => wrap around as nclient_unauth is
     unsigned
  4. virNetServerCheckLimits(srv) will disable the services forever

To fix it, add an auth_pending field to the client struct so that it
is now possible to determine if the authentication process has already
been handled for this client.

Setting the authentication method to none for the client in
virNetServerProcessClients is not a proper way to indicate that the
counter has been decremented, as this would imply that the client is
authenticated.

Additionally, adjust the existing test cases for this new field.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
2018-01-04 06:55:31 -05:00
Marc Hartmayer
f1d8251972 rpc: Introduce virNetServerSetClientAuthenticated
Combine virNetServerClientSetAuth(client,
VIR_NET_SERVER_SERVICE_AUTH_NONE) and virNetServerTrackCompletedAuth
into one new function named virNetServerSetClientAuthenticated.

After using this new function the function
virNetServerTrackCompletedAuth was superfluous and is therefore
removed. In addition, it is not very common that a
'{{function}}' (virNetServerTrackCompletedAuth) does more than just
the locking compared to
'{{function}}Locked' (virNetServerTrackCompletedAuthLocked).

virNetServerTrackPendingAuth was already superfluous and therefore
it's also removed.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: Stefan Zimmermann <stzi@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-01-04 06:55:31 -05:00
Marc Hartmayer
0eaa59dce1 rpc: Correct locking and simplify the function
The lock for @client must not only be held for the duration of
checking whether the client wants to close, but also for as long as
we're closing the client. The same applies to the tracking of
authentications.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
2018-01-04 06:55:31 -05:00
Marc Hartmayer
be680bed4a rpc: Refactor the condition whether a client needs authentication
Add virNetServerClientAuthMethodImpliesAuthenticated() for deciding
whether a authentication method implies that a client is automatically
authenticated or not. Use this new function in
virNetServerClientNeedAuthLocked().

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: Stefan Zimmermann <stzi@linux.vnet.ibm.com>
2018-01-04 06:55:31 -05:00
Marc Hartmayer
c10103e941 rpc: First test if authentication is required
This makes the code more efficient.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: Stefan Zimmermann <stzi@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-01-04 06:55:31 -05:00
Marc Hartmayer
ee8bb0511d rpc: Be more precise in which cases the authentication is needed and introduce *Locked
Be more precise in which cases the authentication is needed and
introduce *Locked.

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>
Reviewed-by: Stefan Zimmermann <stzi@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-01-04 06:55:31 -05:00
Marc Hartmayer
6e7e553180 rpc: Add typedef for the anonymous enum used for authentication methods
Add typedef for the anonymous enum used for the authentication methods
and remove the default case. This allows the usage of the type in a
switch statement and taking advantage of the compilers feature to
detect uncovered cases.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: Stefan Zimmermann <stzi@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-01-04 06:55:31 -05:00
Marc Hartmayer
125f7d9e10 rpc: Remove duplicate declaration of virNetServerAddClient
Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: Stefan Zimmermann <stzi@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-01-04 06:55:31 -05:00
Eduardo Habkost
9a22251bbe qemu_cgroup: Fix 'rc' argument on virDomainAuditCgroupPath() calls
All calls to virDomainAuditCgroupPath() were passing 'rc == 0' as
argument, when it was supposed to pass the 'rc' value directly.

As a consequence, the audit events that were supposed to be
logged (actual cgroup changes) were never being logged, and bogus
audit events were logged when using regular files as disk image.

Fix all calls to use the return value of
virCgroup{Allow,Deny}Device*() directly as the 'rc' argument.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-01-04 10:50:38 +01:00
Julio Faracco
d0307a9a76 storage: Fixing missing 'backingStore' tag from volume XML dumps.
After commit a693fdb 'vol-dumpxml' missed the ability to show backingStore
information. This commit adds a volume type for files that fixes this
problem.

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

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
2018-01-03 16:04:24 +01:00
Michal Privoznik
6534b3c4bb qemuBuildMemPathStr: Forbid memoryBacking/access for non-numa case
https://bugzilla.redhat.com/show_bug.cgi?id=1448149

If a domain has no numa nodes, that means we don't put any
memory-backend-file onto the qemu command line. That in turn
means we can't set access='shared'. Therefore, we should produce
an error instead of ignoring the setting silently.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-01-03 15:53:00 +01:00
Peter Krempa
f10bb3347b qemu: monitor: Decrease logging verbosity
The PROBE macro used in qemuMonitorIOProcess and the VIR_DEBUG message
in qemuMonitorJSONIOProcess create a lot of logging churn when debug
logging is enabled during monitor communication.

The messages logged from the PROBE macro are rather useless since they
are reporting the partial state of receiving the reply from qemu. The
actual full reply is still logged in qemuMonitorJSONIOProcessLine once
the full message is received.
2018-01-03 15:21:30 +01:00
Peter Krempa
f06e488d54 util: probe: Add quiet versions of the "PROBE" macro
PROBE macro adds a logging entry, when used in places seeing a lot of
traffic this can cause a significant slowdown.
2018-01-03 15:21:06 +01:00
Chen Hanxiao
c1a6e2fb43 util: virstring: Tweak a few more descriptions.
There are a few more description-related issues that commit @9026d115
forgot to address.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-03 12:42:53 +01:00
Cédric Bosdonnat
faec195861 lxc: set a hostname based on the container name
Set a transient hostname on containers. The hostname is computed from
the container name, only keeping the valid characters [a-zA-Z0-9-] in it.
This filtering is based on RFC 1123 and allows a digit to start the
hostname.
2018-01-03 10:58:16 +01:00
Cédric Bosdonnat
b475a91b77 Add virStringFilterChars() string utility
Add a function to filter a string based on a list of valid characters.
2018-01-03 10:58:16 +01:00
Chen Hanxiao
9026d1152c util: fix the description of virStringSearch
There's no argument named @result, use @matches instead.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
Signed-off-by: Erik Skultety <eskultet@redhat.com>
2018-01-03 09:54:14 +01:00
Michal Privoznik
4ce06ba6f4 src: Export virDomainMemoryAccessType*String
These are already exported at header file level because of
VIR_ENUM_DECL being in numa_conf.h. However, they are not being
exported at object level because of missing libvirt_private.syms
record.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-01-03 07:02:15 +01:00
Andrea Bolognani
a38aa340fe qemu: Enforce vCPU hotplug granularity constraints
QEMU 2.7 and newer don't allow guests to start unless the initial
vCPUs count is a multiple of the vCPU hotplug granularity, so
validate it and report an error if needed.

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

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2018-01-02 14:22:06 +01:00
Andrea Bolognani
54acfac4a5 qemu: Invert condition nesting in qemuDomainDefValidate()
While at the moment we're only performing a single check that is
connected to vCPU hotplugging, we're going to introduce a second
one soon. Move the topology check underneath the capability check
to make that easier; since, after this change, the 'topologycpus'
variable doesn't need to have function scope, we move its
declaration to the inner scope as well.

The comments around the check are modified in order to explain
the different QEMU versions involved.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2018-01-02 14:22:05 +01:00
Pavel Hrdina
bbf6573e94 conf: honor maxnames in nodeListDevices API
Introduced by commit <4ae9dbea99c>.

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-01-02 10:28:09 +01:00
John Ferlan
715b321da1 qemu: Move TCP and haveTLS checks into qemuDomainDelChardevTLSObjects
Similar to qemuDomainAddChardevTLSObjects let's move the chardev
source must be TCP and it has the @haveTLS flag set checks before
trying to delete the TLS objects.

For the Chr device this represents no change; however, for RNG device
this is an additionaly check that was missed in commit id '68808516'.
Before adding the objects, TCP and haveTLS are checked.
2017-12-21 10:05:31 -05:00
John Ferlan
10dcdfa32a qemu: Introduce qemuDomainDelChardevTLSObjects
Let's make a comment deletion helper similar to the Add helper
that can be called after the ExitMonitor.

The modify qemuDomainRemoveChrDevice and qemuDomainRemoveRNGDevice
to call the helper instead of inlining the copy and pasted code.
2017-12-21 10:05:31 -05:00
Cédric Bosdonnat
2089ab2112 netserver: close clients before stopping all drivers
So far clients were closed when disposing the daemon, after the state
driver cleanup. This was leading to libvirtd crashing at shutdown due
to missing driver.

Moving the client close in virNetServerClose() fixes the problem.

Reviewed-by: Erik Skultety <eskultet@redhat.com>
2017-12-21 13:17:26 +01:00
Erik Skultety
a8582e3656 admin: Use the connection to determine a client is connected readonly
Prior to this change, we relied solely on the inherited readonly
attribute of a service's socket. This only worked for our UNIX sockets
(and only to some degree), but doesn't work for TCP sockets which are RW
by default, but such connections support RO as well. This patch forces
an update on the client object once we have established a connection to
reflect the nature of the connection itself rather than relying on the
underlying socket's attributes.
Clients connected to the admin server have always been connected as RW
only.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1524399
Signed-off-by: Erik Skultety <eskultet@redhat.com>
2017-12-18 08:42:29 +01:00
Jim Fehlig
69ed99c786 libxl: mark domain0 as persistent
A Xen domain0 is better described as a persistent domain. Mark it
as such during intialization.
2017-12-15 15:25:01 -07:00
Laine Stump
16a9a28129 qemu: log error on attempts to set filterref on an OVS-connected interface
ebtables/iptables processing is skipped for any interface connected to
Open vSwitch (they have their own packet filtering), likewise for
midonet (according to
http://blog.midokura.com/2016/04/midonet-rule-chains), but libvirt
would allow adding a <filterref> to interfaces connected in these
ways, so the user might mistakenly believe they were being protected.

This patch checks for a non-NULL <virtualport> element for an
interface (or its network) and logs an error if <virtualport> and
<filterref> are both present. This could cause some previously working
domains to no longer start, but that's really the whole point of this
patch - to warn people that their filterref isn't protecting them as
they might have thought.

I don't bother checking this during post-parse validation, because
such a check would be incomplete - it's possible that a network would
have a <virtualport> that would be applied to an interface, and you
can't know that until the domain is started.

Resolves: https://bugzilla.redhat.com/1502754
2017-12-14 14:31:28 -05:00
Laine Stump
b21163bd11 qemu: delete exist bandwidth restrictions when they are removed from config
When the <bandwidth> of an interface is changed with update-device,
the old settings are cleared with tc, then new settings added with
tc. But if the <bandwidth has been removed, the old settings weren't
being removed, so the bandwidth restrictions would still be active on
the interface although the interface status in libvirt showed that
they had been removed.

This patch fixes it by calling virNetDevBandwidthClear() if the
"modification" to the interface bandwidth was to completely clear
it.

An alternative could have been to modify virNetDevBandwidthSet() to
always clear existing bandwith settings at the beginning of the
function (currently it short circuits in that case, doing nothing),
but that would have led to cases where virNetDevBandwidthClear() was
now being called in cases where it previously wasn't, and while many
of those cases would be NOPs, there could be cases where it would
cause an error. The way this patch works, the ...Clear() function is
only called in cases where the ...Set() function had previously been
called successfully, so the risk of regression is minimized.

  Resolves: https://bugzilla.redhat.com/1454709
2017-12-14 13:52:34 -05:00
Ján Tomko
8d51042ef8 qemu: remove input device after receiving the event
Also call qemuDomainRemoveInputDevice if we receive the
event after the Detach API ends.

Commit 67486bb failed to include this.

https://bugzilla.redhat.com/show_bug.cgi?id=1524837
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2017-12-14 16:36:03 +01:00
Peter Krempa
b3d0270c44 qemu: domain: Parse and format relPath into disk source private data
Register the helpers directly to format and parse the data.

https://bugzilla.redhat.com/show_bug.cgi?id=1523261
2017-12-14 10:29:10 +01:00
Peter Krempa
cd31709351 util: storage: Add helpers to parse and format relPath into privateData
This will be the first private piece of data that will need to be stored
in the XML for some drivers. Add helpers which will do it.
2017-12-14 10:27:30 +01:00
Peter Krempa
aed3d038a6 conf: Add infrastructure for disk source private data XML
VM drivers may need to store additional private data to the status XML
so that it can be restored after libvirtd restart. Since not everything
is needed add a callback infrastructure, where VM drivers can add only
stuff they need.

Note that the private data is formatted as a <privateData> sub-element
of the <disk> or <backingStore> <source> sub-element. This is done since
storing it out of band (in the VM private data) would require a complex
matching process to allow to put the data into correct place.
2017-12-14 10:24:36 +01:00
John Ferlan
2114154922 util: Report error if vhost-scsi device file cannot be found
https://bugzilla.redhat.com/show_bug.cgi?id=1523564

If the vhost-scsi device file cannot be found, the generic error

    "error: An error occurred, but the cause is unknown"

is returned.  Let's add a real error message to make it clear
why the failure occurred.
2017-12-13 15:37:30 -05:00
John Ferlan
9e030093f2 util: Fix error path in virSCSIVHostOpenVhostSCSI
We cannot be sure someone initialized the passed *vhostfd and we
certainly don't want or need to be calling VIR_FORCE_CLOSE on what
probably is -1. So let's just return -1 immediately.
2017-12-13 15:37:30 -05:00
John Ferlan
10c73bf18a qemu: Need to assign PCI address to vhost-scsi
Commit id '70249927b' neglected to cover this case because the test
had taken the "shortcut" to already add the <address>; however, when
the PCI address assignment code was adjusted by commit id '70249927'
the vhost-scsi (VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST) wasn't
covered thus returning a 0 for pciFlags. So I altered the tests too
to make sure it doesn't happen again.

Previously the qemuxml2xmloutdata was a softlink to the source
qemuxml2argvdata, so I unlinked and recreated the output file to
force generation of the adddress. Without the test changes, an
address generation returns:

    libvirt: Domain Config error : internal error: Cannot automatically
    add a new PCI bus for a device with connect flags 00

if an address was supplied in the test, a restart of libvirtd or
edit of a guest would display the following opaque message:

    warning : qemuDomainCollectPCIAddress:1237 :
    qemuDomainDeviceCalculatePCIConnectFlags() thinks that the device
     with PCI address 0000:00:09.0 should not have a PCI address

where the address is related to the guest PCI address provided.
2017-12-13 15:37:30 -05:00
Marek Marczykowski-Górecki
9f8778dfca xenconfig: fix issue found by coverity in multiple IP support
virStringSplit may return NULL, so we must handle that.

Cc: John Ferlan <jferlan@redhat.com>
Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
2017-12-13 15:31:55 -05:00
Marek Marczykowski-Górecki
a609389310 xenconfig: Remove unnecessary variable clear in xenMakeIPList
Remove the unnecessary clearing of address_array as VIR_ALLOC_N
initialized the array already.

Cc: John Ferlan <jferlan@redhat.com>
Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
2017-12-13 15:31:51 -05:00
John Ferlan
6050affb7f qemu: Tolerate storage source private data being NULL for hotplug SCSI hostdev
Commit id 'c5c96545' neglected to validate that the srcPriv was
non-NULL before dereferencing. Similar problem to what was fixed
by commit id '8056721c' but missed during multiple rebases and
code reworks.
2017-12-13 15:16:15 -05:00
John Ferlan
052ecaee3a storage: Reduce need for using storageDriverLock
Now that the storage pools are self locking, we can reduce the number
of places that need to take the big hammer storage driver lock
2017-12-13 15:06:42 -05:00
John Ferlan
4b2e0ed6e3 storage: Convert virStoragePoolObjList to use virObjectRWLockable
Now that we have a private storage pool list, we can take the next
step and convert to using objects. In this case, we're going to use
RWLockable objects (just like every other driver) with two hash
tables for lookup by UUID or Name.

Along the way the ForEach and Search API's will be adjusted to use
the related Hash API's and the various FindBy functions altered and
augmented to allow for HashLookup w/ and w/o the pool lock already
taken.

After virStoragePoolObjRemove we will need to virObjectUnref(obj)
after to indicate the caller is "done" with it's reference. The
Unlock occurs during the Remove.

The NumOf, GetNames, and Export functions all have their own callback
functions to return the required data and the FindDuplicate code
can use the HashSearch function callbacks.
2017-12-13 15:05:10 -05:00
John Ferlan
90e65353a2 storage: Privatize virStoragePoolObjListPtr
Move the structure into virstorageobj.c.

Use the virStoragePoolObjListNew allocator to fill in the @pools for
the storage driver and test driver.
2017-12-13 14:51:30 -05:00
John Ferlan
d4f80d439e storage: Fix path check in storagePoolLookupByTargetPath
Commit id '5ab746b8' introduced the function as perhaps a copy
of storageVolLookupByPath; however, it did not use the @cleanpath
variable even though it used the virFileSanitizePath. So in essance
the only "check" being done for failure is whether it was possible
to strdup the path.

Looking at the virStoragePoolDefParseXML one will note that the
target.path is stored using the result of virFileSanitizePath.
Therefore, this function should sanitize and use the input @path
for the argument to storagePoolLookupByTargetPathCallback which
is comparing against stored target.path values.

Additionally, if there was an error we should use the proper error
of VIR_ERR_NO_STORAGE_POOL (instead of VIR_ERR_NO_STORAGE_VOL).
2017-12-13 14:51:30 -05:00
Marc Hartmayer
4199c2f221 audit: Log only an info message if audit_level < 2 and audit is not supported
Replace the error message during startup of libvirtd with an info
message if audit_level < 2 and audit is not supported by the
kernel. Audit is not supported by the current kernel if the kernel
does not have audit compiled in or if audit is disabled (e.g. by the
kernel cmdline).

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-12-13 13:42:16 +01:00
Daniel P. Berrange
917047de61 Update to latest keycodemapdb content
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-12-12 16:34:12 +00:00
Michal Privoznik
34fb67efae xenMakeIPList: Don't leak @address_array
==32171== 32 bytes in 1 blocks are definitely lost in loss record 44 of 107
==32171==    at 0x4C2DEF6: calloc (vg_replace_malloc.c:711)
==32171==    by 0x55744A9: virAllocN (viralloc.c:191)
==32171==    by 0x12CED2: xenMakeIPList (xen_common.c:1186)
==32171==    by 0x12D0BE: xenFormatNet (xen_common.c:1221)
==32171==    by 0x12F0D2: xenFormatVif (xen_common.c:1889)
==32171==    by 0x12F2B4: xenFormatConfigCommon (xen_common.c:1944)
==32171==    by 0x13BA32: xenFormatXL (xen_xl.c:1971)
==32171==    by 0x1186CA: testCompareParseXML (xlconfigtest.c:105)
==32171==    by 0x118A64: testCompareHelper (xlconfigtest.c:205)
==32171==    by 0x119E36: virTestRun (testutils.c:180)
==32171==    by 0x11970E: mymain (xlconfigtest.c:301)
==32171==    by 0x11BEE3: virTestMain (testutils.c:1119)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-12-12 16:41:20 +01:00
Michal Privoznik
747faf1149 xenParseXLVnuma: Don't leak @tmp and @token
==30399== 180 (144 direct, 36 indirect) bytes in 3 blocks are definitely lost in loss record 91 of 111
==30399==    at 0x4C2E0FF: realloc (vg_replace_malloc.c:785)
==30399==    by 0x5574572: virReallocN (viralloc.c:245)
==30399==    by 0x5574668: virExpandN (viralloc.c:294)
==30399==    by 0x55747AB: virResizeN (viralloc.c:352)
==30399==    by 0x560074D: virStringSplitCount (virstring.c:115)
==30399==    by 0x137A59: xenParseXLVnuma (xen_xl.c:442)
==30399==    by 0x13952B: xenParseXL (xen_xl.c:1064)
==30399==    by 0x11884D: testCompareFormatXML (xlconfigtest.c:152)
==30399==    by 0x118A87: testCompareHelper (xlconfigtest.c:207)
==30399==    by 0x119E36: virTestRun (testutils.c:180)
==30399==    by 0x119186: mymain (xlconfigtest.c:274)
==30399==    by 0x11BEE3: virTestMain (testutils.c:1119)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-12-12 16:41:01 +01:00
Yuri Chornoivan
ca18914e8a Fix minor typos 2017-12-12 09:13:43 +01:00
Jiri Denemark
fd754cb69c qemu: Avoid comparing size_t with -1
ncpus would be -1 on error and the cleanup for loop would not be skipped
in this case.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-12-11 14:56:22 +01:00
Michal Privoznik
3446750bab qemuDomainUndefineFlags: Fix error message
https://bugzilla.redhat.com/show_bug.cgi?id=1522706

If domain is active, but the undefine API was called without the
VIR_DOMAIN_UNDEFINE_KEEP_NVRAM flag set, the following incorrect
error message is produced:

error: Requested operation is not valid: cannot delete inactive domain with nvram

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-12-11 13:23:30 +01:00
Lin Ma
07adbd4b1f qemu: Introduce qemuDomainDeviceDefValidateControllerIDE
Move the IDE controller check from command line building to
controller def validation. Also explicitly include the avoidance
check for the implicit IDE controller from qemuBuildSkipController.

Cause the IDE case for command line building to generate a
failure if called to add an IDE since that shouldn't happen
if the Validate code did the right thing.
2017-12-09 11:16:58 -05:00
John Ferlan
29d8c17b98 qemu: Move CCW S390 Address check to controller def validate
Move the call to qemuDomainCheckCCWS390AddressSupport from
qemuBuildControllerDevStr to qemuDomainDeviceDefValidateController.

This means we will get the qemuCaps from the driver opaque
variable passed to qemuDomainDeviceDefValidate.
2017-12-09 11:16:58 -05:00
John Ferlan
3ba921869a qemu: Introduce qemuDomainDeviceDefValidateController
Introduce the bare bones helper to validate whether the controller
definition is valid.
2017-12-09 11:16:58 -05:00
John Ferlan
ac0fb44afa qemu: Introduce qemuBuildSkipController
Move the non USB implicit controller checks into their own
helper to reduce the cruft in qemuBuildControllerDevCommandLine.
2017-12-09 11:16:58 -05:00
Marek Marczykowski-Górecki
a861054fc7 xenconfig: add support for multiple IP addresses
Xen's xl config format has long supported specifying multiple IP
addresses for virtual interfaces. E.g.

vif = [ "ip=10.0.0.1 10.1.1.1 2000::1, ..." ]

Add support for converting multiple IP addresses to/from domXML.

Reviewed-by: Jim Fehlig <jfehlig@suse.com>
2017-12-08 14:04:13 -07:00
Marek Marczykowski-Górecki
82ef04fe79 libxl: add support for multiple IP addresses
vif-* scripts support it for a long time, and expect addresses to be
separated by spaces. Add appropriate support to libxl driver.

Reviewed-by: Jim Fehlig <jfehlig@suse.com>
2017-12-08 13:55:07 -07:00
Jiri Denemark
ce73de441d qemu: Make sure host-model uses CPU model supported by QEMU
When reconnecting to a running domain started by old libvirt, which did
not change host-model into a custom CPU definition, we replace the CPU
definition with a specific CPU model from host capabilities. However,
that CPU model may not be supported by the running qemu process. We need
to translate the CPU model to one of the models which libvirt could have
used when starting the domain.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-12-08 15:50:52 +01:00
Jiri Denemark
4486dcdb4a qemu: Separate fetching CPU definitions from filling qemuCaps
virQEMUCapsProbeQMPCPUDefinitions is now a small wrapper which fills in
qemuCaps with CPU models fetched by virQEMUCapsFetchCPUDefinitions.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-12-08 15:50:52 +01:00
Peter Krempa
fac8724ceb qemu: blockjob: Reset disk source index after pivot
Since we are re-detecting the backing chain after pivoting to the active
block commit target (or block copy target) the disk index needs to be
reset to 0. This is necessary since we move a member of the backing
chain to disk->src but clear indexes only starting from
disk->src->backingStore. The freshly detected images have indexes
starting from 1, but since we've pivoted into an image which was
previously a backing store it would have a non-0 index.
The lookup function would then return the top of the chain for queries
like 'vda[1]' instead of the first backing store.

This problem will not be present once we keep the disk indexes stable.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1519745
2017-12-08 10:13:57 +01:00
Ján Tomko
e2ad8e5993 qemuDomainNamespaceSetupDisk: initialize npaths
Introduced by commit d3db304.

Reported-by: John Ferlan <jferlan@redhat.com>
2017-12-07 14:36:02 +01:00
Chen Hanxiao
c416a20db1 virerror: mark VIR_ERR_AGENT_UNSYNCED as DEPRECATED
Since commit 5e5019bf, we've no longer use
VIR_ERR_AGENT_UNSYNCED anymore.
Mark it as DEPRECATED.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-12-07 14:30:20 +01:00
Peter Krempa
2d07f1f0eb storage: Don't dereference driver object if virStorageSource is not initialized
virStorageFileReportBrokenChain uses data from the driver private data
pointer to print the user and group. This would lead to a crash in call
paths where we did not initialize the storage backend as recently added
in commit 24e47ee2b9 to qemuDomainDetermineDiskChain.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1522682
2017-12-07 13:03:09 +01:00
John Ferlan
cc9d272478 qemu: Use virDomainControllerType in qemuBuildControllerDevStr switch
Make sure all types of virDomainControllerType are handled in the
switch statement.
2017-12-06 19:50:11 -05:00
Ján Tomko
a6f7c1b04c Do not pass driver to qemuDomainNamespace{Setup,Teardown} functions
The underlying function which needs the driver gets it from the
passed virDomainObj object anyway.
2017-12-06 16:47:08 +01:00
Ján Tomko
c317328976 Introduce qemuDomainNamespaceUnlinkPath
Use it in every qemuDomainNamespaceTeardown* function that only
wants to unlink one device.
2017-12-06 16:47:08 +01:00
Ján Tomko
7a931a4204 Introduce qemuDomainNamespaceUnlinkPaths
Split out the logic of unlinking devices from
qemuDomainNamespaceTeardownHostdev for reuse in other functions.
2017-12-06 16:47:05 +01:00
Ján Tomko
323b9f72ef Introduce qemuDomainNamespaceMknodPath
Use this function in qemuDomainNamespaceSetup* functions which
only require creating one device.
2017-12-06 15:21:49 +01:00
Ján Tomko
d3db304d2e Introduce qemuDomainNamespaceMknodPaths
Separate the logic of creating devices from their gathering.

Use this new function in qemuDomainNamespaceSetupHostdev and
qemuDomainNamespaceSetupDisk.
2017-12-06 15:21:49 +01:00
Ján Tomko
bc50c99edf qemuDomainNamespaceSetupHostdev: rename path to paths
To match the "things/nthings" pattern used in virDomainDef.
2017-12-06 15:21:49 +01:00
Ján Tomko
be97d8496a qemuDomainNamespaceTeardownHostdev: rename path to paths
To match the "things/nthings" pattern used in virDomainDef.
2017-12-06 15:21:49 +01:00
Nikolay Shirokovskiy
5b0451ab57 qemu: report drive mirror errors on migration
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-12-06 12:43:57 +01:00
Nikolay Shirokovskiy
bc444666f7 qemu: prepare blockjob complete event error usage
This patch pass event error up to the place where we can
use it. Error is passed only for sync blockjob event mode
as we can't use the error in async mode. In async mode we
just pass the event details to the client thru event API
but current blockjob event API can not carry extra parameter.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-12-06 12:43:57 +01:00
Daniel P. Berrange
7993554f70 nwfilter: don't crash listing filters in unprivileged daemon
The unprivileged libvirtd does not support nwfilter config, by leaves the
driver active. It is supposed to result in all APIs being an effective
no-op, but several APIs rely on driver->nwfilters being non-NULL, or they
will reference a NULL pointer. Rather than adding checks for NULL in many
places, just make sure  driver->nwfilters is always initialized.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-12-06 09:37:25 +00:00
Pavel Hrdina
1c57eea362 qemu: fix security labeling for attach/detach of char devices
Commit e93d844b90 was not enough to fix the permission denied
issue.  We need to apply security labels as well.

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-12-05 13:54:48 +01:00
Pavel Hrdina
1b4f66ec80 security: introduce virSecurityManager(Set|Restore)ChardevLabel
SELinux and DAC drivers already have both functions but they were not
exported as public API of security manager.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-12-05 13:54:48 +01:00
Andrea Bolognani
77117e18b7 util: gettid() is Linux-specific
The manual page clearly states that

  gettid() is Linux-specific and should not be used in programs
  that are intended to be portable.

Unfortunately, it looks like macOS implemented the functionality
and defined SYS_gettid accordingly, only to deprecate syscall()
altogether with 10.12 (Sierra), released last late year.

To avoid compilation errors, call gettid() on Linux only.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
2017-12-05 11:28:19 +01:00
John Ferlan
9f0ccc717b conf: Fix memory leak for distances in virDomainNumaFree
Commit id '74119a03f' neglected to clean up @distances when
the numa definition is cleaned up.
2017-12-01 06:28:24 -05:00
John Ferlan
ac6cc1d822 conf: Clean up virDomainNumaDefCPUFormatXML
Don't use a unary comparison for an int value - compare against zero
directly instead.
2017-12-01 06:28:24 -05:00
John Ferlan
742494eed8 conf: Clean up virDomainNumaDefNodeDistanceParseXML
Clean up the style a bit w/r/t to not using a unary operator on an
integer value that could be zero - compare vs. zero instead.

Set the def->mem_nodes[*].distances to rdist or ldist inside the
if condition - no need to set outside since the value being set
to is what was fetched.

During cleanup, be sure to initialize the ndistances on error and
use the < 0 comparison not the unary one.
2017-12-01 06:28:24 -05:00
Michal Privoznik
3eb840904a qemuStateInitialize: Don't leak @memoryBackingPath
==899== 39 bytes in 1 blocks are definitely lost in loss record 732 of 1,003
==899==    at 0x4C2AEDF: malloc (vg_replace_malloc.c:299)
==899==    by 0x8B68CE7: vasprintf (in /lib64/libc-2.25.so)
==899==    by 0x55498D2: virVasprintfInternal (virstring.c:708)
==899==    by 0x55499E7: virAsprintfInternal (virstring.c:729)
==899==    by 0x2BECFFF0: qemuGetMemoryBackingBasePath (qemu_conf.c:1757)
==899==    by 0x2BF23225: qemuStateInitialize (qemu_driver.c:893)
==899==    by 0x563073D: virStateInitialize (libvirt.c:770)
==899==    by 0x124CC4: daemonRunStateInit (libvirtd.c:834)
==899==    by 0x55521CD: virThreadHelper (virthread.c:206)
==899==    by 0x88D9686: start_thread (in /lib64/libpthread-2.25.so)
==899==    by 0x8BEAEFE: clone (in /lib64/libc-2.25.so)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-12-01 10:06:19 +01:00
Michal Privoznik
0fd85b98ae virDomainDiskBackingStoreParse: Don't leak @idx
==1277== 8 bytes in 4 blocks are definitely lost in loss record 39 of 131
==1277==    at 0x4C2AEDF: malloc (vg_replace_malloc.c:299)
==1277==    by 0x68BBBC8: xmlStrndup (in /usr/lib64/libxml2.so.2.9.4)
==1277==    by 0x53B1DC2: virXMLPropString (virxml.c:510)
==1277==    by 0x53D696A: virDomainDiskBackingStoreParse (domain_conf.c:8639)
==1277==    by 0x53DA684: virDomainDiskDefParseXML (domain_conf.c:9590)
==1277==    by 0x53F619F: virDomainDefParseXML (domain_conf.c:19233)
==1277==    by 0x53F96EE: virDomainDefParseNode (domain_conf.c:20083)
==1277==    by 0x53F9540: virDomainDefParse (domain_conf.c:20027)
==1277==    by 0x53F95E6: virDomainDefParseFile (domain_conf.c:20053)
==1277==    by 0x44D1D4: testCompareDomXML2XMLFiles (testutils.c:1265)
==1277==    by 0x42FC7C: testXML2XMLActive (qemuxml2xmltest.c:71)
==1277==    by 0x44AD20: virTestRun (testutils.c:180)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-12-01 10:06:03 +01:00
Michal Privoznik
7d7c01b458 virDomainDiskSourceNetworkParse: Don't leak @tlsCfg or @haveTLS
==861== 3 bytes in 1 blocks are definitely lost in loss record 3 of 168
==861==    at 0x4C2AEDF: malloc (vg_replace_malloc.c:299)
==861==    by 0x8C7FBC8: xmlStrndup (in /usr/lib64/libxml2.so.2.9.4)
==861==    by 0x5DCCDC2: virXMLPropString (virxml.c:510)
==861==    by 0x5DF1232: virDomainDiskSourceNetworkParse (domain_conf.c:8445)
==861==    by 0x5DF1728: virDomainDiskSourceParse (domain_conf.c:8576)
==861==    by 0x5DF41A5: virDomainDiskDefParseXML (domain_conf.c:9238)
==861==    by 0x5E1119F: virDomainDefParseXML (domain_conf.c:19233)
==861==    by 0x5E146EE: virDomainDefParseNode (domain_conf.c:20083)
==861==    by 0x5E14540: virDomainDefParse (domain_conf.c:20027)
==861==    by 0x5E145E6: virDomainDefParseFile (domain_conf.c:20053)
==861==    by 0x4053CC: testCompareXMLToArgv (qemuxml2argvtest.c:455)
==861==    by 0x41F135: virTestRun (testutils.c:180)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-12-01 10:05:42 +01:00
Peter Krempa
adcc31bb89 qemu: domain: Fix backing store terminator for non-backing local files
Raw local files do not pass through the backing store detector and thus
the code did not allocate the required backing store terminator for
them. Previously the terminating element would be formatted into the XML
since the default values used for the metadata allowed that. This is a
regression since a693fdba01 which was not detected in the review.

This patch also reverts all the changes in the test files.
2017-11-30 22:40:23 +01:00
Peter Krempa
24e47ee2b9 qemu: process: Move handling of non-backing files into qemuDomainDetermineDiskChain
Until now we would skip loading of the backing chain for files which
don't support backing chains only when starting up the VM. Move the
check from qemuProcessPrepareHostStorage with some adaptations so that's
always applied.
2017-11-30 22:40:23 +01:00
Peter Krempa
b19710b9b6 qemu: domain: Refactor control flow in qemuDomainDetermineDiskChain
Split out clearing of the backing chain prior to other code since it
will be required later and optimize few layers of nested conditions and
loops.
2017-11-30 22:40:23 +01:00
Pavel Hrdina
cb06ea57ad conf: fix migratable XML for graphics if socket is generated based on config
The graphics code is complex and there are a lot of exceptions and
backward compatible combinations.  One of them is the possibility
to configure "spice_auto_unix_socket" in qemu.conf which will convert
all spice graphics with listen type "address" without any address
specified to listen type "socket" when the guest is started.

We don't format this generated socket into migratable XML to make
migration work with older libvirt.  However, spice has another
exception that if autoport='no' and there is no port configured
it is converted to listen type "none".  Because of this we need
to format autoport='yes' to make sure that the listen type will
be the same as the offline XML.

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

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-30 17:42:02 +01:00
Ján Tomko
65108d94d0 virQEMUCapsHasPCIMultiBus: assume true if we have no version information
In status XML, we do not store the QEMU version information, we only
format all the capabilities. We dropped QEMU_CAPS_PCI_MULTIBUS
in commit 5b783379 which was released in libvirt 3.2.0.

Therefore the only way of telling if the already running domain
at the time of daemon restart has been started with a QEMU that does
use 'pci.0' or not on PPC is to look at the pci-root controller's
alias. This is not an option if the domain has a user-specified alias
for the pci-root.

Instead of reintroducing the capability, assume 'pci.0' when we have
no version information. That way the only left broken use case would
be the combination of user aliases and very old QEMU.

Partially reverts commit 3a37af1e4.

https://bugzilla.redhat.com/show_bug.cgi?id=1518148
2017-11-30 16:49:05 +01:00
Ján Tomko
fdf354fb51 virQEMUCapsHasPCIMultiBus: use def->os.arch
We do not fill out qemuCaps->arch when parsing status XML.

Use def->os.arch like we do for PPC.

This fixes hotplug after daemon restart for domains that use
a user alias for the implicit pci-root on x86.

https://bugzilla.redhat.com/show_bug.cgi?id=1518148
2017-11-30 16:49:05 +01:00
Ján Tomko
dacfc6b10b qemu: prefer the PCI bus alias from status XML
For some corner cases, virQEMUCapsHasPCIMultiBus depends on the QEMU
version, which is by design not stored in the status XML and therefore
it cannot be fixed for all existing running domains.

Prefer the controller alias read from the status XML when formatting
PCI addresses and only fall back to using virQEMUCapsHasPCIMultiBus
if the alias is a user alias.

This fixes hotplug after daemon restart for domains not using user
aliases.

Partially reverts commit 937f3195.

https://bugzilla.redhat.com/show_bug.cgi?id=1518148
2017-11-30 16:49:05 +01:00
Ján Tomko
309cd46b40 Introduce virDomainDeviceAliasIsUserAlias
Allow parts of code outside domain_conf to decide whether the alias
is user-specified or not.
2017-11-30 16:48:58 +01:00
Boris Fiuczynski
681bc423e8 qemu-capabilities: Adjust function header comments of virQEMUCapsInitCPUModel*
Adjust function descriptions of virQEMUCapsInitCPUModelS390 and
virQEMUCapsInitCPUModel to the changes introduced with
commitID 74fc32a955.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-11-29 17:40:31 +01:00
Andrea Bolognani
b2fb483c34 qemu: Require QEMU_CAPS_DEVICE_PL011 for pl011
Even though we never format the device on the QEMU command line,
as it's a platform serial device that's not user-instantiable,
we should still make sure it's available before using it.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:58:41 +01:00
Andrea Bolognani
a45ecb7bf6 qemu: Add QEMU_CAPS_DEVICE_PL011
All serial devices shoule have an associated capability.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:58:37 +01:00
Andrea Bolognani
b9be657b68 qemu: Require QEMU_CAPS_DEVICE_ISA_SERIAL for isa-serial
We should make sure the isa-serial device is available before
formatting it on the QEMU command line.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:58:35 +01:00
Andrea Bolognani
b0f1c291a0 qemu: Add QEMU_CAPS_DEVICE_ISA_SERIAL
All serial devices shoule have an associated capability.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:51:33 +01:00
Pino Toscano
220c1f70dc qemu: switch s390/s390x default console back to serial
Now that <serial> and <console> on s390/s390x behave a bit more like the
other architectures, remove this extra differentation, and use sclp
console by default for new guests.  New virtio consoles can still be
added, and it is actually needed because of the limited number of
instances for sclp and sclplm.

This reverts commit b1c88c1476, whose
reasons are not totally clear.

Signed-off-by: Pino Toscano <ptoscano@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
2017-11-28 15:48:59 +01:00
Pino Toscano
21332bf658 conf: add VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SCLP
Introduce specific a target types with two models for the console
devices (sclp and sclplm) used in s390 and s390x guests, so isa-serial
is no more used for them.

This makes <serial> usable on s390 and s390x guests, with at most only
a single sclpconsole and one sclplmconsole devices usable in a single
guest (due to limitations in QEMU, which will enforce already at
runtime).

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

Signed-off-by: Pino Toscano <ptoscano@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:34 +01:00
Andrea Bolognani
eccdcb81fc conf: Add target type and model for pl011
We can finally introduce a specific target model for the pl011 device
used by mach-virt guests, which means isa-serial will no longer show
up to confuse users.

We make sure migration works in both directions by interpreting the
isa-serial target type, or the lack of target type, appropriately
when parsing the guest XML, and skipping the newly-introduced type
when formatting if for migration. We also verify that pl011 is not
used for non-mach-virt guests and add a bunch of test cases.

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

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:34 +01:00
Andrea Bolognani
b342e94399 qemu: Support usb-serial and pci-serial on pSeries
The existing implementation set the address type for all serial
devices to spapr-vio, which made it impossible to use other devices
such as usb-serial and pci-serial; moreover, some decisions were
made based on the address type rather than the device type.

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

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:33 +01:00
Andrea Bolognani
c498a8921e conf: Add target type and model for spapr-vty
We can finally introduce a specific target model for the spapr-vty
device used by pSeries guests, which means isa-serial will no longer
show up to confuse users.

We make sure migration works in both directions by interpreting the
isa-serial target type, or the lack of target type, appropriately
when parsing the guest XML, and skipping the newly-introduced type
when formatting if for migration. We also verify that spapr-vty is
not used for non-pSeries guests and add a bunch of test cases.

This commit is best viewed with 'git show -w'.

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

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:33 +01:00
Andrea Bolognani
fa96d35242 qemu: Remove redundancy in qemuBuildSerialChrDeviceStr()
Instead duplicating the capability check for each possible target
model, introduce a small helper that matches the target model with
the corresponding capability and collapse all existing checks into
a single one.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:33 +01:00
Andrea Bolognani
7c76c30465 qemu: Format targetModel for serial devices
Now that we've created a distinction between target type and target
model, with the latter being the concrete device name, it's time to
switch to formatting the model instead of the type.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:33 +01:00
Andrea Bolognani
a9254a2d6e qemu: Validate target model for serial devices
Target model and target type must agree for the configuration
to make sense, so check that's actually the case and error out
otherwise.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:33 +01:00
Andrea Bolognani
72bf21f233 qemu: Set targetModel based on targetType for serial devices
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:33 +01:00
Andrea Bolognani
5ad9d9afd4 conf: Parse and format virDomainChrSerialTargetModel
This information will be used to select, and store in the guest
configuration in order to guarantee ABI stability, the concrete
(hypervisor-specific) model for serial devices.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:33 +01:00
Andrea Bolognani
9ae116eadf qemu: Improve qemuDomainChrTargetDefValidate()
Instead of validating each target type / address type combination
separately, create a small helper to perform the matching and
collapse all existing checks into a single one.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:33 +01:00
Andrea Bolognani
81e14caf60 qemu: Introduce qemuDomainChrTargetDefValidate()
Instead of waiting until we get to command line generation, we can
validate the target for a char device much earlier.

Move all the checks out of qemuBuildSerialChrDeviceStr() and into
the new fuction. This will later allow us to validate the target
for platform devices.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:32 +01:00
Andrea Bolognani
7983068fa5 conf: Remove ATTRIBUTE_FALLTHROUGH from virDomainChrTargetDefFormat()
Formatting the <target/> element for serial devices will become a
bit more complicated later on, and leaving the fallthrough behavior
there would do nothing but complicate it further.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:32 +01:00
Andrea Bolognani
46084f2aa1 conf: Improve virDomainChrTargetDefFormat()
Make the switch statement type-aware, avoid calling
virDomainChrTargetTypeToString() more than once and check its
return value before using it.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:32 +01:00
Andrea Bolognani
2cd323e382 conf: Check virDomainChrSourceDefFormat() return value
The function can fail, but none of the caller were accounting
for that.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2017-11-28 15:46:32 +01:00