Commit Graph

184 Commits

Author SHA1 Message Date
Michal Privoznik
0eebdce995 qemuhotplugtest: Verify domain XML on UPDATE
Just like we check the resulting domain XML after ATTACH and
DETACH, we should do the same after UPDATE action. This is as
simple as calling testQemuHotplugCheckResult() and providing
missing XMLs. For those test cases where no change is done, we
can just make the expected XML a symlink to the input XML.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
2023-04-25 08:46:27 +02:00
Michal Privoznik
11793a5311 qemuhotplugtest: use g_autoptr(virDomainDeviceDef)
This brings us one step closer to the caller of
qemuDomainAttachDeviceLive()
(qemuDomainAttachDeviceLiveAndConfig()).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
2023-04-25 08:46:27 +02:00
Michal Privoznik
22c082b8a2 qemuhotplugtest: Don't overwrite vm->def->id in testQemuHotplugCheckResult()
This is a leftover from v2.0.0-rc1~300. In v1.2.12-rc1~43 we've
introduced a code that explicitly sets vm->def->id to -1 to force
generation of inactive XML. But this was removed in the later
commit, which forgot to remove the restoration of the original
dom ID.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
2023-04-25 08:46:27 +02:00
Michal Privoznik
dc4ec0e30b qemuhotplugtest: Fix misleading comment on monitor unlock
There's a comment in testQemuHotplug() trying to explain why we
need to unlock the monitor object. Well, while it might have been
correct when being introduced, it's no longer factually correct
as just any function (attach/detach/update) might talk to the
monitor and it expects the monitor to be unlocked (as it calls
qemuDomainObjEnterMonitor() + qemuDomainObjExitMonitor()).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
2023-04-25 08:46:27 +02:00
Michal Privoznik
e98f0b99c0 qemuhotplugtest: Call qemuDomainUpdateDeviceLive() directly
There's no reason for qemuhotplugtest to reimplement which device
update function to call (testQemuHotplugUpdate()) when
qemuDomainUpdateDeviceLive() already does that. Thus, drop
testQemuHotplugUpdate() and call qemuDomainUpdateDeviceLive()
directly.

BTW: this also shows why reimplementing
qemuDomainUpdateDeviceLive() is bad idea: The
"disk-cdrom-nochange" test is succeeding only because
testQemuHotplugUpdate() supports graphics and returns an
(expected) error for every other devtype.

NB, there's still missing check that the resulting XML is the
expected one (just like we do for attach and detach), but that's
pre-existing and will be fixed later.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
2023-04-25 08:46:27 +02:00
Michal Privoznik
f7b8f740ca qemuhotplugtest: Call qemuDomainAttachDeviceLive() directly
There's no reason for qemuhotplugtest to reimplement which device
attach function to call (testQemuHotplugAttach()) when
qemuDomainAttachDeviceLive() already does that. Thus, drop
testQemuHotplugAttach() and call qemuDomainAttachDeviceLive()
directly.

There's one small catch though, qemuDomainAttachDeviceLive() now
calls one monitor command more (to list all aliases). We don't
care really, because we're not testing that. Therefore, just
provide a dummy reply.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
2023-04-25 08:46:27 +02:00
Michal Privoznik
2577ade457 qemuhotplugtest: Call qemuDomainDetachDeviceLive() directly
The testQemuHotplugDetach() already does call
qemuDomainDetachDeviceLive() but only for some device types. For
the rest it reports an error (but only if running test
verbosely). This makes no sense. Just call
qemuDomainDetachDeviceLive() directly and drop
testQemuHotplugDetach().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
2023-04-25 08:46:27 +02:00
Peter Krempa
fb1bfad7ad qemu: hotplug: Update disk private data after hotplug
The disk private data contain information about the tray and
removability of the disk. Until recently we didn't support hotplug of
removable disks thus it wasn't a problem but now when you can hotplug a
CDROM you would not be able to open its tray.

