Changeset 840


Ignore:
Timestamp:
Feb 4, 2014, 4:58:40 PM (12 years ago)
Author:
Silvan Scherrer
Message:

Samba Server 3.6: adjust locking code

Location:
trunk/server/lib/tdb/common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server/lib/tdb/common/io.c

    r835 r840  
    9292
    9393#ifdef __OS2__
    94         // YD we must upgrade read locks to write locks (exclusive), otherwise
     94        // YD we must upgrade read locks to write locks (exclusive), as otherwise
    9595        // the owner (us) is not allowed to write to the file (different from unix)
    9696        // if a wider previous lock is in effect, we cannot write lock our segment
    9797        // (e.g. a lock_upgrade locks all the file), so we hope the previous lock
    9898        // is a write lock: do not wait for lock.
    99         int upgradeLockRC = tdb_brlock( tdb, F_WRLCK, off, len, F_SETLK);
     99        // so this is what we try here:
     100        // 1. add a write lock and see if it works
     101        // 2. if the write lock wasn't set, we try to unlock the segment
     102        //    first and add the write lock afterwards
     103        int upgradeLockRC = tdb_brlock(tdb, F_WRLCK, off, len, TDB_LOCK_NOWAIT);
     104        if (upgradeLockRC != 0) {
     105                tdb_brunlock(tdb, F_RDLCK, off, len);
     106                int upgradeLockRC = tdb_brlock(tdb, F_WRLCK, off, len, TDB_LOCK_NOWAIT);
     107        }
    100108        TDB_LOG((tdb, TDB_DEBUG_TRACE,"upgrading lock at %d len=%d "
    101109                "before writing %s (rc=%d).\n", off, len,
  • trunk/server/lib/tdb/common/lock.c

    r834 r840  
    3434
    3535static int fcntl_lock(struct tdb_context *tdb,
    36                       int rw, off_t off, off_t len, bool waitflag)
     36                      int rw, tdb_off_t off, size_t len, bool waitflag)
    3737{
    3838        struct flock fl;
     
    4848        fl.l_pid = 0;
    4949
     50#ifdef __OS2__
     51        int cmd = 0;
     52        if (waitflag)
     53                cmd = F_SETLKW;
     54        else
     55                cmd = F_SETLK;
     56
     57        int rc = fcntl(tdb->fd, cmd, &fl);
     58        // if the first lock doesn't work and it's a complete lock,
     59        // we split it in 2 parts. first hash size*4 and then the rest
     60        if (rc != 0 && off == FREELIST_TOP && len == 0) {
     61                fl.l_len = tdb->header.hash_size * 4;
     62                rc = fcntl(tdb->fd, cmd, &fl);
     63                if (rc == 0) {
     64                        fl.l_start = off + tdb->header.hash_size * 4;
     65                        fl.l_len = LONG_MAX;
     66                        rc = fcntl(tdb->fd, cmd, &fl);
     67                }
     68        }
     69        return rc;
     70#else
    5071        if (waitflag)
    5172                return fcntl(tdb->fd, F_SETLKW, &fl);
    5273        else
    5374                return fcntl(tdb->fd, F_SETLK, &fl);
    54 }
    55 
    56 static int fcntl_unlock(struct tdb_context *tdb, int rw, off_t off, off_t len)
     75#endif
     76}
     77
     78static int fcntl_unlock(struct tdb_context *tdb, int rw, tdb_off_t off, size_t len)
    5779{
    5880        struct flock fl;
     
    248270        while (count--) {
    249271                struct timeval tv;
     272#ifdef __OS2__
     273                // we need to remove locks, as upgrade doesn't work
     274                tdb_brunlock(tdb, F_RDLCK, FREELIST_TOP, 0);
     275#endif
    250276                if (tdb_brlock(tdb, F_WRLCK, FREELIST_TOP, 0,
    251277                               TDB_LOCK_WAIT|TDB_LOCK_PROBE) == 0) {
Note: See TracChangeset for help on using the changeset viewer.