1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-05 09:18:06 +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:
Volker Lendecke 2023-07-13 01:19:43 +02:00 committed by Jeremy Allison
parent ad0986652d
commit 0382e07222

View File

@ -257,49 +257,59 @@ struct dbwrap_change_int32_atomic_context {
TDB_DATA key; TDB_DATA key;
int32_t *oldval; int32_t *oldval;
int32_t change_val; int32_t change_val;
NTSTATUS status;
}; };
static NTSTATUS dbwrap_change_int32_atomic_action(struct db_context *db, static void dbwrap_change_int32_atomic_action_fn(struct db_record *rec,
TDB_DATA value,
void *private_data) 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 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) { if (value.dptr == NULL) {
val = *(state->oldval); val = *(state->oldval);
} else if (value.dsize == sizeof(val)) { } else if (value.dsize == sizeof(val)) {
val = IVAL(value.dptr, 0); val = PULL_LE_U32(value.dptr, 0);
*(state->oldval) = val; *(state->oldval) = val;
} else { } else {
ret = NT_STATUS_UNSUCCESSFUL; state->status = NT_STATUS_UNSUCCESSFUL;
goto done; return;
} }
val += state->change_val; 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, static NTSTATUS dbwrap_change_int32_atomic_action(struct db_context *db,
make_tdb_data((const uint8_t *)&v_store, void *private_data)
sizeof(v_store)), {
TDB_REPLACE); struct dbwrap_change_int32_atomic_context *state = private_data;
NTSTATUS status;
done: status = dbwrap_do_locked(db,
TALLOC_FREE(rec); state->key,
return ret; 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, NTSTATUS dbwrap_change_int32_atomic(struct db_context *db,