src/stored/acquire.c
DCR *new_dcr(JCR *jcr, DCR *dcr, DEVICE *dev, bool writing)
{
   DEVICE *odev;
   if (!dcr) {
      dcr = (DCR *)malloc(sizeof(DCR));
      memset(dcr, 0, sizeof(DCR));
      dcr->tid = pthread_self();
      dcr->uploads = New(alist(100, false));
      dcr->downloads = New(alist(100, false));
      dcr->spool_fd = -1;
   }
   dcr->jcr = jcr;                 /* point back to jcr */
   odev = dcr->dev;
   if (dcr->attached_to_dev && odev) {
      Dmsg2(100, "Detach 0x%x from olddev %s\n", dcr, odev->print_name());
      odev->detach_dcr_from_dev(dcr);
   }
   ASSERT2(!dcr->attached_to_dev, "DCR is attached. Wrong!");
   /* Set device information, possibly change device */
   if (dev) {
      ASSERT2(!dev->adata, "Called with adata dev. Wrong!");
      dev->free_dcr_blocks(dcr);
      dev->new_dcr_blocks(dcr);
      if (dcr->rec) {
         free_record(dcr->rec);
      }
      dcr->rec = new_record();
      /* Use job spoolsize prior to device spoolsize */
      if (jcr && jcr->spool_size) {
         dcr->max_job_spool_size = jcr->spool_size;
      } else {
         dcr->max_job_spool_size = dev->device->max_job_spool_size;
      }
      dcr->device = dev->device;
      dcr->set_dev(dev);
      Dmsg2(100, "Attach 0x%x to dev %s\n", dcr, dev->print_name());
      dev->attach_dcr_to_dev(dcr);
   }
   if (writing) {
      dcr->set_writing();
   } else {
      dcr->clear_writing();
   }
   return dcr;
}
/*
 * Create a new Device Control Record and attach
 *   it to the device (if this is a real job).
 * Note, this has been updated so that it can be called first
 *   without a DEVICE, then a second or third time with a DEVICE,
 *   and each time, it should cleanup and point to the new device.
 *   This should facilitate switching devices.
 * Note, each dcr must point to the controlling job (jcr).  However,
 *   a job can have multiple dcrs, so we must not store in the jcr's
 *   structure as previously. The higher level routine must store
 *   this dcr in the right place
 *
 */
Create a new Device Control Record and attach
it to the device (if this is a real job).
Note, this has been updated so that it can be called first
without a DEVICE, then a second or third time with a DEVICE,
and each time, it should cleanup and point to the new device.
This should facilitate switching devices.
Note, each dcr must point to the controlling job (jcr).  However,
a job can have multiple dcrs, so we must not store in the jcr's
structure as previously. The higher level routine must store
this dcr in the right place
Create a new Device Control Record and attach it to the device ( if this is a real job ) . Note this has been updated so that it can be called first without a DEVICE then a second or third time with a DEVICE and each time it should cleanup and point to the new device . This should facilitate switching devices . Note each dcr must point to the controlling job ( jcr ) . However a job can have multiple dcrs so we must not store in the jcr ' s structure as previously . The higher level routine must store this dcr in the right place
DCR *new_dcr(JCR *jcr, DCR *dcr, DEVICE *dev, bool writing)
{
   DEVICE *odev;
   if (!dcr) {
      dcr = (DCR *)malloc(sizeof(DCR));
      memset(dcr, 0, sizeof(DCR));
      dcr->tid = pthread_self();
      dcr->uploads = New(alist(100, false));
      dcr->downloads = New(alist(100, false));
      dcr->spool_fd = -1;
   }
   dcr->jcr = jcr;                 
   odev = dcr->dev;
   if (dcr->attached_to_dev && odev) {
      Dmsg2(100, "Detach 0x%x from olddev %s\n", dcr, odev->print_name());
      odev->detach_dcr_from_dev(dcr);
   }
   ASSERT2(!dcr->attached_to_dev, "DCR is attached. Wrong!");
   if (dev) {
      ASSERT2(!dev->adata, "Called with adata dev. Wrong!");
      dev->free_dcr_blocks(dcr);
      dev->new_dcr_blocks(dcr);
      if (dcr->rec) {
         free_record(dcr->rec);
      }
      dcr->rec = new_record();
      if (jcr && jcr->spool_size) {
         dcr->max_job_spool_size = jcr->spool_size;
      } else {
         dcr->max_job_spool_size = dev->device->max_job_spool_size;
      }
      dcr->device = dev->device;
      dcr->set_dev(dev);
      Dmsg2(100, "Attach 0x%x to dev %s\n", dcr, dev->print_name());
      dev->attach_dcr_to_dev(dcr);
   }
   if (writing) {
      dcr->set_writing();
   } else {
      dcr->clear_writing();
   }
   return dcr;
}
DCR * new_dcr ( JCR * jcr , DCR * dcr , DEVICE * dev , bool writing ) { DEVICE * odev ; if ( ! dcr ) { dcr = ( DCR * ) malloc ( sizeof ( DCR ) ) ; memset ( dcr , 0 , sizeof ( DCR ) ) ; dcr -> tid = pthread_self ( ) ; dcr -> uploads = New ( alist ( 100 , false ) ) ; dcr -> downloads = New ( alist ( 100 , false ) ) ; dcr -> spool_fd = -1 ; } dcr -> jcr = jcr ; odev = dcr -> dev ; if ( dcr -> attached_to_dev && odev ) { Dmsg2 ( 100 , " \n " , dcr , odev -> print_name ( ) ) ; odev -> detach_dcr_from_dev ( dcr ) ; } ASSERT2 ( ! dcr -> attached_to_dev , " " ) ; if ( dev ) { ASSERT2 ( ! dev -> adata , " " ) ; dev -> free_dcr_blocks ( dcr ) ; dev -> new_dcr_blocks ( dcr ) ; if ( dcr -> rec ) { free_record ( dcr -> rec ) ; } dcr -> rec = new_record ( ) ; if ( jcr && jcr -> spool_size ) { dcr -> max_job_spool_size = jcr -> spool_size ; } else { dcr -> max_job_spool_size = dev -> device -> max_job_spool_size ; } dcr -> device = dev -> device ; dcr -> set_dev ( dev ) ; Dmsg2 ( 100 , " \n " , dcr , dev -> print_name ( ) ) ; dev -> attach_dcr_to_dev ( dcr ) ; } if ( writing ) { dcr -> set_writing ( ) ; } else { dcr -> clear_writing ( ) ; } return dcr ; }
Create a new Device Control Record and attach
   it to the device (if this is a real job).
Create a new Device Control Record and attach it to the device ( if this is a real job ) .
/* point back to jcr */ /* Set device information, possibly change device */ /* Use job spoolsize prior to device spoolsize */