src/dird/ua_status.c
static int do_network_status(UAContext *ua)
{
   CLIENT *client = NULL;
   USTORE  store;
   JCR *jcr = ua->jcr;
   char *store_address, ed1[50];
   uint32_t store_port;
   uint64_t nb = 50 * 1024 * 1024;
   POOL_MEM buf;

   int i = find_arg_with_value(ua, "bytes");
   if (i > 0) {
      if (!size_to_uint64(ua->argv[i], strlen(ua->argv[i]), &nb)) {
         return 1;
      }
   }
   
   client = get_client_resource(ua, JT_BACKUP_RESTORE);
   if (!client) {
      return 1;
   }

   store.store = get_storage_resource(ua, false, true);
   if (!store.store) {
      return 1;
   }

   jcr->client = client;
   set_wstorage(jcr, &store);

   if (!ua->api) {
      ua->send_msg(_("Connecting to Storage %s at %s:%d\n"),
                   store.store->name(), store.store->address, store.store->SDport);
   }

   if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
      ua->error_msg(_("Failed to connect to Storage.\n"));
      goto bail_out;
   }

   if (!start_storage_daemon_job(jcr, NULL, NULL)) {
      goto bail_out;
   }

   /*
    * Note startup sequence of SD/FD is different depending on
    *  whether the SD listens (normal) or the SD calls the FD.
    */
   if (!client->sd_calls_client) {
      if (!run_storage_and_start_message_thread(jcr, jcr->store_bsock)) {
         goto bail_out;
      }
   } /* Else it's done in init_storage_job() */

   if (!ua->api) {
      ua->send_msg(_("Connecting to Client %s at %s:%d\n"),
                   client->name(), client->address(buf.addr()), client->FDport);
   }

   if (!connect_to_file_daemon(jcr, 1, 15, 0)) {
      ua->error_msg(_("Failed to connect to Client.\n"));
      goto bail_out;
   }

   if (jcr->sd_calls_client) {
      /*
       * SD must call "client" i.e. FD
       */
      if (jcr->FDVersion < 10) {
         Jmsg(jcr, M_FATAL, 0, _("The File daemon does not support SDCallsClient.\n"));
         goto bail_out;
      }
      if (!send_client_addr_to_sd(jcr)) {
         goto bail_out;
      }
      if (!run_storage_and_start_message_thread(jcr, jcr->store_bsock)) {
         goto bail_out;
      }

      store_address = store.store->address;  /* dummy */
      store_port = 0;                        /* flag that SD calls FD */

   } else {
      /*
       * send Storage daemon address to the File daemon,
       *   then wait for File daemon to make connection
       *   with Storage daemon.
       */
      if (store.store->SDDport == 0) {
         store.store->SDDport = store.store->SDport;
      }

      store_address = get_storage_address(jcr->client, store.store);
      store_port = store.store->SDDport;
   }

   if (!send_store_addr_to_fd(jcr, store.store, store_address, store_port)) {
      goto bail_out;
   }

   if (!ua->api) {
      ua->info_msg(_("Running network test between Client=%s and Storage=%s with %sB ...\n"),
                   client->name(), store.store->name(), edit_uint64_with_suffix(nb, ed1));
   }

   if (!jcr->file_bsock->fsend("testnetwork bytes=%lld\n", nb)) {
      goto bail_out;
   }

   while (jcr->file_bsock->recv() > 0) {
      ua->info_msg(jcr->file_bsock->msg);
   }
   
bail_out:
   if (jcr->file_bsock) {
      jcr->file_bsock->signal(BNET_TERMINATE);
   }
   if (jcr->store_bsock) {
      jcr->store_bsock->signal(BNET_TERMINATE);
   }
   wait_for_storage_daemon_termination(jcr);

   free_bsock(jcr->file_bsock);
   free_bsock(jcr->store_bsock);

   jcr->client = NULL;
   free_wstorage(jcr);
   return 1;
}
/* Test the network between FD and SD */
Test the network between FD and SD
Test the network between FD and SD
static int do_network_status(UAContext *ua)
{
   CLIENT *client = NULL;
   USTORE  store;
   JCR *jcr = ua->jcr;
   char *store_address, ed1[50];
   uint32_t store_port;
   uint64_t nb = 50 * 1024 * 1024;
   POOL_MEM buf;
   int i = find_arg_with_value(ua, "bytes");
   if (i > 0) {
      if (!size_to_uint64(ua->argv[i], strlen(ua->argv[i]), &nb)) {
         return 1;
      }
   }
   client = get_client_resource(ua, JT_BACKUP_RESTORE);
   if (!client) {
      return 1;
   }
   store.store = get_storage_resource(ua, false, true);
   if (!store.store) {
      return 1;
   }
   jcr->client = client;
   set_wstorage(jcr, &store);
   if (!ua->api) {
      ua->send_msg(_("Connecting to Storage %s at %s:%d\n"),
                   store.store->name(), store.store->address, store.store->SDport);
   }
   if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
      ua->error_msg(_("Failed to connect to Storage.\n"));
      goto bail_out;
   }
   if (!start_storage_daemon_job(jcr, NULL, NULL)) {
      goto bail_out;
   }
   if (!client->sd_calls_client) {
      if (!run_storage_and_start_message_thread(jcr, jcr->store_bsock)) {
         goto bail_out;
      }
   } 
   if (!ua->api) {
      ua->send_msg(_("Connecting to Client %s at %s:%d\n"),
                   client->name(), client->address(buf.addr()), client->FDport);
   }
   if (!connect_to_file_daemon(jcr, 1, 15, 0)) {
      ua->error_msg(_("Failed to connect to Client.\n"));
      goto bail_out;
   }
   if (jcr->sd_calls_client) {
      if (jcr->FDVersion < 10) {
         Jmsg(jcr, M_FATAL, 0, _("The File daemon does not support SDCallsClient.\n"));
         goto bail_out;
      }
      if (!send_client_addr_to_sd(jcr)) {
         goto bail_out;
      }
      if (!run_storage_and_start_message_thread(jcr, jcr->store_bsock)) {
         goto bail_out;
      }
      store_address = store.store->address;  
      store_port = 0;                        
   } else {
      if (store.store->SDDport == 0) {
         store.store->SDDport = store.store->SDport;
      }
      store_address = get_storage_address(jcr->client, store.store);
      store_port = store.store->SDDport;
   }
   if (!send_store_addr_to_fd(jcr, store.store, store_address, store_port)) {
      goto bail_out;
   }
   if (!ua->api) {
      ua->info_msg(_("Running network test between Client=%s and Storage=%s with %sB ...\n"),
                   client->name(), store.store->name(), edit_uint64_with_suffix(nb, ed1));
   }
   if (!jcr->file_bsock->fsend("testnetwork bytes=%lld\n", nb)) {
      goto bail_out;
   }
   while (jcr->file_bsock->recv() > 0) {
      ua->info_msg(jcr->file_bsock->msg);
   }
