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>
Whitespace: fix horrible spaces-then-tab-then-spaces indentation.

Signed-off-by: Thomas Sanders <thomas.sanders@citrix.com>
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>
CA-141526: Putting VBD path to /dev/xvdX for HVM guests

/dev/hda is anyways meaningless for HVM guest.So, we always populate the
VBD path to be /dev/xvdX.
Signed-off-by: Ravi Pandey <ravi.pandey@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>
CA-145413: xenopsd internal error: Unix.Unix_error(27, "rmdir", "/var/run/nonpersistent/xenops/extra")

FileFS.rm has a race condition in deleting emtpy dir when there're 2 or more vms are rebooting.
So let's use try-catch to delete empty dir.

Signed-off-by: Phus Lu <phus.lu@citrix.com>
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-144941: Don't checksum the gpg binary

We are already checking the signature of the patch contents, it seems silly to
also checksum the gpg binary itself. It's also becoming a bit of a maintenance
burden and cumbersome in the open source world where this checksum will be
different on every version of every distro.

Signed-off-by: Si Beaumont <simon.beaumont@citrix.com>
Merge pull request #1921 from ravippandey/CA-141526

CA-141526: Putting VBD path to /dev/xvdX for HVM guests
Merge pull request #1925 from phusl/CA-145413

CA-145413: xenopsd internal error: Unix.Unix_error(27, "rmdir", "/var/run/nonpersistent/xenops/extra")
CA-136972: Read raw stats from blktap3

With blktap3, the blkback stats structure is maintained on a shared page
This patch fetches the required counters via C stubs to create the datasources.

Signed-off-by: Siddharth Vinothkumar <siddharth.vinothkumar@citrix.com>
Revised-by: Zheng Li <zheng.li3@citrix.com>
CA-143836: Add VDI.revert to SMAPI

Signed-off-by: John Else <john.else@citrix.com>
CA-143836: Add VDI.revert API call

Signed-off-by: John Else <john.else@citrix.com>
CA-143836: Pass down correct values of is_a_snapshot/snapshot_of

Signed-off-by: John Else <john.else@citrix.com>
CA-143836: Allow VDI.revert operation for cloneable snapshots

Signed-off-by: John Else <john.else@citrix.com>
CA-143836: During VDI.revert, mark leaf with operation `reverting

This mirrors the way allowed_operations are handled for VM.revert.

Signed-off-by: John Else <john.else@citrix.com>
CA-143836: Add vdi_revert to SR allowed_operations

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