src/stored/fd_cmds.c
void run_job(JCR *jcr)
{
   BSOCK *dir = jcr->dir_bsock;
   char ec1[30];

   dir->set_jcr(jcr);
   Dmsg1(120, "Start run Job=%s\n", jcr->Job);
   dir->fsend(Job_start, jcr->Job);
   jcr->start_time = time(NULL);
   jcr->run_time = jcr->start_time;
   jcr->sendJobStatus(JS_Running);

   /* TODO: Remove when the new match_all is well tested */
   jcr->use_new_match_all = use_new_match_all;
   /*
    * A migrate or copy job does both a restore (read_data) and
    *   a backup (append_data).
    * Otherwise we do the commands that the client sends
    *   which are for normal backup or restore jobs.
    */
   Dmsg3(050, "==== JobType=%c run_job=%d sd_client=%d\n", jcr->getJobType(), jcr->JobId, jcr->sd_client);
   if (jcr->is_JobType(JT_BACKUP) && jcr->sd_client) {
      jcr->session_opened = true;
      Dmsg0(050, "Do: receive for 3000 OK data then append\n");
      if (!response(jcr, jcr->file_bsock, "3000 OK data\n", "Append data")) {
         Dmsg1(050, "Expect: 3000 OK data, got: %s", jcr->file_bsock->msg);
         Jmsg0(jcr, M_FATAL, 0, "Append data not accepted\n");
         goto bail_out;
      }
      append_data_cmd(jcr);
      append_end_session(jcr);
   } else if (jcr->is_JobType(JT_MIGRATE) || jcr->is_JobType(JT_COPY)) {
      jcr->session_opened = true;
      /*
       * Send "3000 OK data" now to avoid a dead lock, the other side is also
       * waiting for one. The old code was reading the "3000 OK" reply
       * at the end of the backup (not really appropriate).
       * dedup needs duplex communication with the other side and needs the
       * "3000 OK" to be read, which is handled here by the code below.
       */
      Dmsg0(215, "send OK_data\n");
      jcr->file_bsock->fsend(OK_data);
      jcr->is_ok_data_sent = true;
      Dmsg1(050, "Do: read_data_cmd file_bsock=%p\n", jcr->file_bsock);
      Dmsg0(050, "Do: receive for 3000 OK data then read\n");
      if (!response(jcr, jcr->file_bsock, "3000 OK data\n", "Data received")) {
         Dmsg1(050, "Expect 3000 OK data, got: %s", jcr->file_bsock->msg);
         Jmsg0(jcr, M_FATAL, 0, "Read data not accepted\n");
         jcr->file_bsock->signal(BNET_EOD);
         goto bail_out;
      }
      read_data_cmd(jcr);
      jcr->file_bsock->signal(BNET_EOD);
   } else {
      /* Either a Backup or Restore job */
      Dmsg0(050, "Do: do_client_commands\n");
      do_client_commands(jcr);
   }
bail_out:
   jcr->end_time = time(NULL);
   flush_jobmedia_queue(jcr);
   dequeue_messages(jcr);             /* send any queued messages */
   jcr->setJobStatus(JS_Terminated);
   generate_daemon_event(jcr, "JobEnd");
   generate_plugin_event(jcr, bsdEventJobEnd);
   bash_spaces(jcr->StatusErrMsg);
   dir->fsend(Job_end, jcr->Job, jcr->JobStatus, jcr->JobFiles,
              edit_uint64(jcr->JobBytes, ec1), jcr->JobErrors, jcr->StatusErrMsg);
   Dmsg1(100, "==== %s", dir->msg);
   unbash_spaces(jcr->StatusErrMsg);
   dequeue_daemon_messages(jcr);
   dir->signal(BNET_EOD);             /* send EOD to Director daemon */
   free_plugins(jcr);                 /* release instantiated plugins */
   garbage_collect_memory_pool();
   return;
}
/*
 * Run a Client Job -- Client already authorized
 *  Note: this can be either a backup or restore or
 *    migrate/copy job.
 *
 * Basic task here is:
 * - Read a command from the Client -- FD or SD
 * - Execute it
 *
 */
