Exemplo n.º 1
0
int family_destroy(FAMILY_CTRL *fctrl){
    if(fctrl == NULL){
	  return 0;
    }

    int i = 0;
    for(i = g_list_length(fctrl->seg_storage_list)-1; i >= 0; i--){
        STORAGE_ITEM *storage_item = g_list_nth_data(fctrl->seg_storage_list,i);
	 deinit_storage_handler(storage_item->storage);
        g_free(storage_item);
    }
    g_list_free(fctrl->seg_storage_list);
    g_free(fctrl->father_uri);
    g_free(fctrl);
    return 0;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
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;   
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
0
/*
 * case1 teardown:
 * --close hlfs;
 * --deinit hlfs;
 * --free the structure case1_fixture;
 * --rm hlfs root directory;
 */
void case_teardown()
{
	deinit_storage_handler(fixture.storage);
}