mirror of https://gitee.com/openkylin/libvirt.git
conf: don't use passed in caps in post parse method
To enable the virCapsPtr parameter to the post parse method to be eliminated, the drivers must fetch the virCapsPtr from their own driver via the opaque parameter, or use an alternative approach to validate the parsed data. Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
2578d74aee
commit
4a4132b462
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
|
#include "bhyve_driver.h"
|
||||||
#include "bhyve_conf.h"
|
#include "bhyve_conf.h"
|
||||||
#include "bhyve_device.h"
|
#include "bhyve_device.h"
|
||||||
#include "bhyve_domain.h"
|
#include "bhyve_domain.h"
|
||||||
|
@ -74,11 +75,16 @@ bhyveDomainDefNeedsISAController(virDomainDefPtr def)
|
||||||
|
|
||||||
static int
|
static int
|
||||||
bhyveDomainDefPostParse(virDomainDefPtr def,
|
bhyveDomainDefPostParse(virDomainDefPtr def,
|
||||||
virCapsPtr caps,
|
virCapsPtr _caps G_GNUC_UNUSED,
|
||||||
unsigned int parseFlags G_GNUC_UNUSED,
|
unsigned int parseFlags G_GNUC_UNUSED,
|
||||||
void *opaque G_GNUC_UNUSED,
|
void *opaque,
|
||||||
void *parseOpaque G_GNUC_UNUSED)
|
void *parseOpaque G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
|
bhyveConnPtr driver = opaque;
|
||||||
|
g_autoptr(virCaps) caps = bhyveDriverGetCapabilities(driver);
|
||||||
|
if (!caps)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (!virCapabilitiesDomainSupported(caps, def->os.type,
|
if (!virCapabilitiesDomainSupported(caps, def->os.type,
|
||||||
def->os.arch,
|
def->os.arch,
|
||||||
def->virtType))
|
def->virtType))
|
||||||
|
|
|
@ -928,7 +928,7 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
|
||||||
if (!priv->caps)
|
if (!priv->caps)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(priv->xmlopt = virVMXDomainXMLConfInit()))
|
if (!(priv->xmlopt = virVMXDomainXMLConfInit(priv->caps)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
conn->privateData = priv;
|
conn->privateData = priv;
|
||||||
|
|
|
@ -2470,8 +2470,9 @@ libxlBuildDomainConfig(virPortAllocatorRangePtr graphicsports,
|
||||||
}
|
}
|
||||||
|
|
||||||
virDomainXMLOptionPtr
|
virDomainXMLOptionPtr
|
||||||
libxlCreateXMLConf(void)
|
libxlCreateXMLConf(libxlDriverPrivatePtr driver)
|
||||||
{
|
{
|
||||||
|
libxlDomainDefParserConfig.priv = driver;
|
||||||
return virDomainXMLOptionNew(&libxlDomainDefParserConfig,
|
return virDomainXMLOptionNew(&libxlDomainDefParserConfig,
|
||||||
&libxlDomainXMLPrivateDataCallbacks,
|
&libxlDomainXMLPrivateDataCallbacks,
|
||||||
NULL, NULL, NULL);
|
NULL, NULL, NULL);
|
||||||
|
|
|
@ -207,7 +207,7 @@ libxlMakeUSB(virDomainHostdevDefPtr hostdev, libxl_device_usbdev *usbdev);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
virDomainXMLOptionPtr
|
virDomainXMLOptionPtr
|
||||||
libxlCreateXMLConf(void);
|
libxlCreateXMLConf(libxlDriverPrivatePtr driver);
|
||||||
|
|
||||||
#ifdef LIBXL_HAVE_DEVICE_CHANNEL
|
#ifdef LIBXL_HAVE_DEVICE_CHANNEL
|
||||||
# define LIBXL_ATTR_UNUSED
|
# define LIBXL_ATTR_UNUSED
|
||||||
|
|
|
@ -367,12 +367,15 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
|
||||||
|
|
||||||
static int
|
static int
|
||||||
libxlDomainDefPostParse(virDomainDefPtr def,
|
libxlDomainDefPostParse(virDomainDefPtr def,
|
||||||
virCapsPtr caps,
|
virCapsPtr caps G_GNUC_UNUSED,
|
||||||
unsigned int parseFlags G_GNUC_UNUSED,
|
unsigned int parseFlags G_GNUC_UNUSED,
|
||||||
void *opaque G_GNUC_UNUSED,
|
void *opaque,
|
||||||
void *parseOpaque G_GNUC_UNUSED)
|
void *parseOpaque G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
if (!virCapabilitiesDomainSupported(caps, def->os.type,
|
libxlDriverPrivatePtr driver = opaque;
|
||||||
|
g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
|
||||||
|
|
||||||
|
if (!virCapabilitiesDomainSupported(cfg->caps, def->os.type,
|
||||||
def->os.arch,
|
def->os.arch,
|
||||||
def->virtType))
|
def->virtType))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -769,7 +769,7 @@ libxlStateInitialize(bool privileged,
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(libxl_driver->xmlopt = libxlCreateXMLConf()))
|
if (!(libxl_driver->xmlopt = libxlCreateXMLConf(libxl_driver)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/* Add Domain-0 */
|
/* Add Domain-0 */
|
||||||
|
|
|
@ -207,8 +207,9 @@ virCapsPtr virLXCDriverGetCapabilities(virLXCDriverPtr driver,
|
||||||
|
|
||||||
|
|
||||||
virDomainXMLOptionPtr
|
virDomainXMLOptionPtr
|
||||||
lxcDomainXMLConfInit(void)
|
lxcDomainXMLConfInit(virLXCDriverPtr driver)
|
||||||
{
|
{
|
||||||
|
virLXCDriverDomainDefParserConfig.priv = driver;
|
||||||
return virDomainXMLOptionNew(&virLXCDriverDomainDefParserConfig,
|
return virDomainXMLOptionNew(&virLXCDriverDomainDefParserConfig,
|
||||||
&virLXCDriverPrivateDataCallbacks,
|
&virLXCDriverPrivateDataCallbacks,
|
||||||
&virLXCDriverDomainXMLNamespace,
|
&virLXCDriverDomainXMLNamespace,
|
||||||
|
|
|
@ -112,7 +112,7 @@ int virLXCLoadDriverConfig(virLXCDriverConfigPtr cfg,
|
||||||
virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver);
|
virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver);
|
||||||
virCapsPtr virLXCDriverGetCapabilities(virLXCDriverPtr driver,
|
virCapsPtr virLXCDriverGetCapabilities(virLXCDriverPtr driver,
|
||||||
bool refresh);
|
bool refresh);
|
||||||
virDomainXMLOptionPtr lxcDomainXMLConfInit(void);
|
virDomainXMLOptionPtr lxcDomainXMLConfInit(virLXCDriverPtr driver);
|
||||||
|
|
||||||
static inline void lxcDriverLock(virLXCDriverPtr driver)
|
static inline void lxcDriverLock(virLXCDriverPtr driver)
|
||||||
{
|
{
|
||||||
|
|
|
@ -159,11 +159,41 @@ static void virLXCControllerQuitTimer(int timer G_GNUC_UNUSED, void *opaque)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static virLXCDriverPtr
|
||||||
|
virLXCControllerDriverNew(void)
|
||||||
|
{
|
||||||
|
virLXCDriverPtr driver = g_new0(virLXCDriver, 1);
|
||||||
|
|
||||||
|
if (virMutexInit(&driver->lock) < 0) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"%s", _("cannot initialize mutex"));
|
||||||
|
g_free(driver);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
driver->caps = virLXCDriverCapsInit(NULL);
|
||||||
|
driver->xmlopt = lxcDomainXMLConfInit(driver);
|
||||||
|
|
||||||
|
return driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
virLXCControllerDriverFree(virLXCDriverPtr driver)
|
||||||
|
{
|
||||||
|
if (!driver)
|
||||||
|
return;
|
||||||
|
virObjectUnref(driver->xmlopt);
|
||||||
|
virObjectUnref(driver->caps);
|
||||||
|
virMutexDestroy(&driver->lock);
|
||||||
|
g_free(driver);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static virLXCControllerPtr virLXCControllerNew(const char *name)
|
static virLXCControllerPtr virLXCControllerNew(const char *name)
|
||||||
{
|
{
|
||||||
virLXCControllerPtr ctrl = NULL;
|
virLXCControllerPtr ctrl = NULL;
|
||||||
virCapsPtr caps = NULL;
|
virLXCDriverPtr driver = NULL;
|
||||||
virDomainXMLOptionPtr xmlopt = NULL;
|
|
||||||
char *configFile = NULL;
|
char *configFile = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(ctrl) < 0)
|
if (VIR_ALLOC(ctrl) < 0)
|
||||||
|
@ -174,10 +204,7 @@ static virLXCControllerPtr virLXCControllerNew(const char *name)
|
||||||
|
|
||||||
ctrl->name = g_strdup(name);
|
ctrl->name = g_strdup(name);
|
||||||
|
|
||||||
if (!(caps = virLXCDriverCapsInit(NULL)))
|
if (!(driver = virLXCControllerDriverNew()))
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (!(xmlopt = lxcDomainXMLConfInit()))
|
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if ((configFile = virDomainConfigFile(LXC_STATE_DIR,
|
if ((configFile = virDomainConfigFile(LXC_STATE_DIR,
|
||||||
|
@ -185,7 +212,7 @@ static virLXCControllerPtr virLXCControllerNew(const char *name)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if ((ctrl->vm = virDomainObjParseFile(configFile,
|
if ((ctrl->vm = virDomainObjParseFile(configFile,
|
||||||
caps, xmlopt,
|
driver->caps, driver->xmlopt,
|
||||||
0)) == NULL)
|
0)) == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
ctrl->def = ctrl->vm->def;
|
ctrl->def = ctrl->vm->def;
|
||||||
|
@ -197,8 +224,7 @@ static virLXCControllerPtr virLXCControllerNew(const char *name)
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(configFile);
|
VIR_FREE(configFile);
|
||||||
virObjectUnref(caps);
|
virLXCControllerDriverFree(driver);
|
||||||
virObjectUnref(xmlopt);
|
|
||||||
return ctrl;
|
return ctrl;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
|
|
@ -351,11 +351,15 @@ virDomainXMLPrivateDataCallbacks virLXCDriverPrivateDataCallbacks = {
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virLXCDomainDefPostParse(virDomainDefPtr def,
|
virLXCDomainDefPostParse(virDomainDefPtr def,
|
||||||
virCapsPtr caps,
|
virCapsPtr _caps G_GNUC_UNUSED,
|
||||||
unsigned int parseFlags G_GNUC_UNUSED,
|
unsigned int parseFlags G_GNUC_UNUSED,
|
||||||
void *opaque G_GNUC_UNUSED,
|
void *opaque,
|
||||||
void *parseOpaque G_GNUC_UNUSED)
|
void *parseOpaque G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
|
virLXCDriverPtr driver = opaque;
|
||||||
|
g_autoptr(virCaps) caps = virLXCDriverGetCapabilities(driver, false);
|
||||||
|
if (!caps)
|
||||||
|
return -1;
|
||||||
if (!virCapabilitiesDomainSupported(caps, def->os.type,
|
if (!virCapabilitiesDomainSupported(caps, def->os.type,
|
||||||
def->os.arch,
|
def->os.arch,
|
||||||
def->virtType))
|
def->virtType))
|
||||||
|
|
|
@ -1584,7 +1584,7 @@ static int lxcStateInitialize(bool privileged,
|
||||||
if (!(caps = virLXCDriverGetCapabilities(lxc_driver, true)))
|
if (!(caps = virLXCDriverGetCapabilities(lxc_driver, true)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(lxc_driver->xmlopt = lxcDomainXMLConfInit()))
|
if (!(lxc_driver->xmlopt = lxcDomainXMLConfInit(lxc_driver)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(lxc_driver->closeCallbacks = virCloseCallbacksNew()))
|
if (!(lxc_driver->closeCallbacks = virCloseCallbacksNew()))
|
||||||
|
|
|
@ -1082,12 +1082,13 @@ int openvzGetVEID(const char *name)
|
||||||
|
|
||||||
static int
|
static int
|
||||||
openvzDomainDefPostParse(virDomainDefPtr def,
|
openvzDomainDefPostParse(virDomainDefPtr def,
|
||||||
virCapsPtr caps,
|
virCapsPtr caps G_GNUC_UNUSED,
|
||||||
unsigned int parseFlags G_GNUC_UNUSED,
|
unsigned int parseFlags G_GNUC_UNUSED,
|
||||||
void *opaque G_GNUC_UNUSED,
|
void *opaque,
|
||||||
void *parseOpaque G_GNUC_UNUSED)
|
void *parseOpaque G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
if (!virCapabilitiesDomainSupported(caps, def->os.type,
|
struct openvz_driver *driver = opaque;
|
||||||
|
if (!virCapabilitiesDomainSupported(driver->caps, def->os.type,
|
||||||
def->os.arch,
|
def->os.arch,
|
||||||
def->virtType))
|
def->virtType))
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1133,8 +1134,9 @@ virDomainDefParserConfig openvzDomainDefParserConfig = {
|
||||||
.features = VIR_DOMAIN_DEF_FEATURE_NAME_SLASH,
|
.features = VIR_DOMAIN_DEF_FEATURE_NAME_SLASH,
|
||||||
};
|
};
|
||||||
|
|
||||||
virDomainXMLOptionPtr openvzXMLOption(void)
|
virDomainXMLOptionPtr openvzXMLOption(struct openvz_driver *driver)
|
||||||
{
|
{
|
||||||
|
openvzDomainDefParserConfig.priv = driver;
|
||||||
return virDomainXMLOptionNew(&openvzDomainDefParserConfig,
|
return virDomainXMLOptionNew(&openvzDomainDefParserConfig,
|
||||||
NULL, NULL, NULL, NULL);
|
NULL, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,4 +63,4 @@ int strtoI(const char *str);
|
||||||
int openvzSetDefinedUUID(int vpsid, unsigned char *uuid);
|
int openvzSetDefinedUUID(int vpsid, unsigned char *uuid);
|
||||||
int openvzGetVEID(const char *name);
|
int openvzGetVEID(const char *name);
|
||||||
int openvzReadNetworkConf(virDomainDefPtr def, int veid);
|
int openvzReadNetworkConf(virDomainDefPtr def, int veid);
|
||||||
virDomainXMLOptionPtr openvzXMLOption(void);
|
virDomainXMLOptionPtr openvzXMLOption(struct openvz_driver *driver);
|
||||||
|
|
|
@ -1311,7 +1311,7 @@ static virDrvOpenStatus openvzConnectOpen(virConnectPtr conn,
|
||||||
if (!(driver->caps = openvzCapsInit()))
|
if (!(driver->caps = openvzCapsInit()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(driver->xmlopt = openvzXMLOption()))
|
if (!(driver->xmlopt = openvzXMLOption(driver)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (openvzLoadDomains(driver) < 0)
|
if (openvzLoadDomains(driver) < 0)
|
||||||
|
|
|
@ -1062,12 +1062,13 @@ openSSHSession(virConnectPtr conn, virConnectAuthPtr auth,
|
||||||
|
|
||||||
static int
|
static int
|
||||||
phypDomainDefPostParse(virDomainDefPtr def,
|
phypDomainDefPostParse(virDomainDefPtr def,
|
||||||
virCapsPtr caps,
|
virCapsPtr caps G_GNUC_UNUSED,
|
||||||
unsigned int parseFlags G_GNUC_UNUSED,
|
unsigned int parseFlags G_GNUC_UNUSED,
|
||||||
void *opaque G_GNUC_UNUSED,
|
void *opaque,
|
||||||
void *parseOpaque G_GNUC_UNUSED)
|
void *parseOpaque G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
if (!virCapabilitiesDomainSupported(caps, def->os.type,
|
phyp_driverPtr driver = opaque;
|
||||||
|
if (!virCapabilitiesDomainSupported(driver->caps, def->os.type,
|
||||||
def->os.arch,
|
def->os.arch,
|
||||||
def->virtType))
|
def->virtType))
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1157,6 +1158,7 @@ phypConnectOpen(virConnectPtr conn,
|
||||||
if ((phyp_driver->caps = phypCapsInit()) == NULL)
|
if ((phyp_driver->caps = phypCapsInit()) == NULL)
|
||||||
goto failure;
|
goto failure;
|
||||||
|
|
||||||
|
virPhypDriverDomainDefParserConfig.priv = phyp_driver;
|
||||||
if (!(phyp_driver->xmlopt = virDomainXMLOptionNew(&virPhypDriverDomainDefParserConfig,
|
if (!(phyp_driver->xmlopt = virDomainXMLOptionNew(&virPhypDriverDomainDefParserConfig,
|
||||||
NULL, NULL, NULL, NULL)))
|
NULL, NULL, NULL, NULL)))
|
||||||
goto failure;
|
goto failure;
|
||||||
|
|
|
@ -2094,6 +2094,44 @@ virQEMUCapsSetHostModel(virQEMUCapsPtr qemuCaps,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
virQEMUCapsIsArchSupported(virQEMUCapsPtr qemuCaps,
|
||||||
|
virArch arch)
|
||||||
|
{
|
||||||
|
if (arch == qemuCaps->arch)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (qemuCaps->arch == VIR_ARCH_X86_64 && arch == VIR_ARCH_I686)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (qemuCaps->arch == VIR_ARCH_AARCH64 && arch == VIR_ARCH_ARMV7L)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (qemuCaps->arch == VIR_ARCH_ARMV7L && arch == VIR_ARCH_ARMV6L)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (qemuCaps->arch == VIR_ARCH_PPC64 && arch == VIR_ARCH_PPC64LE)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
virQEMUCapsIsVirtTypeSupported(virQEMUCapsPtr qemuCaps,
|
||||||
|
virDomainVirtType virtType)
|
||||||
|
{
|
||||||
|
if (virtType == VIR_DOMAIN_VIRT_QEMU)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (virtType == VIR_DOMAIN_VIRT_KVM &&
|
||||||
|
virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
|
virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
|
||||||
virArch hostarch,
|
virArch hostarch,
|
||||||
|
|
|
@ -603,6 +603,10 @@ int virQEMUCapsGetCPUFeatures(virQEMUCapsPtr qemuCaps,
|
||||||
bool migratable,
|
bool migratable,
|
||||||
char ***features);
|
char ***features);
|
||||||
|
|
||||||
|
bool virQEMUCapsIsArchSupported(virQEMUCapsPtr qemuCaps,
|
||||||
|
virArch arch);
|
||||||
|
bool virQEMUCapsIsVirtTypeSupported(virQEMUCapsPtr qemuCaps,
|
||||||
|
virDomainVirtType virtType);
|
||||||
bool virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
|
bool virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
|
||||||
virArch hostarch,
|
virArch hostarch,
|
||||||
virDomainVirtType type,
|
virDomainVirtType type,
|
||||||
|
|
|
@ -4691,22 +4691,40 @@ qemuDomainDefPostParseBasic(virDomainDefPtr def,
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuDomainDefPostParse(virDomainDefPtr def,
|
qemuDomainDefPostParse(virDomainDefPtr def,
|
||||||
virCapsPtr caps,
|
virCapsPtr caps G_GNUC_UNUSED,
|
||||||
unsigned int parseFlags,
|
unsigned int parseFlags,
|
||||||
void *opaque,
|
void *opaque,
|
||||||
void *parseOpaque)
|
void *parseOpaque G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virQEMUDriverPtr driver = opaque;
|
virQEMUDriverPtr driver = opaque;
|
||||||
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
||||||
/* Note that qemuCaps may be NULL when this function is called. This
|
g_autoptr(virQEMUCaps) qemuCaps = NULL;
|
||||||
* function shall not fail in that case. It will be re-run on VM startup
|
|
||||||
* with the capabilities populated. */
|
|
||||||
virQEMUCapsPtr qemuCaps = parseOpaque;
|
|
||||||
|
|
||||||
if (!virCapabilitiesDomainSupported(caps, def->os.type,
|
if (!(qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache,
|
||||||
def->os.arch,
|
def->emulator))) {
|
||||||
def->virtType))
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (def->os.type != VIR_DOMAIN_OSTYPE_HVM) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
|
_("Emulator '%s' does not support os type '%s'"),
|
||||||
|
def->emulator, virDomainOSTypeToString(def->os.type));
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!virQEMUCapsIsArchSupported(qemuCaps, def->os.arch)) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
|
_("Emulator '%s' does not support arch '%s'"),
|
||||||
|
def->emulator, virArchToString(def->os.arch));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!virQEMUCapsIsVirtTypeSupported(qemuCaps, def->virtType)) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
|
_("Emulator '%s' does not support virt type '%s'"),
|
||||||
|
def->emulator, virDomainVirtTypeToString(def->virtType));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (def->os.bootloader || def->os.bootloaderArgs) {
|
if (def->os.bootloader || def->os.bootloaderArgs) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
|
@ -4715,15 +4733,9 @@ qemuDomainDefPostParse(virDomainDefPtr def,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!def->os.machine) {
|
if (!def->os.machine) {
|
||||||
g_autofree virCapsDomainDataPtr capsdata = NULL;
|
const char *machine = virQEMUCapsGetPreferredMachine(qemuCaps,
|
||||||
|
def->virtType);
|
||||||
if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type,
|
def->os.machine = g_strdup(machine);
|
||||||
def->os.arch,
|
|
||||||
def->virtType,
|
|
||||||
NULL, NULL))) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
def->os.machine = g_strdup(capsdata->machinetype);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qemuDomainNVRAMPathGenerate(cfg, def);
|
qemuDomainNVRAMPathGenerate(cfg, def);
|
||||||
|
|
|
@ -117,12 +117,13 @@ vmwareDataFreeFunc(void *data)
|
||||||
|
|
||||||
static int
|
static int
|
||||||
vmwareDomainDefPostParse(virDomainDefPtr def,
|
vmwareDomainDefPostParse(virDomainDefPtr def,
|
||||||
virCapsPtr caps,
|
virCapsPtr caps G_GNUC_UNUSED,
|
||||||
unsigned int parseFlags G_GNUC_UNUSED,
|
unsigned int parseFlags G_GNUC_UNUSED,
|
||||||
void *opaque G_GNUC_UNUSED,
|
void *opaque G_GNUC_UNUSED,
|
||||||
void *parseOpaque G_GNUC_UNUSED)
|
void *parseOpaque G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
if (!virCapabilitiesDomainSupported(caps, def->os.type,
|
struct vmware_driver *driver = opaque;
|
||||||
|
if (!virCapabilitiesDomainSupported(driver->caps, def->os.type,
|
||||||
def->os.arch,
|
def->os.arch,
|
||||||
def->virtType))
|
def->virtType))
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -148,11 +149,11 @@ virDomainDefParserConfig vmwareDomainDefParserConfig = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static virDomainXMLOptionPtr
|
static virDomainXMLOptionPtr
|
||||||
vmwareDomainXMLConfigInit(void)
|
vmwareDomainXMLConfigInit(struct vmware_driver *driver)
|
||||||
{
|
{
|
||||||
virDomainXMLPrivateDataCallbacks priv = { .alloc = vmwareDataAllocFunc,
|
virDomainXMLPrivateDataCallbacks priv = { .alloc = vmwareDataAllocFunc,
|
||||||
.free = vmwareDataFreeFunc };
|
.free = vmwareDataFreeFunc };
|
||||||
|
vmwareDomainDefParserConfig.priv = driver;
|
||||||
return virDomainXMLOptionNew(&vmwareDomainDefParserConfig, &priv,
|
return virDomainXMLOptionNew(&vmwareDomainDefParserConfig, &priv,
|
||||||
NULL, NULL, NULL);
|
NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
@ -235,7 +236,7 @@ vmwareConnectOpen(virConnectPtr conn,
|
||||||
if (!(driver->caps = vmwareCapsInit()))
|
if (!(driver->caps = vmwareCapsInit()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(driver->xmlopt = vmwareDomainXMLConfigInit()))
|
if (!(driver->xmlopt = vmwareDomainXMLConfigInit(driver)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (vmwareLoadDomains(driver) < 0)
|
if (vmwareLoadDomains(driver) < 0)
|
||||||
|
|
|
@ -530,11 +530,12 @@ VIR_ENUM_IMPL(virVMXControllerModelSCSI,
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virVMXDomainDefPostParse(virDomainDefPtr def,
|
virVMXDomainDefPostParse(virDomainDefPtr def,
|
||||||
virCapsPtr caps,
|
virCapsPtr _caps G_GNUC_UNUSED,
|
||||||
unsigned int parseFlags G_GNUC_UNUSED,
|
unsigned int parseFlags G_GNUC_UNUSED,
|
||||||
void *opaque G_GNUC_UNUSED,
|
void *opaque,
|
||||||
void *parseOpaque G_GNUC_UNUSED)
|
void *parseOpaque G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
|
virCapsPtr caps = opaque;
|
||||||
if (!virCapabilitiesDomainSupported(caps, def->os.type,
|
if (!virCapabilitiesDomainSupported(caps, def->os.type,
|
||||||
def->os.arch,
|
def->os.arch,
|
||||||
def->virtType))
|
def->virtType))
|
||||||
|
@ -612,8 +613,9 @@ static virXMLNamespace virVMXDomainXMLNamespace = {
|
||||||
};
|
};
|
||||||
|
|
||||||
virDomainXMLOptionPtr
|
virDomainXMLOptionPtr
|
||||||
virVMXDomainXMLConfInit(void)
|
virVMXDomainXMLConfInit(virCapsPtr caps)
|
||||||
{
|
{
|
||||||
|
virVMXDomainDefParserConfig.priv = caps;
|
||||||
return virDomainXMLOptionNew(&virVMXDomainDefParserConfig, NULL,
|
return virDomainXMLOptionNew(&virVMXDomainDefParserConfig, NULL,
|
||||||
&virVMXDomainXMLNamespace, NULL, NULL);
|
&virVMXDomainXMLNamespace, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
typedef struct _virVMXContext virVMXContext;
|
typedef struct _virVMXContext virVMXContext;
|
||||||
|
|
||||||
virDomainXMLOptionPtr virVMXDomainXMLConfInit(void);
|
virDomainXMLOptionPtr virVMXDomainXMLConfInit(virCapsPtr caps);
|
||||||
|
|
||||||
|
|
||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
|
|
@ -241,12 +241,13 @@ vzDomainDefAddDefaultInputDevices(virDomainDefPtr def)
|
||||||
|
|
||||||
static int
|
static int
|
||||||
vzDomainDefPostParse(virDomainDefPtr def,
|
vzDomainDefPostParse(virDomainDefPtr def,
|
||||||
virCapsPtr caps,
|
virCapsPtr caps G_GNUC_UNUSED,
|
||||||
unsigned int parseFlags G_GNUC_UNUSED,
|
unsigned int parseFlags G_GNUC_UNUSED,
|
||||||
void *opaque G_GNUC_UNUSED,
|
void *opaque,
|
||||||
void *parseOpaque G_GNUC_UNUSED)
|
void *parseOpaque G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
if (!virCapabilitiesDomainSupported(caps, def->os.type,
|
vzDriverPtr driver = opaque;
|
||||||
|
if (!virCapabilitiesDomainSupported(driver->caps, def->os.type,
|
||||||
def->os.arch,
|
def->os.arch,
|
||||||
def->virtType))
|
def->virtType))
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -289,10 +290,12 @@ vzDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
|
||||||
static int
|
static int
|
||||||
vzDomainDeviceDefValidate(const virDomainDeviceDef *dev,
|
vzDomainDeviceDefValidate(const virDomainDeviceDef *dev,
|
||||||
const virDomainDef *def,
|
const virDomainDef *def,
|
||||||
void *opaque G_GNUC_UNUSED)
|
void *opaque)
|
||||||
{
|
{
|
||||||
|
vzDriverPtr driver = opaque;
|
||||||
|
|
||||||
if (dev->type == VIR_DOMAIN_DEVICE_DISK)
|
if (dev->type == VIR_DOMAIN_DEVICE_DISK)
|
||||||
return vzCheckUnsupportedDisk(def, dev->data.disk, opaque);
|
return vzCheckUnsupportedDisk(def, dev->data.disk, driver->vzCaps);
|
||||||
else if (dev->type == VIR_DOMAIN_DEVICE_GRAPHICS)
|
else if (dev->type == VIR_DOMAIN_DEVICE_GRAPHICS)
|
||||||
return vzCheckUnsupportedGraphics(dev->data.graphics);
|
return vzCheckUnsupportedGraphics(dev->data.graphics);
|
||||||
|
|
||||||
|
@ -323,7 +326,7 @@ vzDriverObjNew(void)
|
||||||
if (!(driver = virObjectLockableNew(vzDriverClass)))
|
if (!(driver = virObjectLockableNew(vzDriverClass)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
vzDomainDefParserConfig.priv = &driver->vzCaps;
|
vzDomainDefParserConfig.priv = driver;
|
||||||
|
|
||||||
if (!(driver->caps = vzBuildCapabilities()) ||
|
if (!(driver->caps = vzBuildCapabilities()) ||
|
||||||
!(driver->xmlopt = virDomainXMLOptionNew(&vzDomainDefParserConfig,
|
!(driver->xmlopt = virDomainXMLOptionNew(&vzDomainDefParserConfig,
|
||||||
|
|
|
@ -1048,11 +1048,17 @@ endif WITH_LXC
|
||||||
if WITH_QEMU
|
if WITH_QEMU
|
||||||
vircapstest_SOURCES += testutilsqemu.c testutilsqemu.h
|
vircapstest_SOURCES += testutilsqemu.c testutilsqemu.h
|
||||||
endif WITH_QEMU
|
endif WITH_QEMU
|
||||||
|
vircapstest_LDADD =
|
||||||
if WITH_QEMU
|
if WITH_QEMU
|
||||||
vircapstest_LDADD = $(qemu_LDADDS)
|
vircapstest_LDADD += ../src/libvirt_driver_qemu_impl.la
|
||||||
else ! WITH_QEMU
|
if WITH_DTRACE_PROBES
|
||||||
vircapstest_LDADD = $(LDADDS)
|
vircapstest_LDADD += ../src/libvirt_qemu_probes.lo
|
||||||
endif ! WITH_QEMU
|
endif WITH_DTRACE_PROBES
|
||||||
|
endif WITH_QEMU
|
||||||
|
if WITH_LXC
|
||||||
|
vircapstest_LDADD += ../src/libvirt_driver_lxc_impl.la
|
||||||
|
endif WITH_LXC
|
||||||
|
vircapstest_LDADD += $(LDADDS)
|
||||||
|
|
||||||
libdomaincapsmock_la_SOURCES = domaincapsmock.c
|
libdomaincapsmock_la_SOURCES = domaincapsmock.c
|
||||||
libdomaincapsmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS)
|
libdomaincapsmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS)
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
|
|
||||||
# define VIR_FROM_THIS VIR_FROM_LIBXL
|
# define VIR_FROM_THIS VIR_FROM_LIBXL
|
||||||
|
|
||||||
static virCapsPtr caps;
|
static libxlDriverPrivatePtr driver;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
testCompareXMLToDomConfig(const char *xmlfile,
|
testCompareXMLToDomConfig(const char *xmlfile,
|
||||||
|
@ -50,19 +50,13 @@ testCompareXMLToDomConfig(const char *xmlfile,
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
libxl_domain_config actualconfig;
|
libxl_domain_config actualconfig;
|
||||||
libxl_domain_config expectconfig;
|
libxl_domain_config expectconfig;
|
||||||
libxlDriverConfigPtr cfg;
|
|
||||||
xentoollog_logger *log = NULL;
|
xentoollog_logger *log = NULL;
|
||||||
virPortAllocatorRangePtr gports = NULL;
|
virPortAllocatorRangePtr gports = NULL;
|
||||||
virDomainXMLOptionPtr xmlopt = NULL;
|
|
||||||
virDomainDefPtr vmdef = NULL;
|
virDomainDefPtr vmdef = NULL;
|
||||||
char *actualjson = NULL;
|
char *actualjson = NULL;
|
||||||
char *tempjson = NULL;
|
char *tempjson = NULL;
|
||||||
char *expectjson = NULL;
|
char *expectjson = NULL;
|
||||||
|
g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
|
||||||
if (!(cfg = libxlDriverConfigNew()))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
cfg->caps = caps;
|
|
||||||
|
|
||||||
libxl_domain_config_init(&actualconfig);
|
libxl_domain_config_init(&actualconfig);
|
||||||
libxl_domain_config_init(&expectconfig);
|
libxl_domain_config_init(&expectconfig);
|
||||||
|
@ -82,10 +76,7 @@ testCompareXMLToDomConfig(const char *xmlfile,
|
||||||
if (!(gports = virPortAllocatorRangeNew("vnc", 5900, 6000)))
|
if (!(gports = virPortAllocatorRangeNew("vnc", 5900, 6000)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(xmlopt = libxlCreateXMLConf()))
|
if (!(vmdef = virDomainDefParseFile(xmlfile, cfg->caps, driver->xmlopt,
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (!(vmdef = virDomainDefParseFile(xmlfile, caps, xmlopt,
|
|
||||||
NULL, VIR_DOMAIN_XML_INACTIVE)))
|
NULL, VIR_DOMAIN_XML_INACTIVE)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
@ -128,12 +119,9 @@ testCompareXMLToDomConfig(const char *xmlfile,
|
||||||
VIR_FREE(tempjson);
|
VIR_FREE(tempjson);
|
||||||
virDomainDefFree(vmdef);
|
virDomainDefFree(vmdef);
|
||||||
virPortAllocatorRangeFree(gports);
|
virPortAllocatorRangeFree(gports);
|
||||||
virObjectUnref(xmlopt);
|
|
||||||
libxl_domain_config_dispose(&actualconfig);
|
libxl_domain_config_dispose(&actualconfig);
|
||||||
libxl_domain_config_dispose(&expectconfig);
|
libxl_domain_config_dispose(&expectconfig);
|
||||||
xtl_logger_destroy(log);
|
xtl_logger_destroy(log);
|
||||||
cfg->caps = NULL;
|
|
||||||
virObjectUnref(cfg);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +165,7 @@ mymain(void)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((caps = testXLInitCaps()) == NULL)
|
if ((driver = testXLInitDriver()) == NULL)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
# define DO_TEST(name) \
|
# define DO_TEST(name) \
|
||||||
|
@ -216,6 +204,8 @@ mymain(void)
|
||||||
|
|
||||||
unlink("libxl-driver.log");
|
unlink("libxl-driver.log");
|
||||||
|
|
||||||
|
testXLFreeDriver(driver);
|
||||||
|
|
||||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,7 @@
|
||||||
|
|
||||||
# define VIR_FROM_THIS VIR_FROM_NONE
|
# define VIR_FROM_THIS VIR_FROM_NONE
|
||||||
|
|
||||||
static virCapsPtr caps;
|
static virLXCDriverPtr driver;
|
||||||
static virDomainXMLOptionPtr xmlopt;
|
|
||||||
|
|
||||||
static int testSanitizeDef(virDomainDefPtr vmdef)
|
static int testSanitizeDef(virDomainDefPtr vmdef)
|
||||||
{
|
{
|
||||||
|
@ -34,7 +33,7 @@ testCompareXMLToConfigFiles(const char *xmlfile,
|
||||||
if (virTestLoadFile(configfile, &config) < 0)
|
if (virTestLoadFile(configfile, &config) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
vmdef = lxcParseConfigString(config, caps, xmlopt);
|
vmdef = lxcParseConfigString(config, driver->caps, driver->xmlopt);
|
||||||
if ((vmdef && expectError) || (!vmdef && !expectError))
|
if ((vmdef && expectError) || (!vmdef && !expectError))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
@ -42,7 +41,7 @@ testCompareXMLToConfigFiles(const char *xmlfile,
|
||||||
if (testSanitizeDef(vmdef) < 0)
|
if (testSanitizeDef(vmdef) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (!(actualxml = virDomainDefFormat(vmdef, xmlopt, caps, 0)))
|
if (!(actualxml = virDomainDefFormat(vmdef, driver->xmlopt, driver->caps, 0)))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (virTestCompareToFile(actualxml, xmlfile) < 0)
|
if (virTestCompareToFile(actualxml, xmlfile) < 0)
|
||||||
|
@ -109,14 +108,9 @@ mymain(void)
|
||||||
{
|
{
|
||||||
int ret = EXIT_SUCCESS;
|
int ret = EXIT_SUCCESS;
|
||||||
|
|
||||||
if (!(caps = testLXCCapsInit()))
|
if (!(driver = testLXCDriverInit()))
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
if (!(xmlopt = lxcDomainXMLConfInit())) {
|
|
||||||
virObjectUnref(caps);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
# define DO_TEST(name, expectError) \
|
# define DO_TEST(name, expectError) \
|
||||||
do { \
|
do { \
|
||||||
const struct testInfo info = { name, expectError }; \
|
const struct testInfo info = { name, expectError }; \
|
||||||
|
@ -166,8 +160,7 @@ mymain(void)
|
||||||
DO_TEST3("blkiotune", false);
|
DO_TEST3("blkiotune", false);
|
||||||
DO_TEST3("ethernet", false);
|
DO_TEST3("ethernet", false);
|
||||||
|
|
||||||
virObjectUnref(xmlopt);
|
testLXCDriverFree(driver);
|
||||||
virObjectUnref(caps);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,7 @@
|
||||||
|
|
||||||
# define VIR_FROM_THIS VIR_FROM_NONE
|
# define VIR_FROM_THIS VIR_FROM_NONE
|
||||||
|
|
||||||
static virCapsPtr caps;
|
static virLXCDriverPtr driver;
|
||||||
static virDomainXMLOptionPtr xmlopt;
|
|
||||||
|
|
||||||
struct testInfo {
|
struct testInfo {
|
||||||
const char *name;
|
const char *name;
|
||||||
|
@ -39,7 +38,7 @@ testCompareXMLToXMLHelper(const void *data)
|
||||||
xml_out = g_strdup_printf("%s/lxcxml2xmloutdata/lxc-%s.xml",
|
xml_out = g_strdup_printf("%s/lxcxml2xmloutdata/lxc-%s.xml",
|
||||||
abs_srcdir, info->name);
|
abs_srcdir, info->name);
|
||||||
|
|
||||||
ret = testCompareDomXML2XMLFiles(caps, xmlopt, xml_in,
|
ret = testCompareDomXML2XMLFiles(driver->caps, driver->xmlopt, xml_in,
|
||||||
info->different ? xml_out : xml_in,
|
info->different ? xml_out : xml_in,
|
||||||
!info->inactive_only,
|
!info->inactive_only,
|
||||||
info->parse_flags,
|
info->parse_flags,
|
||||||
|
@ -55,10 +54,7 @@ mymain(void)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if ((caps = testLXCCapsInit()) == NULL)
|
if (!(driver = testLXCDriverInit()))
|
||||||
return EXIT_FAILURE;
|
|
||||||
|
|
||||||
if (!(xmlopt = lxcDomainXMLConfInit()))
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
# define DO_TEST_FULL(name, is_different, inactive, parse_flags) \
|
# define DO_TEST_FULL(name, is_different, inactive, parse_flags) \
|
||||||
|
@ -95,8 +91,7 @@ mymain(void)
|
||||||
DO_TEST("initdir");
|
DO_TEST("initdir");
|
||||||
DO_TEST("inituser");
|
DO_TEST("inituser");
|
||||||
|
|
||||||
virObjectUnref(caps);
|
testLXCDriverFree(driver);
|
||||||
virObjectUnref(xmlopt);
|
|
||||||
|
|
||||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,10 @@ testReadNetworkConf(const void *data G_GNUC_UNUSED)
|
||||||
" </interface>\n"
|
" </interface>\n"
|
||||||
" </devices>\n"
|
" </devices>\n"
|
||||||
"</domain>\n";
|
"</domain>\n";
|
||||||
virDomainXMLOptionPtr xmlopt = openvzXMLOption();
|
struct openvz_driver driver = {0};
|
||||||
|
|
||||||
|
driver.xmlopt = openvzXMLOption(&driver);
|
||||||
|
driver.caps = openvzCapsInit();
|
||||||
|
|
||||||
if (!(def = virDomainDefNew()))
|
if (!(def = virDomainDefNew()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -113,7 +116,7 @@ testReadNetworkConf(const void *data G_GNUC_UNUSED)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
actual = virDomainDefFormat(def, xmlopt, NULL, VIR_DOMAIN_DEF_FORMAT_INACTIVE);
|
actual = virDomainDefFormat(def, driver.xmlopt, driver.caps, VIR_DOMAIN_DEF_FORMAT_INACTIVE);
|
||||||
|
|
||||||
if (actual == NULL) {
|
if (actual == NULL) {
|
||||||
fprintf(stderr, "ERROR: %s\n", virGetLastErrorMessage());
|
fprintf(stderr, "ERROR: %s\n", virGetLastErrorMessage());
|
||||||
|
@ -128,7 +131,8 @@ testReadNetworkConf(const void *data G_GNUC_UNUSED)
|
||||||
result = 0;
|
result = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virObjectUnref(xmlopt);
|
virObjectUnref(driver.xmlopt);
|
||||||
|
virObjectUnref(driver.caps);
|
||||||
VIR_FREE(actual);
|
VIR_FREE(actual);
|
||||||
virDomainDefFree(def);
|
virDomainDefFree(def);
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,10 @@
|
||||||
# include "viralloc.h"
|
# include "viralloc.h"
|
||||||
# include "domain_conf.h"
|
# include "domain_conf.h"
|
||||||
|
|
||||||
|
# define VIR_FROM_THIS VIR_FROM_LXC
|
||||||
|
|
||||||
virCapsPtr testLXCCapsInit(void)
|
virCapsPtr
|
||||||
|
testLXCCapsInit(void)
|
||||||
{
|
{
|
||||||
virCapsPtr caps;
|
virCapsPtr caps;
|
||||||
virCapsGuestPtr guest;
|
virCapsGuestPtr guest;
|
||||||
|
@ -54,4 +56,34 @@ virCapsPtr testLXCCapsInit(void)
|
||||||
virObjectUnref(caps);
|
virObjectUnref(caps);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virLXCDriverPtr
|
||||||
|
testLXCDriverInit(void)
|
||||||
|
{
|
||||||
|
virLXCDriverPtr driver = g_new0(virLXCDriver, 1);
|
||||||
|
|
||||||
|
if (virMutexInit(&driver->lock) < 0) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"%s", "cannot initialize mutex");
|
||||||
|
g_free(driver);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
driver->caps = testLXCCapsInit();
|
||||||
|
driver->xmlopt = lxcDomainXMLConfInit(driver);
|
||||||
|
|
||||||
|
return driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
testLXCDriverFree(virLXCDriverPtr driver)
|
||||||
|
{
|
||||||
|
virObjectUnref(driver->xmlopt);
|
||||||
|
virObjectUnref(driver->caps);
|
||||||
|
virMutexDestroy(&driver->lock);
|
||||||
|
g_free(driver);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,7 +18,11 @@
|
||||||
|
|
||||||
#include "capabilities.h"
|
#include "capabilities.h"
|
||||||
|
|
||||||
|
#include "lxc/lxc_conf.h"
|
||||||
|
|
||||||
#define FAKEDEVDIR0 "/fakedevdir0/bla/fasl"
|
#define FAKEDEVDIR0 "/fakedevdir0/bla/fasl"
|
||||||
#define FAKEDEVDIR1 "/fakedevdir1/bla/fasl"
|
#define FAKEDEVDIR1 "/fakedevdir1/bla/fasl"
|
||||||
|
|
||||||
virCapsPtr testLXCCapsInit(void);
|
virCapsPtr testLXCCapsInit(void);
|
||||||
|
virLXCDriverPtr testLXCDriverInit(void);
|
||||||
|
void testLXCDriverFree(virLXCDriverPtr driver);
|
||||||
|
|
|
@ -6,7 +6,9 @@
|
||||||
#include "testutilshostcpus.h"
|
#include "testutilshostcpus.h"
|
||||||
#include "domain_conf.h"
|
#include "domain_conf.h"
|
||||||
|
|
||||||
virCapsPtr
|
#define VIR_FROM_THIS VIR_FROM_LIBXL
|
||||||
|
|
||||||
|
static virCapsPtr
|
||||||
testXLInitCaps(void)
|
testXLInitCaps(void)
|
||||||
{
|
{
|
||||||
virCapsPtr caps;
|
virCapsPtr caps;
|
||||||
|
@ -79,3 +81,33 @@ testXLInitCaps(void)
|
||||||
virObjectUnref(caps);
|
virObjectUnref(caps);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
libxlDriverPrivatePtr testXLInitDriver(void)
|
||||||
|
{
|
||||||
|
libxlDriverPrivatePtr driver = g_new0(libxlDriverPrivate, 1);
|
||||||
|
|
||||||
|
if (virMutexInit(&driver->lock) < 0) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"%s", "cannot initialize mutex");
|
||||||
|
g_free(driver);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
driver->config = libxlDriverConfigNew();
|
||||||
|
|
||||||
|
driver->config->caps = testXLInitCaps();
|
||||||
|
|
||||||
|
driver->xmlopt = libxlCreateXMLConf(driver);
|
||||||
|
|
||||||
|
return driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
void testXLFreeDriver(libxlDriverPrivatePtr driver)
|
||||||
|
{
|
||||||
|
virObjectUnref(driver->config->caps);
|
||||||
|
virObjectUnref(driver->config);
|
||||||
|
virObjectUnref(driver->xmlopt);
|
||||||
|
virMutexDestroy(&driver->lock);
|
||||||
|
g_free(driver);
|
||||||
|
}
|
||||||
|
|
|
@ -18,7 +18,10 @@
|
||||||
|
|
||||||
#include "capabilities.h"
|
#include "capabilities.h"
|
||||||
#ifdef WITH_LIBXL
|
#ifdef WITH_LIBXL
|
||||||
# include "libxl/libxl_capabilities.h"
|
# include "libxl/libxl_conf.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
virCapsPtr testXLInitCaps(void);
|
libxlDriverPrivatePtr testXLInitDriver(void);
|
||||||
|
|
||||||
|
void testXLFreeDriver(libxlDriverPrivatePtr driver);
|
||||||
|
|
||||||
|
#endif /* WITH_LIBXL */
|
||||||
|
|
|
@ -186,7 +186,7 @@ mymain(void)
|
||||||
if (caps == NULL)
|
if (caps == NULL)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
if (!(xmlopt = virVMXDomainXMLConfInit()))
|
if (!(xmlopt = virVMXDomainXMLConfInit(caps)))
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
ctx.opaque = NULL;
|
ctx.opaque = NULL;
|
||||||
|
|
|
@ -36,9 +36,7 @@
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_NONE
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||||
|
|
||||||
static virCapsPtr caps;
|
static libxlDriverPrivatePtr driver;
|
||||||
static virDomainXMLOptionPtr xmlopt;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function provides a mechanism to replace variables in test
|
* This function provides a mechanism to replace variables in test
|
||||||
|
@ -74,6 +72,7 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars)
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virDomainDefPtr def = NULL;
|
virDomainDefPtr def = NULL;
|
||||||
char *replacedXML = NULL;
|
char *replacedXML = NULL;
|
||||||
|
g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
|
||||||
|
|
||||||
if (VIR_ALLOC_N(gotxlcfgData, wrote) < 0)
|
if (VIR_ALLOC_N(gotxlcfgData, wrote) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -84,16 +83,16 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars)
|
||||||
if (replaceVars) {
|
if (replaceVars) {
|
||||||
if (!(replacedXML = testReplaceVarsXML(xml)))
|
if (!(replacedXML = testReplaceVarsXML(xml)))
|
||||||
goto fail;
|
goto fail;
|
||||||
if (!(def = virDomainDefParseString(replacedXML, caps, xmlopt,
|
if (!(def = virDomainDefParseString(replacedXML, cfg->caps, driver->xmlopt,
|
||||||
NULL, VIR_DOMAIN_XML_INACTIVE)))
|
NULL, VIR_DOMAIN_XML_INACTIVE)))
|
||||||
goto fail;
|
goto fail;
|
||||||
} else {
|
} else {
|
||||||
if (!(def = virDomainDefParseFile(xml, caps, xmlopt,
|
if (!(def = virDomainDefParseFile(xml, cfg->caps, driver->xmlopt,
|
||||||
NULL, VIR_DOMAIN_XML_INACTIVE)))
|
NULL, VIR_DOMAIN_XML_INACTIVE)))
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!virDomainDefCheckABIStability(def, def, xmlopt)) {
|
if (!virDomainDefCheckABIStability(def, def, driver->xmlopt)) {
|
||||||
fprintf(stderr, "ABI stability check failed on %s", xml);
|
fprintf(stderr, "ABI stability check failed on %s", xml);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -133,6 +132,7 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars)
|
||||||
virConnectPtr conn;
|
virConnectPtr conn;
|
||||||
virDomainDefPtr def = NULL;
|
virDomainDefPtr def = NULL;
|
||||||
char *replacedXML = NULL;
|
char *replacedXML = NULL;
|
||||||
|
g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
|
||||||
|
|
||||||
conn = virGetConnect();
|
conn = virGetConnect();
|
||||||
if (!conn) goto fail;
|
if (!conn) goto fail;
|
||||||
|
@ -143,10 +143,10 @@ testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars)
|
||||||
if (!(conf = virConfReadString(xlcfgData, 0)))
|
if (!(conf = virConfReadString(xlcfgData, 0)))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (!(def = xenParseXL(conf, caps, xmlopt)))
|
if (!(def = xenParseXL(conf, cfg->caps, driver->xmlopt)))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (!(gotxml = virDomainDefFormat(def, xmlopt, caps,
|
if (!(gotxml = virDomainDefFormat(def, driver->xmlopt, cfg->caps,
|
||||||
VIR_DOMAIN_XML_INACTIVE |
|
VIR_DOMAIN_XML_INACTIVE |
|
||||||
VIR_DOMAIN_XML_SECURE)))
|
VIR_DOMAIN_XML_SECURE)))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -208,10 +208,7 @@ mymain(void)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (!(caps = testXLInitCaps()))
|
if (!(driver = testXLInitDriver()))
|
||||||
return EXIT_FAILURE;
|
|
||||||
|
|
||||||
if (!(xmlopt = libxlCreateXMLConf()))
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
#define DO_TEST_PARSE(name, replace) \
|
#define DO_TEST_PARSE(name, replace) \
|
||||||
|
@ -303,10 +300,9 @@ mymain(void)
|
||||||
DO_TEST("usb");
|
DO_TEST("usb");
|
||||||
DO_TEST("usbctrl");
|
DO_TEST("usbctrl");
|
||||||
|
|
||||||
virObjectUnref(caps);
|
testXLFreeDriver(driver);
|
||||||
virObjectUnref(xmlopt);
|
|
||||||
|
|
||||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_TEST_MAIN(mymain)
|
VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("xl"))
|
||||||
|
|
|
@ -34,8 +34,7 @@
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_NONE
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||||
|
|
||||||
static virCapsPtr caps;
|
static libxlDriverPrivatePtr driver;
|
||||||
static virDomainXMLOptionPtr xmlopt;
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
testCompareParseXML(const char *xmcfg, const char *xml)
|
testCompareParseXML(const char *xmcfg, const char *xml)
|
||||||
|
@ -46,6 +45,7 @@ testCompareParseXML(const char *xmcfg, const char *xml)
|
||||||
virConnectPtr conn = NULL;
|
virConnectPtr conn = NULL;
|
||||||
int wrote = 4096;
|
int wrote = 4096;
|
||||||
virDomainDefPtr def = NULL;
|
virDomainDefPtr def = NULL;
|
||||||
|
g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
|
||||||
|
|
||||||
if (VIR_ALLOC_N(gotxmcfgData, wrote) < 0)
|
if (VIR_ALLOC_N(gotxmcfgData, wrote) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -53,11 +53,11 @@ testCompareParseXML(const char *xmcfg, const char *xml)
|
||||||
conn = virGetConnect();
|
conn = virGetConnect();
|
||||||
if (!conn) goto fail;
|
if (!conn) goto fail;
|
||||||
|
|
||||||
if (!(def = virDomainDefParseFile(xml, caps, xmlopt, NULL,
|
if (!(def = virDomainDefParseFile(xml, cfg->caps, driver->xmlopt, NULL,
|
||||||
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
|
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (!virDomainDefCheckABIStability(def, def, xmlopt)) {
|
if (!virDomainDefCheckABIStability(def, def, driver->xmlopt)) {
|
||||||
fprintf(stderr, "ABI stability check failed on %s", xml);
|
fprintf(stderr, "ABI stability check failed on %s", xml);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,7 @@ testCompareFormatXML(const char *xmcfg, const char *xml)
|
||||||
g_autoptr(virConf) conf = NULL;
|
g_autoptr(virConf) conf = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virDomainDefPtr def = NULL;
|
virDomainDefPtr def = NULL;
|
||||||
|
g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
|
||||||
|
|
||||||
if (virTestLoadFile(xmcfg, &xmcfgData) < 0)
|
if (virTestLoadFile(xmcfg, &xmcfgData) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -97,10 +98,10 @@ testCompareFormatXML(const char *xmcfg, const char *xml)
|
||||||
if (!(conf = virConfReadString(xmcfgData, 0)))
|
if (!(conf = virConfReadString(xmcfgData, 0)))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (!(def = xenParseXM(conf, caps, xmlopt)))
|
if (!(def = xenParseXM(conf, cfg->caps, driver->xmlopt)))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (!(gotxml = virDomainDefFormat(def, xmlopt, caps, VIR_DOMAIN_DEF_FORMAT_SECURE)))
|
if (!(gotxml = virDomainDefFormat(def, driver->xmlopt, cfg->caps, VIR_DOMAIN_DEF_FORMAT_SECURE)))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (virTestCompareToFile(gotxml, xml) < 0)
|
if (virTestCompareToFile(gotxml, xml) < 0)
|
||||||
|
@ -152,10 +153,7 @@ mymain(void)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (!(caps = testXLInitCaps()))
|
if (!(driver = testXLInitDriver()))
|
||||||
return EXIT_FAILURE;
|
|
||||||
|
|
||||||
if (!(xmlopt = libxlCreateXMLConf()))
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
#define DO_TEST_PARSE(name) \
|
#define DO_TEST_PARSE(name) \
|
||||||
|
@ -225,10 +223,9 @@ mymain(void)
|
||||||
DO_TEST("disk-drv-blktap-raw");
|
DO_TEST("disk-drv-blktap-raw");
|
||||||
DO_TEST("disk-drv-blktap2-raw");
|
DO_TEST("disk-drv-blktap2-raw");
|
||||||
|
|
||||||
virObjectUnref(caps);
|
testXLFreeDriver(driver);
|
||||||
virObjectUnref(xmlopt);
|
|
||||||
|
|
||||||
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_TEST_MAIN(mymain)
|
VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("xl"))
|
||||||
|
|
|
@ -207,7 +207,7 @@ mymain(void)
|
||||||
if (caps == NULL)
|
if (caps == NULL)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
if (!(xmlopt = virVMXDomainXMLConfInit()))
|
if (!(xmlopt = virVMXDomainXMLConfInit(caps)))
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
ctx.opaque = NULL;
|
ctx.opaque = NULL;
|
||||||
|
|
Loading…
Reference in New Issue