conf: pass default sec model in parser config

Instead of using the virCapsPtr to get the default security model,
pass this in via the parser config.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2019-11-26 18:57:30 +00:00
parent 99a949ffc4
commit 638ffa2228
6 changed files with 24 additions and 11 deletions

View File

@ -8919,13 +8919,12 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt,
static int static int
virSecurityLabelDefsParseXML(virDomainDefPtr def, virSecurityLabelDefsParseXML(virDomainDefPtr def,
xmlXPathContextPtr ctxt, xmlXPathContextPtr ctxt,
virCapsPtr caps, virDomainXMLOptionPtr xmlopt,
unsigned int flags) unsigned int flags)
{ {
VIR_XPATH_NODE_AUTORESTORE(ctxt); VIR_XPATH_NODE_AUTORESTORE(ctxt);
size_t i = 0, j; size_t i = 0, j;
int n; int n;
virCapsHostPtr host = &caps->host;
g_autofree xmlNodePtr *list = NULL; g_autofree xmlNodePtr *list = NULL;
/* Allocate a security labels based on XML */ /* Allocate a security labels based on XML */
@ -8968,15 +8967,16 @@ virSecurityLabelDefsParseXML(virDomainDefPtr def,
*/ */
if (def->nseclabels == 1 && if (def->nseclabels == 1 &&
!def->seclabels[0]->model && !def->seclabels[0]->model &&
host->nsecModels > 0) { xmlopt != NULL &&
xmlopt->config.defSecModel != NULL) {
if (def->seclabels[0]->type == VIR_DOMAIN_SECLABEL_NONE || if (def->seclabels[0]->type == VIR_DOMAIN_SECLABEL_NONE ||
(def->seclabels[0]->type == VIR_DOMAIN_SECLABEL_DYNAMIC && (def->seclabels[0]->type == VIR_DOMAIN_SECLABEL_DYNAMIC &&
!def->seclabels[0]->baselabel && !def->seclabels[0]->baselabel &&
(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))) { (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))) {
/* Copy model from host. */ /* Copy model from host. */
VIR_DEBUG("Found seclabel without a model, using '%s'", VIR_DEBUG("Found seclabel without a model, using '%s'",
host->secModels[0].model); xmlopt->config.defSecModel);
def->seclabels[0]->model = g_strdup(host->secModels[0].model); def->seclabels[0]->model = g_strdup(xmlopt->config.defSecModel);
if (STREQ(def->seclabels[0]->model, "none") && if (STREQ(def->seclabels[0]->model, "none") &&
flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) { flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) {
@ -19781,7 +19781,7 @@ virDomainMemorytuneDefParse(virDomainDefPtr def,
static virDomainDefPtr static virDomainDefPtr
virDomainDefParseXML(xmlDocPtr xml, virDomainDefParseXML(xmlDocPtr xml,
xmlXPathContextPtr ctxt, xmlXPathContextPtr ctxt,
virCapsPtr caps, virCapsPtr caps G_GNUC_UNUSED,
virDomainXMLOptionPtr xmlopt, virDomainXMLOptionPtr xmlopt,
unsigned int flags) unsigned int flags)
{ {
@ -19889,7 +19889,7 @@ virDomainDefParseXML(xmlDocPtr xml,
/* analysis of security label, done early even though we format it /* analysis of security label, done early even though we format it
* late, so devices can refer to this for defaults */ * late, so devices can refer to this for defaults */
if (!(flags & VIR_DOMAIN_DEF_PARSE_SKIP_SECLABEL)) { if (!(flags & VIR_DOMAIN_DEF_PARSE_SKIP_SECLABEL)) {
if (virSecurityLabelDefsParseXML(def, ctxt, caps, flags) == -1) if (virSecurityLabelDefsParseXML(def, ctxt, xmlopt, flags) == -1)
goto error; goto error;
} }

View File

@ -2707,6 +2707,7 @@ struct _virDomainDefParserConfig {
unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN]; unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN];
virArch defArch; virArch defArch;
const char *netPrefix; const char *netPrefix;
const char *defSecModel;
}; };
typedef void *(*virDomainXMLPrivateDataAllocFunc)(void *); typedef void *(*virDomainXMLPrivateDataAllocFunc)(void *);

View File

@ -1191,9 +1191,11 @@ virQEMUDriverIsPrivileged(virQEMUDriverPtr driver)
} }
virDomainXMLOptionPtr virDomainXMLOptionPtr
virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver) virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver,
const char *defsecmodel)
{ {
virQEMUDriverDomainDefParserConfig.priv = driver; virQEMUDriverDomainDefParserConfig.priv = driver;
virQEMUDriverDomainDefParserConfig.defSecModel = defsecmodel;
return virDomainXMLOptionNew(&virQEMUDriverDomainDefParserConfig, return virDomainXMLOptionNew(&virQEMUDriverDomainDefParserConfig,
&virQEMUDriverPrivateDataCallbacks, &virQEMUDriverPrivateDataCallbacks,
&virQEMUDriverDomainXMLNamespace, &virQEMUDriverDomainXMLNamespace,

View File

@ -366,7 +366,8 @@ int qemuRemoveSharedDisk(virQEMUDriverPtr driver,
int qemuSetUnprivSGIO(virDomainDeviceDefPtr dev); int qemuSetUnprivSGIO(virDomainDeviceDefPtr dev);
int qemuDriverAllocateID(virQEMUDriverPtr driver); int qemuDriverAllocateID(virQEMUDriverPtr driver);
virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver); virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver,
const char *defsecmodel);
int qemuTranslateSnapshotDiskSourcePool(virDomainSnapshotDiskDefPtr def); int qemuTranslateSnapshotDiskSourcePool(virDomainSnapshotDiskDefPtr def);

View File

@ -656,6 +656,8 @@ qemuStateInitialize(bool privileged,
g_autofree char *memoryBackingPath = NULL; g_autofree char *memoryBackingPath = NULL;
bool autostart = true; bool autostart = true;
size_t i; size_t i;
const char *defsecmodel = NULL;
g_autofree virSecurityManagerPtr *sec_managers = NULL;
if (VIR_ALLOC(qemu_driver) < 0) if (VIR_ALLOC(qemu_driver) < 0)
return VIR_DRV_STATE_INIT_ERROR; return VIR_DRV_STATE_INIT_ERROR;
@ -916,7 +918,14 @@ qemuStateInitialize(bool privileged,
if ((qemu_driver->caps = virQEMUDriverCreateCapabilities(qemu_driver)) == NULL) if ((qemu_driver->caps = virQEMUDriverCreateCapabilities(qemu_driver)) == NULL)
goto error; goto error;
if (!(qemu_driver->xmlopt = virQEMUDriverCreateXMLConf(qemu_driver))) if (!(sec_managers = qemuSecurityGetNested(qemu_driver->securityManager)))
goto error;
if (sec_managers[0] != NULL)
defsecmodel = qemuSecurityGetModel(sec_managers[0]);
if (!(qemu_driver->xmlopt = virQEMUDriverCreateXMLConf(qemu_driver,
defsecmodel)))
goto error; goto error;
/* If hugetlbfs is present, then we need to create a sub-directory within /* If hugetlbfs is present, then we need to create a sub-directory within

View File

@ -402,7 +402,7 @@ int qemuTestDriverInit(virQEMUDriver *driver)
if (!driver->qemuCapsCache) if (!driver->qemuCapsCache)
goto error; goto error;
driver->xmlopt = virQEMUDriverCreateXMLConf(driver); driver->xmlopt = virQEMUDriverCreateXMLConf(driver, "none");
if (!driver->xmlopt) if (!driver->xmlopt)
goto error; goto error;