From e5ffcab09dd4f70d2755f5378185862a387a4621 Mon Sep 17 00:00:00 2001 From: Mike Tutkowski Date: Sat, 24 Jan 2015 00:06:37 -0700 Subject: [PATCH] Moving the call to getDeviceId(long, long) avoids a race condition when two volumes are being attached to a VM at the same time --- server/src/com/cloud/storage/VolumeApiServiceImpl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/src/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/com/cloud/storage/VolumeApiServiceImpl.java index 0abb6298534..22c801f454c 100644 --- a/server/src/com/cloud/storage/VolumeApiServiceImpl.java +++ b/server/src/com/cloud/storage/VolumeApiServiceImpl.java @@ -1303,7 +1303,6 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic throw new InvalidParameterValueException("The specified VM already has the maximum number of data disks (" + maxDataVolumesSupported + "). Please specify another VM."); } } - deviceId = getDeviceId(vmId, deviceId); // If local storage is disabled then attaching a volume with local disk // offering not allowed @@ -2300,6 +2299,9 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic } DataTO volTO = volFactory.getVolume(volumeToAttach.getId()).getTO(); + + deviceId = getDeviceId(vm.getId(), deviceId); + DiskTO disk = new DiskTO(volTO, deviceId, volumeToAttach.getPath(), volumeToAttach.getVolumeType()); AttachCommand cmd = new AttachCommand(disk, vm.getInstanceName());