dm cache: pass a new 'critical' flag to the policies when requesting writeback work
[pandora-kernel.git] / drivers / md / dm-cache-policy-internal.h
1 /*
2  * Copyright (C) 2012 Red Hat. All rights reserved.
3  *
4  * This file is released under the GPL.
5  */
6
7 #ifndef DM_CACHE_POLICY_INTERNAL_H
8 #define DM_CACHE_POLICY_INTERNAL_H
9
10 #include "dm-cache-policy.h"
11
12 /*----------------------------------------------------------------*/
13
14 /*
15  * Little inline functions that simplify calling the policy methods.
16  */
17 static inline int policy_map(struct dm_cache_policy *p, dm_oblock_t oblock,
18                              bool can_block, bool can_migrate, bool discarded_oblock,
19                              struct bio *bio, struct policy_locker *locker,
20                              struct policy_result *result)
21 {
22         return p->map(p, oblock, can_block, can_migrate, discarded_oblock, bio, locker, result);
23 }
24
25 static inline int policy_lookup(struct dm_cache_policy *p, dm_oblock_t oblock, dm_cblock_t *cblock)
26 {
27         BUG_ON(!p->lookup);
28         return p->lookup(p, oblock, cblock);
29 }
30
31 static inline void policy_set_dirty(struct dm_cache_policy *p, dm_oblock_t oblock)
32 {
33         if (p->set_dirty)
34                 p->set_dirty(p, oblock);
35 }
36
37 static inline void policy_clear_dirty(struct dm_cache_policy *p, dm_oblock_t oblock)
38 {
39         if (p->clear_dirty)
40                 p->clear_dirty(p, oblock);
41 }
42
43 static inline int policy_load_mapping(struct dm_cache_policy *p,
44                                       dm_oblock_t oblock, dm_cblock_t cblock,
45                                       uint32_t hint, bool hint_valid)
46 {
47         return p->load_mapping(p, oblock, cblock, hint, hint_valid);
48 }
49
50 static inline int policy_walk_mappings(struct dm_cache_policy *p,
51                                       policy_walk_fn fn, void *context)
52 {
53         return p->walk_mappings ? p->walk_mappings(p, fn, context) : 0;
54 }
55
56 static inline int policy_writeback_work(struct dm_cache_policy *p,
57                                         dm_oblock_t *oblock,
58                                         dm_cblock_t *cblock,
59                                         bool critical_only)
60 {
61         return p->writeback_work ? p->writeback_work(p, oblock, cblock, critical_only) : -ENOENT;
62 }
63
64 static inline void policy_remove_mapping(struct dm_cache_policy *p, dm_oblock_t oblock)
65 {
66         p->remove_mapping(p, oblock);
67 }
68
69 static inline int policy_remove_cblock(struct dm_cache_policy *p, dm_cblock_t cblock)
70 {
71         return p->remove_cblock(p, cblock);
72 }
73
74 static inline void policy_force_mapping(struct dm_cache_policy *p,
75                                         dm_oblock_t current_oblock, dm_oblock_t new_oblock)
76 {
77         return p->force_mapping(p, current_oblock, new_oblock);
78 }
79
80 static inline dm_cblock_t policy_residency(struct dm_cache_policy *p)
81 {
82         return p->residency(p);
83 }
84
85 static inline void policy_tick(struct dm_cache_policy *p)
86 {
87         if (p->tick)
88                 return p->tick(p);
89 }
90
91 static inline int policy_emit_config_values(struct dm_cache_policy *p, char *result, unsigned maxlen)
92 {
93         ssize_t sz = 0;
94         if (p->emit_config_values)
95                 return p->emit_config_values(p, result, maxlen);
96
97         DMEMIT("0");
98         return 0;
99 }
100
101 static inline int policy_set_config_value(struct dm_cache_policy *p,
102                                           const char *key, const char *value)
103 {
104         return p->set_config_value ? p->set_config_value(p, key, value) : -EINVAL;
105 }
106
107 /*----------------------------------------------------------------*/
108
109 /*
110  * Creates a new cache policy given a policy name, a cache size, an origin size and the block size.
111  */
112 struct dm_cache_policy *dm_cache_policy_create(const char *name, dm_cblock_t cache_size,
113                                                sector_t origin_size, sector_t block_size);
114
115 /*
116  * Destroys the policy.  This drops references to the policy module as well
117  * as calling it's destroy method.  So always use this rather than calling
118  * the policy->destroy method directly.
119  */
120 void dm_cache_policy_destroy(struct dm_cache_policy *p);
121
122 /*
123  * In case we've forgotten.
124  */
125 const char *dm_cache_policy_get_name(struct dm_cache_policy *p);
126
127 const unsigned *dm_cache_policy_get_version(struct dm_cache_policy *p);
128
129 size_t dm_cache_policy_get_hint_size(struct dm_cache_policy *p);
130
131 /*----------------------------------------------------------------*/
132
133 #endif /* DM_CACHE_POLICY_INTERNAL_H */