Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2003 Sistina Software |
Heinz Mauelshagen | b7fd54a | 2008-04-24 21:43:06 +0100 | [diff] [blame] | 3 | * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is released under the LGPL. |
| 6 | */ |
| 7 | |
| 8 | #include <linux/init.h> |
| 9 | #include <linux/slab.h> |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/vmalloc.h> |
| 12 | |
| 13 | #include "dm-log.h" |
| 14 | #include "dm-io.h" |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 15 | #include "dm.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
Heinz Mauelshagen | b7fd54a | 2008-04-24 21:43:06 +0100 | [diff] [blame] | 17 | #define DM_MSG_PREFIX "dirty region log" |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | static LIST_HEAD(_log_types); |
| 20 | static DEFINE_SPINLOCK(_lock); |
| 21 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 22 | int dm_dirty_log_type_register(struct dm_dirty_log_type *type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | { |
| 24 | spin_lock(&_lock); |
| 25 | type->use_count = 0; |
| 26 | list_add(&type->list, &_log_types); |
| 27 | spin_unlock(&_lock); |
| 28 | |
| 29 | return 0; |
| 30 | } |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 31 | EXPORT_SYMBOL(dm_dirty_log_type_register); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 33 | int dm_dirty_log_type_unregister(struct dm_dirty_log_type *type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { |
| 35 | spin_lock(&_lock); |
| 36 | |
| 37 | if (type->use_count) |
| 38 | DMWARN("Attempt to unregister a log type that is still in use"); |
| 39 | else |
| 40 | list_del(&type->list); |
| 41 | |
| 42 | spin_unlock(&_lock); |
| 43 | |
| 44 | return 0; |
| 45 | } |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 46 | EXPORT_SYMBOL(dm_dirty_log_type_unregister); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 48 | static struct dm_dirty_log_type *_get_type(const char *type_name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 50 | struct dm_dirty_log_type *type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | spin_lock(&_lock); |
| 53 | list_for_each_entry (type, &_log_types, list) |
| 54 | if (!strcmp(type_name, type->name)) { |
| 55 | if (!type->use_count && !try_module_get(type->module)){ |
| 56 | spin_unlock(&_lock); |
| 57 | return NULL; |
| 58 | } |
| 59 | type->use_count++; |
| 60 | spin_unlock(&_lock); |
| 61 | return type; |
| 62 | } |
| 63 | |
| 64 | spin_unlock(&_lock); |
| 65 | return NULL; |
| 66 | } |
| 67 | |
Jonathan Brassow | fb8b284 | 2008-02-08 02:11:19 +0000 | [diff] [blame] | 68 | /* |
| 69 | * get_type |
| 70 | * @type_name |
| 71 | * |
| 72 | * Attempt to retrieve the dirty_log_type by name. If not already |
| 73 | * available, attempt to load the appropriate module. |
| 74 | * |
| 75 | * Log modules are named "dm-log-" followed by the 'type_name'. |
| 76 | * Modules may contain multiple types. |
| 77 | * This function will first try the module "dm-log-<type_name>", |
| 78 | * then truncate 'type_name' on the last '-' and try again. |
| 79 | * |
| 80 | * For example, if type_name was "clustered-disk", it would search |
| 81 | * 'dm-log-clustered-disk' then 'dm-log-clustered'. |
| 82 | * |
| 83 | * Returns: dirty_log_type* on success, NULL on failure |
| 84 | */ |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 85 | static struct dm_dirty_log_type *get_type(const char *type_name) |
Jonathan Brassow | fb8b284 | 2008-02-08 02:11:19 +0000 | [diff] [blame] | 86 | { |
| 87 | char *p, *type_name_dup; |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 88 | struct dm_dirty_log_type *type; |
Jonathan Brassow | fb8b284 | 2008-02-08 02:11:19 +0000 | [diff] [blame] | 89 | |
| 90 | type = _get_type(type_name); |
| 91 | if (type) |
| 92 | return type; |
| 93 | |
| 94 | type_name_dup = kstrdup(type_name, GFP_KERNEL); |
| 95 | if (!type_name_dup) { |
| 96 | DMWARN("No memory left to attempt log module load for \"%s\"", |
| 97 | type_name); |
| 98 | return NULL; |
| 99 | } |
| 100 | |
| 101 | while (request_module("dm-log-%s", type_name_dup) || |
| 102 | !(type = _get_type(type_name))) { |
| 103 | p = strrchr(type_name_dup, '-'); |
| 104 | if (!p) |
| 105 | break; |
| 106 | p[0] = '\0'; |
| 107 | } |
| 108 | |
| 109 | if (!type) |
| 110 | DMWARN("Module for logging type \"%s\" not found.", type_name); |
| 111 | |
| 112 | kfree(type_name_dup); |
| 113 | |
| 114 | return type; |
| 115 | } |
| 116 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 117 | static void put_type(struct dm_dirty_log_type *type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | { |
| 119 | spin_lock(&_lock); |
| 120 | if (!--type->use_count) |
| 121 | module_put(type->module); |
| 122 | spin_unlock(&_lock); |
| 123 | } |
| 124 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 125 | struct dm_dirty_log *dm_dirty_log_create(const char *type_name, |
| 126 | struct dm_target *ti, |
| 127 | unsigned int argc, char **argv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | { |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 129 | struct dm_dirty_log_type *type; |
| 130 | struct dm_dirty_log *log; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
| 132 | log = kmalloc(sizeof(*log), GFP_KERNEL); |
| 133 | if (!log) |
| 134 | return NULL; |
| 135 | |
| 136 | type = get_type(type_name); |
| 137 | if (!type) { |
| 138 | kfree(log); |
| 139 | return NULL; |
| 140 | } |
| 141 | |
| 142 | log->type = type; |
| 143 | if (type->ctr(log, ti, argc, argv)) { |
| 144 | kfree(log); |
| 145 | put_type(type); |
| 146 | return NULL; |
| 147 | } |
| 148 | |
| 149 | return log; |
| 150 | } |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 151 | EXPORT_SYMBOL(dm_dirty_log_create); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 153 | void dm_dirty_log_destroy(struct dm_dirty_log *log) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
| 155 | log->type->dtr(log); |
| 156 | put_type(log->type); |
| 157 | kfree(log); |
| 158 | } |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 159 | EXPORT_SYMBOL(dm_dirty_log_destroy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
| 161 | /*----------------------------------------------------------------- |
| 162 | * Persistent and core logs share a lot of their implementation. |
| 163 | * FIXME: need a reload method to be called from a resume |
| 164 | *---------------------------------------------------------------*/ |
| 165 | /* |
| 166 | * Magic for persistent mirrors: "MiRr" |
| 167 | */ |
| 168 | #define MIRROR_MAGIC 0x4D695272 |
| 169 | |
| 170 | /* |
| 171 | * The on-disk version of the metadata. |
| 172 | */ |
Patrick Caulfield | a4fc471 | 2006-02-01 03:04:51 -0800 | [diff] [blame] | 173 | #define MIRROR_DISK_VERSION 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | #define LOG_OFFSET 2 |
| 175 | |
| 176 | struct log_header { |
| 177 | uint32_t magic; |
| 178 | |
| 179 | /* |
| 180 | * Simple, incrementing version. no backward |
| 181 | * compatibility. |
| 182 | */ |
| 183 | uint32_t version; |
| 184 | sector_t nr_regions; |
| 185 | }; |
| 186 | |
| 187 | struct log_c { |
| 188 | struct dm_target *ti; |
| 189 | int touched; |
| 190 | uint32_t region_size; |
| 191 | unsigned int region_count; |
| 192 | region_t sync_count; |
| 193 | |
| 194 | unsigned bitset_uint32_count; |
| 195 | uint32_t *clean_bits; |
| 196 | uint32_t *sync_bits; |
| 197 | uint32_t *recovering_bits; /* FIXME: this seems excessive */ |
| 198 | |
| 199 | int sync_search; |
| 200 | |
| 201 | /* Resync flag */ |
| 202 | enum sync { |
| 203 | DEFAULTSYNC, /* Synchronize if necessary */ |
| 204 | NOSYNC, /* Devices known to be already in sync */ |
| 205 | FORCESYNC, /* Force a sync to happen */ |
| 206 | } sync; |
| 207 | |
Heinz Mauelshagen | 5d234d1 | 2007-05-09 02:33:03 -0700 | [diff] [blame] | 208 | struct dm_io_request io_req; |
| 209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | /* |
| 211 | * Disk log fields |
| 212 | */ |
Jonathan E Brassow | 01d03a6 | 2007-05-09 02:32:57 -0700 | [diff] [blame] | 213 | int log_dev_failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | struct dm_dev *log_dev; |
| 215 | struct log_header header; |
| 216 | |
Heinz Mauelshagen | 22a1ceb | 2008-04-24 21:43:17 +0100 | [diff] [blame] | 217 | struct dm_io_region header_location; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | struct log_header *disk_header; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | }; |
| 220 | |
| 221 | /* |
| 222 | * The touched member needs to be updated every time we access |
| 223 | * one of the bitsets. |
| 224 | */ |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 225 | static inline int log_test_bit(uint32_t *bs, unsigned bit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | { |
Patrick Caulfield | a4fc471 | 2006-02-01 03:04:51 -0800 | [diff] [blame] | 227 | return ext2_test_bit(bit, (unsigned long *) bs) ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | static inline void log_set_bit(struct log_c *l, |
| 231 | uint32_t *bs, unsigned bit) |
| 232 | { |
Patrick Caulfield | a4fc471 | 2006-02-01 03:04:51 -0800 | [diff] [blame] | 233 | ext2_set_bit(bit, (unsigned long *) bs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | l->touched = 1; |
| 235 | } |
| 236 | |
| 237 | static inline void log_clear_bit(struct log_c *l, |
| 238 | uint32_t *bs, unsigned bit) |
| 239 | { |
Patrick Caulfield | a4fc471 | 2006-02-01 03:04:51 -0800 | [diff] [blame] | 240 | ext2_clear_bit(bit, (unsigned long *) bs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | l->touched = 1; |
| 242 | } |
| 243 | |
| 244 | /*---------------------------------------------------------------- |
| 245 | * Header IO |
| 246 | *--------------------------------------------------------------*/ |
| 247 | static void header_to_disk(struct log_header *core, struct log_header *disk) |
| 248 | { |
| 249 | disk->magic = cpu_to_le32(core->magic); |
| 250 | disk->version = cpu_to_le32(core->version); |
| 251 | disk->nr_regions = cpu_to_le64(core->nr_regions); |
| 252 | } |
| 253 | |
| 254 | static void header_from_disk(struct log_header *core, struct log_header *disk) |
| 255 | { |
| 256 | core->magic = le32_to_cpu(disk->magic); |
| 257 | core->version = le32_to_cpu(disk->version); |
| 258 | core->nr_regions = le64_to_cpu(disk->nr_regions); |
| 259 | } |
| 260 | |
Heinz Mauelshagen | 5d234d1 | 2007-05-09 02:33:03 -0700 | [diff] [blame] | 261 | static int rw_header(struct log_c *lc, int rw) |
| 262 | { |
| 263 | lc->io_req.bi_rw = rw; |
| 264 | lc->io_req.mem.ptr.vma = lc->disk_header; |
| 265 | lc->io_req.notify.fn = NULL; |
| 266 | |
| 267 | return dm_io(&lc->io_req, 1, &lc->header_location, NULL); |
| 268 | } |
| 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | static int read_header(struct log_c *log) |
| 271 | { |
| 272 | int r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
Heinz Mauelshagen | 5d234d1 | 2007-05-09 02:33:03 -0700 | [diff] [blame] | 274 | r = rw_header(log, READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | if (r) |
| 276 | return r; |
| 277 | |
| 278 | header_from_disk(&log->header, log->disk_header); |
| 279 | |
| 280 | /* New log required? */ |
| 281 | if (log->sync != DEFAULTSYNC || log->header.magic != MIRROR_MAGIC) { |
| 282 | log->header.magic = MIRROR_MAGIC; |
| 283 | log->header.version = MIRROR_DISK_VERSION; |
| 284 | log->header.nr_regions = 0; |
| 285 | } |
| 286 | |
Patrick Caulfield | a4fc471 | 2006-02-01 03:04:51 -0800 | [diff] [blame] | 287 | #ifdef __LITTLE_ENDIAN |
| 288 | if (log->header.version == 1) |
| 289 | log->header.version = 2; |
| 290 | #endif |
| 291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | if (log->header.version != MIRROR_DISK_VERSION) { |
| 293 | DMWARN("incompatible disk log version"); |
| 294 | return -EINVAL; |
| 295 | } |
| 296 | |
| 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | static inline int write_header(struct log_c *log) |
| 301 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | header_to_disk(&log->header, log->disk_header); |
Heinz Mauelshagen | 5d234d1 | 2007-05-09 02:33:03 -0700 | [diff] [blame] | 303 | return rw_header(log, WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | /*---------------------------------------------------------------- |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | * core log constructor/destructor |
| 308 | * |
| 309 | * argv contains region_size followed optionally by [no]sync |
| 310 | *--------------------------------------------------------------*/ |
| 311 | #define BYTE_SHIFT 3 |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 312 | static int create_log_context(struct dm_dirty_log *log, struct dm_target *ti, |
Alasdair G Kergon | b7cca19 | 2006-06-26 00:27:29 -0700 | [diff] [blame] | 313 | unsigned int argc, char **argv, |
| 314 | struct dm_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | { |
| 316 | enum sync sync = DEFAULTSYNC; |
| 317 | |
| 318 | struct log_c *lc; |
| 319 | uint32_t region_size; |
| 320 | unsigned int region_count; |
Alasdair G Kergon | b7cca19 | 2006-06-26 00:27:29 -0700 | [diff] [blame] | 321 | size_t bitset_size, buf_size; |
Heinz Mauelshagen | 5d234d1 | 2007-05-09 02:33:03 -0700 | [diff] [blame] | 322 | int r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
| 324 | if (argc < 1 || argc > 2) { |
Heinz Mauelshagen | b7fd54a | 2008-04-24 21:43:06 +0100 | [diff] [blame] | 325 | DMWARN("wrong number of arguments to dirty region log"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | return -EINVAL; |
| 327 | } |
| 328 | |
| 329 | if (argc > 1) { |
| 330 | if (!strcmp(argv[1], "sync")) |
| 331 | sync = FORCESYNC; |
| 332 | else if (!strcmp(argv[1], "nosync")) |
| 333 | sync = NOSYNC; |
| 334 | else { |
Heinz Mauelshagen | b7fd54a | 2008-04-24 21:43:06 +0100 | [diff] [blame] | 335 | DMWARN("unrecognised sync argument to " |
| 336 | "dirty region log: %s", argv[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | return -EINVAL; |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | if (sscanf(argv[0], "%u", ®ion_size) != 1) { |
| 342 | DMWARN("invalid region size string"); |
| 343 | return -EINVAL; |
| 344 | } |
| 345 | |
| 346 | region_count = dm_sector_div_up(ti->len, region_size); |
| 347 | |
| 348 | lc = kmalloc(sizeof(*lc), GFP_KERNEL); |
| 349 | if (!lc) { |
| 350 | DMWARN("couldn't allocate core log"); |
| 351 | return -ENOMEM; |
| 352 | } |
| 353 | |
| 354 | lc->ti = ti; |
| 355 | lc->touched = 0; |
| 356 | lc->region_size = region_size; |
| 357 | lc->region_count = region_count; |
| 358 | lc->sync = sync; |
| 359 | |
| 360 | /* |
Alasdair G Kergon | 0e56822 | 2005-11-21 21:32:34 -0800 | [diff] [blame] | 361 | * Work out how many "unsigned long"s we need to hold the bitset. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | */ |
| 363 | bitset_size = dm_round_up(region_count, |
Alasdair G Kergon | 29121bd | 2006-06-26 00:27:29 -0700 | [diff] [blame] | 364 | sizeof(*lc->clean_bits) << BYTE_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | bitset_size >>= BYTE_SHIFT; |
| 366 | |
Alasdair G Kergon | 29121bd | 2006-06-26 00:27:29 -0700 | [diff] [blame] | 367 | lc->bitset_uint32_count = bitset_size / sizeof(*lc->clean_bits); |
Alasdair G Kergon | b7cca19 | 2006-06-26 00:27:29 -0700 | [diff] [blame] | 368 | |
| 369 | /* |
| 370 | * Disk log? |
| 371 | */ |
| 372 | if (!dev) { |
| 373 | lc->clean_bits = vmalloc(bitset_size); |
| 374 | if (!lc->clean_bits) { |
| 375 | DMWARN("couldn't allocate clean bitset"); |
| 376 | kfree(lc); |
| 377 | return -ENOMEM; |
| 378 | } |
| 379 | lc->disk_header = NULL; |
| 380 | } else { |
| 381 | lc->log_dev = dev; |
Jonathan E Brassow | 01d03a6 | 2007-05-09 02:32:57 -0700 | [diff] [blame] | 382 | lc->log_dev_failed = 0; |
Alasdair G Kergon | b7cca19 | 2006-06-26 00:27:29 -0700 | [diff] [blame] | 383 | lc->header_location.bdev = lc->log_dev->bdev; |
| 384 | lc->header_location.sector = 0; |
| 385 | |
| 386 | /* |
| 387 | * Buffer holds both header and bitset. |
| 388 | */ |
| 389 | buf_size = dm_round_up((LOG_OFFSET << SECTOR_SHIFT) + |
| 390 | bitset_size, ti->limits.hardsect_size); |
| 391 | lc->header_location.count = buf_size >> SECTOR_SHIFT; |
Heinz Mauelshagen | 5d234d1 | 2007-05-09 02:33:03 -0700 | [diff] [blame] | 392 | lc->io_req.mem.type = DM_IO_VMA; |
| 393 | lc->io_req.client = dm_io_client_create(dm_div_up(buf_size, |
| 394 | PAGE_SIZE)); |
| 395 | if (IS_ERR(lc->io_req.client)) { |
| 396 | r = PTR_ERR(lc->io_req.client); |
| 397 | DMWARN("couldn't allocate disk io client"); |
| 398 | kfree(lc); |
| 399 | return -ENOMEM; |
| 400 | } |
Alasdair G Kergon | b7cca19 | 2006-06-26 00:27:29 -0700 | [diff] [blame] | 401 | |
| 402 | lc->disk_header = vmalloc(buf_size); |
| 403 | if (!lc->disk_header) { |
| 404 | DMWARN("couldn't allocate disk log buffer"); |
| 405 | kfree(lc); |
| 406 | return -ENOMEM; |
| 407 | } |
| 408 | |
| 409 | lc->clean_bits = (void *)lc->disk_header + |
| 410 | (LOG_OFFSET << SECTOR_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | } |
Alasdair G Kergon | b7cca19 | 2006-06-26 00:27:29 -0700 | [diff] [blame] | 412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | memset(lc->clean_bits, -1, bitset_size); |
| 414 | |
| 415 | lc->sync_bits = vmalloc(bitset_size); |
| 416 | if (!lc->sync_bits) { |
| 417 | DMWARN("couldn't allocate sync bitset"); |
Alasdair G Kergon | b7cca19 | 2006-06-26 00:27:29 -0700 | [diff] [blame] | 418 | if (!dev) |
| 419 | vfree(lc->clean_bits); |
| 420 | vfree(lc->disk_header); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | kfree(lc); |
| 422 | return -ENOMEM; |
| 423 | } |
| 424 | memset(lc->sync_bits, (sync == NOSYNC) ? -1 : 0, bitset_size); |
| 425 | lc->sync_count = (sync == NOSYNC) ? region_count : 0; |
| 426 | |
| 427 | lc->recovering_bits = vmalloc(bitset_size); |
| 428 | if (!lc->recovering_bits) { |
| 429 | DMWARN("couldn't allocate sync bitset"); |
| 430 | vfree(lc->sync_bits); |
Alasdair G Kergon | b7cca19 | 2006-06-26 00:27:29 -0700 | [diff] [blame] | 431 | if (!dev) |
| 432 | vfree(lc->clean_bits); |
| 433 | vfree(lc->disk_header); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | kfree(lc); |
| 435 | return -ENOMEM; |
| 436 | } |
| 437 | memset(lc->recovering_bits, 0, bitset_size); |
| 438 | lc->sync_search = 0; |
| 439 | log->context = lc; |
Alasdair G Kergon | b7cca19 | 2006-06-26 00:27:29 -0700 | [diff] [blame] | 440 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | return 0; |
| 442 | } |
| 443 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 444 | static int core_ctr(struct dm_dirty_log *log, struct dm_target *ti, |
Alasdair G Kergon | b7cca19 | 2006-06-26 00:27:29 -0700 | [diff] [blame] | 445 | unsigned int argc, char **argv) |
| 446 | { |
| 447 | return create_log_context(log, ti, argc, argv, NULL); |
| 448 | } |
| 449 | |
| 450 | static void destroy_log_context(struct log_c *lc) |
| 451 | { |
| 452 | vfree(lc->sync_bits); |
| 453 | vfree(lc->recovering_bits); |
| 454 | kfree(lc); |
| 455 | } |
| 456 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 457 | static void core_dtr(struct dm_dirty_log *log) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | { |
| 459 | struct log_c *lc = (struct log_c *) log->context; |
Alasdair G Kergon | b7cca19 | 2006-06-26 00:27:29 -0700 | [diff] [blame] | 460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | vfree(lc->clean_bits); |
Alasdair G Kergon | b7cca19 | 2006-06-26 00:27:29 -0700 | [diff] [blame] | 462 | destroy_log_context(lc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | /*---------------------------------------------------------------- |
| 466 | * disk log constructor/destructor |
| 467 | * |
| 468 | * argv contains log_device region_size followed optionally by [no]sync |
| 469 | *--------------------------------------------------------------*/ |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 470 | static int disk_ctr(struct dm_dirty_log *log, struct dm_target *ti, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | unsigned int argc, char **argv) |
| 472 | { |
| 473 | int r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | struct dm_dev *dev; |
| 475 | |
| 476 | if (argc < 2 || argc > 3) { |
Heinz Mauelshagen | b7fd54a | 2008-04-24 21:43:06 +0100 | [diff] [blame] | 477 | DMWARN("wrong number of arguments to disk dirty region log"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | return -EINVAL; |
| 479 | } |
| 480 | |
| 481 | r = dm_get_device(ti, argv[0], 0, 0 /* FIXME */, |
| 482 | FMODE_READ | FMODE_WRITE, &dev); |
| 483 | if (r) |
| 484 | return r; |
| 485 | |
Alasdair G Kergon | b7cca19 | 2006-06-26 00:27:29 -0700 | [diff] [blame] | 486 | r = create_log_context(log, ti, argc - 1, argv + 1, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | if (r) { |
| 488 | dm_put_device(ti, dev); |
| 489 | return r; |
| 490 | } |
| 491 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 495 | static void disk_dtr(struct dm_dirty_log *log) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | { |
| 497 | struct log_c *lc = (struct log_c *) log->context; |
Alasdair G Kergon | b7cca19 | 2006-06-26 00:27:29 -0700 | [diff] [blame] | 498 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | dm_put_device(lc->ti, lc->log_dev); |
| 500 | vfree(lc->disk_header); |
Heinz Mauelshagen | 5d234d1 | 2007-05-09 02:33:03 -0700 | [diff] [blame] | 501 | dm_io_client_destroy(lc->io_req.client); |
Alasdair G Kergon | b7cca19 | 2006-06-26 00:27:29 -0700 | [diff] [blame] | 502 | destroy_log_context(lc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | static int count_bits32(uint32_t *addr, unsigned size) |
| 506 | { |
| 507 | int count = 0, i; |
| 508 | |
| 509 | for (i = 0; i < size; i++) { |
| 510 | count += hweight32(*(addr+i)); |
| 511 | } |
| 512 | return count; |
| 513 | } |
| 514 | |
Jonathan E Brassow | 01d03a6 | 2007-05-09 02:32:57 -0700 | [diff] [blame] | 515 | static void fail_log_device(struct log_c *lc) |
| 516 | { |
| 517 | if (lc->log_dev_failed) |
| 518 | return; |
| 519 | |
| 520 | lc->log_dev_failed = 1; |
| 521 | dm_table_event(lc->ti->table); |
| 522 | } |
| 523 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 524 | static int disk_resume(struct dm_dirty_log *log) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | { |
| 526 | int r; |
| 527 | unsigned i; |
| 528 | struct log_c *lc = (struct log_c *) log->context; |
| 529 | size_t size = lc->bitset_uint32_count * sizeof(uint32_t); |
| 530 | |
| 531 | /* read the disk header */ |
| 532 | r = read_header(lc); |
Jonathan E Brassow | 01d03a6 | 2007-05-09 02:32:57 -0700 | [diff] [blame] | 533 | if (r) { |
Heinz Mauelshagen | b7fd54a | 2008-04-24 21:43:06 +0100 | [diff] [blame] | 534 | DMWARN("%s: Failed to read header on dirty region log device", |
Jonathan E Brassow | 01d03a6 | 2007-05-09 02:32:57 -0700 | [diff] [blame] | 535 | lc->log_dev->name); |
| 536 | fail_log_device(lc); |
Jonathan Brassow | ba8b45c | 2007-05-09 02:33:08 -0700 | [diff] [blame] | 537 | /* |
| 538 | * If the log device cannot be read, we must assume |
| 539 | * all regions are out-of-sync. If we simply return |
| 540 | * here, the state will be uninitialized and could |
| 541 | * lead us to return 'in-sync' status for regions |
| 542 | * that are actually 'out-of-sync'. |
| 543 | */ |
| 544 | lc->header.nr_regions = 0; |
Jonathan E Brassow | 01d03a6 | 2007-05-09 02:32:57 -0700 | [diff] [blame] | 545 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
Alasdair G Kergon | 8a835f1 | 2006-06-26 00:27:30 -0700 | [diff] [blame] | 547 | /* set or clear any new bits -- device has grown */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | if (lc->sync == NOSYNC) |
| 549 | for (i = lc->header.nr_regions; i < lc->region_count; i++) |
| 550 | /* FIXME: amazingly inefficient */ |
| 551 | log_set_bit(lc, lc->clean_bits, i); |
| 552 | else |
| 553 | for (i = lc->header.nr_regions; i < lc->region_count; i++) |
| 554 | /* FIXME: amazingly inefficient */ |
| 555 | log_clear_bit(lc, lc->clean_bits, i); |
| 556 | |
Alasdair G Kergon | 8a835f1 | 2006-06-26 00:27:30 -0700 | [diff] [blame] | 557 | /* clear any old bits -- device has shrunk */ |
| 558 | for (i = lc->region_count; i % (sizeof(*lc->clean_bits) << BYTE_SHIFT); i++) |
| 559 | log_clear_bit(lc, lc->clean_bits, i); |
| 560 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | /* copy clean across to sync */ |
| 562 | memcpy(lc->sync_bits, lc->clean_bits, size); |
| 563 | lc->sync_count = count_bits32(lc->clean_bits, lc->bitset_uint32_count); |
Jonathan E Brassow | 88b20a1 | 2006-12-08 02:41:12 -0800 | [diff] [blame] | 564 | lc->sync_search = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | /* set the correct number of regions in the header */ |
| 567 | lc->header.nr_regions = lc->region_count; |
| 568 | |
| 569 | /* write the new header */ |
Jonathan E Brassow | 01d03a6 | 2007-05-09 02:32:57 -0700 | [diff] [blame] | 570 | r = write_header(lc); |
| 571 | if (r) { |
Heinz Mauelshagen | b7fd54a | 2008-04-24 21:43:06 +0100 | [diff] [blame] | 572 | DMWARN("%s: Failed to write header on dirty region log device", |
Jonathan E Brassow | 01d03a6 | 2007-05-09 02:32:57 -0700 | [diff] [blame] | 573 | lc->log_dev->name); |
| 574 | fail_log_device(lc); |
| 575 | } |
| 576 | |
| 577 | return r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 580 | static uint32_t core_get_region_size(struct dm_dirty_log *log) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | { |
| 582 | struct log_c *lc = (struct log_c *) log->context; |
| 583 | return lc->region_size; |
| 584 | } |
| 585 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 586 | static int core_resume(struct dm_dirty_log *log) |
Jonathan E Brassow | 88b20a1 | 2006-12-08 02:41:12 -0800 | [diff] [blame] | 587 | { |
| 588 | struct log_c *lc = (struct log_c *) log->context; |
| 589 | lc->sync_search = 0; |
| 590 | return 0; |
| 591 | } |
| 592 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 593 | static int core_is_clean(struct dm_dirty_log *log, region_t region) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | { |
| 595 | struct log_c *lc = (struct log_c *) log->context; |
| 596 | return log_test_bit(lc->clean_bits, region); |
| 597 | } |
| 598 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 599 | static int core_in_sync(struct dm_dirty_log *log, region_t region, int block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | { |
| 601 | struct log_c *lc = (struct log_c *) log->context; |
| 602 | return log_test_bit(lc->sync_bits, region); |
| 603 | } |
| 604 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 605 | static int core_flush(struct dm_dirty_log *log) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | { |
| 607 | /* no op */ |
| 608 | return 0; |
| 609 | } |
| 610 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 611 | static int disk_flush(struct dm_dirty_log *log) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | { |
| 613 | int r; |
| 614 | struct log_c *lc = (struct log_c *) log->context; |
| 615 | |
| 616 | /* only write if the log has changed */ |
| 617 | if (!lc->touched) |
| 618 | return 0; |
| 619 | |
Kevin Corry | 702ca6f | 2006-06-26 00:27:28 -0700 | [diff] [blame] | 620 | r = write_header(lc); |
Jonathan E Brassow | 01d03a6 | 2007-05-09 02:32:57 -0700 | [diff] [blame] | 621 | if (r) |
| 622 | fail_log_device(lc); |
| 623 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | lc->touched = 0; |
| 625 | |
| 626 | return r; |
| 627 | } |
| 628 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 629 | static void core_mark_region(struct dm_dirty_log *log, region_t region) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | { |
| 631 | struct log_c *lc = (struct log_c *) log->context; |
| 632 | log_clear_bit(lc, lc->clean_bits, region); |
| 633 | } |
| 634 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 635 | static void core_clear_region(struct dm_dirty_log *log, region_t region) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | { |
| 637 | struct log_c *lc = (struct log_c *) log->context; |
| 638 | log_set_bit(lc, lc->clean_bits, region); |
| 639 | } |
| 640 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 641 | static int core_get_resync_work(struct dm_dirty_log *log, region_t *region) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | { |
| 643 | struct log_c *lc = (struct log_c *) log->context; |
| 644 | |
| 645 | if (lc->sync_search >= lc->region_count) |
| 646 | return 0; |
| 647 | |
| 648 | do { |
Stefan Bader | 1113a7e | 2006-02-02 14:28:07 -0800 | [diff] [blame] | 649 | *region = ext2_find_next_zero_bit( |
| 650 | (unsigned long *) lc->sync_bits, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | lc->region_count, |
| 652 | lc->sync_search); |
| 653 | lc->sync_search = *region + 1; |
| 654 | |
Darrick J. Wong | ac81b2e | 2006-01-06 00:20:11 -0800 | [diff] [blame] | 655 | if (*region >= lc->region_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | return 0; |
| 657 | |
| 658 | } while (log_test_bit(lc->recovering_bits, *region)); |
| 659 | |
| 660 | log_set_bit(lc, lc->recovering_bits, *region); |
| 661 | return 1; |
| 662 | } |
| 663 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 664 | static void core_set_region_sync(struct dm_dirty_log *log, region_t region, |
Jonathan E Brassow | f3ee6b2 | 2006-12-08 02:41:11 -0800 | [diff] [blame] | 665 | int in_sync) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | { |
| 667 | struct log_c *lc = (struct log_c *) log->context; |
| 668 | |
| 669 | log_clear_bit(lc, lc->recovering_bits, region); |
Jonathan E Brassow | f3ee6b2 | 2006-12-08 02:41:11 -0800 | [diff] [blame] | 670 | if (in_sync) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | log_set_bit(lc, lc->sync_bits, region); |
| 672 | lc->sync_count++; |
Jonathan E Brassow | f3ee6b2 | 2006-12-08 02:41:11 -0800 | [diff] [blame] | 673 | } else if (log_test_bit(lc->sync_bits, region)) { |
| 674 | lc->sync_count--; |
| 675 | log_clear_bit(lc, lc->sync_bits, region); |
| 676 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | } |
| 678 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 679 | static region_t core_get_sync_count(struct dm_dirty_log *log) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | { |
| 681 | struct log_c *lc = (struct log_c *) log->context; |
| 682 | |
| 683 | return lc->sync_count; |
| 684 | } |
| 685 | |
| 686 | #define DMEMIT_SYNC \ |
| 687 | if (lc->sync != DEFAULTSYNC) \ |
| 688 | DMEMIT("%ssync ", lc->sync == NOSYNC ? "no" : "") |
| 689 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 690 | static int core_status(struct dm_dirty_log *log, status_type_t status, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | char *result, unsigned int maxlen) |
| 692 | { |
| 693 | int sz = 0; |
| 694 | struct log_c *lc = log->context; |
| 695 | |
| 696 | switch(status) { |
| 697 | case STATUSTYPE_INFO: |
Jonathan E Brassow | 315dcc2 | 2007-05-09 02:32:58 -0700 | [diff] [blame] | 698 | DMEMIT("1 %s", log->type->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | break; |
| 700 | |
| 701 | case STATUSTYPE_TABLE: |
| 702 | DMEMIT("%s %u %u ", log->type->name, |
| 703 | lc->sync == DEFAULTSYNC ? 1 : 2, lc->region_size); |
| 704 | DMEMIT_SYNC; |
| 705 | } |
| 706 | |
| 707 | return sz; |
| 708 | } |
| 709 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 710 | static int disk_status(struct dm_dirty_log *log, status_type_t status, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | char *result, unsigned int maxlen) |
| 712 | { |
| 713 | int sz = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | struct log_c *lc = log->context; |
| 715 | |
| 716 | switch(status) { |
| 717 | case STATUSTYPE_INFO: |
Jonathan E Brassow | 315dcc2 | 2007-05-09 02:32:58 -0700 | [diff] [blame] | 718 | DMEMIT("3 %s %s %c", log->type->name, lc->log_dev->name, |
| 719 | lc->log_dev_failed ? 'D' : 'A'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | break; |
| 721 | |
| 722 | case STATUSTYPE_TABLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | DMEMIT("%s %u %s %u ", log->type->name, |
Jonathan E Brassow | 315dcc2 | 2007-05-09 02:32:58 -0700 | [diff] [blame] | 724 | lc->sync == DEFAULTSYNC ? 2 : 3, lc->log_dev->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | lc->region_size); |
| 726 | DMEMIT_SYNC; |
| 727 | } |
| 728 | |
| 729 | return sz; |
| 730 | } |
| 731 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 732 | static struct dm_dirty_log_type _core_type = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | .name = "core", |
| 734 | .module = THIS_MODULE, |
| 735 | .ctr = core_ctr, |
| 736 | .dtr = core_dtr, |
Jonathan E Brassow | 88b20a1 | 2006-12-08 02:41:12 -0800 | [diff] [blame] | 737 | .resume = core_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | .get_region_size = core_get_region_size, |
| 739 | .is_clean = core_is_clean, |
| 740 | .in_sync = core_in_sync, |
| 741 | .flush = core_flush, |
| 742 | .mark_region = core_mark_region, |
| 743 | .clear_region = core_clear_region, |
| 744 | .get_resync_work = core_get_resync_work, |
Jonathan E Brassow | f3ee6b2 | 2006-12-08 02:41:11 -0800 | [diff] [blame] | 745 | .set_region_sync = core_set_region_sync, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | .get_sync_count = core_get_sync_count, |
| 747 | .status = core_status, |
| 748 | }; |
| 749 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 750 | static struct dm_dirty_log_type _disk_type = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | .name = "disk", |
| 752 | .module = THIS_MODULE, |
| 753 | .ctr = disk_ctr, |
| 754 | .dtr = disk_dtr, |
Jonathan Brassow | 6b3df0d | 2007-10-19 22:47:57 +0100 | [diff] [blame] | 755 | .postsuspend = disk_flush, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | .resume = disk_resume, |
| 757 | .get_region_size = core_get_region_size, |
| 758 | .is_clean = core_is_clean, |
| 759 | .in_sync = core_in_sync, |
| 760 | .flush = disk_flush, |
| 761 | .mark_region = core_mark_region, |
| 762 | .clear_region = core_clear_region, |
| 763 | .get_resync_work = core_get_resync_work, |
Jonathan E Brassow | f3ee6b2 | 2006-12-08 02:41:11 -0800 | [diff] [blame] | 764 | .set_region_sync = core_set_region_sync, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | .get_sync_count = core_get_sync_count, |
| 766 | .status = disk_status, |
| 767 | }; |
| 768 | |
| 769 | int __init dm_dirty_log_init(void) |
| 770 | { |
| 771 | int r; |
| 772 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 773 | r = dm_dirty_log_type_register(&_core_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | if (r) |
| 775 | DMWARN("couldn't register core log"); |
| 776 | |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 777 | r = dm_dirty_log_type_register(&_disk_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | if (r) { |
| 779 | DMWARN("couldn't register disk type"); |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 780 | dm_dirty_log_type_unregister(&_core_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | return r; |
| 784 | } |
| 785 | |
Heinz Mauelshagen | 769aef3 | 2008-04-24 21:43:09 +0100 | [diff] [blame] | 786 | void __exit dm_dirty_log_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | { |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame^] | 788 | dm_dirty_log_type_unregister(&_disk_type); |
| 789 | dm_dirty_log_type_unregister(&_core_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | } |
| 791 | |
Heinz Mauelshagen | 769aef3 | 2008-04-24 21:43:09 +0100 | [diff] [blame] | 792 | module_init(dm_dirty_log_init); |
| 793 | module_exit(dm_dirty_log_exit); |
| 794 | |
| 795 | MODULE_DESCRIPTION(DM_NAME " dirty region log"); |
| 796 | MODULE_AUTHOR("Joe Thornber, Heinz Mauelshagen <dm-devel@redhat.com>"); |
| 797 | MODULE_LICENSE("GPL"); |