From: Kern Sibbald Date: Tue, 14 Jan 2003 20:06:55 +0000 (+0000) Subject: Status cleanup and cancelling FD X-Git-Tag: Release-1.29~31 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d65fe741efdc674ff42d3c5cee82f70c3eade4b8;p=bacula%2Fbacula Status cleanup and cancelling FD git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@289 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/dird/backup.c b/bacula/src/dird/backup.c index 27c165b9b9..4db42b58de 100644 --- a/bacula/src/dird/backup.c +++ b/bacula/src/dird/backup.c @@ -272,13 +272,16 @@ static int wait_for_job_termination(JCR *jcr) set_jcr_job_status(jcr, JS_WaitFD); /* Wait for Client to terminate */ - while ((n = bget_msg(fd, 0)) >= 0 && !job_cancelled(jcr)) { + while ((n = bget_msg(fd, 0)) >= 0) { if (sscanf(fd->msg, EndBackup, &jcr->FDJobStatus, &jcr->JobFiles, &jcr->ReadBytes, &jcr->JobBytes) == 4) { fd_ok = TRUE; set_jcr_job_status(jcr, jcr->FDJobStatus); Dmsg1(100, "FDStatus=%c\n", (char)jcr->JobStatus); } + if (job_cancelled(jcr)) { + break; + } } if (is_bnet_error(fd)) { Jmsg(jcr, M_FATAL, 0, _("db, &jcr->jr)) { Jmsg(jcr, M_WARNING, 0, _("Error getting job record for stats: %s"), db_strerror(jcr->db)); - TermCode = JS_ErrorTerminated; + set_jcr_job_status(jcr, JS_ErrorTerminated); } strcpy(mr.VolumeName, jcr->VolumeName); if (!db_get_media_record(jcr->db, &mr)) { Jmsg(jcr, M_WARNING, 0, _("Error getting Media record for stats: %s"), db_strerror(jcr->db)); - TermCode = JS_ErrorTerminated; + set_jcr_job_status(jcr, JS_ErrorTerminated); } /* Now update the bootstrap file if any */ - if (TermCode == JS_Terminated && jcr->job->WriteBootstrap) { + if (jcr->JobStatus == JS_Terminated && jcr->job->WriteBootstrap) { FILE *fd; BPIPE *bpipe = NULL; int got_pipe = 0; @@ -378,12 +381,12 @@ static void backup_cleanup(JCR *jcr, int TermCode, char *since) } else { Jmsg(jcr, M_ERROR, 0, _("Could not open WriteBootstrap file:\n" "%s: ERR=%s\n"), fname, strerror(errno)); - TermCode = JS_ErrorTerminated; + set_jcr_job_status(jcr, JS_ErrorTerminated); } } msg_type = M_INFO; /* by default INFO message */ - switch (TermCode) { + switch (jcr->JobStatus) { case JS_Terminated: term_msg = _("Backup OK"); break; @@ -405,7 +408,7 @@ static void backup_cleanup(JCR *jcr, int TermCode, char *since) break; default: term_msg = term_code; - sprintf(term_code, _("Inappropriate term code: %c\n"), TermCode); + sprintf(term_code, _("Inappropriate term code: %c\n"), jcr->JobStatus); break; } bstrftime(sdt, sizeof(sdt), jcr->jr.StartTime); @@ -423,7 +426,7 @@ static void backup_cleanup(JCR *jcr, int TermCode, char *since) * it is normal. Or look at it the other way, only for a * normal exit should we complain about this error. */ - if (TermCode == JS_Terminated) { + if (jcr->JobStatus == JS_Terminated) { Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db)); } jcr->VolumeName[0] = 0; /* none */ diff --git a/bacula/src/dird/msgchan.c b/bacula/src/dird/msgchan.c index c8d7682961..74b91e1cc8 100644 --- a/bacula/src/dird/msgchan.c +++ b/bacula/src/dird/msgchan.c @@ -246,10 +246,11 @@ static void *msg_thread(void *arg) void wait_for_storage_daemon_termination(JCR *jcr) { + int cancel_count = 0; /* Now wait for Storage daemon to terminate our message thread */ P(jcr->mutex); set_jcr_job_status(jcr, JS_WaitSD); - while (!jcr->msg_thread_done && !job_cancelled(jcr)) { + while (!jcr->msg_thread_done) { struct timeval tv; struct timezone tz; struct timespec timeout; @@ -259,6 +260,13 @@ void wait_for_storage_daemon_termination(JCR *jcr) timeout.tv_sec = tv.tv_sec + 10; /* wait 10 seconds */ Dmsg0(300, "I'm waiting for message thread termination.\n"); pthread_cond_timedwait(&jcr->term_wait, &jcr->mutex, &timeout); + if (job_cancelled(jcr)) { + cancel_count++; + } + /* Give SD 30 seconds to clean up after cancel */ + if (cancel_count == 3) { + break; + } } V(jcr->mutex); set_jcr_job_status(jcr, jcr->SDJobStatus); diff --git a/bacula/src/dird/scheduler.c b/bacula/src/dird/scheduler.c index f0488f71b8..6206c3b1e5 100644 --- a/bacula/src/dird/scheduler.c +++ b/bacula/src/dird/scheduler.c @@ -10,7 +10,7 @@ * Version $Id$ */ /* - Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker + Copyright (C) 2000-2003 Kern Sibbald and John Walker This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as diff --git a/bacula/src/dird/ua_input.c b/bacula/src/dird/ua_input.c index d9e24f6641..0bb7922057 100644 --- a/bacula/src/dird/ua_input.c +++ b/bacula/src/dird/ua_input.c @@ -8,7 +8,7 @@ */ /* - Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker + Copyright (C) 2000-2003 Kern Sibbald and John Walker This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as diff --git a/bacula/src/filed/backup.c b/bacula/src/filed/backup.c index b2aaf2649a..01fda0db59 100644 --- a/bacula/src/filed/backup.c +++ b/bacula/src/filed/backup.c @@ -49,6 +49,7 @@ int blast_data_to_storage_daemon(JCR *jcr, char *addr) Dmsg1(110, "bfiled: opened data connection %d to stored\n", sd->fd); if (!bnet_set_buffer_size(sd, MAX_NETWORK_BUFFER_SIZE, BNET_SETBUF_WRITE)) { + set_jcr_job_status(jcr, JS_ErrorTerminated); return 0; } diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index f475e1c2dc..b1579624cb 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -550,6 +550,9 @@ static int backup_cmd(JCR *jcr) set_jcr_job_status(jcr, JS_ErrorTerminated); } else { set_jcr_job_status(jcr, JS_Terminated); + if (jcr->JobStatus != JS_Terminated) { + goto cleanup; /* bail out now */ + } /* * Expect to get response to append_data from Storage daemon */ diff --git a/bacula/src/stored/append.c b/bacula/src/stored/append.c index f494cd63a7..3d5ca9009a 100644 --- a/bacula/src/stored/append.c +++ b/bacula/src/stored/append.c @@ -231,26 +231,30 @@ int do_append_data(JCR *jcr) */ sm_check(__FILE__, __LINE__, False); Dmsg0(90, "Write_end_session_label()\n"); + /* Create Job status for end of session label */ - if (!job_cancelled(jcr) && ok) { - set_jcr_job_status(jcr, JS_Terminated); - } else if (!ok) { - set_jcr_job_status(jcr, JS_ErrorTerminated); - } + set_jcr_job_status(jcr, ok?JS_Terminated:JS_ErrorTerminated); + + Dmsg1(200, "Write session label JobStatus=%d\n", jcr->JobStatus); + if (!write_session_label(jcr, block, EOS_LABEL)) { Jmsg1(jcr, M_FATAL, 0, _("Error writting end session label. ERR=%s\n"), strerror_dev(dev)); + set_jcr_job_status(jcr, JS_ErrorTerminated); ok = FALSE; } /* Write out final block of this session */ if (!write_block_to_device(jcr, dev, block)) { Pmsg0(000, _("Set ok=FALSE after write_block_to_device.\n")); + set_jcr_job_status(jcr, JS_ErrorTerminated); ok = FALSE; } + Dmsg1(200, "release device JobStatus=%d\n", jcr->JobStatus); /* Release the device */ if (!release_device(jcr, dev)) { Pmsg0(000, _("Error in release_device\n")); + set_jcr_job_status(jcr, JS_ErrorTerminated); ok = FALSE; } @@ -261,6 +265,8 @@ int do_append_data(JCR *jcr) close_spool_file(jcr, jcr->dir_bsock); } + dir_send_job_status(jcr); /* update director */ + Dmsg0(90, "return from do_append_data()\n"); return ok ? 1 : 0; } diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index 598b864467..aaed0fea09 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -216,8 +216,7 @@ static int cancel_cmd(JCR *cjcr) if (jcr->file_bsock) { bnet_sig(jcr->file_bsock, BNET_TERMINATE); } - bnet_fsend(dir, _("3000 Job %s Status=%c marked to be cancelled.\n"), - jcr->Job, oldStatus); + bnet_fsend(dir, _("3000 Job %s marked to be cancelled.\n"), jcr->Job); free_jcr(jcr); } } else { diff --git a/bacula/src/stored/fd_cmds.c b/bacula/src/stored/fd_cmds.c index 226355beb4..ed1180c153 100644 --- a/bacula/src/stored/fd_cmds.c +++ b/bacula/src/stored/fd_cmds.c @@ -117,7 +117,7 @@ void run_job(JCR *jcr) bnet_fsend(dir, Job_start, jcr->Job); jcr->start_time = time(NULL); jcr->run_time = jcr->start_time; - jcr->JobStatus = JS_Running; + set_jcr_job_status(jcr, JS_Running); dir_send_job_status(jcr); /* update director */ for (quit=0; !quit;) { int stat; @@ -136,7 +136,7 @@ void run_job(JCR *jcr) if (strncmp(fd_cmds[i].cmd, fd->msg, strlen(fd_cmds[i].cmd)) == 0) { found = 1; /* indicate command found */ if (!fd_cmds[i].func(jcr)) { /* do command */ - jcr->JobStatus = JS_ErrorTerminated; + set_jcr_job_status(jcr, JS_ErrorTerminated); quit = 1; } break; @@ -150,9 +150,7 @@ void run_job(JCR *jcr) } bnet_sig(fd, BNET_TERMINATE); /* signal to FD job is done */ jcr->end_time = time(NULL); - if (!job_cancelled(jcr)) { - jcr->JobStatus = JS_Terminated; - } + set_jcr_job_status(jcr, JS_Terminated); bnet_fsend(dir, Job_end, jcr->Job, jcr->JobStatus, jcr->JobFiles, edit_uint64(jcr->JobBytes, ec1)); @@ -238,9 +236,6 @@ static int append_close_session(JCR *jcr) bnet_fsend(fd, NOT_opened); return 0; } - if (jcr->JobStatus != JS_ErrorTerminated) { - jcr->JobStatus = JS_Terminated; - } /* Send final statistics to File daemon */ bnet_fsend(fd, OK_close, jcr->JobStatus); Dmsg1(160, ">filed: %s\n", fd->msg);