From: Yu Watanabe Date: Sat, 12 Apr 2025 15:11:01 +0000 (+0900) Subject: network,udev: use hash_ops with destructor to manage SR-IOV configs X-Git-Tag: v258-rc1~790^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d3af116afd8e19d0162c096e35ca25dc0f0c8939;p=thirdparty%2Fsystemd.git network,udev: use hash_ops with destructor to manage SR-IOV configs --- diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 0a45df5c8e2..3b05cf170cd 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -836,7 +836,7 @@ static Network *network_free(Network *network) { hashmap_free_with_destructor(network->pref64_prefixes_by_section, prefix64_free); hashmap_free(network->rules_by_section); hashmap_free_with_destructor(network->dhcp_static_leases_by_section, dhcp_static_lease_free); - ordered_hashmap_free_with_destructor(network->sr_iov_by_section, sr_iov_free); + ordered_hashmap_free(network->sr_iov_by_section); hashmap_free(network->qdiscs_by_section); hashmap_free(network->tclasses_by_section); diff --git a/src/shared/netif-sriov.c b/src/shared/netif-sriov.c index 20e175edcd3..fc851689b09 100644 --- a/src/shared/netif-sriov.c +++ b/src/shared/netif-sriov.c @@ -9,6 +9,25 @@ #include "stdio-util.h" #include "string-util.h" +static SRIOV* sr_iov_free(SRIOV *sr_iov) { + if (!sr_iov) + return NULL; + + if (sr_iov->sr_iov_by_section && sr_iov->section) + ordered_hashmap_remove(sr_iov->sr_iov_by_section, sr_iov->section); + + config_section_free(sr_iov->section); + + return mfree(sr_iov); +} + +DEFINE_SECTION_CLEANUP_FUNCTIONS(SRIOV, sr_iov_free); + +DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR( + sr_iov_hash_ops_by_section, + ConfigSection, config_section_hash_func, config_section_compare_func, + SRIOV, sr_iov_free); + static int sr_iov_new(SRIOV **ret) { SRIOV *sr_iov; @@ -57,7 +76,7 @@ static int sr_iov_new_static(OrderedHashmap **sr_iov_by_section, const char *fil if (r < 0) return r; - r = ordered_hashmap_ensure_put(sr_iov_by_section, &config_section_hash_ops, n, sr_iov); + r = ordered_hashmap_ensure_put(sr_iov_by_section, &sr_iov_hash_ops_by_section, n, sr_iov); if (r < 0) return r; @@ -68,18 +87,6 @@ static int sr_iov_new_static(OrderedHashmap **sr_iov_by_section, const char *fil return 0; } -SRIOV *sr_iov_free(SRIOV *sr_iov) { - if (!sr_iov) - return NULL; - - if (sr_iov->sr_iov_by_section && sr_iov->section) - ordered_hashmap_remove(sr_iov->sr_iov_by_section, sr_iov->section); - - config_section_free(sr_iov->section); - - return mfree(sr_iov); -} - void sr_iov_hash_func(const SRIOV *sr_iov, struct siphash *state) { assert(sr_iov); assert(state); diff --git a/src/shared/netif-sriov.h b/src/shared/netif-sriov.h index ee769575e5b..4e0b19bf3bb 100644 --- a/src/shared/netif-sriov.h +++ b/src/shared/netif-sriov.h @@ -32,7 +32,6 @@ typedef struct SRIOV { struct ether_addr mac; } SRIOV; -SRIOV *sr_iov_free(SRIOV *sr_iov); void sr_iov_hash_func(const SRIOV *sr_iov, struct siphash *state); int sr_iov_compare_func(const SRIOV *s1, const SRIOV *s2); int sr_iov_set_netlink_message(SRIOV *sr_iov, sd_netlink_message *req); @@ -40,8 +39,6 @@ int sr_iov_get_num_vfs(sd_device *device, uint32_t *ret); int sr_iov_set_num_vfs(sd_device *device, uint32_t num_vfs, OrderedHashmap *sr_iov_by_section); int sr_iov_drop_invalid_sections(uint32_t num_vfs, OrderedHashmap *sr_iov_by_section); -DEFINE_SECTION_CLEANUP_FUNCTIONS(SRIOV, sr_iov_free); - CONFIG_PARSER_PROTOTYPE(config_parse_sr_iov_uint32); CONFIG_PARSER_PROTOTYPE(config_parse_sr_iov_boolean); CONFIG_PARSER_PROTOTYPE(config_parse_sr_iov_link_state); diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index 2ae0f693eee..1e15bc4b8a6 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -75,7 +75,7 @@ static LinkConfig* link_config_free(LinkConfig *config) { erase_and_free(config->wol_password); cpu_set_free(config->rps_cpu_mask); - ordered_hashmap_free_with_destructor(config->sr_iov_by_section, sr_iov_free); + ordered_hashmap_free(config->sr_iov_by_section); return mfree(config); }