Fix it by updating the hotplugged disk the same way we do at startup.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2160435
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-04-24 12:57:56 +02:00
Martin Kletzander
865b071ae8 qemu: Validate watchdog action compatibility per-device
This makes it also work during attach.  Also add a test for attaching a
watchdog with incompatible action.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2187278
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2023-04-20 10:17:35 +02:00
Peter Krempa
6eee2de99f qemuhotplugtest: Make the test more useful by validating used commands against QMP schema
qemuhotplugtest validates only that a given command is used but not the
arguments of the command. With this patch we'll validate the arguments
against the QMP schema thus we can catch possible issues with deprecated
commands.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-04-03 09:19:07 +02:00
Peter Krempa
706cd47487 qemuhotplugtest: Use real 'latest' capabilities for hotplug testing
Rather than test with synthetic capabilities which might get outdated
reuse testQemuGetRealCaps to fetch latest capabilities and use those.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-04-03 09:19:07 +02:00
Peter Krempa
c469b0897c qemuhotplugtest: Refactor calling of testQemuHotplugCpuPrepare
Pass in the whole struct rather than splitting out individual members.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-04-03 09:19:07 +02:00
Peter Krempa
cccabdf8be qemuhotplugtest: Assert QEMU_CAPS_SET_ACTION
With modern qemu we use 'set-action' instead of 'watchdog-set-action'.

Switch to it so that later qemuhotplugtest can be switched to use real
capabilities.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-04-03 09:19:07 +02:00
Peter Krempa
c84e9a3b82 qemuhotplugtest: Enable 'lsilogic' SCSI controller
All real qemus support the 'lsilogic' controller and thus would pick it
as the default rather than virtio-scsi. Since lsilogic is limited in
some aspects we should test it with the proper default model.

In the future the fake capabilities will be replaced by real
capabilities so this test would break.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-04-03 09:19:07 +02:00
Peter Krempa
578c2a0cc7 qemuhotplugtest: Don't fetch capabilities when they are not used
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-04-03 09:19:07 +02:00
Peter Krempa
c0e60063c9 qemu: capabilities: Remove unused virQEMUCapsInitQMPBasicArch
The function doesn't set any capability and we don't want to add
arch-dependent always-peresent capabilities in the future.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-03-07 12:26:33 +01:00
Peter Krempa
e61adbf26b qemu: capabilities: Don't make callers check return of virQEMUCapsNew(Binary)
The allocation of the object itself can't fail. What can fail is the
creation of the class on a programming error. Rather than punting the
error up the stack abort() directly on the first occurence as the error
can't be fixed during runtime.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-03-06 20:55:50 +01:00
Andrea Bolognani
743f26c34a tests: Drop unnecessary configuration overrides
They are not used by the specific test.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-03-06 14:35:35 +01:00
Andrea Bolognani
87b30e6965 tests: Move fakerootdir handling to common logic
Instead of having each test manually initialize and cleanup
its own fakerootdir, do that as part of the common test
initialization logic in virTestMain().

In most cases we can simply drop the relevant code from the
test program, but scsihosttest uses the value of fakerootdir
as a starting point to build another path, so we need to do
things slightly differently. In order to keep things working,
we retrieve the value from the LIBVIRT_FAKE_ROOT_DIR
environment variable, same as all the mock libraries are
already doing.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2023-03-03 13:52:37 +01:00
Andrea Bolognani
457a0183d6 tests: Adopt fakerootdir helpers
Most replacements are completely straightforward but
vircgrouptest requires slightly different handling because,
instead of initializing a single fakerootdir at the start of
the test program and cleaning it up at the end, it creates
multiple different ones one after the other.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2023-03-03 13:52:37 +01:00
Peter Krempa
b155bd095f conf: Use proper type for 'type' field of struct _virDomainDeviceDef
Use virDomainDeviceType as type and update all switch statements which
didn't mention all possible values.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-02-06 13:34:29 +01:00
Ján Tomko
0662e6bd36 qemu: Assume QEMU_CAPS_CCW
Introduced in libvirt by:
  commit f245a9791c
    qemu: introduce capability for virtual-css-bridge

