Commit Graph

27706 Commits

Author SHA1 Message Date
Michal Privoznik
6bc4a371cf qemu: Be tolerant to preexisting aliases
In the future, some aliases might be already parsed therefore we
should avoid overwriting them.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-10-19 17:33:27 +02:00
Michal Privoznik
215ab7aa03 qemu: Move device alias assignment to separate functions
Let's move all the virAsprintf()-s into separate functions for
better structure of the code. Later, when somebody wants to
generate a device alias, all they need is to expose the function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-10-19 17:32:50 +02:00
Michal Privoznik
16bb5a710e qemuAssignDeviceAliases: Use qemuAssignDeviceRNGAlias for assigning RNG aliases
We have a special function for assigning aliases to RNG devices.
Use that instead of plain virAsprintf().

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

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-10-19 17:28:56 +02:00
Peter Krempa
05d4323989 qemu: hotplug: Reuse qemuDomainAttachDiskGeneric in qemuDomainAttachUSBMassStorageDevice
Apart from killing a lot of code this also "implements" authentication
and encryption for USB disks.
2017-10-19 15:04:00 +02:00
Peter Krempa
4e6ac368a5 qemu: hotplug: Reuse qemuDomainAttachDiskGeneric in qemuDomainAttachSCSIDisk
Get rid of the first copy of the mess.
2017-10-19 15:02:44 +02:00
Peter Krempa
5b0dc7fdfd qemu: hotplug: extract disk hotplug worker code
This horrible piece of spaghetti code is copy-past(ae)d in the SCSI and
USB disk hotplug code with minimal changes. Extract it for further
reuse.
2017-10-19 15:00:58 +02:00
Peter Krempa
3c437ebf40 qemu: hotplug: Use disk target in debug/warning messages where appropriate
Some messages deal with the disk itself thus using the disk target is
better than using the disk source name which can be NULL in some cases.
2017-10-19 14:50:50 +02:00
Peter Krempa
c01a2e057f qemu: hotplug: Remove wrong check for empty disks
The check if the disk is empty is wrong and would spuriously reject NBD
sources. Remove it.
2017-10-19 14:50:50 +02:00
Peter Krempa
a4bac46c96 qemu: address: Remove dead code when un-reserving PCI address
The code can't fail so having error handling is pointless.
2017-10-19 14:50:50 +02:00
Ján Tomko
537e86f031 fix error message spacing in qemuDomainDetachNetDevice
Move the space after the colon.
2017-10-19 14:46:13 +02:00
Ján Tomko
311f4069f9 qemu: remove pointless address validation on hot unplug
Back in the times of using 'pci_del', unplugging a device without
a PCI address was not wired up.

After completely removing support for qemu without QEMU_CAPS_DEVICE,
aliases are used to uniquely identify devices in all cases.

Remove the pointless validation of data that was already present
in the domain definition.
2017-10-19 14:45:15 +02:00
Ján Tomko
8a0d84e25b qemuIsMultiFunctionDevice: return early for non-PCI addresses
There is no point in iterating over all devices if none of them
could possibly match.
2017-10-19 14:45:15 +02:00
Ján Tomko
67486bb295 qemu: implement input device hotunplug
Allow unplugging USB and virtio USB devices.

https://bugzilla.redhat.com/show_bug.cgi?id=1379603
2017-10-19 14:43:22 +02:00
Ján Tomko
bc9ffafcc7 qemu: implement input device hotplug
For both virtio input devices and USB input devices.

https://bugzilla.redhat.com/show_bug.cgi?id=1379603
2017-10-19 14:43:22 +02:00
Ján Tomko
c547a5f8d8 Introduce qemuBuildInputDevStr
A function that builds the -device string for input devices.
2017-10-19 14:43:22 +02:00
Ján Tomko
d059b24aea split out qemuAssignDeviceInputAlias
Move assignment of input device alias into a separate function,
for reuse on hotplug.
2017-10-19 14:43:20 +02:00
Ján Tomko
513a8d4588 qemu: allow cold unplugging of input devices
https://bugzilla.redhat.com/show_bug.cgi?id=1379603
2017-10-19 14:42:10 +02:00
Ján Tomko
ba589d88bc qemu: allow coldplugging input devices
https://bugzilla.redhat.com/show_bug.cgi?id=1379603
2017-10-19 14:42:10 +02:00
Ján Tomko
f0cab974af Use qemuDomainEnsureVirtioAddress where possible
There are two more cases where we set an S390/CCW/PCI address
type based on the machine type.

