Blame SOURCES/0015-AD-Remember-last-site-discovered-in-sysdb.patch

ced1f5
From 1be48c91f3d80b51dc2361217f5c840656e0b088 Mon Sep 17 00:00:00 2001
ced1f5
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
ced1f5
Date: Wed, 1 Nov 2017 14:57:17 +0100
ced1f5
Subject: [PATCH 15/21] AD: Remember last site discovered in sysdb
ced1f5
ced1f5
This can speed up sssd startup.
ced1f5
ced1f5
Resolves:
ced1f5
https://pagure.io/SSSD/sssd/issue/3265
ced1f5
ced1f5
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
ced1f5
(cherry picked from commit fb0431b13a9fcd8ac31e622503acbd10d2b73ac9)
ced1f5
---
ced1f5
 src/db/sysdb_subdomains.c                 |  2 +-
ced1f5
 src/providers/ad/ad_init.c                |  2 +-
ced1f5
 src/providers/ad/ad_srv.c                 | 21 +++++++++++++++++++++
ced1f5
 src/providers/ad/ad_srv.h                 |  1 +
ced1f5
 src/providers/ad/ad_subdomains.c          |  2 +-
ced1f5
 src/providers/ipa/ipa_subdomains_server.c |  2 +-
ced1f5
 6 files changed, 26 insertions(+), 4 deletions(-)
ced1f5
ced1f5
diff --git a/src/db/sysdb_subdomains.c b/src/db/sysdb_subdomains.c
ced1f5
index cb5de1afe3e8c9692789c5d2679eb3a4e6e1cdb2..353561765904efe4bd698c38949a1b290ecf0b80 100644
ced1f5
--- a/src/db/sysdb_subdomains.c
ced1f5
+++ b/src/db/sysdb_subdomains.c
ced1f5
@@ -1291,7 +1291,7 @@ sysdb_get_site(TALLOC_CTX *mem_ctx,
ced1f5
                const char **_site)
