Blame SOURCES/0037-Ticket-48960-Crash-in-import_wait_for_space_in_fifo.patch

7c7f29
From b20743a90c1eac752341d19a283e7d3ebf07ac10 Mon Sep 17 00:00:00 2001
7c7f29
From: Thierry Bordaz <tbordaz@redhat.com>
7c7f29
Date: Fri, 19 Aug 2016 14:32:47 +0200
7c7f29
Subject: [PATCH 37/45] Ticket 48960 Crash in import_wait_for_space_in_fifo().
7c7f29
7c7f29
Bug Description:
7c7f29
    At online total import on a consumer, the total import startup
7c7f29
    function allocates a fifo queue and monitor the overall import.
7c7f29
    This queue contain the entries later received during import.
7c7f29
7c7f29
    When monitoring ends (import complete or error) it frees
7c7f29
    the queue.
7c7f29
7c7f29
    Under error condition, there is a possibility that monitoring
7c7f29
    ends while entries are still received (bulk_import_queue).
7c7f29
    So there is a risk that the received entries will be added into
7c7f29
    the queue at the same time the monitoring thread frees the queue
7c7f29
7c7f29
Fix Description:
7c7f29
    The thread storing the entries into the queue runs while
7c7f29
    holding the job->wire_lock.
7c7f29
7c7f29
    To prevent the monitoring thread to frees the queue under
7c7f29
    bulk_import_queue, make sure to acquire job->wire_lock
7c7f29
    before calling import_free_job
7c7f29
7c7f29
https://fedorahosted.org/389/ticket/48960
7c7f29
7c7f29
Reviewed by: Mark Reynolds (thanks Mark !)
7c7f29
7c7f29
Platforms tested: F23
7c7f29
7c7f29
Flag Day: no
7c7f29
7c7f29
Doc impact: no
7c7f29
7c7f29
(cherry picked from commit 776d94214295cc95f9a906d4bb6268397a6bf091)
7c7f29
---
7c7f29
 ldap/servers/slapd/back-ldbm/import-threads.c |  5 +++++
7c7f29
 ldap/servers/slapd/back-ldbm/import.c         | 15 ++++++++++++++-
7c7f29
 2 files changed, 19 insertions(+), 1 deletion(-)
7c7f29
7c7f29
diff --git a/ldap/servers/slapd/back-ldbm/import-threads.c b/ldap/servers/slapd/back-ldbm/import-threads.c
7c7f29
index 1759478..c3fca2b 100644
7c7f29
--- a/ldap/servers/slapd/back-ldbm/import-threads.c
7c7f29
+++ b/ldap/servers/slapd/back-ldbm/import-threads.c
7c7f29
@@ -3201,6 +3201,11 @@ static int bulk_import_queue(ImportJob *job, Slapi_Entry *entry)
7c7f29
         return -1;
7c7f29
     }
7c7f29
 
7c7f29
+    /* The import is aborted, just ignore that entry */
7c7f29
+    if(job->flags & FLAG_ABORT) {
7c7f29
+        return -1;
7c7f29
+    }
7c7f29
+
7c7f29
     PR_Lock(job->wire_lock);
7c7f29
     /* Let's do this inside the lock !*/
7c7f29
     id = job->lead_ID + 1;
7c7f29
diff --git a/ldap/servers/slapd/back-ldbm/import.c b/ldap/servers/slapd/back-ldbm/import.c
7c7f29
index 9b6ae0d..78aefbf 100644
7c7f29
--- a/ldap/servers/slapd/back-ldbm/import.c
7c7f29
+++ b/ldap/servers/slapd/back-ldbm/import.c
7c7f29
@@ -408,8 +408,21 @@ void import_free_job(ImportJob *job)
7c7f29
     
7c7f29
     ldbm_back_free_incl_excl(job->include_subtrees, job->exclude_subtrees);
7c7f29
     charray_free(job->input_filenames);
7c7f29
-    if (job->fifo.size)
7c7f29
+    if (job->fifo.size) {
7c7f29
+        /* bulk_import_queue is running, while holding the job lock.
7c7f29
+         * bulk_import_queue is using the fifo queue.
7c7f29
+         * To avoid freeing fifo queue under bulk_import_queue use
7c7f29
+         * job lock to synchronize
7c7f29
+         */
7c7f29
+        if (job->wire_lock)
7c7f29
+            PR_Lock(job->wire_lock);
7c7f29
+
7c7f29
         import_fifo_destroy(job);
7c7f29
+
7c7f29
+        if (job->wire_lock)
7c7f29
+            PR_Unlock(job->wire_lock);
7c7f29
+    }
7c7f29
+
7c7f29
     if (NULL != job->uuid_namespace)
7c7f29
         slapi_ch_free((void **)&job->uuid_namespace);
7c7f29
     if (job->wire_lock)
7c7f29
-- 
7c7f29
2.4.11
7c7f29