]> git.sur5r.net Git - bacula/bacula/commitdiff
Fix bad bsr generation, make restore forward space more, misc cleanups
authorKern Sibbald <kern@sibbald.com>
Mon, 6 Oct 2003 15:47:55 +0000 (15:47 +0000)
committerKern Sibbald <kern@sibbald.com>
Mon, 6 Oct 2003 15:47:55 +0000 (15:47 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@733 91ce42f0-d328-0410-95d8-f526ca767f89

14 files changed:
bacula/kernstodo
bacula/src/dird/bsr.c
bacula/src/dird/ua_restore.c
bacula/src/filed/job.c
bacula/src/filed/restore.c
bacula/src/findlib/attribs.c
bacula/src/findlib/bfile.c
bacula/src/stored/block.c
bacula/src/stored/btape.c
bacula/src/stored/fd_cmds.c
bacula/src/stored/job.c
bacula/src/stored/match_bsr.c
bacula/src/stored/read_record.c
bacula/src/version.h

index ae2030862d1fd17ea20b4baebf4e0358d21cc106..5170cb51e2afcb5ceb54ce7919c85bd18eb34152 100644 (file)
@@ -21,11 +21,9 @@ Testing to do: (painful)
 - Test cancel at EOM.       
 - Test not zeroing Autochanger slot when it is wrong.
 - Figure out how to use ssh or stunnel to protect Bacula communications.
-- Test connect timeouts.
 
 For 1.33 Testing/Documentation:
-- Combine the 3 places that search run records for the next
-  job. Use find_job_pool() modified in ua_output.c
+- Fix FreeBSD build with tcp_wrapper -- should not have -lnsl
 - Document to start higher priorty jobs before lower ones.
 - suppress "Do not forget to mount the drive!!!" if error
 - Document new records in Director. SDAddress SDDeviceName, SDPassword.
@@ -35,6 +33,9 @@ For 1.33 Testing/Documentation:
 - Add counter variable test.
                 
 For 1.33
+- Either restrict the characters in a name, or fix the problem 
+  emailing with names containing / (smtp command line breaks).
+- Eliminate ua_retention.c (retentioncmd) if possible.
 - Eliminate orphaned jobs: dbcheck, normal pruning, delete job command.
   Hm.  Well, there are the remaining orphaned job records:
 
@@ -75,6 +76,11 @@ For 1.33
      2)  add an option to the purge command to manually purge all jobs with
          no associated volume.
 
+     I think Restore jobs also fall into category 2 above ....  so one might
+     want to make that "The Job record has an EndTime,, but no associated
+     JobMedia record, and is not a Restore job."  
+- Implement RestoreJobRetention? Maybe better "JobRetention" in a Job,
+  which would take precidence over the Catalog "JobRetention".
 - Implement Label Format in Add and Label console commands.
 - make "btape /tmp" work.
 - Make sure a rescheduled job is properly reported by status.
@@ -1011,3 +1017,7 @@ Done: (see kernsdone for more)
 - Document that it is safe to use the drive when the lights stop flashing.
 - Document all the status codes JobLevel, JobType, JobStatus.
 - Add GUI interface to manual
+- Combine the 3 places that search run records for the next
+  job. Use find_job_pool() modified in ua_output.c
+- Test connect timeouts.
+
index ae8ddf2a7e27830a24c0b2ff5983bd6fbba6aae8..2a362192c15f9176c230bb24135460ff6f8cd51c 100644 (file)
@@ -35,6 +35,7 @@
 
 /* Forward referenced functions */
 static void write_bsr(UAContext *ua, RBSR *bsr, FILE *fd);
