]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/block.c
Massive SD calling sequence reorganization
[bacula/bacula] / bacula / src / stored / block.c
index a06460d16100c70fee0e9edaebc7678c6c970cde..915cf6ee65b649a1da733e7f6fa849918e02b883 100644 (file)
@@ -320,14 +320,14 @@ static bool unser_block_header(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
  *       : false on failure
  *
  */
-bool write_block_to_device(DCR *dcr, DEV_BLOCK *block)
+bool write_block_to_device(DCR *dcr)
 {
    bool stat = true;
    DEVICE *dev = dcr->dev;
    JCR *jcr = dcr->jcr;
 
    if (dcr->spooling) {
-      stat = write_block_to_spool_file(dcr, block);
+      stat = write_block_to_spool_file(dcr);
       return stat;
    }
 
@@ -345,8 +345,8 @@ bool write_block_to_device(DCR *dcr, DEV_BLOCK *block)
       /* Create a jobmedia record for this job */
       if (!dir_create_jobmedia_record(dcr)) {
         dev->dev_errno = EIO;
-         Jmsg(jcr, M_ERROR, 0, _("Could not create JobMedia record for Volume=\"%s\" Job=%s\n"),
-           jcr->VolCatInfo.VolCatName, jcr->Job);
+         Jmsg(jcr, M_FATAL, 0, _("Could not create JobMedia record for Volume=\"%s\" Job=%s\n"),
+           dcr->VolCatInfo.VolCatName, jcr->Job);
         set_new_volume_parameters(dcr);
         stat = false;
         goto bail_out;
@@ -360,8 +360,12 @@ bool write_block_to_device(DCR *dcr, DEV_BLOCK *block)
       }
    }
 
-   if (!write_block_to_dev(dcr, block)) {
-       stat = fixup_device_block_write_error(dcr, block);
+   if (!write_block_to_dev(dcr)) {
+       if (job_canceled(jcr)) {
+         stat = 0;
+       } else {
+         stat = fixup_device_block_write_error(dcr);
+       }
    }
 
 bail_out:
@@ -377,14 +381,15 @@ bail_out:
  *  Returns: true  on success or EOT
  *          false on hard error
  */
-bool write_block_to_dev(DCR *dcr, DEV_BLOCK *block)
+bool write_block_to_dev(DCR *dcr)
 {
    ssize_t stat = 0;
    uint32_t wlen;                    /* length to write */
    int hit_max1, hit_max2;
-   bool ok;
+   bool ok = true;
    DEVICE *dev = dcr->dev;
    JCR *jcr = dcr->jcr;
+   DEV_BLOCK *block = dcr->block;
 
 #ifdef NO_TAPE_WRITE_TEST
    empty_block(block);
@@ -452,7 +457,7 @@ bool write_block_to_dev(DCR *dcr, DEV_BLOCK *block)
            edit_uint64_with_commas(max_cap, ed1),  dev->dev_name);
       block->write_failed = true;
       if (weof_dev(dev, 1) != 0) {           /* end tape */
-         Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
+         Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg);
         dev->VolCatInfo.VolCatErrors++;
       }
       /* Don't do update after second EOF or file count will be wrong */
@@ -460,6 +465,7 @@ bool write_block_to_dev(DCR *dcr, DEV_BLOCK *block)
       dev->VolCatInfo.VolCatFiles = dev->file;
       dir_update_volume_info(dcr, false);
       if (dev_cap(dev, CAP_TWOEOF) && weof_dev(dev, 1) != 0) { /* write eof */
+        /* This may not be fatal since we already wrote an EOF */
          Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
         dev->VolCatInfo.VolCatErrors++;
       }
@@ -474,7 +480,7 @@ bool write_block_to_dev(DCR *dcr, DEV_BLOCK *block)
 
       if (dev_state(dev, ST_TAPE) && weof_dev(dev, 1) != 0) {           /* write eof */
         /* Write EOF */
-         Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
+         Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg);
         block->write_failed = true;
         dev->VolCatInfo.VolCatErrors++;
         dev->state |= (ST_EOF | ST_EOT | ST_WEOT);
@@ -543,14 +549,14 @@ bool write_block_to_dev(DCR *dcr, DEV_BLOCK *block)
 #endif
 
    if (stat != (ssize_t)wlen) {
-      /* We should check for errno == ENOSPC, BUT many 
-       * devices simply report EIO when the volume is full.
+      /* Some devices simply report EIO when the volume is full.
        * With a little more thought we may be able to check
        * capacity and distinguish real errors and EOT
        * conditions.  In any case, we probably want to
        * simulate an End of Medium.
        */
       if (stat == -1) {
+        berrno be;
         /* I have added the ifdefing here because it appears on
          * FreeBSD where MTIOCERRSTAT is defined, this not only
          * clears the error but clears the residual unwritten
@@ -562,33 +568,37 @@ bool write_block_to_dev(DCR *dcr, DEV_BLOCK *block)
         if (dev->dev_errno == 0) {
            dev->dev_errno = ENOSPC;        /* out of space */
         }
-         Jmsg4(jcr, M_ERROR, 0, _("Write error at %u:%u on device %s. ERR=%s.\n"), 
-           dev->file, dev->block_num, dev->dev_name, strerror(dev->dev_errno));
+        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());
+        }
       } else {
        dev->dev_errno = ENOSPC;            /* out of space */
+      }  
+      if (dev->dev_errno == ENOSPC) {
          Jmsg(jcr, M_INFO, 0, _("End of Volume \"%s\" at %u:%u on device %s. Write of %u bytes got %d.\n"), 
            dev->VolCatInfo.VolCatName,
            dev->file, dev->block_num, dev->dev_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));
 
       block->write_failed = true;
       if (weof_dev(dev, 1) != 0) {        /* end the tape */
         dev->VolCatInfo.VolCatErrors++;
-         Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
+         Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg);
+        ok = false;
       }
       Dmsg0(100, "dir_update_volume_info\n");
       dev->VolCatInfo.VolCatFiles = dev->file;
       dir_update_volume_info(dcr, false);
