blob: 600c5fb2daad4c231b53a4654316469895af9b0c [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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 void *context;
25};
26
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010027struct dm_dirty_log_type {
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 const char *name;
29 struct module *module;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010031 int (*ctr)(struct dm_dirty_log *log, struct dm_target *ti,
32 unsigned argc, char **argv);
33 void (*dtr)(struct dm_dirty_log *log);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35 /*
36 * There are times when we don't want the log to touch
37 * the disk.
38 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010039 int (*presuspend)(struct dm_dirty_log *log);
40 int (*postsuspend)(struct dm_dirty_log *log);
41 int (*resume)(struct dm_dirty_log *log);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43 /*
44 * Retrieves the smallest size of region that the log can
45 * deal with.
46 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010047 uint32_t (*get_region_size)(struct dm_dirty_log *log);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010049 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 * A predicate to say whether a region is clean or not.
51 * May block.
52 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010053 int (*is_clean)(struct dm_dirty_log *log, region_t region);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55 /*
56 * Returns: 0, 1, -EWOULDBLOCK, < 0
57 *
58 * A predicate function to check the area given by
59 * [sector, sector + len) is in sync.
60 *
61 * If -EWOULDBLOCK is returned the state of the region is
62 * unknown, typically this will result in a read being
63 * passed to a daemon to deal with, since a daemon is
64 * allowed to block.
65 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010066 int (*in_sync)(struct dm_dirty_log *log, region_t region,
67 int can_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69 /*
70 * Flush the current log state (eg, to disk). This
71 * function may block.
72 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010073 int (*flush)(struct dm_dirty_log *log);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75 /*
76 * Mark an area as clean or dirty. These functions may
77 * block, though for performance reasons blocking should
78 * be extremely rare (eg, allocating another chunk of
79 * memory for some reason).
80 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010081 void (*mark_region)(struct dm_dirty_log *log, region_t region);
82 void (*clear_region)(struct dm_dirty_log *log, region_t region);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84 /*
85 * Returns: <0 (error), 0 (no region), 1 (region)
86 *
87 * The mirrord will need perform recovery on regions of
88 * the mirror that are in the NOSYNC state. This
89 * function asks the log to tell the caller about the
90 * next region that this machine should recover.
91 *
92 * Do not confuse this function with 'in_sync()', one
93 * tells you if an area is synchronised, the other
94 * assigns recovery work.
95 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010096 int (*get_resync_work)(struct dm_dirty_log *log, region_t *region);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98 /*
Jonathan E Brassowf3ee6b22006-12-08 02:41:11 -080099 * This notifies the log that the resync status of a region
100 * has changed. It also clears the region from the recovering
101 * list (if present).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100103 void (*set_region_sync)(struct dm_dirty_log *log,
Jonathan E Brassowf3ee6b22006-12-08 02:41:11 -0800104 region_t region, int in_sync);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100106 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 * Returns the number of regions that are in sync.
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100108 */
109 region_t (*get_sync_count)(struct dm_dirty_log *log);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111 /*
112 * Support function for mirror status requests.
113 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100114 int (*status)(struct dm_dirty_log *log, status_type_t status_type,
115 char *result, unsigned maxlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116};
117
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100118int dm_dirty_log_type_register(struct dm_dirty_log_type *type);
119int dm_dirty_log_type_unregister(struct dm_dirty_log_type *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121/*
122 * Make sure you use these two functions, rather than calling
123 * type->constructor/destructor() directly.
124 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100125struct dm_dirty_log *dm_dirty_log_create(const char *type_name,
126 struct dm_target *ti,
127 unsigned argc, char **argv);
128void dm_dirty_log_destroy(struct dm_dirty_log *log);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100130#endif /* __KERNEL__ */
131#endif /* _LINUX_DM_DIRTY_LOG_H */