libxl: use libxl_event_wait to process libxl events
A message that is not in the archive (sent off-list or not yet received): [email protected]
Am Fri, 13 Nov 2015 14:36:54 -0700
schrieb Jim Fehlig <[email protected]>:
Hi,
i have tested the patches provide by Jim Fehlig.
The setup consist of xen 4.6.0 with libvirt 1.2.19 and the patches. As i describe in my posting in the libvirt-user list
(https://www.redhat.com/archives/libvir-list/2015-November/msg00130.html),
the system resume 20 VM´s in parallel, attach a block-device and then attach a network-device, run 60 seconds, destroy each vm and starts again.
until now the test-system has done 1820 cycles
i observe , until now, no errors, no crashes and also the system doesn´t freeze. Everything looks good.
so thank´s a lot for your time, work and help.
all the best
max
Quoted 276 lines
Prior to this patch, libxl events were delivered to libvirt via the libxlDomainEventHandler callback registered with libxl. Documenation in
$xensrc/tools/libxl/libxl_event.hstates that the callback "may occur on any thread in which the application calls libxl". This can result in deadlock since many of the libvirt callees of libxl hold a lock on the virDomainObj they are working on. When the callback is invoked, it attempts to find a virDomainObj corresponding to the domain ID provided by libxl. Searching the domain obj list results in locking each obj before checking if it is active, and its ID equals the requested ID. Deadlock is possible when attempting to lock an obj that is already locked further up the call stack. Indeed, Max Ustermann recently reported an instance of this deadlockhttps://www.redhat.com/archives/libvir-list/2015-November/msg00130.html
This patch moves processing of libxl events to a thread, where
libxl_event_wait()is used to collect events. This allows processing libxl events asynchronously in libvirt, avoiding the deadlock.Reported-by max ustermann <[email protected]>Signed-off-by Jim Fehlig <[email protected]>---
The only reservations I have about this patch come from comments about
libxl_event_waitinlibxl_event.hLike
libxl_event_checkbut blocks if no suitable events are available, until some are. Uses libxl_osevent_beforepoll/_afterpollso may be inefficient if very many domains are being handled by a single program.libvirt does handle "very many domains" :-). But thus far, I haven't noticed any problems in my testing. The reporter expressed interest in testing the patch. Positive results from that testing would improve my confidence, as would an ACK from Ian Jackson.
src/libxl/libxl_domain.c | 130++++++++++++++++++++++-------------------------
src/libxl/libxl_domain.h| 16 +-----src/libxl/libxl_driver.c| 13 ++--- 3 files changed, 66 insertions(+), 93 deletions(-)src/libxl/libxl_domain.c +0
-0@@ -380,27 +380,14 @@ virDomainDefParserConfiglibxlDomainDefParserConfig = { .domainPostParseCallback = libxlDomainDefPostParse, };
src/libxl/libxl_domain.c +3
-14- -struct libxlShutdownThreadInfo -{ -libxlDriverPrivatePtr driver; -virDomainObjPtr vm; -libxl_event *event; -}; - -static void -libxlDomainShutdownThread (void *opaque) +libxlDomainShutdownEventHandler (libxlDriverPrivatePtr driver, +virDomainObjPtr vm, +libxl_event *ev) { -struct libxlShutdownThreadInfo *shutdown_info = opaque; -virDomainObjPtr vm = shutdown_info->vm; -libxl_event *ev = shutdown_info->event; -libxlDriverPrivatePtr driver = shutdown_info->driver;virObjectEventPtr dom_event =NULL ; libxl_shutdown_reason xl_reason =
ev->u.domain_shutdown.shutdown_reason;src/libxl/libxl_domain.c +14
-6-libxlDriverConfigPtr cfg; - - cfg =libxlDriverConfigGet (driver); +libxlDriverConfigPtr cfg =libxlDriverConfigGet (driver);if (libxlDomainObjBeginJob (driver, vm,LIBXL_JOB_MODIFY ) <0 ) goto cleanup;@@ -501,74 +488,77 @@ libxlDomainShutdownThread(void *opaque)virObjectUnlock (vm);if (dom_event)libxlDomainEventQueue (driver, dom_event); -libxl_event_free (cfg->ctx, ev); -VIR_FREE (shutdown_info);virObjectUnref (cfg); } +static int +libxlDomainXEventsPredicate (const libxl_event *event, + ATTRIBUTE_UNUSED void *data) +{ +/* +* Currently we only handle shutdown event +*/ +if (event->type ==LIBXL_EVENT_TYPE_DOMAIN_SHUTDOWN ) +return 1 ; + +return 0 ; +} +/* -* Handle previously registered domain event notification from libxenlight.
+ * Process events from libxl usinglibxl_event_wait. */src/libxl/libxl_domain.c +0
-2-void -libxlDomainEventHandler(void *data, VIR_LIBXL_EVENT_CONST
libxl_event*event) +static voidsrc/libxl/libxl_domain.c +3
-2+libxlDomainXEventsProcess(void *opaque) { -libxlDriverPrivatePtr driver = data; +libxlDriverPrivatePtr driver = opaque; +libxl_event *event;virDomainObjPtr vm =NULL ; - libxl_shutdown_reason xl_reason =
event->u.domain_shutdown.shutdown_reason;src/libxl/libxl_domain.c +6
-9-struct libxlShutdownThreadInfo *shutdown_info =NULL ; -virThread thread; -libxlDriverConfigPtr cfg; +libxl_shutdown_reason xl_reason; +libxlDriverConfigPtr cfg =libxlDriverConfigGet (driver); -if (event->type !=LIBXL_EVENT_TYPE_DOMAIN_SHUTDOWN ) { -VIR_INFO ("Unhandled event type %d" , event->type); - goto error; - } +while (1 ) { + event =NULL ; +libxl_event_wait (cfg->ctx, &event,LIBXL_EVENTMASK_ALL , + libxlDomainXEventsPredicate,NULL ); -/* -* Similar to the xl implementation, ignore SUSPEND. Any actions needed
- * after callinglibxl_domain_suspend()are handled by its
callers.src/libxl/libxl_domain.c +4
-6-*/ -if (xl_reason ==LIBXL_SHUTDOWN_REASON_SUSPEND ) - goto error; +if (event ==NULL ) { +VIR_INFO ("libxl_event_wait returned a NULL event" ); +continue ; + } - vm =virDomainObjListFindByID (driver->domains, event->domid); -if (!vm) { - VIR_INFO("Received event for unknown domain ID %d",
event->domid);src/libxl/libxl_domain.c +0
-5- goto error; - } - -/* -* Start a thread to handle shutdown. We don't want to be tying up
- * libxl's event machinery by doing a potentially lengthy
shutdown.src/libxl/libxl_domain.c +2
-10-*/ -if (VIR_ALLOC (shutdown_info) <0 ) - goto error; - - shutdown_info->driver = driver; - shutdown_info->vm = vm; - shutdown_info->event = (libxl_event *)event; -if (virThreadCreate (&thread, false, libxlDomainShutdownThread, - shutdown_info) <0 ) { + xl_reason = event->u.domain_shutdown.shutdown_reason;/* -* Not much we can do on error here except log it. +* Similar to the xl implementation, ignore SUSPEND. Any actions needed
+ * after callinglibxl_domain_suspend()are handled by its
callers. */
- VIR_ERROR(_("Failed to create thread to handle domain
shutdown"));src/libxl/libxl_domain.c +8
-1- goto error; +if (xl_reason ==LIBXL_SHUTDOWN_REASON_SUSPEND ) { +libxl_event_free (cfg->ctx, event); +continue ; + } + + vm =virDomainObjListFindByID (driver->domains, event->domid); +if (!vm) { + VIR_INFO("Received event for unknown domain ID %d",
event->domid);src/libxl/libxl_domain.c +14
-12+libxl_event_free (cfg->ctx, event); +continue ; + } + +libxlDomainShutdownEventHandler (driver, vm, event); +libxl_event_free (cfg->ctx, event); } -/* -* VM is unlocked and libxl_event freed in shutdown thread -*/ -return ; - - error: - cfg =libxlDriverConfigGet (driver); -/* Cast away any const */ -libxl_event_free (cfg->ctx, (libxl_event *)event);virObjectUnref (cfg); -if (vm) -virObjectUnlock (vm); -VIR_FREE (shutdown_info); +} + +int +libxlDomainXEventsInit (libxlDriverPrivatePtr driver) +{ +virThread thread; + + if (virThreadCreate(&thread, false, libxlDomainXEventsProcess,driver) < 0)
src/libxl/libxl_domain.c +3
-0+return -1 ; + +return 0 ; }void src/libxl/libxl_domain.h +2
-14@@ -112,20 +112,8 @@ void libxlDomainCleanup(libxlDriverPrivatePtr driver, virDomainObjPtr vm); -/* -* Note: Xen 4.3 removed the const from the event handler signature. -* Detect which signature to use based on -* LIBXL_HAVE_NONCONST_EVENT_OCCURS_EVENT_ARG. -*/ -# ifdef LIBXL_HAVE_NONCONST_EVENT_OCCURS_EVENT_ARG -# define VIR_LIBXL_EVENT_CONST /* empty */ -# else -# define VIR_LIBXL_EVENT_CONST const -# endif - -void -libxlDomainEventHandler (void *data, - VIR_LIBXL_EVENT_CONST libxl_event *event); +int +libxlDomainXEventsInit (libxlDriverPrivatePtr driver); int libxlDomainAutoCoreDump(libxlDriverPrivatePtr driver,src/libxl/libxl_driver.c +0
-0@@ -503,12 +503,6 @@ static const libxl_childproc_hooks
libxl_child_hooks= { #endif
};src/libxl/libxl_driver.c +0
-6-const struct libxl_event_hooks ev_hooks = { - .event_occurs_mask =LIBXL_EVENTMASK_ALL , - .event_occurs = libxlDomainEventHandler, - .disaster =NULL , -}; -static int libxlAddDom0 (libxlDriverPrivatePtr driver) {@@ -626,9 +620,6 @@ libxlStateInitialize(bool privileged,/* Setup child process handling. See
$xen-src/tools/libxl/libxl_event.h*/libxl_childproc_setmode(cfg->ctx, &libxl_child_hooks, cfg->ctx);src/libxl/libxl_driver.c +0
-2-/* Register callback to handle domain events */ - libxl_event_register_callbacks(cfg->ctx, &ev_hooks,
libxl_driver); -libxl_driver->config = cfg; if (virFileMakePath(cfg->stateDir) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR,
src/libxl/libxl_driver.c libxlStateInitialize(bool privileged, · line 683
Quoted 10 lines
src/libxl/libxl_driver.c +4
-0@@ -683,6 +674,10 @@ libxlStateInitialize(bool privileged,if (!(libxl_driver->xmlopt =libxlCreateXMLConf ())) goto error; +/* Start processing events from libxl */ +if (libxlDomainXEventsInit (libxl_driver) <0 ) + goto error; +/* Add Domain-0 */ if (libxlAddDom0 (libxl_driver) <0 ) goto error;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 32 lines · Jim Fehlig
Prior to this patch, libxl events were delivered to libvirt via the libxlDomainEventHandler callback registered with libxl. Documenation in
$xensrc/tools/libxl/libxl_event.hstates that the callback "may occur on any thread in which the application calls libxl". This can result in deadlock since many of the libvirt callees of libxl hold a lock on the virDomainObj they are working on. When the callback is invoked, it attempts to find a virDomainObj corresponding to the domain ID provided by libxl. Searching the domain obj list results in locking each obj before checking if it is active, and its ID equals the requested ID. Deadlock is possible when attempting to lock an obj that is already locked further up the call stack. Indeed, Max Ustermann recently reported an instance of this deadlockhttps://www.redhat.com/archives/libvir-list/2015-November/msg00130.html
This patch moves processing of libxl events to a thread, where
libxl_event_wait()is used to collect events. This allows processing libxl events asynchronously in libvirt, avoiding the deadlock.Reported-by max ustermann <[email protected]>Signed-off-by Jim Fehlig <[email protected]>---
The only reservations I have about this patch come from comments about
libxl_event_waitinlibxl_event.hLike
libxl_event_checkbut blocks if no suitable events are available, until some are. Uses libxl_osevent_beforepoll/_afterpollso may be inefficient if very many domains are being handled by a single program.
Quoted 4 lines
libvirt does handle "very many domains" :-). But thus far, I haven't noticed any problems in my testing. The reporter expressed interest in testing the patch. Positive results from that testing would improve my confidence, as would an ACK from Ian Jackson.
Would it be possible/allowable to have your cake and eat it by using the callbacks but having them simply enqueue the events on the libvirt side and kick the dedicated thread for further processing?
Or we could consider whether libxl should gain such functionality.
Quoted 245 lines
src/libxl/libxl_domain.c | 130 ++++++++++++++++++++++-------------------
------
src/libxl/libxl_domain.h | 16 +-----src/libxl/libxl_driver.c| 13 ++---3 files changed, 66 insertions(+), 93 deletions(-)src/libxl/libxl_domain.c +0
-0@@ -380,27 +380,14 @@ virDomainDefParserConfig libxlDomainDefParserConfig = { .domainPostParseCallback = libxlDomainDefPostParse, };src/libxl/libxl_domain.c +0
-9- -struct libxlShutdownThreadInfo -{ - libxlDriverPrivatePtr driver; - virDomainObjPtr vm; - libxl_event *event; -}; - -static void
src/libxl/libxl_domain.c +3
-1-libxlDomainShutdownThread (void *opaque) +libxlDomainShutdownEventHandler(libxlDriverPrivatePtr driver, + virDomainObjPtr vm, + libxl_event *ev){
- struct libxlShutdownThreadInfo*shutdown_info= opaque; - virDomainObjPtr vm =shutdown_info->vm;
- libxl_event *ev =shutdown_info->event;
- libxlDriverPrivatePtr driver =shutdown_info->driver; virObjectEventPtrdom_event= NULL;libxl_shutdown_reasonxl_reason= ev-Quoted 1 line
u.domain_shutdown.shutdown_reason;
- libxlDriverConfigPtr cfg;
-
- cfg = libxlDriverConfigGet(driver);
+ libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY)< 0) goto cleanup;src/libxl/libxl_domain.c +0
-2@@ -501,74 +488,77 @@ libxlDomainShutdownThread(void *opaque) virObjectUnlock(vm); if (dom_event) libxlDomainEventQueue(driver, dom_event); - libxl_event_free(cfg->ctx, ev); - VIR_FREE(shutdown_info); virObjectUnref(cfg); }src/libxl/libxl_domain.c +13
-0+static int +libxlDomainXEventsPredicate (const libxl_event *event, + ATTRIBUTE_UNUSED void *data) +{ + /* + * Currently we only handle shutdown event + */ + if (event->type == LIBXL_EVENT_TYPE_DOMAIN_SHUTDOWN) + return 1; + + return 0; +} +/*
- * Handle previously registered domain event notification from libxenlight.
+ * Process events from libxl usinglibxl_event_wait. */src/libxl/libxl_domain.c +0
-2-void -libxlDomainEventHandler(void *data, VIR_LIBXL_EVENT_CONST libxl_event*event)
src/libxl/libxl_domain.c +2
-0+static void +libxlDomainXEventsProcess (void *opaque){
- libxlDriverPrivatePtr driver = data;
+ libxlDriverPrivatePtr driver = opaque;
+ libxl_event *event;
virDomainObjPtr vm = NULL;
- libxl_shutdown_reasonxl_reason= event-Quoted 1 line
u.domain_shutdown.shutdown_reason;
- struct libxlShutdownThreadInfo
*shutdown_info= NULL;
- virThread thread;
- libxlDriverConfigPtr cfg;
+ libxl_shutdown_reasonxl_reason;
+ libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
- if (event->type!=LIBXL_EVENT_TYPE_DOMAIN_SHUTDOWN) { - VIR_INFO("Unhandled event type %d",event->type);
- goto error;
- }
+ while (1) {
+ event = NULL;
+ libxl_event_wait(cfg->ctx, &event,LIBXL_EVENTMASK_ALL, + libxlDomainXEventsPredicate, NULL);
- /*
- * Similar to the xl implementation, ignore SUSPEND. Any actions needed
- * after callinglibxl_domain_suspend()are handled by its callers. - */
- if (xl_reason==LIBXL_SHUTDOWN_REASON_SUSPEND)
- goto error;
+ if (event == NULL) {
+ VIR_INFO("libxl_event_wait returned a NULL event"); + continue;
+ }
- vm =virDomainObjListFindByID(driver->domains, event->domid); - if (!vm) {
- VIR_INFO("Received event for unknown domain ID %d", event-Quoted 1 line
domid);
- goto error;
- }src/libxl/libxl_domain.c +1
-13- - /* - * Start a thread to handle shutdown. We don't want to be tying up - * libxl's event machinery by doing a potentially lengthy shutdown. - */ - if (VIR_ALLOC(shutdown_info) < 0) - goto error; - - shutdown_info->driver = driver; - shutdown_info->vm = vm; - shutdown_info->event = (libxl_event *)event; - if (virThreadCreate(&thread, false, libxlDomainShutdownThread, - shutdown_info) < 0) { + xl_reason = event->u.domain_shutdown.shutdown_reason;/*
- * Not much we can do on error here except log it. + * Similar to the xl implementation, ignore SUSPEND. Any actions needed
+ * after callinglibxl_domain_suspend()are handled by its callers.
*/
- VIR_ERROR(_("Failed to create thread to handle domain shutdown"));
- goto error;
+ if (xl_reason==LIBXL_SHUTDOWN_REASON_SUSPEND) {
+ libxl_event_free(cfg->ctx, event);
+ continue;
+ }
+
+ vm =virDomainObjListFindByID(driver->domains, event->domid); + if (!vm) {
+ VIR_INFO("Received event for unknown domain ID %d", event-Quoted 1 line
domid);
+ libxl_event_free(cfg->ctx, event);
+ continue;
+ }
+
+ libxlDomainShutdownEventHandler(driver, vm, event); + libxl_event_free(cfg->ctx, event);
}
- /*
- * VM is unlocked andlibxl_eventfreed in shutdown thread - */
- return;
-
- error:
- cfg = libxlDriverConfigGet(driver);
- /* Cast away any const */
- libxl_event_free(cfg->ctx, (libxl_event*)event); virObjectUnref(cfg);
- if (vm)
- virObjectUnlock(vm);
- VIR_FREE(shutdown_info);src/libxl/libxl_domain.c +8
-0+} + +int +libxlDomainXEventsInit (libxlDriverPrivatePtr driver) +{ + virThread thread; + + if (virThreadCreate(&thread, false, libxlDomainXEventsProcess,driver) < 0)
+ return -1;
+
+ return 0;
}
voidsrc/libxl/libxl_domain.h +0
-0@@ -112,20 +112,8 @@ void libxlDomainCleanup(libxlDriverPrivatePtr driver, virDomainObjPtr vm);src/libxl/libxl_domain.h +2
-14-/* -* Note: Xen 4.3 removed the const from the event handler signature. -* Detect which signature to use based on -* LIBXL_HAVE_NONCONST_EVENT_OCCURS_EVENT_ARG. -*/ -# ifdef LIBXL_HAVE_NONCONST_EVENT_OCCURS_EVENT_ARG -# define VIR_LIBXL_EVENT_CONST /* empty */ -# else -# define VIR_LIBXL_EVENT_CONST const -# endif - -void -libxlDomainEventHandler (void *data, - VIR_LIBXL_EVENT_CONST libxl_event *event); +int +libxlDomainXEventsInit (libxlDriverPrivatePtr driver);
int libxlDomainAutoCoreDump(libxlDriverPrivatePtr driver,src/libxl/libxl_driver.c +0
-0@@ -503,12 +503,6 @@ static const libxl_childproc_hooks libxl_child_hooks = { #endif };src/libxl/libxl_driver.c +0
-6-const struct libxl_event_hooks ev_hooks = { - .event_occurs_mask = LIBXL_EVENTMASK_ALL, - .event_occurs = libxlDomainEventHandler, - .disaster = NULL, -}; -static int
libxlAddDom0(libxlDriverPrivatePtr driver)
{src/libxl/libxl_driver.c +0
-0@@ -626,9 +620,6 @@ libxlStateInitialize(bool privileged, /* Setup child process handling. See $xen-
src/tools/libxl/libxl_event.h*/libxl_childproc_setmode(cfg->ctx, &libxl_child_hooks, cfg->ctx);
- /* Register callback to handle domain events */
- libxl_event_register_callbacks(cfg->ctx,&ev_hooks,libxl_driver); -
libxl_driver->config = cfg;
if (virFileMakePath(cfg->stateDir)< 0) { virReportError(VIR_ERR_INTERNAL_ERROR,src/libxl/libxl_driver.c +0
-0@@ -683,6 +674,10 @@ libxlStateInitialize(bool privileged, if (!(libxl_driver->xmlopt = libxlCreateXMLConf())) goto error;
Quoted 8 lines
+ /* Start processing events from libxl */ + if (libxlDomainXEventsInit(libxl_driver)< 0) + goto error;
+
/* Add Domain-0 */
if (libxlAddDom0(libxl_driver)< 0) goto error;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 33 lines · Ian Campbell
Quoted 32 lines · Jim Fehlig
Prior to this patch, libxl events were delivered to libvirt via the libxlDomainEventHandler callback registered with libxl. Documenation in
$xensrc/tools/libxl/libxl_event.hstates that the callback "may occur on any thread in which the application calls libxl". This can result in deadlock since many of the libvirt callees of libxl hold a lock on the virDomainObj they are working on. When the callback is invoked, it attempts to find a virDomainObj corresponding to the domain ID provided by libxl. Searching the domain obj list results in locking each obj before checking if it is active, and its ID equals the requested ID. Deadlock is possible when attempting to lock an obj that is already locked further up the call stack. Indeed, Max Ustermann recently reported an instance of this deadlockhttps://www.redhat.com/archives/libvir-list/2015-November/msg00130.html
This patch moves processing of libxl events to a thread, where
libxl_event_wait()is used to collect events. This allows processing libxl events asynchronously in libvirt, avoiding the deadlock.Reported-by max ustermann <[email protected]>Signed-off-by Jim Fehlig <[email protected]>---
The only reservations I have about this patch come from comments about
libxl_event_waitinlibxl_event.hLike
libxl_event_checkbut blocks if no suitable events are available, until some are. Uses libxl_osevent_beforepoll/_afterpollso may be inefficient if very many domains are being handled by a single program.
Quoted 7 lines
Quoted 4 lines
libvirt does handle "very many domains" :-). But thus far, I haven't noticed any problems in my testing. The reporter expressed interest in testing the patch. Positive results from that testing would improve my confidence, as would an ACK from Ian Jackson.
Would it be possible/allowable to have your cake and eat it by using the callbacks but having them simply enqueue the events on the libvirt side and kick the dedicated thread for further processing?
Sure. But it is not clear how "externally triggered" events are handled. E.g. guest admin performs shutdown or reboot. I was under the impression libxl_event_wait() or registering an event_occurs handler was the only way to receive those events.
Regards,
Jim
Ian Jackson
Acked-byJim Fehlig writes ("[PATCH RFC] libxl: use libxl_event_wait to process libxl events"):
Quoted 5 lines
Prior to this patch, libxl events were delivered to libvirt via the libxlDomainEventHandler callback registered with libxl. Documenation in
$xensrc/tools/libxl/libxl_event.hstates that the callback "may occur on any thread in which the application calls libxl". This can result in deadlock since many of the libvirt
Quoted 8 lines
callees of libxl hold a lock on the virDomainObj they are working on. When the callback is invoked, it attempts to find a virDomainObj corresponding to the domain ID provided by libxl. Searching the domain obj list results in locking each obj before checking if it is active, and its ID equals the requested ID. Deadlock is possible when attempting to lock an obj that is already locked further up the call stack. Indeed, Max Ustermann recently reported an instance of this deadlock
This sounds like a very plausible failure mode.
Quoted 5 lines
https://www.redhat.com/archives/libvir-list/2015-November/msg00130.html
This patch moves processing of libxl events to a thread, where
libxl_event_wait()is used to collect events. This allows processing libxl events asynchronously in libvirt, avoiding the deadlock.
The reasoning is sound and the remedy is IMO correct. (However, you mean "this allows processing libxl events _synchronously_", since what you are doing is serialising them all into your main loop.)
So:
NB that I have not reviewed the patch in detail. I can do that if you like, although of course my knowledge of the innards of libvirt is not wonderful.
Quoted 7 lines
The only reservations I have about this patch come from comments about
libxl_event_waitinlibxl_event.hLike
libxl_event_checkbut blocks if no suitable events are available, until some are. Uses libxl_osevent_beforepoll/_afterpollso may be inefficient if very many domains are being handled by a single program.
If this turns out to be a problem in practice, we will improve libxl's data structures to not involve so many linear searches. (In fact I think you are probably already calling synchronous libxl ao functions, which have the same performance properties, although this is not documented.)
Given what you say above I don't think there is a reasonable alternative remedy. So you should go ahead with this patch.
Regards,
Ian.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 16 lines · Ian Jackson
Jim Fehlig writes ("[PATCH RFC] libxl: use
libxl_event_waitto process libxl events"):Quoted 5 lines
Prior to this patch, libxl events were delivered to libvirt via the libxlDomainEventHandler callback registered with libxl. Documenation in
$xensrc/tools/libxl/libxl_event.hstates that the callback "may occur on any thread in which the application calls libxl". This can result in deadlock since many of the libvirtQuoted 8 lines
callees of libxl hold a lock on the virDomainObj they are working on. When the callback is invoked, it attempts to find a virDomainObj corresponding to the domain ID provided by libxl. Searching the domain obj list results in locking each obj before checking if it is active, and its ID equals the requested ID. Deadlock is possible when attempting to lock an obj that is already locked further up the call stack. Indeed, Max Ustermann recently reported an instance of this deadlock
This sounds like a very plausible failure mode.
Quoted 8 lines
Quoted 5 lines
https://www.redhat.com/archives/libvir-list/2015-November/msg00130.html
This patch moves processing of libxl events to a thread, where
libxl_event_wait()is used to collect events. This allows processing libxl events asynchronously in libvirt, avoiding the deadlock.The reasoning is sound and the remedy is IMO correct. (However, you mean "this allows processing libxl events _synchronously_", since what you are doing is serialising them all into your main loop.)
Ah yes, poor choice of words. The last sentence should read:
This approach gives libvirt more control over event processing, ensuring object locking constraints can be met.
But your comment exposes a flaw in the patch, one that had already been fixed in the event_occurs approach. Shutting down a large memory domain can take considerable time due to memory scrubbing, meanwhile stalling reception of other events. The patch was a bit aggressive in removing libxlDomainShutdownThread().
Quoted 16 lines
So:
Acked-by Ian Jackson <[email protected]>NB that I have not reviewed the patch in detail. I can do that if you like, although of course my knowledge of the innards of libvirt is not wonderful.
Quoted 7 lines
The only reservations I have about this patch come from comments about
libxl_event_waitinlibxl_event.hLike
libxl_event_checkbut blocks if no suitable events are available, until some are. Uses libxl_osevent_beforepoll/_afterpollso may be inefficient if very many domains are being handled by a single program.
Quoted 8 lines
If this turns out to be a problem in practice, we will improve libxl's data structures to not involve so many linear searches. (In fact I think you are probably already calling synchronous libxl ao functions, which have the same performance properties, although this is not documented.)
Given what you say above I don't think there is a reasonable alternative remedy. So you should go ahead with this patch.
Thanks for your comments and ACK'ing the change . I'll submit a V2 that retains handling of shutdown event in a thread.
Regards,
Jim
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 3 lines · Jim Fehlig
Thanks for your comments and ACK'ing the change . I'll submit a V2 that retains handling of shutdown event in a thread.
While testing V2, I noticed occasionally missing a shutdown event. I can see from the logs that domain_death_xswatch_callback is called, a matching domain is found, and shutdown is being reported
2015-11-23 17:01:09 MST libxl: debug: libxl.c:1227:domain_death_xswatch_callback: [evg=0x7fa2fc002570:0] nentries=200 rc=2 0..61 2015-11-23 17:01:09 MST libxl: debug: libxl.c:1238:domain_death_xswatch_callback: [evg=0x7fa2fc002570:0] got=domaininfos[0] got->domain=0 2015-11-23 17:01:09 MST libxl: debug: libxl.c:1264:domain_death_xswatch_callback: exists shutdown_reported=0 dominf.flags=ffff0020 2015-11-23 17:01:09 MST libxl: debug: libxl.c:1238:domain_death_xswatch_callback: [evg=0x7fa34c007e20:61] got=domaininfos[0] got->domain=0 2015-11-23 17:01:09 MST libxl: debug: libxl.c:1238:domain_death_xswatch_callback: [evg=0x7fa34c007e20:61] got=domaininfos[1] got->domain=61 2015-11-23 17:01:09 MST libxl: debug: libxl.c:1264:domain_death_xswatch_callback: exists shutdown_reported=0 dominf.flags=4 2015-11-23 17:01:09 MST libxl: debug:
libxl.c:1276:domain_death_xswatch_callback: shutdown reporting
Seems the call to libxl__event_occurred never pokes libvirt's call to libxl_event_wait. Interestingly, starting another domain does cause libxl_event_wait to return with the missing shutdown event.
I'm testing on a fairly recent (2 weeks) git master. I'm not familiar with the libxl poller code and will need to instrument that a bit to understand why libxl_event_wait isn't poked.
Regards,
Jim