/ Check-in [d849ade3]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Miscellaneous cleanup of OFD logic. Add an #if 0 to disable the use of OFD logic, temporarily, until I can get it to actually work.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | ofd-locks
Files: files | file ages | folders
SHA3-256: d849ade396d2dda4ed18f8e44d19ab218f94ef41a76a99f937238253e716dc05
User & Date: drh 2018-06-19 17:19:46
Context
2018-06-19
19:01
OFD locks are now mostly working, but need additional tests. check-in: 4f1fb5c9 user: drh tags: ofd-locks
17:19
Miscellaneous cleanup of OFD logic. Add an #if 0 to disable the use of OFD logic, temporarily, until I can get it to actually work. check-in: d849ade3 user: drh tags: ofd-locks
13:45
Initial attempt to get SQLite working with OFD locks on Linux. The code here does not function correctly. This is an incremental check-in for a work in progress. check-in: 148f8dec user: drh tags: ofd-locks
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

   179    179   #define IS_LOCK_ERROR(x)  ((x != SQLITE_OK) && (x != SQLITE_BUSY))
   180    180   
   181    181   /*
   182    182   ** Are OFD locks supported?
   183    183   */
   184    184   #if defined(F_OFD_SETLK) && defined(F_OFD_GETLK)
   185    185   # define HAVE_OFD_LOCKS 1
          186  +# define UsesOfd(F)                ((F)->eGetLk==F_OFD_GETLK)
          187  +# define UsesOldStylePosixLocks(F) ((F)->eGetLk==F_GETLK)
   186    188   #else
   187    189   # define HAVE_OFD_LOCKS 0
          190  +# define UsesOfd(F)                0
          191  +# define UsesOldStylePosixLocks(F) 1
   188    192   # define F_OFD_SETLK 0    /* Fake value so we can use the identifier */
   189    193   # define F_OFD_GETLK 0    /* Fake value so we can use the identifier */
   190    194   #endif
   191    195   
   192    196   /* Forward references */
   193    197   typedef struct unixShm unixShm;               /* Connection shared memory */
   194    198   typedef struct unixShmNode unixShmNode;       /* Shared memory instance */
................................................................................
   760    764     char *zOpName, *zType;
   761    765     int s;
   762    766     int savedErrno;
   763    767     if( op==F_GETLK || op==F_OFD_GETLK ){
   764    768       zOpName = "GETLK";
   765    769     }else if( op==F_SETLK || op==F_OFD_SETLK ){
   766    770       zOpName = "SETLK";
          771  +#if HAVE_OFD_LOCKS
          772  +  }else if( op==F_OFD_GETLK ){
          773  +    zOpName = "OFD_GETLK";
          774  +  }else if( op==F_OFD_SETLK ){
          775  +    zOpName = "OFD_SETLK";
          776  +#endif
   767    777     }else{
   768    778       s = osFcntl(fd, op, p);
   769    779       sqlite3DebugPrintf("fcntl unknown %d %d %d\n", fd, op, s);
   770    780       return s;
   771    781     }
   772    782     if( p->l_type==F_RDLCK ){
   773    783       zType = "RDLCK";
................................................................................
   786    796        (int)p->l_pid, s);
   787    797     if( s==(-1)
   788    798      && (op==F_SETLK || op==F_OFD_SETLK)
   789    799      && (p->l_type==F_RDLCK || p->l_type==F_WRLCK)
   790    800     ){
   791    801       struct flock l2;
   792    802       l2 = *p;
   793         -    osFcntl(fd, F_GETLK, &l2);
          803  +    osFcntl(fd, op==F_SETLK ? F_GETLK : F_OFD_GETLK, &l2);
   794    804       if( l2.l_type==F_RDLCK ){
   795    805         zType = "RDLCK";
   796    806       }else if( l2.l_type==F_WRLCK ){
   797    807         zType = "WRLCK";
   798    808       }else if( l2.l_type==F_UNLCK ){
   799    809         zType = "UNLCK";
   800    810       }else{
................................................................................
  1698   1708     }
  1699   1709   
  1700   1710     /* If a SHARED lock is requested, and some thread using this PID already
  1701   1711     ** has a SHARED or RESERVED lock, then increment reference counts and
  1702   1712     ** return SQLITE_OK.
  1703   1713     */
  1704   1714     if( eFileLock==SHARED_LOCK
  1705         -   && pFile->eGetLk==F_GETLK
         1715  +   && UsesOldStylePosixLocks(pFile)
  1706   1716      && (pInode->eFileLock==SHARED_LOCK || pInode->eFileLock==RESERVED_LOCK)
  1707   1717     ){
  1708   1718       assert( eFileLock==SHARED_LOCK );
  1709   1719       assert( pFile->eFileLock==0 );
  1710   1720       assert( pInode->nShared>0 );
  1711   1721       pFile->eFileLock = SHARED_LOCK;
  1712   1722       pInode->nShared++;
  1713   1723       pInode->nLock++;
  1714   1724       goto end_lock;
  1715   1725     }
  1716         -
  1717   1726   
  1718   1727     /* A PENDING lock is needed before acquiring a SHARED lock and before
  1719   1728     ** acquiring an EXCLUSIVE lock.  For the SHARED lock, the PENDING will
  1720   1729     ** be released.
  1721   1730     */
  1722   1731     lock.l_len = 1L;
  1723   1732     lock.l_whence = SEEK_SET;
................................................................................
  5459   5468     /* No locking occurs in temporary files */
  5460   5469     assert( zFilename!=0 || (ctrlFlags & UNIXFILE_NOLOCK)!=0 );
  5461   5470   
  5462   5471     OSTRACE(("OPEN    %-3d %s\n", h, zFilename));
  5463   5472     pNew->h = h;
  5464   5473     pNew->eSetLk = F_SETLK;
  5465   5474     pNew->eGetLk = F_GETLK;
  5466         -#if HAVE_OFD_LOCKS
         5475  +#if HAVE_OFD_LOCKS && 0
  5467   5476     {
  5468   5477       struct flock lock;
  5469   5478       lock.l_whence = SEEK_SET;
  5470   5479       lock.l_start = RESERVED_BYTE;
  5471   5480       lock.l_len = 1;
  5472   5481       lock.l_type = F_WRLCK;
  5473   5482       lock.l_pid = 0;