Changeset 61
- Timestamp:
- Aug 20, 2007, 10:37:46 PM (18 years ago)
- Location:
- trunk/samba/source/tdb/common
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/samba/source/tdb/common/io.c
r1 r61 88 88 return -1; 89 89 90 #ifdef __OS2__ 91 // YD we must upgrade read locks to write locks (exclusive), otherwise 92 // the owner (us) is not allowed to write to the file (different from unix) 93 TDB_LOG((tdb, TDB_DEBUG_TRACE,"unlocking at %d len=%d before writing.\n", off, len)); 94 tdb_brlock( tdb, off, F_UNLCK, F_SETLK, 0, 1); 95 // if a wider previous lock is in effect, we cannot write lock our segment 96 // (e.g. a lock_upgrade locks all the file), so we hope the previous lock 97 // is a write lock: do not wait for lock. 98 tdb_brlock( tdb, off, F_WRLCK, F_SETLK, 0, len); 99 #endif 100 90 101 if (tdb->map_ptr) { 91 102 memcpy(off + (char *)tdb->map_ptr, buf, len); … … 95 106 TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_write failed at %d len=%d (%s)\n", 96 107 off, len, strerror(errno))); 108 #ifdef __OS2__ 109 // remove our lock 110 tdb_brlock( tdb, off, F_UNLCK, F_SETLK, 0, len); 111 #endif 97 112 return TDB_ERRCODE(TDB_ERR_IO, -1); 98 113 } 114 #ifdef __OS2__ 115 // remove our lock 116 tdb_brlock( tdb, off, F_UNLCK, F_SETLK, 0, len); 117 #endif 99 118 return 0; 100 119 } -
trunk/samba/source/tdb/common/lock.c
r45 r61 29 29 #include "tdb_private.h" 30 30 31 #if 0 // for debugging... 32 #i nclude "tdb/tools/printf.c"31 32 #if 1 // for debugging... 33 33 34 34 #if 0 … … 95 95 } 96 96 97 TDB_LOG((tdb, TDB_DEBUG_TRACE,"_mutex_brlock handle %d, offset %d\n", hSem, offset)); 98 97 99 if (lck_type == F_SETLKW) 98 100 ulTimeout = SEM_INDEFINITE_WAIT; … … 120 122 121 123 errno = EINVAL; 122 #if 0123 debug_printf("_mutex_brlock pid %X, failed (fd=%d) at offset %d rw_type=%d lck_type=%d len=%d, rc=%d\n",124 getpid(), tdb->fd, offset, rw_type, lck_type, (int)len, rc) ;124 #if 1 125 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", 126 getpid(), tdb->fd, offset, rw_type, lck_type, (int)len, rc)); 125 127 #endif 126 128 return TDB_ERRCODE(TDB_ERR_LOCK, -1); … … 149 151 off_t cbRange; 150 152 153 #if 1 154 TDB_LOG((tdb, TDB_DEBUG_TRACE, "tdb_brlock pid %X, fd %d, lck_type %s, rw_type %s, offset %d, len %d\n", 155 getpid(), tdb->fd, lock_type(lck_type), read_type(rw_type), offset, len)); 156 #endif 157 151 158 switch( offset) { 152 159 case GLOBAL_LOCK: 153 160 case ACTIVE_LOCK: 154 161 case TRANSACTION_LOCK: 155 return _mutex_brlock( tdb, offset, 156 rw_type, lck_type, probe, len); 162 return _mutex_brlock( tdb, offset, rw_type, lck_type, probe, len); 157 163 } 158 164 … … 166 172 } 167 173 168 #if 0169 debug_printf("tdb_brlock pid %X, fd %d, lck_type %s, rw_type %s, offset %d, len %d\n",170 getpid(), tdb->fd, lock_type(lck_type), read_type(rw_type), offset, len);171 #endif172 173 174 /* flags and order */ 174 175 fAccess = 0; /* exclusive */ … … 199 200 #if 0 200 201 if (rc != NO_ERROR) { 201 debug_printf("tdb_brlock pid %X, fd %d, rc=%d FAILED\n",202 getpid(), tdb->fd, rc) ;202 TDB_LOG(( tdb, TDB_DEBUG_TRACE, "tdb_brlock pid %X, fd %d, rc=%d FAILED\n", 203 getpid(), tdb->fd, rc)); 203 204 } 204 205 #endif 205 206 if (rc != NO_ERROR && lck_type == F_SETLKW) { 206 207 #if 0 207 debug_printf("tdb_brlock pid %X, fd %d, rc=%d RETRY WAIT\n",208 getpid(), tdb->fd, rc) ;209 #endif 210 int count = 10;208 TDB_LOG(( tdb, TDB_DEBUG_TRACE, "tdb_brlock pid %X, fd %d, rc=%d RETRY WAIT\n", 209 getpid(), tdb->fd, rc)); 210 #endif 211 int count = 20; 211 212 do { 212 rc = DosSetFileLocks(tdb->fd, &aflock[0], &aflock[1], 100 0, fAccess);213 rc = DosSetFileLocks(tdb->fd, &aflock[0], &aflock[1], 100, fAccess); 213 214 #if 0 214 debug_printf("tdb_brlock pid %X, fd %d, rc=%d RETRY WAIT(%d)\n",215 getpid(), tdb->fd, rc,count) ;215 TDB_LOG(( tdb, TDB_DEBUG_TRACE, "tdb_brlock pid %X, fd %d, rc=%d RETRY WAIT(%d)\n", 216 getpid(), tdb->fd, rc,count)); 216 217 #endif 217 218 count--; … … 230 231 tdb->fd, offset, rw_type, lck_type, (int)len)); 231 232 } 232 #if 0233 debug_printf("tdb_brlock pid %X, failed (fd=%d) at offset %d rw_type=%d lck_type=%d len=%d\n",234 getpid(), tdb->fd, offset, rw_type, lck_type, (int)len) ;235 #endif 236 return TDB_ERRCODE(TDB_ERR_LOCK, -1); 237 } 238 #if 0239 debug_printf("tdb_brlock pid %X, fd %d, lck_type %s, rw_type %s, offset %d, len %d DONE\n",240 getpid(), tdb->fd, lock_type(lck_type), read_type(rw_type), offset, len) ;233 #if 1 234 TDB_LOG(( tdb, TDB_DEBUG_ERROR, "tdb_brlock pid %X, failed (fd=%d) at offset %d rw_type=%d lck_type=%d len=%d\n", 235 getpid(), tdb->fd, offset, rw_type, lck_type, (int)len)); 236 #endif 237 return TDB_ERRCODE(TDB_ERR_LOCK, -1); 238 } 239 #if 1 240 TDB_LOG(( tdb, TDB_DEBUG_TRACE, "tdb_brlock pid %X, fd %d, lck_type %s, rw_type %s, offset %d, len %d DONE\n", 241 getpid(), tdb->fd, lock_type(lck_type), read_type(rw_type), offset, len)); 241 242 #endif 242 243 … … 291 292 int tdb_brlock_upgrade(struct tdb_context *tdb, tdb_off_t offset, size_t len) 292 293 { 294 TDB_LOG(( tdb, TDB_DEBUG_TRACE, "tdb_brlock_upgrade pid %X, fd %d, offset %d, len %d\n", 295 getpid(), tdb->fd, offset, len)); 293 296 int count = 1000; 294 297 while (count--) { -
trunk/samba/source/tdb/common/open.c
r59 r61 178 178 goto fail; 179 179 } 180 TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_open_ex pid %d global handle %d\n", getpid(), tdb->hGlobalLock)); 180 181 sprintf( szSem, "\\SEM32\\TDB_AL_%s%s%s", dir, fname, ext); 181 182 rc = DosCreateMutexSem( szSem, &tdb->hActiveLock, 0, FALSE); … … 187 188 goto fail; 188 189 } 190 TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_open_ex pid %d active handle %d\n", getpid(), tdb->hActiveLock)); 189 191 sprintf( szSem, "\\SEM32\\TDB_TL_%s%s%s", dir, fname, ext); 190 192 rc = DosCreateMutexSem( szSem, &tdb->hTransactionLock, 0, FALSE); … … 196 198 goto fail; 197 199 } 200 TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_open_ex pid %d transaction handle %d\n", getpid(), tdb->hTransactionLock)); 198 201 } 199 202 #endif … … 456 459 struct stat st; 457 460 461 TDB_LOG((tdb, TDB_DEBUG_TRACE, "tdb_reopen pid %d\n", getpid())); 462 458 463 if (tdb->flags & TDB_INTERNAL) { 459 464 return 0; /* Nothing to do. */ 460 465 } 466 467 #ifdef __OS2__ 468 469 DosCloseMutexSem( tdb->hGlobalLock); 470 tdb->hGlobalLock = 0; 471 DosCloseMutexSem( tdb->hActiveLock); 472 tdb->hActiveLock = 0; 473 DosCloseMutexSem( tdb->hTransactionLock); 474 tdb->hTransactionLock = 0; 475 476 if (!(tdb->flags & TDB_INTERNAL)) 477 { 478 char szSem[_MAX_PATH]; 479 char drive[_MAX_DRIVE], dir[_MAX_DIR]; 480 char fname[_MAX_FNAME], ext[_MAX_EXT]; 481 APIRET rc; 482 // extract path info 483 _splitpath( tdb->name, drive, dir, fname, ext); 484 sprintf( szSem, "\\SEM32\\TDB_GL_%s%s%s", dir, fname, ext); 485 rc = DosCreateMutexSem( szSem, &tdb->hGlobalLock, 0, FALSE); 486 if (rc == ERROR_DUPLICATE_NAME) 487 rc = DosOpenMutexSem( szSem, &tdb->hGlobalLock); 488 if (rc != NO_ERROR) { 489 printf( "cannot open %s %d\n", szSem, rc); 490 errno = EINVAL; 491 goto fail; 492 } 493 TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_reopen pid %d global handle %d\n", getpid(), tdb->hGlobalLock)); 494 sprintf( szSem, "\\SEM32\\TDB_AL_%s%s%s", dir, fname, ext); 495 rc = DosCreateMutexSem( szSem, &tdb->hActiveLock, 0, FALSE); 496 if (rc == ERROR_DUPLICATE_NAME) 497 rc = DosOpenMutexSem( szSem, &tdb->hActiveLock); 498 if (rc != NO_ERROR) { 499 printf( "cannot open %s %d\n", szSem, rc); 500 errno = EINVAL; 501 goto fail; 502 } 503 TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_reopen pid %d active handle %d\n", getpid(), tdb->hActiveLock)); 504 sprintf( szSem, "\\SEM32\\TDB_TL_%s%s%s", dir, fname, ext); 505 rc = DosCreateMutexSem( szSem, &tdb->hTransactionLock, 0, FALSE); 506 if (rc == ERROR_DUPLICATE_NAME) 507 rc = DosOpenMutexSem( szSem, &tdb->hTransactionLock); 508 if (rc != NO_ERROR) { 509 printf( "cannot open %s %d\n", szSem, rc); 510 errno = EINVAL; 511 goto fail; 512 } 513 TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_reopen pid %d transaction handle %d\n", getpid(), tdb->hTransactionLock)); 514 } 515 #endif 461 516 462 517 if (tdb->num_locks != 0 || tdb->global_lock.count) { … … 483 538 if ((tdb->flags & TDB_CLEAR_IF_FIRST) && 484 539 (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_RDLCK, F_SETLKW, 0, 1) == -1)) { 485 #ifndef __OS2__ // PS 20070511 hack for WINS server crash540 // YD sem handle was wrong, testme #ifndef __OS2__ // PS 20070511 hack for WINS server crash 486 541 TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_reopen: failed to obtain active lock\n")); 487 542 goto fail; 488 #endif543 //#endif 489 544 } 490 545 if (fstat(tdb->fd, &st) != 0) { -
trunk/samba/source/tdb/common/transaction.c
r30 r61 436 436 /* get a read lock from the freelist to the end of file. This 437 437 is upgraded to a write lock during the commit */ 438 #ifndef __OS2__ // YD the transation lock is an exclusive lock for us, it is enough. 438 439 if (tdb_brlock(tdb, FREELIST_TOP, F_RDLCK, F_SETLKW, 0, 0) == -1) { 439 440 TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_start: failed to get hash locks\n")); … … 441 442 goto fail; 442 443 } 444 #endif 443 445 444 446 /* setup a copy of the hash table heads so the hash scan in … … 479 481 480 482 fail: 483 #ifndef __OS2__ // YD the transation lock is an exclusive lock for us, it is enough. 481 484 tdb_brlock(tdb, FREELIST_TOP, F_UNLCK, F_SETLKW, 0, 0); 485 #endif 482 486 tdb_brlock(tdb, TRANSACTION_LOCK, F_UNLCK, F_SETLKW, 0, 1); 483 487 SAFE_FREE(tdb->transaction->hash_heads); … … 534 538 tdb->methods = tdb->transaction->io_methods; 535 539 540 #ifndef __OS2__ // YD the transation lock is an exclusive lock for us, it is enough. 536 541 tdb_brlock(tdb, FREELIST_TOP, F_UNLCK, F_SETLKW, 0, 0); 542 #endif 537 543 tdb_brlock(tdb, TRANSACTION_LOCK, F_UNLCK, F_SETLKW, 0, 1); 538 544 SAFE_FREE(tdb->transaction->hash_heads); … … 822 828 823 829 /* upgrade the main transaction lock region to a write lock */ 830 #ifndef __OS2__ // YD the global lock is an exclusive lock for us, it is enough. 824 831 if (tdb_brlock_upgrade(tdb, FREELIST_TOP, 0) == -1) { 825 832 TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_start: failed to upgrade hash locks\n")); … … 828 835 return -1; 829 836 } 837 #endif 830 838 831 839 /* get the global lock - this prevents new users attaching to the database
Note:
See TracChangeset
for help on using the changeset viewer.