Commit Graph

32656 Commits

Author SHA1 Message Date
Daniel P. Berrangé
ff376c6283 tests: fix mocking of stat() / lstat() functions
Quite a few of the tests have a need to mock the stat() / lstat()
functions and they are taking somewhat different & inconsistent
approaches none of which are actually fully correct. This is shown
by fact that 'make check' fails on 32-bit hosts. Investigation
revealed that the code was calling into the native C library impl,
not getting intercepted by our mocks.

The POSIX stat() function might resolve to any number of different
symbols in the C library.

The may be an additional stat64() function exposed by the headers
too.

On 64-bit hosts the stat & stat64 functions are identical, always
refering to the 64-bit ABI.

On 32-bit hosts they refer to the 32-bit & 64-bit ABIs respectively.

Libvirt uses _FILE_OFFSET_BITS=64 on 32-bit hosts, which causes the
C library to transparently rewrite stat() calls to be stat64() calls.
Libvirt will never see the 32-bit ABI from the traditional stat()
call. We cannot assume this rewriting is done using a macro. It might
be, but on GLibC it is done with a magic __asm__ statement to apply
the rewrite at link time instead of at preprocessing.

In GLibC there may be two additional functions exposed by the headers,
__xstat() and __xstat64(). When these exist, stat() and stat64() are
transparently rewritten to call __xstat() and __xstat64() respectively.
The former symbols will not actally exist in the library at all, only
the header. The leading "__" indicates the symbols are a private impl
detail of the C library that applications should not care about.
Unfortunately, because we are trying to mock replace the C library,
we need to know about this internal impl detail.

With all this in mind the list of functions we have to mock will depend
on several factors

 - If _FILE_OFFSET_BITS is set, then we are on a 32-bit host, and we
   only need to mock stat64 and __xstat64. The other stat / __xstat
   functions exist, but we'll never call them so they can be ignored
   for mocking.

 - If _FILE_OFFSET_BITS is not set, then we are on a 64-bit host and
   we should mock stat, stat64, __xstat & __xstat64. Either may be
   called by app code.

 - If __xstat & __xstat64 exist, then stat & stat64 will not exist
   as symbols in the library, so the latter should not be mocked.

The same all applies to lstat()

These rules are complex enough that we don't want to duplicate them
across every mock file, so this centralizes all the logic in a helper
file virmockstathelper.c that should be #included when needed. The
code merely need to provide a filename rewriting callback called
virMockStatRedirect(). Optionally VIR_MOCK_STAT_HOOK can be defined
as a macro if further processing is needed inline.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-04-03 11:31:38 +01:00
Peter Krempa
ac21141ce4 qemu: monitor: Avoid unnecessary copies of command string
Use virJSONValueToBuffer so that we can append the command terminator
string without copying of the string again. Also avoid a 'strlen' as we
can query the buffer use size.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2019-04-03 11:58:10 +02:00
Peter Krempa
d8306dce0f qemu: monitor: Remove few debug statements
The internal qemu machinery already logs the sent message via the PROBE
point in qemuMonitorSend and the monitor receive function. Those are way
better as they are easy grepable. Remove the additional ones from the
monitor code which just duplicate the sent data.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2019-04-03 11:58:10 +02:00
Peter Krempa
a2a04524be util: json: Export virJSONValueToBuffer
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2019-04-03 11:58:10 +02:00
Peter Krempa
cfe6cecdca util: json: Don't bother logging output string in virJSONValueToString
We have tests that validate the XML formatter. Additionally almost every
guide tells users to disable JSON logging. Drop logging of output string
in virJSONValueToString.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2019-04-03 11:58:10 +02:00
Peter Krempa
6a604f759d util: json: Use virBuffer in JSON->string conversion
The last step of the conversion involves copying of the generated JSON
into a separate string. We can use a virBuffer to do this as this will
also allow to subsequently use the buffer when we actually need to do
some other formatting of the string.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2019-04-03 11:58:10 +02:00
Peter Krempa
29ad523018 util: buffer: Use 'size_t' for buffer size variables
Use size_t for all sizes. The '*' modifier unfortunately does require an
int so a temporary variable is necessary in the tests.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
2019-04-03 11:58:10 +02:00
Peter Krempa
14f7030f95 util: buffer: Remove struct member munging
This was meant to stop abusing the members directly, but we don't do
this for other internal structs. Additionally this did not stop the
test from touching the members. Remove the header obscurization.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:10 +02:00
Peter Krempa
fb59497484 Use VIR_AUTODISPOSE_STR instead of VIR_DISPOSE_STRING where possible
Refactor code paths which clear strings on cleanup paths to use the
automatic helper.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:10 +02:00
Peter Krempa
a9b3afabcd util: alloc: Add automatic cleanup/disposal of strings
VIR_AUTODISPOSE_STR is similar to VIR_AUTOFREE(char *) but uses
virDispose for clearing of the stored string.

