From 4947216b49603ec81f94319710a79478aa4216f5 Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Wed, 6 Nov 2019 11:55:56 +0100 Subject: [PATCH] stored: place members into separate struct ReadSession --- core/src/stored/bsr.cc | 6 +++--- core/src/stored/btape.cc | 2 +- core/src/stored/butil.cc | 4 ++-- core/src/stored/device.cc | 14 +++++++------- core/src/stored/dir_cmd.cc | 9 ++++++--- core/src/stored/fd_cmds.cc | 18 ++++++++++++------ core/src/stored/jcr_private.h | 26 +++++++++++++------------- core/src/stored/job.cc | 12 ++++++------ core/src/stored/ndmp_tape.cc | 12 ++++++------ core/src/stored/read_record.cc | 21 +++++++++++---------- 10 files changed, 67 insertions(+), 57 deletions(-) diff --git a/core/src/stored/bsr.cc b/core/src/stored/bsr.cc index e4eaaf1c483..2c174d83c16 100644 --- a/core/src/stored/bsr.cc +++ b/core/src/stored/bsr.cc @@ -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 */ @@ -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; diff --git a/core/src/stored/btape.cc b/core/src/stored/btape.cc index 0ffbbb4276c..924bdb4cd79 100644 --- a/core/src/stored/btape.cc +++ b/core/src/stored/btape.cc @@ -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) { diff --git a/core/src/stored/butil.cc b/core/src/stored/butil.cc index 60dc78f9cf7..93ccb348f4b 100644 --- a/core/src/stored/butil.cc +++ b/core/src/stored/butil.cc @@ -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); @@ -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); diff --git a/core/src/stored/device.cc b/core/src/stored/device.cc index 449fbede64b..ee809b28a9c 100644 --- a/core/src/stored/device.cc +++ b/core/src/stored/device.cc @@ -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"), @@ -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; diff --git a/core/src/stored/dir_cmd.cc b/core/src/stored/dir_cmd.cc index 3fb1edcf5c9..80a49537f3b 100644 --- a/core/src/stored/dir_cmd.cc +++ b/core/src/stored/dir_cmd.cc @@ -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; diff --git a/core/src/stored/fd_cmds.cc b/core/src/stored/fd_cmds.cc index dd8d1ab1251..11b52872410 100644 --- a/core/src/stored/fd_cmds.cc +++ b/core/src/stored/fd_cmds.cc @@ -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); @@ -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; diff --git a/core/src/stored/jcr_private.h b/core/src/stored/jcr_private.h index 540aecb513b..4d9c581c517 100644 --- a/core/src/stored/jcr_private.h +++ b/core/src/stored/jcr_private.h @@ -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{}; @@ -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 */ diff --git a/core/src/stored/job.cc b/core/src/stored/job.cc index c8f212cf8b9..dcd3384c806 100644 --- a/core/src/stored/job.cc +++ b/core/src/stored/job.cc @@ -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) { diff --git a/core/src/stored/ndmp_tape.cc b/core/src/stored/ndmp_tape.cc index 100bf116fa0..10555cf9614 100644 --- a/core/src/stored/ndmp_tape.cc +++ b/core/src/stored/ndmp_tape.cc @@ -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; @@ -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. @@ -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) { diff --git a/core/src/stored/read_record.cc b/core/src/stored/read_record.cc index e2a4dc4b3f3..326e6d75a0c 100644 --- a/core/src/stored/read_record.cc +++ b/core/src/stored/read_record.cc @@ -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) @@ -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; } @@ -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, @@ -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); @@ -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)) {