conf: do not count per-device boot elements when parsing <os><boot>

When parsing bootable devices, we maintain a bitmap of used
<boot order=""> elements. Use it in the post-parse function
to figure out whether the user tried to mix per-device and
per-domain boot elements.

This removes the need to count them twice.
This commit is contained in:
Ján Tomko 2017-08-18 17:55:54 +02:00
parent 4b759a4041
commit a530078cd2

View File

@ -4784,7 +4784,8 @@ virDomainDefPostParseCPU(virDomainDefPtr def)
static int static int
virDomainDefPostParseCommon(virDomainDefPtr def, virDomainDefPostParseCommon(virDomainDefPtr def,
struct virDomainDefPostParseDeviceIteratorData *data) struct virDomainDefPostParseDeviceIteratorData *data,
virHashTablePtr bootHash)
{ {
/* verify init path for container based domains */ /* verify init path for container based domains */
if (def->os.type == VIR_DOMAIN_OSTYPE_EXE && !def->os.init) { if (def->os.type == VIR_DOMAIN_OSTYPE_EXE && !def->os.init) {
@ -4793,6 +4794,20 @@ virDomainDefPostParseCommon(virDomainDefPtr def,
return -1; return -1;
} }
if (def->os.type == VIR_DOMAIN_OSTYPE_HVM && bootHash) {
if (def->os.nBootDevs > 0 && virHashSize(bootHash) > 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("per-device boot elements cannot be used"
" together with os/boot elements"));
return -1;
}
if (def->os.nBootDevs == 0 && virHashSize(bootHash) == 0) {
def->os.nBootDevs = 1;
def->os.bootDevs[0] = VIR_DOMAIN_BOOT_DISK;
}
}
if (virDomainVcpuDefPostParse(def) < 0) if (virDomainVcpuDefPostParse(def) < 0)
return -1; return -1;
@ -4861,7 +4876,8 @@ virDomainDefPostParseInternal(virDomainDefPtr def,
virCapsPtr caps, virCapsPtr caps,
unsigned int parseFlags, unsigned int parseFlags,
virDomainXMLOptionPtr xmlopt, virDomainXMLOptionPtr xmlopt,
void *parseOpaque) void *parseOpaque,
virHashTablePtr bootHash)
{ {
int ret = -1; int ret = -1;
bool localParseOpaque = false; bool localParseOpaque = false;
@ -4917,7 +4933,7 @@ virDomainDefPostParseInternal(virDomainDefPtr def,
if (virDomainDefPostParseCheckFailure(def, parseFlags, ret) < 0) if (virDomainDefPostParseCheckFailure(def, parseFlags, ret) < 0)
goto cleanup; goto cleanup;
if ((ret = virDomainDefPostParseCommon(def, &data)) < 0) if ((ret = virDomainDefPostParseCommon(def, &data, bootHash)) < 0)
goto cleanup; goto cleanup;
if (xmlopt->config.assignAddressesCallback) { if (xmlopt->config.assignAddressesCallback) {
@ -4952,7 +4968,7 @@ virDomainDefPostParse(virDomainDefPtr def,
void *parseOpaque) void *parseOpaque)
{ {
return virDomainDefPostParseInternal(def, caps, parseFlags, xmlopt, return virDomainDefPostParseInternal(def, caps, parseFlags, xmlopt,
parseOpaque); parseOpaque, NULL);
} }
@ -16265,28 +16281,11 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt,
int n; int n;
char *tmp = NULL; char *tmp = NULL;
int ret = -1; int ret = -1;
unsigned long deviceBoot;
if (virXPathULong("count(./devices/disk[boot]"
"|./devices/interface[boot]"
"|./devices/hostdev[boot]"
"|./devices/redirdev[boot])", ctxt, &deviceBoot) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot count boot devices"));
goto cleanup;
}
/* analysis of the boot devices */ /* analysis of the boot devices */
if ((n = virXPathNodeSet("./os/boot", ctxt, &nodes)) < 0) if ((n = virXPathNodeSet("./os/boot", ctxt, &nodes)) < 0)
goto cleanup; goto cleanup;
if (n > 0 && deviceBoot) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("per-device boot elements cannot be used"
" together with os/boot elements"));
goto cleanup;
}
for (i = 0; i < n && i < VIR_DOMAIN_BOOT_LAST; i++) { for (i = 0; i < n && i < VIR_DOMAIN_BOOT_LAST; i++) {
int val; int val;
char *dev = virXMLPropString(nodes[i], "dev"); char *dev = virXMLPropString(nodes[i], "dev");
@ -16305,10 +16304,6 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt,
VIR_FREE(dev); VIR_FREE(dev);
def->os.bootDevs[def->os.nBootDevs++] = val; def->os.bootDevs[def->os.nBootDevs++] = val;
} }
if (def->os.nBootDevs == 0 && !deviceBoot) {
def->os.nBootDevs = 1;
def->os.bootDevs[0] = VIR_DOMAIN_BOOT_DISK;
}
if ((node = virXPathNode("./os/bootmenu[1]", ctxt))) { if ((node = virXPathNode("./os/bootmenu[1]", ctxt))) {
tmp = virXMLPropString(node, "enable"); tmp = virXMLPropString(node, "enable");
@ -19077,7 +19072,8 @@ virDomainDefParseXML(xmlDocPtr xml,
goto error; goto error;
/* callback to fill driver specific domain aspects */ /* callback to fill driver specific domain aspects */
if (virDomainDefPostParse(def, caps, flags, xmlopt, parseOpaque) < 0) if (virDomainDefPostParseInternal(def, caps, flags, xmlopt, parseOpaque,
bootHash) < 0)
goto error; goto error;
/* valdiate configuration */ /* valdiate configuration */