]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/block.c
- Add VolumePurged method to Python JobEvents class. Fixes
[bacula/bacula] / bacula / src / stored / block.c
index f69dc097e62b936aae153d29156e2bb2b05f5441..1461f777144db3c830f4af549635e10b4b4cff23 100644 (file)
@@ -13,7 +13,7 @@
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
-   version 2 as ammended with additional clauses defined in the
+   version 2 as amended with additional clauses defined in the
    file LICENSE in the main source directory.
 
    This program is distributed in the hope that it will be useful,
@@ -75,8 +75,8 @@ void dump_block(DEV_BLOCK *b, const char *msg)
 
    BlockCheckSum = bcrc32((uint8_t *)b->buf+BLKHDR_CS_LENGTH,
                          block_len-BLKHDR_CS_LENGTH);
-   Pmsg6(000, "Dump block %s %x: size=%d BlkNum=%d\n"
-"               Hdrcksum=%x cksum=%x\n",
+   Pmsg6(000, _("Dump block %s %x: size=%d BlkNum=%d\n"
+"               Hdrcksum=%x cksum=%x\n"),
       msg, b, block_len, BlockNumber, CheckSum, BlockCheckSum);
    p = b->buf + bhl;
    while (p < (b->buf + block_len+WRITE_RECHDR_LENGTH)) {
@@ -88,7 +88,7 @@ void dump_block(DEV_BLOCK *b, const char *msg)
       unser_int32(FileIndex);
       unser_int32(Stream);
       unser_uint32(data_len);
-      Pmsg6(000, "   Rec: VId=%u VT=%u FI=%s Strm=%s len=%d p=%x\n",
+      Pmsg6(000, _("   Rec: VId=%u VT=%u FI=%s Strm=%s len=%d p=%x\n"),
            VolSessionId, VolSessionTime, FI_to_ascii(FileIndex),
            stream_to_ascii(Stream, FileIndex), data_len, p);
       p += data_len + rhl;
@@ -117,7 +117,7 @@ DEV_BLOCK *new_block(DEVICE *dev)
    block->buf = get_memory(block->buf_len);
    empty_block(block);
    block->BlockVer = BLOCK_VER;       /* default write version */
-   Dmsg1(350, "Returning new block=%x\n", block);
+   Dmsg1(650, "Returning new block=%x\n", block);
    return block;
 }
 
@@ -154,9 +154,9 @@ void print_block_read_errors(JCR *jcr, DEV_BLOCK *block)
  */
 void free_block(DEV_BLOCK *block)
 {
-   Dmsg1(199, "free_block buffer %x\n", block->buf);
+   Dmsg1(999, "free_block buffer %x\n", block->buf);
    free_memory(block->buf);
-   Dmsg1(199, "free_block block %x\n", block);
+   Dmsg1(999, "free_block block %x\n", block);
    free_memory((POOLMEM *)block);
 }
 
@@ -182,7 +182,7 @@ void ser_block_header(DEV_BLOCK *block)
    uint32_t CheckSum = 0;
    uint32_t block_len = block->binbuf;
 
-   Dmsg1(390, "ser_block_header: block_len=%d\n", block_len);
+   Dmsg1(1390, "ser_block_header: block_len=%d\n", block_len);
    ser_begin(block->buf, BLKHDR2_LENGTH);
    ser_uint32(CheckSum);
    ser_uint32(block_len);
@@ -196,7 +196,7 @@ void ser_block_header(DEV_BLOCK *block)
    /* Checksum whole block except for the checksum */
    CheckSum = bcrc32((uint8_t *)block->buf+BLKHDR_CS_LENGTH,
                  block_len-BLKHDR_CS_LENGTH);
-   Dmsg1(390, "ser_bloc_header: checksum=%x\n", CheckSum);
+   Dmsg1(1390, "ser_bloc_header: checksum=%x\n", CheckSum);
    ser_begin(block->buf, BLKHDR2_LENGTH);
    ser_uint32(CheckSum);              /* now add checksum to block header */
 }
@@ -464,7 +464,7 @@ bool write_block_to_dev(DCR *dcr)
          max_cap = dev->VolCatInfo.VolCatMaxBytes;
       }
       Jmsg(jcr, M_INFO, 0, _("User defined maximum volume capacity %s exceeded on device %s.\n"),
-            edit_uint64_with_commas(max_cap, ed1),  dev->dev_name);
+            edit_uint64_with_commas(max_cap, ed1),  dev->print_name());
       terminate_writing_volume(dcr);
       reread_last_block(dcr);   /* DEBUG */
       dev->dev_errno = ENOSPC;
