]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/getmsg.c
kes Implement bsr block level checking for disk files. However,
[bacula/bacula] / bacula / src / dird / getmsg.c
index 7a183ba43b71809a58315f3089b98f331fb0fb6b..4cfd87d765f9655601e676efda93546122e6386f 100644 (file)
@@ -1,29 +1,7 @@
-/*
- *
- *   Bacula Director -- routines to receive network data and
- *    handle network signals. These routines handle the connections
- *    to the Storage daemon and the File daemon.
- *
- *     Kern Sibbald, August MM
- *
- *    This routine runs as a thread and must be thread reentrant.
- *
- *  Basic tasks done here:
- *    Handle  network signals (signals).
- *       Signals always have return status 0 from bnet_recv() and
- *       a zero or negative message length.
- *    Pass appropriate messages back to the caller (responses).
- *       Responses always have a digit as the first character.
- *    Handle requests for message and catalog services (requests).
- *       Requests are any message that does not begin with a digit.
- *       In affect, they are commands.
- *
- *   Version $Id$
- */
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2008 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Bacula® is a registered trademark of John Walker.
+   Bacula® is a registered trademark of Kern Sibbald.
    The licensor of Bacula is the Free Software Foundation Europe
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
 */
+/*
+ *
+ *   Bacula Director -- routines to receive network data and
+ *    handle network signals. These routines handle the connections
+ *    to the Storage daemon and the File daemon.
+ *
+ *     Kern Sibbald, August MM
+ *
+ *    This routine runs as a thread and must be thread reentrant.
+ *
+ *  Basic tasks done here:
+ *    Handle  network signals (signals).
+ *       Signals always have return status 0 from bnet_recv() and
+ *       a zero or negative message length.
+ *    Pass appropriate messages back to the caller (responses).
+ *       Responses always have a digit as the first character.
+ *    Handle requests for message and catalog services (requests).
+ *       Requests are any message that does not begin with a digit.
+ *       In affect, they are commands.
+ *
+ *   Version $Id$
+ */
 
 #include "bacula.h"
 #include "dird.h"
@@ -70,6 +70,33 @@ static char Device_update[]   = "DevUpd Job=%127s "
 
 static char OK_msg[] = "1000 OK\n";
 
+
+void set_jcr_sd_job_status(JCR *jcr, int SDJobStatus)
+{
+   bool set_waittime=false;
+   Dmsg2(800, "set_jcr_sd_job_status(%s, %c)\n", jcr->Job, SDJobStatus);
+   /* if wait state is new, we keep current time for watchdog MaxWaitTime */
+   switch (SDJobStatus) {
+      case JS_WaitMedia:
+      case JS_WaitMount:
+      case JS_WaitMaxJobs:
+         set_waittime = true;
+      default:
+         break;
+   }
+
+   if (job_waiting(jcr)) {
+      set_waittime = false;
+   }
+
+   if (set_waittime) {
+      /* set it before JobStatus */
+      Dmsg0(800, "Setting wait_time\n");
+      jcr->wait_time = time(NULL);
+   }
+   jcr->SDJobStatus = SDJobStatus;
+}
+
 /*
  * Get a message
  *  Call appropriate processing routine
@@ -102,12 +129,12 @@ int bget_dirmsg(BSOCK *bs)
    char Job[MAX_NAME_LENGTH];
    char MsgType[20];
    int type, level;
-   JCR *jcr;
+   JCR *jcr = bs->jcr();
    char *msg;
 
    for (;;) {
       n = bs->recv();
-      Dmsg2(900, "bget_dirmsg %d: %s", n, bs->msg);
+      Dmsg2(300, "bget_dirmsg %d: %s\n", n, bs->msg);
 
       if (is_bnet_stop(bs)) {
          return n;                    /* error or terminate */
@@ -142,7 +169,7 @@ int bget_dirmsg(BSOCK *bs)
             bs->fsend("btime %s\n", edit_uint64(get_current_btime(),ed1));
             break;
          default:
