Ignore:
Timestamp:
Jun 7, 2010, 9:08:40 AM (15 years ago)
Author:
Silvan Scherrer
Message:

Samba Server 3.5: changes from 3.3

File:
1 edited

Legend:

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

    r414 r456  
    2727
    2828#include "tdb_private.h"
     29
     30#ifdef __OS2__
     31// nmbd.c sets it to 1
     32int global_Sem32Add = 0;
     33#endif
    2934
    3035/* all contexts, to ensure no double-opens (fcntl locks don't nest!) */
     
    179184        tdb->hash_fn = hash_fn ? hash_fn : default_tdb_hash;
    180185
     186#ifdef __OS2__
     187        if (os2_crtsem(tdb, name, "tdb_open_ex") != 0) {
     188                goto fail;
     189        }
     190#endif
     191
    181192        /* cache the page size */
    182193        tdb->page_size = getpagesize();
     
    250261        /* we need to zero database if we are the only one with it open */
    251262        if ((tdb_flags & TDB_CLEAR_IF_FIRST) &&
    252             (!tdb->read_only) &&
    253             (locked = (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_WRLCK, F_SETLK, 0, 1) == 0))) {
     263            (!tdb->read_only)
     264#ifndef __OS2__
     265            && (locked = (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_WRLCK, F_SETLK, 0, 1) == 0))
     266#endif
     267            ) {
    254268                open_flags |= O_CREAT;
    255269                if (ftruncate(tdb->fd, 0) == -1) {
     
    314328        tdb_mmap(tdb);
    315329        if (locked) {
     330#ifndef __OS2__
    316331                if (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_UNLCK, F_SETLK, 0, 1) == -1) {
    317332                        TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: "
     
    321336                }
    322337
     338#endif
    323339        }
    324340
     
    327343           users know we're using it. */
    328344
     345#ifndef __OS2__
    329346        if (tdb_flags & TDB_CLEAR_IF_FIRST) {
    330347                /* leave this lock in place to indicate it's in use */
     
    332349                        goto fail;
    333350        }
     351#endif
    334352
    335353        /* if needed, run recovery */
     
    337355                goto fail;
    338356        }
     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
    339363
    340364#ifdef TDB_TRACE
     
    358382         * do with disk files, and resume here by releasing their
    359383         * global lock and hooking into the active list. */
     384#ifndef __OS2__
    360385        if (tdb->methods->tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLKW, 0, 1) == -1)
    361386                goto fail;
     387#endif
    362388        tdb->next = tdbs;
    363         tdbs = tdb;
     389                tdbs = tdb;
    364390        return tdb;
    365391
     
    380406        }
    381407        SAFE_FREE(tdb->name);
     408#ifdef __OS2__
     409        DosCloseMutexSem( tdb->hGlobalLock);
     410        tdb->hGlobalLock = 0;
     411        DosCloseMutexSem( tdb->hActiveLock);
     412        tdb->hActiveLock = 0;
     413        DosCloseMutexSem( tdb->hTransactionLock);
     414        tdb->hTransactionLock = 0;
     415#endif
    382416        if (tdb->fd != -1)
    383417                if (close(tdb->fd) != 0)
     
    420454        }
    421455        SAFE_FREE(tdb->name);
     456#ifdef __OS2__
     457        // YD internal databases do not have a global lock
     458        if (!(tdb->flags & TDB_INTERNAL))
     459                tdb->methods->tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLK, 0, 1);
     460#endif
    422461        if (tdb->fd != -1) {
    423462                ret = close(tdb->fd);
     
    425464        }
    426465        SAFE_FREE(tdb->lockrecs);
     466#ifdef __OS2__
     467        DosCloseMutexSem( tdb->hGlobalLock);
     468        tdb->hGlobalLock = 0;
     469        DosCloseMutexSem( tdb->hActiveLock);
     470        tdb->hActiveLock = 0;
     471        DosCloseMutexSem( tdb->hTransactionLock);
     472        tdb->hTransactionLock = 0;
     473#endif
    427474
    428475        /* Remove from contexts list */
     
    465512                return 0; /* Nothing to do. */
    466513        }
     514
     515#ifdef __OS2__
     516        DosCloseMutexSem( tdb->hGlobalLock);
     517        tdb->hGlobalLock = 0;
     518        DosCloseMutexSem( tdb->hActiveLock);
     519        tdb->hActiveLock = 0;
     520        DosCloseMutexSem( tdb->hTransactionLock);
     521        tdb->hTransactionLock = 0;
     522
     523        if (os2_crtsem(tdb, tdb->name, "tdb_reopen") != 0) {
     524                goto fail;
     525        }
     526#endif
    467527
    468528        if (tdb->num_locks != 0 || tdb->global_lock.count) {
     
    551611        return 0;
    552612}
     613
     614#ifdef __OS2__
     615int os2_crtsem(struct tdb_context *tdb, const char *name, const char *caller)
     616{
     617        if (!(tdb->flags & TDB_INTERNAL))
     618        {
     619                char    szSem[_MAX_PATH];
     620                char    drive[_MAX_DRIVE], dir[_MAX_DIR];
     621                char    fname[_MAX_FNAME], ext[_MAX_EXT];
     622                APIRET  rc;
     623                // extract path info
     624                _splitpath( name, drive, dir, fname, ext);
     625                sprintf( szSem, "\\SEM32\\TDB_GL_%s%s%s%i", dir, fname, ext, global_Sem32Add);
     626                rc = DosCreateMutexSem( szSem, &tdb->hGlobalLock, 0, FALSE);
     627                if (rc == ERROR_DUPLICATE_NAME)
     628                        rc = DosOpenMutexSem( szSem, &tdb->hGlobalLock);
     629                if (rc != NO_ERROR) {
     630                                TDB_LOG((tdb, TDB_DEBUG_ERROR, "cannot open %s %d\n", szSem, rc));
     631                        errno = EINVAL;
     632                        return -1;
     633                }
     634                TDB_LOG((tdb, TDB_DEBUG_TRACE,"%s pid %d global handle %d\n", caller, getpid(), tdb->hGlobalLock));
     635
     636                sprintf( szSem, "\\SEM32\\TDB_AL_%s%s%s%i", dir, fname, ext, global_Sem32Add);
     637                rc = DosCreateMutexSem( szSem, &tdb->hActiveLock, 0, FALSE);
     638                if (rc == ERROR_DUPLICATE_NAME)
     639                        rc = DosOpenMutexSem( szSem, &tdb->hActiveLock);
     640                if (rc != NO_ERROR) {
     641                        TDB_LOG((tdb, TDB_DEBUG_ERROR, "cannot open %s %d\n", szSem, rc));
     642                        errno = EINVAL;
     643                        return -1;
     644                }
     645                TDB_LOG((tdb, TDB_DEBUG_TRACE,"%s pid %d active handle %d\n", caller, getpid(), tdb->hActiveLock));
     646
     647                sprintf( szSem, "\\SEM32\\TDB_TL_%s%s%s%i", dir, fname, ext, global_Sem32Add);
     648                rc = DosCreateMutexSem( szSem, &tdb->hTransactionLock, 0, FALSE);
     649                if (rc == ERROR_DUPLICATE_NAME)
     650                        rc = DosOpenMutexSem( szSem, &tdb->hTransactionLock);
     651                if (rc != NO_ERROR) {
     652                        TDB_LOG((tdb, TDB_DEBUG_ERROR, "cannot open %s %d\n", szSem, rc));
     653                        errno = EINVAL;
     654                        return -1;
     655                }
     656                TDB_LOG((tdb, TDB_DEBUG_TRACE,"%s pid %d transaction handle %d\n", caller, getpid(), tdb->hTransactionLock));
     657        }
     658        return 0;
     659}
     660#endif
     661               
Note: See TracChangeset for help on using the changeset viewer.