From d988217814df77e87aa2179eff393867c15bdcb5 Mon Sep 17 00:00:00 2001 From: Alaa Eddine Elamri Date: Fri, 28 Oct 2022 10:25:38 +0200 Subject: complying with the deprecation of implicit capture of `this` via `[=]` --- core/src/tests/thread_list.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 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() -- cgit v1.2.3 From 74ff88ea658f8e48a850a4d301f16fe700625781 Mon Sep 17 00:00:00 2001 From: Alaa Eddine Elamri Date: Thu, 6 Oct 2022 10:49:13 +0200 Subject: windows: fix windows complaints --- core/src/dird/fd_cmds.cc | 2 +- core/src/tests/version_strings.cc | 17 ++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/core/src/dird/fd_cmds.cc b/core/src/dird/fd_cmds.cc index a8d65cc78..f11ceec3f 100644 --- a/core/src/dird/fd_cmds.cc +++ b/core/src/dird/fd_cmds.cc @@ -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: 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 -#include - -#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 +#include + TEST(version_strings, version) { std::string ver_full{kBareosVersionStrings.Full}; -- cgit v1.2.3 From dedc7f8e3a9175fd937fdd3ab788223702555f88 Mon Sep 17 00:00:00 2001 From: Alaa Eddine Elamri Date: Fri, 28 Oct 2022 10:40:34 +0200 Subject: bsock: switch volatile to std::atomic --- core/src/lib/bsock.cc | 6 +++--- core/src/lib/bsock.h | 38 ++++++++++++++++++++------------------ core/src/lib/bsock_tcp.cc | 12 ++++++------ core/src/lib/connection_pool.h | 4 +++- 4 files changed, 32 insertions(+), 28 deletions(-) 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 -#include -#include #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 +#include +#include +#include + 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 timer_start; /* Time started read/write */ + int b_errno; /* BareosSocket errno */ + int blocking_; /* Blocking state (0 = nonblocking, 1 = blocking) */ + std::atomic errors; /* Incremented for each error on socket */ + std::atomic 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/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 + template 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 in_use_; time_t connect_time_; pthread_mutex_t mutex_; }; -- cgit v1.2.3 From 5287fd913609785d197d5adcbe3576f375fb8909 Mon Sep 17 00:00:00 2001 From: Alaa Eddine Elamri Date: Fri, 28 Oct 2022 12:05:24 +0200 Subject: jcr: use count volatile to atomic --- core/src/include/jcr.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/core/src/include/jcr.h b/core/src/include/jcr.h index 2594353df..8fcf1cf12 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 +#include +#include struct job_callback_item; class BareosDb; @@ -81,7 +82,7 @@ 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 _use_count{}; /**< Use count */ int32_t JobType_{}; /**< Backup, restore, verify ... */ int32_t JobLevel_{}; /**< Job level */ int32_t Protocol_{}; /**< Backup Protocol */ @@ -98,15 +99,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); } -- cgit v1.2.3 From 26fe7f497a9361d871d76eff464a8c8513c8b2a8 Mon Sep 17 00:00:00 2001 From: Alaa Eddine Elamri Date: Fri, 21 Oct 2022 16:50:09 +0200 Subject: jcr_private: SDJobStatus from volatile to atomic --- core/src/dird/backup.cc | 6 ++++-- core/src/dird/dir_plugins.cc | 2 +- core/src/dird/jcr_private.h | 2 +- core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/core/src/dird/backup.cc b/core/src/dird/backup.cc index 07a57ab6d..3174cd55e 100644 --- a/core/src/dird/backup.cc +++ b/core/src/dird/backup.cc @@ -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, jcr->JobStatus, + 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, jcr->JobStatus, + jcr->impl->SDJobStatus.load()); CancelStorageDaemonJob(jcr); } diff --git a/core/src/dird/dir_plugins.cc b/core/src/dird/dir_plugins.cc index 23ecbb092..869c86754 100644 --- a/core/src/dird/dir_plugins.cc +++ b/core/src/dird/dir_plugins.cc @@ -687,7 +687,7 @@ static bRC bareosGetValue(PluginContext* ctx, brDirVariable var, void* value) 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/jcr_private.h b/core/src/dird/jcr_private.h index 77511686e..ecc16c49d 100644 --- a/core/src/dird/jcr_private.h +++ b/core/src/dird/jcr_private.h @@ -111,7 +111,7 @@ 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 */ + std::atomic SDJobStatus{}; /**< Storage Job Status */ volatile int32_t FDJobStatus{}; /**< File daemon Job Status */ uint32_t DumpLevel{}; /**< Dump level when doing a NDMP backup */ uint32_t ExpectedFiles{}; /**< Expected restore files */ diff --git a/core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc b/core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc index 141c7261f..8677b40a9 100644 --- a/core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc +++ b/core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc @@ -332,10 +332,10 @@ static inline int NdmpWaitForJobTermination(JobControlRecord* jcr) * 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, jcr->JobStatus, 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); + jcr->JobStatus, jcr->impl->SDJobStatus.load()); CancelStorageDaemonJob(jcr); } -- cgit v1.2.3 From 7f903c52bf86c154de67d6d0b4058d0fc797351c Mon Sep 17 00:00:00 2001 From: Alaa Eddine Elamri Date: Fri, 21 Oct 2022 16:55:09 +0200 Subject: jcr_private: FDJobStatus from volatile to atomic --- core/src/dird/backup.cc | 4 ++-- core/src/dird/dir_plugins.cc | 2 +- core/src/dird/jcr_private.h | 2 +- core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc | 5 +++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/core/src/dird/backup.cc b/core/src/dird/backup.cc index 3174cd55e..b6a0d75ca 100644 --- a/core/src/dird/backup.cc +++ b/core/src/dird/backup.cc @@ -683,12 +683,12 @@ 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, + fd_ok, jcr->impl->FDJobStatus.load(), jcr->JobStatus, 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->FDJobStatus.load(), jcr->JobStatus, jcr->impl->SDJobStatus.load()); CancelStorageDaemonJob(jcr); } diff --git a/core/src/dird/dir_plugins.cc b/core/src/dird/dir_plugins.cc index 869c86754..6c6637796 100644 --- a/core/src/dird/dir_plugins.cc +++ b/core/src/dird/dir_plugins.cc @@ -682,7 +682,7 @@ 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; diff --git a/core/src/dird/jcr_private.h b/core/src/dird/jcr_private.h index ecc16c49d..d72e09e17 100644 --- a/core/src/dird/jcr_private.h +++ b/core/src/dird/jcr_private.h @@ -112,7 +112,7 @@ struct JobControlRecordPrivate { uint64_t SDJobBytes{}; /**< Number of bytes processed this job */ uint32_t SDErrors{}; /**< Number of non-fatal errors */ std::atomic SDJobStatus{}; /**< Storage Job Status */ - volatile int32_t FDJobStatus{}; /**< File daemon Job Status */ + std::atomic 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 */ diff --git a/core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc b/core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc index 8677b40a9..e879a1f31 100644 --- a/core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc +++ b/core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc @@ -332,9 +332,10 @@ static inline int NdmpWaitForJobTermination(JobControlRecord* jcr) * 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.load()); + jcr->impl->FDJobStatus.load(), jcr->JobStatus, + jcr->impl->SDJobStatus.load()); if (jcr->IsCanceled() || (!jcr->impl->res.job->RescheduleIncompleteJobs)) { - Dmsg3(100, "FDJS=%d JS=%d SDJS=%d\n", jcr->impl->FDJobStatus, + Dmsg3(100, "FDJS=%d JS=%d SDJS=%d\n", jcr->impl->FDJobStatus.load(), jcr->JobStatus, jcr->impl->SDJobStatus.load()); CancelStorageDaemonJob(jcr); } -- cgit v1.2.3 From dee4a25256fdabc8ab601f3714eba834e395d587 Mon Sep 17 00:00:00 2001 From: Alaa Eddine Elamri Date: Fri, 21 Oct 2022 16:56:49 +0200 Subject: jcr_private: sd_msg_thread_done from volatile to atomic --- core/src/dird/jcr_private.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/dird/jcr_private.h b/core/src/dird/jcr_private.h index d72e09e17..810ea58d9 100644 --- a/core/src/dird/jcr_private.h +++ b/core/src/dird/jcr_private.h @@ -139,7 +139,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 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 */ -- cgit v1.2.3 From 3aba6b1194411c89ade805d7cf816bdb8ac6a41e Mon Sep 17 00:00:00 2001 From: Alaa Eddine Elamri Date: Fri, 21 Oct 2022 17:21:45 +0200 Subject: device_control_record.h: remove volatile keyword from Device* --- core/src/stored/device_control_record.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 */ -- cgit v1.2.3 From 6c265ec52d1968b0c5f5e573833fe260e48ee30a Mon Sep 17 00:00:00 2001 From: Alaa Eddine Elamri Date: Mon, 24 Oct 2022 10:16:05 +0200 Subject: replace volatile device pointers with actual variable --- core/src/stored/ansi_label.cc | 49 ++++++++++---------- core/src/stored/autochanger.cc | 37 ++++++++------- core/src/stored/label.cc | 101 +++++++++++++++++++++-------------------- core/src/stored/vol_mgr.cc | 63 ++++++++++++------------- 4 files changed, 125 insertions(+), 125 deletions(-) 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/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/label.cc b/core/src/stored/label.cc index 1906d9cd7..3ecb57c7c 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; } diff --git a/core/src/stored/vol_mgr.cc b/core/src/stored/vol_mgr.cc index e0b60245b..b49270f98 100644 --- a/core/src/stored/vol_mgr.cc +++ b/core/src/stored/vol_mgr.cc @@ -368,10 +368,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 +381,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 +396,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 +421,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 +438,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 +458,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 +473,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 +481,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 +517,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 +533,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: -- cgit v1.2.3 From 098a464acdcf74063d5412d9047a12a8cfb169eb Mon Sep 17 00:00:00 2001 From: Alaa Eddine Elamri Date: Mon, 24 Oct 2022 10:20:15 +0200 Subject: remove volatile from swap_device --- core/src/stored/dev.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 +#include + template 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 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 */ -- cgit v1.2.3 From ee9346d7c3d6ea2f6b483ed1aa8b85830ad45d60 Mon Sep 17 00:00:00 2001 From: Alaa Eddine Elamri Date: Fri, 28 Oct 2022 14:03:00 +0200 Subject: vol_mgr: replace volatile with atomic for use_count_ volmgr vol_mgr: use std::construct_at instead of placement new --- core/src/stored/vol_mgr.cc | 4 ++-- core/src/stored/vol_mgr.h | 28 ++++++++++------------------ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/core/src/stored/vol_mgr.cc b/core/src/stored/vol_mgr.cc index b49270f98..0d035e23a 100644 --- a/core/src/stored/vol_mgr.cc +++ b/core/src/stored/vol_mgr.cc @@ -261,10 +261,10 @@ static VolumeReservationItem* new_vol_item(DeviceControlRecord* dcr, const char* VolumeName) { VolumeReservationItem* vol; - VolumeReservationItem emptyVol; vol = (VolumeReservationItem*)malloc(sizeof(VolumeReservationItem)); - *vol = emptyVol; + std::construct_at(vol); + vol->vol_name = strdup(VolumeName); if (dcr) { vol->dev = dcr->dev; 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 + template 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 use_count_{0}; /**< Use count */ pthread_mutex_t mutex_ = PTHREAD_MUTEX_INITIALIZER; /**< Vol muntex */ public: dlink 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_; } -- cgit v1.2.3 From f5a02861cae9360971198ecd8510690076a22124 Mon Sep 17 00:00:00 2001 From: Alaa Eddine Elamri Date: Fri, 28 Oct 2022 13:56:21 +0200 Subject: vol_mgr: remove duplicate FreeReadVolItem --- core/src/stored/vol_mgr.cc | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/core/src/stored/vol_mgr.cc b/core/src/stored/vol_mgr.cc index 0d035e23a..7cc1b3b93 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); @@ -279,25 +278,7 @@ static VolumeReservationItem* new_vol_item(DeviceControlRecord* dcr, static void FreeVolItem(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; } -} - -static void FreeReadVolItem(VolumeReservationItem* vol) -{ - Device* dev = NULL; + Device* dev = nullptr; vol->DecUseCount(); vol->Lock(); @@ -310,7 +291,7 @@ static void FreeReadVolItem(VolumeReservationItem* vol) if (vol->dev) { dev = vol->dev; } vol->DestroyMutex(); free(vol); - if (dev) { dev->vol = NULL; } + if (dev) { dev->vol = nullptr; } } /** @@ -656,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; @@ -669,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(); } } -- cgit v1.2.3 From ed0626520e8db05d5f9845c9e9c97a18429aa395 Mon Sep 17 00:00:00 2001 From: Alaa Eddine Elamri Date: Fri, 28 Oct 2022 11:36:32 +0200 Subject: remove reset jobstatus and replace with forcejobstatus --- core/src/dird/fd_cmds.cc | 2 +- core/src/include/jcr.h | 1 - core/src/lib/jcr.cc | 5 ----- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/core/src/dird/fd_cmds.cc b/core/src/dird/fd_cmds.cc index f11ceec3f..38509c8df 100644 --- a/core/src/dird/fd_cmds.cc +++ b/core/src/dird/fd_cmds.cc @@ -294,7 +294,7 @@ bool ConnectToFileDaemon(JobControlRecord* jcr, delete jcr->file_bsock; jcr->file_bsock = nullptr; } - jcr->resetJobStatus(JS_Running); + jcr->forceJobStatus(JS_Running); jcr->impl->connection_handshake_try_ = ClientConnectionHandshakeMode::kCleartextFirst; break; diff --git a/core/src/include/jcr.h b/core/src/include/jcr.h index 8fcf1cf12..f338f88a5 100644 --- a/core/src/include/jcr.h +++ b/core/src/include/jcr.h @@ -133,7 +133,6 @@ class JobControlRecord { 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 */ bool sendJobStatus(); /**< in lib/jcr.c */ bool sendJobStatus(int newJobStatus); /**< in lib/jcr.c */ bool JobReads(); /**< in lib/jcr.c */ diff --git a/core/src/lib/jcr.cc b/core/src/lib/jcr.cc index 7927ad127..cc1f1e072 100644 --- a/core/src/lib/jcr.cc +++ b/core/src/lib/jcr.cc @@ -756,11 +756,6 @@ void JobControlRecord::setJobStarted() job_started_time = time(nullptr); } -void JobControlRecord::resetJobStatus(int newJobStatus) -{ - JobStatus = newJobStatus; -} - void JobControlRecord::setJobStatus(int newJobStatus) { int priority; -- cgit v1.2.3 From 65d3ad166f03a1b89c4ad15c973293702475aea6 Mon Sep 17 00:00:00 2001 From: Alaa Eddine Elamri Date: Fri, 28 Oct 2022 12:58:00 +0200 Subject: rename setJobStatus to setJobStatusWithPriorityCheck --- core/src/dird/admin.cc | 6 ++-- core/src/dird/archive.cc | 6 ++-- core/src/dird/backup.cc | 20 ++++++------ core/src/dird/bsr.cc | 2 +- core/src/dird/consolidate.cc | 6 ++-- core/src/dird/fd_cmds.cc | 18 +++++------ core/src/dird/getmsg.cc | 6 ++-- core/src/dird/job.cc | 29 ++++++++--------- core/src/dird/jobq.cc | 16 +++++----- core/src/dird/migrate.cc | 32 +++++++++---------- core/src/dird/msgchan.cc | 4 +-- core/src/dird/ndmp_dma_backup_NDMP_BAREOS.cc | 6 ++-- core/src/dird/ndmp_dma_backup_NDMP_NATIVE.cc | 6 ++-- core/src/dird/ndmp_dma_backup_common.cc | 2 +- core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc | 6 ++-- core/src/dird/ndmp_dma_restore_NDMP_NATIVE.cc | 2 +- core/src/dird/restore.cc | 8 ++--- core/src/dird/storage.cc | 6 ++-- core/src/dird/ua_server.cc | 2 +- core/src/dird/vbackup.cc | 10 +++--- core/src/dird/verify.cc | 36 ++++++++++++---------- core/src/filed/backup.cc | 8 ++--- core/src/filed/compression.cc | 6 ++-- core/src/filed/dir_cmd.cc | 28 +++++++++-------- core/src/filed/estimate.cc | 2 +- core/src/filed/restore.cc | 8 ++--- core/src/filed/sd_cmds.cc | 4 +-- core/src/filed/verify.cc | 4 +-- core/src/filed/verify_vol.cc | 12 ++++---- core/src/include/jcr.h | 2 +- core/src/lib/compression.cc | 12 ++++---- core/src/lib/jcr.cc | 6 ++-- core/src/lib/message.cc | 2 +- core/src/lib/runscript.cc | 4 +-- .../src/plugins/stored/autoxflate/autoxflate-sd.cc | 4 +-- core/src/stored/append.cc | 18 +++++------ core/src/stored/bscan.cc | 2 +- core/src/stored/btape.cc | 8 ++--- core/src/stored/dir_cmd.cc | 2 +- core/src/stored/fd_cmds.cc | 8 ++--- core/src/stored/job.cc | 4 +-- core/src/stored/mac.cc | 12 ++++---- core/src/stored/ndmp_tape.cc | 10 +++--- core/src/stored/read.cc | 4 +-- core/src/stored/reserve.cc | 2 +- core/src/stored/sd_cmds.cc | 8 +++-- core/src/stored/spool.cc | 4 +-- core/src/stored/stored.cc | 2 +- 48 files changed, 211 insertions(+), 204 deletions(-) diff --git a/core/src/dird/admin.cc b/core/src/dird/admin.cc index ce71d9db7..e3c91b2ef 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,7 +80,7 @@ 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 */ diff --git a/core/src/dird/archive.cc b/core/src/dird/archive.cc index 44d957767..1d0a3dfca 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,7 +79,7 @@ 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 */ diff --git a/core/src/dird/backup.cc b/core/src/dird/backup.cc index b6a0d75ca..bd41e9616 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,7 +656,7 @@ int WaitForJobTermination(JobControlRecord* jcr, int timeout) &ReadBytes, &JobBytes, &JobErrors, &VSS, &Encrypt) == 7) { fd_ok = true; - jcr->setJobStatus(jcr->impl->FDJobStatus); + jcr->setJobStatusWithPriorityCheck(jcr->impl->FDJobStatus); Dmsg1(100, "FDStatus=%c\n", (char)jcr->JobStatus); } else { Jmsg(jcr, M_WARNING, 0, _("Unexpected Client Job message: %s\n"), @@ -745,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)); @@ -828,7 +828,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 */ @@ -869,7 +869,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..8206cb53b 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,7 +343,7 @@ 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 */ diff --git a/core/src/dird/fd_cmds.cc b/core/src/dird/fd_cmds.cc index 38509c8df..146403e6d 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; @@ -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); @@ -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) _("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/job.cc b/core/src/dird/job.cc index a317f873a..30648b890 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")); } @@ -676,7 +677,7 @@ bool CancelJob(UaContext* ua, JobControlRecord* jcr) char ed1[50]; int32_t old_status = jcr->JobStatus; - 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); @@ -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); diff --git a/core/src/dird/jobq.cc b/core/src/dird/jobq.cc index 5d1bd8c17..d9a6883d6 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) { @@ -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; } @@ -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; @@ -676,7 +676,7 @@ static bool RescheduleJob(JobControlRecord* jcr, jobq_t* jq, jobq_item_t* je) njcr->impl->res.run_next_pool_override = jcr->impl->res.run_next_pool_override; njcr->JobStatus = -1; - njcr->setJobStatus(jcr->JobStatus); + njcr->setJobStatusWithPriorityCheck(jcr->JobStatus); 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..0194c7036 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,7 +1242,7 @@ 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); + jcr->setJobStatusWithPriorityCheck(JS_Terminated); MigrationCleanup(jcr, jcr->JobStatus); return true; } @@ -1252,7 +1252,7 @@ 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); + jcr->setJobStatusWithPriorityCheck(JS_Terminated); MigrationCleanup(jcr, jcr->JobStatus); 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); } } @@ -1515,10 +1515,10 @@ static inline bool DoMigrationSelection(JobControlRecord* jcr) retval = getJobs_to_migrate(jcr); if (retval) { - jcr->setJobStatus(JS_Terminated); + jcr->setJobStatusWithPriorityCheck(JS_Terminated); MigrationCleanup(jcr, jcr->JobStatus); } 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); 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..413343993 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)); diff --git a/core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc b/core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc index e879a1f31..9a2680cb5 100644 --- a/core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc +++ b/core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc @@ -325,7 +325,7 @@ 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 @@ -429,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)) { @@ -442,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_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/vbackup.cc b/core/src/dird/vbackup.cc index e06c12619..5370a6616 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,14 +368,14 @@ 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; } @@ -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)); 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..773a0cfa5 100644 --- a/core/src/filed/dir_cmd.cc +++ b/core/src/filed/dir_cmd.cc @@ -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/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/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 f338f88a5..816aa1a92 100644 --- a/core/src/include/jcr.h +++ b/core/src/include/jcr.h @@ -132,7 +132,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 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 */ 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/jcr.cc b/core/src/lib/jcr.cc index cc1f1e072..c3de7a874 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(); } @@ -743,7 +743,7 @@ bool JobControlRecord::sendJobStatus() bool JobControlRecord::sendJobStatus(int newJobStatus) { if (!is_JobStatus(newJobStatus)) { - setJobStatus(newJobStatus); + setJobStatusWithPriorityCheck(newJobStatus); if (dir_bsock) { return dir_bsock->fsend(Job_status, Job, JobStatus); } } @@ -756,7 +756,7 @@ void JobControlRecord::setJobStarted() job_started_time = time(nullptr); } -void JobControlRecord::setJobStatus(int newJobStatus) +void JobControlRecord::setJobStatusWithPriorityCheck(int newJobStatus) { int priority; int old_priority = 0; diff --git a/core/src/lib/message.cc b/core/src/lib/message.cc index ed45a30aa..1c4e66176 100644 --- a/core/src/lib/message.cc +++ b/core/src/lib/message.cc @@ -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/runscript.cc b/core/src/lib/runscript.cc index ee16bf438..94f1bfeac 100644 --- a/core/src/lib/runscript.cc +++ b/core/src/lib/runscript.cc @@ -190,7 +190,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 +274,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/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/append.cc b/core/src/stored/append.cc index 1c3336ec4..411890967 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 @@ -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/bscan.cc b/core/src/stored/bscan.cc index 041f0ee17..22dd2cc5f 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; 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/dir_cmd.cc b/core/src/stored/dir_cmd.cc index 078b21d1b..5e1180c52 100644 --- a/core/src/stored/dir_cmd.cc +++ b/core/src/stored/dir_cmd.cc @@ -518,7 +518,7 @@ static bool CancelCmd(JobControlRecord* cjcr) } oldStatus = jcr->JobStatus; - jcr->setJobStatus(status); + 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..a8ce421ba 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,7 +177,7 @@ 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); @@ -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; } diff --git a/core/src/stored/job.cc b/core/src/stored/job.cc index fd209fd79..f6a3d4318 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: diff --git a/core/src/stored/mac.cc b/core/src/stored/mac.cc index 38b952eff..9a24c02a6 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) { /* @@ -644,7 +644,7 @@ bail_out: JS_Terminated to write into EOS_LABEL */ char currentJobStatus = jcr->JobStatus; - jcr->setJobStatus(JS_Terminated); + 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,7 +708,7 @@ 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, diff --git a/core/src/stored/ndmp_tape.cc b/core/src/stored/ndmp_tape.cc index 5e0f15447..78693ca83 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; } @@ -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..b648a7f8f 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,7 +258,7 @@ 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); diff --git a/core/src/stored/spool.cc b/core/src/stored/spool.cc index 5b567eaca..cb8148ee6 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; 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(); -- cgit v1.2.3 From 61b44e4b967180c2eec19bda3934cc185b79f4b8 Mon Sep 17 00:00:00 2001 From: Alaa Eddine Elamri Date: Fri, 28 Oct 2022 13:00:42 +0200 Subject: rename forceJobStatus to setJobStatus --- core/src/dird/fd_cmds.cc | 2 +- core/src/include/jcr.h | 2 +- core/src/stored/spool.cc | 32 ++++++++++++++++---------------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/core/src/dird/fd_cmds.cc b/core/src/dird/fd_cmds.cc index 146403e6d..422d3effa 100644 --- a/core/src/dird/fd_cmds.cc +++ b/core/src/dird/fd_cmds.cc @@ -294,7 +294,7 @@ bool ConnectToFileDaemon(JobControlRecord* jcr, delete jcr->file_bsock; jcr->file_bsock = nullptr; } - jcr->forceJobStatus(JS_Running); + jcr->setJobStatus(JS_Running); jcr->impl->connection_handshake_try_ = ClientConnectionHandshakeMode::kCleartextFirst; break; diff --git a/core/src/include/jcr.h b/core/src/include/jcr.h index 816aa1a92..13270d394 100644 --- a/core/src/include/jcr.h +++ b/core/src/include/jcr.h @@ -118,7 +118,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_; } diff --git a/core/src/stored/spool.cc b/core/src/stored/spool.cc index cb8148ee6..770421aa6 100644 --- a/core/src/stored/spool.cc +++ b/core/src/stored/spool.cc @@ -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; } -- cgit v1.2.3 From d4c36b692473d72074abb014e9ef4d3054b403f0 Mon Sep 17 00:00:00 2001 From: Alaa Eddine Elamri Date: Fri, 28 Oct 2022 13:18:12 +0200 Subject: replace volatile jobstatus with atomic replace problematic accesses to JobStatus with getter --- core/src/dird/admin.cc | 3 ++- core/src/dird/archive.cc | 3 ++- core/src/dird/backup.cc | 7 ++++--- core/src/dird/consolidate.cc | 3 ++- core/src/dird/dir_plugins.cc | 2 +- core/src/dird/job.cc | 2 +- core/src/dird/jobq.cc | 2 +- core/src/dird/ndmp_dma_backup_common.cc | 3 ++- core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc | 4 ++-- core/src/dird/ua_status.cc | 4 ++-- core/src/dird/vbackup.cc | 3 ++- core/src/filed/dir_cmd.cc | 2 +- core/src/filed/fd_plugins.cc | 2 +- core/src/filed/status.cc | 3 ++- core/src/include/jcr.h | 2 +- core/src/lib/jcr.cc | 14 +++++++------- core/src/lib/runscript.cc | 10 +++++----- core/src/stored/append.cc | 2 +- core/src/stored/bscan.cc | 2 +- core/src/stored/fd_cmds.cc | 6 +++--- core/src/stored/job.cc | 2 +- core/src/stored/mac.cc | 4 ++-- core/src/stored/ndmp_tape.cc | 2 +- core/src/stored/sd_cmds.cc | 2 +- core/src/stored/sd_plugins.cc | 2 +- core/src/stored/status.cc | 3 ++- 26 files changed, 51 insertions(+), 43 deletions(-) diff --git a/core/src/dird/admin.cc b/core/src/dird/admin.cc index e3c91b2ef..8ce010cd9 100644 --- a/core/src/dird/admin.cc +++ b/core/src/dird/admin.cc @@ -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 1d0a3dfca..a90751499 100644 --- a/core/src/dird/archive.cc +++ b/core/src/dird/archive.cc @@ -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 bd41e9616..d004f691a 100644 --- a/core/src/dird/backup.cc +++ b/core/src/dird/backup.cc @@ -683,12 +683,12 @@ 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.load(), jcr->JobStatus, + 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.load(), jcr->JobStatus, + jcr->impl->FDJobStatus.load(), jcr->getJobStatus(), jcr->impl->SDJobStatus.load()); CancelStorageDaemonJob(jcr); } @@ -789,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; } diff --git a/core/src/dird/consolidate.cc b/core/src/dird/consolidate.cc index 8206cb53b..9216c080d 100644 --- a/core/src/dird/consolidate.cc +++ b/core/src/dird/consolidate.cc @@ -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 6c6637796..6cd0bc640 100644 --- a/core/src/dird/dir_plugins.cc +++ b/core/src/dird/dir_plugins.cc @@ -644,7 +644,7 @@ static bRC bareosGetValue(PluginContext* ctx, brDirVariable var, void* value) case bDirVarJobStatus: *((int*)value) = jcr->JobStatus; Dmsg1(debuglevel, "dir-plugin: return bDirVarJobStatus=%c\n", - jcr->JobStatus); + jcr->getJobStatus()); break; case bDirVarPriority: *((int*)value) = jcr->JobPriority; diff --git a/core/src/dird/job.cc b/core/src/dird/job.cc index 30648b890..8882ccdff 100644 --- a/core/src/dird/job.cc +++ b/core/src/dird/job.cc @@ -649,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; } diff --git a/core/src/dird/jobq.cc b/core/src/dird/jobq.cc index d9a6883d6..128cc59bc 100644 --- a/core/src/dird/jobq.cc +++ b/core/src/dird/jobq.cc @@ -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 diff --git a/core/src/dird/ndmp_dma_backup_common.cc b/core/src/dird/ndmp_dma_backup_common.cc index 413343993..b9e569fe1 100644 --- a/core/src/dird/ndmp_dma_backup_common.cc +++ b/core/src/dird/ndmp_dma_backup_common.cc @@ -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 9a2680cb5..955d07995 100644 --- a/core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc +++ b/core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc @@ -332,11 +332,11 @@ static inline int NdmpWaitForJobTermination(JobControlRecord* jcr) * so that we let the SD despool. */ Dmsg4(100, "cancel=%d FDJS=%d JS=%d SDJS=%d\n", jcr->IsCanceled(), - jcr->impl->FDJobStatus.load(), jcr->JobStatus, + 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.load(), - jcr->JobStatus, jcr->impl->SDJobStatus.load()); + jcr->getJobStatus(), jcr->impl->SDJobStatus.load()); CancelStorageDaemonJob(jcr); } diff --git a/core/src/dird/ua_status.cc b/core/src/dird/ua_status.cc index f73af0b90..8494227ce 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); @@ -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 5370a6616..29edcd2f3 100644 --- a/core/src/dird/vbackup.cc +++ b/core/src/dird/vbackup.cc @@ -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/filed/dir_cmd.cc b/core/src/filed/dir_cmd.cc index 773a0cfa5..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); diff --git a/core/src/filed/fd_plugins.cc b/core/src/filed/fd_plugins.cc index 07ffdefd3..43dc3e949 100644 --- a/core/src/filed/fd_plugins.cc +++ b/core/src/filed/fd_plugins.cc @@ -2056,7 +2056,7 @@ static bRC bareosGetValue(PluginContext* ctx, bVariable var, void* value) case bVarJobStatus: *((int*)value) = jcr->JobStatus; 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/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/include/jcr.h b/core/src/include/jcr.h index 13270d394..931c4d38e 100644 --- a/core/src/include/jcr.h +++ b/core/src/include/jcr.h @@ -165,7 +165,7 @@ 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 */ + std::atomic 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/jcr.cc b/core/src/lib/jcr.cc index c3de7a874..ae127a6b6 100644 --- a/core/src/lib/jcr.cc +++ b/core/src/lib/jcr.cc @@ -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; } @@ -744,7 +744,7 @@ bool JobControlRecord::sendJobStatus(int newJobStatus) { if (!is_JobStatus(newJobStatus)) { setJobStatusWithPriorityCheck(newJobStatus); - if (dir_bsock) { return dir_bsock->fsend(Job_status, Job, JobStatus); } + if (dir_bsock) { return dir_bsock->fsend(Job_status, Job, getJobStatus()); } } return true; @@ -1042,11 +1042,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/runscript.cc b/core/src/lib/runscript.cc index 94f1bfeac..8a17b7dd2 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()) { @@ -151,7 +151,7 @@ int RunScripts(JobControlRecord* jcr, && (JobCanceled(jcr) || jcr->JobStatus == 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; } } @@ -162,7 +162,7 @@ int RunScripts(JobControlRecord* 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; } } @@ -173,7 +173,7 @@ int RunScripts(JobControlRecord* jcr, && (JobCanceled(jcr) || jcr->JobStatus == 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; } } diff --git a/core/src/stored/append.cc b/core/src/stored/append.cc index 411890967..2fdedce74 100644 --- a/core/src/stored/append.cc +++ b/core/src/stored/append.cc @@ -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 diff --git a/core/src/stored/bscan.cc b/core/src/stored/bscan.cc index 22dd2cc5f..967354d8b 100644 --- a/core/src/stored/bscan.cc +++ b/core/src/stored/bscan.cc @@ -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); diff --git a/core/src/stored/fd_cmds.cc b/core/src/stored/fd_cmds.cc index a8ce421ba..917061b6d 100644 --- a/core/src/stored/fd_cmds.cc +++ b/core/src/stored/fd_cmds.cc @@ -181,7 +181,7 @@ void RunJob(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 */ @@ -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 f6a3d4318..623ca8aca 100644 --- a/core/src/stored/job.cc +++ b/core/src/stored/job.cc @@ -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/mac.cc b/core/src/stored/mac.cc index 9a24c02a6..a4c6a29f3 100644 --- a/core/src/stored/mac.cc +++ b/core/src/stored/mac.cc @@ -711,9 +711,9 @@ bail_out: 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 78693ca83..ada800e5f 100644 --- a/core/src/stored/ndmp_tape.cc +++ b/core/src/stored/ndmp_tape.cc @@ -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 diff --git a/core/src/stored/sd_cmds.cc b/core/src/stored/sd_cmds.cc index b648a7f8f..9cfc6bb0c 100644 --- a/core/src/stored/sd_cmds.cc +++ b/core/src/stored/sd_cmds.cc @@ -263,7 +263,7 @@ bool DoListenRun(JobControlRecord* jcr) 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..4b01a6a72 100644 --- a/core/src/stored/sd_plugins.cc +++ b/core/src/stored/sd_plugins.cc @@ -738,7 +738,7 @@ static bRC bareosGetValue(PluginContext* ctx, bsdrVariable var, void* value) case bsdVarJobStatus: *((int*)value) = jcr->JobStatus; 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/status.cc b/core/src/stored/status.cc index 27dd18f67..2451d52d4 100644 --- a/core/src/stored/status.cc +++ b/core/src/stored/status.cc @@ -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); -- cgit v1.2.3 From c94a9a9ff09cc7c398e3621f0314573c9fc44ef6 Mon Sep 17 00:00:00 2001 From: Alaa Eddine Elamri Date: Fri, 28 Oct 2022 13:38:46 +0200 Subject: make JobStatus private and replace accesses with setter and getter --- core/src/cats/sql_create.cc | 6 +++--- core/src/cats/sql_update.cc | 2 +- core/src/dird/admin.cc | 2 +- core/src/dird/archive.cc | 2 +- core/src/dird/backup.cc | 6 +++--- core/src/dird/consolidate.cc | 2 +- core/src/dird/dir_plugins.cc | 2 +- core/src/dird/jcr_private.h | 24 +++++++++++++----------- core/src/dird/job.cc | 10 +++++----- core/src/dird/jobq.cc | 6 +++--- core/src/dird/migrate.cc | 14 +++++++------- core/src/dird/ndmp_dma_backup_common.cc | 2 +- core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc | 2 +- core/src/dird/ua_cmds.cc | 6 +++--- core/src/dird/ua_select.cc | 10 +++++++--- core/src/dird/ua_status.cc | 10 +++++----- core/src/dird/vbackup.cc | 6 +++--- core/src/filed/fd_plugins.cc | 2 +- core/src/include/jcr.h | 11 ++++++----- core/src/lib/jcr.cc | 2 +- core/src/lib/message.cc | 4 ++-- core/src/lib/recent_job_results_list.cc | 4 ++-- core/src/lib/runscript.cc | 11 +++++++---- core/src/lib/util.cc | 2 +- core/src/stored/bscan.cc | 6 +++--- core/src/stored/butil.cc | 2 +- core/src/stored/dir_cmd.cc | 2 +- core/src/stored/label.cc | 2 +- core/src/stored/mac.cc | 2 +- core/src/stored/sd_plugins.cc | 2 +- core/src/stored/status.cc | 6 +++--- 31 files changed, 90 insertions(+), 80 deletions(-) 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 8ce010cd9..d51e60a36 100644 --- a/core/src/dird/admin.cc +++ b/core/src/dird/admin.cc @@ -84,7 +84,7 @@ void AdminCleanup(JobControlRecord* jcr, int TermCode) } msg_type = M_INFO; /* by default INFO message */ - switch (jcr->JobStatus) { + switch (jcr->getJobStatus()) { case JS_Terminated: TermMsg = _("Admin OK"); break; diff --git a/core/src/dird/archive.cc b/core/src/dird/archive.cc index a90751499..dad5ac6ab 100644 --- a/core/src/dird/archive.cc +++ b/core/src/dird/archive.cc @@ -83,7 +83,7 @@ void ArchiveCleanup(JobControlRecord* jcr, int TermCode) } msg_type = M_INFO; /* by default INFO message */ - switch (jcr->JobStatus) { + switch (jcr->getJobStatus()) { case JS_Terminated: TermMsg = _("Archive OK"); break; diff --git a/core/src/dird/backup.cc b/core/src/dird/backup.cc index d004f691a..8ab09913a 100644 --- a/core/src/dird/backup.cc +++ b/core/src/dird/backup.cc @@ -657,7 +657,7 @@ int WaitForJobTermination(JobControlRecord* jcr, int timeout) == 7) { fd_ok = true; jcr->setJobStatusWithPriorityCheck(jcr->impl->FDJobStatus); - Dmsg1(100, "FDStatus=%c\n", (char)jcr->JobStatus); + Dmsg1(100, "FDStatus=%c\n", (char)jcr->getJobStatus()); } else { Jmsg(jcr, M_WARNING, 0, _("Unexpected Client Job message: %s\n"), fd->msg); @@ -717,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; } @@ -757,7 +757,7 @@ void NativeBackupCleanup(JobControlRecord* jcr, int TermCode) UpdateBootstrapFile(jcr); - switch (jcr->JobStatus) { + switch (jcr->getJobStatus()) { case JS_Terminated: TermMsg = _("Backup OK"); break; diff --git a/core/src/dird/consolidate.cc b/core/src/dird/consolidate.cc index 9216c080d..4fdedbb23 100644 --- a/core/src/dird/consolidate.cc +++ b/core/src/dird/consolidate.cc @@ -347,7 +347,7 @@ void ConsolidateCleanup(JobControlRecord* jcr, int TermCode) } msg_type = M_INFO; /* by default INFO message */ - switch (jcr->JobStatus) { + switch (jcr->getJobStatus()) { case JS_Terminated: TermMsg = _("Consolidate OK"); break; diff --git a/core/src/dird/dir_plugins.cc b/core/src/dird/dir_plugins.cc index 6cd0bc640..183938919 100644 --- a/core/src/dird/dir_plugins.cc +++ b/core/src/dird/dir_plugins.cc @@ -642,7 +642,7 @@ 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->getJobStatus()); break; diff --git a/core/src/dird/jcr_private.h b/core/src/dird/jcr_private.h index 810ea58d9..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 */ diff --git a/core/src/dird/job.cc b/core/src/dird/job.cc index 8882ccdff..4114688b9 100644 --- a/core/src/dird/job.cc +++ b/core/src/dird/job.cc @@ -675,7 +675,7 @@ 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->setJobStatusWithPriorityCheck(JS_Canceled); @@ -957,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: @@ -1399,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_, @@ -1413,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; @@ -1636,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 128cc59bc..8c4281ab3 100644 --- a/core/src/dird/jobq.cc +++ b/core/src/dird/jobq.cc @@ -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; } @@ -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->setJobStatusWithPriorityCheck(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 { diff --git a/core/src/dird/migrate.cc b/core/src/dird/migrate.cc index 0194c7036..8280e7c48 100644 --- a/core/src/dird/migrate.cc +++ b/core/src/dird/migrate.cc @@ -1243,7 +1243,7 @@ static inline bool DoActualMigration(JobControlRecord* jcr) edit_int64(jcr->impl->previous_jr.JobId, ed1), jcr->get_ActionName(true), jcr->get_OperationName()); jcr->setJobStatusWithPriorityCheck(JS_Terminated); - MigrationCleanup(jcr, jcr->JobStatus); + MigrationCleanup(jcr, jcr->getJobStatus()); return true; } @@ -1253,7 +1253,7 @@ static inline bool DoActualMigration(JobControlRecord* jcr) edit_int64(jcr->impl->previous_jr.JobId, ed1), jcr->get_OperationName()); jcr->setJobStatusWithPriorityCheck(JS_Terminated); - MigrationCleanup(jcr, jcr->JobStatus); + MigrationCleanup(jcr, jcr->getJobStatus()); return true; } @@ -1501,7 +1501,7 @@ bail_out: FreePairedStorage(jcr); if (jcr->is_JobStatus(JS_Terminated)) { - MigrationCleanup(jcr, jcr->JobStatus); + MigrationCleanup(jcr, jcr->getJobStatus()); retval = true; } @@ -1516,7 +1516,7 @@ static inline bool DoMigrationSelection(JobControlRecord* jcr) retval = getJobs_to_migrate(jcr); if (retval) { jcr->setJobStatusWithPriorityCheck(JS_Terminated); - MigrationCleanup(jcr, jcr->JobStatus); + MigrationCleanup(jcr, jcr->getJobStatus()); } else { jcr->setJobStatusWithPriorityCheck(JS_ErrorTerminated); } @@ -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/ndmp_dma_backup_common.cc b/core/src/dird/ndmp_dma_backup_common.cc index b9e569fe1..3d43e1f94 100644 --- a/core/src/dird/ndmp_dma_backup_common.cc +++ b/core/src/dird/ndmp_dma_backup_common.cc @@ -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; diff --git a/core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc b/core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc index 955d07995..6d1f2c44b 100644 --- a/core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc +++ b/core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc @@ -344,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; } 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* 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_status.cc b/core/src/dird/ua_status.cc index 8494227ce..20e830194 100644 --- a/core/src/dird/ua_status.cc +++ b/core/src/dird/ua_status.cc @@ -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; diff --git a/core/src/dird/vbackup.cc b/core/src/dird/vbackup.cc index 29edcd2f3..9acd1b67d 100644 --- a/core/src/dird/vbackup.cc +++ b/core/src/dird/vbackup.cc @@ -380,7 +380,7 @@ bool DoNativeVbackup(JobControlRecord* jcr) 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 @@ -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; diff --git a/core/src/filed/fd_plugins.cc b/core/src/filed/fd_plugins.cc index 43dc3e949..b992e1af2 100644 --- a/core/src/filed/fd_plugins.cc +++ b/core/src/filed/fd_plugins.cc @@ -2054,7 +2054,7 @@ 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->getJobStatus()); break; diff --git a/core/src/include/jcr.h b/core/src/include/jcr.h index 931c4d38e..1b7949184 100644 --- a/core/src/include/jcr.h +++ b/core/src/include/jcr.h @@ -67,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))) @@ -83,6 +84,7 @@ class JobControlRecord { private: pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; /**< Jcr mutex */ std::atomic _use_count{}; /**< Use count */ + std::atomic JobStatus{}; /**< ready, running, blocked, terminated */ int32_t JobType_{}; /**< Backup, restore, verify ... */ int32_t JobLevel_{}; /**< Job level */ int32_t Protocol_{}; /**< Backup Protocol */ @@ -165,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 */ - std::atomic 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/jcr.cc b/core/src/lib/jcr.cc index ae127a6b6..71447eaa7 100644 --- a/core/src/lib/jcr.cc +++ b/core/src/lib/jcr.cc @@ -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: diff --git a/core/src/lib/message.cc b/core/src/lib/message.cc index 1c4e66176..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; 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 8a17b7dd2..57ab1a2f3 100644 --- a/core/src/lib/runscript.cc +++ b/core/src/lib/runscript.cc @@ -146,9 +146,11 @@ 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->getJobStatus()); @@ -157,7 +159,7 @@ int RunScripts(JobControlRecord* jcr, } 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", @@ -170,7 +172,8 @@ 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->getJobStatus()); 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/stored/bscan.cc b/core/src/stored/bscan.cc index 967354d8b..6c5fbb5da 100644 --- a/core/src/stored/bscan.cc +++ b/core/src/stored/bscan.cc @@ -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; @@ -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/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/dir_cmd.cc b/core/src/stored/dir_cmd.cc index 5e1180c52..3a91ad245 100644 --- a/core/src/stored/dir_cmd.cc +++ b/core/src/stored/dir_cmd.cc @@ -517,7 +517,7 @@ static bool CancelCmd(JobControlRecord* cjcr) } } - oldStatus = jcr->JobStatus; + oldStatus = jcr->getJobStatus(); jcr->setJobStatusWithPriorityCheck(status); Dmsg2(800, "Cancel JobId=%d %p\n", jcr->JobId, jcr); diff --git a/core/src/stored/label.cc b/core/src/stored/label.cc index 3ecb57c7c..c2f6e1a80 100644 --- a/core/src/stored/label.cc +++ b/core/src/stored/label.cc @@ -624,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 a4c6a29f3..52936d1a6 100644 --- a/core/src/stored/mac.cc +++ b/core/src/stored/mac.cc @@ -643,7 +643,7 @@ bail_out: memorize current JobStatus and set to JS_Terminated to write into EOS_LABEL */ - char currentJobStatus = jcr->JobStatus; + char currentJobStatus = jcr->getJobStatus(); jcr->setJobStatusWithPriorityCheck(JS_Terminated); // Write End Of Session Label diff --git a/core/src/stored/sd_plugins.cc b/core/src/stored/sd_plugins.cc index 4b01a6a72..53d4ed56a 100644 --- a/core/src/stored/sd_plugins.cc +++ b/core/src/stored/sd_plugins.cc @@ -736,7 +736,7 @@ 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->getJobStatus()); break; diff --git a/core/src/stored/status.cc b/core/src/stored/status.cc index 2451d52d4..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); -- cgit v1.2.3 From 608f067fa68047cdb1cbe9cb9dcf5741bcb43f6b Mon Sep 17 00:00:00 2001 From: Alaa Eddine Elamri Date: Fri, 28 Oct 2022 15:54:16 +0200 Subject: use compare exchange before changing status --- core/src/lib/jcr.cc | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/core/src/lib/jcr.cc b/core/src/lib/jcr.cc index 71447eaa7..cd983b894 100644 --- a/core/src/lib/jcr.cc +++ b/core/src/lib/jcr.cc @@ -759,13 +759,9 @@ void JobControlRecord::setJobStarted() 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); @@ -789,7 +785,7 @@ void JobControlRecord::setJobStatusWithPriorityCheck(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) { -- cgit v1.2.3 From b1c6f2cecd92a881e7929631527a766130565397 Mon Sep 17 00:00:00 2001 From: Alaa Eddine Elamri Date: Fri, 28 Oct 2022 19:40:57 +0200 Subject: vol_mgr: replace construct_at with placement new Certain compilers we use in our containers seem to not support std::construct_at --- core/src/stored/vol_mgr.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/stored/vol_mgr.cc b/core/src/stored/vol_mgr.cc index 7cc1b3b93..b4eff74cc 100644 --- a/core/src/stored/vol_mgr.cc +++ b/core/src/stored/vol_mgr.cc @@ -262,7 +262,7 @@ static VolumeReservationItem* new_vol_item(DeviceControlRecord* dcr, VolumeReservationItem* vol; vol = (VolumeReservationItem*)malloc(sizeof(VolumeReservationItem)); - std::construct_at(vol); + vol = new (vol) VolumeReservationItem(); vol->vol_name = strdup(VolumeName); if (dcr) { -- cgit v1.2.3 From 01cbf13f0b898b39c3bc361ec49528bf2f537b72 Mon Sep 17 00:00:00 2001 From: Andreas Rogge Date: Mon, 7 Nov 2022 13:54:36 +0100 Subject: python-fd: force C++17 for python modules C++20 supports designated initializers. However, it doesn't allow mixing of named and unnamed initialization. As we need to use the PyVarObject_HEAD_INIT() macro, which doesn't name the attributes it sets, we have to downgrade the compiler to C++17, so designated initializers are handled as compiler extension, which will allow the mixing that occurs here. See also: https://github.com/python/cpython/issues/99202 --- core/src/plugins/filed/python/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) 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 "") -- cgit v1.2.3 From 392277507d57e6a70ba69551b1aa62f5306914bc Mon Sep 17 00:00:00 2001 From: Andreas Rogge Date: Mon, 7 Nov 2022 15:36:29 +0100 Subject: Updated CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) 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 -- cgit v1.2.3