dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0001-Providers-Delay-online-check-on-startup.patch

841ac7
From dab55626ce859dd519fe108b89fa723a38fb21d1 Mon Sep 17 00:00:00 2001
841ac7
From: Tomas Halman <thalman@redhat.com>
841ac7
Date: Wed, 20 Mar 2019 15:44:02 +0100
841ac7
Subject: [PATCH] Providers: Delay online check on startup
841ac7
841ac7
Typical usecase is system startup or network restart. In such
841ac7
cases SSSD receives several messages from the system about
841ac7
network change and immediately starts connecting.
841ac7
With multiple addresses on interface or multiple interfaces
841ac7
SSSD receives even more messages.
841ac7
841ac7
This patch introduces 1s delay for online check after first
841ac7
message.
841ac7
841ac7
Online callback tries 3 times to go online. There is increasing
841ac7
delay between online checks up to 4s.
841ac7
841ac7
Resolves: https://pagure.io/SSSD/sssd/issue/3467
841ac7
841ac7
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
841ac7
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
841ac7
(cherry picked from commit fe4288088e6cccf7650e5c5def3bd67be90756be)
841ac7
---
841ac7
 src/providers/backend.h          |  1 +
841ac7
 src/providers/data_provider_be.c | 94 ++++++++++++++++++++++++--------
841ac7
 2 files changed, 72 insertions(+), 23 deletions(-)
841ac7
841ac7
diff --git a/src/providers/backend.h b/src/providers/backend.h
841ac7
index 1fe1c2313..5ab47b29a 100644
841ac7
--- a/src/providers/backend.h
841ac7
+++ b/src/providers/backend.h
841ac7
@@ -112,6 +112,7 @@ struct be_ctx {
841ac7
     struct be_refresh_ctx *refresh_ctx;
841ac7
 
841ac7
     size_t check_online_ref_count;
841ac7
+    int check_online_retry_delay;
841ac7
 
841ac7
     struct data_provider *provider;
841ac7
 
841ac7
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
841ac7
index fad6f2801..17513111c 100644
841ac7
--- a/src/providers/data_provider_be.c
841ac7
+++ b/src/providers/data_provider_be.c
841ac7
@@ -50,6 +50,9 @@
841ac7
 #include "resolv/async_resolv.h"
841ac7
 #include "monitor/monitor_interfaces.h"
841ac7
 
841ac7
+#define ONLINE_CB_RETRY 3
841ac7
+#define ONLINE_CB_RETRY_MAX_DELAY 4
841ac7
+
841ac7
 static int data_provider_res_init(struct sbus_request *dbus_req, void *data);
841ac7
 static int data_provider_go_offline(struct sbus_request *dbus_req, void *data);
841ac7
 static int data_provider_reset_offline(struct sbus_request *dbus_req, void *data);
841ac7
@@ -71,7 +74,7 @@ bool be_is_offline(struct be_ctx *ctx)
841ac7
     return ctx->offstat.offline;
841ac7
 }
841ac7
 
841ac7
-static void check_if_online(struct be_ctx *be_ctx);
841ac7
+static void check_if_online(struct be_ctx *be_ctx, int delay);
841ac7
 
841ac7
 static errno_t
