Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/bareos/bareos.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Rogge <andreas.rogge@bareos.com>2022-11-07 19:17:15 +0300
committerGitHub <noreply@github.com>2022-11-07 19:17:15 +0300
commit43dea814df71216651108f87f21f0116195a6b6c (patch)
treec6b1be8c1d3183dd42d4f2725f7b3bb2de7437b2
parent87d3420ea8e36da9244a097eddf2ebd329fd75d7 (diff)
parent392277507d57e6a70ba69551b1aa62f5306914bc (diff)
Merge pull request #1271
Prepare Bareos for an upgrade to the C++20 standard
-rw-r--r--CHANGELOG.md2
-rw-r--r--core/src/cats/sql_create.cc6
-rw-r--r--core/src/cats/sql_update.cc2
-rw-r--r--core/src/dird/admin.cc11
-rw-r--r--core/src/dird/archive.cc11
-rw-r--r--core/src/dird/backup.cc35
-rw-r--r--core/src/dird/bsr.cc2
-rw-r--r--core/src/dird/consolidate.cc11
-rw-r--r--core/src/dird/dir_plugins.cc8
-rw-r--r--core/src/dird/fd_cmds.cc22
-rw-r--r--core/src/dird/getmsg.cc6
-rw-r--r--core/src/dird/jcr_private.h30
-rw-r--r--core/src/dird/job.cc41
-rw-r--r--core/src/dird/jobq.cc22
-rw-r--r--core/src/dird/migrate.cc46
-rw-r--r--core/src/dird/msgchan.cc4
-rw-r--r--core/src/dird/ndmp_dma_backup_NDMP_BAREOS.cc6
-rw-r--r--core/src/dird/ndmp_dma_backup_NDMP_NATIVE.cc6
-rw-r--r--core/src/dird/ndmp_dma_backup_common.cc7
-rw-r--r--core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc15
-rw-r--r--core/src/dird/ndmp_dma_restore_NDMP_NATIVE.cc2
-rw-r--r--core/src/dird/restore.cc8
-rw-r--r--core/src/dird/storage.cc6
-rw-r--r--core/src/dird/ua_cmds.cc6
-rw-r--r--core/src/dird/ua_select.cc10
-rw-r--r--core/src/dird/ua_server.cc2
-rw-r--r--core/src/dird/ua_status.cc14
-rw-r--r--core/src/dird/vbackup.cc19
-rw-r--r--core/src/dird/verify.cc36
-rw-r--r--core/src/filed/backup.cc8
-rw-r--r--core/src/filed/compression.cc6
-rw-r--r--core/src/filed/dir_cmd.cc30
-rw-r--r--core/src/filed/estimate.cc2
-rw-r--r--core/src/filed/fd_plugins.cc4
-rw-r--r--core/src/filed/restore.cc8
-rw-r--r--core/src/filed/sd_cmds.cc4
-rw-r--r--core/src/filed/status.cc3
-rw-r--r--core/src/filed/verify.cc4
-rw-r--r--core/src/filed/verify_vol.cc12
-rw-r--r--core/src/include/jcr.h29
-rw-r--r--core/src/lib/bsock.cc6
-rw-r--r--core/src/lib/bsock.h38
-rw-r--r--core/src/lib/bsock_tcp.cc12
-rw-r--r--core/src/lib/compression.cc12
-rw-r--r--core/src/lib/connection_pool.h4
-rw-r--r--core/src/lib/jcr.cc37
-rw-r--r--core/src/lib/message.cc6
-rw-r--r--core/src/lib/recent_job_results_list.cc4
-rw-r--r--core/src/lib/runscript.cc25
-rw-r--r--core/src/lib/util.cc2
-rw-r--r--core/src/plugins/filed/python/CMakeLists.txt2
-rw-r--r--core/src/plugins/stored/autoxflate/autoxflate-sd.cc4
-rw-r--r--core/src/stored/ansi_label.cc49
-rw-r--r--core/src/stored/append.cc20
-rw-r--r--core/src/stored/autochanger.cc37
-rw-r--r--core/src/stored/bscan.cc10
-rw-r--r--core/src/stored/btape.cc8
-rw-r--r--core/src/stored/butil.cc2
-rw-r--r--core/src/stored/dev.h4
-rw-r--r--core/src/stored/device_control_record.h2
-rw-r--r--core/src/stored/dir_cmd.cc4
-rw-r--r--core/src/stored/fd_cmds.cc14
-rw-r--r--core/src/stored/job.cc6
-rw-r--r--core/src/stored/label.cc103
-rw-r--r--core/src/stored/mac.cc18
-rw-r--r--core/src/stored/ndmp_tape.cc12
-rw-r--r--core/src/stored/read.cc4
-rw-r--r--core/src/stored/reserve.cc2
-rw-r--r--core/src/stored/sd_cmds.cc10
-rw-r--r--core/src/stored/sd_plugins.cc4
-rw-r--r--core/src/stored/spool.cc36
-rw-r--r--core/src/stored/status.cc9
-rw-r--r--core/src/stored/stored.cc2
-rw-r--r--core/src/stored/vol_mgr.cc98
-rw-r--r--core/src/stored/vol_mgr.h28
-rw-r--r--core/src/tests/thread_list.cc3
-rw-r--r--core/src/tests/version_strings.cc17
77 files changed, 577 insertions, 583 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 23e030056..78f22bae1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -144,6 +144,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https:
- core and webui: adapt binary info messages to new wording [PR #1298]
- build: enable -Wextra warning level and apply required changes [PR #1261]
- lib: make foreach_res() reload-safe [PR #1279]
+- Prepare Bareos for an upgrade to the C++20 standard [PR #1271]
### Deprecated
- make_catalog_backup.pl is now a shell wrapper script which will be removed in version 23.
@@ -340,6 +341,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https:
[PR #1267]: https://github.com/bareos/bareos/pull/1267
[PR #1268]: https://github.com/bareos/bareos/pull/1268
[PR #1270]: https://github.com/bareos/bareos/pull/1270
+[PR #1271]: https://github.com/bareos/bareos/pull/1271
[PR #1275]: https://github.com/bareos/bareos/pull/1275
[PR #1277]: https://github.com/bareos/bareos/pull/1277
[PR #1278]: https://github.com/bareos/bareos/pull/1278
diff --git a/core/src/cats/sql_create.cc b/core/src/cats/sql_create.cc
index 90c836b49..dea5346e9 100644
--- a/core/src/cats/sql_create.cc
+++ b/core/src/cats/sql_create.cc
@@ -802,7 +802,7 @@ bool BareosDb::CreateFilesetRecord(JobControlRecord* jcr, FileSetDbRecord* fsr)
bool BareosDb::WriteBatchFileRecords(JobControlRecord* jcr)
{
bool retval = false;
- int JobStatus = jcr->JobStatus;
+ int JobStatus = jcr->getJobStatus();
if (!jcr->batch_started) { /* no files to backup ? */
Dmsg0(50, "db_create_file_record : no files\n");
@@ -811,7 +811,7 @@ bool BareosDb::WriteBatchFileRecords(JobControlRecord* jcr)
Dmsg1(50, "db_create_file_record changes=%u\n", changes);
- jcr->JobStatus = JS_AttrInserting;
+ jcr->setJobStatus(JS_AttrInserting);
Jmsg(jcr, M_INFO, 0,
"Insert of attributes batch table with %u entries start\n",
@@ -850,7 +850,7 @@ bool BareosDb::WriteBatchFileRecords(JobControlRecord* jcr)
}
/* clang-format on */
- jcr->JobStatus = JobStatus; /* reset entry status */
+ jcr->setJobStatus(JobStatus); /* reset entry status */
Jmsg(jcr, M_INFO, 0, "Insert of attributes batch table done\n");
retval = true;
diff --git a/core/src/cats/sql_update.cc b/core/src/cats/sql_update.cc
index 55f558a7d..df1826a6c 100644
--- a/core/src/cats/sql_update.cc
+++ b/core/src/cats/sql_update.cc
@@ -102,7 +102,7 @@ bool BareosDb::UpdateJobStartRecord(JobControlRecord* jcr, JobDbRecord* jr)
"UPDATE Job SET JobStatus='%c',Level='%c',StartTime='%s',"
"ClientId=%s,JobTDate=%s,PoolId=%s,FileSetId=%s,VolSessionId=%lu,"
"VolSessionTime=%lu WHERE JobId=%s",
- (char)(jcr->JobStatus), (char)(jr->JobLevel), dt,
+ (char)(jcr->getJobStatus()), (char)(jr->JobLevel), dt,
edit_int64(jr->ClientId, ed1), edit_uint64(JobTDate, ed2),
edit_int64(jr->PoolId, ed3), edit_int64(jr->FileSetId, ed4),
jcr->VolSessionId, jcr->VolSessionTime, edit_int64(jr->JobId, ed5));
diff --git a/core/src/dird/admin.cc b/core/src/dird/admin.cc
index ce71d9db7..d51e60a36 100644
--- a/core/src/dird/admin.cc
+++ b/core/src/dird/admin.cc
@@ -2,7 +2,7 @@
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2003-2012 Free Software Foundation Europe e.V.
- Copyright (C) 2016-2020 Bareos GmbH & Co. KG
+ Copyright (C) 2016-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
@@ -59,7 +59,7 @@ bool do_admin(JobControlRecord* jcr)
Jmsg(jcr, M_INFO, 0, _("Start Admin JobId %d, Job=%s\n"), jcr->JobId,
jcr->Job);
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
AdminCleanup(jcr, JS_Terminated);
return true;
@@ -80,11 +80,11 @@ void AdminCleanup(JobControlRecord* jcr, int TermCode)
Jmsg(jcr, M_WARNING, 0,
_("Error getting Job record for Job report: ERR=%s\n"),
jcr->db->strerror());
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
}
msg_type = M_INFO; /* by default INFO message */
- switch (jcr->JobStatus) {
+ switch (jcr->getJobStatus()) {
case JS_Terminated:
TermMsg = _("Admin OK");
break;
@@ -98,7 +98,8 @@ void AdminCleanup(JobControlRecord* jcr, int TermCode)
break;
default:
TermMsg = term_code;
- sprintf(term_code, _("Inappropriate term code: %c\n"), jcr->JobStatus);
+ sprintf(term_code, _("Inappropriate term code: %c\n"),
+ jcr->getJobStatus());
break;
}
bstrftimes(schedt, sizeof(schedt), jcr->impl->jr.SchedTime);
diff --git a/core/src/dird/archive.cc b/core/src/dird/archive.cc
index 44d957767..dad5ac6ab 100644
--- a/core/src/dird/archive.cc
+++ b/core/src/dird/archive.cc
@@ -1,7 +1,7 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
- Copyright (C) 2016-2020 Bareos GmbH & Co. KG
+ Copyright (C) 2016-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
@@ -58,7 +58,7 @@ bool DoArchive(JobControlRecord* jcr)
Jmsg(jcr, M_INFO, 0, _("Start Archive JobId %d, Job=%s\n"), jcr->JobId,
jcr->Job);
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
ArchiveCleanup(jcr, JS_Terminated);
return true;
@@ -79,11 +79,11 @@ void ArchiveCleanup(JobControlRecord* jcr, int TermCode)
Jmsg(jcr, M_WARNING, 0,
_("Error getting Job record for Job report: ERR=%s\n"),
jcr->db->strerror());
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
}
msg_type = M_INFO; /* by default INFO message */
- switch (jcr->JobStatus) {
+ switch (jcr->getJobStatus()) {
case JS_Terminated:
TermMsg = _("Archive OK");
break;
@@ -97,7 +97,8 @@ void ArchiveCleanup(JobControlRecord* jcr, int TermCode)
break;
default:
TermMsg = term_code;
- sprintf(term_code, _("Inappropriate term code: %c\n"), jcr->JobStatus);
+ sprintf(term_code, _("Inappropriate term code: %c\n"),
+ jcr->getJobStatus());
break;
}
diff --git a/core/src/dird/backup.cc b/core/src/dird/backup.cc
index 07a57ab6d..8ab09913a 100644
--- a/core/src/dird/backup.cc
+++ b/core/src/dird/backup.cc
@@ -385,7 +385,7 @@ bool DoNativeBackup(JobControlRecord* jcr)
Jmsg(jcr, M_INFO, 0, _("Start Backup JobId %s, Job=%s\n"),
edit_uint64(jcr->JobId, ed1), jcr->Job);
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
Dmsg2(100, "JobId=%d JobLevel=%c\n", jcr->impl->jr.JobId,
jcr->impl->jr.JobLevel);
if (!jcr->db->UpdateJobStartRecord(jcr, &jcr->impl->jr)) {
@@ -411,7 +411,7 @@ bool DoNativeBackup(JobControlRecord* jcr)
* will be contacting him for a backup session.
*/
Dmsg0(110, "Open connection with storage daemon\n");
- jcr->setJobStatus(JS_WaitSD);
+ jcr->setJobStatusWithPriorityCheck(JS_WaitSD);
if (!ConnectToStorageDaemon(jcr, 10, me->SDConnectTimeout, true)) {
return false;
@@ -446,7 +446,7 @@ bool DoNativeBackup(JobControlRecord* jcr)
Dmsg0(150, "Storage daemon connection OK\n");
}
- jcr->setJobStatus(JS_WaitFD);
+ jcr->setJobStatusWithPriorityCheck(JS_WaitFD);
if (!ConnectToFileDaemon(jcr, 10, me->FDConnectTimeout, true)) {
goto bail_out;
}
@@ -462,7 +462,7 @@ bool DoNativeBackup(JobControlRecord* jcr)
goto close_fd;
}
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
if (!SendLevelCommand(jcr)) { goto bail_out; }
@@ -616,7 +616,7 @@ close_fd:
}
bail_out:
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
WaitForJobTermination(jcr, me->FDConnectTimeout);
return false;
@@ -642,7 +642,7 @@ int WaitForJobTermination(JobControlRecord* jcr, int timeout)
int Encrypt = 0;
btimer_t* tid = NULL;
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
if (fd) {
if (timeout) {
@@ -656,8 +656,8 @@ int WaitForJobTermination(JobControlRecord* jcr, int timeout)
&ReadBytes, &JobBytes, &JobErrors, &VSS, &Encrypt)
== 7) {
fd_ok = true;
- jcr->setJobStatus(jcr->impl->FDJobStatus);
- Dmsg1(100, "FDStatus=%c\n", (char)jcr->JobStatus);
+ jcr->setJobStatusWithPriorityCheck(jcr->impl->FDJobStatus);
+ Dmsg1(100, "FDStatus=%c\n", (char)jcr->getJobStatus());
} else {
Jmsg(jcr, M_WARNING, 0, _("Unexpected Client Job message: %s\n"),
fd->msg);
@@ -683,11 +683,13 @@ int WaitForJobTermination(JobControlRecord* jcr, int timeout)
* the SD despool.
*/
Dmsg5(100, "cancel=%d fd_ok=%d FDJS=%d JS=%d SDJS=%d\n", jcr->IsCanceled(),
- fd_ok, jcr->impl->FDJobStatus, jcr->JobStatus, jcr->impl->SDJobStatus);
+ fd_ok, jcr->impl->FDJobStatus.load(), jcr->getJobStatus(),
+ jcr->impl->SDJobStatus.load());
if (jcr->IsCanceled()
|| (!jcr->impl->res.job->RescheduleIncompleteJobs && !fd_ok)) {
Dmsg4(100, "fd_ok=%d FDJS=%d JS=%d SDJS=%d\n", fd_ok,
- jcr->impl->FDJobStatus, jcr->JobStatus, jcr->impl->SDJobStatus);
+ jcr->impl->FDJobStatus.load(), jcr->getJobStatus(),
+ jcr->impl->SDJobStatus.load());
CancelStorageDaemonJob(jcr);
}
@@ -715,7 +717,7 @@ int WaitForJobTermination(JobControlRecord* jcr, int timeout)
if (!fd_ok || IsBnetError(fd)) { /* if fd not set, that use !fd_ok */
jcr->impl->FDJobStatus = JS_ErrorTerminated;
}
- if (jcr->JobStatus != JS_Terminated) { return jcr->JobStatus; }
+ if (jcr->getJobStatus() != JS_Terminated) { return jcr->getJobStatus(); }
if (jcr->impl->FDJobStatus != JS_Terminated) {
return jcr->impl->FDJobStatus;
}
@@ -743,7 +745,7 @@ void NativeBackupCleanup(JobControlRecord* jcr, int TermCode)
Jmsg(jcr, M_WARNING, 0,
_("Error getting Job record for Job report: ERR=%s\n"),
jcr->db->strerror());
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
}
bstrncpy(cr.Name, jcr->impl->res.client->resource_name_, sizeof(cr.Name));
@@ -755,7 +757,7 @@ void NativeBackupCleanup(JobControlRecord* jcr, int TermCode)
UpdateBootstrapFile(jcr);
- switch (jcr->JobStatus) {
+ switch (jcr->getJobStatus()) {
case JS_Terminated:
TermMsg = _("Backup OK");
break;
@@ -787,7 +789,8 @@ void NativeBackupCleanup(JobControlRecord* jcr, int TermCode)
break;
default:
TermMsg = term_code;
- sprintf(term_code, _("Inappropriate term code: %c\n"), jcr->JobStatus);
+ sprintf(term_code, _("Inappropriate term code: %c\n"),
+ jcr->getJobStatus());
break;
}
@@ -826,7 +829,7 @@ void UpdateBootstrapFile(JobControlRecord* jcr)
"update Bootstrap file. ERR=%s\n"),
jcr->db->strerror());
if (jcr->impl->SDJobFiles != 0) {
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
}
}
/* Start output with when and who wrote it */
@@ -867,7 +870,7 @@ void UpdateBootstrapFile(JobControlRecord* jcr)
_("Could not open WriteBootstrap file:\n"
"%s: ERR=%s\n"),
fname, be.bstrerror());
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
}
FreePoolMemory(fname);
}
diff --git a/core/src/dird/bsr.cc b/core/src/dird/bsr.cc
index a66c94d20..968f64aac 100644
--- a/core/src/dird/bsr.cc
+++ b/core/src/dird/bsr.cc
@@ -580,7 +580,7 @@ bool OpenBootstrapFile(JobControlRecord* jcr, bootstrap_info& info)
BErrNo be;
Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"),
jcr->RestoreBootstrap, be.bstrerror());
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return false;
}
diff --git a/core/src/dird/consolidate.cc b/core/src/dird/consolidate.cc
index eb91d833c..4fdedbb23 100644
--- a/core/src/dird/consolidate.cc
+++ b/core/src/dird/consolidate.cc
@@ -115,7 +115,7 @@ bool DoConsolidate(JobControlRecord* jcr)
Jmsg(jcr, M_INFO, 0, _("Start Consolidate JobId %d, Job=%s\n"), jcr->JobId,
jcr->Job);
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
foreach_res (job, R_JOB) {
if (job->AlwaysIncremental) {
@@ -319,7 +319,7 @@ bool DoConsolidate(JobControlRecord* jcr)
bail_out:
// Restore original job back to jcr.
jcr->impl->res.job = tmpjob;
- jcr->setJobStatus(JS_Terminated);
+ jcr->setJobStatusWithPriorityCheck(JS_Terminated);
ConsolidateCleanup(jcr, JS_Terminated);
if (jobids) { free(jobids); }
@@ -343,11 +343,11 @@ void ConsolidateCleanup(JobControlRecord* jcr, int TermCode)
Jmsg(jcr, M_WARNING, 0,
_("Error getting Job record for Job report: ERR=%s\n"),
jcr->db->strerror());
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
}
msg_type = M_INFO; /* by default INFO message */
- switch (jcr->JobStatus) {
+ switch (jcr->getJobStatus()) {
case JS_Terminated:
TermMsg = _("Consolidate OK");
break;
@@ -361,7 +361,8 @@ void ConsolidateCleanup(JobControlRecord* jcr, int TermCode)
break;
default:
TermMsg = term_code;
- sprintf(term_code, _("Inappropriate term code: %c\n"), jcr->JobStatus);
+ sprintf(term_code, _("Inappropriate term code: %c\n"),
+ jcr->getJobStatus());
break;
}
bstrftimes(schedt, sizeof(schedt), jcr->impl->jr.SchedTime);
diff --git a/core/src/dird/dir_plugins.cc b/core/src/dird/dir_plugins.cc
index 23ecbb092..183938919 100644
--- a/core/src/dird/dir_plugins.cc
+++ b/core/src/dird/dir_plugins.cc
@@ -642,9 +642,9 @@ static bRC bareosGetValue(PluginContext* ctx, brDirVariable var, void* value)
NPRT(*((char**)value)));
break;
case bDirVarJobStatus:
- *((int*)value) = jcr->JobStatus;
+ *((int*)value) = jcr->getJobStatus();
Dmsg1(debuglevel, "dir-plugin: return bDirVarJobStatus=%c\n",
- jcr->JobStatus);
+ jcr->getJobStatus());
break;
case bDirVarPriority:
*((int*)value) = jcr->JobPriority;
@@ -682,12 +682,12 @@ static bRC bareosGetValue(PluginContext* ctx, brDirVariable var, void* value)
case bDirVarFDJobStatus:
*((int*)value) = jcr->impl->FDJobStatus;
Dmsg1(debuglevel, "dir-plugin: return bDirVarFDJobStatus=%c\n",
- jcr->impl->FDJobStatus);
+ jcr->impl->FDJobStatus.load());
break;
case bDirVarSDJobStatus:
*((int*)value) = jcr->impl->SDJobStatus;
Dmsg1(debuglevel, "dir-plugin: return bDirVarSDJobStatus=%c\n",
- jcr->impl->SDJobStatus);
+ jcr->impl->SDJobStatus.load());
break;
case bDirVarLastRate:
*((int*)value) = jcr->LastRate;
diff --git a/core/src/dird/fd_cmds.cc b/core/src/dird/fd_cmds.cc
index a8d65cc78..422d3effa 100644
--- a/core/src/dird/fd_cmds.cc
+++ b/core/src/dird/fd_cmds.cc
@@ -145,7 +145,7 @@ static bool connect_outbound_to_file_daemon(JobControlRecord* jcr,
jcr->impl->res.client->FDport, verbose)) {
delete fd;
fd = NULL;
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
} else {
jcr->file_bsock = fd;
jcr->authenticated = false;
@@ -192,7 +192,7 @@ static void SendInfoSuccess(JobControlRecord* jcr, UaContext* ua)
std::string m;
if (jcr->impl->res.client->connection_successful_handshake_
== ClientConnectionHandshakeMode::kUndefined) {
- m += "\r\v";
+ m = "\r\v";
}
switch (jcr->impl->connection_handshake_try_) {
case ClientConnectionHandshakeMode::kTlsFirst:
@@ -274,7 +274,7 @@ bool ConnectToFileDaemon(JobControlRecord* jcr,
}
if (jcr->file_bsock) {
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
if (AuthenticateWithFileDaemon(jcr)) {
success = true;
SendInfoSuccess(jcr, ua);
@@ -294,7 +294,7 @@ bool ConnectToFileDaemon(JobControlRecord* jcr,
delete jcr->file_bsock;
jcr->file_bsock = nullptr;
}
- jcr->resetJobStatus(JS_Running);
+ jcr->setJobStatus(JS_Running);
jcr->impl->connection_handshake_try_
= ClientConnectionHandshakeMode::kCleartextFirst;
break;
@@ -317,7 +317,7 @@ bool ConnectToFileDaemon(JobControlRecord* jcr,
&& jcr->impl->connection_handshake_try_
!= ClientConnectionHandshakeMode::kFailed);
- if (!success) { jcr->setJobStatus(JS_ErrorTerminated); }
+ if (!success) { jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated); }
return success;
}
@@ -347,7 +347,7 @@ int SendJobInfoToFileDaemon(JobControlRecord* jcr)
storage = jcr->impl->res.read_storage;
} else {
Jmsg(jcr, M_FATAL, 0, _("No read or write storage defined\n"));
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return 0;
}
if (storage) {
@@ -379,7 +379,7 @@ int SendJobInfoToFileDaemon(JobControlRecord* jcr)
if (!bstrncmp(fd->msg, OKjob, strlen(OKjob))) {
Jmsg(jcr, M_FATAL, 0, _("File daemon \"%s\" rejected Job command: %s\n"),
jcr->impl->res.client->resource_name_, fd->msg);
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return 0;
} else if (jcr->db) {
ClientDbRecord cr;
@@ -397,7 +397,7 @@ int SendJobInfoToFileDaemon(JobControlRecord* jcr)
} else {
Jmsg(jcr, M_FATAL, 0, _("FD gave bad response to JobId command: %s\n"),
BnetStrerror(fd));
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return 0;
}
@@ -690,7 +690,7 @@ static bool SendFileset(JobControlRecord* jcr)
return true;
bail_out:
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return false;
}
@@ -1086,7 +1086,7 @@ int GetAttributesAndPutInCatalog(JobControlRecord* jcr)
_("<filed: bad attributes, expected 3 fields got %d\n"
"message_length=%d msg=%s\n"),
len, fd->message_length, fd->msg);
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return 0;
}
p = fd->msg;
@@ -1178,7 +1178,7 @@ int GetAttributesAndPutInCatalog(JobControlRecord* jcr)
jcr->cached_attribute = false;
}
- jcr->setJobStatus(JS_Terminated);
+ jcr->setJobStatusWithPriorityCheck(JS_Terminated);
return 1;
}
diff --git a/core/src/dird/getmsg.cc b/core/src/dird/getmsg.cc
index f4bfa8f96..a16f698c2 100644
--- a/core/src/dird/getmsg.cc
+++ b/core/src/dird/getmsg.cc
@@ -3,7 +3,7 @@
Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
- Copyright (C) 2013-2019 Bareos GmbH & Co. KG
+ Copyright (C) 2013-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
@@ -86,10 +86,10 @@ static void SetJcrSdJobStatus(JobControlRecord* jcr, int SDJobStatus)
// Some SD Job status setting are propagated to the controlling Job.
switch (jcr->impl->SDJobStatus) {
case JS_Incomplete:
- jcr->setJobStatus(JS_Incomplete);
+ jcr->setJobStatusWithPriorityCheck(JS_Incomplete);
break;
case JS_FatalError:
- jcr->setJobStatus(JS_FatalError);
+ jcr->setJobStatusWithPriorityCheck(JS_FatalError);
break;
default:
break;
diff --git a/core/src/dird/jcr_private.h b/core/src/dird/jcr_private.h
index 77511686e..00f22b50b 100644
--- a/core/src/dird/jcr_private.h
+++ b/core/src/dird/jcr_private.h
@@ -45,17 +45,19 @@ namespace storagedaemon {
struct BootStrapRecord;
} // namespace storagedaemon
-#define JobWaiting(jcr) \
- (jcr->job_started \
- && (jcr->JobStatus == JS_WaitFD || jcr->JobStatus == JS_WaitSD \
- || jcr->JobStatus == JS_WaitMedia || jcr->JobStatus == JS_WaitMount \
- || jcr->JobStatus == JS_WaitStoreRes || jcr->JobStatus == JS_WaitJobRes \
- || jcr->JobStatus == JS_WaitClientRes \
- || jcr->JobStatus == JS_WaitMaxJobs \
- || jcr->JobStatus == JS_WaitPriority \
- || jcr->impl->SDJobStatus == JS_WaitMedia \
- || jcr->impl->SDJobStatus == JS_WaitMount \
- || jcr->impl->SDJobStatus == JS_WaitDevice \
+#define JobWaiting(jcr) \
+ (jcr->job_started \
+ && (jcr->getJobStatus() == JS_WaitFD || jcr->getJobStatus() == JS_WaitSD \
+ || jcr->getJobStatus() == JS_WaitMedia \
+ || jcr->getJobStatus() == JS_WaitMount \
+ || jcr->getJobStatus() == JS_WaitStoreRes \
+ || jcr->getJobStatus() == JS_WaitJobRes \
+ || jcr->getJobStatus() == JS_WaitClientRes \
+ || jcr->getJobStatus() == JS_WaitMaxJobs \
+ || jcr->getJobStatus() == JS_WaitPriority \
+ || jcr->impl->SDJobStatus == JS_WaitMedia \
+ || jcr->impl->SDJobStatus == JS_WaitMount \
+ || jcr->impl->SDJobStatus == JS_WaitDevice \
|| jcr->impl->SDJobStatus == JS_WaitMaxJobs))
/* clang-format off */
@@ -111,8 +113,8 @@ struct JobControlRecordPrivate {
uint32_t SDJobFiles{}; /**< Number of files written, this job */
uint64_t SDJobBytes{}; /**< Number of bytes processed this job */
uint32_t SDErrors{}; /**< Number of non-fatal errors */
- volatile int32_t SDJobStatus{}; /**< Storage Job Status */
- volatile int32_t FDJobStatus{}; /**< File daemon Job Status */
+ std::atomic<int32_t> SDJobStatus{}; /**< Storage Job Status */
+ std::atomic<int32_t> FDJobStatus{}; /**< File daemon Job Status */
uint32_t DumpLevel{}; /**< Dump level when doing a NDMP backup */
uint32_t ExpectedFiles{}; /**< Expected restore files */
uint32_t MediaId{}; /**< DB record IDs associated with this job */
@@ -139,7 +141,7 @@ struct JobControlRecordPrivate {
int32_t reschedule_count{}; /**< Number of times rescheduled */
int32_t FDVersion{}; /**< File daemon version number */
int64_t spool_size{}; /**< Spool size for this job */
- volatile bool sd_msg_thread_done{}; /**< Set when Storage message thread done */
+ std::atomic<bool> sd_msg_thread_done{}; /**< Set when Storage message thread done */
bool IgnoreDuplicateJobChecking{}; /**< Set in migration jobs */
bool IgnoreLevelPoolOverrides{}; /**< Set if a cmdline pool was specified */
bool IgnoreClientConcurrency{}; /**< Set in migration jobs */
diff --git a/core/src/dird/job.cc b/core/src/dird/job.cc
index a317f873a..4114688b9 100644
--- a/core/src/dird/job.cc
+++ b/core/src/dird/job.cc
@@ -171,7 +171,7 @@ bool SetupJob(JobControlRecord* jcr, bool suppress_output)
jcr->impl->nextrun_ready_inited = true;
CreateUniqueJobName(jcr, jcr->impl->res.job->resource_name_);
- jcr->setJobStatus(JS_Created);
+ jcr->setJobStatusWithPriorityCheck(JS_Created);
jcr->unlock();
// Open database
@@ -364,7 +364,7 @@ bool SetupJob(JobControlRecord* jcr, bool suppress_output)
break;
default:
Pmsg1(0, _("Unimplemented job type: %d\n"), jcr->getJobType());
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
goto bail_out;
}
@@ -424,7 +424,7 @@ bool UseWaitingClient(JobControlRecord* jcr, int timeout)
void UpdateJobEnd(JobControlRecord* jcr, int TermCode)
{
DequeueMessages(jcr); /* display any queued messages */
- jcr->setJobStatus(TermCode);
+ jcr->setJobStatusWithPriorityCheck(TermCode);
UpdateJobEndRecord(jcr);
}
@@ -442,8 +442,9 @@ static void* job_thread(void* arg)
DetachIfNotDetached(pthread_self());
Dmsg0(200, "=====Start Job=========\n");
- jcr->setJobStatus(JS_Running); /* this will be set only if no error */
- jcr->start_time = time(NULL); /* set the real start time */
+ jcr->setJobStatusWithPriorityCheck(
+ JS_Running); /* this will be set only if no error */
+ jcr->start_time = time(NULL); /* set the real start time */
jcr->impl->jr.StartTime = jcr->start_time;
// Let the statistics subsystem know a new Job was started.
@@ -452,13 +453,13 @@ static void* job_thread(void* arg)
if (jcr->impl->res.job->MaxStartDelay != 0
&& jcr->impl->res.job->MaxStartDelay
< (utime_t)(jcr->start_time - jcr->sched_time)) {
- jcr->setJobStatus(JS_Canceled);
+ jcr->setJobStatusWithPriorityCheck(JS_Canceled);
Jmsg(jcr, M_FATAL, 0,
_("Job canceled because max start delay time exceeded.\n"));
}
if (JobCheckMaxrunschedtime(jcr)) {
- jcr->setJobStatus(JS_Canceled);
+ jcr->setJobStatusWithPriorityCheck(JS_Canceled);
Jmsg(jcr, M_FATAL, 0,
_("Job canceled because max run sched time exceeded.\n"));
}
@@ -648,7 +649,7 @@ static void* job_thread(void* arg)
if (jcr->msg_queue && jcr->msg_queue->size() > 0) { DequeueMessages(jcr); }
GeneratePluginEvent(jcr, bDirEventJobEnd);
- Dmsg1(50, "======== End Job stat=%c ==========\n", jcr->JobStatus);
+ Dmsg1(50, "======== End Job stat=%c ==========\n", jcr->getJobStatus());
return NULL;
}
@@ -674,9 +675,9 @@ void SdMsgThreadSendSignal(JobControlRecord* jcr, int sig)
bool CancelJob(UaContext* ua, JobControlRecord* jcr)
{
char ed1[50];
- int32_t old_status = jcr->JobStatus;
+ int32_t old_status = jcr->getJobStatus();
- jcr->setJobStatus(JS_Canceled);
+ jcr->setJobStatusWithPriorityCheck(JS_Canceled);
switch (old_status) {
case JS_Created:
@@ -740,17 +741,17 @@ static void JobMonitorWatchdog(watchdog_t* self)
/* check MaxWaitTime */
if (JobCheckMaxwaittime(jcr)) {
- jcr->setJobStatus(JS_Canceled);
+ jcr->setJobStatusWithPriorityCheck(JS_Canceled);
Qmsg(jcr, M_FATAL, 0, _("Max wait time exceeded. Job canceled.\n"));
cancel = true;
/* check MaxRunTime */
} else if (JobCheckMaxruntime(jcr)) {
- jcr->setJobStatus(JS_Canceled);
+ jcr->setJobStatusWithPriorityCheck(JS_Canceled);
Qmsg(jcr, M_FATAL, 0, _("Max run time exceeded. Job canceled.\n"));
cancel = true;
/* check MaxRunSchedTime */
} else if (JobCheckMaxrunschedtime(jcr)) {
- jcr->setJobStatus(JS_Canceled);
+ jcr->setJobStatusWithPriorityCheck(JS_Canceled);
Qmsg(jcr, M_FATAL, 0, _("Max run sched time exceeded. Job canceled.\n"));
cancel = true;
}
@@ -943,7 +944,7 @@ bool AllowDuplicateJob(JobControlRecord* jcr)
// cancel_dup will be done below
if (cancel_me) {
/* Zap current job */
- jcr->setJobStatus(JS_Canceled);
+ jcr->setJobStatusWithPriorityCheck(JS_Canceled);
Jmsg(jcr, M_FATAL, 0,
_("JobId %d already running. Duplicate job not allowed.\n"),
djcr->JobId);
@@ -956,7 +957,7 @@ bool AllowDuplicateJob(JobControlRecord* jcr)
* If CancelQueuedDuplicates is set do so only if job is queued.
*/
if (job->CancelQueuedDuplicates) {
- switch (djcr->JobStatus) {
+ switch (djcr->getJobStatus()) {
case JS_Created:
case JS_WaitJobRes:
case JS_WaitClientRes:
@@ -978,13 +979,13 @@ bool AllowDuplicateJob(JobControlRecord* jcr)
djcr->JobId);
CancelJob(ua, djcr);
Bmicrosleep(0, 500000);
- djcr->setJobStatus(JS_Canceled);
+ djcr->setJobStatusWithPriorityCheck(JS_Canceled);
CancelJob(ua, djcr);
FreeUaContext(ua);
Dmsg2(800, "Cancel dup %p JobId=%d\n", djcr, djcr->JobId);
} else {
// Zap current job
- jcr->setJobStatus(JS_Canceled);
+ jcr->setJobStatusWithPriorityCheck(JS_Canceled);
Jmsg(jcr, M_FATAL, 0,
_("JobId %d already running. Duplicate job not allowed.\n"),
djcr->JobId);
@@ -1398,7 +1399,7 @@ void InitJcrJobRecord(JobControlRecord* jcr)
jcr->impl->jr.EndTime = 0; /* perhaps rescheduled, clear it */
jcr->impl->jr.JobType = jcr->getJobType();
jcr->impl->jr.JobLevel = jcr->getJobLevel();
- jcr->impl->jr.JobStatus = jcr->JobStatus;
+ jcr->impl->jr.JobStatus = jcr->getJobStatus();
jcr->impl->jr.JobId = jcr->JobId;
jcr->impl->jr.JobSumTotalBytes = 18446744073709551615LLU;
bstrncpy(jcr->impl->jr.Name, jcr->impl->res.job->resource_name_,
@@ -1412,7 +1413,7 @@ void UpdateJobEndRecord(JobControlRecord* jcr)
jcr->impl->jr.EndTime = time(NULL);
jcr->end_time = jcr->impl->jr.EndTime;
jcr->impl->jr.JobId = jcr->JobId;
- jcr->impl->jr.JobStatus = jcr->JobStatus;
+ jcr->impl->jr.JobStatus = jcr->getJobStatus();
jcr->impl->jr.JobFiles = jcr->JobFiles;
jcr->impl->jr.JobBytes = jcr->JobBytes;
jcr->impl->jr.ReadBytes = jcr->ReadBytes;
@@ -1635,7 +1636,7 @@ void SetJcrDefaults(JobControlRecord* jcr, JobResource* job)
jcr->impl->res.job = job;
jcr->setJobType(job->JobType);
jcr->setJobProtocol(job->Protocol);
- jcr->JobStatus = JS_Created;
+ jcr->setJobStatus(JS_Created);
switch (jcr->getJobType()) {
case JT_ADMIN:
diff --git a/core/src/dird/jobq.cc b/core/src/dird/jobq.cc
index 5d1bd8c17..8c4281ab3 100644
--- a/core/src/dird/jobq.cc
+++ b/core/src/dird/jobq.cc
@@ -167,7 +167,7 @@ extern "C" void* sched_wait(void* arg)
Dmsg0(2300, "Enter sched_wait.\n");
free(arg);
time_t wtime = jcr->sched_time - time(NULL);
- jcr->setJobStatus(JS_WaitStartTime);
+ jcr->setJobStatusWithPriorityCheck(JS_WaitStartTime);
// Wait until scheduled time arrives
if (wtime > 0) {
@@ -421,7 +421,7 @@ extern "C" void* jobq_server(void* arg)
// Call user's routine here
Dmsg3(2300, "Calling user engine for jobid=%d use=%d stat=%c\n",
- jcr->JobId, jcr->UseCount(), jcr->JobStatus);
+ jcr->JobId, jcr->UseCount(), jcr->getJobStatus());
jq->engine(je->jcr);
// Job finished detach from thread
@@ -509,7 +509,7 @@ extern "C" void* jobq_server(void* arg)
|| (jcr->JobPriority < Priority
&& jcr->impl->res.job->allow_mixed_priority
&& running_allow_mix))) {
- jcr->setJobStatus(JS_WaitPriority);
+ jcr->setJobStatusWithPriorityCheck(JS_WaitPriority);
break;
}
@@ -625,7 +625,7 @@ static bool RescheduleJob(JobControlRecord* jcr, jobq_t* jq, jobq_item_t* je)
_("Rescheduled Job %s at %s to re-run in %d seconds (%s).\n"),
jcr->Job, dt, (int)jcr->impl->res.job->RescheduleInterval, dt2);
DirdFreeJcrPointers(jcr); /* partial cleanup old stuff */
- jcr->JobStatus = -1;
+ jcr->setJobStatus(-1);
jcr->impl->SDJobStatus = 0;
jcr->JobErrors = 0;
if (!AllowDuplicateJob(jcr)) { return false; }
@@ -653,7 +653,7 @@ static bool RescheduleJob(JobControlRecord* jcr, jobq_t* jq, jobq_item_t* je)
* conflicts. We now create a new job, copying the
* appropriate fields.
*/
- jcr->setJobStatus(JS_WaitStartTime);
+ jcr->setJobStatusWithPriorityCheck(JS_WaitStartTime);
njcr = NewDirectorJcr(DirdFreeJcr);
SetJcrDefaults(njcr, jcr->impl->res.job);
njcr->impl->reschedule_count = jcr->impl->reschedule_count;
@@ -675,8 +675,8 @@ static bool RescheduleJob(JobControlRecord* jcr, jobq_t* jq, jobq_item_t* je)
njcr->impl->res.next_pool = jcr->impl->res.next_pool;
njcr->impl->res.run_next_pool_override
= jcr->impl->res.run_next_pool_override;
- njcr->JobStatus = -1;
- njcr->setJobStatus(jcr->JobStatus);
+ njcr->setJobStatus(-1);
+ njcr->setJobStatusWithPriorityCheck(jcr->getJobStatus());
if (jcr->impl->res.read_storage) {
CopyRstorage(njcr, jcr->impl->res.read_storage_list, _("previous Job"));
} else {
@@ -747,7 +747,7 @@ static bool AcquireResources(JobControlRecord* jcr)
if (jcr->impl->res.read_storage) {
if (!IncReadStore(jcr)) {
- jcr->setJobStatus(JS_WaitStoreRes);
+ jcr->setJobStatusWithPriorityCheck(JS_WaitStoreRes);
return false;
}
@@ -756,7 +756,7 @@ static bool AcquireResources(JobControlRecord* jcr)
if (jcr->impl->res.write_storage) {
if (!IncWriteStore(jcr)) {
DecReadStore(jcr);
- jcr->setJobStatus(JS_WaitStoreRes);
+ jcr->setJobStatusWithPriorityCheck(JS_WaitStoreRes);
return false;
}
@@ -766,7 +766,7 @@ static bool AcquireResources(JobControlRecord* jcr)
// Back out previous locks
DecWriteStore(jcr);
DecReadStore(jcr);
- jcr->setJobStatus(JS_WaitClientRes);
+ jcr->setJobStatusWithPriorityCheck(JS_WaitClientRes);
return false;
}
@@ -776,7 +776,7 @@ static bool AcquireResources(JobControlRecord* jcr)
DecWriteStore(jcr);
DecReadStore(jcr);
DecClientConcurrency(jcr);
- jcr->setJobStatus(JS_WaitJobRes);
+ jcr->setJobStatusWithPriorityCheck(JS_WaitJobRes);
return false;
}
diff --git a/core/src/dird/migrate.cc b/core/src/dird/migrate.cc
index 1b52f183f..8280e7c48 100644
--- a/core/src/dird/migrate.cc
+++ b/core/src/dird/migrate.cc
@@ -1047,7 +1047,7 @@ bool DoMigrationInit(JobControlRecord* jcr)
}
if (jcr->impl->previous_jr.JobId == 0 || jcr->impl->ExpectedFiles == 0) {
- jcr->setJobStatus(JS_Terminated);
+ jcr->setJobStatusWithPriorityCheck(JS_Terminated);
Dmsg1(dbglevel, "JobId=%d expected files == 0\n", (int)jcr->JobId);
if (jcr->impl->previous_jr.JobId == 0) {
Jmsg(jcr, M_INFO, 0, _("No previous Job found to %s.\n"),
@@ -1242,8 +1242,8 @@ static inline bool DoActualMigration(JobControlRecord* jcr)
_("JobId %s already %s probably by another Job. %s stopped.\n"),
edit_int64(jcr->impl->previous_jr.JobId, ed1),
jcr->get_ActionName(true), jcr->get_OperationName());
- jcr->setJobStatus(JS_Terminated);
- MigrationCleanup(jcr, jcr->JobStatus);
+ jcr->setJobStatusWithPriorityCheck(JS_Terminated);
+ MigrationCleanup(jcr, jcr->getJobStatus());
return true;
}
@@ -1252,8 +1252,8 @@ static inline bool DoActualMigration(JobControlRecord* jcr)
_("JobId %s cannot %s using the same read and write storage.\n"),
edit_int64(jcr->impl->previous_jr.JobId, ed1),
jcr->get_OperationName());
- jcr->setJobStatus(JS_Terminated);
- MigrationCleanup(jcr, jcr->JobStatus);
+ jcr->setJobStatusWithPriorityCheck(JS_Terminated);
+ MigrationCleanup(jcr, jcr->getJobStatus());
return true;
}
@@ -1308,7 +1308,7 @@ static inline bool DoActualMigration(JobControlRecord* jcr)
jcr->impl->res.write_storage_list = write_storage_list;
// Start conversation with Reading Storage daemon
- jcr->setJobStatus(JS_WaitSD);
+ jcr->setJobStatusWithPriorityCheck(JS_WaitSD);
if (!ConnectToStorageDaemon(jcr, 10, me->SDConnectTimeout, true)) {
goto bail_out;
}
@@ -1317,7 +1317,7 @@ static inline bool DoActualMigration(JobControlRecord* jcr)
Dmsg0(110, "Open connection with writing storage daemon\n");
// Start conversation with Writing Storage daemon
- mig_jcr->setJobStatus(JS_WaitSD);
+ mig_jcr->setJobStatusWithPriorityCheck(JS_WaitSD);
if (!ConnectToStorageDaemon(mig_jcr, 10, me->SDConnectTimeout, true)) {
goto bail_out;
}
@@ -1344,8 +1344,8 @@ static inline bool DoActualMigration(JobControlRecord* jcr)
// Open a message channel connection with the Storage daemon.
Dmsg0(110, "Open connection with storage daemon\n");
- jcr->setJobStatus(JS_WaitSD);
- mig_jcr->setJobStatus(JS_WaitSD);
+ jcr->setJobStatusWithPriorityCheck(JS_WaitSD);
+ mig_jcr->setJobStatusWithPriorityCheck(JS_WaitSD);
// Start conversation with Storage daemon
if (!ConnectToStorageDaemon(jcr, 10, me->SDConnectTimeout, true)) {
@@ -1377,7 +1377,7 @@ static inline bool DoActualMigration(JobControlRecord* jcr)
jcr->start_time = time(NULL);
jcr->impl->jr.StartTime = jcr->start_time;
jcr->impl->jr.JobTDate = jcr->start_time;
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
// Update job start record for this migration control job
if (!jcr->db->UpdateJobStartRecord(jcr, &jcr->impl->jr)) {
@@ -1391,7 +1391,7 @@ static inline bool DoActualMigration(JobControlRecord* jcr)
mig_jcr->start_time = time(NULL);
mig_jcr->impl->jr.StartTime = mig_jcr->start_time;
mig_jcr->impl->jr.JobTDate = mig_jcr->start_time;
- mig_jcr->setJobStatus(JS_Running);
+ mig_jcr->setJobStatusWithPriorityCheck(JS_Running);
// Update job start record for the real migration backup job
if (!mig_jcr->db->UpdateJobStartRecord(mig_jcr, &mig_jcr->impl->jr)) {
@@ -1455,8 +1455,8 @@ static inline bool DoActualMigration(JobControlRecord* jcr)
// Now start a Storage daemon message thread
if (!StartStorageDaemonMessageThread(jcr)) { goto bail_out; }
- jcr->setJobStatus(JS_Running);
- mig_jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
+ mig_jcr->setJobStatusWithPriorityCheck(JS_Running);
/*
* Pickup Job termination data
@@ -1467,13 +1467,13 @@ static inline bool DoActualMigration(JobControlRecord* jcr)
if (jcr->impl->remote_replicate) {
WaitForStorageDaemonTermination(jcr);
WaitForStorageDaemonTermination(mig_jcr);
- jcr->setJobStatus(jcr->impl->SDJobStatus);
+ jcr->setJobStatusWithPriorityCheck(jcr->impl->SDJobStatus);
if (mig_jcr->batch_started) {
mig_jcr->db_batch->WriteBatchFileRecords(mig_jcr);
}
} else {
WaitForStorageDaemonTermination(jcr);
- jcr->setJobStatus(jcr->impl->SDJobStatus);
+ jcr->setJobStatusWithPriorityCheck(jcr->impl->SDJobStatus);
if (jcr->batch_started) { jcr->db_batch->WriteBatchFileRecords(jcr); }
}
@@ -1501,7 +1501,7 @@ bail_out:
FreePairedStorage(jcr);
if (jcr->is_JobStatus(JS_Terminated)) {
- MigrationCleanup(jcr, jcr->JobStatus);
+ MigrationCleanup(jcr, jcr->getJobStatus());
retval = true;
}
@@ -1515,10 +1515,10 @@ static inline bool DoMigrationSelection(JobControlRecord* jcr)
retval = getJobs_to_migrate(jcr);
if (retval) {
- jcr->setJobStatus(JS_Terminated);
- MigrationCleanup(jcr, jcr->JobStatus);
+ jcr->setJobStatusWithPriorityCheck(JS_Terminated);
+ MigrationCleanup(jcr, jcr->getJobStatus());
} else {
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
}
return retval;
@@ -1817,7 +1817,7 @@ void MigrationCleanup(JobControlRecord* jcr, int TermCode)
Jmsg(jcr, M_WARNING, 0,
_("Error getting Job record for Job report: ERR=%s\n"),
jcr->db->strerror());
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
}
UpdateBootstrapFile(mig_jcr);
@@ -1852,7 +1852,7 @@ void MigrationCleanup(JobControlRecord* jcr, int TermCode)
}
}
- switch (jcr->JobStatus) {
+ switch (jcr->getJobStatus()) {
case JS_Terminated:
TermMsg = _("%s OK");
break;
@@ -1868,7 +1868,7 @@ void MigrationCleanup(JobControlRecord* jcr, int TermCode)
* can be different so that is why we do a second switch inside the
* switch on the JobStatus.
*/
- switch (jcr->JobStatus) {
+ switch (jcr->getJobStatus()) {
case JS_Canceled:
TermMsg = _("%s Canceled");
break;
@@ -1902,7 +1902,7 @@ void MigrationCleanup(JobControlRecord* jcr, int TermCode)
Mmsg(query, "DELETE FROM job WHERE JobId=%d", jcr->JobId);
jcr->db->SqlQuery(query.c_str());
- switch (jcr->JobStatus) {
+ switch (jcr->getJobStatus()) {
case JS_Terminated:
TermMsg = _("%s OK");
break;
diff --git a/core/src/dird/msgchan.cc b/core/src/dird/msgchan.cc
index 0473466b4..eea3cbd3f 100644
--- a/core/src/dird/msgchan.cc
+++ b/core/src/dird/msgchan.cc
@@ -103,7 +103,7 @@ static inline bool SendBootstrapFileToSd(JobControlRecord* jcr,
BErrNo be;
Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"),
jcr->RestoreBootstrap, be.bstrerror());
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return false;
}
sd->fsend(bootstrap);
@@ -492,7 +492,7 @@ void WaitForStorageDaemonTermination(JobControlRecord* jcr)
/* Give SD 30 seconds to clean up after cancel */
if (cancel_count == 6) { break; }
}
- jcr->setJobStatus(JS_Terminated);
+ jcr->setJobStatusWithPriorityCheck(JS_Terminated);
}
} /* namespace directordaemon */
diff --git a/core/src/dird/ndmp_dma_backup_NDMP_BAREOS.cc b/core/src/dird/ndmp_dma_backup_NDMP_BAREOS.cc
index a4d614770..4ea73026d 100644
--- a/core/src/dird/ndmp_dma_backup_NDMP_BAREOS.cc
+++ b/core/src/dird/ndmp_dma_backup_NDMP_BAREOS.cc
@@ -184,7 +184,7 @@ bool DoNdmpBackup(JobControlRecord* jcr)
Jmsg(jcr, M_INFO, 0, _("Start NDMP Backup JobId %s, Job=%s\n"),
edit_uint64(jcr->JobId, ed1), jcr->Job);
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
Dmsg2(100, "JobId=%d JobLevel=%c\n", jcr->impl->jr.JobId,
jcr->impl->jr.JobLevel);
if (!jcr->db->UpdateJobStartRecord(jcr, &jcr->impl->jr)) {
@@ -215,7 +215,7 @@ bool DoNdmpBackup(JobControlRecord* jcr)
if (jcr->impl->res.write_storage->paired_storage) {
SetPairedStorage(jcr);
- jcr->setJobStatus(JS_WaitSD);
+ jcr->setJobStatusWithPriorityCheck(JS_WaitSD);
if (!ConnectToStorageDaemon(jcr, 10, me->SDConnectTimeout, true)) {
return false;
}
@@ -447,7 +447,7 @@ cleanup:
bail_out:
// Error handling of failed Job.
status = JS_ErrorTerminated;
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
if (jcr->store_bsock) {
CancelStorageDaemonJob(jcr);
diff --git a/core/src/dird/ndmp_dma_backup_NDMP_NATIVE.cc b/core/src/dird/ndmp_dma_backup_NDMP_NATIVE.cc
index 71b8cfc30..98aa86f71 100644
--- a/core/src/dird/ndmp_dma_backup_NDMP_NATIVE.cc
+++ b/core/src/dird/ndmp_dma_backup_NDMP_NATIVE.cc
@@ -2,7 +2,7 @@
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2011-2015 Planets Communications B.V.
- Copyright (C) 2013-2019 Bareos GmbH & Co. KG
+ Copyright (C) 2013-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
@@ -186,7 +186,7 @@ bool DoNdmpBackupNdmpNative(JobControlRecord* jcr)
Jmsg(jcr, M_INFO, 0, _("Start NDMP Backup JobId %s, Job=%s\n"),
edit_uint64(jcr->JobId, ed1), jcr->Job);
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
Dmsg2(100, "JobId=%d JobLevel=%c\n", jcr->impl->jr.JobId,
jcr->impl->jr.JobLevel);
if (!jcr->db->UpdateJobStartRecord(jcr, &jcr->impl->jr)) {
@@ -401,7 +401,7 @@ cleanup:
bail_out:
// Error handling of failed Job.
status = JS_ErrorTerminated;
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
ok_out:
if (nis) {
diff --git a/core/src/dird/ndmp_dma_backup_common.cc b/core/src/dird/ndmp_dma_backup_common.cc
index efe385d0e..3d43e1f94 100644
--- a/core/src/dird/ndmp_dma_backup_common.cc
+++ b/core/src/dird/ndmp_dma_backup_common.cc
@@ -281,7 +281,7 @@ void NdmpBackupCleanup(JobControlRecord* jcr, int TermCode)
Jmsg(jcr, M_WARNING, 0,
_("Error getting Job record for Job report: ERR=%s"),
jcr->db->strerror());
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
}
bstrncpy(cr.Name, jcr->impl->res.client->resource_name_, sizeof(cr.Name));
@@ -293,7 +293,7 @@ void NdmpBackupCleanup(JobControlRecord* jcr, int TermCode)
UpdateBootstrapFile(jcr);
- switch (jcr->JobStatus) {
+ switch (jcr->getJobStatus()) {
case JS_Terminated:
TermMsg = _("Backup OK");
break;
@@ -322,7 +322,8 @@ void NdmpBackupCleanup(JobControlRecord* jcr, int TermCode)
break;
default:
TermMsg = term_code;
- sprintf(term_code, _("Inappropriate term code: %c\n"), jcr->JobStatus);
+ sprintf(term_code, _("Inappropriate term code: %c\n"),
+ jcr->getJobStatus());
break;
}
diff --git a/core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc b/core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc
index 141c7261f..6d1f2c44b 100644
--- a/core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc
+++ b/core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc
@@ -325,17 +325,18 @@ bool DoNdmpRestoreInit(JobControlRecord* jcr)
static inline int NdmpWaitForJobTermination(JobControlRecord* jcr)
{
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
/*
* Force cancel in SD if failing, but not for Incomplete jobs
* so that we let the SD despool.
*/
Dmsg4(100, "cancel=%d FDJS=%d JS=%d SDJS=%d\n", jcr->IsCanceled(),
- jcr->impl->FDJobStatus, jcr->JobStatus, jcr->impl->SDJobStatus);
+ jcr->impl->FDJobStatus.load(), jcr->getJobStatus(),
+ jcr->impl->SDJobStatus.load());
if (jcr->IsCanceled() || (!jcr->impl->res.job->RescheduleIncompleteJobs)) {
- Dmsg3(100, "FDJS=%d JS=%d SDJS=%d\n", jcr->impl->FDJobStatus,
- jcr->JobStatus, jcr->impl->SDJobStatus);
+ Dmsg3(100, "FDJS=%d JS=%d SDJS=%d\n", jcr->impl->FDJobStatus.load(),
+ jcr->getJobStatus(), jcr->impl->SDJobStatus.load());
CancelStorageDaemonJob(jcr);
}
@@ -343,7 +344,7 @@ static inline int NdmpWaitForJobTermination(JobControlRecord* jcr)
WaitForStorageDaemonTermination(jcr);
jcr->impl->FDJobStatus = JS_Terminated;
- if (jcr->JobStatus != JS_Terminated) { return jcr->JobStatus; }
+ if (jcr->getJobStatus() != JS_Terminated) { return jcr->getJobStatus(); }
if (jcr->impl->FDJobStatus != JS_Terminated) {
return jcr->impl->FDJobStatus;
}
@@ -428,7 +429,7 @@ static inline bool DoNdmpRestoreBootstrap(JobControlRecord* jcr)
*
*/
Dmsg0(10, "Open connection to storage daemon\n");
- jcr->setJobStatus(JS_WaitSD);
+ jcr->setJobStatusWithPriorityCheck(JS_WaitSD);
// Start conversation with Storage daemon
if (!ConnectToStorageDaemon(jcr, 10, me->SDConnectTimeout, true)) {
@@ -441,7 +442,7 @@ static inline bool DoNdmpRestoreBootstrap(JobControlRecord* jcr)
goto cleanup;
}
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
// Send the bootstrap file -- what Volumes/files to restore
if (!SendBootstrapFile(jcr, sd, info)
diff --git a/core/src/dird/ndmp_dma_restore_NDMP_NATIVE.cc b/core/src/dird/ndmp_dma_restore_NDMP_NATIVE.cc
index a2916f54d..023e12233 100644
--- a/core/src/dird/ndmp_dma_restore_NDMP_NATIVE.cc
+++ b/core/src/dird/ndmp_dma_restore_NDMP_NATIVE.cc
@@ -305,7 +305,7 @@ static bool DoNdmpNativeRestore(JobControlRecord* jcr)
ndmp_sess.dump_media_info = 1; // for debugging
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
// Initialize the session structure.
if (ndma_session_initialize(&ndmp_sess)) { goto cleanup_ndmp; }
diff --git a/core/src/dird/restore.cc b/core/src/dird/restore.cc
index f14bd02cb..bca1b0a45 100644
--- a/core/src/dird/restore.cc
+++ b/core/src/dird/restore.cc
@@ -3,7 +3,7 @@
Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
- Copyright (C) 2013-2021 Bareos GmbH & Co. KG
+ Copyright (C) 2013-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
@@ -153,7 +153,7 @@ static inline bool DoNativeRestoreBootstrap(JobControlRecord* jcr)
*
*/
Dmsg0(10, "Open connection with storage daemon\n");
- jcr->setJobStatus(JS_WaitSD);
+ jcr->setJobStatusWithPriorityCheck(JS_WaitSD);
// Start conversation with Storage daemon
if (!ConnectToStorageDaemon(jcr, 10, me->SDConnectTimeout, true)) {
@@ -168,7 +168,7 @@ static inline bool DoNativeRestoreBootstrap(JobControlRecord* jcr)
if (first_time) {
// Start conversation with File daemon
- jcr->setJobStatus(JS_WaitFD);
+ jcr->setJobStatusWithPriorityCheck(JS_WaitFD);
jcr->impl->keep_sd_auth_key = true; /* don't clear the sd_auth_key now */
if (!ConnectToFileDaemon(jcr, 10, me->FDConnectTimeout, true)) {
@@ -191,7 +191,7 @@ static inline bool DoNativeRestoreBootstrap(JobControlRecord* jcr)
}
}
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
// Send the bootstrap file -- what Volumes/files to restore
bool success = false;
diff --git a/core/src/dird/storage.cc b/core/src/dird/storage.cc
index 34038ed89..47b464957 100644
--- a/core/src/dird/storage.cc
+++ b/core/src/dird/storage.cc
@@ -480,7 +480,7 @@ bool SelectNextRstore(JobControlRecord* jcr, bootstrap_info& info)
R_STORAGE, info.storage))) {
Jmsg(jcr, M_FATAL, 0, _("Could not get storage resource '%s'.\n"),
info.storage);
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return false;
}
@@ -498,13 +498,13 @@ bool SelectNextRstore(JobControlRecord* jcr, bootstrap_info& info)
DecReadStore(jcr);
FreeRstorage(jcr);
SetRstorage(jcr, &ustore);
- jcr->setJobStatus(JS_WaitSD);
+ jcr->setJobStatusWithPriorityCheck(JS_WaitSD);
// Wait for up to 6 hours to increment read stoage counter
for (int i = 0; i < MAX_TRIES; i++) {
// Try to get read storage counter incremented
if (IncReadStore(jcr)) {
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
return true;
}
Bmicrosleep(10, 0); /* Sleep 10 secs */
diff --git a/core/src/dird/ua_cmds.cc b/core/src/dird/ua_cmds.cc
index c86e986b1..05bd82eea 100644
--- a/core/src/dird/ua_cmds.cc
+++ b/core/src/dird/ua_cmds.cc
@@ -623,7 +623,7 @@ bool Do_a_command(UaContext* ua)
* ua->jcr->setJobStatus(JS_Running)
* isn't enough, as it does not overwrite error states.
*/
- ua->jcr->JobStatus = JS_Running;
+ ua->jcr->setJobStatus(JS_Running);
if (ua->api) { user->signal(BNET_CMD_BEGIN); }
ua->send->SetMode(ua->api);
@@ -2741,8 +2741,8 @@ static bool wait_cmd(UaContext* ua, const char*)
for (bool waiting = false; !waiting;) {
foreach_jcr (jcr) {
if (jcr->JobId != 0
- && (jcr->JobStatus == JS_WaitMedia
- || jcr->JobStatus == JS_WaitMount)) {
+ && (jcr->getJobStatus() == JS_WaitMedia
+ || jcr->getJobStatus() == JS_WaitMount)) {
waiting = true;
break;
}
diff --git a/core/src/dird/ua_select.cc b/core/src/dird/ua_select.cc
index cc0b3a7ff..b8c013fc6 100644
--- a/core/src/dird/ua_select.cc
+++ b/core/src/dird/ua_select.cc
@@ -1691,16 +1691,20 @@ alist<JobId_t*>* select_jobs(UaContext* ua, const char* reason)
case all_jobs:
break;
case created_jobs:
- if (jcr->JobStatus != JS_Created) { continue; }
+ if (jcr->getJobStatus() != JS_Created) { continue; }
break;
case blocked_jobs:
- if (!jcr->job_started || jcr->JobStatus != JS_Blocked) { continue; }
+ if (!jcr->job_started || jcr->getJobStatus() != JS_Blocked) {
+ continue;
+ }
break;
case waiting_jobs:
if (!JobWaiting(jcr)) { continue; }
break;
case running_jobs:
- if (!jcr->job_started || jcr->JobStatus != JS_Running) { continue; }
+ if (!jcr->job_started || jcr->getJobStatus() != JS_Running) {
+ continue;
+ }
break;
default:
break;
diff --git a/core/src/dird/ua_server.cc b/core/src/dird/ua_server.cc
index 280f4ebdf..8bfb3410d 100644
--- a/core/src/dird/ua_server.cc
+++ b/core/src/dird/ua_server.cc
@@ -73,7 +73,7 @@ JobControlRecord* new_control_jcr(const char* base_name, int job_type)
jcr->sched_time = jcr->start_time;
jcr->setJobType(job_type);
jcr->setJobLevel(L_NONE);
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
jcr->JobId = 0;
return jcr;
diff --git a/core/src/dird/ua_status.cc b/core/src/dird/ua_status.cc
index f73af0b90..20e830194 100644
--- a/core/src/dird/ua_status.cc
+++ b/core/src/dird/ua_status.cc
@@ -111,7 +111,7 @@ bool DotStatusCmd(UaContext* ua, const char* cmd)
if (njcr->JobId != 0
&& ua->AclAccessOk(Job_ACL, njcr->impl->res.job->resource_name_)) {
ua->SendMsg(DotStatusJob, edit_int64(njcr->JobId, ed1),
- njcr->JobStatus, njcr->JobErrors);
+ njcr->getJobStatus(), njcr->JobErrors);
}
}
endeach_jcr(njcr);
@@ -291,12 +291,12 @@ static void DoAllStatus(UaContext* ua)
}
UnlockRes(my_config);
- previous_JobStatus = ua->jcr->JobStatus;
+ previous_JobStatus = ua->jcr->getJobStatus();
/* Call each unique Storage daemon */
for (j = 0; j < i; j++) {
StorageStatus(ua, unique_store[j], NULL);
- ua->jcr->JobStatus = previous_JobStatus;
+ ua->jcr->setJobStatus(previous_JobStatus);
}
free(unique_store);
@@ -326,12 +326,12 @@ static void DoAllStatus(UaContext* ua)
}
UnlockRes(my_config);
- previous_JobStatus = ua->jcr->JobStatus;
+ previous_JobStatus = ua->jcr->getJobStatus();
/* Call each unique File daemon */
for (j = 0; j < i; j++) {
ClientStatus(ua, unique_client[j], NULL);
- ua->jcr->JobStatus = previous_JobStatus;
+ ua->jcr->setJobStatus(previous_JobStatus);
}
free(unique_client);
}
@@ -970,7 +970,7 @@ static void ListRunningJobs(UaContext* ua)
continue;
}
njobs++;
- switch (jcr->JobStatus) {
+ switch (jcr->getJobStatus()) {
case JS_Created:
msg = _("is waiting execution");
break;
@@ -1068,7 +1068,7 @@ static void ListRunningJobs(UaContext* ua)
default:
emsg = (char*)GetPoolMemory(PM_FNAME);
- Mmsg(emsg, _("is in unknown state %c"), jcr->JobStatus);
+ Mmsg(emsg, _("is in unknown state %c"), jcr->getJobStatus());
pool_mem = true;
msg = emsg;
break;
diff --git a/core/src/dird/vbackup.cc b/core/src/dird/vbackup.cc
index e06c12619..9acd1b67d 100644
--- a/core/src/dird/vbackup.cc
+++ b/core/src/dird/vbackup.cc
@@ -319,7 +319,7 @@ bool DoNativeVbackup(JobControlRecord* jcr)
* daemon.
*/
Dmsg0(110, "Open connection with storage daemon\n");
- jcr->setJobStatus(JS_WaitSD);
+ jcr->setJobStatusWithPriorityCheck(JS_WaitSD);
// Start conversation with Storage daemon
if (!ConnectToStorageDaemon(jcr, 10, me->SDConnectTimeout, true)) {
@@ -347,7 +347,7 @@ bool DoNativeVbackup(JobControlRecord* jcr)
jcr->start_time = time(NULL);
jcr->impl->jr.StartTime = jcr->start_time;
jcr->impl->jr.JobTDate = jcr->start_time;
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
// Update job start record
if (!jcr->db->UpdateJobStartRecord(jcr, &jcr->impl->jr)) {
@@ -368,19 +368,19 @@ bool DoNativeVbackup(JobControlRecord* jcr)
// Now start a Storage daemon message thread
if (!StartStorageDaemonMessageThread(jcr)) { return false; }
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
/*
* Pickup Job termination data
* Note, the SD stores in jcr->JobFiles/ReadBytes/JobBytes/JobErrors
*/
WaitForStorageDaemonTermination(jcr);
- jcr->setJobStatus(jcr->impl->SDJobStatus);
+ jcr->setJobStatusWithPriorityCheck(jcr->impl->SDJobStatus);
jcr->db_batch->WriteBatchFileRecords(
jcr); /* used by bulk batch file insert */
if (!jcr->is_JobStatus(JS_Terminated)) { return false; }
- NativeVbackupCleanup(jcr, jcr->JobStatus, JobLevel_of_first_job);
+ NativeVbackupCleanup(jcr, jcr->getJobStatus(), JobLevel_of_first_job);
// Remove the successfully consolidated jobids from the database
if (jcr->impl->res.job->AlwaysIncremental
@@ -407,7 +407,7 @@ void NativeVbackupCleanup(JobControlRecord* jcr, int TermCode, int JobLevel)
Dmsg2(100, "Enter backup_cleanup %d %c\n", TermCode, TermCode);
- switch (jcr->JobStatus) {
+ switch (jcr->getJobStatus()) {
case JS_Terminated:
case JS_Warnings:
jcr->impl->jr.JobLevel = JobLevel; /* We want this to appear as what the
@@ -444,7 +444,7 @@ void NativeVbackupCleanup(JobControlRecord* jcr, int TermCode, int JobLevel)
Jmsg(jcr, M_WARNING, 0,
_("Error getting Job record for Job report: ERR=%s\n"),
jcr->db->strerror());
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
}
bstrncpy(cr.Name, jcr->impl->res.client->resource_name_, sizeof(cr.Name));
@@ -456,7 +456,7 @@ void NativeVbackupCleanup(JobControlRecord* jcr, int TermCode, int JobLevel)
UpdateBootstrapFile(jcr);
- switch (jcr->JobStatus) {
+ switch (jcr->getJobStatus()) {
case JS_Terminated:
TermMsg = _("Backup OK");
break;
@@ -485,7 +485,8 @@ void NativeVbackupCleanup(JobControlRecord* jcr, int TermCode, int JobLevel)
break;
default:
TermMsg = term_code;
- sprintf(term_code, _("Inappropriate term code: %c\n"), jcr->JobStatus);
+ sprintf(term_code, _("Inappropriate term code: %c\n"),
+ jcr->getJobStatus());
break;
}
diff --git a/core/src/dird/verify.cc b/core/src/dird/verify.cc
index 17a8d3b93..d2c944f93 100644
--- a/core/src/dird/verify.cc
+++ b/core/src/dird/verify.cc
@@ -237,7 +237,7 @@ bool DoVerify(JobControlRecord* jcr)
switch (JobLevel) {
case L_VERIFY_VOLUME_TO_CATALOG:
// Start conversation with Storage daemon
- jcr->setJobStatus(JS_Blocked);
+ jcr->setJobStatusWithPriorityCheck(JS_Blocked);
if (!ConnectToStorageDaemon(jcr, 10, me->SDConnectTimeout, true)) {
return false;
}
@@ -260,7 +260,7 @@ bool DoVerify(JobControlRecord* jcr)
}
// OK, now connect to the File daemon and ask him for the files.
- jcr->setJobStatus(JS_Blocked);
+ jcr->setJobStatusWithPriorityCheck(JS_Blocked);
if (!ConnectToFileDaemon(jcr, 10, me->FDConnectTimeout, true)) {
goto bail_out;
}
@@ -278,7 +278,7 @@ bool DoVerify(JobControlRecord* jcr)
break;
default:
// OK, now connect to the File daemon and ask him for the files.
- jcr->setJobStatus(JS_Blocked);
+ jcr->setJobStatusWithPriorityCheck(JS_Blocked);
if (!ConnectToFileDaemon(jcr, 10, me->FDConnectTimeout, true)) {
goto bail_out;
}
@@ -287,7 +287,7 @@ bool DoVerify(JobControlRecord* jcr)
break;
}
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
Dmsg0(30, ">filed: Send include list\n");
if (!SendIncludeList(jcr)) { goto bail_out; }
@@ -661,7 +661,7 @@ void GetAttributesAndCompareToCatalog(JobControlRecord* jcr, JobId_t JobId)
&jcr->impl->previous_jr, &fdbr)) {
Jmsg(jcr, M_INFO, 0, _("New file: %s\n"), jcr->impl->fname);
Dmsg1(020, _("File not in catalog: %s\n"), jcr->impl->fname);
- jcr->setJobStatus(JS_Differences);
+ jcr->setJobStatusWithPriorityCheck(JS_Differences);
continue;
} else {
/*
@@ -689,7 +689,7 @@ void GetAttributesAndCompareToCatalog(JobControlRecord* jcr, JobId_t JobId)
_(" st_ino differ. Cat: %s File: %s\n"),
edit_uint64((uint64_t)statc.st_ino, ed1),
edit_uint64((uint64_t)statf.st_ino, ed2));
- jcr->setJobStatus(JS_Differences);
+ jcr->setJobStatusWithPriorityCheck(JS_Differences);
}
break;
case 'p': /* permissions bits */
@@ -698,7 +698,7 @@ void GetAttributesAndCompareToCatalog(JobControlRecord* jcr, JobId_t JobId)
Jmsg(jcr, M_INFO, 0,
_(" st_mode differ. Cat: %x File: %x\n"),
(uint32_t)statc.st_mode, (uint32_t)statf.st_mode);
- jcr->setJobStatus(JS_Differences);
+ jcr->setJobStatusWithPriorityCheck(JS_Differences);
}
break;
case 'n': /* number of links */
@@ -707,7 +707,7 @@ void GetAttributesAndCompareToCatalog(JobControlRecord* jcr, JobId_t JobId)
Jmsg(jcr, M_INFO, 0,
_(" st_nlink differ. Cat: %d File: %d\n"),
(uint32_t)statc.st_nlink, (uint32_t)statf.st_nlink);
- jcr->setJobStatus(JS_Differences);
+ jcr->setJobStatusWithPriorityCheck(JS_Differences);
}
break;
case 'u': /* user id */
@@ -716,7 +716,7 @@ void GetAttributesAndCompareToCatalog(JobControlRecord* jcr, JobId_t JobId)
Jmsg(jcr, M_INFO, 0,
_(" st_uid differ. Cat: %u File: %u\n"),
(uint32_t)statc.st_uid, (uint32_t)statf.st_uid);
- jcr->setJobStatus(JS_Differences);
+ jcr->setJobStatusWithPriorityCheck(JS_Differences);
}
break;
case 'g': /* group id */
@@ -725,7 +725,7 @@ void GetAttributesAndCompareToCatalog(JobControlRecord* jcr, JobId_t JobId)
Jmsg(jcr, M_INFO, 0,
_(" st_gid differ. Cat: %u File: %u\n"),
(uint32_t)statc.st_gid, (uint32_t)statf.st_gid);
- jcr->setJobStatus(JS_Differences);
+ jcr->setJobStatusWithPriorityCheck(JS_Differences);
}
break;
case 's': /* size */
@@ -735,28 +735,28 @@ void GetAttributesAndCompareToCatalog(JobControlRecord* jcr, JobId_t JobId)
_(" st_size differ. Cat: %s File: %s\n"),
edit_uint64((uint64_t)statc.st_size, ed1),
edit_uint64((uint64_t)statf.st_size, ed2));
- jcr->setJobStatus(JS_Differences);
+ jcr->setJobStatusWithPriorityCheck(JS_Differences);
}
break;
case 'a': /* access time */
if (statc.st_atime != statf.st_atime) {
PrtFname(jcr);
Jmsg(jcr, M_INFO, 0, _(" st_atime differs\n"));
- jcr->setJobStatus(JS_Differences);
+ jcr->setJobStatusWithPriorityCheck(JS_Differences);
}
break;
case 'm':
if (statc.st_mtime != statf.st_mtime) {
PrtFname(jcr);
Jmsg(jcr, M_INFO, 0, _(" st_mtime differs\n"));
- jcr->setJobStatus(JS_Differences);
+ jcr->setJobStatusWithPriorityCheck(JS_Differences);
}
break;
case 'c': /* ctime */
if (statc.st_ctime != statf.st_ctime) {
PrtFname(jcr);
Jmsg(jcr, M_INFO, 0, _(" st_ctime differs\n"));
- jcr->setJobStatus(JS_Differences);
+ jcr->setJobStatusWithPriorityCheck(JS_Differences);
}
break;
case 'd': /* file size decrease */
@@ -766,7 +766,7 @@ void GetAttributesAndCompareToCatalog(JobControlRecord* jcr, JobId_t JobId)
_(" st_size decrease. Cat: %s File: %s\n"),
edit_uint64((uint64_t)statc.st_size, ed1),
edit_uint64((uint64_t)statf.st_size, ed2));
- jcr->setJobStatus(JS_Differences);
+ jcr->setJobStatusWithPriorityCheck(JS_Differences);
}
break;
case '5': /* compare MD5 */
@@ -813,7 +813,7 @@ void GetAttributesAndCompareToCatalog(JobControlRecord* jcr, JobId_t JobId)
PrtFname(jcr);
Jmsg(jcr, M_INFO, 0, _(" %s differs. File=%s Cat=%s\n"),
stream_to_ascii(stream), buf.c_str(), fdbr.Digest);
- jcr->setJobStatus(JS_Differences);
+ jcr->setJobStatusWithPriorityCheck(JS_Differences);
}
do_Digest = CRYPTO_DIGEST_NONE;
}
@@ -842,7 +842,9 @@ void GetAttributesAndCompareToCatalog(JobControlRecord* jcr, JobId_t JobId)
JobId, jcr->JobId);
/* MissingHandler is called for each file found */
jcr->db->SqlQuery(buf.c_str(), MissingHandler, (void*)jcr);
- if (jcr->impl->fn_printed) { jcr->setJobStatus(JS_Differences); }
+ if (jcr->impl->fn_printed) {
+ jcr->setJobStatusWithPriorityCheck(JS_Differences);
+ }
bail_out:
FreePoolMemory(fname);
diff --git a/core/src/filed/backup.cc b/core/src/filed/backup.cc
index 371bb32c3..e81f7cea9 100644
--- a/core/src/filed/backup.cc
+++ b/core/src/filed/backup.cc
@@ -105,7 +105,7 @@ bool BlastDataToStorageDaemon(JobControlRecord* jcr,
sd = jcr->store_bsock;
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
Dmsg1(300, "filed: opened data connection %d to stored\n", sd->fd_);
@@ -120,7 +120,7 @@ bool BlastDataToStorageDaemon(JobControlRecord* jcr,
buf_size = 0; /* use default */
}
if (!sd->SetBufferSize(buf_size, BNET_SETBUF_WRITE)) {
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
Jmsg(jcr, M_FATAL, 0, _("Cannot set buffer size FD->SD.\n"));
return false;
}
@@ -160,7 +160,7 @@ bool BlastDataToStorageDaemon(JobControlRecord* jcr,
// Subroutine SaveFile() is called for each file
if (!FindFiles(jcr, (FindFilesPacket*)jcr->impl->ff, SaveFile, PluginSave)) {
ok = false; /* error */
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
}
if (have_acl && jcr->impl->acl_data->u.build->nr_errors > 0) {
@@ -1214,7 +1214,7 @@ bool EncodeAndSendAttributes(JobControlRecord* jcr,
// Debug code: check if we must hangup
if (hangup && (jcr->JobFiles > (uint32_t)hangup)) {
- jcr->setJobStatus(JS_Incomplete);
+ jcr->setJobStatusWithPriorityCheck(JS_Incomplete);
Jmsg1(jcr, M_FATAL, 0, "Debug hangup requested after %d files.\n", hangup);
SetHangup(0);
return false;
diff --git a/core/src/filed/compression.cc b/core/src/filed/compression.cc
index de1bea4f8..1c62c50d8 100644
--- a/core/src/filed/compression.cc
+++ b/core/src/filed/compression.cc
@@ -3,7 +3,7 @@
Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
- Copyright (C) 2013-2019 Bareos GmbH & Co. KG
+ Copyright (C) 2013-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
@@ -166,7 +166,7 @@ bool SetupCompressionContext(b_ctx& bctx)
!= Z_OK) {
Jmsg(bctx.jcr, M_FATAL, 0,
_("Compression deflateParams error: %d\n"), zstat);
- bctx.jcr->setJobStatus(JS_ErrorTerminated);
+ bctx.jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
goto bail_out;
}
}
@@ -203,7 +203,7 @@ bool SetupCompressionContext(b_ctx& bctx)
!= Z_OK) {
Jmsg(bctx.jcr, M_FATAL, 0,
_("Compression fastlzlibSetCompressor error: %d\n"), zstat);
- bctx.jcr->setJobStatus(JS_ErrorTerminated);
+ bctx.jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
goto bail_out;
}
}
diff --git a/core/src/filed/dir_cmd.cc b/core/src/filed/dir_cmd.cc
index 8ecaa181d..a47ca928f 100644
--- a/core/src/filed/dir_cmd.cc
+++ b/core/src/filed/dir_cmd.cc
@@ -471,7 +471,7 @@ void* process_director_commands(JobControlRecord* jcr, BareosSocket* dir)
if (jcr->JobId) { /* send EndJob if running a job */
char ed1[50], ed2[50];
// Send termination status back to Dir
- dir->fsend(EndJob, jcr->JobStatus, jcr->JobFiles,
+ dir->fsend(EndJob, jcr->getJobStatus(), jcr->JobFiles,
edit_uint64(jcr->ReadBytes, ed1),
edit_uint64(jcr->JobBytes, ed2), jcr->JobErrors,
jcr->impl->enable_vss, jcr->impl->crypto.pki_encrypt);
@@ -757,7 +757,7 @@ static bool CancelCmd(JobControlRecord* jcr)
dir->fsend(_("2901 Job %s not found.\n"), Job);
} else {
GeneratePluginEvent(cjcr, bEventCancelCommand, nullptr);
- cjcr->setJobStatus(JS_Canceled);
+ cjcr->setJobStatusWithPriorityCheck(JS_Canceled);
if (cjcr->store_bsock) {
cjcr->store_bsock->SetTimedOut();
cjcr->store_bsock->SetTerminated();
@@ -1332,7 +1332,7 @@ static bool BootstrapCmd(JobControlRecord* jcr)
*/
while (dir->recv() >= 0) {}
FreeBootstrap(jcr);
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return false;
}
@@ -1878,7 +1878,7 @@ static bool BackupCmd(JobControlRecord* jcr)
goto cleanup;
}
- jcr->setJobStatus(JS_Blocked);
+ jcr->setJobStatusWithPriorityCheck(JS_Blocked);
jcr->setJobType(JT_BACKUP);
Dmsg1(100, "begin backup ff=%p\n", jcr->impl->ff);
@@ -1999,11 +1999,11 @@ static bool BackupCmd(JobControlRecord* jcr)
// Send Files to Storage daemon
Dmsg1(110, "begin blast ff=%p\n", (FindFilesPacket*)jcr->impl->ff);
if (!BlastDataToStorageDaemon(jcr, nullptr, cipher)) {
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
BnetSuppressErrorMessages(sd, 1);
Dmsg0(110, "Error in blast_data.\n");
} else {
- jcr->setJobStatus(JS_Terminated);
+ jcr->setJobStatusWithPriorityCheck(JS_Terminated);
/* Note, the above set status will not override an error */
if (!jcr->IsTerminatedOk()) {
BnetSuppressErrorMessages(sd, 1);
@@ -2011,7 +2011,7 @@ static bool BackupCmd(JobControlRecord* jcr)
}
// Expect to get response to append_data from Storage daemon
if (!response(jcr, sd, OK_append, "Append Data")) {
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
goto cleanup;
}
@@ -2019,7 +2019,7 @@ static bool BackupCmd(JobControlRecord* jcr)
sd->fsend(append_end, jcr->impl->Ticket);
/* Get end OK */
if (!response(jcr, sd, OK_end, "Append End")) {
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
goto cleanup;
}
@@ -2277,14 +2277,14 @@ static bool RestoreCmd(JobControlRecord* jcr)
dir->fsend(OKrestore);
Dmsg1(110, "filed>dird: %s", dir->msg);
- jcr->setJobStatus(JS_Blocked);
+ jcr->setJobStatusWithPriorityCheck(JS_Blocked);
if (!OpenSdReadSession(jcr)) {
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
goto bail_out;
}
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
// Do restore of files and data
StartDirHeartbeat(jcr);
@@ -2314,9 +2314,9 @@ static bool RestoreCmd(JobControlRecord* jcr)
StopDirHeartbeat(jcr);
if (jcr->JobWarnings) {
- jcr->setJobStatus(JS_Warnings);
+ jcr->setJobStatusWithPriorityCheck(JS_Warnings);
} else {
- jcr->setJobStatus(JS_Terminated);
+ jcr->setJobStatusWithPriorityCheck(JS_Terminated);
}
// Send Close session command to Storage daemon
@@ -2361,7 +2361,9 @@ static bool RestoreCmd(JobControlRecord* jcr)
bail_out:
BfreeAndNull(jcr->where);
- if (jcr->JobErrors) { jcr->setJobStatus(JS_ErrorTerminated); }
+ if (jcr->JobErrors) {
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
+ }
Dmsg0(100, "Done in job.c\n");
diff --git a/core/src/filed/estimate.cc b/core/src/filed/estimate.cc
index a423cbc23..167107ea3 100644
--- a/core/src/filed/estimate.cc
+++ b/core/src/filed/estimate.cc
@@ -40,7 +40,7 @@ int MakeEstimate(JobControlRecord* jcr)
{
int status;
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
SetFindOptions((FindFilesPacket*)jcr->impl->ff, jcr->impl->incremental,
jcr->impl->since_time);
diff --git a/core/src/filed/fd_plugins.cc b/core/src/filed/fd_plugins.cc
index 07ffdefd3..b992e1af2 100644
--- a/core/src/filed/fd_plugins.cc
+++ b/core/src/filed/fd_plugins.cc
@@ -2054,9 +2054,9 @@ static bRC bareosGetValue(PluginContext* ctx, bVariable var, void* value)
NPRT(*((char**)value)));
break;
case bVarJobStatus:
- *((int*)value) = jcr->JobStatus;
+ *((int*)value) = jcr->getJobStatus();
Dmsg1(debuglevel, "fd-plugin: return bVarJobStatus=%d\n",
- jcr->JobStatus);
+ jcr->getJobStatus());
break;
case bVarSinceTime:
*((int*)value) = (int)jcr->impl->since_time;
diff --git a/core/src/filed/restore.cc b/core/src/filed/restore.cc
index 5458f80e8..a11cff2f8 100644
--- a/core/src/filed/restore.cc
+++ b/core/src/filed/restore.cc
@@ -414,7 +414,7 @@ void DoRestore(JobControlRecord* jcr)
rctx.jcr = jcr;
sd = jcr->store_bsock;
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
LockRes(my_config);
ClientResource* client
@@ -426,7 +426,7 @@ void DoRestore(JobControlRecord* jcr)
buf_size = 0; /* use default */
}
if (!BnetSetBufferSize(sd, buf_size, BNET_SETBUF_WRITE)) {
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return;
}
jcr->buf_size = sd->message_length;
@@ -1040,11 +1040,11 @@ void DoRestore(JobControlRecord* jcr)
}
if (!ClosePreviousStream(jcr, rctx)) { goto bail_out; }
- jcr->setJobStatus(JS_Terminated);
+ jcr->setJobStatusWithPriorityCheck(JS_Terminated);
goto ok_out;
bail_out:
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
ok_out:
#ifdef HAVE_WIN32
diff --git a/core/src/filed/sd_cmds.cc b/core/src/filed/sd_cmds.cc
index 91991ab3f..879fe9592 100644
--- a/core/src/filed/sd_cmds.cc
+++ b/core/src/filed/sd_cmds.cc
@@ -1,7 +1,7 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
- Copyright (C) 2013-2019 Bareos GmbH & Co. KG
+ Copyright (C) 2013-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
@@ -84,7 +84,7 @@ void* handle_stored_connection(BareosSocket* sd)
if (!AuthenticateStoragedaemon(jcr)) {
Dmsg1(50, "Authentication failed Job %s\n", jcr->Job);
Jmsg(jcr, M_FATAL, 0, _("Unable to authenticate Storage daemon\n"));
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
} else {
Dmsg2(50, "OK Authentication jid=%u Job %s\n", (uint32_t)jcr->JobId,
jcr->Job);
diff --git a/core/src/filed/status.cc b/core/src/filed/status.cc
index 6355a2a7b..4d8f3d2b6 100644
--- a/core/src/filed/status.cc
+++ b/core/src/filed/status.cc
@@ -440,7 +440,8 @@ bool QstatusCmd(JobControlRecord* jcr)
dir->fsend(OKqstatus, cmd);
foreach_jcr (njcr) {
if (njcr->JobId != 0) {
- dir->fsend(DotStatusJob, njcr->JobId, njcr->JobStatus, njcr->JobErrors);
+ dir->fsend(DotStatusJob, njcr->JobId, njcr->getJobStatus(),
+ njcr->JobErrors);
}
}
endeach_jcr(njcr);
diff --git a/core/src/filed/verify.cc b/core/src/filed/verify.cc
index 544010859..01b05a127 100644
--- a/core/src/filed/verify.cc
+++ b/core/src/filed/verify.cc
@@ -62,7 +62,7 @@ static bool calculate_file_chksum(JobControlRecord* jcr,
*/
void DoVerify(JobControlRecord* jcr)
{
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
jcr->buf_size = DEFAULT_NETWORK_BUFFER_SIZE;
if ((jcr->impl->big_buf = (char*)malloc(jcr->buf_size)) == NULL) {
Jmsg1(jcr, M_ABORT, 0, _("Cannot malloc %d network read buffer\n"),
@@ -79,7 +79,7 @@ void DoVerify(JobControlRecord* jcr)
free(jcr->impl->big_buf);
jcr->impl->big_buf = NULL;
}
- jcr->setJobStatus(JS_Terminated);
+ jcr->setJobStatusWithPriorityCheck(JS_Terminated);
}
/**
diff --git a/core/src/filed/verify_vol.cc b/core/src/filed/verify_vol.cc
index adb2b0c6b..dcaff73b8 100644
--- a/core/src/filed/verify_vol.cc
+++ b/core/src/filed/verify_vol.cc
@@ -2,7 +2,7 @@
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2002-2010 Free Software Foundation Europe e.V.
- Copyright (C) 2016-2020 Bareos GmbH & Co. KG
+ Copyright (C) 2016-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
@@ -62,11 +62,11 @@ void DoVerifyVolume(JobControlRecord* jcr)
sd = jcr->store_bsock;
if (!sd) {
Jmsg(jcr, M_FATAL, 0, _("Storage command not issued before Verify.\n"));
- jcr->setJobStatus(JS_FatalError);
+ jcr->setJobStatusWithPriorityCheck(JS_FatalError);
return;
}
dir = jcr->dir_bsock;
- jcr->setJobStatus(JS_Running);
+ jcr->setJobStatusWithPriorityCheck(JS_Running);
LockRes(my_config);
ClientResource* client
@@ -79,7 +79,7 @@ void DoVerifyVolume(JobControlRecord* jcr)
buf_size = 0; /* use default */
}
if (!BnetSetBufferSize(sd, buf_size, BNET_SETBUF_WRITE)) {
- jcr->setJobStatus(JS_FatalError);
+ jcr->setJobStatusWithPriorityCheck(JS_FatalError);
return;
}
jcr->buf_size = sd->message_length;
@@ -264,11 +264,11 @@ void DoVerifyVolume(JobControlRecord* jcr)
} /* end switch */
} /* end while bnet_get */
- jcr->setJobStatus(JS_Terminated);
+ jcr->setJobStatusWithPriorityCheck(JS_Terminated);
goto ok_out;
bail_out:
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
ok_out:
CleanupCompression(jcr);
diff --git a/core/src/include/jcr.h b/core/src/include/jcr.h
index 2594353df..1b7949184 100644
--- a/core/src/include/jcr.h
+++ b/core/src/include/jcr.h
@@ -45,8 +45,9 @@
#include "lib/breg.h"
#include "lib/dlink.h"
#include "lib/path_list.h"
-#include <unordered_set>
+#include <unordered_set>
+#include <atomic>
struct job_callback_item;
class BareosDb;
@@ -66,11 +67,12 @@ struct CopyThreadContext;
typedef void(JCR_free_HANDLER)(JobControlRecord* jcr);
#define JobTerminatedSuccessfully(jcr) \
- (jcr->JobStatus == JS_Terminated || jcr->JobStatus == JS_Warnings)
+ (jcr->getJobStatus() == JS_Terminated || jcr->getJobStatus() == JS_Warnings)
-#define JobCanceled(jcr) \
- (jcr->JobStatus == JS_Canceled || jcr->JobStatus == JS_ErrorTerminated \
- || jcr->JobStatus == JS_FatalError)
+#define JobCanceled(jcr) \
+ (jcr->getJobStatus() == JS_Canceled \
+ || jcr->getJobStatus() == JS_ErrorTerminated \
+ || jcr->getJobStatus() == JS_FatalError)
#define foreach_jcr(jcr) \
for (jcr = jcr_walk_start(); jcr; (jcr = jcr_walk_next(jcr)))
@@ -81,7 +83,8 @@ typedef void(JCR_free_HANDLER)(JobControlRecord* jcr);
class JobControlRecord {
private:
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; /**< Jcr mutex */
- volatile int32_t _use_count{}; /**< Use count */
+ std::atomic<int32_t> _use_count{}; /**< Use count */
+ std::atomic<int32_t> JobStatus{}; /**< ready, running, blocked, terminated */
int32_t JobType_{}; /**< Backup, restore, verify ... */
int32_t JobLevel_{}; /**< Job level */
int32_t Protocol_{}; /**< Backup Protocol */
@@ -98,15 +101,11 @@ class JobControlRecord {
void unlock() { unlock_mutex(mutex); }
void IncUseCount(void)
{
- lock();
- _use_count++;
- unlock();
+ ++_use_count;
}
void DecUseCount(void)
{
- lock();
- _use_count--;
- unlock();
+ --_use_count;
}
int32_t UseCount() const { return _use_count; }
void InitMutex(void) { pthread_mutex_init(&mutex, NULL); }
@@ -121,7 +120,7 @@ class JobControlRecord {
void setJobLevel(int32_t JobLevel) { JobLevel_ = JobLevel; }
void setJobType(int32_t JobType) { JobType_ = JobType; }
void setJobProtocol(int32_t JobProtocol) { Protocol_ = JobProtocol; }
- void forceJobStatus(int32_t aJobStatus) { JobStatus = aJobStatus; }
+ void setJobStatus(int32_t aJobStatus) { JobStatus = aJobStatus; }
void setJobStarted();
int32_t getJobType() const { return JobType_; }
int32_t getJobLevel() const { return JobLevel_; }
@@ -135,8 +134,7 @@ class JobControlRecord {
bool IsPlugin() const { return (cmd_plugin || opt_plugin); }
const char* get_OperationName(); /**< in lib/jcr.c */
const char* get_ActionName(bool past = false); /**< in lib/jcr.c */
- void setJobStatus(int newJobStatus); /**< in lib/jcr.c */
- void resetJobStatus(int newJobStatus); /**< in lib/jcr.c */
+ void setJobStatusWithPriorityCheck(int newJobStatus); /**< in lib/jcr.c */
bool sendJobStatus(); /**< in lib/jcr.c */
bool sendJobStatus(int newJobStatus); /**< in lib/jcr.c */
bool JobReads(); /**< in lib/jcr.c */
@@ -169,7 +167,6 @@ class JobControlRecord {
uint64_t LastJobBytes{}; /**< Last sample number bytes */
uint64_t ReadBytes{}; /**< Bytes read -- before compression */
FileId_t FileId{}; /**< Last FileId used */
- volatile int32_t JobStatus{}; /**< ready, running, blocked, terminated */
int32_t JobPriority{}; /**< Job priority */
time_t sched_time{}; /**< Job schedule time, i.e. when it should start */
time_t initial_sched_time{}; /**< Original sched time before any reschedules are done */
diff --git a/core/src/lib/bsock.cc b/core/src/lib/bsock.cc
index 5eadb5d09..a4817059a 100644
--- a/core/src/lib/bsock.cc
+++ b/core/src/lib/bsock.cc
@@ -97,11 +97,11 @@ BareosSocket::BareosSocket(const BareosSocket& other)
in_msg_no = other.in_msg_no;
out_msg_no = other.out_msg_no;
message_length = other.message_length;
- timer_start = other.timer_start;
+ timer_start = other.timer_start.load();
b_errno = other.b_errno;
blocking_ = other.blocking_;
- errors = other.errors;
- suppress_error_msgs_ = other.suppress_error_msgs_;
+ errors = other.errors.load();
+ suppress_error_msgs_ = other.suppress_error_msgs_.load();
sleep_time_after_authentication_error
= other.sleep_time_after_authentication_error;
client_addr = other.client_addr;
diff --git a/core/src/lib/bsock.h b/core/src/lib/bsock.h
index 859c57983..5a2632047 100644
--- a/core/src/lib/bsock.h
+++ b/core/src/lib/bsock.h
@@ -2,7 +2,7 @@
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2000-2009 Free Software Foundation Europe e.V.
- Copyright (C) 2016-2021 Bareos GmbH & Co. KG
+ Copyright (C) 2016-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
@@ -37,9 +37,6 @@
#define BAREOS_LIB_BSOCK_H_
#include <include/bareos.h>
-#include <mutex>
-#include <functional>
-#include <cassert>
#include "lib/address_conf.h"
#include "lib/bnet_network_dump.h"
#include "lib/tls.h"
@@ -47,6 +44,11 @@
#include "lib/tls_conf.h"
#include "include/version_numbers.h"
+#include <mutex>
+#include <functional>
+#include <cassert>
+#include <atomic>
+
struct btimer_t; /* forward reference */
class BareosSocket;
class Tls;
@@ -62,20 +64,20 @@ class BareosSocket {
* bat breaks on some systems such as RedHat.
*/
public:
- int fd_; /* Socket file descriptor */
- uint64_t read_seqno; /* Read sequence number */
- POOLMEM* msg; /* Message pool buffer */
- POOLMEM* errmsg; /* Edited error message */
- int spool_fd_; /* Spooling file */
- IPADDR* src_addr; /* IP address to source connections from */
- uint32_t in_msg_no; /* Input message number */
- uint32_t out_msg_no; /* Output message number */
- int32_t message_length; /* Message length */
- volatile time_t timer_start; /* Time started read/write */
- int b_errno; /* BareosSocket errno */
- int blocking_; /* Blocking state (0 = nonblocking, 1 = blocking) */
- volatile int errors; /* Incremented for each error on socket */
- volatile bool suppress_error_msgs_; /* Set to suppress error messages */
+ int fd_; /* Socket file descriptor */
+ uint64_t read_seqno; /* Read sequence number */
+ POOLMEM* msg; /* Message pool buffer */
+ POOLMEM* errmsg; /* Edited error message */
+ int spool_fd_; /* Spooling file */
+ IPADDR* src_addr; /* IP address to source connections from */
+ uint32_t in_msg_no; /* Input message number */
+ uint32_t out_msg_no; /* Output message number */
+ int32_t message_length; /* Message length */
+ std::atomic<time_t> timer_start; /* Time started read/write */
+ int b_errno; /* BareosSocket errno */
+ int blocking_; /* Blocking state (0 = nonblocking, 1 = blocking) */
+ std::atomic<int> errors; /* Incremented for each error on socket */
+ std::atomic<bool> suppress_error_msgs_; /* Set to suppress error messages */
int sleep_time_after_authentication_error;
struct sockaddr client_addr; /* Client's IP address */
diff --git a/core/src/lib/bsock_tcp.cc b/core/src/lib/bsock_tcp.cc
index bc92dbd46..84571e9e5 100644
--- a/core/src/lib/bsock_tcp.cc
+++ b/core/src/lib/bsock_tcp.cc
@@ -396,7 +396,7 @@ bool BareosSocketTCP::SendPacket(int32_t* hdr, int32_t pktsiz)
rc = write_nbytes((char*)hdr, pktsiz);
timer_start = 0; /* clear timer */
if (rc != pktsiz) {
- errors++;
+ ++errors;
if (errno == 0) {
b_errno = EIO;
} else {
@@ -451,7 +451,7 @@ bool BareosSocketTCP::send()
if (errors) {
if (!suppress_error_msgs_) {
Qmsg4(jcr_, M_ERROR, 0, _("Socket has errors=%d on call to %s:%s:%d\n"),
- errors, who_, host_, port_);
+ errors.load(), who_, host_, port_);
}
return false;
}
@@ -544,13 +544,13 @@ int32_t BareosSocketTCP::recv()
} else {
b_errno = errno;
}
- errors++;
+ ++errors;
nbytes = BNET_HARDEOF; /* assume hard EOF received */
goto get_out;
}
timer_start = 0; /* clear timer */
if (nbytes != header_length) {
- errors++;
+ ++errors;
b_errno = EIO;
Qmsg5(jcr_, M_ERROR, 0, _("Read expected %d got %d from %s:%s:%d\n"),
header_length, nbytes, who_, host_, port_);
@@ -600,7 +600,7 @@ int32_t BareosSocketTCP::recv()
} else {
b_errno = errno;
}
- errors++;
+ ++errors;
Qmsg4(jcr_, M_ERROR, 0, _("Read error from %s:%s:%d: ERR=%s\n"), who_,
host_, port_, this->bstrerror());
nbytes = BNET_ERROR;
@@ -611,7 +611,7 @@ int32_t BareosSocketTCP::recv()
message_length = nbytes;
if (nbytes != pktsiz) {
b_errno = EIO;
- errors++;
+ ++errors;
Qmsg5(jcr_, M_ERROR, 0, _("Read expected %d got %d from %s:%s:%d\n"),
pktsiz, nbytes, who_, host_, port_);
nbytes = BNET_ERROR;
diff --git a/core/src/lib/compression.cc b/core/src/lib/compression.cc
index e6ef413c1..ab507793d 100644
--- a/core/src/lib/compression.cc
+++ b/core/src/lib/compression.cc
@@ -3,7 +3,7 @@
Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
- Copyright (C) 2013-2021 Bareos GmbH & Co. KG
+ Copyright (C) 2013-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
@@ -304,7 +304,7 @@ static bool compress_with_zlib(JobControlRecord* jcr,
if ((zstat = deflate(pZlibStream, Z_FINISH)) != Z_STREAM_END) {
Jmsg(jcr, M_FATAL, 0, _("Compression deflate error: %d\n"), zstat);
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return false;
}
@@ -313,7 +313,7 @@ static bool compress_with_zlib(JobControlRecord* jcr,
// Reset zlib stream to be able to begin from scratch again
if ((zstat = deflateReset(pZlibStream)) != Z_OK) {
Jmsg(jcr, M_FATAL, 0, _("Compression deflateReset error: %d\n"), zstat);
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return false;
}
@@ -344,7 +344,7 @@ static bool compress_with_lzo(JobControlRecord* jcr,
if (lzores != LZO_E_OK || *compress_len > max_compress_len) {
// This should NEVER happen
Jmsg(jcr, M_FATAL, 0, _("Compression LZO error: %d\n"), lzores);
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return false;
}
@@ -376,7 +376,7 @@ static bool compress_with_fastlz(JobControlRecord* jcr,
if ((zstat = fastlzlibCompress(pZfastStream, Z_FINISH)) != Z_STREAM_END) {
Jmsg(jcr, M_FATAL, 0, _("Compression fastlzlibCompress error: %d\n"),
zstat);
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return false;
}
@@ -386,7 +386,7 @@ static bool compress_with_fastlz(JobControlRecord* jcr,
if ((zstat = fastlzlibCompressReset(pZfastStream)) != Z_OK) {
Jmsg(jcr, M_FATAL, 0, _("Compression fastlzlibCompressReset error: %d\n"),
zstat);
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return false;
}
diff --git a/core/src/lib/connection_pool.h b/core/src/lib/connection_pool.h
index 64414fcd1..d37f1b269 100644
--- a/core/src/lib/connection_pool.h
+++ b/core/src/lib/connection_pool.h
@@ -28,6 +28,8 @@
#ifndef BAREOS_LIB_CONNECTION_POOL_H_
#define BAREOS_LIB_CONNECTION_POOL_H_
+#include <atomic>
+
template <typename T> class alist;
class BareosSocket;
@@ -57,7 +59,7 @@ class Connection {
char name_[MAX_NAME_LENGTH];
int protocol_version_;
bool authenticated_;
- volatile bool in_use_;
+ std::atomic<bool> in_use_;
time_t connect_time_;
pthread_mutex_t mutex_;
};
diff --git a/core/src/lib/jcr.cc b/core/src/lib/jcr.cc
index 7927ad127..cd983b894 100644
--- a/core/src/lib/jcr.cc
+++ b/core/src/lib/jcr.cc
@@ -217,7 +217,7 @@ JobControlRecord::JobControlRecord()
JobId = 0;
setJobType(JT_SYSTEM); /* internal job until defined */
setJobLevel(L_NONE);
- setJobStatus(JS_Created); /* ready to run */
+ setJobStatusWithPriorityCheck(JS_Created); /* ready to run */
SetTimeoutHandler();
}
@@ -660,7 +660,7 @@ TlsPolicy JcrGetTlsPolicy(const char* unified_job_name)
static void UpdateWaitTime(JobControlRecord* jcr, int newJobStatus)
{
bool enter_in_waittime;
- int oldJobStatus = jcr->JobStatus;
+ int oldJobStatus = jcr->getJobStatus();
switch (newJobStatus) {
case JS_WaitFD:
@@ -734,7 +734,7 @@ static int GetStatusPriority(int JobStatus)
// Send Job status to Director
bool JobControlRecord::sendJobStatus()
{
- if (dir_bsock) { return dir_bsock->fsend(Job_status, Job, JobStatus); }
+ if (dir_bsock) { return dir_bsock->fsend(Job_status, Job, getJobStatus()); }
return true;
}
@@ -743,8 +743,8 @@ bool JobControlRecord::sendJobStatus()
bool JobControlRecord::sendJobStatus(int newJobStatus)
{
if (!is_JobStatus(newJobStatus)) {
- setJobStatus(newJobStatus);
- if (dir_bsock) { return dir_bsock->fsend(Job_status, Job, JobStatus); }
+ setJobStatusWithPriorityCheck(newJobStatus);
+ if (dir_bsock) { return dir_bsock->fsend(Job_status, Job, getJobStatus()); }
}
return true;
@@ -756,21 +756,12 @@ void JobControlRecord::setJobStarted()
job_started_time = time(nullptr);
}
-void JobControlRecord::resetJobStatus(int newJobStatus)
-{
- JobStatus = newJobStatus;
-}
-
-void JobControlRecord::setJobStatus(int newJobStatus)
+void JobControlRecord::setJobStatusWithPriorityCheck(int newJobStatus)
{
int priority;
- int old_priority = 0;
- int oldJobStatus = ' ';
+ int oldJobStatus = JobStatus;
+ int old_priority = GetStatusPriority(oldJobStatus);
- if (JobStatus) {
- oldJobStatus = JobStatus;
- old_priority = GetStatusPriority(oldJobStatus);
- }
priority = GetStatusPriority(newJobStatus);
Dmsg2(800, "setJobStatus(%s, %c)\n", Job, newJobStatus);
@@ -794,7 +785,7 @@ void JobControlRecord::setJobStatus(int newJobStatus)
if (priority > old_priority || (priority == 0 && old_priority == 0)) {
Dmsg4(800, "Set new stat. old: %c,%d new: %c,%d\n", oldJobStatus,
old_priority, newJobStatus, priority);
- JobStatus = newJobStatus; /* replace with new status */
+ JobStatus.compare_exchange_strong(oldJobStatus, newJobStatus);
}
if (oldJobStatus != JobStatus) {
@@ -1047,11 +1038,11 @@ void DbgPrintJcr(FILE* fp)
jcr; jcr = (JobControlRecord*)job_control_record_chain->next(jcr)) {
fprintf(fp, "threadid=%s JobId=%d JobStatus=%c jcr=%p name=%s\n",
edit_pthread(jcr->my_thread_id, ed1, sizeof(ed1)), (int)jcr->JobId,
- jcr->JobStatus, jcr, jcr->Job);
- fprintf(fp,
- "threadid=%s killable=%d JobId=%d JobStatus=%c jcr=%p name=%s\n",
- edit_pthread(jcr->my_thread_id, ed1, sizeof(ed1)),
- jcr->IsKillable(), (int)jcr->JobId, jcr->JobStatus, jcr, jcr->Job);
+ jcr->getJobStatus(), jcr, jcr->Job);
+ fprintf(
+ fp, "threadid=%s killable=%d JobId=%d JobStatus=%c jcr=%p name=%s\n",
+ edit_pthread(jcr->my_thread_id, ed1, sizeof(ed1)), jcr->IsKillable(),
+ (int)jcr->JobId, jcr->getJobStatus(), jcr, jcr->Job);
fprintf(fp, "\tUseCount=%i\n", jcr->UseCount());
fprintf(fp, "\tJobType=%c JobLevel=%c\n", jcr->getJobType(),
jcr->getJobLevel());
diff --git a/core/src/lib/message.cc b/core/src/lib/message.cc
index ed45a30aa..27b0fc4f2 100644
--- a/core/src/lib/message.cc
+++ b/core/src/lib/message.cc
@@ -370,7 +370,7 @@ void CloseMsg(JobControlRecord* jcr)
switch (d->dest_code_) {
case MessageDestinationCode::KMailOnError:
if (jcr) {
- switch (jcr->JobStatus) {
+ switch (jcr->getJobStatus()) {
case JS_Terminated:
case JS_Warnings:
goto rem_temp_file;
@@ -381,7 +381,7 @@ void CloseMsg(JobControlRecord* jcr)
break;
case MessageDestinationCode::kMailOnSuccess:
if (jcr) {
- switch (jcr->JobStatus) {
+ switch (jcr->getJobStatus()) {
case JS_Terminated:
case JS_Warnings:
break;
@@ -1291,7 +1291,7 @@ void Jmsg(JobControlRecord* jcr, int type, utime_t mtime, const char* fmt, ...)
break;
case M_FATAL:
Mmsg(buf, _("%s JobId %u: Fatal error: "), my_name, JobId);
- if (jcr) { jcr->setJobStatus(JS_FatalError); }
+ if (jcr) { jcr->setJobStatusWithPriorityCheck(JS_FatalError); }
if (jcr && jcr->JobErrors == 0) { jcr->JobErrors = 1; }
break;
case M_ERROR:
diff --git a/core/src/lib/recent_job_results_list.cc b/core/src/lib/recent_job_results_list.cc
index 3165c1af0..18724ba18 100644
--- a/core/src/lib/recent_job_results_list.cc
+++ b/core/src/lib/recent_job_results_list.cc
@@ -3,7 +3,7 @@
Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
- Copyright (C) 2019-2019 Bareos GmbH & Co. KG
+ Copyright (C) 2019-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
@@ -128,7 +128,7 @@ void RecentJobResultsList::Append(JobControlRecord* jcr)
bstrncpy(je.Job, jcr->Job, sizeof(je.Job));
je.JobFiles = jcr->JobFiles;
je.JobBytes = jcr->JobBytes;
- je.JobStatus = jcr->JobStatus;
+ je.JobStatus = jcr->getJobStatus();
je.JobLevel = jcr->getJobLevel();
je.start_time = jcr->start_time;
je.end_time = time(nullptr);
diff --git a/core/src/lib/runscript.cc b/core/src/lib/runscript.cc
index ee16bf438..57ab1a2f3 100644
--- a/core/src/lib/runscript.cc
+++ b/core/src/lib/runscript.cc
@@ -113,7 +113,7 @@ int RunScripts(JobControlRecord* jcr,
int when;
Dmsg2(200, "runscript: running all RunScript object (%s) JobStatus=%c\n",
- label, jcr->JobStatus);
+ label, jcr->getJobStatus());
if (strstr(label, NT_("Before"))) {
when = SCRIPT_Before;
@@ -133,7 +133,7 @@ int RunScripts(JobControlRecord* jcr,
"runscript: try to run (Target=%s, OnSuccess=%i, OnFailure=%i, "
"CurrentJobStatus=%c, command=%s)\n",
NSTDPRNT(script->target), script->on_success, script->on_failure,
- jcr->JobStatus, NSTDPRNT(script->command));
+ jcr->getJobStatus(), NSTDPRNT(script->command));
runit = false;
if (!script->IsLocal()) {
@@ -146,23 +146,25 @@ int RunScripts(JobControlRecord* jcr,
} else {
if ((script->when & SCRIPT_Before) && (when & SCRIPT_Before)) {
if ((script->on_success
- && (jcr->JobStatus == JS_Running || jcr->JobStatus == JS_Created))
+ && (jcr->getJobStatus() == JS_Running
+ || jcr->getJobStatus() == JS_Created))
|| (script->on_failure
- && (JobCanceled(jcr) || jcr->JobStatus == JS_Differences))) {
+ && (JobCanceled(jcr)
+ || jcr->getJobStatus() == JS_Differences))) {
Dmsg4(200, "runscript: Run it because SCRIPT_Before (%s,%i,%i,%c)\n",
script->command.c_str(), script->on_success, script->on_failure,
- jcr->JobStatus);
+ jcr->getJobStatus());
runit = true;
}
}
if ((script->when & SCRIPT_AfterVSS) && (when & SCRIPT_AfterVSS)) {
- if ((script->on_success && (jcr->JobStatus == JS_Blocked))
+ if ((script->on_success && (jcr->getJobStatus() == JS_Blocked))
|| (script->on_failure && JobCanceled(jcr))) {
Dmsg4(200,
"runscript: Run it because SCRIPT_AfterVSS (%s,%i,%i,%c)\n",
script->command.c_str(), script->on_success, script->on_failure,
- jcr->JobStatus);
+ jcr->getJobStatus());
runit = true;
}
}
@@ -170,10 +172,11 @@ int RunScripts(JobControlRecord* jcr,
if ((script->when & SCRIPT_After) && (when & SCRIPT_After)) {
if ((script->on_success && jcr->IsTerminatedOk())
|| (script->on_failure
- && (JobCanceled(jcr) || jcr->JobStatus == JS_Differences))) {
+ && (JobCanceled(jcr)
+ || jcr->getJobStatus() == JS_Differences))) {
Dmsg4(200, "runscript: Run it because SCRIPT_After (%s,%i,%i,%c)\n",
script->command.c_str(), script->on_success, script->on_failure,
- jcr->JobStatus);
+ jcr->getJobStatus());
runit = true;
}
}
@@ -190,7 +193,7 @@ int RunScripts(JobControlRecord* jcr,
_("Runscript: run %s \"%s\" could not execute, "
"not in one of the allowed scripts dirs\n"),
label, script->command.c_str());
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
goto bail_out;
}
@@ -274,7 +277,7 @@ bool RunScript::Run(JobControlRecord* jcr, const char* name)
bail_out:
/* cancel running job properly */
- if (fail_on_error) { jcr->setJobStatus(JS_ErrorTerminated); }
+ if (fail_on_error) { jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated); }
Dmsg1(100, "runscript failed. fail_on_error=%d\n", fail_on_error);
return false;
}
diff --git a/core/src/lib/util.cc b/core/src/lib/util.cc
index 1cb6191b5..52a96e6d6 100644
--- a/core/src/lib/util.cc
+++ b/core/src/lib/util.cc
@@ -962,7 +962,7 @@ POOLMEM* edit_job_codes(JobControlRecord* jcr,
break;
case 'e': /* Job Exit code */
if (jcr) {
- str = job_status_to_str(jcr->JobStatus);
+ str = job_status_to_str(jcr->getJobStatus());
} else {
str = _("*None*");
}
diff --git a/core/src/plugins/filed/python/CMakeLists.txt b/core/src/plugins/filed/python/CMakeLists.txt
index 08af03d73..f81513766 100644
--- a/core/src/plugins/filed/python/CMakeLists.txt
+++ b/core/src/plugins/filed/python/CMakeLists.txt
@@ -116,6 +116,7 @@ if(Python2_FOUND)
LINK_FLAGS "${Python2_BLDSHARED_FLAGS}"
LINKER_LANGUAGE CXX
INCLUDE_DIRECTORIES "${pymod2_include_dirs}"
+ CXX_STANDARD 17
)
target_compile_options(bareosfd-python2-module PUBLIC -fno-strict-aliasing)
if(NOT "${Python2_CCSHARED}" STREQUAL "")
@@ -154,6 +155,7 @@ if(Python3_FOUND)
LINK_FLAGS "${Python3_BLDSHARED_FLAGS}"
LINKER_LANGUAGE CXX
INCLUDE_DIRECTORIES "${pymod3_include_dirs}"
+ CXX_STANDARD 17
)
target_compile_options(bareosfd-python3-module PUBLIC -fno-strict-aliasing)
if(NOT "${Python3_CCSHARED}" STREQUAL "")
diff --git a/core/src/plugins/stored/autoxflate/autoxflate-sd.cc b/core/src/plugins/stored/autoxflate/autoxflate-sd.cc
index d7c198a71..9dbe6d0ef 100644
--- a/core/src/plugins/stored/autoxflate/autoxflate-sd.cc
+++ b/core/src/plugins/stored/autoxflate/autoxflate-sd.cc
@@ -481,7 +481,7 @@ static bool SetupAutoDeflation(PluginContext* ctx, DeviceControlRecord* dcr)
!= Z_OK) {
Jmsg(ctx, M_FATAL,
_("autoxflate-sd: Compression deflateParams error: %d\n"), zstat);
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
goto bail_out;
}
break;
@@ -517,7 +517,7 @@ static bool SetupAutoDeflation(PluginContext* ctx, DeviceControlRecord* dcr)
_("autoxflate-sd: Compression fastlzlibSetCompressor error: "
"%d\n"),
zstat);
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
goto bail_out;
}
break;
diff --git a/core/src/stored/ansi_label.cc b/core/src/stored/ansi_label.cc
index c0927ab0c..7ce5c3827 100644
--- a/core/src/stored/ansi_label.cc
+++ b/core/src/stored/ansi_label.cc
@@ -3,7 +3,7 @@
Copyright (C) 2005-2009 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
- Copyright (C) 2013-2021 Bareos GmbH & Co. KG
+ Copyright (C) 2013-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
@@ -57,7 +57,6 @@ static bool SameLabelNames(char* bareos_name, char* ansi_name);
*/
int ReadAnsiIbmLabel(DeviceControlRecord* dcr)
{
- Device* volatile dev = dcr->dev;
JobControlRecord* jcr = dcr->jcr;
char label[80]; /* tape label */
int status, i;
@@ -69,36 +68,36 @@ int ReadAnsiIbmLabel(DeviceControlRecord* dcr)
* If tape read the following EOF mark, on disk do not read.
*/
Dmsg0(100, "Read ansi label.\n");
- if (!dev->IsTape()) { return VOL_OK; }
+ if (!dcr->dev->IsTape()) { return VOL_OK; }
- dev->label_type = B_BAREOS_LABEL; /* assume Bareos label */
+ dcr->dev->label_type = B_BAREOS_LABEL; /* assume Bareos label */
// Read a maximum of 5 records VOL1, HDR1, ... HDR4
for (i = 0; i < 6; i++) {
do {
- status = dev->read(label, sizeof(label));
+ status = dcr->dev->read(label, sizeof(label));
} while (status == -1 && errno == EINTR);
if (status < 0) {
BErrNo be;
- dev->clrerror(-1);
+ dcr->dev->clrerror(-1);
Dmsg1(100, "Read device got: ERR=%s\n", be.bstrerror());
Mmsg2(jcr->errmsg, _("Read error on device %s in ANSI label. ERR=%s\n"),
- dev->archive_device_string, be.bstrerror());
- Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
- dev->VolCatInfo.VolCatErrors++;
+ dcr->dev->archive_device_string, be.bstrerror());
+ Jmsg(jcr, M_ERROR, 0, "%s", dcr->dev->errmsg);
+ dcr->dev->VolCatInfo.VolCatErrors++;
return VOL_IO_ERROR;
}
if (status == 0) {
- if (dev->AtEof()) {
- dev->SetEot(); /* second eof, set eot bit */
+ if (dcr->dev->AtEof()) {
+ dcr->dev->SetEot(); /* second eof, set eot bit */
Dmsg0(100, "EOM on ANSI label\n");
Mmsg0(jcr->errmsg,
_("Insane! End of tape while reading ANSI label.\n"));
return VOL_LABEL_ERROR; /* at EOM this shouldn't happen */
} else {
- dev->SetAteof(); /* set eof state */
+ dcr->dev->SetAteof(); /* set eof state */
}
}
@@ -107,7 +106,7 @@ int ReadAnsiIbmLabel(DeviceControlRecord* dcr)
if (status == 80) {
if (bstrncmp("VOL1", label, 4)) {
ok = true;
- dev->label_type = B_ANSI_LABEL;
+ dcr->dev->label_type = B_ANSI_LABEL;
Dmsg0(100, "Got ANSI VOL1 label\n");
} else {
// Try EBCDIC
@@ -115,7 +114,7 @@ int ReadAnsiIbmLabel(DeviceControlRecord* dcr)
if (bstrncmp("VOL1", label, 4)) {
ok = true;
;
- dev->label_type = B_IBM_LABEL;
+ dcr->dev->label_type = B_IBM_LABEL;
Dmsg0(100, "Found IBM label.\n");
Dmsg0(100, "Got IBM VOL1 label\n");
}
@@ -135,26 +134,26 @@ int ReadAnsiIbmLabel(DeviceControlRecord* dcr)
char* p = &label[4];
char* q;
- FreeVolume(dev);
+ FreeVolume(dcr->dev);
// Store new Volume name
- q = dev->VolHdr.VolumeName;
+ q = dcr->dev->VolHdr.VolumeName;
for (int i = 0; *p != ' ' && i < 6; i++) { *q++ = *p++; }
*q = 0;
Dmsg0(100, "Call reserve_volume\n");
// why is this reserve_volume() needed???? KES
- reserve_volume(dcr, dev->VolHdr.VolumeName);
- dev = dcr->dev; /* may have changed in reserve_volume */
+ reserve_volume(dcr, dcr->dev->VolHdr.VolumeName);
+ dcr->dev = dcr->dev; /* may have changed in reserve_volume */
Dmsg2(100, "Wanted ANSI Vol %s got %6s\n", VolName,
- dev->VolHdr.VolumeName);
+ dcr->dev->VolHdr.VolumeName);
Mmsg2(jcr->errmsg, _("Wanted ANSI Volume \"%s\" got \"%s\"\n"),
- VolName, dev->VolHdr.VolumeName);
+ VolName, dcr->dev->VolHdr.VolumeName);
return VOL_NAME_ERROR;
}
}
break;
case 1:
- if (dev->label_type == B_IBM_LABEL) {
+ if (dcr->dev->label_type == B_IBM_LABEL) {
EbcdicToAscii(label, label, sizeof(label));
}
@@ -173,7 +172,7 @@ int ReadAnsiIbmLabel(DeviceControlRecord* dcr)
&label[4]);
Mmsg1(jcr->errmsg,
_("ANSI/IBM Volume \"%s\" does not belong to Bareos.\n"),
- dev->VolHdr.VolumeName);
+ dcr->dev->VolHdr.VolumeName);
return VOL_NAME_ERROR; /* Not a Bareos label */
}
} else {
@@ -182,14 +181,14 @@ int ReadAnsiIbmLabel(DeviceControlRecord* dcr)
&label[4]);
Mmsg1(jcr->errmsg,
_("ANSI/IBM Volume \"%s\" does not belong to Bareos.\n"),
- dev->VolHdr.VolumeName);
+ dcr->dev->VolHdr.VolumeName);
return VOL_NAME_ERROR; /* Not a Bareos label */
}
}
Dmsg0(100, "Got HDR1 label\n");
break;
case 2:
- if (dev->label_type == B_IBM_LABEL) {
+ if (dcr->dev->label_type == B_IBM_LABEL) {
EbcdicToAscii(label, label, sizeof(label));
}
@@ -207,7 +206,7 @@ int ReadAnsiIbmLabel(DeviceControlRecord* dcr)
return VOL_OK;
}
- if (dev->label_type == B_IBM_LABEL) {
+ if (dcr->dev->label_type == B_IBM_LABEL) {
EbcdicToAscii(label, label, sizeof(label));
}
diff --git a/core/src/stored/append.cc b/core/src/stored/append.cc
index 1c3336ec4..2fdedce74 100644
--- a/core/src/stored/append.cc
+++ b/core/src/stored/append.cc
@@ -181,18 +181,18 @@ bool DoAppendData(JobControlRecord* jcr, BareosSocket* bs, const char* what)
jcr->impl->dcr->device_resource->max_network_buffer_size,
BNET_SETBUF_WRITE)) {
Jmsg0(jcr, M_FATAL, 0, _("Unable to set network buffer size.\n"));
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return false;
}
if (!AcquireDeviceForAppend(jcr->impl->dcr)) {
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return false;
}
if (GeneratePluginEvent(jcr, bSdEventSetupRecordTranslation, jcr->impl->dcr)
!= bRC_OK) {
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return false;
}
@@ -204,13 +204,13 @@ bool DoAppendData(JobControlRecord* jcr, BareosSocket* bs, const char* what)
Dmsg1(50, "Begin append device=%s\n", dev->print_name());
if (!BeginDataSpool(jcr->impl->dcr)) {
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return false;
}
if (!BeginAttributeSpool(jcr)) {
DiscardDataSpool(jcr->impl->dcr);
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return false;
}
@@ -223,7 +223,7 @@ bool DoAppendData(JobControlRecord* jcr, BareosSocket* bs, const char* what)
if (!WriteSessionLabel(jcr->impl->dcr, SOS_LABEL)) {
Jmsg1(jcr, M_FATAL, 0, _("Write session label failed. ERR=%s\n"),
dev->bstrerror());
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
ok = false;
}
if (dev->VolCatInfo.VolCatName[0] == 0) {
@@ -403,7 +403,7 @@ bool DoAppendData(JobControlRecord* jcr, BareosSocket* bs, const char* what)
}
// Create Job status for end of session label
- jcr->setJobStatus(ok ? JS_Terminated : JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(ok ? JS_Terminated : JS_ErrorTerminated);
if (ok && bs == jcr->file_bsock) {
// Terminate connection with FD
@@ -415,7 +415,7 @@ bool DoAppendData(JobControlRecord* jcr, BareosSocket* bs, const char* what)
bs->fsend("3999 Failed append\n");
}
- Dmsg1(200, "Write EOS label JobStatus=%c\n", jcr->JobStatus);
+ Dmsg1(200, "Write EOS label JobStatus=%c\n", jcr->getJobStatus());
/*
* Check if we can still write. This may not be the case
@@ -429,7 +429,7 @@ bool DoAppendData(JobControlRecord* jcr, BareosSocket* bs, const char* what)
dev->bstrerror());
PossibleIncompleteJob(jcr, last_file_index);
}
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
ok = false;
}
Dmsg0(90, "back from write_end_session_label()\n");
@@ -443,7 +443,7 @@ bool DoAppendData(JobControlRecord* jcr, BareosSocket* bs, const char* what)
Dmsg0(100, _("Set ok=FALSE after WriteBlockToDevice.\n"));
PossibleIncompleteJob(jcr, last_file_index);
}
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
ok = false;
} else if (ok && !jcr->IsJobCanceled()) {
// Send attributes of the final partial block of the session
diff --git a/core/src/stored/autochanger.cc b/core/src/stored/autochanger.cc
index 7e8674e7a..4c70f78b0 100644
--- a/core/src/stored/autochanger.cc
+++ b/core/src/stored/autochanger.cc
@@ -3,7 +3,7 @@
Copyright (C) 2002-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
- Copyright (C) 2013-2021 Bareos GmbH & Co. KG
+ Copyright (C) 2013-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
@@ -123,11 +123,10 @@ int AutoloadDevice(DeviceControlRecord* dcr, int writing, BareosSocket* dir)
slot_number_t wanted_slot;
JobControlRecord* jcr = dcr->jcr;
drive_number_t drive;
- Device* volatile dev = dcr->dev;
- if (!dev->AttachedToAutochanger()) {
+ if (!dcr->dev->AttachedToAutochanger()) {
Dmsg1(100, "Device %s is not attached to an autochanger\n",
- dev->print_name());
+ dcr->dev->print_name());
return 0;
}
@@ -138,7 +137,7 @@ int AutoloadDevice(DeviceControlRecord* dcr, int writing, BareosSocket* dir)
return 1; /* nothing to load */
}
- drive = dev->drive_index;
+ drive = dcr->dev->drive_index;
wanted_slot = dcr->VolCatInfo.InChanger ? dcr->VolCatInfo.Slot : 0;
Dmsg3(100, "autoload: slot=%hd InChgr=%d Vol=%s\n", dcr->VolCatInfo.Slot,
dcr->VolCatInfo.InChanger, dcr->getVolCatName());
@@ -162,31 +161,31 @@ int AutoloadDevice(DeviceControlRecord* dcr, int writing, BareosSocket* dir)
changer = GetPoolMemory(PM_FNAME);
if (!IsSlotNumberValid(wanted_slot)) {
// Suppress info when polling
- if (!dev->poll) {
+ if (!dcr->dev->poll) {
Jmsg(
jcr, M_INFO, 0,
_("No slot defined in catalog (slot=%hd) for Volume \"%s\" on %s.\n"),
- wanted_slot, dcr->getVolCatName(), dev->print_name());
+ wanted_slot, dcr->getVolCatName(), dcr->dev->print_name());
Jmsg(jcr, M_INFO, 0,
_("Cartridge change or \"update slots\" may be required.\n"));
}
rtn_stat = 0;
} else if (!dcr->device_resource->changer_name) {
// Suppress info when polling
- if (!dev->poll) {
+ if (!dcr->dev->poll) {
Jmsg(jcr, M_INFO, 0,
_("No \"Changer Device\" for %s. Manual load of Volume may be "
"required.\n"),
- dev->print_name());
+ dcr->dev->print_name());
}
rtn_stat = 0;
} else if (!dcr->device_resource->changer_command) {
// Suppress info when polling
- if (!dev->poll) {
+ if (!dcr->dev->poll) {
Jmsg(jcr, M_INFO, 0,
_("No \"Changer Command\" for %s. Manual load of Volume may be "
"required.\n"),
- dev->print_name());
+ dcr->dev->print_name());
}
rtn_stat = 0;
} else {
@@ -218,7 +217,7 @@ int AutoloadDevice(DeviceControlRecord* dcr, int writing, BareosSocket* dir)
// Load the desired volume.
Dmsg2(100, "Doing changer load slot %hd %s\n", wanted_slot,
- dev->print_name());
+ dcr->dev->print_name());
Jmsg(
jcr, M_INFO, 0,
_("3304 Issuing autochanger \"load slot %hd, drive %hd\" command.\n"),
@@ -226,7 +225,7 @@ int AutoloadDevice(DeviceControlRecord* dcr, int writing, BareosSocket* dir)
dcr->VolCatInfo.Slot = wanted_slot; /* slot to be loaded */
changer = edit_device_codes(
dcr, changer, dcr->device_resource->changer_command, "load");
- dev->close(dcr);
+ dcr->dev->close(dcr);
Dmsg1(200, "Run program=%s\n", changer);
status = RunProgramFullOutput(changer, timeout, results.addr());
if (status == 0) {
@@ -236,10 +235,10 @@ int AutoloadDevice(DeviceControlRecord* dcr, int writing, BareosSocket* dir)
wanted_slot, drive);
Dmsg2(100, "load slot %hd, drive %hd, status is OK.\n", wanted_slot,
drive);
- dev->SetSlotNumber(wanted_slot); /* set currently loaded slot */
- if (dev->vol) {
+ dcr->dev->SetSlotNumber(wanted_slot); /* set currently loaded slot */
+ if (dcr->dev->vol) {
// We just swapped this Volume so it cannot be swapping any more
- dev->vol->ClearSwapping();
+ dcr->dev->vol->ClearSwapping();
}
} else {
BErrNo be;
@@ -257,13 +256,13 @@ int AutoloadDevice(DeviceControlRecord* dcr, int writing, BareosSocket* dir)
_("3992 Bad autochanger \"load slot %hd, drive %hd\": "
"ERR=%s.\nResults=%s\n"),
wanted_slot, drive, be.bstrerror(), results.c_str());
- dev->SetSlotNumber(-1); /* mark unknown */
+ dcr->dev->SetSlotNumber(-1); /* mark unknown */
}
Dmsg2(100, "load slot %hd status=%d\n", wanted_slot, status);
UnlockChanger(dcr);
} else {
- status = 0; /* we got what we want */
- dev->SetSlotNumber(wanted_slot); /* set currently loaded slot */
+ status = 0; /* we got what we want */
+ dcr->dev->SetSlotNumber(wanted_slot); /* set currently loaded slot */
}
Dmsg1(100, "After changer, status=%d\n", status);
diff --git a/core/src/stored/bscan.cc b/core/src/stored/bscan.cc
index 041f0ee17..6c5fbb5da 100644
--- a/core/src/stored/bscan.cc
+++ b/core/src/stored/bscan.cc
@@ -699,7 +699,7 @@ static bool RecordCb(DeviceControlRecord* dcr, DeviceRecord* rec)
UpdateJobRecord(db, &jr, &elabel, rec);
mjcr->end_time = jr.EndTime;
- mjcr->setJobStatus(JS_Terminated);
+ mjcr->setJobStatusWithPriorityCheck(JS_Terminated);
// Create JobMedia record
mjcr->impl->read_dcr->VolLastIndex = dcr->VolLastIndex;
@@ -1258,7 +1258,7 @@ static bool UpdateJobRecord(BareosDb* db,
jr->JobId = mjcr->JobId;
jr->JobStatus = elabel->JobStatus;
- mjcr->JobStatus = elabel->JobStatus;
+ mjcr->setJobStatus(elabel->JobStatus);
jr->JobFiles = elabel->JobFiles;
if (jr->JobFiles > 0) { /* If we found files, force PurgedFiles */
jr->PurgedFiles = 0;
@@ -1294,7 +1294,7 @@ static bool UpdateJobRecord(BareosDb* db,
char sdt[50], edt[50];
char ec1[30], ec2[30], ec3[30];
- switch (mjcr->JobStatus) {
+ switch (mjcr->getJobStatus()) {
case JS_Terminated:
TermMsg = _("Backup OK");
break;
@@ -1310,7 +1310,7 @@ static bool UpdateJobRecord(BareosDb* db,
break;
default:
TermMsg = term_code;
- sprintf(term_code, _("Job Termination code: %d"), mjcr->JobStatus);
+ sprintf(term_code, _("Job Termination code: %d"), mjcr->getJobStatus());
break;
}
bstrftime(sdt, sizeof(sdt), mjcr->start_time);
@@ -1427,7 +1427,7 @@ static JobControlRecord* create_jcr(JobDbRecord* jr,
jobjcr->impl = new JobControlRecordPrivate;
jobjcr->setJobType(jr->JobType);
jobjcr->setJobLevel(jr->JobLevel);
- jobjcr->JobStatus = jr->JobStatus;
+ jobjcr->setJobStatus(jr->JobStatus);
bstrncpy(jobjcr->Job, jr->Job, sizeof(jobjcr->Job));
jobjcr->JobId = JobId; /* this is JobId on tape */
jobjcr->sched_time = jr->SchedTime;
diff --git a/core/src/stored/btape.cc b/core/src/stored/btape.cc
index 5cacbf439..9a1c63a1a 100644
--- a/core/src/stored/btape.cc
+++ b/core/src/stored/btape.cc
@@ -2145,7 +2145,7 @@ static void fillcmd()
*/
Dmsg0(100, "just before acquire_device\n");
if (!AcquireDeviceForAppend(dcr)) {
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
exit_code = 1;
return;
}
@@ -2154,7 +2154,7 @@ static void fillcmd()
Dmsg0(100, "Just after AcquireDeviceForAppend\n");
// Write Begin Session Record
if (!WriteSessionLabel(dcr, SOS_LABEL)) {
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
Jmsg1(jcr, M_FATAL, 0, _("Write session label failed. ERR=%s\n"),
dev->bstrerror());
ok = false;
@@ -2255,10 +2255,10 @@ static void fillcmd()
Dmsg0(100, "Write_end_session_label()\n");
/* Create Job status for end of session label */
if (!JobCanceled(jcr) && ok) {
- jcr->setJobStatus(JS_Terminated);
+ jcr->setJobStatusWithPriorityCheck(JS_Terminated);
} else if (!ok) {
Pmsg0(000, _("Job canceled.\n"));
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
exit_code = 1;
}
if (!WriteSessionLabel(dcr, EOS_LABEL)) {
diff --git a/core/src/stored/butil.cc b/core/src/stored/butil.cc
index feb6215e6..d8bea286a 100644
--- a/core/src/stored/butil.cc
+++ b/core/src/stored/butil.cc
@@ -73,7 +73,7 @@ JobControlRecord* SetupDummyJcr(const char* name,
jcr->JobId = 0;
jcr->setJobType(JT_CONSOLE);
jcr->setJobLevel(L_FULL);
- jcr->JobStatus = JS_Terminated;
+ jcr->setJobStatus(JS_Terminated);
jcr->where = strdup("");
jcr->impl->job_name = GetPoolMemory(PM_FNAME);
PmStrcpy(jcr->impl->job_name, "Dummy.Job.Name");
diff --git a/core/src/stored/dev.h b/core/src/stored/dev.h
index ef4225313..4aca812ad 100644
--- a/core/src/stored/dev.h
+++ b/core/src/stored/dev.h
@@ -65,6 +65,8 @@
#include "stored/volume_catalog_info.h"
#include <vector>
+#include <atomic>
+
template <typename T> class dlist;
namespace storagedaemon {
@@ -203,7 +205,7 @@ class Device {
public:
Device() = default;
virtual ~Device();
- Device* volatile swap_dev{}; /**< Swap vol from this device */
+ Device* swap_dev{}; /**< Swap vol from this device */
std::vector<DeviceControlRecord*> attached_dcrs; /**< Attached DeviceControlRecords */
pthread_mutex_t mutex_ = PTHREAD_MUTEX_INITIALIZER; /**< Access control */
pthread_mutex_t spool_mutex = PTHREAD_MUTEX_INITIALIZER; /**< Mutex for updating spool_size */
diff --git a/core/src/stored/device_control_record.h b/core/src/stored/device_control_record.h
index 9ae738d0c..b2c349656 100644
--- a/core/src/stored/device_control_record.h
+++ b/core/src/stored/device_control_record.h
@@ -72,7 +72,7 @@ class DeviceControlRecord {
JobControlRecord* jcr{}; /**< Pointer to JobControlRecord */
pthread_mutex_t mutex_ = PTHREAD_MUTEX_INITIALIZER; /**< Access control */
pthread_mutex_t r_mutex = PTHREAD_MUTEX_INITIALIZER; /**< rLock pre-mutex */
- Device* volatile dev{}; /**< Pointer to device */
+ Device* dev{}; /**< Pointer to device */
DeviceResource* device_resource{}; /**< Pointer to device resource */
DeviceBlock* block{}; /**< Pointer to current block */
DeviceRecord* rec{}; /**< Pointer to record being processed */
diff --git a/core/src/stored/dir_cmd.cc b/core/src/stored/dir_cmd.cc
index 078b21d1b..3a91ad245 100644
--- a/core/src/stored/dir_cmd.cc
+++ b/core/src/stored/dir_cmd.cc
@@ -517,8 +517,8 @@ static bool CancelCmd(JobControlRecord* cjcr)
}
}
- oldStatus = jcr->JobStatus;
- jcr->setJobStatus(status);
+ oldStatus = jcr->getJobStatus();
+ jcr->setJobStatusWithPriorityCheck(status);
Dmsg2(800, "Cancel JobId=%d %p\n", jcr->JobId, jcr);
if (!jcr->authenticated
diff --git a/core/src/stored/fd_cmds.cc b/core/src/stored/fd_cmds.cc
index 30e2ad4c6..917061b6d 100644
--- a/core/src/stored/fd_cmds.cc
+++ b/core/src/stored/fd_cmds.cc
@@ -3,7 +3,7 @@
Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
- Copyright (C) 2013-2021 Bareos GmbH & Co. KG
+ Copyright (C) 2013-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
@@ -134,7 +134,7 @@ void* HandleFiledConnection(BareosSocket* fd, char* job_name)
if (!AuthenticateFiledaemon(jcr)) {
Dmsg1(50, "Authentication failed Job %s\n", jcr->Job);
Jmsg(jcr, M_FATAL, 0, _("Unable to authenticate File daemon\n"));
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
} else {
utime_t now;
@@ -177,11 +177,11 @@ void RunJob(JobControlRecord* jcr)
jcr->end_time = time(NULL);
DequeueMessages(jcr); /* send any queued messages */
- jcr->setJobStatus(JS_Terminated);
+ jcr->setJobStatusWithPriorityCheck(JS_Terminated);
GeneratePluginEvent(jcr, bSdEventJobEnd);
- dir->fsend(Job_end, jcr->Job, jcr->JobStatus, jcr->JobFiles,
+ dir->fsend(Job_end, jcr->Job, jcr->getJobStatus(), jcr->JobFiles,
edit_uint64(jcr->JobBytes, ec1), jcr->JobErrors);
dir->signal(BNET_EOD); /* send EOD to Director daemon */
@@ -220,7 +220,7 @@ void DoFdCommands(JobControlRecord* jcr)
} else {
Jmsg0(jcr, M_FATAL, 0, _("Command error with FD, hanging up.\n"));
}
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
}
quit = true;
}
@@ -318,7 +318,7 @@ static bool AppendCloseSession(JobControlRecord* jcr)
}
// Send final statistics to File daemon
- fd->fsend(OK_close, jcr->JobStatus);
+ fd->fsend(OK_close, jcr->getJobStatus());
Dmsg1(120, ">filed: %s", fd->msg);
fd->signal(BNET_EOD); /* send EOD to File daemon */
@@ -414,7 +414,7 @@ static bool ReadCloseSession(JobControlRecord* jcr)
}
// Send final close msg to File daemon
- fd->fsend(OK_close, jcr->JobStatus);
+ fd->fsend(OK_close, jcr->getJobStatus());
Dmsg1(160, ">filed: %s", fd->msg);
fd->signal(BNET_EOD); /* send EOD to File daemon */
diff --git a/core/src/stored/job.cc b/core/src/stored/job.cc
index fd209fd79..623ca8aca 100644
--- a/core/src/stored/job.cc
+++ b/core/src/stored/job.cc
@@ -98,7 +98,7 @@ bool job_cmd(JobControlRecord* jcr)
PmStrcpy(jcr->errmsg, dir->msg);
dir->fsend(BAD_job, status, jcr->errmsg);
Dmsg1(100, ">dird: %s", dir->msg);
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return false;
}
@@ -346,7 +346,7 @@ bool FinishCmd(JobControlRecord* jcr)
jcr->end_time = time(NULL);
DequeueMessages(jcr); /* send any queued messages */
- jcr->setJobStatus(JS_Terminated);
+ jcr->setJobStatusWithPriorityCheck(JS_Terminated);
switch (jcr->getJobType()) {
case JT_BACKUP:
@@ -361,7 +361,7 @@ bool FinishCmd(JobControlRecord* jcr)
GeneratePluginEvent(jcr, bSdEventJobEnd);
- dir->fsend(Job_end, jcr->Job, jcr->JobStatus, jcr->JobFiles,
+ dir->fsend(Job_end, jcr->Job, jcr->getJobStatus(), jcr->JobFiles,
edit_uint64(jcr->JobBytes, ec1), jcr->JobErrors);
dir->signal(BNET_EOD); /* send EOD to Director daemon */
diff --git a/core/src/stored/label.cc b/core/src/stored/label.cc
index 1906d9cd7..c2f6e1a80 100644
--- a/core/src/stored/label.cc
+++ b/core/src/stored/label.cc
@@ -3,7 +3,7 @@
Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
- Copyright (C) 2013-2021 Bareos GmbH & Co. KG
+ Copyright (C) 2013-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
@@ -69,7 +69,6 @@ static void CreateVolumeLabelRecord(DeviceControlRecord* dcr,
int ReadDevVolumeLabel(DeviceControlRecord* dcr)
{
JobControlRecord* jcr = dcr->jcr;
- Device* volatile dev = dcr->dev;
char* VolName = dcr->VolumeName;
DeviceRecord* record;
bool ok = false;
@@ -81,31 +80,33 @@ int ReadDevVolumeLabel(DeviceControlRecord* dcr)
* We always write the label in an 64512 byte / 63k block.
* so we never have problems reading the volume label.
*/
- dev->SetLabelBlocksize(dcr);
+ dcr->dev->SetLabelBlocksize(dcr);
Dmsg5(100,
"Enter ReadVolumeLabel res=%d device=%s vol=%s dev_Vol=%s "
"max_blocksize=%u\n",
- dev->NumReserved(), dev->print_name(), VolName,
- dev->VolHdr.VolumeName[0] ? dev->VolHdr.VolumeName : "*NULL*",
- dev->max_block_size);
+ dcr->dev->NumReserved(), dcr->dev->print_name(), VolName,
+ dcr->dev->VolHdr.VolumeName[0] ? dcr->dev->VolHdr.VolumeName : "*NULL*",
+ dcr->dev->max_block_size);
- if (!dev->IsOpen()) {
- if (!dev->open(dcr, DeviceMode::OPEN_READ_ONLY)) { return VOL_IO_ERROR; }
+ if (!dcr->dev->IsOpen()) {
+ if (!dcr->dev->open(dcr, DeviceMode::OPEN_READ_ONLY)) {
+ return VOL_IO_ERROR;
+ }
}
- dev->ClearLabeled();
- dev->ClearAppend();
- dev->ClearRead();
- dev->label_type = B_BAREOS_LABEL;
+ dcr->dev->ClearLabeled();
+ dcr->dev->ClearAppend();
+ dcr->dev->ClearRead();
+ dcr->dev->label_type = B_BAREOS_LABEL;
- if (!dev->rewind(dcr)) {
+ if (!dcr->dev->rewind(dcr)) {
Mmsg(jcr->errmsg, _("Couldn't rewind device %s: ERR=%s\n"),
- dev->print_name(), dev->print_errmsg());
+ dcr->dev->print_name(), dcr->dev->print_errmsg());
Dmsg1(130, "return VOL_NO_MEDIA: %s", jcr->errmsg);
return VOL_NO_MEDIA;
}
- bstrncpy(dev->VolHdr.Id, "**error**", sizeof(dev->VolHdr.Id));
+ bstrncpy(dcr->dev->VolHdr.Id, "**error**", sizeof(dcr->dev->VolHdr.Id));
/*
* The stored plugin handling the bSdEventLabelRead event can abort
@@ -119,21 +120,21 @@ int ReadDevVolumeLabel(DeviceControlRecord* dcr)
// Read ANSI/IBM label if so requested
want_ansi_label = dcr->VolCatInfo.LabelType != B_BAREOS_LABEL
|| dcr->device_resource->label_type != B_BAREOS_LABEL;
- if (want_ansi_label || dev->HasCap(CAP_CHECKLABELS)) {
+ if (want_ansi_label || dcr->dev->HasCap(CAP_CHECKLABELS)) {
status = ReadAnsiIbmLabel(dcr);
// If we want a label and didn't find it, return error
if (want_ansi_label && status != VOL_OK) { goto bail_out; }
if (status == VOL_NAME_ERROR || status == VOL_LABEL_ERROR) {
Mmsg(jcr->errmsg,
_("Wrong Volume mounted on device %s: Wanted %s have %s\n"),
- dev->print_name(), VolName, dev->VolHdr.VolumeName);
- if (!dev->poll && jcr->impl->label_errors++ > 100) {
+ dcr->dev->print_name(), VolName, dcr->dev->VolHdr.VolumeName);
+ if (!dcr->dev->poll && jcr->impl->label_errors++ > 100) {
Jmsg(jcr, M_FATAL, 0, _("Too many tries: %s"), jcr->errmsg);
}
goto bail_out;
}
if (status != VOL_OK) { /* Not an ANSI/IBM label, so re-read */
- dev->rewind(dcr);
+ dcr->dev->rewind(dcr);
} else {
have_ansi_label = true;
}
@@ -149,30 +150,30 @@ int ReadDevVolumeLabel(DeviceControlRecord* dcr)
Mmsg(jcr->errmsg,
_("Requested Volume \"%s\" on %s is not a Bareos "
"labeled Volume, because: ERR=%s"),
- NPRT(VolName), dev->print_name(), dev->print_errmsg());
+ NPRT(VolName), dcr->dev->print_name(), dcr->dev->print_errmsg());
Dmsg1(130, "%s", jcr->errmsg);
} else if (!ReadRecordFromBlock(dcr, record)) {
Mmsg(jcr->errmsg, _("Could not read Volume label from block.\n"));
Dmsg1(130, "%s", jcr->errmsg);
- } else if (!UnserVolumeLabel(dev, record)) {
+ } else if (!UnserVolumeLabel(dcr->dev, record)) {
Mmsg(jcr->errmsg, _("Could not UnSerialize Volume label: ERR=%s\n"),
- dev->print_errmsg());
+ dcr->dev->print_errmsg());
Dmsg1(130, "%s", jcr->errmsg);
- } else if (!bstrcmp(dev->VolHdr.Id, BareosId)
- && !bstrcmp(dev->VolHdr.Id, OldBaculaId)
- && !bstrcmp(dev->VolHdr.Id, OlderBaculaId)) {
- Mmsg(jcr->errmsg, _("Volume Header Id bad: %s\n"), dev->VolHdr.Id);
+ } else if (!bstrcmp(dcr->dev->VolHdr.Id, BareosId)
+ && !bstrcmp(dcr->dev->VolHdr.Id, OldBaculaId)
+ && !bstrcmp(dcr->dev->VolHdr.Id, OlderBaculaId)) {
+ Mmsg(jcr->errmsg, _("Volume Header Id bad: %s\n"), dcr->dev->VolHdr.Id);
Dmsg1(130, "%s", jcr->errmsg);
} else {
ok = true;
}
FreeRecord(record); /* finished reading Volume record */
- if (!dev->IsVolumeToUnload()) { dev->ClearUnload(); }
+ if (!dcr->dev->IsVolumeToUnload()) { dcr->dev->ClearUnload(); }
if (!ok) {
if (forge_on || jcr->impl->ignore_label_errors) {
- dev->SetLabeled(); /* set has Bareos label */
+ dcr->dev->SetLabeled(); /* set has Bareos label */
Jmsg(jcr, M_ERROR, 0, "%s", jcr->errmsg);
goto ok_out;
}
@@ -186,11 +187,11 @@ int ReadDevVolumeLabel(DeviceControlRecord* dcr)
* then read the Bareos Volume label. Now we need to
* make sure we have the right Volume.
*/
- if (dev->VolHdr.VerNum != BareosTapeVersion
- && dev->VolHdr.VerNum != OldCompatibleBareosTapeVersion1) {
+ if (dcr->dev->VolHdr.VerNum != BareosTapeVersion
+ && dcr->dev->VolHdr.VerNum != OldCompatibleBareosTapeVersion1) {
Mmsg(jcr->errmsg,
_("Volume on %s has wrong Bareos version. Wanted %d got %d\n"),
- dev->print_name(), BareosTapeVersion, dev->VolHdr.VerNum);
+ dcr->dev->print_name(), BareosTapeVersion, dcr->dev->VolHdr.VerNum);
Dmsg1(130, "VOL_VERSION_ERROR: %s", jcr->errmsg);
status = VOL_VERSION_ERROR;
goto bail_out;
@@ -200,12 +201,12 @@ int ReadDevVolumeLabel(DeviceControlRecord* dcr)
* We are looking for either an unused Bareos tape (PRE_LABEL) or
* a Bareos volume label (VOL_LABEL)
*/
- if (dev->VolHdr.LabelType != PRE_LABEL
- && dev->VolHdr.LabelType != VOL_LABEL) {
+ if (dcr->dev->VolHdr.LabelType != PRE_LABEL
+ && dcr->dev->VolHdr.LabelType != VOL_LABEL) {
Mmsg(jcr->errmsg, _("Volume on %s has bad Bareos label type: %x\n"),
- dev->print_name(), dev->VolHdr.LabelType);
+ dcr->dev->print_name(), dcr->dev->VolHdr.LabelType);
Dmsg1(130, "%s", jcr->errmsg);
- if (!dev->poll && jcr->impl->label_errors++ > 100) {
+ if (!dcr->dev->poll && jcr->impl->label_errors++ > 100) {
Jmsg(jcr, M_FATAL, 0, _("Too many tries: %s"), jcr->errmsg);
}
Dmsg0(150, "return VOL_LABEL_ERROR\n");
@@ -213,22 +214,22 @@ int ReadDevVolumeLabel(DeviceControlRecord* dcr)
goto bail_out;
}
- dev->SetLabeled(); /* set has Bareos label */
+ dcr->dev->SetLabeled(); /* set has Bareos label */
/* Compare Volume Names */
Dmsg2(130, "Compare Vol names: VolName=%s hdr=%s\n", VolName ? VolName : "*",
- dev->VolHdr.VolumeName);
+ dcr->dev->VolHdr.VolumeName);
if (VolName && *VolName && *VolName != '*'
- && !bstrcmp(dev->VolHdr.VolumeName, VolName)) {
+ && !bstrcmp(dcr->dev->VolHdr.VolumeName, VolName)) {
Mmsg(jcr->errmsg,
_("Wrong Volume mounted on device %s: Wanted %s have %s\n"),
- dev->print_name(), VolName, dev->VolHdr.VolumeName);
+ dcr->dev->print_name(), VolName, dcr->dev->VolHdr.VolumeName);
Dmsg1(130, "%s", jcr->errmsg);
/*
* Cancel Job if too many label errors
* => we are in a loop
*/
- if (!dev->poll && jcr->impl->label_errors++ > 100) {
+ if (!dcr->dev->poll && jcr->impl->label_errors++ > 100) {
Jmsg(jcr, M_FATAL, 0, "Too many tries: %s", jcr->errmsg);
}
Dmsg0(150, "return VOL_NAME_ERROR\n");
@@ -236,12 +237,12 @@ int ReadDevVolumeLabel(DeviceControlRecord* dcr)
goto bail_out;
}
- if (debug_level >= 200) { DumpVolumeLabel(dev); }
+ if (debug_level >= 200) { DumpVolumeLabel(dcr->dev); }
Dmsg0(130, "Leave ReadVolumeLabel() VOL_OK\n");
// If we are a streaming device, we only get one chance to read
- if (!dev->HasCap(CAP_STREAM)) {
- dev->rewind(dcr);
+ if (!dcr->dev->HasCap(CAP_STREAM)) {
+ dcr->dev->rewind(dcr);
if (have_ansi_label) {
status = ReadAnsiIbmLabel(dcr);
// If we want a label and didn't find it, return error
@@ -249,12 +250,12 @@ int ReadDevVolumeLabel(DeviceControlRecord* dcr)
}
}
- Dmsg1(100, "Call reserve_volume=%s\n", dev->VolHdr.VolumeName);
- if (reserve_volume(dcr, dev->VolHdr.VolumeName) == NULL) {
+ Dmsg1(100, "Call reserve_volume=%s\n", dcr->dev->VolHdr.VolumeName);
+ if (reserve_volume(dcr, dcr->dev->VolHdr.VolumeName) == NULL) {
Mmsg2(jcr->errmsg, _("Could not reserve volume %s on %s\n"),
- dev->VolHdr.VolumeName, dev->print_name());
- Dmsg2(150, "Could not reserve volume %s on %s\n", dev->VolHdr.VolumeName,
- dev->print_name());
+ dcr->dev->VolHdr.VolumeName, dcr->dev->print_name());
+ Dmsg2(150, "Could not reserve volume %s on %s\n",
+ dcr->dev->VolHdr.VolumeName, dcr->dev->print_name());
status = VOL_NAME_ERROR;
goto bail_out;
}
@@ -279,13 +280,13 @@ ok_out:
* Reset blocksizes from volinfo to device as we set blocksize to
* DEFAULT_BLOCK_SIZE to read the label
*/
- dev->SetBlocksizes(dcr);
+ dcr->dev->SetBlocksizes(dcr);
return VOL_OK;
bail_out:
EmptyBlock(dcr->block);
- dev->rewind(dcr);
+ dcr->dev->rewind(dcr);
Dmsg1(150, "return %d\n", status);
return status;
}
@@ -623,7 +624,7 @@ static void CreateSessionLabel(DeviceControlRecord* dcr,
ser_uint32(jcr->JobErrors);
/* Added in VerNum 11 */
- ser_uint32(jcr->JobStatus);
+ ser_uint32(jcr->getJobStatus());
}
SerEnd(rec->data, SER_LENGTH_Session_Label);
rec->data_len = SerLength(rec->data);
diff --git a/core/src/stored/mac.cc b/core/src/stored/mac.cc
index 38b952eff..52936d1a6 100644
--- a/core/src/stored/mac.cc
+++ b/core/src/stored/mac.cc
@@ -158,7 +158,7 @@ static bool CloneRecordInternally(DeviceControlRecord* dcr, DeviceRecord* rec)
if (!WriteSessionLabel(jcr->impl->dcr, SOS_LABEL)) {
Jmsg1(jcr, M_FATAL, 0, _("Write session label failed. ERR=%s\n"),
dev->bstrerror());
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
retval = false;
goto bail_out;
}
@@ -627,7 +627,7 @@ bool DoMacRun(JobControlRecord* jcr)
}
bail_out:
- if (!ok) { jcr->setJobStatus(JS_ErrorTerminated); }
+ if (!ok) { jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated); }
if (!acquire_fail && !jcr->impl->remote_replicate && jcr->impl->dcr) {
/*
@@ -643,8 +643,8 @@ bail_out:
memorize current JobStatus and set to
JS_Terminated to write into EOS_LABEL
*/
- char currentJobStatus = jcr->JobStatus;
- jcr->setJobStatus(JS_Terminated);
+ char currentJobStatus = jcr->getJobStatus();
+ jcr->setJobStatusWithPriorityCheck(JS_Terminated);
// Write End Of Session Label
DeviceControlRecord* dcr = jcr->impl->dcr;
@@ -655,11 +655,11 @@ bail_out:
Jmsg1(jcr, M_FATAL, 0, _("Error writing end session label. ERR=%s\n"),
dev->bstrerror());
}
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
ok = false;
} else {
/* restore JobStatus */
- jcr->setJobStatus(currentJobStatus);
+ jcr->setJobStatusWithPriorityCheck(currentJobStatus);
}
// Flush out final partial block of this session
if (!jcr->impl->dcr->WriteBlockToDevice()) {
@@ -708,12 +708,12 @@ bail_out:
Dmsg0(30, "Done reading.\n");
jcr->end_time = time(NULL);
DequeueMessages(jcr); /* send any queued messages */
- if (ok) { jcr->setJobStatus(JS_Terminated); }
+ if (ok) { jcr->setJobStatusWithPriorityCheck(JS_Terminated); }
GeneratePluginEvent(jcr, bSdEventJobEnd);
- dir->fsend(Job_end, jcr->Job, jcr->JobStatus, jcr->JobFiles,
+ dir->fsend(Job_end, jcr->Job, jcr->getJobStatus(), jcr->JobFiles,
edit_uint64(jcr->JobBytes, ec1), jcr->JobErrors);
- Dmsg4(100, Job_end, jcr->Job, jcr->JobStatus, jcr->JobFiles, ec1);
+ Dmsg4(100, Job_end, jcr->Job, jcr->getJobStatus(), jcr->JobFiles, ec1);
dir->signal(BNET_EOD); /* send EOD to Director daemon */
FreePlugins(jcr); /* release instantiated plugins */
diff --git a/core/src/stored/ndmp_tape.cc b/core/src/stored/ndmp_tape.cc
index 5e0f15447..ada800e5f 100644
--- a/core/src/stored/ndmp_tape.cc
+++ b/core/src/stored/ndmp_tape.cc
@@ -716,7 +716,7 @@ extern "C" ndmp9_error bndmp_tape_open(struct ndm_session* sess,
return NDMP9_NO_ERR;
bail_out:
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return NDMP9_NO_DEVICE_ERR;
}
@@ -832,7 +832,7 @@ extern "C" ndmp9_error bndmp_tape_write(struct ndm_session* sess,
*done_count = count;
err = NDMP9_NO_ERR;
} else {
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
err = NDMP9_IO_ERR;
}
@@ -886,7 +886,7 @@ extern "C" ndmp9_error bndmp_tape_read(struct ndm_session* sess,
err = NDMP9_NO_ERR;
}
} else {
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
err = NDMP9_IO_ERR;
}
@@ -939,7 +939,7 @@ void EndOfNdmpBackup(JobControlRecord* jcr)
/* Check if we can still write. This may not be the case
* if we are at the end of the tape or we got a fatal I/O error. */
if (dcr->dev && dcr->dev->CanWrite()) {
- Dmsg1(200, "Write EOS label JobStatus=%c\n", jcr->JobStatus);
+ Dmsg1(200, "Write EOS label JobStatus=%c\n", jcr->getJobStatus());
if (!WriteSessionLabel(dcr, EOS_LABEL)) {
/* Print only if JobStatus JS_Terminated and not cancelled to avoid
@@ -948,7 +948,7 @@ void EndOfNdmpBackup(JobControlRecord* jcr)
Jmsg1(jcr, M_FATAL, 0, _("Error writing end session label. ERR=%s\n"),
dcr->dev->bstrerror());
}
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
}
Dmsg0(90, "back from write_end_session_label()\n");
@@ -961,7 +961,7 @@ void EndOfNdmpBackup(JobControlRecord* jcr)
Jmsg2(jcr, M_FATAL, 0, _("Fatal append error on device %s: ERR=%s\n"),
dcr->dev->print_name(), dcr->dev->bstrerror());
}
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
}
}
diff --git a/core/src/stored/read.cc b/core/src/stored/read.cc
index 3470ecac7..f418d61eb 100644
--- a/core/src/stored/read.cc
+++ b/core/src/stored/read.cc
@@ -3,7 +3,7 @@
Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
- Copyright (C) 2013-2020 Bareos GmbH & Co. KG
+ Copyright (C) 2013-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
@@ -84,7 +84,7 @@ bool DoReadData(JobControlRecord* jcr)
// Let any SD plugin know now its time to setup the record translation infra.
if (GeneratePluginEvent(jcr, bSdEventSetupRecordTranslation, dcr) != bRC_OK) {
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
return false;
}
diff --git a/core/src/stored/reserve.cc b/core/src/stored/reserve.cc
index bf353714d..a3ab22a79 100644
--- a/core/src/stored/reserve.cc
+++ b/core/src/stored/reserve.cc
@@ -80,7 +80,7 @@ bool use_cmd(JobControlRecord* jcr)
{
// Get the device, media, and pool information
if (!UseDeviceCmd(jcr)) {
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
memset(jcr->sd_auth_key, 0, strlen(jcr->sd_auth_key));
return false;
}
diff --git a/core/src/stored/sd_cmds.cc b/core/src/stored/sd_cmds.cc
index 6761ad6fb..9cfc6bb0c 100644
--- a/core/src/stored/sd_cmds.cc
+++ b/core/src/stored/sd_cmds.cc
@@ -134,7 +134,9 @@ void* handle_stored_connection(BareosSocket* sd, char* job_name)
jcr->Job);
}
- if (!jcr->authenticated) { jcr->setJobStatus(JS_ErrorTerminated); }
+ if (!jcr->authenticated) {
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
+ }
pthread_cond_signal(&jcr->impl->job_start_wait); /* wake waiting job */
FreeJcr(jcr);
@@ -174,7 +176,7 @@ static void DoSdCommands(JobControlRecord* jcr)
} else {
Jmsg0(jcr, M_FATAL, 0, _("Command error with SD, hanging up.\n"));
}
- jcr->setJobStatus(JS_ErrorTerminated);
+ jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated);
}
quit = true;
}
@@ -256,12 +258,12 @@ bool DoListenRun(JobControlRecord* jcr)
jcr->end_time = time(NULL);
DequeueMessages(jcr); /* send any queued messages */
- jcr->setJobStatus(JS_Terminated);
+ jcr->setJobStatusWithPriorityCheck(JS_Terminated);
cleanup:
GeneratePluginEvent(jcr, bSdEventJobEnd);
- dir->fsend(Job_end, jcr->Job, jcr->JobStatus, jcr->JobFiles,
+ dir->fsend(Job_end, jcr->Job, jcr->getJobStatus(), jcr->JobFiles,
edit_uint64(jcr->JobBytes, ec1), jcr->JobErrors);
dir->signal(BNET_EOD); /* send EOD to Director daemon */
diff --git a/core/src/stored/sd_plugins.cc b/core/src/stored/sd_plugins.cc
index 943ba9480..53d4ed56a 100644
--- a/core/src/stored/sd_plugins.cc
+++ b/core/src/stored/sd_plugins.cc
@@ -736,9 +736,9 @@ static bRC bareosGetValue(PluginContext* ctx, bsdrVariable var, void* value)
NPRT(*((char**)value)));
break;
case bsdVarJobStatus:
- *((int*)value) = jcr->JobStatus;
+ *((int*)value) = jcr->getJobStatus();
Dmsg1(debuglevel, "sd-plugin: return bsdVarJobStatus=%c\n",
- jcr->JobStatus);
+ jcr->getJobStatus());
break;
case bsdVarVolumeName:
if (jcr->impl->dcr) {
diff --git a/core/src/stored/spool.cc b/core/src/stored/spool.cc
index 5b567eaca..770421aa6 100644
--- a/core/src/stored/spool.cc
+++ b/core/src/stored/spool.cc
@@ -265,12 +265,12 @@ static bool DespoolData(DeviceControlRecord* dcr, bool commit)
"...\n"),
jcr->impl->dcr->VolumeName,
edit_uint64_with_commas(jcr->impl->dcr->job_spool_size, ec1));
- jcr->setJobStatus(JS_DataCommitting);
+ jcr->setJobStatusWithPriorityCheck(JS_DataCommitting);
} else {
Jmsg(jcr, M_INFO, 0,
_("Writing spooled data to Volume. Despooling %s bytes ...\n"),
edit_uint64_with_commas(jcr->impl->dcr->job_spool_size, ec1));
- jcr->setJobStatus(JS_DataDespooling);
+ jcr->setJobStatusWithPriorityCheck(JS_DataDespooling);
}
jcr->sendJobStatus(JS_DataDespooling);
dcr->despool_wait = true;
@@ -334,7 +334,7 @@ static bool DespoolData(DeviceControlRecord* dcr, bool commit)
Dmsg2(000, "Fatal append error on device %s: ERR=%s\n",
dcr->dev->print_name(), dcr->dev->bstrerror());
/* Force in case Incomplete set */
- jcr->forceJobStatus(JS_FatalError);
+ jcr->setJobStatus(JS_FatalError);
}
Dmsg3(800, "Write block ok=%d FI=%d LI=%d\n", ok, block->FirstIndex,
block->LastIndex);
@@ -354,7 +354,7 @@ static bool DespoolData(DeviceControlRecord* dcr, bool commit)
Jmsg2(jcr, M_FATAL, 0,
_("Could not create JobMedia record for Volume=\"%s\" Job=%s\n"),
dcr->getVolCatName(), jcr->Job);
- jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
+ jcr->setJobStatus(JS_FatalError); /* override any Incomplete */
}
/* Set new file/block parameters for current dcr */
SetNewFileParameters(dcr);
@@ -458,7 +458,7 @@ static int ReadBlockFromSpoolFile(DeviceControlRecord* dcr)
_("Spool header read error. Wanted %u bytes, got %d\n"), rlen,
status);
}
- jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
+ jcr->setJobStatus(JS_FatalError); /* override any Incomplete */
return RB_ERROR;
}
rlen = hdr.len;
@@ -467,7 +467,7 @@ static int ReadBlockFromSpoolFile(DeviceControlRecord* dcr)
rlen);
Jmsg2(jcr, M_FATAL, 0, _("Spool block too big. Max %u bytes, got %u\n"),
block->buf_len, rlen);
- jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
+ jcr->setJobStatus(JS_FatalError); /* override any Incomplete */
return RB_ERROR;
}
status = read(dcr->spool_fd, (char*)block->buf, (size_t)rlen);
@@ -476,7 +476,7 @@ static int ReadBlockFromSpoolFile(DeviceControlRecord* dcr)
status);
Jmsg2(dcr->jcr, M_FATAL, 0,
_("Spool data read error. Wanted %u bytes, got %d\n"), rlen, status);
- jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
+ jcr->setJobStatus(JS_FatalError); /* override any Incomplete */
return RB_ERROR;
}
/* Setup write pointers */
@@ -582,7 +582,7 @@ static bool WriteSpoolHeader(DeviceControlRecord* dcr)
Jmsg(jcr, M_FATAL, 0, _("Error writing header to spool file. ERR=%s\n"),
be.bstrerror());
- jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
+ jcr->setJobStatus(JS_FatalError); /* override any Incomplete */
}
if (status != (ssize_t)sizeof(hdr)) {
Jmsg(jcr, M_ERROR, 0,
@@ -607,7 +607,7 @@ static bool WriteSpoolHeader(DeviceControlRecord* dcr)
}
if (!DespoolData(dcr, false)) {
Jmsg(jcr, M_FATAL, 0, _("Fatal despooling error.\n"));
- jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
+ jcr->setJobStatus(JS_FatalError); /* override any Incomplete */
return false;
}
continue; /* try again */
@@ -615,7 +615,7 @@ static bool WriteSpoolHeader(DeviceControlRecord* dcr)
return true;
}
Jmsg(jcr, M_FATAL, 0, _("Retrying after header spooling error failed.\n"));
- jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
+ jcr->setJobStatus(JS_FatalError); /* override any Incomplete */
return false;
}
@@ -633,7 +633,7 @@ static bool WriteSpoolData(DeviceControlRecord* dcr)
Jmsg(jcr, M_FATAL, 0, _("Error writing data to spool file. ERR=%s\n"),
be.bstrerror());
- jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
+ jcr->setJobStatus(JS_FatalError); /* override any Incomplete */
}
if (status != (ssize_t)block->binbuf) {
// If we wrote something, truncate it and the header, then despool
@@ -654,7 +654,7 @@ static bool WriteSpoolData(DeviceControlRecord* dcr)
if (!DespoolData(dcr, false)) {
Jmsg(jcr, M_FATAL, 0, _("Fatal despooling error.\n"));
- jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
+ jcr->setJobStatus(JS_FatalError); /* override any Incomplete */
return false;
}
@@ -667,7 +667,7 @@ static bool WriteSpoolData(DeviceControlRecord* dcr)
}
Jmsg(jcr, M_FATAL, 0, _("Retrying after data spooling error failed.\n"));
- jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
+ jcr->setJobStatus(JS_FatalError); /* override any Incomplete */
return false;
}
@@ -739,7 +739,7 @@ static bool BlastAttrSpoolFile(JobControlRecord* jcr, boffset_t)
if (jcr->dir_bsock->recv() <= 0) {
Jmsg(jcr, M_FATAL, 0, _("Network error on BlastAttributes.\n"));
- jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
+ jcr->setJobStatus(JS_FatalError); /* override any Incomplete */
return false;
}
@@ -764,7 +764,7 @@ bool CommitAttributeSpool(JobControlRecord* jcr)
Jmsg(jcr, M_FATAL, 0, _("lseek on attributes file failed: ERR=%s\n"),
be.bstrerror());
- jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
+ jcr->setJobStatus(JS_FatalError); /* override any Incomplete */
goto bail_out;
}
@@ -779,7 +779,7 @@ bool CommitAttributeSpool(JobControlRecord* jcr)
Jmsg(jcr, M_FATAL, 0,
_("Truncate on attributes file failed: ERR=%s\n"),
be.bstrerror());
- jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
+ jcr->setJobStatus(JS_FatalError); /* override any Incomplete */
goto bail_out;
}
Dmsg2(100, "=== Attrib spool truncated from %lld to %lld\n", size,
@@ -793,7 +793,7 @@ bool CommitAttributeSpool(JobControlRecord* jcr)
Jmsg(jcr, M_FATAL, 0, _("Fseek on attributes file failed: ERR=%s\n"),
be.bstrerror());
- jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
+ jcr->setJobStatus(JS_FatalError); /* override any Incomplete */
goto bail_out;
}
@@ -835,7 +835,7 @@ static bool OpenAttrSpoolFile(JobControlRecord* jcr, BareosSocket* bs)
Jmsg(jcr, M_FATAL, 0, _("fopen attr spool file %s failed: ERR=%s\n"), name,
be.bstrerror());
- jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
+ jcr->setJobStatus(JS_FatalError); /* override any Incomplete */
FreePoolMemory(name);
return false;
}
diff --git a/core/src/stored/status.cc b/core/src/stored/status.cc
index 27dd18f67..7a662f69c 100644
--- a/core/src/stored/status.cc
+++ b/core/src/stored/status.cc
@@ -519,7 +519,7 @@ static void SendBlockedStatus(Device* dev, StatusPacket* sp)
bool found_jcr = false;
dev->Lock();
for (auto dcr : dev->attached_dcrs) {
- if (dcr->jcr->JobStatus == JS_WaitMount) {
+ if (dcr->jcr->getJobStatus() == JS_WaitMount) {
len = Mmsg(
msg,
_(" Device is BLOCKED waiting for mount of volume \"%s\",\n"
@@ -528,7 +528,7 @@ static void SendBlockedStatus(Device* dev, StatusPacket* sp)
dcr->VolumeName, dcr->pool_name, dcr->media_type);
sp->send(msg, len);
found_jcr = true;
- } else if (dcr->jcr->JobStatus == JS_WaitMedia) {
+ } else if (dcr->jcr->getJobStatus() == JS_WaitMedia) {
len = Mmsg(msg,
_(" Device is BLOCKED waiting to create a volume for:\n"
" Pool: %s\n"
@@ -663,7 +663,7 @@ static void ListRunningJobs(StatusPacket* sp)
}
foreach_jcr (jcr) {
- if (jcr->JobStatus == JS_WaitFD) {
+ if (jcr->getJobStatus() == JS_WaitFD) {
len = Mmsg(msg, _("%s Job %s waiting for Client connection.\n"),
job_type_to_str(jcr->getJobType()), jcr->Job);
sp->send(msg, len);
@@ -985,7 +985,8 @@ bool DotstatusCmd(JobControlRecord* jcr)
dir->fsend(OKdotstatus, cmd.c_str());
foreach_jcr (njcr) {
if (njcr->JobId != 0) {
- dir->fsend(DotStatusJob, njcr->JobId, njcr->JobStatus, njcr->JobErrors);
+ dir->fsend(DotStatusJob, njcr->JobId, njcr->getJobStatus(),
+ njcr->JobErrors);
}
}
endeach_jcr(njcr);
diff --git a/core/src/stored/stored.cc b/core/src/stored/stored.cc
index 25371c15d..1c329549d 100644
--- a/core/src/stored/stored.cc
+++ b/core/src/stored/stored.cc
@@ -613,7 +613,7 @@ static
foreach_jcr (jcr) {
BareosSocket* fd;
if (jcr->JobId == 0) { continue; /* ignore console */ }
- jcr->setJobStatus(JS_Canceled);
+ jcr->setJobStatusWithPriorityCheck(JS_Canceled);
fd = jcr->file_bsock;
if (fd) {
fd->SetTimedOut();
diff --git a/core/src/stored/vol_mgr.cc b/core/src/stored/vol_mgr.cc
index e0b60245b..b4eff74cc 100644
--- a/core/src/stored/vol_mgr.cc
+++ b/core/src/stored/vol_mgr.cc
@@ -51,7 +51,6 @@ static int read_vol_list_lock_count = 0;
/* Forward referenced functions */
static void FreeVolItem(VolumeReservationItem* vol);
-static void FreeReadVolItem(VolumeReservationItem* vol);
static VolumeReservationItem* new_vol_item(DeviceControlRecord* dcr,
const char* VolumeName);
static void DebugListVolumes(const char* imsg);
@@ -163,7 +162,7 @@ void AddReadVolume(JobControlRecord* jcr, const char* VolumeName)
LockReadVolumes();
vol = (VolumeReservationItem*)read_vol_list->binary_insert(nvol, ReadCompare);
if (vol != nvol) {
- FreeReadVolItem(nvol);
+ FreeVolItem(nvol);
Dmsg2(debuglevel, "read_vol=%s JobId=%d already in list.\n", VolumeName,
jcr->JobId);
} else {
@@ -191,7 +190,7 @@ void RemoveReadVolume(JobControlRecord* jcr, const char* VolumeName)
}
if (fvol) {
read_vol_list->remove(fvol);
- FreeReadVolItem(fvol);
+ FreeVolItem(fvol);
}
UnlockReadVolumes();
// pthread_cond_broadcast(&wait_next_vol);
@@ -261,10 +260,10 @@ static VolumeReservationItem* new_vol_item(DeviceControlRecord* dcr,
const char* VolumeName)
{
VolumeReservationItem* vol;
- VolumeReservationItem emptyVol;
vol = (VolumeReservationItem*)malloc(sizeof(VolumeReservationItem));
- *vol = emptyVol;
+ vol = new (vol) VolumeReservationItem();
+
vol->vol_name = strdup(VolumeName);
if (dcr) {
vol->dev = dcr->dev;
@@ -279,7 +278,7 @@ static VolumeReservationItem* new_vol_item(DeviceControlRecord* dcr,
static void FreeVolItem(VolumeReservationItem* vol)
{
- Device* dev = NULL;
+ Device* dev = nullptr;
vol->DecUseCount();
vol->Lock();
@@ -292,25 +291,7 @@ static void FreeVolItem(VolumeReservationItem* vol)
if (vol->dev) { dev = vol->dev; }
vol->DestroyMutex();
free(vol);
- if (dev) { dev->vol = NULL; }
-}
-
-static void FreeReadVolItem(VolumeReservationItem* vol)
-{
- Device* dev = NULL;
-
- vol->DecUseCount();
- vol->Lock();
- if (vol->UseCount() > 0) {
- vol->Unlock();
- return;
- }
- vol->Unlock();
- free(vol->vol_name);
- if (vol->dev) { dev = vol->dev; }
- vol->DestroyMutex();
- free(vol);
- if (dev) { dev->vol = NULL; }
+ if (dev) { dev->vol = nullptr; }
}
/**
@@ -368,10 +349,9 @@ VolumeReservationItem* reserve_volume(DeviceControlRecord* dcr,
const char* VolumeName)
{
VolumeReservationItem *vol, *nvol;
- Device* volatile dev = dcr->dev;
if (JobCanceled(dcr->jcr)) { return NULL; }
- ASSERT(dev != NULL);
+ ASSERT(dcr->dev != NULL);
Dmsg2(debuglevel, "enter reserve_volume=%s drive=%s\n", VolumeName,
dcr->dev->print_name());
@@ -382,7 +362,7 @@ VolumeReservationItem* reserve_volume(DeviceControlRecord* dcr,
Mmsg(dcr->jcr->errmsg,
_("Could not reserve volume \"%s\" for append, because it is read by "
"another Job.\n"),
- dev->VolHdr.VolumeName);
+ dcr->dev->VolHdr.VolumeName);
return NULL;
}
@@ -397,10 +377,10 @@ VolumeReservationItem* reserve_volume(DeviceControlRecord* dcr,
* First, remove any old volume attached to this device as it is no longer
* used.
*/
- if (dev->vol) {
- vol = dev->vol;
+ if (dcr->dev->vol) {
+ vol = dcr->dev->vol;
Dmsg4(debuglevel, "Vol attached=%s, newvol=%s volinuse=%d on %s\n",
- vol->vol_name, VolumeName, vol->IsInUse(), dev->print_name());
+ vol->vol_name, VolumeName, vol->IsInUse(), dcr->dev->print_name());
/*
* Make sure we don't remove the current volume we are inserting
* because it was probably inserted by another job, or it
@@ -422,11 +402,11 @@ VolumeReservationItem* reserve_volume(DeviceControlRecord* dcr,
vol->vol_name);
// If old Volume is still mounted, must unload it
- if (bstrcmp(vol->vol_name, dev->VolHdr.VolumeName)) {
+ if (bstrcmp(vol->vol_name, dcr->dev->VolHdr.VolumeName)) {
Dmsg0(50, "SetUnload\n");
- dev->SetUnload(); /* have to unload current volume */
+ dcr->dev->SetUnload(); /* have to unload current volume */
}
- FreeVolume(dev); /* Release old volume entry */
+ FreeVolume(dcr->dev); /* Release old volume entry */
if (debug_level >= debuglevel) { DebugListVolumes("reserve_vol free"); }
}
@@ -439,11 +419,12 @@ VolumeReservationItem* reserve_volume(DeviceControlRecord* dcr,
* See if this is a request for reading a file type device which can be
* accesses by multiple readers at once without disturbing each other.
*/
- if (me->filedevice_concurrent_read && !dcr->IsWriting() && dev->IsFile()) {
+ if (me->filedevice_concurrent_read && !dcr->IsWriting()
+ && dcr->dev->IsFile()) {
nvol->SetJobid(dcr->jcr->JobId);
nvol->SetReading();
vol = nvol;
- dev->vol = vol;
+ dcr->dev->vol = vol;
/*
* Read volumes on file based devices are not inserted into the write volume
@@ -458,7 +439,7 @@ VolumeReservationItem* reserve_volume(DeviceControlRecord* dcr,
if (vol != nvol) {
Dmsg2(debuglevel, "Found vol=%s dev-same=%d\n", vol->vol_name,
- dev == vol->dev);
+ dcr->dev == vol->dev);
/*
* At this point, a Volume with this name already is in the list,
@@ -473,7 +454,7 @@ VolumeReservationItem* reserve_volume(DeviceControlRecord* dcr,
FreeVolItem(nvol);
if (vol->dev) {
- Dmsg2(debuglevel, "dev=%s vol->dev=%s\n", dev->print_name(),
+ Dmsg2(debuglevel, "dev=%s vol->dev=%s\n", dcr->dev->print_name(),
vol->dev->print_name());
}
@@ -481,35 +462,35 @@ VolumeReservationItem* reserve_volume(DeviceControlRecord* dcr,
* Check if we are trying to use the Volume on a different drive dev is our
* device vol->dev is where the Volume we want is
*/
- if (dev != vol->dev) {
+ if (dcr->dev != vol->dev) {
// Caller wants to switch Volume to another device
// should be different devices with different names
- if (bstrcmp(dev->print_name(), vol->dev->print_name())) {
+ if (bstrcmp(dcr->dev->print_name(), vol->dev->print_name())) {
// names are same
Dmsg1(100, "device pointers are different but have same name %s\n",
- dev->print_name());
+ dcr->dev->print_name());
}
if (!vol->dev->IsBusy() && !vol->IsSwapping()) {
slot_number_t slot;
Dmsg3(debuglevel, "==== Swap vol=%s from dev=%s to %s\n", VolumeName,
- vol->dev->print_name(), dev->print_name());
- FreeVolume(dev); /* free any volume attached to our drive */
- Dmsg1(50, "SetUnload dev=%s\n", dev->print_name());
- dev->SetUnload(); /* Unload any volume that is on our drive */
+ vol->dev->print_name(), dcr->dev->print_name());
+ FreeVolume(dcr->dev); /* free any volume attached to our drive */
+ Dmsg1(50, "SetUnload dev=%s\n", dcr->dev->print_name());
+ dcr->dev->SetUnload(); /* Unload any volume that is on our drive */
dcr->SetDev(vol->dev); /* temp point to other dev */
slot = GetAutochangerLoadedSlot(dcr); /* get slot on other drive */
- dcr->SetDev(dev); /* restore dev */
+ dcr->SetDev(dcr->dev); /* restore dev */
vol->SetSlotNumber(slot); /* save slot */
vol->dev->SetUnload(); /* unload the other drive */
vol->SetSwapping(); /* swap from other drive */
- dev->swap_dev = vol->dev; /* remember to get this vol */
- dev->SetLoad(); /* then reload on our drive */
+ dcr->dev->swap_dev = vol->dev; /* remember to get this vol */
+ dcr->dev->SetLoad(); /* then reload on our drive */
vol->dev->vol = NULL; /* remove volume from other drive */
- vol->dev = dev; /* point the Volume at our drive */
- dev->vol = vol; /* point our drive at the Volume */
+ vol->dev = dcr->dev; /* point the Volume at our drive */
+ dcr->dev->vol = vol; /* point our drive at the Volume */
} else {
Jmsg7(dcr->jcr, M_WARNING, 0,
"Need volume from other drive, but swap not possible. "
@@ -517,13 +498,14 @@ VolumeReservationItem* reserve_volume(DeviceControlRecord* dcr,
"vol=%s from dev=%s to %s\n",
vol->dev->CanRead(), vol->dev->num_writers,
vol->dev->NumReserved(), vol->IsSwapping(), VolumeName,
- vol->dev->print_name(), dev->print_name());
- if (vol->IsSwapping() && dev->swap_dev) {
+ vol->dev->print_name(), dcr->dev->print_name());
+ if (vol->IsSwapping() && dcr->dev->swap_dev) {
Dmsg3(debuglevel, "Swap failed vol=%s from=%s to dev=%s\n",
- vol->vol_name, dev->swap_dev->print_name(), dev->print_name());
+ vol->vol_name, dcr->dev->swap_dev->print_name(),
+ dcr->dev->print_name());
} else {
Dmsg3(debuglevel, "Swap failed vol=%s from=%p to dev=%s\n",
- vol->vol_name, dev->swap_dev, dev->print_name());
+ vol->vol_name, dcr->dev->swap_dev, dcr->dev->print_name());
}
if (debug_level >= debuglevel) { DebugListVolumes("failed swap"); }
@@ -532,10 +514,10 @@ VolumeReservationItem* reserve_volume(DeviceControlRecord* dcr,
goto get_out;
}
} else {
- dev->vol = vol;
+ dcr->dev->vol = vol;
}
} else {
- dev->vol = vol; /* point to newly inserted volume */
+ dcr->dev->vol = vol; /* point to newly inserted volume */
}
get_out:
@@ -655,7 +637,7 @@ VolumeReservationItem* ReadVolWalkNext(VolumeReservationItem* prev_vol)
Dmsg2(debuglevel, "Inc walk_next UseCount=%d volname=%s\n", vol->UseCount(),
vol->vol_name);
}
- if (prev_vol) { FreeReadVolItem(prev_vol); }
+ if (prev_vol) { FreeVolItem(prev_vol); }
UnlockReadVolumes();
return vol;
@@ -668,7 +650,7 @@ void ReadVolWalkEnd(VolumeReservationItem* vol)
LockReadVolumes();
Dmsg2(debuglevel, "Free walk_end UseCount=%d volname=%s\n", vol->UseCount(),
vol->vol_name);
- FreeReadVolItem(vol);
+ FreeVolItem(vol);
UnlockReadVolumes();
}
}
diff --git a/core/src/stored/vol_mgr.h b/core/src/stored/vol_mgr.h
index 61f0c887b..b954b39d1 100644
--- a/core/src/stored/vol_mgr.h
+++ b/core/src/stored/vol_mgr.h
@@ -46,6 +46,8 @@
#ifndef BAREOS_STORED_VOL_MGR_H_
#define BAREOS_STORED_VOL_MGR_H_
+#include <atomic>
+
template <typename T> class dlist;
namespace storagedaemon {
@@ -60,12 +62,12 @@ void ReadVolWalkEnd(VolumeReservationItem* vol);
// Volume reservation class -- see vol_mgr.c and reserve.c
class VolumeReservationItem {
- bool swapping_{false}; /**< set when swapping to another drive */
- bool in_use_{false}; /**< set when volume reserved or in use */
- bool reading_{false}; /**< set when reading */
- slot_number_t slot_{0}; /**< slot of swapping volume */
- uint32_t JobId_{0}; /**< JobId for read volumes */
- volatile int32_t use_count_{0}; /**< Use count */
+ bool swapping_{false}; /**< set when swapping to another drive */
+ bool in_use_{false}; /**< set when volume reserved or in use */
+ bool reading_{false}; /**< set when reading */
+ slot_number_t slot_{0}; /**< slot of swapping volume */
+ uint32_t JobId_{0}; /**< JobId for read volumes */
+ std::atomic<int32_t> use_count_{0}; /**< Use count */
pthread_mutex_t mutex_ = PTHREAD_MUTEX_INITIALIZER; /**< Vol muntex */
public:
dlink<VolumeReservationItem> link;
@@ -76,18 +78,8 @@ class VolumeReservationItem {
void DestroyMutex() { pthread_mutex_destroy(&mutex_); }
void Lock() { lock_mutex(mutex_); }
void Unlock() { unlock_mutex(mutex_); }
- void IncUseCount(void)
- {
- lock_mutex(mutex_);
- use_count_++;
- unlock_mutex(mutex_);
- }
- void DecUseCount(void)
- {
- lock_mutex(mutex_);
- use_count_--;
- unlock_mutex(mutex_);
- }
+ void IncUseCount(void) { ++use_count_; }
+ void DecUseCount(void) { --use_count_; }
int32_t UseCount() const { return use_count_; }
bool IsSwapping() const { return swapping_; }
bool is_reading() const { return reading_; }
diff --git a/core/src/tests/thread_list.cc b/core/src/tests/thread_list.cc
index 9e73c18aa..0c456893d 100644
--- a/core/src/tests/thread_list.cc
+++ b/core/src/tests/thread_list.cc
@@ -57,7 +57,8 @@ class WaitCondition {
{
std::unique_lock<std::mutex> ul(mutex_);
status_ = Status::kWaiting;
- bool success = cond_variable_.wait_for(ul, ms, [=]() { return notified; });
+ bool success
+ = cond_variable_.wait_for(ul, ms, [this]() { return notified; });
status_ = success ? Status::kSuccess : Status::kTimedOut;
}
void NotifyOne()
diff --git a/core/src/tests/version_strings.cc b/core/src/tests/version_strings.cc
index 43a30be95..981b557c0 100644
--- a/core/src/tests/version_strings.cc
+++ b/core/src/tests/version_strings.cc
@@ -1,7 +1,7 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
- Copyright (C) 2019-2019 Bareos GmbH & Co. KG
+ Copyright (C) 2019-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
@@ -18,20 +18,15 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
-#include <algorithm>
-#include <vector>
-
-#if defined(HAVE_MINGW)
-# include "include/bareos.h"
-# include "gtest/gtest.h"
-#else
-# include "gtest/gtest.h"
-# include "include/bareos.h"
-#endif
+#include "include/bareos.h"
+#include "gtest/gtest.h"
#include "lib/version.h"
+#include <algorithm>
+#include <vector>
+
TEST(version_strings, version)
{
std::string ver_full{kBareosVersionStrings.Full};