]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/mac.c
dhb Added comments for each function. There are questions above
[bacula/bacula] / bacula / src / stored / mac.c
index 5e51f453f642a91e8bfc42d06e61c4ab8ce1c629..900701eba4c1cbffa231e54439309267c9e23ebb 100644 (file)
@@ -7,19 +7,32 @@
  *   Version $Id$
  */
 /*
-   Copyright (C) 2006 Kern Sibbald
+   Bacula® - The Network Backup Solution
 
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as amended with additional clauses defined in the
-   file LICENSE in the main source directory.
+   Copyright (C) 2006-2006 Free Software Foundation Europe e.V.
 
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
-   the file LICENSE for additional details.
+   The main author of Bacula is Kern Sibbald, with contributions from
+   many others, a complete list can be found in the file AUTHORS.
+   This program is Free Software; you can redistribute it and/or
+   modify it under the terms of version two of the GNU General Public
+   License as published by the Free Software Foundation plus additions
+   that are listed in the file LICENSE.
 
- */
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+   Bacula® is a registered trademark of John Walker.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+   Switzerland, email:ftf@fsfeurope.org.
+*/
 
 #include "bacula.h"
 #include "stored.h"
@@ -62,55 +75,70 @@ bool do_mac(JCR *jcr)
 
    Dmsg0(20, "Start read data.\n");
 
+   if (!jcr->read_dcr || !jcr->dcr) {
+      Jmsg(jcr, M_FATAL, 0, _("Read and write devices not properly initialized.\n"));
+      goto bail_out;
+   }
+   Dmsg2(100, "read_dcr=%p write_dcr=%p\n", jcr->read_dcr, jcr->dcr);
+
 
    create_restore_volume_list(jcr);
