From: Ralph Boehme Date: Mon, 4 Nov 2024 06:54:19 +0000 (+0100) Subject: dbwrap: add record flags to struct db_record X-Git-Tag: talloc-2.5.0~238 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6a88642c8ed95f5ce9f6c1326f15b4bcfe6dd4f0;p=thirdparty%2Fsamba.git dbwrap: add record flags to struct db_record This is needed to implement persistent record deletion in the case that a record was stored as persistent, then fetched and is then stored without persistency. The additional tdb record header uses CTDB_REC_FLAG_PERSISTENT to denote if the record was stored as persistent. When fetching a record we remember the persistency property in record.flags.persistent. When a subsequent store doesn't request persistency and record.flags.persistent is set, we delete record from the persistent database. Signed-off-by: Ralph Boehme Reviewed-by: Martin Schwenke --- diff --git a/lib/dbwrap/dbwrap.h b/lib/dbwrap/dbwrap.h index 67569083765..b1127bc612e 100644 --- a/lib/dbwrap/dbwrap.h +++ b/lib/dbwrap/dbwrap.h @@ -70,6 +70,10 @@ enum dbwrap_req_state { DBWRAP_REQ_ERROR }; +struct db_record_flags { + bool persistent : 1; +}; + /* The following definitions come from lib/dbwrap.c */ TDB_DATA dbwrap_record_get_key(const struct db_record *rec); diff --git a/lib/dbwrap/dbwrap_private.h b/lib/dbwrap/dbwrap_private.h index 3ac5ebf97a1..3dc7bb20e45 100644 --- a/lib/dbwrap/dbwrap_private.h +++ b/lib/dbwrap/dbwrap_private.h @@ -33,6 +33,7 @@ struct db_record { NTSTATUS (*storev)(struct db_record *rec, const TDB_DATA *dbufs, int num_dbufs, int flag); NTSTATUS (*delete_rec)(struct db_record *rec); + struct db_record_flags flags; void *private_data; }; diff --git a/lib/dbwrap/dbwrap_rbt.c b/lib/dbwrap/dbwrap_rbt.c index 89d30bb3232..6cd8d936db6 100644 --- a/lib/dbwrap/dbwrap_rbt.c +++ b/lib/dbwrap/dbwrap_rbt.c @@ -380,6 +380,7 @@ static struct db_record *db_rbt_fetch_locked(struct db_context *db_ctx, rec_priv = (struct db_rbt_rec *) ((char *)result + DBWRAP_RBT_ALIGN(sizeof(struct db_record))); + result->flags = (struct db_record_flags) {}; result->storev = db_rbt_storev; result->delete_rec = db_rbt_delete; result->private_data = rec_priv; diff --git a/lib/dbwrap/dbwrap_tdb.c b/lib/dbwrap/dbwrap_tdb.c index 6cd95fa25ad..582cea6b97f 100644 --- a/lib/dbwrap/dbwrap_tdb.c +++ b/lib/dbwrap/dbwrap_tdb.c @@ -95,6 +95,7 @@ static int db_tdb_fetchlock_parse(TDB_DATA key, TDB_DATA data, } state->result = result; + result->flags = (struct db_record_flags) {}; result->key.dsize = key.dsize; result->key.dptr = ((uint8_t *)result) + sizeof(struct db_record); memcpy(result->key.dptr, key.dptr, key.dsize); diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c index 807b7f52248..65e710e552d 100644 --- a/source3/lib/dbwrap/dbwrap_ctdb.c +++ b/source3/lib/dbwrap/dbwrap_ctdb.c @@ -1107,6 +1107,7 @@ static struct db_record *fetch_locked_internal(struct db_ctdb_ctx *ctx, return NULL; } + result->flags = (struct db_record_flags) {}; result->db = ctx->db; result->private_data = (void *)crec; crec->ctdb_ctx = ctx;