+void print_bsr(UAContext *ua, RBSR *bsr);
 
 
 /*
@@ -62,20 +63,26 @@ static void free_findex(RBSR_FINDEX *fi)
  *  range regardless of volume. The FirstIndex and LastIndex
  *  passed in here are for the current volume, so when 
  *  writing out the fi, constrain them to those values.
+ *
+ * We are called here once for each JobMedia record
+ *  for each Volume.
  */
 static void write_findex(UAContext *ua, RBSR_FINDEX *fi, 
              int32_t FirstIndex, int32_t LastIndex, FILE *fd) 
 {
-   if (fi) {
+   for ( ; fi; fi=fi->next) {
       int32_t findex, findex2;
-      findex = fi->findex < FirstIndex ? FirstIndex : fi->findex;
-      findex2 = fi->findex2 > LastIndex ? LastIndex : fi->findex2;
-      if (findex == findex2) {
-         fprintf(fd, "FileIndex=%d\n", findex);
-      } else {
-         fprintf(fd, "FileIndex=%d-%d\n", findex, findex2);
+      if ((fi->findex >= FirstIndex && fi->findex <= LastIndex) ||
+         (fi->findex2 >= FirstIndex && fi->findex2 <= LastIndex) ||
+         (fi->findex < FirstIndex && fi->findex2 > LastIndex)) {
+        findex = fi->findex < FirstIndex ? FirstIndex : fi->findex;
+        findex2 = fi->findex2 > LastIndex ? LastIndex : fi->findex2;
+        if (findex == findex2) {
+            fprintf(fd, "FileIndex=%d\n", findex);
+        } else {
+            fprintf(fd, "FileIndex=%d-%d\n", findex, findex2);
+        }
       }
-      write_findex(ua, fi->next, FirstIndex, LastIndex, fd);
    }
 }
 
@@ -101,13 +108,15 @@ static bool is_volume_selected(RBSR_FINDEX *fi,
 
 static void print_findex(UAContext *ua, RBSR_FINDEX *fi)
 {
-   if (fi) {
+   bsendmsg(ua, "fi=0x%x\n", (unsigned)fi);
+   for ( ; fi; fi=fi->next) {
       if (fi->findex == fi->findex2) {
          bsendmsg(ua, "FileIndex=%d\n", fi->findex);
+//       Dmsg1(000, "FileIndex=%d\n", fi->findex);
       } else {
          bsendmsg(ua, "FileIndex=%d-%d\n", fi->findex, fi->findex2);
+//       Dmsg2(000, "FileIndex=%d-%d\n", fi->findex, fi->findex2);
       }
-      print_findex(ua, fi->next);
    }
 }
 
@@ -210,6 +219,10 @@ int write_bsr_file(UAContext *ua, RBSR *bsr)
 static void write_bsr(UAContext *ua, RBSR *bsr, FILE *fd)
 {
    if (bsr) {
+      /*
+       * For a given volume, loop over all the JobMedia records.
+       *   VolCount is the number of JobMedia records.
+       */
       for (int i=0; i < bsr->VolCount; i++) {
         if (!is_volume_selected(bsr->fi, bsr->VolParams[i].FirstIndex,
              bsr->VolParams[i].LastIndex)) {
@@ -233,7 +246,7 @@ static void write_bsr(UAContext *ua, RBSR *bsr, FILE *fd)
    }
 }
 
-static void print_bsr(UAContext *ua, RBSR *bsr)
+void print_bsr(UAContext *ua, RBSR *bsr)
 {
    if (bsr) {
       for (int i=0; i < bsr->VolCount; i++) {
@@ -296,7 +309,7 @@ void add_findex(RBSR *bsr, uint32_t JobId, int32_t findex)
    }
 
    /* 
-    * At this point, bsr points to bsr containing JobId,
+    * At this point, bsr points to bsr containing this JobId,
     *  and we are sure that there is at least one fi record.
     */
    lfi = fi = bsr->fi;
@@ -318,6 +331,10 @@ void add_findex(RBSR *bsr, uint32_t JobId, int32_t findex)
       if (findex == (fi->findex2 + 1)) {  /* extend up */
         RBSR_FINDEX *nfi;     
         fi->findex2 = findex;
+        /*
+         * If the following record contains one higher, merge its
+         *   file index by extending it up.
+         */
         if (fi->next && ((findex+1) == fi->next->findex)) { 
            nfi = fi->next;
            fi->findex2 = nfi->findex2;
index c195a50ef4a1199de5931e609fc618f37f274861..88e40b4d2770a393988d3c86668515448daa220c 100644 (file)
@@ -39,6 +39,7 @@
 
 /* Imported functions */
 extern int runcmd(UAContext *ua, char *cmd);
+extern void print_bsr(UAContext *ua, RBSR *bsr);
 
 /* Imported variables */
 extern char *uar_list_jobs,    *uar_file,        *uar_sel_files;
@@ -174,7 +175,6 @@ int restorecmd(UAContext *ua, char *cmd)
         free_rx(&rx);
         return 0;
       }
-//    print_bsr(ua, rx.bsr);
       write_bsr_file(ua, rx.bsr);
       bsendmsg(ua, _("\n%u file%s selected to restore.\n\n"), rx.selected_files,
          rx.selected_files==1?"":"s");
@@ -422,6 +422,9 @@ static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx)
         if (!get_client_name(ua, rx)) {
            return 0;
         }
+         bsendmsg(ua, _("Enter file names, or < to enter a filename\n"      
+                        "containg a list of file names, and terminate\n"
+                        "them with a blank line.\n"));
         for ( ;; ) {
             if (!get_cmd(ua, _("Enter filename: "))) {
               return 0;
@@ -513,6 +516,7 @@ static int insert_file_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *fi
    split_path_and_filename(rx, file);
    Mmsg(&rx->query, uar_jobid_fileindex, rx->path, rx->fname, rx->ClientName);
    rx->found = false;
+   /* Find and insert jobid and File Index */
    if (!db_sql_query(ua->db, rx->query, jobid_fileindex_handler, (void *)rx)) {
       bsendmsg(ua, _("Query failed: %s. ERR=%s\n"), 
         rx->query, db_strerror(ua->db));
index e79f6142bde2ba7147177c446da2af736a9a2830..1f9662d4bafb62b0d6325611784e86448bcc21d2 100644 (file)
@@ -1049,6 +1049,7 @@ static void filed_free_jcr(JCR *jcr)
    if (jcr->RestoreBootstrap) {
       unlink(jcr->RestoreBootstrap);
       free_pool_memory(jcr->RestoreBootstrap);
+      jcr->RestoreBootstrap = NULL;
    }
    if (jcr->last_fname) {
       free_pool_memory(jcr->last_fname);
@@ -1096,6 +1097,7 @@ static int send_bootstrap_file(JCR *jcr)
    char buf[2000];
    BSOCK *sd = jcr->store_bsock;
    char *bootstrap = "bootstrap\n";
+   int stat = 0;
 
    Dmsg1(400, "send_bootstrap_file: %s\n", jcr->RestoreBootstrap);
    if (!jcr->RestoreBootstrap) {
@@ -1106,7 +1108,7 @@ static int send_bootstrap_file(JCR *jcr)
       Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"), 
         jcr->RestoreBootstrap, strerror(errno));
       set_jcr_job_status(jcr, JS_ErrorTerminated);
-      return 0;
+      goto bail_out;
    }
    pm_strcpy(&sd->msg, bootstrap);  
    sd->msglen = strlen(sd->msg);
@@ -1119,7 +1121,16 @@ static int send_bootstrap_file(JCR *jcr)
    fclose(bs);
    if (!response(jcr, sd, OKSDbootstrap, "Bootstrap")) {
       set_jcr_job_status(jcr, JS_ErrorTerminated);
-      return 0;
+      goto bail_out;
    }
-   return 1;
+   stat = 1;
+
+bail_out:
+   if (jcr->RestoreBootstrap) {
+      unlink(jcr->RestoreBootstrap);
+      free_pool_memory(jcr->RestoreBootstrap);
+      jcr->RestoreBootstrap = NULL;
+   }
+
+   return stat;
 }
index 068306b060330a26d2dd2600516fe1e114c4247f..b7bb63320aa2f5c7229f3b6969f2d82146c0672f 100644 (file)
@@ -33,6 +33,7 @@
 static char rec_header[] = "rechdr %ld %ld %ld %ld %ld";
 
 /* Forward referenced functions */
+static char *zlib_strerror(int stat);
 
 #define RETRY 10                     /* retry wait time */
 
@@ -47,7 +48,7 @@ void do_restore(JCR *jcr)
    uint32_t size;
    uint32_t VolSessionId, VolSessionTime;
    int32_t file_index;
-   int extract = FALSE;
+   bool extract = false;
    BFILE bfd;
    int stat;
    uint32_t total = 0;               /* Job total but only 32 bits for debug */
@@ -125,7 +126,7 @@ void do_restore(JCR *jcr)
                Jmsg0(jcr, M_ERROR, 0, _("Logic error output file should be open\n"));
            }
            set_attributes(jcr, attr, &bfd);
-           extract = FALSE;
+           extract = false;
             Dmsg0(30, "Stop extracting.\n");
         }
 
@@ -157,14 +158,14 @@ void do_restore(JCR *jcr)
         jcr->num_files_examined++;
 
          Dmsg1(30, "Outfile=%s\n", attr->ofname);
-        extract = FALSE;
+        extract = false;
         stat = create_file(jcr, attr, &bfd, jcr->replace);
         switch (stat) {
         case CF_ERROR:
         case CF_SKIP:
            break;
         case CF_EXTRACT:
-           extract = TRUE;
+           extract = true;
            P(jcr->mutex);
            pm_strcpy(&jcr->last_fname, attr->ofname);
            V(jcr->mutex);
@@ -206,7 +207,8 @@ void do_restore(JCR *jcr)
                  if (blseek(&bfd, (off_t)fileAddr, SEEK_SET) < 0) {
                      Jmsg3(jcr, M_ERROR, 0, _("Seek to %s error on %s: ERR=%s\n"),
                         edit_uint64(fileAddr, ec1), attr->ofname, berror(&bfd));
-                    extract = FALSE;
+                    extract = false;
+                    bclose(&bfd);
                     continue;
                  }
               }
@@ -218,7 +220,8 @@ void do_restore(JCR *jcr)
            if ((uint32_t)bwrite(&bfd, wbuf, wsize) != wsize) {
                Dmsg0(0, "===Write error===\n");
                Jmsg2(jcr, M_ERROR, 0, _("Write error on %s: ERR=%s\n"), attr->ofname, berror(&bfd));
-              extract = FALSE;
+              extract = false;
+              bclose(&bfd);
               continue;
            } 
            total += wsize;
@@ -250,7 +253,8 @@ void do_restore(JCR *jcr)
                  if (blseek(&bfd, (off_t)fileAddr, SEEK_SET) < 0) {
                      Jmsg3(jcr, M_ERROR, 0, _("Seek to %s error on %s: ERR=%s\n"),
                         edit_uint64(fileAddr, ec1), attr->ofname, berror(&bfd));
-                    extract = FALSE;
+                    extract = false;
+                    bclose(&bfd);
                     continue;
                  }
               }
@@ -262,8 +266,10 @@ void do_restore(JCR *jcr)
             Dmsg2(100, "Comp_len=%d msglen=%d\n", compress_len, wsize);
            if ((stat=uncompress((Byte *)jcr->compress_buf, &compress_len, 
                  (const Byte *)wbuf, (uLong)wsize)) != Z_OK) {
-               Jmsg(jcr, M_ERROR, 0, _("Uncompression error. ERR=%d\n"), stat);
-              extract = FALSE;
+               Jmsg(jcr, M_ERROR, 0, _("Uncompression error on file %s. ERR=%s\n"), 
+                 attr->ofname, zlib_strerror(stat));
+              extract = false;
+              bclose(&bfd);
               continue;
            }
 
@@ -271,7 +277,8 @@ void do_restore(JCR *jcr)
            if ((uLong)bwrite(&bfd, jcr->compress_buf, compress_len) != compress_len) {
                Dmsg0(0, "===Write error===\n");
                Jmsg2(jcr, M_ERROR, 0, _("Write error on %s: %s\n"), attr->ofname, berror(&bfd));
-              extract = FALSE;
+              extract = false;
+              bclose(&bfd);
               continue;
            }
            total += compress_len;
@@ -282,7 +289,8 @@ void do_restore(JCR *jcr)
 #else
         if (extract) {
             Jmsg(jcr, M_ERROR, 0, _("GZIP data stream found, but GZIP not configured!\n"));
-           extract = FALSE;
+           extract = false;
+           bclose(&bfd);
            continue;
         }
 #endif
@@ -308,7 +316,7 @@ void do_restore(JCR *jcr)
                Jmsg0(jcr, M_ERROR, 0, _("Logic error output file should be open but is not.\n"));
            }
            set_attributes(jcr, attr, &bfd);
-           extract = FALSE;
+           extract = false;
         }
          Jmsg(jcr, M_ERROR, 0, _("Unknown stream=%d ignored. This shouldn't happen!\n"), stream);
          Dmsg2(0, "None of above!!! stream=%d data=%s\n", stream,sd->msg);
@@ -333,6 +341,7 @@ ok_out:
       free(jcr->compress_buf);
       jcr->compress_buf = NULL;
    }
+   bclose(&bfd);
    free_attr(attr);
    Dmsg2(10, "End Do Restore. Files=%d Bytes=%" lld "\n", jcr->JobFiles,
       jcr->JobBytes);
@@ -341,3 +350,29 @@ ok_out:
         non_support_data, non_support_attr);
    }
 }         
+
+/*
+ * Convert ZLIB error code into an ASCII message
+ */
+static char *zlib_strerror(int stat)
+{
+   if (stat >= 0) {
+      return "None";
+   }
+   switch (stat) {
+   case Z_ERRNO:
+      return "Zlib errno";
+   case Z_STREAM_ERROR:
+      return "Zlib stream error";
+   case Z_DATA_ERROR:
+      return "Zlib data error";
+   case Z_MEM_ERROR:
+      return "Zlib memory error";
+   case Z_BUF_ERROR:
+      return "Zlib buffer error";
+   case Z_VERSION_ERROR:
+      return "Zlib version error";
+   default:
+      return "*none*";
+   }
+}
index 27d92542624ebda39026ee08800cee9853a41d46..f0d65be64cebafa9eb498af37b99a9763de1e6e9 100755 (executable)
@@ -241,6 +241,7 @@ int set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd)
       if (is_bopen(ofd)) {
         bclose(ofd); 
       }