-            Emsg1(M_WARNING, 0, _("bget_dirmsg: unknown bnet signal %d\n"), bs->msglen);
+            Jmsg1(jcr, M_WARNING, 0, _("bget_dirmsg: unknown bnet signal %d\n"), bs->msglen);
             return n;
          }
          continue;
@@ -160,21 +187,13 @@ int bget_dirmsg(BSOCK *bs)
        *  Try to fulfill it.
        */
       if (sscanf(bs->msg, "%020s Job=%127s ", MsgType, Job) != 2) {
-         Emsg1(M_ERROR, 0, _("Malformed message: %s\n"), bs->msg);
+         Jmsg1(jcr, M_ERROR, 0, _("Malformed message: %s\n"), bs->msg);
          continue;
       }
-      if (strcmp(Job, "*System*") == 0) {
-         jcr = NULL;                  /* No jcr */
-      } else if (!(jcr=get_jcr_by_full_name(Job))) {
-         Emsg1(M_ERROR, 0, _("Job not found: %s\n"), bs->msg);
-         continue;
-      }
-      Dmsg1(900, "Getmsg got jcr 0x%x\n", jcr);
 
       /* Skip past "Jmsg Job=nnn" */
       if (!(msg=find_msg_start(bs->msg))) {
-         Emsg1(M_ERROR, 0, _("Malformed message: %s\n"), bs->msg);
-         free_jcr(jcr);
+         Jmsg1(jcr, M_ERROR, 0, _("Malformed message: %s\n"), bs->msg);
          continue;
       }
 
@@ -185,8 +204,7 @@ int bget_dirmsg(BSOCK *bs)
       if (bs->msg[0] == 'J') {           /* Job message */
          if (sscanf(bs->msg, "Jmsg Job=%127s type=%d level=%d",
                     Job, &type, &level) != 3) {
-            Emsg1(M_ERROR, 0, _("Malformed message: %s\n"), bs->msg);
-            free_jcr(jcr);
+            Jmsg1(jcr, M_ERROR, 0, _("Malformed message: %s\n"), bs->msg);
             continue;
          }
          Dmsg1(900, "Got msg: %s\n", bs->msg);
@@ -199,7 +217,6 @@ int bget_dirmsg(BSOCK *bs)
          }
          Dmsg1(900, "Dispatch msg: %s", msg);
          dispatch_message(jcr, type, level, msg);
-         free_jcr(jcr);
          continue;
       }
       /*
@@ -209,32 +226,26 @@ int bget_dirmsg(BSOCK *bs)
       if (bs->msg[0] == 'C') {        /* Catalog request */
          Dmsg2(900, "Catalog req jcr 0x%x: %s", jcr, bs->msg);
          catalog_request(jcr, bs);
-         Dmsg1(900, "Calling freejcr 0x%x\n", jcr);
-         free_jcr(jcr);
          continue;
       }
-      if (bs->msg[0] == 'U') {        /* Catalog update */
+      if (bs->msg[0] == 'U') {        /* SD sending attributes */
          Dmsg2(900, "Catalog upd jcr 0x%x: %s", jcr, bs->msg);
          catalog_update(jcr, bs);
-         Dmsg1(900, "Calling freejcr 0x%x\n", jcr);
-         free_jcr(jcr);
          continue;
       }
       if (bs->msg[0] == 'M') {        /* Mount request */
          Dmsg1(900, "Mount req: %s", bs->msg);
          mount_request(jcr, bs, msg);
-         free_jcr(jcr);
          continue;
       }
       if (bs->msg[0] == 'S') {       /* Status change */
          int JobStatus;
          char Job[MAX_NAME_LENGTH];
          if (sscanf(bs->msg, Job_status, &Job, &JobStatus) == 2) {
-            jcr->SDJobStatus = JobStatus; /* current status */
+            set_jcr_sd_job_status(jcr, JobStatus); /* current status */
          } else {
-            Emsg1(M_ERROR, 0, _("Malformed message: %s\n"), bs->msg);
+            Jmsg1(jcr, M_ERROR, 0, _("Malformed message: %s\n"), bs->msg);
          }
-         free_jcr(jcr);
          continue;
       }
 #ifdef needed