Skip to content

Commit

Permalink
jcr: swapped some #defined functions into static function calls
Browse files Browse the repository at this point in the history
- added JobCanceled and JobTerminatedSuccessfully
- added JobWaiting
- swapped IsCanceled with JobCanceled
  • Loading branch information
franku committed Jul 10, 2018
1 parent 91f4640 commit 41c993b
Show file tree
Hide file tree
Showing 48 changed files with 187 additions and 188 deletions.
4 changes: 2 additions & 2 deletions core/src/cats/sql_create.cc
Expand Up @@ -823,7 +823,7 @@ bool BareosDb::WriteBatchFileRecords(JobControlRecord *jcr)
return true;
}

if (JobCanceled(jcr)) {
if (JobControlRecord::JobCanceled(jcr)) {
goto bail_out;
}

Expand All @@ -837,7 +837,7 @@ bool BareosDb::WriteBatchFileRecords(JobControlRecord *jcr)
Jmsg1(jcr, M_FATAL, 0, "Batch end %s\n", errmsg);
goto bail_out;
}
if (JobCanceled(jcr)) {
if (JobControlRecord::JobCanceled(jcr)) {
goto bail_out;
}

Expand Down
16 changes: 8 additions & 8 deletions core/src/dird/backup.cc
Expand Up @@ -218,7 +218,7 @@ static int AccurateListHandler(void *ctx, int num_fields, char **row)
{
JobControlRecord *jcr = (JobControlRecord *)ctx;

if (JobCanceled(jcr)) {
if (JobControlRecord::JobCanceled(jcr)) {
return 1;
}

Expand Down Expand Up @@ -317,7 +317,7 @@ bool SendAccurateCurrentFiles(JobControlRecord *jcr)
/*
* In base level, no previous job is used and no restart incomplete jobs
*/
if (jcr->IsCanceled() || jcr->is_JobLevel(L_BASE)) {
if (jcr->JobCanceled() || jcr->is_JobLevel(L_BASE)) {
return true;
}

Expand Down Expand Up @@ -726,7 +726,7 @@ int WaitForJobTermination(JobControlRecord *jcr, int timeout)
Jmsg(jcr, M_WARNING, 0, _("Unexpected Client Job message: %s\n"),
fd->msg);
}
if (JobCanceled(jcr)) {
if (JobControlRecord::JobCanceled(jcr)) {
break;
}
}
Expand All @@ -738,7 +738,7 @@ int WaitForJobTermination(JobControlRecord *jcr, int timeout)
int i = 0;
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->res.job->RescheduleIncompleteJobs && jcr->IsCanceled()) {
while (i++ < 10 && jcr->res.job->RescheduleIncompleteJobs && jcr->JobCanceled()) {
Bmicrosleep(3, 0);
}

Expand All @@ -749,9 +749,9 @@ 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(), fd_ok, jcr->FDJobStatus,
Dmsg5(100, "cancel=%d fd_ok=%d FDJS=%d JS=%d SDJS=%d\n", jcr->JobCanceled(), fd_ok, jcr->FDJobStatus,
jcr->JobStatus, jcr->SDJobStatus);
if (jcr->IsCanceled() || (!jcr->res.job->RescheduleIncompleteJobs && !fd_ok)) {
if (jcr->JobCanceled() || (!jcr->res.job->RescheduleIncompleteJobs && !fd_ok)) {
Dmsg4(100, "fd_ok=%d FDJS=%d JS=%d SDJS=%d\n", fd_ok, jcr->FDJobStatus,
jcr->JobStatus, jcr->SDJobStatus);
CancelStorageDaemonJob(jcr);
Expand Down Expand Up @@ -873,7 +873,7 @@ void UpdateBootstrapFile(JobControlRecord *jcr)
/*
* Now update the bootstrap file if any
*/
if (jcr->IsTerminatedOk() &&
if (jcr->JobTerminatedSuccessfully() &&
jcr->jr.JobBytes &&
jcr->res.job->WriteBootstrap) {
FILE *fd;
Expand Down Expand Up @@ -987,7 +987,7 @@ void GenerateBackupSummary(JobControlRecord *jcr, ClientDbRecord *cr, int msg_ty
* it is normal. Or look at it the other way, only for a
* normal exit should we complain about this error.
*/
if (jcr->IsTerminatedOk() && jcr->jr.JobBytes) {
if (jcr->JobTerminatedSuccessfully() && jcr->jr.JobBytes) {
Jmsg(jcr, M_ERROR, 0, "%s", jcr->db->strerror());
}
jcr->VolumeName[0] = 0; /* none */
Expand Down
12 changes: 6 additions & 6 deletions core/src/dird/catreq.cc
Expand Up @@ -658,7 +658,7 @@ void CatalogUpdate(JobControlRecord *jcr, BareosSocket *bs)
return; /* user disabled cataloging */
}

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

Expand All @@ -674,7 +674,7 @@ void CatalogUpdate(JobControlRecord *jcr, BareosSocket *bs)
UpdateAttribute(jcr, bs->msg, bs->message_length);

bail_out:
if (jcr->IsJobCanceled()) {
if (jcr->JobCanceled()) {
CancelStorageDaemonJob(jcr);
}
}
Expand All @@ -696,7 +696,7 @@ bool DespoolAttributesFromFile(JobControlRecord *jcr, const char *file)

Dmsg0(100, "Begin DespoolAttributesFromFile\n");

if (jcr->IsJobCanceled() || !jcr->res.pool->catalog_files || !jcr->db) {
if (jcr->JobCanceled() || !jcr->res.pool->catalog_files || !jcr->db) {
goto bail_out; /* user disabled cataloging */
}

Expand Down Expand Up @@ -733,9 +733,9 @@ bool DespoolAttributesFromFile(JobControlRecord *jcr, const char *file)
size += nbytes;
}

if (!jcr->IsJobCanceled()) {
if (!jcr->JobCanceled()) {
UpdateAttribute(jcr, msg, message_length);
if (jcr->IsJobCanceled()) {
if (jcr->JobCanceled()) {
goto bail_out;
}
}
Expand All @@ -748,7 +748,7 @@ bool DespoolAttributesFromFile(JobControlRecord *jcr, const char *file)
close(spool_fd);
}

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

Expand Down
4 changes: 2 additions & 2 deletions core/src/dird/dir_plugins.cc
Expand Up @@ -252,7 +252,7 @@ bRC GeneratePluginEvent(JobControlRecord *jcr, bDirEventType eventType, void *va
}
}

if (jcr->IsJobCanceled()) {
if (jcr->JobCanceled()) {
Dmsg0(debuglevel, "Cancel return from GeneratePluginEvent\n");
rc = bRC_Cancel;
}
Expand Down Expand Up @@ -524,7 +524,7 @@ void NewPlugins(JobControlRecord *jcr)
Dmsg0(debuglevel, "No dir plugin list!\n");
return;
}
if (jcr->IsJobCanceled()) {
if (jcr->JobCanceled()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/fd_cmds.cc
Expand Up @@ -779,7 +779,7 @@ static int RestoreObjectHandler(void *ctx, int num_fields, char **row)
JobControlRecord *jcr = octx->jcr;

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

Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/getmsg.cc
Expand Up @@ -89,7 +89,7 @@ static void SetJcrSdJobStatus(JobControlRecord *jcr, int SDJobStatus)
break;
}

if (JobWaiting(jcr)) {
if (JobControlRecord::JobWaiting(jcr)) {
set_waittime = false;
}

Expand Down
36 changes: 18 additions & 18 deletions core/src/dird/job.cc
Expand Up @@ -235,7 +235,7 @@ bool SetupJob(JobControlRecord *jcr, bool suppress_output)
DispatchNewPluginOptions(jcr);
GeneratePluginEvent(jcr, bDirEventJobStart);

if (JobCanceled(jcr)) {
if (JobControlRecord::JobCanceled(jcr)) {
goto bail_out;
}

Expand Down Expand Up @@ -358,7 +358,7 @@ bool SetupJob(JobControlRecord *jcr, bool suppress_output)
* If there is nothing to do the DoMigrationInit() function will set
* the termination status to JS_Terminated.
*/
if (JobTerminatedSuccessfully(jcr)) {
if (JobControlRecord::JobTerminatedSuccessfully(jcr)) {
MigrationCleanup(jcr, jcr->getJobStatus());
goto bail_out;
}
Expand All @@ -373,7 +373,7 @@ bool SetupJob(JobControlRecord *jcr, bool suppress_output)
* If there is nothing to do the do_consolidation_init() function will set
* the termination status to JS_Terminated.
*/
if (JobTerminatedSuccessfully(jcr)) {
if (JobControlRecord::JobTerminatedSuccessfully(jcr)) {
ConsolidateCleanup(jcr, jcr->getJobStatus());
goto bail_out;
}
Expand Down Expand Up @@ -513,7 +513,7 @@ static void *job_thread(void *arg)
case JT_BACKUP:
switch (jcr->getJobProtocol()) {
case PT_NDMP_BAREOS:
if (!JobCanceled(jcr)) {
if (!JobControlRecord::JobCanceled(jcr)) {
if (DoNdmpBackup(jcr)) {
DoAutoprune(jcr);
} else {
Expand All @@ -524,7 +524,7 @@ static void *job_thread(void *arg)
}
break;
case PT_NDMP_NATIVE:
if (!JobCanceled(jcr)) {
if (!JobControlRecord::JobCanceled(jcr)) {
if (DoNdmpBackupNdmpNative(jcr)) {
DoAutoprune(jcr);
} else {
Expand All @@ -535,7 +535,7 @@ static void *job_thread(void *arg)
}
break;
default:
if (!JobCanceled(jcr)) {
if (!JobControlRecord::JobCanceled(jcr)) {
if (jcr->is_JobLevel(L_VIRTUAL_FULL)) {
if (DoNativeVbackup(jcr)) {
DoAutoprune(jcr);
Expand All @@ -560,7 +560,7 @@ static void *job_thread(void *arg)
}
break;
case JT_VERIFY:
if (!JobCanceled(jcr)) {
if (!JobControlRecord::JobCanceled(jcr)) {
if (DoVerify(jcr)) {
DoAutoprune(jcr);
} else {
Expand All @@ -573,7 +573,7 @@ static void *job_thread(void *arg)
case JT_RESTORE:
switch (jcr->getJobProtocol()) {
case PT_NDMP_BAREOS:
if (!JobCanceled(jcr)) {
if (!JobControlRecord::JobCanceled(jcr)) {
if (DoNdmpRestore(jcr)) {
DoAutoprune(jcr);
} else {
Expand All @@ -584,7 +584,7 @@ static void *job_thread(void *arg)
}
break;
case PT_NDMP_NATIVE:
if (!JobCanceled(jcr)) {
if (!JobControlRecord::JobCanceled(jcr)) {
if (DoNdmpRestoreNdmpNative(jcr)) {
DoAutoprune(jcr);
} else {
Expand All @@ -595,7 +595,7 @@ static void *job_thread(void *arg)
}
break;
default:
if (!JobCanceled(jcr)) {
if (!JobControlRecord::JobCanceled(jcr)) {
if (DoNativeRestore(jcr)) {
DoAutoprune(jcr);
} else {
Expand All @@ -608,7 +608,7 @@ static void *job_thread(void *arg)
}
break;
case JT_ADMIN:
if (!JobCanceled(jcr)) {
if (!JobControlRecord::JobCanceled(jcr)) {
if (do_admin(jcr)) {
DoAutoprune(jcr);
} else {
Expand All @@ -619,7 +619,7 @@ static void *job_thread(void *arg)
}
break;
case JT_ARCHIVE:
if (!JobCanceled(jcr)) {
if (!JobControlRecord::JobCanceled(jcr)) {
if (DoArchive(jcr)) {
DoAutoprune(jcr);
} else {
Expand All @@ -631,7 +631,7 @@ static void *job_thread(void *arg)
break;
case JT_COPY:
case JT_MIGRATE:
if (!JobCanceled(jcr)) {
if (!JobControlRecord::JobCanceled(jcr)) {
if (DoMigration(jcr)) {
DoAutoprune(jcr);
} else {
Expand All @@ -642,7 +642,7 @@ static void *job_thread(void *arg)
}
break;
case JT_CONSOLIDATE:
if (!JobCanceled(jcr)) {
if (!JobControlRecord::JobCanceled(jcr)) {
if (DoConsolidate(jcr)) {
DoAutoprune(jcr);
} else {
Expand Down Expand Up @@ -776,7 +776,7 @@ static void JobMonitorWatchdog(watchdog_t *self)
foreach_jcr(jcr) {
bool cancel = false;

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

if (!JobWaiting(jcr)) {
if (!JobControlRecord::JobWaiting(jcr)) {
return false;
}

Expand Down Expand Up @@ -850,7 +850,7 @@ static bool JobCheckMaxruntime(JobControlRecord *jcr)
JobResource *job = jcr->res.job;
utime_t run_time;

if (JobCanceled(jcr) || !jcr->job_started) {
if (JobControlRecord::JobCanceled(jcr) || !jcr->job_started) {
return false;
}
if (job->MaxRunTime == 0 && job->FullMaxRunTime == 0 &&
Expand Down Expand Up @@ -888,7 +888,7 @@ static bool JobCheckMaxruntime(JobControlRecord *jcr)
*/
static bool JobCheckMaxrunschedtime(JobControlRecord *jcr)
{
if (jcr->MaxRunSchedTime == 0 || JobCanceled(jcr)) {
if (jcr->MaxRunSchedTime == 0 || JobControlRecord::JobCanceled(jcr)) {
return false;
}
if ((watchdog_time - jcr->initial_sched_time) < jcr->MaxRunSchedTime) {
Expand Down
10 changes: 5 additions & 5 deletions core/src/dird/jobq.cc
Expand Up @@ -191,7 +191,7 @@ extern "C" void *sched_wait(void *arg)
wtime = 30;
}
Bmicrosleep(wtime, 0);
if (JobCanceled(jcr)) {
if (JobControlRecord::JobCanceled(jcr)) {
break;
}
wtime = jcr->sched_time - time(NULL);
Expand Down Expand Up @@ -237,7 +237,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 (!JobControlRecord::JobCanceled(jcr) && wtime > 0) {
SetThreadConcurrency(jq->max_workers + 2);
sched_pkt = (wait_pkt *)malloc(sizeof(wait_pkt));
sched_pkt->jcr = jcr;
Expand All @@ -262,7 +262,7 @@ int JobqAdd(jobq_t *jq, JobControlRecord *jcr)
* While waiting in a queue this job is not attached to a thread
*/
SetJcrInTsd(INVALID_JCR);
if (JobCanceled(jcr)) {
if (JobControlRecord::JobCanceled(jcr)) {
/*
* Add job to ready queue so that it is canceled quickly
*/
Expand Down Expand Up @@ -565,7 +565,7 @@ extern "C" void *jobq_server(void *arg)
/*
* If resource conflict, job is canceled
*/
if (!JobCanceled(jcr)) {
if (!JobControlRecord::JobCanceled(jcr)) {
je = jn; /* point to next waiting job */
continue;
}
Expand Down Expand Up @@ -670,7 +670,7 @@ static bool RescheduleJob(JobControlRecord *jcr, jobq_t *jq, jobq_item_t *je)
* Check for failed jobs
*/
(jcr->res.job->RescheduleOnError &&
!jcr->IsTerminatedOk() &&
!jcr->JobTerminatedSuccessfully() &&
!jcr->is_JobStatus(JS_Canceled) &&
jcr->is_JobType(JT_BACKUP));
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/dird/migrate.cc
Expand Up @@ -1834,7 +1834,7 @@ void MigrationCleanup(JobControlRecord *jcr, int TermCode)
new_jobid);
jcr->db->SqlQuery(query.c_str());

if (jcr->IsTerminatedOk()) {
if (jcr->JobTerminatedSuccessfully()) {
UaContext *ua;

switch (jcr->getJobType()) {
Expand Down Expand Up @@ -1943,7 +1943,7 @@ void MigrationCleanup(JobControlRecord *jcr, int TermCode)
* it is normal. Or look at it the other way, only for a
* normal exit should we complain about this error.
*/
if (jcr->IsTerminatedOk() && jcr->jr.JobBytes) {
if (jcr->JobTerminatedSuccessfully() && jcr->jr.JobBytes) {
Jmsg(jcr, M_ERROR, 0, "%s", mig_jcr->db->strerror());
}
mig_jcr->VolumeName[0] = 0; /* none */
Expand Down

0 comments on commit 41c993b

Please sign in to comment.