Changeset 847


Ignore:
Timestamp:
Feb 14, 2014, 7:01:54 PM (11 years ago)
Author:
Silvan Scherrer
Message:

samba server 3.5: bring 3.5 code base in line with 3.6

Location:
branches/samba-3.5.x/lib/tdb/common
Files:
4 edited

Legend:

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

    r836 r847  
    9191
    9292#ifdef __OS2__
    93         // YD we must upgrade read locks to write locks (exclusive), otherwise
     93        // YD we must upgrade read locks to write locks (exclusive), as otherwise
    9494        // the owner (us) is not allowed to write to the file (different from unix)
    9595        // if a wider previous lock is in effect, we cannot write lock our segment
    9696        // (e.g. a lock_upgrade locks all the file), so we hope the previous lock
    9797        // is a write lock: do not wait for lock.
    98         int upgradeLockRC = tdb_brlock( tdb, off, F_WRLCK, F_SETLK, 0, len);
     98        // so this is what we try here:
     99        // 1. add a write lock and see if it works
     100        // 2. if the write lock wasn't set, we try to unlock the segment
     101        //    first and add the write lock afterwards
     102        int upgradeLockRC = 0;
     103        upgradeLockRC = tdb_brlock( tdb, off, F_WRLCK, F_SETLK, 0, len);
     104        if (upgradeLockRC != 0) {
     105                tdb_brlock(tdb, off, F_UNLCK, F_SETLK, 0, len);
     106                upgradeLockRC = tdb_brlock(tdb, off, F_WRLCK, F_SETLK, 0, len);
     107        }
    99108        TDB_LOG((tdb, TDB_DEBUG_TRACE,"upgrading lock at %d len=%d "
    100109                "before writing %s (rc=%d).\n", off, len,
    101                  upgradeLockRC ? "was successfull":"failed", upgradeLockRC));
     110                 upgradeLockRC ? "failed":"was successfull", upgradeLockRC));
    102111#endif
    103112
     
    137146
    138147#ifdef __OS2__ // remove our lock, if upgrade succeded
    139                         if (upgradeLockRC == 0)
    140                                 tdb_brlock( tdb, off, F_UNLCK, F_SETLK, 0, len);
     148        if (upgradeLockRC == 0)
     149                tdb_brlock( tdb, off, F_UNLCK, F_SETLK, 0, len);
    141150#endif
    142151
  • branches/samba-3.5.x/lib/tdb/common/lock.c

    r836 r847  
    3636}
    3737
     38#ifdef __OS2__
     39static int handle_mutex_lock(struct tdb_context *tdb, HMTX mutex, int rw, int waitflag)
     40{
     41        ULONG   ulTimeout;
     42        APIRET  rc;
     43
     44        if (mutex == 0) {
     45                printf( "fcntl_lock: sem not initialised\n");
     46                exit(1);
     47        }
     48
     49        if (waitflag == F_SETLKW)
     50                ulTimeout = SEM_INDEFINITE_WAIT;
     51        else
     52                ulTimeout = SEM_IMMEDIATE_RETURN;
     53
     54        switch (rw) {
     55        case F_UNLCK:
     56                rc = DosReleaseMutexSem(mutex);
     57                break;
     58        case F_RDLCK: // we never wait for a read lock, as several want to hold one
     59                rc = DosRequestMutexSem(mutex, SEM_IMMEDIATE_RETURN);
     60                if (rc == ERROR_NOT_OWNER || ERROR_TIMEOUT)
     61                        rc = NO_ERROR;
     62                break;
     63        case F_WRLCK:
     64                rc = DosRequestMutexSem(mutex, ulTimeout);
     65                break;
     66        }
     67
     68        if (rc == NO_ERROR || rc == ERROR_SEM_OWNER_DIED)
     69                return 0;
     70
     71        TDB_LOG((tdb, TDB_DEBUG_TRACE,"handle_mutex_lock: (fd=%d) rw_type=%d waitflag=%d (rc=%d)\n",
     72                tdb->fd, rw, waitflag, rc));
     73
     74        errno = EINVAL;
     75        return -1;
     76}
     77#endif
     78
    3879/* a byte range locking function - return 0 on success
    3980   this functions locks/unlocks 1 byte at the specified offset.
     
    70111        fl.l_pid = 0;
    71112
     113#ifdef __OS2__
     114        TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_brlock: (fd=%d) offset=%d rw_type=%d len=%d lock_type=%d\n",
     115                tdb->fd, offset, rw_type, len, lck_type));
     116
     117        if (offset == ACTIVE_LOCK) {
     118                ret = handle_mutex_lock(tdb, tdb->hActiveLock, rw_type, lck_type);
     119        } else {
     120
     121#endif
    72122        do {
    73123                ret = fcntl(tdb->fd,lck_type,&fl);
     
    81131        } while (ret == -1 && errno == EINTR);
    82132
     133#ifdef __OS2__
     134        }
     135#endif
    83136        if (ret == -1) {
    84137                tdb->ecode = TDB_ERR_LOCK;
     
    109162                struct timeval tv;
    110163
     164#ifdef __OS2__
     165                // we need to remove locks, as upgrade doesn't work
     166                tdb_brlock(tdb, offset, F_UNLCK, F_SETLK, 1, len);
     167#endif
    111168                if (tdb_brlock(tdb, offset, F_WRLCK, F_SETLKW, 1, len) == 0) {
    112169                        return 0;
  • branches/samba-3.5.x/lib/tdb/common/open.c

    r836 r847  
    231231        }
    232232
     233#ifdef __OS2__
     234        if (os2_crtSem(tdb, name, "tdb_open_ex") != 0)
     235                goto fail;
     236#endif
     237
    233238        if ((tdb->fd = open(name, open_flags, mode)) == -1) {
    234239                TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_open_ex: could not open file %s: %s\n",
     
    367372        { int save_errno = errno;
    368373
     374#ifdef __OS2__
     375        DosCloseMutexSem(tdb->hActiveLock);
     376        tdb->hActiveLock = 0;
     377#endif
    369378        if (!tdb)
    370379                return NULL;
     
    434443        }
    435444
     445#ifdef __OS2__
     446        DosCloseMutexSem(tdb->hActiveLock);
     447        tdb->hActiveLock = 0;
     448#endif
     449
    436450#ifdef TDB_TRACE
    437451        close(tdb->tracefd);
     
    500514        tdb_mmap(tdb);
    501515#endif /* fake pread or pwrite */
     516
     517#ifdef __OS2__
     518        DosCloseMutexSem(tdb->hActiveLock);
     519        tdb->hActiveLock = 0;
     520
     521        if (os2_crtSem(tdb, tdb->name, "tdb_reopen") != 0)
     522                goto fail;
     523#endif
    502524
    503525        if (active_lock &&
     
    551573        return 0;
    552574}
     575#ifdef __OS2__
     576int os2_crtSem(struct tdb_context *tdb, const char *name, const char *caller)
     577{
     578        // name could be null, so handle it
     579        if (name == NULL)
     580                return -1;
     581
     582        char    szSem[_MAX_PATH];
     583        char    drive[_MAX_DRIVE], dir[_MAX_DIR];
     584        char    fname[_MAX_FNAME], ext[_MAX_EXT];
     585        APIRET  rc;
     586        // extract path info
     587        _splitpath(name, drive, dir, fname, ext);
     588        sprintf(szSem, "\\SEM32\\TDB_AL_%s%s%s", dir, fname, ext);
     589        rc = DosCreateMutexSem(szSem, &tdb->hActiveLock, 0, FALSE);
     590        if (rc == ERROR_DUPLICATE_NAME)
     591                rc = DosOpenMutexSem(szSem, &tdb->hActiveLock);
     592        if (rc != NO_ERROR) {
     593                TDB_LOG((tdb, TDB_DEBUG_ERROR, "os2_crtSem: cannot create sem32 %s (rc=%d) called from %s\n",
     594                        szSem, rc, caller));
     595                errno = EINVAL;
     596                return -1;
     597        }
     598        return 0;
     599}
     600#endif
  • branches/samba-3.5.x/lib/tdb/common/tdb_private.h

    r836 r847  
    2323   License along with this library; if not, see <http://www.gnu.org/licenses/>.
    2424*/
     25#ifdef __OS2__
     26#define INCL_ERRORS
     27#define INCL_DOS
     28#include <os2.h>
     29#endif
    2530
    2631#include "replace.h"
     
    204209#endif
    205210        volatile sig_atomic_t *interrupt_sig_ptr;
     211#ifdef __OS2__
     212        HMTX    hActiveLock;
     213#endif
    206214};
    207215
Note: See TracChangeset for help on using the changeset viewer.