mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15:17 +00:00
libxl: pass driver config to libxlMakeDomBuildInfo
Preparation for global nestedhvm configuration - libxlMakeDomBuildInfo needs access to libxlDriverConfig. No functional change. Adjusting tests require slightly more mockup functions, because of libxlDriverConfigNew() call. Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Jim Fehlig <jfehlig@suse.com>
This commit is contained in:
parent
13019ba8e1
commit
446d091498
@ -271,11 +271,12 @@ libxlMakeChrdevStr(virDomainChrDefPtr def, char **buf)
|
||||
|
||||
static int
|
||||
libxlMakeDomBuildInfo(virDomainDefPtr def,
|
||||
libxl_ctx *ctx,
|
||||
libxlDriverConfigPtr cfg,
|
||||
virCapsPtr caps,
|
||||
libxl_domain_config *d_config)
|
||||
{
|
||||
virDomainClockDef clock = def->clock;
|
||||
libxl_ctx *ctx = cfg->ctx;
|
||||
libxl_domain_build_info *b_info = &d_config->b_info;
|
||||
int hvm = def->os.type == VIR_DOMAIN_OSTYPE_HVM;
|
||||
size_t i;
|
||||
@ -2346,17 +2347,17 @@ libxlDriverNodeGetInfo(libxlDriverPrivatePtr driver, virNodeInfoPtr info)
|
||||
int
|
||||
libxlBuildDomainConfig(virPortAllocatorRangePtr graphicsports,
|
||||
virDomainDefPtr def,
|
||||
const char *channelDir LIBXL_ATTR_UNUSED,
|
||||
libxl_ctx *ctx,
|
||||
virCapsPtr caps,
|
||||
libxlDriverConfigPtr cfg,
|
||||
libxl_domain_config *d_config)
|
||||
{
|
||||
virCapsPtr caps = cfg->caps;
|
||||
libxl_ctx *ctx = cfg->ctx;
|
||||
libxl_domain_config_init(d_config);
|
||||
|
||||
if (libxlMakeDomCreateInfo(ctx, def, &d_config->c_info) < 0)
|
||||
return -1;
|
||||
|
||||
if (libxlMakeDomBuildInfo(def, ctx, caps, d_config) < 0)
|
||||
if (libxlMakeDomBuildInfo(def, cfg, caps, d_config) < 0)
|
||||
return -1;
|
||||
|
||||
#ifdef LIBXL_HAVE_VNUMA
|
||||
@ -2388,7 +2389,7 @@ libxlBuildDomainConfig(virPortAllocatorRangePtr graphicsports,
|
||||
#endif
|
||||
|
||||
#ifdef LIBXL_HAVE_DEVICE_CHANNEL
|
||||
if (libxlMakeChannelList(channelDir, def, d_config) < 0)
|
||||
if (libxlMakeChannelList(cfg->channelDir, def, d_config) < 0)
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
|
@ -215,9 +215,7 @@ libxlCreateXMLConf(void);
|
||||
int
|
||||
libxlBuildDomainConfig(virPortAllocatorRangePtr graphicsports,
|
||||
virDomainDefPtr def,
|
||||
const char *channelDir LIBXL_ATTR_UNUSED,
|
||||
libxl_ctx *ctx,
|
||||
virCapsPtr caps,
|
||||
libxlDriverConfigPtr cfg,
|
||||
libxl_domain_config *d_config);
|
||||
|
||||
static inline void
|
||||
|
@ -1261,7 +1261,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
|
||||
goto cleanup_dom;
|
||||
|
||||
if (libxlBuildDomainConfig(driver->reservedGraphicsPorts, vm->def,
|
||||
cfg->channelDir, cfg->ctx, cfg->caps, &d_config) < 0)
|
||||
cfg, &d_config) < 0)
|
||||
goto cleanup_dom;
|
||||
|
||||
if (cfg->autoballoon && libxlDomainFreeMem(cfg->ctx, &d_config) < 0)
|
||||
|
@ -528,6 +528,7 @@ libxlxml2domconfigtest_LDADD = $(libxl_LDADDS) $(LIBXML_LIBS)
|
||||
|
||||
virmocklibxl_la_SOURCES = \
|
||||
virmocklibxl.c
|
||||
virmocklibxl_la_CFLAGS = $(LIBXL_CFLAGS)
|
||||
virmocklibxl_la_LDFLAGS = $(MOCKLIBS_LDFLAGS)
|
||||
virmocklibxl_la_LIBADD = $(MOCKLIBS_LIBS)
|
||||
|
||||
|
@ -56,8 +56,8 @@ testCompareXMLToDomConfig(const char *xmlfile,
|
||||
int ret = -1;
|
||||
libxl_domain_config actualconfig;
|
||||
libxl_domain_config expectconfig;
|
||||
libxlDriverConfigPtr cfg;
|
||||
xentoollog_logger *log = NULL;
|
||||
libxl_ctx *ctx = NULL;
|
||||
virPortAllocatorRangePtr gports = NULL;
|
||||
virDomainXMLOptionPtr xmlopt = NULL;
|
||||
virDomainDefPtr vmdef = NULL;
|
||||
@ -68,10 +68,18 @@ testCompareXMLToDomConfig(const char *xmlfile,
|
||||
libxl_domain_config_init(&actualconfig);
|
||||
libxl_domain_config_init(&expectconfig);
|
||||
|
||||
if (!(cfg = libxlDriverConfigNew()))
|
||||
goto cleanup;
|
||||
|
||||
cfg->caps = caps;
|
||||
|
||||
if (!(log = (xentoollog_logger *)xtl_createlogger_stdiostream(stderr, XTL_DEBUG, 0)))
|
||||
goto cleanup;
|
||||
|
||||
if (libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, log) < 0)
|
||||
/* replace logger with stderr one */
|
||||
libxl_ctx_free(cfg->ctx);
|
||||
|
||||
if (libxl_ctx_alloc(&cfg->ctx, LIBXL_VERSION, 0, log) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(gports = virPortAllocatorRangeNew("vnc", 5900, 6000)))
|
||||
@ -84,22 +92,22 @@ testCompareXMLToDomConfig(const char *xmlfile,
|
||||
NULL, VIR_DOMAIN_XML_INACTIVE)))
|
||||
goto cleanup;
|
||||
|
||||
if (libxlBuildDomainConfig(gports, vmdef, NULL, ctx, caps, &actualconfig) < 0)
|
||||
if (libxlBuildDomainConfig(gports, vmdef, cfg, &actualconfig) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(actualjson = libxl_domain_config_to_json(ctx, &actualconfig))) {
|
||||
if (!(actualjson = libxl_domain_config_to_json(cfg->ctx, &actualconfig))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
"Failed to retrieve JSON doc for libxl_domain_config");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
virTestLoadFile(jsonfile, &tempjson);
|
||||
if (libxl_domain_config_from_json(ctx, &expectconfig, tempjson) != 0) {
|
||||
if (libxl_domain_config_from_json(cfg->ctx, &expectconfig, tempjson) != 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
"Failed to create libxl_domain_config from JSON doc");
|
||||
goto cleanup;
|
||||
}
|
||||
if (!(expectjson = libxl_domain_config_to_json(ctx, &expectconfig))) {
|
||||
if (!(expectjson = libxl_domain_config_to_json(cfg->ctx, &expectconfig))) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
"Failed to retrieve JSON doc for libxl_domain_config");
|
||||
goto cleanup;
|
||||
@ -122,10 +130,11 @@ testCompareXMLToDomConfig(const char *xmlfile,
|
||||
virDomainDefFree(vmdef);
|
||||
virPortAllocatorRangeFree(gports);
|
||||
virObjectUnref(xmlopt);
|
||||
libxl_ctx_free(ctx);
|
||||
libxl_domain_config_dispose(&actualconfig);
|
||||
libxl_domain_config_dispose(&expectconfig);
|
||||
xtl_logger_destroy(log);
|
||||
cfg->caps = NULL;
|
||||
virObjectUnref(cfg);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
# include <sys/stat.h>
|
||||
# include <unistd.h>
|
||||
# include <libxl.h>
|
||||
# include <util/virfile.h>
|
||||
# include <xenstore.h>
|
||||
# include <xenctrl.h>
|
||||
# include <sys/socket.h>
|
||||
@ -49,6 +50,25 @@ VIR_MOCK_IMPL_RET_ARGS(xc_interface_open,
|
||||
}
|
||||
|
||||
|
||||
VIR_MOCK_IMPL_RET_ARGS(libxl_get_version_info,
|
||||
const libxl_version_info*,
|
||||
libxl_ctx *, ctx)
|
||||
{
|
||||
static libxl_version_info info;
|
||||
|
||||
memset(&info, 0, sizeof(info));
|
||||
|
||||
/* silence gcc warning about unused function */
|
||||
if (0)
|
||||
real_libxl_get_version_info(ctx);
|
||||
return &info;
|
||||
}
|
||||
|
||||
VIR_MOCK_STUB_RET_ARGS(libxl_get_free_memory,
|
||||
int, 0,
|
||||
libxl_ctx *, ctx,
|
||||
uint32_t *, memkb);
|
||||
|
||||
VIR_MOCK_STUB_RET_ARGS(xc_interface_close,
|
||||
int, 0,
|
||||
xc_interface *, handle)
|
||||
@ -75,6 +95,17 @@ VIR_MOCK_STUB_RET_ARGS(bind,
|
||||
const struct sockaddr *, addr,
|
||||
socklen_t, addrlen)
|
||||
|
||||
VIR_MOCK_IMPL_RET_ARGS(virFileMakePath, int,
|
||||
const char *, path)
|
||||
{
|
||||
/* replace log path with a writable directory */
|
||||
if (strstr(path, "/log/")) {
|
||||
snprintf((char*)path, strlen(path), ".");
|
||||
return 0;
|
||||
}
|
||||
return real_virFileMakePath(path);
|
||||
}
|
||||
|
||||
VIR_MOCK_IMPL_RET_ARGS(__xstat, int,
|
||||
int, ver,
|
||||
const char *, path,
|
||||
|
Loading…
x
Reference in New Issue
Block a user