src/stored/cloud_dev.c
void *download_engine(transfer *tpkt)
{
#ifdef RANDOM_WAIT_ENABLE
   srand(time(NULL));
   /* wait between 2 and 12 seconds */
   int s_time = RANDOM_WAIT_MIN + rand() % (RANDOM_WAIT_MAX-RANDOM_WAIT_MIN);
   bmicrosleep(s_time, 0);
#endif
   if (tpkt && tpkt->m_driver) {
      /* call the driver method async */
      Dmsg4(dbglvl, "Download starts %s-%d : job : %d driver :%p\n",
         tpkt->m_volume_name, tpkt->m_part, tpkt->m_dcr->jcr->JobId, tpkt->m_driver);
      if (!tpkt->m_driver->copy_cloud_part_to_cache(tpkt)) {
         Dmsg4(dbglvl, "Download error!! JobId=%d part=%d Vol=%s cache=%s\n",
            tpkt->m_dcr->jcr->JobId, tpkt->m_part, tpkt->m_volume_name, tpkt->m_cache_fname);
         POOL_MEM dmsg(PM_MESSAGE);
         tpkt->append_status(dmsg);
         Dmsg1(dbglvl, "%s\n",dmsg.c_str());

         /* download failed -> remove the temp xfer file */
         if (unlink(tpkt->m_cache_fname) != 0) {
            berrno be;
            Dmsg2(dbglvl, "Unable to delete %s. ERR=%s\n", tpkt->m_cache_fname, be.bstrerror());
         } else {
            Dmsg1(dbglvl, "Unlink file %s\n", tpkt->m_cache_fname);
         }

         return tpkt;
      }
      else {
         POOLMEM *cache_fname = get_pool_memory(PM_FNAME);
         pm_strcpy(cache_fname, tpkt->m_cache_fname);
         char *p = strstr(cache_fname, XFER_TMP_NAME);
         char partnumber[20];
         bsnprintf(partnumber, sizeof(partnumber), "part.%d", tpkt->m_part);
         strcpy(p,partnumber);
         if (rename(tpkt->m_cache_fname, cache_fname) != 0) {
            Dmsg5(dbglvl, "Download copy error!! JobId=%d part=%d Vol=%s temp cache=%s cache=%s\n",
            tpkt->m_dcr->jcr->JobId, tpkt->m_part, tpkt->m_volume_name, tpkt->m_cache_fname, cache_fname);
            free_pool_memory(cache_fname);
            return tpkt;
         }
         free_pool_memory(cache_fname);
      }
      Dmsg2(dbglvl, "Download end JobId : %d driver :%p\n",
         tpkt->m_dcr->jcr->JobId, tpkt->m_driver);
   }
   return NULL;
}
/*
 * This download_engine is called by workq in a worker thread.
 */
