1
2
3
4
5
6
7#ifndef DM_CACHE_METADATA_H
8#define DM_CACHE_METADATA_H
9
10#include "dm-cache-block-types.h"
11#include "dm-cache-policy-internal.h"
12#include "persistent-data/dm-space-map-metadata.h"
13
14
15
16#define DM_CACHE_METADATA_BLOCK_SIZE DM_SM_METADATA_BLOCK_SIZE
17
18
19
20
21
22#define DM_CACHE_METADATA_MAX_SECTORS DM_SM_METADATA_MAX_SECTORS
23
24
25
26
27#define DM_CACHE_METADATA_MAX_SECTORS_WARNING (16 * (1024 * 1024 * 1024 >> SECTOR_SHIFT))
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49#define DM_CACHE_FEATURE_COMPAT_SUPP 0UL
50#define DM_CACHE_FEATURE_COMPAT_RO_SUPP 0UL
51#define DM_CACHE_FEATURE_INCOMPAT_SUPP 0UL
52
53struct dm_cache_metadata;
54
55
56
57
58
59struct dm_cache_metadata *dm_cache_metadata_open(struct block_device *bdev,
60 sector_t data_block_size,
61 bool may_format_device,
62 size_t policy_hint_size,
63 unsigned metadata_version);
64
65void dm_cache_metadata_close(struct dm_cache_metadata *cmd);
66
67
68
69
70
71
72int dm_cache_resize(struct dm_cache_metadata *cmd, dm_cblock_t new_cache_size);
73int dm_cache_size(struct dm_cache_metadata *cmd, dm_cblock_t *result);
74
75int dm_cache_discard_bitset_resize(struct dm_cache_metadata *cmd,
76 sector_t discard_block_size,
77 dm_dblock_t new_nr_entries);
78
79typedef int (*load_discard_fn)(void *context, sector_t discard_block_size,
80 dm_dblock_t dblock, bool discarded);
81int dm_cache_load_discards(struct dm_cache_metadata *cmd,
82 load_discard_fn fn, void *context);
83
84int dm_cache_set_discard(struct dm_cache_metadata *cmd, dm_dblock_t dblock, bool discard);
85
86int dm_cache_remove_mapping(struct dm_cache_metadata *cmd, dm_cblock_t cblock);
87int dm_cache_insert_mapping(struct dm_cache_metadata *cmd, dm_cblock_t cblock, dm_oblock_t oblock);
88int dm_cache_changed_this_transaction(struct dm_cache_metadata *cmd);
89
90typedef int (*load_mapping_fn)(void *context, dm_oblock_t oblock,
91 dm_cblock_t cblock, bool dirty,
92 uint32_t hint, bool hint_valid);
93int dm_cache_load_mappings(struct dm_cache_metadata *cmd,
94 struct dm_cache_policy *policy,
95 load_mapping_fn fn,
96 void *context);
97
98int dm_cache_set_dirty_bits(struct dm_cache_metadata *cmd,
99 unsigned nr_bits, unsigned long *bits);
100
101struct dm_cache_statistics {
102 uint32_t read_hits;
103 uint32_t read_misses;
104 uint32_t write_hits;
105 uint32_t write_misses;
106};
107
108void dm_cache_metadata_get_stats(struct dm_cache_metadata *cmd,
109 struct dm_cache_statistics *stats);
110
111
112
113
114void dm_cache_metadata_set_stats(struct dm_cache_metadata *cmd,
115 struct dm_cache_statistics *stats);
116
117int dm_cache_commit(struct dm_cache_metadata *cmd, bool clean_shutdown);
118
119int dm_cache_get_free_metadata_block_count(struct dm_cache_metadata *cmd,
120 dm_block_t *result);
121
122int dm_cache_get_metadata_dev_size(struct dm_cache_metadata *cmd,
123 dm_block_t *result);
124
125void dm_cache_dump(struct dm_cache_metadata *cmd);
126
127
128
129
130
131
132
133
134
135
136
137
138int dm_cache_write_hints(struct dm_cache_metadata *cmd, struct dm_cache_policy *p);
139
140
141
142
143int dm_cache_metadata_all_clean(struct dm_cache_metadata *cmd, bool *result);
144
145int dm_cache_metadata_needs_check(struct dm_cache_metadata *cmd, bool *result);
146int dm_cache_metadata_set_needs_check(struct dm_cache_metadata *cmd);
147void dm_cache_metadata_set_read_only(struct dm_cache_metadata *cmd);
148void dm_cache_metadata_set_read_write(struct dm_cache_metadata *cmd);
149int dm_cache_metadata_abort(struct dm_cache_metadata *cmd);
150
151
152
153#endif
154