Skip to content

Commit

Permalink
jcr.h: remove JobCanceled macro and replace with method
Browse files Browse the repository at this point in the history
  • Loading branch information
alaaeddineelamri authored and pstorz committed May 30, 2023
1 parent 5f1d377 commit f281c12
Show file tree
Hide file tree
Showing 38 changed files with 112 additions and 115 deletions.
12 changes: 6 additions & 6 deletions core/src/dird/backup.cc
Expand Up @@ -205,7 +205,7 @@ static int AccurateListHandler(void* ctx, int num_fields, char** row)
{
JobControlRecord* jcr = (JobControlRecord*)ctx;

if (JobCanceled(jcr)) { return 1; }
if (jcr->IsJobCanceled()) { return 1; }

if (row[2][0] == '0') { /* discard when file_index == 0 */
return 0;
Expand Down Expand Up @@ -297,7 +297,7 @@ bool SendAccurateCurrentFiles(JobControlRecord* jcr)
db_list_ctx nb;

// In base level, no previous job is used and no restart incomplete jobs
if (jcr->IsCanceled() || jcr->is_JobLevel(L_BASE)) { return true; }
if (jcr->IsJobCanceled() || jcr->is_JobLevel(L_BASE)) { return true; }

if (!jcr->accurate) { return true; }

Expand Down Expand Up @@ -664,7 +664,7 @@ int WaitForJobTermination(JobControlRecord* jcr, int timeout)
Jmsg(jcr, M_WARNING, 0, _("Unexpected Client Job message: %s\n"),
fd->msg);
}
if (JobCanceled(jcr)) { break; }
if (jcr->IsJobCanceled()) { break; }
}
if (tid) { StopBsockTimer(tid); }

Expand All @@ -673,7 +673,7 @@ int WaitForJobTermination(JobControlRecord* jcr, int timeout)
Jmsg(jcr, M_FATAL, 0, _("Network error with FD during %s: ERR=%s\n"),
job_type_to_str(jcr->getJobType()), fd->bstrerror());
while (i++ < 10 && jcr->dir_impl->res.job->RescheduleIncompleteJobs
&& jcr->IsCanceled()) {
&& jcr->IsJobCanceled()) {
Bmicrosleep(3, 0);
}
}
Expand All @@ -682,10 +682,10 @@ int WaitForJobTermination(JobControlRecord* jcr, int timeout)

