Skip to content

Commit eab5814

Browse files
author
Mike Tutkowski
committed
Remove iSCSI targets and rescan asynchronously
1 parent 63fddf2 commit eab5814

1 file changed

Lines changed: 37 additions & 8 deletions

File tree

plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2813,9 +2813,9 @@ public void handleTargets(boolean add, ModifyTargetsCommand.TargetTypeToRemove t
28132813
}
28142814
}
28152815

2816-
boolean rescan = false;
2817-
28182816
if (add) {
2817+
boolean rescan = false;
2818+
28192819
if (staticTargetsForHost.size() > 0) {
28202820
addRemoveInternetScsiTargetsToAllHosts(true, getTargets(staticTargetsForHost), hosts);
28212821

@@ -2825,25 +2825,31 @@ public void handleTargets(boolean add, ModifyTargetsCommand.TargetTypeToRemove t
28252825
if (dynamicTargetsForHost.size() > 0) {
28262826
rescan = true;
28272827
}
2828+
2829+
if (rescan) {
2830+
rescanAllHosts(hosts, true, false);
2831+
}
28282832
}
28292833
else {
2834+
boolean rescan = false;
2835+
28302836
if (staticTargetsForHost.size() > 0 &&
28312837
(ModifyTargetsCommand.TargetTypeToRemove.STATIC.equals(targetTypeToRemove) || ModifyTargetsCommand.TargetTypeToRemove.BOTH.equals(targetTypeToRemove))) {
2832-
addRemoveInternetScsiTargetsToAllHosts(false, getTargets(staticTargetsForHost), hosts);
2838+
addRemoveInternetScsiTargetsToAllHostsAsync(false, getTargets(staticTargetsForHost), hosts);
28332839

28342840
rescan = true;
28352841
}
28362842

28372843
if (dynamicTargetsForHost.size() > 0 &&
28382844
(ModifyTargetsCommand.TargetTypeToRemove.DYNAMIC.equals(targetTypeToRemove) || ModifyTargetsCommand.TargetTypeToRemove.BOTH.equals(targetTypeToRemove))) {
2839-
addRemoveInternetScsiTargetsToAllHosts(false, getTargets(dynamicTargetsForHost), hosts);
2845+
addRemoveInternetScsiTargetsToAllHostsAsync(false, getTargets(dynamicTargetsForHost), hosts);
28402846

28412847
rescan = true;
28422848
}
2843-
}
28442849

2845-
if (rescan) {
2846-
rescanAllHosts(hosts, true, false);
2850+
if (rescan) {
2851+
rescanAllHostsAsync(hosts, true, false);
2852+
}
28472853
}
28482854
}
28492855
}
@@ -2861,7 +2867,19 @@ private void addRemoveInternetScsiTargetsToAllHosts(VmwareContext context, final
28612867
addRemoveInternetScsiTargetsToAllHosts(add, targets, hosts);
28622868
}
28632869

2864-
private void addRemoveInternetScsiTargetsToAllHosts(final boolean add, final List<HostInternetScsiHbaStaticTarget> targets,
2870+
private void addRemoveInternetScsiTargetsToAllHostsAsync(boolean add, List<HostInternetScsiHbaStaticTarget> targets,
2871+
List<HostMO> hosts) throws Exception {
2872+
new Thread(() -> {
2873+
try {
2874+
addRemoveInternetScsiTargetsToAllHosts(add, targets, hosts);
2875+
}
2876+
catch (Exception ex) {
2877+
s_logger.warn(ex.getMessage());
2878+
}
2879+
}).run();
2880+
}
2881+
2882+
private void addRemoveInternetScsiTargetsToAllHosts(boolean add, List<HostInternetScsiHbaStaticTarget> targets,
28652883
List<HostMO> hosts) throws Exception {
28662884
ExecutorService executorService = Executors.newFixedThreadPool(hosts.size());
28672885

@@ -2924,6 +2942,17 @@ private void rescanAllHosts(VmwareContext context, List<Pair<ManagedObjectRefere
29242942
rescanAllHosts(hosts, rescanHba, rescanVmfs);
29252943
}
29262944

2945+
private void rescanAllHostsAsync(List<HostMO> lstHosts, boolean rescanHba, boolean rescanVmfs) throws Exception {
2946+
new Thread(() -> {
2947+
try {
2948+
rescanAllHosts(lstHosts, rescanHba, rescanVmfs);
2949+
}
2950+
catch (Exception ex) {
2951+
s_logger.warn(ex.getMessage());
2952+
}
2953+
}).run();
2954+
}
2955+
29272956
private void rescanAllHosts(List<HostMO> lstHosts, boolean rescanHba, boolean rescanVmfs) throws Exception {
29282957
if (!rescanHba && !rescanVmfs) {
29292958
// nothing to do

0 commit comments

Comments
 (0)