src/stored/reserve.c
static bool reserve_device_for_read(DCR *dcr)
{
   DEVICE *dev = dcr->dev;
   JCR *jcr = dcr->jcr;
   bool ok = false;

   ASSERT2(dcr, "No dcr in reserve_device_for_read!");
   if (job_canceled(jcr)) {
      return false;
   }

   dev->Lock();

   if (dev->is_device_unmounted()) {
      Mmsg(jcr->errmsg, _("3601 JobId=%u %s device %s is BLOCKED due to user unmount.\n"),
           jcr->JobId, dev->print_type(), dev->print_name());
      queue_reserve_message(jcr);
      Dmsg1(dbglvl, "Device %s is BLOCKED due to user unmount.\n", dev->print_name());
      goto bail_out;
   }

   if (dev->is_busy()) {
      Mmsg(jcr->errmsg, _("3602 JobId=%u %s device %s is busy (already reading/writing)."
            " read=%d, writers=%d reserved=%d\n"),
            jcr->JobId, dev->print_type(), dev->print_name(),
            dev->state & ST_READ?1:0, dev->num_writers, dev->num_reserved());
      queue_reserve_message(jcr);
      Dmsg4(dbglvl, "Device %s is busy ST_READ=%d num_writers=%d reserved=%d.\n",
         dev->print_name(),
         dev->state & ST_READ?1:0, dev->num_writers, dev->num_reserved());
      goto bail_out;
   }

   /* Note: on failure this returns jcr->errmsg properly edited */
   if (generate_plugin_event(jcr, bsdEventDeviceTryOpen, dcr) != bRC_OK) {
      queue_reserve_message(jcr);
      goto bail_out;
   }
   dev->clear_append();
   dcr->set_reserved_for_read();
   ok = true;

bail_out:
   dev->Unlock();
   return ok;
}
/*
 * We "reserve" the drive by setting the ST_READ bit. No one else
 *  should touch the drive until that is cleared.
 *  This allows the DIR to "reserve" the device before actually
 *  starting the job.
 */
We "reserve" the drive by setting the ST_READ bit. No one else
should touch the drive until that is cleared.
This allows the DIR to "reserve" the device before actually
starting the job.
We " reserve " the drive by setting the ST_READ bit . No one else should touch the drive until that is cleared . This allows the DIR to " reserve " the device before actually starting the job .
static bool reserve_device_for_read(DCR *dcr)
{
   DEVICE *dev = dcr->dev;
   JCR *jcr = dcr->jcr;
   bool ok = false;
   ASSERT2(dcr, "No dcr in reserve_device_for_read!");
   if (job_canceled(jcr)) {
      return false;
   }
   dev->Lock();
   if (dev->is_device_unmounted()) {
      Mmsg(jcr->errmsg, _("3601 JobId=%u %s device %s is BLOCKED due to user unmount.\n"),
           jcr->JobId, dev->print_type(), dev->print_name());
      queue_reserve_message(jcr);
      Dmsg1(dbglvl, "Device %s is BLOCKED due to user unmount.\n", dev->print_name());
      goto bail_out;
   }
   if (dev->is_busy()) {
      Mmsg(jcr->errmsg, _("3602 JobId=%u %s device %s is busy (already reading/writing)."
            " read=%d, writers=%d reserved=%d\n"),
            jcr->JobId, dev->print_type(), dev->print_name(),
            dev->state & ST_READ?1:0, dev->num_writers, dev->num_reserved());
      queue_reserve_message(jcr);
      Dmsg4(dbglvl, "Device %s is busy ST_READ=%d num_writers=%d reserved=%d.\n",
         dev->print_name(),
         dev->state & ST_READ?1:0, dev->num_writers, dev->num_reserved());
      goto bail_out;
   }
   if (generate_plugin_event(jcr, bsdEventDeviceTryOpen, dcr) != bRC_OK) {
      queue_reserve_message(jcr);
      goto bail_out;
   }
   dev->clear_append();
   dcr->set_reserved_for_read();
   ok = true;
bail_out:
   dev->Unlock();
   return ok;
}
static bool reserve_device_for_read ( DCR * dcr ) { DEVICE * dev = dcr -> dev ; JCR * jcr = dcr -> jcr ; bool ok = false ; ASSERT2 ( dcr , " " ) ; if ( job_canceled ( jcr ) ) { return false ; } dev -> Lock ( ) ; if ( dev -> is_device_unmounted ( ) ) { Mmsg ( jcr -> errmsg , _ ( " \n " ) , jcr -> JobId , dev -> print_type ( ) , dev -> print_name ( ) ) ; queue_reserve_message ( jcr ) ; Dmsg1 ( dbglvl , " \n " , dev -> print_name ( ) ) ; goto bail_out ; } if ( dev -> is_busy ( ) ) { Mmsg ( jcr -> errmsg , _ ( " " " \n " ) , jcr -> JobId , dev -> print_type ( ) , dev -> print_name ( ) , dev -> state & ST_READ ? 1 : 0 , dev -> num_writers , dev -> num_reserved ( ) ) ; queue_reserve_message ( jcr ) ; Dmsg4 ( dbglvl , " \n " , dev -> print_name ( ) , dev -> state & ST_READ ? 1 : 0 , dev -> num_writers , dev -> num_reserved ( ) ) ; goto bail_out ; } if ( generate_plugin_event ( jcr , bsdEventDeviceTryOpen , dcr ) != bRC_OK ) { queue_reserve_message ( jcr ) ; goto bail_out ; } dev -> clear_append ( ) ; dcr -> set_reserved_for_read ( ) ; ok = true ; bail_out : dev -> Unlock ( ) ; return ok ; }
We "reserve" the drive by setting the ST_READ bit.
We " reserve " the drive by setting the ST_READ bit .
/* Note: on failure this returns jcr->errmsg properly edited */