Fixes for PBD.{plug|unplug}
Fixes for PBD.{plug|unplug}

- On PBD.plug or unplug, require SRMaster to be true before
  starting/stopping database replication to metadata VDIs, or
  adding/removing foreign metadata VDIs from the cache.
- On PBD.plug, catch any and all exceptions when trying to re-enable
  database replication to the SR - if this fails then PBD.plug should
  continue as normal.
- On PBD.unplug, check that there are no active non-metadata VDIs before
  disabling database replication. If there are active non-metadata VDIs
  then the PBD.unplug will fail, so database replication shouldn't be
  disabled yet.

Signed-off-by: John Else <37b74501daa612e48fea94f9846ed4ddeb6a8f07@citrix.com>

rafalmiel/xen-api,euanh/xen-api,vasilenkomike/xen-api,huizh/xen-api,ravippandey/xen-api,rafalmiel/xen-api,jjd27/xen-api,koushikcgit/xen-api,guard163/xen-api,Frezzle/xen-api,simonjbeaumont/xen-api,Frezzle/xen-api,koushikcgit/xen-api,srowe/xen-api,vasilenkomike/xen-api,agimofcarmen/xen-api,djs55/xen-api,euanh/xen-api,anoobs/xen-api,euanh/xen-api,thomassa/xen-api,euanh/xen-api,huizh/xen-api,robertbreker/xen-api,robertbreker/xen-api,euanh/xen-api,salvocambria/xen-api,rafalmiel/xen-api,huizh/xen-api,anoobs/xen-api,simonjbeaumont/xen-api,cheng-z/xen-api,agimofcarmen/xen-api,salvocambria/xen-api,anoobs/xen-api,guard163/xen-api,cheng--zhang/xen-api,srowe/xen-api,djs55/xen-api,vasilenkomike/xen-api,vasilenkomike/xen-api,Frezzle/xen-api,agimofcarmen/xen-api,koushikcgit/xen-api,jjd27/xen-api,jjd27/xen-api,Frezzle/xen-api,cheng--zhang/xen-api,srowe/xen-api,guard163/xen-api,jjd27/xen-api,srowe/xen-api,djs55/xen-api,cheng-z/xen-api,vasilenkomike/xen-api,vasilenkomike/xen-api,huizh/xen-api,thomassa/xen-api,robertbreker/xen-api,cheng--zhang/xen-api,cheng-z/xen-api,srowe/xen-api,cheng-z/xen-api,ravippandey/xen-api,simonjbeaumont/xen-api,guard163/xen-api,ravippandey/xen-api,thomassa/xen-api,huizh/xen-api,koushikcgit/xen-api,koushikcgit/xen-api,djs55/xen-api,cheng--zhang/xen-api,salvocambria/xen-api,anoobs/xen-api,jjd27/xen-api,euanh/xen-api,robertbreker/xen-api,cheng--zhang/xen-api,ravippandey/xen-api,robertbreker/xen-api,cheng-z/xen-api,robertbreker/xen-api,koushikcgit/xen-api,rafalmiel/xen-api,thomassa/xen-api,anoobs/xen-api,salvocambria/xen-api,agimofcarmen/xen-api,cheng--zhang/xen-api,thomassa/xen-api,jjd27/xen-api,Frezzle/xen-api,salvocambria/xen-api,simonjbeaumont/xen-api,thomassa/xen-api,simonjbeaumont/xen-api,rafalmiel/xen-api,djs55/xen-api,huizh/xen-api,agimofcarmen/xen-api,djs55/xen-api,salvocambria/xen-api,agimofcarmen/xen-api,rafalmiel/xen-api,anoobs/xen-api,simonjbeaumont/xen-api,ravippandey/xen-api,guard163/xen-api,cheng--zhang/xen-api,guard163/xen-api,ravippandey/xen-api,cheng-z/xen-api,cheng-z/xen-api