+      pm_strcpy(&attr->ofname, "*none*");
       return 1;
    }
 
@@ -249,6 +250,7 @@ int set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd)
       if (is_bopen(ofd)) {
         bclose(ofd); 
       }
+      pm_strcpy(&attr->ofname, "*none*");
       return 1;
    }
    /*
@@ -307,6 +309,7 @@ int set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd)
         stat = 0;
       }
    }
+   pm_strcpy(&attr->ofname, "*none*");
    umask(old_mask);
    return stat;
 }
index ba90a83938c96e867309af9dbb17993b8d0fd2e7..2ade59f41fb7f7737b6fbae8a92b667a1400e9e8 100644 (file)
@@ -485,6 +485,9 @@ int bclose(BFILE *bfd)
 { 
    int stat;  
    Dmsg1(50, "Close file %d\n", bfd->fid);
+   if (bfd->fid == -1) {
+      return 0;
+   }
    stat = close(bfd->fid);
    bfd->berrno = errno;
    bfd->fid = -1;
index bdb2fab3834557dfae9dd5d6d95e6dae2c607d36..bbdc478ed6c73db45eb7729d2ebe44df76f2ebf0 100644 (file)
@@ -399,7 +399,8 @@ int write_block_to_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
       Jmsg(jcr, M_INFO, 0, _("User defined maximum volume capacity %s exceeded on device %s.\n"),
            edit_uint64(max_cap, ed1),  dev->dev_name);
       block->write_failed = true;
-      weof_dev(dev, 2);              /* end the tape */
+      weof_dev(dev, 1);              /* end the tape */
+      weof_dev(dev, 1);
       dev->state |= (ST_EOF | ST_EOT | ST_WEOT);
       return 0;   
    }
