mdbx: portability fixes for SunOS/Solaris/OpenIndiana.

Change-Id: I0442367e798903598d706c65b536a127ca982fce
This commit is contained in:
Leonid Yuriev 2019-11-09 10:50:43 +03:00
parent bb2d2877c4
commit 5af02290e6
9 changed files with 80 additions and 57 deletions

9
mdbx.h
View File

@ -769,7 +769,16 @@ struct iovec {
#define HAVE_STRUCT_IOVEC
#endif /* HAVE_STRUCT_IOVEC */
#if defined(__sun) || defined(__SVR4) || defined(__svr4__)
/* The `iov_len` is signed on Sun/Solaris.
* So define custom MDBX_val to avoid a lot of warings. */
typedef struct MDBX_val {
void *iov_base /* pointer to some data */;
size_t iov_len /* the length of data in bytes */;
} MDBX_val;
#else
typedef struct iovec MDBX_val;
#endif
/* The maximum size of a data item.
* MDBX only store a 32 bit value for node sizes. */

View File

@ -3479,8 +3479,8 @@ static int __cold mdbx_set_readahead(MDBX_env *env, const size_t offset,
if (unlikely(madvise(env->me_map + offset, length, MADV_WILLNEED) != 0))
return errno;
#elif defined(POSIX_MADV_WILLNEED)
rc = posix_madvise(env->me_map + offset, length, POSIX_MADV_WILLNEED);
if (unlikely(rc != 0))
int err = posix_madvise(env->me_map + offset, length, POSIX_MADV_WILLNEED);
if (unlikely(err != 0))
return errno;
#elif defined(_WIN32) || defined(_WIN64)
if (mdbx_PrefetchVirtualMemory) {
@ -6329,7 +6329,7 @@ static int mdbx_page_flush(MDBX_txn *txn, const unsigned keep) {
}
iov_off = pgno2bytes(env, dp->mp_pgno);
}
iov[iov_items].iov_base = dp;
iov[iov_items].iov_base = (void *)dp;
iov[iov_items].iov_len = size;
iov_items += 1;
iov_bytes += size;
@ -7428,7 +7428,8 @@ static void __cold mdbx_setup_pagesize(MDBX_env *env, const size_t pagesize) {
STATIC_ASSERT(mdbx_nodemax(MIN_PAGESIZE) > 42);
STATIC_ASSERT(mdbx_nodemax(MAX_PAGESIZE) < UINT16_MAX);
const intptr_t nodemax = mdbx_nodemax(pagesize);
mdbx_ensure(env, nodemax > 42 && nodemax < UINT16_MAX && nodemax % 2 == 0);
mdbx_ensure(env,
nodemax > 42 && nodemax < (int)UINT16_MAX && nodemax % 2 == 0);
env->me_nodemax = (unsigned)nodemax;
STATIC_ASSERT(mdbx_maxkey(MIN_PAGESIZE) > 42);
@ -8076,9 +8077,9 @@ static int __cold mdbx_setup_dxb(MDBX_env *env, const int lck_rc) {
env->me_dxb_mmap.current - used_aligned2os_bytes,
MADV_DONTNEED);
#elif defined(POSIX_MADV_DONTNEED)
(void)madvise(env->me_map + used_aligned2os_bytes,
env->me_dxb_mmap.current - used_aligned2os_bytes,
POSIX_MADV_DONTNEED);
(void)posix_madvise(env->me_map + used_aligned2os_bytes,
env->me_dxb_mmap.current - used_aligned2os_bytes,
POSIX_MADV_DONTNEED);
#elif defined(POSIX_FADV_DONTNEED)
(void)posix_fadvise(env->me_fd, used_aligned2os_bytes,
env->me_dxb_mmap.current - used_aligned2os_bytes,
@ -8094,8 +8095,8 @@ static int __cold mdbx_setup_dxb(MDBX_env *env, const int lck_rc) {
const bool readahead = (env->me_flags & MDBX_NORDAHEAD) == 0 &&
mdbx_is_readahead_reasonable(env->me_dxb_mmap.current,
0) == MDBX_RESULT_TRUE;
err = mdbx_set_readahead(env, 0, env->me_dxb_mmap.current, readahead);
if (err != MDBX_SUCCESS)
err = mdbx_set_readahead(env, 0, used_bytes, readahead);
if (err != MDBX_SUCCESS && lck_rc == /* lck exclusive */ MDBX_RESULT_TRUE)
return err;
mdbx_assert(env, used_bytes >= pgno2bytes(env, NUM_METAS) &&
@ -13025,7 +13026,7 @@ static int mdbx_page_split(MDBX_cursor *mc, const MDBX_val *newkey,
rp->mp_lower += sizeof(indx_t);
mdbx_cassert(mc, rp->mp_upper >= ksize - sizeof(indx_t));
rp->mp_upper -= (indx_t)(ksize - sizeof(indx_t));
mdbx_cassert(mc, x <= UINT16_MAX);
mdbx_cassert(mc, x <= (int)UINT16_MAX);
mc->mc_ki[mc->mc_top] = (indx_t)x;
}
} else {

View File

@ -233,7 +233,8 @@
#ifndef MDBX_USE_OFDLOCKS
#if defined(F_OFD_SETLK) && defined(F_OFD_SETLKW) && defined(F_OFD_GETLK) && \
!defined(MDBX_SAFE4QEMU)
!defined(MDBX_SAFE4QEMU) && \
!defined(__sun) /* OFD-lock are broken on Solaris */
#define MDBX_USE_OFDLOCKS 1
#else
#define MDBX_USE_OFDLOCKS 0

View File

@ -179,6 +179,11 @@ __extern_C void __assert_rtn(const char *function, const char *file, int line,
#define __assert_fail(assertion, file, line, function) \
__assert_rtn(function, file, line, assertion)
#elif defined(__sun) || defined(__SVR4) || defined(__svr4__)
__extern_C void __assert_c99(const char *assection, const char *file, int line,
const char *function) __noreturn;
#define __assert_fail(assertion, file, line, function) \
__assert_c99(assertion, file, line, function)
#elif defined(__OpenBSD__)
__extern_C __dead void __assert2(const char *file, int line,
const char *function,
@ -1070,24 +1075,27 @@ static int mdbx_check_fs_local(mdbx_filehandle_t handle, int flags) {
const unsigned type = 0;
const char *const name = statvfs_info.f_fstypename;
const size_t name_len = VFS_NAMELEN;
#elif defined(_AIX) || defined(__OS400__) || defined(FSTYPSZ) || \
defined(_FSTYPSZ)
#elif defined(_AIX) || defined(__OS400__)
const char *const name = statvfs_info.f_basetype;
const size_t name_len = sizeof(statvfs_info.f_basetype);
struct stat st;
if (fstat(handle, &st))
return errno;
const unsigned type = st.st_vfstype;
if ((st.st_flag & FS_REMOTE) != 0 && !(flags & MDBX_EXCLUSIVE))
return MDBX_EREMOTE;
#elif defined(FSTYPSZ) || defined(_FSTYPSZ)
const unsigned type = 0;
const char *const name = statfs_info.f_basetype;
const size_t name_len = sizeof(statfs_info.f_basetype);
const char *const name = statvfs_info.f_basetype;
const size_t name_len = sizeof(statvfs_info.f_basetype);
#elif defined(__sun) || defined(__SVR4) || defined(__svr4__) || \
defined(ST_FSTYPSZ) || defined(_ST_FSTYPSZ)
const unsigned type = 0;
#if defined(_ST_FSTYPSZ) || defined(_ST_FSTYPSZ)
struct stat stat_info;
if (fstat(handle, &stat_info))
struct stat st;
if (fstat(handle, &st))
return errno;
const char *const name = stat_info.st_fstype;
const char *const name = st.st_fstype;
const size_t name_len = strlen(name);
#else
const char *const name = "";
const size_t name_len = 0;
#endif
#else
struct statfs statfs_info;
if (fstatfs(handle, &statfs_info))
@ -1135,10 +1143,10 @@ static int mdbx_check_fs_local(mdbx_filehandle_t handle, int flags) {
#endif /* ST/MNT_LOCAL */
#ifdef ST_EXPORTED
if (st_flags & ST_EXPORTED)
if ((st_flags & ST_EXPORTED) != 0 && !(flags & MDBX_RDONLY))
return MDBX_EREMOTE;
#elif defined(MNT_EXPORTED)
if (mnt_flags & MNT_EXPORTED)
if ((mnt_flags & MNT_EXPORTED) != 0 && !(flags & MDBX_RDONLY))
return MDBX_EREMOTE;
#endif /* ST/MNT_EXPORTED */
@ -1190,7 +1198,7 @@ MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map,
map->current = size;
#endif
} else {
uint64_t filesize;
uint64_t filesize = 0;
err = mdbx_filesize(map->fd, &filesize);
if (err != MDBX_SUCCESS)
return err;
@ -1451,7 +1459,7 @@ retry_mapview:;
map->limit = ViewSize;
#else
uint64_t filesize;
uint64_t filesize = 0;
int rc = mdbx_filesize(map->fd, &filesize);
if (rc != MDBX_SUCCESS)
return rc;
@ -1749,7 +1757,7 @@ static __cold __maybe_unused bool bootid_parse_uuid(bin128_t *s, const void *p,
__cold MDBX_INTERNAL_FUNC bin128_t mdbx_osal_bootid(void) {
bin128_t bin = {{0, 0}};
bool got_machineid = false, got_bootime = false, got_bootseq = false;
bool got_machineid = false, got_boottime = false, got_bootseq = false;
#if defined(__linux__) || defined(__gnu_linux__)
{
@ -1790,7 +1798,7 @@ __cold MDBX_INTERNAL_FUNC bin128_t mdbx_osal_bootid(void) {
len = sizeof(boottime);
if (!sysctlbyname("kern.boottime", &boottime, &len, nullptr, 0) &&
len == sizeof(boottime) && boottime.tv_sec)
got_bootime = true;
got_boottime = true;
}
#endif /* Apple/Darwin */
@ -1878,7 +1886,7 @@ __cold MDBX_INTERNAL_FUNC bin128_t mdbx_osal_bootid(void) {
&len) == ERROR_SUCCESS &&
len >= sizeof(buf.BaseTime) && buf.BaseTime) {
bootid_collect(&bin, &buf.BaseTime, len);
got_bootime = true;
got_boottime = true;
}
/* BootTime from SYSTEM_TIMEOFDAY_INFORMATION */
@ -1891,14 +1899,14 @@ __cold MDBX_INTERNAL_FUNC bin128_t mdbx_osal_bootid(void) {
buf.SysTimeOfDayInfoHacked.BootTime.QuadPart) {
bootid_collect(&bin, &buf.SysTimeOfDayInfoHacked.BootTime,
sizeof(buf.SysTimeOfDayInfoHacked.BootTime));
got_bootime = true;
got_boottime = true;
}
if (!got_bootime) {
if (!got_boottime) {
uint64_t boottime = windows_bootime();
if (boottime) {
bootid_collect(&bin, &boottime, sizeof(boottime));
got_bootime = true;
got_boottime = true;
}
}
}
@ -1962,7 +1970,7 @@ __cold MDBX_INTERNAL_FUNC bin128_t mdbx_osal_bootid(void) {
/*--------------------------------------------------------------------------*/
#if defined(CTL_KERN) && defined(KERN_BOOTTIME)
if (!got_bootime) {
if (!got_boottime) {
static const int mib[] = {CTL_KERN, KERN_BOOTTIME};
struct timeval boottime;
size_t len = sizeof(boottime);
@ -1974,13 +1982,13 @@ __cold MDBX_INTERNAL_FUNC bin128_t mdbx_osal_bootid(void) {
ARRAY_LENGTH(mib), &boottime, &len, NULL, 0) == 0 &&
len == sizeof(boottime) && boottime.tv_sec) {
bootid_collect(&bin, &boottime, len);
got_bootime = true;
got_boottime = true;
}
}
#endif /* CTL_KERN && KERN_BOOTTIME */
#if defined(__sun) || defined(__SVR4) || defined(__svr4__)
if (!got_bootime) {
if (!got_boottime) {
kstat_ctl_t *kc = kstat_open();
if (kc) {
kstat_t *kp = kstat_lookup(kc, "unix", 0, "system_misc");
@ -2005,13 +2013,13 @@ __cold MDBX_INTERNAL_FUNC bin128_t mdbx_osal_bootid(void) {
#endif /* SunOS / Solaris */
#if _XOPEN_SOURCE_EXTENDED && defined(BOOT_TIME)
if (!got_bootime) {
if (!got_boottime) {
setutxent();
const struct utmpx id = {.ut_type = BOOT_TIME};
const struct utmpx *entry = getutxid(&id);
if (entry) {
bootid_collect(&bin, entry, sizeof(*entry));
got_bootime = true;
got_boottime = true;
while (unlikely((entry = getutxid(&id)) != nullptr)) {
/* have multiple reboot records, assuming we can distinguish next
* bootsession even if RTC is wrong or absent */
@ -2024,7 +2032,7 @@ __cold MDBX_INTERNAL_FUNC bin128_t mdbx_osal_bootid(void) {
#endif /* _XOPEN_SOURCE_EXTENDED && BOOT_TIME */
if (!got_bootseq) {
if (!got_bootime || !MDBX_TRUST_RTC)
if (!got_boottime || !MDBX_TRUST_RTC)
goto lack;
#if defined(_WIN32) || defined(_WIN64)

View File

@ -38,6 +38,8 @@
!defined(MDBX_TOOLS)
#define _NO_CRT_STDIO_INLINE
#endif
#elif !defined(_POSIX_C_SOURCE)
#define _POSIX_C_SOURCE 200809L
#endif /* Windows */
/*----------------------------------------------------------------------------*/
@ -87,13 +89,6 @@
#include <sys/vmmeter.h>
#else
#include <malloc.h>
#ifndef _POSIX_C_SOURCE
#ifdef _POSIX_SOURCE
#define _POSIX_C_SOURCE 1
#else
#define _POSIX_C_SOURCE 0
#endif
#endif
#endif /* !xBSD */
#if defined(__FreeBSD__) || __has_include(<malloc_np.h>)

View File

@ -133,9 +133,9 @@ void output_nocheckloglevel_ap(const logging::loglevel priority,
last = stdout;
fprintf(last,
"[ %02d%02d%02d-%02d:%02d:%02d.%06d_%05u %-10s %.4s ] %s" /* TODO */,
"[ %02d%02d%02d-%02d:%02d:%02d.%06d_%05lu %-10s %.4s ] %s" /* TODO */,
tm.tm_year - 100, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min,
tm.tm_sec, chrono::fractional2us(now.fractional), osal_getpid(),
tm.tm_sec, chrono::fractional2us(now.fractional), (long)osal_getpid(),
prefix.c_str(), level2str(priority), suffix.c_str());
va_list ones;
@ -169,8 +169,8 @@ void output_nocheckloglevel_ap(const logging::loglevel priority,
if (same_or_higher(priority, error)) {
if (last != stderr) {
fprintf(stderr, "[ %05u %-10s %.4s ] %s", osal_getpid(), prefix.c_str(),
level2str(priority), suffix.c_str());
fprintf(stderr, "[ %05lu %-10s %.4s ] %s", (long)osal_getpid(),
prefix.c_str(), level2str(priority), suffix.c_str());
vfprintf(stderr, format, ones);
if (end == '\n')
fflush(stderr);

View File

@ -565,8 +565,8 @@ int main(int argc, char *const argv[]) {
if (!actor)
continue;
log_verbose("actor #%u, id %d, pid %u: %s\n", actor->actor_id,
actor->space_id, pid, status2str(status));
log_verbose("actor #%u, id %d, pid %ld: %s\n", actor->actor_id,
actor->space_id, (long)pid, status2str(status));
if (status > as_running) {
left -= 1;
if (status != as_successful) {
@ -603,10 +603,18 @@ int main(int argc, char *const argv[]) {
#if defined(__linux__) || defined(__gnu_linux__) || defined(__FreeBSD__) || \
defined(__NetBSD__) || defined(__OpenBSD__) || defined(__BSD__) || \
defined(__bsdi__) || defined(__DragonFly__) || defined(__APPLE__) || \
defined(__MACH__)
defined(__MACH__) || defined(__sun)
log_notice("%6s: read %ld, write %ld", "IOPs", spent.ru_inblock,
spent.ru_oublock);
log_notice("%6s: %ld Kb", "RAM", spent.ru_maxrss);
if (spent.ru_maxrss > 0)
log_notice("%6s: %ld Kb", "RAM",
spent.ru_maxrss
#if defined(__sun)
* getpagesize() / 1024u
#elif defined(__APPLE__)
/ 1024u
#endif
);
log_notice("%6s: reclaims %ld, faults %ld, swaps %ld", "Paging",
spent.ru_minflt, spent.ru_majflt, spent.ru_nswap);
#endif /* Linux */

View File

@ -298,7 +298,8 @@ int osal_actor_start(const actor_config &config, mdbx_pid_t &pid) {
if (pid < 0)
return errno;
log_trace("osal_actor_start: fork pid %i for %u", pid, config.actor_id);
log_trace("osal_actor_start: fork pid %ld for %u", (long)pid,
config.actor_id);
childs[pid] = as_running;
return 0;
}

View File

@ -85,9 +85,9 @@ int testcase::oom_callback(MDBX_env *env, mdbx_pid_t pid, mdbx_tid_t tid,
testcase *self = (testcase *)mdbx_env_get_userctx(env);
if (retry == 0)
log_notice("oom_callback: waitfor pid %u, thread %" PRIuPTR
log_notice("oom_callback: waitfor pid %lu, thread %" PRIuPTR
", txn #%" PRIu64 ", gap %d, scape %zu",
pid, (size_t)tid, txn, gap, space);
(long)pid, (size_t)tid, txn, gap, space);
if (self->should_continue(true)) {
osal_yield();