block->bufp = block->buf + bhl;
if (strncmp(Id, BLKHDR1_ID, BLKHDR_ID_LENGTH) != 0) {
dev->dev_errno = EIO;
- Mmsg4(&dev->errmsg, _("Volume data error at %u:%u! Wanted ID: \"%s\", got \"%s\". Buffer discarded.\n"),
+ Mmsg4(dev->errmsg, _("Volume data error at %u:%u! Wanted ID: \"%s\", got \"%s\". Buffer discarded.\n"),
dev->file, dev->block_num, BLKHDR1_ID, Id);
if (block->read_errors == 0 || verbose >= 2) {
Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
block->bufp = block->buf + bhl;
if (strncmp(Id, BLKHDR2_ID, BLKHDR_ID_LENGTH) != 0) {
dev->dev_errno = EIO;
- Mmsg4(&dev->errmsg, _("Volume data error at %u:%u! Wanted ID: \"%s\", got \"%s\". Buffer discarded.\n"),
+ Mmsg4(dev->errmsg, _("Volume data error at %u:%u! Wanted ID: \"%s\", got \"%s\". Buffer discarded.\n"),
dev->file, dev->block_num, BLKHDR2_ID, Id);
if (block->read_errors == 0 || verbose >= 2) {
Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
}
} else {
dev->dev_errno = EIO;
- Mmsg4(&dev->errmsg, _("Volume data error at %u:%u! Wanted ID: \"%s\", got \"%s\". Buffer discarded.\n"),
+ Mmsg4(dev->errmsg, _("Volume data error at %u:%u! Wanted ID: \"%s\", got \"%s\". Buffer discarded.\n"),
dev->file, dev->block_num, BLKHDR2_ID, Id);
if (block->read_errors == 0 || verbose >= 2) {
Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
/* Sanity check */
if (block_len > MAX_BLOCK_LENGTH) {
dev->dev_errno = EIO;
- Mmsg3(&dev->errmsg, _("Volume data error at %u:%u! Block length %u is insane (too large), probably due to a bad archive.\n"),
+ Mmsg3(dev->errmsg, _("Volume data error at %u:%u! Block length %u is insane (too large), probably due to a bad archive.\n"),
dev->file, dev->block_num, block_len);
if (block->read_errors == 0 || verbose >= 2) {
Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
block_len-BLKHDR_CS_LENGTH);
if (BlockCheckSum != CheckSum) {
dev->dev_errno = EIO;
- Mmsg5(&dev->errmsg, _("Volume data error at %u:%u! Block checksum mismatch in block %u: calc=%x blk=%x\n"),
+ Mmsg5(dev->errmsg, _("Volume data error at %u:%u! Block checksum mismatch in block %u: calc=%x blk=%x\n"),
dev->file, dev->block_num, (unsigned)BlockNumber, BlockCheckSum, CheckSum);
if (block->read_errors == 0 || verbose >= 2) {
Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
* : 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;
}
/* 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;
}
}
- 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:
* 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);
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 */
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++;
}
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);
#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
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
/*
* 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;
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) {
}
}
free_block(lblock);
+ dcr->block = block;
}
}
#endif
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;
* 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;
* 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;
int retry;
JCR *jcr = dcr->jcr;
DEVICE *dev = dcr->dev;
+ DEV_BLOCK *block = dcr->block;
if (dev_state(dev, ST_EOT)) {
return false;
reread:
if (looping > 1) {
dev->dev_errno = EIO;
- Mmsg1(&dev->errmsg, _("Block buffer size looping problem on device %s\n"),
+ Mmsg1(dev->errmsg, _("Block buffer size looping problem on device %s\n"),
dev->dev_name);
Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
block->read_len = 0;
}
} 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);
+ Dmsg1(90, "Read device got: ERR=%s\n", strerror(errno));
block->read_len = 0;
- Mmsg4(&dev->errmsg, _("Read error at file:blk %u:%u on device %s. ERR=%s.\n"),
+ Mmsg4(dev->errmsg, _("Read error at file:blk %u:%u on device %s. ERR=%s.\n"),
dev->file, dev->block_num, dev->dev_name, strerror(dev->dev_errno));
Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
if (dev->state & ST_EOF) { /* EOF just seen? */
Dmsg1(90, "Read device got %d bytes\n", stat);
if (stat == 0) { /* Got EOF ! */
dev->block_num = block->read_len = 0;
- Mmsg3(&dev->errmsg, _("Read zero bytes at %u:%u on device %s.\n"),
+ Mmsg3(dev->errmsg, _("Read zero bytes at %u:%u on device %s.\n"),
dev->file, dev->block_num, dev->dev_name);
if (dev->state & ST_EOF) { /* EOF already read? */
dev->state |= ST_EOT; /* yes, 2 EOFs => EOT */
block->read_len = stat; /* save length read */
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"),
+ 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);
Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
dev->state |= ST_SHORT; /* set short block */
*/
if (block->block_len > block->buf_len) {
dev->dev_errno = EIO;
- Mmsg2(&dev->errmsg, _("Block length %u is greater than buffer %u. Attempting recovery.\n"),
+ Mmsg2(dev->errmsg, _("Block length %u is greater than buffer %u. Attempting recovery.\n"),
block->block_len, block->buf_len);
Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
Pmsg1(000, "%s", dev->errmsg);
lseek(dev->fd, pos, SEEK_SET);
dev->file_addr = pos;
}
- Mmsg1(&dev->errmsg, _("Setting block buffer size to %u bytes.\n"), block->block_len);
+ Mmsg1(dev->errmsg, _("Setting block buffer size to %u bytes.\n"), block->block_len);
Jmsg(jcr, M_INFO, 0, "%s", dev->errmsg);
Pmsg1(000, "%s", dev->errmsg);
/* Set new block length */
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"),
+ 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);
Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
dev->state |= ST_SHORT; /* set short block */
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;