Which mentions that its support was in QEMU 2.7.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-10-03 19:46:42 +02:00
Peter Krempa
a0b8b54348 qemu: Retire QEMU_CAPS_BLOCKDEV
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-08-11 15:25:36 +02:00
Peter Krempa
2ebb44a957 qemuhotplugtest: Switch to -blockdev mode
Enable blockdev mode and convert the expected commands to the modern
equivalents in preparation for removing the old-style hotplug code
paths.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-08-11 15:22:14 +02:00
Peter Krempa
071a4c8ba7 qemu: alias: Remove check for QEMU_CAPS_BLOCKDEV
The only instance in this file can be simplified to avoid checking the
capability.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-08-11 15:14:18 +02:00
Kristina Hanicova
203e74ff42 qemu: remove unused driver and all its propagations
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2022-08-10 16:50:07 +02:00
Paolo Bonzini
2dd3ec6f57 qemu: deprecate query-cpus-fast capability
All supported versions of QEMU have the command.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2022-08-08 17:36:49 +02:00
minglei.liu
3078799fef qemu: support CDROM hotplug cdrom with USB/SCSI bus
QEMU supports hotplug of a cdrom device with USB or SCSI bus. Just
unblock these devices in qemuDomainAttachDeviceDiskLiveInternal() and
qemuDomainDetachPrepDisk().

Fixes: https://gitlab.com/libvirt/libvirt/-/issues/261

Signed-off-by: minglei.liu <minglei.liu@smartx.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-07-20 16:53:51 +02:00
Peng Liang
48e8c36b05 tests: Remove unused includes
Signed-off-by: Peng Liang <tcx4c70@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-06-16 06:43:58 +02:00
Jiri Denemark
76baf935aa qemu: Do not pass unused opaque pointer to monitor callbacks
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-05-24 16:26:04 +02:00
Peter Krempa
1e925d1c17 qemu_fd: Don't rely on fdset id allocation by qemu
If we use our own fdset ID when hot-adding a fdset we can vastly
simplify our internals.

As a stop-gap when a fdset would be added behind libvirt's back we'll
validated that the fdset to be added is not yet used.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-05-16 09:15:45 +02:00
Peter Krempa
47b6829edc qemu: Always assume QEMU_CAPS_CHARDEV_FD_PASS_COMMANDLINE
All qemu versions now support FD passing either directly or via FDset.
Assume that we always have this capability so that we can simplify
chardev handling in many cases.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-04-04 12:26:59 +02:00
Peter Krempa
874b00f750 qemuhotplugtest: Assume QEMU_CAPS_CHARDEV_FD_PASS_COMMANDLINE
All modern QEMU versions use FD passing for listening unix sockets so
the test should reflect this. This will later help when removing the
legacy code paths when we drop support for old QEMUs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-15 09:32:23 +01:00
Peter Krempa
ad81aa8ad0 qemu: Honour 'virtlogd' use when hotplugging chardevs
Setup the chardev similarly to how we do it on startup so that virtlogd
is properly used with chardevs which are hotplugged to a VM.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-14 13:14:00 +01:00
Peter Krempa
22d5ce0252 qemuDomainRemoveChrDevice: Detach fdset after chardev hot-unplug
Our code uses fdsets for the pipe passed from virtlogd to qemu, but the
chardev hot-unplug code neglected to detach the fdset after the chardev
was removed. This kept the FDs open by qemu even after they were not
used any more.

