1 /* 2 * Copyright (C) 2017 Red Hat. All rights reserved. 3 * 4 * This file is released under the GPL. 5 */ 6 7 #ifndef DM_CACHE_BACKGROUND_WORK_H 8 #define DM_CACHE_BACKGROUND_WORK_H 9 10 #include <linux/vmalloc.h> 11 #include "dm-cache-policy.h" 12 13 /*----------------------------------------------------------------*/ 14 15 /* 16 * The cache policy decides what background work should be performed, 17 * such as promotions, demotions and writebacks. The core cache target 18 * is in charge of performing the work, and does so when it sees fit. 19 * 20 * The background_tracker acts as a go between. Keeping track of future 21 * work that the policy has decided upon, and handing (issuing) it to 22 * the core target when requested. 23 * 24 * There is no locking in this, so calls will probably need to be 25 * protected with a spinlock. 26 */ 27 28 struct background_work; 29 struct background_tracker; 30 31 /* 32 * Create a new tracker, it will not be able to queue more than 33 * 'max_work' entries. 34 */ 35 struct background_tracker *btracker_create(unsigned max_work); 36 37 /* 38 * Destroy the tracker. No issued, but not complete, work should 39 * exist when this is called. It is fine to have queued but unissued 40 * work. 41 */ 42 void btracker_destroy(struct background_tracker *b); 43 44 unsigned btracker_nr_writebacks_queued(struct background_tracker *b); 45 unsigned btracker_nr_demotions_queued(struct background_tracker *b); 46 47 /* 48 * Queue some work within the tracker. 'work' should point to the work 49 * to queue, this will be copied (ownership doesn't pass). If pwork 50 * is not NULL then it will be set to point to the tracker's internal 51 * copy of the work. 52 * 53 * returns -EINVAL iff the work is already queued. -ENOMEM if the work 54 * couldn't be queued for another reason. 55 */ 56 int btracker_queue(struct background_tracker *b, 57 struct policy_work *work, 58 struct policy_work **pwork); 59 60 /* 61 * Hands out the next piece of work to be performed. 62 * Returns -ENODATA if there's no work. 63 */ 64 int btracker_issue(struct background_tracker *b, struct policy_work **work); 65 66 /* 67 * Informs the tracker that the work has been completed and it may forget 68 * about it. 69 */ 70 void btracker_complete(struct background_tracker *b, struct policy_work *op); 71 72 /* 73 * Predicate to see if an origin block is already scheduled for promotion. 74 */ 75 bool btracker_promotion_already_present(struct background_tracker *b, 76 dm_oblock_t oblock); 77 78 /*----------------------------------------------------------------*/ 79 80 #endif 81