Blame view

drivers/md/dm-log.c 20 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
  /*
   * Copyright (C) 2003 Sistina Software
b7fd54a70   Heinz Mauelshagen   dm log: generalis...
3
   * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
5
6
7
8
9
10
11
   *
   * This file is released under the LGPL.
   */
  
  #include <linux/init.h>
  #include <linux/slab.h>
  #include <linux/module.h>
  #include <linux/vmalloc.h>
a765e20ee   Alasdair G Kergon   dm: move include ...
12
13
  #include <linux/dm-io.h>
  #include <linux/dm-dirty-log.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
14

586e80e6e   Mikulas Patocka   dm: remove dm hea...
15
  #include <linux/device-mapper.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
16

b7fd54a70   Heinz Mauelshagen   dm log: generalis...
17
  #define DM_MSG_PREFIX "dirty region log"
72d948616   Alasdair G Kergon   [PATCH] dm: impro...
18

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
20
  static LIST_HEAD(_log_types);
  static DEFINE_SPINLOCK(_lock);
ec44ab9d6   Mike Snitzer   dm log: remove st...
21
  static struct dm_dirty_log_type *__find_dirty_log_type(const char *name)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22
  {
ec44ab9d6   Mike Snitzer   dm log: remove st...
23
  	struct dm_dirty_log_type *log_type;
2a23aa1dd   Jonathan Brassow   dm log: make modu...
24
25
  
  	list_for_each_entry(log_type, &_log_types, list)
ec44ab9d6   Mike Snitzer   dm log: remove st...
26
  		if (!strcmp(name, log_type->name))
2a23aa1dd   Jonathan Brassow   dm log: make modu...
27
28
29
30
  			return log_type;
  
  	return NULL;
  }
ec44ab9d6   Mike Snitzer   dm log: remove st...
31
  static struct dm_dirty_log_type *_get_dirty_log_type(const char *name)
2a23aa1dd   Jonathan Brassow   dm log: make modu...
32
  {
ec44ab9d6   Mike Snitzer   dm log: remove st...
33
  	struct dm_dirty_log_type *log_type;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
34
35
  
  	spin_lock(&_lock);
2a23aa1dd   Jonathan Brassow   dm log: make modu...
36
37
  
  	log_type = __find_dirty_log_type(name);
ec44ab9d6   Mike Snitzer   dm log: remove st...
38
  	if (log_type && !try_module_get(log_type->module))
84e67c931   Mike Snitzer   dm log: use stand...
39
  		log_type = NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
41
  
  	spin_unlock(&_lock);
2a23aa1dd   Jonathan Brassow   dm log: make modu...
42
43
  
  	return log_type;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
  }
fb8b28480   Jonathan Brassow   dm log: auto load...
45
46
47
48
  /*
   * get_type
   * @type_name
   *
2a23aa1dd   Jonathan Brassow   dm log: make modu...
49
   * Attempt to retrieve the dm_dirty_log_type by name.  If not already
fb8b28480   Jonathan Brassow   dm log: auto load...
50
51
52
53
54
55
56
57
58
59
60
61
   * available, attempt to load the appropriate module.
   *
   * Log modules are named "dm-log-" followed by the 'type_name'.
   * Modules may contain multiple types.
   * This function will first try the module "dm-log-<type_name>",
   * then truncate 'type_name' on the last '-' and try again.
   *
   * For example, if type_name was "clustered-disk", it would search
   * 'dm-log-clustered-disk' then 'dm-log-clustered'.
   *
   * Returns: dirty_log_type* on success, NULL on failure
   */
416cd17b1   Heinz Mauelshagen   dm log: clean int...
62
  static struct dm_dirty_log_type *get_type(const char *type_name)
fb8b28480   Jonathan Brassow   dm log: auto load...
63
64
  {
  	char *p, *type_name_dup;
ec44ab9d6   Mike Snitzer   dm log: remove st...
65
  	struct dm_dirty_log_type *log_type;
fb8b28480   Jonathan Brassow   dm log: auto load...
66

2a23aa1dd   Jonathan Brassow   dm log: make modu...
67
68
69
70
71
  	if (!type_name)
  		return NULL;
  
  	log_type = _get_dirty_log_type(type_name);
  	if (log_type)
ec44ab9d6   Mike Snitzer   dm log: remove st...
72
  		return log_type;
fb8b28480   Jonathan Brassow   dm log: auto load...
73
74
75
76
77
78
79
80
81
  
  	type_name_dup = kstrdup(type_name, GFP_KERNEL);
  	if (!type_name_dup) {
  		DMWARN("No memory left to attempt log module load for \"%s\"",
  		       type_name);
  		return NULL;
  	}
  
  	while (request_module("dm-log-%s", type_name_dup) ||
2a23aa1dd   Jonathan Brassow   dm log: make modu...
82
  	       !(log_type = _get_dirty_log_type(type_name))) {
fb8b28480   Jonathan Brassow   dm log: auto load...
83
84
85
86
87
  		p = strrchr(type_name_dup, '-');
  		if (!p)
  			break;
  		p[0] = '\0';
  	}
2a23aa1dd   Jonathan Brassow   dm log: make modu...
88
  	if (!log_type)
fb8b28480   Jonathan Brassow   dm log: auto load...
89
90
91
  		DMWARN("Module for logging type \"%s\" not found.", type_name);
  
  	kfree(type_name_dup);
ec44ab9d6   Mike Snitzer   dm log: remove st...
92
  	return log_type;
fb8b28480   Jonathan Brassow   dm log: auto load...
93
  }
416cd17b1   Heinz Mauelshagen   dm log: clean int...
94
  static void put_type(struct dm_dirty_log_type *type)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