@@ -484,7 +484,7 @@ bool write_block_to_dev(DCR *dcr)
          dev->dev_errno = ENOSPC;
          return false;
       }
-      if (!write_ansi_ibm_labels(dcr, ANSI_EOF_LABEL, dev->VolHdr.VolName)) {
+      if (!write_ansi_ibm_labels(dcr, ANSI_EOF_LABEL, dev->VolHdr.VolumeName)) {
          return false;
       }
 
@@ -500,11 +500,11 @@ bool write_block_to_dev(DCR *dcr)
    }
 
    dev->VolCatInfo.VolCatWrites++;
-   Dmsg1(300, "Write block of %u bytes\n", wlen);
+   Dmsg1(1300, "Write block of %u bytes\n", wlen);
 #ifdef DEBUG_BLOCK_ZEROING
    uint32_t *bp = (uint32_t *)block->buf;
    if (bp[0] == 0 && bp[1] == 0 && bp[2] == 0 && block->buf[12] == 0) {
-      Jmsg0(jcr, M_ABORT, 0, "Write block header zeroed.\n");
+      Jmsg0(jcr, M_ABORT, 0, _("Write block header zeroed.\n"));
    }
 #endif
 
@@ -515,7 +515,7 @@ bool write_block_to_dev(DCR *dcr)
 
 #ifdef DEBUG_BLOCK_ZEROING
    if (bp[0] == 0 && bp[1] == 0 && bp[2] == 0 && block->buf[12] == 0) {
-      Jmsg0(jcr, M_ABORT, 0, "Write block header zeroed.\n");
+      Jmsg0(jcr, M_ABORT, 0, _("Write block header zeroed.\n"));
    }
 #endif
 
@@ -534,7 +534,7 @@ bool write_block_to_dev(DCR *dcr)
          }
          if (dev->dev_errno != ENOSPC) {
             Jmsg4(jcr, M_ERROR, 0, _("Write error at %u:%u on device %s. ERR=%s.\n"),
-               dev->file, dev->block_num, dev->dev_name, be.strerror());
+               dev->file, dev->block_num, dev->print_name(), be.strerror());
          }
       } else {
         dev->dev_errno = ENOSPC;            /* out of space */
@@ -544,8 +544,9 @@ bool write_block_to_dev(DCR *dcr)
             dev->VolCatInfo.VolCatName,
             dev->file, dev->block_num, dev->print_name(), wlen, stat);
       }
