X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fstored%2Fwait.c;h=65535d5a924ecc7e95183fa2e668cafafb52bc85;hb=5acaefa52eef9207ee62d4fe9d231701c0dc4529;hp=c7563c4959124ff472e9b29dedff9de4c8f1b1a8;hpb=3189ae754a5235fe68c01338a55879e970bd4b7f;p=bacula%2Fbacula diff --git a/bacula/src/stored/wait.c b/bacula/src/stored/wait.c index c7563c4959..65535d5a92 100644 --- a/bacula/src/stored/wait.c +++ b/bacula/src/stored/wait.c @@ -1,17 +1,7 @@ -/* - * Subroutines to handle waiting for operator intervention - * or waiting for a Device to be released - * - * Code for wait_for_sysop() pulled from askdir.c - * - * Kern Sibbald, March 2005 - * - * Version $Id$ - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. + Copyright (C) 2000-2007 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. @@ -35,6 +25,16 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * Subroutines to handle waiting for operator intervention + * or waiting for a Device to be released + * + * Code for wait_for_sysop() pulled from askdir.c + * + * Kern Sibbald, March 2005 + * + * Version $Id$ + */ #include "bacula.h" /* pull in global headers */ @@ -61,7 +61,7 @@ int wait_for_sysop(DCR *dcr) DEVICE *dev = dcr->dev; JCR *jcr = dcr->jcr; - P(dev->mutex); + dev->dlock(); Dmsg1(100, "Enter blocked=%s\n", dev->print_blocked()); unmounted = is_device_unmounted(dev); @@ -85,7 +85,7 @@ int wait_for_sysop(DCR *dcr) if (!unmounted) { Dmsg1(400, "blocked=%s\n", dev->print_blocked()); - dev->dev_prev_blocked = dev->dev_blocked; + dev->dev_prev_blocked = dev->blocked(); dev->set_blocked(BST_WAITING_FOR_SYSOP); /* indicate waiting for mount */ } @@ -100,7 +100,7 @@ int wait_for_sysop(DCR *dcr) dev->print_name(), (int)me->heartbeat_interval, dev->wait_sec, add_wait); start = time(NULL); /* Wait required time */ - stat = pthread_cond_timedwait(&dev->wait_next_vol, &dev->mutex, &timeout); + stat = pthread_cond_timedwait(&dev->wait_next_vol, &dev->m_mutex, &timeout); Dmsg2(400, "Wokeup from sleep on device stat=%d blocked=%s\n", stat, dev->print_blocked()); @@ -151,7 +151,7 @@ int wait_for_sysop(DCR *dcr) /* * Check if user mounted the device while we were waiting */ - if (dev->get_blocked() == BST_MOUNT) { /* mount request ? */ + if (dev->blocked() == BST_MOUNT) { /* mount request ? */ stat = W_MOUNT; break; } @@ -184,14 +184,17 @@ int wait_for_sysop(DCR *dcr) Dmsg1(400, "set %s\n", dev->print_blocked()); } Dmsg1(400, "Exit blocked=%s\n", dev->print_blocked()); - V(dev->mutex); + 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. @@ -203,7 +206,7 @@ bool wait_for_device(JCR *jcr, bool first) 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 */ Dmsg0(100, "Enter wait_for_device\n"); P(device_release_mutex); @@ -214,17 +217,17 @@ bool wait_for_device(JCR *jcr, bool first) 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; }