Changeset 847
- Timestamp:
- Feb 14, 2014, 7:01:54 PM (11 years ago)
- 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 91 91 92 92 #ifdef __OS2__ 93 // YD we must upgrade read locks to write locks (exclusive), otherwise93 // YD we must upgrade read locks to write locks (exclusive), as otherwise 94 94 // the owner (us) is not allowed to write to the file (different from unix) 95 95 // if a wider previous lock is in effect, we cannot write lock our segment 96 96 // (e.g. a lock_upgrade locks all the file), so we hope the previous lock 97 97 // 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 } 99 108 TDB_LOG((tdb, TDB_DEBUG_TRACE,"upgrading lock at %d len=%d " 100 109 "before writing %s (rc=%d).\n", off, len, 101 upgradeLockRC ? " was successfull":"failed", upgradeLockRC));110 upgradeLockRC ? "failed":"was successfull", upgradeLockRC)); 102 111 #endif 103 112 … … 137 146 138 147 #ifdef __OS2__ // remove our lock, if upgrade succeded 139 140 148 if (upgradeLockRC == 0) 149 tdb_brlock( tdb, off, F_UNLCK, F_SETLK, 0, len); 141 150 #endif 142 151 -
branches/samba-3.5.x/lib/tdb/common/lock.c
r836 r847 36 36 } 37 37 38 #ifdef __OS2__ 39 static 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 38 79 /* a byte range locking function - return 0 on success 39 80 this functions locks/unlocks 1 byte at the specified offset. … … 70 111 fl.l_pid = 0; 71 112 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 72 122 do { 73 123 ret = fcntl(tdb->fd,lck_type,&fl); … … 81 131 } while (ret == -1 && errno == EINTR); 82 132 133 #ifdef __OS2__ 134 } 135 #endif 83 136 if (ret == -1) { 84 137 tdb->ecode = TDB_ERR_LOCK; … … 109 162 struct timeval tv; 110 163 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 111 168 if (tdb_brlock(tdb, offset, F_WRLCK, F_SETLKW, 1, len) == 0) { 112 169 return 0; -
branches/samba-3.5.x/lib/tdb/common/open.c
r836 r847 231 231 } 232 232 233 #ifdef __OS2__ 234 if (os2_crtSem(tdb, name, "tdb_open_ex") != 0) 235 goto fail; 236 #endif 237 233 238 if ((tdb->fd = open(name, open_flags, mode)) == -1) { 234 239 TDB_LOG((tdb, TDB_DEBUG_WARNING, "tdb_open_ex: could not open file %s: %s\n", … … 367 372 { int save_errno = errno; 368 373 374 #ifdef __OS2__ 375 DosCloseMutexSem(tdb->hActiveLock); 376 tdb->hActiveLock = 0; 377 #endif 369 378 if (!tdb) 370 379 return NULL; … … 434 443 } 435 444 445 #ifdef __OS2__ 446 DosCloseMutexSem(tdb->hActiveLock); 447 tdb->hActiveLock = 0; 448 #endif 449 436 450 #ifdef TDB_TRACE 437 451 close(tdb->tracefd); … … 500 514 tdb_mmap(tdb); 501 515 #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 502 524 503 525 if (active_lock && … … 551 573 return 0; 552 574 } 575 #ifdef __OS2__ 576 int 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 23 23 License along with this library; if not, see <http://www.gnu.org/licenses/>. 24 24 */ 25 #ifdef __OS2__ 26 #define INCL_ERRORS 27 #define INCL_DOS 28 #include <os2.h> 29 #endif 25 30 26 31 #include "replace.h" … … 204 209 #endif 205 210 volatile sig_atomic_t *interrupt_sig_ptr; 211 #ifdef __OS2__ 212 HMTX hActiveLock; 213 #endif 206 214 }; 207 215
Note:
See TracChangeset
for help on using the changeset viewer.