Skip to content

Commit

Permalink
stored: place members into separate struct ReadSession
Browse files Browse the repository at this point in the history
  • Loading branch information
franku committed Nov 7, 2019
1 parent 2f40f56 commit 4947216
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 57 deletions.
6 changes: 3 additions & 3 deletions core/src/stored/bsr.cc
Expand Up @@ -801,7 +801,7 @@ static bool AddRestoreVolume(JobControlRecord* jcr, VolumeList* vol)
/* Add volume to volume manager's read list */
AddReadVolume(jcr, vol->VolumeName);

if (!next) { /* list empty ? */
if (!next) { /* list empty ? */
jcr->impl->VolList = vol; /* yes, add volume */
} else {
/* Loop through all but last */
Expand Down Expand Up @@ -840,8 +840,8 @@ void CreateRestoreVolumeList(JobControlRecord* jcr)
*/
jcr->impl->NumReadVolumes = 0;
jcr->impl->CurReadVolume = 0;
if (jcr->impl->bsr) {
BootStrapRecord* bsr = jcr->impl->bsr;
if (jcr->impl->read_session.bsr) {
BootStrapRecord* bsr = jcr->impl->read_session.bsr;
if (!bsr->volume || !bsr->volume->VolumeName[0]) { return; }
for (; bsr; bsr = bsr->next) {
BsrVolume* bsrvol;
Expand Down
2 changes: 1 addition & 1 deletion core/src/stored/btape.cc
Expand Up @@ -2446,7 +2446,7 @@ static bool do_unfill()
last_block = last_block1;

FreeRestoreVolumeList(jcr);
jcr->impl->bsr = NULL;
jcr->impl->read_session.bsr = NULL;
bstrncpy(dcr->VolumeName, "TestVolume1|TestVolume2", sizeof(dcr->VolumeName));
CreateRestoreVolumeList(jcr);
if (jcr->impl->VolList != NULL) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/stored/butil.cc
Expand Up @@ -71,7 +71,7 @@ JobControlRecord* SetupJcr(const char* name,
JobControlRecord* jcr = new_jcr(MyFreeJcr);
jcr->impl = new JobControlRecordPrivate;

jcr->impl->bsr = bsr;
jcr->impl->read_session.bsr = bsr;
jcr->impl->director = director;
jcr->VolSessionId = 1;
jcr->VolSessionTime = (uint32_t)time(NULL);
Expand Down Expand Up @@ -142,7 +142,7 @@ static bool setup_to_access_device(DeviceControlRecord* dcr,
} else {
VolName[0] = 0;
}
if (!jcr->impl->bsr && VolName[0] == 0) {
if (!jcr->impl->read_session.bsr && VolName[0] == 0) {
if (!bstrncmp(dev_name, "/dev/", 5)) {
/* Try stripping file part */
p = dev_name + strlen(dev_name);
Expand Down
14 changes: 7 additions & 7 deletions core/src/stored/device.cc
Expand Up @@ -313,9 +313,9 @@ BootStrapRecord* PositionDeviceToFirstFile(JobControlRecord* jcr,
* Now find and position to first file and block
* on this tape.
*/
if (jcr->impl->bsr) {
jcr->impl->bsr->Reposition = true; /* force repositioning */
bsr = find_next_bsr(jcr->impl->bsr, dev);
if (jcr->impl->read_session.bsr) {
jcr->impl->read_session.bsr->Reposition = true;
bsr = find_next_bsr(jcr->impl->read_session.bsr, dev);
if (GetBsrStartAddr(bsr, &file, &block) > 0) {
Jmsg(jcr, M_INFO, 0,
_("Forward spacing Volume \"%s\" to file:block %u:%u.\n"),
Expand All @@ -339,15 +339,15 @@ bool TryDeviceRepositioning(JobControlRecord* jcr,
BootStrapRecord* bsr;
Device* dev = dcr->dev;

bsr = find_next_bsr(jcr->impl->bsr, dev);
if (bsr == NULL && jcr->impl->bsr->mount_next_volume) {
bsr = find_next_bsr(jcr->impl->read_session.bsr, dev);
if (bsr == NULL && jcr->impl->read_session.bsr->mount_next_volume) {
Dmsg0(500, "Would mount next volume here\n");
Dmsg2(500, "Current position (file:block) %u:%u\n", dev->file,
dev->block_num);
jcr->impl->bsr->mount_next_volume = false;
jcr->impl->read_session.bsr->mount_next_volume = false;
if (!dev->AtEot()) {
/* Set EOT flag to force mount of next Volume */
jcr->impl->mount_next_volume = true;
jcr->impl->read_session.mount_next_volume = true;
dev->SetEot();
}
rec->Block = 0;
Expand Down
9 changes: 6 additions & 3 deletions core/src/stored/dir_cmd.cc
Expand Up @@ -1314,12 +1314,15 @@ static inline bool GetBootstrapFile(JobControlRecord* jcr, BareosSocket* sock)
}
fclose(bs);
Dmsg0(10, "=== end bootstrap file ===\n");
jcr->impl->bsr = libbareos::parse_bsr(jcr, jcr->RestoreBootstrap);
if (!jcr->impl->bsr) {
jcr->impl->read_session.bsr =
libbareos::parse_bsr(jcr, jcr->RestoreBootstrap);
if (!jcr->impl->read_session.bsr) {
Jmsg(jcr, M_FATAL, 0, _("Error parsing bootstrap file.\n"));
goto bail_out;
}
if (debug_level >= 10) { libbareos::DumpBsr(jcr->impl->bsr, true); }
if (debug_level >= 10) {
libbareos::DumpBsr(jcr->impl->read_session.bsr, true);
}
/* If we got a bootstrap, we are reading, so create read volume list */
CreateRestoreVolumeList(jcr);
ok = true;
Expand Down
18 changes: 12 additions & 6 deletions core/src/stored/fd_cmds.cc
Expand Up @@ -382,9 +382,12 @@ static bool ReadOpenSession(JobControlRecord* jcr)
}

if (sscanf(fd->msg, read_open, jcr->impl->read_dcr->VolumeName,
&jcr->impl->read_VolSessionId, &jcr->impl->read_VolSessionTime,
&jcr->impl->read_StartFile, &jcr->impl->read_EndFile,
&jcr->impl->read_StartBlock, &jcr->impl->read_EndBlock) == 7) {
&jcr->impl->read_session.read_VolSessionId,
&jcr->impl->read_session.read_VolSessionTime,
&jcr->impl->read_session.read_StartFile,
&jcr->impl->read_session.read_EndFile,
&jcr->impl->read_session.read_StartBlock,
&jcr->impl->read_session.read_EndBlock) == 7) {
if (jcr->impl->session_opened) {
PmStrcpy(jcr->errmsg, _("Attempt to open read on non-open session.\n"));
fd->fsend(NOT_opened);
Expand All @@ -393,10 +396,13 @@ static bool ReadOpenSession(JobControlRecord* jcr)
Dmsg4(100,
"ReadOpenSession got: JobId=%d Vol=%s VolSessId=%ld VolSessT=%ld\n",
jcr->JobId, jcr->impl->read_dcr->VolumeName,
jcr->impl->read_VolSessionId, jcr->impl->read_VolSessionTime);
jcr->impl->read_session.read_VolSessionId,
jcr->impl->read_session.read_VolSessionTime);
Dmsg4(100, " StartF=%ld EndF=%ld StartB=%ld EndB=%ld\n",
jcr->impl->read_StartFile, jcr->impl->read_EndFile,
jcr->impl->read_StartBlock, jcr->impl->read_EndBlock);
jcr->impl->read_session.read_StartFile,
jcr->impl->read_session.read_EndFile,
jcr->impl->read_session.read_StartBlock,
jcr->impl->read_session.read_EndBlock);
}

jcr->impl->session_opened = true;
Expand Down
26 changes: 13 additions & 13 deletions core/src/stored/jcr_private.h
Expand Up @@ -36,6 +36,18 @@ class DeviceControlRecord;
class DirectorResource;
struct BootStrapRecord;

struct ReadSession {
READ_CTX* rctx{};
BootStrapRecord* bsr{};
bool mount_next_volume{};
uint32_t read_VolSessionId{};
uint32_t read_VolSessionTime{};
uint32_t read_StartFile{};
uint32_t read_EndFile{};
uint32_t read_StartBlock{};
uint32_t read_EndBlock{};
};

struct DeviceWaitTimes {
int32_t min_wait{};
int32_t max_wait{};
Expand Down Expand Up @@ -83,19 +95,7 @@ struct JobControlRecordPrivate {
bool insert_jobmedia_records{}; /**< Need to insert job media records */
uint64_t RemainingQuota{}; /**< Available bytes to use as quota */

/*
* Parameters for Open Read Session
*/
storagedaemon::READ_CTX* rctx{}; /**< Read context used to keep track of what is processed or not */
storagedaemon::BootStrapRecord* bsr{}; /**< Bootstrap record -- has everything */
bool mount_next_volume{}; /**< Set to cause next volume mount */
uint32_t read_VolSessionId{};
uint32_t read_VolSessionTime{};
uint32_t read_StartFile{};
uint32_t read_EndFile{};
uint32_t read_StartBlock{};
uint32_t read_EndBlock{};

storagedaemon::ReadSession read_session;
storagedaemon::DeviceWaitTimes device_wait_times;
};
/* clang-format on */
Expand Down
12 changes: 6 additions & 6 deletions core/src/stored/job.cc
Expand Up @@ -429,14 +429,14 @@ void StoredFreeJcr(JobControlRecord* jcr)

if (jcr->impl->backup_format) { FreeMemory(jcr->impl->backup_format); }

if (jcr->impl->bsr) {
libbareos::FreeBsr(jcr->impl->bsr);
jcr->impl->bsr = NULL;
if (jcr->impl->read_session.bsr) {
libbareos::FreeBsr(jcr->impl->read_session.bsr);
jcr->impl->read_session.bsr = NULL;
}

if (jcr->impl->rctx) {
FreeReadContext(jcr->impl->rctx);
jcr->impl->rctx = NULL;
if (jcr->impl->read_session.rctx) {
FreeReadContext(jcr->impl->read_session.rctx);
jcr->impl->read_session.rctx = NULL;
}

if (jcr->compress.deflate_buffer || jcr->compress.inflate_buffer) {
Expand Down
12 changes: 6 additions & 6 deletions core/src/stored/ndmp_tape.cc
Expand Up @@ -377,7 +377,7 @@ static inline bool bndmp_read_data_from_block(JobControlRecord* jcr,
uint32_t* data_length)
{
DeviceControlRecord* dcr = jcr->impl->read_dcr;
READ_CTX* rctx = jcr->impl->rctx;
READ_CTX* rctx = jcr->impl->read_session.rctx;
bool done = false;
bool ok = true;

Expand Down Expand Up @@ -768,13 +768,13 @@ extern "C" ndmp9_error bndmp_tape_open(struct ndm_session* sess,
Dmsg1(50, "Begin reading device=%s\n", dcr->dev->print_name());

PositionDeviceToFirstFile(jcr, dcr);
jcr->impl->mount_next_volume = false;
jcr->impl->read_session.mount_next_volume = false;

/*
* Allocate a new read context for this Job.
*/
rctx = new_read_context();
jcr->impl->rctx = rctx;
jcr->impl->read_session.rctx = rctx;

/*
* Read the first block and setup record processing.
Expand Down Expand Up @@ -1113,9 +1113,9 @@ void EndOfNdmpBackup(JobControlRecord* jcr)

void EndOfNdmpRestore(JobControlRecord* jcr)
{
if (jcr->impl->rctx) {
FreeReadContext(jcr->impl->rctx);
jcr->impl->rctx = NULL;
if (jcr->impl->read_session.rctx) {
FreeReadContext(jcr->impl->read_session.rctx);
jcr->impl->read_session.rctx = NULL;
}

if (jcr->impl->acquired_storage) {
Expand Down
21 changes: 11 additions & 10 deletions core/src/stored/read_record.cc
Expand Up @@ -222,15 +222,15 @@ bool ReadNextBlockFromDevice(DeviceControlRecord* dcr,
trec->FileIndex = EOT_LABEL;
trec->File = dcr->dev->file;
*status = RecordCb(dcr, trec);
if (jcr->impl->mount_next_volume) {
jcr->impl->mount_next_volume = false;
if (jcr->impl->read_session.mount_next_volume) {
jcr->impl->read_session.mount_next_volume = false;
dcr->dev->ClearEot();
}
FreeRecord(trec);
}
return false;
}
jcr->impl->mount_next_volume = false;
jcr->impl->read_session.mount_next_volume = false;

/*
* We just have a new tape up, now read the label (first record)
Expand Down Expand Up @@ -329,11 +329,12 @@ bool ReadNextRecordFromBlock(DeviceControlRecord* dcr,
*/
if (rec->FileIndex < 0) {
HandleSessionRecord(dcr->dev, rec, &rctx->sessrec);
if (jcr->impl->bsr) {
if (jcr->impl->read_session.bsr) {
/*
* We just check block FI and FT not FileIndex
*/
rec->match_stat = MatchBsrBlock(jcr->impl->bsr, dcr->block);
rec->match_stat =
MatchBsrBlock(jcr->impl->read_session.bsr, dcr->block);
} else {
rec->match_stat = 0;
}
Expand All @@ -344,9 +345,9 @@ bool ReadNextRecordFromBlock(DeviceControlRecord* dcr,
/*
* Apply BootStrapRecord filter
*/
if (jcr->impl->bsr) {
rec->match_stat =
MatchBsr(jcr->impl->bsr, rec, &dev->VolHdr, &rctx->sessrec, jcr);
if (jcr->impl->read_session.bsr) {
rec->match_stat = MatchBsr(jcr->impl->read_session.bsr, rec,
&dev->VolHdr, &rctx->sessrec, jcr);
if (rec->match_stat == -1) { /* no more possible matches */
*done = true; /* all items found, stop */
Dmsg2(debuglevel, "All done=(file:block) %u:%u\n", dev->file,
Expand Down Expand Up @@ -377,7 +378,7 @@ bool ReadNextRecordFromBlock(DeviceControlRecord* dcr,

if (rctx->lastFileIndex != READ_NO_FILEINDEX &&
rctx->lastFileIndex != rec->FileIndex) {
if (IsThisBsrDone(jcr->impl->bsr, rec) &&
if (IsThisBsrDone(jcr->impl->read_session.bsr, rec) &&
TryDeviceRepositioning(jcr, rec, dcr)) {
Dmsg2(debuglevel, "This bsr done, break pos %u:%u\n", dev->file,
dev->block_num);
Expand Down Expand Up @@ -412,7 +413,7 @@ bool ReadRecords(DeviceControlRecord* dcr,

rctx = new_read_context();
PositionDeviceToFirstFile(jcr, dcr);
jcr->impl->mount_next_volume = false;
jcr->impl->read_session.mount_next_volume = false;

while (ok && !done) {
if (JobCanceled(jcr)) {
Expand Down

0 comments on commit 4947216

Please sign in to comment.