コード例 #1
0
ファイル: syndicate-vacuum.cpp プロジェクト: iychoi/syndicate
// entry point 
int main( int argc, char** argv ) {
   
   int rc = 0;
   struct UG_state* ug = NULL;
   struct SG_gateway* gateway = NULL;
   char* path = NULL;
   int path_optind = 0;
   struct tool_opts opts;
   struct UG_vacuum_context* vctx = NULL;
   
   memset( &opts, 0, sizeof(tool_opts) );
   
   rc = parse_args( argc, argv, &opts );
   if( rc != 0 ) {
      
      usage( argv[0], "file [file...]" );
      md_common_usage();
      exit(1);
   }
   
   // setup...
   ug = UG_init( argc, argv, opts.anonymous );
   if( ug == NULL ) {
      
      SG_error("%s", "UG_init failed\n" );
      exit(1);
   }
   
   gateway = UG_state_gateway( ug );
   
   // get the directory path 
   path_optind = SG_gateway_first_arg_optind( gateway );
   if( path_optind == argc ) {
      
      usage( argv[0], "file [file...]" );
      md_common_usage();
      UG_shutdown( ug );
      exit(1);
   }
   
   for( int i = path_optind; i < argc; i++ ) {
            
        path = argv[ i ];
        rc = UG_vacuum_begin( ug, path, &vctx );
        if( rc != 0 ) {
           fprintf(stderr, "Failed to vacuum '%s': %s\n", path, strerror(abs(rc)) );
           continue;
        }

        printf("Vacuuming %s\n", path );

        UG_vacuum_wait( vctx );
   }

   UG_shutdown( ug );
   exit(0);
}
コード例 #2
0
ファイル: syndicate-mkdir.cpp プロジェクト: iychoi/syndicate
// entry point 
int main( int argc, char** argv ) {
   
   int rc = 0;
   struct UG_state* ug = NULL;
   struct SG_gateway* gateway = NULL;
   char* path = NULL;
   int path_optind = 0;
   mode_t um = umask(0);
   umask( um );
   
   struct tool_opts opts;
   
   memset( &opts, 0, sizeof(tool_opts) );
   
   rc = parse_args( argc, argv, &opts );
   if( rc != 0 ) {
      
      usage( argv[0], "dir [dir...]" );
      md_common_usage();
      exit(1);
   }
   
   // setup...
   ug = UG_init( argc, argv, opts.anonymous );
   if( ug == NULL ) {
      
      SG_error("%s", "UG_init failed\n" );
      exit(1);
   }
   
   gateway = UG_state_gateway( ug );
   
   // get the directory path 
   path_optind = SG_gateway_first_arg_optind( gateway );
   if( path_optind == argc ) {
      
      usage( argv[0], "dir [dir...]" );
      UG_shutdown( ug );
      exit(1);
   }
   
   for( int i = path_optind; i < argc; i++ ) {
        
       path = argv[ i ];
        
       // try to mkdir 
       rc = UG_mkdir( ug, path, um & 0777 );
       if( rc != 0 ) {
            
          fprintf(stderr, "Failed to mkdir '%s': %s\n", path, strerror( abs(rc) ) );
       }
   }
   
   UG_shutdown( ug );
   exit(rc);
}
コード例 #3
0
/**
 * @brief syndicate-unlink entry point
 *
 */
