Exemple #1
0
// set up the AG
// return a client on success
// return NULL on error
struct AG_state* AG_init( int argc, char** argv ) {
   
   int rc = 0;
   struct UG_state* ug = NULL;
   struct AG_state* ag = NULL;
   struct md_opts* overrides = md_opts_new( 1 );
   
   if( overrides == NULL ) {
      return NULL;
   }

   md_opts_default( overrides );
   md_opts_set_client( overrides, false );
   md_opts_set_gateway_type( overrides, SYNDICATE_AG );
   md_opts_set_driver_config( overrides, AG_DEFAULT_DRIVER_EXEC_STR, AG_DRIVER_ROLES, AG_DRIVER_NUM_ROLES );

   ag = SG_CALLOC( struct AG_state, 1 );
   if( ag == NULL ) {
      // OOM 
      md_opts_free( overrides );
      SG_safe_free( overrides );
      return NULL;
   }

   // create UG core
   ug = UG_init_ex( argc, argv, overrides, ag );

   md_opts_free( overrides );
   SG_safe_free( overrides );

   if( ug == NULL ) {
      SG_error("%s", "UG_init failed\n");
      SG_safe_free( ag );
      return NULL;
   }

   ag->ug_core = ug;

   rc = pthread_rwlock_init( &ag->lock, NULL );
   if( rc != 0 ) {
      SG_error("pthread_rwlock_init rc = %d\n", rc );
      UG_shutdown( ug );
      SG_safe_free( ag );
      return NULL;
   }

   // add AG server-side behaviors
   AG_server_install_methods( AG_state_gateway( ag ) ); 

   return ag;
}
Exemple #2
0
int main( int argc, char** argv ) {
   
   int rc = 0;
   struct syndicate_state state;
   struct md_opts opts;
   struct UG_opts ug_opts;
   int local_optind = 0;
   uint64_t volume_id = 0;
   ms_path_t path;
   struct ms_client_multi_result result;
   
   md_opts_default( &opts );
   
   // get options
   rc = md_opts_parse( &opts, argc, argv, &local_optind, NULL, NULL );
   if( rc != 0 ) {
      SG_error("md_opts_parse rc = %d\n", rc );
      md_common_usage( argv[0] );
      exit(1);
   }
   
   memset( &ug_opts, 0, sizeof(struct UG_opts) );
   
   // connect to syndicate
   rc = syndicate_client_init( &state, &opts, &ug_opts );
   if( rc != 0 ) {
      SG_error("syndicate_client_init rc = %d\n", rc );
      exit(1);
   }
   
   // get volume ID
   volume_id = ms_client_get_volume_id( state.ms );
   
   
   printf("\n\n\nBegin getattr multi\n\n\n");
   
   // get each path and file ID
   for( int i = local_optind; i < argc; i++ ) {
      
      struct ms_path_ent path_ent;
      uint64_t file_id = 0;
         
      // file ID 
      rc = sscanf( argv[i], "%" PRIX64, &file_id );
      if( rc != 1 ) {
         SG_error("failed to parse file_id ID '%s'\n", argv[i] );
         exit(1);
      }
      
      printf("   getattr(%" PRIX64 ")\n", file_id );
      ms_client_make_path_ent( &path_ent, volume_id, 0, file_id, 0, 0, 0, 0, NULL, NULL );
      path.push_back( path_ent );
   }
   
   printf("\n\n\n");
   
   // get all 
   rc = ms_client_getattr_multi( state.ms, &path, &result );
   
   if( rc != 0 ) {
      SG_error("ms_client_getattr_multi rc = %d\n", rc );
      exit(1);
   }
   
   printf("\n\n\n");
   
   for( unsigned int i = 0; i < result.num_ents; i++ ) {
      
      if( result.ents[i].file_id != 0 ) {
         printf("Entry: %" PRIX64 " %s mode=%o version=%" PRId64 " write_nonce=%" PRId64 " generation=%d\n",
                result.ents[i].file_id, result.ents[i].name, result.ents[i].mode, result.ents[i].version, result.ents[i].write_nonce, result.ents[i].generation );
      }
   }
   
   ms_client_multi_result_free( &result );
   
   printf("\n\n\nEnd getattr multi\n\n\n");
   
   syndicate_client_shutdown( &state, 0 );
   
   return 0;
}