Exemplo n.º 1
0
/* Shrink a clients cache by an amount of pages */
int dm_mem_cache_shrink(struct dm_mem_cache_client *cl, unsigned objects)
{
	int r;
	unsigned pages = objects * cl->chunks * cl->pages_per_chunk, p = pages;
	unsigned long flags;
	struct page_list *last = NULL, *pl, *pos;

	BUG_ON(!pages);

	spin_lock_irqsave(&cl->lock, flags);
	pl = pos = cl->free_list;
	while (p-- && pos->next) {
		last = pos;
		pos = pos->next;
	}

	if (++p)
		r = -ENOMEM;
	else {
		r = 0;
		cl->free_list = pos;
		cl->free_pages -= pages;
		cl->total_pages -= pages;
		cl->objects -= objects;
		last->next = NULL;
	}
	spin_unlock_irqrestore(&cl->lock, flags);

	if (!r) {
		free_cache_pages(pl);
		mempool_resize(cl->objs_pool, cl->objects, GFP_NOIO);
	}

	return r;
}
Exemplo n.º 2
0
/*
 * Grow a clients cache by an amount of pages.
 *
 * Don't call from interrupt context!
 */
int dm_mem_cache_grow(struct dm_mem_cache_client *cl, unsigned objects)
{
	unsigned pages = objects * cl->chunks * cl->pages_per_chunk;
	struct page_list *pl, *last;

	BUG_ON(!pages);
	pl = alloc_cache_pages(pages);
	if (!pl)
		return -ENOMEM;

	last = pl;
	while (last->next)
		last = last->next;

	spin_lock_irq(&cl->lock);
	last->next = cl->free_list;
	cl->free_list = pl;
	cl->free_pages += pages;
	cl->total_pages += pages;
	cl->objects += objects;
	spin_unlock_irq(&cl->lock);

	mempool_resize(cl->objs_pool, cl->objects, GFP_NOIO);
	return 0;
}
Exemplo n.º 3
0
static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act)
{
    if (zfcp_erp_adapter_strat_fsf_xconf(act) == ZFCP_ERP_FAILED)
        return ZFCP_ERP_FAILED;

    if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED)
        return ZFCP_ERP_FAILED;

    if (mempool_resize(act->adapter->pool.sr_data,
                       act->adapter->stat_read_buf_num, GFP_KERNEL))
        return ZFCP_ERP_FAILED;

    if (mempool_resize(act->adapter->pool.status_read_req,
                       act->adapter->stat_read_buf_num, GFP_KERNEL))
        return ZFCP_ERP_FAILED;

    atomic_set(&act->adapter->stat_miss, act->adapter->stat_read_buf_num);
    if (zfcp_status_read_refill(act->adapter))
        return ZFCP_ERP_FAILED;

    return ZFCP_ERP_SUCCEEDED;
}
Exemplo n.º 4
0
void p_string_append_len(T S, const char *s, size_t l)
{
	if ((S->used + l) > S->len) {
		size_t oldsize = SIZE(S);
		S->len += l;
		S->str = mempool_resize(S->pool, S->str, oldsize, SIZE(S));
		assert(S->str);
	}
	char *dest = S->str;
	dest += S->used;
	memcpy(dest, s, l);
	S->used += l;
	S->str[S->used] = '\0';
}
Exemplo n.º 5
0
T p_string_assign(T S, const char *s)
{
	size_t oldsize, newsize;
	size_t l = strlen(s);
	S->used = 0;
	memset(S->str, 0, SIZE(S));
	oldsize = SIZE(S);
	newsize = (sizeof(char) * (l + 1));
	if (newsize > oldsize) {
		S->len = l;
		S->str = mempool_resize(S->pool, S->str, oldsize, SIZE(S));
	}
	memset(S->str, 0, SIZE(S));
	memcpy(S->str, s, l);
	S->used = l;
	return S;
}
Exemplo n.º 6
0
static inline void append(T S, const char *s, va_list ap)
{
	va_list ap_copy;
	size_t oldsize;

	while (true) {
		va_copy(ap_copy, ap);
		int n = vsnprintf((char *)(S->str + S->used), S->len - S->used, s, ap_copy);
		va_end(ap_copy);
		if ((S->used + n) < S->len) {
			S->used += n;
			break;
		}
		oldsize = SIZE(S);
		S->len += STRLEN + n;
		S->str = mempool_resize(S->pool, S->str, oldsize, SIZE(S));
	}
}
Exemplo n.º 7
0
static int resize_pool(unsigned int new_ios)
{
	int r = 0;

	if (_io_pool) {
		if (new_ios == 0) {
			/* free off the pool */
			mempool_destroy(_io_pool);
			_io_pool = NULL;
			bioset_free(_bios);
			_bios = NULL;

		} else {
			/* resize the pool */
			r = mempool_resize(_io_pool, new_ios, GFP_KERNEL);
		}

	} else {
		/* create new pool */
		_io_pool = mempool_create(new_ios, alloc_io, free_io, NULL);
		if (!_io_pool)
			return -ENOMEM;

		_bios = bioset_create(16, 16, 4);
		if (!_bios) {
			mempool_destroy(_io_pool);
			_io_pool = NULL;
			return -ENOMEM;
		}
	}

	if (!r)
		_num_ios = new_ios;

	return r;
}
Exemplo n.º 8
0
Arquivo: dm-io.c Projeto: 710leo/LVS
int dm_io_client_resize(unsigned num_pages, struct dm_io_client *client)
{
	return mempool_resize(client->pool, pages_to_ios(num_pages),
			      GFP_KERNEL);
}