コード例 #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;
}
コード例 #2
0
int export_load_rmfentry(export_t * e) 
{
   int ret=0;
   int user_id;
   uint64_t count = 0;
   uint64_t file_id;
   rozofs_inode_t inode;
   int i;
   rmfentry_disk_t trash_entry;
   exp_trck_top_header_t *tracking_trash_p; 
   exp_trck_header_memory_t *slice_hdr_p;
   exp_trck_file_header_t tracking_buffer;
   rmfentry_t *rmfe;   
   time_t      when = time(NULL)+common_config.deletion_delay;   
   /*
   ** get the pointer to the tracking context associated with the 
   ** export
   */
   tracking_trash_p = e->trk_tb_p->tracking_table[ROZOFS_TRASH];   
   /*
   ** go through all the slices of the export check for all the file
   ** that are under deletion 
   ** The slices correspond to the case of the trash only
   */ 
   for (user_id = 0; user_id < EXP_TRCK_MAX_USER_ID; user_id++)
   {
     inode.s.usr_id = user_id;
     file_id = 0;
    
     /*
     ** read the main tracking file of each slices: the main tracking file contains the 
     ** first and list index of individual tracking file that contains the information
     ** relative to the file to delete. There are a maximum of 2044 files per tracking
     * file
     */
     slice_hdr_p = tracking_trash_p->entry_p[user_id];
     for (file_id = slice_hdr_p->entry.first_idx; file_id <= slice_hdr_p->entry.last_idx; file_id++)
     {
       ret = exp_metadata_get_tracking_file_header(tracking_trash_p,user_id,file_id,&tracking_buffer,NULL);
       if (ret < 0)
       {
	 if (errno != ENOENT)
	 {
            severe("error while main tracking file header of slice %d %s\n",user_id,strerror(errno));
	    continue;
	 }
	 ret = 0;
	 continue;
       }
       /*
       ** get the current count within the tracking file
       */
       {
          while(loop_fdl)
	  {
	     sleep(5);
	     severe("FDL bug wait for gdb");
	  }
       }
       count +=exp_metadata_get_tracking_file_count(&tracking_buffer);
       inode.s.file_id = file_id;

       for (i = 0; i < EXP_TRCK_MAX_INODE_PER_FILE; i++)
       {
          inode.s.idx = i;
	  if (tracking_buffer.inode_idx_table[i] == 0xffff) continue;
	  ret = exp_metadata_read_attributes(tracking_trash_p,&inode,&trash_entry,sizeof(trash_entry));
	  if (ret < 0)
	  {
	    severe("error while reading attributes at idx %d for trash slice %d in file %llu: %s\n",
	            inode.s.idx,inode.s.usr_id,
	            (long long unsigned int)inode.s.file_id,
		    strerror(errno));
		    continue;
	  }
	  /*
	  ** allocate memory for the file to delete
	  */
            for(;;)
	    {
              rmfe = xmalloc(sizeof (rmfentry_t));
	      if (rmfe == NULL)
	      {
		 /*
		 ** out of memory: just wait for a while and then retry
		 */
		 sleep(2);
	      }
	      break;
	    }
#if 0
	    {
	       char buf_fid[64];
	       rozofs_uuid_unparse(trash_entry.fid,buf_fid);
	       severe("FDL slice %u file %llu index %d  trash fid %s ",user_id,file_id,i, buf_fid);
	    }
#endif
            memcpy(rmfe->fid, trash_entry.fid, sizeof (fid_t));
            rmfe->cid = trash_entry.cid;
            memcpy(rmfe->initial_dist_set, trash_entry.initial_dist_set,
                    sizeof (sid_t) * ROZOFS_SAFE_MAX);
            memcpy(rmfe->current_dist_set, trash_entry.current_dist_set,
                    sizeof (sid_t) * ROZOFS_SAFE_MAX);
            memcpy(rmfe->trash_inode,trash_entry.trash_inode,sizeof(fid_t));
            list_init(&rmfe->list);
	    rmfe->time = when;
	    /*
	    **  Compute hash value for this fid
	    */
            uint32_t hash = rozofs_storage_fid_slice(trash_entry.fid);
	  
            /* Acquire lock on bucket trash list
	    */
            if ((errno = pthread_rwlock_wrlock
                    (&e->trash_buckets[hash].rm_lock)) != 0) {
                severe("pthread_rwlock_wrlock failed: %s", strerror(errno));
                // Best effort
            }
            /*
	    ** Check size of file : TODO: cannot be done here since the 
	    ** file size is not save on disk
	    */
            if (trash_entry.size >= RM_FILE_SIZE_TRESHOLD) {
                // Add to front of list
                list_push_front(&e->trash_buckets[hash].rmfiles, &rmfe->list);
            } else {
                // Add to back of list
                list_push_back(&e->trash_buckets[hash].rmfiles, &rmfe->list);
            }
            export_rm_bins_reload_count++;
            if ((errno = pthread_rwlock_unlock
                    (&e->trash_buckets[hash].rm_lock)) != 0) {
                severe("pthread_rwlock_unlock failed: %s", strerror(errno));
                // Best effort
            }
       }
       /*
       ** try the next
       */
     }   
   }
   return ret;
}