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>
This commit is contained in:
Jiri Denemark 2016-06-15 16:45:47 +02:00
parent 10d0e6e9c8
commit 14319c81a0
13 changed files with 68 additions and 18 deletions

View File

@ -154,7 +154,12 @@
...
&lt;cpu&gt;
&lt;mode name='host-passthrough' supported='yes'/&gt;
&lt;mode name='host-model' supported='yes'/&gt;
&lt;mode name='host-model' supported='yes'&gt;
&lt;model fallback='allow'&gt;Broadwell&lt;/model&gt;
&lt;vendor&gt;Intel&lt;/vendor&gt;
&lt;feature policy='disable' name='aes'/&gt;
&lt;feature policy='require' name='vmx'/&gt;
&lt;/mode&gt;
&lt;mode name='custom' supported='yes'&gt;
&lt;model usable='no'&gt;Broadwell&lt;/model&gt;
&lt;model usable='yes'&gt;Broadwell-noTSX&lt;/model&gt;
@ -177,7 +182,19 @@
<dd>No mode specific details are provided.</dd>
<dt><code>host-model</code></dt>
<dd>No mode specific details are provided yet.</dd>
<dd>
If <code>host-model</code> is supported by the hypervisor, the
<code>mode</code> describes the guest CPU which will be used when
starting a domain with <code>host-model</code> CPU. The hypervisor
specifics (such as unsupported CPU models or features, machine type,
etc.) may be accounted for in this guest CPU specification and thus
the CPU can be different from the one shown in host capabilities XML.
This is indicated by the <code>fallback</code> attribute of the
<code>model</code> sub element: <code>allow</code> means not all
specifics were accounted for and thus the CPU a guest will see may
be different; <code>forbid</code> indicates that the CPU a guest will
see should match this CPU definition.
</dd>
<dt><code>custom</code></dt>
<dd>

View File

@ -2,6 +2,7 @@
<!-- A Relax NG schema for the libvirt domain capabilities XML format -->
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
<include href='basictypes.rng'/>
<include href='cputypes.rng'/>
<start>
<ref name='domainCapabilities'/>
</start>
@ -94,6 +95,15 @@
<value>host-model</value>
</attribute>
<ref name='supported'/>
<optional>
<ref name="cpuModel"/>
<optional>
<ref name="cpuVendor"/>
</optional>
<zeroOrMore>
<ref name="cpuFeature"/>
</zeroOrMore>
</optional>
</element>
</define>

View File

@ -402,9 +402,19 @@ virDomainCapsCPUFormat(virBufferPtr buf,
virCPUModeTypeToString(VIR_CPU_MODE_HOST_PASSTHROUGH),
cpu->hostPassthrough ? "yes" : "no");
virBufferAsprintf(buf, "<mode name='%s' supported='%s'/>\n",
virCPUModeTypeToString(VIR_CPU_MODE_HOST_MODEL),
cpu->hostModel ? "yes" : "no");
virBufferAsprintf(buf, "<mode name='%s' ",
virCPUModeTypeToString(VIR_CPU_MODE_HOST_MODEL));
if (cpu->hostModel) {
virBufferAddLit(buf, "supported='yes'>\n");
virBufferAdjustIndent(buf, 2);
virCPUDefFormatBuf(buf, cpu->hostModel, false);
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</mode>\n");
} else {
virBufferAddLit(buf, "supported='no'/>\n");
}
virBufferAsprintf(buf, "<mode name='%s' ",
virCPUModeTypeToString(VIR_CPU_MODE_CUSTOM));

View File

@ -132,7 +132,7 @@ typedef struct _virDomainCapsCPU virDomainCapsCPU;
typedef virDomainCapsCPU *virDomainCapsCPUPtr;
struct _virDomainCapsCPU {
bool hostPassthrough;
bool hostModel;
virCPUDefPtr hostModel;
virDomainCapsCPUModelsPtr custom;
};

View File

