Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * multipath.c : Multiple Devices driver for Linux |
| 3 | * |
| 4 | * Copyright (C) 1999, 2000, 2001 Ingo Molnar, Red Hat |
| 5 | * |
| 6 | * Copyright (C) 1996, 1997, 1998 Ingo Molnar, Miguel de Icaza, Gadi Oxman |
| 7 | * |
| 8 | * MULTIPATH management functions. |
| 9 | * |
| 10 | * derived from raid1.c. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2, or (at your option) |
| 15 | * any later version. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * (for example /usr/src/linux/COPYING); if not, write to the Free |
| 19 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 22 | #include <linux/blkdev.h> |
Paul Gortmaker | 056075c | 2011-07-03 13:58:33 -0400 | [diff] [blame] | 23 | #include <linux/module.h> |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 24 | #include <linux/raid/md_u.h> |
NeilBrown | bff6197 | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 25 | #include <linux/seq_file.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
NeilBrown | 43b2e5d | 2009-03-31 14:33:13 +1100 | [diff] [blame] | 27 | #include "md.h" |
Christoph Hellwig | ef740c3 | 2009-03-31 14:27:03 +1100 | [diff] [blame] | 28 | #include "multipath.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | #define MAX_WORK_PER_DISK 128 |
| 31 | |
| 32 | #define NR_RESERVED_BUFS 32 |
| 33 | |
NeilBrown | 69724e2 | 2011-10-11 16:48:57 +1100 | [diff] [blame] | 34 | static int multipath_map (struct mpconf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | { |
| 36 | int i, disks = conf->raid_disks; |
| 37 | |
| 38 | /* |
NeilBrown | f72ffdd | 2014-09-30 14:23:59 +1000 | [diff] [blame] | 39 | * Later we do read balancing on the read side |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | * now we use the first available disk. |
| 41 | */ |
| 42 | |
| 43 | rcu_read_lock(); |
| 44 | for (i = 0; i < disks; i++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 45 | struct md_rdev *rdev = rcu_dereference(conf->multipaths[i].rdev); |
NeilBrown | f5b67ae | 2016-06-02 16:19:53 +1000 | [diff] [blame] | 46 | if (rdev && test_bit(In_sync, &rdev->flags) && |
| 47 | !test_bit(Faulty, &rdev->flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | atomic_inc(&rdev->nr_pending); |
| 49 | rcu_read_unlock(); |
| 50 | return i; |
| 51 | } |
| 52 | } |
| 53 | rcu_read_unlock(); |
| 54 | |
| 55 | printk(KERN_ERR "multipath_map(): no more operational IO paths?\n"); |
| 56 | return (-1); |
| 57 | } |
| 58 | |
| 59 | static void multipath_reschedule_retry (struct multipath_bh *mp_bh) |
| 60 | { |
| 61 | unsigned long flags; |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 62 | struct mddev *mddev = mp_bh->mddev; |
NeilBrown | 69724e2 | 2011-10-11 16:48:57 +1100 | [diff] [blame] | 63 | struct mpconf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
| 65 | spin_lock_irqsave(&conf->device_lock, flags); |
| 66 | list_add(&mp_bh->retry_list, &conf->retry_list); |
| 67 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 68 | md_wakeup_thread(mddev->thread); |
| 69 | } |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | /* |
| 72 | * multipath_end_bh_io() is called when we have finished servicing a multipathed |
| 73 | * operation and are ready to return a success/failure code to the buffer |
| 74 | * cache layer. |
| 75 | */ |
| 76 | static void multipath_end_bh_io (struct multipath_bh *mp_bh, int err) |
| 77 | { |
| 78 | struct bio *bio = mp_bh->master_bio; |
NeilBrown | 69724e2 | 2011-10-11 16:48:57 +1100 | [diff] [blame] | 79 | struct mpconf *conf = mp_bh->mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 81 | bio->bi_error = err; |
| 82 | bio_endio(bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | mempool_free(mp_bh, conf->pool); |
| 84 | } |
| 85 | |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 86 | static void multipath_end_request(struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
H Hartley Sweeten | 7b92813 | 2010-03-08 16:02:40 +1100 | [diff] [blame] | 88 | struct multipath_bh *mp_bh = bio->bi_private; |
NeilBrown | 69724e2 | 2011-10-11 16:48:57 +1100 | [diff] [blame] | 89 | struct mpconf *conf = mp_bh->mddev->private; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 90 | struct md_rdev *rdev = conf->multipaths[mp_bh->path].rdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 92 | if (!bio->bi_error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | multipath_end_bh_io(mp_bh, 0); |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 94 | else if (!(bio->bi_opf & REQ_RAHEAD)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | /* |
| 96 | * oops, IO error: |
| 97 | */ |
| 98 | char b[BDEVNAME_SIZE]; |
| 99 | md_error (mp_bh->mddev, rdev); |
NeilBrown | f72ffdd | 2014-09-30 14:23:59 +1000 | [diff] [blame] | 100 | printk(KERN_ERR "multipath: %s: rescheduling sector %llu\n", |
| 101 | bdevname(rdev->bdev,b), |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 102 | (unsigned long long)bio->bi_iter.bi_sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | multipath_reschedule_retry(mp_bh); |
| 104 | } else |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 105 | multipath_end_bh_io(mp_bh, bio->bi_error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | rdev_dec_pending(rdev, conf->mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Linus Torvalds | b4fdcb0 | 2011-11-04 17:06:58 -0700 | [diff] [blame] | 109 | static void multipath_make_request(struct mddev *mddev, struct bio * bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
NeilBrown | 69724e2 | 2011-10-11 16:48:57 +1100 | [diff] [blame] | 111 | struct mpconf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | struct multipath_bh * mp_bh; |
| 113 | struct multipath_info *multipath; |
| 114 | |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 115 | if (unlikely(bio->bi_opf & REQ_PREFLUSH)) { |
Tejun Heo | e9c7469 | 2010-09-03 11:56:18 +0200 | [diff] [blame] | 116 | md_flush_request(mddev, bio); |
Christoph Hellwig | 5a7bbad | 2011-09-12 12:12:01 +0200 | [diff] [blame] | 117 | return; |
NeilBrown | e5dcdd8 | 2005-09-09 16:23:41 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | mp_bh = mempool_alloc(conf->pool, GFP_NOIO); |
| 121 | |
| 122 | mp_bh->master_bio = bio; |
| 123 | mp_bh->mddev = mddev; |
| 124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | mp_bh->path = multipath_map(conf); |
| 126 | if (mp_bh->path < 0) { |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 127 | bio_io_error(bio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | mempool_free(mp_bh, conf->pool); |
Christoph Hellwig | 5a7bbad | 2011-09-12 12:12:01 +0200 | [diff] [blame] | 129 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | } |
| 131 | multipath = conf->multipaths + mp_bh->path; |
| 132 | |
Ming Lei | fafcde3 | 2016-03-12 09:29:40 +0800 | [diff] [blame] | 133 | bio_init(&mp_bh->bio); |
| 134 | __bio_clone_fast(&mp_bh->bio, bio); |
| 135 | |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 136 | mp_bh->bio.bi_iter.bi_sector += multipath->rdev->data_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | mp_bh->bio.bi_bdev = multipath->rdev->bdev; |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 138 | mp_bh->bio.bi_opf |= REQ_FAILFAST_TRANSPORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | mp_bh->bio.bi_end_io = multipath_end_request; |
| 140 | mp_bh->bio.bi_private = mp_bh; |
| 141 | generic_make_request(&mp_bh->bio); |
Christoph Hellwig | 5a7bbad | 2011-09-12 12:12:01 +0200 | [diff] [blame] | 142 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } |
| 144 | |
NeilBrown | 40cf212 | 2016-06-02 16:19:52 +1000 | [diff] [blame] | 145 | static void multipath_status(struct seq_file *seq, struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | { |
NeilBrown | 69724e2 | 2011-10-11 16:48:57 +1100 | [diff] [blame] | 147 | struct mpconf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | int i; |
NeilBrown | f72ffdd | 2014-09-30 14:23:59 +1000 | [diff] [blame] | 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | seq_printf (seq, " [%d/%d] [", conf->raid_disks, |
NeilBrown | 92f861a | 2011-05-11 14:38:02 +1000 | [diff] [blame] | 151 | conf->raid_disks - mddev->degraded); |
NeilBrown | 40cf212 | 2016-06-02 16:19:52 +1000 | [diff] [blame] | 152 | rcu_read_lock(); |
| 153 | for (i = 0; i < conf->raid_disks; i++) { |
| 154 | struct md_rdev *rdev = rcu_dereference(conf->multipaths[i].rdev); |
| 155 | seq_printf (seq, "%s", rdev && test_bit(In_sync, &rdev->flags) ? "U" : "_"); |
| 156 | } |
| 157 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | seq_printf (seq, "]"); |
| 159 | } |
| 160 | |
NeilBrown | 5c675f8 | 2014-12-15 12:56:56 +1100 | [diff] [blame] | 161 | static int multipath_congested(struct mddev *mddev, int bits) |
NeilBrown | 0d12922 | 2006-10-03 01:15:54 -0700 | [diff] [blame] | 162 | { |
NeilBrown | 69724e2 | 2011-10-11 16:48:57 +1100 | [diff] [blame] | 163 | struct mpconf *conf = mddev->private; |
NeilBrown | 0d12922 | 2006-10-03 01:15:54 -0700 | [diff] [blame] | 164 | int i, ret = 0; |
| 165 | |
| 166 | rcu_read_lock(); |
| 167 | for (i = 0; i < mddev->raid_disks ; i++) { |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 168 | struct md_rdev *rdev = rcu_dereference(conf->multipaths[i].rdev); |
NeilBrown | 0d12922 | 2006-10-03 01:15:54 -0700 | [diff] [blame] | 169 | if (rdev && !test_bit(Faulty, &rdev->flags)) { |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 170 | struct request_queue *q = bdev_get_queue(rdev->bdev); |
NeilBrown | 0d12922 | 2006-10-03 01:15:54 -0700 | [diff] [blame] | 171 | |
| 172 | ret |= bdi_congested(&q->backing_dev_info, bits); |
| 173 | /* Just like multipath_map, we just check the |
| 174 | * first available device |
| 175 | */ |
| 176 | break; |
| 177 | } |
| 178 | } |
| 179 | rcu_read_unlock(); |
| 180 | return ret; |
| 181 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
| 183 | /* |
| 184 | * Careful, this can execute in IRQ contexts as well! |
| 185 | */ |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 186 | static void multipath_error (struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | { |
NeilBrown | 69724e2 | 2011-10-11 16:48:57 +1100 | [diff] [blame] | 188 | struct mpconf *conf = mddev->private; |
NeilBrown | 6f8d0c7 | 2011-05-11 14:38:44 +1000 | [diff] [blame] | 189 | char b[BDEVNAME_SIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
NeilBrown | 92f861a | 2011-05-11 14:38:02 +1000 | [diff] [blame] | 191 | if (conf->raid_disks - mddev->degraded <= 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | /* |
| 193 | * Uh oh, we can do nothing if this is our last path, but |
| 194 | * first check if this is a queued request for a device |
| 195 | * which has just failed. |
| 196 | */ |
NeilBrown | f72ffdd | 2014-09-30 14:23:59 +1000 | [diff] [blame] | 197 | printk(KERN_ALERT |
NeilBrown | 6f8d0c7 | 2011-05-11 14:38:44 +1000 | [diff] [blame] | 198 | "multipath: only one IO path left and IO error.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | /* leave it active... it's all we have */ |
NeilBrown | 6f8d0c7 | 2011-05-11 14:38:44 +1000 | [diff] [blame] | 200 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | } |
NeilBrown | 6f8d0c7 | 2011-05-11 14:38:44 +1000 | [diff] [blame] | 202 | /* |
| 203 | * Mark disk as unusable |
| 204 | */ |
| 205 | if (test_and_clear_bit(In_sync, &rdev->flags)) { |
| 206 | unsigned long flags; |
| 207 | spin_lock_irqsave(&conf->device_lock, flags); |
| 208 | mddev->degraded++; |
| 209 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 210 | } |
| 211 | set_bit(Faulty, &rdev->flags); |
| 212 | set_bit(MD_CHANGE_DEVS, &mddev->flags); |
| 213 | printk(KERN_ALERT "multipath: IO failure on %s," |
| 214 | " disabling IO path.\n" |
| 215 | "multipath: Operation continuing" |
| 216 | " on %d IO paths.\n", |
| 217 | bdevname(rdev->bdev, b), |
| 218 | conf->raid_disks - mddev->degraded); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | } |
| 220 | |
NeilBrown | 69724e2 | 2011-10-11 16:48:57 +1100 | [diff] [blame] | 221 | static void print_multipath_conf (struct mpconf *conf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | { |
| 223 | int i; |
| 224 | struct multipath_info *tmp; |
| 225 | |
| 226 | printk("MULTIPATH conf printout:\n"); |
| 227 | if (!conf) { |
| 228 | printk("(conf==NULL)\n"); |
| 229 | return; |
| 230 | } |
NeilBrown | 92f861a | 2011-05-11 14:38:02 +1000 | [diff] [blame] | 231 | printk(" --- wd:%d rd:%d\n", conf->raid_disks - conf->mddev->degraded, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | conf->raid_disks); |
| 233 | |
| 234 | for (i = 0; i < conf->raid_disks; i++) { |
| 235 | char b[BDEVNAME_SIZE]; |
| 236 | tmp = conf->multipaths + i; |
| 237 | if (tmp->rdev) |
| 238 | printk(" disk%d, o:%d, dev:%s\n", |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 239 | i,!test_bit(Faulty, &tmp->rdev->flags), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | bdevname(tmp->rdev->bdev,b)); |
| 241 | } |
| 242 | } |
| 243 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 244 | static int multipath_add_disk(struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | { |
NeilBrown | 69724e2 | 2011-10-11 16:48:57 +1100 | [diff] [blame] | 246 | struct mpconf *conf = mddev->private; |
Jesper Juhl | 352d768 | 2006-01-09 20:54:44 -0800 | [diff] [blame] | 247 | struct request_queue *q; |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 248 | int err = -EEXIST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | int path; |
| 250 | struct multipath_info *p; |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 251 | int first = 0; |
| 252 | int last = mddev->raid_disks - 1; |
| 253 | |
| 254 | if (rdev->raid_disk >= 0) |
| 255 | first = last = rdev->raid_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
| 257 | print_multipath_conf(conf); |
| 258 | |
Neil Brown | 6c2fce2 | 2008-06-28 08:31:31 +1000 | [diff] [blame] | 259 | for (path = first; path <= last; path++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | if ((p=conf->multipaths+path)->rdev == NULL) { |
Jesper Juhl | 352d768 | 2006-01-09 20:54:44 -0800 | [diff] [blame] | 261 | q = rdev->bdev->bd_disk->queue; |
Martin K. Petersen | 8f6c2e4 | 2009-07-01 11:13:45 +1000 | [diff] [blame] | 262 | disk_stack_limits(mddev->gendisk, rdev->bdev, |
| 263 | rdev->data_offset << 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | |
Dan Williams | 1501efa | 2016-01-13 16:00:07 -0800 | [diff] [blame] | 265 | err = md_integrity_add_rdev(rdev, mddev); |
| 266 | if (err) |
| 267 | break; |
NeilBrown | 6f8d0c7 | 2011-05-11 14:38:44 +1000 | [diff] [blame] | 268 | spin_lock_irq(&conf->device_lock); |
NeilBrown | 750a8f3 | 2006-10-28 10:38:31 -0700 | [diff] [blame] | 269 | mddev->degraded--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | rdev->raid_disk = path; |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 271 | set_bit(In_sync, &rdev->flags); |
NeilBrown | 6f8d0c7 | 2011-05-11 14:38:44 +1000 | [diff] [blame] | 272 | spin_unlock_irq(&conf->device_lock); |
Suzanne Wood | d6065f7 | 2005-11-08 21:39:27 -0800 | [diff] [blame] | 273 | rcu_assign_pointer(p->rdev, rdev); |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 274 | err = 0; |
| 275 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | print_multipath_conf(conf); |
Neil Brown | 199050e | 2008-06-28 08:31:33 +1000 | [diff] [blame] | 279 | |
| 280 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | } |
| 282 | |
NeilBrown | b8321b6 | 2011-12-23 10:17:51 +1100 | [diff] [blame] | 283 | static int multipath_remove_disk(struct mddev *mddev, struct md_rdev *rdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | { |
NeilBrown | 69724e2 | 2011-10-11 16:48:57 +1100 | [diff] [blame] | 285 | struct mpconf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | int err = 0; |
NeilBrown | b8321b6 | 2011-12-23 10:17:51 +1100 | [diff] [blame] | 287 | int number = rdev->raid_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | struct multipath_info *p = conf->multipaths + number; |
| 289 | |
| 290 | print_multipath_conf(conf); |
| 291 | |
NeilBrown | b8321b6 | 2011-12-23 10:17:51 +1100 | [diff] [blame] | 292 | if (rdev == p->rdev) { |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 293 | if (test_bit(In_sync, &rdev->flags) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | atomic_read(&rdev->nr_pending)) { |
NeilBrown | dfc7064 | 2008-05-23 13:04:39 -0700 | [diff] [blame] | 295 | printk(KERN_ERR "hot-remove-disk, slot %d is identified" |
| 296 | " but is still operational!\n", number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | err = -EBUSY; |
| 298 | goto abort; |
| 299 | } |
| 300 | p->rdev = NULL; |
NeilBrown | d787be4 | 2016-06-02 16:19:53 +1000 | [diff] [blame] | 301 | if (!test_bit(RemoveSynchronized, &rdev->flags)) { |
| 302 | synchronize_rcu(); |
| 303 | if (atomic_read(&rdev->nr_pending)) { |
| 304 | /* lost the race, try later */ |
| 305 | err = -EBUSY; |
| 306 | p->rdev = rdev; |
| 307 | goto abort; |
| 308 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | } |
Martin K. Petersen | a91a278 | 2011-03-17 11:11:05 +0100 | [diff] [blame] | 310 | err = md_integrity_register(mddev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | } |
| 312 | abort: |
| 313 | |
| 314 | print_multipath_conf(conf); |
| 315 | return err; |
| 316 | } |
| 317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | /* |
| 319 | * This is a kernel thread which: |
| 320 | * |
| 321 | * 1. Retries failed read operations on working multipaths. |
| 322 | * 2. Updates the raid superblock when problems encounter. |
| 323 | * 3. Performs writes following reads for array syncronising. |
| 324 | */ |
| 325 | |
Shaohua Li | 4ed8731 | 2012-10-11 13:34:00 +1100 | [diff] [blame] | 326 | static void multipathd(struct md_thread *thread) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | { |
Shaohua Li | 4ed8731 | 2012-10-11 13:34:00 +1100 | [diff] [blame] | 328 | struct mddev *mddev = thread->mddev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | struct multipath_bh *mp_bh; |
| 330 | struct bio *bio; |
| 331 | unsigned long flags; |
NeilBrown | 69724e2 | 2011-10-11 16:48:57 +1100 | [diff] [blame] | 332 | struct mpconf *conf = mddev->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | struct list_head *head = &conf->retry_list; |
| 334 | |
| 335 | md_check_recovery(mddev); |
| 336 | for (;;) { |
| 337 | char b[BDEVNAME_SIZE]; |
| 338 | spin_lock_irqsave(&conf->device_lock, flags); |
| 339 | if (list_empty(head)) |
| 340 | break; |
| 341 | mp_bh = list_entry(head->prev, struct multipath_bh, retry_list); |
| 342 | list_del(head->prev); |
| 343 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 344 | |
| 345 | bio = &mp_bh->bio; |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 346 | bio->bi_iter.bi_sector = mp_bh->master_bio->bi_iter.bi_sector; |
NeilBrown | f72ffdd | 2014-09-30 14:23:59 +1000 | [diff] [blame] | 347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | if ((mp_bh->path = multipath_map (conf))<0) { |
| 349 | printk(KERN_ALERT "multipath: %s: unrecoverable IO read" |
| 350 | " error for block %llu\n", |
| 351 | bdevname(bio->bi_bdev,b), |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 352 | (unsigned long long)bio->bi_iter.bi_sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | multipath_end_bh_io(mp_bh, -EIO); |
| 354 | } else { |
| 355 | printk(KERN_ERR "multipath: %s: redirecting sector %llu" |
| 356 | " to another IO path\n", |
| 357 | bdevname(bio->bi_bdev,b), |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 358 | (unsigned long long)bio->bi_iter.bi_sector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | *bio = *(mp_bh->master_bio); |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 360 | bio->bi_iter.bi_sector += |
| 361 | conf->multipaths[mp_bh->path].rdev->data_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | bio->bi_bdev = conf->multipaths[mp_bh->path].rdev->bdev; |
Jens Axboe | 1eff9d3 | 2016-08-05 15:35:16 -0600 | [diff] [blame] | 363 | bio->bi_opf |= REQ_FAILFAST_TRANSPORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | bio->bi_end_io = multipath_end_request; |
| 365 | bio->bi_private = mp_bh; |
| 366 | generic_make_request(bio); |
| 367 | } |
| 368 | } |
| 369 | spin_unlock_irqrestore(&conf->device_lock, flags); |
| 370 | } |
| 371 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 372 | static sector_t multipath_size(struct mddev *mddev, sector_t sectors, int raid_disks) |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 373 | { |
| 374 | WARN_ONCE(sectors || raid_disks, |
| 375 | "%s does not support generic reshape\n", __func__); |
| 376 | |
| 377 | return mddev->dev_sectors; |
| 378 | } |
| 379 | |
NeilBrown | fd01b88 | 2011-10-11 16:47:53 +1100 | [diff] [blame] | 380 | static int multipath_run (struct mddev *mddev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | { |
NeilBrown | 69724e2 | 2011-10-11 16:48:57 +1100 | [diff] [blame] | 382 | struct mpconf *conf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | int disk_idx; |
| 384 | struct multipath_info *disk; |
NeilBrown | 3cb0300 | 2011-10-11 16:45:26 +1100 | [diff] [blame] | 385 | struct md_rdev *rdev; |
NeilBrown | 92f861a | 2011-05-11 14:38:02 +1000 | [diff] [blame] | 386 | int working_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
Andre Noll | 0894cc3 | 2009-06-18 08:49:23 +1000 | [diff] [blame] | 388 | if (md_check_no_bitmap(mddev)) |
| 389 | return -EINVAL; |
| 390 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | if (mddev->level != LEVEL_MULTIPATH) { |
| 392 | printk("multipath: %s: raid level not set to multipath IO (%d)\n", |
| 393 | mdname(mddev), mddev->level); |
| 394 | goto out; |
| 395 | } |
| 396 | /* |
| 397 | * copy the already verified devices into our private MULTIPATH |
| 398 | * bookkeeping area. [whatever we allocate in multipath_run(), |
NeilBrown | afa0f55 | 2014-12-15 12:56:58 +1100 | [diff] [blame] | 399 | * should be freed in multipath_free()] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | */ |
| 401 | |
NeilBrown | 69724e2 | 2011-10-11 16:48:57 +1100 | [diff] [blame] | 402 | conf = kzalloc(sizeof(struct mpconf), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | mddev->private = conf; |
| 404 | if (!conf) { |
NeilBrown | f72ffdd | 2014-09-30 14:23:59 +1000 | [diff] [blame] | 405 | printk(KERN_ERR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | "multipath: couldn't allocate memory for %s\n", |
| 407 | mdname(mddev)); |
| 408 | goto out; |
| 409 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
NeilBrown | 9ffae0c | 2006-01-06 00:20:32 -0800 | [diff] [blame] | 411 | conf->multipaths = kzalloc(sizeof(struct multipath_info)*mddev->raid_disks, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | GFP_KERNEL); |
| 413 | if (!conf->multipaths) { |
NeilBrown | f72ffdd | 2014-09-30 14:23:59 +1000 | [diff] [blame] | 414 | printk(KERN_ERR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | "multipath: couldn't allocate memory for %s\n", |
| 416 | mdname(mddev)); |
| 417 | goto out_free_conf; |
| 418 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
NeilBrown | 92f861a | 2011-05-11 14:38:02 +1000 | [diff] [blame] | 420 | working_disks = 0; |
NeilBrown | dafb20f | 2012-03-19 12:46:39 +1100 | [diff] [blame] | 421 | rdev_for_each(rdev, mddev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | disk_idx = rdev->raid_disk; |
| 423 | if (disk_idx < 0 || |
| 424 | disk_idx >= mddev->raid_disks) |
| 425 | continue; |
| 426 | |
| 427 | disk = conf->multipaths + disk_idx; |
| 428 | disk->rdev = rdev; |
Martin K. Petersen | 8f6c2e4 | 2009-07-01 11:13:45 +1000 | [diff] [blame] | 429 | disk_stack_limits(mddev->gendisk, rdev->bdev, |
| 430 | rdev->data_offset << 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
NeilBrown | b2d444d | 2005-11-08 21:39:31 -0800 | [diff] [blame] | 432 | if (!test_bit(Faulty, &rdev->flags)) |
NeilBrown | 92f861a | 2011-05-11 14:38:02 +1000 | [diff] [blame] | 433 | working_disks++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | conf->raid_disks = mddev->raid_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | conf->mddev = mddev; |
| 438 | spin_lock_init(&conf->device_lock); |
| 439 | INIT_LIST_HEAD(&conf->retry_list); |
| 440 | |
NeilBrown | 92f861a | 2011-05-11 14:38:02 +1000 | [diff] [blame] | 441 | if (!working_disks) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | printk(KERN_ERR "multipath: no operational IO paths for %s\n", |
| 443 | mdname(mddev)); |
| 444 | goto out_free_conf; |
| 445 | } |
NeilBrown | 92f861a | 2011-05-11 14:38:02 +1000 | [diff] [blame] | 446 | mddev->degraded = conf->raid_disks - working_disks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
Sage Weil | bbba809 | 2009-09-21 17:02:55 -0700 | [diff] [blame] | 448 | conf->pool = mempool_create_kmalloc_pool(NR_RESERVED_BUFS, |
Matthew Dobson | 26b6e05 | 2006-03-26 01:37:48 -0800 | [diff] [blame] | 449 | sizeof(struct multipath_bh)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | if (conf->pool == NULL) { |
NeilBrown | f72ffdd | 2014-09-30 14:23:59 +1000 | [diff] [blame] | 451 | printk(KERN_ERR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | "multipath: couldn't allocate memory for %s\n", |
| 453 | mdname(mddev)); |
| 454 | goto out_free_conf; |
| 455 | } |
| 456 | |
| 457 | { |
NeilBrown | 0232605 | 2012-07-03 15:56:52 +1000 | [diff] [blame] | 458 | mddev->thread = md_register_thread(multipathd, mddev, |
| 459 | "multipath"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | if (!mddev->thread) { |
| 461 | printk(KERN_ERR "multipath: couldn't allocate thread" |
| 462 | " for %s\n", mdname(mddev)); |
| 463 | goto out_free_conf; |
| 464 | } |
| 465 | } |
| 466 | |
NeilBrown | f72ffdd | 2014-09-30 14:23:59 +1000 | [diff] [blame] | 467 | printk(KERN_INFO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | "multipath: array %s active with %d out of %d IO paths\n", |
NeilBrown | 92f861a | 2011-05-11 14:38:02 +1000 | [diff] [blame] | 469 | mdname(mddev), conf->raid_disks - mddev->degraded, |
| 470 | mddev->raid_disks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | /* |
| 472 | * Ok, everything is just fine now |
| 473 | */ |
Dan Williams | 1f40362 | 2009-03-31 14:59:03 +1100 | [diff] [blame] | 474 | md_set_array_sectors(mddev, multipath_size(mddev, 0, 0)); |
NeilBrown | 7a5febe | 2005-05-16 21:53:16 -0700 | [diff] [blame] | 475 | |
Martin K. Petersen | a91a278 | 2011-03-17 11:11:05 +0100 | [diff] [blame] | 476 | if (md_integrity_register(mddev)) |
| 477 | goto out_free_conf; |
| 478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | return 0; |
| 480 | |
| 481 | out_free_conf: |
Julia Lawall | 644df1a | 2015-09-13 14:15:10 +0200 | [diff] [blame] | 482 | mempool_destroy(conf->pool); |
Jesper Juhl | 990a8ba | 2005-06-21 17:17:30 -0700 | [diff] [blame] | 483 | kfree(conf->multipaths); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | kfree(conf); |
| 485 | mddev->private = NULL; |
| 486 | out: |
| 487 | return -EIO; |
| 488 | } |
| 489 | |
NeilBrown | afa0f55 | 2014-12-15 12:56:58 +1100 | [diff] [blame] | 490 | static void multipath_free(struct mddev *mddev, void *priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | { |
NeilBrown | afa0f55 | 2014-12-15 12:56:58 +1100 | [diff] [blame] | 492 | struct mpconf *conf = priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | mempool_destroy(conf->pool); |
| 495 | kfree(conf->multipaths); |
| 496 | kfree(conf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | } |
| 498 | |
NeilBrown | 84fc4b5 | 2011-10-11 16:49:58 +1100 | [diff] [blame] | 499 | static struct md_personality multipath_personality = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | { |
| 501 | .name = "multipath", |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 502 | .level = LEVEL_MULTIPATH, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | .owner = THIS_MODULE, |
| 504 | .make_request = multipath_make_request, |
| 505 | .run = multipath_run, |
NeilBrown | afa0f55 | 2014-12-15 12:56:58 +1100 | [diff] [blame] | 506 | .free = multipath_free, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | .status = multipath_status, |
| 508 | .error_handler = multipath_error, |
| 509 | .hot_add_disk = multipath_add_disk, |
| 510 | .hot_remove_disk= multipath_remove_disk, |
Dan Williams | 80c3a6c | 2009-03-17 18:10:40 -0700 | [diff] [blame] | 511 | .size = multipath_size, |
NeilBrown | 5c675f8 | 2014-12-15 12:56:56 +1100 | [diff] [blame] | 512 | .congested = multipath_congested, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | }; |
| 514 | |
| 515 | static int __init multipath_init (void) |
| 516 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 517 | return register_md_personality (&multipath_personality); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | static void __exit multipath_exit (void) |
| 521 | { |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 522 | unregister_md_personality (&multipath_personality); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | module_init(multipath_init); |
| 526 | module_exit(multipath_exit); |
| 527 | MODULE_LICENSE("GPL"); |
NeilBrown | 0efb9e6 | 2009-12-14 12:49:58 +1100 | [diff] [blame] | 528 | MODULE_DESCRIPTION("simple multi-path personality for MD"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | MODULE_ALIAS("md-personality-7"); /* MULTIPATH */ |
NeilBrown | d9d166c | 2006-01-06 00:20:51 -0800 | [diff] [blame] | 530 | MODULE_ALIAS("md-multipath"); |
NeilBrown | 2604b70 | 2006-01-06 00:20:36 -0800 | [diff] [blame] | 531 | MODULE_ALIAS("md-level--4"); |