Reuse qemuDomainEnsureVirtioAddress to reduce repetition.
2017-10-19 14:41:55 +02:00
Ján Tomko
f16600ff91 Split out qemuDomainEnsureVirtioAddress
Split out the common code responsible for reserving/assigning
PCI/CCW addresses for virtio disks into a helper function
for reuse by other virtio devices.
2017-10-19 14:41:51 +02:00
Ján Tomko
5ec76b0cb4 Move qemuCheckCCWS390AddressSupport to qemu_domain
Let it be reused in qemu_domain_address.
2017-10-19 14:39:05 +02:00
Ján Tomko
fef2855366 qemuDomainAttachRNGDevice: do not access source.file randomly
We pass the source.file to qemuCheckCCWS390AddressSupport for
the purpose of reporting an error message without actually checking
that the rng device is of type VIR_DOMAIN_RNG_BACKEND_RANDOM.

Change it to a hardcoded "rng" string, which also avoids
referring to the device by a host-side attribute.
2017-10-19 14:34:21 +02:00
Ján Tomko
7afaaa934b qemuDomainAttachControllerDevice: remove dead code
After a successful attach, the device address has already been set.
Remove the pointless assignment.
2017-10-19 14:34:21 +02:00
Ján Tomko
2690b5b930 conf: audit passthrough input devices at domain startup
Introduce virDomainAuditInput and use it to log the evdev passed
to the guest.
2017-10-19 14:34:21 +02:00
Pavel Hrdina
d66fc71d31 qemu: implement virDomainSetLifecycleAction() API
There is one limitation for using this API, when the guest is started
with all actions set to "destroy" we put "-no-reboot" on the QEMU
command line.  That cannot be changed while QEMU is running and
the QEMU process is always terminated no matter what is configured
for any action.

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

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 11:52:38 +02:00
Pavel Hrdina
e859da6f42 qemu: send allowReboot in migration cookie
We need to send allowReboot in the migration cookie to ensure the same
behavior of the virDomainSetLifecycleAction() API on the destination.

Consider this scenario:

    1. On the source the domain is started with:
        <on_poweroff>destroy</on_poweroff>
        <on_reboot>restart</on_reboot>
        <on_crash>destroy</on_crash>

    2. User calls an API to set "destroy" for <on_reboot>:
        <on_poweroff>destroy</on_poweroff>
        <on_reboot>destroy</on_reboot>
        <on_crash>destroy</on_crash>

    3. The guest is migrated to a different host

    4a. Without the allowReboot in the migration cookie the QEMU
        process on destination would be started with -no-reboot
        which would prevent using the virDomainSetLifecycleAction() API
        for the rest of the guest lifetime.

    4b. With the allowReboot in the migration cookie the QEMU process
        on destination is started without -no-reboot like it was started
        on the source host and the virDomainSetLifecycleAction() API
        continues to work.

The following patch adds a QEMU implementation of the
virDomainSetLifecycleAction() API and that implementation disallows
using the API if all actions are set to "destroy" because we add
"-no-reboot" on the QEMU command line.  Changing the lifecycle action
is in this case pointless because the QEMU process is always terminated.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 11:52:34 +02:00
Pavel Hrdina
a9d637e71e qemu: move detection whether to use -no-reboot to qemu_domain
This will be used later on in implementation of new API
virDomainSetLifecycleAction().  In order to use it, we need to store
the value in status XML to not lose the information if libvirtd is
restarted.

