Changeset 61


Ignore:
Timestamp:
Aug 20, 2007, 8:37:46 PM (13 years ago)
Author:
Yuri Dario
Message:

More changes for locking problems:

  • reopen semaphore handles for new processes;
  • remove locks done after using exclusive locks with semaphores;
  • more logging;
  • upgrade read locks to write (exclusive) locks before writing to file (this makes real

unlocks to fail, fixme);

Location:
trunk/samba/source/tdb/common
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/samba/source/tdb/common/io.c

    r1 r61  
    8888                return -1;
    8989
     90#ifdef __OS2__
     91        // YD we must upgrade read locks to write locks (exclusive), otherwise
     92        // the owner (us) is not allowed to write to the file (different from unix)
     93        TDB_LOG((tdb, TDB_DEBUG_TRACE,"unlocking at %d len=%d before writing.\n", off, len));
     94        tdb_brlock( tdb, off, F_UNLCK, F_SETLK, 0, 1);
     95        // if a wider previous lock is in effect, we cannot write lock our segment
     96        // (e.g. a lock_upgrade locks all the file), so we hope the previous lock
     97        // is a write lock: do not wait for lock.
     98        tdb_brlock( tdb, off, F_WRLCK, F_SETLK, 0, len);
     99#endif
     100
    90101        if (tdb->map_ptr) {
    91102                memcpy(off + (char *)tdb->map_ptr, buf, len);
     
    95106                TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_write failed at %d len=%d (%s)\n",
    96107                           off, len, strerror(errno)));
     108#ifdef __OS2__
     109                // remove our lock
     110                tdb_brlock( tdb, off, F_UNLCK, F_SETLK, 0, len);
     111#endif
    97112                return TDB_ERRCODE(TDB_ERR_IO, -1);
    98113        }
     114#ifdef __OS2__
     115        // remove our lock
     116        tdb_brlock( tdb, off, F_UNLCK, F_SETLK, 0, len);
     117#endif
    99118        return 0;
    100119}
  • trunk/samba/source/tdb/common/lock.c

    r45 r61  
    2929#include "tdb_private.h"
    3030
    31 #if 0 // for debugging...
    32 #include "tdb/tools/printf.c"
     31
     32#if 1 // for debugging...
    3333
    3434#if 0
     
    9595        }
    9696
     97        TDB_LOG((tdb, TDB_DEBUG_TRACE,"_mutex_brlock handle %d, offset %d\n", hSem, offset));
     98
    9799        if (lck_type == F_SETLKW)
    98100                ulTimeout = SEM_INDEFINITE_WAIT;
     
    120122
    121123        errno = EINVAL;
    122 #if 0
    123         debug_printf("_mutex_brlock pid %X, failed (fd=%d) at offset %d rw_type=%d lck_type=%d len=%d, rc=%d\n",
    124                  getpid(), tdb->fd, offset, rw_type, lck_type, (int)len, rc);
     124#if 1
     125        TDB_LOG(( tdb, TDB_DEBUG_ERROR, "_mutex_brlock pid %X, failed (fd=%d) at offset %d rw_type=%d lck_type=%d len=%d, rc=%d\n",
     126                 getpid(), tdb->fd, offset, rw_type, lck_type, (int)len, rc));
    125127#endif
    126128        return TDB_ERRCODE(TDB_ERR_LOCK, -1);
     
    149151        off_t       cbRange;
    150152
     153#if 1
     154        TDB_LOG((tdb, TDB_DEBUG_TRACE, "tdb_brlock pid %X, fd %d, lck_type %s, rw_type %s, offset %d, len %d\n",
     155                getpid(), tdb->fd, lock_type(lck_type), read_type(rw_type), offset, len));
     156#endif
     157       
    151158        switch( offset) {
    152159        case GLOBAL_LOCK:
    153160        case ACTIVE_LOCK:
    154161        case TRANSACTION_LOCK:
    155                 return _mutex_brlock( tdb, offset,
    156                 rw_type,  lck_type,  probe, len);
     162                return _mutex_brlock( tdb, offset, rw_type,  lck_type,  probe, len);
    157163        }
    158164
     
    166172        }
    167173
    168 #if 0
    169         debug_printf("tdb_brlock pid %X, fd %d, lck_type %s, rw_type %s, offset %d, len %d\n",
    170                 getpid(), tdb->fd, lock_type(lck_type), read_type(rw_type), offset, len);
    171 #endif
    172        
    173174        /* flags and order */
    174175        fAccess = 0; /* exclusive */
     
    199200#if 0
    200201        if (rc != NO_ERROR) {
    201                 debug_printf("tdb_brlock pid %X, fd %d, rc=%d FAILED\n",
    202                         getpid(), tdb->fd, rc);
     202                TDB_LOG(( tdb, TDB_DEBUG_TRACE, "tdb_brlock pid %X, fd %d, rc=%d FAILED\n",
     203                        getpid(), tdb->fd, rc));
    203204        }
    204205#endif
    205206        if (rc != NO_ERROR && lck_type == F_SETLKW) {
    206207#if 0
    207                 debug_printf("tdb_brlock pid %X, fd %d, rc=%d RETRY WAIT\n",
    208                         getpid(), tdb->fd, rc);
    209 #endif
    210                 int     count = 10;
     208                TDB_LOG(( tdb, TDB_DEBUG_TRACE, "tdb_brlock pid %X, fd %d, rc=%d RETRY WAIT\n",
     209                        getpid(), tdb->fd, rc));
     210#endif
     211                int     count = 20;
    211212                do {
    212                         rc = DosSetFileLocks(tdb->fd, &aflock[0], &aflock[1], 1000, fAccess);
     213                        rc = DosSetFileLocks(tdb->fd, &aflock[0], &aflock[1], 100, fAccess);
    213214#if 0
    214                         debug_printf("tdb_brlock pid %X, fd %d, rc=%d RETRY WAIT(%d)\n",
    215                                 getpid(), tdb->fd, rc,count);
     215                        TDB_LOG(( tdb, TDB_DEBUG_TRACE, "tdb_brlock pid %X, fd %d, rc=%d RETRY WAIT(%d)\n",
     216                                getpid(), tdb->fd, rc,count));
    216217#endif
    217218                        count--;
     
    230231                                 tdb->fd, offset, rw_type, lck_type, (int)len));
    231232                }
    232 #if 0
    233                 debug_printf("tdb_brlock pid %X, failed (fd=%d) at offset %d rw_type=%d lck_type=%d len=%d\n",
    234                          getpid(), tdb->fd, offset, rw_type, lck_type, (int)len);
    235 #endif
    236                 return TDB_ERRCODE(TDB_ERR_LOCK, -1);
    237         }
    238 #if 0
    239         debug_printf("tdb_brlock pid %X, fd %d, lck_type %s, rw_type %s, offset %d, len %d DONE\n",
    240                 getpid(), tdb->fd, lock_type(lck_type), read_type(rw_type), offset, len);
     233#if 1
     234                TDB_LOG(( tdb, TDB_DEBUG_ERROR, "tdb_brlock pid %X, failed (fd=%d) at offset %d rw_type=%d lck_type=%d len=%d\n",
     235                         getpid(), tdb->fd, offset, rw_type, lck_type, (int)len));
     236#endif
     237                return TDB_ERRCODE(TDB_ERR_LOCK, -1);
     238        }
     239#if 1
     240        TDB_LOG(( tdb, TDB_DEBUG_TRACE, "tdb_brlock pid %X, fd %d, lck_type %s, rw_type %s, offset %d, len %d DONE\n",
     241                getpid(), tdb->fd, lock_type(lck_type), read_type(rw_type), offset, len));
    241242#endif
    242243
     
    291292int tdb_brlock_upgrade(struct tdb_context *tdb, tdb_off_t offset, size_t len)
    292293{
     294        TDB_LOG(( tdb, TDB_DEBUG_TRACE, "tdb_brlock_upgrade pid %X, fd %d, offset %d, len %d\n",
     295                getpid(), tdb->fd, offset, len));
    293296        int count = 1000;
    294297        while (count--) {
  • trunk/samba/source/tdb/common/open.c

    r59 r61  
    178178                        goto fail;
    179179                }
     180                TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_open_ex pid %d global handle %d\n", getpid(), tdb->hGlobalLock));
    180181                sprintf( szSem, "\\SEM32\\TDB_AL_%s%s%s", dir, fname, ext);
    181182                rc = DosCreateMutexSem( szSem, &tdb->hActiveLock, 0, FALSE);
     
    187188                        goto fail;
    188189                }
     190                TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_open_ex pid %d active handle %d\n", getpid(), tdb->hActiveLock));
    189191                sprintf( szSem, "\\SEM32\\TDB_TL_%s%s%s", dir, fname, ext);
    190192                rc = DosCreateMutexSem( szSem, &tdb->hTransactionLock, 0, FALSE);
     
    196198                        goto fail;
    197199                }
     200                TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_open_ex pid %d transaction handle %d\n", getpid(), tdb->hTransactionLock));
    198201        }
    199202#endif
     
    456459        struct stat st;
    457460
     461        TDB_LOG((tdb, TDB_DEBUG_TRACE, "tdb_reopen pid %d\n", getpid()));
     462
    458463        if (tdb->flags & TDB_INTERNAL) {
    459464                return 0; /* Nothing to do. */
    460465        }
     466
     467#ifdef __OS2__
     468
     469        DosCloseMutexSem( tdb->hGlobalLock);
     470        tdb->hGlobalLock = 0;
     471        DosCloseMutexSem( tdb->hActiveLock);
     472        tdb->hActiveLock = 0;
     473        DosCloseMutexSem( tdb->hTransactionLock);
     474        tdb->hTransactionLock = 0;
     475
     476        if (!(tdb->flags & TDB_INTERNAL))
     477        {
     478                char    szSem[_MAX_PATH];
     479                char    drive[_MAX_DRIVE], dir[_MAX_DIR];
     480                char    fname[_MAX_FNAME], ext[_MAX_EXT];
     481                APIRET  rc;
     482                // extract path info
     483                _splitpath( tdb->name, drive, dir, fname, ext);
     484                sprintf( szSem, "\\SEM32\\TDB_GL_%s%s%s", dir, fname, ext);
     485                rc = DosCreateMutexSem( szSem, &tdb->hGlobalLock, 0, FALSE);
     486                if (rc == ERROR_DUPLICATE_NAME)
     487                        rc = DosOpenMutexSem( szSem, &tdb->hGlobalLock);
     488                if (rc != NO_ERROR) {
     489                        printf( "cannot open %s %d\n", szSem, rc);
     490                        errno = EINVAL;
     491                        goto fail;
     492                }
     493                TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_reopen pid %d global handle %d\n", getpid(), tdb->hGlobalLock));
     494                sprintf( szSem, "\\SEM32\\TDB_AL_%s%s%s", dir, fname, ext);
     495                rc = DosCreateMutexSem( szSem, &tdb->hActiveLock, 0, FALSE);
     496                if (rc == ERROR_DUPLICATE_NAME)
     497                        rc = DosOpenMutexSem( szSem, &tdb->hActiveLock);
     498                if (rc != NO_ERROR) {
     499                        printf( "cannot open %s %d\n", szSem, rc);
     500                        errno = EINVAL;
     501                        goto fail;
     502                }
     503                TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_reopen pid %d active handle %d\n", getpid(), tdb->hActiveLock));
     504                sprintf( szSem, "\\SEM32\\TDB_TL_%s%s%s", dir, fname, ext);
     505                rc = DosCreateMutexSem( szSem, &tdb->hTransactionLock, 0, FALSE);
     506                if (rc == ERROR_DUPLICATE_NAME)
     507                        rc = DosOpenMutexSem( szSem, &tdb->hTransactionLock);
     508                if (rc != NO_ERROR) {
     509                        printf( "cannot open %s %d\n", szSem, rc);
     510                        errno = EINVAL;
     511                        goto fail;
     512                }
     513                TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_reopen pid %d transaction handle %d\n", getpid(), tdb->hTransactionLock));
     514        }
     515#endif
    461516
    462517        if (tdb->num_locks != 0 || tdb->global_lock.count) {
     
    483538        if ((tdb->flags & TDB_CLEAR_IF_FIRST) &&
    484539            (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_RDLCK, F_SETLKW, 0, 1) == -1)) {
    485 #ifndef __OS2__ // PS 20070511 hack for WINS server crash
     540// YD sem handle was wrong, testme #ifndef __OS2__ // PS 20070511 hack for WINS server crash
    486541                TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: failed to obtain active lock\n"));
    487542                goto fail;
    488 #endif
     543//#endif
    489544        }
    490545        if (fstat(tdb->fd, &st) != 0) {
  • trunk/samba/source/tdb/common/transaction.c

    r30 r61  
    436436        /* get a read lock from the freelist to the end of file. This
    437437           is upgraded to a write lock during the commit */
     438#ifndef __OS2__ // YD the transation lock is an exclusive lock for us, it is enough.
    438439        if (tdb_brlock(tdb, FREELIST_TOP, F_RDLCK, F_SETLKW, 0, 0) == -1) {
    439440                TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_start: failed to get hash locks\n"));
     
    441442                goto fail;
    442443        }
     444#endif
    443445
    444446        /* setup a copy of the hash table heads so the hash scan in
     
    479481       
    480482fail:
     483#ifndef __OS2__ // YD the transation lock is an exclusive lock for us, it is enough.
    481484        tdb_brlock(tdb, FREELIST_TOP, F_UNLCK, F_SETLKW, 0, 0);
     485#endif
    482486        tdb_brlock(tdb, TRANSACTION_LOCK, F_UNLCK, F_SETLKW, 0, 1);
    483487        SAFE_FREE(tdb->transaction->hash_heads);
     
    534538        tdb->methods = tdb->transaction->io_methods;
    535539
     540#ifndef __OS2__ // YD the transation lock is an exclusive lock for us, it is enough.
    536541        tdb_brlock(tdb, FREELIST_TOP, F_UNLCK, F_SETLKW, 0, 0);
     542#endif
    537543        tdb_brlock(tdb, TRANSACTION_LOCK, F_UNLCK, F_SETLKW, 0, 1);
    538544        SAFE_FREE(tdb->transaction->hash_heads);
     
    822828
    823829        /* upgrade the main transaction lock region to a write lock */
     830#ifndef __OS2__ // YD the global lock is an exclusive lock for us, it is enough.
    824831        if (tdb_brlock_upgrade(tdb, FREELIST_TOP, 0) == -1) {
    825832                TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_start: failed to upgrade hash locks\n"));
     
    828835                return -1;
    829836        }
     837#endif
    830838
    831839        /* get the global lock - this prevents new users attaching to the database
Note: See TracChangeset for help on using the changeset viewer.