23 #include <linux/module.h>
24 #include <linux/raid/md_u.h>
26 #include <linux/slab.h>
30 #define MAX_WORK_PER_DISK 128
32 #define NR_RESERVED_BUFS 32
35 static int multipath_map (
struct mpconf *conf)
45 for (i = 0; i < disks; i++) {
55 printk(
KERN_ERR "multipath_map(): no more operational IO paths?\n");
59 static void multipath_reschedule_retry (
struct multipath_bh *mp_bh)
86 static void multipath_end_request(
struct bio *bio,
int error)
88 int uptodate =
test_bit(BIO_UPTODATE, &bio->bi_flags);
94 multipath_end_bh_io(mp_bh, 0);
103 (
unsigned long long)bio->bi_sector);
104 multipath_reschedule_retry(mp_bh);
106 multipath_end_bh_io(mp_bh, error);
107 rdev_dec_pending(rdev, conf->
mddev);
110 static void multipath_make_request(
struct mddev *
mddev,
struct bio * bio)
124 mp_bh->
mddev = mddev;
126 mp_bh->
path = multipath_map(conf);
127 if (mp_bh->
path < 0) {
135 mp_bh->
bio.bi_sector += multipath->
rdev->data_offset;
136 mp_bh->
bio.bi_bdev = multipath->
rdev->bdev;
138 mp_bh->
bio.bi_end_io = multipath_end_request;
139 mp_bh->
bio.bi_private = mp_bh;
144 static void multipath_status (
struct seq_file *seq,
struct mddev *mddev)
158 static int multipath_congested(
void *
data,
int bits)
160 struct mddev *mddev =
data;
173 ret |= bdi_congested(&q->backing_dev_info, bits);
187 static void multipath_error (
struct mddev *mddev,
struct md_rdev *rdev)
199 "multipath: only one IO path left and IO error.\n");
215 " disabling IO path.\n"
216 "multipath: Operation continuing"
217 " on %d IO paths.\n",
222 static void print_multipath_conf (
struct mpconf *conf)
227 printk(
"MULTIPATH conf printout:\n");
239 printk(
" disk%d, o:%d, dev:%s\n",
246 static int multipath_add_disk(
struct mddev *mddev,
struct md_rdev *rdev)
259 print_multipath_conf(conf);
261 for (path = first; path <= last; path++)
263 q = rdev->
bdev->bd_disk->queue;
273 if (q->merge_bvec_fn) {
290 print_multipath_conf(conf);
295 static int multipath_remove_disk(
struct mddev *mddev,
struct md_rdev *rdev)
302 print_multipath_conf(conf);
304 if (rdev == p->
rdev) {
308 " but is still operational!\n", number);
324 print_multipath_conf(conf);
340 struct mddev *mddev = thread->
mddev;
351 if (list_empty(head))
358 bio->bi_sector = mp_bh->
master_bio->bi_sector;
360 if ((mp_bh->
path = multipath_map (conf))<0) {
362 " error for block %llu\n",
364 (
unsigned long long)bio->bi_sector);
365 multipath_end_bh_io(mp_bh, -
EIO);
368 " to another IO path\n",
370 (
unsigned long long)bio->bi_sector);
372 bio->bi_sector += conf->
multipaths[mp_bh->
path].rdev->data_offset;
375 bio->bi_end_io = multipath_end_request;
376 bio->bi_private = mp_bh;
386 "%s does not support generic reshape\n", __func__);
391 static int multipath_run (
struct mddev *mddev)
403 printk(
"multipath: %s: raid level not set to multipath IO (%d)\n",
404 mdname(mddev), mddev->
level);
417 "multipath: couldn't allocate memory for %s\n",
426 "multipath: couldn't allocate memory for %s\n",
446 if (rdev->
bdev->bd_disk->queue->merge_bvec_fn) {
461 if (!working_disks) {
472 "multipath: couldn't allocate memory for %s\n",
482 " for %s\n", mdname(mddev));
488 "multipath: array %s active with %d out of %d IO paths\n",
496 mddev->
queue->backing_dev_info.congested_fn = multipath_congested;
497 mddev->
queue->backing_dev_info.congested_data =
mddev;
515 static int multipath_stop (
struct mddev *mddev)
533 .make_request = multipath_make_request,
534 .run = multipath_run,
535 .stop = multipath_stop,
536 .status = multipath_status,
537 .error_handler = multipath_error,
538 .hot_add_disk = multipath_add_disk,
539 .hot_remove_disk= multipath_remove_disk,
540 .size = multipath_size,
543 static int __init multipath_init (
void)
548 static void __exit multipath_exit (
void)