mirror of
https://github.com/samba-team/samba.git
synced 2024-12-24 21:34:56 +03:00
tdb_compat: make tdb2s temporarily read-only for tdb_traverse_read()
It doesn't make a difference unless the tdb2 opens a TDB1 on disk, in which case tdb1_traverse() takes a write lock on the entire file. By setting the tdb to read-only first, we simulate the old behaviour. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
bdc5499205
commit
73e4f35e3d
@ -38,6 +38,26 @@ enum TDB_ERROR tdb_transaction_start_nonblock(struct tdb_context *tdb)
|
||||
return ecode;
|
||||
}
|
||||
|
||||
/* For TDB1 tdbs, read traverse vs normal matters: write traverse
|
||||
locks the entire thing! */
|
||||
int64_t tdb_traverse_read_(struct tdb_context *tdb,
|
||||
int (*fn)(struct tdb_context *,
|
||||
TDB_DATA, TDB_DATA,
|
||||
void *),
|
||||
void *p)
|
||||
{
|
||||
int64_t ret;
|
||||
|
||||
if (tdb_get_flags(tdb) & TDB_RDONLY) {
|
||||
return tdb_traverse(tdb, fn, p);
|
||||
}
|
||||
|
||||
tdb_add_flag(tdb, TDB_RDONLY);
|
||||
ret = tdb_traverse(tdb, fn, p);
|
||||
tdb_remove_flag(tdb, TDB_RDONLY);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* This handles TDB_CLEAR_IF_FIRST.
|
||||
*/
|
||||
|
@ -62,8 +62,13 @@ static inline TDB_DATA tdb_nextkey_compat(struct tdb_context *tdb, TDB_DATA k)
|
||||
return k;
|
||||
}
|
||||
|
||||
/* tdb_traverse_read and tdb_traverse are equal: both only take read locks. */
|
||||
#define tdb_traverse_read tdb_traverse
|
||||
#define tdb_traverse_read(tdb, fn, p) \
|
||||
tdb_traverse_read_(tdb, typesafe_cb_preargs(int, void *, (fn), (p), \
|
||||
struct tdb_context *, \
|
||||
TDB_DATA, TDB_DATA), (p))
|
||||
int64_t tdb_traverse_read_(struct tdb_context *tdb,
|
||||
int (*fn)(struct tdb_context *,
|
||||
TDB_DATA, TDB_DATA, void *), void *p);
|
||||
|
||||
/* Old-style tdb_errorstr */
|
||||
#define tdb_errorstr_compat(tdb) tdb_errorstr(tdb_error(tdb))
|
||||
|
Loading…
Reference in New Issue
Block a user