Preliminary raw partition support

Currently requires using new MDB_RAWPART flag on env_open.
Should we try to make it automatic instead? Check any path
starting with /dev/ to see if it's a block device?
rawpart
Howard Chu 9 years ago
parent e46d78b7b0
commit 8f0c9e6d39
  1. 2
      libraries/liblmdb/lmdb.h
  2. 16
      libraries/liblmdb/mdb.c

@ -311,6 +311,8 @@ typedef void (MDB_rel_func)(MDB_val *item, void *oldptr, void *newptr, void *rel
#define MDB_NORDAHEAD 0x800000 #define MDB_NORDAHEAD 0x800000
/** don't initialize malloc'd memory before writing to datafile */ /** don't initialize malloc'd memory before writing to datafile */
#define MDB_NOMEMINIT 0x1000000 #define MDB_NOMEMINIT 0x1000000
/** use a raw partition */
#define MDB_RAWPART 0x2000000
/** @} */ /** @} */
/** @defgroup mdb_dbi_open Database Flags /** @defgroup mdb_dbi_open Database Flags

@ -3904,6 +3904,8 @@ mdb_env_read_header(MDB_env *env, MDB_meta *meta)
p = (MDB_page *)&pbuf; p = (MDB_page *)&pbuf;
if (!F_ISSET(p->mp_flags, P_META)) { if (!F_ISSET(p->mp_flags, P_META)) {
if (env->me_flags & MDB_RAWPART)
return ENOENT;
DPRINTF(("page %"Y"u not a meta page", p->mp_pgno)); DPRINTF(("page %"Y"u not a meta page", p->mp_pgno));
return MDB_INVALID; return MDB_INVALID;
} }
@ -4229,7 +4231,7 @@ mdb_env_map(MDB_env *env, void *addr)
int prot = PROT_READ; int prot = PROT_READ;
if (flags & MDB_WRITEMAP) { if (flags & MDB_WRITEMAP) {
prot |= PROT_WRITE; 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(); return ErrCode();
} }
env->me_map = mmap(addr, env->me_mapsize, prot, MAP_SHARED, env->me_map = mmap(addr, env->me_mapsize, prot, MAP_SHARED,
@ -5054,7 +5056,7 @@ fail:
*/ */
#define CHANGEABLE (MDB_NOSYNC|MDB_NOMETASYNC|MDB_MAPASYNC|MDB_NOMEMINIT) #define CHANGEABLE (MDB_NOSYNC|MDB_NOMETASYNC|MDB_MAPASYNC|MDB_NOMEMINIT)
#define CHANGELESS (MDB_FIXEDMAP|MDB_NOSUBDIR|MDB_RDONLY| \ #define CHANGELESS (MDB_FIXEDMAP|MDB_NOSUBDIR|MDB_RDONLY| \
MDB_WRITEMAP|MDB_NOTLS|MDB_NOLOCK|MDB_NORDAHEAD) MDB_WRITEMAP|MDB_NOTLS|MDB_NOLOCK|MDB_NORDAHEAD|MDB_RAWPART)
#if VALID_FLAGS & PERSISTENT_FLAGS & (CHANGEABLE|CHANGELESS) #if VALID_FLAGS & PERSISTENT_FLAGS & (CHANGEABLE|CHANGELESS)
# error "Persistent DB flags & env flags overlap, but both go in mm_flags" # error "Persistent DB flags & env flags overlap, but both go in mm_flags"
@ -5086,6 +5088,8 @@ mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode
len = strlen(path); len = strlen(path);
if (flags & MDB_NOSUBDIR) { if (flags & MDB_NOSUBDIR) {
rc = len + sizeof(LOCKSUFF) + len + 1; rc = len + sizeof(LOCKSUFF) + len + 1;
} else if (flags & MDB_RAWPART) {
rc = len + sizeof(LOCKSUFF) + len + sizeof("/tmp");
} else { } else {
rc = len + sizeof(LOCKNAME) + len + sizeof(DATANAME); rc = len + sizeof(LOCKNAME) + len + sizeof(DATANAME);
} }
@ -5096,6 +5100,14 @@ mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode
dpath = lpath + len + sizeof(LOCKSUFF); dpath = lpath + len + sizeof(LOCKSUFF);
sprintf(lpath, "%s" LOCKSUFF, path); sprintf(lpath, "%s" LOCKSUFF, path);
strcpy(dpath, path); strcpy(dpath, path);
} else if (flags & MDB_RAWPART) {
char *ptr;
dpath = lpath + len + sizeof(LOCKSUFF) + sizeof("/tmp");
sprintf(lpath, "/tmp%s" LOCKSUFF, path);
strcpy(dpath, path);
ptr = lpath + sizeof("/tmp");
while ((ptr=strchr(ptr, '/')))
*ptr++ = '_';
} else { } else {
dpath = lpath + len + sizeof(LOCKNAME); dpath = lpath + len + sizeof(LOCKNAME);
sprintf(lpath, "%s" LOCKNAME, path); sprintf(lpath, "%s" LOCKNAME, path);

Loading…
Cancel
Save