int main( int argc, char** argv ) {
   
   int rc = 0;
   struct UG_state* ug = NULL;
   struct SG_gateway* gateway = NULL;
   char* path = NULL;
   int path_optind = 0;
   
   struct tool_opts opts;
   
   memset( &opts, 0, sizeof(tool_opts) );
   
   argc = parse_args( argc, argv, &opts );
   if( argc < 0 ) {
      
      usage( argv[0], "file [file...]" );
      md_common_usage();
      exit(1);
   }
   
   // setup...
   ug = UG_init( argc, argv );
   if( ug == NULL ) {
      
      SG_error("%s", "UG_init failed\n" );
      exit(1);
   }
   
   gateway = UG_state_gateway( ug );
   
   // get the directory path 
   path_optind = SG_gateway_first_arg_optind( gateway );
   if( path_optind == argc ) {
      
      usage( argv[0], "file [file...]" );
      UG_shutdown( ug );
      exit(1);
   }
   
   for( int i = path_optind; i < argc; i++ ) {
        
        path = argv[ i ];
        
        // try to unlink
        SG_debug("unlink '%s'\n", path);
        rc = UG_unlink( ug, path );
        if( rc != 0 ) {
            
            fprintf(stderr, "Failed to unlink '%s': %s\n", path, strerror( abs(rc) ) );
        }
   }
   
   UG_shutdown( ug );
   exit(rc);
}
コード例 #4
0
ファイル: syndicate-trunc.cpp プロジェクト: iychoi/syndicate
// entry point 
int main( int argc, char** argv ) {
   
   int rc = 0;
   struct UG_state* ug = NULL;
   struct SG_gateway* gateway = NULL;
   char* path = NULL;
   char* tmp = NULL;
   int64_t size = 0;
   int path_optind = 0;
   
   struct tool_opts opts;
   
   memset( &opts, 0, sizeof(tool_opts) );
   
   rc = parse_args( argc, argv, &opts );
   if( rc != 0 ) {
      
      usage( argv[0], "file size [file size...]" );
      md_common_usage();
      exit(1);
   }
   
   // setup...
   ug = UG_init( argc, argv, opts.anonymous );
   if( ug == NULL ) {
      
      SG_error("%s", "UG_init failed\n" );
      exit(1);
   }
   
   gateway = UG_state_gateway( ug );
   
   // get the directory path 
   path_optind = SG_gateway_first_arg_optind( gateway );
   if( path_optind == argc || (argc - path_optind) % 2 != 0 ) {
      
      usage( argv[0], "file size [file size...]" );
      UG_shutdown( ug );
      exit(1);
   }
   
   for( int i = path_optind; i < argc; i+=2 ) {
        
        path = argv[ i ];
        size = (int64_t)strtoll(argv[ i+1 ], &tmp, 10);
        
        if( tmp == argv[i+1] || size < 0 ) {
           fprintf(stderr, "'%s' could not be parsed to a positive integer\n", argv[i+1]);
           usage(argv[0], "file size [file size...]");
           UG_shutdown(ug);
           exit(1);
        }
        
        // try to truncate
        rc = UG_truncate( ug, path, size );
        if( rc != 0 ) {
            
            fprintf(stderr, "Failed to trucate '%s' to %" PRIu64 " bytes: %s\n", path, size, strerror( abs(rc) ) );
        }
   }
   
   UG_shutdown( ug );
   exit(rc);
}
コード例 #5
0
/**
 * @brief syndicate-removexattr entry point
 *
 */
