More RAWPART support

Use mmap to read and initialize the meta pages, raw device
may not support read/write syscalls.
mdb.master3
Howard Chu 7 years ago
parent 5c0dda76c9
commit a7df9e63a5
  1. 40
      libraries/liblmdb/mdb.c

@ -4415,6 +4415,8 @@ fail:
return rc; return rc;
} }
static int ESECT mdb_env_map(MDB_env *env, void *addr);
/** Read the environment parameters of a DB environment before /** Read the environment parameters of a DB environment before
* mapping it into memory. * mapping it into memory.
* @param[in] env the environment handle * @param[in] env the environment handle
@ -4431,6 +4433,27 @@ mdb_env_read_header(MDB_env *env, int prev, MDB_meta *meta)
int i, rc, off; int i, rc, off;
enum { Size = sizeof(pbuf) }; 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);
p = (MDB_page *)env->me_map;
for (i=0; i<NUM_METAS; i++) {
if (!F_ISSET(p->mp_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. /* We don't know the page size yet, so use a minimum value.
* Read both meta pages so we can use the latest one. * Read both meta pages so we can use the latest one.
*/ */
@ -4526,6 +4549,18 @@ mdb_env_init_meta(MDB_env *env, MDB_meta *meta)
psize = env->me_psize; 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); p = calloc(NUM_METAS, psize);
if (!p) if (!p)
return ENOMEM; return ENOMEM;
@ -4800,6 +4835,8 @@ mdb_env_map(MDB_env *env, void *addr)
#else /* !_WIN32 */ #else /* !_WIN32 */
int mmap_flags = MAP_SHARED; int mmap_flags = MAP_SHARED;
int prot = PROT_READ; int prot = PROT_READ;
if (flags & MDB_WRITEMAP)
prot |= PROT_WRITE;
#ifdef MAP_NOSYNC /* Used on FreeBSD */ #ifdef MAP_NOSYNC /* Used on FreeBSD */
if (flags & MDB_NOSYNC) if (flags & MDB_NOSYNC)
mmap_flags |= MAP_NOSYNC; mmap_flags |= MAP_NOSYNC;
@ -4815,7 +4852,6 @@ mdb_env_map(MDB_env *env, void *addr)
} else } else
{ {
if (flags & MDB_WRITEMAP) { if (flags & MDB_WRITEMAP) {
prot |= PROT_WRITE;
if (!(flags & MDB_RAWPART) && ftruncate(env->me_fd, env->me_mapsize) < 0) if (!(flags & MDB_RAWPART) && ftruncate(env->me_fd, env->me_mapsize) < 0)
return ErrCode(); return ErrCode();
} }
@ -5957,7 +5993,7 @@ mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode
if (rc) if (rc)
return ErrCode(); return ErrCode();
flags &= ~MDB_RAWPART; flags &= ~MDB_RAWPART;
if (S_ISBLK(st.st_mode)) if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode))
flags |= MDB_RAWPART | MDB_NOSUBDIR; flags |= MDB_RAWPART | MDB_NOSUBDIR;
} }
#endif #endif

Loading…
Cancel
Save