This patch also refactors VIR_DISPOSE to use the new helper which is
used for the new macro.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:10 +02:00
Peter Krempa
c358adc571 qemu: capabilities: Always assume disk snapshot caps
'blockdev-snapshot-sync' is present in QEMU since v0.14.0-rc0 and
'transaction' since v1.1.0 (52e7c241ac766406f05fa)

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:10 +02:00
Peter Krempa
72e88ca0a2 qemu: capabilities: Always assume QEMU_CAPS_DRIVE_MIRROR
qemu added the 'drive-mirror' command in v1.3.0 (d9b902db3fb71fdc)

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:10 +02:00
Peter Krempa
852afb2dc4 qemu: capabilities: Always assume QEMU_CAPS_BLOCK_COMMIT
qemu added the 'block-commit' command in v1.3.0 (ed61fc10e8c8d2)

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:10 +02:00
Peter Krempa
f1a0d2277c qemu: domain: drop qemuDomainSupportsBlockJobs
It always returns true.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:10 +02:00
Peter Krempa
d5654a7537 qemu: capabilities: Always assume QEMU_CAPS_BLOCKJOB_ASYNC
This was detected by the presence of 'block-stream' which is present in
qemu since v1.1 (db58f9c0605fa151b8c4)

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
22b83a54f5 conf: Add 'index' attribute for <disk><mirror><source>
Similarly to the disk source we need to keep the disk index (which is in
the qemu driver used for identification of the source for block jobs)
for the <mirror> element so that when it's replaced as a disk source
after pivoting all the allocated data is present.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
4e797f1af9 conf: Parse and format 'backingStore' for disk <mirror>
When the block copy operation is started with a reused external file in
incremental mode libvirt will need to open and insert the backing chain
for that file into qemu (in -blockdev mode). This means that we'll need
to track the backing chain and metadata such as node names for the full
chain of <mirror>.

This patch invokes the full backing chain formatter and parser for
<mirror> so that the chain can be kept with <mirror>.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
944d09fa3e conf: Refactor virDomainDiskDefMirrorParse
Use virDomainStorageSourceParseBase and other tricks.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
54b36c03a0 conf: Pass 'flags' to virDomainDiskSourceFormat in virDomainDiskDefFormatMirror
We have the proper flags available so we can pass them to the fomatter.
The added bonus is that private data may be formatted into the status
XML.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
86855f761f conf: use virXMLFormatElement in virDomainDiskDefFormatMirror
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
670053326b qemu: Parse NBD storage source private data by virDomainStorageSourceParse
Drop the local call in favor of passing in xmlopt.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
79e3b15ce6 qemu: Use virDomainStorageSourceParseBase in qemuDomainObjPrivateXMLParseJobNBDSource
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
ef5ed42655 qemu: Remove cleanup in qemuDomainObjPrivateXMLParseJobNBDSource
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
e1899a2490 qemu: Use VIR_AUTOFREE in qemuDomainObjPrivateXMLParseJobNBDSource
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
08c4a54ec0 conf: Modify arguments passed to virDomainDiskBackingStoreFormat
Pass in 'src' rather than the backing store of it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
d588981913 conf: Document virDomainStorageSourceParse
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
868be7ce58 conf: Use virDomainStorageSourceParseBase in virDomainDiskBackingStoreParse
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
18bc52bce0 conf: introduce virDomainStorageSourceParseBase
The helper converts the 'type', 'format' and index values to enum
values/numbers and does validation.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
dfaf170df5 conf: Replace virDomainDiskSourceParse by virDomainStorageSourceParse
virDomainDiskSourceParse was now just a thin wrapper without any extra
value. Replace all usage of it by the function it calls and remove the
function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
54fc720d8e conf: Document virDomainDiskSourceFormat
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
218c81ead0 conf: Merge virDomainStorageSourceFormat into virDomainDiskSourceFormat
There was only one caller, remove the unnecessary wrapper.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
0f13b78b20 conf: Use virXMLFormatElement in virDomainDiskBackingStoreFormat
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
945eab4060 conf: Avoid temporary variable in virDomainDiskBackingStoreFormat
Modify the check that the format is in range to be standalone and use
the convertor function directly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
eaef9b1f67 conf: Simplify control flow in virDomainDiskSourceFormat
Now that the cleanup is handled automatically it can be removed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
4bc429868e conf: Unexport virDomainStorageSourceFormat
It's not used outside of src/conf/domain_conf.c

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
0c10edadde qemu: domain: Modify <migrationSource> to look like <disk>
When adding <migrationSource> I've used a slightly unusual approach. To
allow using the disk source XML parser and formatter convert
<migrationSource> to look like <disk>. This means that <source> will be
added as a subelement of <migrationSource> rather than being formatted
inline.

