Changeset 745 for trunk/server/lib/tdb/common/tdb.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/lib/tdb/common/tdb.c
r648 r745 7 7 Copyright (C) Paul `Rusty' Russell 2000 8 8 Copyright (C) Jeremy Allison 2000-2003 9 9 10 10 ** NOTE! The following LGPL license applies to the tdb 11 11 ** library. This does NOT imply that all of Samba is released 12 12 ** under the LGPL 13 13 14 14 This library is free software; you can redistribute it and/or 15 15 modify it under the terms of the GNU Lesser General Public … … 28 28 #include "tdb_private.h" 29 29 30 TDB_DATA tdb_null;30 _PUBLIC_ TDB_DATA tdb_null; 31 31 32 32 /* … … 34 34 the TDB_SEQNUM flag 35 35 */ 36 void tdb_increment_seqnum_nonblock(struct tdb_context *tdb)36 _PUBLIC_ void tdb_increment_seqnum_nonblock(struct tdb_context *tdb) 37 37 { 38 38 tdb_off_t seqnum=0; 39 39 40 40 if (!(tdb->flags & TDB_SEQNUM)) { 41 41 return; … … 60 60 } 61 61 62 if (tdb_brlock(tdb, TDB_SEQNUM_OFS, F_WRLCK, F_SETLKW, 1, 1) != 0) { 62 if (tdb_nest_lock(tdb, TDB_SEQNUM_OFS, F_WRLCK, 63 TDB_LOCK_WAIT|TDB_LOCK_PROBE) != 0) { 63 64 return; 64 65 } … … 66 67 tdb_increment_seqnum_nonblock(tdb); 67 68 68 tdb_ brlock(tdb, TDB_SEQNUM_OFS, F_UNLCK, F_SETLKW, 1, 1);69 tdb_nest_unlock(tdb, TDB_SEQNUM_OFS, F_WRLCK, false); 69 70 } 70 71 … … 80 81 { 81 82 tdb_off_t rec_ptr; 82 83 83 84 /* read in the hash top */ 84 85 if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1) … … 154 155 } 155 156 } 156 157 157 158 158 /* must be long enough key, data and tailer */ … … 171 171 return tdb_rec_write(tdb, rec_ptr, &rec); 172 172 } 173 173 174 174 return 0; 175 175 } … … 200 200 } 201 201 202 TDB_DATA tdb_fetch(struct tdb_context *tdb, TDB_DATA key)202 _PUBLIC_ TDB_DATA tdb_fetch(struct tdb_context *tdb, TDB_DATA key) 203 203 { 204 204 TDB_DATA ret = _tdb_fetch(tdb, key); … … 213 213 * should be fast and should not block on other syscalls. 214 214 * 215 * DON T CALL OTHER TDB CALLS FROM THE PARSER, THIS MIGHT LEAD TO SEGFAULTS.215 * DON'T CALL OTHER TDB CALLS FROM THE PARSER, THIS MIGHT LEAD TO SEGFAULTS. 216 216 * 217 217 * For mmapped tdb's that do not have a transaction open it points the parsing … … 222 222 * This is interesting for all readers of potentially large data structures in 223 223 * the tdb records, ldb indexes being one example. 224 * 225 * Return -1 if the record was not found. 224 226 */ 225 227 226 int tdb_parse_record(struct tdb_context *tdb, TDB_DATA key,228 _PUBLIC_ int tdb_parse_record(struct tdb_context *tdb, TDB_DATA key, 227 229 int (*parser)(TDB_DATA key, TDB_DATA data, 228 230 void *private_data), … … 238 240 239 241 if (!(rec_ptr = tdb_find_lock_hash(tdb,key,hash,F_RDLCK,&rec))) { 242 /* record not found */ 240 243 tdb_trace_1rec_ret(tdb, "tdb_parse_record", key, -1); 241 244 tdb->ecode = TDB_ERR_NOEXIST; 242 return 0;245 return -1; 243 246 } 244 247 tdb_trace_1rec_ret(tdb, "tdb_parse_record", key, 0); … … 261 264 { 262 265 struct tdb_record rec; 263 266 264 267 if (tdb_find_lock_hash(tdb, key, hash, F_RDLCK, &rec) == 0) 265 268 return 0; … … 268 271 } 269 272 270 int tdb_exists(struct tdb_context *tdb, TDB_DATA key)273 _PUBLIC_ int tdb_exists(struct tdb_context *tdb, TDB_DATA key) 271 274 { 272 275 uint32_t hash = tdb->hash_fn(&key); … … 319 322 tdb_off_t rec_ptr; 320 323 struct tdb_record rec; 321 324 322 325 /* read in the hash top */ 323 326 if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1) … … 348 351 return -1; 349 352 } 350 353 351 354 /* read in the hash top */ 352 355 if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1) … … 427 430 } 428 431 429 int tdb_delete(struct tdb_context *tdb, TDB_DATA key)432 _PUBLIC_ int tdb_delete(struct tdb_context *tdb, TDB_DATA key) 430 433 { 431 434 uint32_t hash = tdb->hash_fn(&key); … … 444 447 { 445 448 tdb_off_t rec_ptr; 446 449 447 450 /* read in the hash top */ 448 451 if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1) … … 597 600 return 0 on success, -1 on failure 598 601 */ 599 int tdb_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag)602 _PUBLIC_ int tdb_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag) 600 603 { 601 604 uint32_t hash; … … 620 623 621 624 /* Append to an entry. Create if not exist. */ 622 int tdb_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf)625 _PUBLIC_ int tdb_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf) 623 626 { 624 627 uint32_t hash; … … 659 662 ret = _tdb_store(tdb, key, dbuf, 0, hash); 660 663 tdb_trace_2rec_retrec(tdb, "tdb_append", key, new_dbuf, dbuf); 661 664 662 665 failed: 663 666 tdb_unlock(tdb, BUCKET(hash), F_WRLCK); … … 671 674 useful for external logging functions 672 675 */ 673 const char *tdb_name(struct tdb_context *tdb)676 _PUBLIC_ const char *tdb_name(struct tdb_context *tdb) 674 677 { 675 678 return tdb->name; … … 681 684 of the fd 682 685 */ 683 int tdb_fd(struct tdb_context *tdb)686 _PUBLIC_ int tdb_fd(struct tdb_context *tdb) 684 687 { 685 688 return tdb->fd; … … 690 693 useful for external tdb routines that wish to log tdb errors 691 694 */ 692 tdb_log_func tdb_log_fn(struct tdb_context *tdb)695 _PUBLIC_ tdb_log_func tdb_log_fn(struct tdb_context *tdb) 693 696 { 694 697 return tdb->log.log_fn; … … 706 709 test of a possible tdb change. 707 710 */ 708 int tdb_get_seqnum(struct tdb_context *tdb)711 _PUBLIC_ int tdb_get_seqnum(struct tdb_context *tdb) 709 712 { 710 713 tdb_off_t seqnum=0; … … 714 717 } 715 718 716 int tdb_hash_size(struct tdb_context *tdb)719 _PUBLIC_ int tdb_hash_size(struct tdb_context *tdb) 717 720 { 718 721 return tdb->header.hash_size; 719 722 } 720 723 721 size_t tdb_map_size(struct tdb_context *tdb)724 _PUBLIC_ size_t tdb_map_size(struct tdb_context *tdb) 722 725 { 723 726 return tdb->map_size; 724 727 } 725 728 726 int tdb_get_flags(struct tdb_context *tdb)729 _PUBLIC_ int tdb_get_flags(struct tdb_context *tdb) 727 730 { 728 731 return tdb->flags; 729 732 } 730 733 731 void tdb_add_flags(struct tdb_context *tdb, unsigned flags)734 _PUBLIC_ void tdb_add_flags(struct tdb_context *tdb, unsigned flags) 732 735 { 733 736 if ((flags & TDB_ALLOW_NESTING) && … … 749 752 } 750 753 751 void tdb_remove_flags(struct tdb_context *tdb, unsigned flags)754 _PUBLIC_ void tdb_remove_flags(struct tdb_context *tdb, unsigned flags) 752 755 { 753 756 if ((flags & TDB_ALLOW_NESTING) && … … 773 776 enable sequence number handling on an open tdb 774 777 */ 775 void tdb_enable_seqnum(struct tdb_context *tdb)778 _PUBLIC_ void tdb_enable_seqnum(struct tdb_context *tdb) 776 779 { 777 780 tdb->flags |= TDB_SEQNUM; … … 805 808 /* 806 809 wipe the entire database, deleting all records. This can be done 807 very fast by using a globallock. The entire data portion of the810 very fast by using a allrecord lock. The entire data portion of the 808 811 file becomes a single entry in the freelist. 809 812 810 813 This code carefully steps around the recovery area, leaving it alone 811 814 */ 812 int tdb_wipe_all(struct tdb_context *tdb)815 _PUBLIC_ int tdb_wipe_all(struct tdb_context *tdb) 813 816 { 814 817 int i; … … 917 920 repack a tdb 918 921 */ 919 int tdb_repack(struct tdb_context *tdb)922 _PUBLIC_ int tdb_repack(struct tdb_context *tdb) 920 923 { 921 924 struct tdb_context *tmp_db; … … 987 990 } 988 991 992 /* Even on files, we can get partial writes due to signals. */ 993 bool tdb_write_all(int fd, const void *buf, size_t count) 994 { 995 while (count) { 996 ssize_t ret; 997 ret = write(fd, buf, count); 998 if (ret < 0) 999 return false; 1000 buf = (const char *)buf + ret; 1001 count -= ret; 1002 } 1003 return true; 1004 } 1005 989 1006 #ifdef TDB_TRACE 990 1007 static void tdb_trace_write(struct tdb_context *tdb, const char *str) 991 1008 { 992 if ( write(tdb->tracefd, str, strlen(str)) !=strlen(str)) {1009 if (!tdb_write_alltdb->tracefd, str, strlen(str)) { 993 1010 close(tdb->tracefd); 994 1011 tdb->tracefd = -1;
Note:
See TracChangeset
for help on using the changeset viewer.