]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network,udev: use hash_ops with destructor to manage SR-IOV configs
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 12 Apr 2025 15:11:01 +0000 (00:11 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 13 Apr 2025 01:09:53 +0000 (10:09 +0900)
src/network/networkd-network.c
src/shared/netif-sriov.c
src/shared/netif-sriov.h
src/udev/net/link-config.c

index 0a45df5c8e2b6996fed633b7ac32e30c8d060161..3b05cf170cd8fd7acb9fbc7cfe026cfa4fd64ceb 100644 (file)
@@ -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);
 
index 20e175edcd3c8a7e2486cb61be2f9f133a6ccf40..fc851689b092e87913f3e431f54228431128ebf7 100644 (file)
@@ -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);
index ee769575e5be98dd45126b325088aaa7b9372094..4e0b19bf3bb56090b29aca9b2c4261b3da165412 100644 (file)
@@ -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);
index 2ae0f693eee80f521d24e88e738fba737f157be4..1e15bc4b8a6864e148b743006378136d2e4f01f7 100644 (file)
@@ -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);
 }