]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/wait.c
Fix bad debug statement
[bacula/bacula] / bacula / src / stored / wait.c
index 6251a9b4ab76a6567ce02473d1f15ccd86b7ecaa..957e89fbc240d6106e23867642a3be201b2b7bdd 100644 (file)
@@ -61,7 +61,7 @@ int wait_for_sysop(DCR *dcr)
    DEVICE *dev = dcr->dev;
    JCR *jcr = dcr->jcr;
 
-   dev->lock();  
+   dev->dlock();  
    Dmsg1(100, "Enter blocked=%s\n", dev->print_blocked());
    unmounted = is_device_unmounted(dev);
 
@@ -112,11 +112,11 @@ int wait_for_sysop(DCR *dcr)
          if (now - last_heartbeat >= me->heartbeat_interval) {
             /* send heartbeats */
             if (jcr->file_bsock) {
-               bnet_sig(jcr->file_bsock, BNET_HEARTBEAT);
+               jcr->file_bsock->signal(BNET_HEARTBEAT);
                Dmsg0(400, "Send heartbeat to FD.\n");
             }
             if (jcr->dir_bsock) {
-               bnet_sig(jcr->dir_bsock, BNET_HEARTBEAT);
+               jcr->dir_bsock->signal(BNET_HEARTBEAT);
             }
             last_heartbeat = now;
          }
@@ -124,7 +124,7 @@ int wait_for_sysop(DCR *dcr)
 
       if (stat == EINVAL) {
          berrno be;
-         Jmsg1(jcr, M_FATAL, 0, _("pthread timedwait error. ERR=%s\n"), be.strerror(stat));
+         Jmsg1(jcr, M_FATAL, 0, _("pthread timedwait error. ERR=%s\n"), be.bstrerror(stat));
          stat = W_ERROR;               /* error */
          break;
       }
@@ -184,47 +184,52 @@ int wait_for_sysop(DCR *dcr)
       Dmsg1(400, "set %s\n", dev->print_blocked());
    }
    Dmsg1(400, "Exit blocked=%s\n", dev->print_blocked());
-   dev->unlock();
+   dev->dunlock();
    return stat;
 }
 
 
 /*
  * Wait for any device to be released, then we return, so 
- *  higher level code can rescan possible devices.
+ *  higher level code can rescan possible devices.  Since there
+ *  could be a job waiting for a drive to free up, we wait a maximum
+ *  of 1 minute then retry just in case a broadcast was lost, and 
+ *  we return to rescan the devices.
  * 
  * Returns: true  if a device has changed state
  *          false if the total wait time has expired.
  */
-bool wait_for_device(JCR *jcr, bool first)
+bool wait_for_device(JCR *jcr, int &retries)
 {
    struct timeval tv;
    struct timezone tz;
    struct timespec timeout;
    int stat = 0;
    bool ok = true;
-   const int wait_time = 5 * 60;       /* wait 5 minutes */
+   const int max_wait_time = 1 * 60;       /* wait 1 minute */
+   char ed1[50];
 
    Dmsg0(100, "Enter wait_for_device\n");
    P(device_release_mutex);
 
-   if (first) {
-      Jmsg(jcr, M_MOUNT, 0, _("Job %s waiting to reserve a device.\n"), jcr->Job);
+   if (++retries % 5 == 0) {
+      /* Print message every 5 minutes */
+      Jmsg(jcr, M_MOUNT, 0, _("JobId=%s, Job %s waiting to reserve a device.\n"), 
+         edit_uint64(jcr->JobId, ed1), jcr->Job);
    }
 
    gettimeofday(&tv, &tz);
    timeout.tv_nsec = tv.tv_usec * 1000;
-   timeout.tv_sec = tv.tv_sec + wait_time;
+   timeout.tv_sec = tv.tv_sec + max_wait_time;
 
-   Dmsg0(100, "I'm going to wait for a device.\n");
+   Dmsg1(100, "JobId=%u going to wait for a device.\n", (uint32_t)jcr->JobId);
 
    /* Wait required time */
    stat = pthread_cond_timedwait(&wait_device_release, &device_release_mutex, &timeout);
-   Dmsg1(100, "Wokeup from sleep on device stat=%d\n", stat);
-
+   Dmsg2(100, "JobId=%u wokeup from sleep on device stat=%d\n", (uint32_t)jcr->JobId, stat);
 
    V(device_release_mutex);
-   Dmsg1(100, "Return from wait_device ok=%d\n", ok);
+   Dmsg2(100, "JobId=%u return from wait_device ok=%d\n", (uint32_t)jcr->JobId, ok);
    return ok;
 }