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