Run a Client Job -- Client already authorized
Note: this can be either a backup or restore or
migrate/copy job.

Basic task here is:
- Read a command from the Client -- FD or SD
- Execute it
Run a Client Job -- Client already authorized Note : this can be either a backup or restore or migrate / copy job . Basic task here is : - Read a command from the Client -- FD or SD - Execute it
void run_job(JCR *jcr)
{
   BSOCK *dir = jcr->dir_bsock;
   char ec1[30];
   dir->set_jcr(jcr);
   Dmsg1(120, "Start run Job=%s\n", jcr->Job);
   dir->fsend(Job_start, jcr->Job);
   jcr->start_time = time(NULL);
   jcr->run_time = jcr->start_time;
   jcr->sendJobStatus(JS_Running);
   jcr->use_new_match_all = use_new_match_all;
   Dmsg3(050, "==== JobType=%c run_job=%d sd_client=%d\n", jcr->getJobType(), jcr->JobId, jcr->sd_client);
   if (jcr->is_JobType(JT_BACKUP) && jcr->sd_client) {
      jcr->session_opened = true;
      Dmsg0(050, "Do: receive for 3000 OK data then append\n");
      if (!response(jcr, jcr->file_bsock, "3000 OK data\n", "Append data")) {
         Dmsg1(050, "Expect: 3000 OK data, got: %s", jcr->file_bsock->msg);
         Jmsg0(jcr, M_FATAL, 0, "Append data not accepted\n");
         goto bail_out;
      }
      append_data_cmd(jcr);
      append_end_session(jcr);
   } else if (jcr->is_JobType(JT_MIGRATE) || jcr->is_JobType(JT_COPY)) {
      jcr->session_opened = true;
      Dmsg0(215, "send OK_data\n");
      jcr->file_bsock->fsend(OK_data);
      jcr->is_ok_data_sent = true;
      Dmsg1(050, "Do: read_data_cmd file_bsock=%p\n", jcr->file_bsock);
      Dmsg0(050, "Do: receive for 3000 OK data then read\n");
      if (!response(jcr, jcr->file_bsock, "3000 OK data\n", "Data received")) {
         Dmsg1(050, "Expect 3000 OK data, got: %s", jcr->file_bsock->msg);
         Jmsg0(jcr, M_FATAL, 0, "Read data not accepted\n");
         jcr->file_bsock->signal(BNET_EOD);
         goto bail_out;
      }
      read_data_cmd(jcr);
      jcr->file_bsock->signal(BNET_EOD);
   } else {
      Dmsg0(050, "Do: do_client_commands\n");
      do_client_commands(jcr);
   }
bail_out:
   jcr->end_time = time(NULL);
   flush_jobmedia_queue(jcr);
   dequeue_messages(jcr);             
   jcr->setJobStatus(JS_Terminated);
   generate_daemon_event(jcr, "JobEnd");
   generate_plugin_event(jcr, bsdEventJobEnd);
   bash_spaces(jcr->StatusErrMsg);
   dir->fsend(Job_end, jcr->Job, jcr->JobStatus, jcr->JobFiles,
              edit_uint64(jcr->JobBytes, ec1), jcr->JobErrors, jcr->StatusErrMsg);
   Dmsg1(100, "==== %s", dir->msg);
   unbash_spaces(jcr->StatusErrMsg);
   dequeue_daemon_messages(jcr);
   dir->signal(BNET_EOD);             
   free_plugins(jcr);                 
   garbage_collect_memory_pool();
   return;
}
void run_job ( JCR * jcr ) { BSOCK * dir = jcr -> dir_bsock ; char ec1 [ 30 ] ; dir -> set_jcr ( jcr ) ; Dmsg1 ( 120 , " \n " , jcr -> Job ) ; dir -> fsend ( Job_start , jcr -> Job ) ; jcr -> start_time = time ( NULL ) ; jcr -> run_time = jcr -> start_time ; jcr -> sendJobStatus ( JS_Running ) ; jcr -> use_new_match_all = use_new_match_all ; Dmsg3 ( 050 , " \n " , jcr -> getJobType ( ) , jcr -> JobId , jcr -> sd_client ) ; if ( jcr -> is_JobType ( JT_BACKUP ) && jcr -> sd_client ) { jcr -> session_opened = true ; Dmsg0 ( 050 , " \n " ) ; if ( ! response ( jcr , jcr -> file_bsock , " \n " , " " ) ) { Dmsg1 ( 050 , " " , jcr -> file_bsock -> msg ) ; Jmsg0 ( jcr , M_FATAL , 0 , " \n " ) ; goto bail_out ; } append_data_cmd ( jcr ) ; append_end_session ( jcr ) ; } else if ( jcr -> is_JobType ( JT_MIGRATE ) || jcr -> is_JobType ( JT_COPY ) ) { jcr -> session_opened = true ; Dmsg0 ( 215 , " \n " ) ; jcr -> file_bsock -> fsend ( OK_data ) ; jcr -> is_ok_data_sent = true ; Dmsg1 ( 050 , " \n " , jcr -> file_bsock ) ; Dmsg0 ( 050 , " \n " ) ; if ( ! response ( jcr , jcr -> file_bsock , " \n " , " " ) ) { Dmsg1 ( 050 , " " , jcr -> file_bsock -> msg ) ; Jmsg0 ( jcr , M_FATAL , 0 , " \n " ) ; jcr -> file_bsock -> signal ( BNET_EOD ) ; goto bail_out ; } read_data_cmd ( jcr ) ; jcr -> file_bsock -> signal ( BNET_EOD ) ; } else { Dmsg0 ( 050 , " \n " ) ; do_client_commands ( jcr ) ; } bail_out : jcr -> end_time = time ( NULL ) ; flush_jobmedia_queue ( jcr ) ; dequeue_messages ( jcr ) ; jcr -> setJobStatus ( JS_Terminated ) ; generate_daemon_event ( jcr , " " ) ; generate_plugin_event ( jcr , bsdEventJobEnd ) ; bash_spaces ( jcr -> StatusErrMsg ) ; dir -> fsend ( Job_end , jcr -> Job , jcr -> JobStatus , jcr -> JobFiles , edit_uint64 ( jcr -> JobBytes , ec1 ) , jcr -> JobErrors , jcr -> StatusErrMsg ) ; Dmsg1 ( 100 , " " , dir -> msg ) ; unbash_spaces ( jcr -> StatusErrMsg ) ; dequeue_daemon_messages ( jcr ) ; dir -> signal ( BNET_EOD ) ; free_plugins ( jcr ) ; garbage_collect_memory_pool ( ) ; return ; }
Run a Client Job -- Client already authorized
  Note: this can be either a backup or restore or
    migrate/copy job.
Run a Client Job -- Client already authorized Note : this can be either a backup or restore or migrate / copy job .
/* TODO: Remove when the new match_all is well tested */ /*
    * A migrate or copy job does both a restore (read_data) and
    *   a backup (append_data).
    * Otherwise we do the commands that the client sends
    *   which are for normal backup or restore jobs.
    */ /*
       * Send "3000 OK data" now to avoid a dead lock, the other side is also
       * waiting for one. The old code was reading the "3000 OK" reply
       * at the end of the backup (not really appropriate).
       * dedup needs duplex communication with the other side and needs the
       * "3000 OK" to be read, which is handled here by the code below.
       */ /* Either a Backup or Restore job */ /* send any queued messages */ /* send EOD to Director daemon */ /* release instantiated plugins */