From 5edc81d75c34a45717926607c120f1a123dd09b0 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Fri, 24 Nov 2006 11:14:59 +0000 Subject: [PATCH] Cleanup some of the error termination code in migration. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3691 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/console/console.c | 12 +++++ bacula/src/dird/job.c | 8 +-- bacula/src/dird/migrate.c | 100 ++++++++++++++++++----------------- bacula/technotes-1.39 | 1 + 4 files changed, 69 insertions(+), 52 deletions(-) diff --git a/bacula/src/console/console.c b/bacula/src/console/console.c index 1bef020596..3356c361cb 100644 --- a/bacula/src/console/console.c +++ b/bacula/src/console/console.c @@ -99,6 +99,7 @@ static int inputcmd(FILE *input, BSOCK *UA_sock); static int outputcmd(FILE *input, BSOCK *UA_sock); static int teecmd(FILE *input, BSOCK *UA_sock); static int quitcmd(FILE *input, BSOCK *UA_sock); +static int echocmd(FILE *input, BSOCK *UA_sock); static int timecmd(FILE *input, BSOCK *UA_sock); static int sleepcmd(FILE *input, BSOCK *UA_sock); @@ -164,6 +165,7 @@ static struct cmdstruct commands[] = { { N_("sleep"), sleepcmd, _("sleep specified time")}, { N_("time"), timecmd, _("print current time")}, { N_("version"), versioncmd, _("print Console's version")}, + { N_("echo"), echocmd, _("echo command string")}, { N_("exit"), quitcmd, _("exit = quit")}, { N_("zed_keys"), zed_keyscmd, _("zed_keys = use zed keys instead of bash keys")}, }; @@ -891,6 +893,16 @@ static int do_outputcmd(FILE *input, BSOCK *UA_sock) return 1; } +static int echocmd(FILE *intut, BSOCK *UA_sock) +{ + for (int i=1; i < argc; i++) { + senditf("%s", argk[i]); + sendit(" "); + } + sendit("\n"); + return 1; +} + static int quitcmd(FILE *input, BSOCK *UA_sock) { return 0; diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 43d5bdcdd3..09fdc13b40 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -896,20 +896,20 @@ void get_job_storage(USTORE *store, JOB *job, RUN *run) { if (run && run->pool && run->pool->storage) { store->store = (STORE *)run->pool->storage->first(); - pm_strcpy(store->store_source, _("run pool override")); + pm_strcpy(store->store_source, _("Run pool override")); return; } if (run && run->storage) { store->store = run->storage; - pm_strcpy(store->store_source, _("run storage override")); + pm_strcpy(store->store_source, _("Run storage override")); return; } if (job->pool->storage) { store->store = (STORE *)job->pool->storage->first(); - pm_strcpy(store->store_source, _("job pool storage")); + pm_strcpy(store->store_source, _("Pool resource")); } else { store->store = (STORE *)job->storage->first(); - pm_strcpy(store->store_source, _("job storage")); + pm_strcpy(store->store_source, _("Job resource")); } } diff --git a/bacula/src/dird/migrate.c b/bacula/src/dird/migrate.c index 6f660a6b59..a9edb88176 100644 --- a/bacula/src/dird/migrate.c +++ b/bacula/src/dird/migrate.c @@ -124,14 +124,6 @@ bool do_migration_init(JCR *jcr) return false; } - /* If pool storage specified, use it instead of job storage */ - copy_wstorage(jcr, jcr->pool->storage, _("Pool resource")); - - if (jcr->wstorage->size() == 0) { - Jmsg(jcr, M_FATAL, 0, _("No Storage specification found in Job or Pool.\n")); - return false; - } - create_restore_bootstrap_file(jcr); if (jcr->previous_jr.JobId == 0 || jcr->ExpectedFiles == 0) { @@ -159,7 +151,13 @@ bool do_migration_init(JCR *jcr) job = (JOB *)GetResWithName(R_JOB, jcr->jr.Name); prev_job = (JOB *)GetResWithName(R_JOB, jcr->previous_jr.Name); UnlockRes(); - if (!job || !prev_job) { + if (!job) { + Jmsg(jcr, M_FATAL, 0, _("Job resource not found for \"%s\".\n"), jcr->jr.Name); + return false; + } + if (!prev_job) { + Jmsg(jcr, M_FATAL, 0, _("Previous Job resource not found for \"%s\".\n"), + jcr->previous_jr.Name); return false; } @@ -173,6 +171,7 @@ bool do_migration_init(JCR *jcr) */ set_jcr_defaults(mig_jcr, prev_job); if (!setup_job(mig_jcr)) { + Jmsg(jcr, M_FATAL, 0, _("setup job failed.\n")); return false; } @@ -232,15 +231,14 @@ bool do_migration_init(JCR *jcr) return false; } - if (!jcr->pool->storage) { + if (!jcr->pool->storage || jcr->pool->storage->size() == 0) { Jmsg(jcr, M_FATAL, 0, _("No Storage specification found in Next Pool \"%s\".\n"), jcr->pool->hdr.name); return false; } /* If pool storage specified, use it instead of job storage for backup */ - copy_wstorage(jcr, jcr->pool->storage, _("Next pool resource")); - + copy_wstorage(jcr, jcr->pool->storage, _("NextPool in Pool resource")); return true; } @@ -257,6 +255,10 @@ bool do_migration(JCR *jcr) BSOCK *sd; JCR *mig_jcr = jcr->mig_jcr; /* newly migrated job */ + if (!mig_jcr) { + Jmsg(jcr, M_INFO, 0, _("No files found to migrate.\n")); + return false; + } /* Print Job Start message */ Jmsg(jcr, M_INFO, 0, _("Start Migration JobId %s, Job=%s\n"), @@ -788,7 +790,6 @@ ok_out: goto out; bail_out: - jcr->MigrateJobId = 0; ok = false; out: @@ -1031,41 +1032,42 @@ void migration_cleanup(JCR *jcr, int TermCode) } mig_jcr->VolumeName[0] = 0; /* none */ } - } - - msg_type = M_INFO; /* by default INFO message */ - switch (jcr->JobStatus) { - case JS_Terminated: - if (jcr->Errors || jcr->SDErrors) { - term_msg = _("%s OK -- with warnings"); - } else { - term_msg = _("%s OK"); - } - break; - case JS_FatalError: - case JS_ErrorTerminated: - term_msg = _("*** %s Error ***"); - msg_type = M_ERROR; /* Generate error message */ - if (jcr->store_bsock) { - bnet_sig(jcr->store_bsock, BNET_TERMINATE); - if (jcr->SD_msg_chan) { - pthread_cancel(jcr->SD_msg_chan); + switch (jcr->JobStatus) { + case JS_Terminated: + if (jcr->Errors || jcr->SDErrors) { + term_msg = _("%s OK -- with warnings"); + } else { + term_msg = _("%s OK"); } - } - break; - case JS_Canceled: - term_msg = _("%s Canceled"); - if (jcr->store_bsock) { - bnet_sig(jcr->store_bsock, BNET_TERMINATE); - if (jcr->SD_msg_chan) { - pthread_cancel(jcr->SD_msg_chan); + break; + case JS_FatalError: + case JS_ErrorTerminated: + term_msg = _("*** %s Error ***"); + msg_type = M_ERROR; /* Generate error message */ + if (jcr->store_bsock) { + bnet_sig(jcr->store_bsock, BNET_TERMINATE); + if (jcr->SD_msg_chan) { + pthread_cancel(jcr->SD_msg_chan); + } + } + break; + case JS_Canceled: + term_msg = _("%s Canceled"); + if (jcr->store_bsock) { + bnet_sig(jcr->store_bsock, BNET_TERMINATE); + if (jcr->SD_msg_chan) { + pthread_cancel(jcr->SD_msg_chan); + } } + break; + default: + term_msg = _("Inappropriate %s term code"); + break; } - break; - default: - term_msg = _("Inappropriate %s term code"); - break; - } + } else { + term_msg = _("%s -- no files to migrate"); + } + bsnprintf(term_code, sizeof(term_code), term_msg, "Migration"); bstrftimes(sdt, sizeof(sdt), jcr->jr.StartTime); bstrftimes(edt, sizeof(edt), jcr->jr.EndTime); @@ -1088,7 +1090,7 @@ void migration_cleanup(JCR *jcr, int TermCode) " Client: %s\n" " FileSet: \"%s\" %s\n" " Pool: \"%s\" (From %s)\n" -" Read Storage: \"%s\" (From %s_\n" +" Read Storage: \"%s\" (From %s)\n" " Write Storage: \"%s\" (From %s)\n" " Start time: %s\n" " End time: %s\n" @@ -1115,8 +1117,10 @@ void migration_cleanup(JCR *jcr, int TermCode) jcr->client->name(), jcr->fileset->name(), jcr->FSCreateTime, jcr->pool->name(), jcr->pool_source, - jcr->rstore->name(), jcr->rstore_source, - jcr->wstore->name(), jcr->wstore_source, + jcr->rstore?jcr->rstore->name():"*None*", + NPRT(jcr->rstore_source), + jcr->wstore?jcr->wstore->name():"*None*", + NPRT(jcr->wstore_source), sdt, edt, edit_utime(RunTime, elapsed, sizeof(elapsed)), diff --git a/bacula/technotes-1.39 b/bacula/technotes-1.39 index 933422cfe2..0e6b0395d1 100644 --- a/bacula/technotes-1.39 +++ b/bacula/technotes-1.39 @@ -2,6 +2,7 @@ General: 22Nov06 +kes Cleanup some of the error termination code in migration. kes Separate read/write source strings to keep track of where storage devices are used in a job. kes Implement a new method of keeping track of which storage -- 2.39.5