]> git.sur5r.net Git - bacula/bacula/commitdiff
Backport more master code
authorKern Sibbald <kern@sibbald.com>
Sun, 19 Aug 2012 11:16:58 +0000 (13:16 +0200)
committerKern Sibbald <kern@sibbald.com>
Sat, 20 Apr 2013 12:50:53 +0000 (14:50 +0200)
bacula/src/stored/block.c
bacula/src/stored/bls.c
bacula/src/stored/btape.c
bacula/src/stored/dev.c
bacula/src/stored/label.c
bacula/src/stored/protos.h
bacula/src/stored/read_record.c
bacula/src/stored/record.c

index e859ae89bba525b398dff14e33cddee5a90e150d..b80c4a0737cafcf2e9a6660e30083bafe8b42cb2 100644 (file)
 #include "bacula.h"
 #include "stored.h"
 
+#ifdef DEBUG_BLOCK_CHECKSUM
+static const bool debug_block_checksum = true;
+#else
+static const bool debug_block_checksum = false;
+#endif
+
+#ifdef NO_TAPE_WRITE_TEST
+static const bool no_tape_write_test = true;
+#else
+static const bool no_tape_write_test = false;
+#endif
+
+
 static bool terminate_writing_volume(DCR *dcr);
 static bool do_new_file_bookkeeping(DCR *dcr);
 static bool do_dvd_size_checks(DCR *dcr);
@@ -345,6 +358,7 @@ bool DCR::write_block_to_device()
    DCR *dcr = this;
 
    if (dcr->spooling) {
+      Dmsg0(100, "Write to spool\n");
       stat = write_block_to_spool_file(dcr);
       return stat;
    }
@@ -363,6 +377,7 @@ bool DCR::write_block_to_device()
    if (dcr->NewVol || dcr->NewFile) {
       if (job_canceled(jcr)) {
          stat = false;
+         Dmsg0(100, "Canceled\n");
          goto bail_out;
       }
       /* Create a jobmedia record for this job */
@@ -372,6 +387,7 @@ bool DCR::write_block_to_device()
             dcr->getVolCatName(), jcr->Job);
          set_new_volume_parameters(dcr);
          stat = false;
+         Dmsg0(100, "cannot create media record\n");
          goto bail_out;
       }
       if (dcr->NewVol) {
@@ -411,11 +427,12 @@ bool DCR::write_block_to_dev()
    int hit_max1, hit_max2;
    bool ok = true;
    DCR *dcr = this;
+   uint32_t checksum;
 
-#ifdef NO_TAPE_WRITE_TEST
-   empty_block(block);
-   return true;
-#endif
+   if (no_tape_write_test) {
+      empty_block(block);
+      return true;
+   }
    if (job_canceled(jcr)) {
       return false;
    }
@@ -433,18 +450,22 @@ bool DCR::write_block_to_dev()
       Dmsg0(100, "return write_block_to_dev with ST_WEOT\n");
       dev->dev_errno = ENOSPC;
       Jmsg1(jcr, M_FATAL, 0,  _("Cannot write block. Device at EOM. dev=%s\n"), dev->print_name());
+      Dmsg1(100, "Attempt to write on read-only Volume. dev=%s\n", dev->print_name());
       return false;
    }
    if (!dev->can_append()) {
       dev->dev_errno = EIO;
       Jmsg1(jcr, M_FATAL, 0, _("Attempt to write on read-only Volume. dev=%s\n"), dev->print_name());
+      Dmsg1(100, "Attempt to write on read-only Volume. dev=%s\n", dev->print_name());
       return false;
    }
-
    if (!dev->is_open()) {
       Jmsg1(jcr, M_FATAL, 0, _("Attempt to write on closed device=%s\n"), dev->print_name());
+      Dmsg1(100, "Attempt to write on closed device=%s\n", dev->print_name());
       return false;
    }
+
    /*
     * Clear to the end of the buffer if it is not full,
     *  and on tape devices, apply min and fixed blocking.
@@ -473,12 +494,7 @@ bool DCR::write_block_to_dev()
       }
    }
 
-#ifdef DEBUG_BLOCK_CHECKSUM
-   uint32_t checksum;
    checksum = ser_block_header(block, dev->do_checksum());
-#else
-   ser_block_header(block, dev->do_checksum());
-#endif
 
    /* Limit maximum Volume size to value specified by user */
    hit_max1 = (dev->max_volume_size > 0) &&
@@ -558,14 +574,14 @@ bool DCR::write_block_to_dev()
 
    } while (stat == -1 && (errno == EBUSY || errno == EIO) && retry++ < 3);
 
