]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/block.c
Fix for reused thread ids by FreeBSD + qfill command
[bacula/bacula] / bacula / src / stored / block.c
index a7ca9e0980c6256df06846d64325f2b521d71749..a9dac5700909041bcf5b3bbaaf4c638f2a0fc906 100644 (file)
@@ -144,7 +144,8 @@ void empty_block(DEV_BLOCK *block)
    block->binbuf = WRITE_BLKHDR_LENGTH;
    block->bufp = block->buf + block->binbuf;
    block->read_len = 0;
-   block->failed_write = FALSE;
+   block->write_failed = false;
+   block->block_read = false;
 }
 
 /*
@@ -355,7 +356,7 @@ int write_block_to_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
       }
       Jmsg(jcr, M_INFO, 0, _("User defined maximum volume capacity %s exceeded on device %s.\n"),
            edit_uint64(max_cap, ed1),  dev->dev_name);
-      block->failed_write = TRUE;
+      block->write_failed = true;
       dev->EndBlock = dev->block_num;
       dev->EndFile  = dev->file;
       weof_dev(dev, 1);              /* end the tape */
@@ -376,32 +377,32 @@ int write_block_to_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
    }
 
    dev->VolCatInfo.VolCatWrites++;
-   Dmsg1(500, "Write block of %u bytes\n", wlen);      
+   Dmsg1(300, "Write block of %u bytes\n", wlen);      
    if ((uint32_t)(stat=write(dev->fd, block->buf, (size_t)wlen)) != wlen) {
       /* We should check for errno == ENOSPC, BUT many 
-       * devices simply report EIO when it is full.
-       * with a little more thought we may be able to check
+       * 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.
        */
-      clrerror_dev(dev, -1);
-
-      if (dev->dev_errno == 0) {
-        dev->dev_errno = ENOSPC;        /* out of space */
-      }
-
-      Dmsg4(10, "=== Write error. size=%u rtn=%d  errno=%d: ERR=%s\n", 
-        wlen, stat, dev->dev_errno, strerror(dev->dev_errno));
-
       if (stat == -1) {
+        clrerror_dev(dev, -1);
+        if (dev->dev_errno == 0) {
+           dev->dev_errno = ENOSPC;        /* out of space */
+        }
          Jmsg(jcr, M_ERROR, 0, _("Write error on device %s. ERR=%s.\n"), 
            dev->dev_name, strerror(dev->dev_errno));
       } else {
+       dev->dev_errno = ENOSPC;            /* out of space */
          Jmsg3(jcr, M_INFO, 0, _("End of medium on device %s. Write of %u bytes got %d.\n"), 
            dev->dev_name, wlen, stat);
       }  
-      block->failed_write = TRUE;
+
+      Dmsg4(10, "=== Write error. size=%u rtn=%d  errno=%d: ERR=%s\n", 
+        wlen, stat, dev->dev_errno, strerror(dev->dev_errno));
+
+      block->write_failed = true;
       dev->EndBlock = dev->block_num;
       dev->EndFile  = dev->file;
       weof_dev(dev, 1);              /* end the tape */
@@ -466,7 +467,6 @@ int write_block_to_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
    dev->block_num++;
    block->BlockNumber++;
 
-
    Dmsg2(190, "write_block: wrote block %d bytes=%d\n", dev->block_num,
       wlen);
    empty_block(block);
@@ -513,7 +513,10 @@ reread:
    }
    do {
       stat = read(dev->fd, block->buf, (size_t)block->buf_len);
-   } while (stat == -1 && (errno == EINTR || errno == EIO) && retry++ < 6);
+      if (retry == 1) {
+        dev->VolCatInfo.VolCatErrors++;   
+      }
+   } while (stat == -1 && (errno == EINTR || errno == EIO) && retry++ < 11);
    if (stat < 0) {
       Dmsg1(90, "Read device got: ERR=%s\n", strerror(errno));
       clrerror_dev(dev, -1);
@@ -521,13 +524,16 @@ reread:
       Mmsg2(&dev->errmsg, _("Read error on device %s. ERR=%s.\n"), 
         dev->dev_name, strerror(dev->dev_errno));
       Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
+      if (dev->state & ST_EOF) {  /* EOF just seen? */
+        dev->state |= ST_EOT;    /* yes, error => EOT */
+      }
       return 0;
    }
    Dmsg1(90, "Read device got %d bytes\n", stat);
    if (stat == 0) {            /* Got EOF ! */
       dev->block_num = block->read_len = 0;
       Mmsg1(&dev->errmsg, _("Read zero bytes on device %s.\n"), dev->dev_name);
-      if (dev->state & ST_EOF) { /* EOF alread read? */
+      if (dev->state & ST_EOF) { /* EOF already read? */
         dev->state |= ST_EOT;  /* yes, 2 EOFs => EOT */
         block->read_len = 0;
         return 0;
@@ -554,15 +560,6 @@ reread:
       return 0;
    }
 
-#ifdef somehow_working
-   if (check_block_numbers) {
-      if (BlockNumber != block->BlockNumber) {
-         Jmsg(jcr, M_ERROR, 0, _("Incorrect block sequence number. Expected %u, got %u\n"),
-           BlockNumber, block->BlockNumber);
-      }
-   }
-#endif
-
    /*
     * If the block is bigger than the buffer, we reposition for
     *  re-reading the block, allocate a buffer of the correct size,
@@ -637,5 +634,6 @@ reread:
    }
    Dmsg2(200, "Exit read_block read_len=%d block_len=%d\n",
       block->read_len, block->block_len);
+   block->block_read = true;
    return 1;
 }