This download_engine is called by workq in a worker thread.
This download_engine is called by workq in a worker thread .
void *download_engine(transfer *tpkt)
{
#ifdef RANDOM_WAIT_ENABLE
   srand(time(NULL));
   int s_time = RANDOM_WAIT_MIN + rand() % (RANDOM_WAIT_MAX-RANDOM_WAIT_MIN);
   bmicrosleep(s_time, 0);
#endif
   if (tpkt && tpkt->m_driver) {
      Dmsg4(dbglvl, "Download starts %s-%d : job : %d driver :%p\n",
         tpkt->m_volume_name, tpkt->m_part, tpkt->m_dcr->jcr->JobId, tpkt->m_driver);
      if (!tpkt->m_driver->copy_cloud_part_to_cache(tpkt)) {
         Dmsg4(dbglvl, "Download error!! JobId=%d part=%d Vol=%s cache=%s\n",
            tpkt->m_dcr->jcr->JobId, tpkt->m_part, tpkt->m_volume_name, tpkt->m_cache_fname);
         POOL_MEM dmsg(PM_MESSAGE);
         tpkt->append_status(dmsg);
         Dmsg1(dbglvl, "%s\n",dmsg.c_str());
         if (unlink(tpkt->m_cache_fname) != 0) {
            berrno be;
            Dmsg2(dbglvl, "Unable to delete %s. ERR=%s\n", tpkt->m_cache_fname, be.bstrerror());
         } else {
            Dmsg1(dbglvl, "Unlink file %s\n", tpkt->m_cache_fname);
         }
         return tpkt;
      }
      else {
         POOLMEM *cache_fname = get_pool_memory(PM_FNAME);
         pm_strcpy(cache_fname, tpkt->m_cache_fname);
         char *p = strstr(cache_fname, XFER_TMP_NAME);
         char partnumber[20];
         bsnprintf(partnumber, sizeof(partnumber), "part.%d", tpkt->m_part);
         strcpy(p,partnumber);
         if (rename(tpkt->m_cache_fname, cache_fname) != 0) {
            Dmsg5(dbglvl, "Download copy error!! JobId=%d part=%d Vol=%s temp cache=%s cache=%s\n",
            tpkt->m_dcr->jcr->JobId, tpkt->m_part, tpkt->m_volume_name, tpkt->m_cache_fname, cache_fname);
            free_pool_memory(cache_fname);
            return tpkt;
         }
         free_pool_memory(cache_fname);
      }
      Dmsg2(dbglvl, "Download end JobId : %d driver :%p\n",
         tpkt->m_dcr->jcr->JobId, tpkt->m_driver);
   }
   return NULL;
}
void * download_engine ( transfer * tpkt ) { #ifdef RANDOM_WAIT_ENABLE srand ( time ( NULL ) ) ; int s_time = RANDOM_WAIT_MIN + rand ( ) % ( RANDOM_WAIT_MAX - RANDOM_WAIT_MIN ) ; bmicrosleep ( s_time , 0 ) ; #endif if ( tpkt && tpkt -> m_driver ) { Dmsg4 ( dbglvl , " \n " , tpkt -> m_volume_name , tpkt -> m_part , tpkt -> m_dcr -> jcr -> JobId , tpkt -> m_driver ) ; if ( ! tpkt -> m_driver -> copy_cloud_part_to_cache ( tpkt ) ) { Dmsg4 ( dbglvl , " \n " , tpkt -> m_dcr -> jcr -> JobId , tpkt -> m_part , tpkt -> m_volume_name , tpkt -> m_cache_fname ) ; POOL_MEM dmsg ( PM_MESSAGE ) ; tpkt -> append_status ( dmsg ) ; Dmsg1 ( dbglvl , " \n " , dmsg . c_str ( ) ) ; if ( unlink ( tpkt -> m_cache_fname ) != 0 ) { berrno be ; Dmsg2 ( dbglvl , " \n " , tpkt -> m_cache_fname , be . bstrerror ( ) ) ; } else { Dmsg1 ( dbglvl , " \n " , tpkt -> m_cache_fname ) ; } return tpkt ; } else { POOLMEM * cache_fname = get_pool_memory ( PM_FNAME ) ; pm_strcpy ( cache_fname , tpkt -> m_cache_fname ) ; char * p = strstr ( cache_fname , XFER_TMP_NAME ) ; char partnumber [ 20 ] ; bsnprintf ( partnumber , sizeof ( partnumber ) , " " , tpkt -> m_part ) ; strcpy ( p , partnumber ) ; if ( rename ( tpkt -> m_cache_fname , cache_fname ) != 0 ) { Dmsg5 ( dbglvl , " \n " , tpkt -> m_dcr -> jcr -> JobId , tpkt -> m_part , tpkt -> m_volume_name , tpkt -> m_cache_fname , cache_fname ) ; free_pool_memory ( cache_fname ) ; return tpkt ; } free_pool_memory ( cache_fname ) ; } Dmsg2 ( dbglvl , " \n " , tpkt -> m_dcr -> jcr -> JobId , tpkt -> m_driver ) ; } return NULL ; }
This download_engine is called by workq in a worker thread.
This download_engine is called by workq in a worker thread .
/* wait between 2 and 12 seconds */ /* call the driver method async */ /* download failed -> remove the temp xfer file */