[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 17/23] libxl: suspend: New domain_suspend_pvcontrol_acked
Factor out domain_suspend_pvcontrol_acked. This replaces a bunch of open-coded strcmp()s and makes the code clearer. It also eliminates the need to check for state==NULL each time it's read, because we can check for NULL once before the strcmp. No functional change. Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx> CC: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx> CC: Ian Campbell <ian.campbell@xxxxxxxxxx> --- tools/libxl/libxl_dom.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c index 59f6ce3..a0b3a57 100644 --- a/tools/libxl/libxl_dom.c +++ b/tools/libxl/libxl_dom.c @@ -1034,6 +1034,12 @@ static void domain_suspend_common_done(libxl__egc *egc, libxl__domain_suspend_state *dss, bool ok); +static bool domain_suspend_pvcontrol_acked(const char *state) { + /* any value other than "suspend", including ENOENT, is OK */ + if (!state) return 1; + return strcmp(state,"suspend"); +} + /* calls dss->callback_common_done when done */ static void domain_suspend_callback_common(libxl__egc *egc, libxl__domain_suspend_state *dss) @@ -1091,11 +1097,10 @@ static void domain_suspend_callback_common(libxl__egc *egc, LOG(DEBUG, "wait for the guest to acknowledge suspend request"); watchdog = 60; - while (!strcmp(state, "suspend") && watchdog > 0) { + while (!domain_suspend_pvcontrol_acked(state) && watchdog > 0) { usleep(100000); state = libxl__domain_pvcontrol_read(gc, XBT_NULL, domid); - if (!state) state = ""; watchdog--; } @@ -1109,21 +1114,19 @@ static void domain_suspend_callback_common(libxl__egc *egc, * against the guest catching up and acknowledging the request * at the last minute. */ - if (!strcmp(state, "suspend")) { + if (!domain_suspend_pvcontrol_acked(state)) { LOG(ERROR, "guest didn't acknowledge suspend, cancelling request"); retry_transaction: t = xs_transaction_start(CTX->xsh); state = libxl__domain_pvcontrol_read(gc, t, domid); - if (!state) state = ""; - if (!strcmp(state, "suspend")) + if (!domain_suspend_pvcontrol_acked(state)) libxl__domain_pvcontrol_write(gc, t, domid, ""); if (!xs_transaction_end(CTX->xsh, t, 0)) if (errno == EAGAIN) goto retry_transaction; - } /* @@ -1131,7 +1134,7 @@ static void domain_suspend_callback_common(libxl__egc *egc, * acknowledged while we were cancelling the request in which * case we lost the race while cancelling and should continue. */ - if (!strcmp(state, "suspend")) { + if (!domain_suspend_pvcontrol_acked(state)) { LOG(ERROR, "guest didn't acknowledge suspend, request cancelled"); goto err; } -- 1.7.10.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |