conf: Introduce VIR_DOMAIN_LOADER_TYPE_NONE

This is going to extend virDomainLoader enum. The reason is that
once loader path is NULL its type makes no sense. However, since
value of zero corresponds to VIR_DOMAIN_LOADER_TYPE_ROM the
following XML would be produced:

  <os>
    <loader type='rom'/>
    ...
  </os>

To solve this, introduce VIR_DOMAIN_LOADER_TYPE_NONE which would
correspond to value of zero and then use post parse callback to
set the default loader type to 'rom' if needed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Michal Privoznik 2019-02-25 14:46:07 +01:00
parent cdd592553a
commit d21f89cc1a
5 changed files with 26 additions and 3 deletions

View File

@ -1059,6 +1059,7 @@ VIR_ENUM_IMPL(virDomainMemoryAllocation, VIR_DOMAIN_MEMORY_ALLOCATION_LAST,
VIR_ENUM_IMPL(virDomainLoader,
VIR_DOMAIN_LOADER_TYPE_LAST,
"none",
"rom",
"pflash",
);
@ -4305,6 +4306,20 @@ virDomainDefPostParseMemory(virDomainDefPtr def,
}
static void
virDomainDefPostParseOs(virDomainDefPtr def)
{
if (!def->os.loader)
return;
if (def->os.loader->path &&
def->os.loader->type == VIR_DOMAIN_LOADER_TYPE_NONE) {
/* By default, loader is type of 'rom' */
def->os.loader->type = VIR_DOMAIN_LOADER_TYPE_ROM;
}
}
static void
virDomainDefPostParseMemtune(virDomainDefPtr def)
{
@ -5480,6 +5495,8 @@ virDomainDefPostParseCommon(virDomainDefPtr def,
if (virDomainDefPostParseMemory(def, data->parseFlags) < 0)
return -1;
virDomainDefPostParseOs(def);
virDomainDefPostParseMemtune(def);
if (virDomainDefRejectDuplicateControllers(def) < 0)
@ -18280,7 +18297,7 @@ virDomainLoaderDefParseXML(xmlNodePtr node,
if (type_str) {
int type;
if ((type = virDomainLoaderTypeFromString(type_str)) < 0) {
if ((type = virDomainLoaderTypeFromString(type_str)) <= 0) {
virReportError(VIR_ERR_XML_DETAIL,
_("unknown type value: %s"), type_str);
return -1;
@ -27007,12 +27024,14 @@ virDomainLoaderDefFormat(virBufferPtr buf,
if (loader->secure)
virBufferAsprintf(buf, " secure='%s'", secure);
virBufferAsprintf(buf, " type='%s'", type);
if (loader->type != VIR_DOMAIN_LOADER_TYPE_NONE)
virBufferAsprintf(buf, " type='%s'", type);
if (loader->path)
virBufferEscapeString(buf, ">%s</loader>\n", loader->path);
else
virBufferAddLit(buf, "/>\n");
if (loader->nvram || loader->templt) {
virBufferAddLit(buf, "<nvram");
virBufferEscapeString(buf, " template='%s'", loader->templt);

View File

@ -1954,7 +1954,8 @@ struct _virDomainBIOSDef {
};
typedef enum {
VIR_DOMAIN_LOADER_TYPE_ROM = 0,
VIR_DOMAIN_LOADER_TYPE_NONE = 0,
VIR_DOMAIN_LOADER_TYPE_ROM,
VIR_DOMAIN_LOADER_TYPE_PFLASH,
VIR_DOMAIN_LOADER_TYPE_LAST

View File

@ -9967,6 +9967,7 @@ qemuBuildDomainLoaderCommandLine(virCommandPtr cmd,
}
break;
case VIR_DOMAIN_LOADER_TYPE_NONE:
case VIR_DOMAIN_LOADER_TYPE_LAST:
/* nada */
break;

View File

@ -12280,6 +12280,7 @@ qemuDomainSetupLoader(virQEMUDriverConfigPtr cfg ATTRIBUTE_UNUSED,
goto cleanup;
break;
case VIR_DOMAIN_LOADER_TYPE_NONE:
case VIR_DOMAIN_LOADER_TYPE_LAST:
break;
}

View File

@ -10,6 +10,7 @@
<value>/foo/bar</value>
<value>/tmp/my_path</value>
<enum name='type'>
<value>none</value>
<value>rom</value>
<value>pflash</value>
</enum>