95
  {
2a23aa1dd   Jonathan Brassow   dm log: make modu...
96
97
  	if (!type)
  		return;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
98
  	spin_lock(&_lock);
ec44ab9d6   Mike Snitzer   dm log: remove st...
99
  	if (!__find_dirty_log_type(type->name))
2a23aa1dd   Jonathan Brassow   dm log: make modu...
100
  		goto out;
84e67c931   Mike Snitzer   dm log: use stand...
101
  	module_put(type->module);
2a23aa1dd   Jonathan Brassow   dm log: make modu...
102
103
  
  out:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
104
105
  	spin_unlock(&_lock);
  }
b8206bc3d   Alasdair G Kergon   dm log: move regi...
106
107
  int dm_dirty_log_type_register(struct dm_dirty_log_type *type)
  {
2a23aa1dd   Jonathan Brassow   dm log: make modu...
108
  	int r = 0;
b8206bc3d   Alasdair G Kergon   dm log: move regi...
109
  	spin_lock(&_lock);
2a23aa1dd   Jonathan Brassow   dm log: make modu...
110
  	if (!__find_dirty_log_type(type->name))
ec44ab9d6   Mike Snitzer   dm log: remove st...
111
112
  		list_add(&type->list, &_log_types);
  	else
2a23aa1dd   Jonathan Brassow   dm log: make modu...
113
  		r = -EEXIST;
b8206bc3d   Alasdair G Kergon   dm log: move regi...
114
  	spin_unlock(&_lock);
2a23aa1dd   Jonathan Brassow   dm log: make modu...
115
  	return r;
b8206bc3d   Alasdair G Kergon   dm log: move regi...
116
117
118
119
120
121
  }
  EXPORT_SYMBOL(dm_dirty_log_type_register);
  
  int dm_dirty_log_type_unregister(struct dm_dirty_log_type *type)
  {
  	spin_lock(&_lock);
ec44ab9d6   Mike Snitzer   dm log: remove st...
122
  	if (!__find_dirty_log_type(type->name)) {
2a23aa1dd   Jonathan Brassow   dm log: make modu...
123
124
125
  		spin_unlock(&_lock);
  		return -EINVAL;
  	}
ec44ab9d6   Mike Snitzer   dm log: remove st...
126
  	list_del(&type->list);
b8206bc3d   Alasdair G Kergon   dm log: move regi...
127
128
129
130
131
132
  
  	spin_unlock(&_lock);
  
  	return 0;
  }
  EXPORT_SYMBOL(dm_dirty_log_type_unregister);
416cd17b1   Heinz Mauelshagen   dm log: clean int...
133
  struct dm_dirty_log *dm_dirty_log_create(const char *type_name,
87a8f240e   Mikulas Patocka   dm log: add flush...
134
135
136
  			struct dm_target *ti,
  			int (*flush_callback_fn)(struct dm_target *ti),
  			unsigned int argc, char **argv)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
137
  {
416cd17b1   Heinz Mauelshagen   dm log: clean int...
138
139
  	struct dm_dirty_log_type *type;
  	struct dm_dirty_log *log;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
140
141
142
143
144
145
146
147
148
149
  
  	log = kmalloc(sizeof(*log), GFP_KERNEL);
  	if (!log)
  		return NULL;
  
  	type = get_type(type_name);
  	if (!type) {
  		kfree(log);
  		return NULL;
  	}
87a8f240e   Mikulas Patocka   dm log: add flush...
150
  	log->flush_callback_fn = flush_callback_fn;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
151
152
153
154
155
156
157
158
159
  	log->type = type;
  	if (type->ctr(log, ti, argc, argv)) {
  		kfree(log);
  		put_type(type);
  		return NULL;
  	}
  
  	return log;
  }
416cd17b1   Heinz Mauelshagen   dm log: clean int...
160
  EXPORT_SYMBOL(dm_dirty_log_create);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
161

416cd17b1   Heinz Mauelshagen   dm log: clean int...
162
  void dm_dirty_log_destroy(struct dm_dirty_log *log)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
163
164
165
166
167
  {
  	log->type->dtr(log);
  	put_type(log->type);
  	kfree(log);
  }
416cd17b1   Heinz Mauelshagen   dm log: clean int...
168
  EXPORT_SYMBOL(dm_dirty_log_destroy);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
169
170
171
172
173
174
175
176
177
178
179
180
181
  
  /*-----------------------------------------------------------------
   * Persistent and core logs share a lot of their implementation.
   * FIXME: need a reload method to be called from a resume
   *---------------------------------------------------------------*/
  /*
   * Magic for persistent mirrors: "MiRr"
   */
  #define MIRROR_MAGIC 0x4D695272
  
  /*
   * The on-disk version of the metadata.
   */
a4fc4717f   Patrick Caulfield   [PATCH] device-ma...
182
  #define MIRROR_DISK_VERSION 2
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
183
  #define LOG_OFFSET 2
