static void iostash_exit(void)
{
	DBG("++ iostash_exit() ++\n");
	_free_resource();
	_destroy_iostash_kobjects();
	DBG("-- iostash_exit() ++\n");
}
Esempio n. 2
0
/*
	decrement the reference count of a resource.
	remove the resource entry if the reference count
	reaches zero.
*/
F8RES_API __bool unload_resource(
	const f8_uuid * id
	)
{
	RESMAP::iterator it;
	F8_RESOURCE * res;

	it = g_Resources.find(*id);
	if(it == g_Resources.end()){
		return __false;
	}
	res = &it->second;
	assert(res->refcount > 0);
	res->refcount--;
	
	if(0 == res->refcount){
		/* garbage collection */
		if(res->delProc){
			res->delProc(id);
		}
		_free_resource(res);
		g_Resources.erase(it);
	}
	
	return __true;
}
static int __init iostash_init(void)
{
    int ret = -1, i;

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
	ERR("Kernel version < 2.6.28 not supported.");
	return -ENOENT;
#endif
	DBG("++ iostash_init() ++\n");

	memset(&gctx, 0, sizeof(gctx));
	do {
		gctx.io_pool = KMEM_CACHE(iostash_bio, 0);
		if (!gctx.io_pool) {
			ERR("iostash_init: KMEM_CACHE() failed\n");
			break;
		}

		gctx.io_client = dm_io_client_create();
		if (IS_ERR(gctx.io_client)) {
			ERR("iostash_init: dm_io_client() failed\n");
			break;
		}

		gctx.sce = sce_create();
		if (!gctx.sce) {
			ERR("iostash_init: sce_create() failed\n");
			break;
		}

		gctx.pdm = pdm_create(gctx.sce, poptask_read, poptask_write);

		if (_init_iostash_kobjects()) {
		    ERR("KOBJECT INIT FAILED!");
		    _destroy_iostash_kobjects();
		}

		mutex_init(&gctx.ctl_mtx);

		for (i = 0; i < IOSTASH_MAXHDD_BCKTS; ++i)
		    INIT_LIST_HEAD(&gctx.hddtbl.bucket[i]);

		for (i = 0; i < IOSTASH_MAXSSD_BCKTS; ++i)
		    INIT_LIST_HEAD(&gctx.ssdtbl.bucket[i]);

		ret = 0;

	} while (0);

	if (ret) {
		_free_resource();
	}

	DBG("-- iostash_init() returns = %d --\n", ret);
	return ret;
}
Esempio n. 4
0
/*
	remove all entries from resource database.
*/
F8RES_API void reset_resources()
{	
	F8_RESOURCE * res;
	RESMAP::iterator it;
	it = g_Resources.begin();
	while(it != g_Resources.end()){
		res = &it->second;
		_free_resource(res);
		it++;
	}
	g_Resources.clear();
}
Esempio n. 5
0
/*
	move_resource
	will decrement usage count of the source resource,
	note this will not necessary cause the source resource
	to be deleted, only if its usage count reaches zero.
*/
F8RES_API int move_resource(
	const f8_uuid * s, 
	const f8_uuid * t
	)
{
	int r;
	F8_RESOURCE *tr, *sr;

	if(query_resource(t) >= 0){
		return F8_NAME_DUPLICATE;
	}
	sr = _get_res(s);
	if(!sr){
		return F8_OBJECT_NOT_FOUND;
	}
	if(!create_resource(t)){
		return F8_LOW_MEMORY;
	}
	if(sr->refcount == 1){
		/*
			a little optimization, if the reference count of source
			is 1, then no actual copy is made, instead, we move
			the contents of s to t, and detach s from its contents.
		*/
		tr = _get_res(t);
		delete tr->pItems;
		tr->pItems = _get_res(s)->pItems;
		sr->pItems = 0;
		_free_resource(sr);
		r = F8_SUCCESS;
	}else{
		r = copy_resource(s, t);
	}
	/*
	this will decrement the reference count, and remove the
	resource entry if necessary
	*/
	unload_resource(s);
	return r;
}