]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/read_record.c
update configure
[bacula/bacula] / bacula / src / stored / read_record.c
index 1ca911aa8345d18ba6d94381ecf4ac7789608ca3..968a9805f9e698c47ba3c32a4b5fdd7104ddbae0 100644 (file)
@@ -1,12 +1,12 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2002-2008 Free Software Foundation Europe e.V.
+   Copyright (C) 2002-2010 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.
    This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
+   modify it under the terms of version three of the GNU Affero General Public
    License as published by the Free Software Foundation and included
    in the file LICENSE.
 
@@ -15,7 +15,7 @@
    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
+   You should have received a copy of the GNU Affero 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.
@@ -38,7 +38,6 @@
  *
  *    Kern E. Sibbald, August MMII
  *
- *   Version $Id$
  */
 
 #include "bacula.h"
@@ -52,8 +51,14 @@ static bool try_repositioning(JCR *jcr, DEV_RECORD *rec, DCR *dcr);
 static char *rec_state_to_str(DEV_RECORD *rec);
 #endif
 
-static const int dbglvl = 200;
+static const int dbglvl = 500;
+static const int no_FileIndex = -999999;
 
+/*
+ * This subroutine reads all the records and passes them back to your
+ *  callback routine (also mount routine at EOM).
+ * You must not change any values in the DEV_RECORD packet
+ */
 bool read_records(DCR *dcr,
        bool record_cb(DCR *dcr, DEV_RECORD *rec),
        bool mount_cb(DCR *dcr))
