Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2003 Sistina Software Limited. |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 3 | * Copyright (C) 2005-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 GPL. |
| 6 | */ |
| 7 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 8 | #include "dm-bio-record.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/init.h> |
| 11 | #include <linux/mempool.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/pagemap.h> |
| 14 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/workqueue.h> |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 16 | #include <linux/device-mapper.h> |
Alasdair G Kergon | a765e20 | 2008-04-24 22:02:01 +0100 | [diff] [blame] | 17 | #include <linux/dm-io.h> |
| 18 | #include <linux/dm-dirty-log.h> |
| 19 | #include <linux/dm-kcopyd.h> |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 20 | #include <linux/dm-region-hash.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 22 | #define DM_MSG_PREFIX "raid1" |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 23 | |
| 24 | #define MAX_RECOVERY 1 /* Maximum number of regions recovered in parallel. */ |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 25 | |
Lidong Zhong | ed63287 | 2015-05-13 14:04:10 +0800 | [diff] [blame] | 26 | #define DM_RAID1_HANDLE_ERRORS 0x01 |
| 27 | #define DM_RAID1_KEEP_LOG 0x02 |
Jonathan Brassow | f44db67 | 2007-07-12 17:29:04 +0100 | [diff] [blame] | 28 | #define errors_handled(p) ((p)->features & DM_RAID1_HANDLE_ERRORS) |
Lidong Zhong | ed63287 | 2015-05-13 14:04:10 +0800 | [diff] [blame] | 29 | #define keep_log(p) ((p)->features & DM_RAID1_KEEP_LOG) |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 30 | |
Jonathan E Brassow | 3318404 | 2006-11-08 17:44:44 -0800 | [diff] [blame] | 31 | static DECLARE_WAIT_QUEUE_HEAD(_kmirrord_recovery_stopped); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | /*----------------------------------------------------------------- |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 34 | * Mirror set structures. |
| 35 | *---------------------------------------------------------------*/ |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 36 | enum dm_raid1_error { |
| 37 | DM_RAID1_WRITE_ERROR, |
Mikulas Patocka | 64b30c4 | 2009-12-10 23:52:02 +0000 | [diff] [blame] | 38 | DM_RAID1_FLUSH_ERROR, |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 39 | DM_RAID1_SYNC_ERROR, |
| 40 | DM_RAID1_READ_ERROR |
| 41 | }; |
| 42 | |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 43 | struct mirror { |
Jonathan Brassow | aa5617c | 2007-10-19 22:47:58 +0100 | [diff] [blame] | 44 | struct mirror_set *ms; |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 45 | atomic_t error_count; |
Al Viro | 39ed7ad | 2008-02-13 03:53:00 +0000 | [diff] [blame] | 46 | unsigned long error_type; |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 47 | struct dm_dev *dev; |
| 48 | sector_t offset; |
| 49 | }; |
| 50 | |
| 51 | struct mirror_set { |
| 52 | struct dm_target *ti; |
| 53 | struct list_head list; |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 54 | |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 55 | uint64_t features; |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 56 | |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 57 | spinlock_t lock; /* protects the lists */ |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 58 | struct bio_list reads; |
| 59 | struct bio_list writes; |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 60 | struct bio_list failures; |
Mikulas Patocka | 0478850 | 2009-12-10 23:52:03 +0000 | [diff] [blame] | 61 | struct bio_list holds; /* bios are waiting until suspend */ |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 62 | |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 63 | struct dm_region_hash *rh; |
| 64 | struct dm_kcopyd_client *kcopyd_client; |
Milan Broz | 88be163 | 2007-05-09 02:33:04 -0700 | [diff] [blame] | 65 | struct dm_io_client *io_client; |
| 66 | |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 67 | /* recovery */ |
| 68 | region_t nr_regions; |
| 69 | int in_sync; |
Jonathan Brassow | fc1ff95 | 2007-07-12 17:29:15 +0100 | [diff] [blame] | 70 | int log_failure; |
Mikulas Patocka | 929be8f | 2009-12-10 23:52:06 +0000 | [diff] [blame] | 71 | int leg_failure; |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 72 | atomic_t suspend; |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 73 | |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 74 | atomic_t default_mirror; /* Default mirror */ |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 75 | |
Holger Smolinski | 6ad36fe | 2007-05-09 02:32:50 -0700 | [diff] [blame] | 76 | struct workqueue_struct *kmirrord_wq; |
| 77 | struct work_struct kmirrord_work; |
Mikulas Patocka | a2aebe0 | 2008-04-24 22:10:42 +0100 | [diff] [blame] | 78 | struct timer_list timer; |
| 79 | unsigned long timer_pending; |
| 80 | |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 81 | struct work_struct trigger_event; |
Holger Smolinski | 6ad36fe | 2007-05-09 02:32:50 -0700 | [diff] [blame] | 82 | |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 83 | unsigned nr_mirrors; |
Neil Brown | e4c8b3b | 2006-06-26 00:27:26 -0700 | [diff] [blame] | 84 | struct mirror mirror[0]; |
| 85 | }; |
| 86 | |
Mikulas Patocka | df5d2e9 | 2013-03-01 22:45:49 +0000 | [diff] [blame] | 87 | DECLARE_DM_KCOPYD_THROTTLE_WITH_MODULE_PARM(raid1_resync_throttle, |
| 88 | "A percentage of time allocated for raid resynchronization"); |
| 89 | |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 90 | static void wakeup_mirrord(void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 92 | struct mirror_set *ms = context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Holger Smolinski | 6ad36fe | 2007-05-09 02:32:50 -0700 | [diff] [blame] | 94 | queue_work(ms->kmirrord_wq, &ms->kmirrord_work); |
| 95 | } |
| 96 | |
Mikulas Patocka | a2aebe0 | 2008-04-24 22:10:42 +0100 | [diff] [blame] | 97 | static void delayed_wake_fn(unsigned long data) |
| 98 | { |
| 99 | struct mirror_set *ms = (struct mirror_set *) data; |
| 100 | |
| 101 | clear_bit(0, &ms->timer_pending); |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 102 | wakeup_mirrord(ms); |
Mikulas Patocka | a2aebe0 | 2008-04-24 22:10:42 +0100 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | static void delayed_wake(struct mirror_set *ms) |
| 106 | { |
| 107 | if (test_and_set_bit(0, &ms->timer_pending)) |
| 108 | return; |
| 109 | |
| 110 | ms->timer.expires = jiffies + HZ / 5; |
| 111 | ms->timer.data = (unsigned long) ms; |
| 112 | ms->timer.function = delayed_wake_fn; |
| 113 | add_timer(&ms->timer); |
| 114 | } |
| 115 | |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 116 | static void wakeup_all_recovery_waiters(void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | { |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 118 | wake_up_all(&_kmirrord_recovery_stopped); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 121 | static void queue_bio(struct mirror_set *ms, struct bio *bio, int rw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
| 123 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | int should_wake = 0; |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 125 | struct bio_list *bl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 127 | bl = (rw == WRITE) ? &ms->writes : &ms->reads; |
| 128 | spin_lock_irqsave(&ms->lock, flags); |
| 129 | should_wake = !(bl->head); |
| 130 | bio_list_add(bl, bio); |
| 131 | spin_unlock_irqrestore(&ms->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
| 133 | if (should_wake) |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 134 | wakeup_mirrord(ms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 137 | static void dispatch_bios(void *context, struct bio_list *bio_list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | { |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 139 | struct mirror_set *ms = context; |
| 140 | struct bio *bio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 142 | while ((bio = bio_list_pop(bio_list))) |
| 143 | queue_bio(ms, bio, WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Mikulas Patocka | 89c7cd8 | 2012-12-21 20:23:39 +0000 | [diff] [blame] | 146 | struct dm_raid1_bio_record { |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 147 | struct mirror *m; |
Mikulas Patocka | 0045d61 | 2012-12-21 20:23:40 +0000 | [diff] [blame] | 148 | /* if details->bi_bdev == NULL, details were not saved */ |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 149 | struct dm_bio_details details; |
Mikulas Patocka | 0045d61 | 2012-12-21 20:23:40 +0000 | [diff] [blame] | 150 | region_t write_region; |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 151 | }; |
| 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | /* |
| 154 | * Every mirror should look like this one. |
| 155 | */ |
| 156 | #define DEFAULT_MIRROR 0 |
| 157 | |
| 158 | /* |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 159 | * This is yucky. We squirrel the mirror struct away inside |
| 160 | * bi_next for read/write buffers. This is safe since the bh |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | * doesn't get submitted to the lower levels of block layer. |
| 162 | */ |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 163 | static struct mirror *bio_get_m(struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | { |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 165 | return (struct mirror *) bio->bi_next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 168 | static void bio_set_m(struct bio *bio, struct mirror *m) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | { |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 170 | bio->bi_next = (struct bio *) m; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 173 | static struct mirror *get_default_mirror(struct mirror_set *ms) |
| 174 | { |
| 175 | return &ms->mirror[atomic_read(&ms->default_mirror)]; |
| 176 | } |
| 177 | |
| 178 | static void set_default_mirror(struct mirror *m) |
| 179 | { |
| 180 | struct mirror_set *ms = m->ms; |
| 181 | struct mirror *m0 = &(ms->mirror[0]); |
| 182 | |
| 183 | atomic_set(&ms->default_mirror, m - m0); |
| 184 | } |
| 185 | |
Mikulas Patocka | 87968dd | 2009-12-10 23:52:04 +0000 | [diff] [blame] | 186 | static struct mirror *get_valid_mirror(struct mirror_set *ms) |
| 187 | { |
| 188 | struct mirror *m; |
| 189 | |
| 190 | for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++) |
| 191 | if (!atomic_read(&m->error_count)) |
| 192 | return m; |
| 193 | |
| 194 | return NULL; |
| 195 | } |
| 196 | |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 197 | /* fail_mirror |
| 198 | * @m: mirror device to fail |
| 199 | * @error_type: one of the enum's, DM_RAID1_*_ERROR |
| 200 | * |
| 201 | * If errors are being handled, record the type of |
| 202 | * error encountered for this device. If this type |
| 203 | * of error has already been recorded, we can return; |
| 204 | * otherwise, we must signal userspace by triggering |
| 205 | * an event. Additionally, if the device is the |
| 206 | * primary device, we must choose a new primary, but |
| 207 | * only if the mirror is in-sync. |
| 208 | * |
| 209 | * This function must not block. |
| 210 | */ |
| 211 | static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type) |
| 212 | { |
| 213 | struct mirror_set *ms = m->ms; |
| 214 | struct mirror *new; |
| 215 | |
Mikulas Patocka | 929be8f | 2009-12-10 23:52:06 +0000 | [diff] [blame] | 216 | ms->leg_failure = 1; |
| 217 | |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 218 | /* |
| 219 | * error_count is used for nothing more than a |
| 220 | * simple way to tell if a device has encountered |
| 221 | * errors. |
| 222 | */ |
| 223 | atomic_inc(&m->error_count); |
| 224 | |
| 225 | if (test_and_set_bit(error_type, &m->error_type)) |
| 226 | return; |
| 227 | |
Jonathan Brassow | d460c65 | 2009-01-06 03:04:57 +0000 | [diff] [blame] | 228 | if (!errors_handled(ms)) |
| 229 | return; |
| 230 | |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 231 | if (m != get_default_mirror(ms)) |
| 232 | goto out; |
| 233 | |
Lidong Zhong | ed63287 | 2015-05-13 14:04:10 +0800 | [diff] [blame] | 234 | if (!ms->in_sync && !keep_log(ms)) { |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 235 | /* |
| 236 | * Better to issue requests to same failing device |
| 237 | * than to risk returning corrupt data. |
| 238 | */ |
| 239 | DMERR("Primary mirror (%s) failed while out-of-sync: " |
| 240 | "Reads may fail.", m->dev->name); |
| 241 | goto out; |
| 242 | } |
| 243 | |
Mikulas Patocka | 87968dd | 2009-12-10 23:52:04 +0000 | [diff] [blame] | 244 | new = get_valid_mirror(ms); |
| 245 | if (new) |
| 246 | set_default_mirror(new); |
| 247 | else |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 248 | DMWARN("All sides of mirror have failed."); |
| 249 | |
| 250 | out: |
| 251 | schedule_work(&ms->trigger_event); |
| 252 | } |
| 253 | |
Mikulas Patocka | c0da374 | 2009-12-10 23:52:02 +0000 | [diff] [blame] | 254 | static int mirror_flush(struct dm_target *ti) |
| 255 | { |
| 256 | struct mirror_set *ms = ti->private; |
| 257 | unsigned long error_bits; |
| 258 | |
| 259 | unsigned int i; |
| 260 | struct dm_io_region io[ms->nr_mirrors]; |
| 261 | struct mirror *m; |
| 262 | struct dm_io_request io_req = { |
Mike Christie | e604714 | 2016-06-05 14:32:04 -0500 | [diff] [blame] | 263 | .bi_op = REQ_OP_WRITE, |
| 264 | .bi_op_flags = WRITE_FLUSH, |
Mikulas Patocka | c0da374 | 2009-12-10 23:52:02 +0000 | [diff] [blame] | 265 | .mem.type = DM_IO_KMEM, |
Mike Snitzer | 5fc2ffe | 2011-01-13 19:59:48 +0000 | [diff] [blame] | 266 | .mem.ptr.addr = NULL, |
Mikulas Patocka | c0da374 | 2009-12-10 23:52:02 +0000 | [diff] [blame] | 267 | .client = ms->io_client, |
| 268 | }; |
| 269 | |
| 270 | for (i = 0, m = ms->mirror; i < ms->nr_mirrors; i++, m++) { |
| 271 | io[i].bdev = m->dev->bdev; |
| 272 | io[i].sector = 0; |
| 273 | io[i].count = 0; |
| 274 | } |
| 275 | |
| 276 | error_bits = -1; |
| 277 | dm_io(&io_req, ms->nr_mirrors, io, &error_bits); |
| 278 | if (unlikely(error_bits != 0)) { |
| 279 | for (i = 0; i < ms->nr_mirrors; i++) |
| 280 | if (test_bit(i, &error_bits)) |
| 281 | fail_mirror(ms->mirror + i, |
Mikulas Patocka | 64b30c4 | 2009-12-10 23:52:02 +0000 | [diff] [blame] | 282 | DM_RAID1_FLUSH_ERROR); |
Mikulas Patocka | c0da374 | 2009-12-10 23:52:02 +0000 | [diff] [blame] | 283 | return -EIO; |
| 284 | } |
| 285 | |
| 286 | return 0; |
| 287 | } |
| 288 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | /*----------------------------------------------------------------- |
| 290 | * Recovery. |
| 291 | * |
| 292 | * When a mirror is first activated we may find that some regions |
| 293 | * are in the no-sync state. We have to recover these by |
| 294 | * recopying from the default mirror to all the others. |
| 295 | *---------------------------------------------------------------*/ |
Alasdair G Kergon | 4cdc1d1 | 2008-03-28 14:16:10 -0700 | [diff] [blame] | 296 | static void recovery_complete(int read_err, unsigned long write_err, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | void *context) |
| 298 | { |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 299 | struct dm_region *reg = context; |
| 300 | struct mirror_set *ms = dm_rh_region_context(reg); |
Jonathan Brassow | 8f0205b | 2008-02-08 02:11:32 +0000 | [diff] [blame] | 301 | int m, bit = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
Jonathan Brassow | 8f0205b | 2008-02-08 02:11:32 +0000 | [diff] [blame] | 303 | if (read_err) { |
Jonathan Brassow | f44db67 | 2007-07-12 17:29:04 +0100 | [diff] [blame] | 304 | /* Read error means the failure of default mirror. */ |
| 305 | DMERR_LIMIT("Unable to read primary mirror during recovery"); |
Jonathan Brassow | 8f0205b | 2008-02-08 02:11:32 +0000 | [diff] [blame] | 306 | fail_mirror(get_default_mirror(ms), DM_RAID1_SYNC_ERROR); |
| 307 | } |
Jonathan Brassow | f44db67 | 2007-07-12 17:29:04 +0100 | [diff] [blame] | 308 | |
Jonathan Brassow | 8f0205b | 2008-02-08 02:11:32 +0000 | [diff] [blame] | 309 | if (write_err) { |
Alasdair G Kergon | 4cdc1d1 | 2008-03-28 14:16:10 -0700 | [diff] [blame] | 310 | DMERR_LIMIT("Write error during recovery (error = 0x%lx)", |
Jonathan Brassow | f44db67 | 2007-07-12 17:29:04 +0100 | [diff] [blame] | 311 | write_err); |
Jonathan Brassow | 8f0205b | 2008-02-08 02:11:32 +0000 | [diff] [blame] | 312 | /* |
| 313 | * Bits correspond to devices (excluding default mirror). |
| 314 | * The default mirror cannot change during recovery. |
| 315 | */ |
| 316 | for (m = 0; m < ms->nr_mirrors; m++) { |
| 317 | if (&ms->mirror[m] == get_default_mirror(ms)) |
| 318 | continue; |
| 319 | if (test_bit(bit, &write_err)) |
| 320 | fail_mirror(ms->mirror + m, |
| 321 | DM_RAID1_SYNC_ERROR); |
| 322 | bit++; |
| 323 | } |
| 324 | } |
Jonathan Brassow | f44db67 | 2007-07-12 17:29:04 +0100 | [diff] [blame] | 325 | |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 326 | dm_rh_recovery_end(reg, !(read_err || write_err)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 329 | static int recover(struct mirror_set *ms, struct dm_region *reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | { |
| 331 | int r; |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 332 | unsigned i; |
Heinz Mauelshagen | eb69aca | 2008-04-24 21:43:19 +0100 | [diff] [blame] | 333 | struct dm_io_region from, to[DM_KCOPYD_MAX_REGIONS], *dest; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | struct mirror *m; |
| 335 | unsigned long flags = 0; |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 336 | region_t key = dm_rh_get_region_key(reg); |
| 337 | sector_t region_size = dm_rh_get_region_size(ms->rh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
| 339 | /* fill in the source */ |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 340 | m = get_default_mirror(ms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | from.bdev = m->dev->bdev; |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 342 | from.sector = m->offset + dm_rh_region_to_sector(ms->rh, key); |
| 343 | if (key == (ms->nr_regions - 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | /* |
| 345 | * The final region may be smaller than |
| 346 | * region_size. |
| 347 | */ |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 348 | from.count = ms->ti->len & (region_size - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | if (!from.count) |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 350 | from.count = region_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } else |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 352 | from.count = region_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
| 354 | /* fill in the destinations */ |
| 355 | for (i = 0, dest = to; i < ms->nr_mirrors; i++) { |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 356 | if (&ms->mirror[i] == get_default_mirror(ms)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | continue; |
| 358 | |
| 359 | m = ms->mirror + i; |
| 360 | dest->bdev = m->dev->bdev; |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 361 | dest->sector = m->offset + dm_rh_region_to_sector(ms->rh, key); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | dest->count = from.count; |
| 363 | dest++; |
| 364 | } |
| 365 | |
| 366 | /* hand to kcopyd */ |
Jonathan Brassow | f7c83e2 | 2008-10-10 13:36:59 +0100 | [diff] [blame] | 367 | if (!errors_handled(ms)) |
| 368 | set_bit(DM_KCOPYD_IGNORE_ERROR, &flags); |
| 369 | |
Heinz Mauelshagen | eb69aca | 2008-04-24 21:43:19 +0100 | [diff] [blame] | 370 | r = dm_kcopyd_copy(ms->kcopyd_client, &from, ms->nr_mirrors - 1, to, |
| 371 | flags, recovery_complete, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
| 373 | return r; |
| 374 | } |
| 375 | |
Lidong Zhong | ed63287 | 2015-05-13 14:04:10 +0800 | [diff] [blame] | 376 | static void reset_ms_flags(struct mirror_set *ms) |
| 377 | { |
| 378 | unsigned int m; |
| 379 | |
| 380 | ms->leg_failure = 0; |
| 381 | for (m = 0; m < ms->nr_mirrors; m++) { |
| 382 | atomic_set(&(ms->mirror[m].error_count), 0); |
| 383 | ms->mirror[m].error_type = 0; |
| 384 | } |
| 385 | } |
| 386 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | static void do_recovery(struct mirror_set *ms) |
| 388 | { |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 389 | struct dm_region *reg; |
| 390 | struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | int r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
| 393 | /* |
| 394 | * Start quiescing some regions. |
| 395 | */ |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 396 | dm_rh_recovery_prepare(ms->rh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
| 398 | /* |
| 399 | * Copy any already quiesced regions. |
| 400 | */ |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 401 | while ((reg = dm_rh_recovery_start(ms->rh))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | r = recover(ms, reg); |
| 403 | if (r) |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 404 | dm_rh_recovery_end(reg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | /* |
| 408 | * Update the in sync flag. |
| 409 | */ |
| 410 | if (!ms->in_sync && |
| 411 | (log->type->get_sync_count(log) == ms->nr_regions)) { |
| 412 | /* the sync is complete */ |
| 413 | dm_table_event(ms->ti->table); |
| 414 | ms->in_sync = 1; |
Lidong Zhong | ed63287 | 2015-05-13 14:04:10 +0800 | [diff] [blame] | 415 | reset_ms_flags(ms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | |
| 419 | /*----------------------------------------------------------------- |
| 420 | * Reads |
| 421 | *---------------------------------------------------------------*/ |
| 422 | static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector) |
| 423 | { |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 424 | struct mirror *m = get_default_mirror(ms); |
| 425 | |
| 426 | do { |
| 427 | if (likely(!atomic_read(&m->error_count))) |
| 428 | return m; |
| 429 | |
| 430 | if (m-- == ms->mirror) |
| 431 | m += ms->nr_mirrors; |
| 432 | } while (m != get_default_mirror(ms)); |
| 433 | |
| 434 | return NULL; |
| 435 | } |
| 436 | |
| 437 | static int default_ok(struct mirror *m) |
| 438 | { |
| 439 | struct mirror *default_mirror = get_default_mirror(m->ms); |
| 440 | |
| 441 | return !atomic_read(&default_mirror->error_count); |
| 442 | } |
| 443 | |
| 444 | static int mirror_available(struct mirror_set *ms, struct bio *bio) |
| 445 | { |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 446 | struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); |
| 447 | region_t region = dm_rh_bio_to_region(ms->rh, bio); |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 448 | |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 449 | if (log->type->in_sync(log, region, 0)) |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 450 | return choose_mirror(ms, bio->bi_iter.bi_sector) ? 1 : 0; |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 451 | |
| 452 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | /* |
| 456 | * remap a buffer to a particular mirror. |
| 457 | */ |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 458 | static sector_t map_sector(struct mirror *m, struct bio *bio) |
| 459 | { |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 460 | if (unlikely(!bio->bi_iter.bi_size)) |
Mikulas Patocka | 4184153 | 2009-12-10 23:51:59 +0000 | [diff] [blame] | 461 | return 0; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 462 | return m->offset + dm_target_offset(m->ms->ti, bio->bi_iter.bi_sector); |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | static void map_bio(struct mirror *m, struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | { |
| 467 | bio->bi_bdev = m->dev->bdev; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 468 | bio->bi_iter.bi_sector = map_sector(m, bio); |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Heinz Mauelshagen | 22a1ceb | 2008-04-24 21:43:17 +0100 | [diff] [blame] | 471 | static void map_region(struct dm_io_region *io, struct mirror *m, |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 472 | struct bio *bio) |
| 473 | { |
| 474 | io->bdev = m->dev->bdev; |
| 475 | io->sector = map_sector(m, bio); |
Kent Overstreet | aa8b57a | 2013-02-05 15:19:29 -0800 | [diff] [blame] | 476 | io->count = bio_sectors(bio); |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Mikulas Patocka | 0478850 | 2009-12-10 23:52:03 +0000 | [diff] [blame] | 479 | static void hold_bio(struct mirror_set *ms, struct bio *bio) |
| 480 | { |
| 481 | /* |
Takahiro Yasui | f070304 | 2010-03-06 02:32:35 +0000 | [diff] [blame] | 482 | * Lock is required to avoid race condition during suspend |
| 483 | * process. |
Mikulas Patocka | 0478850 | 2009-12-10 23:52:03 +0000 | [diff] [blame] | 484 | */ |
Takahiro Yasui | f070304 | 2010-03-06 02:32:35 +0000 | [diff] [blame] | 485 | spin_lock_irq(&ms->lock); |
| 486 | |
Mikulas Patocka | 0478850 | 2009-12-10 23:52:03 +0000 | [diff] [blame] | 487 | if (atomic_read(&ms->suspend)) { |
Takahiro Yasui | f070304 | 2010-03-06 02:32:35 +0000 | [diff] [blame] | 488 | spin_unlock_irq(&ms->lock); |
| 489 | |
| 490 | /* |
| 491 | * If device is suspended, complete the bio. |
| 492 | */ |
Mikulas Patocka | 0478850 | 2009-12-10 23:52:03 +0000 | [diff] [blame] | 493 | if (dm_noflush_suspending(ms->ti)) |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 494 | bio->bi_error = DM_ENDIO_REQUEUE; |
Mikulas Patocka | 0478850 | 2009-12-10 23:52:03 +0000 | [diff] [blame] | 495 | else |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 496 | bio->bi_error = -EIO; |
| 497 | |
| 498 | bio_endio(bio); |
Mikulas Patocka | 0478850 | 2009-12-10 23:52:03 +0000 | [diff] [blame] | 499 | return; |
| 500 | } |
| 501 | |
| 502 | /* |
| 503 | * Hold bio until the suspend is complete. |
| 504 | */ |
Mikulas Patocka | 0478850 | 2009-12-10 23:52:03 +0000 | [diff] [blame] | 505 | bio_list_add(&ms->holds, bio); |
| 506 | spin_unlock_irq(&ms->lock); |
| 507 | } |
| 508 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 509 | /*----------------------------------------------------------------- |
| 510 | * Reads |
| 511 | *---------------------------------------------------------------*/ |
| 512 | static void read_callback(unsigned long error, void *context) |
| 513 | { |
| 514 | struct bio *bio = context; |
| 515 | struct mirror *m; |
| 516 | |
| 517 | m = bio_get_m(bio); |
| 518 | bio_set_m(bio, NULL); |
| 519 | |
| 520 | if (likely(!error)) { |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 521 | bio_endio(bio); |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 522 | return; |
| 523 | } |
| 524 | |
| 525 | fail_mirror(m, DM_RAID1_READ_ERROR); |
| 526 | |
| 527 | if (likely(default_ok(m)) || mirror_available(m->ms, bio)) { |
| 528 | DMWARN_LIMIT("Read failure on mirror device %s. " |
| 529 | "Trying alternative device.", |
| 530 | m->dev->name); |
| 531 | queue_bio(m->ms, bio, bio_rw(bio)); |
| 532 | return; |
| 533 | } |
| 534 | |
| 535 | DMERR_LIMIT("Read failure on mirror device %s. Failing I/O.", |
| 536 | m->dev->name); |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 537 | bio_io_error(bio); |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | /* Asynchronous read. */ |
| 541 | static void read_async_bio(struct mirror *m, struct bio *bio) |
| 542 | { |
Heinz Mauelshagen | 22a1ceb | 2008-04-24 21:43:17 +0100 | [diff] [blame] | 543 | struct dm_io_region io; |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 544 | struct dm_io_request io_req = { |
Mike Christie | e604714 | 2016-06-05 14:32:04 -0500 | [diff] [blame] | 545 | .bi_op = REQ_OP_READ, |
| 546 | .bi_op_flags = 0, |
Kent Overstreet | 003b5c5 | 2013-10-11 15:45:43 -0700 | [diff] [blame] | 547 | .mem.type = DM_IO_BIO, |
| 548 | .mem.ptr.bio = bio, |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 549 | .notify.fn = read_callback, |
| 550 | .notify.context = bio, |
| 551 | .client = m->ms->io_client, |
| 552 | }; |
| 553 | |
| 554 | map_region(&io, m, bio); |
| 555 | bio_set_m(bio, m); |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 556 | BUG_ON(dm_io(&io_req, 1, &io, NULL)); |
| 557 | } |
| 558 | |
| 559 | static inline int region_in_sync(struct mirror_set *ms, region_t region, |
| 560 | int may_block) |
| 561 | { |
| 562 | int state = dm_rh_get_state(ms->rh, region, may_block); |
| 563 | return state == DM_RH_CLEAN || state == DM_RH_DIRTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | static void do_reads(struct mirror_set *ms, struct bio_list *reads) |
| 567 | { |
| 568 | region_t region; |
| 569 | struct bio *bio; |
| 570 | struct mirror *m; |
| 571 | |
| 572 | while ((bio = bio_list_pop(reads))) { |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 573 | region = dm_rh_bio_to_region(ms->rh, bio); |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 574 | m = get_default_mirror(ms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
| 576 | /* |
| 577 | * We can only read balance if the region is in sync. |
| 578 | */ |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 579 | if (likely(region_in_sync(ms, region, 1))) |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 580 | m = choose_mirror(ms, bio->bi_iter.bi_sector); |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 581 | else if (m && atomic_read(&m->error_count)) |
| 582 | m = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 584 | if (likely(m)) |
| 585 | read_async_bio(m, bio); |
| 586 | else |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 587 | bio_io_error(bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | |
| 591 | /*----------------------------------------------------------------- |
| 592 | * Writes. |
| 593 | * |
| 594 | * We do different things with the write io depending on the |
| 595 | * state of the region that it's in: |
| 596 | * |
| 597 | * SYNC: increment pending, use kcopyd to write to *all* mirrors |
| 598 | * RECOVERING: delay the io until recovery completes |
| 599 | * NOSYNC: increment pending, just write to the default mirror |
| 600 | *---------------------------------------------------------------*/ |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 601 | |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | static void write_callback(unsigned long error, void *context) |
| 604 | { |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 605 | unsigned i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | struct bio *bio = (struct bio *) context; |
| 607 | struct mirror_set *ms; |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 608 | int should_wake = 0; |
| 609 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 611 | ms = bio_get_m(bio)->ms; |
| 612 | bio_set_m(bio, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
| 614 | /* |
| 615 | * NOTE: We don't decrement the pending count here, |
| 616 | * instead it is done by the targets endio function. |
| 617 | * This way we handle both writes to SYNC and NOSYNC |
| 618 | * regions with the same code. |
| 619 | */ |
Mikulas Patocka | 60f355e | 2009-12-10 23:52:05 +0000 | [diff] [blame] | 620 | if (likely(!error)) { |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 621 | bio_endio(bio); |
Mikulas Patocka | 60f355e | 2009-12-10 23:52:05 +0000 | [diff] [blame] | 622 | return; |
| 623 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
Mikulas Patocka | f2ed51a | 2015-02-12 10:09:20 -0500 | [diff] [blame] | 625 | /* |
| 626 | * If the bio is discard, return an error, but do not |
| 627 | * degrade the array. |
| 628 | */ |
Mike Christie | e604714 | 2016-06-05 14:32:04 -0500 | [diff] [blame] | 629 | if (bio_op(bio) == REQ_OP_DISCARD) { |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 630 | bio->bi_error = -EOPNOTSUPP; |
| 631 | bio_endio(bio); |
Mikulas Patocka | f2ed51a | 2015-02-12 10:09:20 -0500 | [diff] [blame] | 632 | return; |
| 633 | } |
| 634 | |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 635 | for (i = 0; i < ms->nr_mirrors; i++) |
| 636 | if (test_bit(i, &error)) |
| 637 | fail_mirror(ms->mirror + i, DM_RAID1_WRITE_ERROR); |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 638 | |
Mikulas Patocka | 60f355e | 2009-12-10 23:52:05 +0000 | [diff] [blame] | 639 | /* |
| 640 | * Need to raise event. Since raising |
| 641 | * events can block, we need to do it in |
| 642 | * the main thread. |
| 643 | */ |
| 644 | spin_lock_irqsave(&ms->lock, flags); |
| 645 | if (!ms->failures.head) |
| 646 | should_wake = 1; |
| 647 | bio_list_add(&ms->failures, bio); |
| 648 | spin_unlock_irqrestore(&ms->lock, flags); |
| 649 | if (should_wake) |
| 650 | wakeup_mirrord(ms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | static void do_write(struct mirror_set *ms, struct bio *bio) |
| 654 | { |
| 655 | unsigned int i; |
Heinz Mauelshagen | 22a1ceb | 2008-04-24 21:43:17 +0100 | [diff] [blame] | 656 | struct dm_io_region io[ms->nr_mirrors], *dest = io; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | struct mirror *m; |
Milan Broz | 88be163 | 2007-05-09 02:33:04 -0700 | [diff] [blame] | 658 | struct dm_io_request io_req = { |
Mike Christie | e604714 | 2016-06-05 14:32:04 -0500 | [diff] [blame] | 659 | .bi_op = REQ_OP_WRITE, |
| 660 | .bi_op_flags = bio->bi_rw & WRITE_FLUSH_FUA, |
Kent Overstreet | 003b5c5 | 2013-10-11 15:45:43 -0700 | [diff] [blame] | 661 | .mem.type = DM_IO_BIO, |
| 662 | .mem.ptr.bio = bio, |
Milan Broz | 88be163 | 2007-05-09 02:33:04 -0700 | [diff] [blame] | 663 | .notify.fn = write_callback, |
| 664 | .notify.context = bio, |
| 665 | .client = ms->io_client, |
| 666 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | |
Mike Christie | e604714 | 2016-06-05 14:32:04 -0500 | [diff] [blame] | 668 | if (bio_op(bio) == REQ_OP_DISCARD) { |
| 669 | io_req.bi_op = REQ_OP_DISCARD; |
Mike Snitzer | 5fc2ffe | 2011-01-13 19:59:48 +0000 | [diff] [blame] | 670 | io_req.mem.type = DM_IO_KMEM; |
| 671 | io_req.mem.ptr.addr = NULL; |
| 672 | } |
| 673 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 674 | for (i = 0, m = ms->mirror; i < ms->nr_mirrors; i++, m++) |
| 675 | map_region(dest++, m, bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 677 | /* |
| 678 | * Use default mirror because we only need it to retrieve the reference |
| 679 | * to the mirror set in write_callback(). |
| 680 | */ |
| 681 | bio_set_m(bio, get_default_mirror(ms)); |
Milan Broz | 88be163 | 2007-05-09 02:33:04 -0700 | [diff] [blame] | 682 | |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 683 | BUG_ON(dm_io(&io_req, ms->nr_mirrors, io, NULL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | static void do_writes(struct mirror_set *ms, struct bio_list *writes) |
| 687 | { |
| 688 | int state; |
| 689 | struct bio *bio; |
| 690 | struct bio_list sync, nosync, recover, *this_list = NULL; |
Jonathan Brassow | 7513c2a | 2009-04-02 19:55:30 +0100 | [diff] [blame] | 691 | struct bio_list requeue; |
| 692 | struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); |
| 693 | region_t region; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | |
| 695 | if (!writes->head) |
| 696 | return; |
| 697 | |
| 698 | /* |
| 699 | * Classify each write. |
| 700 | */ |
| 701 | bio_list_init(&sync); |
| 702 | bio_list_init(&nosync); |
| 703 | bio_list_init(&recover); |
Jonathan Brassow | 7513c2a | 2009-04-02 19:55:30 +0100 | [diff] [blame] | 704 | bio_list_init(&requeue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | |
| 706 | while ((bio = bio_list_pop(writes))) { |
Mike Christie | 28a8f0d | 2016-06-05 14:32:25 -0500 | [diff] [blame^] | 707 | if ((bio->bi_rw & REQ_PREFLUSH) || |
Mike Christie | e604714 | 2016-06-05 14:32:04 -0500 | [diff] [blame] | 708 | (bio_op(bio) == REQ_OP_DISCARD)) { |
Mikulas Patocka | 4184153 | 2009-12-10 23:51:59 +0000 | [diff] [blame] | 709 | bio_list_add(&sync, bio); |
| 710 | continue; |
| 711 | } |
| 712 | |
Jonathan Brassow | 7513c2a | 2009-04-02 19:55:30 +0100 | [diff] [blame] | 713 | region = dm_rh_bio_to_region(ms->rh, bio); |
| 714 | |
| 715 | if (log->type->is_remote_recovering && |
| 716 | log->type->is_remote_recovering(log, region)) { |
| 717 | bio_list_add(&requeue, bio); |
| 718 | continue; |
| 719 | } |
| 720 | |
| 721 | state = dm_rh_get_state(ms->rh, region, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | switch (state) { |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 723 | case DM_RH_CLEAN: |
| 724 | case DM_RH_DIRTY: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | this_list = &sync; |
| 726 | break; |
| 727 | |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 728 | case DM_RH_NOSYNC: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | this_list = &nosync; |
| 730 | break; |
| 731 | |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 732 | case DM_RH_RECOVERING: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | this_list = &recover; |
| 734 | break; |
| 735 | } |
| 736 | |
| 737 | bio_list_add(this_list, bio); |
| 738 | } |
| 739 | |
| 740 | /* |
Jonathan Brassow | 7513c2a | 2009-04-02 19:55:30 +0100 | [diff] [blame] | 741 | * Add bios that are delayed due to remote recovery |
| 742 | * back on to the write queue |
| 743 | */ |
| 744 | if (unlikely(requeue.head)) { |
| 745 | spin_lock_irq(&ms->lock); |
| 746 | bio_list_merge(&ms->writes, &requeue); |
| 747 | spin_unlock_irq(&ms->lock); |
Mikulas Patocka | 6988568 | 2009-07-23 20:30:37 +0100 | [diff] [blame] | 748 | delayed_wake(ms); |
Jonathan Brassow | 7513c2a | 2009-04-02 19:55:30 +0100 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | * Increment the pending counts for any regions that will |
| 753 | * be written to (writes to recover regions are going to |
| 754 | * be delayed). |
| 755 | */ |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 756 | dm_rh_inc_pending(ms->rh, &sync); |
| 757 | dm_rh_inc_pending(ms->rh, &nosync); |
Jonathan Brassow | d2b6986 | 2009-09-04 20:40:32 +0100 | [diff] [blame] | 758 | |
| 759 | /* |
| 760 | * If the flush fails on a previous call and succeeds here, |
| 761 | * we must not reset the log_failure variable. We need |
| 762 | * userspace interaction to do that. |
| 763 | */ |
| 764 | ms->log_failure = dm_rh_flush(ms->rh) ? 1 : ms->log_failure; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | |
| 766 | /* |
| 767 | * Dispatch io. |
| 768 | */ |
Mikulas Patocka | 5528d17 | 2010-02-16 18:42:55 +0000 | [diff] [blame] | 769 | if (unlikely(ms->log_failure) && errors_handled(ms)) { |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 770 | spin_lock_irq(&ms->lock); |
| 771 | bio_list_merge(&ms->failures, &sync); |
| 772 | spin_unlock_irq(&ms->lock); |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 773 | wakeup_mirrord(ms); |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 774 | } else |
Jonathan Brassow | fc1ff95 | 2007-07-12 17:29:15 +0100 | [diff] [blame] | 775 | while ((bio = bio_list_pop(&sync))) |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 776 | do_write(ms, bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | |
| 778 | while ((bio = bio_list_pop(&recover))) |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 779 | dm_rh_delay(ms->rh, bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | |
| 781 | while ((bio = bio_list_pop(&nosync))) { |
Lidong Zhong | ed63287 | 2015-05-13 14:04:10 +0800 | [diff] [blame] | 782 | if (unlikely(ms->leg_failure) && errors_handled(ms) && !keep_log(ms)) { |
Mikulas Patocka | ede5ea0 | 2010-03-06 02:32:22 +0000 | [diff] [blame] | 783 | spin_lock_irq(&ms->lock); |
| 784 | bio_list_add(&ms->failures, bio); |
| 785 | spin_unlock_irq(&ms->lock); |
| 786 | wakeup_mirrord(ms); |
| 787 | } else { |
Mikulas Patocka | 929be8f | 2009-12-10 23:52:06 +0000 | [diff] [blame] | 788 | map_bio(get_default_mirror(ms), bio); |
| 789 | generic_make_request(bio); |
| 790 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | } |
| 792 | } |
| 793 | |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 794 | static void do_failures(struct mirror_set *ms, struct bio_list *failures) |
| 795 | { |
| 796 | struct bio *bio; |
| 797 | |
Mikulas Patocka | 0f398a8 | 2009-12-10 23:52:04 +0000 | [diff] [blame] | 798 | if (likely(!failures->head)) |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 799 | return; |
| 800 | |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 801 | /* |
| 802 | * If the log has failed, unattempted writes are being |
Mikulas Patocka | 0f398a8 | 2009-12-10 23:52:04 +0000 | [diff] [blame] | 803 | * put on the holds list. We can't issue those writes |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 804 | * until a log has been marked, so we must store them. |
| 805 | * |
| 806 | * If a 'noflush' suspend is in progress, we can requeue |
| 807 | * the I/O's to the core. This give userspace a chance |
| 808 | * to reconfigure the mirror, at which point the core |
| 809 | * will reissue the writes. If the 'noflush' flag is |
| 810 | * not set, we have no choice but to return errors. |
| 811 | * |
| 812 | * Some writes on the failures list may have been |
| 813 | * submitted before the log failure and represent a |
| 814 | * failure to write to one of the devices. It is ok |
| 815 | * for us to treat them the same and requeue them |
| 816 | * as well. |
| 817 | */ |
Mikulas Patocka | 0f398a8 | 2009-12-10 23:52:04 +0000 | [diff] [blame] | 818 | while ((bio = bio_list_pop(failures))) { |
Mikulas Patocka | 60f355e | 2009-12-10 23:52:05 +0000 | [diff] [blame] | 819 | if (!ms->log_failure) { |
Mikulas Patocka | 0f398a8 | 2009-12-10 23:52:04 +0000 | [diff] [blame] | 820 | ms->in_sync = 0; |
Mikulas Patocka | c58098b | 2009-12-10 23:52:05 +0000 | [diff] [blame] | 821 | dm_rh_mark_nosync(ms->rh, bio); |
Mikulas Patocka | 0f398a8 | 2009-12-10 23:52:04 +0000 | [diff] [blame] | 822 | } |
Mikulas Patocka | 60f355e | 2009-12-10 23:52:05 +0000 | [diff] [blame] | 823 | |
| 824 | /* |
| 825 | * If all the legs are dead, fail the I/O. |
Lidong Zhong | ed63287 | 2015-05-13 14:04:10 +0800 | [diff] [blame] | 826 | * If the device has failed and keep_log is enabled, |
| 827 | * fail the I/O. |
| 828 | * |
| 829 | * If we have been told to handle errors, and keep_log |
| 830 | * isn't enabled, hold the bio and wait for userspace to |
| 831 | * deal with the problem. |
| 832 | * |
Mikulas Patocka | 60f355e | 2009-12-10 23:52:05 +0000 | [diff] [blame] | 833 | * Otherwise pretend that the I/O succeeded. (This would |
| 834 | * be wrong if the failed leg returned after reboot and |
| 835 | * got replicated back to the good legs.) |
| 836 | */ |
Lidong Zhong | ed63287 | 2015-05-13 14:04:10 +0800 | [diff] [blame] | 837 | if (unlikely(!get_valid_mirror(ms) || (keep_log(ms) && ms->log_failure))) |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 838 | bio_io_error(bio); |
Lidong Zhong | ed63287 | 2015-05-13 14:04:10 +0800 | [diff] [blame] | 839 | else if (errors_handled(ms) && !keep_log(ms)) |
Mikulas Patocka | 60f355e | 2009-12-10 23:52:05 +0000 | [diff] [blame] | 840 | hold_bio(ms, bio); |
| 841 | else |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 842 | bio_endio(bio); |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 843 | } |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | static void trigger_event(struct work_struct *work) |
| 847 | { |
| 848 | struct mirror_set *ms = |
| 849 | container_of(work, struct mirror_set, trigger_event); |
| 850 | |
| 851 | dm_table_event(ms->ti->table); |
| 852 | } |
| 853 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | /*----------------------------------------------------------------- |
| 855 | * kmirrord |
| 856 | *---------------------------------------------------------------*/ |
Mikulas Patocka | a2aebe0 | 2008-04-24 22:10:42 +0100 | [diff] [blame] | 857 | static void do_mirror(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | { |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 859 | struct mirror_set *ms = container_of(work, struct mirror_set, |
| 860 | kmirrord_work); |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 861 | struct bio_list reads, writes, failures; |
| 862 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 864 | spin_lock_irqsave(&ms->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | reads = ms->reads; |
| 866 | writes = ms->writes; |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 867 | failures = ms->failures; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | bio_list_init(&ms->reads); |
| 869 | bio_list_init(&ms->writes); |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 870 | bio_list_init(&ms->failures); |
| 871 | spin_unlock_irqrestore(&ms->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 873 | dm_rh_update_states(ms->rh, errors_handled(ms)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | do_recovery(ms); |
| 875 | do_reads(ms, &reads); |
| 876 | do_writes(ms, &writes); |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 877 | do_failures(ms, &failures); |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 878 | } |
| 879 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | /*----------------------------------------------------------------- |
| 881 | * Target functions |
| 882 | *---------------------------------------------------------------*/ |
| 883 | static struct mirror_set *alloc_context(unsigned int nr_mirrors, |
| 884 | uint32_t region_size, |
| 885 | struct dm_target *ti, |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 886 | struct dm_dirty_log *dl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | { |
| 888 | size_t len; |
| 889 | struct mirror_set *ms = NULL; |
| 890 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | len = sizeof(*ms) + (sizeof(ms->mirror[0]) * nr_mirrors); |
| 892 | |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 893 | ms = kzalloc(len, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | if (!ms) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 895 | ti->error = "Cannot allocate mirror context"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | return NULL; |
| 897 | } |
| 898 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | spin_lock_init(&ms->lock); |
Mikulas Patocka | 5339fc2 | 2009-12-10 23:52:06 +0000 | [diff] [blame] | 900 | bio_list_init(&ms->reads); |
| 901 | bio_list_init(&ms->writes); |
| 902 | bio_list_init(&ms->failures); |
| 903 | bio_list_init(&ms->holds); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | |
| 905 | ms->ti = ti; |
| 906 | ms->nr_mirrors = nr_mirrors; |
| 907 | ms->nr_regions = dm_sector_div_up(ti->len, region_size); |
| 908 | ms->in_sync = 0; |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 909 | ms->log_failure = 0; |
Mikulas Patocka | 929be8f | 2009-12-10 23:52:06 +0000 | [diff] [blame] | 910 | ms->leg_failure = 0; |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 911 | atomic_set(&ms->suspend, 0); |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 912 | atomic_set(&ms->default_mirror, DEFAULT_MIRROR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
Mikulas Patocka | bda8efe | 2011-05-29 13:03:09 +0100 | [diff] [blame] | 914 | ms->io_client = dm_io_client_create(); |
Milan Broz | 88be163 | 2007-05-09 02:33:04 -0700 | [diff] [blame] | 915 | if (IS_ERR(ms->io_client)) { |
| 916 | ti->error = "Error creating dm_io client"; |
| 917 | kfree(ms); |
| 918 | return NULL; |
| 919 | } |
| 920 | |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 921 | ms->rh = dm_region_hash_create(ms, dispatch_bios, wakeup_mirrord, |
| 922 | wakeup_all_recovery_waiters, |
| 923 | ms->ti->begin, MAX_RECOVERY, |
| 924 | dl, region_size, ms->nr_regions); |
| 925 | if (IS_ERR(ms->rh)) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 926 | ti->error = "Error creating dirty region hash"; |
Dmitry Monakhov | a72cf73 | 2007-10-19 22:38:39 +0100 | [diff] [blame] | 927 | dm_io_client_destroy(ms->io_client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | kfree(ms); |
| 929 | return NULL; |
| 930 | } |
| 931 | |
| 932 | return ms; |
| 933 | } |
| 934 | |
| 935 | static void free_context(struct mirror_set *ms, struct dm_target *ti, |
| 936 | unsigned int m) |
| 937 | { |
| 938 | while (m--) |
| 939 | dm_put_device(ti, ms->mirror[m].dev); |
| 940 | |
Milan Broz | 88be163 | 2007-05-09 02:33:04 -0700 | [diff] [blame] | 941 | dm_io_client_destroy(ms->io_client); |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 942 | dm_region_hash_destroy(ms->rh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | kfree(ms); |
| 944 | } |
| 945 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | static int get_mirror(struct mirror_set *ms, struct dm_target *ti, |
| 947 | unsigned int mirror, char **argv) |
| 948 | { |
Andrew Morton | 4ee218c | 2006-03-27 01:17:48 -0800 | [diff] [blame] | 949 | unsigned long long offset; |
Mikulas Patocka | 31998ef | 2012-03-28 18:41:26 +0100 | [diff] [blame] | 950 | char dummy; |
Vivek Goyal | e80d1c8 | 2015-07-31 09:20:36 -0400 | [diff] [blame] | 951 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | |
Mikulas Patocka | 31998ef | 2012-03-28 18:41:26 +0100 | [diff] [blame] | 953 | if (sscanf(argv[1], "%llu%c", &offset, &dummy) != 1) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 954 | ti->error = "Invalid offset"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | return -EINVAL; |
| 956 | } |
| 957 | |
Vivek Goyal | e80d1c8 | 2015-07-31 09:20:36 -0400 | [diff] [blame] | 958 | ret = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), |
| 959 | &ms->mirror[mirror].dev); |
| 960 | if (ret) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 961 | ti->error = "Device lookup failure"; |
Vivek Goyal | e80d1c8 | 2015-07-31 09:20:36 -0400 | [diff] [blame] | 962 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | } |
| 964 | |
Jonathan Brassow | aa5617c | 2007-10-19 22:47:58 +0100 | [diff] [blame] | 965 | ms->mirror[mirror].ms = ms; |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 966 | atomic_set(&(ms->mirror[mirror].error_count), 0); |
| 967 | ms->mirror[mirror].error_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | ms->mirror[mirror].offset = offset; |
| 969 | |
| 970 | return 0; |
| 971 | } |
| 972 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | /* |
| 974 | * Create dirty log: log_type #log_params <log_params> |
| 975 | */ |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 976 | static struct dm_dirty_log *create_dirty_log(struct dm_target *ti, |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 977 | unsigned argc, char **argv, |
| 978 | unsigned *args_used) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | { |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 980 | unsigned param_count; |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 981 | struct dm_dirty_log *dl; |
Mikulas Patocka | 31998ef | 2012-03-28 18:41:26 +0100 | [diff] [blame] | 982 | char dummy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | |
| 984 | if (argc < 2) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 985 | ti->error = "Insufficient mirror log arguments"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | return NULL; |
| 987 | } |
| 988 | |
Mikulas Patocka | 31998ef | 2012-03-28 18:41:26 +0100 | [diff] [blame] | 989 | if (sscanf(argv[1], "%u%c", ¶m_count, &dummy) != 1) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 990 | ti->error = "Invalid mirror log argument count"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | return NULL; |
| 992 | } |
| 993 | |
| 994 | *args_used = 2 + param_count; |
| 995 | |
| 996 | if (argc < *args_used) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 997 | ti->error = "Insufficient mirror log arguments"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | return NULL; |
| 999 | } |
| 1000 | |
Mikulas Patocka | c0da374 | 2009-12-10 23:52:02 +0000 | [diff] [blame] | 1001 | dl = dm_dirty_log_create(argv[0], ti, mirror_flush, param_count, |
| 1002 | argv + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | if (!dl) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 1004 | ti->error = "Error creating mirror dirty log"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | return NULL; |
| 1006 | } |
| 1007 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | return dl; |
| 1009 | } |
| 1010 | |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 1011 | static int parse_features(struct mirror_set *ms, unsigned argc, char **argv, |
| 1012 | unsigned *args_used) |
| 1013 | { |
| 1014 | unsigned num_features; |
| 1015 | struct dm_target *ti = ms->ti; |
Mikulas Patocka | 31998ef | 2012-03-28 18:41:26 +0100 | [diff] [blame] | 1016 | char dummy; |
Lidong Zhong | ed63287 | 2015-05-13 14:04:10 +0800 | [diff] [blame] | 1017 | int i; |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 1018 | |
| 1019 | *args_used = 0; |
| 1020 | |
| 1021 | if (!argc) |
| 1022 | return 0; |
| 1023 | |
Mikulas Patocka | 31998ef | 2012-03-28 18:41:26 +0100 | [diff] [blame] | 1024 | if (sscanf(argv[0], "%u%c", &num_features, &dummy) != 1) { |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 1025 | ti->error = "Invalid number of features"; |
| 1026 | return -EINVAL; |
| 1027 | } |
| 1028 | |
| 1029 | argc--; |
| 1030 | argv++; |
| 1031 | (*args_used)++; |
| 1032 | |
| 1033 | if (num_features > argc) { |
| 1034 | ti->error = "Not enough arguments to support feature count"; |
| 1035 | return -EINVAL; |
| 1036 | } |
| 1037 | |
Lidong Zhong | ed63287 | 2015-05-13 14:04:10 +0800 | [diff] [blame] | 1038 | for (i = 0; i < num_features; i++) { |
| 1039 | if (!strcmp("handle_errors", argv[0])) |
| 1040 | ms->features |= DM_RAID1_HANDLE_ERRORS; |
| 1041 | else if (!strcmp("keep_log", argv[0])) |
| 1042 | ms->features |= DM_RAID1_KEEP_LOG; |
| 1043 | else { |
| 1044 | ti->error = "Unrecognised feature requested"; |
| 1045 | return -EINVAL; |
| 1046 | } |
| 1047 | |
| 1048 | argc--; |
| 1049 | argv++; |
| 1050 | (*args_used)++; |
| 1051 | } |
| 1052 | if (!errors_handled(ms) && keep_log(ms)) { |
| 1053 | ti->error = "keep_log feature requires the handle_errors feature"; |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 1054 | return -EINVAL; |
| 1055 | } |
| 1056 | |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 1057 | return 0; |
| 1058 | } |
| 1059 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | /* |
| 1061 | * Construct a mirror mapping: |
| 1062 | * |
| 1063 | * log_type #log_params <log_params> |
| 1064 | * #mirrors [mirror_path offset]{2,} |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 1065 | * [#features <features>] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | * |
| 1067 | * log_type is "core" or "disk" |
| 1068 | * #log_params is between 1 and 3 |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 1069 | * |
Lidong Zhong | ed63287 | 2015-05-13 14:04:10 +0800 | [diff] [blame] | 1070 | * If present, supported features are "handle_errors" and "keep_log". |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv) |
| 1073 | { |
| 1074 | int r; |
| 1075 | unsigned int nr_mirrors, m, args_used; |
| 1076 | struct mirror_set *ms; |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 1077 | struct dm_dirty_log *dl; |
Mikulas Patocka | 31998ef | 2012-03-28 18:41:26 +0100 | [diff] [blame] | 1078 | char dummy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | |
| 1080 | dl = create_dirty_log(ti, argc, argv, &args_used); |
| 1081 | if (!dl) |
| 1082 | return -EINVAL; |
| 1083 | |
| 1084 | argv += args_used; |
| 1085 | argc -= args_used; |
| 1086 | |
Mikulas Patocka | 31998ef | 2012-03-28 18:41:26 +0100 | [diff] [blame] | 1087 | if (!argc || sscanf(argv[0], "%u%c", &nr_mirrors, &dummy) != 1 || |
Heinz Mauelshagen | eb69aca | 2008-04-24 21:43:19 +0100 | [diff] [blame] | 1088 | nr_mirrors < 2 || nr_mirrors > DM_KCOPYD_MAX_REGIONS + 1) { |
Alasdair G Kergon | 72d9486 | 2006-06-26 00:27:35 -0700 | [diff] [blame] | 1089 | ti->error = "Invalid number of mirrors"; |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 1090 | dm_dirty_log_destroy(dl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | return -EINVAL; |
| 1092 | } |
| 1093 | |
| 1094 | argv++, argc--; |
| 1095 | |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 1096 | if (argc < nr_mirrors * 2) { |
| 1097 | ti->error = "Too few mirror arguments"; |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 1098 | dm_dirty_log_destroy(dl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | return -EINVAL; |
| 1100 | } |
| 1101 | |
| 1102 | ms = alloc_context(nr_mirrors, dl->type->get_region_size(dl), ti, dl); |
| 1103 | if (!ms) { |
Heinz Mauelshagen | 416cd17 | 2008-04-24 21:43:35 +0100 | [diff] [blame] | 1104 | dm_dirty_log_destroy(dl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | return -ENOMEM; |
| 1106 | } |
| 1107 | |
| 1108 | /* Get the mirror parameter sets */ |
| 1109 | for (m = 0; m < nr_mirrors; m++) { |
| 1110 | r = get_mirror(ms, ti, m, argv); |
| 1111 | if (r) { |
| 1112 | free_context(ms, ti, m); |
| 1113 | return r; |
| 1114 | } |
| 1115 | argv += 2; |
| 1116 | argc -= 2; |
| 1117 | } |
| 1118 | |
| 1119 | ti->private = ms; |
Mike Snitzer | 542f903 | 2012-07-27 15:08:00 +0100 | [diff] [blame] | 1120 | |
| 1121 | r = dm_set_target_max_io_len(ti, dm_rh_get_region_size(ms->rh)); |
| 1122 | if (r) |
| 1123 | goto err_free_context; |
| 1124 | |
Alasdair G Kergon | 55a62ee | 2013-03-01 22:45:47 +0000 | [diff] [blame] | 1125 | ti->num_flush_bios = 1; |
| 1126 | ti->num_discard_bios = 1; |
Mike Snitzer | 30187e1 | 2016-01-31 13:28:26 -0500 | [diff] [blame] | 1127 | ti->per_io_data_size = sizeof(struct dm_raid1_bio_record); |
Alasdair G Kergon | 0ac5548 | 2012-07-27 15:08:08 +0100 | [diff] [blame] | 1128 | ti->discard_zeroes_data_unsupported = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | |
Tejun Heo | 670368a | 2013-07-30 08:40:21 -0400 | [diff] [blame] | 1130 | ms->kmirrord_wq = alloc_workqueue("kmirrord", WQ_MEM_RECLAIM, 0); |
Holger Smolinski | 6ad36fe | 2007-05-09 02:32:50 -0700 | [diff] [blame] | 1131 | if (!ms->kmirrord_wq) { |
| 1132 | DMERR("couldn't start kmirrord"); |
Dmitry Monakhov | a72cf73 | 2007-10-19 22:38:39 +0100 | [diff] [blame] | 1133 | r = -ENOMEM; |
| 1134 | goto err_free_context; |
Holger Smolinski | 6ad36fe | 2007-05-09 02:32:50 -0700 | [diff] [blame] | 1135 | } |
| 1136 | INIT_WORK(&ms->kmirrord_work, do_mirror); |
Mikulas Patocka | a2aebe0 | 2008-04-24 22:10:42 +0100 | [diff] [blame] | 1137 | init_timer(&ms->timer); |
| 1138 | ms->timer_pending = 0; |
Jonathan Brassow | 72f4b31 | 2008-02-08 02:11:29 +0000 | [diff] [blame] | 1139 | INIT_WORK(&ms->trigger_event, trigger_event); |
Holger Smolinski | 6ad36fe | 2007-05-09 02:32:50 -0700 | [diff] [blame] | 1140 | |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 1141 | r = parse_features(ms, argc, argv, &args_used); |
Dmitry Monakhov | a72cf73 | 2007-10-19 22:38:39 +0100 | [diff] [blame] | 1142 | if (r) |
| 1143 | goto err_destroy_wq; |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 1144 | |
| 1145 | argv += args_used; |
| 1146 | argc -= args_used; |
| 1147 | |
Jonathan Brassow | f44db67 | 2007-07-12 17:29:04 +0100 | [diff] [blame] | 1148 | /* |
| 1149 | * Any read-balancing addition depends on the |
| 1150 | * DM_RAID1_HANDLE_ERRORS flag being present. |
| 1151 | * This is because the decision to balance depends |
| 1152 | * on the sync state of a region. If the above |
| 1153 | * flag is not present, we ignore errors; and |
| 1154 | * the sync state may be inaccurate. |
| 1155 | */ |
| 1156 | |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 1157 | if (argc) { |
| 1158 | ti->error = "Too many mirror arguments"; |
Dmitry Monakhov | a72cf73 | 2007-10-19 22:38:39 +0100 | [diff] [blame] | 1159 | r = -EINVAL; |
| 1160 | goto err_destroy_wq; |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 1161 | } |
| 1162 | |
Mikulas Patocka | df5d2e9 | 2013-03-01 22:45:49 +0000 | [diff] [blame] | 1163 | ms->kcopyd_client = dm_kcopyd_client_create(&dm_kcopyd_throttle); |
Mikulas Patocka | fa34ce7 | 2011-05-29 13:03:13 +0100 | [diff] [blame] | 1164 | if (IS_ERR(ms->kcopyd_client)) { |
| 1165 | r = PTR_ERR(ms->kcopyd_client); |
Dmitry Monakhov | a72cf73 | 2007-10-19 22:38:39 +0100 | [diff] [blame] | 1166 | goto err_destroy_wq; |
Mikulas Patocka | fa34ce7 | 2011-05-29 13:03:13 +0100 | [diff] [blame] | 1167 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 1169 | wakeup_mirrord(ms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | return 0; |
Dmitry Monakhov | a72cf73 | 2007-10-19 22:38:39 +0100 | [diff] [blame] | 1171 | |
| 1172 | err_destroy_wq: |
| 1173 | destroy_workqueue(ms->kmirrord_wq); |
| 1174 | err_free_context: |
| 1175 | free_context(ms, ti, ms->nr_mirrors); |
| 1176 | return r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | static void mirror_dtr(struct dm_target *ti) |
| 1180 | { |
| 1181 | struct mirror_set *ms = (struct mirror_set *) ti->private; |
| 1182 | |
Mikulas Patocka | a2aebe0 | 2008-04-24 22:10:42 +0100 | [diff] [blame] | 1183 | del_timer_sync(&ms->timer); |
Holger Smolinski | 6ad36fe | 2007-05-09 02:32:50 -0700 | [diff] [blame] | 1184 | flush_workqueue(ms->kmirrord_wq); |
Tejun Heo | 4382973 | 2012-08-20 14:51:24 -0700 | [diff] [blame] | 1185 | flush_work(&ms->trigger_event); |
Heinz Mauelshagen | eb69aca | 2008-04-24 21:43:19 +0100 | [diff] [blame] | 1186 | dm_kcopyd_client_destroy(ms->kcopyd_client); |
Holger Smolinski | 6ad36fe | 2007-05-09 02:32:50 -0700 | [diff] [blame] | 1187 | destroy_workqueue(ms->kmirrord_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | free_context(ms, ti, ms->nr_mirrors); |
| 1189 | } |
| 1190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | /* |
| 1192 | * Mirror mapping function |
| 1193 | */ |
Mikulas Patocka | 7de3ee5 | 2012-12-21 20:23:41 +0000 | [diff] [blame] | 1194 | static int mirror_map(struct dm_target *ti, struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | { |
| 1196 | int r, rw = bio_rw(bio); |
| 1197 | struct mirror *m; |
| 1198 | struct mirror_set *ms = ti->private; |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 1199 | struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); |
Mikulas Patocka | 0045d61 | 2012-12-21 20:23:40 +0000 | [diff] [blame] | 1200 | struct dm_raid1_bio_record *bio_record = |
| 1201 | dm_per_bio_data(bio, sizeof(struct dm_raid1_bio_record)); |
| 1202 | |
| 1203 | bio_record->details.bi_bdev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | |
| 1205 | if (rw == WRITE) { |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1206 | /* Save region for mirror_end_io() handler */ |
Mikulas Patocka | 0045d61 | 2012-12-21 20:23:40 +0000 | [diff] [blame] | 1207 | bio_record->write_region = dm_rh_bio_to_region(ms->rh, bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | queue_bio(ms, bio, rw); |
Kiyoshi Ueda | d2a7ad2 | 2006-12-08 02:41:06 -0800 | [diff] [blame] | 1209 | return DM_MAPIO_SUBMITTED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | } |
| 1211 | |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 1212 | r = log->type->in_sync(log, dm_rh_bio_to_region(ms->rh, bio), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | if (r < 0 && r != -EWOULDBLOCK) |
| 1214 | return r; |
| 1215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | /* |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1217 | * If region is not in-sync queue the bio. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | */ |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1219 | if (!r || (r == -EWOULDBLOCK)) { |
| 1220 | if (rw == READA) |
| 1221 | return -EWOULDBLOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | queue_bio(ms, bio, rw); |
Kiyoshi Ueda | d2a7ad2 | 2006-12-08 02:41:06 -0800 | [diff] [blame] | 1224 | return DM_MAPIO_SUBMITTED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | } |
| 1226 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1227 | /* |
| 1228 | * The region is in-sync and we can perform reads directly. |
| 1229 | * Store enough information so we can retry if it fails. |
| 1230 | */ |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 1231 | m = choose_mirror(ms, bio->bi_iter.bi_sector); |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1232 | if (unlikely(!m)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | return -EIO; |
| 1234 | |
Mikulas Patocka | 89c7cd8 | 2012-12-21 20:23:39 +0000 | [diff] [blame] | 1235 | dm_bio_record(&bio_record->details, bio); |
Mikulas Patocka | 89c7cd8 | 2012-12-21 20:23:39 +0000 | [diff] [blame] | 1236 | bio_record->m = m; |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1237 | |
| 1238 | map_bio(m, bio); |
| 1239 | |
Kiyoshi Ueda | d2a7ad2 | 2006-12-08 02:41:06 -0800 | [diff] [blame] | 1240 | return DM_MAPIO_REMAPPED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | } |
| 1242 | |
Mikulas Patocka | 7de3ee5 | 2012-12-21 20:23:41 +0000 | [diff] [blame] | 1243 | static int mirror_end_io(struct dm_target *ti, struct bio *bio, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | { |
| 1245 | int rw = bio_rw(bio); |
| 1246 | struct mirror_set *ms = (struct mirror_set *) ti->private; |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1247 | struct mirror *m = NULL; |
| 1248 | struct dm_bio_details *bd = NULL; |
Mikulas Patocka | 0045d61 | 2012-12-21 20:23:40 +0000 | [diff] [blame] | 1249 | struct dm_raid1_bio_record *bio_record = |
| 1250 | dm_per_bio_data(bio, sizeof(struct dm_raid1_bio_record)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | |
| 1252 | /* |
| 1253 | * We need to dec pending if this was a write. |
| 1254 | */ |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1255 | if (rw == WRITE) { |
Mike Christie | 28a8f0d | 2016-06-05 14:32:25 -0500 | [diff] [blame^] | 1256 | if (!(bio->bi_rw & REQ_PREFLUSH) && |
| 1257 | bio_op(bio) != REQ_OP_DISCARD) |
Mikulas Patocka | 0045d61 | 2012-12-21 20:23:40 +0000 | [diff] [blame] | 1258 | dm_rh_dec(ms->rh, bio_record->write_region); |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1259 | return error; |
| 1260 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1262 | if (error == -EOPNOTSUPP) |
| 1263 | goto out; |
| 1264 | |
Christoph Hellwig | 7b6d91d | 2010-08-07 18:20:39 +0200 | [diff] [blame] | 1265 | if ((error == -EWOULDBLOCK) && (bio->bi_rw & REQ_RAHEAD)) |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1266 | goto out; |
| 1267 | |
| 1268 | if (unlikely(error)) { |
Mikulas Patocka | 0045d61 | 2012-12-21 20:23:40 +0000 | [diff] [blame] | 1269 | if (!bio_record->details.bi_bdev) { |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1270 | /* |
| 1271 | * There wasn't enough memory to record necessary |
| 1272 | * information for a retry or there was no other |
| 1273 | * mirror in-sync. |
| 1274 | */ |
Adrian Bunk | e03f1a8 | 2008-02-19 19:44:19 +0000 | [diff] [blame] | 1275 | DMERR_LIMIT("Mirror read failed."); |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1276 | return -EIO; |
| 1277 | } |
Adrian Bunk | e03f1a8 | 2008-02-19 19:44:19 +0000 | [diff] [blame] | 1278 | |
Mikulas Patocka | 89c7cd8 | 2012-12-21 20:23:39 +0000 | [diff] [blame] | 1279 | m = bio_record->m; |
Adrian Bunk | e03f1a8 | 2008-02-19 19:44:19 +0000 | [diff] [blame] | 1280 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1281 | DMERR("Mirror read failed from %s. Trying alternative device.", |
| 1282 | m->dev->name); |
| 1283 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1284 | fail_mirror(m, DM_RAID1_READ_ERROR); |
| 1285 | |
| 1286 | /* |
| 1287 | * A failed read is requeued for another attempt using an intact |
| 1288 | * mirror. |
| 1289 | */ |
| 1290 | if (default_ok(m) || mirror_available(ms, bio)) { |
Mikulas Patocka | 89c7cd8 | 2012-12-21 20:23:39 +0000 | [diff] [blame] | 1291 | bd = &bio_record->details; |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1292 | |
| 1293 | dm_bio_restore(bd, bio); |
Mikulas Patocka | 0045d61 | 2012-12-21 20:23:40 +0000 | [diff] [blame] | 1294 | bio_record->details.bi_bdev = NULL; |
Mikulas Patocka | f3a44fe | 2014-02-18 09:57:22 -0500 | [diff] [blame] | 1295 | |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1296 | queue_bio(ms, bio, rw); |
Mikulas Patocka | 19cbbc6 | 2012-12-21 20:23:32 +0000 | [diff] [blame] | 1297 | return DM_ENDIO_INCOMPLETE; |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1298 | } |
| 1299 | DMERR("All replicated volumes dead, failing I/O"); |
| 1300 | } |
| 1301 | |
| 1302 | out: |
Mikulas Patocka | 0045d61 | 2012-12-21 20:23:40 +0000 | [diff] [blame] | 1303 | bio_record->details.bi_bdev = NULL; |
Jonathan Brassow | 06386bb | 2008-02-08 02:11:37 +0000 | [diff] [blame] | 1304 | |
| 1305 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | } |
| 1307 | |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1308 | static void mirror_presuspend(struct dm_target *ti) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | { |
| 1310 | struct mirror_set *ms = (struct mirror_set *) ti->private; |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 1311 | struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | |
Mikulas Patocka | 0478850 | 2009-12-10 23:52:03 +0000 | [diff] [blame] | 1313 | struct bio_list holds; |
| 1314 | struct bio *bio; |
| 1315 | |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1316 | atomic_set(&ms->suspend, 1); |
| 1317 | |
| 1318 | /* |
Takahiro Yasui | f070304 | 2010-03-06 02:32:35 +0000 | [diff] [blame] | 1319 | * Process bios in the hold list to start recovery waiting |
| 1320 | * for bios in the hold list. After the process, no bio has |
| 1321 | * a chance to be added in the hold list because ms->suspend |
| 1322 | * is set. |
| 1323 | */ |
| 1324 | spin_lock_irq(&ms->lock); |
| 1325 | holds = ms->holds; |
| 1326 | bio_list_init(&ms->holds); |
| 1327 | spin_unlock_irq(&ms->lock); |
| 1328 | |
| 1329 | while ((bio = bio_list_pop(&holds))) |
| 1330 | hold_bio(ms, bio); |
| 1331 | |
| 1332 | /* |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1333 | * We must finish up all the work that we've |
| 1334 | * generated (i.e. recovery work). |
| 1335 | */ |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 1336 | dm_rh_stop_recovery(ms->rh); |
Jonathan E Brassow | 3318404 | 2006-11-08 17:44:44 -0800 | [diff] [blame] | 1337 | |
Jonathan E Brassow | 3318404 | 2006-11-08 17:44:44 -0800 | [diff] [blame] | 1338 | wait_event(_kmirrord_recovery_stopped, |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 1339 | !dm_rh_recovery_in_flight(ms->rh)); |
Jonathan E Brassow | 3318404 | 2006-11-08 17:44:44 -0800 | [diff] [blame] | 1340 | |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1341 | if (log->type->presuspend && log->type->presuspend(log)) |
| 1342 | /* FIXME: need better error handling */ |
| 1343 | DMWARN("log presuspend failed"); |
| 1344 | |
| 1345 | /* |
| 1346 | * Now that recovery is complete/stopped and the |
| 1347 | * delayed bios are queued, we need to wait for |
| 1348 | * the worker thread to complete. This way, |
| 1349 | * we know that all of our I/O has been pushed. |
| 1350 | */ |
| 1351 | flush_workqueue(ms->kmirrord_wq); |
| 1352 | } |
| 1353 | |
| 1354 | static void mirror_postsuspend(struct dm_target *ti) |
| 1355 | { |
| 1356 | struct mirror_set *ms = ti->private; |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 1357 | struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1358 | |
Jonathan Brassow | 6b3df0d | 2007-10-19 22:47:57 +0100 | [diff] [blame] | 1359 | if (log->type->postsuspend && log->type->postsuspend(log)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | /* FIXME: need better error handling */ |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1361 | DMWARN("log postsuspend failed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | static void mirror_resume(struct dm_target *ti) |
| 1365 | { |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1366 | struct mirror_set *ms = ti->private; |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 1367 | struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1368 | |
| 1369 | atomic_set(&ms->suspend, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | if (log->type->resume && log->type->resume(log)) |
| 1371 | /* FIXME: need better error handling */ |
| 1372 | DMWARN("log resume failed"); |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 1373 | dm_rh_start_recovery(ms->rh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | } |
| 1375 | |
Jonathan Brassow | af195ac | 2008-02-08 02:11:39 +0000 | [diff] [blame] | 1376 | /* |
| 1377 | * device_status_char |
| 1378 | * @m: mirror device/leg we want the status of |
| 1379 | * |
| 1380 | * We return one character representing the most severe error |
| 1381 | * we have encountered. |
| 1382 | * A => Alive - No failures |
| 1383 | * D => Dead - A write failure occurred leaving mirror out-of-sync |
| 1384 | * S => Sync - A sychronization failure occurred, mirror out-of-sync |
| 1385 | * R => Read - A read failure occurred, mirror data unaffected |
| 1386 | * |
| 1387 | * Returns: <char> |
| 1388 | */ |
| 1389 | static char device_status_char(struct mirror *m) |
| 1390 | { |
| 1391 | if (!atomic_read(&(m->error_count))) |
| 1392 | return 'A'; |
| 1393 | |
Mikulas Patocka | 64b30c4 | 2009-12-10 23:52:02 +0000 | [diff] [blame] | 1394 | return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' : |
| 1395 | (test_bit(DM_RAID1_WRITE_ERROR, &(m->error_type))) ? 'D' : |
Jonathan Brassow | af195ac | 2008-02-08 02:11:39 +0000 | [diff] [blame] | 1396 | (test_bit(DM_RAID1_SYNC_ERROR, &(m->error_type))) ? 'S' : |
| 1397 | (test_bit(DM_RAID1_READ_ERROR, &(m->error_type))) ? 'R' : 'U'; |
| 1398 | } |
| 1399 | |
| 1400 | |
Mikulas Patocka | fd7c092 | 2013-03-01 22:45:44 +0000 | [diff] [blame] | 1401 | static void mirror_status(struct dm_target *ti, status_type_t type, |
| 1402 | unsigned status_flags, char *result, unsigned maxlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | { |
Jonathan E Brassow | 315dcc2 | 2007-05-09 02:32:58 -0700 | [diff] [blame] | 1404 | unsigned int m, sz = 0; |
Lidong Zhong | ed63287 | 2015-05-13 14:04:10 +0800 | [diff] [blame] | 1405 | int num_feature_args = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | struct mirror_set *ms = (struct mirror_set *) ti->private; |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 1407 | struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh); |
Jonathan Brassow | af195ac | 2008-02-08 02:11:39 +0000 | [diff] [blame] | 1408 | char buffer[ms->nr_mirrors + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | switch (type) { |
| 1411 | case STATUSTYPE_INFO: |
| 1412 | DMEMIT("%d ", ms->nr_mirrors); |
Jonathan Brassow | af195ac | 2008-02-08 02:11:39 +0000 | [diff] [blame] | 1413 | for (m = 0; m < ms->nr_mirrors; m++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | DMEMIT("%s ", ms->mirror[m].dev->name); |
Jonathan Brassow | af195ac | 2008-02-08 02:11:39 +0000 | [diff] [blame] | 1415 | buffer[m] = device_status_char(&(ms->mirror[m])); |
| 1416 | } |
| 1417 | buffer[m] = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | |
Jonathan Brassow | af195ac | 2008-02-08 02:11:39 +0000 | [diff] [blame] | 1419 | DMEMIT("%llu/%llu 1 %s ", |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 1420 | (unsigned long long)log->type->get_sync_count(log), |
Jonathan Brassow | af195ac | 2008-02-08 02:11:39 +0000 | [diff] [blame] | 1421 | (unsigned long long)ms->nr_regions, buffer); |
Jonathan E Brassow | 315dcc2 | 2007-05-09 02:32:58 -0700 | [diff] [blame] | 1422 | |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 1423 | sz += log->type->status(log, type, result+sz, maxlen-sz); |
Jonathan E Brassow | 315dcc2 | 2007-05-09 02:32:58 -0700 | [diff] [blame] | 1424 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | break; |
| 1426 | |
| 1427 | case STATUSTYPE_TABLE: |
Heinz Mauelshagen | 1f965b1 | 2008-10-21 17:45:06 +0100 | [diff] [blame] | 1428 | sz = log->type->status(log, type, result, maxlen); |
Jonathan E Brassow | 315dcc2 | 2007-05-09 02:32:58 -0700 | [diff] [blame] | 1429 | |
Jonathan Brassow | e52b8f6 | 2006-10-03 01:15:32 -0700 | [diff] [blame] | 1430 | DMEMIT("%d", ms->nr_mirrors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | for (m = 0; m < ms->nr_mirrors; m++) |
Jonathan Brassow | e52b8f6 | 2006-10-03 01:15:32 -0700 | [diff] [blame] | 1432 | DMEMIT(" %s %llu", ms->mirror[m].dev->name, |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1433 | (unsigned long long)ms->mirror[m].offset); |
Jonathan E Brassow | a8e6afa | 2007-05-09 02:32:59 -0700 | [diff] [blame] | 1434 | |
Lidong Zhong | ed63287 | 2015-05-13 14:04:10 +0800 | [diff] [blame] | 1435 | num_feature_args += !!errors_handled(ms); |
| 1436 | num_feature_args += !!keep_log(ms); |
| 1437 | if (num_feature_args) { |
| 1438 | DMEMIT(" %d", num_feature_args); |
| 1439 | if (errors_handled(ms)) |
| 1440 | DMEMIT(" handle_errors"); |
| 1441 | if (keep_log(ms)) |
| 1442 | DMEMIT(" keep_log"); |
| 1443 | } |
| 1444 | |
| 1445 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | } |
| 1448 | |
Mike Snitzer | af4874e | 2009-06-22 10:12:33 +0100 | [diff] [blame] | 1449 | static int mirror_iterate_devices(struct dm_target *ti, |
| 1450 | iterate_devices_callout_fn fn, void *data) |
| 1451 | { |
| 1452 | struct mirror_set *ms = ti->private; |
| 1453 | int ret = 0; |
| 1454 | unsigned i; |
| 1455 | |
| 1456 | for (i = 0; !ret && i < ms->nr_mirrors; i++) |
| 1457 | ret = fn(ti, ms->mirror[i].dev, |
Mike Snitzer | 5dea271 | 2009-07-23 20:30:42 +0100 | [diff] [blame] | 1458 | ms->mirror[i].offset, ti->len, data); |
Mike Snitzer | af4874e | 2009-06-22 10:12:33 +0100 | [diff] [blame] | 1459 | |
| 1460 | return ret; |
| 1461 | } |
| 1462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | static struct target_type mirror_target = { |
| 1464 | .name = "mirror", |
Lidong Zhong | ed63287 | 2015-05-13 14:04:10 +0800 | [diff] [blame] | 1465 | .version = {1, 14, 0}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | .module = THIS_MODULE, |
| 1467 | .ctr = mirror_ctr, |
| 1468 | .dtr = mirror_dtr, |
| 1469 | .map = mirror_map, |
| 1470 | .end_io = mirror_end_io, |
Jonathan Brassow | b80aa7a | 2008-02-08 02:11:35 +0000 | [diff] [blame] | 1471 | .presuspend = mirror_presuspend, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | .postsuspend = mirror_postsuspend, |
| 1473 | .resume = mirror_resume, |
| 1474 | .status = mirror_status, |
Mike Snitzer | af4874e | 2009-06-22 10:12:33 +0100 | [diff] [blame] | 1475 | .iterate_devices = mirror_iterate_devices, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | }; |
| 1477 | |
| 1478 | static int __init dm_mirror_init(void) |
| 1479 | { |
| 1480 | int r; |
| 1481 | |
Mikulas Patocka | 95f8fac | 2009-04-02 19:55:24 +0100 | [diff] [blame] | 1482 | r = dm_register_target(&mirror_target); |
| 1483 | if (r < 0) { |
| 1484 | DMERR("Failed to register mirror target"); |
| 1485 | goto bad_target; |
| 1486 | } |
| 1487 | |
| 1488 | return 0; |
| 1489 | |
| 1490 | bad_target: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | return r; |
| 1492 | } |
| 1493 | |
| 1494 | static void __exit dm_mirror_exit(void) |
| 1495 | { |
Mikulas Patocka | 10d3bd0 | 2009-01-06 03:04:58 +0000 | [diff] [blame] | 1496 | dm_unregister_target(&mirror_target); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | /* Module hooks */ |
| 1500 | module_init(dm_mirror_init); |
| 1501 | module_exit(dm_mirror_exit); |
| 1502 | |
| 1503 | MODULE_DESCRIPTION(DM_NAME " mirror target"); |
| 1504 | MODULE_AUTHOR("Joe Thornber"); |
| 1505 | MODULE_LICENSE("GPL"); |