]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
cache: pre-allocating cache file when cache size is being changed
authorLukáš Ježek <lukas.jezek@nic.cz>
Tue, 7 Jan 2020 14:45:08 +0000 (15:45 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 8 Jan 2020 15:16:51 +0000 (16:16 +0100)
NEWS
lib/cache/cdb_lmdb.c

diff --git a/NEWS b/NEWS
index a4753682b46c7a17294b8e5790146653a40b340b..26e1dc652f4893ef8fa3ab1f8508635783b638fe 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,7 @@ Improvements
 - use SO_REUSEPORT_LB if available (FreeBSD 12.0+)
 - lua: remove dependency on lua-socket and lua-sec, used lua-http and cqueues (#512, #521, !894)
 - net.listen(): allow binding to non-local address with freebind option (!898)
+- cache: pre-allocate the file to avoid SIGBUS later (not macOS; !917, #525)
 
 
 Knot Resolver 4.3.0 (2019-12-04)
index 48129635826116104695e9455ec6b27d26f88f6d..30c43639595d21aa24595c1736fc7903378a82f2 100644 (file)
@@ -334,6 +334,27 @@ static int cdb_open(struct lmdb_env *env, const char *path, size_t mapsize,
                return lmdb_error(ret);
        }
 
+#if !defined(__MACOSX__) && !(defined(__APPLE__) && defined(__MACH__))
+       auto_free char *mdb_datafile = kr_strcatdup(2, path, "/data.mdb");
+       int fd = open(mdb_datafile, O_RDWR);
+       if (fd == -1) {
+               mdb_txn_abort(txn);
+               stats->close++;
+               mdb_env_close(env->env);
+               return kr_error(errno);
+       }
+
+       ret = posix_fallocate(fd, 0, mapsize);
+       if (ret != 0) {
+               mdb_txn_abort(txn);
+               stats->close++;
+               mdb_env_close(env->env);
+               close(fd);
+               return kr_error(ret);
+       }
+       close(fd);
+#endif
+
        stats->commit++;
        ret = mdb_txn_commit(txn);
        if (ret != MDB_SUCCESS) {