server: Do not resize volume of running vm on KVM host if host is not Up or not Enabled (#4148)

If we resize a volume of a vm running on a host which is not Up or not Enable, the job will be scheduled to another normal host. Then the volume will be resized by "qemu-img resize" instead of "virsh blockresize", the image might be corrupted after resize.
This commit is contained in:
Wei Zhou 2020-06-25 07:10:31 +02:00 committed by GitHub
parent b79407c50b
commit 5526342f4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 0 deletions

View File

@ -109,11 +109,13 @@ import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.StorageUnavailableException;
import com.cloud.gpu.GPU;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.hypervisor.HypervisorCapabilitiesVO;
import com.cloud.hypervisor.dao.HypervisorCapabilitiesDao;
import com.cloud.org.Grouping;
import com.cloud.resource.ResourceState;
import com.cloud.serializer.GsonHelper;
import com.cloud.server.ResourceTag;
import com.cloud.server.TaggedResourceService;
@ -1187,6 +1189,21 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
if (currentSize != newSize && _volsDao.getHypervisorType(volume.getId()) == HypervisorType.XenServer && !userVm.getState().equals(State.Stopped)) {
throw new InvalidParameterValueException(errorMsg);
}
/* Do not resize volume of running vm on KVM host if host is not Up or not Enabled */
if (currentSize != newSize && userVm.getState() == State.Running && userVm.getHypervisorType() == HypervisorType.KVM) {
if (userVm.getHostId() == null) {
throw new InvalidParameterValueException("Cannot find the hostId of running vm " + userVm.getUuid());
}
HostVO host = _hostDao.findById(userVm.getHostId());
if (host == null) {
throw new InvalidParameterValueException("The KVM host where vm is running does not exist");
} else if (host.getStatus() != Status.Up) {
throw new InvalidParameterValueException("The KVM host where vm is running is not Up");
} else if (host.getResourceState() != ResourceState.Enabled) {
throw new InvalidParameterValueException("The KVM host where vm is running is not Enabled");
}
}
}
ResizeVolumePayload payload = new ResizeVolumePayload(newSize, newMinIops, newMaxIops, newHypervisorSnapshotReserve, shrinkOk, instanceName, hosts, isManaged);