]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/job.c
kes Move the checking of the database in initializion of the Director
[bacula/bacula] / bacula / src / dird / job.c
index 8c2153b0a4bbc5a2c82aa02583e8329cae6b7f36..0df94071043f6719f5e6f250d5452a7b6be7d00f 100644 (file)
@@ -9,7 +9,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
@@ -156,6 +156,10 @@ bool setup_job(JCR *jcr)
     * Create Job record
     */
    init_jcr_job_record(jcr);
+   if (!get_or_create_client_record(jcr)) {
+      goto bail_out;
+   }
+
    if (!db_create_job_record(jcr, jcr->db, &jcr->jr)) {
       Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
       goto bail_out;
@@ -164,10 +168,6 @@ bool setup_job(JCR *jcr)
    Dmsg4(100, "Created job record JobId=%d Name=%s Type=%c Level=%c\n",
        jcr->JobId, jcr->Job, jcr->jr.JobType, jcr->jr.JobLevel);
 
-   if (!get_or_create_client_record(jcr)) {
-      goto bail_out;
-   }
-
    generate_daemon_event(jcr, "JobStart");
 
    if (job_canceled(jcr)) {
@@ -399,10 +399,8 @@ bool cancel_job(UAContext *ua, JCR *jcr)
             USTORE store;
             if (jcr->rstorage) {
                store.store = jcr->rstore;
-               pm_strcpy(store.store_source, jcr->rstore_source);
             } else {
                store.store = jcr->wstore;
-               pm_strcpy(store.store_source, jcr->wstore_source);
             }
             set_wstorage(ua->jcr, &store);
          }
@@ -443,7 +441,7 @@ static void job_monitor_watchdog(watchdog_t *self)
    Dmsg1(800, "job_monitor_watchdog %p called\n", self);
 
    foreach_jcr(jcr) {
-      bool cancel;
+      bool cancel = false;
 
       if (jcr->JobId == 0 || job_canceled(jcr)) {
          Dmsg2(800, "Skipping JCR=%p Job=%s\n", jcr, jcr->Job);
@@ -483,7 +481,6 @@ static void job_monitor_watchdog(watchdog_t *self)
 static bool job_check_maxwaittime(JCR *control_jcr, JCR *jcr)
 {
    bool cancel = false;
-   bool ok_to_cancel = false;
    JOB *job = jcr->job;
 
    if (job_canceled(jcr)) {
@@ -495,69 +492,18 @@ static bool job_check_maxwaittime(JCR *control_jcr, JCR *jcr)
    } 
    if (jcr->JobLevel == L_FULL && job->FullMaxWaitTime != 0 &&
          (watchdog_time - jcr->start_time) >= job->FullMaxWaitTime) {
-      ok_to_cancel = true;
+      cancel = true;
    } else if (jcr->JobLevel == L_DIFFERENTIAL && job->DiffMaxWaitTime != 0 &&
          (watchdog_time - jcr->start_time) >= job->DiffMaxWaitTime) {
-      ok_to_cancel = true;
+      cancel = true;
    } else if (jcr->JobLevel == L_INCREMENTAL && job->IncMaxWaitTime != 0 &&
          (watchdog_time - jcr->start_time) >= job->IncMaxWaitTime) {
-      ok_to_cancel = true;
+      cancel = true;
    } else if (job->MaxWaitTime != 0 &&
          (watchdog_time - jcr->start_time) >= job->MaxWaitTime) {
-      ok_to_cancel = true;
-   }
-   if (!ok_to_cancel) {
-      return false;
-   }
-
-/*
- * I don't see the need for all this -- kes 17Dec06
- */
-#ifdef xxx
-   Dmsg3(800, "Job %d (%s): MaxWaitTime of %d seconds exceeded, "
-         "checking status\n",
-         jcr->JobId, jcr->Job, job->MaxWaitTime);
-   switch (jcr->JobStatus) {
-   case JS_Created:
-   case JS_Blocked:
-   case JS_WaitFD:
-   case JS_WaitSD:
-   case JS_WaitStoreRes:
-   case JS_WaitClientRes:
-   case JS_WaitJobRes:
-   case JS_WaitPriority:
-   case JS_WaitMaxJobs:
-   case JS_WaitStartTime:
       cancel = true;
-      Dmsg0(200, "JCR blocked in #1\n");
-      break;
-   case JS_Running:
-      Dmsg0(800, "JCR running, checking SD status\n");
-      switch (jcr->SDJobStatus) {
-      case JS_WaitMount:
-      case JS_WaitMedia:
-      case JS_WaitFD:
-         cancel = true;
-         Dmsg0(800, "JCR blocked in #2\n");
-         break;
-      default:
-         Dmsg0(800, "JCR not blocked in #2\n");
-         break;
-      }
-      break;
-   case JS_Terminated:
-   case JS_ErrorTerminated:
-   case JS_Canceled:
-   case JS_FatalError:
-      Dmsg0(800, "JCR already dead in #3\n");
-      break;
-   default:
-      Jmsg1(jcr, M_ERROR, 0, _("Unhandled job status code %d\n"),
-            jcr->JobStatus);
    }
-   Dmsg3(800, "MaxWaitTime result: %scancel JCR %p (%s)\n",
-         cancel ? "" : "do not ", jcr, jcr->job);
-#endif
+
    return cancel;
 }
 
@@ -567,8 +513,6 @@ static bool job_check_maxwaittime(JCR *control_jcr, JCR *jcr)
  */
 static bool job_check_maxruntime(JCR *control_jcr, JCR *jcr)
 {
-   bool cancel = false;
-
    if (jcr->job->MaxRunTime == 0 || job_canceled(jcr)) {
       return false;
    }
@@ -578,37 +522,7 @@ static bool job_check_maxruntime(JCR *control_jcr, JCR *jcr)
       return false;
    }
 
-#ifdef xxx
-   switch (jcr->JobStatus) {
-   case JS_Created:
-   case JS_Running:
-   case JS_Blocked:
-   case JS_WaitFD:
-   case JS_WaitSD:
-   case JS_WaitStoreRes:
-   case JS_WaitClientRes:
-   case JS_WaitJobRes:
-   case JS_WaitPriority:
-   case JS_WaitMaxJobs:
-   case JS_WaitStartTime:
-   case JS_Differences:
-      cancel = true;
-      break;
-   case JS_Terminated:
-   case JS_ErrorTerminated:
-   case JS_Canceled:
-   case JS_FatalError:
-      cancel = false;
-      break;
-   default:
-      Jmsg1(jcr, M_ERROR, 0, _("Unhandled job status code %d\n"),
-            jcr->JobStatus);
-   }
-
-   Dmsg3(200, "MaxRunTime result: %scancel JCR %p (%s)\n",
-         cancel ? "" : "do not ", jcr, jcr->job);
-#endif
-   return cancel;
+   return true;
 }
 
 /*
@@ -854,27 +768,6 @@ void dird_free_jcr_pointers(JCR *jcr)
       free_pool_memory(jcr->fname);
       jcr->fname = NULL;
    }
-   if (jcr->pool_source) {
-      free_pool_memory(jcr->pool_source);
-      jcr->pool_source = NULL;
-   }
-   if (jcr->rpool_source) {
-      free_pool_memory(jcr->rpool_source);
-      jcr->rpool_source = NULL;
-   }
-   if (jcr->wstore_source) {
-      free_pool_memory(jcr->wstore_source);
-      jcr->wstore_source = NULL;
-   }
-   if (jcr->rstore_source) {
-      free_pool_memory(jcr->rstore_source);
-      jcr->rstore_source = NULL;
-   }
-   if (jcr->stime) {
-      Dmsg0(200, "Free JCR stime\n");
-      free_pool_memory(jcr->stime);
-      jcr->stime = NULL;
-   }
    if (jcr->RestoreBootstrap) {
       free(jcr->RestoreBootstrap);
       jcr->RestoreBootstrap = NULL;
@@ -907,6 +800,40 @@ void dird_free_jcr(JCR *jcr)
       pthread_cond_destroy(&jcr->term_wait);
       jcr->term_wait_inited = false;
    }
+   if (jcr->db) {
+      db_close_database(jcr, jcr->db);
+      jcr->db = NULL;
+   }
+   if (jcr->db_batch) {
+      db_close_database(jcr, jcr->db_batch);
+      jcr->db_batch = NULL;
+   }
+   if (jcr->stime) {
+      Dmsg0(200, "Free JCR stime\n");
+      free_pool_memory(jcr->stime);
+      jcr->stime = NULL;
+   }
+   if (jcr->fname) {
+      Dmsg0(200, "Free JCR fname\n");
+      free_pool_memory(jcr->fname);
+      jcr->fname = NULL;
+   }
+   if (jcr->pool_source) {
+      free_pool_memory(jcr->pool_source);
+      jcr->pool_source = NULL;
+   }
+   if (jcr->rpool_source) {
+      free_pool_memory(jcr->rpool_source);
+      jcr->rpool_source = NULL;
+   }
+   if (jcr->wstore_source) {
+      free_pool_memory(jcr->wstore_source);
+      jcr->wstore_source = NULL;
+   }
+   if (jcr->rstore_source) {
+      free_pool_memory(jcr->rstore_source);
+      jcr->rstore_source = NULL;
+   }
 
    /* Delete lists setup to hold storage pointers */
    free_rwstorage(jcr);
@@ -957,6 +884,12 @@ void set_jcr_defaults(JCR *jcr, JOB *job)
    case JT_RESTORE:
       jcr->JobLevel = L_NONE;
       break;
+   case JT_MIGRATE:
+      if (!jcr->rpool_source) {
+         jcr->rpool_source = get_pool_memory(PM_MESSAGE);
+         pm_strcpy(jcr->rpool_source, _("unknown source"));
+      }
+      /* Fall-through wanted */
    default:
       jcr->JobLevel = job->JobLevel;
       break;
@@ -968,6 +901,7 @@ void set_jcr_defaults(JCR *jcr, JOB *job)
       jcr->pool_source = get_pool_memory(PM_MESSAGE);
       pm_strcpy(jcr->pool_source, _("unknown source"));
    }
+
    jcr->JobPriority = job->Priority;
    /* Copy storage definitions -- deleted in dir_free_jcr above */
    if (job->storage) {