io_uring/cmd: add cmd lazy tw wake helper
[linux-block.git] / include / linux / dm-dirty-log.h
CommitLineData
3bd94003 1/* SPDX-License-Identifier: GPL-2.0-only */
1da177e4
LT
2/*
3 * Copyright (C) 2003 Sistina Software
416cd17b
HM
4 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
5 *
6 * Device-Mapper dirty region log.
1da177e4
LT
7 *
8 * This file is released under the LGPL.
9 */
10
416cd17b
HM
11#ifndef _LINUX_DM_DIRTY_LOG
12#define _LINUX_DM_DIRTY_LOG
13
14#ifdef __KERNEL__
1da177e4 15
416cd17b
HM
16#include <linux/types.h>
17#include <linux/device-mapper.h>
1da177e4
LT
18
19typedef sector_t region_t;
20
416cd17b 21struct dm_dirty_log_type;
1da177e4 22
416cd17b
HM
23struct dm_dirty_log {
24 struct dm_dirty_log_type *type;
87a8f240 25 int (*flush_callback_fn)(struct dm_target *ti);
1da177e4
LT
26 void *context;
27};
28
416cd17b 29struct dm_dirty_log_type {
1da177e4
LT
30 const char *name;
31 struct module *module;
1da177e4 32
ec44ab9d
MS
33 /* For internal device-mapper use */
34 struct list_head list;
35
416cd17b 36 int (*ctr)(struct dm_dirty_log *log, struct dm_target *ti,
86a3238c 37 unsigned int argc, char **argv);
416cd17b 38 void (*dtr)(struct dm_dirty_log *log);
1da177e4
LT
39
40 /*
41 * There are times when we don't want the log to touch
42 * the disk.
43 */
416cd17b
HM
44 int (*presuspend)(struct dm_dirty_log *log);
45 int (*postsuspend)(struct dm_dirty_log *log);
46 int (*resume)(struct dm_dirty_log *log);
1da177e4
LT
47
48 /*
49 * Retrieves the smallest size of region that the log can
50 * deal with.
51 */
416cd17b 52 uint32_t (*get_region_size)(struct dm_dirty_log *log);
1da177e4 53
416cd17b 54 /*
1da177e4
LT
55 * A predicate to say whether a region is clean or not.
56 * May block.
57 */
416cd17b 58 int (*is_clean)(struct dm_dirty_log *log, region_t region);
1da177e4
LT
59
60 /*
61 * Returns: 0, 1, -EWOULDBLOCK, < 0
62 *
63 * A predicate function to check the area given by
64 * [sector, sector + len) is in sync.
65 *
66 * If -EWOULDBLOCK is returned the state of the region is
67 * unknown, typically this will result in a read being
68 * passed to a daemon to deal with, since a daemon is
69 * allowed to block.
70 */
416cd17b
HM
71 int (*in_sync)(struct dm_dirty_log *log, region_t region,
72 int can_block);
1da177e4
LT
73
74 /*
75 * Flush the current log state (eg, to disk). This
76 * function may block.
77 */
416cd17b 78 int (*flush)(struct dm_dirty_log *log);
1da177e4
LT
79
80 /*
81 * Mark an area as clean or dirty. These functions may
82 * block, though for performance reasons blocking should
83 * be extremely rare (eg, allocating another chunk of
84 * memory for some reason).
85 */
416cd17b
HM
86 void (*mark_region)(struct dm_dirty_log *log, region_t region);
87 void (*clear_region)(struct dm_dirty_log *log, region_t region);
1da177e4
LT
88
89 /*
90 * Returns: <0 (error), 0 (no region), 1 (region)
91 *
92 * The mirrord will need perform recovery on regions of
93 * the mirror that are in the NOSYNC state. This
94 * function asks the log to tell the caller about the
95 * next region that this machine should recover.
96 *
97 * Do not confuse this function with 'in_sync()', one
98 * tells you if an area is synchronised, the other
99 * assigns recovery work.
a4a82ce3 100 */
416cd17b 101 int (*get_resync_work)(struct dm_dirty_log *log, region_t *region);
1da177e4
LT
102
103 /*
f3ee6b2f
JB
104 * This notifies the log that the resync status of a region
105 * has changed. It also clears the region from the recovering
106 * list (if present).
1da177e4 107 */
416cd17b 108 void (*set_region_sync)(struct dm_dirty_log *log,
f3ee6b2f 109 region_t region, int in_sync);
1da177e4 110
416cd17b 111 /*
1da177e4 112 * Returns the number of regions that are in sync.
416cd17b
HM
113 */
114 region_t (*get_sync_count)(struct dm_dirty_log *log);
1da177e4
LT
115
116 /*
117 * Support function for mirror status requests.
118 */
416cd17b 119 int (*status)(struct dm_dirty_log *log, status_type_t status_type,
86a3238c 120 char *result, unsigned int maxlen);
7513c2a7
JB
121
122 /*
123 * is_remote_recovering is necessary for cluster mirroring. It provides
124 * a way to detect recovery on another node, so we aren't writing
125 * concurrently. This function is likely to block (when a cluster log
126 * is used).
127 *
128 * Returns: 0, 1
129 */
130 int (*is_remote_recovering)(struct dm_dirty_log *log, region_t region);
1da177e4
LT
131};
132
416cd17b
HM
133int dm_dirty_log_type_register(struct dm_dirty_log_type *type);
134int dm_dirty_log_type_unregister(struct dm_dirty_log_type *type);
1da177e4
LT
135
136/*
137 * Make sure you use these two functions, rather than calling
138 * type->constructor/destructor() directly.
139 */
416cd17b 140struct dm_dirty_log *dm_dirty_log_create(const char *type_name,
87a8f240
MP
141 struct dm_target *ti,
142 int (*flush_callback_fn)(struct dm_target *ti),
86a3238c 143 unsigned int argc, char **argv);
416cd17b 144void dm_dirty_log_destroy(struct dm_dirty_log *log);
1da177e4 145
416cd17b
HM
146#endif /* __KERNEL__ */
147#endif /* _LINUX_DM_DIRTY_LOG_H */