Beispiel #1
0
int
hlfs_get_inode_info(const char *uri,
		uint64_t inode_addr,
		uint64_t *mtime,
		uint64_t *length) {
	int ret = 0;
	struct back_storage *storage = init_storage_handler(uri);
	if (NULL == uri) {
		HLOG_ERROR("init storage handler error!");
		ret = -1;
		goto out;
	}
	struct inode *inode = load_inode(storage, inode_addr);
	if (NULL == inode) {
		HLOG_ERROR("load inode error!");
		ret = -1;
		goto out;
	}
	*mtime = inode->mtime;
	*length = inode->length;
out:
	g_free(storage);
	g_free(inode);
	return ret;
}
Beispiel #2
0
/*  write trigger wb*/
void test_get_refer_inode()
{
	char *uri = "local:///tmp/testenv/testfs";
	struct back_storage *storage = init_storage_handler(uri);
	int ret = 0;
	uint32_t segment_size = 0;
	uint32_t block_size = 0;
	uint64_t max_fs_size = 0;
	uint32_t is_compress = 0;
	ret = read_fs_meta(storage, &segment_size, &block_size, &max_fs_size, \
			&is_compress);
	g_assert(ret == 0);
	GHashTable *ss_hashtable = \
				   g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
	ret = load_all_snapshot(storage, "snapshot.txt", ss_hashtable);
	printf("snapshot loaded\n"); 
	g_assert(ret == 0);
	GList *ss_list = NULL;
	ret = sort_all_snapshot(ss_hashtable, &ss_list);
	printf("snapshot sorted\n"); 
	g_assert(ss_list != NULL);
	g_assert(ret == 0);
	int i;
	for (i = 0;i < 9;i++) {
		struct inode *inode = NULL;
		char *up_sname;
		ret = get_refer_inode_between_snapshots(storage, i, ss_list, \
				&inode, &up_sname);
		printf("segno :%d ret:%d\n", i, ret);
	}
}
Beispiel #3
0
void case_setup()
{
	system("rm -rf /tmp/testenv");
	system("mkdir /tmp/testenv/testfs -p");
	//system("cd ../../../../ && ./output/bin/mkfs.hlfs -u local:///tmp/testenv/testfs -b 8192 -s 67108864 -m 1024 ");
	//system("cd -");
	char * uri = "local:///tmp/testenv/testfs";
    fixture.storage = init_storage_handler(uri);
    g_assert(NULL != fixture.storage);
}
Beispiel #4
0
/*  write trigger wb*/
void test_seg_usage_calc()
{
    char * uri = "local:///tmp/testenv/testfs";
    struct back_storage *storage = init_storage_handler(uri);
    uint32_t segment_size = 0;
    uint32_t block_size = 0;
    uint64_t max_fs_size = 0;
    int ret = read_fs_meta(storage,&segment_size, &block_size,&max_fs_size);
    g_assert(ret == 0);
    GHashTable   * ss_hashtable = g_hash_table_new_full(g_str_hash,g_str_equal,NULL,NULL);
    ret = load_all_snapshot(storage,"snapshot.txt",ss_hashtable);
    printf("snapshot loaded\n"); 
    g_assert(ret == 0);
    GList* ss_list = NULL;
    ret = sort_all_snapshot(ss_hashtable,&ss_list);
    printf("snapshot sorted\n"); 
    g_assert(ss_list !=NULL);
    g_assert(ret == 0);
    int i;
    for(i=13;i<17;i++){
        struct inode * inode=NULL;
        char *up_sname;
        ret = get_refer_inode_between_snapshots(storage,i,ss_list,&inode,&up_sname);
        printf("segno :%d ret:%d\n",i,ret);
        if(ret == 0){
           printf("seg is in snapshots\n");
           SEG_USAGE_T seg_usage;
           memset(&seg_usage,0,sizeof(SEG_USAGE_T));
           ret = seg_usage_calc(storage,block_size,i,inode,&seg_usage);
           g_assert(ret ==0);
           char textbuf[4096];
           memset(textbuf,4096,0);
           ret = seg_usage2text(&seg_usage,textbuf);
           g_assert(ret > 0);
           printf("textbuf is :%s\n",textbuf);
        }
        if(ret == 1){
           printf("seg is on snapshot,do nothing\n");
        }
        if(ret == 2){
           printf("seg is above snapshot,maybe need migrate\n");
        }
    }

}
static void 
hlfs_get_all_snapshots_tear_down(Fixture *fixture, const void *data) {
	const char *test_dir = (const char *) data;
	g_print("clean dir path: %s\n", test_dir);
	char *fs_dir = g_build_filename(test_dir, "testfs", NULL);
#if 0
	pid_t status;
	const char cmd[256];
	memset((char *) cmd, 0, 256);
	sprintf((char *) cmd, "%s %s %s", "rm", "-r", fs_dir);
	g_message("cmd is [%s]", cmd);
	status = system(cmd);

	struct back_storage *storage = init_storage_handler(fixture->uri);
	g_assert(storage != NULL);
	int nums = 0;
	bs_file_info_t *infos = storage->bs_file_list_dir(storage, ".", &nums);
	g_assert(infos != NULL);
	bs_file_info_t *info = infos;
	int i = 0;
	g_message("nums is %d", nums);
	for (i = 0; i < nums; i++) {
		g_message("info name is %s", info->name);
		char *tmp_file = g_build_filename(fs_dir, info->name, NULL);
		g_message("tmp file name is [%s]", tmp_file);
		g_assert(g_remove(tmp_file) == 0);
		g_free(tmp_file);
		info += 1;
	}
	//	char *sb_file = g_build_filename(fs_dir, "superblock", NULL);
	//	g_assert(g_remove(sb_file) == 0);
	g_assert(g_remove(fs_dir) == 0);
	g_free(fixture->uri);
	g_free(fs_dir);
	//	g_free(sb_file);
	g_free(storage);
	g_free(infos);
#endif
	g_free(fs_dir);
	g_free(fixture->uri);
	hlfs_close(fixture->ctrl);
	deinit_hlfs(fixture->ctrl);
	return;
}
Beispiel #6
0
int faimly_init(FAMILY_CTRL *fctrl,char* furi,uint64_t fbase_inode,uint32_t fsegno){
	int ret = 0;
	
	struct back_storage *storage =NULL;
	char *uri = furi;
	char * father_uri = NULL;
    uint64_t base_father_inode,max_fs_size;
    uint32_t from_segno,seg_size,block_size;
	STORAGE_ITEM *storage_item = NULL;
    from_segno = fsegno;
    do{
	   father_uri=NULL;
	   if(NULL == (storage = init_storage_handler(uri))){
	   	  HLOG_ERROR("fail to init storage for uri:%s",uri);
		  ret = -1;
	  	  goto out;;
	   }	
	   //g_tree_insert(fctrl->seg_storage_map,GINT_TO_POINTER((uint32_t)(segno-1),storage);
	   storage_item = g_malloc0(sizeof(STORAGE_ITEM));
	   storage_item->storage = storage;
	   storage_item->segno = from_segno -1;
	   HLOG_DEBUG("from_segno:%d\n",from_segno);
	   fctrl->seg_storage_list = g_list_append(fctrl->seg_storage_list,storage_item);
       if(0 !=(ret = read_fs_meta_all(storage,&seg_size,&block_size,&max_fs_size,
		   			            &father_uri,&base_father_inode,&from_segno))){
		  HLOG_ERROR("fail to read fs meta info");
		  ret = -1;
		  goto out;
       }
       if(father_uri!=NULL){
	   	  HLOG_DEBUG("need read uri:%s 's father uri:%s",uri,father_uri);
		  HLOG_DEBUG("from_segno:%d",from_segno);
		  uri = father_uri;
       }else{
          HLOG_DEBUG("need read uri:%s is first uri",uri);
		  break;
       }
	}while(1);
    fctrl->from_segno = fsegno;
    fctrl->father_uri = g_strdup(furi);
    fctrl->base_father_inode = fbase_inode;
out:
	return ret;
}
Beispiel #7
0
/*  mkfs_rmfs -u uri */
int main(int argc, char *argv[])
{
//	if (log4c_init()) {
//		g_message("log4c_init failed!");
//	}
	GError *error = NULL;
	GOptionContext *context;
	context = g_option_context_new("-hlfs rmfs");
	g_option_context_add_main_entries(context, entries, NULL);
	g_option_context_set_help_enabled(context, TRUE);
	g_option_group_set_error_hook(g_option_context_get_main_group(context),
			(GOptionErrorFunc)error_func);
	if (!g_option_context_parse(context, &argc, &argv, &error)) {
		g_message("option parsing failed: %s", error->message);
		exit(EXIT_FAILURE);
	}

	g_print("fs uri is :%s\n", uri);
	int ret = 0;
		
	struct back_storage *storage = init_storage_handler(uri);
	if (NULL == storage) {
		g_message("can not get storage handler for uri:%s", uri);
		ret = -1;
		goto out;
	}
    if (0 != hlfs_rmfs(storage)){
    	g_printf("Can not remove fs!\n");
    	ret = -1;
		goto out1;
    }

out1:
	deinit_storage_handler(storage);
out:
	g_free(uri);
	g_option_context_free(context);
//	if (log4c_fini()) {
//		g_message("log4c_fini failed!");
//	}
	return 0;
}
Beispiel #8
0
int hlfs_lstat(const char*uri,HLFS_STAT_T *stat){
	//HLOG_DEBUG("enter func %s", __func__);
    int ret = 0;
    if(NULL == uri|| NULL == stat){
	   HLOG_ERROR("param error");
          return -1; 
    }
    struct back_storage *storage = init_storage_handler(uri);
    if(storage == NULL){
       ret = -1;
       goto out;
    }
    uint32_t seg_size,block_size,last_segno,last_offset;
    uint64_t max_fs_size;
    ret = read_fs_meta(storage,&seg_size,&block_size,&max_fs_size);
    if(ret != 0){
         HLOG_ERROR("can not read fs meta data");
         goto out;
    }
    ret =get_cur_latest_segment_info(storage,&last_segno,&last_offset);
    if(ret !=0){
         HLOG_ERROR("can not read fs meta data");
         goto out;
    }
    stat->seg_size    = seg_size;
    stat->block_size  = block_size;
    stat->max_fs_size = max_fs_size;
    g_strlcpy(stat->fsname,g_basename(uri),MAX_FILE_NAME_LEN);
    stat->last_segno  = last_segno;
    stat->last_offset = last_offset;
out:
    if(storage!=NULL){
       deinit_storage_handler(storage);
    }
	//HLOG_DEBUG("leave func %s", __func__);
    return ret;   
}
Beispiel #9
0
/*  mkfs.lhfs -l http://<path>  -s name */
int main(int argc, char *argv[])
{
	if (log4c_init()) {
		g_message("log4c_init failed!");
	}
    GError *error = NULL;
    GOptionContext *context;
    context = g_option_context_new("- mkfs hlfs");
    g_option_context_add_main_entries(context, entries, NULL);
    g_option_context_set_help_enabled(context, TRUE);
    g_option_group_set_error_hook(g_option_context_get_main_group(context),
            					(GOptionErrorFunc)error_func);
    if (!g_option_context_parse(context, &argc, &argv, &error)) {
        g_message("option parsing failed: %s", error->message);
        exit(EXIT_FAILURE);
    }

    //g_print("location is :%s\n",location);
    //g_print("fsname   is :%s\n",fsname);
    //g_print("block size   is :%d\n",block_size);
    //g_print("segment size   is :%d\n",seg_size);

//  seg_size = SEGMENT_SIZE;
    if(seg_size <= 0 ||  seg_size%(1024*1024)!=0){
       g_message("segsize <=0 or segment size must 1M margin");
       return -1;
    }
    if(block_size <=0 || block_size%(512) != 0){
       g_message("blocksize <=0 or block size must 512 margin");
       return -1;
    }
    if(max_fs_size <=0){
       g_message("max fs size <=0");
       return -1;
    }
    struct back_storage *storage = init_storage_handler(uri);
    if(NULL ==storage){
       g_message("can not get storage handler for uri:%s",uri);
       g_option_context_free(context);
       return -1;
    }
    
    if((0==storage->bs_file_is_exist(storage,NULL)) && (0==storage->bs_file_is_exist(storage,"superblock"))){
        g_message("hlfs with uri:%s has exist",uri);
        g_option_context_free(context);
        return 1;
    }
    if( 0!=storage->bs_file_mkdir(storage,NULL)){
        g_message("can not mkdir for our fs %s",uri);
        g_option_context_free(context);
        return -1;
    }

    GKeyFile *sb_keyfile= g_key_file_new();
    g_key_file_set_string(sb_keyfile,"METADATA","uri",uri);
    g_key_file_set_integer(sb_keyfile,"METADATA","block_size",block_size);
    g_key_file_set_integer(sb_keyfile,"METADATA","segment_size",seg_size);
    g_key_file_set_uint64(sb_keyfile,"METADATA","max_fs_size",max_fs_size);
    gchar *data = g_key_file_to_data(sb_keyfile,NULL,NULL);
    g_message("key file data :%s",data);
    char *head,*hostname,*dir,*fs_name;
    int port;
    parse_from_uri(uri,&head,&hostname,&dir,&fs_name,&port);
    char *sb_file_path = g_build_filename(dir,fs_name,"superblock",NULL);
    g_message("sb file path %s",sb_file_path);
    bs_file_t file = storage->bs_file_create(storage,"superblock");
    g_message("sb file path 1%s",sb_file_path);
    //bs_file_t file = storage->bs_file_open(storage,"superblock",BS_WRITEABLE);
    if (NULL == file) {
       g_message("open file :superblock failed");
       g_free(sb_file_path);
       g_option_context_free(context);
       return -1;
    }

    g_message("sb file path 2%s",sb_file_path);
    int size = storage->bs_file_append(storage, file,(char*)data,strlen(data)+1);
    if(size != strlen(data)+1){
       g_message("can not write superblock file");
       g_free(sb_file_path);
       g_option_context_free(context);
       return -1;
    }
    g_message("append size:%d",size);
    storage->bs_file_flush(storage,file);
    storage->bs_file_close(storage,file);
    deinit_storage_handler(storage);
    if (log4c_fini()) {
	    g_message("log4c_fini failed!");
    }
    return 0;
}