bail_out:
   if (jcr->file_bsock) {
      jcr->file_bsock->signal(BNET_TERMINATE);
   }
   if (jcr->store_bsock) {
      jcr->store_bsock->signal(BNET_TERMINATE);
   }
   wait_for_storage_daemon_termination(jcr);
   free_bsock(jcr->file_bsock);
   free_bsock(jcr->store_bsock);
   jcr->client = NULL;
   free_wstorage(jcr);
   return 1;
}
static int do_network_status ( UAContext * ua ) { CLIENT * client = NULL ; USTORE store ; JCR * jcr = ua -> jcr ; char * store_address , ed1 [ 50 ] ; uint32_t store_port ; uint64_t nb = 50 * 1024 * 1024 ; POOL_MEM buf ; int i = find_arg_with_value ( ua , " " ) ; if ( i > 0 ) { if ( ! size_to_uint64 ( ua -> argv [ i ] , strlen ( ua -> argv [ i ] ) , & nb ) ) { return 1 ; } } client = get_client_resource ( ua , JT_BACKUP_RESTORE ) ; if ( ! client ) { return 1 ; } store . store = get_storage_resource ( ua , false , true ) ; if ( ! store . store ) { return 1 ; } jcr -> client = client ; set_wstorage ( jcr , & store ) ; if ( ! ua -> api ) { ua -> send_msg ( _ ( " \n " ) , store . store -> name ( ) , store . store -> address , store . store -> SDport ) ; } if ( ! connect_to_storage_daemon ( jcr , 10 , SDConnectTimeout , 1 ) ) { ua -> error_msg ( _ ( " \n " ) ) ; goto bail_out ; } if ( ! start_storage_daemon_job ( jcr , NULL , NULL ) ) { goto bail_out ; } if ( ! client -> sd_calls_client ) { if ( ! run_storage_and_start_message_thread ( jcr , jcr -> store_bsock ) ) { goto bail_out ; } } if ( ! ua -> api ) { ua -> send_msg ( _ ( " \n " ) , client -> name ( ) , client -> address ( buf . addr ( ) ) , client -> FDport ) ; } if ( ! connect_to_file_daemon ( jcr , 1 , 15 , 0 ) ) { ua -> error_msg ( _ ( " \n " ) ) ; goto bail_out ; } if ( jcr -> sd_calls_client ) { if ( jcr -> FDVersion < 10 ) { Jmsg ( jcr , M_FATAL , 0 , _ ( " \n " ) ) ; goto bail_out ; } if ( ! send_client_addr_to_sd ( jcr ) ) { goto bail_out ; } if ( ! run_storage_and_start_message_thread ( jcr , jcr -> store_bsock ) ) { goto bail_out ; } store_address = store . store -> address ; store_port = 0 ; } else { if ( store . store -> SDDport == 0 ) { store . store -> SDDport = store . store -> SDport ; } store_address = get_storage_address ( jcr -> client , store . store ) ; store_port = store . store -> SDDport ; } if ( ! send_store_addr_to_fd ( jcr , store . store , store_address , store_port ) ) { goto bail_out ; } if ( ! ua -> api ) { ua -> info_msg ( _ ( " \n " ) , client -> name ( ) , store . store -> name ( ) , edit_uint64_with_suffix ( nb , ed1 ) ) ; } if ( ! jcr -> file_bsock -> fsend ( " \n " , nb ) ) { goto bail_out ; } while ( jcr -> file_bsock -> recv ( ) > 0 ) { ua -> info_msg ( jcr -> file_bsock -> msg ) ; } bail_out : if ( jcr -> file_bsock ) { jcr -> file_bsock -> signal ( BNET_TERMINATE ) ; } if ( jcr -> store_bsock ) { jcr -> store_bsock -> signal ( BNET_TERMINATE ) ; } wait_for_storage_daemon_termination ( jcr ) ; free_bsock ( jcr -> file_bsock ) ; free_bsock ( jcr -> store_bsock ) ; jcr -> client = NULL ; free_wstorage ( jcr ) ; return 1 ; }
Test the network between FD and SD
Test the network between FD and SD
/*
    * Note startup sequence of SD/FD is different depending on
    *  whether the SD listens (normal) or the SD calls the FD.
    */ /* Else it's done in init_storage_job() */ /*
       * SD must call "client" i.e. FD
       */ /* dummy */ /* flag that SD calls FD */ /*
       * send Storage daemon address to the File daemon,
       *   then wait for File daemon to make connection
       *   with Storage daemon.
       */