Github user HrWiggles commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/1953#discussion_r102181285 --- Diff: server/src/com/cloud/storage/VolumeApiServiceImpl.java --- @@ -2639,22 +2639,23 @@ private int getMaxDataVolumesSupported(UserVmVO vm) { return maxDataVolumesSupported.intValue(); } - private Long getDeviceId(long vmId, Long deviceId) { + private Long getDeviceId(UserVmVO vm, Long deviceId) { // allocate deviceId - List<VolumeVO> vols = _volsDao.findByInstance(vmId); + int maxDataVolumesSupported = getMaxDataVolumesSupported(vm); + List<VolumeVO> vols = _volsDao.findByInstance(vm.getId()); if (deviceId != null) { - if (deviceId.longValue() > 15 || deviceId.longValue() == 3) { - throw new RuntimeException("deviceId should be 1,2,4-15"); + if (deviceId.longValue() > maxDataVolumesSupported || deviceId.longValue() == 3) { + throw new RuntimeException("deviceId should be 1,2,4-" + maxDataVolumesSupported); } for (VolumeVO vol : vols) { if (vol.getDeviceId().equals(deviceId)) { - throw new RuntimeException("deviceId " + deviceId + " is used by vm" + vmId); + throw new RuntimeException("deviceId " + deviceId + " is used by vm" + vm.getId()); } } } else { // allocate deviceId here List<String> devIds = new ArrayList<String>(); - for (int i = 1; i < 15; i++) { + for (int i = 1; i < maxDataVolumesSupported; i++) { devIds.add(String.valueOf(i)); } devIds.remove("3"); --- End diff -- Not part of your changes but... there's a possible `NoSuchElementException` below, for line: ``` deviceId = Long.parseLong(devIds.iterator().next()); ``` A check should be added for whether `devIds` is empty and, if so, throw a `RuntimeException` with an error message which specifies that all possible device ids are already in use by the vm (if only to be consistent with the rest of the method).
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---