Changeset 836
- Timestamp:
- Nov 25, 2013, 6:40:10 PM (12 years ago)
- Location:
- branches/samba-3.5.x
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/samba-3.5.x/lib/tdb/common/io.c
r599 r836 93 93 // YD we must upgrade read locks to write locks (exclusive), otherwise 94 94 // the owner (us) is not allowed to write to the file (different from unix) 95 TDB_LOG((tdb, TDB_DEBUG_TRACE,"unlocking at %d len=%d before writing.\n", off, len));96 tdb_brlock( tdb, off, F_UNLCK, F_SETLK, 0, 1);97 95 // if a wider previous lock is in effect, we cannot write lock our segment 98 96 // (e.g. a lock_upgrade locks all the file), so we hope the previous lock 99 97 // is a write lock: do not wait for lock. 100 tdb_brlock( tdb, off, F_WRLCK, F_SETLK, 0, len); 98 int upgradeLockRC = tdb_brlock( tdb, off, F_WRLCK, F_SETLK, 0, len); 99 TDB_LOG((tdb, TDB_DEBUG_TRACE,"upgrading lock at %d len=%d " 100 "before writing %s (rc=%d).\n", off, len, 101 upgradeLockRC ? "was successfull":"failed", upgradeLockRC)); 101 102 #endif 102 103 … … 127 128 len, off)); 128 129 129 #ifdef __OS2__ // remove our lock 130 tdb_brlock( tdb, off, F_UNLCK, F_SETLK, 0, len); 130 #ifdef __OS2__ // remove our lock, if upgrade succeded 131 if (upgradeLockRC == 0) 132 tdb_brlock( tdb, off, F_UNLCK, F_SETLK, 0, len); 131 133 #endif 132 134 return -1; … … 134 136 } 135 137 136 #ifdef __OS2__ // remove our lock 137 tdb_brlock( tdb, off, F_UNLCK, F_SETLK, 0, len); 138 #ifdef __OS2__ // remove our lock, if upgrade succeded 139 if (upgradeLockRC == 0) 140 tdb_brlock( tdb, off, F_UNLCK, F_SETLK, 0, len); 138 141 #endif 139 142 -
branches/samba-3.5.x/lib/tdb/common/lock.c
r829 r836 30 30 #define TDB_MARK_LOCK 0x80000000 31 31 32 #ifdef __OS2__33 34 static char* lock_type( int lck)35 {36 static char buffer[16];37 switch(lck) {38 case F_GETLK: return "F_GETLK";39 case F_SETLK: return "F_SETLK";40 case F_SETLKW: return "F_SETLKW";41 default:42 sprintf( buffer, "unknown %d", lck);43 }44 return buffer;45 }46 47 static char* read_type( int rw)48 {49 static char buffer[16];50 switch(rw) {51 case F_RDLCK: return "F_RDLCK";52 case F_UNLCK: return "F_UNLCK";53 case F_WRLCK: return "F_WRLCK";54 default:55 sprintf( buffer, "unknown %d", rw);56 }57 return buffer;58 }59 60 static int _mutex_brlock(struct tdb_context *tdb, tdb_off_t offset,61 int rw_type, int lck_type, int probe, size_t len)62 {63 HMTX hSem;64 ULONG ulTimeout;65 APIRET rc;66 67 switch( offset) {68 case GLOBAL_LOCK:69 hSem = tdb->hGlobalLock;70 break;71 case ACTIVE_LOCK:72 hSem = tdb->hActiveLock;73 break;74 case TRANSACTION_LOCK:75 hSem = tdb->hTransactionLock;76 break;77 default:78 TDB_LOG((tdb, TDB_DEBUG_FATAL, "_mutex_brlock unknown offset %d\n", offset));79 exit(1);80 }81 if (hSem == 0) {82 TDB_LOG((tdb, TDB_DEBUG_FATAL, "_mutex_brlock unknown sem handle offset %d\n", offset));83 exit(1);84 }85 86 TDB_LOG((tdb, TDB_DEBUG_TRACE,"_mutex_brlock handle %d, offset %d\n", hSem, offset));87 88 if (lck_type == F_SETLKW)89 ulTimeout = SEM_INDEFINITE_WAIT;90 else91 ulTimeout = SEM_IMMEDIATE_RETURN;92 93 switch (rw_type) {94 case F_UNLCK:95 rc = DosReleaseMutexSem( hSem);96 break;97 case F_RDLCK:98 case F_WRLCK:99 rc = DosRequestMutexSem( hSem, ulTimeout);100 break;101 default:102 TDB_LOG((tdb, TDB_DEBUG_FATAL, "_mutex_brlock unknown rw_type request %d\n", rw_type));103 exit(1);104 break;105 }106 107 if (rc == NO_ERROR108 || rc == ERROR_SEM_OWNER_DIED109 || rc == ERROR_NOT_OWNER)110 return 0;111 112 errno = EINVAL;113 TDB_LOG(( tdb, TDB_DEBUG_ERROR, "_mutex_brlock pid %X, failed (fd=%d) at offset %d rw_type=%d lck_type=%d len=%d, rc=%d\n",114 getpid(), tdb->fd, offset, rw_type, lck_type, (int)len, rc));115 tdb->ecode = TDB_ERR_LOCK;116 return -1;117 }118 #endif119 32 120 33 void tdb_setalarm_sigptr(struct tdb_context *tdb, volatile sig_atomic_t *ptr) … … 135 48 { 136 49 137 #ifdef __OS2__138 APIRET rc;139 ULONG fAccess = 0;140 FILELOCK lockArea = {0}, unlockArea = {0};141 142 TDB_LOG((tdb, TDB_DEBUG_TRACE, "tdb_brlock in pid %X, fd %d, lck_type %s, rw_type %s, offset %d, len %d\n",143 getpid(), tdb->fd, lock_type(lck_type), read_type(rw_type), offset, len));144 145 if (tdb->flags & TDB_NOLOCK) {146 return 0;147 }148 149 if ((rw_type == F_WRLCK) && (tdb->read_only || tdb->traverse_read)) {150 tdb->ecode = TDB_ERR_RDONLY;151 return -1;152 }153 154 switch( offset) {155 case GLOBAL_LOCK:156 case ACTIVE_LOCK:157 case TRANSACTION_LOCK:158 return _mutex_brlock( tdb, offset, rw_type, lck_type, probe, len);159 }160 161 /* flags and order */162 switch (rw_type)163 {164 case F_UNLCK:165 unlockArea.lOffset = offset;166 unlockArea.lRange = len ? len : LONG_MAX;167 break;168 case F_RDLCK:169 lockArea.lOffset = offset;170 lockArea.lRange = len ? len : LONG_MAX;171 fAccess = 1; /* read-only */172 case F_WRLCK:173 lockArea.lOffset = offset;174 lockArea.lRange = len ? len : LONG_MAX;175 break;176 default:177 break;178 }179 180 rc = DosSetFileLocks(tdb->fd, &unlockArea, &lockArea, SEM_IMMEDIATE_RETURN, fAccess);181 182 if (rc != NO_ERROR && lck_type == F_SETLKW) {183 int count = 20;184 do {185 rc = DosSetFileLocks(tdb->fd, &unlockArea, &lockArea, 100, fAccess);186 count--;187 } while( count>0 && rc !=NO_ERROR);188 189 }190 191 TDB_LOG(( tdb, TDB_DEBUG_TRACE, "tdb_brlock out pid %d, fd %d, lck_type %s, rw_type %s, offset %d, len %d, rc=%d\n",192 getpid(), tdb->fd, lock_type(lck_type), read_type(rw_type), offset, len, rc));193 194 if (rc != NO_ERROR) {195 errno = EINVAL;196 /* Generic lock error. errno set by fcntl.197 * EAGAIN is an expected return from non-blocking198 * locks. */199 if (!probe && lck_type != F_SETLK) {200 /* Ensure error code is set for log fun to examine. */201 tdb->ecode = TDB_ERR_LOCK;202 TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_brlock failed (fd=%d) at offset %d rw_type=%d lck_type=%d len=%d\n",203 tdb->fd, offset, rw_type, lck_type, (int)len));204 }205 206 TDB_LOG(( tdb, TDB_DEBUG_TRACE, "tdb_brlock pid %X, failed (fd=%d) at offset %d rw_type=%d lck_type=%d len=%d\n",207 getpid(), tdb->fd, offset, rw_type, lck_type, (int)len));208 tdb->ecode = TDB_ERR_LOCK;209 return -1;210 }211 #else212 213 50 struct flock fl; 214 51 int ret; … … 226 63 fl.l_whence = SEEK_SET; 227 64 fl.l_start = offset; 65 #ifdef __OS2__ 66 fl.l_len = len ? len:LONG_MAX; 67 #else 228 68 fl.l_len = len; 69 #endif 229 70 fl.l_pid = 0; 230 71 … … 251 92 return -1; 252 93 } 253 #endif254 94 return 0; 255 95 … … 268 108 while (count--) { 269 109 struct timeval tv; 270 271 #ifdef __OS2__272 // YD we cannot upgrade without an unlock first...273 tdb_brlock(tdb, offset, F_UNLCK, F_SETLKW, 1, len);274 #endif275 110 276 111 if (tdb_brlock(tdb, offset, F_WRLCK, F_SETLKW, 1, len) == 0) { -
branches/samba-3.5.x/lib/tdb/common/open.c
r829 r836 27 27 28 28 #include "tdb_private.h" 29 30 #ifdef __OS2__31 // nmbd.c sets it to 132 int global_Sem32Add = 0;33 #endif34 29 35 30 /* all contexts, to ensure no double-opens (fcntl locks don't nest!) */ … … 184 179 tdb->hash_fn = hash_fn ? hash_fn : default_tdb_hash; 185 180 186 #ifdef __OS2__187 if (os2_CrtSem(tdb, name, "tdb_open_ex") != 0) {188 goto fail;189 }190 #endif191 192 181 /* cache the page size */ 193 182 tdb->page_size = getpagesize(); … … 262 251 if ((tdb_flags & TDB_CLEAR_IF_FIRST) && 263 252 (!tdb->read_only) 264 #ifndef __OS2__265 253 && (locked = (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_WRLCK, F_SETLK, 0, 1) == 0)) 266 #endif267 254 ) { 268 255 open_flags |= O_CREAT; … … 328 315 tdb_mmap(tdb); 329 316 if (locked) { 330 #ifndef __OS2__331 317 if (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_UNLCK, F_SETLK, 0, 1) == -1) { 332 318 TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: " … … 335 321 goto fail; 336 322 } 337 338 #endif339 323 } 340 324 … … 343 327 users know we're using it. */ 344 328 345 #ifndef __OS2__346 329 if (tdb_flags & TDB_CLEAR_IF_FIRST) { 347 330 /* leave this lock in place to indicate it's in use */ … … 349 332 goto fail; 350 333 } 351 #endif352 334 353 335 /* if needed, run recovery */ … … 355 337 goto fail; 356 338 } 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 #endif363 339 364 340 #ifdef TDB_TRACE … … 382 358 * do with disk files, and resume here by releasing their 383 359 * global lock and hooking into the active list. */ 384 #ifndef __OS2__385 360 if (tdb->methods->tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLKW, 0, 1) == -1) 386 361 goto fail; 387 #endif388 362 tdb->next = tdbs; 389 363 tdbs = tdb; … … 406 380 } 407 381 SAFE_FREE(tdb->name); 408 #ifdef __OS2__409 os2_DltSem(tdb, "tdb_open_ex");410 #endif411 382 if (tdb->fd != -1) 412 383 if (close(tdb->fd) != 0) … … 449 420 } 450 421 SAFE_FREE(tdb->name); 451 #ifdef __OS2__452 // YD internal databases do not have a global lock453 if (!(tdb->flags & TDB_INTERNAL))454 tdb->methods->tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLK, 0, 1);455 #endif456 422 if (tdb->fd != -1) { 457 423 ret = close(tdb->fd); … … 459 425 } 460 426 SAFE_FREE(tdb->lockrecs); 461 #ifdef __OS2__462 os2_DltSem(tdb, "tdb_close");463 #endif464 427 465 428 /* Remove from contexts list */ … … 502 465 return 0; /* Nothing to do. */ 503 466 } 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 #endif512 467 513 468 if (tdb->num_locks != 0 || tdb->global_lock.count) { … … 596 551 return 0; 597 552 } 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 it603 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 info612 _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 #endif661 -
branches/samba-3.5.x/lib/tdb/common/tdb_private.h
r833 r836 23 23 License along with this library; if not, see <http://www.gnu.org/licenses/>. 24 24 */ 25 26 #ifdef __OS2__27 #define INCL_ERRORS28 #define INCL_DOS29 #include <os2.h>30 #endif31 25 32 26 #include "replace.h" … … 210 204 #endif 211 205 volatile sig_atomic_t *interrupt_sig_ptr; 212 #ifdef __OS2__213 HMTX hGlobalLock;214 HMTX hActiveLock;215 HMTX hTransactionLock;216 #endif217 206 }; 218 207 -
branches/samba-3.5.x/lib/tdb/common/transaction.c
r657 r836 495 495 /* get a read lock from the freelist to the end of file. This 496 496 is upgraded to a write lock during the commit */ 497 #ifndef __OS2__ // YD the transation lock is an exclusive lock for us, it is enough.498 497 if (tdb_brlock(tdb, FREELIST_TOP, F_RDLCK, F_SETLKW, 0, 0) == -1) { 499 498 TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_start: failed to get hash locks\n")); … … 501 500 goto fail; 502 501 } 503 #endif504 502 505 503 /* setup a copy of the hash table heads so the hash scan in … … 533 531 534 532 fail: 535 #ifndef __OS2__ // YD the transation lock is an exclusive lock for us, it is enough.536 533 tdb_brlock(tdb, FREELIST_TOP, F_UNLCK, F_SETLKW, 0, 0); 537 #endif538 534 tdb_transaction_unlock(tdb); 539 535 SAFE_FREE(tdb->transaction->blocks); … … 636 632 tdb->methods = tdb->transaction->io_methods; 637 633 638 #ifndef __OS2__ // YD the transation lock is an exclusive lock for us, it is enough639 634 tdb_brlock(tdb, FREELIST_TOP, F_UNLCK, F_SETLKW, 0, 0); 640 #endif641 635 tdb_transaction_unlock(tdb); 642 636 SAFE_FREE(tdb->transaction->hash_heads); … … 946 940 947 941 /* upgrade the main transaction lock region to a write lock */ 948 #ifndef __OS2__ // YD the global lock is an exclusive lock for us, it is enough949 942 if (tdb_brlock_upgrade(tdb, FREELIST_TOP, 0) == -1) { 950 943 TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: failed to upgrade hash locks\n")); … … 953 946 return -1; 954 947 } 955 #endif956 948 957 949 /* get the global lock - this prevents new users attaching to the database -
branches/samba-3.5.x/source3/nmbd/nmbd.c
r832 r836 29 29 extern bool rescan_listen_set; 30 30 extern bool global_in_nmbd; 31 32 #ifdef __OS2__33 extern int global_Sem32Add;34 #endif35 31 36 32 extern bool override_logfile; … … 791 787 TALLOC_CTX *frame = talloc_stackframe(); /* Setup tos. */ 792 788 793 #ifdef __OS2__794 global_Sem32Add = 1;795 #endif796 797 789 load_case_tables(); 798 790
Note:
See TracChangeset
for help on using the changeset viewer.