Commit Graph

5588 Commits

Author SHA1 Message Date
Michal Privoznik
c41b989112 virDomainDefParse{File,String}: Introduce @parseOpaque argument
We want to pass the proper opaque pointer instead of NULL to
virDomainDefParse and subsequently virDomainDefParseNode too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-09-26 16:50:12 +02:00
Michal Privoznik
da6c604af2 virDomainDefParseNode: Introduce @parseOpaque argument
We want to pass the proper opaque pointer instead of NULL to
virDomainDefParseXML and subsequently virDomainDefPostParse too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-09-26 16:50:12 +02:00
Michal Privoznik
940d91c55b virDomainDefPostParse: Introduce @parseOpaque argument
Some callers might want to pass yet another pointer to opaque
data to post parse callbacks. The driver generic one is not
enough because two threads executing post parse callback might
want to see different data (e.g. domain object pointer that
domain def belongs to).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-09-26 16:50:12 +02:00
John Ferlan
9e14689ea5 qemu: Get/return compressedpath program
Based upon a patch from Chen Hanxiao <chenhanxiao@gmail.com>, rather than
need to call virFindFileInPath twice, let's just save the path and pass it
along with the compressed type. (NB: the second call would be in virExec as
called from virCommandRunAsync which is called from qemuMigrationToFile
using the argument 'compressor' which up to this point would be the string
from the cfg file that isn't the fully qualified path).

Since we now have the path, we can remove qemuCompressProgramName which
would return NULL or the string representation of the compress type.
2016-09-26 07:44:42 -04:00
John Ferlan
9477b4a0a5 qemu: Remove qemuCompressProgramAvailable
There's only one caller and the code is duplicitous just converting the
recently converted cfg image name back into it's string value in order to
get/find the path to the image.  A subsequent patch can return this path.
2016-09-26 07:44:42 -04:00
John Ferlan
48cb9f0542 qemu: Use qemuGetCompressionProgram for error paths
Let's do some more code reuse - there are 3 other callers that care to
check/get the compress program. Each of those though cares whether the
requested cfg image is valid and exists. So, add a parameter to handle
those cases.

NB: We won't need to initialize the returned value in the case where
the cfg image doesn't exist since the called program will handle that.
2016-09-26 07:44:42 -04:00
John Ferlan
4052ac2726 qemu: Alter qemuGetCompressionProgram warning message
Add a new parameter 'styleFormat' to be used when printing the
warning message so that it's "clearer" what style of compression
call caused the error. Add that style to both messages as a paremter.

Also a VIR_WARN error message doesn't need to be translated
 (e.g. inside _()), so remove the need for the translation.
2016-09-26 07:44:42 -04:00
John Ferlan
882e360dac qemu: Remove getCompressionType
There's only one caller now anyway... Besides it's just a shell for
getting the compress type.  Subsequent patches will return the path
to the compression program.
2016-09-26 07:44:42 -04:00
John Ferlan
02d32d2d5d qemu: Introduce helper qemuGetCompressionProgram
Split out the guts of getCompressionType to perform the same functionality
in the new helper program with a subsequent patch goal to be reusable for
other callers making similar checks/calls to ensure the compression type
is valid and that the compression program cannot be found.
2016-09-26 07:44:42 -04:00
John Ferlan
6994815467 qemu: Adjust doCoreDump to call getCompressionType
Rather than calling getCompressionType from each of the callers, just call
it from doCoreDump.  A subsequent patch will be adjust the code even more.
2016-09-26 07:44:42 -04:00
John Ferlan
abaa86f9ab qemu: Move getCompressionType
A subsequent patch will adjust the 3 callers to just call from doCoreDump.
2016-09-26 07:44:42 -04:00
Michal Privoznik
b55c064f3b qemuBuildHostNetStr: Realign
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-09-23 16:09:03 +02:00
John Ferlan
e3d3c04a6c qemu: Fix improper indention
Commit id 'ce61c164' indented wrong - not sure how I did that...
2016-09-22 16:49:25 -04:00
Jiri Denemark
c944a63461 Move CMT feature filtering to QEMU driver
It really doesn't belong to the generic CPU driver.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-22 15:40:09 +02:00
Jiri Denemark
7ce711a30e qemu: Update guest CPU def in live XML
Storing the updated CPU definition in the live domain definition saves
us from having to update it over and over when we need it. Not to
mention that we will soon further update the CPU definition according to
QEMU once it's started.

A highly wanted side effect of this patch, libvirt will pass all CPU
features explicitly specified in domain XML to QEMU, even those that are
already included in the host model.

This patch should fix the following bugs:
    https://bugzilla.redhat.com/show_bug.cgi?id=1207095
    https://bugzilla.redhat.com/show_bug.cgi?id=1339680
    https://bugzilla.redhat.com/show_bug.cgi?id=1371039
    https://bugzilla.redhat.com/show_bug.cgi?id=1373849
    https://bugzilla.redhat.com/show_bug.cgi?id=1375524
    https://bugzilla.redhat.com/show_bug.cgi?id=1377913

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-22 15:40:09 +02:00
Jiri Denemark
7f127ded65 cpu: Rework cpuCompare* APIs
Both cpuCompare* APIs are renamed to virCPUCompare*. And they should now
work for any guest CPU definition, i.e., even for host-passthrough
(trivial) and host-model CPUs. The implementation in x86 driver is
enhanced to provide a hint about -noTSX Broadwell and Haswell models
when appropriate.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-22 15:40:09 +02:00
Jiri Denemark
46c49a3004 cpu: Rename cpuHasFeature to virCPUDataCheckFeature
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-22 15:40:09 +02:00
Jiri Denemark
3b6be3c0c5 cpu: Rework cpuUpdate
The reworked API is now called virCPUUpdate and it should change the
provided CPU definition into a one which can be consumed by the QEMU
command line builder:

    - host-passthrough remains unchanged
    - host-model is turned into custom CPU with a model and features
      copied from host
    - custom CPU with minimum match is converted similarly to host-model
    - optional features are updated according to host's CPU

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-22 15:40:09 +02:00
Jiri Denemark
803497a8ac qemu: Introduce virQEMUCapsIsCPUModeSupported
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-22 15:40:09 +02:00
Jiri Denemark
21dead6370 qemu: Introduce virQEMUCapsGetHostModel
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-22 15:40:08 +02:00
Jiri Denemark
14319c81a0 Show host model in domain capabilities
The domain capabilities XML is capable of showing whether each guest CPU
mode is supported or not with a possibility to provide additional
details. This patch enhances host-model capability to advertise the
exact CPU model which will be used as a host-model:

    <cpu>
        ...
        <mode name='host-model' supported='yes'>
            <model fallback='allow'>Broadwell</model>
            <vendor>Intel</vendor>
            <feature policy='disable' name='aes'/>
            <feature policy='require' name='vmx'/>
        </mode>
        ...
    </cpu>

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-22 15:40:08 +02:00
Jiri Denemark
68c7011856 qemu: Store host-model CPU in qemu capabilities
Host capabilities provide libvirt's view of the host CPU, but for a
useful support for host-model CPUs we really need a hypervisor's view of
the CPU. And since the view can be differ with emulator, qemu
capabilities is the best place to store the host CPU model.

This patch just copies the CPU model from host capabilities, but this
will change in the future.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-22 15:40:08 +02:00
Jiri Denemark
b27adaed37 qemu: Propagate virCapsPtr to virQEMUCapsNewForBinaryInternal
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-22 15:40:08 +02:00
Jiri Denemark
d4c007e6d5 domcaps: Add CPU usable flag
In case a hypervisor is able to tell us a list of supported CPU models
and whether each CPU models can be used on the current host, we can
propagate this to domain capabilities. This is a better alternative
to calling virConnectCompareCPU for each supported CPU model.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-22 15:40:08 +02:00
Jiri Denemark
33f9ccc141 domcaps: Show only CPU models supported by libvirt
Listing all CPU models supported by QEMU in domain capabilities makes
little sense when libvirt will refuse any model it doesn't know about.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-22 15:40:08 +02:00
Jiri Denemark
84d38307fe qemu: Fill in CPU domain capabilities
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-22 15:40:08 +02:00
Jiri Denemark
f2e71550d6 qemu: Introduce virQEMUCapsGuestIsNative
To have a single place where we decide whether a guest can run natively
on a host.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-22 15:40:08 +02:00
Jiri Denemark
e9634933ea qemu: Separate guest CPU validation from command line creation
qemu_command.c should deal with translating our domain definition into a
QEMU command line and nothing else.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-22 15:40:08 +02:00
Jiri Denemark
6bb5f0b218 qemuxml2argvtest: Properly initialize qemuCaps->arch
qemuCaps->arch should match the guest architecture from domain XML.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-22 15:40:08 +02:00
Jiri Denemark
d037d8006f qemu: Use virDomainCapsCPUModels for cpuDefinitions
The list of supported CPU models in domain capabilities is stored in
virDomainCapsCPUModels. Let's use the same object for storing CPU models
in QEMU capabilities.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-22 15:40:08 +02:00
Jiri Denemark
350e3fee0e cpuGetModels: Switch to virArch
Our internal APIs mostly use virArch rather than strings. Switching
cpuGetModels to virArch will save us from unnecessary conversions in the
future.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-22 15:40:08 +02:00
Pavel Hrdina
53e3f69b3c qemu_process: move graphics validation into separate function
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-09-21 23:14:10 +02:00
Chen Hanxiao
5853ea85dc qemu_process: show shutoff reasons when debug log disabled
We have a few of senarios that libvirtd would invoke qemuProcessStop
and leave a "shutting down" in /var/log/libvirt/qemu/$DOMAIN.log.

The shutoff reason showing in debug log is also very important
for us to know why VM shutting down in domain log,
as we seldom enable debug log of libvirtd.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
2016-09-21 17:03:24 -04:00
Peter Krempa
006a532cc0 qemu: driver: Don't return automatic NUMA emulator pinning data for persistentDef
Calling virDomainGetEmulatorPinInfo on a live VM with automatic NUMA
pinning and VIR_DOMAIN_AFFECT_CONFIG would return the automatic pinning
data in some cases which is bogus. Use the autoCpuset property only when
called on a live definition.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1365779
2016-09-21 16:32:36 +02:00
Peter Krempa
552892c59d qemu: driver: Don't return automatic NUMA vCPU pinning data for persistentDef
Calling virDomainGetVcpuPinInfo on a live VM with automatic NUMA pinning
and VIR_DOMAIN_AFFECT_CONFIG would return the automatic pinning data
in some cases which is bogus. Use the autoCpuset property only when
called on a live definition.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1365779
2016-09-21 16:32:36 +02:00
Peter Krempa
63aac8c299 qemu: domain: Add macro to simplify access to vm private data
Sometimes adding a separate variable to access vm->privateData is not
necessary. Add a macro that will do the typecasting rather than having
to add a temp variable to force the compiler to typecast it.
2016-09-21 16:32:36 +02:00
Jiri Denemark
2e164b451e qemu: Ignore graphics cookie if port == 0
Old libvirt represents

    <graphics type='spice'>
      <listen type='none'/>
    </graphics>

as

    <graphics type='spice' autoport='no'/>

In this mode, QEMU doesn't listen for SPICE connection anywhere and
clients have to use virDomainOpenGraphics* APIs to attach to the domain.
That is, the client has to run on the same host where the domains runs
and it's impossible to tell the client to reconnect to the destination
QEMU during migration (unless there is some kind of proxy on the host).

While current libvirt correctly ignores such graphics devices when
creating graphics migration cookie, old libvirt just sends

    <graphics type='spice' port='0' listen='0.0.0.0' tlsPort='-1'/>

in the cookie. After seeing this cookie, we happily would call
client_migrate_info QMP command and wait for SPICE_MIGRATE_COMPLETED
event, which is quite pointless since the doesn't know where to connecti
anyway. We should just ignore such cookies.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-21 14:11:26 +02:00
Jiri Denemark
53ae58b0ed qemuDomainOpenGraphics: Start job early
Checking if a domain's definition or if it is active before we got a job
is pointless since the domain might have changed in the meantime.

Luckily libvirtd didn't crash when the API tried to talk to an inactive
domain:

debug : qemuDomainObjBeginJobInternal:2914 : Started job: modify
    (async=none vm=0x7f8f340140c0 name=ble)
debug : qemuDomainObjEnterMonitorInternal:3137 : Entering monitor
    (mon=(nil) vm=0x7f8f340140c0 name=ble)
warning : virObjectLock:319 : Object (nil) ((unknown)) is not a
    virObjectLockable instance
debug : qemuMonitorOpenGraphics:3505 : protocol=spice fd=27
    fdname=graphicsfd skipauth=1
error : qemuMonitorOpenGraphics:3508 : invalid argument: monitor must
    not be NULL
debug : qemuDomainObjExitMonitorInternal:3160 : Exited monitor
    (mon=(nil) vm=0x7f8f340140c0 name=ble)
debug : qemuDomainObjEndJob:3068 : Stopping job: modify (async=none
    vm=0x7f8f340140c0 name=ble)

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-09-21 14:11:26 +02:00
Nikolay Shirokovskiy
6bff9c03c9 qemu: agent: give better error messages whe agent monitor is down
We can receive NULL as sync reply in two situations. First
is garbage sync reply and this situation is handled by
resending sync message. Second is different cases
of rebooting guest, destroing domain etc and we can
give more meaningful error message. Actually we have
this error message in qemuAgentCommand already which checks
for the same sitatuion. AFAIK case with mon->running
is just to be safe on adding some future(?) cases of
returning NULL reply.
2016-09-20 16:27:58 +02:00
Nikolay Shirokovskiy
3f90a1aac0 qemu: agent: reissue sync on garbage sync reply
We can easily handle receiving garbage on sync. We don't
have to make client deal with this situation. We just
need to resend sync command but this time garbage is
not be possible.
2016-09-20 16:27:58 +02:00
Nikolay Shirokovskiy
5e5019bf78 qemu: agent: skip outdated sync replies
When we wait for sync reply we can receive delayed
reply to syncs or commands that were sent erlier. We can
safely skip them until we receive sync reply with correct id.
There is no much sense report this situation to client.
Actually with a bit of "luck" if we involve client into
this the play can go on forever: send sync 0, receive
sync reply -1, send sync 1, receive reply 0 ...
2016-09-20 16:27:58 +02:00
Nikolay Shirokovskiy
832d48d790 qemu: agent: ignore garbage while waiting for sync reply
After sync is sent we can receive garbare and this is not error.
Consider next regular case:

1. libvirtd sends sync
2. qga sends partial sync reply and die
3. libvirtd sends sync
4. qga sends sync reply
5. libvirtd receives garbage
  (half of first reply and second reply together)

We should handle this situation as it is recoverable.
Next sync can succeed. Let's report reply is NULL,
it will be converted to the VIR_ERR_AGENT_UNSYNCED
which signals client to retry.
2016-09-20 16:27:58 +02:00
Nikolay Shirokovskiy
4fd25421e3 qemu: agent: ignore delayed reply when unsynced
Errors in qemuAgentIOProcessLine stop agent IO processing just
like any regular IO error, however some of current errors
that this functions spawns are false positives. Consider
next case for example:

1. send sync (unsynced state)
2. receive sync reply (sync established)
3. command send, but timeout occured (unsynced state)
4. receive command reply

Last IO triggers error because current code ignores
only delayed syncs when unsynced

We should not treat any delayed reply as error in unsynced
state. Until client and qga are not in sync delayed reply to any
command is possible. msg == NULL is the exact criterion
that we are not in sync.
2016-09-20 16:27:58 +02:00
Martin Kletzander
a9996a4599 qemu: Add qemuAssignDeviceShmemAlias and use it
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-09-20 15:42:43 +02:00
Martin Kletzander
a0c99e1a0a qemu: Rename qemuBuildShmemBackendStr to qemuBuildShmemBackendChrStr
There will be more backends in the future so let's not complicate it.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-09-20 15:42:43 +02:00
Martin Kletzander
0f61d7b5f2 qemu: Abstract shmem socket path preparation
Put it into qemuDomainPrepareShmemChardev() so it can be used later.
Also don't fill in the path unless the server option is enabled.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-09-20 15:42:43 +02:00
Martin Kletzander
6b5622e4b5 qemu: Reorder shmem params nicely
Always format id first so that we don't need to do that twice in
different code paths.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-09-20 15:42:43 +02:00
Martin Kletzander
9187cecc81 qemu: Move common checks outside qemuBuildShmemDevLegacyStr
Some checks will need to be performed for newer device types as well, so
let's not duplicate them.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-09-20 15:42:43 +02:00
Martin Kletzander
bf854ae3f1 qemu: Rename qemuBuildShmemDevStr to qemuBuildShmemDevLegacyStr
This will make sense after adding support for newer device types.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-09-20 15:42:43 +02:00
Martin Kletzander
c7e0a6a667 qemu: Make qemuBuildShmemDevStr static
It isn't used anywhere else.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-09-20 15:42:43 +02:00