src/stored/acquire.c
DCR *acquire_device_for_append(DCR *dcr)
{
   DEVICE *dev = dcr->dev;
   JCR *jcr = dcr->jcr;
   bool ok = false;
   bool have_vol = false;

   Enter(200);
   dcr->set_ameta();
   init_device_wait_timers(dcr);

   dev->Lock_acquire();             /* only one job at a time */
   dev->Lock();
   Dmsg1(100, "acquire_append device is %s\n", dev->print_type());
   /*
    * With the reservation system, this should not happen
    */
   if (dev->can_read()) {
      Mmsg2(jcr->errmsg, "Want to append but %s device %s is busy reading.\n",
         dev->print_type(), dev->print_name());
      Jmsg(jcr, M_FATAL, 0, jcr->errmsg);
      Dmsg0(50, jcr->errmsg);
      goto get_out;
   }

   dev->clear_unload();

   /*
    * have_vol defines whether or not mount_next_write_volume should
    *   ask the Director again about what Volume to use.
    */
   if (dev->can_append() && dcr->is_suitable_volume_mounted() &&
       strcmp(dcr->VolCatInfo.VolCatStatus, "Recycle") != 0) {
      Dmsg0(190, "device already in append.\n");
      /*
       * At this point, the correct tape is already mounted, so
       *   we do not need to do mount_next_write_volume(), unless
       *   we need to recycle the tape.
       */
       if (dev->num_writers == 0) {
          dev->VolCatInfo = dcr->VolCatInfo;   /* structure assignment */
       }
       have_vol = dcr->is_tape_position_ok();
   }

   if (!have_vol) {
      dev->rLock(true);
      block_device(dev, BST_DOING_ACQUIRE);
      dev->Unlock();
      Dmsg1(190, "jid=%u Do mount_next_write_vol\n", (uint32_t)jcr->JobId);
      if (!dcr->mount_next_write_volume()) {
         if (!job_canceled(jcr)) {
            /* Reduce "noise" -- don't print if job canceled */
            Mmsg2(jcr->errmsg, _("Could not ready %s device %s for append.\n"),
               dev->print_type(), dev->print_name());
            Jmsg(jcr, M_FATAL, 0, jcr->errmsg);
            Dmsg0(50, jcr->errmsg);
         }
         dev->Lock();
         unblock_device(dev);
         goto get_out;
      }
      Dmsg2(190, "Output pos=%u:%u\n", dcr->dev->file, dcr->dev->block_num);
      dev->Lock();
      unblock_device(dev);
   }

   if (generate_plugin_event(jcr, bsdEventDeviceOpen, dcr) != bRC_OK) {
      Mmsg0(jcr->errmsg,  _("generate_plugin_event(bsdEventDeviceOpen) Failed\n"));
      Jmsg(jcr, M_FATAL, 0, jcr->errmsg);
      Dmsg0(50, jcr->errmsg);
      goto get_out;
   }

   dev->num_writers++;                /* we are now a writer */
   if (jcr->NumWriteVolumes == 0) {
      jcr->NumWriteVolumes = 1;
   }
   dev->VolCatInfo.VolCatJobs++;              /* increment number of jobs on vol */

   ok = dir_update_volume_info(dcr, false, false); /* send Volume info to Director */
   if (!ok) {                   /* We cannot use this volume/device */
      Jmsg(jcr, M_WARNING, 0, _("Warning cannot use Volume \"%s\", update_volume_info failed.\n"),
         dev->VolCatInfo.VolCatName);
      dev->num_writers--;       /* on fail update_volume do not update num_writers */
      /* TODO: See if we revert the NumWriteVolumes as well */
   }

   Dmsg4(100, "=== nwriters=%d nres=%d vcatjob=%d dev=%s\n",
      dev->num_writers, dev->num_reserved(), dev->VolCatInfo.VolCatJobs,
      dev->print_name());

get_out:
   /* Don't plugin close here, we might have multiple writers */
   dcr->clear_reserved();
   dev->Unlock();
   dev->Unlock_acquire();
   Leave(200);
   return ok ? dcr : NULL;
}
/*
 * Acquire device for writing. We permit multiple writers.
 *  If this is the first one, we read the label.
 *
 *  Returns: NULL if failed for any reason
 *           dcr if successful.
 *   Note, normally reserve_device_for_append() is called
 *   before this routine.
 */