Conversion from the old format in the parser is very simple as it
involves only moving the XPath context current node slightly if the new
format is found.

The status XML to XML test shows that the upgrade is done correctly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
1af846dd27 tests: qemustatusxml2xml: Add separate output for migration-out-nbd-tls
Upcomming change will modify some aspects. To allow testing upgrade path
add a separate output file so that we can see the conversion from old to
new config.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
ba3349185a tests: qemustatusxml2xml: Add another disk to migration-out-nbd-tls case
Upcomming change will modify some aspects. To allow testing upgrade path
add another disk.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
058f99d8fb tests: qemuxml2xml: Use virdeterministichashmock.so
Block job related data will be stored in a has table and formatted into
the status XML. Use the mock to guarantee stable tests.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
a9621831a3 conf: Export virDomainDiskSourceFormat
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
5f6f803ca1 conf: Merge virDomainDiskSourceFormatInternal into virDomainDiskSourceFormat
Remove the wrapper and fix callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
6bee0262c7 conf: Remove @seclabels from virDomainStorageSourceFormat
All callers including transitive callers through
virDomainDiskSourceFormatInternal always pass true. Remove the argument.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
da9f3cd84b conf: Format seclabels for <backingStore>
We parse the seclabels and use them internally so omitting them when
formatting would be misleading. Additionally our schema actually allows
them.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
e8e51b634f qemu: domain: Forbid copy_on_read option also for floppies
Using copy_on_read for removable disks is a hassle. It also does not
work for CDROMs at all as the image is supposed to be read-only and we
might ignore it for floppies when they are started as empty. Forbid it
for floppies completely rather than trying to support what probably
nobody is using.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
b3736febca qemu: hotplug: Disallow media change while blockjob is active
Until the block job completes we can't change the disk chain. Removal
would fail as the block job still has reference to the chain.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
0beac488e0 qemu: hotplug: Use VIR_AUTOUNREF for virQEMUDriverConfigPtr
Unref the config pointer automatically in code paths which get a local
copy.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
24fce6637c qemu: hotplug: Remove unused copies of virQEMUDriverConfigPtr
qemuDomainChangeGraphicsPasswords and qemuDomainRemoveHostDevice
don't use 'cfg' any more since commits 4327df7eee and 802c59d4b9
respectively.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
63ff670f40 qemu: domain: Use VIR_AUTOFREE in qemuDomainObjPrivateXMLParseBlockjobs
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
8f956ee71a qemu: Remove cleanup section of virQEMUCapsInitQMPMonitorTCG
There's nothing to clean up.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-04-03 11:58:09 +02:00
Peter Krempa
e125000a88 qemu: Remove ATTRIBUTE_UNUSED from 'qemuCaps' of virQEMUCapsInitQMPMonitorTCG
It's actually used.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2019-04-03 11:58:09 +02:00