From fcb139a79e4fdfd0cd3072f6c744c6e58010fcd9 Mon Sep 17 00:00:00 2001 From: Alain Spineux Date: Fri, 18 Nov 2022 10:44:20 +0100 Subject: [PATCH] BB03 recycle continuity --- bacula/src/stored/block_util.c | 8 ++++---- bacula/src/stored/dev.c | 2 +- bacula/src/stored/label.c | 1 + bacula/src/stored/record.h | 5 ++++- bacula/src/stored/record_read.c | 1 + 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/bacula/src/stored/block_util.c b/bacula/src/stored/block_util.c index 5fda8b3f2..5028130cc 100644 --- a/bacula/src/stored/block_util.c +++ b/bacula/src/stored/block_util.c @@ -487,7 +487,8 @@ bool unser_block_header(DCR *dcr, DEVICE *dev, DEV_BLOCK *block) unser_bytes(Id, BLKHDR_ID_LENGTH); ASSERT(unser_length(block->buf) == BLKHDR1_LENGTH); Id[BLKHDR_ID_LENGTH] = 0; - block->CheckSum64 = CheckSumLo; // only for BB01 & BB02 + block->CheckSum64 = CheckSumLo; /* only for BB01 & BB02 */ + block->blkh_options = BLKHOPT_NONE; /* only in BB03 */ if (Id[3] == '1') { bhl = BLKHDR1_LENGTH; block->BlockVer = 1; @@ -527,12 +528,11 @@ bool unser_block_header(DCR *dcr, DEVICE *dev, DEV_BLOCK *block) } } else if (Id[3] == '3') { bhl = BLKHDR3_LENGTH; - uint32_t blkh_options = CheckSumLo; /* in BB03 blkh_options is stored at the checksum location */ + block->blkh_options = CheckSumLo; /* in BB03 blkh_options is stored at the checksum location */ unser_uint32(block->VolSessionId); unser_uint32(block->VolSessionTime); - /* decrypt the block before to calculate the checksum */ - if ((blkh_options & BLKHOPT_ENCRYPT_BLOCK) && block->dev->crypto_device_ctx) + if ((block->blkh_options & BLKHOPT_ENCRYPT_BLOCK) && block->dev->crypto_device_ctx) { block_cipher_init_iv_header(block->dev->crypto_device_ctx, BlockNumber, block->VolSessionId, block->VolSessionTime); block_cipher_decrypt(block->dev->crypto_device_ctx, block_len-bhl, block->buf+bhl, block->buf_enc); diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index 5b1b8eb3d..9e3ab5dcb 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -1194,7 +1194,7 @@ bool DEVICE::load_encryption_key(DCR *dcr, const char *operation, } /* don't use encryption if volume encryption is not enable or we are reading * (aka not recycling) a BB02 volume */ - if (device->volume_encryption == ET_NONE || (op != op_label && VolHdr.BlockVer <= 2)) { + if (device->volume_encryption == ET_NONE || (op != op_label && !(VolHdr.blkh_options & BLKHOPT_ENCRYPT_VOL))) { return ok; } JCR *jcr = dcr->jcr; diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index 06c843320..77412aaf9 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -1037,6 +1037,7 @@ bool unser_volume_label(DEVICE *dev, DEV_RECORD *rec) dev->VolHdr.LabelType = rec->FileIndex; dev->VolHdr.LabelSize = rec->data_len; dev->VolHdr.BlockVer = rec->BlockVer; + dev->VolHdr.blkh_options = rec->blkh_options; /* Unserialize the record into the Volume Header */ Dmsg2(100, "reclen=%d recdata=%s", rec->data_len, rec->data); diff --git a/bacula/src/stored/record.h b/bacula/src/stored/record.h index dfb74ec3e..71da5620c 100644 --- a/bacula/src/stored/record.h +++ b/bacula/src/stored/record.h @@ -121,7 +121,8 @@ struct DEV_RECORD { uint32_t extra_bytes; /* the extra size that must be accounted in VolABytes */ uint32_t state_bits; /* state bits */ uint32_t RecNum; /* Record number in the block */ - int BlockVer; /* 1, 2 or .. from BB01, BB02, ... */ + int BlockVer; /* from the block header: 1,2,3 from BB?? */ + uint32_t blkh_options; /* from the block header: about block encryption */ uint32_t BlockNumber; /* Block number for this record (used in read_records()) */ bool invalid; /* The record may be invalid if it was merged with a previous record */ rec_state wstate; /* state of write_record_to_block */ @@ -173,6 +174,7 @@ struct Volume_Label { uint32_t VerNum; /* Label version number */ int BlockVer; /* 1, 2 or .. from BB01, BB02 from the FIRST block */ + uint32_t blkh_options; /* the block options bits from the FIRST block */ /* VerNum <= 10 */ float64_t label_date; /* Date tape labeled */ float64_t label_time; /* Time tape labeled */ @@ -207,6 +209,7 @@ struct Volume_Label { uint64_t MaxPartSize; /* Maximum Part Size */ /* For Volume encryption */ + bool is_vol_encrypted; uint32_t EncCypherKeySize; uint32_t MasterKeyIdSize; unsigned char EncCypherKey[MAX_BLOCK_CIPHER_KEY_LEN]; /* The encryption key diff --git a/bacula/src/stored/record_read.c b/bacula/src/stored/record_read.c index 0b925c937..96aac12fd 100644 --- a/bacula/src/stored/record_read.c +++ b/bacula/src/stored/record_read.c @@ -253,6 +253,7 @@ bool read_record_from_block(DCR *dcr, DEV_RECORD *rec) rec->Addr = rec->StartAddr = dcr->block->BlockAddr; } rec->BlockVer = dcr->block->BlockVer; /* needed for unser_volume_label() */ + rec->blkh_options = dcr->block->blkh_options; /* needed for unser_volume_label() */ /* We read the next record */ dcr->block->RecNum++; -- 2.47.3