Skip to content

Commit

Permalink
stored: move daemon private data to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
franku committed Nov 7, 2019
1 parent e2057b5 commit 042d2cf
Show file tree
Hide file tree
Showing 36 changed files with 629 additions and 538 deletions.
77 changes: 0 additions & 77 deletions core/src/include/jcr.h
Expand Up @@ -37,10 +37,6 @@
#include <include/bareos.h>
#include "lib/tls_conf.h"

#ifdef STORAGE_DAEMON
#include "stored/read_ctx.h"
#endif

#ifdef DIRECTOR_DAEMON
#include "cats/cats.h"
#include "dird/client_connection_handshake_mode.h"
Expand All @@ -52,13 +48,6 @@ typedef struct s_tree_root TREE_ROOT;

class dlist;

namespace storagedaemon {
struct VolumeList;
class DeviceControlRecord;
class DirectorResource;
struct BootStrapRecord;
} // namespace storagedaemon

namespace filedaemon {
class BareosAccurateFilelist;
struct save_pkt;
Expand Down Expand Up @@ -391,72 +380,6 @@ class JobControlRecord {
bool is_passive_client_connection_probing = false; /**< Set if director probes a passive client connection */

JobControlRecordPrivate* impl_;

#ifdef STORAGE_DAEMON
/*
* Storage Daemon specific part of JobControlRecord
*/
JobControlRecord* next_dev = nullptr; /**< Next JobControlRecord attached to device */
JobControlRecord* prev_dev = nullptr; /**< Previous JobControlRecord attached to device */
char* dir_auth_key = nullptr; /**< Dir auth key */
pthread_cond_t job_start_wait = PTHREAD_COND_INITIALIZER; /**< Wait for FD to start Job */
pthread_cond_t job_end_wait = PTHREAD_COND_INITIALIZER; /**< Wait for Job to end */
int32_t type = 0;
storagedaemon::DeviceControlRecord* read_dcr = nullptr; /**< Device context for reading */
storagedaemon::DeviceControlRecord* dcr = nullptr; /**< Device context record */
alist* dcrs = nullptr; /**< List of dcrs open */
POOLMEM* job_name = nullptr; /**< Base Job name (not unique) */
POOLMEM* fileset_name = nullptr; /**< FileSet */
POOLMEM* fileset_md5 = nullptr; /**< MD5 for FileSet */
POOLMEM* backup_format = nullptr; /**< Backup format used when doing a NDMP backup */
storagedaemon::VolumeList* VolList = nullptr; /**< List to read */
int32_t NumWriteVolumes = 0; /**< Number of volumes written */
int32_t NumReadVolumes = 0; /**< Total number of volumes to read */
int32_t CurReadVolume = 0; /**< Current read volume number */
int32_t label_errors = 0; /**< Count of label errors */
bool session_opened = false;
bool remote_replicate = false; /**< Replicate data to remote SD */
int32_t Ticket = 0; /**< Ticket for this job */
bool ignore_label_errors = false; /**< Ignore Volume label errors */
bool spool_attributes = false; /**< Set if spooling attributes */
bool no_attributes = false; /**< Set if no attributes wanted */
int64_t spool_size = 0; /**< Spool size for this job */
bool spool_data = false; /**< Set to spool data */
int32_t CurVol = 0; /**< Current Volume count */
storagedaemon::DirectorResource* director = nullptr; /**< Director resource */
alist* plugin_options = nullptr; /**< Specific Plugin Options sent by DIR */
alist* write_store = nullptr; /**< List of write storage devices sent by DIR */
alist* read_store = nullptr; /**< List of read devices sent by DIR */
alist* reserve_msgs = nullptr; /**< Reserve fail messages */
bool acquired_storage = false; /**< Did we acquire our reserved storage already or not */
bool PreferMountedVols = false; /**< Prefer mounted vols rather than new */
bool Resched = false; /**< Job may be rescheduled */
bool insert_jobmedia_records = false; /**< Need to insert job media records */
uint64_t RemainingQuota = 0; /**< Available bytes to use as quota */

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

/*
* Device wait times
*/
int32_t min_wait = 0;
int32_t max_wait = 0;
int32_t max_num_wait = 0;
int32_t wait_sec = 0;
int32_t rem_wait_sec = 0;
int32_t num_wait = 0;
#endif /* STORAGE_DAEMON */
};
/* clang-format on */

Expand Down
5 changes: 3 additions & 2 deletions core/src/plugins/stored/scsicrypto-sd.cc
Expand Up @@ -61,6 +61,7 @@
*/
#include "include/bareos.h"
#include "stored/stored.h"
#include "stored/jcr_private.h"
#include "lib/berrno.h"
#include "lib/status.h"
#include "lib/crypto_wrap.h"
Expand Down Expand Up @@ -365,8 +366,8 @@ static bRC do_set_scsi_encryption_key(void* value)
* has been wrapped using RFC3394 key wrapping. We first copy the current
* wrapped key into a temporary variable for unwrapping.
*/
if (dcr->jcr && dcr->jcr->director) {
director = dcr->jcr->director;
if (dcr->jcr && dcr->jcr->impl_->director) {
director = dcr->jcr->impl_->director;
if (director->keyencrkey.value) {
char WrappedVolEncrKey[MAX_NAME_LENGTH];

Expand Down
23 changes: 12 additions & 11 deletions core/src/stored/acquire.cc
Expand Up @@ -43,6 +43,7 @@
#include "lib/berrno.h"
#include "include/jcr.h"
#include "stored/block.h"
#include "stored/jcr_private.h"

namespace storagedaemon {

Expand Down Expand Up @@ -112,20 +113,20 @@ bool AcquireDeviceForRead(DeviceControlRecord* dcr)
}

/* Find next Volume, if any */
vol = jcr->VolList;
vol = jcr->impl_->VolList;
if (!vol) {
char ed1[50];
Jmsg(jcr, M_FATAL, 0,
_("No volumes specified for reading. Job %s canceled.\n"),
edit_int64(jcr->JobId, ed1));
goto get_out;
}
jcr->CurReadVolume++;
for (i = 1; i < jcr->CurReadVolume; i++) { vol = vol->next; }
jcr->impl_->CurReadVolume++;
for (i = 1; i < jcr->impl_->CurReadVolume; i++) { vol = vol->next; }
if (!vol) {
Jmsg(jcr, M_FATAL, 0,
_("Logic error: no next volume to read. Numvol=%d Curvol=%d\n"),
jcr->NumReadVolumes, jcr->CurReadVolume);
jcr->impl_->NumReadVolumes, jcr->impl_->CurReadVolume);
goto get_out; /* should not happen */
}
SetDcrFromVol(dcr, vol);
Expand Down Expand Up @@ -166,8 +167,8 @@ bool AcquireDeviceForRead(DeviceControlRecord* dcr)
LockReservations();
memset(&rctx, 0, sizeof(ReserveContext));
rctx.jcr = jcr;
jcr->read_dcr = dcr;
jcr->reserve_msgs = new alist(10, not_owned_by_alist);
jcr->impl_->read_dcr = dcr;
jcr->impl_->reserve_msgs = new alist(10, not_owned_by_alist);
rctx.any_drive = true;
rctx.device_name = vol->device;
store = new DirectorStorage;
Expand Down Expand Up @@ -508,7 +509,7 @@ DeviceControlRecord* AcquireDeviceForAppend(DeviceControlRecord* dcr)
}

dev->num_writers++; /* we are now a writer */
if (jcr->NumWriteVolumes == 0) { jcr->NumWriteVolumes = 1; }
if (jcr->impl_->NumWriteVolumes == 0) { jcr->impl_->NumWriteVolumes = 1; }
dev->VolCatInfo.VolCatJobs++; /* increment number of jobs on vol */
Dmsg4(100, "=== nwriters=%d nres=%d vcatjob=%d dev=%s\n", dev->num_writers,
dev->NumReserved(), dev->VolCatInfo.VolCatJobs, dev->print_name());
Expand Down Expand Up @@ -782,8 +783,8 @@ void SetupNewDcrDevice(JobControlRecord* jcr,
/*
* Use job spoolsize prior to device spoolsize
*/
if (jcr && jcr->spool_size) {
dcr->max_job_spool_size = jcr->spool_size;
if (jcr && jcr->impl_->spool_size) {
dcr->max_job_spool_size = jcr->impl_->spool_size;
} else {
dcr->max_job_spool_size = dev->device->max_job_spool_size;
}
Expand Down Expand Up @@ -876,9 +877,9 @@ void FreeDeviceControlRecord(DeviceControlRecord* dcr)

if (dcr->rec) { FreeRecord(dcr->rec); }

if (jcr && jcr->dcr == dcr) { jcr->dcr = NULL; }
if (jcr && jcr->impl_->dcr == dcr) { jcr->impl_->dcr = NULL; }

if (jcr && jcr->read_dcr == dcr) { jcr->read_dcr = NULL; }
if (jcr && jcr->impl_->read_dcr == dcr) { jcr->impl_->read_dcr = NULL; }

V(dcr->mutex_);

Expand Down
7 changes: 4 additions & 3 deletions core/src/stored/append.cc
Expand Up @@ -32,6 +32,7 @@
#include "stored/acquire.h"
#include "stored/append.h"
#include "stored/fd_cmds.h"
#include "stored/jcr_private.h"
#include "stored/label.h"
#include "stored/spool.h"
#include "lib/bget_msg.h"
Expand Down Expand Up @@ -60,7 +61,7 @@ bool DoAppendData(JobControlRecord* jcr, BareosSocket* bs, const char* what)
int32_t n, file_index, stream, last_file_index, job_elapsed;
bool ok = true;
char buf1[100];
DeviceControlRecord* dcr = jcr->dcr;
DeviceControlRecord* dcr = jcr->impl_->dcr;
Device* dev;
POOLMEM* rec_data;
char ec[50];
Expand Down Expand Up @@ -362,11 +363,11 @@ bool SendAttrsToDir(JobControlRecord* jcr, DeviceRecord* rec)
rec->maskedStream == STREAM_UNIX_ATTRIBUTES_EX ||
rec->maskedStream == STREAM_RESTORE_OBJECT ||
CryptoDigestStreamType(rec->maskedStream) != CRYPTO_DIGEST_NONE) {
if (!jcr->no_attributes) {
if (!jcr->impl_->no_attributes) {
BareosSocket* dir = jcr->dir_bsock;
if (AreAttributesSpooled(jcr)) { dir->SetSpooling(); }
Dmsg0(850, "Send attributes to dir.\n");
if (!jcr->dcr->DirUpdateFileAttributes(rec)) {
if (!jcr->impl_->dcr->DirUpdateFileAttributes(rec)) {
Jmsg(jcr, M_FATAL, 0, _("Error updating file attributes. ERR=%s\n"),
dir->bstrerror());
dir->ClearSpooling();
Expand Down
7 changes: 4 additions & 3 deletions core/src/stored/authenticate.cc
Expand Up @@ -30,7 +30,7 @@
#include "include/bareos.h"
#include "stored/stored.h"
#include "stored/stored_globals.h"
#include "include/jcr.h"
#include "stored/jcr_private.h"
#include "lib/parse_conf.h"
#include "lib/bsock.h"
#include "lib/bnet_network_dump.h"
Expand Down Expand Up @@ -89,7 +89,7 @@ bool AuthenticateDirector(JobControlRecord* jcr)

UnbashSpaces(dirname);
director = (DirectorResource*)my_config->GetResWithName(R_DIRECTOR, dirname);
jcr->director = director;
jcr->impl_->director = director;

if (!director) {
Dmsg2(debuglevel, "Connection from unknown Director %s at %s rejected.\n",
Expand Down Expand Up @@ -161,7 +161,8 @@ bool AuthenticateWithStoragedaemon(JobControlRecord* jcr)
password.value = jcr->sd_auth_key;

if (!sd->AuthenticateOutboundConnection(
jcr, my_config->CreateOwnQualifiedNameForNetworkDump(), identity, password, me)) {
jcr, my_config->CreateOwnQualifiedNameForNetworkDump(), identity,
password, me)) {
Jmsg1(jcr, M_FATAL, 0,
_("Authorization problem: Two way security handshake failed with "
"Storage daemon at %s\n"),
Expand Down
27 changes: 14 additions & 13 deletions core/src/stored/bcopy.cc
Expand Up @@ -34,6 +34,7 @@
#include "lib/crypto_cache.h"
#include "stored/acquire.h"
#include "stored/butil.h"
#include "stored/jcr_private.h"
#include "stored/label.h"
#include "stored/mount.h"
#include "stored/read_record.h"
Expand Down Expand Up @@ -207,9 +208,9 @@ int main(int argc, char* argv[])
true); /* read device */
if (!in_jcr) { exit(1); }

in_jcr->ignore_label_errors = ignore_label_errors;
in_jcr->impl_->ignore_label_errors = ignore_label_errors;

in_dev = in_jcr->dcr->dev;
in_dev = in_jcr->impl_->dcr->dev;
if (!in_dev) { exit(1); }

/*
Expand All @@ -222,7 +223,7 @@ int main(int argc, char* argv[])
false); /* write device */
if (!out_jcr) { exit(1); }

out_dev = out_jcr->dcr->dev;
out_dev = out_jcr->impl_->dcr->dev;
if (!out_dev) { exit(1); }

Dmsg0(100, "About to acquire device for writing\n");
Expand All @@ -231,22 +232,22 @@ int main(int argc, char* argv[])
* For we must now acquire the device for writing
*/
out_dev->rLock(false);
if (!out_dev->open(out_jcr->dcr, OPEN_READ_WRITE)) {
if (!out_dev->open(out_jcr->impl_->dcr, OPEN_READ_WRITE)) {
Emsg1(M_FATAL, 0, _("dev open failed: %s\n"), out_dev->errmsg);
out_dev->Unlock();
exit(1);
}
out_dev->Unlock();
if (!AcquireDeviceForAppend(out_jcr->dcr)) {
if (!AcquireDeviceForAppend(out_jcr->impl_->dcr)) {
FreeJcr(in_jcr);
exit(1);
}
out_block = out_jcr->dcr->block;
out_block = out_jcr->impl_->dcr->block;

ok = ReadRecords(in_jcr->dcr, RecordCb, MountNextReadVolume);
ok = ReadRecords(in_jcr->impl_->dcr, RecordCb, MountNextReadVolume);

if (ok || out_dev->CanWrite()) {
if (!out_jcr->dcr->WriteBlockToDevice()) {
if (!out_jcr->impl_->dcr->WriteBlockToDevice()) {
Pmsg0(000, _("Write of last block failed.\n"));
}
}
Expand Down Expand Up @@ -305,18 +306,18 @@ static bool RecordCb(DeviceControlRecord* in_dcr, DeviceRecord* rec)
/* Skipping record, because does not match BootStrapRecord filter */
return true;
}
while (!WriteRecordToBlock(out_jcr->dcr, rec)) {
while (!WriteRecordToBlock(out_jcr->impl_->dcr, rec)) {
Dmsg2(150, "!WriteRecordToBlock data_len=%d rem=%d\n", rec->data_len,
rec->remainder);
if (!out_jcr->dcr->WriteBlockToDevice()) {
if (!out_jcr->impl_->dcr->WriteBlockToDevice()) {
Dmsg2(90, "Got WriteBlockToDev error on device %s: ERR=%s\n",
out_dev->print_name(), out_dev->bstrerror());
Jmsg(out_jcr, M_FATAL, 0, _("Cannot fixup device error. %s\n"),
out_dev->bstrerror());
return false;
}
}
if (!out_jcr->dcr->WriteBlockToDevice()) {
if (!out_jcr->impl_->dcr->WriteBlockToDevice()) {
Dmsg2(90, "Got WriteBlockToDev error on device %s: ERR=%s\n",
out_dev->print_name(), out_dev->bstrerror());
Jmsg(out_jcr, M_FATAL, 0, _("Cannot fixup device error. %s\n"),
Expand All @@ -341,10 +342,10 @@ static bool RecordCb(DeviceControlRecord* in_dcr, DeviceRecord* rec)
return true;
}
records++;
while (!WriteRecordToBlock(out_jcr->dcr, rec)) {
while (!WriteRecordToBlock(out_jcr->impl_->dcr, rec)) {
Dmsg2(150, "!WriteRecordToBlock data_len=%d rem=%d\n", rec->data_len,
rec->remainder);
if (!out_jcr->dcr->WriteBlockToDevice()) {
if (!out_jcr->impl_->dcr->WriteBlockToDevice()) {
Dmsg2(90, "Got WriteBlockToDev error on device %s: ERR=%s\n",
out_dev->print_name(), out_dev->bstrerror());
Jmsg(out_jcr, M_FATAL, 0, _("Cannot fixup device error. %s\n"),
Expand Down
7 changes: 4 additions & 3 deletions core/src/stored/bextract.cc
Expand Up @@ -34,6 +34,7 @@
#include "lib/crypto_cache.h"
#include "stored/acquire.h"
#include "stored/butil.h"
#include "stored/jcr_private.h"
#include "stored/mount.h"
#include "stored/read_record.h"
#include "findlib/find.h"
Expand Down Expand Up @@ -402,9 +403,9 @@ static void DoExtract(char* devname)
jcr = SetupJcr("bextract", devname, bsr, director, dcr, VolumeName,
true); /* read device */
if (!jcr) { exit(1); }
dev = jcr->read_dcr->dev;
dev = jcr->impl_->read_dcr->dev;
if (!dev) { exit(1); }
dcr = jcr->read_dcr;
dcr = jcr->impl_->read_dcr;

/*
* Make sure where directory exists and that it is a directory
Expand Down Expand Up @@ -453,7 +454,7 @@ static void DoExtract(char* devname)

CleanupCompression(jcr);

CleanDevice(jcr->dcr);
CleanDevice(jcr->impl_->dcr);
dev->term();
FreeDeviceControlRecord(dcr);
FreeJcr(jcr);
Expand Down

0 comments on commit 042d2cf

Please sign in to comment.