CA-74343: Fix HA on VLANs

The recent change to not automatically plug VLANs on host boot (for
scalability reasons), led the HA code to believe that VMs on VLANs
were not agile, even if they were.

It turns out that the agility check for networking is too strict.
Currently, xapi only considers a VM agile if all its networks
1. have PIFs on all enabled hosts, AND
2. have all those PIFs attached/plugged.

This is too strict, because a PIF can always be plugged, unless it is
a bond slave, and xapi automatically plugs a PIF when it is needed by a
VM.

Therefore, the agility check was changed to require that a VM's networks
1. have PIFs on all enabled hosts, AND
2. none of those PIFs are bond slaves.

Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
CA-90457: Don't set rebalance-interval for LACP bonds.

Signed-off-by: John Else <john.else@citrix.com>
Revert the rebalance-interval changes to networkd of e9219fab22c574028f2c4ce6fa3649e3e8e8596e

The policies for which values are set in the network layer should be in xapi. Networkd should
just do do what xapi says.

After this change, the default rebalance-intervals are unchanged: for balance-slb bonds is 30min,
while for LACP bonds, the value is unset and the default from the ovs is used (10s). However, the
change makes it possible for the user to override the rebalance-interval using the other-config key,
even in the LACP case (for whatever reason).

Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
Use is_valid_ref rather than comparing with Ref.null

Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
CA-91927: Reduce the frequency of VM.allowed_operations updates.

When xapi receives a VM update from xenopsd, allowed_operations should
only be updated if a VM field which could affect the allowed_operations
was changed.

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

$ camlp4o -printer o -no_comments ocaml/xapi/xapi_vdi| md5sum
089dfa0d238d159793ae1bd7e172d0d5  -
$ git checkout HEAD^
$ camlp4o -printer o -no_comments ocaml/xapi/xapi_vdi.ml | md5sum
089dfa0d238d159793ae1bd7e172d0d5  -

Signed-off-by: John Else <john.else@citrix.com>
CA-90263: Pass through a list of SR, PBD and VBD records to Xapi_vdi.check_operation_error

Signed-off-by: John Else <john.else@citrix.com>
CA-90263: Improve efficiency of Xapi_vdi.check_operation_error.

This changeset removes most of the database calls from this function,
assuming it is passed lists of SR, PBD and VBD records.

Signed-off-by: John Else <john.else@citrix.com>
CA-90263: Cache the return values of Helpers.is_tools_sr

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

$ camlp4o -printer o -no_comments ocaml/xapi/cancel_tasks.ml | md5sum
70ace4121b6a103e16526323078806bd  -
$ git checkout HEAD^
$ camlp4o -printer o -no_comments ocaml/xapi/cancel_tasks.ml | md5sum
70ace4121b6a103e16526323078806bd  -

Signed-off-by: John Else <john.else@citrix.com>
CA-90263: Improve efficiency of Cancel_tasks.update_all_allowed_operations.

Instead of calling Xapi_vdi.update_allowed_operations, call
Xapi_vdi.update_allowed_operations_internal and pass in cached lists of
SR, PBD and VBD records.

Signed-off-by: John Else <john.else@citrix.com>
Add timing stats to Cancel_tasks.update_all_allowed_operations

Signed-off-by: John Else <john.else@citrix.com>
Add timing stats to Db_gc.single_pass

Signed-off-by: John Else <john.else@citrix.com>
CA-90263: Don't get the SR UUID for each VDI when resynchronising VDI activations.

Signed-off-by: John Else <john.else@citrix.com>
CA-91927: Xapi_xenops event thread should update VM.allowed_operations on master instead of localhost.

Signed-off-by: John Else <john.else@citrix.com>
CA-90263: Remove the need to ever get an SR record as part of Xapi_vdi.check_operation_error

Signed-off-by: John Else <john.else@citrix.com>
CA-91931: Prevent spurious exceptions being raised by Event.from

Signed-off-by: Jon Ludlam <jonathan.ludlam@eu.citrix.com>
CA-91927: Reduce the number of times a guest agent updated causes an allowed-operations update

Signed-off-by: Jon Ludlam <jonathan.ludlam@eu.citrix.com>
CA-91930: Remove union of subscriptions between event.from invocations.

This fixes an issue whereby when parallel event.from calls were being
processed, each call would get the union of events meant for each. This
causes particular problems when XenCenter is connected as it registers
for _all_ events. Therefore any other calls made to event.from will
receive _all_ events whenever the GUI is connected. Additionally, as
there is no way to generate a token for 'now', this means that the
initial call to event.from will dump the _entire_ database, including
all the messages, requiring reading these from the disk.

Signed-off-by: Jon Ludlam <jonathan.ludlam@eu.citrix.com>
CA-91930: Add some warning comments to make sure we don't regress this fix.

Signed-off-by: Jon Ludlam <jonathan.ludlam@eu.citrix.com>