From 281b298118181065c08e9f67c58c0b23e3d7d5fe Mon Sep 17 00:00:00 2001 From: vkalintiris Date: Wed, 23 Oct 2024 06:19:49 +0300 Subject: [PATCH] Reorganize top-level headers in libnetdata. (#18643) Move top-level libnetdata headers (simple hashtable, bitmap, linked list, xxHash) into more specific subdirectories and update the corresponding include paths throughout the project to reflect these changes. --- CMakeLists.txt | 8 +++++--- src/collectors/apps.plugin/apps_pid.c | 2 +- src/collectors/log2journal/log2journal.h | 6 +++--- src/collectors/network-viewer.plugin/network-viewer.c | 2 +- .../windows-events-fields-cache.c | 2 +- .../windows-events.plugin/windows-events-providers.c | 2 +- src/database/engine/journalfile.c | 1 - src/libnetdata/{ => bitmap}/bitmap64.h | 0 src/libnetdata/common.h | 4 ++-- src/libnetdata/config/dyncfg.c | 2 +- src/libnetdata/facets/facets.c | 8 ++++---- src/libnetdata/libnetdata.h | 2 +- .../{linked-lists.h => linked_lists/linked_lists.h} | 0 src/libnetdata/local-sockets/local-sockets.h | 10 +++++----- src/libnetdata/os/system-maps/cached-gid-groupname.c | 2 +- src/libnetdata/os/system-maps/cached-sid-username.c | 2 +- src/libnetdata/os/system-maps/cached-uid-username.c | 2 +- src/libnetdata/os/system-maps/system-services.h | 2 +- src/libnetdata/os/windows-perflib/perflib-names.c | 2 +- src/libnetdata/query_progress/progress.c | 4 ++-- .../{ => simple_hashtable}/simple_hashtable.h | 2 +- .../{ => simple_hashtable}/simple_hashtable_undef.h | 0 src/libnetdata/{ => xxHash}/xxhash.h | 0 23 files changed, 33 insertions(+), 32 deletions(-) rename src/libnetdata/{ => bitmap}/bitmap64.h (100%) rename src/libnetdata/{linked-lists.h => linked_lists/linked_lists.h} (100%) rename src/libnetdata/{ => simple_hashtable}/simple_hashtable.h (99%) rename src/libnetdata/{ => simple_hashtable}/simple_hashtable_undef.h (100%) rename src/libnetdata/{ => xxHash}/xxhash.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index d88091391506ef..ccb561e1d51dc1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -636,6 +636,7 @@ set(LIBNETDATA_FILES src/libnetdata/aral/aral.h src/libnetdata/avl/avl.c src/libnetdata/avl/avl.h + src/libnetdata/bitmap/bitmap64.h src/libnetdata/buffer/buffer.c src/libnetdata/buffer/buffer.h src/libnetdata/ringbuffer/ringbuffer.c @@ -674,6 +675,7 @@ set(LIBNETDATA_FILES src/libnetdata/line_splitter/line_splitter.c src/libnetdata/line_splitter/line_splitter.h src/libnetdata/libnetdata.h + src/libnetdata/linked_lists/linked_lists.h src/libnetdata/locks/locks.c src/libnetdata/locks/locks.h src/libnetdata/log/systemd-journal-helpers.c @@ -682,7 +684,6 @@ set(LIBNETDATA_FILES src/libnetdata/log/nd_log.h src/libnetdata/os/os.c src/libnetdata/os/os.h - src/libnetdata/simple_hashtable.h src/libnetdata/os/byteorder.h src/libnetdata/onewayalloc/onewayalloc.c src/libnetdata/onewayalloc/onewayalloc.h @@ -693,6 +694,8 @@ set(LIBNETDATA_FILES src/libnetdata/required_dummies.h src/libnetdata/socket/security.c src/libnetdata/socket/security.h + src/libnetdata/simple_hashtable/simple_hashtable.h + src/libnetdata/simple_hashtable/simple_hashtable_undef.h src/libnetdata/simple_pattern/simple_pattern.c src/libnetdata/simple_pattern/simple_pattern.h src/libnetdata/socket/socket.c @@ -733,11 +736,9 @@ set(LIBNETDATA_FILES src/libnetdata/dictionary/dictionary-hashtable.h src/libnetdata/dictionary/dictionary-item.h src/libnetdata/dictionary/dictionary-callbacks.h - src/libnetdata/linked-lists.h src/libnetdata/storage-point.h src/libnetdata/parsers/parsers.h src/libnetdata/parsers/duration.c - src/libnetdata/bitmap64.h src/libnetdata/os/gettid.c src/libnetdata/os/gettid.h src/libnetdata/os/adjtimex.c @@ -860,6 +861,7 @@ set(LIBNETDATA_FILES src/libnetdata/log/nd_log-common.h src/libnetdata/log/nd_log-to-windows-common.h src/libnetdata/common.h + src/libnetdata/xxHash/xxhash.h ) if(ENABLE_PLUGIN_EBPF) diff --git a/src/collectors/apps.plugin/apps_pid.c b/src/collectors/apps.plugin/apps_pid.c index 509aeadb5db2b4..0dcee7ccead753 100644 --- a/src/collectors/apps.plugin/apps_pid.c +++ b/src/collectors/apps.plugin/apps_pid.c @@ -13,7 +13,7 @@ static inline void link_pid_to_its_parent(struct pid_stat *p); #define SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION pid_stat_to_pid_ptr #define SIMPLE_HASHTABLE_COMPARE_KEYS_FUNCTION pid_ptr_eq #define SIMPLE_HASHTABLE_SAMPLE_IMPLEMENTATION 0 -#include "libnetdata/simple_hashtable.h" +#include "libnetdata/simple_hashtable/simple_hashtable.h" static inline int32_t *pid_stat_to_pid_ptr(struct pid_stat *p) { return &p->pid; diff --git a/src/collectors/log2journal/log2journal.h b/src/collectors/log2journal/log2journal.h index 5bdf7276b00641..ce1b86f4a78539 100644 --- a/src/collectors/log2journal/log2journal.h +++ b/src/collectors/log2journal/log2journal.h @@ -109,7 +109,7 @@ static inline void freez(void *ptr) { // ---------------------------------------------------------------------------- #define XXH_INLINE_ALL -#include "libnetdata/xxhash.h" +#include "libnetdata/xxHash/xxhash.h" #define PCRE2_CODE_UNIT_WIDTH 8 #include @@ -122,14 +122,14 @@ static inline void freez(void *ptr) { // hashtable for HASHED_KEY // cleanup hashtable defines -#include "libnetdata/simple_hashtable_undef.h" +#include "libnetdata/simple_hashtable/simple_hashtable_undef.h" struct hashed_key; static inline int compare_keys(struct hashed_key *k1, struct hashed_key *k2); #define SIMPLE_HASHTABLE_SORT_FUNCTION compare_keys #define SIMPLE_HASHTABLE_VALUE_TYPE struct hashed_key #define SIMPLE_HASHTABLE_NAME _KEY -#include "libnetdata/simple_hashtable.h" +#include "libnetdata/simple_hashtable/simple_hashtable.h" // ---------------------------------------------------------------------------- diff --git a/src/collectors/network-viewer.plugin/network-viewer.c b/src/collectors/network-viewer.plugin/network-viewer.c index 6892287f2b29fe..75ce5ee2ef07f8 100644 --- a/src/collectors/network-viewer.plugin/network-viewer.c +++ b/src/collectors/network-viewer.plugin/network-viewer.c @@ -31,7 +31,7 @@ static SPAWN_SERVER *spawn_srv = NULL; #define SIMPLE_HASHTABLE_VALUE_TYPE LOCAL_SOCKET #define SIMPLE_HASHTABLE_NAME _AGGREGATED_SOCKETS -#include "libnetdata/simple_hashtable.h" +#include "libnetdata/simple_hashtable/simple_hashtable.h" netdata_mutex_t stdout_mutex = NETDATA_MUTEX_INITIALIZER; static bool plugin_should_exit = false; diff --git a/src/collectors/windows-events.plugin/windows-events-fields-cache.c b/src/collectors/windows-events.plugin/windows-events-fields-cache.c index 1e1e2a4e96bd1e..4b4b72fa4e4bf2 100644 --- a/src/collectors/windows-events.plugin/windows-events-fields-cache.c +++ b/src/collectors/windows-events.plugin/windows-events-fields-cache.c @@ -19,7 +19,7 @@ typedef struct field_value { #define SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION field_cache_value_to_key #define SIMPLE_HASHTABLE_COMPARE_KEYS_FUNCTION field_cache_cache_compar #define SIMPLE_HASHTABLE_SAMPLE_IMPLEMENTATION 1 -#include "libnetdata/simple_hashtable.h" +#include "libnetdata/simple_hashtable/simple_hashtable.h" static inline WEVT_FIELD_KEY *field_cache_value_to_key(WEVT_FIELD_VALUE *p) { return &p->key; diff --git a/src/collectors/windows-events.plugin/windows-events-providers.c b/src/collectors/windows-events.plugin/windows-events-providers.c index 68045127aecf09..d4c4d35ea15de2 100644 --- a/src/collectors/windows-events.plugin/windows-events-providers.c +++ b/src/collectors/windows-events.plugin/windows-events-providers.c @@ -64,7 +64,7 @@ typedef struct provider { #define SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION provider_value_to_key #define SIMPLE_HASHTABLE_COMPARE_KEYS_FUNCTION provider_cache_compar #define SIMPLE_HASHTABLE_SAMPLE_IMPLEMENTATION 1 -#include "libnetdata/simple_hashtable.h" +#include "libnetdata/simple_hashtable/simple_hashtable.h" static struct { SPINLOCK spinlock; diff --git a/src/database/engine/journalfile.c b/src/database/engine/journalfile.c index 4ea988d6458561..b120ce3c3bcd86 100644 --- a/src/database/engine/journalfile.c +++ b/src/database/engine/journalfile.c @@ -1,5 +1,4 @@ // SPDX-License-Identifier: GPL-3.0-or-later -#include "libnetdata/bitmap64.h" #include "rrdengine.h" static void after_extent_write_journalfile_v1_io(uv_fs_t* req) diff --git a/src/libnetdata/bitmap64.h b/src/libnetdata/bitmap/bitmap64.h similarity index 100% rename from src/libnetdata/bitmap64.h rename to src/libnetdata/bitmap/bitmap64.h diff --git a/src/libnetdata/common.h b/src/libnetdata/common.h index b959929d2aa51b..f7f3a779658728 100644 --- a/src/libnetdata/common.h +++ b/src/libnetdata/common.h @@ -252,7 +252,7 @@ typedef uint32_t uid_t; #endif #define XXH_INLINE_ALL -#include "xxhash.h" +#include "xxHash/xxhash.h" // -------------------------------------------------------------------------------------------------------------------- // OpenSSL @@ -378,7 +378,7 @@ typedef uint32_t uid_t; // -------------------------------------------------------------------------------------------------------------------- // Macro-only includes -#include "linked-lists.h" +#include "linked_lists/linked_lists.h" // -------------------------------------------------------------------------------------------------------------------- diff --git a/src/libnetdata/config/dyncfg.c b/src/libnetdata/config/dyncfg.c index 61d8dea505e6a1..81b050f89a5c4b 100644 --- a/src/libnetdata/config/dyncfg.c +++ b/src/libnetdata/config/dyncfg.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-or-later -#include "../../libnetdata/libnetdata.h" +#include "../libnetdata.h" // ---------------------------------------------------------------------------- diff --git a/src/libnetdata/facets/facets.c b/src/libnetdata/facets/facets.c index 50ddf79ef48f2f..230e03de5eed78 100644 --- a/src/libnetdata/facets/facets.c +++ b/src/libnetdata/facets/facets.c @@ -102,25 +102,25 @@ static inline bool is_valid_string_hash(const char *s) { // hashtable for FACET_VALUE // cleanup hashtable defines -#include "../../libnetdata/simple_hashtable_undef.h" +#include "../simple_hashtable/simple_hashtable_undef.h" struct facet_value; // #define SIMPLE_HASHTABLE_SORT_FUNCTION compare_facet_value #define SIMPLE_HASHTABLE_VALUE_TYPE struct facet_value #define SIMPLE_HASHTABLE_NAME _VALUE -#include "../simple_hashtable.h" +#include "../simple_hashtable/simple_hashtable.h" // ---------------------------------------------------------------------------- // hashtable for FACET_KEY // cleanup hashtable defines -#include "../../libnetdata/simple_hashtable_undef.h" +#include "../simple_hashtable/simple_hashtable_undef.h" struct facet_key; // #define SIMPLE_HASHTABLE_SORT_FUNCTION compare_facet_key #define SIMPLE_HASHTABLE_VALUE_TYPE struct facet_key #define SIMPLE_HASHTABLE_NAME _KEY -#include "../simple_hashtable.h" +#include "../simple_hashtable/simple_hashtable.h" // ---------------------------------------------------------------------------- diff --git a/src/libnetdata/libnetdata.h b/src/libnetdata/libnetdata.h index 2ba64b95bdc5c4..acee0675f4f5e3 100644 --- a/src/libnetdata/libnetdata.h +++ b/src/libnetdata/libnetdata.h @@ -88,7 +88,7 @@ char *find_and_replace(const char *src, const char *find, const char *replace, c #define error_report(x, args...) do { errno_clear(); netdata_log_error(x, ##args); } while(0) -#include "bitmap64.h" +#include "bitmap/bitmap64.h" #define COMPRESSION_MAX_CHUNK 0x4000 #define COMPRESSION_MAX_OVERHEAD 128 diff --git a/src/libnetdata/linked-lists.h b/src/libnetdata/linked_lists/linked_lists.h similarity index 100% rename from src/libnetdata/linked-lists.h rename to src/libnetdata/linked_lists/linked_lists.h diff --git a/src/libnetdata/local-sockets/local-sockets.h b/src/libnetdata/local-sockets/local-sockets.h index 4230b94ed70186..06ac08767c82f3 100644 --- a/src/libnetdata/local-sockets/local-sockets.h +++ b/src/libnetdata/local-sockets/local-sockets.h @@ -29,7 +29,7 @@ #define SIMPLE_HASHTABLE_VALUE_TYPE uint64_t #define SIMPLE_HASHTABLE_NAME _NET_NS -#include "libnetdata/simple_hashtable.h" +#include "libnetdata/simple_hashtable/simple_hashtable.h" // -------------------------------------------------------------------------------------------------------------------- // hashtable for keeping the sockets of PIDs @@ -38,7 +38,7 @@ struct pid_socket; #define SIMPLE_HASHTABLE_VALUE_TYPE struct pid_socket #define SIMPLE_HASHTABLE_NAME _PID_SOCKET -#include "libnetdata/simple_hashtable.h" +#include "libnetdata/simple_hashtable/simple_hashtable.h" // -------------------------------------------------------------------------------------------------------------------- // hashtable for keeping all the sockets @@ -47,7 +47,7 @@ struct pid_socket; struct local_socket; #define SIMPLE_HASHTABLE_VALUE_TYPE struct local_socket #define SIMPLE_HASHTABLE_NAME _LOCAL_SOCKET -#include "libnetdata/simple_hashtable.h" +#include "libnetdata/simple_hashtable/simple_hashtable.h" // -------------------------------------------------------------------------------------------------------------------- // hashtable for keeping all local IPs @@ -56,7 +56,7 @@ struct local_socket; union ipv46; #define SIMPLE_HASHTABLE_VALUE_TYPE union ipv46 #define SIMPLE_HASHTABLE_NAME _LOCAL_IP -#include "libnetdata/simple_hashtable.h" +#include "libnetdata/simple_hashtable/simple_hashtable.h" // -------------------------------------------------------------------------------------------------------------------- // hashtable for keeping all listening ports @@ -65,7 +65,7 @@ union ipv46; struct local_port; #define SIMPLE_HASHTABLE_VALUE_TYPE struct local_port #define SIMPLE_HASHTABLE_NAME _LISTENING_PORT -#include "libnetdata/simple_hashtable.h" +#include "libnetdata/simple_hashtable/simple_hashtable.h" // -------------------------------------------------------------------------------------------------------------------- diff --git a/src/libnetdata/os/system-maps/cached-gid-groupname.c b/src/libnetdata/os/system-maps/cached-gid-groupname.c index be34b3efec5cd3..4b22bc04a14955 100644 --- a/src/libnetdata/os/system-maps/cached-gid-groupname.c +++ b/src/libnetdata/os/system-maps/cached-gid-groupname.c @@ -11,7 +11,7 @@ #define SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION cached_groupname_to_gid_ptr #define SIMPLE_HASHTABLE_COMPARE_KEYS_FUNCTION compar_gid_ptr #define SIMPLE_HASHTABLE_NAME _GROUPNAMES_CACHE -#include "libnetdata/simple_hashtable.h" +#include "libnetdata/simple_hashtable/simple_hashtable.h" static struct { bool initialized; diff --git a/src/libnetdata/os/system-maps/cached-sid-username.c b/src/libnetdata/os/system-maps/cached-sid-username.c index 466ca62c639e47..f3dec1aa7eebdf 100644 --- a/src/libnetdata/os/system-maps/cached-sid-username.c +++ b/src/libnetdata/os/system-maps/cached-sid-username.c @@ -31,7 +31,7 @@ typedef struct { #define SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION sid_value_to_key #define SIMPLE_HASHTABLE_COMPARE_KEYS_FUNCTION sid_cache_compar #define SIMPLE_HASHTABLE_SAMPLE_IMPLEMENTATION 1 -#include "libnetdata/simple_hashtable.h" +#include "libnetdata/simple_hashtable/simple_hashtable.h" static struct { SPINLOCK spinlock; diff --git a/src/libnetdata/os/system-maps/cached-uid-username.c b/src/libnetdata/os/system-maps/cached-uid-username.c index 2de4ad9c5f9a96..4b5977d323dfdc 100644 --- a/src/libnetdata/os/system-maps/cached-uid-username.c +++ b/src/libnetdata/os/system-maps/cached-uid-username.c @@ -11,7 +11,7 @@ #define SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION cached_username_to_uid_ptr #define SIMPLE_HASHTABLE_COMPARE_KEYS_FUNCTION compar_uid_ptr #define SIMPLE_HASHTABLE_NAME _USERNAMES_CACHE -#include "libnetdata/simple_hashtable.h" +#include "libnetdata/simple_hashtable/simple_hashtable.h" static struct { uint32_t version; diff --git a/src/libnetdata/os/system-maps/system-services.h b/src/libnetdata/os/system-maps/system-services.h index f056bc21b76de9..5d3592bbf04ce7 100644 --- a/src/libnetdata/os/system-maps/system-services.h +++ b/src/libnetdata/os/system-maps/system-services.h @@ -12,7 +12,7 @@ #define SIMPLE_HASHTABLE_VALUE_TYPE STRING #define SIMPLE_HASHTABLE_NAME _SERVICENAMES_CACHE -#include "libnetdata/simple_hashtable.h" +#include "libnetdata/simple_hashtable/simple_hashtable.h" typedef struct servicenames_cache { SPINLOCK spinlock; diff --git a/src/libnetdata/os/windows-perflib/perflib-names.c b/src/libnetdata/os/windows-perflib/perflib-names.c index b4404e1ea22ad4..ee717d9a85a8d3 100644 --- a/src/libnetdata/os/windows-perflib/perflib-names.c +++ b/src/libnetdata/os/windows-perflib/perflib-names.c @@ -26,7 +26,7 @@ static inline const char *value2key_perfLibRegistryEntry(perfLibRegistryEntry *e #define SIMPLE_HASHTABLE_KEY_TYPE const char #define SIMPLE_HASHTABLE_VALUE_TYPE perfLibRegistryEntry #define SIMPLE_HASHTABLE_NAME _PERFLIB -#include "libnetdata/simple_hashtable.h" +#include "libnetdata/simple_hashtable/simple_hashtable.h" static struct { SPINLOCK spinlock; diff --git a/src/libnetdata/query_progress/progress.c b/src/libnetdata/query_progress/progress.c index fb5aae3601bb1c..157f20f112a49d 100644 --- a/src/libnetdata/query_progress/progress.c +++ b/src/libnetdata/query_progress/progress.c @@ -8,7 +8,7 @@ // hashtable for HASHED_KEY // cleanup hashtable defines -#include "../simple_hashtable_undef.h" +#include "../simple_hashtable/simple_hashtable_undef.h" struct query; #define SIMPLE_HASHTABLE_VALUE_TYPE struct query @@ -16,7 +16,7 @@ struct query; #define SIMPLE_HASHTABLE_NAME _QUERY #define SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION query_transaction #define SIMPLE_HASHTABLE_COMPARE_KEYS_FUNCTION query_compare_keys -#include "../simple_hashtable.h" +#include "../simple_hashtable/simple_hashtable.h" // ---------------------------------------------------------------------------- diff --git a/src/libnetdata/simple_hashtable.h b/src/libnetdata/simple_hashtable/simple_hashtable.h similarity index 99% rename from src/libnetdata/simple_hashtable.h rename to src/libnetdata/simple_hashtable/simple_hashtable.h index 4a7c9fbd42b80f..fe88d23f887f29 100644 --- a/src/libnetdata/simple_hashtable.h +++ b/src/libnetdata/simple_hashtable/simple_hashtable.h @@ -507,7 +507,7 @@ static inline SIMPLE_HASHTABLE_SLOT_NAMED *simple_hashtable_next_read_only_named #ifndef XXH_INLINE_ALL #define XXH_INLINE_ALL #endif -#include "xxhash.h" +#include "../xxHash/xxhash.h" #define simple_hashtable_set_named CONCAT(simple_hashtable_set, SIMPLE_HASHTABLE_NAME) #define simple_hashtable_get_named CONCAT(simple_hashtable_get, SIMPLE_HASHTABLE_NAME) diff --git a/src/libnetdata/simple_hashtable_undef.h b/src/libnetdata/simple_hashtable/simple_hashtable_undef.h similarity index 100% rename from src/libnetdata/simple_hashtable_undef.h rename to src/libnetdata/simple_hashtable/simple_hashtable_undef.h diff --git a/src/libnetdata/xxhash.h b/src/libnetdata/xxHash/xxhash.h similarity index 100% rename from src/libnetdata/xxhash.h rename to src/libnetdata/xxHash/xxhash.h