Acquire device for writing. We permit multiple writers.
If this is the first one, we read the label.

NULL if failed for any reason
dcr if successful.
Note, normally reserve_device_for_append() is called
before this routine.
Acquire device for writing . We permit multiple writers . If this is the first one we read the label . NULL if failed for any reason dcr if successful . Note normally reserve_device_for_append () is called before this routine .
DCR *acquire_device_for_append(DCR *dcr)
{
   DEVICE *dev = dcr->dev;
   JCR *jcr = dcr->jcr;
   bool ok = false;
   bool have_vol = false;
   Enter(200);
   dcr->set_ameta();
   init_device_wait_timers(dcr);
   dev->Lock_acquire();             
   dev->Lock();
   Dmsg1(100, "acquire_append device is %s\n", dev->print_type());
   if (dev->can_read()) {
      Mmsg2(jcr->errmsg, "Want to append but %s device %s is busy reading.\n",
         dev->print_type(), dev->print_name());
      Jmsg(jcr, M_FATAL, 0, jcr->errmsg);
      Dmsg0(50, jcr->errmsg);
      goto get_out;
   }
   dev->clear_unload();
   if (dev->can_append() && dcr->is_suitable_volume_mounted() &&
       strcmp(dcr->VolCatInfo.VolCatStatus, "Recycle") != 0) {
      Dmsg0(190, "device already in append.\n");
       if (dev->num_writers == 0) {
          dev->VolCatInfo = dcr->VolCatInfo;   
       }
       have_vol = dcr->is_tape_position_ok();
   }
   if (!have_vol) {
      dev->rLock(true);
      block_device(dev, BST_DOING_ACQUIRE);
      dev->Unlock();
      Dmsg1(190, "jid=%u Do mount_next_write_vol\n", (uint32_t)jcr->JobId);
      if (!dcr->mount_next_write_volume()) {
         if (!job_canceled(jcr)) {
            Mmsg2(jcr->errmsg, _("Could not ready %s device %s for append.\n"),
               dev->print_type(), dev->print_name());
            Jmsg(jcr, M_FATAL, 0, jcr->errmsg);
            Dmsg0(50, jcr->errmsg);
         }
         dev->Lock();
         unblock_device(dev);
         goto get_out;
      }
      Dmsg2(190, "Output pos=%u:%u\n", dcr->dev->file, dcr->dev->block_num);
      dev->Lock();
      unblock_device(dev);
   }
   if (generate_plugin_event(jcr, bsdEventDeviceOpen, dcr) != bRC_OK) {
      Mmsg0(jcr->errmsg,  _("generate_plugin_event(bsdEventDeviceOpen) Failed\n"));
      Jmsg(jcr, M_FATAL, 0, jcr->errmsg);
      Dmsg0(50, jcr->errmsg);
      goto get_out;
   }
   dev->num_writers++;                
   if (jcr->NumWriteVolumes == 0) {
      jcr->NumWriteVolumes = 1;
   }
   dev->VolCatInfo.VolCatJobs++;              
   ok = dir_update_volume_info(dcr, false, false); 
   if (!ok) {                   
      Jmsg(jcr, M_WARNING, 0, _("Warning cannot use Volume \"%s\", update_volume_info failed.\n"),
         dev->VolCatInfo.VolCatName);
      dev->num_writers--;       
   }
   Dmsg4(100, "=== nwriters=%d nres=%d vcatjob=%d dev=%s\n",
      dev->num_writers, dev->num_reserved(), dev->VolCatInfo.VolCatJobs,
      dev->print_name());
get_out:
   dcr->clear_reserved();
   dev->Unlock();
   dev->Unlock_acquire();
   Leave(200);
   return ok ? dcr : NULL;
}
DCR * acquire_device_for_append ( DCR * dcr ) { DEVICE * dev = dcr -> dev ; JCR * jcr = dcr -> jcr ; bool ok = false ; bool have_vol = false ; Enter ( 200 ) ; dcr -> set_ameta ( ) ; init_device_wait_timers ( dcr ) ; dev -> Lock_acquire ( ) ; dev -> Lock ( ) ; Dmsg1 ( 100 , " \n " , dev -> print_type ( ) ) ; if ( dev -> can_read ( ) ) { Mmsg2 ( jcr -> errmsg , " \n " , dev -> print_type ( ) , dev -> print_name ( ) ) ; Jmsg ( jcr , M_FATAL , 0 , jcr -> errmsg ) ; Dmsg0 ( 50 , jcr -> errmsg ) ; goto get_out ; } dev -> clear_unload ( ) ; if ( dev -> can_append ( ) && dcr -> is_suitable_volume_mounted ( ) && strcmp ( dcr -> VolCatInfo . VolCatStatus , " " ) != 0 ) { Dmsg0 ( 190 , " \n " ) ; if ( dev -> num_writers == 0 ) { dev -> VolCatInfo = dcr -> VolCatInfo ; } have_vol = dcr -> is_tape_position_ok ( ) ; } if ( ! have_vol ) { dev -> rLock ( true ) ; block_device ( dev , BST_DOING_ACQUIRE ) ; dev -> Unlock ( ) ; Dmsg1 ( 190 , " \n " , ( uint32_t ) jcr -> JobId ) ; if ( ! dcr -> mount_next_write_volume ( ) ) { if ( ! job_canceled ( jcr ) ) { Mmsg2 ( jcr -> errmsg , _ ( " \n " ) , dev -> print_type ( ) , dev -> print_name ( ) ) ; Jmsg ( jcr , M_FATAL , 0 , jcr -> errmsg ) ; Dmsg0 ( 50 , jcr -> errmsg ) ; } dev -> Lock ( ) ; unblock_device ( dev ) ; goto get_out ; } Dmsg2 ( 190 , " \n " , dcr -> dev -> file , dcr -> dev -> block_num ) ; dev -> Lock ( ) ; unblock_device ( dev ) ; } if ( generate_plugin_event ( jcr , bsdEventDeviceOpen , dcr ) != bRC_OK ) { Mmsg0 ( jcr -> errmsg , _ ( " \n " ) ) ; Jmsg ( jcr , M_FATAL , 0 , jcr -> errmsg ) ; Dmsg0 ( 50 , jcr -> errmsg ) ; goto get_out ; } dev -> num_writers ++ ; if ( jcr -> NumWriteVolumes == 0 ) { jcr -> NumWriteVolumes = 1 ; } dev -> VolCatInfo . VolCatJobs ++ ; ok = dir_update_volume_info ( dcr , false , false ) ; if ( ! ok ) { Jmsg ( jcr , M_WARNING , 0 , _ ( " \" \" \n " ) , dev -> VolCatInfo . VolCatName ) ; dev -> num_writers -- ; } Dmsg4 ( 100 , " \n " , dev -> num_writers , dev -> num_reserved ( ) , dev -> VolCatInfo . VolCatJobs , dev -> print_name ( ) ) ; get_out : dcr -> clear_reserved ( ) ; dev -> Unlock ( ) ; dev -> Unlock_acquire ( ) ; Leave ( 200 ) ; return ok ? dcr : NULL ; }
Acquire device for writing.
Acquire device for writing .
/* only one job at a time */ /*
    * With the reservation system, this should not happen
    */ /*
    * have_vol defines whether or not mount_next_write_volume should
    *   ask the Director again about what Volume to use.
    */ /*
       * At this point, the correct tape is already mounted, so
       *   we do not need to do mount_next_write_volume(), unless
       *   we need to recycle the tape.
       */ /* structure assignment */ /* Reduce "noise" -- don't print if job canceled */ /* we are now a writer */ /* increment number of jobs on vol */ /* send Volume info to Director */ /* We cannot use this volume/device */ /* on fail update_volume do not update num_writers */ /* TODO: See if we revert the NumWriteVolumes as well */ /* Don't plugin close here, we might have multiple writers */