]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/mac.c
This commit was manufactured by cvs2svn to create tag
[bacula/bacula] / bacula / src / dird / mac.c
index d0425523771c7aa7e80ffd7d322b39b1064b3879..163304779fdd8e7a5d83729445d66353580c454d 100644 (file)
@@ -8,14 +8,14 @@
  *  Basic tasks done here:
  *     Open DB and create records for this job.
  *     Open Message Channel with Storage daemon to tell him a job will be starting.
- *     Open connection with Storage daemon and pass him commands
+ *     Open connection with File daemon and pass him commands
  *       to do the backup.
- *     When the Storage daemon finishes the job, update the DB.
+ *     When the File daemon finishes the job, update the DB.
  *
  *   Version $Id$
  */
 /*
-   Copyright (C) 2004-2006 Kern Sibbald
+   Copyright (C) 2004-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
@@ -33,8 +33,6 @@
 #include "dird.h"
 #include "ua.h"
 
-static char OKbootstrap[] = "3000 OK bootstrap\n";
-
 /* 
  * Called here before the job is run to do the job
  *   specific setup.
@@ -42,7 +40,11 @@ static char OKbootstrap[] = "3000 OK bootstrap\n";
 bool do_mac_init(JCR *jcr)
 {
    POOL_DBR pr;
+   JOB_DBR jr;
+   JobId_t input_jobid;
    char *Name;
+   RESTORE_CTX rx;
+   UAContext *ua;
    const char *Type;
 
    switch(jcr->JobType) {
@@ -67,35 +69,36 @@ bool do_mac_init(JCR *jcr)
    /*
     * Find JobId of last job that ran.
     */
+   memcpy(&jr, &jcr->jr, sizeof(jr));
    Name = jcr->job->migration_job->hdr.name;
    Dmsg1(100, "find last jobid for: %s\n", NPRT(Name));
