From 4af688cebbe4712fc6bade299bb081d0292984d8 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 22 Nov 2006 15:48:29 +0000 Subject: [PATCH] kes Make sure that the storage for a job is pulled first from the Pool and if not from the Job. kes Ensure that either the Pool or the Job specifies a Storage resource. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3687 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/dird.c | 5 +++++ bacula/src/dird/job.c | 38 +++++++++++++++++++++++++++++++++--- bacula/src/dird/protos.h | 1 + bacula/src/dird/ua_dotcmds.c | 2 +- bacula/src/dird/ua_output.c | 2 +- bacula/src/dird/ua_run.c | 4 ++-- bacula/src/dird/ua_status.c | 2 +- bacula/technotes-1.39 | 5 +++++ 8 files changed, 51 insertions(+), 8 deletions(-) diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index 2d19f24ec9..0077507b30 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -726,6 +726,11 @@ static int check_resources() Emsg0(M_ERROR_TERM, 0, _("Too many items in Job resource\n")); } } + if (!job->storage && !job->pool->storage) { + Jmsg(NULL, M_FATAL, 0, _("No storage specified in Job \"%s\" nor in Pool.\n"), + job->hdr.name); + OK = false; + } } /* End loop over Job res */ /* Loop over databases */ diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index f817e88632..798ff22037 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -883,6 +883,20 @@ void dird_free_jcr(JCR *jcr) Dmsg0(200, "End dird free_jcr\n"); } +/* + * The Job storage definition must be either in the Job record + * or in the Pool record. The Pool record overrides the Job + * record. + */ +STORE *get_job_storage(JOB *job) +{ + if (job->pool->storage) { + return (STORE *)job->pool->storage->first(); + } else { + return (STORE *)job->storage->first(); + } +} + /* * Set some defaults in the JCR necessary to * run. These items are pulled from the job @@ -916,7 +930,11 @@ void set_jcr_defaults(JCR *jcr, JOB *job) } jcr->JobPriority = job->Priority; /* Copy storage definitions -- deleted in dir_free_jcr above */ - copy_rwstorage(jcr, job->storage, _("Job resource")); + if (job->storage) { + copy_rwstorage(jcr, job->storage, _("Job resource")); + } else { + copy_rwstorage(jcr, job->pool->storage, _("Job resource")); + } jcr->client = job->client; if (!jcr->client_name) { jcr->client_name = get_pool_memory(PM_NAME); @@ -974,6 +992,10 @@ void copy_rwstorage(JCR *jcr, alist *storage, const char *where) /* Set storage override */ void set_rwstorage(JCR *jcr, STORE *store) { + if (!store) { + Jmsg(jcr, M_FATAL, 0, _("No storage specified.\n")); + return; + } set_rstorage(jcr, store); set_wstorage(jcr, store); } @@ -1011,6 +1033,12 @@ void set_rstorage(JCR *jcr, STORE *store) { STORE *storage; + if (!store) { + return; + } + if (!jcr->rstorage) { + jcr->rstorage = New(alist(10, not_owned_by_alist)); + } jcr->rstore = store; foreach_alist(storage, jcr->rstorage) { if (store == storage) { @@ -1057,6 +1085,12 @@ void set_wstorage(JCR *jcr, STORE *store) { STORE *storage; + if (!store) { + return; + } + if (!jcr->wstorage) { + jcr->wstorage = New(alist(10, not_owned_by_alist)); + } jcr->wstore = store; foreach_alist(storage, jcr->wstorage) { if (store == storage) { @@ -1076,8 +1110,6 @@ void free_wstorage(JCR *jcr) jcr->wstore = NULL; } - - void create_clones(JCR *jcr) { /* diff --git a/bacula/src/dird/protos.h b/bacula/src/dird/protos.h index ccd7708568..1c48fc9ab1 100644 --- a/bacula/src/dird/protos.h +++ b/bacula/src/dird/protos.h @@ -111,6 +111,7 @@ extern DBId_t get_or_create_pool_record(JCR *jcr, char *pool_name); extern void apply_pool_overrides(JCR *jcr); extern JobId_t run_job(JCR *jcr); extern bool cancel_job(UAContext *ua, JCR *jcr); +extern STORE *get_job_storage(JOB *job); extern void init_jcr_job_record(JCR *jcr); extern void copy_rwstorage(JCR *jcr, alist *storage, const char *where); extern void set_rwstorage(JCR *jcr, STORE *store); diff --git a/bacula/src/dird/ua_dotcmds.c b/bacula/src/dird/ua_dotcmds.c index ecb26693c7..2552cd2f70 100644 --- a/bacula/src/dird/ua_dotcmds.c +++ b/bacula/src/dird/ua_dotcmds.c @@ -296,7 +296,7 @@ static int defaultscmd(UAContext *ua, const char *cmd) bsendmsg(ua, "pool=%s", job->pool->hdr.name); bsendmsg(ua, "messages=%s", job->messages->hdr.name); bsendmsg(ua, "client=%s", job->client->hdr.name); - store = (STORE *)job->storage->first(); + store = get_job_storage(job); bsendmsg(ua, "storage=%s", store->hdr.name); bsendmsg(ua, "where=%s", job->RestoreWhere?job->RestoreWhere:""); bsendmsg(ua, "level=%s", level_to_str(job->JobLevel)); diff --git a/bacula/src/dird/ua_output.c b/bacula/src/dird/ua_output.c index 30352ef11d..ce329205d5 100644 --- a/bacula/src/dird/ua_output.c +++ b/bacula/src/dird/ua_output.c @@ -483,7 +483,7 @@ static bool list_nextvol(UAContext *ua, int ndays) if (run->storage) { jcr->wstore = run->storage; } else { - jcr->wstore = (STORE *)job->storage->first(); + jcr->wstore = get_job_storage(job); } mr.StorageId = jcr->wstore->StorageId; if (!find_next_volume_for_append(jcr, &mr, 1, false/*no create*/)) { diff --git a/bacula/src/dird/ua_run.c b/bacula/src/dird/ua_run.c index 55b60907b9..ddc82bd206 100644 --- a/bacula/src/dird/ua_run.c +++ b/bacula/src/dird/ua_run.c @@ -352,8 +352,8 @@ int run_cmd(UAContext *ua, const char *cmd) } store = select_storage_resource(ua); } - } else if (job->storage) { - store = (STORE *)job->storage->first(); /* use default */ + } else { + store = get_job_storage(job); /* use default */ } if (!store) { return 1; diff --git a/bacula/src/dird/ua_status.c b/bacula/src/dird/ua_status.c index 7a4715d338..89afc6fb25 100644 --- a/bacula/src/dird/ua_status.c +++ b/bacula/src/dird/ua_status.c @@ -483,7 +483,7 @@ static void list_scheduled_jobs(UAContext *ua) if (run->storage) { store = run->storage; } else { - store = (STORE *)job->storage->first(); + store = get_job_storage(job); } if (!hdr_printed) { prt_runhdr(ua); diff --git a/bacula/technotes-1.39 b/bacula/technotes-1.39 index 6b336eebda..b19a25f78e 100644 --- a/bacula/technotes-1.39 +++ b/bacula/technotes-1.39 @@ -1,6 +1,11 @@ Technical notes on version 1.39 General: +22Nov06 +kes Make sure that the storage for a job is pulled first from + the Pool and if not from the Job. +kes Ensure that either the Pool or the Job specifies a Storage + resource. 21Nov06 kes Start applying new FSFE copyright. 20Nov06 -- 2.39.5