static int tdb_write(struct tdb_context *tdb, tdb_off_t off,
const void *buf, tdb_len_t len)
{
- if (tdb->read_only) {
+ if (tdb->read_only || tdb->traverse_read) {
tdb->ecode = TDB_ERR_RDONLY;
return -1;
}
{
char buf[1024];
- if (tdb->read_only) {
+ if (tdb->read_only || tdb->traverse_read) {
tdb->ecode = TDB_ERR_RDONLY;
return -1;
}
return 0;
}
- if ((rw_type == F_WRLCK) && (tdb->read_only)) {
+ if ((rw_type == F_WRLCK) && (tdb->read_only || tdb->traverse_read)) {
tdb->ecode = TDB_ERR_RDONLY;
return -1;
}
u32 i;
/* There are no locks on read-only dbs */
- if (tdb->read_only)
+ if (tdb->read_only || tdb->traverse_read)
return TDB_ERRCODE(TDB_ERR_LOCK, -1);
for (i = 0; i < tdb->header.hash_size; i++)
if (tdb_lock(tdb, i, F_WRLCK))
tdb_off_t last_ptr, i;
struct list_struct lastrec;
- if (tdb->read_only) return -1;
+ if (tdb->read_only || tdb->traverse_read) return -1;
if (tdb_write_lock_record(tdb, rec_ptr) == -1) {
/* Someone traversing here: mark it as dead */
char *p = NULL;
int ret = 0;
- if (tdb->read_only) {
+ if (tdb->read_only || tdb->traverse_read) {
tdb->ecode = TDB_ERR_RDONLY;
return -1;
}
int fd; /* open file descriptor for the database */
tdb_len_t map_size; /* how much space has been mapped */
int read_only; /* opened read-only */
+ int traverse_read; /* read-only traversal */
struct tdb_lock_type *locked; /* array of chain locks */
enum TDB_ERROR ecode; /* error code for last tdb error */
struct tdb_header header; /* a cached copy of the header */
int tdb_transaction_start(struct tdb_context *tdb)
{
/* some sanity checks */
- if (tdb->read_only || (tdb->flags & TDB_INTERNAL)) {
+ if (tdb->read_only || (tdb->flags & TDB_INTERNAL) || tdb->traverse_read) {
TDB_LOG((tdb, 0, "tdb_transaction_start: cannot start a transaction on a read-only or internal db\n"));
tdb->ecode = TDB_ERR_EINVAL;
return -1;
/* Try to clean dead ones from old traverses */
current = tlock->off;
tlock->off = rec->next;
- if (!tdb->read_only &&
+ if (!(tdb->read_only || tdb->traverse_read) &&
tdb_do_delete(tdb, current, rec) != 0)
goto fail;
}
tdb_traverse_func fn, void *private)
{
struct tdb_traverse_lock tl = { NULL, 0, 0, F_RDLCK };
- int ret, read_only = tdb->read_only;
- tdb->read_only = 1;
+ int ret;
+ tdb->traverse_read++;
ret = tdb_traverse_internal(tdb, fn, private, &tl);
- tdb->read_only = read_only;
+ tdb->traverse_read--;
return ret;
}
struct tdb_traverse_lock tl = { NULL, 0, 0, F_WRLCK };
int ret;
- if (tdb->read_only) {
+ if (tdb->read_only || tdb->traverse_read) {
return tdb_traverse_read(tdb, fn, private);
}