Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 07FED200C22 for ; Tue, 21 Feb 2017 23:34:11 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 06B8E160B68; Tue, 21 Feb 2017 22:34:11 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 4D158160B4F for ; Tue, 21 Feb 2017 23:34:10 +0100 (CET) Received: (qmail 50812 invoked by uid 500); 21 Feb 2017 22:34:09 -0000 Mailing-List: contact dev-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list dev@cloudstack.apache.org Received: (qmail 50800 invoked by uid 99); 21 Feb 2017 22:34:09 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Feb 2017 22:34:09 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 03458DFF0F; Tue, 21 Feb 2017 22:34:08 +0000 (UTC) From: HrWiggles To: dev@cloudstack.apache.org Reply-To: dev@cloudstack.apache.org References: In-Reply-To: Subject: [GitHub] cloudstack pull request #1953: CLOUDSTACK-9794: Unable to attach more than 1... Content-Type: text/plain Message-Id: <20170221223409.03458DFF0F@git1-us-west.apache.org> Date: Tue, 21 Feb 2017 22:34:08 +0000 (UTC) archived-at: Tue, 21 Feb 2017 22:34:11 -0000 Github user HrWiggles commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/1953#discussion_r102336557 --- 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 vols = _volsDao.findByInstance(vmId); + int maxDataVolumesSupported = getMaxDataVolumesSupported(vm); + List 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 devIds = new ArrayList(); - for (int i = 1; i < 15; i++) { + for (int i = 1; i < maxDataVolumesSupported; i++) { --- End diff -- @sureshanaparti If the condition really should be `i < maxDataVolumesSupported` (which would make the maximum device id returned by the method be `maxDataVolumesSupported - 1`), then the check + error message above ``` if (deviceId.longValue() <= 0 || deviceId.longValue() > maxDataVolumesSupported || deviceId.longValue() == 3) { throw new RuntimeException("deviceId should be 1,2,4-" + maxDataVolumesSupported); ``` need to be changed so as not to include the value of `maxDataVolumesSupported` itself. Otherwise, when `maxDataVolumesSupported` has value `6` (for example), the method would not ever return `6` when parameter `deviceId` is specified as `null` but would return `6` when parameter `deviceId` is specified as `6` (assuming device id `6` is not already in use). Also, the error message would state "deviceId should be 1,2,4-6" whenever parameter `deviceId` would be specified as an invalid value, which would not be correct (as `5` should be the highest valid device id). --- 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 infrastructure@apache.org or file a JIRA ticket with INFRA. ---