If some guest was started by old libvirt where it was not possible
to change the lifecycle action for running guest, we can safely
detect it based on the current actions from the status XML.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 11:52:30 +02:00
Pavel Hrdina
dd97c1480e virsh: introduce set-lifecycle-action command
Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 11:52:28 +02:00
Pavel Hrdina
1a2f34e363 lib: introduce virDomainSetLifecycleAction() API
Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 11:52:26 +02:00
Pavel Hrdina
17f1a647a0 qemu: pass priv data instead of qemuCaps and autoNodeset
Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 11:52:24 +02:00
Pavel Hrdina
2dfef1240a qemu: pass priv data to qemuBuildMasterKeyCommandLine
Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 11:52:21 +02:00
Pavel Hrdina
ebf3abb166 qemu: pass priv data to qemuBuildPMCommandLine
Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 11:52:19 +02:00
Pavel Hrdina
b569ef0a76 qemu: pass priv data to qemuBuildMonitorCommandLine
Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 11:52:16 +02:00
Pavel Hrdina
e54d4d5e98 qemu: pass virDomainObjPtr to qemuBuildCommandLine
Extract the required data inside a function instead of passing it
all as arguments.

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

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

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 11:52:09 +02:00
Pavel Hrdina
1ccf35b4f2 conf: introduce virDomainLifecycle enum to list all lifecycle types
Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 11:52:06 +02:00
Pavel Hrdina
55c63295b2 conf: rename virDomainLifecycleAction enum functions
Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 11:52:04 +02:00
Pavel Hrdina
21068580d6 conf: rename lifecycle enum values to correspond with typedef keyword
Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2017-10-19 11:51:53 +02:00
Jiri Denemark
86fde4d2b2 bhyve: Fix build
Commit v3.8.0-95-gfd885a06a dropped nmodels parameter from several APIs
in src/cpu/cpu.h, but failed to update all callers.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-10-19 11:13:54 +02:00
Erik Skultety
1af4580408 nodedev: udev: Hook up virFileWaitForAccess to work around uevent race
If we find ourselves in the situation that the 'add' uevent has been
fired earlier than the sysfs tree for a device was created, we should
use the best-effort approach and give kernel some predetermined amount
of time, thus waiting for the attributes to be ready rather than
discarding the device from our device list forever. If those don't appear
in the given time frame, we need to move on, since libvirt can't wait
indefinitely.

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

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2017-10-19 08:54:53 +02:00
Erik Skultety
caf26412b6 util: Introduce virFileWaitForExists
Since we have a number of places where we workaround timing issues with
devices, attributes (files in general) not being available at the time
of processing them by calling usleep in a loop for a fixed number of
tries, we could as well have a utility function that would do that.
Therefore we won't have to duplicate this ugly workaround even more.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2017-10-19 08:54:53 +02:00
Erik Skultety
cdbe13329a nodedev: udev: Convert udevEventHandleThread to an actual thread routine
Adjust udevEventHandleThread to be a proper thread routine running in an
infinite loop handling devices. The handler thread pulls all available
data from the udev monitor and only then waits until a wakeup signal for
new incoming data has been emitted by udevEventHandleCallback.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2017-10-19 08:54:53 +02:00
Erik Skultety
5a47baaf44 nodedev: udev: Split udevEventHandleCallback in two functions
This patch splits udevEventHandleCallback in two (introduces
udevEventHandleThread) in order to be later able to refactor the latter
to actually become a normal thread which will wait some time for the
kernel to create the whole sysfs tree for a device as we cannot do that
in the event loop directly.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2017-10-19 08:54:53 +02:00
Erik Skultety
6215b036e7 nodedev: udev: Unlock the private data before setting up 'system' node
udevSetupSystemDev only needs the udev data lock to be locked because of
calling udevGetDMIData which accesses some protected structure members,
but it can do that on its own just fine, no need to hold the lock the
whole time.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2017-10-19 08:54:53 +02:00
Erik Skultety
37e02f68d0 nodedev: udev: Remove driver locks from stateInitialize and stateCleanup
The driver locks are unnecessary here, since currently the cleanup is
only called from the main daemon thread, so we can't race here. Moreover
@devs and @privateData are self-lockable objects, so no problem there
either.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2017-10-19 08:54:53 +02:00
Erik Skultety
365553645c nodedev: udev: Convert udev private data to a lockable object
Since there's going to be a worker thread which needs to have some data
protected by a lock, the whole code would just simply get unnecessary
complex, since two sets of locks would be necessary, driver lock (for
udev monitor and event handle) and a mutex protecting thread-local data.
Given the future thread will need to access the udev monitor socket as
well, why not protect everything with a single lock, even better, by
converting the driver's private data to a lockable object, we get the
automatic object disposal feature for free.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2017-10-19 08:54:53 +02:00
Erik Skultety
c6a16d3c64 nodedev: udev: Introduce udevEventMonitorSanityCheck helper function
We need to perform a sanity check on the udev monitor before every
use so that we know nothing has changed in the meantime. The reason for
moving the code to a separate helper is to enhance readability and shift
the focus on the important stuff within the udevEventHandleCallback
handler.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2017-10-19 08:54:53 +02:00
Erik Skultety
643c74abff nodedev: Move privileged flag from udev private data to driver's state
Even though hal doesn't make use of it, the privileged flag is related
to the daemon/driver rather than the backend actually used.
While at it, get rid of some tab indentation in the driver state struct.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2017-10-19 08:54:52 +02:00
Chen Hanxiao
b3aaff56db virsh: domifaddr: clarify description of --full option
Option --full will always display the name and MAC address of the
the interface. Both virsh help and virsh man page didn't mention that.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
2017-10-18 09:51:32 -04:00