1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2003 Sistina Software
4 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
6 * Device-Mapper dirty region log.
8 * This file is released under the LGPL.
11 #ifndef _LINUX_DM_DIRTY_LOG
12 #define _LINUX_DM_DIRTY_LOG
16 #include <linux/types.h>
17 #include <linux/device-mapper.h>
19 typedef sector_t region_t
;
21 struct dm_dirty_log_type
;
24 struct dm_dirty_log_type
*type
;
25 int (*flush_callback_fn
)(struct dm_target
*ti
);
29 struct dm_dirty_log_type
{
31 struct module
*module
;
33 /* For internal device-mapper use */
34 struct list_head list
;
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
);
41 * There are times when we don't want the log to touch
44 int (*presuspend
)(struct dm_dirty_log
*log
);
45 int (*postsuspend
)(struct dm_dirty_log
*log
);
46 int (*resume
)(struct dm_dirty_log
*log
);
49 * Retrieves the smallest size of region that the log can
52 uint32_t (*get_region_size
)(struct dm_dirty_log
*log
);
55 * A predicate to say whether a region is clean or not.
58 int (*is_clean
)(struct dm_dirty_log
*log
, region_t region
);
61 * Returns: 0, 1, -EWOULDBLOCK, < 0
63 * A predicate function to check the area given by
64 * [sector, sector + len) is in sync.
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
71 int (*in_sync
)(struct dm_dirty_log
*log
, region_t region
,
75 * Flush the current log state (eg, to disk). This
78 int (*flush
)(struct dm_dirty_log
*log
);
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).
86 void (*mark_region
)(struct dm_dirty_log
*log
, region_t region
);
87 void (*clear_region
)(struct dm_dirty_log
*log
, region_t region
);
90 * Returns: <0 (error), 0 (no region), 1 (region)
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.
97 * Do not confuse this function with 'in_sync()', one
98 * tells you if an area is synchronised, the other
99 * assigns recovery work.
101 int (*get_resync_work
)(struct dm_dirty_log
*log
, region_t
*region
);
104 * This notifies the log that the resync status of a region
105 * has changed. It also clears the region from the recovering
108 void (*set_region_sync
)(struct dm_dirty_log
*log
,
109 region_t region
, int in_sync
);
112 * Returns the number of regions that are in sync.
114 region_t (*get_sync_count
)(struct dm_dirty_log
*log
);
117 * Support function for mirror status requests.
119 int (*status
)(struct dm_dirty_log
*log
, status_type_t status_type
,
120 char *result
, unsigned int maxlen
);
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
130 int (*is_remote_recovering
)(struct dm_dirty_log
*log
, region_t region
);
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
);
137 * Make sure you use these two functions, rather than calling
138 * type->constructor/destructor() directly.
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
);
146 #endif /* __KERNEL__ */
147 #endif /* _LINUX_DM_DIRTY_LOG_H */