@ -4358,9 +4358,7 @@ virQEMUCapsFillDomainCPUCaps(virCapsPtr caps,
virQEMUCapsGuestIsNative(caps->host.arch, qemuCaps->arch))
domCaps->cpu.hostPassthrough = true;
if (qemuCaps->cpuDefinitions && caps->host.cpu)
domCaps->cpu.hostModel = virQEMUCapsGuestIsNative(caps->host.arch,
qemuCaps->arch);
domCaps->cpu.hostModel = virCPUDefCopy(qemuCaps->hostCPUModel);
if (qemuCaps->cpuDefinitions &&
cpuGetModels(domCaps->arch, &models) >= 0) {

View File

@ -21,7 +21,10 @@
</os>
<cpu>
<mode name='host-passthrough' supported='yes'/>
<mode name='host-model' supported='yes'/>
<mode name='host-model' supported='yes'>
<model>host</model>
<vendor>CPU Vendorrr</vendor>
</mode>
<mode name='custom' supported='yes'>
<model usable='unknown'>Model1</model>
<model usable='no'>Model2</model>

View File

@ -20,7 +20,9 @@
</os>
<cpu>
<mode name='host-passthrough' supported='yes'/>
<mode name='host-model' supported='yes'/>
<mode name='host-model' supported='yes'>
<model fallback='allow'>Broadwell</model>
</mode>
<mode name='custom' supported='yes'>
<model usable='unknown'>Opteron_G5</model>
<model usable='unknown'>Opteron_G4</model>

View File

@ -20,7 +20,7 @@
</os>
<cpu>
<mode name='host-passthrough' supported='yes'/>
<mode name='host-model' supported='yes'/>
<mode name='host-model' supported='no'/>
<mode name='custom' supported='yes'>
<model usable='unknown'>pxa262</model>
<model usable='unknown'>pxa270-a0</model>

View File

@ -20,7 +20,7 @@
</os>
<cpu>
<mode name='host-passthrough' supported='yes'/>
<mode name='host-model' supported='yes'/>
<mode name='host-model' supported='no'/>
<mode name='custom' supported='yes'>
<model usable='unknown'>pxa262</model>
<model usable='unknown'>pxa270-a0</model>

View File

@ -20,7 +20,7 @@
</os>
<cpu>
<mode name='host-passthrough' supported='yes'/>
<mode name='host-model' supported='yes'/>
<mode name='host-model' supported='no'/>
<mode name='custom' supported='yes'>
<model usable='unknown'>pxa262</model>
<model usable='unknown'>pxa270-a0</model>

View File

@ -20,7 +20,9 @@
</os>
<cpu>
<mode name='host-passthrough' supported='yes'/>
<mode name='host-model' supported='yes'/>
<mode name='host-model' supported='yes'>
<model fallback='allow'>POWER8</model>
</mode>
<mode name='custom' supported='yes'>
<model usable='unknown'>POWER8</model>
<model usable='unknown'>POWER7</model>

View File

@ -20,7 +20,9 @@
</os>
<cpu>
<mode name='host-passthrough' supported='yes'/>
<mode name='host-model' supported='yes'/>
<mode name='host-model' supported='yes'>
<model fallback='allow'>Broadwell</model>
</mode>
<mode name='custom' supported='yes'>
<model usable='unknown'>Opteron_G5</model>
<model usable='unknown'>Opteron_G4</model>

View File

@ -65,8 +65,14 @@ fillAllCaps(virDomainCapsPtr domCaps)
virDomainCapsDeviceGraphicsPtr graphics = &domCaps->graphics;
virDomainCapsDeviceVideoPtr video = &domCaps->video;
virDomainCapsDeviceHostdevPtr hostdev = &domCaps->hostdev;
domCaps->maxvcpus = 255;
virCPUDef host = {
VIR_CPU_TYPE_HOST, 0, 0,
VIR_ARCH_X86_64, (char *) "host",
NULL, 0, (char *) "CPU Vendorrr",
0, 0, 0, 0, 0, NULL,
};
domCaps->maxvcpus = 255;
os->supported = true;
loader->supported = true;
@ -79,7 +85,7 @@ fillAllCaps(virDomainCapsPtr domCaps)
return -1;
cpu->hostPassthrough = true;
cpu->hostModel = true;
cpu->hostModel = virCPUDefCopy(&host);
if (!(cpu->custom = virDomainCapsCPUModelsNew(3)) ||
virDomainCapsCPUModelsAdd(cpu->custom, "Model1", -1,
VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0 ||