-   if (jcr->NumVolumes == 0) {
+   if (jcr->NumReadVolumes == 0) {
       Jmsg(jcr, M_FATAL, 0, _("No Volume names found for %s.\n"), Type);
-      free_restore_volume_list(jcr);
-      return false;
+      goto bail_out;
    }
 
-   Dmsg3(200, "Found %d volumes names for %s. First=%s\n", jcr->NumVolumes,
+   Dmsg3(200, "Found %d volumes names for %s. First=%s\n", jcr->NumReadVolumes,
       jcr->VolList->VolumeName, Type);
 
-   /* Ready device for reading */
-   if (!acquire_device_for_read(jcr->read_dcr)) {
-      ok = false;
-      goto bail_out;
-   }
-
-   if (!acquire_device_for_append(jcr->dcr)) {
+   /* Ready devices for reading and writing */
+   if (!acquire_device_for_read(jcr->read_dcr) ||
+       !acquire_device_for_append(jcr->dcr)) {
       set_jcr_job_status(jcr, JS_ErrorTerminated);
-      ok = false;
       goto bail_out;
    }
+
+   Dmsg2(200, "===== After acquire pos %u:%u\n", jcr->dcr->dev->file, jcr->dcr->dev->block_num);
+     
+
+   set_jcr_job_status(jcr, JS_Running);
+   dir_send_job_status(jcr);
+
    jcr->dcr->VolFirstIndex = jcr->dcr->VolLastIndex = 0;
    jcr->run_time = time(NULL);
 
    ok = read_records(jcr->read_dcr, record_cb, mount_next_read_volume);
+   goto ok_out;
 
 bail_out:
-
-   dev = jcr->dcr->dev;
-   if (ok || dev->can_write()) {
-      /* Flush out final partial block of this session */
-      if (!write_block_to_device(jcr->dcr)) {
-         Jmsg2(jcr, M_FATAL, 0, _("Fatal append error on device %s: ERR=%s\n"),
-               dev->print_name(), strerror_dev(dev));
-         Dmsg0(100, _("Set ok=FALSE after write_block_to_device.\n"));
-         ok = false;
-      }
-   }  
+   ok = false;
+
+ok_out:
+   if (jcr->dcr) {
+      dev = jcr->dcr->dev;
+      if (ok || dev->can_write()) {
+         /* Flush out final partial block of this session */
+         if (!write_block_to_device(jcr->dcr)) {
+            Jmsg2(jcr, M_FATAL, 0, _("Fatal append error on device %s: ERR=%s\n"),
+                  dev->print_name(), dev->bstrerror());
+            Dmsg0(100, _("Set ok=FALSE after write_block_to_device.\n"));
+            ok = false;
+         }
+         Dmsg2(200, "Flush block to device pos %u:%u\n", dev->file, dev->block_num);
+      }  
 
 
-   if (ok && dev->is_dvd()) {
-      ok = dvd_close_job(jcr->dcr);   /* do DVD cleanup if any */
+      if (ok && dev->is_dvd()) {
+         ok = dvd_close_job(jcr->dcr);   /* do DVD cleanup if any */
+      }
+      /* Release the device -- and send final Vol info to DIR */
+      release_device(jcr->dcr);
    }
-   /* Release the device -- and send final Vol info to DIR */
-   release_device(jcr->dcr);
 
-   if (!release_device(jcr->read_dcr)) {
-      ok = false;
+   if (jcr->read_dcr) {
+      if (!release_device(jcr->read_dcr)) {
+         ok = false;
+      }
    }
 
    free_restore_volume_list(jcr);
@@ -134,7 +162,7 @@ bail_out:
    generate_daemon_event(jcr, "JobEnd");
    bnet_fsend(dir, Job_end, jcr->Job, jcr->JobStatus, jcr->JobFiles,
       edit_uint64(jcr->JobBytes, ec1));
-   Dmsg4(400, Job_end, jcr->Job, jcr->JobStatus, jcr->JobFiles, ec1); 
+   Dmsg4(200, Job_end, jcr->Job, jcr->JobStatus, jcr->JobFiles, ec1); 
        
    bnet_sig(dir, BNET_EOD);           /* send EOD to Director daemon */
 
@@ -148,41 +176,54 @@ bail_out:
  */
 static bool record_cb(DCR *dcr, DEV_RECORD *rec)
 {
-   bool ok = true;
    JCR *jcr = dcr->jcr;
+   DEVICE *dev = jcr->dcr->dev;
    char buf1[100], buf2[100];
    int32_t stream;   
    
+   /* If label and not for us, discard it */
+   if (rec->FileIndex < 0 && rec->match_stat <= 0) {
+      return true;
+   }
+   /* We want to write SOS_LABEL and EOS_LABEL discard all others */
    switch (rec->FileIndex) {                        
    case PRE_LABEL:
    case VOL_LABEL:
    case EOT_LABEL:
+   case EOM_LABEL:
       return true;                    /* don't write vol labels */
    }
+   /*
+    * Modify record SessionId and SessionTime to correspond to
+    * output.
+    */
    rec->VolSessionId = jcr->VolSessionId;
    rec->VolSessionTime = jcr->VolSessionTime;
-   Dmsg4(850, "before writ_rec FI=%d SessId=%d Strm=%s len=%d\n",
-      rec->FileIndex, rec->VolSessionId, 
-      stream_to_ascii(buf1, rec->Stream,rec->FileIndex),
-      rec->data_len);
+   Dmsg5(200, "before write_rec JobId=%d FI=%s SessId=%d Strm=%s len=%d\n",
+      jcr->JobId,
+      FI_to_ascii(buf1, rec->FileIndex), rec->VolSessionId,
+      stream_to_ascii(buf1, rec->Stream,rec->FileIndex), rec->data_len);
 
    while (!write_record_to_block(jcr->dcr->block, rec)) {
-      Dmsg2(850, "!write_record_to_block data_len=%d rem=%d\n", rec->data_len,
-                 rec->remainder);
+      Dmsg4(200, "!write_record_to_block blkpos=%u:%u len=%d rem=%d\n", 
+            dev->file, dev->block_num, rec->data_len, rec->remainder);
       if (!write_block_to_device(jcr->dcr)) {
-         DEVICE *dev = jcr->dcr->dev;
          Dmsg2(90, "Got write_block_to_dev error on device %s. %s\n",
-            dev->print_name(), strerror_dev(dev));
+            dev->print_name(), dev->bstrerror());
          Jmsg2(jcr, M_FATAL, 0, _("Fatal append error on device %s: ERR=%s\n"),
-               dev->print_name(), strerror_dev(dev));
+               dev->print_name(), dev->bstrerror());
          return false;
       }
+      Dmsg2(200, "===== Wrote block new pos %u:%u\n", dev->file, dev->block_num);
    }
    jcr->JobBytes += rec->data_len;   /* increment bytes this job */
    if (rec->FileIndex > 0) {
       jcr->JobFiles = rec->FileIndex;
+   } else {
+      return true;                    /* don't send LABELs to Dir */
    }
-   Dmsg4(850, "write_record FI=%s SessId=%d Strm=%s len=%d\n",
+   Dmsg5(500, "wrote_record JobId=%d FI=%s SessId=%d Strm=%s len=%d\n",
+      jcr->JobId,
       FI_to_ascii(buf1, rec->FileIndex), rec->VolSessionId,
       stream_to_ascii(buf2, rec->Stream, rec->FileIndex), rec->data_len);
 
@@ -205,5 +246,5 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec)
       }
    }
 
-   return ok;
+   return true;
 }