From 4a0a7b03f132536c1ef5b099c76a2e4ca03f448d Mon Sep 17 00:00:00 2001 From: Wilson Liu Date: Mon, 22 Feb 2016 16:09:33 +0800 Subject: [PATCH] Huawei: Consider bandwidth when selecting port Currently we count the weight of each FC port when selecting port for zoning, but if all the weights are equal, for example, at the very beginning when all ports' weight are zero, we should select the ports which have the bigger bandwidth. Closes-Bug: #1548220 Change-Id: I59b3f0bb9adb1038f54b2f4a3c1dfa8bdc520ae9 --- .../volume/drivers/huawei/fc_zone_helper.py | 5 +- cinder/volume/drivers/huawei/huawei_driver.py | 49 +++++++++++-------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/cinder/volume/drivers/huawei/fc_zone_helper.py b/cinder/volume/drivers/huawei/fc_zone_helper.py index 66fb5aa41..7e0a8a4e8 100644 --- a/cinder/volume/drivers/huawei/fc_zone_helper.py +++ b/cinder/volume/drivers/huawei/fc_zone_helper.py @@ -75,13 +75,15 @@ class FCZoneHelper(object): if total_bandwidth: weight += float(lun_num) / float(total_bandwidth) - return weight + bandwidth = float(ports_info[port]['bandwidth']) + return (weight, 10000 / bandwidth) def _get_weighted_ports_per_contr(self, ports, ports_info): port_weight_map = {} for port in ports: port_weight_map[port] = self._count_port_weight(port, ports_info) + LOG.debug("port_weight_map: %s", port_weight_map) sorted_ports = sorted(port_weight_map.items(), key=lambda d: d[1]) weighted_ports = [] count = 0 @@ -132,6 +134,7 @@ class FCZoneHelper(object): lun_info = self.client.get_lun_info(lun_id) lun_contr_id = lun_info['OWNINGCONTROLLER'] engines = self.client.get_all_engines() + LOG.debug("Get array engines: %s", engines) for engine in engines: contrs = json.loads(engine['NODELIST']) diff --git a/cinder/volume/drivers/huawei/huawei_driver.py b/cinder/volume/drivers/huawei/huawei_driver.py index 80e02b600..84243c322 100644 --- a/cinder/volume/drivers/huawei/huawei_driver.py +++ b/cinder/volume/drivers/huawei/huawei_driver.py @@ -1818,23 +1818,8 @@ class HuaweiFCDriver(HuaweiBaseDriver, driver.FibreChannelDriver): fc_info = {'driver_volume_type': 'fibre_channel', 'data': {}} else: - portg_id = None - if not self.fcsan: - self.fcsan = fczm_utils.create_lookup_service() - - if self.fcsan: - zone_helper = fc_zone_helper.FCZoneHelper(self.fcsan, - self.client) - - (tgt_port_wwns, portg_id, init_targ_map) = ( - zone_helper.get_init_targ_map(wwns, host_id)) - else: - (tgt_port_wwns, init_targ_map) = ( - self.client.get_init_targ_map(wwns)) - - for wwn in wwns: - if self.client.is_fc_initiator_associated_to_host(wwn): - self.client.remove_fc_from_host(wwn) + fc_info, portg_id = self._delete_zone_and_remove_fc_initiators( + wwns, host_id) if lungroup_id: if view_id and self.client.lungroup_associated( view_id, lungroup_id): @@ -1867,10 +1852,6 @@ class HuaweiFCDriver(HuaweiBaseDriver, driver.FibreChannelDriver): if view_id: self.client.delete_mapping_view(view_id) - fc_info = {'driver_volume_type': 'fibre_channel', - 'data': {'target_wwn': tgt_port_wwns, - 'initiator_target_map': init_targ_map}} - # Deal with hypermetro connection. metadata = huawei_utils.get_volume_metadata(volume) LOG.info(_LI("Detach Volume, metadata is: %s."), metadata) @@ -1884,3 +1865,29 @@ class HuaweiFCDriver(HuaweiBaseDriver, driver.FibreChannelDriver): fc_info) return fc_info + + def _delete_zone_and_remove_fc_initiators(self, wwns, host_id): + # Get tgt_port_wwns and init_targ_map to remove zone. + portg_id = None + if not self.fcsan: + self.fcsan = fczm_utils.create_lookup_service() + if self.fcsan: + zone_helper = fc_zone_helper.FCZoneHelper(self.fcsan, + self.client) + (tgt_port_wwns, portg_id, init_targ_map) = ( + zone_helper.get_init_targ_map(wwns, host_id)) + else: + (tgt_port_wwns, init_targ_map) = ( + self.client.get_init_targ_map(wwns)) + + # Remove the initiators from host if need. + if host_id: + fc_initiators = self.client.get_host_fc_initiators(host_id) + for wwn in wwns: + if wwn in fc_initiators: + self.client.remove_fc_from_host(wwn) + + info = {'driver_volume_type': 'fibre_channel', + 'data': {'target_wwn': tgt_port_wwns, + 'initiator_target_map': init_targ_map}} + return info, portg_id -- 2.45.2