Don't call VM.stat every time we receive a xapi event on a VM.

VM.stat is expensive as it does lots of xenstore reads - just check that
the VM exists in xenopsd's database instead.

Signed-off-by: John Else <john.else@citrix.com>
(cherry picked from commit 25210a1c7031ca16665393ed6b7ba62abab8b157)
Dump xenopsd updates every time we push an update.

Signed-off-by: John Else <john.else@citrix.com>
(cherry picked from commit 9c3613a5f8edf6839fb3fcc58a7e7e81821bf4b8)
Sort events properly.

Signed-off-by: John Else <john.else@citrix.com>
(cherry picked from commit 054e14bce51b31afe474a59b2f66f719231eee67)
CA-87377: Snapshot updates state in inject_barrier

Xapi then receives updates including barrier information from the
updates.get API call. Xapi processes the barriers first, as these
have threads waiting on them.

Signed-off-by: Jon Ludlam <jonathan.ludlam@eu.citrix.com>
(cherry picked from commit 0ad8b6e1034f4243b3bf2fc9fb2a95e42cfec9db)
CA-87377: Add barriers info to xn diagnostics

Signed-off-by: Jon Ludlam <jonathan.ludlam@eu.citrix.com>
(cherry picked from commit cbff8f1cdffea1e337ef950b1b59dcf4871800f3)
CA-105160: Make sure event_wait is cancellable

Signed-off-by: Jon Ludlam <jonathan.ludlam@eu.citrix.com>
(cherry picked from commit 1049853ba2c5b37cde231a0844ef78fd6aa45c32)
CA-105159: Wait for ack of shutdown request for HVM guests with PV drivers

The code paths only handled fully-PV guests and HVM guests without PV drivers.
In the case of PV drivers we did not wait for the shutdown request to be
acknowledged. This did not enable early exit if the request was not
acknowledged.

Signed-off-by: Si Beaumont <simon.beaumont@citrix.com>
(cherry picked from commit 6de03e86b7804c63749d9ebd764839f66492d30d)
CA-105155: Make sure we timeout as requested

Signed-off-by: Jon Ludlam <jonathan.ludlam@eu.citrix.com>
(cherry picked from commit 72d98cac67a53e6d76539df7dda927b8368c051b)
Make VM.shutdown timeout configurable.

The default remains at 1200.0

Configure by creating/editing a file /etc/xensource/xapi_globs.conf
and put in the line:

domain_shutdown_total_timeout = 30.0

for example.

Signed-off-by: Jon Ludlam <jonathan.ludlam@eu.citrix.com>
(cherry picked from commit 647ee26dff92678155f5550eff9fa9ad58c738ea)
Make it such that you can do a hard_shutdown even if a clean_shutdown is in progress

Same for reboot

Signed-off-by: Jon Ludlam <jonathan.ludlam@eu.citrix.com>
(cherry picked from commit 5bbd34c82c356144654eef95e822141785bf19d5)
SCTX-1334: Ensure that a force shutdown cancels any clean_shutdown.

Signed-off-by: Jon Ludlam <jonathan.ludlam@eu.citrix.com>
(cherry picked from commit 345eaad8b90c5b403494b0e1f66ed36737eeb9a0)
CA-105793: Don't ignore the shutdown_delay parameter.

Signed-off-by: Jon Ludlam <jonathan.ludlam@eu.citrix.com>
(cherry picked from commit 0314a7cf1be817e480a2b94dbc9c391800ce6c59)
SCTX-1334: Add exception handlers

In response to code review with djs55

Signed-off-by: Jon Ludlam <jonathan.ludlam@eu.citrix.com>
(cherry picked from commit f279f9335bc510532d3545045dd829f031788057)
Raise the correct error if a xenops task is cancelled

Signed-off-by: Jon Ludlam <jonathan.ludlam@eu.citrix.com>
(cherry picked from commit a2c26fbd4f1497b846661940c0c5b126a1aa906a)
Merge pull request #1254 from thomassa/CLEARWATER-SCTX-1334-again

CLEARWATER SCTX-1334: dup pull-reqs #1062 #1199