CP-4277: Allow unsigned patches to be installable

This is controlled by the presence of the hotfix file's sha1sum
in the FIST-point "allowed_unsigned_patches".

Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
Merge pull request #1190 from robhoes/cp4277-ta

TAMPA-LCM: CP-4277: Allow unsigned patches to be installable
CA-95669: VNC/VNCTerm should listen on localhost only (127.0.0.1)
(The commit from Feb/March 2013 didn't fix this.)

This only fixes the problem for guest domains, not for dom0.

The dom0 vncterm is run from /etc/inittab so we shall need to
change the repository that adds the relevant line to that file.

Signed-off-by: Thomas Sanders <thomas.sanders@citrix.com>
(cherry picked from commit 484e4bfca5c6154e6a3b3722d937d34a805cadbc)
CA-100489: xenopsd: ignore errors in PCI.unplug when VM does not exist

This makes it consistent with VIF.unplug and VBD.unplug, and prevents xenopsd
from spinning in VM.shutdown with PCI devices present.

Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
Merge pull request #1314 from akshayramani/CP-5221

 CA-100489: xenopsd: ignore errors in PCI.unplug when VM does not exist
CA-109035: Remove the correct xenstore key when PCI unplugging.

We were always attempting to remove dev-0 instead of dev-n. This
led to multiple attempts to e.g. deassign_device for all but the
first passed through device. It also led to a cancelled shutdown
attempting to unplug everything again without any exception handler,
leading to an infinite loop.

Signed-off-by: Jon Ludlam <jonathan.ludlam@eu.citrix.com>
XOP-385: Up timout in shutdown.py to 600 from 60 seconds.

We only hit this timeout if the VMs fail to cleanly shutdown.
This will be fixed in a different way in trunk where we have the
'VM.shutdown' API call.

Signed-off-by: Jon Ludlam <jonathan.ludlam@eu.citrix.com>
Merge pull request #1342 from jonludlam/xop-385

XOP-385
Fix VIF.remove_ipv6_allowed
CA-107702: Ensure that networkd explicitly configures all physical interfaces with IP in dom0

This is done by marking the interfaces as "persistent" in networkd. Previously, only bridge
interfaces (xenbr*, xapi*) with IP configuration were made persistent. However, their associated
physical interfaces (eth0 etc.) should receive the same treatment, so that attributes such as the
MTU are configured on these as well.

When a host starts, interfaces with IP config need to be configured before xapi can start,
especially on pool slaves, or if HA is enabled.

Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
CA-105080: just added some comments
Signed-off-by: Thomas Sanders <thomas.sanders@citrix.com>
Whitespace: Reformat Pool.create_VLAN_from_PIF

$ camlp4o -printer o -no_comments xapi_pool.ml | md5sum
6afb19c9cff915091d37775375954312

Signed-off-by: Si Beaumont <simon.beaumont@citrix.com>
CA-106560: Create VLANs on slaves that are in 'Maintenance Mode'

Weaken the condition for creating VLANs on slaves during
a Pool.create_VLAN_from_PIF from hosts that are enabled to hosts that are live
(according to the host metrics). This enables the VLAN to be created on slaves
that are in XenCenter's 'Maintenance Mode'.

Signed-off-by: Si Beaumont <simon.beaumont@citrix.com>
CA-96541/SCTX-1188: Fix race condition when creating metrics for VLAN PIFs

This fixes a race condition between the thread that copies bonds and VLANs from
the master when a new slave joins the pool, and the thread that creates/updates
the PIF_metrics (the "monitor thread"). Or in fact a race between anything that
creates a bond and very soon after that a VLAN on top of it.

Since XCP1.6/XS6.1, VLANs no longer have their own PIF_metrics. Rather, they point
to the PIF_metrics of the underlying PIF, which can be either a physical PIF
(e.g. for eth0), or a bond PIF. Therefore, the carrier of a VLAN PIF is the same
as the carrier of the underlying PIF.

When a physical PIF or bond PIF is created, it does not immediately have
PIF_metrics (PIF.metrics = "OpaqueRef:NULL"). The PIF_metrics object is created
and assigned to the PIF by the monitor thread a short while after that. If you
create a VLAN before the PIF_metrics have been created, the PIF.metrics field from
the underlying PIF will still be copied, which is "OpaqueRef:NULL". This will never
get updated, because the monitor thread ignores VLANs.

The fix is simply to immediately create an (empty) metrics object when creating a
bond.

Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
Oliver/HFX-780:CA-96886: Fix race for a PCI device by multiple starting VMs

When multiple simultaneously starting VMs try to grab the same PCI device, only one of them
may get it, and the others must fail to start. However, xapi considers a PCI device "assigned"
to a VM only when the VM has started and the device has been made available to the VM, which
is some time after xapi has asked xenopsd to start the VM and give it the PCI device. This means
that there is a window during which multiple VM may be given the same device.

This patch attempts to resolve this by temporarily reserving a PCI device for a VM in xapi, before telling xenopsd to start the VM.

Signed-off-by: Rob Hoes <rob.hoes@citrix.com>

Conflicts:

	ocaml/test/OMakefile
CA-100685: When domain disappears during VM shutdown operation, just go ahead instead of rasing any cancellation error

Signed-off-by: Zheng Li <zheng.li@eu.citrix.com>
CA-109300: nm: correctly set persistence on parent bridge of VLAN

A VLAN bridge is never "persistent" (i.e. it is never brought up by
networkd on startup), while the parent bridge of the VLAN may be
persistent (in case it has a management IP address).

The bug was that, when creating a VLAN, it set the persistence of
the parent bridge equal to the persitence of the VLAN.

Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
CA-102259: Refactor xenstore-watching code out of xenopsd

This code is potentially reusable by other components, so this patch disentangles the xenopsd-specific stuff from the generic xenstore-watching stuff.

Summary of the refactoring, from the point of view of xenops_server_xen:

 * Split IntMap watches into IntSet watches (domains being watched, moved to xenstore_watch) and IntMap device_watches (list of devices watched per domain, kept)

 * Moved several functions into xenstore_watch's new WATCH_ACTIONS interface:
    - the code that does an action depending on which watch fired (to watch_fired, also including fire_event_on_vm and fire_event_on_device),
    - renamed all_domU_watches (to interesting_paths_for_domain),
    - the device-specific bits of remove_domU_watches (in domain_disappeared, which also inherited the content of cancel_domU_operations),
    - definition of unmanaged domain (in unmanaged_domain), and
    - definition of what we want to do each time we notice a domain running (in found_running_domain).

 * Moved to xenstore_watch's WatchXenstore module:
    - list_domains (verbatim)
    - domain_looks_different (verbatim),
    - list_different_domains (verbatim),
    - watch_xenstore, with the following changes:
       (a) rename {add,remove}_domU_watches to {add,remove}_watches_for_domain (but don't take the device-specific bit in remove_domU_watches)
       (b) call the functions listed above through WATCH_ACTIONS, and
    - the code that creates the watch_xenstore thread (to a function "create_watcher_thread") (verbatim).
Install xenstore_watch as an ocamlfindable package

This enables it to be used by the rrdd plugins, for which the code lives in a different repository.
CA-106034: update device_watches when domain appears/disappears

When a domain appears, we need to initialise the entry in device_watches for
that domid. When a domain disappears, we need to remove the entry in
device_watches for that domid.

This was overlooked in the refactoring of CA-102259 -- the old semantics of
add_domU_watches and remove_domU_watches was not preserved as the watches map
was split into a set of domain watches and a map of device_watches.

Acked-by: Jonathan Davies <Jonathan.Davies@eu.citrix.com>
Signed-off-by: Mike McClurg <mike.mcclurg@citrix.com>