841ac7
 try_to_go_online(TALLOC_CTX *mem_ctx,
841ac7
@@ -82,7 +85,7 @@ try_to_go_online(TALLOC_CTX *mem_ctx,
841ac7
 {
841ac7
     struct be_ctx *ctx = (struct be_ctx*) be_ctx_void;
841ac7
 
841ac7
-    check_if_online(ctx);
841ac7
+    check_if_online(ctx, 0);
841ac7
     return EOK;
841ac7
 }
841ac7
 
841ac7
@@ -247,10 +250,39 @@ static errno_t be_check_online_request(struct be_ctx *be_ctx)
841ac7
     return EOK;
841ac7
 }
841ac7
 
841ac7
+static void check_if_online_delayed(struct tevent_context *ev,
841ac7
+                                    struct tevent_timer *tim,
841ac7
+                                    struct timeval current_time,
841ac7
+                                    void *private_data)
841ac7
+{
841ac7
+    errno_t ret;
841ac7
+    struct be_ctx *be_ctx = talloc_get_type(private_data, struct be_ctx);
841ac7
+
841ac7
+    be_run_unconditional_online_cb(be_ctx);
841ac7
+
841ac7
+    if (!be_is_offline(be_ctx)) {
841ac7
+        DEBUG(SSSDBG_TRACE_INTERNAL,
841ac7
+              "Backend is already online, nothing to do.\n");
841ac7
+        be_ctx->check_online_ref_count = 0;
841ac7
+        return;
841ac7
+    }
841ac7
+
841ac7
+    DEBUG(SSSDBG_TRACE_INTERNAL, "Trying to go back online!\n");
841ac7
+
841ac7
+    ret = be_check_online_request(be_ctx);
841ac7
+    if (ret != EOK) {
841ac7
+        DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create check online req.\n");
841ac7
+    } else {
841ac7
+        DEBUG(SSSDBG_TRACE_INTERNAL, "Check online req created.\n");
841ac7
+    }
841ac7
+}
841ac7
+
841ac7
 static void be_check_online_done(struct tevent_req *req)
841ac7
 {
841ac7
     struct be_ctx *be_ctx;
841ac7
     struct dp_reply_std *reply;
841ac7
+    struct tevent_timer *time_event;
841ac7
+    struct timeval schedule;
841ac7
     errno_t ret;
841ac7
 
841ac7
     be_ctx = tevent_req_callback_data(req, struct be_ctx);
841ac7
@@ -285,11 +317,24 @@ static void be_check_online_done(struct tevent_req *req)
841ac7
     be_ctx->check_online_ref_count--;
841ac7
 
841ac7
     if (reply->dp_error != DP_ERR_OK && be_ctx->check_online_ref_count > 0) {
841ac7
-        ret = be_check_online_request(be_ctx);
841ac7
-        if (ret != EOK) {
841ac7
-            DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create check online req.\n");
841ac7
+        be_ctx->check_online_retry_delay *= 2;
841ac7
+        if (be_ctx->check_online_retry_delay > ONLINE_CB_RETRY_MAX_DELAY) {
841ac7
+            be_ctx->check_online_retry_delay = ONLINE_CB_RETRY_MAX_DELAY;
841ac7
+        }
841ac7
+
841ac7
+        schedule = tevent_timeval_current_ofs(be_ctx->check_online_retry_delay,
841ac7
+                                              0);
841ac7
+        time_event = tevent_add_timer(be_ctx->ev, be_ctx, schedule,
841ac7
+                                      check_if_online_delayed, be_ctx);
841ac7
+
841ac7
+        if (time_event == NULL) {
841ac7
+            DEBUG(SSSDBG_OP_FAILURE, "Failed to schedule online check\n");
841ac7
             goto done;
841ac7
         }
841ac7
+
841ac7
+        DEBUG(SSSDBG_TRACE_INTERNAL,
841ac7
+              "Schedule check_if_online_delayed in %ds.\n",
841ac7
+              be_ctx->check_online_retry_delay);
841ac7
         return;
841ac7
     }
841ac7
 
841ac7
@@ -303,28 +348,23 @@ done:
841ac7
     }
841ac7
 }
841ac7
 
841ac7
-static void check_if_online(struct be_ctx *be_ctx)
841ac7
+static void check_if_online(struct be_ctx *be_ctx, int delay)
841ac7
 {
841ac7
-    errno_t ret;
841ac7
-
841ac7
-    be_run_unconditional_online_cb(be_ctx);
841ac7
-
841ac7
-    if (!be_is_offline(be_ctx)) {
841ac7
-        DEBUG(SSSDBG_TRACE_INTERNAL,
841ac7
-              "Backend is already online, nothing to do.\n");
841ac7
-        return;
841ac7
-    }
841ac7
+    struct tevent_timer *time_event;
841ac7
+    struct timeval schedule;
841ac7
 
841ac7
     /* Make sure nobody tries to go online while we are checking */
841ac7
     be_ctx->offstat.went_offline = time(NULL);
841ac7
 
841ac7
-    DEBUG(SSSDBG_TRACE_INTERNAL, "Trying to go back online!\n");
841ac7
-
841ac7
     be_ctx->check_online_ref_count++;
841ac7
 
841ac7
     if (be_ctx->check_online_ref_count != 1) {
841ac7
         DEBUG(SSSDBG_TRACE_INTERNAL,
841ac7
               "There is an online check already running.\n");
841ac7
+        /* Do not have more than ONLINE_CB_RETRY retries in the queue */
841ac7
+        if (be_ctx->check_online_ref_count > ONLINE_CB_RETRY) {
841ac7
+            be_ctx->check_online_ref_count--;
841ac7
+        }
841ac7
         return;
841ac7
     }
841ac7
 
841ac7
@@ -334,12 +374,20 @@ static void check_if_online(struct be_ctx *be_ctx)
841ac7
         goto failed;
841ac7
     }
841ac7
 
841ac7
-    ret = be_check_online_request(be_ctx);
841ac7
-    if (ret != EOK) {
841ac7
-        DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create check online req.\n");
841ac7
+    schedule = tevent_timeval_current_ofs(delay, 0);
841ac7
+    time_event = tevent_add_timer(be_ctx->ev, be_ctx, schedule,
841ac7
+                                  check_if_online_delayed, be_ctx);
841ac7
+
841ac7
+    if (time_event == NULL) {
841ac7
+        DEBUG(SSSDBG_OP_FAILURE,
841ac7
+              "Scheduling check_if_online_delayed failed.\n");
841ac7
         goto failed;
841ac7
     }
841ac7
 
841ac7
+    be_ctx->check_online_ref_count = ONLINE_CB_RETRY;
841ac7
+    be_ctx->check_online_retry_delay = 1;
841ac7
+    DEBUG(SSSDBG_TRACE_INTERNAL,
841ac7
+          "Schedule check_if_online_delayed in %ds.\n", delay);
841ac7
     return;
841ac7
 
841ac7
 failed:
841ac7
@@ -373,7 +421,7 @@ static void signal_be_reset_offline(struct tevent_context *ev,
841ac7
                                     void *private_data)
841ac7
 {
841ac7
     struct be_ctx *ctx = talloc_get_type(private_data, struct be_ctx);
841ac7
-    check_if_online(ctx);
841ac7
+    check_if_online(ctx, 0);
841ac7
 }
841ac7
 
841ac7
 errno_t be_process_init(TALLOC_CTX *mem_ctx,
841ac7
@@ -649,7 +697,7 @@ static int data_provider_res_init(struct sbus_request *dbus_req, void *data)
841ac7
     be_ctx = talloc_get_type(data, struct be_ctx);
841ac7
 
841ac7
     resolv_reread_configuration(be_ctx->be_res->resolv);
841ac7
-    check_if_online(be_ctx);
841ac7
+    check_if_online(be_ctx, 1);
841ac7
 
841ac7
     return monitor_common_res_init(dbus_req, data);
841ac7
 }
841ac7
@@ -666,7 +714,7 @@ static int data_provider_reset_offline(struct sbus_request *dbus_req, void *data
841ac7
 {
841ac7
     struct be_ctx *be_ctx;
841ac7
     be_ctx = talloc_get_type(data, struct be_ctx);
841ac7
-    check_if_online(be_ctx);
841ac7
+    check_if_online(be_ctx, 1);
841ac7
     return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
841ac7
 }
841ac7
 
841ac7
-- 
841ac7
2.19.1
841ac7