Skip to content

Commit c1d3f98

Browse files
skattoju4yadvr
authored andcommitted
server: filter volumes by host when refreshing stats (#3486)
Currently when refreshing disk usage stats all kvm agents are asked to collect stats for all volumes. In setups with multiple kvm hosts where managed storage is used, not all volumes are attached to all kvm hosts, this results in a large number of warnings in the kvm agent logs. This change introduces a filter step in case managed storage is used so that the management server only requests kvm agents for stats about volumes that are connected to each kvm host.
1 parent d930982 commit c1d3f98

4 files changed

Lines changed: 31 additions & 3 deletions

File tree

engine/schema/src/main/java/com/cloud/storage/dao/VolumeDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S
4646

4747
List<VolumeVO> findByInstanceAndType(long id, Volume.Type vType);
4848

49+
List<VolumeVO> findByInstanceIdAndPoolId(long instanceId, long poolId);
50+
4951
List<VolumeVO> findByInstanceIdDestroyed(long vmId);
5052

5153
List<VolumeVO> findByPod(long podId);

engine/schema/src/main/java/com/cloud/storage/dao/VolumeDaoImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ public List<VolumeVO> findByPoolId(long poolId) {
127127
return listBy(sc);
128128
}
129129

130+
@Override
131+
public List<VolumeVO> findByInstanceIdAndPoolId(long instanceId, long poolId) {
132+
SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();
133+
sc.setParameters("instanceId", instanceId);
134+
sc.setParameters("poolId", poolId);
135+
sc.setParameters("notDestroyed", Volume.State.Destroy);
136+
return listBy(sc);
137+
}
138+
130139
@Override
131140
public VolumeVO findByPoolIdName(long poolId, String name) {
132141
SearchCriteria<VolumeVO> sc = AllFieldsSearch.create();

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiAdmStorageAdaptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ private long getDeviceSize(String deviceByPath) {
242242
String result = iScsiAdmCmd.execute(parser);
243243

244244
if (result != null) {
245-
s_logger.warn("Unable to retrieve the size of device " + deviceByPath);
245+
s_logger.warn("Unable to retrieve the size of device (resource may have moved to a different host)" + deviceByPath);
246246

247247
return 0;
248248
}

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,14 +1938,24 @@ public HashMap<Long, VmStatsEntry> getVirtualMachineStatistics(long hostId, Stri
19381938
}
19391939

19401940
@Override
1941-
public HashMap<String, VolumeStatsEntry> getVolumeStatistics(long clusterId, String poolUuid, StoragePoolType poolType, List<String> volumeLocator, int timeout) {
1941+
public HashMap<String, VolumeStatsEntry> getVolumeStatistics(long clusterId, String poolUuid, StoragePoolType poolType, List<String> volumeLocators, int timeout) {
19421942
List<HostVO> neighbors = _resourceMgr.listHostsInClusterByStatus(clusterId, Status.Up);
1943+
StoragePool storagePool = _storagePoolDao.findPoolByUUID(poolUuid);
19431944
for (HostVO neighbor : neighbors) {
1944-
GetVolumeStatsCommand cmd = new GetVolumeStatsCommand(poolType, poolUuid, volumeLocator);
1945+
if (storagePool.isManaged()) {
1946+
1947+
volumeLocators = getVolumesByHost(neighbor, storagePool);
1948+
1949+
}
1950+
1951+
GetVolumeStatsCommand cmd = new GetVolumeStatsCommand(poolType, poolUuid, volumeLocators);
1952+
19451953
if (timeout > 0) {
19461954
cmd.setWait(timeout/1000);
19471955
}
1956+
19481957
Answer answer = _agentMgr.easySend(neighbor.getId(), cmd);
1958+
19491959
if (answer instanceof GetVolumeStatsAnswer){
19501960
GetVolumeStatsAnswer volstats = (GetVolumeStatsAnswer)answer;
19511961
return volstats.getVolumeStats();
@@ -1954,6 +1964,13 @@ public HashMap<String, VolumeStatsEntry> getVolumeStatistics(long clusterId, Str
19541964
return null;
19551965
}
19561966

1967+
private List<String> getVolumesByHost(HostVO host, StoragePool pool){
1968+
List<UserVmVO> vmsPerHost = _vmDao.listByHostId(host.getId());
1969+
return vmsPerHost.stream()
1970+
.flatMap(vm -> _volsDao.findByInstanceIdAndPoolId(vm.getId(),pool.getId()).stream().map(vol -> vol.getPath()))
1971+
.collect(Collectors.toList());
1972+
}
1973+
19571974
@Override
19581975
@DB
19591976
public UserVm recoverVirtualMachine(RecoverVMCmd cmd) throws ResourceAllocationException, CloudRuntimeException {

0 commit comments

Comments
 (0)