Example #1
0
/**
* Parse and display a RozoFS FID
*/
void uma_dbg_split_fid(char * argv[], uint32_t tcpRef, void *bufRef) {
  char *pChar = uma_dbg_get_buffer();

  if (argv[1] == NULL) {
    rozofs_string_append(pChar, "Missing FID parameter");   	      
  }  
  else {
    uuid_t fid;
    if (rozofs_uuid_parse(argv[1], fid)<0) {
      *pChar ++ = '"';
      pChar += rozofs_string_append(pChar, argv[1]);   	
      *pChar ++ =  '"';                   
      rozofs_string_append(pChar, " is not a FID");   	          
    }
    else {
      pChar = fid2string(fid,pChar);
      pChar += rozofs_eol(pChar);   	
    }  
  }  
  uma_dbg_send(tcpRef, bufRef, TRUE, uma_dbg_get_buffer());   	  
}
Example #2
0
int rozofs_parse_object_name(char *name,mattr_obj_t *attr_p)
{
  int ret;
  int layout;
  int eid;
  int cid;
  int sid;
  int i;
  int nb_sid;
  uint64_t size;
  char *pnext;
  char *cur = name;
  int len;
  
  memset(attr_p,0,sizeof(mattr_obj_t));
  len = strlen(name);

  while(1)
  {
    /*
    ** get the eid
    */
    errno = 0;
    eid = strtoul(name,&pnext,10);
    if (eid == ULONG_MAX) break;
    if (errno != 0) break;
    if (*pnext !='-') 
    {
      errno = EINVAL;
      break;
    }
    /*
    ** get the cid
    */
    errno = 0;
    cur = pnext+1;
    cid = strtoul(cur,&pnext,10);
    if (errno != 0) 
    {
       break;
    }
    if (*pnext !='-') 
    {
      errno = EINVAL;
      break;
    }
    attr_p->cid = cid;
    /*
    ** get the layout
    */
    errno = 0;
    cur = pnext+1;
    layout = strtoul(cur,&pnext,10);
    if (errno != 0) 
    {
       break;
    }
    if (*pnext !='-') 
    {
      errno = EINVAL;
      break;
    }
    /*
    ** get the distribution: remenber that the number
    ** of sid depends on the layout
    */
    nb_sid = rozofs_get_safe(layout);
    if (nb_sid < 0)
    {
      errno = EINVAL;
      break;
    }
    for (i = 0; i < nb_sid; i++)
    {
      errno = 0;
      cur = pnext+1;
      sid = strtoull(cur,&pnext,10);
      if (errno != 0) 
      {
	 break;
      }
      if (*pnext !='-') 
      {
	errno = EINVAL;
	break;
      } 
      attr_p->sids[i] = (uint8_t)sid;        
    }
    if (errno!= 0) break;
    /*
    ** get the fid
    */
    cur = pnext+1;
    if (pnext[37] != '-')
    {
      errno = EINVAL;
      break;    
    }
    pnext[37]=0;
    ret = rozofs_uuid_parse(cur,attr_p->fid);
    if (ret < 0)
    {
      errno = EINVAL;
    } 
    pnext+=37;
    /*
    ** get the size
    */
    errno = 0;
    cur = pnext+1;
    size = strtoull(cur,&pnext,10);
    if (errno != 0) 
    {
       break;
    }
    attr_p->size = size;
    break;
  }
  if (errno!=0) 
  {
    return -1;
  }
  if ((pnext-name) != len)
  {
     errno = EINVAL;
    return -1;
  }  
  return 0;

}
Example #3
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;
}