| 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; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | void *context; | 
|  | 25 | }; | 
|  | 26 |  | 
| Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 27 | struct dm_dirty_log_type { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | const char *name; | 
|  | 29 | struct module *module; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 |  | 
| Mike Snitzer | ec44ab9 | 2009-04-02 19:55:30 +0100 | [diff] [blame] | 31 | /* For internal device-mapper use */ | 
|  | 32 | struct list_head list; | 
|  | 33 |  | 
| Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 34 | int (*ctr)(struct dm_dirty_log *log, struct dm_target *ti, | 
|  | 35 | unsigned argc, char **argv); | 
|  | 36 | void (*dtr)(struct dm_dirty_log *log); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 |  | 
|  | 38 | /* | 
|  | 39 | * There are times when we don't want the log to touch | 
|  | 40 | * the disk. | 
|  | 41 | */ | 
| Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 42 | int (*presuspend)(struct dm_dirty_log *log); | 
|  | 43 | int (*postsuspend)(struct dm_dirty_log *log); | 
|  | 44 | int (*resume)(struct dm_dirty_log *log); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 |  | 
|  | 46 | /* | 
|  | 47 | * Retrieves the smallest size of region that the log can | 
|  | 48 | * deal with. | 
|  | 49 | */ | 
| Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 50 | uint32_t (*get_region_size)(struct dm_dirty_log *log); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 |  | 
| Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 52 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | * A predicate to say whether a region is clean or not. | 
|  | 54 | * May block. | 
|  | 55 | */ | 
| Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 56 | int (*is_clean)(struct dm_dirty_log *log, region_t region); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 |  | 
|  | 58 | /* | 
|  | 59 | *  Returns: 0, 1, -EWOULDBLOCK, < 0 | 
|  | 60 | * | 
|  | 61 | * A predicate function to check the area given by | 
|  | 62 | * [sector, sector + len) is in sync. | 
|  | 63 | * | 
|  | 64 | * If -EWOULDBLOCK is returned the state of the region is | 
|  | 65 | * unknown, typically this will result in a read being | 
|  | 66 | * passed to a daemon to deal with, since a daemon is | 
|  | 67 | * allowed to block. | 
|  | 68 | */ | 
| Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 69 | int (*in_sync)(struct dm_dirty_log *log, region_t region, | 
|  | 70 | int can_block); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 |  | 
|  | 72 | /* | 
|  | 73 | * Flush the current log state (eg, to disk).  This | 
|  | 74 | * function may block. | 
|  | 75 | */ | 
| Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 76 | int (*flush)(struct dm_dirty_log *log); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 |  | 
|  | 78 | /* | 
|  | 79 | * Mark an area as clean or dirty.  These functions may | 
|  | 80 | * block, though for performance reasons blocking should | 
|  | 81 | * be extremely rare (eg, allocating another chunk of | 
|  | 82 | * memory for some reason). | 
|  | 83 | */ | 
| Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 84 | void (*mark_region)(struct dm_dirty_log *log, region_t region); | 
|  | 85 | void (*clear_region)(struct dm_dirty_log *log, region_t region); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 |  | 
|  | 87 | /* | 
|  | 88 | * Returns: <0 (error), 0 (no region), 1 (region) | 
|  | 89 | * | 
|  | 90 | * The mirrord will need perform recovery on regions of | 
|  | 91 | * the mirror that are in the NOSYNC state.  This | 
|  | 92 | * function asks the log to tell the caller about the | 
|  | 93 | * next region that this machine should recover. | 
|  | 94 | * | 
|  | 95 | * Do not confuse this function with 'in_sync()', one | 
|  | 96 | * tells you if an area is synchronised, the other | 
|  | 97 | * assigns recovery work. | 
|  | 98 | */ | 
| Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 99 | int (*get_resync_work)(struct dm_dirty_log *log, region_t *region); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 |  | 
|  | 101 | /* | 
| Jonathan E Brassow | f3ee6b2 | 2006-12-08 02:41:11 -0800 | [diff] [blame] | 102 | * This notifies the log that the resync status of a region | 
|  | 103 | * has changed.  It also clears the region from the recovering | 
|  | 104 | * list (if present). | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | */ | 
| Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 106 | void (*set_region_sync)(struct dm_dirty_log *log, | 
| Jonathan E Brassow | f3ee6b2 | 2006-12-08 02:41:11 -0800 | [diff] [blame] | 107 | region_t region, int in_sync); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 |  | 
| Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 109 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | * Returns the number of regions that are in sync. | 
| Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 111 | */ | 
|  | 112 | region_t (*get_sync_count)(struct dm_dirty_log *log); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 |  | 
|  | 114 | /* | 
|  | 115 | * Support function for mirror status requests. | 
|  | 116 | */ | 
| Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 117 | int (*status)(struct dm_dirty_log *log, status_type_t status_type, | 
|  | 118 | char *result, unsigned maxlen); | 
| Jonathan Brassow | 7513c2a | 2009-04-02 19:55:30 +0100 | [diff] [blame] | 119 |  | 
|  | 120 | /* | 
|  | 121 | * is_remote_recovering is necessary for cluster mirroring. It provides | 
|  | 122 | * a way to detect recovery on another node, so we aren't writing | 
|  | 123 | * concurrently.  This function is likely to block (when a cluster log | 
|  | 124 | * is used). | 
|  | 125 | * | 
|  | 126 | * Returns: 0, 1 | 
|  | 127 | */ | 
|  | 128 | int (*is_remote_recovering)(struct dm_dirty_log *log, region_t region); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | }; | 
|  | 130 |  | 
| Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 131 | int dm_dirty_log_type_register(struct dm_dirty_log_type *type); | 
|  | 132 | int dm_dirty_log_type_unregister(struct dm_dirty_log_type *type); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 |  | 
|  | 134 | /* | 
|  | 135 | * Make sure you use these two functions, rather than calling | 
|  | 136 | * type->constructor/destructor() directly. | 
|  | 137 | */ | 
| Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 138 | struct dm_dirty_log *dm_dirty_log_create(const char *type_name, | 
|  | 139 | struct dm_target *ti, | 
|  | 140 | unsigned argc, char **argv); | 
|  | 141 | void dm_dirty_log_destroy(struct dm_dirty_log *log); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 |  | 
| Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 143 | #endif	/* __KERNEL__ */ | 
|  | 144 | #endif	/* _LINUX_DM_DIRTY_LOG_H */ |