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)

  1. Replaces F_SETLK / F_SETLKW with F_OFD_SETLK / F_OFD_SETLKW on Linux.
  2. In unixLock() and posixUnlock(), each connection acquires and releases its own kernel OFD read lock directly on pFile->h.
  3. 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.

Edited by Nathan Herring

Merge request reports

Loading
Loading