Ignore:
Timestamp:
Nov 25, 2013, 6:40:10 PM (12 years ago)
Author:
Silvan Scherrer
Message:

Samba 3.5: use fcntl and friends for locking

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/samba-3.5.x/lib/tdb/common/open.c

    r829 r836  
    2727
    2828#include "tdb_private.h"
    29 
    30 #ifdef __OS2__
    31 // nmbd.c sets it to 1
    32 int global_Sem32Add = 0;
    33 #endif
    3429
    3530/* all contexts, to ensure no double-opens (fcntl locks don't nest!) */
     
    184179        tdb->hash_fn = hash_fn ? hash_fn : default_tdb_hash;
    185180
    186 #ifdef __OS2__
    187         if (os2_CrtSem(tdb, name, "tdb_open_ex") != 0) {
    188                 goto fail;
    189         }
    190 #endif
    191 
    192181        /* cache the page size */
    193182        tdb->page_size = getpagesize();
     
    262251        if ((tdb_flags & TDB_CLEAR_IF_FIRST) &&
    263252            (!tdb->read_only)
    264 #ifndef __OS2__
    265253            && (locked = (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_WRLCK, F_SETLK, 0, 1) == 0))
    266 #endif
    267254            ) {
    268255                open_flags |= O_CREAT;
     
    328315        tdb_mmap(tdb);
    329316        if (locked) {
    330 #ifndef __OS2__
    331317                if (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_UNLCK, F_SETLK, 0, 1) == -1) {
    332318                        TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: "
     
    335321                        goto fail;
    336322                }
    337 
    338 #endif
    339323        }
    340324
     
    343327           users know we're using it. */
    344328
    345 #ifndef __OS2__
    346329        if (tdb_flags & TDB_CLEAR_IF_FIRST) {
    347330                /* leave this lock in place to indicate it's in use */
     
    349332                        goto fail;
    350333        }
    351 #endif
    352334
    353335        /* if needed, run recovery */
     
    355337                goto fail;
    356338        }
    357 
    358 #ifdef __OS2__
    359         // YD internal databases do not get global lock!
    360         if (tdb->methods->tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLKW, 0, 1) == -1)
    361                 goto fail;
    362 #endif
    363339
    364340#ifdef TDB_TRACE
     
    382358         * do with disk files, and resume here by releasing their
    383359         * global lock and hooking into the active list. */
    384 #ifndef __OS2__
    385360        if (tdb->methods->tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLKW, 0, 1) == -1)
    386361                goto fail;
    387 #endif
    388362        tdb->next = tdbs;
    389363                tdbs = tdb;
     
    406380        }
    407381        SAFE_FREE(tdb->name);
    408 #ifdef __OS2__
    409         os2_DltSem(tdb, "tdb_open_ex");
    410 #endif
    411382        if (tdb->fd != -1)
    412383                if (close(tdb->fd) != 0)
     
    449420        }
    450421        SAFE_FREE(tdb->name);
    451 #ifdef __OS2__
    452         // YD internal databases do not have a global lock
    453         if (!(tdb->flags & TDB_INTERNAL))
    454                 tdb->methods->tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLK, 0, 1);
    455 #endif
    456422        if (tdb->fd != -1) {
    457423                ret = close(tdb->fd);
     
    459425        }
    460426        SAFE_FREE(tdb->lockrecs);
    461 #ifdef __OS2__
    462         os2_DltSem(tdb, "tdb_close");   
    463 #endif
    464427
    465428        /* Remove from contexts list */
     
    502465                return 0; /* Nothing to do. */
    503466        }
    504 
    505 #ifdef __OS2__
    506         os2_DltSem(tdb, "tdb_reopen");
    507 
    508         if (os2_CrtSem(tdb, tdb->name, "tdb_reopen") != 0) {
    509                 goto fail;
    510         }
    511 #endif
    512467
    513468        if (tdb->num_locks != 0 || tdb->global_lock.count) {
     
    596551        return 0;
    597552}
    598 
    599 #ifdef __OS2__
    600 int os2_CrtSem(struct tdb_context *tdb, const char *name, const char *caller)
    601 {
    602         // name could be null, so handle it
    603         if (name == NULL) return -1;
    604 
    605         if (!(tdb->flags & TDB_INTERNAL))
    606         {
    607                 char    szSem[_MAX_PATH];
    608                 char    drive[_MAX_DRIVE], dir[_MAX_DIR];
    609                 char    fname[_MAX_FNAME], ext[_MAX_EXT];
    610                 APIRET  rc;
    611                 // extract path info
    612                 _splitpath( name, drive, dir, fname, ext);
    613                 sprintf( szSem, "\\SEM32\\TDB_GL_%s%s%s%i", dir, fname, ext, global_Sem32Add);
    614                 rc = DosCreateMutexSem( szSem, &tdb->hGlobalLock, 0, FALSE);
    615                 if (rc == ERROR_DUPLICATE_NAME)
    616                         rc = DosOpenMutexSem( szSem, &tdb->hGlobalLock);
    617                 if (rc != NO_ERROR) {
    618                                 TDB_LOG((tdb, TDB_DEBUG_ERROR, "cannot open %s %d\n", szSem, rc));
    619                         errno = EINVAL;
    620                         return -1;
    621                 }
    622                 TDB_LOG((tdb, TDB_DEBUG_TRACE,"%s pid %d global handle %d\n", caller, getpid(), tdb->hGlobalLock));
    623 
    624                 sprintf( szSem, "\\SEM32\\TDB_AL_%s%s%s%i", dir, fname, ext, global_Sem32Add);
    625                 rc = DosCreateMutexSem( szSem, &tdb->hActiveLock, 0, FALSE);
    626                 if (rc == ERROR_DUPLICATE_NAME)
    627                         rc = DosOpenMutexSem( szSem, &tdb->hActiveLock);
    628                 if (rc != NO_ERROR) {
    629                         TDB_LOG((tdb, TDB_DEBUG_ERROR, "cannot open %s %d\n", szSem, rc));
    630                         errno = EINVAL;
    631                         return -1;
    632                 }
    633                 TDB_LOG((tdb, TDB_DEBUG_TRACE,"%s pid %d active handle %d\n", caller, getpid(), tdb->hActiveLock));
    634 
    635                 sprintf( szSem, "\\SEM32\\TDB_TL_%s%s%s%i", dir, fname, ext, global_Sem32Add);
    636                 rc = DosCreateMutexSem( szSem, &tdb->hTransactionLock, 0, FALSE);
    637                 if (rc == ERROR_DUPLICATE_NAME)
    638                         rc = DosOpenMutexSem( szSem, &tdb->hTransactionLock);
    639                 if (rc != NO_ERROR) {
    640                         TDB_LOG((tdb, TDB_DEBUG_ERROR, "cannot open %s %d\n", szSem, rc));
    641                         errno = EINVAL;
    642                         return -1;
    643                 }
    644                 TDB_LOG((tdb, TDB_DEBUG_TRACE,"%s pid %d transaction handle %d\n", caller, getpid(), tdb->hTransactionLock));
    645         }
    646         return 0;
    647 }
    648 
    649 int os2_DltSem(struct tdb_context *tdb, const char *caller)
    650 {
    651         DosCloseMutexSem( tdb->hGlobalLock);
    652         tdb->hGlobalLock = 0;
    653         DosCloseMutexSem( tdb->hActiveLock);
    654         tdb->hActiveLock = 0;
    655         DosCloseMutexSem( tdb->hTransactionLock);
    656         tdb->hTransactionLock = 0;
    657 
    658         return 0;
    659 }
    660 #endif
    661                
Note: See TracChangeset for help on using the changeset viewer.