From 747f5d3594566e4a9f56595cfd0feef7004e3485 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sun, 21 Feb 2016 18:29:40 +0000 Subject: Preliminary raw partition support Autodetects that a block device is being used. --- external/db_drivers/liblmdb/mdb.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'external') diff --git a/external/db_drivers/liblmdb/mdb.c b/external/db_drivers/liblmdb/mdb.c index 6314d5775..0d01d2959 100644 --- a/external/db_drivers/liblmdb/mdb.c +++ b/external/db_drivers/liblmdb/mdb.c @@ -1473,6 +1473,8 @@ struct MDB_env { #define MDB_ENV_TXKEY 0x10000000U /** fdatasync is unreliable */ #define MDB_FSYNCONLY 0x08000000U + /** using a raw block device */ +#define MDB_RAWPART 0x04000000U uint32_t me_flags; /**< @ref mdb_env */ unsigned int me_psize; /**< DB page size, inited from me_os_psize */ unsigned int me_os_psize; /**< OS page size, from #GET_PAGESIZE */ @@ -4081,6 +4083,8 @@ mdb_env_read_header(MDB_env *env, int prev, MDB_meta *meta) p = (MDB_page *)&pbuf; if (!F_ISSET(p->mp_flags, P_META)) { + if (env->me_flags & MDB_RAWPART) + return ENOENT; DPRINTF(("page %"Yu" not a meta page", p->mp_pgno)); return MDB_INVALID; } @@ -4410,7 +4414,7 @@ mdb_env_map(MDB_env *env, void *addr) int prot = PROT_READ; if (flags & MDB_WRITEMAP) { prot |= PROT_WRITE; - if (ftruncate(env->me_fd, env->me_mapsize) < 0) + if (!(flags & MDB_RAWPART) && ftruncate(env->me_fd, env->me_mapsize) < 0) return ErrCode(); } env->me_map = mmap(addr, env->me_mapsize, prot, MAP_SHARED, @@ -5448,6 +5452,17 @@ mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode if (rc) goto leave; #endif +#endif +#ifndef _WIN32 + { + struct stat st; + rc = stat(path, &st); + if (rc) + return ErrCode(); + flags &= ~MDB_RAWPART; + if (S_ISBLK(st.st_mode)) + flags |= MDB_RAWPART | MDB_NOSUBDIR; + } #endif flags |= MDB_ENV_ACTIVE; /* tell mdb_env_close0() to clean up */ -- cgit v1.2.3 From 4e7586c9e41689b116108b806ab322b30f771082 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Mon, 11 Jun 2018 10:12:03 +0100 Subject: More RAWPART support Use mmap to read and initialize the meta pages, raw device may not support read/write syscalls. --- external/db_drivers/liblmdb/mdb.c | 44 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'external') diff --git a/external/db_drivers/liblmdb/mdb.c b/external/db_drivers/liblmdb/mdb.c index 0d01d2959..52ad844e9 100644 --- a/external/db_drivers/liblmdb/mdb.c +++ b/external/db_drivers/liblmdb/mdb.c @@ -4040,6 +4040,8 @@ fail: return rc; } +static int ESECT mdb_env_map(MDB_env *env, void *addr); + /** Read the environment parameters of a DB environment before * mapping it into memory. * @param[in] env the environment handle @@ -4056,6 +4058,31 @@ mdb_env_read_header(MDB_env *env, int prev, MDB_meta *meta) int i, rc, off; enum { Size = sizeof(pbuf) }; + if (env->me_flags & MDB_RAWPART) { +#define VM_ALIGN 0x200000 + env->me_mapsize += VM_ALIGN-1; + env->me_mapsize &= ~(VM_ALIGN-1); + env->me_psize = env->me_os_psize; + rc = mdb_env_map(env, NULL); + if (rc) { + DPRINTF(("mdb_env_map: %s", mdb_strerror(rc))); + return rc; + } + p = (MDB_page *)env->me_map; + for (i=0; imp_flags, P_META)) + return ENOENT; + if (env->me_metas[i]->mm_magic != MDB_MAGIC) + return MDB_INVALID; + if (env->me_metas[i]->mm_version != MDB_DATA_VERSION) + return MDB_VERSION_MISMATCH; + if (i == 0 || env->me_metas[i]->mm_txnid > meta->mm_txnid) + *meta = *env->me_metas[i]; + p = (MDB_page *)((char *)p + env->me_psize); + } + return 0; + } + /* We don't know the page size yet, so use a minimum value. * Read both meta pages so we can use the latest one. */ @@ -4152,6 +4179,18 @@ mdb_env_init_meta(MDB_env *env, MDB_meta *meta) psize = env->me_psize; + if ((env->me_flags & (MDB_RAWPART|MDB_WRITEMAP)) == (MDB_RAWPART|MDB_WRITEMAP)) { + p = (MDB_page *)env->me_map; + p->mp_pgno = 0; + p->mp_flags = P_META; + *(MDB_meta *)METADATA(p) = *meta; + q = (MDB_page *)((char *)p + psize); + q->mp_pgno = 1; + q->mp_flags = P_META; + *(MDB_meta *)METADATA(q) = *meta; + return 0; + } + p = calloc(NUM_METAS, psize); if (!p) return ENOMEM; @@ -5460,8 +5499,11 @@ mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode if (rc) return ErrCode(); flags &= ~MDB_RAWPART; - if (S_ISBLK(st.st_mode)) + if (S_ISBLK(st.st_mode)) { flags |= MDB_RAWPART | MDB_NOSUBDIR; + if (!env->me_mapsize) + env->me_mapsize = DEFAULT_MAPSIZE; + } } #endif flags |= MDB_ENV_ACTIVE; /* tell mdb_env_close0() to clean up */ -- cgit v1.2.3 From b46a60e3907c597b8b4b272eca357d38534f5e40 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sun, 11 Oct 2020 01:32:30 +0100 Subject: Fix rawpart flag collision --- external/db_drivers/liblmdb/mdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'external') diff --git a/external/db_drivers/liblmdb/mdb.c b/external/db_drivers/liblmdb/mdb.c index 52ad844e9..c30a8e52a 100644 --- a/external/db_drivers/liblmdb/mdb.c +++ b/external/db_drivers/liblmdb/mdb.c @@ -1467,14 +1467,14 @@ struct MDB_env { #endif /** Failed to update the meta page. Probably an I/O error. */ #define MDB_FATAL_ERROR 0x80000000U + /** using a raw block device */ +#define MDB_RAWPART 0x40000000U /** Some fields are initialized. */ #define MDB_ENV_ACTIVE 0x20000000U /** me_txkey is set */ #define MDB_ENV_TXKEY 0x10000000U /** fdatasync is unreliable */ #define MDB_FSYNCONLY 0x08000000U - /** using a raw block device */ -#define MDB_RAWPART 0x04000000U uint32_t me_flags; /**< @ref mdb_env */ unsigned int me_psize; /**< DB page size, inited from me_os_psize */ unsigned int me_os_psize; /**< OS page size, from #GET_PAGESIZE */ -- cgit v1.2.3 From 493577a6cd016ee56465f5adb8e1dc8f10f2daa5 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Wed, 7 Jul 2021 12:26:18 +0100 Subject: Silence spurious fallthru warning --- external/db_drivers/liblmdb/mdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'external') diff --git a/external/db_drivers/liblmdb/mdb.c b/external/db_drivers/liblmdb/mdb.c index c30a8e52a..f29a75de8 100644 --- a/external/db_drivers/liblmdb/mdb.c +++ b/external/db_drivers/liblmdb/mdb.c @@ -7725,7 +7725,7 @@ more: offset *= 4; /* space for 4 more */ break; } - /* FALLTHRU: Big enough MDB_DUPFIXED sub-page */ + /* FALLTHRU *//* Big enough MDB_DUPFIXED sub-page */ case MDB_CURRENT: fp->mp_flags |= P_DIRTY; COPY_PGNO(fp->mp_pgno, mp->mp_pgno); -- cgit v1.2.3 From ade464a5a0adaa166171f803078e9ac31b99bb06 Mon Sep 17 00:00:00 2001 From: Kris Zyp Date: Mon, 2 Nov 2020 20:33:09 +0000 Subject: ITS#9385 fix using MDB_NOSUBDIR with nonexistent file --- external/db_drivers/liblmdb/mdb.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'external') diff --git a/external/db_drivers/liblmdb/mdb.c b/external/db_drivers/liblmdb/mdb.c index f29a75de8..bf60c7013 100644 --- a/external/db_drivers/liblmdb/mdb.c +++ b/external/db_drivers/liblmdb/mdb.c @@ -5495,11 +5495,8 @@ mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode #ifndef _WIN32 { struct stat st; - rc = stat(path, &st); - if (rc) - return ErrCode(); flags &= ~MDB_RAWPART; - if (S_ISBLK(st.st_mode)) { + if (!stat(path, &st) && (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode))) { flags |= MDB_RAWPART | MDB_NOSUBDIR; if (!env->me_mapsize) env->me_mapsize = DEFAULT_MAPSIZE; -- cgit v1.2.3