2 * Copyright (C) 2017 Red Hat. All rights reserved.
4 * This file is released under the GPL.
7 #ifndef DM_CACHE_BACKGROUND_WORK_H
8 #define DM_CACHE_BACKGROUND_WORK_H
10 #include <linux/vmalloc.h>
11 #include "dm-cache-policy.h"
13 /*----------------------------------------------------------------*/
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.
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.
24 * There is no locking in this, so calls will probably need to be
25 * protected with a spinlock.
28 struct background_work;
29 struct background_tracker;
32 * Create a new tracker, it will not be able to queue more than
35 struct background_tracker *btracker_create(unsigned int max_work);
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
42 void btracker_destroy(struct background_tracker *b);
44 unsigned int btracker_nr_writebacks_queued(struct background_tracker *b);
45 unsigned int btracker_nr_demotions_queued(struct background_tracker *b);
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
53 * returns -EINVAL iff the work is already queued. -ENOMEM if the work
54 * couldn't be queued for another reason.
56 int btracker_queue(struct background_tracker *b,
57 struct policy_work *work,
58 struct policy_work **pwork);
61 * Hands out the next piece of work to be performed.
62 * Returns -ENODATA if there's no work.
64 int btracker_issue(struct background_tracker *b, struct policy_work **work);
67 * Informs the tracker that the work has been completed and it may forget
70 void btracker_complete(struct background_tracker *b, struct policy_work *op);
73 * Predicate to see if an origin block is already scheduled for promotion.
75 bool btracker_promotion_already_present(struct background_tracker *b,
78 /*----------------------------------------------------------------*/