mirror of https://gitee.com/openkylin/libvirt.git
libxl: provide integration with lock manager
Provide integration with libvirt's lock manager in the libxl driver. Signed-off-by: Jim Fehlig <jfehlig@suse.com>
This commit is contained in:
parent
066f7c7c3a
commit
198cc1d339
|
@ -2247,6 +2247,12 @@ BUILT_SOURCES += locking/qemu-lockd.conf
|
||||||
DISTCLEANFILES += locking/qemu-lockd.conf
|
DISTCLEANFILES += locking/qemu-lockd.conf
|
||||||
endif WITH_QEMU
|
endif WITH_QEMU
|
||||||
|
|
||||||
|
if WITH_LIBXL
|
||||||
|
nodist_conf_DATA += locking/libxl-lockd.conf
|
||||||
|
BUILT_SOURCES += locking/libxl-lockd.conf
|
||||||
|
DISTCLEANFILES += locking/libxl-lockd.conf
|
||||||
|
endif WITH_LIBXL
|
||||||
|
|
||||||
locking/%-lockd.conf: $(srcdir)/locking/lockd.conf
|
locking/%-lockd.conf: $(srcdir)/locking/lockd.conf
|
||||||
$(AM_V_GEN)$(MKDIR_P) locking ; \
|
$(AM_V_GEN)$(MKDIR_P) locking ; \
|
||||||
cp $< $@
|
cp $< $@
|
||||||
|
@ -2432,6 +2438,12 @@ nodist_conf_DATA += locking/qemu-sanlock.conf
|
||||||
BUILT_SOURCES += locking/qemu-sanlock.conf
|
BUILT_SOURCES += locking/qemu-sanlock.conf
|
||||||
DISTCLEANFILES += locking/qemu-sanlock.conf
|
DISTCLEANFILES += locking/qemu-sanlock.conf
|
||||||
endif WITH_QEMU
|
endif WITH_QEMU
|
||||||
|
|
||||||
|
if WITH_LIBXL
|
||||||
|
nodist_conf_DATA += locking/libxl-sanlock.conf
|
||||||
|
BUILT_SOURCES += locking/libxl-sanlock.conf
|
||||||
|
DISTCLEANFILES += locking/libxl-sanlock.conf
|
||||||
|
endif WITH_LIBXL
|
||||||
else ! WITH_SANLOCK
|
else ! WITH_SANLOCK
|
||||||
EXTRA_DIST += $(LOCK_DRIVER_SANLOCK_SOURCES)
|
EXTRA_DIST += $(LOCK_DRIVER_SANLOCK_SOURCES)
|
||||||
endif ! WITH_SANLOCK
|
endif ! WITH_SANLOCK
|
||||||
|
|
|
@ -25,9 +25,11 @@ module Libvirtd_libxl =
|
||||||
|
|
||||||
(* Config entry grouped by function - same order as example config *)
|
(* Config entry grouped by function - same order as example config *)
|
||||||
let autoballoon_entry = bool_entry "autoballoon"
|
let autoballoon_entry = bool_entry "autoballoon"
|
||||||
|
let lock_entry = str_entry "lock_manager"
|
||||||
|
|
||||||
(* Each entry in the config is one of the following ... *)
|
(* Each entry in the config is one of the following ... *)
|
||||||
let entry = autoballoon_entry
|
let entry = autoballoon_entry
|
||||||
|
| lock_entry
|
||||||
|
|
||||||
let comment = [ label "#comment" . del /#[ \t]*/ "# " . store /([^ \t\n][^\n]*)?/ . del /\n/ "\n" ]
|
let comment = [ label "#comment" . del /#[ \t]*/ "# " . store /([^ \t\n][^\n]*)?/ . del /\n/ "\n" ]
|
||||||
let empty = [ label "#empty" . eol ]
|
let empty = [ label "#empty" . eol ]
|
||||||
|
|
|
@ -10,3 +10,13 @@
|
||||||
# autoballoon setting.
|
# autoballoon setting.
|
||||||
#
|
#
|
||||||
#autoballoon = 1
|
#autoballoon = 1
|
||||||
|
|
||||||
|
|
||||||
|
# In order to prevent accidentally starting two domains that
|
||||||
|
# share one writable disk, libvirt offers two approaches for
|
||||||
|
# locking files: sanlock and virtlockd. sanlock is an external
|
||||||
|
# project which libvirt integrates with via the libvirt-lock-sanlock
|
||||||
|
# package. virtlockd is a libvirt implementation that is enabled with
|
||||||
|
# "lockd". Accepted values are "sanlock" and "lockd".
|
||||||
|
#
|
||||||
|
#lock_manager = "lockd"
|
||||||
|
|
|
@ -102,6 +102,7 @@ libxlDriverConfigDispose(void *obj)
|
||||||
VIR_FREE(cfg->libDir);
|
VIR_FREE(cfg->libDir);
|
||||||
VIR_FREE(cfg->saveDir);
|
VIR_FREE(cfg->saveDir);
|
||||||
VIR_FREE(cfg->autoDumpDir);
|
VIR_FREE(cfg->autoDumpDir);
|
||||||
|
VIR_FREE(cfg->lockManagerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1498,6 +1499,7 @@ int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg,
|
||||||
const char *filename)
|
const char *filename)
|
||||||
{
|
{
|
||||||
virConfPtr conf = NULL;
|
virConfPtr conf = NULL;
|
||||||
|
virConfValuePtr p;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
/* Check the file is readable before opening it, otherwise
|
/* Check the file is readable before opening it, otherwise
|
||||||
|
@ -1515,6 +1517,18 @@ int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg,
|
||||||
if (libxlGetAutoballoonConf(cfg, conf) < 0)
|
if (libxlGetAutoballoonConf(cfg, conf) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
if ((p = virConfGetValue(conf, "lock_manager"))) {
|
||||||
|
if (p->type != VIR_CONF_STRING) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"%s",
|
||||||
|
_("Unexpected type for 'lock_manager' setting"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VIR_STRDUP(cfg->lockManagerName, p->str) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
# include "virobject.h"
|
# include "virobject.h"
|
||||||
# include "virchrdev.h"
|
# include "virchrdev.h"
|
||||||
# include "virhostdev.h"
|
# include "virhostdev.h"
|
||||||
|
# include "locking/lock_manager.h"
|
||||||
|
|
||||||
# define LIBXL_DRIVER_NAME "xenlight"
|
# define LIBXL_DRIVER_NAME "xenlight"
|
||||||
# define LIBXL_VNC_PORT_MIN 5900
|
# define LIBXL_VNC_PORT_MIN 5900
|
||||||
|
@ -98,6 +99,8 @@ struct _libxlDriverConfig {
|
||||||
* memory for new domains from domain0. */
|
* memory for new domains from domain0. */
|
||||||
bool autoballoon;
|
bool autoballoon;
|
||||||
|
|
||||||
|
char *lockManagerName;
|
||||||
|
|
||||||
/* Once created, caps are immutable */
|
/* Once created, caps are immutable */
|
||||||
virCapsPtr caps;
|
virCapsPtr caps;
|
||||||
|
|
||||||
|
@ -144,6 +147,9 @@ struct _libxlDriverPrivate {
|
||||||
|
|
||||||
/* Immutable pointer, lockless APIs*/
|
/* Immutable pointer, lockless APIs*/
|
||||||
virSysinfoDefPtr hostsysinfo;
|
virSysinfoDefPtr hostsysinfo;
|
||||||
|
|
||||||
|
/* Immutable pointer. lockless access */
|
||||||
|
virLockManagerPluginPtr lockManager;
|
||||||
};
|
};
|
||||||
|
|
||||||
# define LIBXL_SAVE_MAGIC "libvirt-xml\n \0 \r"
|
# define LIBXL_SAVE_MAGIC "libvirt-xml\n \0 \r"
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include "virlog.h"
|
#include "virlog.h"
|
||||||
#include "virstring.h"
|
#include "virstring.h"
|
||||||
#include "virtime.h"
|
#include "virtime.h"
|
||||||
|
#include "locking/domain_lock.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_LIBXL
|
#define VIR_FROM_THIS VIR_FROM_LIBXL
|
||||||
|
|
||||||
|
@ -217,12 +218,36 @@ libxlDomainObjPrivateFree(void *data)
|
||||||
{
|
{
|
||||||
libxlDomainObjPrivatePtr priv = data;
|
libxlDomainObjPrivatePtr priv = data;
|
||||||
|
|
||||||
|
VIR_FREE(priv->lockState);
|
||||||
virObjectUnref(priv);
|
virObjectUnref(priv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
libxlDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, void *data)
|
||||||
|
{
|
||||||
|
libxlDomainObjPrivatePtr priv = data;
|
||||||
|
|
||||||
|
priv->lockState = virXPathString("string(./lockstate)", ctxt);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
libxlDomainObjPrivateXMLFormat(virBufferPtr buf, void *data)
|
||||||
|
{
|
||||||
|
libxlDomainObjPrivatePtr priv = data;
|
||||||
|
|
||||||
|
if (priv->lockState)
|
||||||
|
virBufferAsprintf(buf, "<lockstate>%s</lockstate>\n", priv->lockState);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
virDomainXMLPrivateDataCallbacks libxlDomainXMLPrivateDataCallbacks = {
|
virDomainXMLPrivateDataCallbacks libxlDomainXMLPrivateDataCallbacks = {
|
||||||
.alloc = libxlDomainObjPrivateAlloc,
|
.alloc = libxlDomainObjPrivateAlloc,
|
||||||
.free = libxlDomainObjPrivateFree,
|
.free = libxlDomainObjPrivateFree,
|
||||||
|
.parse = libxlDomainObjPrivateXMLParse,
|
||||||
|
.format = libxlDomainObjPrivateXMLFormat,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -667,6 +692,11 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
|
||||||
virHostdevReAttachDomainDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
|
virHostdevReAttachDomainDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
|
||||||
vm->def, VIR_HOSTDEV_SP_PCI, NULL);
|
vm->def, VIR_HOSTDEV_SP_PCI, NULL);
|
||||||
|
|
||||||
|
VIR_FREE(priv->lockState);
|
||||||
|
if (virDomainLockProcessPause(driver->lockManager, vm, &priv->lockState) < 0)
|
||||||
|
VIR_WARN("Unable to release lease on %s", vm->def->name);
|
||||||
|
VIR_DEBUG("Preserving lock state '%s'", NULLSTR(priv->lockState));
|
||||||
|
|
||||||
vm->def->id = -1;
|
vm->def->id = -1;
|
||||||
|
|
||||||
if (priv->deathW) {
|
if (priv->deathW) {
|
||||||
|
@ -960,6 +990,20 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
|
||||||
vm->def, VIR_HOSTDEV_SP_PCI) < 0)
|
vm->def, VIR_HOSTDEV_SP_PCI) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
if (virDomainLockProcessStart(driver->lockManager,
|
||||||
|
"xen:///system",
|
||||||
|
vm,
|
||||||
|
true,
|
||||||
|
NULL) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (virDomainLockProcessResume(driver->lockManager,
|
||||||
|
"xen:///system",
|
||||||
|
vm,
|
||||||
|
priv->lockState) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
VIR_FREE(priv->lockState);
|
||||||
|
|
||||||
/* Unlock virDomainObj while creating the domain */
|
/* Unlock virDomainObj while creating the domain */
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
|
|
||||||
|
@ -990,7 +1034,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("libxenlight failed to restore domain '%s'"),
|
_("libxenlight failed to restore domain '%s'"),
|
||||||
d_config.c_info.name);
|
d_config.c_info.name);
|
||||||
goto cleanup;
|
goto release_dom;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1003,6 +1047,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
|
||||||
if (libxl_evenable_domain_death(cfg->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;
|
||||||
|
|
||||||
|
@ -1040,6 +1085,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
cleanup_dom:
|
cleanup_dom:
|
||||||
|
ret = -1;
|
||||||
if (priv->deathW) {
|
if (priv->deathW) {
|
||||||
libxl_evdisable_domain_death(cfg->ctx, priv->deathW);
|
libxl_evdisable_domain_death(cfg->ctx, priv->deathW);
|
||||||
priv->deathW = NULL;
|
priv->deathW = NULL;
|
||||||
|
@ -1048,6 +1094,9 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
|
||||||
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);
|
||||||
|
|
||||||
|
release_dom:
|
||||||
|
virDomainLockProcessPause(driver->lockManager, vm, &priv->lockState);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
libxl_domain_config_dispose(&d_config);
|
libxl_domain_config_dispose(&d_config);
|
||||||
VIR_FREE(dom_xml);
|
VIR_FREE(dom_xml);
|
||||||
|
|
|
@ -64,6 +64,7 @@ struct _libxlDomainObjPrivate {
|
||||||
virChrdevsPtr devs;
|
virChrdevsPtr devs;
|
||||||
libxl_evgen_domain_death *deathW;
|
libxl_evgen_domain_death *deathW;
|
||||||
unsigned short migrationPort;
|
unsigned short migrationPort;
|
||||||
|
char *lockState;
|
||||||
|
|
||||||
struct libxlDomainJobObj job;
|
struct libxlDomainJobObj job;
|
||||||
};
|
};
|
||||||
|
|
|
@ -57,6 +57,7 @@
|
||||||
#include "viratomic.h"
|
#include "viratomic.h"
|
||||||
#include "virhostdev.h"
|
#include "virhostdev.h"
|
||||||
#include "network/bridge_driver.h"
|
#include "network/bridge_driver.h"
|
||||||
|
#include "locking/domain_lock.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_LIBXL
|
#define VIR_FROM_THIS VIR_FROM_LIBXL
|
||||||
|
|
||||||
|
@ -411,6 +412,7 @@ libxlStateCleanup(void)
|
||||||
virObjectUnref(libxl_driver->domains);
|
virObjectUnref(libxl_driver->domains);
|
||||||
virObjectUnref(libxl_driver->reservedVNCPorts);
|
virObjectUnref(libxl_driver->reservedVNCPorts);
|
||||||
virObjectUnref(libxl_driver->migrationPorts);
|
virObjectUnref(libxl_driver->migrationPorts);
|
||||||
|
virLockManagerPluginUnref(libxl_driver->lockManager);
|
||||||
|
|
||||||
virObjectEventStateFree(libxl_driver->domainEventState);
|
virObjectEventStateFree(libxl_driver->domainEventState);
|
||||||
virSysinfoDefFree(libxl_driver->hostsysinfo);
|
virSysinfoDefFree(libxl_driver->hostsysinfo);
|
||||||
|
@ -590,6 +592,14 @@ libxlStateInitialize(bool privileged,
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(libxl_driver->lockManager =
|
||||||
|
virLockManagerPluginNew(cfg->lockManagerName ?
|
||||||
|
cfg->lockManagerName : "nop",
|
||||||
|
"libxl",
|
||||||
|
cfg->configBaseDir,
|
||||||
|
0)))
|
||||||
|
goto error;
|
||||||
|
|
||||||
/* read the host sysinfo */
|
/* read the host sysinfo */
|
||||||
libxl_driver->hostsysinfo = virSysinfoRead();
|
libxl_driver->hostsysinfo = virSysinfoRead();
|
||||||
|
|
||||||
|
@ -2859,11 +2869,21 @@ libxlDomainAttachDeviceDiskLive(virDomainObjPtr vm, virDomainDeviceDefPtr dev)
|
||||||
if (libxlMakeDisk(l_disk, &x_disk) < 0)
|
if (libxlMakeDisk(l_disk, &x_disk) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
if (virDomainLockDiskAttach(libxl_driver->lockManager,
|
||||||
|
"xen:///system",
|
||||||
|
vm, l_disk) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if ((ret = libxl_device_disk_add(cfg->ctx, vm->def->id,
|
if ((ret = libxl_device_disk_add(cfg->ctx, vm->def->id,
|
||||||
&x_disk, NULL)) < 0) {
|
&x_disk, NULL)) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("libxenlight failed to attach disk '%s'"),
|
_("libxenlight failed to attach disk '%s'"),
|
||||||
l_disk->dst);
|
l_disk->dst);
|
||||||
|
if (virDomainLockDiskDetach(libxl_driver->lockManager,
|
||||||
|
vm, l_disk) < 0) {
|
||||||
|
VIR_WARN("Unable to release lock on %s",
|
||||||
|
virDomainDiskGetSource(l_disk));
|
||||||
|
}
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3004,6 +3024,11 @@ libxlDomainDetachDeviceDiskLive(virDomainObjPtr vm, virDomainDeviceDefPtr dev)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (virDomainLockDiskDetach(libxl_driver->lockManager,
|
||||||
|
vm, l_disk) < 0)
|
||||||
|
VIR_WARN("Unable to release lock on %s",
|
||||||
|
virDomainDiskGetSource(l_disk));
|
||||||
|
|
||||||
virDomainDiskRemove(vm->def, idx);
|
virDomainDiskRemove(vm->def, idx);
|
||||||
virDomainDiskDefFree(l_disk);
|
virDomainDiskDefFree(l_disk);
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include "libxl_driver.h"
|
#include "libxl_driver.h"
|
||||||
#include "libxl_conf.h"
|
#include "libxl_conf.h"
|
||||||
#include "libxl_migration.h"
|
#include "libxl_migration.h"
|
||||||
|
#include "locking/domain_lock.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_LIBXL
|
#define VIR_FROM_THIS VIR_FROM_LIBXL
|
||||||
|
|
||||||
|
@ -469,6 +470,7 @@ libxlDomainMigrationPerform(libxlDriverPrivatePtr driver,
|
||||||
const char *dname ATTRIBUTE_UNUSED,
|
const char *dname ATTRIBUTE_UNUSED,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
|
libxlDomainObjPrivatePtr priv = vm->privateData;
|
||||||
char *hostname = NULL;
|
char *hostname = NULL;
|
||||||
unsigned short port = 0;
|
unsigned short port = 0;
|
||||||
char portstr[100];
|
char portstr[100];
|
||||||
|
@ -503,6 +505,10 @@ libxlDomainMigrationPerform(libxlDriverPrivatePtr driver,
|
||||||
sockfd = virNetSocketDupFD(sock, true);
|
sockfd = virNetSocketDupFD(sock, true);
|
||||||
virObjectUnref(sock);
|
virObjectUnref(sock);
|
||||||
|
|
||||||
|
if (virDomainLockProcessPause(driver->lockManager, vm, &priv->lockState) < 0)
|
||||||
|
VIR_WARN("Unable to release lease on %s", vm->def->name);
|
||||||
|
VIR_DEBUG("Preserving lock state '%s'", NULLSTR(priv->lockState));
|
||||||
|
|
||||||
/* suspend vm and send saved data to dst through socket fd */
|
/* suspend vm and send saved data to dst through socket fd */
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
ret = libxlDoMigrateSend(driver, vm, flags, sockfd);
|
ret = libxlDoMigrateSend(driver, vm, flags, sockfd);
|
||||||
|
|
|
@ -3,3 +3,4 @@ module Test_libvirtd_libxl =
|
||||||
|
|
||||||
test Libvirtd_libxl.lns get conf =
|
test Libvirtd_libxl.lns get conf =
|
||||||
{ "autoballoon" = "1" }
|
{ "autoballoon" = "1" }
|
||||||
|
{ "lock_manager" = "lockd" }
|
||||||
|
|
Loading…
Reference in New Issue