summaryrefslogtreecommitdiffstats
path: root/src/providers
diff options
context:
space:
mode:
authorPavel Březina <pbrezina@redhat.com>2013-10-24 11:17:43 +0200
committerJakub Hrozek <jhrozek@redhat.com>2013-10-25 22:18:55 +0200
commit3acf08156e66e9e86d4a80ff566aa75aa71a65b8 (patch)
tree4ebd12d1851f610c3d072c4dbfa19f4acee4d676 /src/providers
parentbc0d2a41b8e7b8549ddb3161596013bfef91fd77 (diff)
downloadsssd-3acf08156e66e9e86d4a80ff566aa75aa71a65b8.tar.gz
sssd-3acf08156e66e9e86d4a80ff566aa75aa71a65b8.tar.xz
sssd-3acf08156e66e9e86d4a80ff566aa75aa71a65b8.zip
dp: convert cleanup task to be_ptask
Resolves: https://fedorahosted.org/sssd/ticket/1968
Diffstat (limited to 'src/providers')
-rw-r--r--src/providers/ldap/ldap_common.c22
-rw-r--r--src/providers/ldap/ldap_common.h6
-rw-r--r--src/providers/ldap/ldap_id_cleanup.c107
-rw-r--r--src/providers/ldap/sdap.h2
4 files changed, 64 insertions, 73 deletions
diff --git a/src/providers/ldap/ldap_common.c b/src/providers/ldap/ldap_common.c
index d4d171de1..9609975e3 100644
--- a/src/providers/ldap/ldap_common.c
+++ b/src/providers/ldap/ldap_common.c
@@ -939,29 +939,19 @@ int sdap_id_setup_tasks(struct sdap_id_ctx *ctx,
be_ptask_send_t send_fn,
be_ptask_recv_t recv_fn)
{
- struct timeval tv;
- int ret = EOK;
- int delay;
+ int ret;
/* set up enumeration task */
if (sdom->dom->enumerate) {
- DEBUG(SSSDBG_TRACE_FUNC, ("Setting up enumeration for %s\n", sdom->dom->name));
+ DEBUG(SSSDBG_TRACE_FUNC, ("Setting up enumeration for %s\n",
+ sdom->dom->name));
ret = ldap_setup_enumeration(ctx, conn, sdom, send_fn, recv_fn);
} else {
/* the enumeration task, runs the cleanup process by itself,
* but if enumeration is not running we need to schedule it */
- delay = dp_opt_get_int(ctx->opts->basic, SDAP_CACHE_PURGE_TIMEOUT);
- if (delay == 0) {
- /* Cleanup has been explicitly disabled, so we won't
- * schedule any cleanup tasks.
- */
- return EOK;
- }
-
- /* run the first one in a couple of seconds so that we have time to
- * finish initializations first*/
- tv = tevent_timeval_current_ofs(10, 0);
- ret = ldap_id_cleanup_create_timer(ctx, sdom, tv);
+ DEBUG(SSSDBG_TRACE_FUNC, ("Setting up cleanup task for %s\n",
+ sdom->dom->name));
+ ret = ldap_setup_cleanup(ctx, sdom);
}
return ret;
diff --git a/src/providers/ldap/ldap_common.h b/src/providers/ldap/ldap_common.h
index 0bd6c9cc2..8b2b1ea91 100644
--- a/src/providers/ldap/ldap_common.h
+++ b/src/providers/ldap/ldap_common.h
@@ -195,11 +195,11 @@ ldap_enumeration_send(TALLOC_CTX *mem_ctx,
void *pvt);
errno_t ldap_enumeration_recv(struct tevent_req *req);
+errno_t ldap_setup_cleanup(struct sdap_id_ctx *id_ctx,
+ struct sdap_domain *sdom);
+
errno_t ldap_id_cleanup(struct sdap_options *opts,
struct sdap_domain *sdom);
-int ldap_id_cleanup_create_timer(struct sdap_id_ctx *ctx,
- struct sdap_domain *sdom,
- struct timeval tv);
void sdap_mark_offline(struct sdap_id_ctx *ctx);
diff --git a/src/providers/ldap/ldap_id_cleanup.c b/src/providers/ldap/ldap_id_cleanup.c
index 06cdae0a7..36ef6f420 100644
--- a/src/providers/ldap/ldap_id_cleanup.c
+++ b/src/providers/ldap/ldap_id_cleanup.c
@@ -38,74 +38,73 @@ struct ldap_id_cleanup_ctx {
struct sdap_domain *sdom;
};
-static errno_t ldap_id_cleanup_set_timer(struct ldap_id_cleanup_ctx *cctx,
- struct timeval tv);
+static errno_t ldap_cleanup_task(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct be_ctx *be_ctx,
+ struct be_ptask *be_ptask,
+ void *pvt)
+{
+ struct ldap_id_cleanup_ctx *cleanup_ctx = NULL;
+
+ cleanup_ctx = talloc_get_type(pvt, struct ldap_id_cleanup_ctx);
+ return ldap_id_cleanup(cleanup_ctx->ctx->opts, cleanup_ctx->sdom);
+}
-static void ldap_id_cleanup_timer(struct tevent_context *ev,
- struct tevent_timer *tt,
- struct timeval tv, void *pvt)
+errno_t ldap_setup_cleanup(struct sdap_id_ctx *id_ctx,
+ struct sdap_domain *sdom)
{
- struct ldap_id_cleanup_ctx *cctx = talloc_get_type(pvt,
- struct ldap_id_cleanup_ctx);
- int delay;
errno_t ret;
-
- if (be_is_offline(cctx->ctx->be)) {
- DEBUG(SSSDBG_TRACE_FUNC, ("Backend is marked offline, retry later!\n"));
- /* schedule starting from now, not the last run */
- delay = dp_opt_get_int(cctx->ctx->opts->basic,
- SDAP_CACHE_PURGE_TIMEOUT);
- tv = tevent_timeval_current_ofs(delay, 0);
- ldap_id_cleanup_set_timer(cctx, tv);
- return;
+ time_t first_delay;
+ time_t period;
+ struct ldap_id_cleanup_ctx *cleanup_ctx = NULL;
+ char *name = NULL;
+
+ period = dp_opt_get_int(id_ctx->opts->basic, SDAP_CACHE_PURGE_TIMEOUT);
+ if (period == 0) {
+ /* Cleanup has been explicitly disabled, so we won't
+ * create any cleanup tasks. */
+ ret = EOK;
+ goto done;
}
- ret = ldap_id_cleanup(cctx->ctx->opts, cctx->sdom);
- if (ret != EOK) {
- /* On error schedule starting from now, not the last run */
- tv = tevent_timeval_current();
- } else {
- tv = cctx->sdom->last_purge;
- }
+ /* Run the first one in a couple of seconds so that we have time to
+ * finish initializations first. */
+ first_delay = 10;
- delay = dp_opt_get_int(cctx->ctx->opts->basic, SDAP_CACHE_PURGE_TIMEOUT);
- tv = tevent_timeval_add(&tv, delay, 0);
- ldap_id_cleanup_set_timer(cctx, tv);
-}
+ cleanup_ctx = talloc_zero(sdom, struct ldap_id_cleanup_ctx);
+ if (cleanup_ctx == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
-static errno_t ldap_id_cleanup_set_timer(struct ldap_id_cleanup_ctx *cctx,
- struct timeval tv)
-{
- struct tevent_timer *cleanup_task;
+ cleanup_ctx->ctx = id_ctx;
+ cleanup_ctx->sdom = sdom;
- cleanup_task = tevent_add_timer(cctx->ctx->be->ev, cctx->ctx,
- tv, ldap_id_cleanup_timer, cctx);
- if (cleanup_task == NULL) {
- DEBUG(SSSDBG_CRIT_FAILURE, ("FATAL: failed to setup cleanup task!\n"));
- return EFAULT;
+ name = talloc_asprintf(cleanup_ctx, "Cleanup of %s", sdom->dom->name);
+ if (name == NULL) {
+ return ENOMEM;
}
- return EOK;
-}
-
-int ldap_id_cleanup_create_timer(struct sdap_id_ctx *ctx,
- struct sdap_domain *sdom,
- struct timeval tv)
-{
- struct ldap_id_cleanup_ctx *cctx;
+ ret = be_ptask_create_sync(sdom, id_ctx->be, period, first_delay,
+ 5 /* enabled delay */, period /* timeout */,
+ BE_PTASK_OFFLINE_SKIP, ldap_cleanup_task,
+ cleanup_ctx, name, &sdom->cleanup_task);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_FATAL_FAILURE, ("Unable to initialize cleanup periodic "
+ "task for %s\n", sdom->dom->name));
+ goto done;
+ }
- DEBUG(SSSDBG_FUNC_DATA,
- ("Scheduling next cleanup at %ld.%ld\n",
- (long)tv.tv_sec, (long)tv.tv_usec));
+ talloc_steal(sdom->cleanup_task, cleanup_ctx);
+ ret = EOK;
- cctx = talloc(ctx, struct ldap_id_cleanup_ctx);
- if (cctx == NULL) {
- return ENOMEM;
+done:
+ talloc_free(name);
+ if (ret != EOK) {
+ talloc_free(cleanup_ctx);
}
- cctx->ctx = ctx;
- cctx->sdom = sdom;
- return ldap_id_cleanup_set_timer(cctx, tv);
+ return ret;
}
static int cleanup_users(struct sdap_options *opts,
diff --git a/src/providers/ldap/sdap.h b/src/providers/ldap/sdap.h
index 0e886e980..abc9052f6 100644
--- a/src/providers/ldap/sdap.h
+++ b/src/providers/ldap/sdap.h
@@ -386,6 +386,8 @@ struct sdap_domain {
/* Enumeration and cleanup periodic task */
struct be_ptask *enum_task;
+ struct be_ptask *cleanup_task;
+
/* enumeration loop timer */
struct timeval last_enum;
/* cleanup loop timer */