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/open.c

    r825 r834  
    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!) */
     
    242237        }
    243238
    244 #ifdef __OS2__
    245         if (os2_CrtSem(tdb, "tdb_open_ex") != 0) {
    246                 goto fail;
    247         }
    248 #endif
    249239        /* cache the page size */
    250240        tdb->page_size = getpagesize();
     
    322312        /* we need to zero database if we are the only one with it open */
    323313        if ((tdb_flags & TDB_CLEAR_IF_FIRST) &&
    324 #ifndef __OS2__
    325314            (!tdb->read_only) &&
    326315            (locked = (tdb_nest_lock(tdb, ACTIVE_LOCK, F_WRLCK, TDB_LOCK_NOWAIT|TDB_LOCK_PROBE) == 0))) {
    327 #else
    328             (!tdb->read_only) ) {
    329 #endif
    330316                int ret;
    331317                ret = tdb_brlock(tdb, F_WRLCK, FREELIST_TOP, 0,
     
    429415        tdb_mmap(tdb);
    430416        if (locked) {
    431 #ifndef __OS2__
    432417                if (tdb_nest_unlock(tdb, ACTIVE_LOCK, F_WRLCK, false) == -1) {
    433418                        TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: "
     
    437422                }
    438423
    439 #endif
    440424        }
    441425
     
    444428           users know we're using it. */
    445429
    446 #ifndef __OS2__
    447430        if (tdb_flags & TDB_CLEAR_IF_FIRST) {
    448431                /* leave this lock in place to indicate it's in use */
     
    451434                }
    452435        }
    453 #endif
    454436
    455437        /* if needed, run recovery */
     
    457439                goto fail;
    458440        }
    459 
    460 #ifdef __OS2__
    461         // YD internal databases do not get global lock!
    462         if (tdb_nest_unlock(tdb, OPEN_LOCK, F_WRLCK, false) == -1)
    463                 goto fail;
    464 #endif
    465441
    466442#ifdef TDB_TRACE
     
    484460         * do with disk files, and resume here by releasing their
    485461         * open lock and hooking into the active list. */
    486 #ifndef __OS2__
    487462        if (tdb_nest_unlock(tdb, OPEN_LOCK, F_WRLCK, false) == -1) {
    488463                goto fail;
    489464        }
    490 #endif
    491465        tdb->next = tdbs;
    492466        tdbs = tdb;
     
    511485                if (close(tdb->fd) != 0)
    512486                        TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: failed to close tdb->fd on error!\n"));
    513 #ifdef __OS2__
    514         os2_DltSem(tdb, "tdb_open_ex");
    515 #endif
    516487        SAFE_FREE(tdb->lockrecs);
    517488        SAFE_FREE(tdb->name);
     
    553524        }
    554525        SAFE_FREE(tdb->name);
    555 #ifdef __OS2__
    556         // YD internal databases do not have a global lock
    557         if (!(tdb->flags & TDB_INTERNAL))
    558         tdb_nest_unlock(tdb, OPEN_LOCK, F_WRLCK, false);
    559 #endif
    560526        if (tdb->fd != -1) {
    561527                ret = close(tdb->fd);
     
    564530        SAFE_FREE(tdb->lockrecs);
    565531
    566 #ifdef __OS2__
    567         os2_DltSem(tdb, "tdb_close");   
    568 #endif
    569532        /* Remove from contexts list */
    570533        for (i = &tdbs; *i; i = &(*i)->next) {
     
    606569                return 0; /* Nothing to do. */
    607570        }
    608 
    609 #ifdef __OS2__
    610         os2_DltSem(tdb, "tdb_reopen");
    611 
    612         if (os2_CrtSem(tdb, "tdb_reopen") != 0) {
    613                 goto fail;
    614         }
    615 #endif
    616571
    617572        if (tdb_have_extra_locks(tdb)) {
     
    703658        return 0;
    704659}
    705 
    706 #ifdef __OS2__
    707 int os2_CrtSem(struct tdb_context *tdb, const char *caller)
    708 {
    709         // tbd->name could be null, so handle it
    710         if (tdb->name == NULL) return -1;
    711        
    712         if (!(tdb->flags & TDB_INTERNAL))
    713         {
    714                 char    szSem[_MAX_PATH];
    715                 char    drive[_MAX_DRIVE], dir[_MAX_DIR];
    716                 char    fname[_MAX_FNAME], ext[_MAX_EXT];
    717                 APIRET  rc;
    718                 // extract path info
    719                 _splitpath( tdb->name, drive, dir, fname, ext);
    720                 sprintf( szSem, "\\SEM32\\TDB_OL_%s%s%s%i", dir, fname, ext, global_Sem32Add);
    721                 rc = DosCreateMutexSem( szSem, &tdb->hGlobalLock, 0, FALSE);
    722                 if (rc == ERROR_DUPLICATE_NAME)
    723                         rc = DosOpenMutexSem( szSem, &tdb->hGlobalLock);
    724                 if (rc != NO_ERROR) {
    725                                 TDB_LOG((tdb, TDB_DEBUG_ERROR, "cannot open %s %d\n", szSem, rc));
    726                         errno = EINVAL;
    727                         return -1;
    728                 }
    729                 TDB_LOG((tdb, TDB_DEBUG_TRACE,"%s pid %d open handle %d\n", caller, getpid(), tdb->hGlobalLock));
    730 
    731                 sprintf( szSem, "\\SEM32\\TDB_AL_%s%s%s%i", dir, fname, ext, global_Sem32Add);
    732                 rc = DosCreateMutexSem( szSem, &tdb->hActiveLock, 0, FALSE);
    733                 if (rc == ERROR_DUPLICATE_NAME)
    734                         rc = DosOpenMutexSem( szSem, &tdb->hActiveLock);
    735                 if (rc != NO_ERROR) {
    736                         TDB_LOG((tdb, TDB_DEBUG_ERROR, "cannot open %s %d\n", szSem, rc));
    737                         errno = EINVAL;
    738                         return -1;
    739                 }
    740                 TDB_LOG((tdb, TDB_DEBUG_TRACE,"%s pid %d active handle %d\n", caller, getpid(), tdb->hActiveLock));
    741 
    742                 sprintf( szSem, "\\SEM32\\TDB_TL_%s%s%s%i", dir, fname, ext, global_Sem32Add);
    743                 rc = DosCreateMutexSem( szSem, &tdb->hTransactionLock, 0, FALSE);
    744                 if (rc == ERROR_DUPLICATE_NAME)
    745                         rc = DosOpenMutexSem( szSem, &tdb->hTransactionLock);
    746                 if (rc != NO_ERROR) {
    747                         TDB_LOG((tdb, TDB_DEBUG_ERROR, "cannot open %s %d\n", szSem, rc));
    748                         errno = EINVAL;
    749                         return -1;
    750                 }
    751                 TDB_LOG((tdb, TDB_DEBUG_TRACE,"%s pid %d transaction handle %d\n", caller, getpid(), tdb->hTransactionLock));
    752         }
    753         return 0;
    754 }
    755 
    756 int os2_DltSem(struct tdb_context *tdb, const char *caller)
    757 {
    758         DosCloseMutexSem( tdb->hGlobalLock);
    759         tdb->hGlobalLock = 0;
    760         DosCloseMutexSem( tdb->hActiveLock);
    761         tdb->hActiveLock = 0;
    762         DosCloseMutexSem( tdb->hTransactionLock);
    763         tdb->hTransactionLock = 0;
    764 
    765         return 0;
    766 }
    767 #endif
Note: See TracChangeset for help on using the changeset viewer.