int main( int argc, char** argv ) {
   
   int rc = 0;
   struct UG_state* ug = NULL;
   struct SG_gateway* gateway = NULL;
   char* path = NULL;
   char* xattr = NULL;
   int path_optind = 0;
   struct tool_opts opts;
  
   uint64_t* times = NULL; 
   struct timespec ts_begin;
   struct timespec ts_end;
   
   memset( &opts, 0, sizeof(tool_opts) );
   
   argc = parse_args( argc, argv, &opts );
   if( argc < 0 ) {
      
      usage( argv[0], "path xattr [xattr...]" );
      md_common_usage();
      exit(1);
   }
   
   // setup...
   ug = UG_init( argc, argv );
   if( ug == NULL ) {
      
      SG_error("%s", "UG_init failed\n" );
      exit(1);
   }
   
   gateway = UG_state_gateway( ug );
   
   // get the directory path 
   path_optind = SG_gateway_first_arg_optind( gateway );
   if( path_optind + 1 >= argc ) {
      
      usage( argv[0], "path xattr [xattr...]" );
      md_common_usage();
      UG_shutdown( ug );
      exit(1);
   }
   
   if( opts.benchmark ) {
      times = SG_CALLOC( uint64_t, argc - path_optind + 1 );
      if( times == NULL ) {
          UG_shutdown( ug );
          SG_error("%s", "Out of memory\n");
          exit(1);
      }
   }

   path = argv[path_optind];

   for( int i = path_optind + 1; i < argc; i++ ) {
            
        xattr = argv[ i ];

        // load up...
        clock_gettime( CLOCK_MONOTONIC, &ts_begin );

        rc = UG_removexattr( ug, path, xattr );
        if( rc < 0 ) {
           fprintf(stderr, "Failed to removexattr '%s' '%s': %s\n", path, xattr, strerror(abs(rc)) );
           rc = 1;
           break;
        }

        clock_gettime( CLOCK_MONOTONIC, &ts_end );

        if( times != NULL ) {
            times[i - path_optind] = md_timespec_diff( &ts_end, &ts_begin );
        }
   }

   if( times != NULL ) {
    
      printf("@@@@@");
      for( int i = path_optind; i < argc - 1; i++ ) {
         printf("%" PRIu64 ",", times[i - path_optind] );
      }
      printf("%" PRIu64 "@@@@@\n", times[argc - 1 - path_optind] );

      SG_safe_free( times );
   }

   UG_shutdown( ug );
   exit(rc);
}
コード例 #6
0
/**
 * @brief syndicate-get entry point
 *
 */
