CA-76600: preserve /vm and /vss over localhost migrate

Rather than having the higher-level software special case localhost
migrate, we use reference counting to decide when to delete /vm
and /vss. When we create a new domain for a specific UUID, we
record the domain in
  /vm/<uuid>/domains/<domid> = <local domain path>

In domain destroy, we delete /vm and /vss if the domains directory
is empty.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
CA-76600: preserve the rtc/timeoffset over migrate

Unfortunately the rtc/timeoffset can be changed dynamically by
the guest (via qemu) but isn't stored in the domain save record.
Therefore we need to both update our domain persistent state
in xenopsd (for migrate/resume) *and* update our VM config in
the higher-level toolstack (ie xapi) for start.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
[xapi] clean up xenopsd VMs marked as "Suspended" on restart

Normally a xapi suspend or migrate will clean up these xenopsd VMs inline
but a badly-timed xapi restart can leave them lying around. Therefore
on_xapi_restart will perform a xenopsd VM.shutdown and VM.remove on any
Suspended Vms it finds.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
[xenops] VM.destroy_device_model and VM.destroy now work on VMs even if the domain has been destroyed already

Now these functions are idempotent, it should be easier to write robust cleanup code.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
[xenops] if migration receive fails, call VM.shutdown and VM.remove to clean up

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
[xapi] if a VM is left Suspended after a migration failure, power it off

Unfortunately the domain is not actually saved to disk so cannot be properly resumed (yet)

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
[xenops] VM's last_start_time must be preserved over migrate

Otherwise the guest agent updates from xenstore will be considered stale

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
CA-78569: when creating a XenAPI VM for dom0, use the memory_* values from xenopsd if they exist

This means that memory_* will be preserved over pool.join.

It's also a step in the right direction to trust the on-host service (xenopsd) as authoritative for host-specific data.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
CA-76523: on spontaneous VM shutdown, do not reset ha_always_run

The convention is that VM.ha_always_run should be reset when an API
call is received (the API call overrides the current policy) but
an internal VM shutdown is treated as a VM failure, and HA restarts it.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
CA-77555: add exception handlers around each xenopsd VM event stanza, so one failure does not block the rest

It's important that the event resync logic doesn't fail, otherwise the VM state in xapi will be out-of-sync.

In the event that something does fail, log the error and resynchronise as much as possible.

In future we may wish to consider artificially injecting events periodically in the event of failure, in the hope that the state will change enough in future to avoid the problem.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
Merge commit '6001bbe6004aa178412fffc324faf68af66c0475'
Merge commit '1f922392bd90ec01efebd5fc0a7a33252ea51df7'