-      Dmsg6(100, "=== Write error. size=%u rtn=%d dev_blk=%d blk_blk=%d errno=%d: ERR=%s\n",
-         wlen, stat, dev->block_num, block->BlockNumber, dev->dev_errno, strerror(dev->dev_errno));
+      Dmsg7(100, "=== Write error. fd=%d size=%u rtn=%d dev_blk=%d blk_blk=%d errno=%d: ERR=%s\n",
+         dev->fd, wlen, stat, dev->block_num, block->BlockNumber, 
+         dev->dev_errno, strerror(dev->dev_errno));
 
       ok = terminate_writing_volume(dcr);
       if (!ok && !forge_on) {
@@ -571,9 +572,12 @@ bool write_block_to_dev(DCR *dcr)
       dcr->EndBlock = dev->EndBlock;
       dcr->EndFile  = dev->EndFile;
    } else {
-      /* Save address of start of block just written */
-      dcr->EndBlock = (uint32_t)dev->file_addr;
-      dcr->EndFile = (uint32_t)(dev->file_addr >> 32);
+      /* Save address of block just written */
+      uint64_t addr = dev->file_addr + wlen - 1;
+      dcr->EndBlock = (uint32_t)addr;
+      dcr->EndFile = (uint32_t)(addr >> 32);
+      dev->block_num = dcr->EndBlock;
+      dev->file = dcr->EndFile;
    }
    if (dcr->VolFirstIndex == 0 && block->FirstIndex > 0) {
       dcr->VolFirstIndex = block->FirstIndex;
@@ -586,7 +590,7 @@ bool write_block_to_dev(DCR *dcr)
    dev->file_size += wlen;
    dev->part_size += wlen;
 
-   Dmsg2(300, "write_block: wrote block %d bytes=%d\n", dev->block_num, wlen);
+   Dmsg2(1300, "write_block: wrote block %d bytes=%d\n", dev->block_num, wlen);
    empty_block(block);
    return true;
 }
