xref: /openbmc/linux/include/linux/dm-dirty-log.h (revision a4a82ce3)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2003 Sistina Software
4  * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
5  *
6  * Device-Mapper dirty region log.
7  *
8  * This file is released under the LGPL.
9  */
10 
11 #ifndef _LINUX_DM_DIRTY_LOG
12 #define _LINUX_DM_DIRTY_LOG
13 
14 #ifdef __KERNEL__
15 
16 #include <linux/types.h>
17 #include <linux/device-mapper.h>
18 
19 typedef sector_t region_t;
20 
21 struct dm_dirty_log_type;
22 
23 struct dm_dirty_log {
24 	struct dm_dirty_log_type *type;
25 	int (*flush_callback_fn)(struct dm_target *ti);
26 	void *context;
27 };
28 
29 struct dm_dirty_log_type {
30 	const char *name;
31 	struct module *module;
32 
33 	/* For internal device-mapper use */
34 	struct list_head list;
35 
36 	int (*ctr)(struct dm_dirty_log *log, struct dm_target *ti,
37 		   unsigned int argc, char **argv);
38 	void (*dtr)(struct dm_dirty_log *log);
39 
40 	/*
41 	 * There are times when we don't want the log to touch
42 	 * the disk.
43 	 */
44 	int (*presuspend)(struct dm_dirty_log *log);
45 	int (*postsuspend)(struct dm_dirty_log *log);
46 	int (*resume)(struct dm_dirty_log *log);
47 
48 	/*
49 	 * Retrieves the smallest size of region that the log can
50 	 * deal with.
51 	 */
52 	uint32_t (*get_region_size)(struct dm_dirty_log *log);
53 
54 	/*
55 	 * A predicate to say whether a region is clean or not.
56 	 * May block.
57 	 */
58 	int (*is_clean)(struct dm_dirty_log *log, region_t region);
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 	 */
71 	int (*in_sync)(struct dm_dirty_log *log, region_t region,
72 		       int can_block);
73 
74 	/*
75 	 * Flush the current log state (eg, to disk).  This
76 	 * function may block.
77 	 */
78 	int (*flush)(struct dm_dirty_log *log);
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 	 */
86 	void (*mark_region)(struct dm_dirty_log *log, region_t region);
87 	void (*clear_region)(struct dm_dirty_log *log, region_t region);
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.
100 	 */
101 	int (*get_resync_work)(struct dm_dirty_log *log, region_t *region);
102 
103 	/*
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).
107 	 */
108 	void (*set_region_sync)(struct dm_dirty_log *log,
109 				region_t region, int in_sync);
110 
111 	/*
112 	 * Returns the number of regions that are in sync.
113 	 */
114 	region_t (*get_sync_count)(struct dm_dirty_log *log);
115 
116 	/*
117 	 * Support function for mirror status requests.
118 	 */
119 	int (*status)(struct dm_dirty_log *log, status_type_t status_type,
120 		      char *result, unsigned int maxlen);
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);
131 };
132 
133 int dm_dirty_log_type_register(struct dm_dirty_log_type *type);
134 int dm_dirty_log_type_unregister(struct dm_dirty_log_type *type);
135 
136 /*
137  * Make sure you use these two functions, rather than calling
138  * type->constructor/destructor() directly.
139  */
140 struct dm_dirty_log *dm_dirty_log_create(const char *type_name,
141 			struct dm_target *ti,
142 			int (*flush_callback_fn)(struct dm_target *ti),
143 			unsigned int argc, char **argv);
144 void dm_dirty_log_destroy(struct dm_dirty_log *log);
145 
146 #endif	/* __KERNEL__ */
147 #endif	/* _LINUX_DM_DIRTY_LOG_H */
148