src/stored/dircmd.c
static bool upload_cmd(JCR *jcr)
{
   POOLMEM *volname, *poolname, *mtype, *err;
   POOL_MEM dev_name;
   BSOCK *dir = jcr->dir_bsock;
   DCR *dcr = NULL;
   DEVICE *dev;
   bool ok = false;
   int32_t slot, drive;

   volname = get_memory(dir->msglen+1);
   poolname = get_memory(dir->msglen+1);
   mtype = get_memory(dir->msglen+1);
   err = get_pool_memory(PM_MESSAGE);
   *volname = *poolname = *mtype = *err = 0;

   if (sscanf(dir->msg, "upload Storage=%127s Volume=%127s PoolName=%127s "
              "MediaType=%127s Slot=%d drive=%d",
               dev_name.c_str(), volname, poolname, mtype,
               &slot, &drive) == 6) {
      ok = true;
   }
   if (ok) {
      unbash_spaces(volname);
      unbash_spaces(poolname);
      unbash_spaces(mtype);
      dcr = find_device(jcr, dev_name, mtype, drive);
      if (dcr) {
         uint32_t max_jobs;
         dev = dcr->dev;
         ok = true;
         dev->Lock();                 /* Use P to avoid indefinite block */
         max_jobs = dev->max_concurrent_jobs;
         dev->max_concurrent_jobs = 1;
         bstrncpy(dcr->VolumeName, volname, sizeof(dcr->VolumeName));
         if (dcr->can_i_write_volume()) {
            if (reserve_volume(dcr, volname) == NULL) {
               ok = false;
            }
            Dmsg1(400, "Reserved volume \"%s\"\n", volname);
         } else {
            ok = false;
         }
         if (!ok) {
            dir->fsend(_("3908 Error reserving Volume=\"%s\": %s"), volname, jcr->errmsg);
            dev->max_concurrent_jobs = max_jobs;
            dev->Unlock();
            goto bail_out;
         }
         if ((!dev->is_open() && !dev->is_busy()) || dev->can_obtain_block()) {
            Dmsg0(400, "Can upload, because device is not open.\n");
            dev->setVolCatName(volname);
            dev->part = 0;
            if (dev->open_device(dcr, OPEN_READ_WRITE)) {
               ok = dev->upload_cache(dcr, volname, err);
               dev->part = 0;
               dev->close(dcr);
               dev->end_of_job(dcr);
            }
         } else if (dev->is_busy() || dev->is_blocked()) {
            send_dir_busy_message(dir, dev);
         } else {                     /* device not being used */
            Dmsg0(400, "Can upload, because device not used\n");
            dev->setVolCatName(volname);
            dev->part = 0;
            if (dev->open_device(dcr, OPEN_READ_WRITE)) {
               ok = dev->upload_cache(dcr, volname, err);
               dev->part = 0;
               dev->close(dcr);
               dev->end_of_job(dcr);
            }
         }
         dev->max_concurrent_jobs = max_jobs;
         volume_unused(dcr);
         dev->Unlock();
#ifdef DEVELOPER
         if (chk_dbglvl(DT_VOLUME)) {
            Dmsg0(0, "Waiting few seconds to force a bug...\n");
            bmicrosleep(30, 0);
            Dmsg0(0, "Doing free_volume()\n");
         }
#endif
      } else {
         dir->fsend(_("3999 Device \"%s\" not found or could not be opened.\n"), dev_name.c_str());
      }
   } else {
      /* NB dir->msg gets clobbered in bnet_fsend, so save command */
      pm_strcpy(jcr->errmsg, dir->msg);
      dir->fsend(_("3912 Error scanning upload command: ERR=%s\n"), jcr->errmsg);
   }
bail_out:
   if (ok) {
      dir->fsend(_("3000 OK upload.\n"));
   } else {
      dir->fsend(_("3999 Error with the upload: ERR=%s\n"), err);
   }
   if (dcr) {
      free_dcr(dcr);
   }
   free_pool_memory(err);
   free_memory(volname);
   free_memory(poolname);
   free_memory(mtype);
   dir->signal(BNET_EOD);
   return true;
}
/*
 * Handles upload cache to Cloud command
 */
