提交 a5bf06ba 编写于 作者: J Jim Fehlig

libxl: remove per-domain libxl_ctx

Although needed in the Xen 4.1 libxl days, there is no longer any
benefit to having per-domain libxl_ctx.  On the contrary, their use
makes the code unecessarily complicated and prone to deadlocks under
load.  As suggested by the libxl maintainers, use a single libxl_ctx
as a handle to libxl instead of per-domain ctx's.

One downside to using a single libxl_ctx is there are no longer
per-domain log files for log messages emitted by libxl.  Messages
for all domains will be sent to /var/log/libvirt/libxl/libxl-driver.log.
Signed-off-by: NJim Fehlig <jfehlig@suse.com>
上级 6728645a
...@@ -210,11 +210,6 @@ libxlDomainObjPrivateDispose(void *obj) ...@@ -210,11 +210,6 @@ libxlDomainObjPrivateDispose(void *obj)
libxlDomainObjFreeJob(priv); libxlDomainObjFreeJob(priv);
virChrdevFree(priv->devs); virChrdevFree(priv->devs);
libxl_ctx_free(priv->ctx);
if (priv->logger_file)
VIR_FORCE_FCLOSE(priv->logger_file);
xtl_logger_destroy(priv->logger);
} }
static void static void
...@@ -533,49 +528,6 @@ libxlDomainEventHandler(void *data, VIR_LIBXL_EVENT_CONST libxl_event *event) ...@@ -533,49 +528,6 @@ libxlDomainEventHandler(void *data, VIR_LIBXL_EVENT_CONST libxl_event *event)
virObjectUnlock(vm); virObjectUnlock(vm);
} }
int
libxlDomainObjPrivateInitCtx(virDomainObjPtr vm)
{
libxlDomainObjPrivatePtr priv = vm->privateData;
char *log_file;
int ret = -1;
if (priv->ctx)
return 0;
if (virAsprintf(&log_file, "%s/%s.log", LIBXL_LOG_DIR, vm->def->name) < 0)
return -1;
if ((priv->logger_file = fopen(log_file, "a")) == NULL) {
virReportSystemError(errno,
_("failed to open logfile %s"),
log_file);
goto cleanup;
}
priv->logger =
(xentoollog_logger *)xtl_createlogger_stdiostream(priv->logger_file,
XTL_DEBUG, 0);
if (!priv->logger) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot create libxenlight logger for domain %s"),
vm->def->name);
goto cleanup;
}
if (libxl_ctx_alloc(&priv->ctx, LIBXL_VERSION, 0, priv->logger)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Failed libxl context initialization"));
goto cleanup;
}
ret = 0;
cleanup:
VIR_FREE(log_file);
return ret;
}
void void
libxlDomainEventQueue(libxlDriverPrivatePtr driver, virObjectEventPtr event) libxlDomainEventQueue(libxlDriverPrivatePtr driver, virObjectEventPtr event)
{ {
...@@ -690,7 +642,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver, ...@@ -690,7 +642,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
vm->def->id = -1; vm->def->id = -1;
if (priv->deathW) { if (priv->deathW) {
libxl_evdisable_domain_death(priv->ctx, priv->deathW); libxl_evdisable_domain_death(cfg->ctx, priv->deathW);
priv->deathW = NULL; priv->deathW = NULL;
} }
...@@ -766,7 +718,6 @@ int ...@@ -766,7 +718,6 @@ int
libxlDomainAutoCoreDump(libxlDriverPrivatePtr driver, libxlDomainAutoCoreDump(libxlDriverPrivatePtr driver,
virDomainObjPtr vm) virDomainObjPtr vm)
{ {
libxlDomainObjPrivatePtr priv = vm->privateData;
libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
time_t curtime = time(NULL); time_t curtime = time(NULL);
char timestr[100]; char timestr[100];
...@@ -788,7 +739,7 @@ libxlDomainAutoCoreDump(libxlDriverPrivatePtr driver, ...@@ -788,7 +739,7 @@ libxlDomainAutoCoreDump(libxlDriverPrivatePtr driver,
/* Unlock virDomainObj while dumping core */ /* Unlock virDomainObj while dumping core */
virObjectUnlock(vm); virObjectUnlock(vm);
libxl_domain_core_dump(priv->ctx, vm->def->id, dumpfile, NULL); libxl_domain_core_dump(cfg->ctx, vm->def->id, dumpfile, NULL);
virObjectLock(vm); virObjectLock(vm);
ignore_value(libxlDomainObjEndJob(driver, vm)); ignore_value(libxlDomainObjEndJob(driver, vm));
...@@ -804,7 +755,7 @@ libxlDomainAutoCoreDump(libxlDriverPrivatePtr driver, ...@@ -804,7 +755,7 @@ libxlDomainAutoCoreDump(libxlDriverPrivatePtr driver,
int int
libxlDomainSetVcpuAffinities(libxlDriverPrivatePtr driver, virDomainObjPtr vm) libxlDomainSetVcpuAffinities(libxlDriverPrivatePtr driver, virDomainObjPtr vm)
{ {
libxlDomainObjPrivatePtr priv = vm->privateData; libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
virDomainDefPtr def = vm->def; virDomainDefPtr def = vm->def;
libxl_bitmap map; libxl_bitmap map;
virBitmapPtr cpumask = NULL; virBitmapPtr cpumask = NULL;
...@@ -837,7 +788,7 @@ libxlDomainSetVcpuAffinities(libxlDriverPrivatePtr driver, virDomainObjPtr vm) ...@@ -837,7 +788,7 @@ libxlDomainSetVcpuAffinities(libxlDriverPrivatePtr driver, virDomainObjPtr vm)
map.size = cpumaplen; map.size = cpumaplen;
map.map = cpumap; map.map = cpumap;
if (libxl_set_vcpuaffinity(priv->ctx, def->id, vcpu, &map) != 0) { if (libxl_set_vcpuaffinity(cfg->ctx, def->id, vcpu, &map) != 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to pin vcpu '%d' with libxenlight"), vcpu); _("Failed to pin vcpu '%d' with libxenlight"), vcpu);
goto cleanup; goto cleanup;
...@@ -850,6 +801,7 @@ libxlDomainSetVcpuAffinities(libxlDriverPrivatePtr driver, virDomainObjPtr vm) ...@@ -850,6 +801,7 @@ libxlDomainSetVcpuAffinities(libxlDriverPrivatePtr driver, virDomainObjPtr vm)
cleanup: cleanup:
VIR_FREE(cpumap); VIR_FREE(cpumap);
virObjectUnref(cfg);
return ret; return ret;
} }
...@@ -955,9 +907,6 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, ...@@ -955,9 +907,6 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
libxl_domain_config_init(&d_config); libxl_domain_config_init(&d_config);
if (libxlDomainObjPrivateInitCtx(vm) < 0)
return ret;
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0) if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
return ret; return ret;
...@@ -1005,10 +954,10 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, ...@@ -1005,10 +954,10 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
} }
if (libxlBuildDomainConfig(driver->reservedVNCPorts, vm->def, if (libxlBuildDomainConfig(driver->reservedVNCPorts, vm->def,
priv->ctx, &d_config) < 0) cfg->ctx, &d_config) < 0)
goto endjob; goto endjob;
if (cfg->autoballoon && libxlDomainFreeMem(priv->ctx, &d_config) < 0) { if (cfg->autoballoon && libxlDomainFreeMem(cfg->ctx, &d_config) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("libxenlight failed to get free memory for domain '%s'"), _("libxenlight failed to get free memory for domain '%s'"),
d_config.c_info.name); d_config.c_info.name);
...@@ -1025,16 +974,16 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, ...@@ -1025,16 +974,16 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
aop_console_how.for_callback = vm; aop_console_how.for_callback = vm;
aop_console_how.callback = libxlConsoleCallback; aop_console_how.callback = libxlConsoleCallback;
if (restore_fd < 0) { if (restore_fd < 0) {
ret = libxl_domain_create_new(priv->ctx, &d_config, ret = libxl_domain_create_new(cfg->ctx, &d_config,
&domid, NULL, &aop_console_how); &domid, NULL, &aop_console_how);
} else { } else {
#ifdef LIBXL_HAVE_DOMAIN_CREATE_RESTORE_PARAMS #ifdef LIBXL_HAVE_DOMAIN_CREATE_RESTORE_PARAMS
params.checkpointed_stream = 0; params.checkpointed_stream = 0;
ret = libxl_domain_create_restore(priv->ctx, &d_config, &domid, ret = libxl_domain_create_restore(cfg->ctx, &d_config, &domid,
restore_fd, &params, NULL, restore_fd, &params, NULL,
&aop_console_how); &aop_console_how);
#else #else
ret = libxl_domain_create_restore(priv->ctx, &d_config, &domid, ret = libxl_domain_create_restore(cfg->ctx, &d_config, &domid,
restore_fd, NULL, &aop_console_how); restore_fd, NULL, &aop_console_how);
#endif #endif
} }
...@@ -1059,13 +1008,13 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, ...@@ -1059,13 +1008,13 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
vm->def->id = domid; vm->def->id = domid;
/* Always enable domain death events */ /* Always enable domain death events */
if (libxl_evenable_domain_death(priv->ctx, vm->def->id, 0, &priv->deathW)) if (libxl_evenable_domain_death(cfg->ctx, vm->def->id, 0, &priv->deathW))
goto cleanup_dom; goto cleanup_dom;
if ((dom_xml = virDomainDefFormat(vm->def, 0)) == NULL) if ((dom_xml = virDomainDefFormat(vm->def, 0)) == NULL)
goto cleanup_dom; goto cleanup_dom;
if (libxl_userdata_store(priv->ctx, domid, "libvirt-xml", if (libxl_userdata_store(cfg->ctx, domid, "libvirt-xml",
(uint8_t *)dom_xml, strlen(dom_xml) + 1)) { (uint8_t *)dom_xml, strlen(dom_xml) + 1)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("libxenlight failed to store userdata")); _("libxenlight failed to store userdata"));
...@@ -1076,7 +1025,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, ...@@ -1076,7 +1025,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
goto cleanup_dom; goto cleanup_dom;
if (!start_paused) { if (!start_paused) {
libxl_domain_unpause(priv->ctx, domid); libxl_domain_unpause(cfg->ctx, domid);
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED); virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED);
} else { } else {
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_USER); virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_USER);
...@@ -1100,10 +1049,10 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, ...@@ -1100,10 +1049,10 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
cleanup_dom: cleanup_dom:
if (priv->deathW) { if (priv->deathW) {
libxl_evdisable_domain_death(priv->ctx, priv->deathW); libxl_evdisable_domain_death(cfg->ctx, priv->deathW);
priv->deathW = NULL; priv->deathW = NULL;
} }
libxl_domain_destroy(priv->ctx, domid, NULL); libxl_domain_destroy(cfg->ctx, domid, NULL);
vm->def->id = -1; vm->def->id = -1;
virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_FAILED); virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_FAILED);
......
...@@ -60,11 +60,6 @@ typedef libxlDomainObjPrivate *libxlDomainObjPrivatePtr; ...@@ -60,11 +60,6 @@ typedef libxlDomainObjPrivate *libxlDomainObjPrivatePtr;
struct _libxlDomainObjPrivate { struct _libxlDomainObjPrivate {
virObjectLockable parent; virObjectLockable parent;
/* per domain log stream for libxl messages */
FILE *logger_file;
xentoollog_logger *logger;
/* per domain libxl ctx */
libxl_ctx *ctx;
/* console */ /* console */
virChrdevsPtr devs; virChrdevsPtr devs;
libxl_evgen_domain_death *deathW; libxl_evgen_domain_death *deathW;
......
此差异已折叠。
/* /*
* libxl_migration.c: methods for handling migration with libxenlight * libxl_migration.c: methods for handling migration with libxenlight
* *
* Copyright (C) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany. * Copyright (C) 2014-2015 SUSE LINUX Products GmbH, Nuernberg, Germany.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -176,7 +176,6 @@ libxlDoMigrateSend(libxlDriverPrivatePtr driver, ...@@ -176,7 +176,6 @@ libxlDoMigrateSend(libxlDriverPrivatePtr driver,
unsigned long flags, unsigned long flags,
int sockfd) int sockfd)
{ {
libxlDomainObjPrivatePtr priv;
libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
virObjectEventPtr event = NULL; virObjectEventPtr event = NULL;
int xl_flags = 0; int xl_flags = 0;
...@@ -185,12 +184,11 @@ libxlDoMigrateSend(libxlDriverPrivatePtr driver, ...@@ -185,12 +184,11 @@ libxlDoMigrateSend(libxlDriverPrivatePtr driver,
if (flags & VIR_MIGRATE_LIVE) if (flags & VIR_MIGRATE_LIVE)
xl_flags = LIBXL_SUSPEND_LIVE; xl_flags = LIBXL_SUSPEND_LIVE;
priv = vm->privateData; ret = libxl_domain_suspend(cfg->ctx, vm->def->id, sockfd,
ret = libxl_domain_suspend(priv->ctx, vm->def->id, sockfd,
xl_flags, NULL); xl_flags, NULL);
if (ret != 0) { if (ret != 0) {
/* attempt to resume the domain on failure */ /* attempt to resume the domain on failure */
if (libxl_domain_resume(priv->ctx, vm->def->id, 1, 0) != 0) { if (libxl_domain_resume(cfg->ctx, vm->def->id, 1, 0) != 0) {
VIR_DEBUG("Failed to resume domain following failed migration"); VIR_DEBUG("Failed to resume domain following failed migration");
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, virDomainObjSetState(vm, VIR_DOMAIN_PAUSED,
VIR_DOMAIN_PAUSED_MIGRATION); VIR_DOMAIN_PAUSED_MIGRATION);
...@@ -547,7 +545,7 @@ libxlDomainMigrationFinish(virConnectPtr dconn, ...@@ -547,7 +545,7 @@ libxlDomainMigrationFinish(virConnectPtr dconn,
/* Unpause if requested */ /* Unpause if requested */
if (!(flags & VIR_MIGRATE_PAUSED)) { if (!(flags & VIR_MIGRATE_PAUSED)) {
if (libxl_domain_unpause(priv->ctx, vm->def->id) != 0) { if (libxl_domain_unpause(cfg->ctx, vm->def->id) != 0) {
virReportError(VIR_ERR_OPERATION_FAILED, "%s", virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("Failed to unpause domain")); _("Failed to unpause domain"));
goto cleanup; goto cleanup;
...@@ -577,7 +575,7 @@ libxlDomainMigrationFinish(virConnectPtr dconn, ...@@ -577,7 +575,7 @@ libxlDomainMigrationFinish(virConnectPtr dconn,
cleanup: cleanup:
if (dom == NULL) { if (dom == NULL) {
libxl_domain_destroy(priv->ctx, vm->def->id, NULL); libxl_domain_destroy(cfg->ctx, vm->def->id, NULL);
libxlDomainCleanup(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED); libxlDomainCleanup(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED);
event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED, event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED,
VIR_DOMAIN_EVENT_STOPPED_FAILED); VIR_DOMAIN_EVENT_STOPPED_FAILED);
...@@ -598,12 +596,11 @@ libxlDomainMigrationConfirm(libxlDriverPrivatePtr driver, ...@@ -598,12 +596,11 @@ libxlDomainMigrationConfirm(libxlDriverPrivatePtr driver,
int cancelled) int cancelled)
{ {
libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
libxlDomainObjPrivatePtr priv = vm->privateData;
virObjectEventPtr event = NULL; virObjectEventPtr event = NULL;
int ret = -1; int ret = -1;
if (cancelled) { if (cancelled) {
if (libxl_domain_resume(priv->ctx, vm->def->id, 1, 0) == 0) { if (libxl_domain_resume(cfg->ctx, vm->def->id, 1, 0) == 0) {
ret = 0; ret = 0;
} else { } else {
VIR_DEBUG("Unable to resume domain '%s' after failed migration", VIR_DEBUG("Unable to resume domain '%s' after failed migration",
...@@ -617,7 +614,7 @@ libxlDomainMigrationConfirm(libxlDriverPrivatePtr driver, ...@@ -617,7 +614,7 @@ libxlDomainMigrationConfirm(libxlDriverPrivatePtr driver,
goto cleanup; goto cleanup;
} }
libxl_domain_destroy(priv->ctx, vm->def->id, NULL); libxl_domain_destroy(cfg->ctx, vm->def->id, NULL);
libxlDomainCleanup(driver, vm, VIR_DOMAIN_SHUTOFF_MIGRATED); libxlDomainCleanup(driver, vm, VIR_DOMAIN_SHUTOFF_MIGRATED);
event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED, event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED,
VIR_DOMAIN_EVENT_STOPPED_MIGRATED); VIR_DOMAIN_EVENT_STOPPED_MIGRATED);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册