/// <summary> /// Try to forget an SR that has previously failed to completely plug. Nothrow guarantee. /// </summary> private void ForgetFailedSR(XenRef <SR> sr) { try { foreach (XenRef <PBD> pbd in XenAPI.SR.get_PBDs(Session, sr.opaque_ref)) { if (PBD.get_currently_attached(Session, pbd)) { PBD.unplug(Session, pbd); } } XenAPI.SR.forget(Session, sr.opaque_ref); } catch { log.Debug("SR.forget() failed! Continuing anyway"); } }
/// <summary> /// Disable clustering on the host (if the network is used by clustering), before changing the management interface; /// Before disabling clustering we also unplug all the GFS2 SRs /// </summary> private void DisableClustering(PIF pif, out List <PBD> gfs2Pbds) { gfs2Pbds = new List <PBD>(); var isUsedByClustering = Connection.Cache.Clusters.Any(cluster => cluster.network.opaque_ref == pif.network.opaque_ref); if (!isUsedByClustering) { return; } var host = Connection.Resolve(pif.host); if (host == null) { return; } var clusterHost = Connection.Cache.Cluster_hosts.FirstOrDefault(c => c.host.opaque_ref == host.opaque_ref); if (clusterHost == null) { return; } // unplug the GFS2 SRs, saving the list of the PBDs unplugged, to plug back later foreach (var pbd in Connection.ResolveAll(host.PBDs).Where(pbd => pbd.currently_attached)) { var sr = Connection.Resolve(pbd.SR); if (sr != null && sr.GetSRType(true) == SR.SRTypes.gfs2) { gfs2Pbds.Add(pbd); Description = string.Format(Messages.ACTION_SR_DETACHING, sr.Name(), host.Name()); PBD.unplug(Session, pbd.opaque_ref); } } // disable clustering Description = string.Format(Messages.DISABLING_CLUSTERING_ON_POOL, host.Name()); log.Debug(Description); Cluster_host.disable(Session, clusterHost.opaque_ref); }
protected override void Run() { Exception unplugException = null; // Only unplug and replug already plugged pbds List <String> pluggedPBDrefs = new List <String>(); try { foreach (PBD pbd in host.Connection.ResolveAll(host.PBDs)) { if (!pbd.currently_attached) { continue; } pluggedPBDrefs.Add(pbd.opaque_ref); PBD.unplug(Session, pbd.opaque_ref); } // CA-19392: Multipath enablement / disablement if (Helpers.KolkataOrGreater(host)) { Host.set_multipathing(Session, host.opaque_ref, multipath); } else { Host.remove_from_other_config(Session, host.opaque_ref, Host.MULTIPATH); Host.add_to_other_config(Session, host.opaque_ref, Host.MULTIPATH, multipath.ToString().ToLowerInvariant()); } Host.remove_from_other_config(Session, host.opaque_ref, Host.MULTIPATH_HANDLE); if (multipath) { Host.add_to_other_config(Session, host.opaque_ref, Host.MULTIPATH_HANDLE, DEFAULT_MULTIPATH_HANDLE); } } catch (Exception e) { unplugException = e; log.Debug("Error occurred unplugging pbds", e); throw; } finally { Exception plugException = null; foreach (String pbdRef in pluggedPBDrefs) { try { PBD.plug(Session, pbdRef); } catch (Exception e) { if (unplugException == null && plugException == null) { plugException = e; } log.Debug("Error occurred replugging pbds", e); } } // Only throw a plug exception if there we no unplug exceptions if (unplugException == null && plugException != null) { throw plugException; } } }