Handles upload cache to Cloud command
Handles upload cache to Cloud command
static bool upload_cmd(JCR *jcr)
{
   POOLMEM *volname, *poolname, *mtype, *err;
   POOL_MEM dev_name;
   BSOCK *dir = jcr->dir_bsock;
   DCR *dcr = NULL;
   DEVICE *dev;
   bool ok = false;
   int32_t slot, drive;
   volname = get_memory(dir->msglen+1);
   poolname = get_memory(dir->msglen+1);
   mtype = get_memory(dir->msglen+1);
   err = get_pool_memory(PM_MESSAGE);
   *volname = *poolname = *mtype = *err = 0;
   if (sscanf(dir->msg, "upload Storage=%127s Volume=%127s PoolName=%127s "
              "MediaType=%127s Slot=%d drive=%d",
               dev_name.c_str(), volname, poolname, mtype,
               &slot, &drive) == 6) {
      ok = true;
   }
   if (ok) {
      unbash_spaces(volname);
      unbash_spaces(poolname);
      unbash_spaces(mtype);
      dcr = find_device(jcr, dev_name, mtype, drive);
      if (dcr) {
         uint32_t max_jobs;
         dev = dcr->dev;
         ok = true;
         dev->Lock();                 
         max_jobs = dev->max_concurrent_jobs;
         dev->max_concurrent_jobs = 1;
         bstrncpy(dcr->VolumeName, volname, sizeof(dcr->VolumeName));
         if (dcr->can_i_write_volume()) {
            if (reserve_volume(dcr, volname) == NULL) {
               ok = false;
            }
            Dmsg1(400, "Reserved volume \"%s\"\n", volname);
         } else {
            ok = false;
         }
         if (!ok) {
            dir->fsend(_("3908 Error reserving Volume=\"%s\": %s"), volname, jcr->errmsg);
            dev->max_concurrent_jobs = max_jobs;
            dev->Unlock();
            goto bail_out;
         }
         if ((!dev->is_open() && !dev->is_busy()) || dev->can_obtain_block()) {
            Dmsg0(400, "Can upload, because device is not open.\n");
            dev->setVolCatName(volname);
            dev->part = 0;
            if (dev->open_device(dcr, OPEN_READ_WRITE)) {
               ok = dev->upload_cache(dcr, volname, err);
               dev->part = 0;
               dev->close(dcr);
               dev->end_of_job(dcr);
            }
         } else if (dev->is_busy() || dev->is_blocked()) {
            send_dir_busy_message(dir, dev);
         } else {                     
            Dmsg0(400, "Can upload, because device not used\n");
            dev->setVolCatName(volname);
            dev->part = 0;
            if (dev->open_device(dcr, OPEN_READ_WRITE)) {
               ok = dev->upload_cache(dcr, volname, err);
               dev->part = 0;
               dev->close(dcr);
               dev->end_of_job(dcr);
            }
         }
         dev->max_concurrent_jobs = max_jobs;
         volume_unused(dcr);
         dev->Unlock();
#ifdef DEVELOPER
         if (chk_dbglvl(DT_VOLUME)) {
            Dmsg0(0, "Waiting few seconds to force a bug...\n");
            bmicrosleep(30, 0);
            Dmsg0(0, "Doing free_volume()\n");
         }
#endif
      } else {
         dir->fsend(_("3999 Device \"%s\" not found or could not be opened.\n"), dev_name.c_str());
      }
   } else {
      pm_strcpy(jcr->errmsg, dir->msg);
      dir->fsend(_("3912 Error scanning upload command: ERR=%s\n"), jcr->errmsg);
   }
bail_out:
   if (ok) {
      dir->fsend(_("3000 OK upload.\n"));
   } else {
      dir->fsend(_("3999 Error with the upload: ERR=%s\n"), err);
   }
   if (dcr) {
      free_dcr(dcr);
   }
   free_pool_memory(err);
   free_memory(volname);
   free_memory(poolname);
   free_memory(mtype);
   dir->signal(BNET_EOD);
   return true;
}
static bool upload_cmd ( JCR * jcr ) { POOLMEM * volname , * poolname , * mtype , * err ; POOL_MEM dev_name ; BSOCK * dir = jcr -> dir_bsock ; DCR * dcr = NULL ; DEVICE * dev ; bool ok = false ; int32_t slot , drive ; volname = get_memory ( dir -> msglen + 1 ) ; poolname = get_memory ( dir -> msglen + 1 ) ; mtype = get_memory ( dir -> msglen + 1 ) ; err = get_pool_memory ( PM_MESSAGE ) ; * volname = * poolname = * mtype = * err = 0 ; if ( sscanf ( dir -> msg , " " " " , dev_name . c_str ( ) , volname , poolname , mtype , & slot , & drive ) == 6 ) { ok = true ; } if ( ok ) { unbash_spaces ( volname ) ; unbash_spaces ( poolname ) ; unbash_spaces ( mtype ) ; dcr = find_device ( jcr , dev_name , mtype , drive ) ; if ( dcr ) { uint32_t max_jobs ; dev = dcr -> dev ; ok = true ; dev -> Lock ( ) ; max_jobs = dev -> max_concurrent_jobs ; dev -> max_concurrent_jobs = 1 ; bstrncpy ( dcr -> VolumeName , volname , sizeof ( dcr -> VolumeName ) ) ; if ( dcr -> can_i_write_volume ( ) ) { if ( reserve_volume ( dcr , volname ) == NULL ) { ok = false ; } Dmsg1 ( 400 , " \" \" \n " , volname ) ; } else { ok = false ; } if ( ! ok ) { dir -> fsend ( _ ( " \" \" " ) , volname , jcr -> errmsg ) ; dev -> max_concurrent_jobs = max_jobs ; dev -> Unlock ( ) ; goto bail_out ; } if ( ( ! dev -> is_open ( ) && ! dev -> is_busy ( ) ) || dev -> can_obtain_block ( ) ) { Dmsg0 ( 400 , " \n " ) ; dev -> setVolCatName ( volname ) ; dev -> part = 0 ; if ( dev -> open_device ( dcr , OPEN_READ_WRITE ) ) { ok = dev -> upload_cache ( dcr , volname , err ) ; dev -> part = 0 ; dev -> close ( dcr ) ; dev -> end_of_job ( dcr ) ; } } else if ( dev -> is_busy ( ) || dev -> is_blocked ( ) ) { send_dir_busy_message ( dir , dev ) ; } else { Dmsg0 ( 400 , " \n " ) ; dev -> setVolCatName ( volname ) ; dev -> part = 0 ; if ( dev -> open_device ( dcr , OPEN_READ_WRITE ) ) { ok = dev -> upload_cache ( dcr , volname , err ) ; dev -> part = 0 ; dev -> close ( dcr ) ; dev -> end_of_job ( dcr ) ; } } dev -> max_concurrent_jobs = max_jobs ; volume_unused ( dcr ) ; dev -> Unlock ( ) ; #ifdef DEVELOPER if ( chk_dbglvl ( DT_VOLUME ) ) { Dmsg0 ( 0 , " \n " ) ; bmicrosleep ( 30 , 0 ) ; Dmsg0 ( 0 , " \n " ) ; } #endif } else { dir -> fsend ( _ ( " \" \" \n " ) , dev_name . c_str ( ) ) ; } } else { pm_strcpy ( jcr -> errmsg , dir -> msg ) ; dir -> fsend ( _ ( " \n " ) , jcr -> errmsg ) ; } bail_out : if ( ok ) { dir -> fsend ( _ ( " \n " ) ) ; } else { dir -> fsend ( _ ( " \n " ) , err ) ; } if ( dcr ) { free_dcr ( dcr ) ; } free_pool_memory ( err ) ; free_memory ( volname ) ; free_memory ( poolname ) ; free_memory ( mtype ) ; dir -> signal ( BNET_EOD ) ; return true ; }
Handles upload cache to Cloud command
Handles upload cache to Cloud command
/* Use P to avoid indefinite block */ /* device not being used */ /* NB dir->msg gets clobbered in bnet_fsend, so save command */