After the refactor to use qemuFDPass for chardevs we now configure the
'opaque' field for fdsets used for chardevs so we can use
qemuHotplugRemoveFDSet to remove the unused fdset.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-14 13:14:00 +01:00
Michal Privoznik
b118215703 tests: Use g_autoptr(qemuMonitorTest)
Instead of calling qemuMonitorTestFree() explicitly, we can use
g_autoptr() and let it be called automagically.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2021-11-11 16:16:26 +01:00
Peter Krempa
4b1199a5c4 qemuhotplugtest: Remove tests for legacy cpu hotplug on x86
Modern cpu hotplug was introduced in qemu-2.7, thus all qemu versions
actually support it. Remove the tests for the legacy hotplug.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-01 16:14:53 +01:00
Peter Krempa
686caa57e5 qemu: validate: Always assume QEMU_CAPS_SPICE_FILE_XFER_DISABLE
QEMU added the capability to disable file transfers via spice in commit
5ad24e5f3b ("spice: Add -spice disable-agent-file-transfer cmdline
option (rhbz#961850)") released in qemu-v1.6.0 and the option can't be
disabled.

Remove the unnecessary validation.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-09-24 10:37:01 +02:00
Peter Krempa
7d3ca9dbdd qemuhotplugtest: Add also always-present capabilities
Use virQEMUCapsInitQMPBasicArch in qemuHotplugCreateObjects so that we
also add the always-present capabilities to the set of capabilities used
for the hotplug test and fix fallout.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2021-05-03 12:14:44 +02:00
Michal Privoznik
c8238579fb lib: Drop internal virXXXPtr typedefs
Historically, we declared pointer type to our types:

  typedef struct _virXXX virXXX;
  typedef virXXX *virXXXPtr;

But usefulness of such declaration is questionable, at best.
Unfortunately, we can't drop every such declaration - we have to
carry some over, because they are part of public API (e.g.
virDomainPtr). But for internal types - we can do drop them and
use what every other C project uses 'virXXX *'.

This change was generated by a very ugly shell script that
generated sed script which was then called over each file in the
repository. For the shell script refer to the cover letter:

https://listman.redhat.com/archives/libvir-list/2021-March/msg00537.html

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-04-13 17:00:38 +02:00
Laine Stump
05332bb866 tests: replace VIR_FREE with g_free in all vir*Free() functions
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-02-05 00:20:45 -05:00
Peter Krempa
62a01d84a3 util: hash: Retire 'virHashTable' in favor of 'GHashTable'
Don't hide our use of GHashTable behind our typedef. This will also
promote the use of glibs hash function directly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Matt Coleman <matt@datto.com>
2020-11-06 10:40:51 +01:00
Jonathon Jongsma
b79abf9c3c qemu: support hotplug of vdpa devices
By using the new qemu monitor functions to handle passing and removing
file descriptors, we can support hotplug of vdpa devices.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
2020-10-20 15:15:06 -04:00
Daniel Henrique Barboza
03e4e4b21e qemu_command.c: move QEMU_CAPS_DEVICE_USB_KBD check to qemu_validate.c
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-10-15 10:50:34 -03:00
Ján Tomko
a037ae8614 tests: use g_new0 instead of VIR_ALLOC
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2020-09-23 14:54:38 +02:00
Jonathon Jongsma
a5af3bd862 tests: change confusing macro agument names
Rather than use the names "fial" and "kep", use "fail" and "keep". In
the DO_TEST() macro, to prevent the preprocessor replacing the struct
member names during assignment, use the names "fail_" and "keep_"
instead.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2020-09-02 23:45:39 -04:00
Ján Tomko
d43f393134 tests: qemu: remove unnecessary labels
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2020-08-03 07:23:46 +02:00
Ján Tomko
bcbb026993 tests: qemu: use g_autoptr where possible
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2020-08-03 07:23:46 +02:00
Ján Tomko
845fee02c1 tests: qemu: use g_autofree where possible
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2020-08-03 07:23:46 +02:00
Michal Privoznik
b150fbc4fe qemuhotplugtest: Free monitor iff successfully initialized
If initializing test monitor in testQemuHotplugCpuPrepare()
fails, the control jumps to error label where
testQemuHotplugCpuDataFree() is called. But since the data->mon
is NULL due to aforementioned failure,
qemuMonitorTestGetMonitor() dereferences a NULL pointer leading
to a SIGSEGV.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2020-06-29 12:38:22 +02:00