-#ifdef DEBUG_BLOCK_CHECKSUM
-   uint32_t achecksum = ser_block_header(block, dev->do_checksum());
-   if (checksum != achecksum) {
-      Jmsg2(jcr, M_ERROR, 0, _("Block checksum changed during write: before=%ud after=%ud\n"),
-         checksum, achecksum);
-      dump_block(block, "with checksum error");
+   if (debug_block_checksum) {
+      uint32_t achecksum = ser_block_header(block, dev->do_checksum());
+      if (checksum != achecksum) {
+         Jmsg2(jcr, M_ERROR, 0, _("Block checksum changed during write: before=%ud after=%ud\n"),
+            checksum, achecksum);
+         dump_block(block, "with checksum error");
+      }
    }
-#endif
 
 #ifdef DEBUG_BLOCK_ZEROING
    if (bp[0] == 0 && bp[1] == 0 && bp[2] == 0 && block->buf[12] == 0) {
@@ -1067,6 +1083,7 @@ reread:
       Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
       dev->set_short_block();   
       block->read_len = block->binbuf = 0;
+      Dmsg2(200, "set block=%p binbuf=%d\n", block, block->binbuf);
       return false;             /* return error */
    }
 
index bcdd6e385f10a53338973c38c9d561db4a9581f4..771f8554841e60500030f995031f528a571fbfbc 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2012 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.
@@ -295,7 +295,7 @@ static void do_blocks(char *infname)
             DEV_RECORD *record;
             record = new_record();
             dcr->read_block_from_device(NO_BLOCK_NUMBER_CHECK);
-            read_record_from_block(dcr, block, record);
+            read_record_from_block(dcr, record);
             get_session_record(dev, record, &sessrec);
             free_record(record);
             Jmsg(jcr, M_INFO, 0, _("Mounted Volume \"%s\".\n"), dcr->VolumeName);
@@ -323,7 +323,7 @@ static void do_blocks(char *infname)
         block->BlockNumber, block->block_len, block->BlockVer,
         block->VolSessionId, block->VolSessionTime);
       if (verbose == 1) {
-         read_record_from_block(dcr, block, rec);
+         read_record_from_block(dcr, rec);
          Pmsg9(-1, _("File:blk=%u:%u blk_num=%u blen=%u First rec FI=%s SessId=%u SessTim=%u Strm=%s rlen=%d\n"),
               dev->file, dev->block_num,
               block->BlockNumber, block->block_len,
index 703f412227791583288a4ce754b1ee7cc22d3c50..967887290d4de97d85527c210001ec3654b60246 100644 (file)
@@ -863,7 +863,7 @@ static bool re_read_block_test()
       goto bail_out;
    }
    memset(rec->data, 0, rec->data_len);
-   if (!read_record_from_block(dcr, block, rec)) {
+   if (!read_record_from_block(dcr, rec)) {
       berrno be;
       Pmsg1(0, _("Read block failed! ERR=%s\n"), be.bstrerror(dev->dev_errno));
       goto bail_out;
@@ -1234,7 +1234,7 @@ read_again:
          goto bail_out;
       }
       memset(rec->data, 0, rec->data_len);
-      if (!read_record_from_block(dcr, block, rec)) {
+      if (!read_record_from_block(dcr, rec)) {
          berrno be;
          Pmsg2(0, _("Read record failed. Block %d! ERR=%s\n"), i, be.bstrerror(dev->dev_errno));
          goto bail_out;
@@ -1366,7 +1366,7 @@ read_again:
          goto bail_out;
       }
       memset(rec->data, 0, rec->data_len);
-      if (!read_record_from_block(dcr, block, rec)) {
+      if (!read_record_from_block(dcr, rec)) {
          berrno be;
          Pmsg1(0, _("Read record failed! ERR=%s\n"), be.bstrerror(dev->dev_errno));
          goto bail_out;
@@ -2115,7 +2115,7 @@ static void scan_blocks()
          block->VolSessionId, block->VolSessionTime);
       if (verbose == 1) {
          DEV_RECORD *rec = new_record();
-         read_record_from_block(dcr, block, rec);
+         read_record_from_block(dcr, rec);
          Pmsg9(-1, _("Block=%u file,blk=%u,%u blen=%u First rec FI=%s SessId=%u SessTim=%u Strm=%s rlen=%d\n"),
               block->BlockNumber, dev->file, dev->block_num, block->block_len,
               FI_to_ascii(buf1, rec->FileIndex), rec->VolSessionId, rec->VolSessionTime,
index ee8b91bc2f4f8f7fce43cfd0a609362d5db8efc5..7c6d57bcf84ae6e930c1db6e0166ff18d3f4d565 100644 (file)
@@ -1756,7 +1756,8 @@ void DEVICE::close()
    case B_VTL_DEV:
    case B_VTAPE_DEV:
    case B_TAPE_DEV:
-      unlock_door(); 
+      unlock_door();
+      /* Fall through wanted */
    default:
       d_close(m_fd);
       break;
index d5f0043e0bfa41c5eb7f02ad8398f37f5c0ecb4a..c7ce4d1a00f4f392bdc76cb1e90b4aba299d07f2 100644 (file)
@@ -131,7 +131,7 @@ int read_dev_volume_label(DCR *dcr)
            "labeled Volume, because: ERR=%s"), NPRT(VolName), 
            dev->print_name(), dev->print_errmsg());
       Dmsg1(130, "%s", jcr->errmsg);
-   } else if (!read_record_from_block(dcr, block, record)) {
+   } else if (!read_record_from_block(dcr, record)) {
       Mmsg(jcr->errmsg, _("Could not read Volume label from block.\n"));
       Dmsg1(130, "%s", jcr->errmsg);
    } else if (!unser_volume_label(dev, record)) {
index 7958564043cb61f9e1c8f1e9fb5eb45cf9316ae8..ed9badf6ed052eada7b47b05d5787109c083475e 100644 (file)
@@ -193,7 +193,7 @@ const char *FI_to_ascii(char *buf, int fi);
 const char *stream_to_ascii(char *buf, int stream, int fi);
 bool        write_record_to_block(DCR *dcr, DEV_RECORD *rec);
 bool        can_write_record_to_block(DEV_BLOCK *block, DEV_RECORD *rec);
-bool        read_record_from_block(DCR *dcr, DEV_BLOCK *block, DEV_RECORD *rec);
+bool        read_record_from_block(DCR *dcr, DEV_RECORD *rec);
 DEV_RECORD *new_record();
 void        free_record(DEV_RECORD *rec);
 void        empty_record(DEV_RECORD *rec);
index ab77400e1afe16ffb05952cd94c753d5b29e4b1f..92383abc09808c4aa7def5995cadeb79a6753b26 100644 (file)
@@ -120,7 +120,7 @@ bool read_records(DCR *dcr,
              *  most likely reading the previous record.
              */
             dcr->read_block_from_device(NO_BLOCK_NUMBER_CHECK);
-            read_record_from_block(dcr, block, trec);
+            read_record_from_block(dcr, trec);
             handle_session_record(dev, trec, &sessrec);
             ok = record_cb(dcr, trec);
             free_record(trec);
@@ -199,7 +199,7 @@ bool read_records(DCR *dcr,
       lastFileIndex = no_FileIndex;
       Dmsg1(dbglvl, "Block %s empty\n", is_block_empty(rec)?"is":"NOT");
       for (rec->state_bits=0; ok && !is_block_empty(rec); ) {
-         if (!read_record_from_block(dcr, block, rec)) {
+         if (!read_record_from_block(dcr, rec)) {
             Dmsg3(400, "!read-break. state_bits=%s blk=%d rem=%d\n", rec_state_bits_to_str(rec),
                   block->BlockNumber, rec->remainder);
             break;
index d1e7cfa82b312255dfcd8060322b3291271efcda..73f0c9f713496a0e3e196c78404c0c3fc3f5219a 100644 (file)
@@ -546,7 +546,7 @@ uint64_t get_record_address(DEV_RECORD *rec)
  *                 routine may have to be called again with a new
  *                 block if the entire record was not read.
  */
-bool read_record_from_block(DCR *dcr, DEV_BLOCK *block, DEV_RECORD *rec)
+bool read_record_from_block(DCR *dcr, DEV_RECORD *rec)
 {
    ser_declare;
    uint32_t remlen;
@@ -558,45 +558,45 @@ bool read_record_from_block(DCR *dcr, DEV_BLOCK *block, DEV_RECORD *rec)
    uint32_t rhl;
    char buf1[100], buf2[100];
 
-   remlen = block->binbuf;
+   remlen = dcr->block->binbuf;
 
    /* Clear state flags */
    rec->state_bits = 0;
-   if (block->dev->is_tape()) {
+   if (dcr->block->dev->is_tape()) {
       rec->state_bits |= REC_ISTAPE;
    }
-   rec->Block = ((DEVICE *)block->dev)->EndBlock;
-   rec->File = ((DEVICE *)block->dev)->EndFile;
+   rec->Block = ((DEVICE *)(dcr->block->dev))->EndBlock;
+   rec->File = ((DEVICE *)(dcr->block->dev))->EndFile;
 
    /*
     * Get the header. There is always a full header,
     * otherwise we find it in the next block.
     */
-   Dmsg3(450, "Block=%d Ver=%d size=%u\n", block->BlockNumber, block->BlockVer,
-         block->block_len);
-   if (block->BlockVer == 1) {
+   Dmsg3(450, "Block=%d Ver=%d size=%u\n", dcr->block->BlockNumber, dcr->block->BlockVer,
+         dcr->block->block_len);
+   if (dcr->block->BlockVer == 1) {
       rhl = RECHDR1_LENGTH;
    } else {
       rhl = RECHDR2_LENGTH;
    }
    if (remlen >= rhl) {
       Dmsg4(450, "Enter read_record_block: remlen=%d data_len=%d rem=%d blkver=%d\n",
-            remlen, rec->data_len, rec->remainder, block->BlockVer);
+            remlen, rec->data_len, rec->remainder, dcr->block->BlockVer);
 
-      unser_begin(block->bufp, WRITE_RECHDR_LENGTH);
-      if (block->BlockVer == 1) {
+      unser_begin(dcr->block->bufp, WRITE_RECHDR_LENGTH);
+      if (dcr->block->BlockVer == 1) {
          unser_uint32(VolSessionId);
          unser_uint32(VolSessionTime);
       } else {
-         VolSessionId = block->VolSessionId;
-         VolSessionTime = block->VolSessionTime;
+         VolSessionId = dcr->block->VolSessionId;
+         VolSessionTime = dcr->block->VolSessionTime;
       }
       unser_int32(FileIndex);
       unser_int32(Stream);
       unser_uint32(data_bytes);
 
-      block->bufp += rhl;
-      block->binbuf -= rhl;
+      dcr->block->bufp += rhl;
+      dcr->block->binbuf -= rhl;
       remlen -= rhl;
 
       /* If we are looking for more (remainder!=0), we reject anything
@@ -633,10 +633,10 @@ bool read_record_from_block(DCR *dcr, DEV_BLOCK *block, DEV_RECORD *rec)
       rec->VolSessionTime = VolSessionTime;
       rec->FileIndex = FileIndex;
       if (FileIndex > 0) {
-         if (block->FirstIndex == 0) {
-            block->FirstIndex = FileIndex;
+         if (dcr->block->FirstIndex == 0) {
+            dcr->block->FirstIndex = FileIndex;
          }
-         block->LastIndex = FileIndex;
+         dcr->block->LastIndex = FileIndex;
       }
 
       Dmsg6(450, "rd_rec_blk() got FI=%s SessId=%d Strm=%s len=%u\n"
@@ -655,7 +655,7 @@ bool read_record_from_block(DCR *dcr, DEV_BLOCK *block, DEV_RECORD *rec)
        */
       Dmsg0(450, "read_record_block: nothing\n");
       rec->state_bits |= (REC_NO_HEADER | REC_BLOCK_EMPTY);
-      empty_block(block);                      /* mark block empty */
+      empty_block(dcr->block);                 /* mark block empty */
       return false;
    }
 
@@ -666,7 +666,7 @@ bool read_record_from_block(DCR *dcr, DEV_BLOCK *block, DEV_RECORD *rec)
        *   continuing with this block.
        */
       rec->state_bits |= (REC_NO_HEADER | REC_BLOCK_EMPTY);
-      empty_block(block);
+      empty_block(dcr->block);
       Jmsg2(dcr->jcr, M_WARNING, 0, _("Sanity check failed. maxlen=%d datalen=%d. Block discarded.\n"),
          MAX_BLOCK_LENGTH, data_bytes);
       return false;
@@ -684,15 +684,15 @@ bool read_record_from_block(DCR *dcr, DEV_BLOCK *block, DEV_RECORD *rec)
     */
    if (remlen >= data_bytes) {
       /* Got whole record */
-      memcpy(rec->data+rec->data_len, block->bufp, data_bytes);
-      block->bufp += data_bytes;
-      block->binbuf -= data_bytes;
+      memcpy(rec->data+rec->data_len, dcr->block->bufp, data_bytes);
+      dcr->block->bufp += data_bytes;
+      dcr->block->binbuf -= data_bytes;
       rec->data_len += data_bytes;
    } else {
       /* Partial record */
-      memcpy(rec->data+rec->data_len, block->bufp, remlen);
-      block->bufp += remlen;
-      block->binbuf -= remlen;
+      memcpy(rec->data+rec->data_len, dcr->block->bufp, remlen);
+      dcr->block->bufp += remlen;
+      dcr->block->binbuf -= remlen;
       rec->data_len += remlen;
       rec->remainder = 1;             /* partial record transferred */
       Dmsg1(450, "read_record_block: partial xfered=%d\n", rec->data_len);