ntdb_check_: enum NTDB_ERROR (struct ntdb_context *, enum NTDB_ERROR (*)(NTDB_DATA, NTDB_DATA, void *), void *)
ntdb_close: int (struct ntdb_context *)
ntdb_delete: enum NTDB_ERROR (struct ntdb_context *, NTDB_DATA)
-ntdb_error: enum NTDB_ERROR (struct ntdb_context *)
ntdb_errorstr: const char *(enum NTDB_ERROR)
ntdb_exists: bool (struct ntdb_context *, NTDB_DATA)
ntdb_fd: int (const struct ntdb_context *)
ecode = ntdb_allrecord_lock(ntdb, F_RDLCK, NTDB_LOCK_WAIT, false);
if (ecode != NTDB_SUCCESS) {
- return ntdb->last_error = ecode;
+ return ecode;
}
ecode = ntdb_lock_expand(ntdb, F_RDLCK);
if (ecode != NTDB_SUCCESS) {
ntdb_allrecord_unlock(ntdb, F_RDLCK);
- return ntdb->last_error = ecode;
+ return ecode;
}
ecode = check_header(ntdb, &recovery, &features, &num_capabilities);
ntdb_unlock_expand(ntdb, F_RDLCK);
free(fr);
free(used);
- return ntdb->last_error = ecode;
+ return ecode;
}
- ntdb functions return NTDB_SUCCESS (ie 0) on success, and a negative
error on failure, whereas tdb functions returned 0 on success, and
-1 on failure. tdb then used tdb_error() to determine the error;
- this is also supported in ntdb to ease backwards compatibility,
- though the other form is preferred.
+ this API is nasty if we ever want to support threads, so is not supported.
- ntdb's ntdb_fetch() returns an error, tdb's returned the data directly
(or tdb_null, and you were supposed to check tdb_error() to find out why).
contention - it cannot guarantee how many records will be locked */
_PUBLIC_ enum NTDB_ERROR ntdb_chainlock(struct ntdb_context *ntdb, NTDB_DATA key)
{
- return ntdb->last_error = chainlock(ntdb, &key, F_WRLCK, NTDB_LOCK_WAIT,
- "ntdb_chainlock");
+ return chainlock(ntdb, &key, F_WRLCK, NTDB_LOCK_WAIT, "ntdb_chainlock");
}
_PUBLIC_ void ntdb_chainunlock(struct ntdb_context *ntdb, NTDB_DATA key)
_PUBLIC_ enum NTDB_ERROR ntdb_chainlock_read(struct ntdb_context *ntdb, NTDB_DATA key)
{
- return ntdb->last_error = chainlock(ntdb, &key, F_RDLCK, NTDB_LOCK_WAIT,
- "ntdb_chainlock_read");
+ return chainlock(ntdb, &key, F_RDLCK, NTDB_LOCK_WAIT,
+ "ntdb_chainlock_read");
}
_PUBLIC_ void ntdb_chainunlock_read(struct ntdb_context *ntdb, NTDB_DATA key)
off = find_and_lock(ntdb, key, F_WRLCK, &h, &rec, NULL);
if (NTDB_OFF_IS_ERR(off)) {
- return ntdb->last_error = NTDB_OFF_TO_ERR(off);
+ return NTDB_OFF_TO_ERR(off);
}
/* Now we have lock on this hash bucket. */
}
ntdb_unlock_hashes(ntdb, h.hlock_start,
h.hlock_range, F_WRLCK);
- return ntdb->last_error = NTDB_SUCCESS;
+ return NTDB_SUCCESS;
}
} else {
if (flag == NTDB_MODIFY) {
ecode = replace_data(ntdb, &h, key, dbuf, off, old_room, off);
out:
ntdb_unlock_hashes(ntdb, h.hlock_start, h.hlock_range, F_WRLCK);
- return ntdb->last_error = ecode;
+ return ecode;
}
_PUBLIC_ enum NTDB_ERROR ntdb_append(struct ntdb_context *ntdb,
off = find_and_lock(ntdb, key, F_WRLCK, &h, &rec, NULL);
if (NTDB_OFF_IS_ERR(off)) {
- return ntdb->last_error = NTDB_OFF_TO_ERR(off);
+ return NTDB_OFF_TO_ERR(off);
}
if (off) {
free(newdata);
out:
ntdb_unlock_hashes(ntdb, h.hlock_start, h.hlock_range, F_WRLCK);
- return ntdb->last_error = ecode;
+ return ecode;
}
_PUBLIC_ enum NTDB_ERROR ntdb_fetch(struct ntdb_context *ntdb, NTDB_DATA key,
off = find_and_lock(ntdb, key, F_RDLCK, &h, &rec, NULL);
if (NTDB_OFF_IS_ERR(off)) {
- return ntdb->last_error = NTDB_OFF_TO_ERR(off);
+ return NTDB_OFF_TO_ERR(off);
}
if (!off) {
}
ntdb_unlock_hashes(ntdb, h.hlock_start, h.hlock_range, F_RDLCK);
- return ntdb->last_error = ecode;
+ return ecode;
}
_PUBLIC_ bool ntdb_exists(struct ntdb_context *ntdb, NTDB_DATA key)
off = find_and_lock(ntdb, key, F_RDLCK, &h, &rec, NULL);
if (NTDB_OFF_IS_ERR(off)) {
- ntdb->last_error = NTDB_OFF_TO_ERR(off);
return false;
}
ntdb_unlock_hashes(ntdb, h.hlock_start, h.hlock_range, F_RDLCK);
- ntdb->last_error = NTDB_SUCCESS;
return off ? true : false;
}
off = find_and_lock(ntdb, key, F_WRLCK, &h, &rec, NULL);
if (NTDB_OFF_IS_ERR(off)) {
- return ntdb->last_error = NTDB_OFF_TO_ERR(off);
+ return NTDB_OFF_TO_ERR(off);
}
if (!off) {
unlock:
ntdb_unlock_hashes(ntdb, h.hlock_start, h.hlock_range, F_WRLCK);
- return ntdb->last_error = ecode;
+ return ecode;
}
_PUBLIC_ unsigned int ntdb_get_flags(struct ntdb_context *ntdb)
static bool readonly_changable(struct ntdb_context *ntdb, const char *caller)
{
if (inside_transaction(ntdb)) {
- ntdb->last_error = ntdb_logerr(ntdb, NTDB_ERR_EINVAL,
- NTDB_LOG_USE_ERROR,
- "%s: can't change"
- " NTDB_RDONLY inside transaction",
- caller);
+ ntdb_logerr(ntdb, NTDB_ERR_EINVAL, NTDB_LOG_USE_ERROR,
+ "%s: can't change"
+ " NTDB_RDONLY inside transaction",
+ caller);
return false;
}
return true;
_PUBLIC_ void ntdb_add_flag(struct ntdb_context *ntdb, unsigned flag)
{
if (ntdb->flags & NTDB_INTERNAL) {
- ntdb->last_error = ntdb_logerr(ntdb, NTDB_ERR_EINVAL,
- NTDB_LOG_USE_ERROR,
- "ntdb_add_flag: internal db");
+ ntdb_logerr(ntdb, NTDB_ERR_EINVAL, NTDB_LOG_USE_ERROR,
+ "ntdb_add_flag: internal db");
return;
}
switch (flag) {
ntdb->flags |= NTDB_RDONLY;
break;
default:
- ntdb->last_error = ntdb_logerr(ntdb, NTDB_ERR_EINVAL,
- NTDB_LOG_USE_ERROR,
- "ntdb_add_flag: Unknown flag %u",
- flag);
+ ntdb_logerr(ntdb, NTDB_ERR_EINVAL, NTDB_LOG_USE_ERROR,
+ "ntdb_add_flag: Unknown flag %u", flag);
}
}
_PUBLIC_ void ntdb_remove_flag(struct ntdb_context *ntdb, unsigned flag)
{
if (ntdb->flags & NTDB_INTERNAL) {
- ntdb->last_error = ntdb_logerr(ntdb, NTDB_ERR_EINVAL,
- NTDB_LOG_USE_ERROR,
- "ntdb_remove_flag: internal db");
+ ntdb_logerr(ntdb, NTDB_ERR_EINVAL, NTDB_LOG_USE_ERROR,
+ "ntdb_remove_flag: internal db");
return;
}
switch (flag) {
break;
case NTDB_RDONLY:
if ((ntdb->open_flags & O_ACCMODE) == O_RDONLY) {
- ntdb->last_error = ntdb_logerr(ntdb, NTDB_ERR_EINVAL,
- NTDB_LOG_USE_ERROR,
- "ntdb_remove_flag: can't"
- " remove NTDB_RDONLY on ntdb"
- " opened with O_RDONLY");
+ ntdb_logerr(ntdb, NTDB_ERR_EINVAL, NTDB_LOG_USE_ERROR,
+ "ntdb_remove_flag: can't"
+ " remove NTDB_RDONLY on ntdb"
+ " opened with O_RDONLY");
break;
}
if (readonly_changable(ntdb, "ntdb_remove_flag"))
ntdb->flags &= ~NTDB_RDONLY;
break;
default:
- ntdb->last_error = ntdb_logerr(ntdb, NTDB_ERR_EINVAL,
- NTDB_LOG_USE_ERROR,
- "ntdb_remove_flag: Unknown flag %u",
- flag);
+ ntdb_logerr(ntdb, NTDB_ERR_EINVAL, NTDB_LOG_USE_ERROR,
+ "ntdb_remove_flag: Unknown flag %u",
+ flag);
}
}
return "Invalid error code";
}
-_PUBLIC_ enum NTDB_ERROR ntdb_error(struct ntdb_context *ntdb)
-{
- return ntdb->last_error;
-}
-
enum NTDB_ERROR COLD ntdb_logerr(struct ntdb_context *ntdb,
enum NTDB_ERROR ecode,
enum ntdb_log_level level,
off = find_and_lock(ntdb, key, F_RDLCK, &h, &rec, NULL);
if (NTDB_OFF_IS_ERR(off)) {
- return ntdb->last_error = NTDB_OFF_TO_ERR(off);
+ return NTDB_OFF_TO_ERR(off);
}
if (!off) {
}
ntdb_unlock_hashes(ntdb, h.hlock_start, h.hlock_range, F_RDLCK);
- return ntdb->last_error = ecode;
+ return ecode;
}
_PUBLIC_ const char *ntdb_name(const struct ntdb_context *ntdb)
_PUBLIC_ int64_t ntdb_get_seqnum(struct ntdb_context *ntdb)
{
- ntdb_off_t off;
-
- off = ntdb_read_off(ntdb, offsetof(struct ntdb_header, seqnum));
- if (NTDB_OFF_IS_ERR(off))
- ntdb->last_error = NTDB_OFF_TO_ERR(off);
- else
- ntdb->last_error = NTDB_SUCCESS;
- return off;
+ return ntdb_read_off(ntdb, offsetof(struct ntdb_header, seqnum));
}
__location__
" Failed to create tmp_db");
ntdb_transaction_cancel(ntdb);
- return ntdb->last_error = state.error;
+ return state.error;
}
state.dest_db = tmp_db;
void *data),
void *data);
-/**
- * ntdb_error - get the last error (not threadsafe)
- * @ntdb: the ntdb context returned from ntdb_open()
- *
- * Returns the last error returned by a NTDB function.
- *
- * This makes porting from TDB easier, but note that the last error is not
- * reliable in threaded programs.
- */
-enum NTDB_ERROR ntdb_error(struct ntdb_context *ntdb);
-
/**
* enum ntdb_summary_flags - flags for ntdb_summary.
*/
case NTDB_ATTRIBUTE_HASH:
case NTDB_ATTRIBUTE_SEED:
case NTDB_ATTRIBUTE_OPENHOOK:
- return ntdb->last_error
- = ntdb_logerr(ntdb, NTDB_ERR_EINVAL,
- NTDB_LOG_USE_ERROR,
- "ntdb_set_attribute:"
- " cannot set %s after opening",
- attr->base.attr == NTDB_ATTRIBUTE_HASH
- ? "NTDB_ATTRIBUTE_HASH"
- : attr->base.attr == NTDB_ATTRIBUTE_SEED
- ? "NTDB_ATTRIBUTE_SEED"
- : "NTDB_ATTRIBUTE_OPENHOOK");
+ return ntdb_logerr(ntdb, NTDB_ERR_EINVAL,
+ NTDB_LOG_USE_ERROR,
+ "ntdb_set_attribute:"
+ " cannot set %s after opening",
+ attr->base.attr == NTDB_ATTRIBUTE_HASH
+ ? "NTDB_ATTRIBUTE_HASH"
+ : attr->base.attr == NTDB_ATTRIBUTE_SEED
+ ? "NTDB_ATTRIBUTE_SEED"
+ : "NTDB_ATTRIBUTE_OPENHOOK");
case NTDB_ATTRIBUTE_STATS:
- return ntdb->last_error
- = ntdb_logerr(ntdb, NTDB_ERR_EINVAL,
- NTDB_LOG_USE_ERROR,
- "ntdb_set_attribute:"
- " cannot set NTDB_ATTRIBUTE_STATS");
+ return ntdb_logerr(ntdb, NTDB_ERR_EINVAL,
+ NTDB_LOG_USE_ERROR,
+ "ntdb_set_attribute:"
+ " cannot set NTDB_ATTRIBUTE_STATS");
case NTDB_ATTRIBUTE_FLOCK:
ntdb->lock_fn = attr->flock.lock;
ntdb->unlock_fn = attr->flock.unlock;
ntdb->lock_data = attr->flock.data;
break;
default:
- return ntdb->last_error
- = ntdb_logerr(ntdb, NTDB_ERR_EINVAL,
- NTDB_LOG_USE_ERROR,
- "ntdb_set_attribute:"
- " unknown attribute type %u",
- attr->base.attr);
+ return ntdb_logerr(ntdb, NTDB_ERR_EINVAL,
+ NTDB_LOG_USE_ERROR,
+ "ntdb_set_attribute:"
+ " unknown attribute type %u",
+ attr->base.attr);
}
return NTDB_SUCCESS;
}
switch (attr->base.attr) {
case NTDB_ATTRIBUTE_LOG:
if (!ntdb->log_fn)
- return ntdb->last_error = NTDB_ERR_NOEXIST;
+ return NTDB_ERR_NOEXIST;
attr->log.fn = ntdb->log_fn;
attr->log.data = ntdb->log_data;
break;
break;
case NTDB_ATTRIBUTE_OPENHOOK:
if (!ntdb->openhook)
- return ntdb->last_error = NTDB_ERR_NOEXIST;
+ return NTDB_ERR_NOEXIST;
attr->openhook.fn = ntdb->openhook;
attr->openhook.data = ntdb->openhook_data;
break;
attr->flock.data = ntdb->lock_data;
break;
default:
- return ntdb->last_error
- = ntdb_logerr(ntdb, NTDB_ERR_EINVAL,
- NTDB_LOG_USE_ERROR,
- "ntdb_get_attribute:"
- " unknown attribute type %u",
- attr->base.attr);
+ return ntdb_logerr(ntdb, NTDB_ERR_EINVAL,
+ NTDB_LOG_USE_ERROR,
+ "ntdb_get_attribute:"
+ " unknown attribute type %u",
+ attr->base.attr);
}
attr->base.next = NULL;
return NTDB_SUCCESS;
ntdb->flags = ntdb_flags;
ntdb->log_fn = NULL;
ntdb->open_flags = open_flags;
- ntdb->last_error = NTDB_SUCCESS;
ntdb->file = NULL;
ntdb->openhook = NULL;
ntdb->lock_fn = ntdb_fcntl_lock;
enum NTDB_ERROR (*openhook)(int fd, void *data);
void *openhook_data;
- /* Last error we returned. */
- enum NTDB_ERROR last_error;
-
/* Are we accessing directly? (debugging check). */
int direct_access;
key = PyString_AsNtdb_Data(py_key);
if (ntdb_exists(self->ctx, key))
return Py_True;
- if (ntdb_error(self->ctx) != NTDB_ERR_NOEXIST)
- PyErr_NTDB_ERROR_IS_ERR_RAISE(ntdb_error(self->ctx));
return Py_False;
}
ecode = ntdb_allrecord_lock(ntdb, F_RDLCK, NTDB_LOCK_WAIT, false);
if (ecode != NTDB_SUCCESS) {
- return ntdb->last_error = ecode;
+ return ecode;
}
ecode = ntdb_lock_expand(ntdb, F_RDLCK);
if (ecode != NTDB_SUCCESS) {
ntdb_allrecord_unlock(ntdb, F_RDLCK);
- return ntdb->last_error = ecode;
+ return ecode;
}
/* Start stats off empty. */
ntdb_allrecord_unlock(ntdb, F_RDLCK);
ntdb_unlock_expand(ntdb, F_RDLCK);
- return ntdb->last_error = ecode;
+ return ecode;
}
#include <stdbool.h>
/* FIXME: Check these! */
-#define INITIAL_NTDB_MALLOC "open.c", 403, FAILTEST_MALLOC
+#define INITIAL_NTDB_MALLOC "open.c", 399, FAILTEST_MALLOC
#define URANDOM_OPEN "open.c", 62, FAILTEST_OPEN
#define URANDOM_READ "open.c", 42, FAILTEST_READ
_exit(11);
}
-static void fatal(struct ntdb_context *ntdb, const char *why)
+static void warn_on_err(enum NTDB_ERROR e, struct ntdb_context *ntdb,
+ const char *why)
{
- fprintf(stderr, "%u:%s:%s\n", getpid(), why,
- ntdb ? ntdb_errorstr(ntdb_error(ntdb)) : "(no ntdb)");
- error_count++;
+ if (e != NTDB_SUCCESS) {
+ fprintf(stderr, "%u:%s:%s\n", getpid(), why,
+ ntdb ? ntdb_errorstr(e) : "(no ntdb)");
+ error_count++;
+ }
}
static char *randbuf(int len)
int klen, dlen;
char *k, *d;
NTDB_DATA key, data;
+ enum NTDB_ERROR e;
klen = 1 + (rand() % KEYLEN);
dlen = 1 + (rand() % DATALEN);
#if TRANSACTION_PROB
if (in_traverse == 0 && in_transaction == 0 && (always_transaction || random() % TRANSACTION_PROB == 0)) {
- if (ntdb_transaction_start(db) != 0) {
- fatal(db, "ntdb_transaction_start failed");
- }
+ e = ntdb_transaction_start(db);
+ warn_on_err(e, db, "ntdb_transaction_start failed");
in_transaction++;
goto next;
}
if (in_traverse == 0 && in_transaction && random() % TRANSACTION_PROB == 0) {
if (random() % TRANSACTION_PREPARE_PROB == 0) {
- if (ntdb_transaction_prepare_commit(db) != 0) {
- fatal(db, "ntdb_transaction_prepare_commit failed");
- }
- }
- if (ntdb_transaction_commit(db) != 0) {
- fatal(db, "ntdb_transaction_commit failed");
+ e = ntdb_transaction_prepare_commit(db);
+ warn_on_err(e, db, "ntdb_transaction_prepare_commit failed");
}
+ e = ntdb_transaction_commit(db);
+ warn_on_err(e, db, "ntdb_transaction_commit failed");
in_transaction--;
goto next;
}
#if STORE_PROB
if (random() % STORE_PROB == 0) {
- if (ntdb_store(db, key, data, NTDB_REPLACE) != 0) {
- fatal(db, "ntdb_store failed");
- }
+ e = ntdb_store(db, key, data, NTDB_REPLACE);
+ warn_on_err(e, db, "ntdb_store failed");
goto next;
}
#endif
#if APPEND_PROB
if (random() % APPEND_PROB == 0) {
- if (ntdb_append(db, key, data) != 0) {
- fatal(db, "ntdb_append failed");
- }
+ e = ntdb_append(db, key, data);
+ warn_on_err(e, db, "ntdb_append failed");
goto next;
}
#endif
data.dsize = 0;
data.dptr = NULL;
}
- if (ntdb_store(db, key, data, NTDB_REPLACE) != 0) {
- fatal(db, "ntdb_store failed");
- }
+ e = ntdb_store(db, key, data, NTDB_REPLACE);
+ warn_on_err(e, db, "ntdb_store failed");
if (data.dptr) free(data.dptr);
ntdb_chainunlock(db, key);
goto next;
db = ntdb_open(filename, ntdb_flags, O_RDWR | O_CREAT, 0600,
&log_attr);
if (!db) {
- fatal(NULL, "db open failed");
+ fprintf(stderr, "%u:%s:%s\n", getpid(), filename,
+ "db open failed");
+ exit(1);
}
#if 0
}
if (error_count == 0) {
+ enum NTDB_ERROR e;
+
ntdb_traverse(db, NULL, NULL);
#if TRANSACTION_PROB
if (always_transaction) {
ntdb_transaction_cancel(db);
in_transaction--;
}
- if (ntdb_transaction_start(db) != 0)
- fatal(db, "ntdb_transaction_start failed");
+ e = ntdb_transaction_start(db);
+ if (e) {
+ warn_on_err(e, db,
+ "ntdb_transaction_start failed");
+ exit(1);
+ }
}
#endif
ntdb_traverse(db, traverse_fn, NULL);
#if TRANSACTION_PROB
if (always_transaction) {
- if (ntdb_transaction_commit(db) != 0)
- fatal(db, "ntdb_transaction_commit failed");
+ e = ntdb_transaction_commit(db);
+ warn_on_err(e, db, "ntdb_transaction_commit failed");
}
#endif
}
int *done;
int ntdb_flags = NTDB_DEFAULT;
char *test_ntdb;
+ enum NTDB_ERROR e;
log_attr.base.attr = NTDB_ATTRIBUTE_LOG;
log_attr.base.next = &seed_attr;
db = ntdb_open(test_ntdb, NTDB_DEFAULT, O_RDWR | O_CREAT,
0600, &log_attr);
if (!db) {
- fatal(db, "db open failed");
+ fprintf(stderr, "%u:%s:%s\n", getpid(), test_ntdb,
+ "db open failed");
exit(1);
}
- if (ntdb_check(db, NULL, NULL) != 0) {
- fatal(db, "db check failed");
+ e = ntdb_check(db, NULL, NULL);
+ if (e) {
+ warn_on_err(e, db, "db check failed");
exit(1);
}
ntdb_close(db);
ntdb->stats.transactions++;
/* some sanity checks */
if (ntdb->flags & NTDB_INTERNAL) {
- return ntdb->last_error = ntdb_logerr(ntdb, NTDB_ERR_EINVAL,
- NTDB_LOG_USE_ERROR,
- "ntdb_transaction_start:"
- " cannot start a"
- " transaction on an"
- " internal ntdb");
+ return ntdb_logerr(ntdb, NTDB_ERR_EINVAL, NTDB_LOG_USE_ERROR,
+ "ntdb_transaction_start:"
+ " cannot start a transaction on an"
+ " internal ntdb");
}
if (ntdb->flags & NTDB_RDONLY) {
- return ntdb->last_error = ntdb_logerr(ntdb, NTDB_ERR_RDONLY,
- NTDB_LOG_USE_ERROR,
- "ntdb_transaction_start:"
- " cannot start a"
- " transaction on a "
- " read-only ntdb");
+ return ntdb_logerr(ntdb, NTDB_ERR_RDONLY, NTDB_LOG_USE_ERROR,
+ "ntdb_transaction_start:"
+ " cannot start a transaction on a"
+ " read-only ntdb");
}
/* cope with nested ntdb_transaction_start() calls */
if (ntdb->transaction != NULL) {
if (!(ntdb->flags & NTDB_ALLOW_NESTING)) {
- return ntdb->last_error
- = ntdb_logerr(ntdb, NTDB_ERR_IO,
- NTDB_LOG_USE_ERROR,
- "ntdb_transaction_start:"
- " already inside transaction");
+ return ntdb_logerr(ntdb, NTDB_ERR_IO,
+ NTDB_LOG_USE_ERROR,
+ "ntdb_transaction_start:"
+ " already inside transaction");
}
ntdb->transaction->nesting++;
ntdb->stats.transaction_nest++;
/* the caller must not have any locks when starting a
transaction as otherwise we'll be screwed by lack
of nested locks in POSIX */
- return ntdb->last_error = ntdb_logerr(ntdb, NTDB_ERR_LOCK,
- NTDB_LOG_USE_ERROR,
- "ntdb_transaction_start:"
- " cannot start a"
- " transaction with locks"
- " held");
+ return ntdb_logerr(ntdb, NTDB_ERR_LOCK,
+ NTDB_LOG_USE_ERROR,
+ "ntdb_transaction_start:"
+ " cannot start a transaction with locks"
+ " held");
}
ntdb->transaction = (struct ntdb_transaction *)
calloc(sizeof(struct ntdb_transaction), 1);
if (ntdb->transaction == NULL) {
- return ntdb->last_error = ntdb_logerr(ntdb, NTDB_ERR_OOM,
- NTDB_LOG_ERROR,
- "ntdb_transaction_start:"
- " cannot allocate");
+ return ntdb_logerr(ntdb, NTDB_ERR_OOM, NTDB_LOG_ERROR,
+ "ntdb_transaction_start:"
+ " cannot allocate");
}
/* get the transaction write lock. This is a blocking lock. As
if (ecode != NTDB_SUCCESS) {
SAFE_FREE(ntdb->transaction->blocks);
SAFE_FREE(ntdb->transaction);
- return ntdb->last_error = ecode;
+ return ecode;
}
/* get a read lock over entire file. This is upgraded to a write
transaction specific methods */
ntdb->transaction->io_methods = ntdb->io;
ntdb->io = &transaction_methods;
- return ntdb->last_error = NTDB_SUCCESS;
+ return NTDB_SUCCESS;
fail_allrecord_lock:
ntdb_transaction_unlock(ntdb, F_WRLCK);
SAFE_FREE(ntdb->transaction->blocks);
SAFE_FREE(ntdb->transaction);
- return ntdb->last_error = ecode;
+ return ecode;
}
*/
_PUBLIC_ enum NTDB_ERROR ntdb_transaction_prepare_commit(struct ntdb_context *ntdb)
{
- return ntdb->last_error = _ntdb_transaction_prepare_commit(ntdb);
+ return _ntdb_transaction_prepare_commit(ntdb);
}
/*
enum NTDB_ERROR ecode;
if (ntdb->transaction == NULL) {
- return ntdb->last_error = ntdb_logerr(ntdb, NTDB_ERR_EINVAL,
- NTDB_LOG_USE_ERROR,
- "ntdb_transaction_commit:"
- " no transaction");
+ return ntdb_logerr(ntdb, NTDB_ERR_EINVAL, NTDB_LOG_USE_ERROR,
+ "ntdb_transaction_commit:"
+ " no transaction");
}
ntdb_trace(ntdb, "ntdb_transaction_commit");
if (ntdb->transaction->nesting != 0) {
ntdb->transaction->nesting--;
- return ntdb->last_error = NTDB_SUCCESS;
+ return NTDB_SUCCESS;
}
/* check for a null transaction */
if (ntdb->transaction->blocks == NULL) {
_ntdb_transaction_cancel(ntdb);
- return ntdb->last_error = NTDB_SUCCESS;
+ return NTDB_SUCCESS;
}
if (!ntdb->transaction->prepared) {
ecode = _ntdb_transaction_prepare_commit(ntdb);
if (ecode != NTDB_SUCCESS) {
_ntdb_transaction_cancel(ntdb);
- return ntdb->last_error = ecode;
+ return ecode;
}
}
_ntdb_transaction_cancel(ntdb);
- return ntdb->last_error = ecode;
+ return ecode;
}
SAFE_FREE(ntdb->transaction->blocks[i]);
}
/* ensure the new data is on disk */
ecode = transaction_sync(ntdb, 0, ntdb->file->map_size);
if (ecode != NTDB_SUCCESS) {
- return ntdb->last_error = ecode;
+ return ecode;
}
/*
ntdb->transaction->old_map_size = ntdb->file->map_size;
_ntdb_transaction_cancel(ntdb);
- return ntdb->last_error = NTDB_SUCCESS;
+ return NTDB_SUCCESS;
}
count++;
if (fn && fn(ntdb, k, d, p)) {
free(k.dptr);
- ntdb->last_error = NTDB_SUCCESS;
return count;
}
free(k.dptr);
}
if (ecode != NTDB_ERR_NOEXIST) {
- return NTDB_ERR_TO_OFF(ntdb->last_error = ecode);
+ return NTDB_ERR_TO_OFF(ecode);
}
- ntdb->last_error = NTDB_SUCCESS;
return count;
}
{
struct traverse_info tinfo;
- return ntdb->last_error = first_in_hash(ntdb, &tinfo, key, NULL);
+ return first_in_hash(ntdb, &tinfo, key, NULL);
}
/* We lock twice, not very efficient. We could keep last key & tinfo cached. */
tinfo.prev = find_and_lock(ntdb, *key, F_RDLCK, &h, &rec, &tinfo);
free(key->dptr);
if (NTDB_OFF_IS_ERR(tinfo.prev)) {
- return ntdb->last_error = NTDB_OFF_TO_ERR(tinfo.prev);
+ return NTDB_OFF_TO_ERR(tinfo.prev);
}
ntdb_unlock_hashes(ntdb, h.hlock_start, h.hlock_range, F_RDLCK);
- return ntdb->last_error = next_in_hash(ntdb, &tinfo, key, NULL);
+ return next_in_hash(ntdb, &tinfo, key, NULL);
}
static int wipe_one(struct ntdb_context *ntdb,
ecode = ntdb_allrecord_lock(ntdb, F_WRLCK, NTDB_LOCK_WAIT, false);
if (ecode != NTDB_SUCCESS)
- return ntdb->last_error = ecode;
+ return ecode;
/* FIXME: Be smarter. */
count = ntdb_traverse(ntdb, wipe_one, &ecode);
if (count < 0)
ecode = NTDB_OFF_TO_ERR(count);
ntdb_allrecord_unlock(ntdb, F_WRLCK);
- return ntdb->last_error = ecode;
+ return ecode;
}