From c225990b8ebfbed43e1724e4059dcc45bee6cb0b Mon Sep 17 00:00:00 2001 From: Colin Vidal Date: Fri, 20 Dec 2024 11:15:37 +0100 Subject: [PATCH] Move LMDB common definitions in a dedicated header As several places uses custom LMDB macros, this centralize those definitions inside a dedicated `lib/isc/include/isc/lmdb.h` header file, so future uses cases not DNS-centrics could fit into there as well. MDB_CREATE is removed as well because: - it was useless (it's needed only for named DB, which is not the case for all use case so far) - it was used in `mdb_env_open` which is not expecting this flag: it should be passed (if needed) to `mdb_dbi_open`. It was likely ignored so far. --- bin/named/server.c | 3 +-- bin/tools/named-nzd2nzf.c | 3 ++- lib/dns/include/dns/view.h | 11 ----------- lib/dns/view.c | 2 +- lib/isc/Makefile.am | 1 + lib/isc/cfgmgr.c | 4 ++-- lib/isc/include/isc/lmdb.h | 27 +++++++++++++++++++++++++++ 7 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 lib/isc/include/isc/lmdb.h diff --git a/bin/named/server.c b/bin/named/server.c index f6988b1fc1..53127d4144 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -140,8 +141,6 @@ #include #endif /* ifdef HAVE_LIBSCF */ -#include - #ifndef SIZE_MAX #define SIZE_MAX ((size_t)-1) #endif /* ifndef SIZE_MAX */ diff --git a/bin/tools/named-nzd2nzf.c b/bin/tools/named-nzd2nzf.c index c77cbb5375..9703d5e265 100644 --- a/bin/tools/named-nzd2nzf.c +++ b/bin/tools/named-nzd2nzf.c @@ -11,10 +11,11 @@ * information regarding copyright ownership. */ -#include #include #include +#include + #include int diff --git a/lib/dns/include/dns/view.h b/lib/dns/include/dns/view.h index 86e771c09d..fa824779c3 100644 --- a/lib/dns/include/dns/view.h +++ b/lib/dns/include/dns/view.h @@ -246,17 +246,6 @@ struct dns_view { #define DNS_VIEWATTR_ADBSHUTDOWN 0x02 #define DNS_VIEWATTR_REQSHUTDOWN 0x04 -#define DNS_LMDB_COMMON_FLAGS (MDB_CREATE | MDB_NOSUBDIR | MDB_NOLOCK) -#ifndef __OpenBSD__ -#define DNS_LMDB_FLAGS (DNS_LMDB_COMMON_FLAGS) -#else /* __OpenBSD__ */ -/* - * OpenBSD does not have a unified buffer cache, which requires both reads and - * writes to be performed using mmap(). - */ -#define DNS_LMDB_FLAGS (DNS_LMDB_COMMON_FLAGS | MDB_WRITEMAP) -#endif /* __OpenBSD__ */ - isc_result_t dns_view_create(isc_mem_t *mctx, isc_loopmgr_t *loopmgr, dns_dispatchmgr_t *dispmgr, dns_rdataclass_t rdclass, diff --git a/lib/dns/view.c b/lib/dns/view.c index f6c056ac8a..9d1a51a948 100644 --- a/lib/dns/view.c +++ b/lib/dns/view.c @@ -15,7 +15,6 @@ #include #include -#include #include #include @@ -23,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/lib/isc/Makefile.am b/lib/isc/Makefile.am index 71dd5bac0f..98a3525522 100644 --- a/lib/isc/Makefile.am +++ b/lib/isc/Makefile.am @@ -44,6 +44,7 @@ libisc_la_HEADERS = \ include/isc/job.h \ include/isc/lex.h \ include/isc/list.h \ + include/isc/lmdb.h \ include/isc/log.h \ include/isc/loop.h \ include/isc/magic.h \ diff --git a/lib/isc/cfgmgr.c b/lib/isc/cfgmgr.c index fcb77f17af..af55f5e59f 100644 --- a/lib/isc/cfgmgr.c +++ b/lib/isc/cfgmgr.c @@ -11,17 +11,17 @@ * information regarding copyright ownership. */ -#include #include #include #include +#include #include +#include #include #include #include #include -#include /* * See MDB_MAXKEYSIZE documentation, but not accessible as defined in diff --git a/lib/isc/include/isc/lmdb.h b/lib/isc/include/isc/lmdb.h new file mode 100644 index 0000000000..391303c24f --- /dev/null +++ b/lib/isc/include/isc/lmdb.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * SPDX-License-Identifier: MPL-2.0 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at https://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +#pragma once + +#include + +#define DNS_LMDB_COMMON_FLAGS (MDB_NOSUBDIR | MDB_NOLOCK) +#ifndef __OpenBSD__ +#define DNS_LMDB_FLAGS (DNS_LMDB_COMMON_FLAGS) +#else /* __OpenBSD__ */ +/* + * OpenBSD does not have a unified buffer cache, which requires both reads and + * writes to be performed using mmap(). + */ +#define DNS_LMDB_FLAGS (DNS_LMDB_COMMON_FLAGS | MDB_WRITEMAP) +#endif /* __OpenBSD__ */