]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Huawei: Consider bandwidth when selecting port
authorWilson Liu <liuxinguo@huawei.com>
Mon, 22 Feb 2016 08:09:33 +0000 (16:09 +0800)
committerWilson Liu <liuxinguo@huawei.com>
Sat, 27 Feb 2016 01:45:56 +0000 (09:45 +0800)
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

cinder/volume/drivers/huawei/fc_zone_helper.py
cinder/volume/drivers/huawei/huawei_driver.py

index 66fb5aa41c57735122d3cdc0e46897babab29c6d..7e0a8a4e839f66b393ec64f8ba90adf771bd6c66 100644 (file)
@@ -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'])
index 80e02b6008947149dd45ef2de5b9e48685eeaebd..84243c3221ee6ba5ad067cd73616aa6d32b1bfe1 100644 (file)
@@ -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