blob: 7084503c3405f80cd94f9fc261f9b7cd1530f499 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2003 Sistina Software
Heinz Mauelshagen416cd172008-04-24 21:43:35 +01003 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
4 *
5 * Device-Mapper dirty region log.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * This file is released under the LGPL.
8 */
9
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010010#ifndef _LINUX_DM_DIRTY_LOG
11#define _LINUX_DM_DIRTY_LOG
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010013#ifdef __KERNEL__
14
15#include <linux/types.h>
16#include <linux/device-mapper.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18typedef sector_t region_t;
19
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010020struct dm_dirty_log_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010022struct dm_dirty_log {
23 struct dm_dirty_log_type *type;
Mikulas Patocka87a8f242009-12-10 23:52:01 +000024 int (*flush_callback_fn)(struct dm_target *ti);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 void *context;
26};
27
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010028struct dm_dirty_log_type {
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 const char *name;
30 struct module *module;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Mike Snitzerec44ab92009-04-02 19:55:30 +010032 /* For internal device-mapper use */
33 struct list_head list;
34
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010035 int (*ctr)(struct dm_dirty_log *log, struct dm_target *ti,
36 unsigned argc, char **argv);
37 void (*dtr)(struct dm_dirty_log *log);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39 /*
40 * There are times when we don't want the log to touch
41 * the disk.
42 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010043 int (*presuspend)(struct dm_dirty_log *log);
44 int (*postsuspend)(struct dm_dirty_log *log);
45 int (*resume)(struct dm_dirty_log *log);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47 /*
48 * Retrieves the smallest size of region that the log can
49 * deal with.
50 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010051 uint32_t (*get_region_size)(struct dm_dirty_log *log);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010053 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 * A predicate to say whether a region is clean or not.
55 * May block.
56 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010057 int (*is_clean)(struct dm_dirty_log *log, region_t region);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59 /*
60 * Returns: 0, 1, -EWOULDBLOCK, < 0
61 *
62 * A predicate function to check the area given by
63 * [sector, sector + len) is in sync.
64 *
65 * If -EWOULDBLOCK is returned the state of the region is
66 * unknown, typically this will result in a read being
67 * passed to a daemon to deal with, since a daemon is
68 * allowed to block.
69 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010070 int (*in_sync)(struct dm_dirty_log *log, region_t region,
71 int can_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73 /*
74 * Flush the current log state (eg, to disk). This
75 * function may block.
76 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010077 int (*flush)(struct dm_dirty_log *log);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79 /*
80 * Mark an area as clean or dirty. These functions may
81 * block, though for performance reasons blocking should
82 * be extremely rare (eg, allocating another chunk of
83 * memory for some reason).
84 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010085 void (*mark_region)(struct dm_dirty_log *log, region_t region);
86 void (*clear_region)(struct dm_dirty_log *log, region_t region);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88 /*
89 * Returns: <0 (error), 0 (no region), 1 (region)
90 *
91 * The mirrord will need perform recovery on regions of
92 * the mirror that are in the NOSYNC state. This
93 * function asks the log to tell the caller about the
94 * next region that this machine should recover.
95 *
96 * Do not confuse this function with 'in_sync()', one
97 * tells you if an area is synchronised, the other
98 * assigns recovery work.
99 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100100 int (*get_resync_work)(struct dm_dirty_log *log, region_t *region);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102 /*
Jonathan E Brassowf3ee6b22006-12-08 02:41:11 -0800103 * This notifies the log that the resync status of a region
104 * has changed. It also clears the region from the recovering
105 * list (if present).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100107 void (*set_region_sync)(struct dm_dirty_log *log,
Jonathan E Brassowf3ee6b22006-12-08 02:41:11 -0800108 region_t region, int in_sync);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100110 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 * Returns the number of regions that are in sync.
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100112 */
113 region_t (*get_sync_count)(struct dm_dirty_log *log);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115 /*
116 * Support function for mirror status requests.
117 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100118 int (*status)(struct dm_dirty_log *log, status_type_t status_type,
119 char *result, unsigned maxlen);
Jonathan Brassow7513c2a2009-04-02 19:55:30 +0100120
121 /*
122 * is_remote_recovering is necessary for cluster mirroring. It provides
123 * a way to detect recovery on another node, so we aren't writing
124 * concurrently. This function is likely to block (when a cluster log
125 * is used).
126 *
127 * Returns: 0, 1
128 */
129 int (*is_remote_recovering)(struct dm_dirty_log *log, region_t region);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130};
131
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100132int dm_dirty_log_type_register(struct dm_dirty_log_type *type);
133int dm_dirty_log_type_unregister(struct dm_dirty_log_type *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135/*
136 * Make sure you use these two functions, rather than calling
137 * type->constructor/destructor() directly.
138 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100139struct dm_dirty_log *dm_dirty_log_create(const char *type_name,
Mikulas Patocka87a8f242009-12-10 23:52:01 +0000140 struct dm_target *ti,
141 int (*flush_callback_fn)(struct dm_target *ti),
142 unsigned argc, char **argv);
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100143void dm_dirty_log_destroy(struct dm_dirty_log *log);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100145#endif /* __KERNEL__ */
146#endif /* _LINUX_DM_DIRTY_LOG_H */