dm: use fsleep() instead of msleep() for deterministic sleep duration
[linux-block.git] / include / linux / dm-region-hash.h
CommitLineData
3bd94003 1/* SPDX-License-Identifier: GPL-2.0-only */
1f965b19
HM
2/*
3 * Copyright (C) 2003 Sistina Software Limited.
4 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
5 *
6 * Device-Mapper dirty region hash interface.
7 *
8 * This file is released under the GPL.
9 */
10
11#ifndef DM_REGION_HASH_H
12#define DM_REGION_HASH_H
13
14#include <linux/dm-dirty-log.h>
15
16/*-----------------------------------------------------------------
17 * Region hash
18 *----------------------------------------------------------------*/
19struct dm_region_hash;
20struct dm_region;
21
22/*
23 * States a region can have.
24 */
25enum dm_rh_region_states {
26 DM_RH_CLEAN = 0x01, /* No writes in flight. */
27 DM_RH_DIRTY = 0x02, /* Writes in flight. */
28 DM_RH_NOSYNC = 0x04, /* Out of sync. */
29 DM_RH_RECOVERING = 0x08, /* Under resynchronization. */
30};
31
32/*
33 * Region hash create/destroy.
34 */
35struct bio_list;
36struct dm_region_hash *dm_region_hash_create(
37 void *context, void (*dispatch_bios)(void *context,
38 struct bio_list *bios),
39 void (*wakeup_workers)(void *context),
40 void (*wakeup_all_recovery_waiters)(void *context),
41 sector_t target_begin, unsigned max_recovery,
42 struct dm_dirty_log *log, uint32_t region_size,
43 region_t nr_regions);
44void dm_region_hash_destroy(struct dm_region_hash *rh);
45
46struct dm_dirty_log *dm_rh_dirty_log(struct dm_region_hash *rh);
47
48/*
49 * Conversion functions.
50 */
51region_t dm_rh_bio_to_region(struct dm_region_hash *rh, struct bio *bio);
52sector_t dm_rh_region_to_sector(struct dm_region_hash *rh, region_t region);
53void *dm_rh_region_context(struct dm_region *reg);
54
55/*
56 * Get region size and key (ie. number of the region).
57 */
58sector_t dm_rh_get_region_size(struct dm_region_hash *rh);
59region_t dm_rh_get_region_key(struct dm_region *reg);
60
61/*
62 * Get/set/update region state (and dirty log).
63 *
64 */
65int dm_rh_get_state(struct dm_region_hash *rh, region_t region, int may_block);
66void dm_rh_set_state(struct dm_region_hash *rh, region_t region,
67 enum dm_rh_region_states state, int may_block);
68
69/* Non-zero errors_handled leaves the state of the region NOSYNC */
70void dm_rh_update_states(struct dm_region_hash *rh, int errors_handled);
71
72/* Flush the region hash and dirty log. */
73int dm_rh_flush(struct dm_region_hash *rh);
74
75/* Inc/dec pending count on regions. */
76void dm_rh_inc_pending(struct dm_region_hash *rh, struct bio_list *bios);
77void dm_rh_dec(struct dm_region_hash *rh, region_t region);
78
79/* Delay bios on regions. */
80void dm_rh_delay(struct dm_region_hash *rh, struct bio *bio);
81
c58098be 82void dm_rh_mark_nosync(struct dm_region_hash *rh, struct bio *bio);
1f965b19
HM
83
84/*
85 * Region recovery control.
86 */
87
88/* Prepare some regions for recovery by starting to quiesce them. */
89void dm_rh_recovery_prepare(struct dm_region_hash *rh);
90
91/* Try fetching a quiesced region for recovery. */
92struct dm_region *dm_rh_recovery_start(struct dm_region_hash *rh);
93
94/* Report recovery end on a region. */
95void dm_rh_recovery_end(struct dm_region *reg, int error);
96
97/* Returns number of regions with recovery work outstanding. */
98int dm_rh_recovery_in_flight(struct dm_region_hash *rh);
99
100/* Start/stop recovery. */
101void dm_rh_start_recovery(struct dm_region_hash *rh);
102void dm_rh_stop_recovery(struct dm_region_hash *rh);
103
104#endif /* DM_REGION_HASH_H */