-   jcr->target_jr.JobType = JT_BACKUP;
-   if (!db_find_last_jobid(jcr, jcr->db, Name, &jcr->target_jr)) {
-      Jmsg(jcr, M_FATAL, 0, 
-           _("Previous job \"%s\" not found. ERR=%s\n"), Name,
-           db_strerror(jcr->db));
+   if (!db_find_last_jobid(jcr, jcr->db, Name, &jr)) {
+      Jmsg(jcr, M_FATAL, 0, _(
+           _("Unable to find JobId of previous Job for this client.\n")));
       return false;
    }
-   Dmsg1(100, "Last jobid=%d\n", jcr->target_jr.JobId);
+   input_jobid = jr.JobId;
+   Dmsg1(100, "Last jobid=%d\n", input_jobid);
 
-   if (!db_get_job_record(jcr, jcr->db, &jcr->target_jr)) {
+   jcr->previous_jr.JobId = input_jobid;
+   if (!db_get_job_record(jcr, jcr->db, &jcr->previous_jr)) {
       Jmsg(jcr, M_FATAL, 0, _("Could not get job record for previous Job. ERR=%s"),
            db_strerror(jcr->db));
       return false;
    }
-   if (jcr->target_jr.JobStatus != 'T') {
+   if (jcr->previous_jr.JobStatus != 'T') {
       Jmsg(jcr, M_FATAL, 0, _("Last Job %d did not terminate normally. JobStatus=%c\n"),
-         jcr->target_jr.JobId, jcr->target_jr.JobStatus);
+         input_jobid, jcr->previous_jr.JobStatus);
       return false;
    }
    Jmsg(jcr, M_INFO, 0, _("%s using JobId=%d Job=%s\n"),
-      Type, jcr->target_jr.JobId, jcr->target_jr.Job);
+      Type, jcr->previous_jr.JobId, jcr->previous_jr.Job);
 
 
    /*
     * Get the Pool record -- first apply any level defined pools
     */
-   switch (jcr->target_jr.JobLevel) {
+   switch (jcr->JobLevel) {
    case L_FULL:
       if (jcr->full_pool) {
          jcr->pool = jcr->full_pool;
@@ -125,19 +128,28 @@ bool do_mac_init(JCR *jcr)
          Jmsg(jcr, M_INFO, 0, _("Pool %s created in database.\n"), pr.Name);
       }
    }
+   jcr->PoolId = pr.PoolId;               /****FIXME**** this can go away */
    jcr->jr.PoolId = pr.PoolId;
 
-   /* If pool storage specified, use it instead of job storage */
-   copy_storage(jcr, jcr->pool->storage);
-
-   if (!jcr->storage) {
-      Jmsg(jcr, M_FATAL, 0, _("No Storage specification found in Job or Pool.\n"));
+   memset(&rx, 0, sizeof(rx));
+   rx.bsr = new_bsr();
+   rx.JobIds = "";                       
+   rx.bsr->JobId = jcr->previous_jr.JobId;
+   ua = new_ua_context(jcr);
+   complete_bsr(ua, rx.bsr);
+   rx.bsr->fi = new_findex();
+   rx.bsr->fi->findex = 1;
+   rx.bsr->fi->findex2 = jcr->previous_jr.JobFiles;
+   jcr->ExpectedFiles = write_bsr_file(ua, rx);
+   if (jcr->ExpectedFiles == 0) {
+      free_ua_context(ua);
+      free_bsr(rx.bsr);
       return false;
    }
+   free_ua_context(ua);
+   free_bsr(rx.bsr);
 
-   if (!create_restore_bootstrap_file(jcr)) {
-      return false;
-   }
+   jcr->needs_sd = true;
    return true;
 }
 
@@ -149,13 +161,9 @@ bool do_mac_init(JCR *jcr)
  */
 bool do_mac(JCR *jcr)
 {
-   POOL_DBR pr;
-   POOL *pool;
+   int stat;
    const char *Type;
    char ed1[100];
-   BSOCK *sd;
-   JOB *job, *tjob;
-   JCR *tjcr;
 
    switch(jcr->JobType) {
    case JT_MIGRATE:
@@ -173,99 +181,10 @@ bool do_mac(JCR *jcr)
    }
 
 
-   Dmsg4(100, "Target: Name=%s JobId=%d Type=%c Level=%c\n",
-      jcr->target_jr.Name, jcr->target_jr.JobId, 
-      jcr->target_jr.JobType, jcr->target_jr.JobLevel);
-
-   Dmsg4(100, "Current: Name=%s JobId=%d Type=%c Level=%c\n",
-      jcr->jr.Name, jcr->jr.JobId, 
-      jcr->jr.JobType, jcr->jr.JobLevel);
-
-   LockRes();
-   job = (JOB *)GetResWithName(R_JOB, jcr->jr.Name);
-   tjob = (JOB *)GetResWithName(R_JOB, jcr->target_jr.Name);
-   UnlockRes();
-   if (!job || !tjob) {
-      return false;
-   }
-
-   /* 
-    * Target jcr is the new Job that corresponds to the original
-    *  target job. It "runs" at the same time as the current 
-    *  migration job and becomes a new backup job that replaces
-    *  the original backup job.  Most operations on the current
-    *  migration jcr are also done on the target jcr.
-    */
-   tjcr = jcr->target_jcr = new_jcr(sizeof(JCR), dird_free_jcr);
-   memcpy(&tjcr->target_jr, &jcr->target_jr, sizeof(tjcr->target_jr));
-
-   /* Turn the tjcr into a "real" job */
-   set_jcr_defaults(tjcr, tjob);
-   if (!setup_job(tjcr)) {
-      return false;
-   }
-   /* Set output PoolId and FileSetId. */
-   tjcr->jr.PoolId = jcr->jr.PoolId;
-   tjcr->jr.FileSetId = jcr->jr.FileSetId;
-
-   /*
-    * Get the PoolId used with the original job. Then
-    *  find the pool name from the database record.
-    */
-   memset(&pr, 0, sizeof(pr));
-   pr.PoolId = tjcr->target_jr.PoolId;
-   if (!db_get_pool_record(jcr, jcr->db, &pr)) {
-      char ed1[50];
-      Jmsg(jcr, M_FATAL, 0, _("Pool for JobId %s not in database. ERR=%s\n"),
-            edit_int64(pr.PoolId, ed1), db_strerror(jcr->db));
-         return false;
-   }
-   /* Get the pool resource corresponding to the original job */
-   pool = (POOL *)GetResWithName(R_POOL, pr.Name);
-   if (!pool) {
-      Jmsg(jcr, M_FATAL, 0, _("Pool resource \"%s\" not found.\n"), pr.Name);
-      return false;
-   }
-
-   /* Check Migration time and High/Low water marks */
-   /* ***FIXME*** */
-
-   /* If pool storage specified, use it for restore */
-   copy_storage(tjcr, pool->storage);
-
-   /* If the original backup pool has a NextPool, make sure a 
-    *  record exists in the database.
-    */
-   if (pool->NextPool) {
-      memset(&pr, 0, sizeof(pr));
-      bstrncpy(pr.Name, pool->NextPool->hdr.name, sizeof(pr.Name));
-
-      while (!db_get_pool_record(jcr, jcr->db, &pr)) { /* get by Name */
-         /* Try to create the pool */
-         if (create_pool(jcr, jcr->db, pool->NextPool, POOL_OP_CREATE) < 0) {
-            Jmsg(jcr, M_FATAL, 0, _("Pool \"%s\" not in database. %s"), pr.Name,
-               db_strerror(jcr->db));
-            return false;
-         } else {
-            Jmsg(jcr, M_INFO, 0, _("Pool \"%s\" created in database.\n"), pr.Name);
-         }
-      }
-      /*
-       * put the "NextPool" resource pointer in our jcr so that we
-       * can pull the Storage reference from it.
-       */
-      tjcr->pool = jcr->pool = pool->NextPool;
-      tjcr->jr.PoolId = jcr->jr.PoolId = pr.PoolId;
-   }
-
-   /* If pool storage specified, use it instead of job storage for backup */
-   copy_storage(jcr, jcr->pool->storage);
-
    /* Print Job Start message */
    Jmsg(jcr, M_INFO, 0, _("Start %s JobId %s, Job=%s\n"),
         Type, edit_uint64(jcr->JobId, ed1), jcr->Job);
 
-   set_jcr_job_status(jcr, JS_Running);
    set_jcr_job_status(jcr, JS_Running);
    Dmsg2(100, "JobId=%d JobLevel=%c\n", jcr->jr.JobId, jcr->jr.JobLevel);
    if (!db_update_job_start_record(jcr, jcr->db, &jcr->jr)) {
@@ -273,12 +192,6 @@ bool do_mac(JCR *jcr)
       return false;
    }
 
-   if (!db_update_job_start_record(tjcr, tjcr->db, &tjcr->jr)) {
-      Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(tjcr->db));
-      return false;
-   }
-
-
    /*
     * Open a message channel connection with the Storage
     * daemon. This is to let him know that our client
@@ -287,52 +200,39 @@ bool do_mac(JCR *jcr)
     */
    Dmsg0(110, "Open connection with storage daemon\n");
    set_jcr_job_status(jcr, JS_WaitSD);
-   set_jcr_job_status(tjcr, JS_WaitSD);
    /*
     * Start conversation with Storage daemon
     */
    if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
       return false;
    }
-   sd = jcr->store_bsock;
    /*
     * Now start a job with the Storage daemon
     */
-   Dmsg2(000, "Read store=%s, write store=%s\n", 
-      ((STORE *)tjcr->storage->first())->hdr.name,
-      ((STORE *)jcr->storage->first())->hdr.name);
-   if (!start_storage_daemon_job(jcr, tjcr->storage, jcr->storage)) {
-      return false;
-   }
-   Dmsg0(150, "Storage daemon connection OK\n");
-
-   if (!send_bootstrap_file(jcr, sd) ||
-       !response(jcr, sd, OKbootstrap, "Bootstrap", DISPLAY_ERROR)) {
+   if (!start_storage_daemon_job(jcr, jcr->storage, jcr->storage)) {
       return false;
    }
-
-
    /*
     * Now start a Storage daemon message thread
     */
    if (!start_storage_daemon_message_thread(jcr)) {
       return false;
    }
+   Dmsg0(150, "Storage daemon connection OK\n");
 
-   if (!bnet_fsend(sd, "run")) {
-      return false;
-   }
-
+   /* Pickup Job termination data */
    set_jcr_job_status(jcr, JS_Running);
-   set_jcr_job_status(tjcr, JS_Running);
 
-   /* Pickup Job termination data */
    /* Note, the SD stores in jcr->JobFiles/ReadBytes/JobBytes/Errors */
    wait_for_storage_daemon_termination(jcr);
 
-   jcr->JobStatus = jcr->SDJobStatus;
-   if (jcr->JobStatus == JS_Terminated) {
-      mac_cleanup(jcr, jcr->JobStatus);
+   if (jcr->JobStatus != JS_Terminated) {
+      stat = jcr->JobStatus;
+   } else {
+      stat = jcr->SDJobStatus;
+   }
+   if (stat == JS_Terminated) {
+      mac_cleanup(jcr, stat);
       return true;
    }
    return false;
@@ -344,17 +244,15 @@ bool do_mac(JCR *jcr)
  */
 void mac_cleanup(JCR *jcr, int TermCode)
 {
-   char sdt[MAX_TIME_LENGTH], edt[MAX_TIME_LENGTH];
-   char ec1[30], ec2[30], ec3[30], ec4[30], elapsed[50];
-   char term_code[100], sd_term_msg[100];
+   char sdt[50], edt[50];
+   char ec1[30], ec2[30], ec3[30], ec4[30], ec5[30], compress[50];
+   char term_code[100], fd_term_msg[100], sd_term_msg[100];
    const char *term_msg;
    int msg_type;
    MEDIA_DBR mr;
-   double kbps;
+   double kbps, compression;
    utime_t RunTime;
    const char *Type;
-   JCR *tjcr = jcr->target_jcr;
-   POOL_MEM query(PM_MESSAGE);
 
    switch(jcr->JobType) {
    case JT_MIGRATE:
@@ -371,31 +269,12 @@ void mac_cleanup(JCR *jcr, int TermCode)
       break;
    }
 
-   /* Ensure target is defined to avoid a lot of testing */
-   if (!tjcr) {
-      tjcr = jcr;
-   }
-   tjcr->JobFiles = jcr->JobFiles = jcr->SDJobFiles;
-   tjcr->JobBytes = jcr->JobBytes = jcr->SDJobBytes;
-   tjcr->VolSessionId = jcr->VolSessionId;
-   tjcr->VolSessionTime = jcr->VolSessionTime;
-
    Dmsg2(100, "Enter mac_cleanup %d %c\n", TermCode, TermCode);
    dequeue_messages(jcr);             /* display any queued messages */
    memset(&mr, 0, sizeof(mr));
    set_jcr_job_status(jcr, TermCode);
-   set_jcr_job_status(tjcr, TermCode);
-
 
    update_job_end_record(jcr);        /* update database */
-   update_job_end_record(tjcr);
-
-   Mmsg(query, "UPDATE Job SET StartTime='%s',EndTime='%s',"
-               "JobTDate=%s WHERE JobId=%s", 
-      jcr->target_jr.cStartTime, jcr->target_jr.cEndTime, 
-      edit_uint64(jcr->target_jr.JobTDate, ec1),
-      edit_uint64(tjcr->jr.JobId, ec2));
-   db_sql_query(tjcr->db, query.c_str(), NULL, NULL);
 
    if (!db_get_job_record(jcr, jcr->db, &jcr->jr)) {
       Jmsg(jcr, M_WARNING, 0, _("Error getting job record for stats: %s"),
@@ -410,20 +289,77 @@ void mac_cleanup(JCR *jcr, int TermCode)
       set_jcr_job_status(jcr, JS_ErrorTerminated);
    }
 
-   update_bootstrap_file(tjcr);
+   /* Now update the bootstrap file if any */
+   if (jcr->JobStatus == JS_Terminated && jcr->jr.JobBytes &&
+       jcr->job->WriteBootstrap) {
+      FILE *fd;
+      BPIPE *bpipe = NULL;
+      int got_pipe = 0;
+      char *fname = jcr->job->WriteBootstrap;
+      VOL_PARAMS *VolParams = NULL;
+      int VolCount;
+
+      if (*fname == '|') {
+         fname++;
+         got_pipe = 1;
+         bpipe = open_bpipe(fname, 0, "w");
+         fd = bpipe ? bpipe->wfd : NULL;
+      } else {
+         /* ***FIXME*** handle BASE */
+         fd = fopen(fname, jcr->JobLevel==L_FULL?"w+":"a+");
+      }
+      if (fd) {
+         VolCount = db_get_job_volume_parameters(jcr, jcr->db, jcr->JobId,
+                    &VolParams);
+         if (VolCount == 0) {
+            Jmsg(jcr, M_ERROR, 0, _("Could not get Job Volume Parameters to "
+                 "update Bootstrap file. ERR=%s\n"), db_strerror(jcr->db));
+             if (jcr->SDJobFiles != 0) {
+                set_jcr_job_status(jcr, JS_ErrorTerminated);
+             }
+
+         }
+         for (int i=0; i < VolCount; i++) {
+            /* Write the record */
+            fprintf(fd, "Volume=\"%s\"\n", VolParams[i].VolumeName);
+            fprintf(fd, "MediaType=\"%s\"\n", VolParams[i].MediaType);
+            fprintf(fd, "VolSessionId=%u\n", jcr->VolSessionId);
+            fprintf(fd, "VolSessionTime=%u\n", jcr->VolSessionTime);
+            fprintf(fd, "VolFile=%u-%u\n", VolParams[i].StartFile,
+                         VolParams[i].EndFile);
+            fprintf(fd, "VolBlock=%u-%u\n", VolParams[i].StartBlock,
+                         VolParams[i].EndBlock);
+            fprintf(fd, "FileIndex=%d-%d\n", VolParams[i].FirstIndex,
+                         VolParams[i].LastIndex);
+         }
+         if (VolParams) {
+            free(VolParams);
+         }
+         if (got_pipe) {
+            close_bpipe(bpipe);
+         } else {
+            fclose(fd);
+         }
+      } else {
+         berrno be;
+         Jmsg(jcr, M_ERROR, 0, _("Could not open WriteBootstrap file:\n"
+              "%s: ERR=%s\n"), fname, be.strerror());
+         set_jcr_job_status(jcr, JS_ErrorTerminated);
+      }
+   }
 
    msg_type = M_INFO;                 /* by default INFO message */
    switch (jcr->JobStatus) {
       case JS_Terminated:
          if (jcr->Errors || jcr->SDErrors) {
-            term_msg = _("%s OK -- with warnings");
+            term_msg = _("Backup OK -- with warnings");
          } else {
-            term_msg = _("%s OK");
+            term_msg = _("Backup OK");
          }
          break;
       case JS_FatalError:
       case JS_ErrorTerminated:
-         term_msg = _("*** %s Error ***");
+         term_msg = _("*** Backup Error ***");
          msg_type = M_ERROR;          /* Generate error message */
          if (jcr->store_bsock) {
             bnet_sig(jcr->store_bsock, BNET_TERMINATE);
@@ -433,7 +369,7 @@ void mac_cleanup(JCR *jcr, int TermCode)
          }
          break;
       case JS_Canceled:
-         term_msg = _("%s Canceled");
+         term_msg = _("Backup Canceled");
          if (jcr->store_bsock) {
             bnet_sig(jcr->store_bsock, BNET_TERMINATE);
             if (jcr->SD_msg_chan) {
@@ -442,10 +378,10 @@ void mac_cleanup(JCR *jcr, int TermCode)
          }
          break;
       default:
-         term_msg = _("Inappropriate %s term code");
+         term_msg = term_code;
+         sprintf(term_code, _("Inappropriate term code: %c\n"), jcr->JobStatus);
          break;
    }
-   bsnprintf(term_code, sizeof(term_code), term_msg, Type);
    bstrftimes(sdt, sizeof(sdt), jcr->jr.StartTime);
    bstrftimes(edt, sizeof(edt), jcr->jr.EndTime);
    RunTime = jcr->jr.EndTime - jcr->jr.StartTime;
@@ -454,7 +390,7 @@ void mac_cleanup(JCR *jcr, int TermCode)
    } else {
       kbps = (double)jcr->jr.JobBytes / (1000 * RunTime);
    }
-   if (!db_get_job_volume_names(tjcr, tjcr->db, tjcr->jr.JobId, &tjcr->VolumeName)) {
+   if (!db_get_job_volume_names(jcr, jcr->db, jcr->jr.JobId, &jcr->VolumeName)) {
       /*
        * Note, if the job has erred, most likely it did not write any
        *  tape, so suppress this "error" message since in that case
@@ -462,19 +398,28 @@ void mac_cleanup(JCR *jcr, int TermCode)
        *  normal exit should we complain about this error.
        */
       if (jcr->JobStatus == JS_Terminated && jcr->jr.JobBytes) {
-         Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(tjcr->db));
+         Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
       }
-      tjcr->VolumeName[0] = 0;         /* none */
+      jcr->VolumeName[0] = 0;         /* none */
    }
 
+   if (jcr->ReadBytes == 0) {
+      bstrncpy(compress, "None", sizeof(compress));
+   } else {
+      compression = (double)100 - 100.0 * ((double)jcr->JobBytes / (double)jcr->ReadBytes);
+      if (compression < 0.5) {
+         bstrncpy(compress, "None", sizeof(compress));
+      } else {
+         bsnprintf(compress, sizeof(compress), "%.1f %%", (float)compression);
+      }
+   }
+   jobstatus_to_ascii(jcr->FDJobStatus, fd_term_msg, sizeof(fd_term_msg));
    jobstatus_to_ascii(jcr->SDJobStatus, sd_term_msg, sizeof(sd_term_msg));
 
 // bmicrosleep(15, 0);                /* for debugging SIGHUP */
 
    Jmsg(jcr, msg_type, 0, _("Bacula %s (%s): %s\n"
-"  Old Backup JobId:       %u\n"
-"  New Backup JobId:       %u\n"
-"  JobId:                  %u\n"
+"  JobId:                  %d\n"
 "  Job:                    %s\n"
 "  Backup Level:           %s%s\n"
 "  Client:                 %s\n"
@@ -482,23 +427,24 @@ void mac_cleanup(JCR *jcr, int TermCode)
 "  Pool:                   \"%s\"\n"
 "  Start time:             %s\n"
 "  End time:               %s\n"
-"  Elapsed time:           %s\n"
-"  Priority:               %d\n"
+"  FD Files Written:       %s\n"
 "  SD Files Written:       %s\n"
-"  SD Bytes Written:       %s (%sB)\n"
+"  FD Bytes Written:       %s\n"
+"  SD Bytes Written:       %s\n"
 "  Rate:                   %.1f KB/s\n"
+"  Software Compression:   %s\n"
 "  Volume name(s):         %s\n"
 "  Volume Session Id:      %d\n"
 "  Volume Session Time:    %d\n"
 "  Last Volume Bytes:      %s\n"
+"  Non-fatal FD errors:    %d\n"
 "  SD Errors:              %d\n"
+"  FD termination status:  %s\n"
 "  SD termination status:  %s\n"
 "  Termination:            %s\n\n"),
    VERSION,
    LSMDATE,
-        edt, 
-        jcr->target_jr.JobId,
-        tjcr->jr.JobId,
+        edt,
         jcr->jr.JobId,
         jcr->jr.Job,
         level_to_str(jcr->JobLevel), jcr->since,
@@ -507,22 +453,21 @@ void mac_cleanup(JCR *jcr, int TermCode)
         jcr->pool->hdr.name,
         sdt,
         edt,
-        edit_utime(RunTime, elapsed, sizeof(elapsed)),
-        jcr->JobPriority,
-        edit_uint64_with_commas(jcr->SDJobFiles, ec2),
-        edit_uint64_with_commas(jcr->SDJobBytes, ec3),
-        edit_uint64_with_suffix(jcr->jr.JobBytes, ec4),
+        edit_uint64_with_commas(jcr->jr.JobFiles, ec1),
+        edit_uint64_with_commas(jcr->SDJobFiles, ec4),
+        edit_uint64_with_commas(jcr->jr.JobBytes, ec2),
+        edit_uint64_with_commas(jcr->SDJobBytes, ec5),
         (float)kbps,
-        tjcr->VolumeName,
+        compress,
+        jcr->VolumeName,
         jcr->VolSessionId,
         jcr->VolSessionTime,
-        edit_uint64_with_commas(mr.VolBytes, ec1),
+        edit_uint64_with_commas(mr.VolBytes, ec3),
+        jcr->Errors,
         jcr->SDErrors,
+        fd_term_msg,
         sd_term_msg,
-        term_code);
+        term_msg);
 
-   Dmsg1(100, "Leave mac_cleanup() target_jcr=0x%x\n", jcr->target_jcr);
-   if (jcr->target_jcr) {
-      free_jcr(jcr->target_jcr);
-   }
+   Dmsg0(100, "Leave mac_cleanup()\n");
 }