]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/jobq.c
ebl Modify disk-changer to check if slot contains something before
[bacula/bacula] / bacula / src / dird / jobq.c
index 308acd77307b378da3f8f44bd505cebba34b39ae..26a3316d6e4904401dc2c89c00d50bd30b89ed00 100644 (file)
@@ -56,8 +56,8 @@ extern "C" void *sched_wait(void *arg);
 
 static int  start_server(jobq_t *jq);
 static bool acquire_resources(JCR *jcr);
-
-
+static void dec_read_store(JCR *jcr);
+static void dec_write_store(JCR *jcr);
 
 /*
  * Initialize a job queue
@@ -477,16 +477,8 @@ void *jobq_server(void *arg)
           *  put into the ready queue.
           */
          if (jcr->acquired_resource_locks) {
-            if (jcr->rstore) {
-               jcr->rstore->NumConcurrentJobs--;
-               Dmsg1(200, "Dec rncj=%d\n", jcr->rstore->NumConcurrentJobs);
-               ASSERT(jcr->rstore->NumConcurrentJobs >= 0);
-            }
-            if (jcr->wstore) {
-               jcr->wstore->NumConcurrentJobs--;
-               Dmsg1(200, "Dec wncj=%d\n", jcr->wstore->NumConcurrentJobs);
-               ASSERT(jcr->wstore->NumConcurrentJobs >= 0);
-            }
+            dec_read_store(jcr);
+            dec_write_store(jcr);
             jcr->client->NumConcurrentJobs--;
             jcr->job->NumConcurrentJobs--;
             jcr->acquired_resource_locks = false;
@@ -692,15 +684,10 @@ static bool acquire_resources(JCR *jcr)
    }
    if (jcr->rstore) {
       Dmsg1(200, "Rstore=%s\n", jcr->rstore->name());
-      if (jcr->rstore->NumConcurrentJobs == 0 &&
-          jcr->rstore->NumConcurrentJobs < jcr->rstore->MaxConcurrentJobs) {
-         /* Simple case, first job */
-         jcr->rstore->NumConcurrentJobs = 1;
-         Dmsg0(200, "Set rncj=1\n");
-      /* We can do this only if multi-drive autochanger */
-//    } else if (jcr->rstore->NumConcurrentJobs < jcr->rstore->MaxConcurrentJobs) {
-//       jcr->rstore->NumConcurrentJobs++;
-//       Dmsg1(200, "Inc rncj=%d\n", jcr->rstore->NumConcurrentJobs);
+      if (jcr->rstore->NumConcurrentJobs < jcr->rstore->MaxConcurrentJobs) {
+         jcr->rstore->NumConcurrentReadJobs++;
+         jcr->rstore->NumConcurrentJobs++;
+         Dmsg1(200, "Inc rncj=%d\n", jcr->rstore->NumConcurrentJobs);
       } else {
          Dmsg1(200, "Fail rncj=%d\n", jcr->rstore->NumConcurrentJobs);
          set_jcr_job_status(jcr, JS_WaitStoreRes);
@@ -710,18 +697,11 @@ static bool acquire_resources(JCR *jcr)
    
    if (jcr->wstore) {
       Dmsg1(200, "Wstore=%s\n", jcr->wstore->name());
-      if (jcr->wstore->NumConcurrentJobs == 0 &&
-          jcr->wstore->NumConcurrentJobs < jcr->wstore->MaxConcurrentJobs) {
-         /* Simple case, first job */
-         jcr->wstore->NumConcurrentJobs = 1;
-         Dmsg0(200, "Set wncj=1\n");
-      } else if (jcr->wstore->NumConcurrentJobs < jcr->wstore->MaxConcurrentJobs) {
+      if (jcr->wstore->NumConcurrentJobs < jcr->wstore->MaxConcurrentJobs) {
          jcr->wstore->NumConcurrentJobs++;
          Dmsg1(200, "Inc wncj=%d\n", jcr->wstore->NumConcurrentJobs);
       } else if (jcr->rstore) {
-         jcr->rstore->NumConcurrentJobs--;        /* back out rstore */
-         Dmsg1(200, "Fail wncj=%d\n", jcr->wstore->NumConcurrentJobs);
-         ASSERT(jcr->rstore->NumConcurrentJobs >= 0);
+         dec_read_store(jcr);
          skip_this_jcr = true;
       } else {
          Dmsg1(200, "Fail wncj=%d\n", jcr->wstore->NumConcurrentJobs);
@@ -737,16 +717,8 @@ static bool acquire_resources(JCR *jcr)
       jcr->client->NumConcurrentJobs++;
    } else {
       /* Back out previous locks */
-      if (jcr->wstore) {
-         jcr->wstore->NumConcurrentJobs--;
-         Dmsg1(200, "Dec wncj=%d\n", jcr->wstore->NumConcurrentJobs);
-         ASSERT(jcr->wstore->NumConcurrentJobs >= 0);
-      }
-      if (jcr->rstore) {
-         jcr->rstore->NumConcurrentJobs--;  
-         Dmsg1(200, "Dec rncj=%d\n", jcr->rstore->NumConcurrentJobs);
-         ASSERT(jcr->rstore->NumConcurrentJobs >= 0);
-      }
+      dec_write_store(jcr);
+      dec_read_store(jcr);
       set_jcr_job_status(jcr, JS_WaitClientRes);
       return false;
    }
@@ -754,16 +726,8 @@ static bool acquire_resources(JCR *jcr)
       jcr->job->NumConcurrentJobs++;
    } else {
       /* Back out previous locks */
-      if (jcr->wstore) {
-         jcr->wstore->NumConcurrentJobs--;
-         Dmsg1(200, "Dec wncj=%d\n", jcr->wstore->NumConcurrentJobs);
-         ASSERT(jcr->wstore->NumConcurrentJobs >= 0);
-      }
-      if (jcr->rstore) {
-         jcr->rstore->NumConcurrentJobs--;
-         Dmsg1(200, "Dec rncj=%d\n", jcr->rstore->NumConcurrentJobs);
-         ASSERT(jcr->rstore->NumConcurrentJobs >= 0);
-      }
+      dec_write_store(jcr);
+      dec_read_store(jcr);
       jcr->client->NumConcurrentJobs--;
       set_jcr_job_status(jcr, JS_WaitJobRes);
       return false;
@@ -772,3 +736,23 @@ static bool acquire_resources(JCR *jcr)
    jcr->acquired_resource_locks = true;
    return true;
 }
+
+static void dec_read_store(JCR *jcr)
+{
+   if (jcr->rstore) {
+      jcr->rstore->NumConcurrentReadJobs--;    /* back out rstore */
+      jcr->rstore->NumConcurrentJobs--;        /* back out rstore */
+      Dmsg1(200, "Dec wncj=%d\n", jcr->wstore->NumConcurrentJobs);
+      ASSERT(jcr->rstore->NumConcurrentReadJobs >= 0);
+      ASSERT(jcr->rstore->NumConcurrentJobs >= 0);
+   }
+}
+
+static void dec_write_store(JCR *jcr)
+{
+   if (jcr->wstore) {
+      jcr->wstore->NumConcurrentJobs--;
+      Dmsg1(200, "Dec wncj=%d\n", jcr->wstore->NumConcurrentJobs);
+      ASSERT(jcr->wstore->NumConcurrentJobs >= 0);
+   }
+}