[SSSD] [PATCH] IPA: add callback to reset subdomain timeouts

Sumit Bose sbose at redhat.com
Mon Oct 21 12:54:24 UTC 2013


Hi,

these two patches are the SSSD part to fix
https://fedorahosted.org/sssd/ticket/2030 . To reset the timeouts I
introduced a new callback type which is always executed if SIGUSR2 (go
online immediately) is received in contrast to the default online
callback which are only executed if the backend was offline before.

If the patch are accepted I will send corresponding ones to FreeIPA to
send the signal if 'ipa trust-add' is run as root.

bye,
Sumit
-------------- next part --------------
From 93ca2029e95ccef3b43dcc5620b168e8844e2ced Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Mon, 21 Oct 2013 13:37:37 +0200
Subject: [PATCH 1/2] 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.
---
 src/providers/data_provider_be.c        |  2 ++
 src/providers/data_provider_callbacks.c | 40 +++++++++++++++++++++++++++++++++
 src/providers/dp_backend.h              |  9 ++++++++
 3 files changed, 51 insertions(+)

diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index 6b58d88..39f9c69 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..22e8764 100644
--- a/src/providers/data_provider_callbacks.c
+++ b/src/providers/data_provider_callbacks.c
@@ -231,6 +231,46 @@ 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)
+{
+    int ret;
+
+    ret = be_add_cb(mem_ctx, ctx, cb, pvt, &ctx->unconditional_online_cb_list,
+                    unconditional_online_cb);
+    if (ret != EOK) {
+        DEBUG(SSSDBG_OP_FAILURE, ("be_add_cb failed.\n"));
+        return ret;
+    }
+
+    /* Make sure we run the callback for the first
+     * connection after startup.
+     */
+    ctx->run_online_cb = true;
+
+    return EOK;
+}
+
+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,
-- 
1.8.3.1

-------------- next part --------------
From 671559f98bdd3b79468548e39a72373cc4e6fc04 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Mon, 21 Oct 2013 14:02:57 +0200
Subject: [PATCH 2/2] IPA: add callback to reset subdomain timeouts

Fixes https://fedorahosted.org/sssd/ticket/2030
---
 src/providers/ipa/ipa_subdomains.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/providers/ipa/ipa_subdomains.c b/src/providers/ipa/ipa_subdomains.c
index ea55f70..d6cb0c6 100644
--- a/src/providers/ipa/ipa_subdomains.c
+++ b/src/providers/ipa/ipa_subdomains.c
@@ -1106,6 +1106,21 @@ static void ipa_subdom_be_req_callback(struct be_req *be_req,
     talloc_free(be_req);
 }
 
+static void ipa_subdom_reset_timeouts_cb(void *pvt)
+{
+    struct ipa_subdomains_ctx *ctx;
+
+    ctx = talloc_get_type(pvt, struct ipa_subdomains_ctx);
+    if (ctx == NULL) {
+        DEBUG(SSSDBG_CRIT_FAILURE, ("Bad private pointer\n"));
+        return;
+    }
+
+    DEBUG(SSSDBG_TRACE_ALL, ("Resetting last_refreshed and disabled_until.\n"));
+    ctx->last_refreshed = 0;
+    ctx->disabled_until = 0;
+}
+
 static void ipa_subdom_online_cb(void *pvt)
 {
     struct ipa_subdomains_ctx *ctx;
@@ -1252,6 +1267,14 @@ int ipa_subdom_init(struct be_ctx *be_ctx,
     *ops = &ipa_subdomains_ops;
     *pvt_data = ctx;
 
+    ret = be_add_unconditional_online_cb(ctx, be_ctx,
+                                         ipa_subdom_reset_timeouts_cb, ctx,
+                                         NULL);
+    if (ret != EOK) {
+        DEBUG(SSSDBG_MINOR_FAILURE,
+              ("Failed to add subdom reset timeouts callback"));
+    }
+
     ret = be_add_online_cb(ctx, be_ctx, ipa_subdom_online_cb, ctx, NULL);
     if (ret != EOK) {
         DEBUG(SSSDBG_MINOR_FAILURE, ("Failed to add subdom online callback"));
-- 
1.8.3.1



More information about the sssd-devel mailing list