283a8328c   Alasdair G Kergon   dm: suppress endi...
184
185
  struct log_header_disk {
  	__le32 magic;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
186
187
188
189
190
  
  	/*
  	 * Simple, incrementing version. no backward
  	 * compatibility.
  	 */
283a8328c   Alasdair G Kergon   dm: suppress endi...
191
192
193
194
195
196
  	__le32 version;
  	__le64 nr_regions;
  } __packed;
  
  struct log_header_core {
  	uint32_t magic;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
197
  	uint32_t version;
283a8328c   Alasdair G Kergon   dm: suppress endi...
198
  	uint64_t nr_regions;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
199
200
201
202
  };
  
  struct log_c {
  	struct dm_target *ti;
b09acf1aa   Mikulas Patocka   dm raid1: split t...
203
204
  	int touched_dirtied;
  	int touched_cleaned;
5adc78d0d   Mikulas Patocka   dm log: introduce...
205
  	int flush_failed;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
  	uint32_t region_size;
  	unsigned int region_count;
  	region_t sync_count;
  
  	unsigned bitset_uint32_count;
  	uint32_t *clean_bits;
  	uint32_t *sync_bits;
  	uint32_t *recovering_bits;	/* FIXME: this seems excessive */
  
  	int sync_search;
  
  	/* Resync flag */
  	enum sync {
  		DEFAULTSYNC,	/* Synchronize if necessary */
  		NOSYNC,		/* Devices known to be already in sync */
  		FORCESYNC,	/* Force a sync to happen */
  	} sync;
5d234d1e0   Heinz Mauelshagen   dm log: update dm...
223
  	struct dm_io_request io_req;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
224
225
226
  	/*
  	 * Disk log fields
  	 */
01d03a660   Jonathan E Brassow   dm log: fault det...
227
  	int log_dev_failed;
64b30c46e   Mikulas Patocka   dm raid1: report ...
228
  	int log_dev_flush_failed;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
229
  	struct dm_dev *log_dev;
283a8328c   Alasdair G Kergon   dm: suppress endi...
230
  	struct log_header_core header;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
231

22a1ceb1e   Heinz Mauelshagen   dm io: clean inte...
232
  	struct dm_io_region header_location;
283a8328c   Alasdair G Kergon   dm: suppress endi...
233
  	struct log_header_disk *disk_header;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
234
235
236
237
238
239
  };
  
  /*
   * The touched member needs to be updated every time we access
   * one of the bitsets.
   */
416cd17b1   Heinz Mauelshagen   dm log: clean int...
240
  static inline int log_test_bit(uint32_t *bs, unsigned bit)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
241
  {
c8f543e07   Akinobu Mita   dm log: clean up ...
242
  	return test_bit_le(bit, bs) ? 1 : 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
243
244
245
246
247
  }
  
  static inline void log_set_bit(struct log_c *l,
  			       uint32_t *bs, unsigned bit)
  {
c8f543e07   Akinobu Mita   dm log: clean up ...
248
  	__set_bit_le(bit, bs);
b09acf1aa   Mikulas Patocka   dm raid1: split t...
249
  	l->touched_cleaned = 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
250
251
252
253
254
  }
  
  static inline void log_clear_bit(struct log_c *l,
  				 uint32_t *bs, unsigned bit)
  {
c8f543e07   Akinobu Mita   dm log: clean up ...
255
  	__clear_bit_le(bit, bs);
b09acf1aa   Mikulas Patocka   dm raid1: split t...
256
  	l->touched_dirtied = 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
257
258
259
260
261
  }
  
  /*----------------------------------------------------------------
   * Header IO
   *--------------------------------------------------------------*/
283a8328c   Alasdair G Kergon   dm: suppress endi...
262
  static void header_to_disk(struct log_header_core *core, struct log_header_disk *disk)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
263
264
265
266
267
  {
  	disk->magic = cpu_to_le32(core->magic);
  	disk->version = cpu_to_le32(core->version);
  	disk->nr_regions = cpu_to_le64(core->nr_regions);
  }
283a8328c   Alasdair G Kergon   dm: suppress endi...
268
  static void header_from_disk(struct log_header_core *core, struct log_header_disk *disk)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
269
270
271
272
273
  {
  	core->magic = le32_to_cpu(disk->magic);
  	core->version = le32_to_cpu(disk->version);
  	core->nr_regions = le64_to_cpu(disk->nr_regions);
  }
9c5a559d9   Heinz Mauelshagen   dm log: fix uniti...
274
  static int rw_header(struct log_c *lc, int op)
5d234d1e0   Heinz Mauelshagen   dm log: update dm...
275
  {
9c5a559d9   Heinz Mauelshagen   dm log: fix uniti...
276
277
  	lc->io_req.bi_op = op;
  	lc->io_req.bi_op_flags = 0;
5d234d1e0   Heinz Mauelshagen   dm log: update dm...
278
279
280
  
  	return dm_io(&lc->io_req, 1, &lc->header_location, NULL);
  }
