]> git.sur5r.net Git - bacula/bacula/commitdiff
Status cleanup and cancelling FD
authorKern Sibbald <kern@sibbald.com>
Tue, 14 Jan 2003 20:06:55 +0000 (20:06 +0000)
committerKern Sibbald <kern@sibbald.com>
Tue, 14 Jan 2003 20:06:55 +0000 (20:06 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@289 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/dird/backup.c
bacula/src/dird/msgchan.c
bacula/src/dird/scheduler.c
bacula/src/dird/ua_input.c
bacula/src/filed/backup.c
bacula/src/filed/job.c
bacula/src/stored/append.c
bacula/src/stored/dircmd.c
bacula/src/stored/fd_cmds.c

index 27c165b9b97348305af8916d144f95d36b8ed05b..4db42b58de66ed20e4bf5d3877561ed901bca756 100644 (file)
@@ -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, _("<filed: network error during BACKUP command. ERR=%s\n"),
@@ -321,18 +324,18 @@ static void backup_cleanup(JCR *jcr, int TermCode, char *since)
    if (!db_get_job_record(jcr->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 */
index c8d768296177e6630dce38353af2d7bc554e4598..74b91e1cc8e63c6712b8258f82ca7eb6dce79af1 100644 (file)
@@ -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);
index f0488f71b8106a50e6119cde7da91c2fe35d4c7b..6206c3b1e572514a7018e4f5d144324266b803a7 100644 (file)
@@ -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
index d9e24f664158d02247b49abb3bca9de1e1e168ec..0bb7922057ca981adc1db8773c2372a22b4686b4 100644 (file)
@@ -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
index b2aaf2649a23a5236e56d671f3be40b76542e709..01fda0db599916a91392753df44c24f119b5adb1 100644 (file)
@@ -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;
    }
 
index f475e1c2dc650ea2b0056251f266a0ba99de221c..b1579624cb8224333c3a84562f19a385f99b4ec4 100644 (file)
@@ -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
        */
index f494cd63a7a97fd93726c195fbe9e7c5ac4be857..3d5ca9009a3a51dab5622812bcd4ce8c2586996b 100644 (file)
@@ -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;
 }
index 598b8644676e57ee9f284953f1116d56e60d3676..aaed0fea09b7355f21d3f9040bd482de9b823ac0 100644 (file)
@@ -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 {
index 226355beb4982ef091c44f7ed4d8f851d217a91d..ed1180c1537b3604aacfaaa0f7ceef3ad0732e97 100644 (file)
@@ -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);