Skip to content

Commit

Permalink
block: create null jobmedia entry to prevent recycling
Browse files Browse the repository at this point in the history
  • Loading branch information
sebsura authored and BareosBot committed Aug 1, 2023
1 parent 9942923 commit 2ec97e4
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions core/src/stored/block.cc
Expand Up @@ -790,6 +790,19 @@ bool DeviceControlRecord::WriteBlockToDev()
return false;
}

// if this is the first write to this volume (from this job) create a null
// jobmedia entry to prevent the volume from getting recycled.
dcr->VolMediaId = dev->VolCatInfo.VolMediaId;
if (dcr->VolFirstIndex == 0 && block->FirstIndex > 0) {
dcr->WroteVol = true;
ASSERT(dcr->DirCreateJobmediaRecord(true));
dcr->VolFirstIndex = block->FirstIndex;
uint64_t addr = dev->file_addr;
dcr->StartBlock = (uint32_t)addr;
dcr->StartFile = (uint32_t)(addr >> 32);
}
if (block->LastIndex > 0) { dcr->VolLastIndex = block->LastIndex; }

// We successfully wrote the block, now do housekeeping
Dmsg2(1300, "VolCatBytes=%d newVolCatBytes=%d\n",
(int)dev->VolCatInfo.VolCatBytes,
Expand All @@ -814,11 +827,6 @@ bool DeviceControlRecord::WriteBlockToDev()
dev->block_num = dcr->EndBlock;
dev->file = dcr->EndFile;
}
dcr->VolMediaId = dev->VolCatInfo.VolMediaId;
if (dcr->VolFirstIndex == 0 && block->FirstIndex > 0) {
dcr->VolFirstIndex = block->FirstIndex;
}
if (block->LastIndex > 0) { dcr->VolLastIndex = block->LastIndex; }
dcr->WroteVol = true;
dev->file_addr += wlen; /* update file address */
dev->file_size += wlen;
Expand Down

0 comments on commit 2ec97e4

Please sign in to comment.