Beispiel #1
0
int main(int argc, char *argv[]) {
  int           idx=1;
  uuid_t        fid;
  char        * pFid=NULL;
  char        * pRoot=NULL;
  int           ret;
  int           slice;
  int           devices;
  rozofs_stor_bins_file_hdr_vall_t hdr;
  char          path[256];
  int           spare;
  int           block_per_chunk;
  int           chunk;
  int           chunk_stop;

  /*
  ** read common config file
  */
  common_config_read(NULL); 
  
  
  // Get utility name
  utility_name = basename(argv[0]); 
  
  if (argc < 3) usage(); 

  idx = 1;
  while (idx < argc) {

    /* -h */
    if (strcmp(argv[idx], "-h") == 0) usage();
    
    /* -d */
    if (strcmp(argv[idx], "-d") == 0) {
      idx++;
      dump_data = 1;
      continue;
    }
    
    /* -f */
    if (strcmp(argv[idx], "-f") == 0) {
      idx++;
      if (idx == argc) {
        printf("%s option set but missing value !!!\n", argv[idx-1]);
        usage();
      } 
      pFid = argv[idx];
      ret = rozofs_uuid_parse( pFid, fid);
      if (ret != 0) {
        printf("%s is not a FID !!!\n", pFid);
        usage();
      }  
      idx++;
      continue;    
    }

    /* -p */
    if (strcmp(argv[idx], "-p") == 0) {
      idx++;
      if (idx == argc) {
        printf("%s option set but missing value !!!\n", argv[idx-1]);
        usage();
      } 
      pRoot = argv[idx];
      struct statfs st;
      if (statfs(pRoot, &st) != 0) {
        printf("%s is not a directory !!!\n", pRoot);
        usage();
      }
      idx++;
      continue;    
    }
    
    /* -a */
    if (strcmp(argv[idx], "-a") == 0) {
      idx++;
      if (idx == argc) {
        printf("%s option set but missing value !!!\n", argv[idx-1]);
        usage();
      } 
      ret = sscanf(argv[idx], "%u", &prjid);
      if (ret != 1) {
        printf("Bad projection identifier %s !!!\n",argv[idx]);
	usage();
      }
      idx++;
      continue;
    }
            
    /* -b */
    if (strcmp(argv[idx], "-b") == 0) {
      display_blocks = 1;
      idx++;
      if (idx == argc) {
        continue;
      } 
      
      ret = sscanf(argv[idx], "%llu:%llu", (long long unsigned int *)&first, (long long unsigned int *)&last);
      if (ret == 2) {
        if (first>last) {
	  printf("first block index %llu must be lower than last block index %llu !!!\n", (long long unsigned int)first, (long long unsigned int)last);
	  usage();
	}
        idx++;
	continue;
      }
      
      ret = sscanf(argv[idx], ":%llu", (long long unsigned int *)&last);
      if (ret == 1) {
        first = 0;
        idx++;
	continue;
      }
            
      ret = sscanf(argv[idx], "%llu", (long long unsigned int *)&first);
      if (ret == 1) {
        if (argv[idx][strlen(argv[idx])-1]==':') {
          last = -1;
	}
	else {
	  last = first;
	}  
        idx++;
	continue;
      }
   
      continue;
    }
    
    printf("No such option or parameter %s\n",argv[idx]);
    usage();
  }
  
  if ((pFid == NULL)||(pRoot == NULL)) {
    printf("Missing mandatory parameters !!!\n");
    usage();
  }

  rozofs_layout_initialize();
  
  /*
  ** Compute the FID slice
  */
  slice = rozofs_storage_fid_slice(fid);
  
  /*
  ** Get the number of devices
  */
  devices = rozofs_storage_get_device_number(pRoot);
  
  /*
  ** Find out a header file
  */
  if (read_hdr_file(pRoot,devices, slice, &hdr, fid, &spare)!= 0) {
    printf("No header file found for %s under %s !!!\n",pFid,pRoot);
    return -1;
  }
  
  block_per_chunk = ROZOFS_STORAGE_NB_BLOCK_PER_CHUNK(hdr.v0.bsize);
   
  
  if (first == 0) {
    chunk = 0;
  }
  else {
    chunk = first / block_per_chunk;
  }  
  
  if (last == -1) {
    chunk_stop = ROZOFS_STORAGE_MAX_CHUNK_PER_FILE+1;
  }
  else {
    chunk_stop = (last / block_per_chunk)+1;
  }  
     
  while(chunk<chunk_stop) {
    int dev;
    
    dev = rozofs_st_header_get_chunk(&hdr, chunk);
      
    if (dev == ROZOFS_EOF_CHUNK) {
      printf ("\n============ CHUNK %d EOF   ================\n", chunk);      
      break;
    }
    if (dev == ROZOFS_EMPTY_CHUNK) {
      printf ("\n============ CHUNK %d EMPTY ================\n", chunk);
      chunk++;
      continue;
    }
    
    storage_build_chunk_full_path(path, pRoot, dev, spare, slice, fid, chunk);
    printf ("\n============ CHUNK %d ==  %s ================\n", chunk, path);
    
    if (display_blocks) {
      read_chunk_file(fid,path,&hdr,spare, chunk*block_per_chunk);
    }  
    chunk++;
  }
  return 0;
}
Beispiel #2
0
int main(int argc, char *argv[]) {
    int c;
    
    static struct option long_options[] = {
        { "help", no_argument, 0, 'h'},
        { "file", required_argument, 0, 'f'},	
        { "layout", required_argument, 0, 'l'},	
        { "bsize", required_argument, 0, 'b'},	
        { "chunk", required_argument, 0, 'c'},	
        { "blockNumber", required_argument, 0, 'n'},	
        { 0, 0, 0, 0}
    };

    // Get utility name
    utility_name = basename(argv[0]);   

    rozofs_layout_initialize();
   
    while (1) {

        int option_index = 0;
        c = getopt_long(argc, argv, "hH:f:l:b:c:n:", long_options, &option_index);

        if (c == -1)
            break;

        switch (c) {

            case 'h':
                usage();
                exit(EXIT_SUCCESS);
                break;
                break;
            case 'f':
	        filename[nb_file++] = optarg;
                break;	
            case 'l':
	        {
		  int ret;
                  ret = sscanf(optarg,"%d", &layout);
                  if (ret <= 0) { 
                      fprintf(stderr, "dataReader failed. Bad layout: %s %s\n", optarg,
                              strerror(errno));
                      exit(EXIT_FAILURE);
                  }
		}
		break;
            case 'c':
	        {
		  int ret;
                  ret = sscanf(optarg,"%d", &firstBlock);
                  if (ret <= 0) { 
                      fprintf(stderr, "dataReader failed. Bad chunk number: %s %s\n", optarg,
                              strerror(errno));
                      exit(EXIT_FAILURE);
                  }
		}
		break;		
            case 'n':
	        {
		  int ret;
                  ret = sscanf(optarg,"%d", &block_number);
                  if (ret < 0) { 
                      fprintf(stderr, "dataReader failed. Bad block number: %s %s\n", optarg,
                              strerror(errno));
                      exit(EXIT_FAILURE);
                  }
		}	
		break;	
            case 'b':
	        {
		  int ret;
                  ret = sscanf(optarg,"%d", &bsize);
                  if (ret < 0) { 
                      fprintf(stderr, "dataReader failed. Bad block size: %s %s\n", optarg,
                              strerror(errno));
                      exit(EXIT_FAILURE);
                  }
		}	
		break;				
	    case '?':
                usage();
                exit(EXIT_SUCCESS);
                break;
            default:
                usage();
                exit(EXIT_FAILURE);
                break;
        }
    }
    openlog("dataReader", LOG_PID, LOG_DAEMON);
    
    
    /*
    ** Check parameter consistency
    */
    if (nb_file == 0){
        fprintf(stderr, "dataReader failed. Missing --file option.\n");
        exit(EXIT_FAILURE);
    }  
 
    bbytes = ROZOFS_BSIZE_BYTES(bsize);
    if (bbytes < 0) {
        fprintf(stderr, "bad block size: %d\n", bsize);
        exit(EXIT_FAILURE);
    }
    firstBlock *= ROZOFS_STORAGE_NB_BLOCK_PER_CHUNK(bsize);

    // Start rebuild storage   
    if (read_data_file() != 0) goto error;
    exit(EXIT_SUCCESS);
    
error:
    exit(EXIT_FAILURE);
}