From 4783c99aab866f470bd59368cfbf5ad5f677b0ec Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 17 Mar 2015 09:30:57 -0600 Subject: [PATCH] libxl: In domain death search, start search at first domid we want From: Ian Jackson When domain_death_xswatch_callback needed a further call to xc_domain_getinfolist it would restart it with the last domain it found rather than the first one it wants. If it only wants one it will also only ask for one domain. The result would then be that it gets the previous domain again (ie, the previous one to the one it wants), which still doesn't reveal the answer to the question, and it would therefore loop again. It's completely unclear to me why I thought it was a good idea to start the xc_domain_getinfolist with the last domain previously found rather than the first one left un-confirmed. The code has been that way since it was introduced. Instead, start each xc_domain_getinfolist at the next domain whose status we need to check. We also need to move the test for !evg into the loop, we now need evg to compute the arguments to getinfolist. Signed-off-by: Ian Jackson Reported-by: Jim Fehlig Reviewed-by: Jim Fehlig Tested-by: Jim Fehlig Acked-by: Wei Liu Acked-by: Ian Campbell --- tools/libxl/libxl.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index ad69a8a719..c904e71cfa 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -1168,22 +1168,20 @@ static void domain_death_xswatch_callback(libxl__egc *egc, libxl__ev_xswatch *w, const char *wpath, const char *epath) { EGC_GC; libxl_evgen_domain_death *evg; - uint32_t domid; int rc; CTX_LOCK; evg = LIBXL_TAILQ_FIRST(&CTX->death_list); - if (!evg) goto out; - - domid = evg->domid; for (;;) { + if (!evg) goto out; + int nentries = LIBXL_TAILQ_NEXT(evg, entry) ? 200 : 1; xc_domaininfo_t domaininfos[nentries]; const xc_domaininfo_t *got = domaininfos, *gotend; - rc = xc_domain_getinfolist(CTX->xch, domid, nentries, domaininfos); + rc = xc_domain_getinfolist(CTX->xch, evg->domid, nentries, domaininfos); if (rc == -1) { LIBXL__EVENT_DISASTER(egc, "xc_domain_getinfolist failed while" " processing @releaseDomain watch event", @@ -1193,8 +1191,10 @@ static void domain_death_xswatch_callback(libxl__egc *egc, libxl__ev_xswatch *w, gotend = &domaininfos[rc]; LIBXL__LOG(CTX, LIBXL__LOG_DEBUG, "[evg=%p:%"PRIu32"]" - " from domid=%"PRIu32" nentries=%d rc=%d", - evg, evg->domid, domid, nentries, rc); + " nentries=%d rc=%d %ld..%ld", + evg, evg->domid, nentries, rc, + rc>0 ? (long)domaininfos[0].domain : 0, + rc>0 ? (long)domaininfos[rc-1].domain : 0); for (;;) { if (!evg) { @@ -1257,7 +1257,6 @@ static void domain_death_xswatch_callback(libxl__egc *egc, libxl__ev_xswatch *w, } assert(rc); /* rc==0 results in us eating all evgs and quitting */ - domid = gotend[-1].domain; } all_reported: out: -- 2.30.2