From 0a320004a9937295ba66a348d1e60682cfdceb26 Mon Sep 17 00:00:00 2001 From: Sumit Bose Date: Oct 22 2013 17:11:36 +0000 Subject: Add unconditional online callbacks Currently online callbacks are only executed if the backend was offline before. This patch add a new class of callback which are always called if the backend gets a request to go online. They can be used e.g. to reset timeouts until a more sophisticated method (OpenLMI, sssctl) is available. --- diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c index e7037d8..a0b2758 100644 --- a/src/providers/data_provider_be.c +++ b/src/providers/data_provider_be.c @@ -2209,6 +2209,8 @@ static void check_if_online(struct be_ctx *ctx) int ret; struct be_req *be_req = NULL; + be_run_unconditional_online_cb(ctx); + if (ctx->offstat.offline == false) { DEBUG(8, ("Backend is already online, nothing to do.\n")); return; diff --git a/src/providers/data_provider_callbacks.c b/src/providers/data_provider_callbacks.c index c41595e..cc50be6 100644 --- a/src/providers/data_provider_callbacks.c +++ b/src/providers/data_provider_callbacks.c @@ -231,6 +231,33 @@ void be_run_online_cb(struct be_ctx *be) { } } +int be_add_unconditional_online_cb(TALLOC_CTX *mem_ctx, struct be_ctx *ctx, + be_callback_t cb, void *pvt, + struct be_cb **unconditional_online_cb) +{ + return be_add_cb(mem_ctx, ctx, cb, pvt, &ctx->unconditional_online_cb_list, + unconditional_online_cb); +} + +void be_run_unconditional_online_cb(struct be_ctx *be) +{ + int ret; + + if (be->unconditional_online_cb_list) { + DEBUG(SSSDBG_TRACE_FUNC, ("Running unconditional online callbacks.\n")); + + ret = be_run_cb(be, be->unconditional_online_cb_list); + if (ret != EOK) { + DEBUG(SSSDBG_OP_FAILURE, ("be_run_cb failed.\n")); + } + + } else { + DEBUG(SSSDBG_TRACE_ALL, + ("List of unconditional online callbacks is empty, " \ + "nothing to do.\n")); + } +} + int be_add_offline_cb(TALLOC_CTX *mem_ctx, struct be_ctx *ctx, be_callback_t cb, void *pvt, struct be_cb **offline_cb) { diff --git a/src/providers/dp_backend.h b/src/providers/dp_backend.h index 76590a3..fc71b60 100644 --- a/src/providers/dp_backend.h +++ b/src/providers/dp_backend.h @@ -126,6 +126,11 @@ struct be_ctx { bool run_online_cb; struct be_cb *offline_cb_list; struct be_cb *reconnect_cb_list; + /* In contrast to online_cb_list which are only run if the backend is + * offline the unconditional_online_cb_list should be run whenever the + * backend receives a request to go online. The typical use case is to + * reset timers independenly of the state of the backend. */ + struct be_cb *unconditional_online_cb_list; struct be_offline_status offstat; @@ -200,6 +205,10 @@ int be_add_online_cb(TALLOC_CTX *mem_ctx, void *pvt, struct be_cb **online_cb); void be_run_online_cb(struct be_ctx *be); +int be_add_unconditional_online_cb(TALLOC_CTX *mem_ctx, struct be_ctx *ctx, + be_callback_t cb, void *pvt, + struct be_cb **unconditional_online_cb); +void be_run_unconditional_online_cb(struct be_ctx *be); int be_add_offline_cb(TALLOC_CTX *mem_ctx, struct be_ctx *ctx, diff --git a/src/providers/ldap/sdap_id_op.c b/src/providers/ldap/sdap_id_op.c index be25b5d..52cf785 100644 --- a/src/providers/ldap/sdap_id_op.c +++ b/src/providers/ldap/sdap_id_op.c @@ -692,6 +692,7 @@ static void sdap_id_op_connect_done(struct tevent_req *subreq) conn_cache->cached_connection = conn_data; /* Run any post-connection routines */ + be_run_unconditional_online_cb(conn_cache->id_conn->id_ctx->be); be_run_online_cb(conn_cache->id_conn->id_ctx->be); } else {