From: Vladimír Čunát Date: Mon, 4 Nov 2024 14:54:48 +0000 (+0100) Subject: mmapped_* nit: move from daemon/ to lib/ X-Git-Tag: v6.0.9~1^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19c4c0b59666554f8ef072aac0699bde9069184c;p=thirdparty%2Fknot-resolver.git mmapped_* nit: move from daemon/ to lib/ We'll utilize this for cache, so this will be an easy way for GC to access the mmapped_* symbols. In lib/ we usually prefix symbols by kr_ but I don't think it's worth the hassle in this case, as mmapped_ seems like a good enough prefix. --- diff --git a/daemon/defer.c b/daemon/defer.c index 59af3e689..32b0358c0 100644 --- a/daemon/defer.c +++ b/daemon/defer.c @@ -3,10 +3,10 @@ */ #include "daemon/defer.h" -#include "daemon/mmapped.h" #include "daemon/session2.h" #include "daemon/udp_queue.h" #include "lib/kru.h" +#include "lib/mmapped.h" #include "lib/utils.h" #define V4_PREFIXES (uint8_t[]) { 18, 20, 24, 32 } diff --git a/daemon/meson.build b/daemon/meson.build index a3f95480b..62ac983b7 100644 --- a/daemon/meson.build +++ b/daemon/meson.build @@ -13,7 +13,6 @@ kresd_src = files([ 'ffimodule.c', 'io.c', 'main.c', - 'mmapped.c', 'network.c', 'proxyv2.c', 'ratelimiting.c', @@ -33,10 +32,10 @@ endif c_src_lint += kresd_src unit_tests += [ - ['ratelimiting', files('ratelimiting.test/tests.c', 'mmapped.c') + libkres_src ], + ['ratelimiting', files('ratelimiting.test/tests.c') + libkres_src ], # parallel tests timeouts under valgrind; they checks mainly for race conditions, which is not needed there - ['ratelimiting-parallel', files('ratelimiting.test/tests-parallel.c', 'mmapped.c') + libkres_src, ['skip_valgrind']] + ['ratelimiting-parallel', files('ratelimiting.test/tests-parallel.c') + libkres_src, ['skip_valgrind']] ] config_tests += [ diff --git a/daemon/ratelimiting.c b/daemon/ratelimiting.c index 528608cf9..29d4c82a0 100644 --- a/daemon/ratelimiting.c +++ b/daemon/ratelimiting.c @@ -4,8 +4,8 @@ #include #include "daemon/ratelimiting.h" -#include "daemon/mmapped.h" #include "lib/kru.h" +#include "lib/mmapped.h" #include "lib/utils.h" #include "lib/resolve.h" diff --git a/lib/meson.build b/lib/meson.build index e369a4526..94bb80c73 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -25,6 +25,7 @@ libkres_src = files([ 'layer/iterate.c', 'layer/validate.c', 'log.c', + 'mmapped.c', 'proto.c', 'rules/api.c', 'rules/defaults.c', @@ -63,6 +64,7 @@ libkres_headers = files([ 'layer.h', 'layer/iterate.h', 'log.h', + 'mmapped.h', 'module.h', 'proto.h', 'resolve.h', diff --git a/daemon/mmapped.c b/lib/mmapped.c similarity index 99% rename from daemon/mmapped.c rename to lib/mmapped.c index 7c6ba099f..f37748b78 100644 --- a/daemon/mmapped.c +++ b/lib/mmapped.c @@ -7,7 +7,7 @@ #include #include -#include "daemon/mmapped.h" +#include "lib/mmapped.h" #include "lib/utils.h" static inline bool fcntl_flock_whole(int fd, short int type, bool wait) diff --git a/daemon/mmapped.h b/lib/mmapped.h similarity index 95% rename from daemon/mmapped.h rename to lib/mmapped.h index 2f810376e..eb542096d 100644 --- a/daemon/mmapped.h +++ b/lib/mmapped.h @@ -2,7 +2,7 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -#include +#include "lib/defines.h" #define MMAPPED_WAS_FIRST 1 @@ -19,12 +19,15 @@ struct mmapped { * you should finish initialization and call mmapped_init_continue to degrade flock to shared. * Otherwise, it waits for shared flock, calls mmap, verifies that header is byte-wise identical and returns zero. * On header mismatch, kr_error(ENOTRECOVERABLE) is returned; on a system error, kr_error(errno) is returned. */ +KR_EXPORT int mmapped_init(struct mmapped *mmapped, const char *mmap_file, size_t size, void *header, size_t header_size); /* Degrade flock to shared after getting MMAPPED_WAS_FIRST from mmapped_init. * * Returns zero on success and kr_error(errno) on system error. */ +KR_EXPORT int mmapped_init_continue(struct mmapped *mmapped); /* Free mmapped memory and, unless the underlying file is used by other processes, truncate it to zero size. */ +KR_EXPORT void mmapped_deinit(struct mmapped *mmapped);