From cbe1d56251be76d0820cf0794eb8eff1c4a6794f Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Tue, 25 Nov 2008 11:10:33 +0000 Subject: [PATCH] More changes to ensure that during thread switches the jcr is removed from the TSD git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@8082 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/dird.c | 2 ++ bacula/src/dird/jobq.c | 9 +++++++++ bacula/src/dird/ua_server.c | 3 ++- bacula/src/lib/jcr.c | 2 +- bacula/src/lib/watchdog.c | 1 + bacula/src/lib/workq.c | 2 ++ bacula/technotes-2.5 | 2 ++ 7 files changed, 19 insertions(+), 2 deletions(-) diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index df6f418fe8..19efc1b761 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -300,6 +300,7 @@ int main (int argc, char *argv[]) init_python_interpreter(&python_args); #endif /* HAVE_PYTHON */ + set_jcr_in_tsd(INVALID_JCR); set_thread_concurrency(director->MaxConcurrentJobs * 2 + 4 /* UA */ + 4 /* sched+watchdog+jobsvr+misc */); @@ -321,6 +322,7 @@ int main (int argc, char *argv[]) while ( (jcr = wait_for_next_job(runjob)) ) { run_job(jcr); /* run job */ free_jcr(jcr); /* release jcr */ + set_jcr_in_tsd(INVALID_JCR); if (runjob) { /* command line, run a single job? */ break; /* yes, terminate */ } diff --git a/bacula/src/dird/jobq.c b/bacula/src/dird/jobq.c index 36bbe4764a..6428dba146 100644 --- a/bacula/src/dird/jobq.c +++ b/bacula/src/dird/jobq.c @@ -180,6 +180,7 @@ void *sched_wait(void *arg) JCR *jcr = ((wait_pkt *)arg)->jcr; jobq_t *jq = ((wait_pkt *)arg)->jq; + set_jcr_in_tsd(jcr); Dmsg0(2300, "Enter sched_wait.\n"); free(arg); time_t wtime = jcr->sched_time - time(NULL); @@ -266,6 +267,8 @@ int jobq_add(jobq_t *jq, JCR *jcr) } item->jcr = jcr; + /* While waiting in a queue this job is not attached to a thread */ + set_jcr_in_tsd(INVALID_JCR); if (job_canceled(jcr)) { /* Add job to ready queue so that it is canceled quickly */ jq->ready_jobs->prepend(item); @@ -398,6 +401,7 @@ void *jobq_server(void *arg) bool timedout = false; bool work = true; + set_jcr_in_tsd(INVALID_JCR); Dmsg0(2300, "Start jobq_server\n"); if ((stat = pthread_mutex_lock(&jq->mutex)) != 0) { berrno be; @@ -454,6 +458,8 @@ void *jobq_server(void *arg) } } jq->running_jobs->append(je); + + /* Attach jcr to this thread while we run the job */ set_jcr_in_tsd(jcr); Dmsg1(2300, "Took jobid=%d from ready and appended to run\n", jcr->JobId); @@ -465,6 +471,9 @@ void *jobq_server(void *arg) jcr->use_count()); jq->engine(je->jcr); + /* Job finished detach from thread */ + set_jcr_in_tsd(INVALID_JCR); + Dmsg2(2300, "Back from user engine jobid=%d use=%d.\n", jcr->JobId, jcr->use_count()); diff --git a/bacula/src/dird/ua_server.c b/bacula/src/dird/ua_server.c index 3a6076b449..89b8aa45c5 100644 --- a/bacula/src/dird/ua_server.c +++ b/bacula/src/dird/ua_server.c @@ -76,6 +76,7 @@ extern "C" void *connect_thread(void *arg) { pthread_detach(pthread_self()); + set_jcr_in_tsd(INVALID_JCR); /* Permit 20 console connections */ bnet_thread_server((dlist*)arg, 20, &ua_workq, handle_UA_client_request); @@ -126,7 +127,7 @@ static void *handle_UA_client_request(void *arg) ua = new_ua_context(jcr); ua->UA_sock = user; - set_jcr_in_tsd(jcr); + set_jcr_in_tsd(INVALID_JCR); user->recv(); /* Get first message */ if (!authenticate_user_agent(ua)) { diff --git a/bacula/src/lib/jcr.c b/bacula/src/lib/jcr.c index b7ce11cbb9..05a94d2128 100644 --- a/bacula/src/lib/jcr.c +++ b/bacula/src/lib/jcr.c @@ -584,7 +584,7 @@ void free_jcr(JCR *jcr) */ void remove_jcr_from_tsd(JCR *jcr) { - JCR *tjcr = get_gcr_from_tsd(); + JCR *tjcr = get_jcr_from_tsd(); if (tjcr == jcr) { set_jcr_in_tsd(INVALID_JCR); } diff --git a/bacula/src/lib/watchdog.c b/bacula/src/lib/watchdog.c index c51b88a6c9..770597dbba 100644 --- a/bacula/src/lib/watchdog.c +++ b/bacula/src/lib/watchdog.c @@ -246,6 +246,7 @@ extern "C" void *watchdog_thread(void *arg) struct timezone tz; utime_t next_time; + set_jcr_in_tsd(INVALID_JCR); Dmsg0(800, "NicB-reworked watchdog thread entered\n"); while (!quit) { diff --git a/bacula/src/lib/workq.c b/bacula/src/lib/workq.c index 2744d23c92..bd108f4875 100644 --- a/bacula/src/lib/workq.c +++ b/bacula/src/lib/workq.c @@ -58,6 +58,7 @@ */ #include "bacula.h" +#include "jcr.h" /* Forward referenced functions */ extern "C" void *workq_server(void *arg); @@ -304,6 +305,7 @@ void *workq_server(void *arg) if ((stat = pthread_mutex_lock(&wq->mutex)) != 0) { return NULL; } + set_jcr_in_tsd(INVALID_JCR); for (;;) { struct timeval tv; diff --git a/bacula/technotes-2.5 b/bacula/technotes-2.5 index 10ab6e02d0..cc9bd59347 100644 --- a/bacula/technotes-2.5 +++ b/bacula/technotes-2.5 @@ -11,6 +11,8 @@ mixed priorities General: 25Nov08 +kes More changes to ensure that during thread switches the jcr + is removed from the TSD. kes Ensure that consoles attach jcr to thread, and that only the thread attached is removed from the TSD. 24Nov08 -- 2.39.5