of: MSI: Simplify irqdomain lookup
[linux/fpc-iii.git] / drivers / md / dm-cache-metadata.h
blob2ffee21f318dfef70c967570b9677da0193d6e12
1 /*
2 * Copyright (C) 2012 Red Hat, Inc.
4 * This file is released under the GPL.
5 */
7 #ifndef DM_CACHE_METADATA_H
8 #define DM_CACHE_METADATA_H
10 #include "dm-cache-block-types.h"
11 #include "dm-cache-policy-internal.h"
12 #include "persistent-data/dm-space-map-metadata.h"
14 /*----------------------------------------------------------------*/
16 #define DM_CACHE_METADATA_BLOCK_SIZE DM_SM_METADATA_BLOCK_SIZE
18 /* FIXME: remove this restriction */
20 * The metadata device is currently limited in size.
22 #define DM_CACHE_METADATA_MAX_SECTORS DM_SM_METADATA_MAX_SECTORS
25 * A metadata device larger than 16GB triggers a warning.
27 #define DM_CACHE_METADATA_MAX_SECTORS_WARNING (16 * (1024 * 1024 * 1024 >> SECTOR_SHIFT))
29 /*----------------------------------------------------------------*/
32 * Ext[234]-style compat feature flags.
34 * A new feature which old metadata will still be compatible with should
35 * define a DM_CACHE_FEATURE_COMPAT_* flag (rarely useful).
37 * A new feature that is not compatible with old code should define a
38 * DM_CACHE_FEATURE_INCOMPAT_* flag and guard the relevant code with
39 * that flag.
41 * A new feature that is not compatible with old code accessing the
42 * metadata RDWR should define a DM_CACHE_FEATURE_RO_COMPAT_* flag and
43 * guard the relevant code with that flag.
45 * As these various flags are defined they should be added to the
46 * following masks.
48 #define DM_CACHE_FEATURE_COMPAT_SUPP 0UL
49 #define DM_CACHE_FEATURE_COMPAT_RO_SUPP 0UL
50 #define DM_CACHE_FEATURE_INCOMPAT_SUPP 0UL
53 * Reopens or creates a new, empty metadata volume.
54 * Returns an ERR_PTR on failure.
56 struct dm_cache_metadata *dm_cache_metadata_open(struct block_device *bdev,
57 sector_t data_block_size,
58 bool may_format_device,
59 size_t policy_hint_size);
61 void dm_cache_metadata_close(struct dm_cache_metadata *cmd);
64 * The metadata needs to know how many cache blocks there are. We don't
65 * care about the origin, assuming the core target is giving us valid
66 * origin blocks to map to.
68 int dm_cache_resize(struct dm_cache_metadata *cmd, dm_cblock_t new_cache_size);
69 dm_cblock_t dm_cache_size(struct dm_cache_metadata *cmd);
71 int dm_cache_discard_bitset_resize(struct dm_cache_metadata *cmd,
72 sector_t discard_block_size,
73 dm_dblock_t new_nr_entries);
75 typedef int (*load_discard_fn)(void *context, sector_t discard_block_size,
76 dm_dblock_t dblock, bool discarded);
77 int dm_cache_load_discards(struct dm_cache_metadata *cmd,
78 load_discard_fn fn, void *context);
80 int dm_cache_set_discard(struct dm_cache_metadata *cmd, dm_dblock_t dblock, bool discard);
82 int dm_cache_remove_mapping(struct dm_cache_metadata *cmd, dm_cblock_t cblock);
83 int dm_cache_insert_mapping(struct dm_cache_metadata *cmd, dm_cblock_t cblock, dm_oblock_t oblock);
84 int dm_cache_changed_this_transaction(struct dm_cache_metadata *cmd);
86 typedef int (*load_mapping_fn)(void *context, dm_oblock_t oblock,
87 dm_cblock_t cblock, bool dirty,
88 uint32_t hint, bool hint_valid);
89 int dm_cache_load_mappings(struct dm_cache_metadata *cmd,
90 struct dm_cache_policy *policy,
91 load_mapping_fn fn,
92 void *context);
94 int dm_cache_set_dirty(struct dm_cache_metadata *cmd, dm_cblock_t cblock, bool dirty);
96 struct dm_cache_statistics {
97 uint32_t read_hits;
98 uint32_t read_misses;
99 uint32_t write_hits;
100 uint32_t write_misses;
103 void dm_cache_metadata_get_stats(struct dm_cache_metadata *cmd,
104 struct dm_cache_statistics *stats);
107 * 'void' because it's no big deal if it fails.
109 void dm_cache_metadata_set_stats(struct dm_cache_metadata *cmd,
110 struct dm_cache_statistics *stats);
112 int dm_cache_commit(struct dm_cache_metadata *cmd, bool clean_shutdown);
114 int dm_cache_get_free_metadata_block_count(struct dm_cache_metadata *cmd,
115 dm_block_t *result);
117 int dm_cache_get_metadata_dev_size(struct dm_cache_metadata *cmd,
118 dm_block_t *result);
120 void dm_cache_dump(struct dm_cache_metadata *cmd);
123 * The policy is invited to save a 32bit hint value for every cblock (eg,
124 * for a hit count). These are stored against the policy name. If
125 * policies are changed, then hints will be lost. If the machine crashes,
126 * hints will be lost.
128 * The hints are indexed by the cblock, but many policies will not
129 * neccessarily have a fast way of accessing efficiently via cblock. So
130 * rather than querying the policy for each cblock, we let it walk its data
131 * structures and fill in the hints in whatever order it wishes.
133 int dm_cache_write_hints(struct dm_cache_metadata *cmd, struct dm_cache_policy *p);
136 * Query method. Are all the blocks in the cache clean?
138 int dm_cache_metadata_all_clean(struct dm_cache_metadata *cmd, bool *result);
140 bool dm_cache_metadata_needs_check(struct dm_cache_metadata *cmd);
141 int dm_cache_metadata_set_needs_check(struct dm_cache_metadata *cmd);
142 void dm_cache_metadata_set_read_only(struct dm_cache_metadata *cmd);
143 void dm_cache_metadata_set_read_write(struct dm_cache_metadata *cmd);
144 int dm_cache_metadata_abort(struct dm_cache_metadata *cmd);
146 /*----------------------------------------------------------------*/
148 #endif /* DM_CACHE_METADATA_H */