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

1) qemuConnectMonitor() unlocks @vm

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

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

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

5) qemuMonitorLastError() dereferences NULL pointer

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

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

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

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2019-10-09 10:32:13 +02:00
..
bhyveargv2xmldata
bhyvexml2argvdata
bhyvexml2xmloutdata
capabilityschemadata
commanddata
cputestdata
domaincapsschemadata qemu: Adapt to changed ppc64 CPU model names 2019-10-09 09:53:41 +02:00
domainconfdata Rename virDomainGetRootFilesystem to virDomainGetFilesystemForTarget 2014-02-20 15:50:46 +00:00
domainschemadata
fchostdata/fc_host
genericxml2xmlindata conf: resctrl object is not properly handled 2019-08-20 15:36:36 +02:00
genericxml2xmloutdata
interfaceschemadata
libxlxml2domconfigdata
lxcconf2xmldata
lxcxml2xmldata
lxcxml2xmloutdata
networkxml2confdata
networkxml2firewalldata
networkxml2xmlin
networkxml2xmlout
networkxml2xmlupdatein
networkxml2xmlupdateout
nodedevschemadata
nssdata nss: Don't stop parsing on unexpected key 2019-08-09 12:17:19 +02:00
nwfilterxml2firewalldata
nwfilterxml2xmlin
nwfilterxml2xmlout
qemuagentdata
qemublocktestdata tests: qemublock: Use bigger numbers as dummy capacity/physical 2019-09-04 09:13:49 +02:00
qemucapabilitiesdata qemu: Adapt to changed ppc64 CPU model names 2019-10-09 09:53:41 +02:00
qemucaps2xmloutdata
qemudomaincheckpointxml2xmlin
qemudomaincheckpointxml2xmlout
qemudomainsnapshotxml2xmlin
qemudomainsnapshotxml2xmlout
qemufirmwaredata
qemuhotplugtestcpus qemu: command: Use all vCPU properties when creating args for vCPU hotplug 2019-08-29 16:36:26 +02:00
qemuhotplugtestdevices tests: Add test case for QEMU pci-hostdev hotplug 2019-09-09 16:44:24 +02:00
qemuhotplugtestdomains tests: Add test case for QEMU pci-hostdev hotplug 2019-09-09 16:44:24 +02:00
qemumemlockdata
qemumigparamsdata
qemumonitorjsondata
qemustatusxml2xmldata tests: qemustatusxml2xml: Fix disk target mess 2019-09-16 11:50:28 +02:00
qemuvhostuserdata qemu: add vhost-user helpers 2019-09-24 13:19:08 -04:00
qemuxml2argvdata tests: qemuxml2argv: Make use of versioned cpu-tsc-frequency and cpu-host-model-cmt tests 2019-10-07 13:46:38 +02:00
qemuxml2xmloutdata conf: new "managed" attribute for target dev of <interface type='ethernet'> 2019-09-09 14:35:54 -04:00
secretxml2xmlin
securityselinuxhelperdata
securityselinuxlabeldata
storagepoolcapsschemadata
storagepoolschemadata
storagepoolxml2argvdata
storagepoolxml2xmlin
storagepoolxml2xmlout
storagevolschemadata
storagevolxml2argvdata
storagevolxml2xmlin
storagevolxml2xmlout
sysinfodata
vboxsnapshotxmldata
vircaps2xmldata
vircgroupdata
virconfdata
virfilecachedata
virfiledata
virhostcpudata
virjsondata
virmacmaptestdata
virnetdaemondata
virnetdevopenvswitchdata
virnetdevtestdata/sys/class/net
virnetworkportxml2xmldata
virnwfilterbindingxml2xmldata
virpcitestdata virpcimock: Mock the SRIOV Virtual functions 2019-09-09 16:44:24 +02:00
virresctrldata
virscsidata
virstorageutildata
virusbtestdata/sys_bus_usb/devices
vmwareverdata
vmx2xmldata vmx: convert firmware config for autoselection 2019-04-15 20:03:55 -04:00
xlconfigdata
xmconfigdata
xml2vmxdata
.valgrind.supp
bhyveargv2xmlmock.c conf: move 'generated' member from virMacAddr to virDomainNetDef 2018-02-19 13:15:00 -05:00
bhyveargv2xmltest.c tests: remove use of virTestOOMActive from bhyve testsuite 2019-09-13 16:03:18 +01:00
bhyvexml2argvmock.c
bhyvexml2argvtest.c tests: Always put a '\n' after each debug print 2019-08-27 15:49:48 +02:00
bhyvexml2xmltest.c tests: Always put a '\n' after each debug print 2019-08-27 15:49:48 +02:00
check-file-access.pl
commandhelper.c tests: Drop /private CWD prefix in commandhelper 2019-08-23 11:26:26 +01:00
commandtest.c util: remove some no-op thread functions 2019-09-19 12:50:21 +01:00
cputest.c qemu_monitor: allow cpu props to be optional 2019-10-07 10:09:49 +02:00
domaincapsmock.c
domaincapstest.c tests: add qemu capabilities data for qemu 4.2 2019-09-27 07:20:14 +02:00
domainconftest.c
esxutilstest.c
eventtest.c util: remove some no-op thread functions 2019-09-19 12:50:21 +01:00
fchosttest.c tests: Add lib- prefix to all mocks 2019-08-23 11:26:26 +01:00
fdstreamtest.c
file_access_whitelist.txt
genericxml2xmltest.c
group-qemu-caps.pl
interfacexml2xmltest.c
libvirtd-fail Forget last daemon/ dir artefacts 2018-07-27 15:44:38 +02:00
libvirtd-pool tests: consistently source test-lib.sh in scripts 2016-04-23 15:41:40 -04:00
libxlmock.c
libxlxml2domconfigtest.c tests: Add lib- prefix to all mocks 2019-08-23 11:26:26 +01:00
lxcconf2xmltest.c
lxcxml2xmltest.c
Makefile.am qemu: add vhost-user helpers 2019-09-24 13:19:08 -04:00
metadatatest.c
networkxml2conftest.c
networkxml2firewalltest.c
networkxml2xmltest.c
networkxml2xmlupdatetest.c
nodedevxml2xmltest.c
nsslinktest.c
nssmock.c
nsstest.c tests: Add lib- prefix to all mocks 2019-08-23 11:26:26 +01:00
nwfilterebiptablestest.c
nwfilterxml2firewalltest.c
nwfilterxml2xmltest.c
objecteventtest.c
objectlocking.ml
openvzutilstest.c
openvzutilstest.conf
pkix_asn1_tab.c
qemuagenttest.c util: remove some no-op thread functions 2019-09-19 12:50:21 +01:00
qemublocktest.c qemu: block: Explicitly specify backingStore when creating format layer props 2019-09-06 08:12:21 +02:00
qemucapabilitiestest.c util: remove some no-op thread functions 2019-09-19 12:50:21 +01:00
qemucaps2xmlmock.c
qemucaps2xmltest.c util: remove some no-op thread functions 2019-09-19 12:50:21 +01:00
qemucapsfixreplies
qemucapsprobe.c util: remove some no-op thread functions 2019-09-19 12:50:21 +01:00
qemucapsprobemock.c
qemucommandutiltest.c
qemucpumock.c
qemudomaincheckpointxml2xmltest.c qemu: Pass correct qemuCaps to virDomainDefParseNode 2019-08-09 13:55:54 +02:00
qemudomainsnapshotxml2xmltest.c qemu: Pass correct qemuCaps to virDomainDefParseNode 2019-08-09 13:55:54 +02:00
qemufirmwaretest.c qemufirmwaretest: Test FW path getting through qemuFirmwareGetSupported() 2019-09-12 12:33:19 +02:00
qemuhotplugtest.c util: remove some no-op thread functions 2019-09-19 12:50:21 +01:00
qemumemlocktest.c tests: Add lib- prefix to all mocks 2019-08-23 11:26:26 +01:00
qemumigparamstest.c util: remove some no-op thread functions 2019-09-19 12:50:21 +01:00
qemumonitorjsontest.c tests: qemumonitor: Add testing for the 'transaction' command and generators 2019-09-30 13:12:56 +02:00
qemumonitortestutils.c qemu: Fix @vm locking issue when connecting to the monitor 2019-10-09 10:32:13 +02:00
qemumonitortestutils.h
qemusecuritymock.c security_util: Remove stale XATTRs 2019-08-22 17:05:17 +02:00
qemusecuritytest.c
qemusecuritytest.h qemusecuritymock: Allow some paths to be not restored 2019-07-03 08:36:04 +02:00
qemuvhostusertest.c qemu: add vhost-user helpers 2019-09-24 13:19:08 -04:00
qemuxml2argvmock.c qemu: support unmanaged target tap dev for <interface type='ethernet'> 2019-09-09 14:38:01 -04:00
qemuxml2argvtest.c tests: qemuxml2argv: Make use of versioned cpu-tsc-frequency and cpu-host-model-cmt tests 2019-10-07 13:46:38 +02:00
qemuxml2xmltest.c conf: new "managed" attribute for target dev of <interface type='ethernet'> 2019-09-09 14:35:54 -04:00
scsihosttest.c
seclabeltest.c util: remove some no-op thread functions 2019-09-19 12:50:21 +01:00
secretxml2xmltest.c
securityselinuxhelper.c
securityselinuxlabeltest.c tests: Always put '\n' at the end of VIR_TEST_VERBOSE 2019-08-27 15:56:17 +02:00
securityselinuxtest.c
shunloadhelper.c
shunloadtest.c
sockettest.c tests: Avoid IPv4-translated IPv6 address in sockettest 2019-08-23 11:26:26 +01:00
ssh.c
storagebackendsheepdogtest.c
storagepoolcapstest.c
storagepoolxml2argvtest.c tests: Always put a '\n' after each debug print 2019-08-27 15:49:48 +02:00
storagepoolxml2xmltest.c
storagevolxml2argvtest.c
storagevolxml2xmltest.c
sysinfotest.c
test-lib.sh build: drop the mktempd gnulib module 2019-10-07 11:34:24 +01:00
test-wrap-argv.pl
testutils.c util: remove some no-op thread functions 2019-09-19 12:50:21 +01:00
testutils.h util: purge all code for testing OOM handling 2019-09-13 10:05:17 +01:00
testutilshostcpus.h
testutilslxc.c
testutilslxc.h
testutilsqemu.c tests: Always put '\n' at the end of VIR_TEST_VERBOSE 2019-08-27 15:56:17 +02:00
testutilsqemu.h tests: add slirp-helper qemuxml2argv test 2019-09-06 12:47:47 +02:00
testutilsqemuschema.c tests: Always put '\n' at the end of VIR_TEST_VERBOSE 2019-08-27 15:56:17 +02:00
testutilsqemuschema.h
testutilsxen.c
testutilsxen.h
utiltest.c tests: Always put a '\n' after each debug print 2019-08-27 15:49:48 +02:00
vboxsnapshotxmltest.c Revert "Include unistd.h directly by files using it" 2019-04-10 12:26:32 +02:00
viralloctest.c
viratomictest.c util: remove some no-op thread functions 2019-09-19 12:50:21 +01:00
virauthconfigtest.c
virbitmaptest.c
virbuftest.c tests: Always put a '\n' after each debug print 2019-08-27 15:49:48 +02:00
vircaps2xmltest.c tests: Add lib- prefix to all mocks 2019-08-23 11:26:26 +01:00
vircapstest.c
vircgroupmock.c
vircgrouptest.c tests: Add lib- prefix to all mocks 2019-08-23 11:26:26 +01:00
virconftest.c lib: Define and use autofree for virConfPtr 2019-09-10 09:34:37 +02:00
vircryptotest.c tests: Add lib- prefix to all mocks 2019-08-23 11:26:26 +01:00
virdbusmock.c
virdbustest.c
virdeterministichashmock.c
virdrivermoduletest.c
virendiantest.c
virerrortest.c tests: Always put '\n' at the end of VIR_TEST_VERBOSE 2019-08-27 15:56:17 +02:00
virfilecachemock.c
virfilecachetest.c tests: Add lib- prefix to all mocks 2019-08-23 11:26:26 +01:00
virfilemock.c
virfiletest.c tests: Add lib- prefix to all mocks 2019-08-23 11:26:26 +01:00
virfilewrapper.c tests: mock execv/execve 2019-09-24 13:19:09 -04:00
virfilewrapper.h
virfirewalltest.c util: purge all code for testing OOM handling 2019-09-13 10:05:17 +01:00
virhashdata.h
virhashtest.c virhashtest: Drop useless new line 2019-08-27 15:58:51 +02:00
virhostcpumock.c
virhostcputest.c tests: Always put a '\n' after each debug print 2019-08-27 15:49:48 +02:00
virhostdevtest.c virhostdevtest: Reset libvirt error on expected failure 2019-08-27 16:10:21 +02:00
viridentitytest.c util: sanitize return values for virIdentity getters 2019-09-16 11:25:34 +01:00
viriscsitest.c tests: Add lib- prefix to all mocks 2019-08-23 11:26:26 +01:00
virjsontest.c tests: Always put '\n' at the end of VIR_TEST_VERBOSE 2019-08-27 15:56:17 +02:00
virkeycodetest.c
virkeyfiletest.c
virkmodtest.c
virlockspacetest.c
virlogtest.c tests: Always put a '\n' after each debug print 2019-08-27 15:49:48 +02:00
virmacmaptest.c tests: Add lib- prefix to all mocks 2019-08-23 11:26:26 +01:00
virmock.h tests: Lookup extended stat/lstat in mocks 2019-08-23 11:26:26 +01:00
virmockstathelpers.c tests: Avoid gnulib replacements in mocks 2019-08-23 11:26:26 +01:00
virnetdaemonmock.c
virnetdaemontest.c tests: Always put a '\n' after each debug print 2019-08-27 15:49:48 +02:00
virnetdevbandwidthmock.c
virnetdevbandwidthtest.c tests: Add lib- prefix to all mocks 2019-08-23 11:26:26 +01:00
virnetdevmock.c
virnetdevopenvswitchtest.c
virnetdevtest.c tests: Add lib- prefix to all mocks 2019-08-23 11:26:26 +01:00
virnetmessagetest.c
virnetserverclientmock.c
virnetserverclienttest.c util: sanitize return values for virIdentity getters 2019-09-16 11:25:34 +01:00
virnetsockettest.c rpc: fix escaping of shell path for netcat binary 2019-10-01 12:57:07 +01:00
virnettlscontexttest.c tests: Add lib- prefix to all mocks 2019-08-23 11:26:26 +01:00
virnettlshelpers.c
virnettlshelpers.h
virnettlssessiontest.c tests: Add lib- prefix to all mocks 2019-08-23 11:26:26 +01:00
virnetworkportxml2xmltest.c conf: take advantage of VIR_AUTOPTR for virNetworkPortDefPtr 2019-09-26 21:38:48 -04:00
virnumamock.c
virnwfilterbindingxml2xmltest.c
virpcimock.c virpcimock.c: simplify getrealpath() usage 2019-09-09 16:44:24 +02:00
virpcitest.c tests: Always put a '\n' after each debug print 2019-08-27 15:49:48 +02:00
virpolkittest.c Revert "dbus: correctly build reply message" 2019-09-10 09:47:13 +02:00
virportallocatormock.c
virportallocatortest.c tests: Add lib- prefix to all mocks 2019-08-23 11:26:26 +01:00
virprocessmock.c tests: Add test case for QEMU pci-hostdev hotplug 2019-09-09 16:44:24 +02:00
virrandommock.c
virresctrltest.c tests: Always put a '\n' after each debug print 2019-08-27 15:49:48 +02:00
virrotatingfiletest.c
virschematest.c nwfilter: move standard XML configs out of examples dir 2019-08-19 11:52:44 +01:00
virscsitest.c
virsh-checkpoint
virsh-cpuset
virsh-define-dev-segfault tests: unify qemu binary paths for all qemu related tests 2017-04-11 14:06:47 +02:00
virsh-int-overflow
virsh-optparse
virsh-read-bufsiz
virsh-read-non-seekable
virsh-schedinfo
virsh-self-test
virsh-snapshot tests: Fix virsh-snapshot/checkpoint without readline-devel 2019-08-02 09:44:41 -05:00
virsh-start
virsh-undefine
virsh-uriprecedence
virsh-vcpupin
virshtest.c
virstoragetest.c util: storagefile: Flag backing store strings with authentication 2019-08-26 13:49:17 +02:00
virstorageutiltest.c
virstringtest.c
virsystemdtest.c tests: Add lib- prefix to all mocks 2019-08-23 11:26:26 +01:00
virt-aa-helper-test
virt-admin-self-test
virtestmock.c
virtimetest.c
virtypedparamtest.c
viruritest.c tests: viruri: Add test for password in URI userinfo 2019-08-26 13:49:16 +02:00
virusbmock.c
virusbtest.c tests: Add lib- prefix to all mocks 2019-08-23 11:26:26 +01:00
vmwarevertest.c
vmx2xmltest.c
vshtabletest.c
xlconfigtest.c lib: Define and use autofree for virConfPtr 2019-09-10 09:34:37 +02:00
xmconfigtest.c lib: Define and use autofree for virConfPtr 2019-09-10 09:34:37 +02:00
xml2vmxtest.c