mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-23 13:05:27 +00:00
conf: Parse firmware format
The default is raw, which corresponds to the historical behavior and is also the only accepted value, at least for now. Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
b3b81e60e4
commit
1a6469e81f
@ -3726,7 +3726,12 @@ virDomainPanicDefFree(virDomainPanicDef *panic)
|
||||
virDomainLoaderDef *
|
||||
virDomainLoaderDefNew(void)
|
||||
{
|
||||
return g_new0(virDomainLoaderDef, 1);
|
||||
virDomainLoaderDef *def = NULL;
|
||||
|
||||
def = g_new0(virDomainLoaderDef, 1);
|
||||
def->format = VIR_STORAGE_FILE_RAW;
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
void
|
||||
@ -16760,6 +16765,7 @@ virDomainLoaderDefParseXMLNvram(virDomainLoaderDef *loader,
|
||||
unsigned int flags)
|
||||
{
|
||||
g_autoptr(virStorageSource) src = virStorageSourceNew();
|
||||
unsigned int format = 0;
|
||||
int typePresent;
|
||||
|
||||
if (!nvramNode)
|
||||
@ -16767,7 +16773,18 @@ virDomainLoaderDefParseXMLNvram(virDomainLoaderDef *loader,
|
||||
|
||||
loader->nvramTemplate = virXMLPropString(nvramNode, "template");
|
||||
|
||||
src->format = VIR_STORAGE_FILE_RAW;
|
||||
if (virXMLPropEnumDefault(nvramNode, "format",
|
||||
virStorageFileFormatTypeFromString, VIR_XML_PROP_NONE,
|
||||
&format, VIR_STORAGE_FILE_RAW) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (format != VIR_STORAGE_FILE_RAW) {
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("Unsupported nvram format '%s'"),
|
||||
virStorageFileFormatTypeToString(format));
|
||||
return -1;
|
||||
}
|
||||
src->format = format;
|
||||
|
||||
if ((typePresent = virXMLPropEnum(nvramNode, "type",
|
||||
virStorageTypeFromString, VIR_XML_PROP_NONE,
|
||||
@ -16801,8 +16818,26 @@ static int
|
||||
virDomainLoaderDefParseXMLLoader(virDomainLoaderDef *loader,
|
||||
xmlNodePtr loaderNode)
|
||||
{
|
||||
if (!loaderNode)
|
||||
unsigned int format = 0;
|
||||
|
||||
if (!loaderNode) {
|
||||
/* If there is no <loader> element but the <nvram> element
|
||||
* was present, copy the format from the latter to the
|
||||
* former.
|
||||
*
|
||||
* This ensures that a configuration such as
|
||||
*
|
||||
* <os>
|
||||
* <nvram format='foo'/>
|
||||
* </os>
|
||||
*
|
||||
* behaves as expected, that is, results in a firmware build
|
||||
* with format 'foo' being selected */
|
||||
if (loader->nvram)
|
||||
loader->format = loader->nvram->format;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (virXMLPropTristateBool(loaderNode, "readonly", VIR_XML_PROP_NONE,
|
||||
&loader->readonly) < 0)
|
||||
@ -16826,6 +16861,19 @@ virDomainLoaderDefParseXMLLoader(virDomainLoaderDef *loader,
|
||||
&loader->stateless) < 0)
|
||||
return -1;
|
||||
|
||||
if (virXMLPropEnumDefault(loaderNode, "format",
|
||||
virStorageFileFormatTypeFromString, VIR_XML_PROP_NONE,
|
||||
&format, VIR_STORAGE_FILE_RAW) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (format != VIR_STORAGE_FILE_RAW) {
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("Unsupported loader format '%s'"),
|
||||
virStorageFileFormatTypeToString(format));
|
||||
return -1;
|
||||
}
|
||||
loader->format = format;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -16848,6 +16896,14 @@ virDomainLoaderDefParseXML(virDomainLoaderDef *loader,
|
||||
loaderNode) < 0)
|
||||
return -1;
|
||||
|
||||
if (loader->nvram && loader->format != loader->nvram->format) {
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("Format mismatch: loader.format='%s' nvram.format='%s'"),
|
||||
virStorageFileFormatTypeToString(loader->format),
|
||||
virStorageFileFormatTypeToString(loader->nvram->format));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -26179,6 +26235,11 @@ virDomainLoaderDefFormatNvram(virBuffer *buf,
|
||||
false, flags, false, false, xmlopt) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (src->format != VIR_STORAGE_FILE_RAW) {
|
||||
virBufferEscapeString(&attrBuf, " format='%s'",
|
||||
virStorageFileFormatTypeToString(src->format));
|
||||
}
|
||||
}
|
||||
|
||||
virXMLFormatElementInternal(buf, "nvram", &attrBuf, childBuf, false, childNewline);
|
||||
@ -26213,6 +26274,11 @@ virDomainLoaderDefFormat(virBuffer *buf,
|
||||
virTristateBoolTypeToString(loader->stateless));
|
||||
}
|
||||
|
||||
if (loader->format != VIR_STORAGE_FILE_RAW) {
|
||||
virBufferEscapeString(&loaderAttrBuf, " format='%s'",
|
||||
virStorageFileFormatTypeToString(loader->format));
|
||||
}
|
||||
|
||||
virBufferEscapeString(&loaderChildBuf, "%s", loader->path);
|
||||
|
||||
virXMLFormatElementInternal(buf, "loader", &loaderAttrBuf, &loaderChildBuf, false, false);
|
||||
|
@ -2311,6 +2311,7 @@ struct _virDomainLoaderDef {
|
||||
virDomainLoader type;
|
||||
virTristateBool secure;
|
||||
virTristateBool stateless;
|
||||
virStorageFileFormat format;
|
||||
virStorageSource *nvram;
|
||||
bool newStyleNVRAM;
|
||||
char *nvramTemplate; /* user override of path to master nvram */
|
||||
|
@ -349,6 +349,9 @@
|
||||
<ref name="virYesNo"/>
|
||||
</attribute>
|
||||
</optional>
|
||||
<optional>
|
||||
<ref name="pflashFormat"/>
|
||||
</optional>
|
||||
<optional>
|
||||
<ref name="absFilePath"/>
|
||||
</optional>
|
||||
@ -361,6 +364,9 @@
|
||||
<ref name="absFilePath"/>
|
||||
</attribute>
|
||||
</optional>
|
||||
<optional>
|
||||
<ref name="pflashFormat"/>
|
||||
</optional>
|
||||
<optional>
|
||||
<choice>
|
||||
<group>
|
||||
@ -7538,6 +7544,14 @@
|
||||
</element>
|
||||
</define>
|
||||
|
||||
<define name="pflashFormat">
|
||||
<attribute name="format">
|
||||
<choice>
|
||||
<value>raw</value>
|
||||
</choice>
|
||||
</attribute>
|
||||
</define>
|
||||
|
||||
<!-- Optional HyperV Enlightenment features -->
|
||||
<define name="hyperv">
|
||||
<element name="hyperv">
|
||||
|
Loading…
x
Reference in New Issue
Block a user