From 3e0c7758ef80a929120bb58a7cf6af4da62fa07c Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Wed, 26 May 2021 20:15:48 +0300 Subject: [PATCH] mdbx: fallback to non-OFD locks after `EINVAL`. Related to https://github.com/erthink/libmdbx/issues/97 --- src/lck-posix.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/lck-posix.c b/src/lck-posix.c index cdf3363b..2fd3bc69 100644 --- a/src/lck-posix.c +++ b/src/lck-posix.c @@ -198,6 +198,22 @@ static int lck_op(mdbx_filehandle_t fd, int cmd, int lck, off_t offset, return MDBX_SUCCESS; } rc = errno; +#if MDBX_USE_OFDLOCKS + if (rc == EINVAL && + (cmd == F_OFD_SETLK || cmd == F_OFD_SETLKW || cmd == F_OFD_GETLK)) { + /* fallback to non-OFD locks */ + if (cmd == F_OFD_SETLK) + cmd = F_SETLK; + else if (cmd == F_OFD_SETLKW) + cmd = F_SETLKW; + else + cmd = F_GETLK; + op_setlk = F_SETLK; + op_setlkw = F_SETLKW; + op_getlk = F_GETLK; + continue; + } +#endif /* MDBX_USE_OFDLOCKS */ if (rc != EINTR || cmd == op_setlkw) { mdbx_assert(nullptr, MDBX_IS_ERROR(rc)); return rc;