123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- #ifndef DM_CACHE_POLICY_H
- #define DM_CACHE_POLICY_H
- #include "dm-cache-block-types.h"
- #include <linux/device-mapper.h>
- enum policy_operation {
- POLICY_HIT,
- POLICY_MISS,
- POLICY_NEW,
- POLICY_REPLACE
- };
- struct policy_locker;
- typedef int (*policy_lock_fn)(struct policy_locker *l, dm_oblock_t oblock);
- struct policy_locker {
- policy_lock_fn fn;
- };
- struct policy_result {
- enum policy_operation op;
- dm_oblock_t old_oblock;
- dm_cblock_t cblock;
- };
- struct dm_cache_policy {
-
-
- void (*destroy)(struct dm_cache_policy *p);
-
- int (*map)(struct dm_cache_policy *p, dm_oblock_t oblock,
- bool can_block, bool can_migrate, bool discarded_oblock,
- struct bio *bio, struct policy_locker *locker,
- struct policy_result *result);
-
- int (*lookup)(struct dm_cache_policy *p, dm_oblock_t oblock, dm_cblock_t *cblock);
- void (*set_dirty)(struct dm_cache_policy *p, dm_oblock_t oblock);
- void (*clear_dirty)(struct dm_cache_policy *p, dm_oblock_t oblock);
-
- int (*load_mapping)(struct dm_cache_policy *p, dm_oblock_t oblock,
- dm_cblock_t cblock, uint32_t hint, bool hint_valid);
-
- uint32_t (*get_hint)(struct dm_cache_policy *p, dm_cblock_t cblock);
-
- void (*remove_mapping)(struct dm_cache_policy *p, dm_oblock_t oblock);
- void (*force_mapping)(struct dm_cache_policy *p, dm_oblock_t current_oblock,
- dm_oblock_t new_oblock);
-
- int (*remove_cblock)(struct dm_cache_policy *p, dm_cblock_t cblock);
-
- int (*writeback_work)(struct dm_cache_policy *p, dm_oblock_t *oblock, dm_cblock_t *cblock,
- bool critical_only);
-
- dm_cblock_t (*residency)(struct dm_cache_policy *p);
-
- void (*tick)(struct dm_cache_policy *p, bool can_block);
-
- int (*emit_config_values)(struct dm_cache_policy *p, char *result,
- unsigned maxlen, ssize_t *sz_ptr);
- int (*set_config_value)(struct dm_cache_policy *p,
- const char *key, const char *value);
-
- void *private;
- };
- #define CACHE_POLICY_NAME_SIZE 16
- #define CACHE_POLICY_VERSION_SIZE 3
- struct dm_cache_policy_type {
-
- struct list_head list;
-
- char name[CACHE_POLICY_NAME_SIZE];
- unsigned version[CACHE_POLICY_VERSION_SIZE];
-
- struct dm_cache_policy_type *real;
-
- size_t hint_size;
- struct module *owner;
- struct dm_cache_policy *(*create)(dm_cblock_t cache_size,
- sector_t origin_size,
- sector_t block_size);
- };
- int dm_cache_policy_register(struct dm_cache_policy_type *type);
- void dm_cache_policy_unregister(struct dm_cache_policy_type *type);
- #endif
|