Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (C) 2012 Red Hat, Inc.
0003  *
0004  * This file is released under the GPL.
0005  */
0006 
0007 #ifndef DM_CACHE_METADATA_H
0008 #define DM_CACHE_METADATA_H
0009 
0010 #include "dm-cache-block-types.h"
0011 #include "dm-cache-policy-internal.h"
0012 #include "persistent-data/dm-space-map-metadata.h"
0013 
0014 /*----------------------------------------------------------------*/
0015 
0016 #define DM_CACHE_METADATA_BLOCK_SIZE DM_SM_METADATA_BLOCK_SIZE
0017 
0018 /* FIXME: remove this restriction */
0019 /*
0020  * The metadata device is currently limited in size.
0021  */
0022 #define DM_CACHE_METADATA_MAX_SECTORS DM_SM_METADATA_MAX_SECTORS
0023 
0024 /*
0025  * A metadata device larger than 16GB triggers a warning.
0026  */
0027 #define DM_CACHE_METADATA_MAX_SECTORS_WARNING (16 * (1024 * 1024 * 1024 >> SECTOR_SHIFT))
0028 
0029 /*----------------------------------------------------------------*/
0030 
0031 /*
0032  * Ext[234]-style compat feature flags.
0033  *
0034  * A new feature which old metadata will still be compatible with should
0035  * define a DM_CACHE_FEATURE_COMPAT_* flag (rarely useful).
0036  *
0037  * A new feature that is not compatible with old code should define a
0038  * DM_CACHE_FEATURE_INCOMPAT_* flag and guard the relevant code with
0039  * that flag.
0040  *
0041  * A new feature that is not compatible with old code accessing the
0042  * metadata RDWR should define a DM_CACHE_FEATURE_RO_COMPAT_* flag and
0043  * guard the relevant code with that flag.
0044  *
0045  * As these various flags are defined they should be added to the
0046  * following masks.
0047  */
0048 
0049 #define DM_CACHE_FEATURE_COMPAT_SUPP      0UL
0050 #define DM_CACHE_FEATURE_COMPAT_RO_SUPP   0UL
0051 #define DM_CACHE_FEATURE_INCOMPAT_SUPP    0UL
0052 
0053 struct dm_cache_metadata;
0054 
0055 /*
0056  * Reopens or creates a new, empty metadata volume.  Returns an ERR_PTR on
0057  * failure.  If reopening then features must match.
0058  */
0059 struct dm_cache_metadata *dm_cache_metadata_open(struct block_device *bdev,
0060                          sector_t data_block_size,
0061                          bool may_format_device,
0062                          size_t policy_hint_size,
0063                          unsigned metadata_version);
0064 
0065 void dm_cache_metadata_close(struct dm_cache_metadata *cmd);
0066 
0067 /*
0068  * The metadata needs to know how many cache blocks there are.  We don't
0069  * care about the origin, assuming the core target is giving us valid
0070  * origin blocks to map to.
0071  */
0072 int dm_cache_resize(struct dm_cache_metadata *cmd, dm_cblock_t new_cache_size);
0073 int dm_cache_size(struct dm_cache_metadata *cmd, dm_cblock_t *result);
0074 
0075 int dm_cache_discard_bitset_resize(struct dm_cache_metadata *cmd,
0076                    sector_t discard_block_size,
0077                    dm_dblock_t new_nr_entries);
0078 
0079 typedef int (*load_discard_fn)(void *context, sector_t discard_block_size,
0080                    dm_dblock_t dblock, bool discarded);
0081 int dm_cache_load_discards(struct dm_cache_metadata *cmd,
0082                load_discard_fn fn, void *context);
0083 
0084 int dm_cache_set_discard(struct dm_cache_metadata *cmd, dm_dblock_t dblock, bool discard);
0085 
0086 int dm_cache_remove_mapping(struct dm_cache_metadata *cmd, dm_cblock_t cblock);
0087 int dm_cache_insert_mapping(struct dm_cache_metadata *cmd, dm_cblock_t cblock, dm_oblock_t oblock);
0088 int dm_cache_changed_this_transaction(struct dm_cache_metadata *cmd);
0089 
0090 typedef int (*load_mapping_fn)(void *context, dm_oblock_t oblock,
0091                    dm_cblock_t cblock, bool dirty,
0092                    uint32_t hint, bool hint_valid);
0093 int dm_cache_load_mappings(struct dm_cache_metadata *cmd,
0094                struct dm_cache_policy *policy,
0095                load_mapping_fn fn,
0096                void *context);
0097 
0098 int dm_cache_set_dirty_bits(struct dm_cache_metadata *cmd,
0099                 unsigned nr_bits, unsigned long *bits);
0100 
0101 struct dm_cache_statistics {
0102     uint32_t read_hits;
0103     uint32_t read_misses;
0104     uint32_t write_hits;
0105     uint32_t write_misses;
0106 };
0107 
0108 void dm_cache_metadata_get_stats(struct dm_cache_metadata *cmd,
0109                  struct dm_cache_statistics *stats);
0110 
0111 /*
0112  * 'void' because it's no big deal if it fails.
0113  */
0114 void dm_cache_metadata_set_stats(struct dm_cache_metadata *cmd,
0115                  struct dm_cache_statistics *stats);
0116 
0117 int dm_cache_commit(struct dm_cache_metadata *cmd, bool clean_shutdown);
0118 
0119 int dm_cache_get_free_metadata_block_count(struct dm_cache_metadata *cmd,
0120                        dm_block_t *result);
0121 
0122 int dm_cache_get_metadata_dev_size(struct dm_cache_metadata *cmd,
0123                    dm_block_t *result);
0124 
0125 void dm_cache_dump(struct dm_cache_metadata *cmd);
0126 
0127 /*
0128  * The policy is invited to save a 32bit hint value for every cblock (eg,
0129  * for a hit count).  These are stored against the policy name.  If
0130  * policies are changed, then hints will be lost.  If the machine crashes,
0131  * hints will be lost.
0132  *
0133  * The hints are indexed by the cblock, but many policies will not
0134  * necessarily have a fast way of accessing efficiently via cblock.  So
0135  * rather than querying the policy for each cblock, we let it walk its data
0136  * structures and fill in the hints in whatever order it wishes.
0137  */
0138 int dm_cache_write_hints(struct dm_cache_metadata *cmd, struct dm_cache_policy *p);
0139 
0140 /*
0141  * Query method.  Are all the blocks in the cache clean?
0142  */
0143 int dm_cache_metadata_all_clean(struct dm_cache_metadata *cmd, bool *result);
0144 
0145 int dm_cache_metadata_needs_check(struct dm_cache_metadata *cmd, bool *result);
0146 int dm_cache_metadata_set_needs_check(struct dm_cache_metadata *cmd);
0147 void dm_cache_metadata_set_read_only(struct dm_cache_metadata *cmd);
0148 void dm_cache_metadata_set_read_write(struct dm_cache_metadata *cmd);
0149 int dm_cache_metadata_abort(struct dm_cache_metadata *cmd);
0150 
0151 /*----------------------------------------------------------------*/
0152 
0153 #endif /* DM_CACHE_METADATA_H */