Ignore:
Timestamp:
Nov 25, 2013, 4:35:16 PM (12 years ago)
Author:
Silvan Scherrer
Message:

Samba 3.6: use fcntl and friends for locking

File:
1 edited

Legend:

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

    r752 r834  
    9494        // YD we must upgrade read locks to write locks (exclusive), otherwise
    9595        // the owner (us) is not allowed to write to the file (different from unix)
    96         TDB_LOG((tdb, TDB_DEBUG_TRACE,"unlocking at %d len=%d before writing.\n", off, len));
    97         tdb_brunlock( tdb, F_RDLCK, off, len);
    9896        // if a wider previous lock is in effect, we cannot write lock our segment
    9997        // (e.g. a lock_upgrade locks all the file), so we hope the previous lock
    10098        // is a write lock: do not wait for lock.
    101         tdb_brlock( tdb, F_WRLCK, off, len, F_SETLK);
     99        int upgradeLockRC = tdb_brlock( tdb, F_WRLCK, off, len, F_SETLK);
     100        TDB_LOG((tdb, TDB_DEBUG_TRACE,"upgrading lock at %d len=%d "
     101                "before writing %s (rc=%d).\n", off, len,
     102                 upgradeLockRC ? "was successfull":"failed", upgradeLockRC));
    102103#endif
    103 
    104104        if (tdb->map_ptr) {
    105105                memcpy(off + (char *)tdb->map_ptr, buf, len);
     
    127127                                 "write %d bytes at %d in two attempts\n",
    128128                                 len, off));
    129 #ifdef __OS2__ // remove our lock
    130                         tdb_brunlock( tdb, F_WRLCK, off, len);
     129#ifdef __OS2__ // remove our lock, if upgrade succeded
     130                        if (upgradeLockRC == 0)
     131                                tdb_brunlock( tdb, F_WRLCK, off, len);
    131132#endif
    132133                        return -1;
    133134                }
    134135        }
    135 #ifdef __OS2__ // remove our lock
    136                         tdb_brunlock( tdb, F_WRLCK, off, len);
     136#ifdef __OS2__ // remove our lock, if upgrade succeded
     137        if (upgradeLockRC == 0)
     138                tdb_brunlock( tdb, F_WRLCK, off, len);
    137139#endif
    138140        return 0;
Note: See TracChangeset for help on using the changeset viewer.