1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2003 Sistina Software Limited.
4 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
6 * Device-Mapper dirty region hash interface.
8 * This file is released under the GPL.
11 #ifndef DM_REGION_HASH_H
12 #define DM_REGION_HASH_H
14 #include <linux/dm-dirty-log.h>
17 *----------------------------------------------------------------
19 *----------------------------------------------------------------
21 struct dm_region_hash
;
25 * States a region can have.
27 enum dm_rh_region_states
{
28 DM_RH_CLEAN
= 0x01, /* No writes in flight. */
29 DM_RH_DIRTY
= 0x02, /* Writes in flight. */
30 DM_RH_NOSYNC
= 0x04, /* Out of sync. */
31 DM_RH_RECOVERING
= 0x08, /* Under resynchronization. */
35 * Region hash create/destroy.
38 struct dm_region_hash
*dm_region_hash_create(
39 void *context
, void (*dispatch_bios
)(void *context
,
40 struct bio_list
*bios
),
41 void (*wakeup_workers
)(void *context
),
42 void (*wakeup_all_recovery_waiters
)(void *context
),
43 sector_t target_begin
, unsigned int max_recovery
,
44 struct dm_dirty_log
*log
, uint32_t region_size
,
46 void dm_region_hash_destroy(struct dm_region_hash
*rh
);
48 struct dm_dirty_log
*dm_rh_dirty_log(struct dm_region_hash
*rh
);
51 * Conversion functions.
53 region_t
dm_rh_bio_to_region(struct dm_region_hash
*rh
, struct bio
*bio
);
54 sector_t
dm_rh_region_to_sector(struct dm_region_hash
*rh
, region_t region
);
55 void *dm_rh_region_context(struct dm_region
*reg
);
58 * Get region size and key (ie. number of the region).
60 sector_t
dm_rh_get_region_size(struct dm_region_hash
*rh
);
61 region_t
dm_rh_get_region_key(struct dm_region
*reg
);
64 * Get/set/update region state (and dirty log).
67 int dm_rh_get_state(struct dm_region_hash
*rh
, region_t region
, int may_block
);
68 void dm_rh_set_state(struct dm_region_hash
*rh
, region_t region
,
69 enum dm_rh_region_states state
, int may_block
);
71 /* Non-zero errors_handled leaves the state of the region NOSYNC */
72 void dm_rh_update_states(struct dm_region_hash
*rh
, int errors_handled
);
74 /* Flush the region hash and dirty log. */
75 int dm_rh_flush(struct dm_region_hash
*rh
);
77 /* Inc/dec pending count on regions. */
78 void dm_rh_inc_pending(struct dm_region_hash
*rh
, struct bio_list
*bios
);
79 void dm_rh_dec(struct dm_region_hash
*rh
, region_t region
);
81 /* Delay bios on regions. */
82 void dm_rh_delay(struct dm_region_hash
*rh
, struct bio
*bio
);
84 void dm_rh_mark_nosync(struct dm_region_hash
*rh
, struct bio
*bio
);
87 * Region recovery control.
90 /* Prepare some regions for recovery by starting to quiesce them. */
91 void dm_rh_recovery_prepare(struct dm_region_hash
*rh
);
93 /* Try fetching a quiesced region for recovery. */
94 struct dm_region
*dm_rh_recovery_start(struct dm_region_hash
*rh
);
96 /* Report recovery end on a region. */
97 void dm_rh_recovery_end(struct dm_region
*reg
, int error
);
99 /* Returns number of regions with recovery work outstanding. */
100 int dm_rh_recovery_in_flight(struct dm_region_hash
*rh
);
102 /* Start/stop recovery. */
103 void dm_rh_start_recovery(struct dm_region_hash
*rh
);
104 void dm_rh_stop_recovery(struct dm_region_hash
*rh
);
106 #endif /* DM_REGION_HASH_H */