Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / drivers / md / dm-memcache.h
1 /*
2  * Copyright (C) 2006-2008 Red Hat, Inc. All rights reserved.
3  *
4  * Module Author: Heinz Mauelshagen <Mauelshagen@RedHat.com>
5  *
6  * Device-mapper memory object handling:
7  *
8  * o allocate/free total_pages in a per client page pool.
9  *
10  * o allocate/free memory objects with chunks (1..n) of
11  *   pages_per_chunk pages hanging off.
12  *
13  * This file is released under the GPL.
14  */
15
16 #ifndef _DM_MEM_CACHE_H
17 #define _DM_MEM_CACHE_H
18
19 #define DM_MEM_CACHE_H_VERSION  "0.1"
20
21 #include "dm.h"
22 #include <linux/dm-io.h>
23
24 static inline struct page_list *pl_elem(struct page_list *pl, unsigned p)
25 {
26         while (pl && p--)
27                 pl = pl->next;
28
29         return pl;
30 }
31
32 struct dm_mem_cache_object {
33         struct page_list *pl; /* Dynamically allocated array */
34         void *private;        /* Caller context reference */
35 };
36
37 struct dm_mem_cache_client;
38
39 /*
40  * Create/destroy dm memory cache client resources.
41  *
42  * On creation, a number of @objects with @chunks of
43  * @pages_per_chunk pages will be allocated.
44  */
45 struct dm_mem_cache_client *
46 dm_mem_cache_client_create(unsigned objects, unsigned chunks,
47                            unsigned pages_per_chunk);
48 void dm_mem_cache_client_destroy(struct dm_mem_cache_client *client);
49
50 /*
51  * Grow/shrink a dm memory cache client resources
52  * by @objetcs amount of objects.
53  */
54 int dm_mem_cache_grow(struct dm_mem_cache_client *client, unsigned objects);
55 int dm_mem_cache_shrink(struct dm_mem_cache_client *client, unsigned objects);
56
57 /*
58  * Allocate/free a memory object
59  *
60  * On allocation one object with an amount of chunks and
61  * an amount of pages per chunk will be returned on success.
62  */
63 struct dm_mem_cache_object *
64 dm_mem_cache_alloc(struct dm_mem_cache_client *client);
65 void dm_mem_cache_free(struct dm_mem_cache_client *client,
66                        struct dm_mem_cache_object *object);
67
68 #endif