Skip to content

Commit aaee31a

Browse files
committed
Get volume physical size from StatsCollector for checking backup resource limit
1 parent c0cfb77 commit aaee31a

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

api/src/main/java/com/cloud/storage/VolumeApiService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,6 @@ Volume updateVolume(long volumeId, String path, String state, Long storageId,
190190
boolean stateTransitTo(Volume vol, Volume.Event event) throws NoTransitionException;
191191

192192
Pair<String, String> checkAndRepairVolume(CheckAndRepairVolumeCmd cmd) throws ResourceAllocationException;
193+
194+
Long getVolumePhysicalUsed(Storage.ImageFormat format, String path, String chainInfo);
193195
}

server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
import com.cloud.serializer.GsonHelper;
162162
import com.cloud.server.ManagementService;
163163
import com.cloud.server.ResourceTag;
164+
import com.cloud.server.StatsCollector;
164165
import com.cloud.server.TaggedResourceService;
165166
import com.cloud.service.ServiceOfferingVO;
166167
import com.cloud.service.dao.ServiceOfferingDao;
@@ -347,7 +348,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
347348
protected StoragePoolDetailsDao storagePoolDetailsDao;
348349
@Inject
349350
private BackupDao backupDao;
350-
351+
@Inject
352+
private StatsCollector statsCollector;
351353

352354
protected Gson _gson;
353355

@@ -5154,6 +5156,21 @@ private VmWorkJobVO createPlaceHolderWork(long instanceId) {
51545156
return workJob;
51555157
}
51565158

5159+
@Override
5160+
public Long getVolumePhysicalUsed(ImageFormat format, String path, String chainInfo) {
5161+
VolumeStats vs = null;
5162+
if (format == ImageFormat.VHD || format == ImageFormat.QCOW2 || format == ImageFormat.RAW) {
5163+
if (path != null) {
5164+
vs = statsCollector.getVolumeStats(path);
5165+
}
5166+
} else if (format == ImageFormat.OVA) {
5167+
if (chainInfo != null) {
5168+
vs = statsCollector.getVolumeStats(chainInfo);
5169+
}
5170+
}
5171+
return (vs == null) ? null : vs.getPhysicalSize();
5172+
}
5173+
51575174
@Override
51585175
public String getConfigComponentName() {
51595176
return VolumeApiService.class.getSimpleName();

server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,11 @@ public boolean createBackup(final Long vmId, final Long scheduleId) throws Resou
585585
Long backupSize = 0L;
586586
for (final Volume volume: volumeDao.findByInstance(vmId)) {
587587
if (Volume.State.Ready.equals(volume.getState())) {
588-
backupSize += volume.getSize();
588+
Long volumeSize = volumeApiService.getVolumePhysicalUsed(volume.getFormat(), volume.getPath(), volume.getChainInfo());
589+
if (volumeSize == null) {
590+
volumeSize = volume.getSize();
591+
}
592+
backupSize += volumeSize;
589593
}
590594
}
591595
try {

0 commit comments

Comments
 (0)