mirror of
https://github.com/samba-team/samba.git
synced 2025-01-03 01:18:10 +03:00
dbwrap: Simplify dbwrap_change_int32_atomic_action()
Use dbwrap_do_locked() Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
parent
ad0986652d
commit
0382e07222
@ -257,49 +257,59 @@ struct dbwrap_change_int32_atomic_context {
|
||||
TDB_DATA key;
|
||||
int32_t *oldval;
|
||||
int32_t change_val;
|
||||
NTSTATUS status;
|
||||
};
|
||||
|
||||
static NTSTATUS dbwrap_change_int32_atomic_action(struct db_context *db,
|
||||
void *private_data)
|
||||
static void dbwrap_change_int32_atomic_action_fn(struct db_record *rec,
|
||||
TDB_DATA value,
|
||||
void *private_data)
|
||||
{
|
||||
struct db_record *rec;
|
||||
struct dbwrap_change_int32_atomic_context *state = private_data;
|
||||
uint8_t v_store[4];
|
||||
TDB_DATA data = {
|
||||
.dptr = v_store,
|
||||
.dsize = sizeof(v_store),
|
||||
};
|
||||
int32_t val = -1;
|
||||
int32_t v_store;
|
||||
NTSTATUS ret;
|
||||
struct dbwrap_change_int32_atomic_context *state;
|
||||
TDB_DATA value;
|
||||
|
||||
state = (struct dbwrap_change_int32_atomic_context *)private_data;
|
||||
|
||||
rec = dbwrap_fetch_locked(db, talloc_tos(), state->key);
|
||||
if (!rec) {
|
||||
return NT_STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
value = dbwrap_record_get_value(rec);
|
||||
|
||||
if (value.dptr == NULL) {
|
||||
val = *(state->oldval);
|
||||
} else if (value.dsize == sizeof(val)) {
|
||||
val = IVAL(value.dptr, 0);
|
||||
val = PULL_LE_U32(value.dptr, 0);
|
||||
*(state->oldval) = val;
|
||||
} else {
|
||||
ret = NT_STATUS_UNSUCCESSFUL;
|
||||
goto done;
|
||||
state->status = NT_STATUS_UNSUCCESSFUL;
|
||||
return;
|
||||
}
|
||||
|
||||
val += state->change_val;
|
||||
PUSH_LE_U32(v_store, 0, val);
|
||||
|
||||
SIVAL(&v_store, 0, val);
|
||||
state->status = dbwrap_record_store(rec, data, TDB_REPLACE);
|
||||
}
|
||||
|
||||
ret = dbwrap_record_store(rec,
|
||||
make_tdb_data((const uint8_t *)&v_store,
|
||||
sizeof(v_store)),
|
||||
TDB_REPLACE);
|
||||
static NTSTATUS dbwrap_change_int32_atomic_action(struct db_context *db,
|
||||
void *private_data)
|
||||
{
|
||||
struct dbwrap_change_int32_atomic_context *state = private_data;
|
||||
NTSTATUS status;
|
||||
|
||||
done:
|
||||
TALLOC_FREE(rec);
|
||||
return ret;
|
||||
status = dbwrap_do_locked(db,
|
||||
state->key,
|
||||
dbwrap_change_int32_atomic_action_fn,
|
||||
state);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
DBG_DEBUG("dbwrap_do_locked() failed: %s\n",
|
||||
nt_errstr(status));
|
||||
return status;
|
||||
}
|
||||
if (!NT_STATUS_IS_OK(state->status)) {
|
||||
DBG_DEBUG("dbwrap_change_int32_atomic_action_fn() "
|
||||
"failed: %s\n",
|
||||
nt_errstr(status));
|
||||
return status;
|
||||
}
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
|
||||
NTSTATUS dbwrap_change_int32_atomic(struct db_context *db,
|
||||
|
Loading…
Reference in New Issue
Block a user