]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/read.c
Use rentrant mysql lib, eliminate race in sql_list, Win32 streams, misc see kes-1.31
[bacula/bacula] / bacula / src / stored / read.c
index f4fa27b31d1ac8a5d426ff1f9e74567241b2c3bc..d59f5418f710e9aa039df1b7b02f5133cf993a4a 100644 (file)
@@ -6,7 +6,7 @@
  *   Version $Id$
  */
 /*
-   Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+   Copyright (C) 2000-2003 Kern Sibbald and John Walker
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -55,6 +55,7 @@ int do_read_data(JCR *jcr)
    BSOCK *ds;
    BSOCK *fd_sock = jcr->file_bsock;
    int ok = TRUE;
+   int done = FALSE;
    DEVICE *dev;
    DEV_RECORD *rec;
    DEV_BLOCK *block;
@@ -82,8 +83,17 @@ int do_read_data(JCR *jcr)
    block = new_block(dev);
 
    create_vol_list(jcr);
+   if (jcr->NumVolumes == 0) {
+      Jmsg(jcr, M_FATAL, 0, _("No Volume names found for restore.\n"));
+      free_block(block);
+      free_vol_list(jcr);
+      return 0;
+   }
+
+   Dmsg2(200, "Found %d volumes names to restore. First=%s\n", jcr->NumVolumes, 
+      jcr->VolList->VolumeName);
 
-   Dmsg1(20, "Found %d volumes names to restore.\n", jcr->NumVolumes);
+   pm_strcpy(&jcr->VolumeName, jcr->VolList->VolumeName);
 
    /* 
     * Ready device for reading, and read records
@@ -103,15 +113,15 @@ int do_read_data(JCR *jcr)
     *  Read records, apply BSR filtering, and return any that are 
     *   matched.
     */
-   for ( ;ok; ) {
-      if (job_cancelled(jcr)) {
+   for ( ;ok && !done; ) {
+      if (job_canceled(jcr)) {
         ok = FALSE;
         break;
       }
       /* Read Record */
       Dmsg1(500, "Main read_record. rem=%d\n", rec->remainder);
 
-      if (!read_block_from_device(dev, block)) {
+      if (block_is_empty(block) && !read_block_from_device(dev, block)) {
          Dmsg1(500, "Main read record failed. rem=%d\n", rec->remainder);
         if (dev->state & ST_EOT) {
            DEV_RECORD *record;
@@ -160,7 +170,11 @@ int do_read_data(JCR *jcr)
 
         /* Match BSR against current record */
         if (jcr->bsr) {
-           if (!match_bsr(jcr->bsr, rec, &dev->VolHdr, &sessrec)) {
+           int stat = match_bsr(jcr->bsr, rec, &dev->VolHdr, &sessrec);
+           if (stat == -1) {         /* no more possible matches */
+              done = TRUE;
+              break;
+           } else if (stat == 0) {   /* no match */
                Dmsg0(50, "BSR rejected record\n");
               rec->remainder = 0;
               continue;
@@ -184,6 +198,9 @@ int do_read_data(JCR *jcr)
          * out the data record
          */
         ds->msg = hdr;
+         Dmsg5(400, "Send to FD: SessId=%u SessTim=%u FI=%d Strm=%d, len=%d\n",
+           rec->VolSessionId, rec->VolSessionTime, rec->FileIndex, rec->Stream,
+           rec->data_len);
         if (!bnet_fsend(ds, rec_header, rec->VolSessionId, rec->VolSessionTime,
                rec->FileIndex, rec->Stream, rec->data_len)) {
             Dmsg1(30, ">filed: Error Hdr=%s\n", ds->msg);