From: Kern Sibbald Date: Sun, 19 Aug 2012 11:16:58 +0000 (+0200) Subject: Backport more master code X-Git-Tag: Release-7.0.0~145 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=c961a7fccda3a0bdb1f8decf16d3602b4b394d51;p=bacula%2Fbacula Backport more master code --- diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index e859ae89bb..b80c4a0737 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -38,6 +38,19 @@ #include "bacula.h" #include "stored.h" +#ifdef DEBUG_BLOCK_CHECKSUM +static const bool debug_block_checksum = true; +#else +static const bool debug_block_checksum = false; +#endif + +#ifdef NO_TAPE_WRITE_TEST +static const bool no_tape_write_test = true; +#else +static const bool no_tape_write_test = false; +#endif + + static bool terminate_writing_volume(DCR *dcr); static bool do_new_file_bookkeeping(DCR *dcr); static bool do_dvd_size_checks(DCR *dcr); @@ -345,6 +358,7 @@ bool DCR::write_block_to_device() DCR *dcr = this; if (dcr->spooling) { + Dmsg0(100, "Write to spool\n"); stat = write_block_to_spool_file(dcr); return stat; } @@ -363,6 +377,7 @@ bool DCR::write_block_to_device() if (dcr->NewVol || dcr->NewFile) { if (job_canceled(jcr)) { stat = false; + Dmsg0(100, "Canceled\n"); goto bail_out; } /* Create a jobmedia record for this job */ @@ -372,6 +387,7 @@ bool DCR::write_block_to_device() dcr->getVolCatName(), jcr->Job); set_new_volume_parameters(dcr); stat = false; + Dmsg0(100, "cannot create media record\n"); goto bail_out; } if (dcr->NewVol) { @@ -411,11 +427,12 @@ bool DCR::write_block_to_dev() int hit_max1, hit_max2; bool ok = true; DCR *dcr = this; + uint32_t checksum; -#ifdef NO_TAPE_WRITE_TEST - empty_block(block); - return true; -#endif + if (no_tape_write_test) { + empty_block(block); + return true; + } if (job_canceled(jcr)) { return false; } @@ -433,18 +450,22 @@ bool DCR::write_block_to_dev() Dmsg0(100, "return write_block_to_dev with ST_WEOT\n"); dev->dev_errno = ENOSPC; Jmsg1(jcr, M_FATAL, 0, _("Cannot write block. Device at EOM. dev=%s\n"), dev->print_name()); + Dmsg1(100, "Attempt to write on read-only Volume. dev=%s\n", dev->print_name()); return false; } if (!dev->can_append()) { dev->dev_errno = EIO; Jmsg1(jcr, M_FATAL, 0, _("Attempt to write on read-only Volume. dev=%s\n"), dev->print_name()); + Dmsg1(100, "Attempt to write on read-only Volume. dev=%s\n", dev->print_name()); return false; } - + if (!dev->is_open()) { Jmsg1(jcr, M_FATAL, 0, _("Attempt to write on closed device=%s\n"), dev->print_name()); + Dmsg1(100, "Attempt to write on closed device=%s\n", dev->print_name()); return false; } + /* * Clear to the end of the buffer if it is not full, * and on tape devices, apply min and fixed blocking. @@ -473,12 +494,7 @@ bool DCR::write_block_to_dev() } } -#ifdef DEBUG_BLOCK_CHECKSUM - uint32_t checksum; checksum = ser_block_header(block, dev->do_checksum()); -#else - ser_block_header(block, dev->do_checksum()); -#endif /* Limit maximum Volume size to value specified by user */ hit_max1 = (dev->max_volume_size > 0) && @@ -558,14 +574,14 @@ bool DCR::write_block_to_dev() } while (stat == -1 && (errno == EBUSY || errno == EIO) && retry++ < 3); -#ifdef DEBUG_BLOCK_CHECKSUM - uint32_t achecksum = ser_block_header(block, dev->do_checksum()); - if (checksum != achecksum) { - Jmsg2(jcr, M_ERROR, 0, _("Block checksum changed during write: before=%ud after=%ud\n"), - checksum, achecksum); - dump_block(block, "with checksum error"); + if (debug_block_checksum) { + uint32_t achecksum = ser_block_header(block, dev->do_checksum()); + if (checksum != achecksum) { + Jmsg2(jcr, M_ERROR, 0, _("Block checksum changed during write: before=%ud after=%ud\n"), + checksum, achecksum); + dump_block(block, "with checksum error"); + } } -#endif #ifdef DEBUG_BLOCK_ZEROING if (bp[0] == 0 && bp[1] == 0 && bp[2] == 0 && block->buf[12] == 0) { @@ -1067,6 +1083,7 @@ reread: Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg); dev->set_short_block(); block->read_len = block->binbuf = 0; + Dmsg2(200, "set block=%p binbuf=%d\n", block, block->binbuf); return false; /* return error */ } diff --git a/bacula/src/stored/bls.c b/bacula/src/stored/bls.c index bcdd6e385f..771f855484 100644 --- a/bacula/src/stored/bls.c +++ b/bacula/src/stored/bls.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2011 Free Software Foundation Europe e.V. + Copyright (C) 2000-2012 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -295,7 +295,7 @@ static void do_blocks(char *infname) DEV_RECORD *record; record = new_record(); dcr->read_block_from_device(NO_BLOCK_NUMBER_CHECK); - read_record_from_block(dcr, block, record); + read_record_from_block(dcr, record); get_session_record(dev, record, &sessrec); free_record(record); Jmsg(jcr, M_INFO, 0, _("Mounted Volume \"%s\".\n"), dcr->VolumeName); @@ -323,7 +323,7 @@ static void do_blocks(char *infname) block->BlockNumber, block->block_len, block->BlockVer, block->VolSessionId, block->VolSessionTime); if (verbose == 1) { - read_record_from_block(dcr, block, rec); + read_record_from_block(dcr, rec); Pmsg9(-1, _("File:blk=%u:%u blk_num=%u blen=%u First rec FI=%s SessId=%u SessTim=%u Strm=%s rlen=%d\n"), dev->file, dev->block_num, block->BlockNumber, block->block_len, diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index 703f412227..967887290d 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -863,7 +863,7 @@ static bool re_read_block_test() goto bail_out; } memset(rec->data, 0, rec->data_len); - if (!read_record_from_block(dcr, block, rec)) { + if (!read_record_from_block(dcr, rec)) { berrno be; Pmsg1(0, _("Read block failed! ERR=%s\n"), be.bstrerror(dev->dev_errno)); goto bail_out; @@ -1234,7 +1234,7 @@ read_again: goto bail_out; } memset(rec->data, 0, rec->data_len); - if (!read_record_from_block(dcr, block, rec)) { + if (!read_record_from_block(dcr, rec)) { berrno be; Pmsg2(0, _("Read record failed. Block %d! ERR=%s\n"), i, be.bstrerror(dev->dev_errno)); goto bail_out; @@ -1366,7 +1366,7 @@ read_again: goto bail_out; } memset(rec->data, 0, rec->data_len); - if (!read_record_from_block(dcr, block, rec)) { + if (!read_record_from_block(dcr, rec)) { berrno be; Pmsg1(0, _("Read record failed! ERR=%s\n"), be.bstrerror(dev->dev_errno)); goto bail_out; @@ -2115,7 +2115,7 @@ static void scan_blocks() block->VolSessionId, block->VolSessionTime); if (verbose == 1) { DEV_RECORD *rec = new_record(); - read_record_from_block(dcr, block, rec); + read_record_from_block(dcr, rec); Pmsg9(-1, _("Block=%u file,blk=%u,%u blen=%u First rec FI=%s SessId=%u SessTim=%u Strm=%s rlen=%d\n"), block->BlockNumber, dev->file, dev->block_num, block->block_len, FI_to_ascii(buf1, rec->FileIndex), rec->VolSessionId, rec->VolSessionTime, diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index ee8b91bc2f..7c6d57bcf8 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -1756,7 +1756,8 @@ void DEVICE::close() case B_VTL_DEV: case B_VTAPE_DEV: case B_TAPE_DEV: - unlock_door(); + unlock_door(); + /* Fall through wanted */ default: d_close(m_fd); break; diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index d5f0043e0b..c7ce4d1a00 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -131,7 +131,7 @@ int read_dev_volume_label(DCR *dcr) "labeled Volume, because: ERR=%s"), NPRT(VolName), dev->print_name(), dev->print_errmsg()); Dmsg1(130, "%s", jcr->errmsg); - } else if (!read_record_from_block(dcr, block, record)) { + } else if (!read_record_from_block(dcr, record)) { Mmsg(jcr->errmsg, _("Could not read Volume label from block.\n")); Dmsg1(130, "%s", jcr->errmsg); } else if (!unser_volume_label(dev, record)) { diff --git a/bacula/src/stored/protos.h b/bacula/src/stored/protos.h index 7958564043..ed9badf6ed 100644 --- a/bacula/src/stored/protos.h +++ b/bacula/src/stored/protos.h @@ -193,7 +193,7 @@ const char *FI_to_ascii(char *buf, int fi); const char *stream_to_ascii(char *buf, int stream, int fi); bool write_record_to_block(DCR *dcr, DEV_RECORD *rec); bool can_write_record_to_block(DEV_BLOCK *block, DEV_RECORD *rec); -bool read_record_from_block(DCR *dcr, DEV_BLOCK *block, DEV_RECORD *rec); +bool read_record_from_block(DCR *dcr, DEV_RECORD *rec); DEV_RECORD *new_record(); void free_record(DEV_RECORD *rec); void empty_record(DEV_RECORD *rec); diff --git a/bacula/src/stored/read_record.c b/bacula/src/stored/read_record.c index ab77400e1a..92383abc09 100644 --- a/bacula/src/stored/read_record.c +++ b/bacula/src/stored/read_record.c @@ -120,7 +120,7 @@ bool read_records(DCR *dcr, * most likely reading the previous record. */ dcr->read_block_from_device(NO_BLOCK_NUMBER_CHECK); - read_record_from_block(dcr, block, trec); + read_record_from_block(dcr, trec); handle_session_record(dev, trec, &sessrec); ok = record_cb(dcr, trec); free_record(trec); @@ -199,7 +199,7 @@ bool read_records(DCR *dcr, lastFileIndex = no_FileIndex; Dmsg1(dbglvl, "Block %s empty\n", is_block_empty(rec)?"is":"NOT"); for (rec->state_bits=0; ok && !is_block_empty(rec); ) { - if (!read_record_from_block(dcr, block, rec)) { + if (!read_record_from_block(dcr, rec)) { Dmsg3(400, "!read-break. state_bits=%s blk=%d rem=%d\n", rec_state_bits_to_str(rec), block->BlockNumber, rec->remainder); break; diff --git a/bacula/src/stored/record.c b/bacula/src/stored/record.c index d1e7cfa82b..73f0c9f713 100644 --- a/bacula/src/stored/record.c +++ b/bacula/src/stored/record.c @@ -546,7 +546,7 @@ uint64_t get_record_address(DEV_RECORD *rec) * routine may have to be called again with a new * block if the entire record was not read. */ -bool read_record_from_block(DCR *dcr, DEV_BLOCK *block, DEV_RECORD *rec) +bool read_record_from_block(DCR *dcr, DEV_RECORD *rec) { ser_declare; uint32_t remlen; @@ -558,45 +558,45 @@ bool read_record_from_block(DCR *dcr, DEV_BLOCK *block, DEV_RECORD *rec) uint32_t rhl; char buf1[100], buf2[100]; - remlen = block->binbuf; + remlen = dcr->block->binbuf; /* Clear state flags */ rec->state_bits = 0; - if (block->dev->is_tape()) { + if (dcr->block->dev->is_tape()) { rec->state_bits |= REC_ISTAPE; } - rec->Block = ((DEVICE *)block->dev)->EndBlock; - rec->File = ((DEVICE *)block->dev)->EndFile; + rec->Block = ((DEVICE *)(dcr->block->dev))->EndBlock; + rec->File = ((DEVICE *)(dcr->block->dev))->EndFile; /* * Get the header. There is always a full header, * otherwise we find it in the next block. */ - Dmsg3(450, "Block=%d Ver=%d size=%u\n", block->BlockNumber, block->BlockVer, - block->block_len); - if (block->BlockVer == 1) { + Dmsg3(450, "Block=%d Ver=%d size=%u\n", dcr->block->BlockNumber, dcr->block->BlockVer, + dcr->block->block_len); + if (dcr->block->BlockVer == 1) { rhl = RECHDR1_LENGTH; } else { rhl = RECHDR2_LENGTH; } if (remlen >= rhl) { Dmsg4(450, "Enter read_record_block: remlen=%d data_len=%d rem=%d blkver=%d\n", - remlen, rec->data_len, rec->remainder, block->BlockVer); + remlen, rec->data_len, rec->remainder, dcr->block->BlockVer); - unser_begin(block->bufp, WRITE_RECHDR_LENGTH); - if (block->BlockVer == 1) { + unser_begin(dcr->block->bufp, WRITE_RECHDR_LENGTH); + if (dcr->block->BlockVer == 1) { unser_uint32(VolSessionId); unser_uint32(VolSessionTime); } else { - VolSessionId = block->VolSessionId; - VolSessionTime = block->VolSessionTime; + VolSessionId = dcr->block->VolSessionId; + VolSessionTime = dcr->block->VolSessionTime; } unser_int32(FileIndex); unser_int32(Stream); unser_uint32(data_bytes); - block->bufp += rhl; - block->binbuf -= rhl; + dcr->block->bufp += rhl; + dcr->block->binbuf -= rhl; remlen -= rhl; /* If we are looking for more (remainder!=0), we reject anything @@ -633,10 +633,10 @@ bool read_record_from_block(DCR *dcr, DEV_BLOCK *block, DEV_RECORD *rec) rec->VolSessionTime = VolSessionTime; rec->FileIndex = FileIndex; if (FileIndex > 0) { - if (block->FirstIndex == 0) { - block->FirstIndex = FileIndex; + if (dcr->block->FirstIndex == 0) { + dcr->block->FirstIndex = FileIndex; } - block->LastIndex = FileIndex; + dcr->block->LastIndex = FileIndex; } Dmsg6(450, "rd_rec_blk() got FI=%s SessId=%d Strm=%s len=%u\n" @@ -655,7 +655,7 @@ bool read_record_from_block(DCR *dcr, DEV_BLOCK *block, DEV_RECORD *rec) */ Dmsg0(450, "read_record_block: nothing\n"); rec->state_bits |= (REC_NO_HEADER | REC_BLOCK_EMPTY); - empty_block(block); /* mark block empty */ + empty_block(dcr->block); /* mark block empty */ return false; } @@ -666,7 +666,7 @@ bool read_record_from_block(DCR *dcr, DEV_BLOCK *block, DEV_RECORD *rec) * continuing with this block. */ rec->state_bits |= (REC_NO_HEADER | REC_BLOCK_EMPTY); - empty_block(block); + empty_block(dcr->block); Jmsg2(dcr->jcr, M_WARNING, 0, _("Sanity check failed. maxlen=%d datalen=%d. Block discarded.\n"), MAX_BLOCK_LENGTH, data_bytes); return false; @@ -684,15 +684,15 @@ bool read_record_from_block(DCR *dcr, DEV_BLOCK *block, DEV_RECORD *rec) */ if (remlen >= data_bytes) { /* Got whole record */ - memcpy(rec->data+rec->data_len, block->bufp, data_bytes); - block->bufp += data_bytes; - block->binbuf -= data_bytes; + memcpy(rec->data+rec->data_len, dcr->block->bufp, data_bytes); + dcr->block->bufp += data_bytes; + dcr->block->binbuf -= data_bytes; rec->data_len += data_bytes; } else { /* Partial record */ - memcpy(rec->data+rec->data_len, block->bufp, remlen); - block->bufp += remlen; - block->binbuf -= remlen; + memcpy(rec->data+rec->data_len, dcr->block->bufp, remlen); + dcr->block->bufp += remlen; + dcr->block->binbuf -= remlen; rec->data_len += remlen; rec->remainder = 1; /* partial record transferred */ Dmsg1(450, "read_record_block: partial xfered=%d\n", rec->data_len);