20a34a8ec   Mikulas Patocka   dm log: add flush...
281
282
283
284
285
286
287
  static int flush_header(struct log_c *lc)
  {
  	struct dm_io_region null_location = {
  		.bdev = lc->header_location.bdev,
  		.sector = 0,
  		.count = 0,
  	};
e6047149d   Mike Christie   dm: use bio op ac...
288
  	lc->io_req.bi_op = REQ_OP_WRITE;
70fd76140   Christoph Hellwig   block,fs: use REQ...
289
  	lc->io_req.bi_op_flags = REQ_PREFLUSH;
20a34a8ec   Mikulas Patocka   dm log: add flush...
290
291
292
  
  	return dm_io(&lc->io_req, 1, &null_location, NULL);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
293
294
295
  static int read_header(struct log_c *log)
  {
  	int r;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
296

9c5a559d9   Heinz Mauelshagen   dm log: fix uniti...
297
  	r = rw_header(log, REQ_OP_READ);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
298
299
300
301
302
303
304
305
306
307
308
  	if (r)
  		return r;
  
  	header_from_disk(&log->header, log->disk_header);
  
  	/* New log required? */
  	if (log->sync != DEFAULTSYNC || log->header.magic != MIRROR_MAGIC) {
  		log->header.magic = MIRROR_MAGIC;
  		log->header.version = MIRROR_DISK_VERSION;
  		log->header.nr_regions = 0;
  	}
a4fc4717f   Patrick Caulfield   [PATCH] device-ma...
309
310
311
312
  #ifdef __LITTLE_ENDIAN
  	if (log->header.version == 1)
  		log->header.version = 2;
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
313
314
315
316
317
318
319
  	if (log->header.version != MIRROR_DISK_VERSION) {
  		DMWARN("incompatible disk log version");
  		return -EINVAL;
  	}
  
  	return 0;
  }
2045e88ed   Milan Broz   dm log: move regi...
320
321
322
323
324
325
326
327
328
329
  static int _check_region_size(struct dm_target *ti, uint32_t region_size)
  {
  	if (region_size < 2 || region_size > ti->len)
  		return 0;
  
  	if (!is_power_of_2(region_size))
  		return 0;
  
  	return 1;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
330
  /*----------------------------------------------------------------
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
331
332
333
334
335
   * core log constructor/destructor
   *
   * argv contains region_size followed optionally by [no]sync
   *--------------------------------------------------------------*/
  #define BYTE_SHIFT 3
416cd17b1   Heinz Mauelshagen   dm log: clean int...
336
  static int create_log_context(struct dm_dirty_log *log, struct dm_target *ti,
b7cca195c   Alasdair G Kergon   [PATCH] dm mirror...
337
338
  			      unsigned int argc, char **argv,
  			      struct dm_dev *dev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
339
340
341
342
343
344
  {
  	enum sync sync = DEFAULTSYNC;
  
  	struct log_c *lc;
  	uint32_t region_size;
  	unsigned int region_count;
b7cca195c   Alasdair G Kergon   [PATCH] dm mirror...
345
  	size_t bitset_size, buf_size;
5d234d1e0   Heinz Mauelshagen   dm log: update dm...
346
  	int r;
31998ef19   Mikulas Patocka   dm: reject traili...
347
  	char dummy;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
348
349
  
  	if (argc < 1 || argc > 2) {
b7fd54a70   Heinz Mauelshagen   dm log: generalis...
350
  		DMWARN("wrong number of arguments to dirty region log");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
351
352
353
354
355
356
357
358
359
  		return -EINVAL;
  	}
  
  	if (argc > 1) {
  		if (!strcmp(argv[1], "sync"))
  			sync = FORCESYNC;
  		else if (!strcmp(argv[1], "nosync"))
  			sync = NOSYNC;
  		else {
b7fd54a70   Heinz Mauelshagen   dm log: generalis...
360
361
  			DMWARN("unrecognised sync argument to "
  			       "dirty region log: %s", argv[1]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
362
363
364
  			return -EINVAL;
  		}
  	}
31998ef19   Mikulas Patocka   dm: reject traili...
365
  	if (sscanf(argv[0], "%u%c", &region_size, &dummy) != 1 ||
2045e88ed   Milan Broz   dm log: move regi...
366
367
  	    !_check_region_size(ti, region_size)) {
  		DMWARN("invalid region size %s", argv[0]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
368
369
370
371
372
373
374
375
376
377
378
379
  		return -EINVAL;
  	}
  
  	region_count = dm_sector_div_up(ti->len, region_size);
  
  	lc = kmalloc(sizeof(*lc), GFP_KERNEL);
  	if (!lc) {
  		DMWARN("couldn't allocate core log");
  		return -ENOMEM;
  	}
  
  	lc->ti = ti;
b09acf1aa   Mikulas Patocka   dm raid1: split t...
380
381
  	lc->touched_dirtied = 0;
  	lc->touched_cleaned = 0;
5adc78d0d   Mikulas Patocka   dm log: introduce...
382
  	lc->flush_failed = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
383
384
385
386
387
  	lc->region_size = region_size;
  	lc->region_count = region_count;
  	lc->sync = sync;
  
  	/*
0e56822d3   Alasdair G Kergon   [PATCH] device-ma...
388
  	 * Work out how many "unsigned long"s we need to hold the bitset.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
389
390
  	 */
  	bitset_size = dm_round_up(region_count,
29121bd0b   Alasdair G Kergon   [PATCH] dm mirror...
391
  				  sizeof(*lc->clean_bits) << BYTE_SHIFT);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
392
  	bitset_size >>= BYTE_SHIFT;
29121bd0b   Alasdair G Kergon   [PATCH] dm mirror...
393
  	lc->bitset_uint32_count = bitset_size / sizeof(*lc->clean_bits);
b7cca195c   Alasdair G Kergon   [PATCH] dm mirror...
394
395
396
397
398
399
400
401
402
403
404
405
406
407
  
  	/*
  	 * Disk log?
  	 */
  	if (!dev) {
  		lc->clean_bits = vmalloc(bitset_size);
  		if (!lc->clean_bits) {
  			DMWARN("couldn't allocate clean bitset");
  			kfree(lc);
  			return -ENOMEM;
  		}
  		lc->disk_header = NULL;
  	} else {
  		lc->log_dev = dev;
01d03a660   Jonathan E Brassow   dm log: fault det...
408
  		lc->log_dev_failed = 0;
64b30c46e   Mikulas Patocka   dm raid1: report ...
409
  		lc->log_dev_flush_failed = 0;
b7cca195c   Alasdair G Kergon   [PATCH] dm mirror...
410
411
412
413
414
415
  		lc->header_location.bdev = lc->log_dev->bdev;
  		lc->header_location.sector = 0;
  
  		/*
  		 * Buffer holds both header and bitset.
  		 */
18d8594dd   Mike Snitzer   dm log: fix creat...
416
417
418
419
  		buf_size =
  		    dm_round_up((LOG_OFFSET << SECTOR_SHIFT) + bitset_size,
  				bdev_logical_block_size(lc->header_location.
  							    bdev));
ac1f0ac22   Milan Broz   dm log: ensure lo...
420

5657e8fa4   Mikulas Patocka   dm: use i_size_read
421
  		if (buf_size > i_size_read(dev->bdev->bd_inode)) {
ac1f0ac22   Milan Broz   dm log: ensure lo...
422
423
424
425
426
  			DMWARN("log device %s too small: need %llu bytes",
  				dev->name, (unsigned long long)buf_size);
  			kfree(lc);
  			return -EINVAL;
  		}
b7cca195c   Alasdair G Kergon   [PATCH] dm mirror...
427
  		lc->header_location.count = buf_size >> SECTOR_SHIFT;
6f3af01cb   Takahiro Yasui   dm log: avoid rei...
428

5d234d1e0   Heinz Mauelshagen   dm log: update dm...
429
  		lc->io_req.mem.type = DM_IO_VMA;
6f3af01cb   Takahiro Yasui   dm log: avoid rei...
430
  		lc->io_req.notify.fn = NULL;
bda8efec5   Mikulas Patocka   dm io: use fixed ...
431
  		lc->io_req.client = dm_io_client_create();
5d234d1e0   Heinz Mauelshagen   dm log: update dm...
432
433
434
435
  		if (IS_ERR(lc->io_req.client)) {
  			r = PTR_ERR(lc->io_req.client);
  			DMWARN("couldn't allocate disk io client");
  			kfree(lc);
dbc883f15   Dan Carpenter   dm log: use PTR_E...
436
  			return r;
5d234d1e0   Heinz Mauelshagen   dm log: update dm...
437
  		}
b7cca195c   Alasdair G Kergon   [PATCH] dm mirror...
438
439
440
441
  
  		lc->disk_header = vmalloc(buf_size);
  		if (!lc->disk_header) {
  			DMWARN("couldn't allocate disk log buffer");
c7a2bd19b   Takahiro Yasui   dm log: fix dm_io...
442
  			dm_io_client_destroy(lc->io_req.client);
b7cca195c   Alasdair G Kergon   [PATCH] dm mirror...
443
444
445
  			kfree(lc);
  			return -ENOMEM;
  		}
6f3af01cb   Takahiro Yasui   dm log: avoid rei...
446
  		lc->io_req.mem.ptr.vma = lc->disk_header;
b7cca195c   Alasdair G Kergon   [PATCH] dm mirror...
447
448
  		lc->clean_bits = (void *)lc->disk_header +
  				 (LOG_OFFSET << SECTOR_SHIFT);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
449
  	}
b7cca195c   Alasdair G Kergon   [PATCH] dm mirror...
450

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
451
452
453
454
455
  	memset(lc->clean_bits, -1, bitset_size);
  
  	lc->sync_bits = vmalloc(bitset_size);
  	if (!lc->sync_bits) {
  		DMWARN("couldn't allocate sync bitset");
b7cca195c   Alasdair G Kergon   [PATCH] dm mirror...
456
457
  		if (!dev)
  			vfree(lc->clean_bits);
c7a2bd19b   Takahiro Yasui   dm log: fix dm_io...
458
459
  		else
  			dm_io_client_destroy(lc->io_req.client);
b7cca195c   Alasdair G Kergon   [PATCH] dm mirror...
460
  		vfree(lc->disk_header);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
461
462
463
464
465
  		kfree(lc);
  		return -ENOMEM;
  	}
  	memset(lc->sync_bits, (sync == NOSYNC) ? -1 : 0, bitset_size);
  	lc->sync_count = (sync == NOSYNC) ? region_count : 0;
e29e65aac   Joe Perches   dm: use vzalloc
466
  	lc->recovering_bits = vzalloc(bitset_size);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
467
468
469
  	if (!lc->recovering_bits) {
  		DMWARN("couldn't allocate sync bitset");
  		vfree(lc->sync_bits);
b7cca195c   Alasdair G Kergon   [PATCH] dm mirror...
470
471
  		if (!dev)
  			vfree(lc->clean_bits);
c7a2bd19b   Takahiro Yasui   dm log: fix dm_io...
472
473
  		else
  			dm_io_client_destroy(lc->io_req.client);
b7cca195c   Alasdair G Kergon   [PATCH] dm mirror...
474
  		vfree(lc->disk_header);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
475
476
477
  		kfree(lc);
  		return -ENOMEM;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
478
479
  	lc->sync_search = 0;
  	log->context = lc;
b7cca195c   Alasdair G Kergon   [PATCH] dm mirror...
480

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
481
482
  	return 0;
  }
416cd17b1   Heinz Mauelshagen   dm log: clean int...
483
  static int core_ctr(struct dm_dirty_log *log, struct dm_target *ti,
b7cca195c   Alasdair G Kergon   [PATCH] dm mirror...
484
485
486
487
488
489
  		    unsigned int argc, char **argv)
  {
  	return create_log_context(log, ti, argc, argv, NULL);
  }
  
  static void destroy_log_context(struct log_c *lc)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
490
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
491
492
493
494
  	vfree(lc->sync_bits);
  	vfree(lc->recovering_bits);
  	kfree(lc);
  }
416cd17b1   Heinz Mauelshagen   dm log: clean int...
495
  static void core_dtr(struct dm_dirty_log *log)
b7cca195c   Alasdair G Kergon   [PATCH] dm mirror...
496
497
498
499
500
501
  {
  	struct log_c *lc = (struct log_c *) log->context;
  
  	vfree(lc->clean_bits);
  	destroy_log_context(lc);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
502
503
504
505
506
  /*----------------------------------------------------------------
   * disk log constructor/destructor
   *
   * argv contains log_device region_size followed optionally by [no]sync
   *--------------------------------------------------------------*/
416cd17b1   Heinz Mauelshagen   dm log: clean int...
507
  static int disk_ctr(struct dm_dirty_log *log, struct dm_target *ti,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
508
509
510
  		    unsigned int argc, char **argv)
  {
  	int r;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
511
512
513
  	struct dm_dev *dev;
  
  	if (argc < 2 || argc > 3) {
b7fd54a70   Heinz Mauelshagen   dm log: generalis...
514
  		DMWARN("wrong number of arguments to disk dirty region log");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
515
516
  		return -EINVAL;
  	}
024d37e95   Milan Broz   dm: fix opening l...
517
  	r = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), &dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
518
519
  	if (r)
  		return r;
b7cca195c   Alasdair G Kergon   [PATCH] dm mirror...
520
  	r = create_log_context(log, ti, argc - 1, argv + 1, dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
521
522
523
524
  	if (r) {
  		dm_put_device(ti, dev);
  		return r;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
525
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
526
  }
416cd17b1   Heinz Mauelshagen   dm log: clean int...
527
  static void disk_dtr(struct dm_dirty_log *log)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
528
529
  {
  	struct log_c *lc = (struct log_c *) log->context;
b7cca195c   Alasdair G Kergon   [PATCH] dm mirror...
530

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
531
532
  	dm_put_device(lc->ti, lc->log_dev);
  	vfree(lc->disk_header);
5d234d1e0   Heinz Mauelshagen   dm log: update dm...
533
  	dm_io_client_destroy(lc->io_req.client);
b7cca195c   Alasdair G Kergon   [PATCH] dm mirror...
534
  	destroy_log_context(lc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
535
  }
01d03a660   Jonathan E Brassow   dm log: fault det...
536
537
538
539
540
541
542
543
  static void fail_log_device(struct log_c *lc)
  {
  	if (lc->log_dev_failed)
  		return;
  
  	lc->log_dev_failed = 1;
  	dm_table_event(lc->ti->table);
  }
416cd17b1   Heinz Mauelshagen   dm log: clean int...
544
  static int disk_resume(struct dm_dirty_log *log)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
545
546
547
548
549
550
551
552
  {
  	int r;
  	unsigned i;
  	struct log_c *lc = (struct log_c *) log->context;
  	size_t size = lc->bitset_uint32_count * sizeof(uint32_t);
  
  	/* read the disk header */
  	r = read_header(lc);
01d03a660   Jonathan E Brassow   dm log: fault det...
553
  	if (r) {
b7fd54a70   Heinz Mauelshagen   dm log: generalis...
554
  		DMWARN("%s: Failed to read header on dirty region log device",
01d03a660   Jonathan E Brassow   dm log: fault det...
555
556
  		       lc->log_dev->name);
  		fail_log_device(lc);
ba8b45cea   Jonathan Brassow   dm log: fix resum...
557
558
559
560
561
562
563
564
  		/*
  		 * If the log device cannot be read, we must assume
  		 * all regions are out-of-sync.  If we simply return
  		 * here, the state will be uninitialized and could
  		 * lead us to return 'in-sync' status for regions
  		 * that are actually 'out-of-sync'.
  		 */
  		lc->header.nr_regions = 0;
01d03a660   Jonathan E Brassow   dm log: fault det...
565
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
566

8a835f11b   Alasdair G Kergon   [PATCH] dm mirror...
567
  	/* set or clear any new bits -- device has grown */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
568
569
570
571
572
573
574
575
  	if (lc->sync == NOSYNC)
  		for (i = lc->header.nr_regions; i < lc->region_count; i++)
  			/* FIXME: amazingly inefficient */
  			log_set_bit(lc, lc->clean_bits, i);
  	else
  		for (i = lc->header.nr_regions; i < lc->region_count; i++)
  			/* FIXME: amazingly inefficient */
  			log_clear_bit(lc, lc->clean_bits, i);
8a835f11b   Alasdair G Kergon   [PATCH] dm mirror...
576
577
578
  	/* clear any old bits -- device has shrunk */
  	for (i = lc->region_count; i % (sizeof(*lc->clean_bits) << BYTE_SHIFT); i++)
  		log_clear_bit(lc, lc->clean_bits, i);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
579
580
  	/* copy clean across to sync */
  	memcpy(lc->sync_bits, lc->clean_bits, size);
8fb980e35   Akinobu Mita   dm: use memweight()
581
582
  	lc->sync_count = memweight(lc->clean_bits,
  				lc->bitset_uint32_count * sizeof(uint32_t));
88b20a1a7   Jonathan E Brassow   [PATCH] dm: raid1...
583
  	lc->sync_search = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
584

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
585
586
  	/* set the correct number of regions in the header */
  	lc->header.nr_regions = lc->region_count;
6f3af01cb   Takahiro Yasui   dm log: avoid rei...
587
  	header_to_disk(&lc->header, lc->disk_header);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
588
  	/* write the new header */
9c5a559d9   Heinz Mauelshagen   dm log: fix uniti...
589
  	r = rw_header(lc, REQ_OP_WRITE);
64b30c46e   Mikulas Patocka   dm raid1: report ...
590
  	if (!r) {
20a34a8ec   Mikulas Patocka   dm log: add flush...
591
  		r = flush_header(lc);
64b30c46e   Mikulas Patocka   dm raid1: report ...
592
593
594
  		if (r)
  			lc->log_dev_flush_failed = 1;
  	}
01d03a660   Jonathan E Brassow   dm log: fault det...
595
  	if (r) {
b7fd54a70   Heinz Mauelshagen   dm log: generalis...
596
  		DMWARN("%s: Failed to write header on dirty region log device",
01d03a660   Jonathan E Brassow   dm log: fault det...
597
598
599
600
601
  		       lc->log_dev->name);
  		fail_log_device(lc);
  	}
  
  	return r;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
602
  }
416cd17b1   Heinz Mauelshagen   dm log: clean int...
603
  static uint32_t core_get_region_size(struct dm_dirty_log *log)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
604
605
606
607
  {
  	struct log_c *lc = (struct log_c *) log->context;
  	return lc->region_size;
  }
416cd17b1   Heinz Mauelshagen   dm log: clean int...
608
  static int core_resume(struct dm_dirty_log *log)
88b20a1a7   Jonathan E Brassow   [PATCH] dm: raid1...
609
610
611
612
613
  {
  	struct log_c *lc = (struct log_c *) log->context;
  	lc->sync_search = 0;
  	return 0;
  }
416cd17b1   Heinz Mauelshagen   dm log: clean int...
614
  static int core_is_clean(struct dm_dirty_log *log, region_t region)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
615
616
617
618
  {
  	struct log_c *lc = (struct log_c *) log->context;
  	return log_test_bit(lc->clean_bits, region);
  }
416cd17b1   Heinz Mauelshagen   dm log: clean int...
619
  static int core_in_sync(struct dm_dirty_log *log, region_t region, int block)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
620
621
622
623
  {
  	struct log_c *lc = (struct log_c *) log->context;
  	return log_test_bit(lc->sync_bits, region);
  }
416cd17b1   Heinz Mauelshagen   dm log: clean int...
624
  static int core_flush(struct dm_dirty_log *log)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
625
626
627
628
  {
  	/* no op */
  	return 0;
  }
416cd17b1   Heinz Mauelshagen   dm log: clean int...
629
  static int disk_flush(struct dm_dirty_log *log)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
630
  {
076010e2e   Mikulas Patocka   dm log: use flush...
631
632
  	int r, i;
  	struct log_c *lc = log->context;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
633
634
  
  	/* only write if the log has changed */
b09acf1aa   Mikulas Patocka   dm raid1: split t...
635
  	if (!lc->touched_cleaned && !lc->touched_dirtied)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
636
  		return 0;
076010e2e   Mikulas Patocka   dm log: use flush...
637
638
639
640
641
642
643
644
645
646
647
648
  	if (lc->touched_cleaned && log->flush_callback_fn &&
  	    log->flush_callback_fn(lc->ti)) {
  		/*
  		 * At this point it is impossible to determine which
  		 * regions are clean and which are dirty (without
  		 * re-reading the log off disk). So mark all of them
  		 * dirty.
  		 */
  		lc->flush_failed = 1;
  		for (i = 0; i < lc->region_count; i++)
  			log_clear_bit(lc, lc->clean_bits, i);
  	}
9c5a559d9   Heinz Mauelshagen   dm log: fix uniti...
649
  	r = rw_header(lc, REQ_OP_WRITE);
01d03a660   Jonathan E Brassow   dm log: fault det...
650
651
  	if (r)
  		fail_log_device(lc);
b09acf1aa   Mikulas Patocka   dm raid1: split t...
652
  	else {
20a34a8ec   Mikulas Patocka   dm log: add flush...
653
654
  		if (lc->touched_dirtied) {
  			r = flush_header(lc);
64b30c46e   Mikulas Patocka   dm raid1: report ...
655
656
  			if (r) {
  				lc->log_dev_flush_failed = 1;
20a34a8ec   Mikulas Patocka   dm log: add flush...
657
  				fail_log_device(lc);
64b30c46e   Mikulas Patocka   dm raid1: report ...
658
  			} else
20a34a8ec   Mikulas Patocka   dm log: add flush...
659
660
  				lc->touched_dirtied = 0;
  		}
b09acf1aa   Mikulas Patocka   dm raid1: split t...
661
662
  		lc->touched_cleaned = 0;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
663
664
665
  
  	return r;
  }
416cd17b1   Heinz Mauelshagen   dm log: clean int...
666
  static void core_mark_region(struct dm_dirty_log *log, region_t region)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
667
668
669
670
  {
  	struct log_c *lc = (struct log_c *) log->context;
  	log_clear_bit(lc, lc->clean_bits, region);
  }
416cd17b1   Heinz Mauelshagen   dm log: clean int...
671
  static void core_clear_region(struct dm_dirty_log *log, region_t region)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
672
673
  {
  	struct log_c *lc = (struct log_c *) log->context;
5adc78d0d   Mikulas Patocka   dm log: introduce...
674
675
  	if (likely(!lc->flush_failed))
  		log_set_bit(lc, lc->clean_bits, region);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
676
  }
416cd17b1   Heinz Mauelshagen   dm log: clean int...
677
  static int core_get_resync_work(struct dm_dirty_log *log, region_t *region)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
678
679
680
681
682
683
684
  {
  	struct log_c *lc = (struct log_c *) log->context;
  
  	if (lc->sync_search >= lc->region_count)
  		return 0;
  
  	do {
c8f543e07   Akinobu Mita   dm log: clean up ...
685
  		*region = find_next_zero_bit_le(lc->sync_bits,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
686
687
688
  					     lc->region_count,
  					     lc->sync_search);
  		lc->sync_search = *region + 1;
ac81b2ee4   Darrick J. Wong   [PATCH] make dm-m...
689
  		if (*region >= lc->region_count)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
690
691
692
693
694
695
696
  			return 0;
  
  	} while (log_test_bit(lc->recovering_bits, *region));
  
  	log_set_bit(lc, lc->recovering_bits, *region);
  	return 1;
  }
416cd17b1   Heinz Mauelshagen   dm log: clean int...
697
  static void core_set_region_sync(struct dm_dirty_log *log, region_t region,
f3ee6b2f6   Jonathan E Brassow   [PATCH] dm: log: ...
698
  				 int in_sync)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
699
700
701
702
  {
  	struct log_c *lc = (struct log_c *) log->context;
  
  	log_clear_bit(lc, lc->recovering_bits, region);
f3ee6b2f6   Jonathan E Brassow   [PATCH] dm: log: ...
703
  	if (in_sync) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
704
705
  		log_set_bit(lc, lc->sync_bits, region);
                  lc->sync_count++;
f3ee6b2f6   Jonathan E Brassow   [PATCH] dm: log: ...
706
707
708
709
          } else if (log_test_bit(lc->sync_bits, region)) {
  		lc->sync_count--;
  		log_clear_bit(lc, lc->sync_bits, region);
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
710
  }
416cd17b1   Heinz Mauelshagen   dm log: clean int...
711
  static region_t core_get_sync_count(struct dm_dirty_log *log)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
712
713
714
715
716
717
718
719
720
  {
          struct log_c *lc = (struct log_c *) log->context;
  
          return lc->sync_count;
  }
  
  #define	DMEMIT_SYNC \
  	if (lc->sync != DEFAULTSYNC) \
  		DMEMIT("%ssync ", lc->sync == NOSYNC ? "no" : "")
416cd17b1   Heinz Mauelshagen   dm log: clean int...
721
  static int core_status(struct dm_dirty_log *log, status_type_t status,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
722
723
724
725
726
727
728
  		       char *result, unsigned int maxlen)
  {
  	int sz = 0;
  	struct log_c *lc = log->context;
  
  	switch(status) {
  	case STATUSTYPE_INFO:
315dcc226   Jonathan E Brassow   dm log: report fa...
729
  		DMEMIT("1 %s", log->type->name);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
730
731
732
733
734
735
736
737
738
739
  		break;
  
  	case STATUSTYPE_TABLE:
  		DMEMIT("%s %u %u ", log->type->name,
  		       lc->sync == DEFAULTSYNC ? 1 : 2, lc->region_size);
  		DMEMIT_SYNC;
  	}
  
  	return sz;
  }
416cd17b1   Heinz Mauelshagen   dm log: clean int...
740
  static int disk_status(struct dm_dirty_log *log, status_type_t status,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
741
742
743
  		       char *result, unsigned int maxlen)
  {
  	int sz = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
744
745
746
747
  	struct log_c *lc = log->context;
  
  	switch(status) {
  	case STATUSTYPE_INFO:
315dcc226   Jonathan E Brassow   dm log: report fa...
748
  		DMEMIT("3 %s %s %c", log->type->name, lc->log_dev->name,
64b30c46e   Mikulas Patocka   dm raid1: report ...
749
750
751
  		       lc->log_dev_flush_failed ? 'F' :
  		       lc->log_dev_failed ? 'D' :
  		       'A');
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
752
753
754
  		break;
  
  	case STATUSTYPE_TABLE:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
755
  		DMEMIT("%s %u %s %u ", log->type->name,
315dcc226   Jonathan E Brassow   dm log: report fa...
756
  		       lc->sync == DEFAULTSYNC ? 2 : 3, lc->log_dev->name,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
757
758
759
760
761
762
  		       lc->region_size);
  		DMEMIT_SYNC;
  	}
  
  	return sz;
  }
416cd17b1   Heinz Mauelshagen   dm log: clean int...
763
  static struct dm_dirty_log_type _core_type = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
764
765
766
767
  	.name = "core",
  	.module = THIS_MODULE,
  	.ctr = core_ctr,
  	.dtr = core_dtr,
88b20a1a7   Jonathan E Brassow   [PATCH] dm: raid1...
768
  	.resume = core_resume,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
769
770
771
772
773
774
775
  	.get_region_size = core_get_region_size,
  	.is_clean = core_is_clean,
  	.in_sync = core_in_sync,
  	.flush = core_flush,
  	.mark_region = core_mark_region,
  	.clear_region = core_clear_region,
  	.get_resync_work = core_get_resync_work,
f3ee6b2f6   Jonathan E Brassow   [PATCH] dm: log: ...
776
  	.set_region_sync = core_set_region_sync,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
777
778
779
  	.get_sync_count = core_get_sync_count,
  	.status = core_status,
  };
416cd17b1   Heinz Mauelshagen   dm log: clean int...
780
  static struct dm_dirty_log_type _disk_type = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
781
782
783
784
  	.name = "disk",
  	.module = THIS_MODULE,
  	.ctr = disk_ctr,
  	.dtr = disk_dtr,
6b3df0d7a   Jonathan Brassow   dm log: split sus...
785
  	.postsuspend = disk_flush,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
786
787
788
789
790
791
792
793
  	.resume = disk_resume,
  	.get_region_size = core_get_region_size,
  	.is_clean = core_is_clean,
  	.in_sync = core_in_sync,
  	.flush = disk_flush,
  	.mark_region = core_mark_region,
  	.clear_region = core_clear_region,
  	.get_resync_work = core_get_resync_work,
f3ee6b2f6   Jonathan E Brassow   [PATCH] dm: log: ...
794
  	.set_region_sync = core_set_region_sync,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
795
796
797
  	.get_sync_count = core_get_sync_count,
  	.status = disk_status,
  };
c8da2f8dd   Adrian Bunk   dm log: make dm_d...
798
  static int __init dm_dirty_log_init(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
799
800
  {
  	int r;
416cd17b1   Heinz Mauelshagen   dm log: clean int...
801
  	r = dm_dirty_log_type_register(&_core_type);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
802
803
  	if (r)
  		DMWARN("couldn't register core log");
416cd17b1   Heinz Mauelshagen   dm log: clean int...
804
  	r = dm_dirty_log_type_register(&_disk_type);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
805
806
  	if (r) {
  		DMWARN("couldn't register disk type");
416cd17b1   Heinz Mauelshagen   dm log: clean int...
807
  		dm_dirty_log_type_unregister(&_core_type);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
808
809
810
811
  	}
  
  	return r;
  }
c8da2f8dd   Adrian Bunk   dm log: make dm_d...
812
  static void __exit dm_dirty_log_exit(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
813
  {
416cd17b1   Heinz Mauelshagen   dm log: clean int...
814
815
  	dm_dirty_log_type_unregister(&_disk_type);
  	dm_dirty_log_type_unregister(&_core_type);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
816
  }
769aef30f   Heinz Mauelshagen   dm log: move dirt...
817
818
819
820
821
822
  module_init(dm_dirty_log_init);
  module_exit(dm_dirty_log_exit);
  
  MODULE_DESCRIPTION(DM_NAME " dirty region log");
  MODULE_AUTHOR("Joe Thornber, Heinz Mauelshagen <dm-devel@redhat.com>");
  MODULE_LICENSE("GPL");