Source
5
5
*/
6
6
7
7
#ifndef DM_CACHE_POLICY_INTERNAL_H
8
8
#define DM_CACHE_POLICY_INTERNAL_H
9
9
10
10
#include <linux/vmalloc.h>
11
11
#include "dm-cache-policy.h"
12
12
13
13
/*----------------------------------------------------------------*/
14
14
15
-
/*
16
-
* Little inline functions that simplify calling the policy methods.
17
-
*/
18
-
static inline int policy_map(struct dm_cache_policy *p, dm_oblock_t oblock,
19
-
bool can_block, bool can_migrate, bool discarded_oblock,
20
-
struct bio *bio, struct policy_locker *locker,
21
-
struct policy_result *result)
15
+
static inline int policy_lookup(struct dm_cache_policy *p, dm_oblock_t oblock, dm_cblock_t *cblock,
16
+
int data_dir, bool fast_copy, bool *background_queued)
22
17
{
23
-
return p->map(p, oblock, can_block, can_migrate, discarded_oblock, bio, locker, result);
18
+
return p->lookup(p, oblock, cblock, data_dir, fast_copy, background_queued);
24
19
}
25
20
26
-
static inline int policy_lookup(struct dm_cache_policy *p, dm_oblock_t oblock, dm_cblock_t *cblock)
21
+
static inline int policy_lookup_with_work(struct dm_cache_policy *p,
22
+
dm_oblock_t oblock, dm_cblock_t *cblock,
23
+
int data_dir, bool fast_copy,
24
+
struct policy_work **work)
27
25
{
28
-
BUG_ON(!p->lookup);
29
-
return p->lookup(p, oblock, cblock);
30
-
}
26
+
if (!p->lookup_with_work) {
27
+
*work = NULL;
28
+
return p->lookup(p, oblock, cblock, data_dir, fast_copy, NULL);
29
+
}
31
30
32
-
static inline void policy_set_dirty(struct dm_cache_policy *p, dm_oblock_t oblock)
33
-
{
34
-
if (p->set_dirty)
35
-
p->set_dirty(p, oblock);
31
+
return p->lookup_with_work(p, oblock, cblock, data_dir, fast_copy, work);
36
32
}
37
33
38
-
static inline void policy_clear_dirty(struct dm_cache_policy *p, dm_oblock_t oblock)
34
+
static inline int policy_get_background_work(struct dm_cache_policy *p,
35
+
bool idle, struct policy_work **result)
39
36
{
40
-
if (p->clear_dirty)
41
-
p->clear_dirty(p, oblock);
37
+
return p->get_background_work(p, idle, result);
42
38
}
43
39
44
-
static inline int policy_load_mapping(struct dm_cache_policy *p,
45
-
dm_oblock_t oblock, dm_cblock_t cblock,
46
-
uint32_t hint, bool hint_valid)
40
+
static inline void policy_complete_background_work(struct dm_cache_policy *p,
41
+
struct policy_work *work,
42
+
bool success)
47
43
{
48
-
return p->load_mapping(p, oblock, cblock, hint, hint_valid);
44
+
return p->complete_background_work(p, work, success);
49
45
}
50
46
51
-
static inline uint32_t policy_get_hint(struct dm_cache_policy *p,
52
-
dm_cblock_t cblock)
47
+
static inline void policy_set_dirty(struct dm_cache_policy *p, dm_cblock_t cblock)
53
48
{
54
-
return p->get_hint ? p->get_hint(p, cblock) : 0;
49
+
p->set_dirty(p, cblock);
55
50
}
56
51
57
-
static inline int policy_writeback_work(struct dm_cache_policy *p,
58
-
dm_oblock_t *oblock,
59
-
dm_cblock_t *cblock,
60
-
bool critical_only)
52
+
static inline void policy_clear_dirty(struct dm_cache_policy *p, dm_cblock_t cblock)
61
53
{
62
-
return p->writeback_work ? p->writeback_work(p, oblock, cblock, critical_only) : -ENOENT;
54
+
p->clear_dirty(p, cblock);
63
55
}
64
56
65
-
static inline void policy_remove_mapping(struct dm_cache_policy *p, dm_oblock_t oblock)
57
+
static inline int policy_load_mapping(struct dm_cache_policy *p,
58
+
dm_oblock_t oblock, dm_cblock_t cblock,
59
+
bool dirty, uint32_t hint, bool hint_valid)
66
60
{
67
-
p->remove_mapping(p, oblock);
61
+
return p->load_mapping(p, oblock, cblock, dirty, hint, hint_valid);
68
62
}
69
63
70
-
static inline int policy_remove_cblock(struct dm_cache_policy *p, dm_cblock_t cblock)
64
+
static inline int policy_invalidate_mapping(struct dm_cache_policy *p,
65
+
dm_cblock_t cblock)
71
66
{
72
-
return p->remove_cblock(p, cblock);
67
+
return p->invalidate_mapping(p, cblock);
73
68
}
74
69
75
-
static inline void policy_force_mapping(struct dm_cache_policy *p,
76
-
dm_oblock_t current_oblock, dm_oblock_t new_oblock)
70
+
static inline uint32_t policy_get_hint(struct dm_cache_policy *p,
71
+
dm_cblock_t cblock)
77
72
{
78
-
return p->force_mapping(p, current_oblock, new_oblock);
73
+
return p->get_hint ? p->get_hint(p, cblock) : 0;
79
74
}
80
75
81
76
static inline dm_cblock_t policy_residency(struct dm_cache_policy *p)
82
77
{
83
78
return p->residency(p);
84
79
}
85
80
86
81
static inline void policy_tick(struct dm_cache_policy *p, bool can_block)
87
82
{
88
83
if (p->tick)
100
95
*sz_ptr = sz;
101
96
return 0;
102
97
}
103
98
104
99
static inline int policy_set_config_value(struct dm_cache_policy *p,
105
100
const char *key, const char *value)
106
101
{
107
102
return p->set_config_value ? p->set_config_value(p, key, value) : -EINVAL;
108
103
}
109
104
105
+
static inline void policy_allow_migrations(struct dm_cache_policy *p, bool allow)
106
+
{
107
+
return p->allow_migrations(p, allow);
108
+
}
109
+
110
110
/*----------------------------------------------------------------*/
111
111
112
112
/*
113
113
* Some utility functions commonly used by policies and the core target.
114
114
*/
115
115
static inline size_t bitset_size_in_bytes(unsigned nr_entries)
116
116
{
117
117
return sizeof(unsigned long) * dm_div_up(nr_entries, BITS_PER_LONG);
118
118
}
119
119