src/stored/dircmd.c
static bool release_cmd(JCR *jcr)
{
   POOL_MEM devname;
   BSOCK *dir = jcr->dir_bsock;
   DEVICE *dev;
   DCR *dcr;
   int32_t drive;

   if (sscanf(dir->msg, "release %127s drive=%d", devname.c_str(), &drive) == 2) {
      dcr = find_device(jcr, devname, NULL, drive);
      if (dcr) {
         dev = dcr->dev;
         dev->Lock();                 /* Use P to avoid indefinite block */
         if (!dev->is_open()) {
            if (!dev->is_busy()) {
               unload_autochanger(dcr, -1);
            }
            Dmsg0(90, "Device already released\n");
            dir->fsend(_("3921 Device \"%s\" already released.\n"),
               dev->print_name());

         } else if (dev->blocked() == BST_WAITING_FOR_SYSOP) {
            Dmsg2(90, "%d waiter dev_block=%d.\n", dev->num_waiting,
               dev->blocked());
            unload_autochanger(dcr, -1);
            dir->fsend(_("3922 Device \"%s\" waiting for sysop.\n"),
               dev->print_name());

         } else if (dev->blocked() == BST_UNMOUNTED_WAITING_FOR_SYSOP) {
            Dmsg2(90, "%d waiter dev_block=%d. doing unmount\n", dev->num_waiting,
               dev->blocked());
            dir->fsend(_("3922 Device \"%s\" waiting for mount.\n"),
               dev->print_name());

         } else if (dev->blocked() == BST_DOING_ACQUIRE) {
            dir->fsend(_("3923 Device \"%s\" is busy in acquire.\n"),
               dev->print_name());

         } else if (dev->blocked() == BST_WRITING_LABEL) {
            dir->fsend(_("3914 Device \"%s\" is being labeled.\n"),
               dev->print_name());

         } else if (dev->is_busy()) {
            send_dir_busy_message(dir, dev);
         } else {                     /* device not being used */
            Dmsg0(90, "Device not in use, releasing\n");
            dcr->release_volume();
            dir->fsend(_("3022 Device \"%s\" released.\n"),
               dev->print_name());
         }
         dev->Unlock();
         free_dcr(dcr);
      } else {
         dir->fsend(_("3999 Device \"%s\" not found or could not be opened.\n"), devname.c_str());
      }
   } else {
      /* NB dir->msg gets clobbered in bnet_fsend, so save command */
      pm_strcpy(jcr->errmsg, dir->msg);
      dir->fsend(_("3927 Error scanning release command: %s\n"), jcr->errmsg);
   }
   dir->signal(BNET_EOD);
   return true;
}
/*
 * Release command from Director. This rewinds the device and if
 *   configured does a offline and ensures that Bacula will
 *   re-read the label of the tape before continuing. This gives
 *   the operator the chance to change the tape anytime before the
 *   next job starts.
 */
