From: Ralph Boehme Date: Tue, 3 Dec 2024 11:21:38 +0000 (+0100) Subject: ctdb-daemon: Implement CTDB_CONTROL_PUSH_RECORD X-Git-Tag: talloc-2.5.0~250 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=07905d9490fcc448a6be0277da3216d0dde8e4ec;p=thirdparty%2Fsamba.git ctdb-daemon: Implement CTDB_CONTROL_PUSH_RECORD Pair-Programmed-With: Martin Schwenke Signed-off-by: Martin Schwenke Signed-off-by: Ralph Boehme --- diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index a79c466c177..9b32feb008b 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -592,6 +592,8 @@ int32_t ctdb_control_register_notify(struct ctdb_context *ctdb, int32_t ctdb_control_deregister_notify(struct ctdb_context *ctdb, uint32_t client_id, TDB_DATA indata); +int32_t ctdb_control_push_record(struct ctdb_context *ctdb, TDB_DATA indata); + struct ctdb_client *ctdb_find_client_by_pid(struct ctdb_context *ctdb, pid_t pid); diff --git a/ctdb/server/ctdb_control.c b/ctdb/server/ctdb_control.c index a51795f340a..00a90774895 100644 --- a/ctdb/server/ctdb_control.c +++ b/ctdb/server/ctdb_control.c @@ -880,6 +880,9 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb, CHECK_CONTROL_DATA_SIZE(0); return ctdb_control_start_ipreallocate(ctdb, c, async_reply); + case CTDB_CONTROL_PUSH_RECORD: + return ctdb_control_push_record(ctdb, indata); + default: DEBUG(DEBUG_CRIT,(__location__ " Unknown CTDB control opcode %u\n", opcode)); return -1; diff --git a/ctdb/server/ctdb_daemon.c b/ctdb/server/ctdb_daemon.c index bb6d504335a..97872eaaa82 100644 --- a/ctdb/server/ctdb_daemon.c +++ b/ctdb/server/ctdb_daemon.c @@ -2115,6 +2115,60 @@ int32_t ctdb_control_deregister_notify(struct ctdb_context *ctdb, uint32_t clien return 0; } +int32_t ctdb_control_push_record(struct ctdb_context *ctdb, + TDB_DATA indata) +{ + struct ctdb_push_record_data *data = NULL; + struct ctdb_db_context *ctdb_db = NULL; + size_t np = 0; + int ret = 0; + + ret = ctdb_push_record_data_pull(indata.dptr, + indata.dsize, + ctdb, + &data, + &np); + if (ret != 0) { + DBG_ERR("Invalid data\n"); + return -1; + } + + if (ctdb->vnn_map->generation != data->generation) { + DBG_INFO("Ignoring outdated push-record\n"); + return 0; + } + + /* + * Do not store on the dmaster. This will have already been + * written by smbd. Storing here would overwrite the already + * written record, which has an incremented RSN. + */ + if (data->hdr.dmaster == ctdb->pnn) { + return 0; + } + + + ctdb_db = find_ctdb_db(ctdb, data->db_id); + if (ctdb_db == NULL) { + DBG_ERR(" Unknown db id 0x%08x\n", data->db_id); + return -1; + } + + data->hdr.flags |= CTDB_REC_FLAG_MIGRATED_WITH_DATA; + + ret = ctdb_ltdb_store(ctdb_db, data->key, &data->hdr, data->value); + if (ret != 0) { + return -1; + } + + ret = ctdb_ltdb_sync(ctdb_db); + if (ret != 0) { + return -1; + } + + return 0; +} + struct ctdb_client *ctdb_find_client_by_pid(struct ctdb_context *ctdb, pid_t pid) { struct ctdb_client_pid_list *client_pid;