X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fmd%2Fmultipath.c;h=14da37fee37b428b72f2f5339f465ad4bfa3e3e8;hb=refs%2Fheads%2Fvserver;hp=9114c7c269ed49cfc38b3b62a364c9627d56791f;hpb=5273a3df6485dc2ad6aa7ddd441b9a21970f003b;p=linux-2.6.git diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c index 9114c7c26..14da37fee 100644 --- a/drivers/md/multipath.c +++ b/drivers/md/multipath.c @@ -35,28 +35,8 @@ #define NR_RESERVED_BUFS 32 -static mdk_personality_t multipath_personality; -static spinlock_t retry_list_lock = SPIN_LOCK_UNLOCKED; -struct multipath_bh *multipath_retry_list = NULL, **multipath_retry_tail; - - -static void *mp_pool_alloc(int gfp_flags, void *data) -{ - struct multipath_bh *mpb; - mpb = kmalloc(sizeof(*mpb), gfp_flags); - if (mpb) - memset(mpb, 0, sizeof(*mpb)); - return mpb; -} - -static void mp_pool_free(void *mpb, void *data) -{ - kfree(mpb); -} - -static int multipath_map (mddev_t *mddev, mdk_rdev_t **rdevp) +static int multipath_map (multipath_conf_t *conf) { - multipath_conf_t *conf = mddev_to_conf(mddev); int i, disks = conf->raid_disks; /* @@ -64,17 +44,16 @@ static int multipath_map (mddev_t *mddev, mdk_rdev_t **rdevp) * now we use the first available disk. */ - spin_lock_irq(&conf->device_lock); + rcu_read_lock(); for (i = 0; i < disks; i++) { - mdk_rdev_t *rdev = conf->multipaths[i].rdev; - if (rdev && rdev->in_sync) { - *rdevp = rdev; + mdk_rdev_t *rdev = rcu_dereference(conf->multipaths[i].rdev); + if (rdev && test_bit(In_sync, &rdev->flags)) { atomic_inc(&rdev->nr_pending); - spin_unlock_irq(&conf->device_lock); - return 0; + rcu_read_unlock(); + return i; } } - spin_unlock_irq(&conf->device_lock); + rcu_read_unlock(); printk(KERN_ERR "multipath_map(): no more operational IO paths?\n"); return (-1); @@ -84,14 +63,11 @@ static void multipath_reschedule_retry (struct multipath_bh *mp_bh) { unsigned long flags; mddev_t *mddev = mp_bh->mddev; + multipath_conf_t *conf = mddev_to_conf(mddev); - spin_lock_irqsave(&retry_list_lock, flags); - if (multipath_retry_list == NULL) - multipath_retry_tail = &multipath_retry_list; - *multipath_retry_tail = mp_bh; - multipath_retry_tail = &mp_bh->next_mp; - mp_bh->next_mp = NULL; - spin_unlock_irqrestore(&retry_list_lock, flags); + spin_lock_irqsave(&conf->device_lock, flags); + list_add(&mp_bh->retry_list, &conf->retry_list); + spin_unlock_irqrestore(&conf->device_lock, flags); md_wakeup_thread(mddev->thread); } @@ -101,16 +77,17 @@ static void multipath_reschedule_retry (struct multipath_bh *mp_bh) * operation and are ready to return a success/failure code to the buffer * cache layer. */ -static void multipath_end_bh_io (struct multipath_bh *mp_bh, int uptodate) +static void multipath_end_bh_io (struct multipath_bh *mp_bh, int err) { struct bio *bio = mp_bh->master_bio; multipath_conf_t *conf = mddev_to_conf(mp_bh->mddev); - bio_endio(bio, bio->bi_size, uptodate ? 0 : -EIO); + bio_endio(bio, bio->bi_size, err); mempool_free(mp_bh, conf->pool); } -int multipath_end_request(struct bio *bio, unsigned int bytes_done, int error) +static int multipath_end_request(struct bio *bio, unsigned int bytes_done, + int error) { int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); struct multipath_bh * mp_bh = (struct multipath_bh *)(bio->bi_private); @@ -121,8 +98,8 @@ int multipath_end_request(struct bio *bio, unsigned int bytes_done, int error) return 1; if (uptodate) - multipath_end_bh_io(mp_bh, uptodate); - else { + multipath_end_bh_io(mp_bh, 0); + else if (!bio_rw_ahead(bio)) { /* * oops, IO error: */ @@ -132,26 +109,9 @@ int multipath_end_request(struct bio *bio, unsigned int bytes_done, int error) bdevname(rdev->bdev,b), (unsigned long long)bio->bi_sector); multipath_reschedule_retry(mp_bh); - } - atomic_dec(&rdev->nr_pending); - return 0; -} - -/* - * This routine returns the disk from which the requested read should - * be done. - */ - -static int multipath_read_balance (multipath_conf_t *conf) -{ - int disk; - - for (disk = 0; disk < conf->raid_disks; disk++) { - mdk_rdev_t *rdev = conf->multipaths[disk].rdev; - if (rdev && rdev->in_sync) - return disk; - } - BUG(); + } else + multipath_end_bh_io(mp_bh, error); + rdev_dec_pending(rdev, conf->mddev); return 0; } @@ -160,16 +120,26 @@ static void unplug_slaves(mddev_t *mddev) multipath_conf_t *conf = mddev_to_conf(mddev); int i; + rcu_read_lock(); for (i=0; iraid_disks; i++) { - mdk_rdev_t *rdev = conf->multipaths[i].rdev; - if (rdev && !rdev->faulty) { + mdk_rdev_t *rdev = rcu_dereference(conf->multipaths[i].rdev); + if (rdev && !test_bit(Faulty, &rdev->flags) + && atomic_read(&rdev->nr_pending)) { request_queue_t *r_queue = bdev_get_queue(rdev->bdev); + atomic_inc(&rdev->nr_pending); + rcu_read_unlock(); + if (r_queue->unplug_fn) r_queue->unplug_fn(r_queue); + + rdev_dec_pending(rdev, mddev); + rcu_read_lock(); } } + rcu_read_unlock(); } + static void multipath_unplug(request_queue_t *q) { unplug_slaves(q->queuedata); @@ -182,29 +152,31 @@ static int multipath_make_request (request_queue_t *q, struct bio * bio) multipath_conf_t *conf = mddev_to_conf(mddev); struct multipath_bh * mp_bh; struct multipath_info *multipath; + const int rw = bio_data_dir(bio); + + if (unlikely(bio_barrier(bio))) { + bio_endio(bio, bio->bi_size, -EOPNOTSUPP); + return 0; + } mp_bh = mempool_alloc(conf->pool, GFP_NOIO); mp_bh->master_bio = bio; mp_bh->mddev = mddev; - if (bio_data_dir(bio)==WRITE) { - disk_stat_inc(mddev->gendisk, writes); - disk_stat_add(mddev->gendisk, write_sectors, bio_sectors(bio)); - } else { - disk_stat_inc(mddev->gendisk, reads); - disk_stat_add(mddev->gendisk, read_sectors, bio_sectors(bio)); + disk_stat_inc(mddev->gendisk, ios[rw]); + disk_stat_add(mddev->gendisk, sectors[rw], bio_sectors(bio)); + + mp_bh->path = multipath_map(conf); + if (mp_bh->path < 0) { + bio_endio(bio, bio->bi_size, -EIO); + mempool_free(mp_bh, conf->pool); + return 0; } - /* - * read balancing logic: - */ - spin_lock_irq(&conf->device_lock); - mp_bh->path = multipath_read_balance(conf); multipath = conf->multipaths + mp_bh->path; - atomic_inc(&multipath->rdev->nr_pending); - spin_unlock_irq(&conf->device_lock); mp_bh->bio = *bio; + mp_bh->bio.bi_sector += multipath->rdev->data_offset; mp_bh->bio.bi_bdev = multipath->rdev->bdev; mp_bh->bio.bi_rw |= (1 << BIO_RW_FAILFAST); mp_bh->bio.bi_end_io = multipath_end_request; @@ -223,10 +195,61 @@ static void multipath_status (struct seq_file *seq, mddev_t *mddev) for (i = 0; i < conf->raid_disks; i++) seq_printf (seq, "%s", conf->multipaths[i].rdev && - conf->multipaths[i].rdev->in_sync ? "U" : "_"); + test_bit(In_sync, &conf->multipaths[i].rdev->flags) ? "U" : "_"); seq_printf (seq, "]"); } +static int multipath_issue_flush(request_queue_t *q, struct gendisk *disk, + sector_t *error_sector) +{ + mddev_t *mddev = q->queuedata; + multipath_conf_t *conf = mddev_to_conf(mddev); + int i, ret = 0; + + rcu_read_lock(); + for (i=0; iraid_disks && ret == 0; i++) { + mdk_rdev_t *rdev = rcu_dereference(conf->multipaths[i].rdev); + if (rdev && !test_bit(Faulty, &rdev->flags)) { + struct block_device *bdev = rdev->bdev; + request_queue_t *r_queue = bdev_get_queue(bdev); + + if (!r_queue->issue_flush_fn) + ret = -EOPNOTSUPP; + else { + atomic_inc(&rdev->nr_pending); + rcu_read_unlock(); + ret = r_queue->issue_flush_fn(r_queue, bdev->bd_disk, + error_sector); + rdev_dec_pending(rdev, mddev); + rcu_read_lock(); + } + } + } + rcu_read_unlock(); + return ret; +} +static int multipath_congested(void *data, int bits) +{ + mddev_t *mddev = data; + multipath_conf_t *conf = mddev_to_conf(mddev); + int i, ret = 0; + + rcu_read_lock(); + for (i = 0; i < mddev->raid_disks ; i++) { + mdk_rdev_t *rdev = rcu_dereference(conf->multipaths[i].rdev); + if (rdev && !test_bit(Faulty, &rdev->flags)) { + request_queue_t *q = bdev_get_queue(rdev->bdev); + + ret |= bdi_congested(&q->backing_dev_info, bits); + /* Just like multipath_map, we just check the + * first available device + */ + break; + } + } + rcu_read_unlock(); + return ret; +} /* * Careful, this can execute in IRQ contexts as well! @@ -248,12 +271,13 @@ static void multipath_error (mddev_t *mddev, mdk_rdev_t *rdev) /* * Mark disk as unusable */ - if (!rdev->faulty) { + if (!test_bit(Faulty, &rdev->flags)) { char b[BDEVNAME_SIZE]; - rdev->in_sync = 0; - rdev->faulty = 1; - mddev->sb_dirty = 1; + clear_bit(In_sync, &rdev->flags); + set_bit(Faulty, &rdev->flags); + set_bit(MD_CHANGE_DEVS, &mddev->flags); conf->working_disks--; + mddev->degraded++; printk(KERN_ALERT "multipath: IO failure on %s," " disabling IO path. \n Operation continuing" " on %d IO paths.\n", @@ -281,7 +305,7 @@ static void print_multipath_conf (multipath_conf_t *conf) tmp = conf->multipaths + i; if (tmp->rdev) printk(" disk%d, o:%d, dev:%s\n", - i,!tmp->rdev->faulty, + i,!test_bit(Faulty, &tmp->rdev->flags), bdevname(tmp->rdev->bdev,b)); } } @@ -290,17 +314,17 @@ static void print_multipath_conf (multipath_conf_t *conf) static int multipath_add_disk(mddev_t *mddev, mdk_rdev_t *rdev) { multipath_conf_t *conf = mddev->private; + struct request_queue *q; int found = 0; int path; struct multipath_info *p; print_multipath_conf(conf); - spin_lock_irq(&conf->device_lock); + for (path=0; pathraid_disks; path++) if ((p=conf->multipaths+path)->rdev == NULL) { - p->rdev = rdev; - blk_queue_stack_limits(mddev->queue, - rdev->bdev->bd_disk->queue); + q = rdev->bdev->bd_disk->queue; + blk_queue_stack_limits(mddev->queue, q); /* as we don't honour merge_bvec_fn, we must never risk * violating it, so limit ->max_sector to one PAGE, as @@ -308,16 +332,17 @@ static int multipath_add_disk(mddev_t *mddev, mdk_rdev_t *rdev) * (Note: it is very unlikely that a device with * merge_bvec_fn will be involved in multipath.) */ - if (rdev->bdev->bd_disk->queue->merge_bvec_fn && + if (q->merge_bvec_fn && mddev->queue->max_sectors > (PAGE_SIZE>>9)) - mddev->queue->max_sectors = (PAGE_SIZE>>9); + blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9); conf->working_disks++; + mddev->degraded--; rdev->raid_disk = path; - rdev->in_sync = 1; + set_bit(In_sync, &rdev->flags); + rcu_assign_pointer(p->rdev, rdev); found = 1; } - spin_unlock_irq(&conf->device_lock); print_multipath_conf(conf); return found; @@ -326,26 +351,29 @@ static int multipath_add_disk(mddev_t *mddev, mdk_rdev_t *rdev) static int multipath_remove_disk(mddev_t *mddev, int number) { multipath_conf_t *conf = mddev->private; - int err = 1; + int err = 0; + mdk_rdev_t *rdev; struct multipath_info *p = conf->multipaths + number; print_multipath_conf(conf); - spin_lock_irq(&conf->device_lock); - if (p->rdev) { - if (p->rdev->in_sync || - atomic_read(&p->rdev->nr_pending)) { + rdev = p->rdev; + if (rdev) { + if (test_bit(In_sync, &rdev->flags) || + atomic_read(&rdev->nr_pending)) { printk(KERN_ERR "hot-remove-disk, slot %d is identified" " but is still operational!\n", number); err = -EBUSY; goto abort; } p->rdev = NULL; - err = 0; + synchronize_rcu(); + if (atomic_read(&rdev->nr_pending)) { + /* lost the race, try later */ + err = -EBUSY; + p->rdev = rdev; + } } - if (err) - MD_BUG(); abort: - spin_unlock_irq(&conf->device_lock); print_multipath_conf(conf); return err; @@ -366,39 +394,43 @@ static void multipathd (mddev_t *mddev) struct multipath_bh *mp_bh; struct bio *bio; unsigned long flags; - mdk_rdev_t *rdev; + multipath_conf_t *conf = mddev_to_conf(mddev); + struct list_head *head = &conf->retry_list; md_check_recovery(mddev); for (;;) { char b[BDEVNAME_SIZE]; - spin_lock_irqsave(&retry_list_lock, flags); - mp_bh = multipath_retry_list; - if (!mp_bh) + spin_lock_irqsave(&conf->device_lock, flags); + if (list_empty(head)) break; - multipath_retry_list = mp_bh->next_mp; - spin_unlock_irqrestore(&retry_list_lock, flags); + mp_bh = list_entry(head->prev, struct multipath_bh, retry_list); + list_del(head->prev); + spin_unlock_irqrestore(&conf->device_lock, flags); - mddev = mp_bh->mddev; bio = &mp_bh->bio; bio->bi_sector = mp_bh->master_bio->bi_sector; - rdev = NULL; - if (multipath_map (mddev, &rdev)<0) { + if ((mp_bh->path = multipath_map (conf))<0) { printk(KERN_ALERT "multipath: %s: unrecoverable IO read" " error for block %llu\n", bdevname(bio->bi_bdev,b), (unsigned long long)bio->bi_sector); - multipath_end_bh_io(mp_bh, 0); + multipath_end_bh_io(mp_bh, -EIO); } else { printk(KERN_ERR "multipath: %s: redirecting sector %llu" " to another IO path\n", bdevname(bio->bi_bdev,b), (unsigned long long)bio->bi_sector); - bio->bi_bdev = rdev->bdev; + *bio = *(mp_bh->master_bio); + bio->bi_sector += conf->multipaths[mp_bh->path].rdev->data_offset; + bio->bi_bdev = conf->multipaths[mp_bh->path].rdev->bdev; + bio->bi_rw |= (1 << BIO_RW_FAILFAST); + bio->bi_end_io = multipath_end_request; + bio->bi_private = mp_bh; generic_make_request(bio); } } - spin_unlock_irqrestore(&retry_list_lock, flags); + spin_unlock_irqrestore(&conf->device_lock, flags); } static int multipath_run (mddev_t *mddev) @@ -420,7 +452,7 @@ static int multipath_run (mddev_t *mddev) * should be freed in multipath_stop()] */ - conf = kmalloc(sizeof(multipath_conf_t), GFP_KERNEL); + conf = kzalloc(sizeof(multipath_conf_t), GFP_KERNEL); mddev->private = conf; if (!conf) { printk(KERN_ERR @@ -428,9 +460,8 @@ static int multipath_run (mddev_t *mddev) mdname(mddev)); goto out; } - memset(conf, 0, sizeof(*conf)); - conf->multipaths = kmalloc(sizeof(struct multipath_info)*mddev->raid_disks, + conf->multipaths = kzalloc(sizeof(struct multipath_info)*mddev->raid_disks, GFP_KERNEL); if (!conf->multipaths) { printk(KERN_ERR @@ -438,9 +469,6 @@ static int multipath_run (mddev_t *mddev) mdname(mddev)); goto out_free_conf; } - memset(conf->multipaths, 0, sizeof(struct multipath_info)*mddev->raid_disks); - - mddev->queue->unplug_fn = multipath_unplug; conf->working_disks = 0; ITERATE_RDEV(mddev,rdev,tmp) { @@ -459,27 +487,26 @@ static int multipath_run (mddev_t *mddev) * a merge_bvec_fn to be involved in multipath */ if (rdev->bdev->bd_disk->queue->merge_bvec_fn && mddev->queue->max_sectors > (PAGE_SIZE>>9)) - mddev->queue->max_sectors = (PAGE_SIZE>>9); + blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9); - if (!rdev->faulty) + if (!test_bit(Faulty, &rdev->flags)) conf->working_disks++; } conf->raid_disks = mddev->raid_disks; - mddev->sb_dirty = 1; conf->mddev = mddev; - conf->device_lock = SPIN_LOCK_UNLOCKED; + spin_lock_init(&conf->device_lock); + INIT_LIST_HEAD(&conf->retry_list); if (!conf->working_disks) { printk(KERN_ERR "multipath: no operational IO paths for %s\n", mdname(mddev)); goto out_free_conf; } - mddev->degraded = conf->raid_disks = conf->working_disks; + mddev->degraded = conf->raid_disks - conf->working_disks; - conf->pool = mempool_create(NR_RESERVED_BUFS, - mp_pool_alloc, mp_pool_free, - NULL); + conf->pool = mempool_create_kzalloc_pool(NR_RESERVED_BUFS, + sizeof(struct multipath_bh)); if (conf->pool == NULL) { printk(KERN_ERR "multipath: couldn't allocate memory for %s\n", @@ -503,13 +530,18 @@ static int multipath_run (mddev_t *mddev) * Ok, everything is just fine now */ mddev->array_size = mddev->size; + + mddev->queue->unplug_fn = multipath_unplug; + mddev->queue->issue_flush_fn = multipath_issue_flush; + mddev->queue->backing_dev_info.congested_fn = multipath_congested; + mddev->queue->backing_dev_info.congested_data = mddev; + return 0; out_free_conf: if (conf->pool) mempool_destroy(conf->pool); - if (conf->multipaths) - kfree(conf->multipaths); + kfree(conf->multipaths); kfree(conf); mddev->private = NULL; out: @@ -522,6 +554,8 @@ static int multipath_stop (mddev_t *mddev) multipath_conf_t *conf = mddev_to_conf(mddev); md_unregister_thread(mddev->thread); + mddev->thread = NULL; + blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/ mempool_destroy(conf->pool); kfree(conf->multipaths); kfree(conf); @@ -529,9 +563,10 @@ static int multipath_stop (mddev_t *mddev) return 0; } -static mdk_personality_t multipath_personality= +static struct mdk_personality multipath_personality = { .name = "multipath", + .level = LEVEL_MULTIPATH, .owner = THIS_MODULE, .make_request = multipath_make_request, .run = multipath_run, @@ -544,15 +579,17 @@ static mdk_personality_t multipath_personality= static int __init multipath_init (void) { - return register_md_personality (MULTIPATH, &multipath_personality); + return register_md_personality (&multipath_personality); } static void __exit multipath_exit (void) { - unregister_md_personality (MULTIPATH); + unregister_md_personality (&multipath_personality); } module_init(multipath_init); module_exit(multipath_exit); MODULE_LICENSE("GPL"); MODULE_ALIAS("md-personality-7"); /* MULTIPATH */ +MODULE_ALIAS("md-multipath"); +MODULE_ALIAS("md-level--4");