Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/lib/tdb/common/tdb.c

    r648 r745  
    77   Copyright (C) Paul `Rusty' Russell              2000
    88   Copyright (C) Jeremy Allison                    2000-2003
    9    
     9
    1010     ** NOTE! The following LGPL license applies to the tdb
    1111     ** library. This does NOT imply that all of Samba is released
    1212     ** under the LGPL
    13    
     13
    1414   This library is free software; you can redistribute it and/or
    1515   modify it under the terms of the GNU Lesser General Public
     
    2828#include "tdb_private.h"
    2929
    30 TDB_DATA tdb_null;
     30_PUBLIC_ TDB_DATA tdb_null;
    3131
    3232/*
     
    3434  the TDB_SEQNUM flag
    3535*/
    36 void tdb_increment_seqnum_nonblock(struct tdb_context *tdb)
     36_PUBLIC_ void tdb_increment_seqnum_nonblock(struct tdb_context *tdb)
    3737{
    3838        tdb_off_t seqnum=0;
    39        
     39
    4040        if (!(tdb->flags & TDB_SEQNUM)) {
    4141                return;
     
    6060        }
    6161
    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) {
    6364                return;
    6465        }
     
    6667        tdb_increment_seqnum_nonblock(tdb);
    6768
    68         tdb_brlock(tdb, TDB_SEQNUM_OFS, F_UNLCK, F_SETLKW, 1, 1);
     69        tdb_nest_unlock(tdb, TDB_SEQNUM_OFS, F_WRLCK, false);
    6970}
    7071
     
    8081{
    8182        tdb_off_t rec_ptr;
    82        
     83
    8384        /* read in the hash top */
    8485        if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1)
     
    154155                }
    155156        }
    156          
    157157
    158158        /* must be long enough key, data and tailer */
     
    171171                return tdb_rec_write(tdb, rec_ptr, &rec);
    172172        }
    173  
     173
    174174        return 0;
    175175}
     
    200200}
    201201
    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)
    203203{
    204204        TDB_DATA ret = _tdb_fetch(tdb, key);
     
    213213 * should be fast and should not block on other syscalls.
    214214 *
    215  * DONT 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.
    216216 *
    217217 * For mmapped tdb's that do not have a transaction open it points the parsing
     
    222222 * This is interesting for all readers of potentially large data structures in
    223223 * the tdb records, ldb indexes being one example.
     224 *
     225 * Return -1 if the record was not found.
    224226 */
    225227
    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,
    227229                     int (*parser)(TDB_DATA key, TDB_DATA data,
    228230                                   void *private_data),
     
    238240
    239241        if (!(rec_ptr = tdb_find_lock_hash(tdb,key,hash,F_RDLCK,&rec))) {
     242                /* record not found */
    240243                tdb_trace_1rec_ret(tdb, "tdb_parse_record", key, -1);
    241244                tdb->ecode = TDB_ERR_NOEXIST;
    242                 return 0;
     245                return -1;
    243246        }
    244247        tdb_trace_1rec_ret(tdb, "tdb_parse_record", key, 0);
     
    261264{
    262265        struct tdb_record rec;
    263        
     266
    264267        if (tdb_find_lock_hash(tdb, key, hash, F_RDLCK, &rec) == 0)
    265268                return 0;
     
    268271}
    269272
    270 int tdb_exists(struct tdb_context *tdb, TDB_DATA key)
     273_PUBLIC_ int tdb_exists(struct tdb_context *tdb, TDB_DATA key)
    271274{
    272275        uint32_t hash = tdb->hash_fn(&key);
     
    319322        tdb_off_t rec_ptr;
    320323        struct tdb_record rec;
    321        
     324
    322325        /* read in the hash top */
    323326        if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1)
     
    348351                return -1;
    349352        }
    350        
     353
    351354        /* read in the hash top */
    352355        if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1)
     
    427430}
    428431
    429 int tdb_delete(struct tdb_context *tdb, TDB_DATA key)
     432_PUBLIC_ int tdb_delete(struct tdb_context *tdb, TDB_DATA key)
    430433{
    431434        uint32_t hash = tdb->hash_fn(&key);
     
    444447{
    445448        tdb_off_t rec_ptr;
    446        
     449
    447450        /* read in the hash top */
    448451        if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1)
     
    597600   return 0 on success, -1 on failure
    598601*/
    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)
    600603{
    601604        uint32_t hash;
     
    620623
    621624/* 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)
    623626{
    624627        uint32_t hash;
     
    659662        ret = _tdb_store(tdb, key, dbuf, 0, hash);
    660663        tdb_trace_2rec_retrec(tdb, "tdb_append", key, new_dbuf, dbuf);
    661        
     664
    662665failed:
    663666        tdb_unlock(tdb, BUCKET(hash), F_WRLCK);
     
    671674  useful for external logging functions
    672675*/
    673 const char *tdb_name(struct tdb_context *tdb)
     676_PUBLIC_ const char *tdb_name(struct tdb_context *tdb)
    674677{
    675678        return tdb->name;
     
    681684  of the fd
    682685*/
    683 int tdb_fd(struct tdb_context *tdb)
     686_PUBLIC_ int tdb_fd(struct tdb_context *tdb)
    684687{
    685688        return tdb->fd;
     
    690693  useful for external tdb routines that wish to log tdb errors
    691694*/
    692 tdb_log_func tdb_log_fn(struct tdb_context *tdb)
     695_PUBLIC_ tdb_log_func tdb_log_fn(struct tdb_context *tdb)
    693696{
    694697        return tdb->log.log_fn;
     
    706709  test of a possible tdb change.
    707710*/
    708 int tdb_get_seqnum(struct tdb_context *tdb)
     711_PUBLIC_ int tdb_get_seqnum(struct tdb_context *tdb)
    709712{
    710713        tdb_off_t seqnum=0;
     
    714717}
    715718
    716 int tdb_hash_size(struct tdb_context *tdb)
     719_PUBLIC_ int tdb_hash_size(struct tdb_context *tdb)
    717720{
    718721        return tdb->header.hash_size;
    719722}
    720723
    721 size_t tdb_map_size(struct tdb_context *tdb)
     724_PUBLIC_ size_t tdb_map_size(struct tdb_context *tdb)
    722725{
    723726        return tdb->map_size;
    724727}
    725728
    726 int tdb_get_flags(struct tdb_context *tdb)
     729_PUBLIC_ int tdb_get_flags(struct tdb_context *tdb)
    727730{
    728731        return tdb->flags;
    729732}
    730733
    731 void tdb_add_flags(struct tdb_context *tdb, unsigned flags)
     734_PUBLIC_ void tdb_add_flags(struct tdb_context *tdb, unsigned flags)
    732735{
    733736        if ((flags & TDB_ALLOW_NESTING) &&
     
    749752}
    750753
    751 void tdb_remove_flags(struct tdb_context *tdb, unsigned flags)
     754_PUBLIC_ void tdb_remove_flags(struct tdb_context *tdb, unsigned flags)
    752755{
    753756        if ((flags & TDB_ALLOW_NESTING) &&
     
    773776  enable sequence number handling on an open tdb
    774777*/
    775 void tdb_enable_seqnum(struct tdb_context *tdb)
     778_PUBLIC_ void tdb_enable_seqnum(struct tdb_context *tdb)
    776779{
    777780        tdb->flags |= TDB_SEQNUM;
     
    805808/*
    806809  wipe the entire database, deleting all records. This can be done
    807   very fast by using a global lock. The entire data portion of the
     810  very fast by using a allrecord lock. The entire data portion of the
    808811  file becomes a single entry in the freelist.
    809812
    810813  This code carefully steps around the recovery area, leaving it alone
    811814 */
    812 int tdb_wipe_all(struct tdb_context *tdb)
     815_PUBLIC_ int tdb_wipe_all(struct tdb_context *tdb)
    813816{
    814817        int i;
     
    917920  repack a tdb
    918921 */
    919 int tdb_repack(struct tdb_context *tdb)
     922_PUBLIC_ int tdb_repack(struct tdb_context *tdb)
    920923{
    921924        struct tdb_context *tmp_db;
     
    987990}
    988991
     992/* Even on files, we can get partial writes due to signals. */
     993bool 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
    9891006#ifdef TDB_TRACE
    9901007static void tdb_trace_write(struct tdb_context *tdb, const char *str)
    9911008{
    992         if (write(tdb->tracefd, str, strlen(str)) != strlen(str)) {
     1009        if (!tdb_write_alltdb->tracefd, str, strlen(str)) {
    9931010                close(tdb->tracefd);
    9941011                tdb->tracefd = -1;
Note: See TracChangeset for help on using the changeset viewer.