@@ -677,20 +681,20 @@ static bool terminate_writing_volume(DCR *dcr)
    dcr->block->write_failed = true;
    if (weof_dev(dev, 1) != 0) {         /* end the tape */
       dev->VolCatInfo.VolCatErrors++;
-      Jmsg(dcr->jcr, M_ERROR, 0, "Error writing final EOF to tape. This tape may not be readable.\n"
-           "%s", dev->errmsg);
+      Jmsg(dcr->jcr, M_ERROR, 0, _("Error writing final EOF to tape. This tape may not be readable.\n"
+           "%s"), dev->errmsg);
       ok = false;
       Dmsg0(100, "WEOF error.\n");
    }
    if (ok) {
-      ok = write_ansi_ibm_labels(dcr, ANSI_EOV_LABEL, dev->VolHdr.VolName);
+      ok = write_ansi_ibm_labels(dcr, ANSI_EOV_LABEL, dev->VolHdr.VolumeName);
    }
    bstrncpy(dev->VolCatInfo.VolCatStatus, "Full", sizeof(dev->VolCatInfo.VolCatStatus));
    dev->VolCatInfo.VolCatFiles = dev->file;   /* set number of files */
    dev->VolCatInfo.VolCatJobs++;              /* increment number of jobs */
    
    if (dev->is_dvd()) { /* Write the current (and last) part. */
-      open_next_part(dev);
+      open_next_part(dcr);
    }
    
    if (!dir_update_volume_info(dcr, false)) {
@@ -783,13 +787,14 @@ static bool do_dvd_size_checks(DCR *dcr)
    if (!(dev->is_tape() || dev->is_fifo()) && dev->max_part_size > 0 &&
         (dev->part_size + block->binbuf) >= dev->max_part_size) {
       if (dev->part < dev->num_parts) {
-         Jmsg3(dcr->jcr, M_FATAL, 0, _("Error while writing, current part number is less than the total number of parts (%d/%d, device=%s)\n"),
+         Jmsg3(dcr->jcr, M_FATAL, 0, _("Error while writing, current part number"
+               " is less than the total number of parts (%d/%d, device=%s)\n"),
                dev->part, dev->num_parts, dev->print_name());
          dev->dev_errno = EIO;
          return false;
       }
       
-      if (open_next_part(dev) < 0) {
+      if (open_next_part(dcr) < 0) {
          Jmsg2(dcr->jcr, M_FATAL, 0, _("Unable to open device next part %s: ERR=%s\n"),
                 dev->print_name(), strerror_dev(dev));
          dev->dev_errno = EIO;
@@ -808,7 +813,8 @@ static bool do_dvd_size_checks(DCR *dcr)
    if (dev->free_space_errno < 0) { /* Error while getting free space */
       char ed1[50], ed2[50];
       Dmsg1(10, "Cannot get free space on the device ERR=%s.\n", dev->errmsg);
-      Jmsg(jcr, M_FATAL, 0, _("End of Volume \"%s\" at %u:%u on device %s (part_size=%s, free_space=%s, free_space_errno=%d, errmsg=%s).\n"),
+      Jmsg(jcr, M_FATAL, 0, _("End of Volume \"%s\" at %u:%u on device %s "
+         "(part_size=%s, free_space=%s, free_space_errno=%d, errmsg=%s).\n"),
            dev->VolCatInfo.VolCatName,
            dev->file, dev->block_num, dev->print_name(),
            edit_uint64_with_commas(dev->part_size, ed1), edit_uint64_with_commas(dev->free_space, ed2),
@@ -820,7 +826,8 @@ static bool do_dvd_size_checks(DCR *dcr)
    if ((dev->free_space_errno > 0 && (dev->part_size + block->binbuf) >= dev->free_space)) {
       char ed1[50], ed2[50];
       Dmsg0(10, "==== Just enough free space on the device to write the current part...\n");
-      Jmsg(jcr, M_INFO, 0, _("End of Volume \"%s\" at %u:%u on device %s (part_size=%s, free_space=%s, free_space_errno=%d).\n"),
+      Jmsg(jcr, M_INFO, 0, _("End of Volume \"%s\" at %u:%u on device %s "
+         "(part_size=%s, free_space=%s, free_space_errno=%d).\n"),
             dev->VolCatInfo.VolCatName,
             dev->file, dev->block_num, dev->print_name(),
             edit_uint64_with_commas(dev->part_size, ed1), edit_uint64_with_commas(dev->free_space, ed2),
@@ -874,25 +881,30 @@ reread:
    if (looping > 1) {
       dev->dev_errno = EIO;
       Mmsg1(dev->errmsg, _("Block buffer size looping problem on device %s\n"),
-         dev->dev_name);
+         dev->print_name());
       Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
       block->read_len = 0;
       return false;
    }
    
-   /*Dmsg1(200, "dev->file_size=%u\n",(unsigned int)dev->file_size);
-   Dmsg1(200, "lseek=%u\n",(unsigned int)lseek(dev->fd, 0, SEEK_CUR));
-   Dmsg1(200, "dev->part_start=%u\n",(unsigned int)dev->part_start);
-   Dmsg1(200, "dev->file_size-dev->part_start=%u\n",(unsigned int)dev->file_size-dev->part_start);
-   Dmsg1(200, "dev->part_size=%u\n", (unsigned int)dev->part_size);
-   Dmsg1(200, "dev->part=%u\n", (unsigned int)dev->part);
-   Dmsg1(200, "dev->VolCatInfo.VolCatParts=%u\n", (unsigned int)dev->VolCatInfo.VolCatParts);
-   Dmsg3(200, "Tests : %d %d %d\n", (dev->VolCatInfo.VolCatParts > 0), ((dev->file_size-dev->part_start) == dev->part_size), (dev->part <= dev->VolCatInfo.VolCatParts));*/
+   /*Dmsg1(100, "dev->file_size=%u\n",(unsigned int)dev->file_size);
+   Dmsg1(100, "dev->file_addr=%u\n",(unsigned int)dev->file_addr);
+   Dmsg1(100, "lseek=%u\n",(unsigned int)lseek(dev->fd, 0, SEEK_CUR));
+   Dmsg1(100, "dev->part_start=%u\n",(unsigned int)dev->part_start);
+   Dmsg1(100, "dev->file_addr-dev->part_start=%u\n",(unsigned int)dev->file_addr-dev->part_start);
+   Dmsg1(100, "dev->file_size-dev->part_start=%u\n",(unsigned int)dev->file_size-dev->part_start);
+   Dmsg1(100, "dev->part_size=%u\n", (unsigned int)dev->part_size);
+   Dmsg1(100, "dev->part=%u\n", (unsigned int)dev->part);
+   Dmsg1(100, "dev->num_parts=%u\n", (unsigned int)dev->num_parts);
+   Dmsg1(100, "dev->VolCatInfo.VolCatParts=%u\n", (unsigned int)dev->VolCatInfo.VolCatParts);
+   Dmsg3(100, "Tests : %d %d %d\n", (dev->VolCatInfo.VolCatParts > 0), 
+         ((dev->file_addr-dev->part_start) == dev->part_size), 
+         (dev->part <= dev->VolCatInfo.VolCatParts));*/
    /* Check for part file end */
    if ((dev->num_parts > 0) &&
-        ((dev->file_size-dev->part_start) == dev->part_size) && 
+        ((dev->file_addr-dev->part_start) == dev->part_size) && 
         (dev->part < dev->num_parts)) {
-      if (open_next_part(dev) < 0) {
+      if (open_next_part(dcr) < 0) {
          Jmsg2(dcr->jcr, M_FATAL, 0, _("Unable to open device next part %s: ERR=%s\n"),
                dev->print_name(), strerror_dev(dev));
          dev->dev_errno = EIO;
@@ -920,7 +932,7 @@ reread:
       Dmsg1(200, "Read device got: ERR=%s\n", be.strerror());
       block->read_len = 0;
       Mmsg4(dev->errmsg, _("Read error at file:blk %u:%u on device %s. ERR=%s.\n"),
-         dev->file, dev->block_num, dev->dev_name, be.strerror());
+         dev->file, dev->block_num, dev->print_name(), be.strerror());
       Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
       if (dev->at_eof()) {        /* EOF just seen? */
          dev->set_eot();          /* yes, error => EOT */
@@ -933,7 +945,7 @@ reread:
       dev->block_num = 0;
       block->read_len = 0;
       Mmsg3(dev->errmsg, _("Read zero bytes at %u:%u on device %s.\n"),
-         dev->file, dev->block_num, dev->dev_name);
+         dev->file, dev->block_num, dev->print_name());
       if (dev->at_eof()) {       /* EOF already read? */
          dev->set_eot();         /* yes, 2 EOFs => EOT */
          return 0;
@@ -946,7 +958,7 @@ reread:
    if (block->read_len < BLKHDR2_LENGTH) {
       dev->dev_errno = EIO;
       Mmsg4(dev->errmsg, _("Volume data error at %u:%u! Very short block of %d bytes on device %s discarded.\n"),
-         dev->file, dev->block_num, block->read_len, dev->dev_name);
+         dev->file, dev->block_num, block->read_len, dev->print_name());
       Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
       dev->set_short_block();   
       block->read_len = block->binbuf = 0;
@@ -1005,7 +1017,7 @@ reread:
    if (block->block_len > block->read_len) {
       dev->dev_errno = EIO;
       Mmsg4(dev->errmsg, _("Volume data error at %u:%u! Short block of %d bytes on device %s discarded.\n"),
-         dev->file, dev->block_num, block->read_len, dev->dev_name);
+         dev->file, dev->block_num, block->read_len, dev->print_name());
       Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
       dev->set_short_block();
       block->read_len = block->binbuf = 0;
@@ -1028,13 +1040,14 @@ reread:
       dcr->EndBlock = dev->EndBlock;
       dcr->EndFile  = dev->EndFile;
    } else {
-      dcr->EndBlock = (uint32_t)dev->file_addr;
-      dcr->EndFile = (uint32_t)(dev->file_addr >> 32);
+      uint64_t addr = dev->file_addr + block->read_len - 1;
+      dcr->EndBlock = (uint32_t)addr;
+      dcr->EndFile = (uint32_t)(addr >> 32);
       dev->block_num = dcr->EndBlock;
       dev->file = dcr->EndFile;
    }
-   dev->file_addr += block->block_len;
-   dev->file_size += block->block_len;
+   dev->file_addr += block->read_len;
+   dev->file_size += block->read_len;
 
    /*
     * If we read a short block on disk,