diff options
author | Kefu Chai <kchai@redhat.com> | 2021-04-23 01:03:54 +0800 |
---|---|---|
committer | Kefu Chai <kchai@redhat.com> | 2021-07-25 19:25:23 +0800 |
commit | 7c91d1afa0b397c816acfd38ae48043be62c01c3 (patch) | |
tree | b7aa34b3b0d718021d75989d22cacc14ad5559bd | |
parent | 8e416bcf954fd4a0d0d854e5dac69eba51d29ad1 (diff) | |
download | ceph-7c91d1afa0b397c816acfd38ae48043be62c01c3.tar.gz |
common/pick_addr: use grading machinery to refactor pick_address()
as picking iface on the same NUMA node is not a hard requirement, the
grading machinery is a nice fit for this purpose.
Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit 329d51c68ec6bf1864aa9430a62d65a93362a1b9)
-rw-r--r-- | src/common/pick_address.cc | 71 |
1 files changed, 33 insertions, 38 deletions
diff --git a/src/common/pick_address.cc b/src/common/pick_address.cc index be4e549f3e2..bb3f7d30cb5 100644 --- a/src/common/pick_address.cc +++ b/src/common/pick_address.cc @@ -117,20 +117,20 @@ bool matches_with_net(CephContext *cct, return matches_with_net(ifa, (sockaddr*)&net, prefix_len, ipv); } -bool matches_with_numa_node(const ifaddrs& ifa, int numa_node) +int grade_with_numa_node(const ifaddrs& ifa, int numa_node) { #if defined(WITH_SEASTAR) || defined(_WIN32) - return true; + return 0; #else if (numa_node < 0) { - return true; + return 0; } int if_node = -1; int r = get_iface_numa_node(ifa.ifa_name, &if_node); if (r < 0) { - return false; + return 0; } - return if_node == numa_node; + return if_node == numa_node ? 1 : 0; #endif } } @@ -150,7 +150,7 @@ const struct sockaddr *find_ip_in_subnet_list( exit(1); } - int best_score = -1; + int best_score = 0; const sockaddr* best_addr = nullptr; for (const auto* addr = ifa; addr != nullptr; addr = addr->ifa_next) { if (!ifs.empty() && @@ -167,10 +167,12 @@ const struct sockaddr *find_ip_in_subnet_list( })) { continue; } - if (!matches_with_numa_node(*addr, numa_node)) { + int score = grade_addr(*addr); + if (score < 0) { continue; } - if (int score = grade_addr(*addr); score > best_score) { + score += grade_with_numa_node(*addr, numa_node); + if (score > best_score) { best_score = score; best_addr = addr->ifa_addr; } @@ -409,36 +411,29 @@ int pick_addresses( !networks.empty()) { int ipv4_r = !(ipv & CEPH_PICK_ADDRESS_IPV4) ? 0 : -1; int ipv6_r = !(ipv & CEPH_PICK_ADDRESS_IPV6) ? 0 : -1; - // first try on preferred numa node (if >= 0), then anywhere. - while (true) { - // note: pass in ipv to filter the matching addresses - if ((ipv & CEPH_PICK_ADDRESS_IPV4) && - (flags & CEPH_PICK_ADDRESS_PREFER_IPV4)) { - ipv4_r = fill_in_one_address(cct, ifa, CEPH_PICK_ADDRESS_IPV4, - networks, interfaces, - addrs, - preferred_numa_node); - } - if (ipv & CEPH_PICK_ADDRESS_IPV6) { - ipv6_r = fill_in_one_address(cct, ifa, CEPH_PICK_ADDRESS_IPV6, - networks, interfaces, - addrs, - preferred_numa_node); - } - if ((ipv & CEPH_PICK_ADDRESS_IPV4) && - !(flags & CEPH_PICK_ADDRESS_PREFER_IPV4)) { - ipv4_r = fill_in_one_address(cct, ifa, CEPH_PICK_ADDRESS_IPV4, - networks, interfaces, - addrs, - preferred_numa_node); - } - if (ipv4_r >= 0 && ipv6_r >= 0) { - break; - } - if (preferred_numa_node < 0) { - return ipv4_r >= 0 && ipv6_r >= 0 ? 0 : -1; - } - preferred_numa_node = -1; // try any numa node + // note: pass in ipv to filter the matching addresses + if ((ipv & CEPH_PICK_ADDRESS_IPV4) && + (flags & CEPH_PICK_ADDRESS_PREFER_IPV4)) { + ipv4_r = fill_in_one_address(cct, ifa, CEPH_PICK_ADDRESS_IPV4, + networks, interfaces, + addrs, + preferred_numa_node); + } + if (ipv & CEPH_PICK_ADDRESS_IPV6) { + ipv6_r = fill_in_one_address(cct, ifa, CEPH_PICK_ADDRESS_IPV6, + networks, interfaces, + addrs, + preferred_numa_node); + } + if ((ipv & CEPH_PICK_ADDRESS_IPV4) && + !(flags & CEPH_PICK_ADDRESS_PREFER_IPV4)) { + ipv4_r = fill_in_one_address(cct, ifa, CEPH_PICK_ADDRESS_IPV4, + networks, interfaces, + addrs, + preferred_numa_node); + } + if (ipv4_r < 0 || ipv6_r < 0) { + return -1; } } |