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