@@ -472,7 +473,8 @@ int write_block_to_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
         wlen, stat, dev->block_num, block->BlockNumber, dev->dev_errno, strerror(dev->dev_errno));
 
       block->write_failed = true;
-      if (weof_dev(dev, 2) != 0) {        /* end the tape */
+      weof_dev(dev,1);
+      if (weof_dev(dev, 1) != 0) {        /* end the tape */
          Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
       }
       dev->state |= (ST_EOF | ST_EOT | ST_WEOT);
@@ -585,7 +587,7 @@ int read_block_from_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, bool check_bloc
    ssize_t stat;
    int looping;
    uint32_t BlockNumber;
-   int retry = 0;
+   int retry;
 
    if (dev_state(dev, ST_EOT)) {
       return 0;
@@ -601,12 +603,14 @@ reread:
       block->read_len = 0;
       return 0;
    }
+   retry = 0;
    do {
       stat = read(dev->fd, block->buf, (size_t)block->buf_len);
       if (retry == 1) {
         dev->VolCatInfo.VolCatErrors++;   
       }
    } while (stat == -1 && (errno == EINTR || errno == EIO) && retry++ < 11);
+// Dmsg1(000, "read stat = %d\n", stat);
    if (stat < 0) {
       Dmsg1(90, "Read device got: ERR=%s\n", strerror(errno));
       clrerror_dev(dev, -1);
index 7b2c5642fedf6c3558b903e648f9b367de405462..d81f177f9706438391fb11a9e37a0dc257b38852 100644 (file)
@@ -464,7 +464,7 @@ static void bsrcmd()
  */
 static void capcmd()
 {
-   printf(_("Device capabilities:\n"));
+   printf(_("Configured device capabilities:\n"));
    printf("%sEOF ", dev->capabilities & CAP_EOF ? "" : "!");
    printf("%sBSR ", dev->capabilities & CAP_BSR ? "" : "!");
    printf("%sBSF ", dev->capabilities & CAP_BSF ? "" : "!");
@@ -1735,6 +1735,7 @@ static void helpcmd()
 {
    unsigned int i;
    usage();
+   printf(_("Interactive commands:\n"));
    printf(_("  Command    Description\n  =======    ===========\n"));
    for (i=0; i<comsize; i++)
       printf("  %-10s %s\n", commands[i].key, commands[i].help);
@@ -1745,7 +1746,7 @@ static void usage()
 {
    fprintf(stderr, _(
 "\nVersion: " VERSION " (" BDATE ")\n\n"
-"Usage: btape [-c config_file] [-d debug_level] [device_name]\n"
+"Usage: btape [-c config_file] [-d debug_level] device_name\n"
 "       -c <file>   set configuration file to file\n"
 "       -dnn        set debug level to nn\n"
 "       -s          turn off signals\n"
index e4eaf9df49d51b9602847fabd8ed9ea899a49a39..e7129a25f301d3453eebf851914c31751dd6faca 100644 (file)
@@ -317,6 +317,7 @@ static int bootstrap_cmd(JCR *jcr)
    BSOCK *fd = jcr->file_bsock;
    POOLMEM *fname = get_pool_memory(PM_FNAME);
    FILE *bs;
+   int stat = 0;
 
    if (jcr->RestoreBootstrap) {
       unlink(jcr->RestoreBootstrap);
@@ -345,15 +346,18 @@ static int bootstrap_cmd(JCR *jcr)
    if (debug_level > 20) {
       dump_bsr(jcr->bsr, true);
    }
-   return bnet_fsend(fd, OK_bootstrap);
+   stat = 1;
 
 bail_out:
    unlink(jcr->RestoreBootstrap);
    free_pool_memory(jcr->RestoreBootstrap);
    jcr->RestoreBootstrap = NULL;
-   bnet_fsend(fd, ERROR_bootstrap);
-   return 0;
-
+   if (stat) {
+      return bnet_fsend(fd, OK_bootstrap);
+   } else {
+      bnet_fsend(fd, ERROR_bootstrap);
+      return 0;
+   }
 }
 
 
index 8673fa4757469bcffeff5669e5e0c23168e05dcc..57902162b0a57c39618fbc7214c9777ca530d2b4 100644 (file)
@@ -103,7 +103,7 @@ int job_cmd(JCR *jcr)
     */
    ojcr = get_jcr_by_full_name(job);
    if (ojcr && !ojcr->authenticated) {
-      Dmsg2(000, "Found ojcr=0x%x Job %s\n", (unsigned)ojcr, job);
+      Dmsg2(100, "Found ojcr=0x%x Job %s\n", (unsigned)ojcr, job);
       free_jcr(ojcr);
    }
    jcr->JobId = JobId;
index ece77a6bd24165fe62b2dfb1e32cca2006ce8439..44f903e3a8d6bc379aaa6a16e0f6ac83ca327fd3 100755 (executable)
@@ -77,8 +77,8 @@ int match_bsr_block(BSR *bsr, DEV_BLOCK *block)
       return 1;                      /* cannot fast reject */
    }
 
-   if (match_block_sesstime(bsr, bsr->sesstime, block)) {
-      return 1;
+   if (!match_block_sesstime(bsr, bsr->sesstime, block)) {
+      return 0;
    }
    return match_block_sessid(bsr, bsr->sessid, block);
 }
@@ -243,7 +243,7 @@ static int match_all(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec,
    if (bsr->done) {
       goto no_match;
    }
-   if (bsr->count && bsr->count <= bsr->found) {
+   if (bsr->count && bsr->found >= bsr->count) {
       bsr->done = true;
       bsr->root->reposition = true;
       Dmsg0(100, "bsr done from count\n");
index 8e34737869e67a9e9e3bfeae10f9426496876a92..1ef694db8bc47a0dc5640bd0e1ac7f743f1a1574 100644 (file)
@@ -34,6 +34,7 @@
 #include "stored.h"
 
 static void handle_session_record(DEVICE *dev, DEV_RECORD *rec, SESSION_LABEL *sessrec);
+static BSR *position_to_first_file(JCR *jcr, DEVICE *dev);
 #ifdef DEBUG
 static char *rec_state_to_str(DEV_RECORD *rec);
 #endif
@@ -52,6 +53,7 @@ int read_records(JCR *jcr,  DEVICE *dev,
 
    block = new_block(dev);
    recs = new dlist(rec, &rec->link);
+   position_to_first_file(jcr, dev);
 
    for ( ; ok && !done; ) {
       if (job_canceled(jcr)) {
@@ -59,18 +61,13 @@ int read_records(JCR *jcr,  DEVICE *dev,
         break;
       }
       if (!read_block_from_device(jcr, dev, block, CHECK_BLOCK_NUMBERS)) {
-         Dmsg0(20, "!read_record()\n");
         if (dev_state(dev, ST_EOT)) {
            DEV_RECORD *trec = new_record();
 
-            Dmsg3(100, "EOT. stat=%s blk=%d rem=%d\n", rec_state_to_str(rec), 
-                 block->BlockNumber, rec->remainder);
             Jmsg(jcr, M_INFO, 0, "End of Volume at file %u  on device %s, Volume \"%s\"\n", 
                 dev->file, dev_name(dev), jcr->VolumeName);
            if (!mount_cb(jcr, dev, block)) {
                Jmsg(jcr, M_INFO, 0, "End of all volumes.\n");
-               Dmsg3(100, "After mount next vol. stat=%s blk=%d rem=%d\n", rec_state_to_str(rec), 
-                 block->BlockNumber, rec->remainder);
               ok = FALSE;
               /*
                * Create EOT Label so that Media record may
@@ -79,13 +76,10 @@ int read_records(JCR *jcr,  DEVICE *dev,
                */
               trec->FileIndex = EOT_LABEL;
               trec->File = dev->file;
-              trec->Block = rec->Block; /* return block last read */
               ok = record_cb(jcr, dev, block, trec);
               free_record(trec);
               break;
            }
-            Dmsg3(100, "After mount next vol. stat=%s blk=%d rem=%d\n", rec_state_to_str(rec), 
-                 block->BlockNumber, rec->remainder);
            /*
             * We just have a new tape up, now read the label (first record)
             *  and pass it off to the callback routine, then continue
@@ -96,33 +90,15 @@ int read_records(JCR *jcr,  DEVICE *dev,
            handle_session_record(dev, trec, &sessrec);
            ok = record_cb(jcr, dev, block, trec);
            free_record(trec);
-           /*
-            * Now find and position to first file and block 
-            *   on this tape.
-            */
-           if (jcr->bsr) {
-              BSR *bsr;
-
-              jcr->bsr->reposition = true;
-              bsr = find_next_bsr(jcr->bsr, dev);
-              if (bsr) {
-                  Jmsg(jcr, M_INFO, 0, _("Forward spacing to file:block %u:%u.\n"), 
-                    bsr->volfile->sfile, bsr->volblock->sblock);
-                  Dmsg4(100, "Reposition new from (file:block) %d:%d to %d:%d\n",
-                       dev->file, dev->block_num, bsr->volfile->sfile,
-                       bsr->volblock->sblock);
-                 reposition_dev(dev, bsr->volfile->sfile, bsr->volblock->sblock);
-                  Dmsg2(100, "Now at (file:block) %d:%d\n",
-                       dev->file, dev->block_num);
-              }
-           }
+           position_to_first_file(jcr, dev);
            /* After reading label, we must read first data block */
            continue;
 
         } else if (dev_state(dev, ST_EOF)) {
-            Jmsg(jcr, M_INFO, 0, "Got EOF at file %u  on device %s, Volume \"%s\"\n", 
+           if (verbose) {
+               Jmsg(jcr, M_INFO, 0, "Got EOF at file %u  on device %s, Volume \"%s\"\n", 
                  dev->file, dev_name(dev), jcr->VolumeName);
-            Dmsg0(20, "read_record got eof. try again\n");
+           }
            continue;
         } else if (dev_state(dev, ST_SHORT)) {
             Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
@@ -134,16 +110,15 @@ int read_records(JCR *jcr,  DEVICE *dev,
            break;
         }
       }
-      Dmsg5(100, "Read block: dev=%d blk=%d VI=%u VT=%u blen=%d\n", dev->block_num, block->BlockNumber, 
+      Dmsg2(100, "New block at position=(file:block) %d:%d\n", dev->file, dev->block_num);
+      Dmsg5(100, "Read block: devblk=%d blk=%d VI=%u VT=%u blen=%d\n", dev->block_num, block->BlockNumber, 
         block->VolSessionId, block->VolSessionTime, block->block_len);
+#ifdef FAST_BLOCK_REJECTION
+      /* this does not stop when file/block are too big */
       if (!match_bsr_block(jcr->bsr, block)) {
-         Dmsg5(100, "reject Blk=%u blen=%u bVer=%d SessId=%u SessTim=%u\n",
-           block->BlockNumber, block->block_len, block->BlockVer,
-           block->VolSessionId, block->VolSessionTime);
         continue;
       }
-      Dmsg4(100, "Block: %d VI=%u VT=%u blen=%d\n", block->BlockNumber, 
-        block->VolSessionId, block->VolSessionTime, block->block_len);
+#endif
 
       /*
        * Get a new record for each Job as defined by
@@ -163,10 +138,12 @@ int read_records(JCR *jcr,  DEVICE *dev,
          Dmsg2(100, "New record for SI=%d ST=%d\n",
             block->VolSessionId, block->VolSessionTime);
       } else {
+#ifdef xxx
         if (rec->Block != 0 && (rec->Block+1) != block->BlockNumber) {
             Jmsg(jcr, M_ERROR, 0, _("Invalid block number. Expected %u, got %u\n"),
                 rec->Block+1, block->BlockNumber);
         }
+#endif 
       }
       Dmsg3(100, "After mount next vol. stat=%s blk=%d rem=%d\n", rec_state_to_str(rec), 
            block->BlockNumber, rec->remainder);
@@ -220,6 +197,7 @@ int read_records(JCR *jcr,  DEVICE *dev,
            int stat = match_bsr(jcr->bsr, rec, &dev->VolHdr, &sessrec);
            if (stat == -1) { /* no more possible matches */
               done = true;   /* all items found, stop */
+               Dmsg2(100, "All done=(file:block) %d:%d\n", dev->file, dev->block_num);
               break;
            } else if (stat == 0) {  /* no match */
               BSR *bsr;
@@ -237,6 +215,11 @@ int read_records(JCR *jcr,  DEVICE *dev,
                   Dmsg4(100, "Reposition from (file:block) %d:%d to %d:%d\n",
                     dev->file, dev->block_num, bsr->volfile->sfile,
                     bsr->volblock->sblock);
+                 if (verbose) {
+                     Jmsg(jcr, M_INFO, 0, "Reposition from (file:block) %d:%d to %d:%d\n",
+                       dev->file, dev->block_num, bsr->volfile->sfile,
+                       bsr->volblock->sblock);
+                 }
                  reposition_dev(dev, bsr->volfile->sfile, bsr->volblock->sblock);
                  rec->Block = 0;
                   Dmsg2(100, "Now at (file:block) %d:%d\n",
@@ -257,6 +240,7 @@ int read_records(JCR *jcr,  DEVICE *dev,
         ok = record_cb(jcr, dev, block, rec);
       } /* end for loop over records */
    } /* end for loop over blocks */
+   Dmsg2(100, "Position=(file:block) %d:%d\n", dev->file, dev->block_num);
 
    /* Walk down list and free all remaining allocated recs */
    for (rec=(DEV_RECORD *)recs->first(); rec; ) {
@@ -271,6 +255,30 @@ int read_records(JCR *jcr,  DEVICE *dev,
    return ok;
 }
 
+static BSR *position_to_first_file(JCR *jcr, DEVICE *dev)
+{
+   BSR *bsr = NULL;
+   /*
+    * Now find and position to first file and block 
+    *  on this tape.
+    */
+   if (jcr->bsr) {
+      jcr->bsr->reposition = true;
+      bsr = find_next_bsr(jcr->bsr, dev);
+      if (bsr) {
+         Jmsg(jcr, M_INFO, 0, _("Forward spacing to file:block %u:%u.\n"), 
+           bsr->volfile->sfile, bsr->volblock->sblock);
+         Dmsg4(100, "Reposition new from (file:block) %d:%d to %d:%d\n",
+              dev->file, dev->block_num, bsr->volfile->sfile,
+              bsr->volblock->sblock);
+        reposition_dev(dev, bsr->volfile->sfile, bsr->volblock->sblock);
+         Dmsg2(100, "Now at (file:block) %d:%d\n",
+              dev->file, dev->block_num);
+      }
+   }
+   return bsr;
+}
+
 
 static void handle_session_record(DEVICE *dev, DEV_RECORD *rec, SESSION_LABEL *sessrec)
 {
index 4b50d657e4d11e1a118cbb400a8791cedce9592d..8839fef8674fc5b6feb507ffd5d975bbdd190fad 100644 (file)
@@ -1,12 +1,12 @@
 /* */
-#undef  VERSION
-#define VERSION "1.32a"
+#undef VERSION
+#define VERSION "1.32b"
 #define VSTRING "1"
-#define BDATE   "04 Oct 2003"
-#define LSMDATE "04Oct03"
+#define BDATE   "08 Oct 2003"
+#define LSMDATE "08Oct03"
 
 /* Debug flags */
-#undef  DEBUG
+#undef DEBUG
 #define DEBUG 1
 #define TRACEBACK 1
 #define SMCHECK