Release command from Director. This rewinds the device and if
configured does a offline and ensures that Bacula will
re-read the label of the tape before continuing. This gives
the operator the chance to change the tape anytime before the
next job starts.
Release command from Director . This rewinds the device and if configured does a offline and ensures that Bacula will re - read the label of the tape before continuing . This gives the operator the chance to change the tape anytime before the next job starts .
static bool release_cmd(JCR *jcr)
{
   POOL_MEM devname;
   BSOCK *dir = jcr->dir_bsock;
   DEVICE *dev;
   DCR *dcr;
   int32_t drive;
   if (sscanf(dir->msg, "release %127s drive=%d", devname.c_str(), &drive) == 2) {
      dcr = find_device(jcr, devname, NULL, drive);
      if (dcr) {
         dev = dcr->dev;
         dev->Lock();                 
         if (!dev->is_open()) {
            if (!dev->is_busy()) {
               unload_autochanger(dcr, -1);
            }
            Dmsg0(90, "Device already released\n");
            dir->fsend(_("3921 Device \"%s\" already released.\n"),
               dev->print_name());
         } else if (dev->blocked() == BST_WAITING_FOR_SYSOP) {
            Dmsg2(90, "%d waiter dev_block=%d.\n", dev->num_waiting,
               dev->blocked());
            unload_autochanger(dcr, -1);
            dir->fsend(_("3922 Device \"%s\" waiting for sysop.\n"),
               dev->print_name());
         } else if (dev->blocked() == BST_UNMOUNTED_WAITING_FOR_SYSOP) {
            Dmsg2(90, "%d waiter dev_block=%d. doing unmount\n", dev->num_waiting,
               dev->blocked());
            dir->fsend(_("3922 Device \"%s\" waiting for mount.\n"),
               dev->print_name());
         } else if (dev->blocked() == BST_DOING_ACQUIRE) {
            dir->fsend(_("3923 Device \"%s\" is busy in acquire.\n"),
               dev->print_name());
         } else if (dev->blocked() == BST_WRITING_LABEL) {
            dir->fsend(_("3914 Device \"%s\" is being labeled.\n"),
               dev->print_name());
         } else if (dev->is_busy()) {
            send_dir_busy_message(dir, dev);
         } else {                     
            Dmsg0(90, "Device not in use, releasing\n");
            dcr->release_volume();
            dir->fsend(_("3022 Device \"%s\" released.\n"),
               dev->print_name());
         }
         dev->Unlock();
         free_dcr(dcr);
      } else {
         dir->fsend(_("3999 Device \"%s\" not found or could not be opened.\n"), devname.c_str());
      }
   } else {
      pm_strcpy(jcr->errmsg, dir->msg);
      dir->fsend(_("3927 Error scanning release command: %s\n"), jcr->errmsg);
   }
   dir->signal(BNET_EOD);
   return true;
}
static bool release_cmd ( JCR * jcr ) { POOL_MEM devname ; BSOCK * dir = jcr -> dir_bsock ; DEVICE * dev ; DCR * dcr ; int32_t drive ; if ( sscanf ( dir -> msg , " " , devname . c_str ( ) , & drive ) == 2 ) { dcr = find_device ( jcr , devname , NULL , drive ) ; if ( dcr ) { dev = dcr -> dev ; dev -> Lock ( ) ; if ( ! dev -> is_open ( ) ) { if ( ! dev -> is_busy ( ) ) { unload_autochanger ( dcr , -1 ) ; } Dmsg0 ( 90 , " \n " ) ; dir -> fsend ( _ ( " \" \" \n " ) , dev -> print_name ( ) ) ; } else if ( dev -> blocked ( ) == BST_WAITING_FOR_SYSOP ) { Dmsg2 ( 90 , " \n " , dev -> num_waiting , dev -> blocked ( ) ) ; unload_autochanger ( dcr , -1 ) ; dir -> fsend ( _ ( " \" \" \n " ) , dev -> print_name ( ) ) ; } else if ( dev -> blocked ( ) == BST_UNMOUNTED_WAITING_FOR_SYSOP ) { Dmsg2 ( 90 , " \n " , dev -> num_waiting , dev -> blocked ( ) ) ; dir -> fsend ( _ ( " \" \" \n " ) , dev -> print_name ( ) ) ; } else if ( dev -> blocked ( ) == BST_DOING_ACQUIRE ) { dir -> fsend ( _ ( " \" \" \n " ) , dev -> print_name ( ) ) ; } else if ( dev -> blocked ( ) == BST_WRITING_LABEL ) { dir -> fsend ( _ ( " \" \" \n " ) , dev -> print_name ( ) ) ; } else if ( dev -> is_busy ( ) ) { send_dir_busy_message ( dir , dev ) ; } else { Dmsg0 ( 90 , " \n " ) ; dcr -> release_volume ( ) ; dir -> fsend ( _ ( " \" \" \n " ) , dev -> print_name ( ) ) ; } dev -> Unlock ( ) ; free_dcr ( dcr ) ; } else { dir -> fsend ( _ ( " \" \" \n " ) , devname . c_str ( ) ) ; } } else { pm_strcpy ( jcr -> errmsg , dir -> msg ) ; dir -> fsend ( _ ( " \n " ) , jcr -> errmsg ) ; } dir -> signal ( BNET_EOD ) ; return true ; }
Release command from Director.
Release command from Director .
/* Use P to avoid indefinite block */ /* device not being used */ /* NB dir->msg gets clobbered in bnet_fsend, so save command */