CA-147161: Discard messages after logging to remote host

Make rsyslog discard messages after they have been logged locally and
sent to a remote host to prevent the default rules from picking them up.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
CA-139501 VM hard_shutdown & hard_reboot must wait for nothing else.

We were already allowing hard_reboot concurrent with a clean_reboot
already in progress, and the same for hard/clean shutdown, but
clean_(shutdown|reboot) would block hard_(reboot|shutdown).

Now the is_allowed_concurrently function allows hard_shutdown
concurrent with anything except itself, and allows hard_reboot
concurrent with anything but itself or hard_shutdown.

Signed-off-by: Thomas Sanders <thomas.sanders@citrix.com>
(cherry picked from commit a9816b9b549fad1e8e4169c69bbad5e9f2f3ab8e)
Whitespace: fix horrible spaces-then-tab-then-spaces indentation.

Signed-off-by: Thomas Sanders <thomas.sanders@citrix.com>
(cherry picked from commit 62393a77fa00cdc1bc798c9bc57fe73fa6413647)
Merge pull request #1959 from rosslagerwall/rsyslog-fix

CA-147161: Discard messages after logging to remote host
CA-148772: support consoles served over Unix domain sockets

Xenopsd with libxl + upstream qemu prefers to bind consoles to
named sockets like

  /var/run/non-persistent/xenospd/consoles/VM/<uuid>

rather than anonymous localhost port numbers. Naming consoles is
a good idea because it prevents accidentally connecting to the
wrong port number.

This patch allows Xapi to connect to these Unix domain socket
consoles. Note there is still a lingering problem with upstream
qemu and XenCenter's built-in RFB client which causes the
keyboard not to work.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
CP-9906: Raise a ref rather than a UUID for VDI_NOT_IN_MAP

The CLI code has the ability to turn the ref into a UUID.

Signed-off-by: John Else <john.else@citrix.com>
(cherry picked from commit 30af00894c46132ae7cd62e6a3f5c8bb8259c1f7)
CP-9906: Improve SXM failure logging

Log that we don't know to where a VDI should be copied.

Signed-off-by: John Else <john.else@citrix.com>
(cherry picked from commit 6bd6d02860b4b49b54e240729d35af334d132c85)
CP-9906: Improve SXM failure error reporting

Raise a proper Api_error if we've failed to determine the destination to
which a snapshot VDI should be migrated.

Signed-off-by: John Else <john.else@citrix.com>
(cherry picked from commit 5042c2ca5fbe760e9c5ad7c935b894d62ac7c8e4)
Merge pull request #1980 from johnelse/sxm-workaround

Improvements to SXM failure logging and error reporting
Merge pull request #1977 from thomassa/trunk_hard_shutboot

CA-139501 VM hard_shutdown & hard_reboot must wait for nothing else.
Merge pull request #1979 from djs55/CA-148772

CA-148772: support consoles served over Unix domain sockets
Handle Rrdd_plugin interface change

Signed-off-by: John Else <john.else@citrix.com>
Merge pull request #1996 from johnelse/rrdd-plugin-interface

Handle Rrdd_plugin interface change
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>
(cherry picked from commit 223be77fe377abeb8bfffd2bbf828566c0691cb4)

Conflicts:

	ocaml/xenops/xenops_server_xen.ml
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>
(cherry picked from commit 43592b1185789a96ef9728ab761a0940639cc7cf)

Conflicts:

	ocaml/xapi/xapi_vm_lifecycle.ml
	ocaml/xenops/xenops_server_xen.ml
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>
(cherry picked from commit 308c81b58f0033dd1966a7b4118802b05233cc0a)
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>
(cherry picked from commit e965a2ee8c71498ec2bce1cf2b607e8990903ce0)
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>
(cherry picked from commit b52a18785ed98ee2fda1c857f09a1c75d5b88c3d)
CP-9366: HVM feature-suspend is obsolete in trunk, so remove check.

Suspend and related operations do not need cooperation from HVM
guests in trunk, so we can remove this part of the check that has
just been forward-ported from the xs64bit (XenServer 6.5) branch
in commit 33d2839e41cd34f5a0730e14e3a193da63f35c49

Signed-off-by: Thomas Sanders <thomas.sanders@citrix.com>
CP-9366: Remove redundant update_allowed_operations calls.

Also use VM.update_allowed_operations rather than imitating it
with separate calls to the specific update_allowed_operations
functions for VM, VBDs and VIFs.

Signed-off-by: Thomas Sanders <thomas.sanders@citrix.com>