]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/jobq.c
Add heap stats to Dir and SD -- eliminate #ifdefs
[bacula/bacula] / bacula / src / dird / jobq.c
index be33bf1611bdfe602d4164d64fe0dc048a6ebf67..8040ed77e0bef02a839ee91b431492dc592df1cd 100755 (executable)
@@ -18,7 +18,7 @@
  *
  */
 /*
-   Copyright (C) 2000-2003 Kern Sibbald and John Walker
+   Copyright (C) 2003-2004 Kern Sibbald and John Walker
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -42,7 +42,9 @@
 
 
 /* Forward referenced functions */
-static void *jobq_server(void *arg);
+extern "C" void *jobq_server(void *arg);
+extern "C" void *sched_wait(void *arg);
+
 static int   start_server(jobq_t *jq);
 
 /*   
@@ -152,7 +154,8 @@ struct wait_pkt {
  *  most jobs are put into the job queue only when their
  *  scheduled time arives.
  */
-static void *sched_wait(void *arg)
+extern "C"  
+void *sched_wait(void *arg)
 {
    JCR *jcr = ((wait_pkt *)arg)->jcr;
    jobq_t *jq = ((wait_pkt *)arg)->jq;
@@ -186,7 +189,6 @@ static void *sched_wait(void *arg)
    return NULL;
 }
 
-
 /*
  *  Add a job to the queue
  *    jq is a queue that was created with jobq_init
@@ -352,7 +354,8 @@ static int start_server(jobq_t *jq)
  * When all the resources are acquired for the job, 
  *  it will call the user's engine.
  */
-static void *jobq_server(void *arg)
+extern "C"  
+void *jobq_server(void *arg)
 {
    struct timespec timeout;
    jobq_t *jq = (jobq_t *)arg;
@@ -443,6 +446,9 @@ static void *jobq_server(void *arg)
          */
         if (jcr->acquired_resource_locks) {
            jcr->store->NumConcurrentJobs--;
+           if (jcr->JobType == JT_RESTORE) {
+              jcr->store->MaxConcurrentJobs = jcr->saveMaxConcurrentJobs;  
+           }
            jcr->client->NumConcurrentJobs--;
            jcr->job->NumConcurrentJobs--;
         }
@@ -532,17 +538,33 @@ static void *jobq_server(void *arg)
               set_jcr_job_status(jcr, JS_WaitPriority);
               break;
            }
-           if (jcr->store->NumConcurrentJobs < jcr->store->MaxConcurrentJobs) {
+           if (jcr->JobType == JT_RESTORE) {
+              /* Let only one Restore job run at a time regardless of MaxConcurrentJobs */
+              if (jcr->store->NumConcurrentJobs == 0) {
+                 jcr->store->NumConcurrentJobs++;
+                 jcr->saveMaxConcurrentJobs = jcr->store->MaxConcurrentJobs;
+                 jcr->store->MaxConcurrentJobs = 1;
+              } else {
+                 set_jcr_job_status(jcr, JS_WaitStoreRes);
+                 je = jn;
+                 continue;
+              }
+           } else if (jcr->store->NumConcurrentJobs < jcr->store->MaxConcurrentJobs) {
               jcr->store->NumConcurrentJobs++;
            } else {
               set_jcr_job_status(jcr, JS_WaitStoreRes);
               je = jn;
               continue;
            }
+
            if (jcr->client->NumConcurrentJobs < jcr->client->MaxConcurrentJobs) {
               jcr->client->NumConcurrentJobs++;
            } else {
+              /* Back out previous locks */
               jcr->store->NumConcurrentJobs--;
+              if (jcr->JobType == JT_RESTORE) {
+                 jcr->store->MaxConcurrentJobs = jcr->saveMaxConcurrentJobs;  
+              }
               set_jcr_job_status(jcr, JS_WaitClientRes);
               je = jn;
               continue;
@@ -550,7 +572,11 @@ static void *jobq_server(void *arg)
            if (jcr->job->NumConcurrentJobs < jcr->job->MaxConcurrentJobs) {
               jcr->job->NumConcurrentJobs++;
            } else {
+              /* Back out previous locks */
               jcr->store->NumConcurrentJobs--;
+              if (jcr->JobType == JT_RESTORE) {
+                 jcr->store->MaxConcurrentJobs = jcr->saveMaxConcurrentJobs;  
+              }
               jcr->client->NumConcurrentJobs--;
               set_jcr_job_status(jcr, JS_WaitJobRes);
               je = jn;