]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sriov: introduce sr_iov_hash_func() and sr_iov_compare_func()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 23 Mar 2022 07:32:51 +0000 (16:32 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 23 Mar 2022 07:32:51 +0000 (16:32 +0900)
src/shared/netif-sriov.c
src/shared/netif-sriov.h

index 720aa65f4c0598dc9662a546379ded9a45639524..9edc1741242e35eed8df557d36d5d7456a2bae2d 100644 (file)
@@ -80,6 +80,26 @@ SRIOV *sr_iov_free(SRIOV *sr_iov) {
         return mfree(sr_iov);
 }
 
+void sr_iov_hash_func(const SRIOV *sr_iov, struct siphash *state) {
+        assert(sr_iov);
+        assert(state);
+
+        siphash24_compress(&sr_iov->vf, sizeof(sr_iov->vf), state);
+}
+
+int sr_iov_compare_func(const SRIOV *s1, const SRIOV *s2) {
+        assert(s1);
+        assert(s2);
+
+        return CMP(s1->vf, s2->vf);
+}
+
+DEFINE_PRIVATE_HASH_OPS(
+        sr_iov_hash_ops,
+        SRIOV,
+        sr_iov_hash_func,
+        sr_iov_compare_func);
+
 int sr_iov_set_netlink_message(SRIOV *sr_iov, sd_netlink_message *req) {
         int r;
 
@@ -296,7 +316,7 @@ static int sr_iov_section_verify(uint32_t num_vfs, SRIOV *sr_iov) {
 }
 
 int sr_iov_drop_invalid_sections(uint32_t num_vfs, OrderedHashmap *sr_iov_by_section) {
-        _cleanup_hashmap_free_ Hashmap *hashmap = NULL;
+        _cleanup_set_free_ Set *set = NULL;
         SRIOV *sr_iov;
         int r;
 
@@ -308,9 +328,7 @@ int sr_iov_drop_invalid_sections(uint32_t num_vfs, OrderedHashmap *sr_iov_by_sec
                         continue;
                 }
 
-                assert(sr_iov->vf < INT_MAX);
-
-                dup = hashmap_remove(hashmap, UINT32_TO_PTR(sr_iov->vf + 1));
+                dup = set_remove(set, sr_iov);
                 if (dup) {
                         log_warning("%s: Conflicting [SR-IOV] section is specified at line %u and %u, "
                                     "dropping the [SR-IOV] section specified at line %u.",
@@ -319,7 +337,7 @@ int sr_iov_drop_invalid_sections(uint32_t num_vfs, OrderedHashmap *sr_iov_by_sec
                         sr_iov_free(dup);
                 }
 
-                r = hashmap_ensure_put(&hashmap, NULL, UINT32_TO_PTR(sr_iov->vf + 1), sr_iov);
+                r = set_ensure_put(&set, &sr_iov_hash_ops, sr_iov);
                 if (r < 0)
                         return log_oom();
                 assert(r > 0);
index 4c85f101c7b3de0e48ae73cfd1f4c542ad20d7cc..ee769575e5be98dd45126b325088aaa7b9372094 100644 (file)
@@ -33,6 +33,8 @@ typedef struct SRIOV {
 } 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);
 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);