From 048e7bc4b74f74a6c06cc9bc894301def2e562c1 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 12 Sep 2007 21:31:57 +0000 Subject: [PATCH] es Fix error message that was clobbered when Dir tells SD it does not have write permission on Volume. This should fix a minor point in bug #942, but not the main problem. kes Add code to cancel job in SD if FD connection fails. This should fix bug #920. kes Add code in FD exit to prevent loops and a crash on FreeBSD. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@5538 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/backup.c | 1 + bacula/src/dird/job.c | 40 ++++++++++++++++++++++++++++++++++++++ bacula/src/dird/protos.h | 1 + bacula/src/dird/restore.c | 1 + bacula/src/dird/verify.c | 1 + bacula/src/filed/filed.c | 12 ++++++++++-- bacula/src/stored/dircmd.c | 2 -- bacula/src/stored/mount.c | 4 +++- bacula/src/version.h | 6 +++--- bacula/technotes-2.3 | 13 ++++++++++--- 10 files changed, 70 insertions(+), 11 deletions(-) diff --git a/bacula/src/dird/backup.c b/bacula/src/dird/backup.c index a6a0b0aeed..161d390c09 100644 --- a/bacula/src/dird/backup.c +++ b/bacula/src/dird/backup.c @@ -165,6 +165,7 @@ bool do_backup(JCR *jcr) set_jcr_job_status(jcr, JS_WaitFD); if (!connect_to_file_daemon(jcr, 10, FDConnectTimeout, 1)) { + cancel_storage_daemon_job(jcr); goto bail_out; } diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 70be904b25..406a43e3bb 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -427,6 +427,46 @@ bool cancel_job(UAContext *ua, JCR *jcr) return true; } +void cancel_storage_daemon_job(JCR *jcr) +{ + UAContext *ua = new_ua_context(jcr); + JCR *control_jcr = new_control_jcr("*JobCancel*", JT_SYSTEM); + BSOCK *sd; + + ua->jcr = control_jcr; + if (jcr->store_bsock) { + if (!ua->jcr->wstorage) { + if (jcr->rstorage) { + copy_wstorage(ua->jcr, jcr->rstorage, _("Job resource")); + } else { + copy_wstorage(ua->jcr, jcr->wstorage, _("Job resource")); + } + } else { + USTORE store; + if (jcr->rstorage) { + store.store = jcr->rstore; + } else { + store.store = jcr->wstore; + } + set_wstorage(ua->jcr, &store); + } + + if (!connect_to_storage_daemon(ua->jcr, 10, SDConnectTimeout, 1)) { + goto bail_out; + } + Dmsg0(200, "Connected to storage daemon\n"); + sd = ua->jcr->store_bsock; + sd->fsend("cancel Job=%s\n", jcr->Job); + while (sd->recv() >= 0) { + } + sd->signal(BNET_TERMINATE); + sd->close(); + ua->jcr->store_bsock = NULL; + } +bail_out: + free_jcr(control_jcr); + free_ua_context(ua); +} static void job_monitor_destructor(watchdog_t *self) { diff --git a/bacula/src/dird/protos.h b/bacula/src/dird/protos.h index 10d27e31eb..c0ad0d5e46 100644 --- a/bacula/src/dird/protos.h +++ b/bacula/src/dird/protos.h @@ -128,6 +128,7 @@ extern void create_clones(JCR *jcr); extern bool 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); /* migration.c */ extern bool do_migration(JCR *jcr); diff --git a/bacula/src/dird/restore.c b/bacula/src/dird/restore.c index 446aac6881..e3a60613b0 100644 --- a/bacula/src/dird/restore.c +++ b/bacula/src/dird/restore.c @@ -135,6 +135,7 @@ bool do_restore(JCR *jcr) */ set_jcr_job_status(jcr, JS_WaitFD); if (!connect_to_file_daemon(jcr, 10, FDConnectTimeout, 1)) { + cancel_storage_daemon_job(jcr); restore_cleanup(jcr, JS_ErrorTerminated); return false; } diff --git a/bacula/src/dird/verify.c b/bacula/src/dird/verify.c index b5418d11ad..26c8b2f589 100644 --- a/bacula/src/dird/verify.c +++ b/bacula/src/dird/verify.c @@ -211,6 +211,7 @@ bool do_verify(JCR *jcr) */ set_jcr_job_status(jcr, JS_Blocked); if (!connect_to_file_daemon(jcr, 10, FDConnectTimeout, 1)) { + cancel_storage_daemon_job(jcr); return false; } diff --git a/bacula/src/filed/filed.c b/bacula/src/filed/filed.c index 3f96b0d913..6852b0ccef 100644 --- a/bacula/src/filed/filed.c +++ b/bacula/src/filed/filed.c @@ -232,6 +232,14 @@ int main (int argc, char *argv[]) void terminate_filed(int sig) { + static bool already_here = false; + + if (already_here) { + exit(1); /* prevent loops */ + } + already_here = true; + stop_watchdog(); + bnet_stop_thread_server(server_tid); generate_daemon_event(NULL, "Exit"); write_state_file(me->working_directory, "bacula-fd", get_first_port_host_order(me->FDaddrs)); @@ -240,12 +248,12 @@ void terminate_filed(int sig) if (configfile != NULL) { free(configfile); } + if (debug_level > 0) { print_memory_pool_stats(); } - free_config_resources(); term_msg(); - stop_watchdog(); + free_config_resources(); cleanup_crypto(); close_memory_pool(); /* release free memory in pool */ sm_dump(false); /* dump orphaned buffers */ diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index 205fe140df..dad767bfc0 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -294,13 +294,11 @@ static bool cancel_cmd(JCR *cjcr) if (!(jcr=get_jcr_by_full_name(Job))) { bnet_fsend(dir, _("3904 Job %s not found.\n"), Job); } else { - jcr->lock(); oldStatus = jcr->JobStatus; set_jcr_job_status(jcr, JS_Canceled); if (!jcr->authenticated && oldStatus == JS_WaitFD) { pthread_cond_signal(&jcr->job_start_wait); /* wake waiting thread */ } - jcr->unlock(); if (jcr->file_bsock) { bnet_sig(jcr->file_bsock, BNET_TERMINATE); } else { diff --git a/bacula/src/stored/mount.c b/bacula/src/stored/mount.c index 102ef85c4b..0b91ce6b74 100644 --- a/bacula/src/stored/mount.c +++ b/bacula/src/stored/mount.c @@ -276,6 +276,8 @@ read_volume: bstrncpy(VolumeName, dcr->VolumeName, sizeof(VolumeName)); bstrncpy(dcr->VolumeName, dev->VolHdr.VolumeName, sizeof(dcr->VolumeName)); if (!dir_get_volume_info(dcr, GET_VOL_INFO_FOR_WRITE)) { + POOL_MEM vol_info_msg; + pm_strcpy(vol_info_msg, jcr->dir_bsock->msg); /* save error message */ /* Restore desired volume name, note device info out of sync */ /* This gets the info regardless of the Pool */ bstrncpy(dcr->VolumeName, dev->VolHdr.VolumeName, sizeof(dcr->VolumeName)); @@ -293,7 +295,7 @@ read_volume: " Current Volume \"%s\" not acceptable because:\n" " %s"), dcrVolCatInfo.VolCatName, dev->VolHdr.VolumeName, - jcr->dir_bsock->msg); + vol_info_msg.c_str()); ask = true; /* Restore saved DCR before continuing */ bstrncpy(dcr->VolumeName, VolumeName, sizeof(dcr->VolumeName)); diff --git a/bacula/src/version.h b/bacula/src/version.h index 7adafd96f2..4cf4e1e2aa 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -3,9 +3,9 @@ */ #undef VERSION -#define VERSION "2.3.3" -#define BDATE "06 September 2007" -#define LSMDATE "06Sep07" +#define VERSION "2.3.4" +#define BDATE "12 September 2007" +#define LSMDATE "12Sep07" #define PROG_COPYRIGHT "Copyright (C) %d-2007 Free Software Foundation Europe e.V.\n" #define BYEAR "2007" /* year for copyright messages in progs */ diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index f23b5be016..4d1d4e8842 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -2,6 +2,12 @@ General: 12Sep07 +kes Fix error message that was clobbered when Dir tells SD it does not + have write permission on Volume. This should fix a minor point + in bug #942, but not the main problem. +kes Add code to cancel job in SD if FD connection fails. This should + fix bug #920. +kes Add code in FD exit to prevent loops and a crash on FreeBSD. dvl Pass jcr and db into db_escape_string() to enable better escaping of strings kes Fix migration code to get correct Volume name with multiple volumes @@ -12,7 +18,7 @@ kes Note, you need GTK >= 2.10 to be able to link the Tray Monitor program. kes Move patches into patches directory. 11Sep07 -ebl Fix bug #946 about "bacula-dir -t" witch doesn't works +ebl Fix bug #946 about "bacula-dir -t" which doesn't works as expected. 09Sep07 ebl Using "m" in bconsole will show messages like before, @@ -24,7 +30,7 @@ kes Fix bug #935, and probably also bug #903 where files were not kes Suppress chown and chmod error messages if the FD is not running as root. 07Sep07 -kes Apply Martin Simmons patch that should turn off the new API usage +kes Apply Martin Simmons' patch that should turn off the new API usage when batch insert is turned off allowing building on older PostgreSQLs. kes Add ./configure search in qwt-qt4 for qwt package @@ -35,7 +41,8 @@ kes Add guid_to_name.c/h which replace idcache. kes Remove enh_fnmatch.c. Make code that references it use fnmatch.c 04Sep07 ebl Detect if new PosgreSQL batch insert API is present. -kes Correct incorrect mempool call causing Director crash. +kes Correct incorrect mempool call causing Director crash. Occurs on + systems without va_copy(). sb Update spec files for 2.2.1 release 03Sep07 kes Fix memory pool call in ua_output.c. bug #934. -- 2.39.5