feat: add Linux Open File Description (OFD) locking patch (sqlite#255)
Summary
Applies Open File Description (OFD) locking on Linux using per-connection F_OFD_SETLK read locking.
Background & Motivation
Under standard POSIX advisory record locks (F_SETLK / F_SETLKW), locks are scoped to (process, inode) pairs. While SQLite internally tracks and defers closing descriptors via unixInodeInfo.pUnused to prevent dropping its own locks, any external code or third-party Go library within the same process calling os.Open / os.Close on the database file causes the Linux kernel to silently drop all POSIX locks held by SQLite on that inode.
With Linux Open File Description locks (F_OFD_SETLK, F_OFD_SETLKW), locks are associated with the underlying open file description rather than the process-inode pair, preventing external close() operations from stripping SQLite's locks.
Implementation Details (Per-Connection OFD Locking)
- Replaces
F_SETLK/F_SETLKWwithF_OFD_SETLK/F_OFD_SETLKWon Linux. - In
unixLock()andposixUnlock(), each connection acquires and releases its own kernel OFD read lock directly onpFile->h. - If running on an older kernel or filesystem mount where OFD returns
EINVAL,osFcntlOfd()automatically performs a one-time fallback to standard POSIX locking with classic in-process refcounting.
Related Merge Requests & Issues
- Prerequisite
libcexport of Linux OFD lock constants: cznic/libc!33 (Merged) - Companion test suite: cznic/sqlite!136
- Main tracking issue: cznic/sqlite#255