blob: 2da48a857cb9e9ce0e54d22ac65dd50e69858cf6 [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 struct list_head list;
29 const char *name;
30 struct module *module;
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010031 unsigned use_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010033 int (*ctr)(struct dm_dirty_log *log, struct dm_target *ti,
34 unsigned argc, char **argv);
35 void (*dtr)(struct dm_dirty_log *log);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37 /*
38 * There are times when we don't want the log to touch
39 * the disk.
40 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010041 int (*presuspend)(struct dm_dirty_log *log);
42 int (*postsuspend)(struct dm_dirty_log *log);
43 int (*resume)(struct dm_dirty_log *log);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45 /*
46 * Retrieves the smallest size of region that the log can
47 * deal with.
48 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010049 uint32_t (*get_region_size)(struct dm_dirty_log *log);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010051 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 * A predicate to say whether a region is clean or not.
53 * May block.
54 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010055 int (*is_clean)(struct dm_dirty_log *log, region_t region);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57 /*
58 * Returns: 0, 1, -EWOULDBLOCK, < 0
59 *
60 * A predicate function to check the area given by
61 * [sector, sector + len) is in sync.
62 *
63 * If -EWOULDBLOCK is returned the state of the region is
64 * unknown, typically this will result in a read being
65 * passed to a daemon to deal with, since a daemon is
66 * allowed to block.
67 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010068 int (*in_sync)(struct dm_dirty_log *log, region_t region,
69 int can_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71 /*
72 * Flush the current log state (eg, to disk). This
73 * function may block.
74 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010075 int (*flush)(struct dm_dirty_log *log);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77 /*
78 * Mark an area as clean or dirty. These functions may
79 * block, though for performance reasons blocking should
80 * be extremely rare (eg, allocating another chunk of
81 * memory for some reason).
82 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010083 void (*mark_region)(struct dm_dirty_log *log, region_t region);
84 void (*clear_region)(struct dm_dirty_log *log, region_t region);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86 /*
87 * Returns: <0 (error), 0 (no region), 1 (region)
88 *
89 * The mirrord will need perform recovery on regions of
90 * the mirror that are in the NOSYNC state. This
91 * function asks the log to tell the caller about the
92 * next region that this machine should recover.
93 *
94 * Do not confuse this function with 'in_sync()', one
95 * tells you if an area is synchronised, the other
96 * assigns recovery work.
97 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +010098 int (*get_resync_work)(struct dm_dirty_log *log, region_t *region);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100 /*
Jonathan E Brassowf3ee6b22006-12-08 02:41:11 -0800101 * This notifies the log that the resync status of a region
102 * has changed. It also clears the region from the recovering
103 * list (if present).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100105 void (*set_region_sync)(struct dm_dirty_log *log,
Jonathan E Brassowf3ee6b22006-12-08 02:41:11 -0800106 region_t region, int in_sync);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100108 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 * Returns the number of regions that are in sync.
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100110 */
111 region_t (*get_sync_count)(struct dm_dirty_log *log);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113 /*
114 * Support function for mirror status requests.
115 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100116 int (*status)(struct dm_dirty_log *log, status_type_t status_type,
117 char *result, unsigned maxlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118};
119
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100120int dm_dirty_log_type_register(struct dm_dirty_log_type *type);
121int dm_dirty_log_type_unregister(struct dm_dirty_log_type *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123/*
124 * Make sure you use these two functions, rather than calling
125 * type->constructor/destructor() directly.
126 */
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100127struct dm_dirty_log *dm_dirty_log_create(const char *type_name,
128 struct dm_target *ti,
129 unsigned argc, char **argv);
130void dm_dirty_log_destroy(struct dm_dirty_log *log);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Heinz Mauelshagen416cd172008-04-24 21:43:35 +0100132#endif /* __KERNEL__ */
133#endif /* _LINUX_DM_DIRTY_LOG_H */