@@ -63,6 +68,7 @@ bool read_records(DCR *dcr,
    DEV_BLOCK *block = dcr->block;
    DEV_RECORD *rec = NULL;
    uint32_t record;
+   int32_t lastFileIndex;
    bool ok = true;
    bool done = false;
    SESSION_LABEL sessrec;
@@ -123,6 +129,7 @@ bool read_records(DCR *dcr,
             continue;
 
          } else if (dev->at_eof()) {
+#ifdef neeeded_xxx
             if (verbose) {
                char *fp;
                uint32_t fp_num;
@@ -134,8 +141,9 @@ bool read_records(DCR *dcr,
                   fp_num = dev->file;
                }
                Jmsg(jcr, M_INFO, 0, _("End of %s %u on device %s, Volume \"%s\"\n"),
-                  fp, fp_num, dev->print_name(), dcr->VolumeName);
+                    fp, fp_num, dev->print_name(), dcr->VolumeName);
             }
+#endif
             Dmsg3(200, "End of file %u  on device %s, Volume \"%s\"\n",
                   dev->file, dev->print_name(), dcr->VolumeName);
             continue;
@@ -188,6 +196,7 @@ bool read_records(DCR *dcr,
             block->BlockNumber, rec->remainder);
       record = 0;
       rec->state = 0;
+      lastFileIndex = no_FileIndex;
       Dmsg1(dbglvl, "Block %s empty\n", is_block_empty(rec)?"is":"NOT");
       for (rec->state=0; ok && !is_block_empty(rec); ) {
          if (!read_record_from_block(dcr, block, rec)) {
@@ -250,7 +259,7 @@ bool read_records(DCR *dcr,
           * Apply BSR filter
           */
          if (jcr->bsr) {
-            rec->match_stat = match_bsr(jcr->bsr, rec, &dev->VolHdr, &sessrec);
+            rec->match_stat = match_bsr(jcr->bsr, rec, &dev->VolHdr, &sessrec, jcr);
             if (rec->match_stat == -1) { /* no more possible matches */
                done = true;   /* all items found, stop */
                Dmsg2(dbglvl, "All done=(file:block) %u:%u\n", dev->file, dev->block_num);
@@ -273,25 +282,39 @@ bool read_records(DCR *dcr,
                rec->VolSessionId, rec->VolSessionTime, rec->FileIndex);
             break;                    /* read second part of record */
          }
+
          Dmsg6(dbglvl, "OK callback. recno=%d state=%s blk=%d SI=%d ST=%d FI=%d\n", record,
                rec_state_to_str(rec), block->BlockNumber,
                rec->VolSessionId, rec->VolSessionTime, rec->FileIndex);
+         if (lastFileIndex != no_FileIndex && lastFileIndex != rec->FileIndex) {
+            if (is_this_bsr_done(jcr->bsr, rec) && try_repositioning(jcr, rec, dcr)) {
+               Dmsg2(dbglvl, "This bsr done, break pos %u:%u\n",
+                     dev->file, dev->block_num);
+               break;
+            }
+            Dmsg2(dbglvl, "==== inside LastIndex=%d FileIndex=%d\n", lastFileIndex, rec->FileIndex);
+         }
+         Dmsg2(dbglvl, "==== LastIndex=%d FileIndex=%d\n", lastFileIndex, rec->FileIndex);
+         lastFileIndex = rec->FileIndex;
          ok = record_cb(dcr, rec);
+#if 0
          /*
           * If we have a digest stream, we check to see if we have 
           *  finished the current bsr, and if so, repositioning will
           *  be turned on.
           */
          if (crypto_digest_stream_type(rec->Stream) != CRYPTO_DIGEST_NONE) {
-            Dmsg3(dbglvl, "Have digest FI=%u before bsr check pos %u:%u\n", rec->FileIndex,
+            Dmsg3(dbglvl, "=== Have digest FI=%u before bsr check pos %u:%u\n", rec->FileIndex,
                   dev->file, dev->block_num);
             if (is_this_bsr_done(jcr->bsr, rec) && try_repositioning(jcr, rec, dcr)) {
+               Dmsg1(dbglvl, "==== BSR done at FI=%d\n", rec->FileIndex);
                Dmsg2(dbglvl, "This bsr done, break pos %u:%u\n",
                      dev->file, dev->block_num);
                break;
             }
             Dmsg2(900, "After is_bsr_done pos %u:%u\n", dev->file, dev->block_num);
          }
+#endif
       } /* end for loop over records */
       Dmsg2(dbglvl, "After end recs in block. pos=%u:%u\n", dev->file, dev->block_num);
    } /* end for loop over blocks */
@@ -338,19 +361,17 @@ static bool try_repositioning(JCR *jcr, DEV_RECORD *rec, DCR *dcr)
        *   when find_next_bsr() is fixed not to return a bsr already
        *   completed.
        */
-      if (dev->file > bsr->volfile->sfile ||             
-         (dev->file == bsr->volfile->sfile && dev->block_num > bsr->volblock->sblock)) {
+      uint32_t block, file;
+      /* TODO: use dev->file_addr ? */
+      uint64_t dev_addr = (((uint64_t) dev->file)<<32) | dev->block_num;
+      uint64_t bsr_addr = get_bsr_start_addr(bsr, &file, &block);
+
+      if (dev_addr > bsr_addr) {
          return false;
       }
-      if (verbose) {
-         Jmsg(jcr, M_INFO, 0, _("Reposition from (file:block) %u:%u to %u:%u\n"),
-            dev->file, dev->block_num, bsr->volfile->sfile,
-            bsr->volblock->sblock);
-      }
       Dmsg4(10, "Try_Reposition from (file:block) %u:%u to %u:%u\n",
-            dev->file, dev->block_num, bsr->volfile->sfile,
-            bsr->volblock->sblock);
-      dev->reposition(dcr, bsr->volfile->sfile, bsr->volblock->sblock);
+            dev->file, dev->block_num, file, block);
+      dev->reposition(dcr, file, block);
       rec->Block = 0;
    }
    return false;
@@ -363,6 +384,7 @@ static BSR *position_to_first_file(JCR *jcr, DCR *dcr)
 {
    BSR *bsr = NULL;
    DEVICE *dev = dcr->dev;
+   uint32_t file, block;
    /*
     * Now find and position to first file and block
     *   on this tape.
@@ -370,11 +392,11 @@ static BSR *position_to_first_file(JCR *jcr, DCR *dcr)
    if (jcr->bsr) {
       jcr->bsr->reposition = true;    /* force repositioning */
       bsr = find_next_bsr(jcr->bsr, dev);
-      if (bsr && (bsr->volfile->sfile != 0 || bsr->volblock->sblock != 0)) {
+      
+      if (get_bsr_start_addr(bsr, &file, &block) > 0) {
          Jmsg(jcr, M_INFO, 0, _("Forward spacing Volume \"%s\" to file:block %u:%u.\n"),
-            dev->VolHdr.VolumeName,
-            bsr->volfile->sfile, bsr->volblock->sblock);
-         dev->reposition(dcr, bsr->volfile->sfile, bsr->volblock->sblock);
+              dev->VolHdr.VolumeName, file, block);
+         dev->reposition(dcr, file, block);
       }
    }
    return bsr;