From f5730f7ef70171d6b637d64c55b7b0da584c403a Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 29 Aug 2009 15:07:02 +0200 Subject: [PATCH] Fix bug #1357 Verify jobs fail when job has zero files --- bacula/src/dird/bsr.c | 4 ++++ bacula/src/dird/job.c | 12 +++++++++--- bacula/src/dird/migrate.c | 5 ++++- bacula/src/dird/protos.h | 2 +- bacula/src/dird/verify.c | 12 +++++++++++- bacula/src/version.h | 4 ++-- bacula/technotes | 2 ++ 7 files changed, 33 insertions(+), 8 deletions(-) diff --git a/bacula/src/dird/bsr.c b/bacula/src/dird/bsr.c index f8b7598930..96d30c0ca3 100644 --- a/bacula/src/dird/bsr.c +++ b/bacula/src/dird/bsr.c @@ -176,6 +176,10 @@ bool complete_bsr(UAContext *ua, RBSR *bsr) } bsr->VolSessionId = jr.VolSessionId; bsr->VolSessionTime = jr.VolSessionTime; + if (jr.JobFiles == 0) { /* zero files is OK, not an error, but */ + bsr->VolCount = 0; /* there are no volumes */ + continue; + } if ((bsr->VolCount=db_get_job_volume_parameters(ua->jcr, ua->db, bsr->JobId, &(bsr->VolParams))) == 0) { ua->error_msg(_("Unable to get Job Volume Parameters. ERR=%s\n"), db_strerror(ua->db)); diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 6a11f9d389..acb6480d12 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -1367,17 +1367,22 @@ void create_clones(JCR *jcr) /* * Given: a JobId in jcr->previous_jr.JobId, * this subroutine writes a bsr file to restore that job. + * Returns: -1 on error + * number of files if OK */ -bool create_restore_bootstrap_file(JCR *jcr) +int create_restore_bootstrap_file(JCR *jcr) { RESTORE_CTX rx; UAContext *ua; + int files; + memset(&rx, 0, sizeof(rx)); rx.bsr = new_bsr(); rx.JobIds = (char *)""; rx.bsr->JobId = jcr->previous_jr.JobId; ua = new_ua_context(jcr); if (!complete_bsr(ua, rx.bsr)) { + files = -1; goto bail_out; } rx.bsr->fi = new_findex(); @@ -1385,17 +1390,18 @@ bool create_restore_bootstrap_file(JCR *jcr) rx.bsr->fi->findex2 = jcr->previous_jr.JobFiles; jcr->ExpectedFiles = write_bsr_file(ua, rx); if (jcr->ExpectedFiles == 0) { + files = 0; goto bail_out; } free_ua_context(ua); free_bsr(rx.bsr); jcr->needs_sd = true; - return true; + return jcr->ExpectedFiles; bail_out: free_ua_context(ua); free_bsr(rx.bsr); - return false; + return files; } /* TODO: redirect command ouput to job log */ diff --git a/bacula/src/dird/migrate.c b/bacula/src/dird/migrate.c index b8fb64d89e..2ffadb76fc 100644 --- a/bacula/src/dird/migrate.c +++ b/bacula/src/dird/migrate.c @@ -152,7 +152,10 @@ bool do_migration_init(JCR *jcr) return true; /* no work */ } - create_restore_bootstrap_file(jcr); + if (create_restore_bootstrap_file(jcr) < 0) { + Jmsg(jcr, M_FATAL, 0, _("Create bootstrap file failed.\n")); + return false; + } if (jcr->previous_jr.JobId == 0 || jcr->ExpectedFiles == 0) { set_jcr_job_status(jcr, JS_Terminated); diff --git a/bacula/src/dird/protos.h b/bacula/src/dird/protos.h index 402c965ac1..a19bdded4d 100644 --- a/bacula/src/dird/protos.h +++ b/bacula/src/dird/protos.h @@ -137,7 +137,7 @@ extern void set_rstorage(JCR *jcr, USTORE *store); extern void free_rstorage(JCR *jcr); extern bool setup_job(JCR *jcr); extern void create_clones(JCR *jcr); -extern bool create_restore_bootstrap_file(JCR *jcr); +extern int create_restore_bootstrap_file(JCR *jcr); extern void dird_free_jcr(JCR *jcr); extern void dird_free_jcr_pointers(JCR *jcr); extern void cancel_storage_daemon_job(JCR *jcr); diff --git a/bacula/src/dird/verify.c b/bacula/src/dird/verify.c index 4373f23a20..98d0c7afac 100644 --- a/bacula/src/dird/verify.c +++ b/bacula/src/dird/verify.c @@ -181,8 +181,18 @@ bool do_verify(JCR *jcr) * File daemon but not used). */ if (jcr->get_JobLevel() == L_VERIFY_VOLUME_TO_CATALOG) { - if (!create_restore_bootstrap_file(jcr)) { + int stat; + /* + * Note: negative status is an error, zero status, means + * no files were backed up, so skip calling SD and + * client. + */ + stat = create_restore_bootstrap_file(jcr); + if (stat < 0) { /* error */ return false; + } else if (stat == 0) { /* No files, nothing to do */ + verify_cleanup(jcr, JS_Terminated); /* clean up */ + return true; /* get out */ } } else { jcr->sd_auth_key = bstrdup("dummy"); /* dummy Storage daemon key */ diff --git a/bacula/src/version.h b/bacula/src/version.h index 411f5d59e8..2dcac1e48c 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "3.0.3" -#define BDATE "22 August 2009" -#define LSMDATE "22Aug09" +#define BDATE "28 August 2009" +#define LSMDATE "28Aug09" #define PROG_COPYRIGHT "Copyright (C) %d-2009 Free Software Foundation Europe e.V.\n" #define BYEAR "2009" /* year for copyright messages in progs */ diff --git a/bacula/technotes b/bacula/technotes index a762c96650..9738213471 100644 --- a/bacula/technotes +++ b/bacula/technotes @@ -2,6 +2,8 @@ General: +28Aug09 +kes Fix bug #1357 Verify jobs fail when job has zero files 26Aug09 kes Fix possible seg fault in db_get_int_handler in accurate code kes Release orphanned buffers in accurate code. -- 2.39.5