ced1f5
 {
ced1f5
     TALLOC_CTX *tmp_ctx;
ced1f5
-    struct ldb_res *res;
ced1f5
+    struct ldb_result *res;
ced1f5
     struct ldb_dn *dn;
ced1f5
     const char *attrs[] = { SYSDB_SITE, NULL };
ced1f5
     errno_t ret;
ced1f5
diff --git a/src/providers/ad/ad_init.c b/src/providers/ad/ad_init.c
ced1f5
index 131e960d4c623398506f834742400df9c786b86b..e62025d4acd24844a5c7082d00c597516f35de16 100644
ced1f5
--- a/src/providers/ad/ad_init.c
ced1f5
+++ b/src/providers/ad/ad_init.c
ced1f5
@@ -199,7 +199,7 @@ static errno_t ad_init_srv_plugin(struct be_ctx *be_ctx,
ced1f5
         return EOK;
ced1f5
     }
ced1f5
 
ced1f5
-    srv_ctx = ad_srv_plugin_ctx_init(be_ctx, be_ctx->be_res,
ced1f5
+    srv_ctx = ad_srv_plugin_ctx_init(be_ctx, be_ctx, be_ctx->be_res,
ced1f5
                                      default_host_dbs, ad_options->id,
ced1f5
                                      hostname, ad_domain,
ced1f5
                                      ad_site_override);
ced1f5
diff --git a/src/providers/ad/ad_srv.c b/src/providers/ad/ad_srv.c
ced1f5
index be1ba0f237add894566ae713ce5e29fd202d414c..4fa1668605e131b2e31802b1401f49fc6e00a23b 100644
ced1f5
--- a/src/providers/ad/ad_srv.c
ced1f5
+++ b/src/providers/ad/ad_srv.c
ced1f5
@@ -34,6 +34,7 @@
ced1f5
 #include "providers/fail_over_srv.h"
ced1f5
 #include "providers/ldap/sdap.h"
ced1f5
 #include "providers/ldap/sdap_async.h"
ced1f5
+#include "db/sysdb.h"
ced1f5
 
ced1f5
 #define AD_SITE_DOMAIN_FMT "%s._sites.%s"
ced1f5
 
ced1f5
@@ -475,6 +476,7 @@ int ad_get_client_site_recv(TALLOC_CTX *mem_ctx,
ced1f5
 }
ced1f5
 
ced1f5
 struct ad_srv_plugin_ctx {
ced1f5
+    struct be_ctx *be_ctx;
ced1f5
     struct be_resolv_ctx *be_res;
ced1f5
     enum host_database *host_dbs;
ced1f5
     struct sdap_options *opts;
ced1f5
@@ -486,6 +488,7 @@ struct ad_srv_plugin_ctx {
ced1f5
 
ced1f5
 struct ad_srv_plugin_ctx *
ced1f5
 ad_srv_plugin_ctx_init(TALLOC_CTX *mem_ctx,
ced1f5
+                       struct be_ctx *be_ctx,
ced1f5
                        struct be_resolv_ctx *be_res,
ced1f5
                        enum host_database *host_dbs,
ced1f5
                        struct sdap_options *opts,
ced1f5
@@ -494,12 +497,14 @@ ad_srv_plugin_ctx_init(TALLOC_CTX *mem_ctx,
ced1f5
                        const char *ad_site_override)
ced1f5
 {
ced1f5
     struct ad_srv_plugin_ctx *ctx = NULL;
ced1f5
+    errno_t ret;
ced1f5
 
ced1f5
     ctx = talloc_zero(mem_ctx, struct ad_srv_plugin_ctx);
ced1f5
     if (ctx == NULL) {
ced1f5
         return NULL;
ced1f5
     }
ced1f5
 
ced1f5
+    ctx->be_ctx = be_ctx;
ced1f5
     ctx->be_res = be_res;
ced1f5
     ctx->host_dbs = host_dbs;
ced1f5
     ctx->opts = opts;
ced1f5
@@ -524,6 +529,15 @@ ad_srv_plugin_ctx_init(TALLOC_CTX *mem_ctx,
ced1f5
         if (ctx->current_site == NULL) {
ced1f5
             goto fail;
ced1f5
         }
ced1f5
+    } else {
ced1f5
+        ret = sysdb_get_site(ctx, be_ctx->domain, &ctx->current_site);
ced1f5
+        if (ret != EOK) {
ced1f5
+            /* Not fatal. */
ced1f5
+            DEBUG(SSSDBG_MINOR_FAILURE,
ced1f5
+                  "Unable to get current site from cache [%d]: %s\n",
ced1f5
+                  ret, sss_strerror(ret));
ced1f5
+            ctx->current_site = NULL;
ced1f5
+        }
ced1f5
     }
ced1f5
 
ced1f5
     return ctx;
ced1f5
@@ -556,6 +570,13 @@ ad_srv_plugin_ctx_switch_site(struct ad_srv_plugin_ctx *ctx,
ced1f5
     talloc_zfree(ctx->current_site);
ced1f5
     ctx->current_site = site;
ced1f5
 
ced1f5
+    ret = sysdb_set_site(ctx->be_ctx->domain, ctx->current_site);
ced1f5
+    if (ret != EOK) {
ced1f5
+        /* Not fatal. */
ced1f5
+        DEBUG(SSSDBG_MINOR_FAILURE, "Unable to store site information "
ced1f5
+              "[%d]: %s\n", ret, sss_strerror(ret));
ced1f5
+    }
ced1f5
+
ced1f5
     return EOK;
ced1f5
 }
ced1f5
 
ced1f5
diff --git a/src/providers/ad/ad_srv.h b/src/providers/ad/ad_srv.h
ced1f5
index ae5efe44755fa09f74064014cce749e35b1831da..fddef686762e57bb95d648247131d39a797aa516 100644
ced1f5
--- a/src/providers/ad/ad_srv.h
ced1f5
+++ b/src/providers/ad/ad_srv.h
ced1f5
@@ -25,6 +25,7 @@ struct ad_srv_plugin_ctx;
ced1f5
 
ced1f5
 struct ad_srv_plugin_ctx *
ced1f5
 ad_srv_plugin_ctx_init(TALLOC_CTX *mem_ctx,
ced1f5
+                       struct be_ctx *be_ctx,
ced1f5
                        struct be_resolv_ctx *be_res,
ced1f5
                        enum host_database *host_dbs,
ced1f5
                        struct sdap_options *opts,
ced1f5
diff --git a/src/providers/ad/ad_subdomains.c b/src/providers/ad/ad_subdomains.c
ced1f5
index 280aa54c23bf61e60d23ea91bd44a39f9f43d155..3fb9b950f171d85817cce35ac92ad7c4974ccb68 100644
ced1f5
--- a/src/providers/ad/ad_subdomains.c
ced1f5
+++ b/src/providers/ad/ad_subdomains.c
ced1f5
@@ -245,7 +245,7 @@ ad_subdom_ad_ctx_new(struct be_ctx *be_ctx,
ced1f5
     ad_options->id_ctx = ad_id_ctx;
ced1f5
 
ced1f5
     /* use AD plugin */
ced1f5
-    srv_ctx = ad_srv_plugin_ctx_init(be_ctx, be_ctx->be_res,
ced1f5
+    srv_ctx = ad_srv_plugin_ctx_init(be_ctx, be_ctx, be_ctx->be_res,
ced1f5
                                      default_host_dbs,
ced1f5
                                      ad_id_ctx->ad_options->id,
ced1f5
                                      hostname,
ced1f5
diff --git a/src/providers/ipa/ipa_subdomains_server.c b/src/providers/ipa/ipa_subdomains_server.c
ced1f5
index 10166d162f746fde176e6c7c2bfbe3906b1bfddc..d670a156b37608d20d49d79131138f02e4abf82b 100644
ced1f5
--- a/src/providers/ipa/ipa_subdomains_server.c
ced1f5
+++ b/src/providers/ipa/ipa_subdomains_server.c
ced1f5
@@ -305,7 +305,7 @@ ipa_ad_ctx_new(struct be_ctx *be_ctx,
ced1f5
     ad_site_override = dp_opt_get_string(ad_options->basic, AD_SITE);
ced1f5
 
ced1f5
     /* use AD plugin */
ced1f5
-    srv_ctx = ad_srv_plugin_ctx_init(be_ctx, be_ctx->be_res,
ced1f5
+    srv_ctx = ad_srv_plugin_ctx_init(be_ctx, be_ctx, be_ctx->be_res,
ced1f5
                                      default_host_dbs,
ced1f5
                                      ad_id_ctx->ad_options->id,
ced1f5
                                      id_ctx->server_mode->hostname,
ced1f5
-- 
ced1f5
2.13.5
ced1f5