Skip to content

Commit

Permalink
core: measure unattached disks
Browse files Browse the repository at this point in the history
The current check doesn't doesn't use measureVolume if the volume is a
leaf, but there is no reason to do this if the disk is not attached to a
running a VM.

This patch checks if the disk is attached to a running VM before
checking if the volume is a leaf to ensure it's measured correctly.

Bug-Url: https://bugzilla.redhat.com/2104806
Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com>
  • Loading branch information
bennyz committed Aug 1, 2022
1 parent cc47990 commit dcc9e37
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.ovirt.engine.core.bll.storage.disk.image;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand All @@ -26,6 +27,7 @@
import org.ovirt.engine.core.common.action.CreateVolumeContainerCommandParameters;
import org.ovirt.engine.core.common.action.MeasureVolumeParameters;
import org.ovirt.engine.core.common.businessentities.StorageDomainStatic;
import org.ovirt.engine.core.common.businessentities.VM;
import org.ovirt.engine.core.common.businessentities.storage.DiskImage;
import org.ovirt.engine.core.common.businessentities.storage.Image;
import org.ovirt.engine.core.common.businessentities.storage.StorageType;
Expand All @@ -37,6 +39,7 @@
import org.ovirt.engine.core.dao.ImageDao;
import org.ovirt.engine.core.dao.StorageDomainDao;
import org.ovirt.engine.core.dao.StorageDomainStaticDao;
import org.ovirt.engine.core.dao.VmDao;
import org.ovirt.engine.core.utils.CollectionUtils;

@InternalCommandAttribute
Expand All @@ -57,6 +60,9 @@ public class CloneImageGroupVolumesStructureCommand<T extends CloneImageGroupVol
@Typed(SerialChildCommandsExecutionCallback.class)
private Instance<SerialChildCommandsExecutionCallback> callbackProvider;

@Inject
private VmDao vmDao;

@Inject
private ImagesHandler imagesHandler;

Expand Down Expand Up @@ -220,7 +226,8 @@ private Long determineImageInitialSize(Image sourceImage,

Guid hostId = imagesHandler.getHostForMeasurement(storagePoolId, imageGroupID);
if (hostId != null) {
if ((srcDomainStorageType.isBlockDomain() || !sourceImage.isActive()) &&
boolean isPluggedToRunningVm = sourceImage.isActive() && isAttachedToRunningVMs(imageGroupID);
if ((srcDomainStorageType.isBlockDomain() || !isPluggedToRunningVm) &&
dstDomainStorageType.isBlockDomain()) {
MeasureVolumeParameters parameters = new MeasureVolumeParameters(storagePoolId,
srcDomain,
Expand Down Expand Up @@ -273,6 +280,13 @@ private Long determineImageInitialSize(Image sourceImage,
return null;
}

private boolean isAttachedToRunningVMs(Guid imageGroupID) {
Map<Boolean, List<VM>> vms = vmDao.getForDisk(imageGroupID, false);
return !vms.isEmpty() && vms.computeIfAbsent(Boolean.TRUE, b -> new ArrayList<>())
.stream()
.anyMatch(VM::isRunning);
}

private VolumeFormat determineVolumeFormat(Guid destStorageDomainId,
VolumeFormat srcVolumeFormat,
VolumeType srcVolumeType) {
Expand Down

0 comments on commit dcc9e37

Please sign in to comment.