int main( int argc, char** argv ) {

   int rc = 0;
   struct UG_state* ug = NULL;
   struct SG_gateway* gateway = NULL;
   char* path = NULL;
   int path_optind = 0;
   char* file_path = NULL;
   int fd = 0;
   char* buf = NULL;
   ssize_t nr = 0;
   ssize_t total = 0;
   UG_handle_t* fh = NULL;

   int t = 0;
   struct timespec ts_begin;
   struct timespec ts_end;
   int64_t* times = NULL;

   mode_t um = umask(0);
   umask( um );

   struct tool_opts opts;

   memset( &opts, 0, sizeof(tool_opts) );

   argc = parse_args( argc, argv, &opts );
   if( argc < 0 ) {

      usage( argv[0], "syndicate_file local_file [syndicate_file local_file...]" );
      md_common_usage();
      exit(1);
   }

   // setup...
   ug = UG_init( argc, argv );
   if( ug == NULL ) {

      SG_error("%s", "UG_init failed\n" );
      exit(1);
   }

   gateway = UG_state_gateway( ug );

   // get the path...
   path_optind = SG_gateway_first_arg_optind( gateway );
   if( path_optind == argc || ((argc - path_optind) % 2) != 0 ) {

      usage( argv[0], "syndicate_file local_file [syndicate_file local_file]" );
      UG_shutdown( ug );
      exit(1);
   }

   if( opts.benchmark ) {
      times = SG_CALLOC( int64_t, (argc - path_optind) / 2 + 1 );
      if( times == NULL ) {
          UG_shutdown( ug );
          SG_error("%s", "Out of memory\n");
          exit(1);
      }
   }

   buf = SG_CALLOC( char, BUF_SIZE );
   if( buf == NULL ) {
      UG_shutdown( ug );
      SG_error("%s", "Out of memory\n");
      exit(1);
   }

   for( int i = path_optind; i < argc; i += 2 ) {

       total = 0;

       // get the syndicate path...
       path = argv[i];

       // get the file path...
       file_path = argv[i+1];

       // open the file...
       fd = open( file_path, O_CREAT | O_EXCL | O_WRONLY, 0600 );
       if( fd < 0 ) {
          rc = -errno;
          fprintf(stderr, "Failed to open '%s': %s\n", file_path, strerror(-rc));
          rc = 1;
          goto get_end;
       }

       // try to open
       fh = UG_open( ug, path, O_RDONLY, &rc );
       if( rc != 0 ) {
          fprintf(stderr, "Failed to open '%s': %d %s\n", path, rc, strerror( abs(rc) ) );
          rc = 1;
          goto get_end;
       }

       clock_gettime( CLOCK_MONOTONIC, &ts_begin );
       while( 1 ) {
          nr = UG_read( ug, buf, BUF_SIZE, fh );
          if( nr == 0 ) {
             break;
          }
          if( nr < 0 ) {
            rc = nr;
            fprintf(stderr, "Failed to read '%s': %s\n", path, strerror(abs(rc)));
            break;
          }

          rc = write( fd, buf, nr );
          if( rc < 0 ) {
             rc = -errno;
             fprintf(stderr, "Failed to write '%s': %d %s\n", file_path, rc, strerror(abs(rc)));
             break;
          }

          total += nr;
       }

       close( fd );

       if( rc < 0 ) {
          rc = 1;
          goto get_end;
       }

       clock_gettime( CLOCK_MONOTONIC, &ts_end );

       // close
       rc = UG_close( ug, fh );
       if( rc != 0 ) {
          fprintf(stderr, "Failed to close '%s': %d %s\n", path, rc, strerror( abs(rc) ) );
          rc = 1;
          goto get_end;
       }

       if( times != NULL ) {
          printf("\n%ld.%ld - %ld.%ld = %ld\n", ts_end.tv_sec, ts_end.tv_nsec, ts_begin.tv_sec, ts_begin.tv_nsec, md_timespec_diff_ms( &ts_end, &ts_begin ));
          times[t] = md_timespec_diff_ms( &ts_end, &ts_begin );
          t++;
       }

       SG_debug("Read %zd bytes for %s\n", total, path );
   }

get_end:

   UG_shutdown( ug );
   SG_safe_free( buf );

   if( times != NULL ) {

      printf("@@@@@");
      for( int i = 0; i < t - 1; i++ ) {
         printf("%" PRId64 ",", times[i] );
      }
      printf("%" PRId64 "@@@@@\n", times[t-1] );

      SG_safe_free( times );
   }

   if( rc != 0 ) {
      exit(1);
   }
   else {
      exit(0);
   }
}
コード例 #7
0
ファイル: listdir.cpp プロジェクト: iychoi/syndicate
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 parent_id = 0;
   ms_path_t path;
   struct ms_client_multi_result result;
   vector<uint64_t> file_ids;
   
   if( argc < 3 ) {
      usage( argv[0] );
      exit(1);
   }
   
   memset( &result, 0, sizeof(struct ms_client_multi_result) );
   
   memset( &opts, 0, sizeof(struct md_opts) );
   
   memset( &ug_opts, 0, sizeof(struct UG_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] );
      usage( argv[0] );
      exit(1);
   }
   
   // 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 parent id and parse it
   rc = sscanf( argv[local_optind], "%" PRIX64, &parent_id );
   if( rc != 1 ) {
      SG_error("failed to parse parent ID '%s'\n", argv[local_optind] );
      exit(1);
   }
   
   printf("\n\n\nBegin listdir\n\n\n");
   
   rc = ms_client_listdir( state.ms, parent_id, 100, 100, &result );
      
   if( rc != 0 ) {
      SG_error("ms_client_listdir rc = %d\n", rc );
      exit(1);
   }
   
   printf("\n\n\n");
      
   for( size_t 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 listdir\n\n\n");
   
   syndicate_client_shutdown( &state, 0 );
   
   return 0;
}
コード例 #8
0
ファイル: syndicate-rename.cpp プロジェクト: iychoi/syndicate
// entry point 
int main( int argc, char** argv ) {
   
   int rc = 0;
   struct UG_state* ug = NULL;
   struct SG_gateway* gateway = NULL;
   char* src_path = NULL;
   int path_optind = 0;
   char* dest_path = NULL;

   mode_t um = umask(0);
   umask( um );
   
   struct tool_opts opts;
   
   memset( &opts, 0, sizeof(tool_opts) );
   
   rc = parse_args( argc, argv, &opts );
   if( rc != 0 ) {
      
      usage( argv[0], "src_file dest_file" );
      md_common_usage();
      exit(1);
   }
   
   // setup...
   ug = UG_init( argc, argv, opts.anonymous );
   if( ug == NULL ) {
      
      SG_error("%s", "UG_init failed\n" );
      exit(1);
   }
   
   gateway = UG_state_gateway( ug );
   
   // get the path...
   path_optind = SG_gateway_first_arg_optind( gateway );
   if( path_optind == argc ) {
      
      usage( argv[0], "src_file dest_file" );
      UG_shutdown( ug );
      exit(1);
   }
  
   // get the src path...
   src_path = argv[ path_optind ];
    
   // get the dest path...
   path_optind++;
   dest_path = argv[path_optind];

   // do the rename 
   rc = UG_rename( ug, src_path, dest_path );
   if( rc != 0 ) {
     SG_error("UG_rename(%s, %s) rc = %d\n", src_path, dest_path, rc );
   } 
   
   UG_shutdown( ug );

   if( rc != 0 ) {
      exit(1);
   }
   else {
      exit(0);
   }
}
コード例 #9
0
ファイル: getattr.cpp プロジェクト: etherparty/syndicate
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;
}
コード例 #10
0
ファイル: syndicate-coord.cpp プロジェクト: iychoi/syndicate
// entry point 
int main( int argc, char** argv ) {
   
   int rc = 0;
   struct UG_state* ug = NULL;
   struct SG_gateway* gateway = NULL;
   int path_optind = 0;
   struct tool_opts opts;
   struct md_entry ent_data;
   char* path = NULL;
   uint64_t new_coord = 0;
   
   memset( &opts, 0, sizeof(tool_opts) );
   
   rc = parse_args( argc, argv, &opts );
   if( rc != 0 ) {
      
      usage( argv[0], "file [file...]" );
      md_common_usage();
      exit(1);
   }
   
   // setup...
   ug = UG_init( argc, argv, opts.anonymous );
   if( ug == NULL ) {
      
      SG_error("%s", "UG_init failed\n" );
      exit(1);
   }
   
   gateway = UG_state_gateway( ug );
   
   // get the list of files to coordinate 
   path_optind = SG_gateway_first_arg_optind( gateway );
   if( path_optind == argc ) {
      
      usage( argv[0], "file [file...]" );
      md_common_usage();
      UG_shutdown( ug );
      exit(1);
   }
   
   for( int i = path_optind; i < argc; i++ ) {

      path = argv[i];

      // make sure this is a file...
      rc = UG_stat_raw( ug, path, &ent_data );
      if( rc != 0 ) {
         SG_error("UG_stat_raw('%s') rc = %d\n", path, rc );
         rc = 1;
         goto UG_coord_shutdown;
      }

      if( ent_data.type != MD_ENTRY_FILE ) {
         fprintf(stderr, "Not a file: %s\n", path );
         rc = 1;
         goto UG_coord_shutdown;
      }

      // if we're not the coordinator, become it 
      if( ent_data.coordinator != SG_gateway_id( gateway ) ) {

         SG_debug("Become the coordinator of '%s'\n", path );
         rc = UG_chcoord( ug, path, &new_coord );
         if( rc != 0 ) {
            fprintf(stderr, "chcoord '%s': %s\n", path, strerror(-rc) );
            rc = 1;
            goto UG_coord_shutdown;
         }
      }

      md_entry_free( &ent_data );
   }

   // proceed to handle requests
   SG_debug("%s", "Proceed to handle requests\n");

   rc = UG_main( ug );
   if( rc != 0 ) {
      fprintf(stderr, "UG_main: %s\n", strerror(-rc) );
      rc = 1;
   }

UG_coord_shutdown:
   UG_shutdown( ug );
   exit(rc);
}