src/filed/hello.c
void *handle_storage_connection(BSOCK *sd)
{
   char job_name[500];
   char tbuf[150];
   int sd_version = 0;
   JCR *jcr;

   if (sscanf(sd->msg, "Hello FD: Bacula Storage calling Start Job %127s %d",
       job_name, &sd_version) != 2) {
      Jmsg(NULL, M_FATAL, 0, _("SD connect failed: Bad Hello command\n"));
      return NULL;
   }
   Dmsg1(110, "Got a SD connection at %s\n", bstrftimes(tbuf, sizeof(tbuf),
         (utime_t)time(NULL)));
   Dmsg1(50, "%s", sd->msg);

   if (!(jcr=get_jcr_by_full_name(job_name))) {
      Jmsg1(NULL, M_FATAL, 0, _("SD connect failed: Job name not found: %s\n"), job_name);
      Dmsg1(3, "**** Job \"%s\" not found.\n", job_name);
      sd->destroy();
      return NULL;
   }
   set_jcr_in_tsd(jcr);
   Dmsg1(150, "Found Job %s\n", job_name);

   jcr->lock_auth();
   /* We already have a socket connected, just discard it */
   if (jcr->sd_calls_client_bsock) {
      Qmsg1(jcr, M_WARNING, 0, _("SD \"%s\" tried to connect two times.\n"), sd->who());
      free_bsock(sd);
      /* will exit just after the unlock() */

   } else {
      /* If we have a previous socket in store_bsock, we are in multi restore mode */
      jcr->sd_calls_client_bsock = sd;
      sd->set_jcr(jcr);
   }
   jcr->unlock_auth();

   if (!sd) {                   /* freed by free_bsock(), connection already done */
      free_jcr(jcr);
      return NULL;
   }

   /* Turn on compression for newer FDs */
   if (sd_version >= 1 && me->comm_compression) {
      sd->set_compress();             /* set compression allowed */
   } else {
      sd->clear_compress();
      Dmsg2(050, "******** No FD compression to SD. sd_ver=%d compres=%d\n",
            sd_version, me->comm_compression);
   }

   if (!jcr->max_bandwidth) {
      if (jcr->director->max_bandwidth_per_job) {
         jcr->max_bandwidth = jcr->director->max_bandwidth_per_job;

      } else if (me->max_bandwidth_per_job) {
         jcr->max_bandwidth = me->max_bandwidth_per_job;
      }
   }
   sd->set_bwlimit(jcr->max_bandwidth);

   Dmsg1(200, "sd_version=%ld\n", sd_version);

   pthread_cond_signal(&jcr->job_start_wait); /* wake waiting job */
   free_jcr(jcr);
   return NULL;
}
/*
 * Note, we handle the initial connection request here.
 *   We only get the jobname and the SD version, then we
 *   return, authentication will be done when the Director
 *   sends the storage command -- as is usually the case.
 *   This should be called only once by the SD.
 */