-      if (dev_cap(dev, CAP_TWOEOF) && weof_dev(dev, 1) != 0) { /* end the tape */
+      if (ok && dev_cap(dev, CAP_TWOEOF) && weof_dev(dev, 1) != 0) {  /* end the tape */
         dev->VolCatInfo.VolCatErrors++;
+        /* This may not be fatal since we already wrote an EOF */
          Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
       }
       dev->state |= (ST_EOF | ST_EOT | ST_WEOT);
        
-      ok = true;
 #define CHECK_LAST_BLOCK
 #ifdef CHECK_LAST_BLOCK
       /* 
@@ -598,8 +608,7 @@ bool write_block_to_dev(DCR *dcr, DEV_BLOCK *block)
        *   then re-read it and verify that the block number is
        *   correct.
        */
-      if ((dev->state & ST_TAPE) && dev_cap(dev, CAP_BSR)) {
-
+      if (ok && (dev->state & ST_TAPE) && dev_cap(dev, CAP_BSR)) {
         /* Now back up over what we wrote and read the last block */
         if (!bsf_dev(dev, 1)) {
            ok = false;
@@ -626,7 +635,8 @@ bool write_block_to_dev(DCR *dcr, DEV_BLOCK *block)
         if (ok) {
            DEV_BLOCK *lblock = new_block(dev);
            /* Note, this can destroy dev->errmsg */
-           if (!read_block_from_dev(dcr, lblock, NO_BLOCK_NUMBER_CHECK)) {
+           dcr->block = lblock;
+           if (!read_block_from_dev(dcr, NO_BLOCK_NUMBER_CHECK)) {
                Jmsg(jcr, M_ERROR, 0, _("Re-read last block at EOT failed. ERR=%s"), dev->errmsg);
            } else {
               if (lblock->BlockNumber+1 == block->BlockNumber) {
@@ -638,6 +648,7 @@ bool write_block_to_dev(DCR *dcr, DEV_BLOCK *block)
               }
            }
            free_block(lblock);
+           dcr->block = block;
         }
       }
 #endif
@@ -653,7 +664,7 @@ bool write_block_to_dev(DCR *dcr, DEV_BLOCK *block)
    dev->block_num++;
    block->BlockNumber++;
 
-   /* Update jcr values */
+   /* Update dcr values */
    if (dev_state(dev, ST_TAPE)) {
       dcr->EndBlock = dev->EndBlock;
       dcr->EndFile  = dev->EndFile;
@@ -682,13 +693,13 @@ bool write_block_to_dev(DCR *dcr, DEV_BLOCK *block)
  * Read block with locking
  *
  */
-bool read_block_from_device(DCR *dcr, DEV_BLOCK *block, bool check_block_numbers)
+bool read_block_from_device(DCR *dcr, bool check_block_numbers)
 {
    bool stat;
    DEVICE *dev = dcr->dev;
    Dmsg0(90, "Enter read_block_from_device\n");
    lock_device(dev);
-   stat = read_block_from_dev(dcr, block, check_block_numbers);
+   stat = read_block_from_dev(dcr, check_block_numbers);
    unlock_device(dev);
    Dmsg0(90, "Leave read_block_from_device\n");
    return stat;
@@ -699,7 +710,7 @@ bool read_block_from_device(DCR *dcr, DEV_BLOCK *block, bool check_block_numbers
  *  the block header.  For a file, the block may be partially
  *  or completely in the current buffer.
  */
-bool read_block_from_dev(DCR *dcr, DEV_BLOCK *block, bool check_block_numbers)
+bool read_block_from_dev(DCR *dcr, bool check_block_numbers)
 {
    ssize_t stat;
    int looping;
@@ -707,6 +718,7 @@ bool read_block_from_dev(DCR *dcr, DEV_BLOCK *block, bool check_block_numbers)
    int retry;
    JCR *jcr = dcr->jcr;
    DEVICE *dev = dcr->dev;
+   DEV_BLOCK *block = dcr->block;
 
    if (dev_state(dev, ST_EOT)) {
       return false;
@@ -845,7 +857,7 @@ reread:
    dev->EndFile  = dev->file;
    dev->block_num++;
 
-   /* Update jcr values */
+   /* Update dcr values */
    if (dev->state & ST_TAPE) {
       dcr->EndBlock = dev->EndBlock;
       dcr->EndFile  = dev->EndFile;