Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (C) 2012 Red Hat. All rights reserved.
0003  *
0004  * This file is released under the GPL.
0005  */
0006 
0007 #ifndef DM_CACHE_POLICY_INTERNAL_H
0008 #define DM_CACHE_POLICY_INTERNAL_H
0009 
0010 #include <linux/vmalloc.h>
0011 #include "dm-cache-policy.h"
0012 
0013 /*----------------------------------------------------------------*/
0014 
0015 static inline int policy_lookup(struct dm_cache_policy *p, dm_oblock_t oblock, dm_cblock_t *cblock,
0016                 int data_dir, bool fast_copy, bool *background_queued)
0017 {
0018     return p->lookup(p, oblock, cblock, data_dir, fast_copy, background_queued);
0019 }
0020 
0021 static inline int policy_lookup_with_work(struct dm_cache_policy *p,
0022                       dm_oblock_t oblock, dm_cblock_t *cblock,
0023                       int data_dir, bool fast_copy,
0024                       struct policy_work **work)
0025 {
0026     if (!p->lookup_with_work) {
0027         *work = NULL;
0028         return p->lookup(p, oblock, cblock, data_dir, fast_copy, NULL);
0029     }
0030 
0031     return p->lookup_with_work(p, oblock, cblock, data_dir, fast_copy, work);
0032 }
0033 
0034 static inline int policy_get_background_work(struct dm_cache_policy *p,
0035                          bool idle, struct policy_work **result)
0036 {
0037     return p->get_background_work(p, idle, result);
0038 }
0039 
0040 static inline void policy_complete_background_work(struct dm_cache_policy *p,
0041                            struct policy_work *work,
0042                            bool success)
0043 {
0044     return p->complete_background_work(p, work, success);
0045 }
0046 
0047 static inline void policy_set_dirty(struct dm_cache_policy *p, dm_cblock_t cblock)
0048 {
0049     p->set_dirty(p, cblock);
0050 }
0051 
0052 static inline void policy_clear_dirty(struct dm_cache_policy *p, dm_cblock_t cblock)
0053 {
0054     p->clear_dirty(p, cblock);
0055 }
0056 
0057 static inline int policy_load_mapping(struct dm_cache_policy *p,
0058                       dm_oblock_t oblock, dm_cblock_t cblock,
0059                       bool dirty, uint32_t hint, bool hint_valid)
0060 {
0061     return p->load_mapping(p, oblock, cblock, dirty, hint, hint_valid);
0062 }
0063 
0064 static inline int policy_invalidate_mapping(struct dm_cache_policy *p,
0065                         dm_cblock_t cblock)
0066 {
0067     return p->invalidate_mapping(p, cblock);
0068 }
0069 
0070 static inline uint32_t policy_get_hint(struct dm_cache_policy *p,
0071                        dm_cblock_t cblock)
0072 {
0073     return p->get_hint ? p->get_hint(p, cblock) : 0;
0074 }
0075 
0076 static inline dm_cblock_t policy_residency(struct dm_cache_policy *p)
0077 {
0078     return p->residency(p);
0079 }
0080 
0081 static inline void policy_tick(struct dm_cache_policy *p, bool can_block)
0082 {
0083     if (p->tick)
0084         return p->tick(p, can_block);
0085 }
0086 
0087 static inline int policy_emit_config_values(struct dm_cache_policy *p, char *result,
0088                         unsigned maxlen, ssize_t *sz_ptr)
0089 {
0090     ssize_t sz = *sz_ptr;
0091     if (p->emit_config_values)
0092         return p->emit_config_values(p, result, maxlen, sz_ptr);
0093 
0094     DMEMIT("0 ");
0095     *sz_ptr = sz;
0096     return 0;
0097 }
0098 
0099 static inline int policy_set_config_value(struct dm_cache_policy *p,
0100                       const char *key, const char *value)
0101 {
0102     return p->set_config_value ? p->set_config_value(p, key, value) : -EINVAL;
0103 }
0104 
0105 static inline void policy_allow_migrations(struct dm_cache_policy *p, bool allow)
0106 {
0107     return p->allow_migrations(p, allow);
0108 }
0109 
0110 /*----------------------------------------------------------------*/
0111 
0112 /*
0113  * Some utility functions commonly used by policies and the core target.
0114  */
0115 static inline size_t bitset_size_in_bytes(unsigned nr_entries)
0116 {
0117     return sizeof(unsigned long) * dm_div_up(nr_entries, BITS_PER_LONG);
0118 }
0119 
0120 static inline unsigned long *alloc_bitset(unsigned nr_entries)
0121 {
0122     size_t s = bitset_size_in_bytes(nr_entries);
0123     return vzalloc(s);
0124 }
0125 
0126 static inline void clear_bitset(void *bitset, unsigned nr_entries)
0127 {
0128     size_t s = bitset_size_in_bytes(nr_entries);
0129     memset(bitset, 0, s);
0130 }
0131 
0132 static inline void free_bitset(unsigned long *bits)
0133 {
0134     vfree(bits);
0135 }
0136 
0137 /*----------------------------------------------------------------*/
0138 
0139 /*
0140  * Creates a new cache policy given a policy name, a cache size, an origin size and the block size.
0141  */
0142 struct dm_cache_policy *dm_cache_policy_create(const char *name, dm_cblock_t cache_size,
0143                            sector_t origin_size, sector_t block_size);
0144 
0145 /*
0146  * Destroys the policy.  This drops references to the policy module as well
0147  * as calling it's destroy method.  So always use this rather than calling
0148  * the policy->destroy method directly.
0149  */
0150 void dm_cache_policy_destroy(struct dm_cache_policy *p);
0151 
0152 /*
0153  * In case we've forgotten.
0154  */
0155 const char *dm_cache_policy_get_name(struct dm_cache_policy *p);
0156 
0157 const unsigned *dm_cache_policy_get_version(struct dm_cache_policy *p);
0158 
0159 size_t dm_cache_policy_get_hint_size(struct dm_cache_policy *p);
0160 
0161 /*----------------------------------------------------------------*/
0162 
0163 #endif /* DM_CACHE_POLICY_INTERNAL_H */