/* Force cancel in SD if failing, but not for Incomplete jobs so that we let
* the SD despool. */
Dmsg5(100, "cancel=%d fd_ok=%d FDJS=%d JS=%d SDJS=%d\n", jcr->IsCanceled(),
Dmsg5(100, "cancel=%d fd_ok=%d FDJS=%d JS=%d SDJS=%d\n", jcr->IsJobCanceled(),
fd_ok, jcr->dir_impl->FDJobStatus.load(), jcr->getJobStatus(),
jcr->dir_impl->SDJobStatus.load());
if (jcr->IsCanceled()
if (jcr->IsJobCanceled()
|| (!jcr->dir_impl->res.job->RescheduleIncompleteJobs && !fd_ok)) {
Dmsg4(100, "fd_ok=%d FDJS=%d JS=%d SDJS=%d\n", fd_ok,
jcr->dir_impl->FDJobStatus.load(), jcr->getJobStatus(),
Expand Down
30 changes: 15 additions & 15 deletions core/src/dird/job.cc
Expand Up @@ -222,7 +222,7 @@ bool SetupJob(JobControlRecord* jcr, bool suppress_output)
DispatchNewPluginOptions(jcr);
GeneratePluginEvent(jcr, bDirEventJobStart);

if (JobCanceled(jcr)) { goto bail_out; }
if (jcr->IsJobCanceled()) { goto bail_out; }

if (jcr->JobReads() && !jcr->dir_impl->res.read_storage_list) {
if (jcr->dir_impl->res.job->storage) {
Expand Down Expand Up @@ -493,7 +493,7 @@ static void* job_thread(void* arg)
case JT_BACKUP:
switch (jcr->getJobProtocol()) {
case PT_NDMP_BAREOS:
if (!JobCanceled(jcr)) {
if (!jcr->IsJobCanceled()) {
if (DoNdmpBackup(jcr)) {
DoAutoprune(jcr);
} else {
Expand All @@ -504,7 +504,7 @@ static void* job_thread(void* arg)
}
break;
case PT_NDMP_NATIVE:
if (!JobCanceled(jcr)) {
if (!jcr->IsJobCanceled()) {
if (DoNdmpBackupNdmpNative(jcr)) {
DoAutoprune(jcr);
} else {
Expand All @@ -515,7 +515,7 @@ static void* job_thread(void* arg)
}
break;
default:
if (!JobCanceled(jcr)) {
if (!jcr->IsJobCanceled()) {
if (jcr->is_JobLevel(L_VIRTUAL_FULL)) {
if (DoNativeVbackup(jcr)) {
DoAutoprune(jcr);
Expand All @@ -540,7 +540,7 @@ static void* job_thread(void* arg)
}
break;
case JT_VERIFY:
if (!JobCanceled(jcr)) {
if (!jcr->IsJobCanceled()) {
if (DoVerify(jcr)) {
DoAutoprune(jcr);
} else {
Expand All @@ -553,7 +553,7 @@ static void* job_thread(void* arg)
case JT_RESTORE:
switch (jcr->getJobProtocol()) {
case PT_NDMP_BAREOS:
if (!JobCanceled(jcr)) {
if (!jcr->IsJobCanceled()) {
if (DoNdmpRestore(jcr)) {
DoAutoprune(jcr);
} else {
Expand All @@ -564,7 +564,7 @@ static void* job_thread(void* arg)
}
break;
case PT_NDMP_NATIVE:
if (!JobCanceled(jcr)) {
if (!jcr->IsJobCanceled()) {
if (DoNdmpRestoreNdmpNative(jcr)) {
DoAutoprune(jcr);
} else {
Expand All @@ -575,7 +575,7 @@ static void* job_thread(void* arg)
}
break;
default:
if (!JobCanceled(jcr)) {
if (!jcr->IsJobCanceled()) {
if (DoNativeRestore(jcr)) {
DoAutoprune(jcr);
} else {
Expand All @@ -588,7 +588,7 @@ static void* job_thread(void* arg)
}
break;
case JT_ADMIN:
if (!JobCanceled(jcr)) {
if (!jcr->IsJobCanceled()) {
if (do_admin(jcr)) {
DoAutoprune(jcr);
} else {
Expand All @@ -599,7 +599,7 @@ static void* job_thread(void* arg)
}
break;
case JT_ARCHIVE:
if (!JobCanceled(jcr)) {
if (!jcr->IsJobCanceled()) {
if (DoArchive(jcr)) {
DoAutoprune(jcr);
} else {
Expand All @@ -611,7 +611,7 @@ static void* job_thread(void* arg)
break;
case JT_COPY:
case JT_MIGRATE:
if (!JobCanceled(jcr)) {
if (!jcr->IsJobCanceled()) {
if (DoMigration(jcr)) {
DoAutoprune(jcr);
} else {
Expand All @@ -622,7 +622,7 @@ static void* job_thread(void* arg)
}
break;
case JT_CONSOLIDATE:
if (!JobCanceled(jcr)) {
if (!jcr->IsJobCanceled()) {
if (DoConsolidate(jcr)) {
DoAutoprune(jcr);
} else {
Expand Down Expand Up @@ -730,7 +730,7 @@ static void JobMonitorWatchdog(watchdog_t* self)
foreach_jcr (jcr) {
bool cancel = false;

if (jcr->JobId == 0 || JobCanceled(jcr) || jcr->dir_impl->no_maxtime) {
if (jcr->JobId == 0 || jcr->IsJobCanceled() || jcr->dir_impl->no_maxtime) {
Dmsg2(800, "Skipping JobControlRecord=%p Job=%s\n", jcr, jcr->Job);
continue;
}
Expand Down Expand Up @@ -801,7 +801,7 @@ static bool JobCheckMaxruntime(JobControlRecord* jcr)
JobResource* job = jcr->dir_impl->res.job;
utime_t run_time;

if (JobCanceled(jcr) || !jcr->job_started) { return false; }
if (jcr->IsJobCanceled() || !jcr->job_started) { return false; }
if (job->MaxRunTime == 0 && job->FullMaxRunTime == 0
&& job->IncMaxRunTime == 0 && job->DiffMaxRunTime == 0) {
return false;
Expand Down Expand Up @@ -837,7 +837,7 @@ static bool JobCheckMaxruntime(JobControlRecord* jcr)
*/
static bool JobCheckMaxrunschedtime(JobControlRecord* jcr)
{
if (jcr->dir_impl->MaxRunSchedTime == 0 || JobCanceled(jcr)) { return false; }
if (jcr->dir_impl->MaxRunSchedTime == 0 || jcr->IsJobCanceled()) { return false; }
if ((watchdog_time - jcr->initial_sched_time)
< jcr->dir_impl->MaxRunSchedTime) {
Dmsg3(200, "Job %p (%s) with MaxRunSchedTime %d not expired\n", jcr,
Expand Down
8 changes: 4 additions & 4 deletions core/src/dird/jobq.cc
Expand Up @@ -182,7 +182,7 @@ extern "C" void* sched_wait(void* arg)
wtime, jcr->UseCount());
if (wtime > 30) { wtime = 30; }
Bmicrosleep(wtime, 0);
if (JobCanceled(jcr)) { break; }
if (jcr->IsJobCanceled()) { break; }
wtime = jcr->sched_time - time(NULL);
}
Dmsg1(200, "resched use=%d\n", jcr->UseCount());
Expand Down Expand Up @@ -227,7 +227,7 @@ int JobqAdd(jobq_t* jq, JobControlRecord* jcr)
jcr->IncUseCount(); /* mark jcr in use by us */
Dmsg3(2300, "JobqAdd jobid=%d jcr=0x%x UseCount=%d\n", jcr->JobId, jcr,
jcr->UseCount());
if (!JobCanceled(jcr) && wtime > 0) {
if (!jcr->IsJobCanceled() && wtime > 0) {
sched_pkt = (wait_pkt*)malloc(sizeof(wait_pkt));
sched_pkt->jcr = jcr;
sched_pkt->jq = jq;
Expand All @@ -250,7 +250,7 @@ int JobqAdd(jobq_t* jq, JobControlRecord* jcr)

// While waiting in a queue this job is not attached to a thread
SetJcrInThreadSpecificData(nullptr);
if (JobCanceled(jcr)) {
if (jcr->IsJobCanceled()) {
// Add job to ready queue so that it is canceled quickly
jq->ready_jobs->prepend(item);
Dmsg1(2300, "Prepended job=%d to ready queue\n", jcr->JobId);
Expand Down Expand Up @@ -515,7 +515,7 @@ extern "C" void* jobq_server(void* arg)

if (!AcquireResources(jcr)) {
// If resource conflict, job is canceled
if (!JobCanceled(jcr)) {
if (!jcr->IsJobCanceled()) {
je = jn; /* point to next waiting job */
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/dird/msgchan.cc
Expand Up @@ -433,7 +433,7 @@ bool StartStorageDaemonMessageThread(JobControlRecord* jcr)
/* Wait for thread to start */
while (!jcr->dir_impl->SD_msg_chan_started) {
Bmicrosleep(0, 50);
if (JobCanceled(jcr) || jcr->dir_impl->sd_msg_thread_done) { return false; }
if (jcr->IsJobCanceled() || jcr->dir_impl->sd_msg_thread_done) { return false; }
}
Dmsg1(100, "SD msg_thread started. use=%d\n", jcr->UseCount());
return true;
Expand Down Expand Up @@ -483,7 +483,7 @@ extern "C" void* msg_thread(void* arg)
// Read the Storage daemon's output.
Dmsg0(100, "Start msg_thread loop\n");
n = 0;
while (!JobCanceled(jcr) && (n = BgetDirmsg(sd)) >= 0) {
while (!jcr->IsJobCanceled() && (n = BgetDirmsg(sd)) >= 0) {
Dmsg1(400, "<stored: %s", sd->msg);
/*
* Check for "3000 OK Job Authorization="
Expand Down Expand Up @@ -545,7 +545,7 @@ void WaitForStorageDaemonTermination(JobControlRecord* jcr)
lock_mutex(mutex);
pthread_cond_timedwait(&jcr->dir_impl->term_wait, &mutex, &timeout);
unlock_mutex(mutex);
if (jcr->IsCanceled()) {
if (jcr->IsJobCanceled()) {
if (jcr->dir_impl->SD_msg_chan_started) {
jcr->store_bsock->SetTimedOut();
jcr->store_bsock->SetTerminated();
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/ndmp_dma_backup_NDMP_NATIVE.cc
Expand Up @@ -64,7 +64,7 @@ int is_job_canceled_cb(struct ndm_session* sess)
NIS* nis = (NIS*)sess->param->log.ctx;
JobControlRecord* jcr = nis->jcr;

return jcr->IsCanceled();
return jcr->IsJobCanceled();
}


Expand Down
4 changes: 2 additions & 2 deletions core/src/dird/ndmp_dma_restore_NDMP_BAREOS.cc
Expand Up @@ -331,10 +331,10 @@ static inline int NdmpWaitForJobTermination(JobControlRecord* jcr)
* Force cancel in SD if failing, but not for Incomplete jobs
* so that we let the SD despool.
*/
Dmsg4(100, "cancel=%d FDJS=%d JS=%d SDJS=%d\n", jcr->IsCanceled(),
Dmsg4(100, "cancel=%d FDJS=%d JS=%d SDJS=%d\n", jcr->IsJobCanceled(),
jcr->dir_impl->FDJobStatus.load(), jcr->getJobStatus(),
jcr->dir_impl->SDJobStatus.load());
if (jcr->IsCanceled()
if (jcr->IsJobCanceled()
|| (!jcr->dir_impl->res.job->RescheduleIncompleteJobs)) {
Dmsg3(100, "FDJS=%d JS=%d SDJS=%d\n", jcr->dir_impl->FDJobStatus.load(),
jcr->getJobStatus(), jcr->dir_impl->SDJobStatus.load());
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/ndmp_dma_restore_common.cc
Expand Up @@ -184,7 +184,7 @@ void NdmpRestoreCleanup(JobControlRecord* jcr, int TermCode)
jcr->dir_impl->unlink_bsr = false;
}

if (JobCanceled(jcr)) { CancelStorageDaemonJob(jcr); }
if (jcr->IsJobCanceled()) { CancelStorageDaemonJob(jcr); }

switch (TermCode) {
case JS_Terminated:
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/restore.cc
Expand Up @@ -420,7 +420,7 @@ void NativeRestoreCleanup(JobControlRecord* jcr, int TermCode)
jcr->dir_impl->unlink_bsr = false;
}

if (JobCanceled(jcr)) { CancelStorageDaemonJob(jcr); }
if (jcr->IsJobCanceled()) { CancelStorageDaemonJob(jcr); }

if (jcr->dir_impl->ExpectedFiles != jcr->JobFiles) {
Jmsg(jcr, M_WARNING, 0,
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/storage.cc
Expand Up @@ -511,7 +511,7 @@ bool SelectNextRstore(JobControlRecord* jcr, bootstrap_info& info)
return true;
}
Bmicrosleep(10, 0); /* Sleep 10 secs */
if (JobCanceled(jcr)) {
if (jcr->IsJobCanceled()) {
FreeRstorage(jcr);
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions core/src/dird/verify.cc
Expand Up @@ -449,7 +449,7 @@ void VerifyCleanup(JobControlRecord* jcr, int TermCode)

UpdateJobEnd(jcr, TermCode);

if (JobCanceled(jcr)) { CancelStorageDaemonJob(jcr); }
if (jcr->IsJobCanceled()) { CancelStorageDaemonJob(jcr); }

if (jcr->dir_impl->unlink_bsr && jcr->RestoreBootstrap) {
SecureErase(jcr, jcr->RestoreBootstrap);
Expand Down Expand Up @@ -588,12 +588,12 @@ void GetAttributesAndCompareToCatalog(JobControlRecord* jcr, JobId_t JobId)
* Filename
* Attributes
* Link name ??? */
while ((n = BgetDirmsg(fd)) >= 0 && !JobCanceled(jcr)) {
while ((n = BgetDirmsg(fd)) >= 0 && !jcr->IsJobCanceled()) {
int stream;
char *attr, *p, *fn;
PoolMem Opts_Digest(PM_MESSAGE); /* Verify Opts or MD5/SHA1 digest */

if (JobCanceled(jcr)) { goto bail_out; }
if (jcr->IsJobCanceled()) { goto bail_out; }
fname = CheckPoolMemorySize(fname, fd->message_length);
jcr->dir_impl->fname
= CheckPoolMemorySize(jcr->dir_impl->fname, fd->message_length);
Expand Down Expand Up @@ -839,7 +839,7 @@ static int MissingHandler(void* ctx, int, char** row)
{
JobControlRecord* jcr = (JobControlRecord*)ctx;

if (JobCanceled(jcr)) { return 1; }
if (jcr->IsJobCanceled()) { return 1; }
if (!jcr->dir_impl->fn_printed) {
Qmsg(jcr, M_WARNING, 0,
_("The following files are in the Catalog but not on %s:\n"),
Expand Down
4 changes: 2 additions & 2 deletions core/src/filed/accurate.cc
Expand Up @@ -113,7 +113,7 @@ bool AccurateFinish(JobControlRecord* jcr)
{
bool retval = true;

if (jcr->IsCanceled() || jcr->IsIncomplete()) {
if (jcr->IsJobCanceled() || jcr->IsIncomplete()) {
AccurateFree(jcr);
return retval;
}
Expand Down Expand Up @@ -330,7 +330,7 @@ bool AccurateCmd(JobControlRecord* jcr)
uint16_t delta_seq;
BareosSocket* dir = jcr->dir_bsock;

if (JobCanceled(jcr)) { return true; }
if (jcr->IsJobCanceled()) { return true; }

if (sscanf(dir->msg, "accurate files=%u", &number_of_previous_files) != 1) {
dir->fsend(_("2991 Bad accurate command\n"));
Expand Down
8 changes: 4 additions & 4 deletions core/src/filed/backup.cc
Expand Up @@ -508,7 +508,7 @@ int SaveFile(JobControlRecord* jcr, FindFilesPacket* ff_pkt, bool)
save_pkt sp; /* use by option plugin */
BareosSocket* sd = jcr->store_bsock;

if (jcr->IsCanceled() || jcr->IsIncomplete()) { return 0; }
if (jcr->IsJobCanceled() || jcr->IsIncomplete()) { return 0; }

jcr->fd_impl->num_files_examined++; /* bump total file count */

Expand Down Expand Up @@ -815,10 +815,10 @@ int SaveFile(JobControlRecord* jcr, FindFilesPacket* ff_pkt, bool)
}

good_rtn:
rtnstat = jcr->IsCanceled() ? 0 : 1; /* good return if not canceled */
rtnstat = jcr->IsJobCanceled() ? 0 : 1; /* good return if not canceled */

bail_out:
if (jcr->IsIncomplete() || jcr->IsCanceled()) { rtnstat = 0; }
if (jcr->IsIncomplete() || jcr->IsJobCanceled()) { rtnstat = 0; }
if (plugin_started) {
SendPluginName(jcr, sd, false); /* signal end of plugin data */
}
Expand Down Expand Up @@ -1214,7 +1214,7 @@ bool EncodeAndSendAttributes(JobControlRecord* jcr,
/* Send Attributes header to Storage daemon
* <file-index> <stream> <info> */
if (!sd->fsend("%ld %d 0", jcr->JobFiles, attr_stream)) {
if (!jcr->IsCanceled() && !jcr->IsIncomplete()) {
if (!jcr->IsJobCanceled() && !jcr->IsIncomplete()) {
Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
sd->bstrerror());
}
Expand Down

0 comments on commit f281c12

Please sign in to comment.