$OpenBSD: patch-servers_slapd_back-mdb_init_c,v 1.2 2016/02/25 00:45:43 sthen Exp $

XXX maintaining the patch here, but MDB is disabled because last time
    it was enabled there were still problems even with this.

--- servers/slapd/back-mdb/init.c.orig	Fri Feb  5 23:57:45 2016
+++ servers/slapd/back-mdb/init.c	Fri Feb 12 13:38:28 2016
@@ -159,6 +159,32 @@ mdb_db_open( BackendDB *be, ConfigReply *cr )
 	dbhome = mdb->mi_dbenv_home;
 #endif
 
+#ifdef __OpenBSD__
+	/*
+	 * Enforce that MDB_WRITEMAP is set.
+	 *
+	 * MDB assumes a unified buffer cache.
+	 *
+	 * See http://www.openldap.org/pub/hyc/mdm-paper.pdf section 3.1,
+	 * references 17, 18, and 19.
+	 *
+	 * From Howard Chu: "This requirement can be relaxed in the
+	 * current version of the library. If you create the environment
+	 * with the MDB_WRITEMAP option then all reads and writes are
+	 * performed using mmap, so the file buffer cache is irrelevant.
+	 * Of course then you lose the protection that the read-only
+	 * map offers."
+	 */
+
+	if ( !(flags & MDB_WRITEMAP) ) {
+		Debug( LDAP_DEBUG_ANY,
+			LDAP_XSTRING(mdb_db_open) ": database \"%s\" does not have writemap. "
+			"This is required on systems without unified buffer cache.\n",
+			be->be_suffix[0].bv_val, rc, 0 );
+		goto fail;
+	}
+#endif
+
 	Debug( LDAP_DEBUG_TRACE,
 		LDAP_XSTRING(mdb_db_open) ": database \"%s\": "
 		"dbenv_open(%s).\n",
