| 1 |
|
| 2 | #ifndef _DM_PCACHE_H
|
| 3 | #define _DM_PCACHE_H
|
| 4 | #include <linux/device-mapper.h>
|
| 5 |
|
| 6 | #include "../dm-core.h"
|
| 7 |
|
| 8 | #define CACHE_DEV_TO_PCACHE(cache_dev) (container_of(cache_dev, struct dm_pcache, cache_dev))
|
| 9 | #define BACKING_DEV_TO_PCACHE(backing_dev) (container_of(backing_dev, struct dm_pcache, backing_dev))
|
| 10 | #define CACHE_TO_PCACHE(cache) (container_of(cache, struct dm_pcache, cache))
|
| 11 |
|
| 12 | #define PCACHE_STATE_RUNNING 1
|
| 13 | #define PCACHE_STATE_STOPPING 2
|
| 14 |
|
| 15 | struct pcache_cache_dev;
|
| 16 | struct pcache_backing_dev;
|
| 17 | struct pcache_cache;
|
| 18 | struct pcache_cache_options;
|
| 19 | struct dm_pcache {
|
| 20 | struct dm_target *ti;
|
| 21 | struct pcache_cache_dev cache_dev;
|
| 22 | struct pcache_backing_dev backing_dev;
|
| 23 | struct pcache_cache cache;
|
| 24 | struct pcache_cache_options opts;
|
| 25 |
|
| 26 | spinlock_t defered_req_list_lock;
|
| 27 | struct list_head defered_req_list;
|
| 28 | struct workqueue_struct *task_wq;
|
| 29 |
|
| 30 | struct work_struct defered_req_work;
|
| 31 |
|
| 32 | atomic_t state;
|
| 33 | atomic_t inflight_reqs;
|
| 34 | wait_queue_head_t inflight_wq;
|
| 35 | };
|
| 36 |
|
| 37 | static inline bool pcache_is_stopping(struct dm_pcache *pcache)
|
| 38 | {
|
| 39 | return (atomic_read(&pcache->state) == PCACHE_STATE_STOPPING);
|
| 40 | }
|
| 41 |
|
| 42 | #define pcache_dev_err(pcache, fmt, ...) \
|
| 43 | pcache_err("%s " fmt, pcache->ti->table->md->name, ##__VA_ARGS__)
|
| 44 | #define pcache_dev_info(pcache, fmt, ...) \
|
| 45 | pcache_info("%s " fmt, pcache->ti->table->md->name, ##__VA_ARGS__)
|
| 46 | #define pcache_dev_debug(pcache, fmt, ...) \
|
| 47 | pcache_debug("%s " fmt, pcache->ti->table->md->name, ##__VA_ARGS__)
|
| 48 |
|
| 49 | struct pcache_request {
|
| 50 | struct dm_pcache *pcache;
|
| 51 | struct bio *bio;
|
| 52 |
|
| 53 | u64 off;
|
| 54 | u32 data_len;
|
| 55 |
|
| 56 | struct kref ref;
|
| 57 | int ret;
|
| 58 |
|
| 59 | struct list_head list_node;
|
| 60 | };
|
| 61 |
|
| 62 | void pcache_req_get(struct pcache_request *pcache_req);
|
| 63 | void pcache_req_put(struct pcache_request *pcache_req, int ret);
|
| 64 |
|
| 65 | void pcache_defer_reqs_kick(struct dm_pcache *pcache);
|
| 66 |
|
| 67 | #endif
|