CP-9366: Watch the "control" xenstore node, and update VM-metrics "other".

Now when qemu writes a feature-flag into the control node, xapi will
notice and so will trigger the existing code that can copy those entries
into the "other" vm guest metrics parameter.

That code used to do nothing unless it found a version for the PV
drivers. These are absent for HVM Linux guests with no guest agent, so
now even if there is no PV driver version we do the minimum work
needed to update "other", including creating the VM guest metrics
record if needed.

Also, now we set the guest metrics record to null on VM start.
This avoids problems of some of its data being wrong (left over from
last time the VM ran, or from the VM's parent if it is a clone) but
being trusted because its last_updated is more recent than VM start
time due to an item in "other" being set before (say) the networks
field is updated.

Signed-off-by: Thomas Sanders <thomas.sanders@citrix.com>
CP-9366: Check HVM feature-flags not just PV drivers

Use these flags to determine the allowed_operations list which is
only advisory.  When it comes to attempting an operation, do not
require the feature-suspend or feature-shutdown flag: attempt the
operation anyway and it is up to the guest whether it cooperates.
The feature-vcpu-hotplug flag is needed for that operation though.

Changes:
* xapi_vm_lifecycle check_operation_error uses the flags to check
  whether we can perform a given operation. (Also checks for PV
  drivers to support old guest agents that do not write the flags.)
* In xapi_host.ml the pre-evacuation check no longer checks for PV
  drivers to learn whether a VM can be migrated.  It was already
  calling Xapi_vm_lifecycle.get_operation_error.
* Appropriate errors are defined: one for each of three features.
* Datamodel: removed vm_missing_pv_drivers from vm_pool_migrate
  error list
* Removed code that raises an Unimplemented exception for HVM
  guests when attempting vCPU hotplug. This allows the code that
  decides based on the feature-flag to work properly.

Signed-off-by: Thomas Sanders <thomas.sanders@citrix.com>
Merge commit '3e0d55055cc6bf11332b88640e45dd58c01dd3b0'
CP-9366: Require feature-suspend for HVM in host evacuation plan.

CA-146028 should be fixed by this commit.

This reverts part of the behaviour-change (but not code-change) of
my commit 43592b1185789a96ef9728ab761a0940639cc7cf

Signed-off-by: Thomas Sanders <thomas.sanders@citrix.com>
CP-9366: Destroy the VM guest metrics discarded on VM start.

Fix a xapi database leak: on VM start we were just setting the
VM's guest metrics record to Ref.null thus orphaning the old
record.  Now we also destroy it.

Signed-off-by: Thomas Sanders <thomas.sanders@citrix.com>
CP-9366: Require HVM feature-flags (or PV drivers) strictly.

When attempting a lifecycle operation on an HVM guest, we now
require any relevant feature-flag (or PV drivers) in the same way
as when calculating the allowed_operations list.

This undoes another part of the behaviour-change (but not
code-change) of my earlier commit
43592b1185789a96ef9728ab761a0940639cc7cf

This returns behaviour for HVM Windows without guest-agent
(without PV drivers) to the same as before any CP-9366 changes.

In a future change we might make this configurable.

Signed-off-by: Thomas Sanders <thomas.sanders@citrix.com>
Merge commit 'e965a2ee8c71498ec2bce1cf2b607e8990903ce0'
Merge remote-tracking branch 'creedence/master' into xs64bit-ring3

Merge in the HVM Linux work which was pushed direct to the creedence
branch.
CA-144658: Do not call squeezer if Host have enough free memory for create VM

In this fix, the problem is in bootstorm, squeezer will be a bottleneck here. For the test environment configure here, start VM don't need squeezer to work since there is lot of memory free in host.
So as a workaround here, we don't need to call squeezer if there are lot of free memory and also all other VMs' memory target has been met.
This fix add a conditional check in change_host_free_memory, which is let "finished" to be true if host memory requirement is smaller than free memory and all VMs meet their targets.

Signed-off-by: Cheng Zhang <cheng.zhang@citrix.com>
Merge pull request #1945 from cheng--zhang/CA-144658

CA-144658: Do not call squeezer if Host have enough free memory for create VM
Revert "CA-100400: GC event queue based on size rather than number."

This reverts commit 2f32598b8544317d332796a4b44a2a99f212edf3.
Revert "CA-100400: Store the event size alongside the event in the event.next queue"

This reverts commit c8e51d598760c5f79f0ab7f20b79f0c0c21b1e87.
Revert "Import xapi_event.ml from trunk"

This reverts commit 5a42c61e6f229cdf0b782b57f12595b3b7ed0d4a.
Revert "quicktest: add a test case for parallel calls to event.from"

This reverts commit b36e85ee1802f0fb11bb37681a36aa08055510f7.
Merge remote-tracking branch 'creedence/master' into xs64bit-ring3

Reverted xapi event changes for CA-100400 on creedence.
quicktest: add a test case for parallel calls to event.from

Sophisticated clients like CloudStack will issue parallel calls to
event.from, looking for different conditions. These calls should
not interfere.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>

Conflicts:
	ocaml/xapi/quicktest.ml
Import xapi_event.ml from trunk

Fixes an issue where parallel event.from instances on the same
session_id can conflict, leading to a SESSION_INVALID exception

This brings xs64bit-ring3 up to trunk c/s
bedca96adfcfdadd2e2e8c2c8b5158b6e5a115bf

Signed-off-by: Jon Ludlam <jonathan.ludlam@citrix.com>
CA-100400: Store the event size alongside the event in the event.next queue

Signed-off-by: Jon Ludlam <jonathan.ludlam@citrix.com>
CA-100400: GC event queue based on size rather than number.

Signed-off-by: Jon Ludlam <jonathan.ludlam@citrix.com>
CA-146736: Fix event registration after pool_migrate_complete

After running pool_migrate_complete, make sure the xapi events thread
re-registers so as to watch events for the newly-arrived VM.

Signed-off-by: John Else <john.else@citrix.com>