]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/block_util.c
Ensure that zero JobMedias are written for labelling
[bacula/bacula] / bacula / src / stored / block_util.c
index 790dad89b7b6af1f7e19945fd3b6c32af5d4d2e4..3d67de92086f20bf44cebdb85c22701dcb2c32ff 100644 (file)
@@ -1,17 +1,20 @@
 /*
-   Bacula® - The Network Backup Solution
+   Bacula(R) - The Network Backup Solution
 
-   Copyright (C) 2001-2014 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2016 Kern Sibbald
 
-   The main author of Bacula is Kern Sibbald, with contributions from many
-   others, a complete list can be found in the file AUTHORS.
+   The original author of Bacula is Kern Sibbald, with contributions
+   from many others, a complete list can be found in the file AUTHORS.
 
    You may use this file and others of this release according to the
    license defined in the LICENSE file, which includes the Affero General
    Public License, v3.0 ("AGPLv3") and some additional permissions and
    terms pursuant to its AGPLv3 Section 7.
 
-   Bacula® is a registered trademark of Kern Sibbald.
+   This notice must be preserved when any source code is 
+   conveyed and/or propagated.
+
+   Bacula(R) is a registered trademark of Kern Sibbald.
 */
 /*
  *
@@ -78,8 +81,11 @@ void dump_block(DEV_BLOCK *b, const char *msg)
       rhl = RECHDR1_LENGTH;
    }
 
-   if (block_len > 4000000) {
-      Dmsg3(20, "!!!Dump block %s 0x%x blocksize too big %u\n", msg, b, block_len);
+   if (block_len > 4000000 || block_len < BLKHDR_CS_LENGTH) {
+      Dmsg4(20, "!!!Dump block %s %p blocksize too %s %lu\n",
+            msg, b,
+            (block_len < BLKHDR_CS_LENGTH)?"small":"big",
+            block_len);
       return;
    }
 
@@ -131,7 +137,6 @@ DEV_BLOCK *new_block(DEVICE *dev)
     */
    block->buf_len = len;
    block->buf = get_memory(block->buf_len);
-   block->rechdr_queue = get_memory(block->buf_len);
    block->rechdr_items = 0;
    empty_block(block);
    block->BlockVer = BLOCK_VER;       /* default write version */
@@ -180,10 +185,9 @@ void DCR::free_blocks()
  */
 void free_block(DEV_BLOCK *block)
 {
-   if (block) {
+   if (block && block->buf) {
       Dmsg1(999, "free_block buffer %x\n", block->buf);
       free_memory(block->buf);
-      free_memory(block->rechdr_queue);
       Dmsg1(999, "free_block block %x\n", block);
       free_memory((POOLMEM *)block);
    }
@@ -269,8 +273,8 @@ bool unser_block_header(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
    unser_uint32(BlockNumber);
    unser_bytes(Id, BLKHDR_ID_LENGTH);
    ASSERT(unser_length(block->buf) == BLKHDR1_LENGTH);
-
    Id[BLKHDR_ID_LENGTH] = 0;
+
    if (Id[3] == '1') {
       bhl = BLKHDR1_LENGTH;
       block->BlockVer = 1;
@@ -554,6 +558,7 @@ bool terminate_writing_volume(DCR *dcr)
        Jmsg(dcr->jcr, M_FATAL, 0, "%s", dev->errmsg);
        ok = false;
    }
+   flush_jobmedia_queue(dcr->jcr);
    dcr->block->write_failed = true;
    if (dev->can_append() && !dev->weof(1)) {     /* end the tape */
       dev->VolCatInfo.VolCatErrors++;
@@ -616,8 +621,8 @@ bool check_for_newvol_or_newfile(DCR *dcr)
          Dmsg0(100, "Canceled\n");
          return false;
       }
-      /* Create a jobmedia record for this job */
-      if (!dir_create_jobmedia_record(dcr)) {
+      /* If we wrote on Volume create a last jobmedia record for this job */
+      if (dcr->VolFirstIndex && !dir_create_jobmedia_record(dcr)) {
          dcr->dev->dev_errno = EIO;
          Jmsg2(jcr, M_FATAL, 0, _("Could not create JobMedia record for Volume=\"%s\" Job=%s\n"),
             dcr->getVolCatName(), jcr->Job);
@@ -626,6 +631,7 @@ bool check_for_newvol_or_newfile(DCR *dcr)
          return false;
       }
       if (dcr->NewVol) {
+         flush_jobmedia_queue(jcr);
          /* Note, setting a new volume also handles any pending new file */
          set_new_volume_parameters(dcr);
       } else {