Note, we handle the initial connection request here.
We only get the jobname and the SD version, then we
return, authentication will be done when the Director
sends the storage command -- as is usually the case.
This should be called only once by the SD.
Note we handle the initial connection request here . We only get the jobname and the SD version then we return authentication will be done when the Director sends the storage command -- as is usually the case . This should be called only once by the SD .
void *handle_storage_connection(BSOCK *sd)
{
   char job_name[500];
   char tbuf[150];
   int sd_version = 0;
   JCR *jcr;
   if (sscanf(sd->msg, "Hello FD: Bacula Storage calling Start Job %127s %d",
       job_name, &sd_version) != 2) {
      Jmsg(NULL, M_FATAL, 0, _("SD connect failed: Bad Hello command\n"));
      return NULL;
   }
   Dmsg1(110, "Got a SD connection at %s\n", bstrftimes(tbuf, sizeof(tbuf),
         (utime_t)time(NULL)));
   Dmsg1(50, "%s", sd->msg);
   if (!(jcr=get_jcr_by_full_name(job_name))) {
      Jmsg1(NULL, M_FATAL, 0, _("SD connect failed: Job name not found: %s\n"), job_name);
      Dmsg1(3, "**** Job \"%s\" not found.\n", job_name);
      sd->destroy();
      return NULL;
   }
   set_jcr_in_tsd(jcr);
   Dmsg1(150, "Found Job %s\n", job_name);
   jcr->lock_auth();
   if (jcr->sd_calls_client_bsock) {
      Qmsg1(jcr, M_WARNING, 0, _("SD \"%s\" tried to connect two times.\n"), sd->who());
      free_bsock(sd);
   } else {
      jcr->sd_calls_client_bsock = sd;
      sd->set_jcr(jcr);
   }
   jcr->unlock_auth();
   if (!sd) {                   
      free_jcr(jcr);
      return NULL;
   }
   if (sd_version >= 1 && me->comm_compression) {
      sd->set_compress();             
   } else {
      sd->clear_compress();
      Dmsg2(050, "******** No FD compression to SD. sd_ver=%d compres=%d\n",
            sd_version, me->comm_compression);
   }
   if (!jcr->max_bandwidth) {
      if (jcr->director->max_bandwidth_per_job) {
         jcr->max_bandwidth = jcr->director->max_bandwidth_per_job;
      } else if (me->max_bandwidth_per_job) {
         jcr->max_bandwidth = me->max_bandwidth_per_job;
      }
   }
   sd->set_bwlimit(jcr->max_bandwidth);
   Dmsg1(200, "sd_version=%ld\n", sd_version);
   pthread_cond_signal(&jcr->job_start_wait); 
   free_jcr(jcr);
   return NULL;
}
void * handle_storage_connection ( BSOCK * sd ) { char job_name [ 500 ] ; char tbuf [ 150 ] ; int sd_version = 0 ; JCR * jcr ; if ( sscanf ( sd -> msg , " " , job_name , & sd_version ) != 2 ) { Jmsg ( NULL , M_FATAL , 0 , _ ( " \n " ) ) ; return NULL ; } Dmsg1 ( 110 , " \n " , bstrftimes ( tbuf , sizeof ( tbuf ) , ( utime_t ) time ( NULL ) ) ) ; Dmsg1 ( 50 , " " , sd -> msg ) ; if ( ! ( jcr = get_jcr_by_full_name ( job_name ) ) ) { Jmsg1 ( NULL , M_FATAL , 0 , _ ( " \n " ) , job_name ) ; Dmsg1 ( 3 , " \" \" \n " , job_name ) ; sd -> destroy ( ) ; return NULL ; } set_jcr_in_tsd ( jcr ) ; Dmsg1 ( 150 , " \n " , job_name ) ; jcr -> lock_auth ( ) ; if ( jcr -> sd_calls_client_bsock ) { Qmsg1 ( jcr , M_WARNING , 0 , _ ( " \" \" \n " ) , sd -> who ( ) ) ; free_bsock ( sd ) ; } else { jcr -> sd_calls_client_bsock = sd ; sd -> set_jcr ( jcr ) ; } jcr -> unlock_auth ( ) ; if ( ! sd ) { free_jcr ( jcr ) ; return NULL ; } if ( sd_version >= 1 && me -> comm_compression ) { sd -> set_compress ( ) ; } else { sd -> clear_compress ( ) ; Dmsg2 ( 050 , " \n " , sd_version , me -> comm_compression ) ; } if ( ! jcr -> max_bandwidth ) { if ( jcr -> director -> max_bandwidth_per_job ) { jcr -> max_bandwidth = jcr -> director -> max_bandwidth_per_job ; } else if ( me -> max_bandwidth_per_job ) { jcr -> max_bandwidth = me -> max_bandwidth_per_job ; } } sd -> set_bwlimit ( jcr -> max_bandwidth ) ; Dmsg1 ( 200 , " \n " , sd_version ) ; pthread_cond_signal ( & jcr -> job_start_wait ) ; free_jcr ( jcr ) ; return NULL ; }
Note, we handle the initial connection request here.
Note we handle the initial connection request here .
/* We already have a socket connected, just discard it */ /* will exit just after the unlock() */ /* If we have a previous socket in store_bsock, we are in multi restore mode */ /* freed by free_bsock(), connection already done */ /* Turn on compression for newer FDs */ /* set compression allowed */ /* wake waiting job */