static NTSTATUS g_lock_store(
struct db_record *rec,
struct g_lock *lck,
- struct server_id *new_shared)
+ struct server_id *new_shared,
+ const TDB_DATA *new_dbufs,
+ size_t num_new_dbufs)
{
uint8_t exclusive[SERVER_ID_BUF_LENGTH];
uint8_t seqnum_buf[sizeof(uint64_t)];
uint8_t sizebuf[sizeof(uint32_t)];
uint8_t new_shared_buf[SERVER_ID_BUF_LENGTH];
- struct TDB_DATA dbufs[] = {
- { .dptr = exclusive, .dsize = sizeof(exclusive) },
- { .dptr = seqnum_buf, .dsize = sizeof(seqnum_buf) },
- { .dptr = sizebuf, .dsize = sizeof(sizebuf) },
- { .dptr = lck->shared,
- .dsize = lck->num_shared * SERVER_ID_BUF_LENGTH },
- { 0 },
- { .dptr = lck->data, .dsize = lck->datalen }
+ struct TDB_DATA dbufs[6 + num_new_dbufs];
+
+ dbufs[0] = (TDB_DATA) {
+ .dptr = exclusive, .dsize = sizeof(exclusive),
+ };
+ dbufs[1] = (TDB_DATA) {
+ .dptr = seqnum_buf, .dsize = sizeof(seqnum_buf),
+ };
+ dbufs[2] = (TDB_DATA) {
+ .dptr = sizebuf, .dsize = sizeof(sizebuf),
+ };
+ dbufs[3] = (TDB_DATA) {
+ .dptr = lck->shared,
+ .dsize = lck->num_shared * SERVER_ID_BUF_LENGTH,
};
+ dbufs[4] = (TDB_DATA) { 0 };
+ dbufs[5] = (TDB_DATA) {
+ .dptr = lck->data, .dsize = lck->datalen,
+ };
+
+ if (num_new_dbufs != 0) {
+ memcpy(&dbufs[6],
+ new_dbufs,
+ num_new_dbufs * sizeof(TDB_DATA));
+ }
server_id_put(exclusive, lck->exclusive);
SBVAL(seqnum_buf, 0, lck->data_seqnum);
}
if (modified) {
- status = g_lock_store(rec, lck, NULL);
+ status = g_lock_store(rec, lck, NULL, NULL, 0);
if (!NT_STATUS_IS_OK(status)) {
DBG_DEBUG("g_lock_store() failed: %s\n",
nt_errstr(status));
lck.exclusive = self;
- status = g_lock_store(rec, &lck, NULL);
+ status = g_lock_store(rec, &lck, NULL, NULL, 0);
if (!NT_STATUS_IS_OK(status)) {
DBG_DEBUG("g_lock_store() failed: %s\n",
nt_errstr(status));
do_shared:
if (lck.num_shared == 0) {
- status = g_lock_store(rec, &lck, &self);
+ status = g_lock_store(rec, &lck, &self, NULL, 0);
if (!NT_STATUS_IS_OK(status)) {
DBG_DEBUG("g_lock_store() failed: %s\n",
nt_errstr(status));
g_lock_cleanup_shared(&lck);
- status = g_lock_store(rec, &lck, &self);
+ status = g_lock_store(rec, &lck, &self, NULL, 0);
if (!NT_STATUS_IS_OK(status)) {
DBG_DEBUG("g_lock_store() failed: %s\n",
nt_errstr(status));
goto not_granted;
}
lck.exclusive = state->me;
- state->status = g_lock_store(rec, &lck, NULL);
+ state->status = g_lock_store(rec, &lck, NULL, NULL, 0);
return;
}
if (state->type == G_LOCK_READ) {
g_lock_cleanup_shared(&lck);
- state->status = g_lock_store(rec, &lck, &state->me);
+ state->status = g_lock_store(rec, &lck, &state->me, NULL, 0);
return;
}
return;
}
- state->status = g_lock_store(rec, &lck, NULL);
+ state->status = g_lock_store(rec, &lck, NULL, NULL, 0);
}
NTSTATUS g_lock_unlock(struct g_lock_ctx *ctx, TDB_DATA key)
lck.data_seqnum += 1;
lck.data = discard_const_p(uint8_t, state->data);
lck.datalen = state->datalen;
- state->status = g_lock_store(rec, &lck, NULL);
+ state->status = g_lock_store(rec, &lck, NULL, NULL, 0);
}
NTSTATUS g_lock_write_data(struct g_lock_ctx *ctx, TDB_DATA key,
lck.data_seqnum += 1;
- status = g_lock_store(rec, &lck, NULL);
+ status = g_lock_store(rec, &lck, NULL, NULL, 0);
if (!NT_STATUS_IS_OK(status)) {
DBG_WARNING("g_lock_store failed: %s\n", nt_errstr(status));
return;