aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-06-12 19:42:39 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-06-12 19:42:39 -0400
commitb2cc9c19e48bcf00f10c23fbf9f6abe43f6929d5 (patch)
treed38b1d04479c14c8a9bfdf01bc817490173dcd28
parenta568fa1c91d4f0e565345119d0b942cc7f74ca3d (diff)
parentac4e97abce9b80c020e7113325f49e58b7b15e3f (diff)
Merge branch 'for-linus' of git://git.kernel.dk/linux-block
Pull block layer fixes from Jens Axboe: "Outside of bcache (which really isn't super big), these are all few-liners. There are a few important fixes in here: - Fix blk pm sleeping when holding the queue lock - A small collection of bcache fixes that have been done and tested since bcache was included in this merge window. - A fix for a raid5 regression introduced with the bio changes. - Two important fixes for mtip32xx, fixing an oops and potential data corruption (or hang) due to wrong bio iteration on stacked devices." * 'for-linus' of git://git.kernel.dk/linux-block: scatterlist: sg_set_buf() argument must be in linear mapping raid5: Initialize bi_vcnt pktcdvd: silence static checker warning block: remove refs to XD disks from documentation blkpm: avoid sleep when holding queue lock mtip32xx: Correctly handle bio->bi_idx != 0 conditions mtip32xx: Fix NULL pointer dereference during module unload bcache: Fix error handling in init code bcache: clarify free/available/unused space bcache: drop "select CLOSURES" bcache: Fix incompatible pointer type warning
-rw-r--r--Documentation/bcache.txt12
-rw-r--r--Documentation/devices.txt8
-rw-r--r--Documentation/kernel-parameters.txt3
-rw-r--r--Documentation/m68k/kernel-options.txt2
-rw-r--r--block/blk-core.c2
-rw-r--r--drivers/block/mtip32xx/mtip32xx.c8
-rw-r--r--drivers/block/pktcdvd.c3
-rw-r--r--drivers/md/bcache/Kconfig1
-rw-r--r--drivers/md/bcache/bcache.h2
-rw-r--r--drivers/md/bcache/stats.c34
-rw-r--r--drivers/md/bcache/super.c185
-rw-r--r--drivers/md/bcache/writeback.c2
-rw-r--r--drivers/md/raid5.c2
-rw-r--r--include/linux/scatterlist.h3
14 files changed, 124 insertions, 143 deletions
diff --git a/Documentation/bcache.txt b/Documentation/bcache.txt
index 77db8809bd96..b3a7e7d384f6 100644
--- a/Documentation/bcache.txt
+++ b/Documentation/bcache.txt
@@ -319,7 +319,10 @@ cache<0..n>
319 Symlink to each of the cache devices comprising this cache set. 319 Symlink to each of the cache devices comprising this cache set.
320 320
321cache_available_percent 321cache_available_percent
322 Percentage of cache device free. 322 Percentage of cache device which doesn't contain dirty data, and could
323 potentially be used for writeback. This doesn't mean this space isn't used
324 for clean cached data; the unused statistic (in priority_stats) is typically
325 much lower.
323 326
324clear_stats 327clear_stats
325 Clears the statistics associated with this cache 328 Clears the statistics associated with this cache
@@ -423,8 +426,11 @@ nbuckets
423 Total buckets in this cache 426 Total buckets in this cache
424 427
425priority_stats 428priority_stats
426 Statistics about how recently data in the cache has been accessed. This can 429 Statistics about how recently data in the cache has been accessed.
427 reveal your working set size. 430 This can reveal your working set size. Unused is the percentage of
431 the cache that doesn't contain any data. Metadata is bcache's
432 metadata overhead. Average is the average priority of cache buckets.
433 Next is a list of quantiles with the priority threshold of each.
428 434
429written 435written
430 Sum of all data that has been written to the cache; comparison with 436 Sum of all data that has been written to the cache; comparison with
diff --git a/Documentation/devices.txt b/Documentation/devices.txt
index 08f01e79c41a..b9015912bca6 100644
--- a/Documentation/devices.txt
+++ b/Documentation/devices.txt
@@ -498,12 +498,8 @@ Your cooperation is appreciated.
498 498
499 Each device type has 5 bits (32 minors). 499 Each device type has 5 bits (32 minors).
500 500
501 13 block 8-bit MFM/RLL/IDE controller 501 13 block Previously used for the XT disk (/dev/xdN)
502 0 = /dev/xda First XT disk whole disk 502 Deleted in kernel v3.9.
503 64 = /dev/xdb Second XT disk whole disk
504
505 Partitions are handled in the same way as IDE disks
506 (see major number 3).
507 503
508 14 char Open Sound System (OSS) 504 14 char Open Sound System (OSS)
509 0 = /dev/mixer Mixer control 505 0 = /dev/mixer Mixer control
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 6e3b18a8afc6..2fe6e767b3d6 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -3351,9 +3351,6 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
3351 plus one apbt timer for broadcast timer. 3351 plus one apbt timer for broadcast timer.
3352 x86_mrst_timer=apbt_only | lapic_and_apbt 3352 x86_mrst_timer=apbt_only | lapic_and_apbt
3353 3353
3354 xd= [HW,XT] Original XT pre-IDE (RLL encoded) disks.
3355 xd_geo= See header of drivers/block/xd.c.
3356
3357 xen_emul_unplug= [HW,X86,XEN] 3354 xen_emul_unplug= [HW,X86,XEN]
3358 Unplug Xen emulated devices 3355 Unplug Xen emulated devices
3359 Format: [unplug0,][unplug1] 3356 Format: [unplug0,][unplug1]
diff --git a/Documentation/m68k/kernel-options.txt b/Documentation/m68k/kernel-options.txt
index 97d45f276fe6..eaf32a1fd0b1 100644
--- a/Documentation/m68k/kernel-options.txt
+++ b/Documentation/m68k/kernel-options.txt
@@ -80,8 +80,6 @@ Valid names are:
80 /dev/sdd: -> 0x0830 (forth SCSI disk) 80 /dev/sdd: -> 0x0830 (forth SCSI disk)
81 /dev/sde: -> 0x0840 (fifth SCSI disk) 81 /dev/sde: -> 0x0840 (fifth SCSI disk)
82 /dev/fd : -> 0x0200 (floppy disk) 82 /dev/fd : -> 0x0200 (floppy disk)
83 /dev/xda: -> 0x0c00 (first XT disk, unused in Linux/m68k)
84 /dev/xdb: -> 0x0c40 (second XT disk, unused in Linux/m68k)
85 83
86 The name must be followed by a decimal number, that stands for the 84 The name must be followed by a decimal number, that stands for the
87partition number. Internally, the value of the number is just 85partition number. Internally, the value of the number is just
diff --git a/block/blk-core.c b/block/blk-core.c
index 33c33bc99ddd..d5745b5833c9 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -3164,7 +3164,7 @@ void blk_post_runtime_resume(struct request_queue *q, int err)
3164 q->rpm_status = RPM_ACTIVE; 3164 q->rpm_status = RPM_ACTIVE;
3165 __blk_run_queue(q); 3165 __blk_run_queue(q);
3166 pm_runtime_mark_last_busy(q->dev); 3166 pm_runtime_mark_last_busy(q->dev);
3167 pm_runtime_autosuspend(q->dev); 3167 pm_request_autosuspend(q->dev);
3168 } else { 3168 } else {
3169 q->rpm_status = RPM_SUSPENDED; 3169 q->rpm_status = RPM_SUSPENDED;
3170 } 3170 }
diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index 847107ef0cce..20dd52a2f92f 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -3002,7 +3002,8 @@ static int mtip_hw_debugfs_init(struct driver_data *dd)
3002 3002
3003static void mtip_hw_debugfs_exit(struct driver_data *dd) 3003static void mtip_hw_debugfs_exit(struct driver_data *dd)
3004{ 3004{
3005 debugfs_remove_recursive(dd->dfs_node); 3005 if (dd->dfs_node)
3006 debugfs_remove_recursive(dd->dfs_node);
3006} 3007}
3007 3008
3008 3009
@@ -3863,7 +3864,7 @@ static void mtip_make_request(struct request_queue *queue, struct bio *bio)
3863 struct driver_data *dd = queue->queuedata; 3864 struct driver_data *dd = queue->queuedata;
3864 struct scatterlist *sg; 3865 struct scatterlist *sg;
3865 struct bio_vec *bvec; 3866 struct bio_vec *bvec;
3866 int nents = 0; 3867 int i, nents = 0;
3867 int tag = 0, unaligned = 0; 3868 int tag = 0, unaligned = 0;
3868 3869
3869 if (unlikely(dd->dd_flag & MTIP_DDF_STOP_IO)) { 3870 if (unlikely(dd->dd_flag & MTIP_DDF_STOP_IO)) {
@@ -3921,11 +3922,12 @@ static void mtip_make_request(struct request_queue *queue, struct bio *bio)
3921 } 3922 }
3922 3923
3923 /* Create the scatter list for this bio. */ 3924 /* Create the scatter list for this bio. */
3924 bio_for_each_segment(bvec, bio, nents) { 3925 bio_for_each_segment(bvec, bio, i) {
3925 sg_set_page(&sg[nents], 3926 sg_set_page(&sg[nents],
3926 bvec->bv_page, 3927 bvec->bv_page,
3927 bvec->bv_len, 3928 bvec->bv_len,
3928 bvec->bv_offset); 3929 bvec->bv_offset);
3930 nents++;
3929 } 3931 }
3930 3932
3931 /* Issue the read/write. */ 3933 /* Issue the read/write. */
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 3c08983e600a..f5d0ea11d9fd 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -83,7 +83,8 @@
83 83
84#define MAX_SPEED 0xffff 84#define MAX_SPEED 0xffff
85 85
86#define ZONE(sector, pd) (((sector) + (pd)->offset) & ~((pd)->settings.size - 1)) 86#define ZONE(sector, pd) (((sector) + (pd)->offset) & \
87 ~(sector_t)((pd)->settings.size - 1))
87 88
88static DEFINE_MUTEX(pktcdvd_mutex); 89static DEFINE_MUTEX(pktcdvd_mutex);
89static struct pktcdvd_device *pkt_devs[MAX_WRITERS]; 90static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
diff --git a/drivers/md/bcache/Kconfig b/drivers/md/bcache/Kconfig
index 05c220d05e23..f950c9d29f3e 100644
--- a/drivers/md/bcache/Kconfig
+++ b/drivers/md/bcache/Kconfig
@@ -1,7 +1,6 @@
1 1
2config BCACHE 2config BCACHE
3 tristate "Block device as cache" 3 tristate "Block device as cache"
4 select CLOSURES
5 ---help--- 4 ---help---
6 Allows a block device to be used as cache for other devices; uses 5 Allows a block device to be used as cache for other devices; uses
7 a btree for indexing and the layout is optimized for SSDs. 6 a btree for indexing and the layout is optimized for SSDs.
diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
index 340146d7c17f..d3e15b42a4ab 100644
--- a/drivers/md/bcache/bcache.h
+++ b/drivers/md/bcache/bcache.h
@@ -1241,7 +1241,7 @@ void bch_cache_set_stop(struct cache_set *);
1241struct cache_set *bch_cache_set_alloc(struct cache_sb *); 1241struct cache_set *bch_cache_set_alloc(struct cache_sb *);
1242void bch_btree_cache_free(struct cache_set *); 1242void bch_btree_cache_free(struct cache_set *);
1243int bch_btree_cache_alloc(struct cache_set *); 1243int bch_btree_cache_alloc(struct cache_set *);
1244void bch_writeback_init_cached_dev(struct cached_dev *); 1244void bch_cached_dev_writeback_init(struct cached_dev *);
1245void bch_moving_init_cache_set(struct cache_set *); 1245void bch_moving_init_cache_set(struct cache_set *);
1246 1246
1247void bch_cache_allocator_exit(struct cache *ca); 1247void bch_cache_allocator_exit(struct cache *ca);
diff --git a/drivers/md/bcache/stats.c b/drivers/md/bcache/stats.c
index 64e679449c2a..b8730e714d69 100644
--- a/drivers/md/bcache/stats.c
+++ b/drivers/md/bcache/stats.c
@@ -93,24 +93,6 @@ static struct attribute *bch_stats_files[] = {
93}; 93};
94static KTYPE(bch_stats); 94static KTYPE(bch_stats);
95 95
96static void scale_accounting(unsigned long data);
97
98void bch_cache_accounting_init(struct cache_accounting *acc,
99 struct closure *parent)
100{
101 kobject_init(&acc->total.kobj, &bch_stats_ktype);
102 kobject_init(&acc->five_minute.kobj, &bch_stats_ktype);
103 kobject_init(&acc->hour.kobj, &bch_stats_ktype);
104 kobject_init(&acc->day.kobj, &bch_stats_ktype);
105
106 closure_init(&acc->cl, parent);
107 init_timer(&acc->timer);
108 acc->timer.expires = jiffies + accounting_delay;
109 acc->timer.data = (unsigned long) acc;
110 acc->timer.function = scale_accounting;
111 add_timer(&acc->timer);
112}
113
114int bch_cache_accounting_add_kobjs(struct cache_accounting *acc, 96int bch_cache_accounting_add_kobjs(struct cache_accounting *acc,
115 struct kobject *parent) 97 struct kobject *parent)
116{ 98{
@@ -244,3 +226,19 @@ void bch_mark_sectors_bypassed(struct search *s, int sectors)
244 atomic_add(sectors, &dc->accounting.collector.sectors_bypassed); 226 atomic_add(sectors, &dc->accounting.collector.sectors_bypassed);
245 atomic_add(sectors, &s->op.c->accounting.collector.sectors_bypassed); 227 atomic_add(sectors, &s->op.c->accounting.collector.sectors_bypassed);
246} 228}
229
230void bch_cache_accounting_init(struct cache_accounting *acc,
231 struct closure *parent)
232{
233 kobject_init(&acc->total.kobj, &bch_stats_ktype);
234 kobject_init(&acc->five_minute.kobj, &bch_stats_ktype);
235 kobject_init(&acc->hour.kobj, &bch_stats_ktype);
236 kobject_init(&acc->day.kobj, &bch_stats_ktype);
237
238 closure_init(&acc->cl, parent);
239 init_timer(&acc->timer);
240 acc->timer.expires = jiffies + accounting_delay;
241 acc->timer.data = (unsigned long) acc;
242 acc->timer.function = scale_accounting;
243 add_timer(&acc->timer);
244}
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index c8046bc4aa57..f88e2b653a3f 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -634,11 +634,10 @@ static int open_dev(struct block_device *b, fmode_t mode)
634 return 0; 634 return 0;
635} 635}
636 636
637static int release_dev(struct gendisk *b, fmode_t mode) 637static void release_dev(struct gendisk *b, fmode_t mode)
638{ 638{
639 struct bcache_device *d = b->private_data; 639 struct bcache_device *d = b->private_data;
640 closure_put(&d->cl); 640 closure_put(&d->cl);
641 return 0;
642} 641}
643 642
644static int ioctl_dev(struct block_device *b, fmode_t mode, 643static int ioctl_dev(struct block_device *b, fmode_t mode,
@@ -732,8 +731,7 @@ static void bcache_device_free(struct bcache_device *d)
732 731
733 if (d->c) 732 if (d->c)
734 bcache_device_detach(d); 733 bcache_device_detach(d);
735 734 if (d->disk && d->disk->flags & GENHD_FL_UP)
736 if (d->disk)
737 del_gendisk(d->disk); 735 del_gendisk(d->disk);
738 if (d->disk && d->disk->queue) 736 if (d->disk && d->disk->queue)
739 blk_cleanup_queue(d->disk->queue); 737 blk_cleanup_queue(d->disk->queue);
@@ -756,12 +754,9 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size)
756 if (!(d->bio_split = bioset_create(4, offsetof(struct bbio, bio))) || 754 if (!(d->bio_split = bioset_create(4, offsetof(struct bbio, bio))) ||
757 !(d->unaligned_bvec = mempool_create_kmalloc_pool(1, 755 !(d->unaligned_bvec = mempool_create_kmalloc_pool(1,
758 sizeof(struct bio_vec) * BIO_MAX_PAGES)) || 756 sizeof(struct bio_vec) * BIO_MAX_PAGES)) ||
759 bio_split_pool_init(&d->bio_split_hook)) 757 bio_split_pool_init(&d->bio_split_hook) ||
760 758 !(d->disk = alloc_disk(1)) ||
761 return -ENOMEM; 759 !(q = blk_alloc_queue(GFP_KERNEL)))
762
763 d->disk = alloc_disk(1);
764 if (!d->disk)
765 return -ENOMEM; 760 return -ENOMEM;
766 761
767 snprintf(d->disk->disk_name, DISK_NAME_LEN, "bcache%i", bcache_minor); 762 snprintf(d->disk->disk_name, DISK_NAME_LEN, "bcache%i", bcache_minor);
@@ -771,10 +766,6 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size)
771 d->disk->fops = &bcache_ops; 766 d->disk->fops = &bcache_ops;
772 d->disk->private_data = d; 767 d->disk->private_data = d;
773 768
774 q = blk_alloc_queue(GFP_KERNEL);
775 if (!q)
776 return -ENOMEM;
777
778 blk_queue_make_request(q, NULL); 769 blk_queue_make_request(q, NULL);
779 d->disk->queue = q; 770 d->disk->queue = q;
780 q->queuedata = d; 771 q->queuedata = d;
@@ -999,14 +990,17 @@ static void cached_dev_free(struct closure *cl)
999 990
1000 mutex_lock(&bch_register_lock); 991 mutex_lock(&bch_register_lock);
1001 992
1002 bd_unlink_disk_holder(dc->bdev, dc->disk.disk); 993 if (atomic_read(&dc->running))
994 bd_unlink_disk_holder(dc->bdev, dc->disk.disk);
1003 bcache_device_free(&dc->disk); 995 bcache_device_free(&dc->disk);
1004 list_del(&dc->list); 996 list_del(&dc->list);
1005 997
1006 mutex_unlock(&bch_register_lock); 998 mutex_unlock(&bch_register_lock);
1007 999
1008 if (!IS_ERR_OR_NULL(dc->bdev)) { 1000 if (!IS_ERR_OR_NULL(dc->bdev)) {
1009 blk_sync_queue(bdev_get_queue(dc->bdev)); 1001 if (dc->bdev->bd_disk)
1002 blk_sync_queue(bdev_get_queue(dc->bdev));
1003
1010 blkdev_put(dc->bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL); 1004 blkdev_put(dc->bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
1011 } 1005 }
1012 1006
@@ -1028,73 +1022,67 @@ static void cached_dev_flush(struct closure *cl)
1028 1022
1029static int cached_dev_init(struct cached_dev *dc, unsigned block_size) 1023static int cached_dev_init(struct cached_dev *dc, unsigned block_size)
1030{ 1024{
1031 int err; 1025 int ret;
1032 struct io *io; 1026 struct io *io;
1033 1027 struct request_queue *q = bdev_get_queue(dc->bdev);
1034 closure_init(&dc->disk.cl, NULL);
1035 set_closure_fn(&dc->disk.cl, cached_dev_flush, system_wq);
1036 1028
1037 __module_get(THIS_MODULE); 1029 __module_get(THIS_MODULE);
1038 INIT_LIST_HEAD(&dc->list); 1030 INIT_LIST_HEAD(&dc->list);
1031 closure_init(&dc->disk.cl, NULL);
1032 set_closure_fn(&dc->disk.cl, cached_dev_flush, system_wq);
1039 kobject_init(&dc->disk.kobj, &bch_cached_dev_ktype); 1033 kobject_init(&dc->disk.kobj, &bch_cached_dev_ktype);
1040
1041 bch_cache_accounting_init(&dc->accounting, &dc->disk.cl);
1042
1043 err = bcache_device_init(&dc->disk, block_size);
1044 if (err)
1045 goto err;
1046
1047 spin_lock_init(&dc->io_lock);
1048 closure_init_unlocked(&dc->sb_write);
1049 INIT_WORK(&dc->detach, cached_dev_detach_finish); 1034 INIT_WORK(&dc->detach, cached_dev_detach_finish);
1035 closure_init_unlocked(&dc->sb_write);
1036 INIT_LIST_HEAD(&dc->io_lru);
1037 spin_lock_init(&dc->io_lock);
1038 bch_cache_accounting_init(&dc->accounting, &dc->disk.cl);
1050 1039
1051 dc->sequential_merge = true; 1040 dc->sequential_merge = true;
1052 dc->sequential_cutoff = 4 << 20; 1041 dc->sequential_cutoff = 4 << 20;
1053 1042
1054 INIT_LIST_HEAD(&dc->io_lru);
1055 dc->sb_bio.bi_max_vecs = 1;
1056 dc->sb_bio.bi_io_vec = dc->sb_bio.bi_inline_vecs;
1057
1058 for (io = dc->io; io < dc->io + RECENT_IO; io++) { 1043 for (io = dc->io; io < dc->io + RECENT_IO; io++) {
1059 list_add(&io->lru, &dc->io_lru); 1044 list_add(&io->lru, &dc->io_lru);
1060 hlist_add_head(&io->hash, dc->io_hash + RECENT_IO); 1045 hlist_add_head(&io->hash, dc->io_hash + RECENT_IO);
1061 } 1046 }
1062 1047
1063 bch_writeback_init_cached_dev(dc); 1048 ret = bcache_device_init(&dc->disk, block_size);
1049 if (ret)
1050 return ret;
1051
1052 set_capacity(dc->disk.disk,
1053 dc->bdev->bd_part->nr_sects - dc->sb.data_offset);
1054
1055 dc->disk.disk->queue->backing_dev_info.ra_pages =
1056 max(dc->disk.disk->queue->backing_dev_info.ra_pages,
1057 q->backing_dev_info.ra_pages);
1058
1059 bch_cached_dev_request_init(dc);
1060 bch_cached_dev_writeback_init(dc);
1064 return 0; 1061 return 0;
1065err:
1066 bcache_device_stop(&dc->disk);
1067 return err;
1068} 1062}
1069 1063
1070/* Cached device - bcache superblock */ 1064/* Cached device - bcache superblock */
1071 1065
1072static const char *register_bdev(struct cache_sb *sb, struct page *sb_page, 1066static void register_bdev(struct cache_sb *sb, struct page *sb_page,
1073 struct block_device *bdev, 1067 struct block_device *bdev,
1074 struct cached_dev *dc) 1068 struct cached_dev *dc)
1075{ 1069{
1076 char name[BDEVNAME_SIZE]; 1070 char name[BDEVNAME_SIZE];
1077 const char *err = "cannot allocate memory"; 1071 const char *err = "cannot allocate memory";
1078 struct gendisk *g;
1079 struct cache_set *c; 1072 struct cache_set *c;
1080 1073
1081 if (!dc || cached_dev_init(dc, sb->block_size << 9) != 0)
1082 return err;
1083
1084 memcpy(&dc->sb, sb, sizeof(struct cache_sb)); 1074 memcpy(&dc->sb, sb, sizeof(struct cache_sb));
1085 dc->sb_bio.bi_io_vec[0].bv_page = sb_page;
1086 dc->bdev = bdev; 1075 dc->bdev = bdev;
1087 dc->bdev->bd_holder = dc; 1076 dc->bdev->bd_holder = dc;
1088 1077
1089 g = dc->disk.disk; 1078 bio_init(&dc->sb_bio);
1090 1079 dc->sb_bio.bi_max_vecs = 1;
1091 set_capacity(g, dc->bdev->bd_part->nr_sects - dc->sb.data_offset); 1080 dc->sb_bio.bi_io_vec = dc->sb_bio.bi_inline_vecs;
1092 1081 dc->sb_bio.bi_io_vec[0].bv_page = sb_page;
1093 g->queue->backing_dev_info.ra_pages = 1082 get_page(sb_page);
1094 max(g->queue->backing_dev_info.ra_pages,
1095 bdev->bd_queue->backing_dev_info.ra_pages);
1096 1083
1097 bch_cached_dev_request_init(dc); 1084 if (cached_dev_init(dc, sb->block_size << 9))
1085 goto err;
1098 1086
1099 err = "error creating kobject"; 1087 err = "error creating kobject";
1100 if (kobject_add(&dc->disk.kobj, &part_to_dev(bdev->bd_part)->kobj, 1088 if (kobject_add(&dc->disk.kobj, &part_to_dev(bdev->bd_part)->kobj,
@@ -1103,6 +1091,8 @@ static const char *register_bdev(struct cache_sb *sb, struct page *sb_page,
1103 if (bch_cache_accounting_add_kobjs(&dc->accounting, &dc->disk.kobj)) 1091 if (bch_cache_accounting_add_kobjs(&dc->accounting, &dc->disk.kobj))
1104 goto err; 1092 goto err;
1105 1093
1094 pr_info("registered backing device %s", bdevname(bdev, name));
1095
1106 list_add(&dc->list, &uncached_devices); 1096 list_add(&dc->list, &uncached_devices);
1107 list_for_each_entry(c, &bch_cache_sets, list) 1097 list_for_each_entry(c, &bch_cache_sets, list)
1108 bch_cached_dev_attach(dc, c); 1098 bch_cached_dev_attach(dc, c);
@@ -1111,15 +1101,10 @@ static const char *register_bdev(struct cache_sb *sb, struct page *sb_page,
1111 BDEV_STATE(&dc->sb) == BDEV_STATE_STALE) 1101 BDEV_STATE(&dc->sb) == BDEV_STATE_STALE)
1112 bch_cached_dev_run(dc); 1102 bch_cached_dev_run(dc);
1113 1103
1114 return NULL; 1104 return;
1115err: 1105err:
1116 kobject_put(&dc->disk.kobj);
1117 pr_notice("error opening %s: %s", bdevname(bdev, name), err); 1106 pr_notice("error opening %s: %s", bdevname(bdev, name), err);
1118 /* 1107 bcache_device_stop(&dc->disk);
1119 * Return NULL instead of an error because kobject_put() cleans
1120 * everything up
1121 */
1122 return NULL;
1123} 1108}
1124 1109
1125/* Flash only volumes */ 1110/* Flash only volumes */
@@ -1717,20 +1702,11 @@ static int cache_alloc(struct cache_sb *sb, struct cache *ca)
1717 size_t free; 1702 size_t free;
1718 struct bucket *b; 1703 struct bucket *b;
1719 1704
1720 if (!ca)
1721 return -ENOMEM;
1722
1723 __module_get(THIS_MODULE); 1705 __module_get(THIS_MODULE);
1724 kobject_init(&ca->kobj, &bch_cache_ktype); 1706 kobject_init(&ca->kobj, &bch_cache_ktype);
1725 1707
1726 memcpy(&ca->sb, sb, sizeof(struct cache_sb));
1727
1728 INIT_LIST_HEAD(&ca->discards); 1708 INIT_LIST_HEAD(&ca->discards);
1729 1709
1730 bio_init(&ca->sb_bio);
1731 ca->sb_bio.bi_max_vecs = 1;
1732 ca->sb_bio.bi_io_vec = ca->sb_bio.bi_inline_vecs;
1733
1734 bio_init(&ca->journal.bio); 1710 bio_init(&ca->journal.bio);
1735 ca->journal.bio.bi_max_vecs = 8; 1711 ca->journal.bio.bi_max_vecs = 8;
1736 ca->journal.bio.bi_io_vec = ca->journal.bio.bi_inline_vecs; 1712 ca->journal.bio.bi_io_vec = ca->journal.bio.bi_inline_vecs;
@@ -1742,18 +1718,17 @@ static int cache_alloc(struct cache_sb *sb, struct cache *ca)
1742 !init_fifo(&ca->free_inc, free << 2, GFP_KERNEL) || 1718 !init_fifo(&ca->free_inc, free << 2, GFP_KERNEL) ||
1743 !init_fifo(&ca->unused, free << 2, GFP_KERNEL) || 1719 !init_fifo(&ca->unused, free << 2, GFP_KERNEL) ||
1744 !init_heap(&ca->heap, free << 3, GFP_KERNEL) || 1720 !init_heap(&ca->heap, free << 3, GFP_KERNEL) ||
1745 !(ca->buckets = vmalloc(sizeof(struct bucket) * 1721 !(ca->buckets = vzalloc(sizeof(struct bucket) *
1746 ca->sb.nbuckets)) || 1722 ca->sb.nbuckets)) ||
1747 !(ca->prio_buckets = kzalloc(sizeof(uint64_t) * prio_buckets(ca) * 1723 !(ca->prio_buckets = kzalloc(sizeof(uint64_t) * prio_buckets(ca) *
1748 2, GFP_KERNEL)) || 1724 2, GFP_KERNEL)) ||
1749 !(ca->disk_buckets = alloc_bucket_pages(GFP_KERNEL, ca)) || 1725 !(ca->disk_buckets = alloc_bucket_pages(GFP_KERNEL, ca)) ||
1750 !(ca->alloc_workqueue = alloc_workqueue("bch_allocator", 0, 1)) || 1726 !(ca->alloc_workqueue = alloc_workqueue("bch_allocator", 0, 1)) ||
1751 bio_split_pool_init(&ca->bio_split_hook)) 1727 bio_split_pool_init(&ca->bio_split_hook))
1752 goto err; 1728 return -ENOMEM;
1753 1729
1754 ca->prio_last_buckets = ca->prio_buckets + prio_buckets(ca); 1730 ca->prio_last_buckets = ca->prio_buckets + prio_buckets(ca);
1755 1731
1756 memset(ca->buckets, 0, ca->sb.nbuckets * sizeof(struct bucket));
1757 for_each_bucket(b, ca) 1732 for_each_bucket(b, ca)
1758 atomic_set(&b->pin, 0); 1733 atomic_set(&b->pin, 0);
1759 1734
@@ -1766,22 +1741,28 @@ err:
1766 return -ENOMEM; 1741 return -ENOMEM;
1767} 1742}
1768 1743
1769static const char *register_cache(struct cache_sb *sb, struct page *sb_page, 1744static void register_cache(struct cache_sb *sb, struct page *sb_page,
1770 struct block_device *bdev, struct cache *ca) 1745 struct block_device *bdev, struct cache *ca)
1771{ 1746{
1772 char name[BDEVNAME_SIZE]; 1747 char name[BDEVNAME_SIZE];
1773 const char *err = "cannot allocate memory"; 1748 const char *err = "cannot allocate memory";
1774 1749
1775 if (cache_alloc(sb, ca) != 0) 1750 memcpy(&ca->sb, sb, sizeof(struct cache_sb));
1776 return err;
1777
1778 ca->sb_bio.bi_io_vec[0].bv_page = sb_page;
1779 ca->bdev = bdev; 1751 ca->bdev = bdev;
1780 ca->bdev->bd_holder = ca; 1752 ca->bdev->bd_holder = ca;
1781 1753
1754 bio_init(&ca->sb_bio);
1755 ca->sb_bio.bi_max_vecs = 1;
1756 ca->sb_bio.bi_io_vec = ca->sb_bio.bi_inline_vecs;
1757 ca->sb_bio.bi_io_vec[0].bv_page = sb_page;
1758 get_page(sb_page);
1759
1782 if (blk_queue_discard(bdev_get_queue(ca->bdev))) 1760 if (blk_queue_discard(bdev_get_queue(ca->bdev)))
1783 ca->discard = CACHE_DISCARD(&ca->sb); 1761 ca->discard = CACHE_DISCARD(&ca->sb);
1784 1762
1763 if (cache_alloc(sb, ca) != 0)
1764 goto err;
1765
1785 err = "error creating kobject"; 1766 err = "error creating kobject";
1786 if (kobject_add(&ca->kobj, &part_to_dev(bdev->bd_part)->kobj, "bcache")) 1767 if (kobject_add(&ca->kobj, &part_to_dev(bdev->bd_part)->kobj, "bcache"))
1787 goto err; 1768 goto err;
@@ -1791,15 +1772,10 @@ static const char *register_cache(struct cache_sb *sb, struct page *sb_page,
1791 goto err; 1772 goto err;
1792 1773
1793 pr_info("registered cache device %s", bdevname(bdev, name)); 1774 pr_info("registered cache device %s", bdevname(bdev, name));
1794 1775 return;
1795 return NULL;
1796err: 1776err:
1777 pr_notice("error opening %s: %s", bdevname(bdev, name), err);
1797 kobject_put(&ca->kobj); 1778 kobject_put(&ca->kobj);
1798 pr_info("error opening %s: %s", bdevname(bdev, name), err);
1799 /* Return NULL instead of an error because kobject_put() cleans
1800 * everything up
1801 */
1802 return NULL;
1803} 1779}
1804 1780
1805/* Global interfaces/init */ 1781/* Global interfaces/init */
@@ -1833,12 +1809,15 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
1833 bdev = blkdev_get_by_path(strim(path), 1809 bdev = blkdev_get_by_path(strim(path),
1834 FMODE_READ|FMODE_WRITE|FMODE_EXCL, 1810 FMODE_READ|FMODE_WRITE|FMODE_EXCL,
1835 sb); 1811 sb);
1836 if (bdev == ERR_PTR(-EBUSY)) 1812 if (IS_ERR(bdev)) {
1837 err = "device busy"; 1813 if (bdev == ERR_PTR(-EBUSY))
1838 1814 err = "device busy";
1839 if (IS_ERR(bdev) ||
1840 set_blocksize(bdev, 4096))
1841 goto err; 1815 goto err;
1816 }
1817
1818 err = "failed to set blocksize";
1819 if (set_blocksize(bdev, 4096))
1820 goto err_close;
1842 1821
1843 err = read_super(sb, bdev, &sb_page); 1822 err = read_super(sb, bdev, &sb_page);
1844 if (err) 1823 if (err)
@@ -1846,33 +1825,33 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
1846 1825
1847 if (SB_IS_BDEV(sb)) { 1826 if (SB_IS_BDEV(sb)) {
1848 struct cached_dev *dc = kzalloc(sizeof(*dc), GFP_KERNEL); 1827 struct cached_dev *dc = kzalloc(sizeof(*dc), GFP_KERNEL);
1828 if (!dc)
1829 goto err_close;
1849 1830
1850 err = register_bdev(sb, sb_page, bdev, dc); 1831 register_bdev(sb, sb_page, bdev, dc);
1851 } else { 1832 } else {
1852 struct cache *ca = kzalloc(sizeof(*ca), GFP_KERNEL); 1833 struct cache *ca = kzalloc(sizeof(*ca), GFP_KERNEL);
1834 if (!ca)
1835 goto err_close;
1853 1836
1854 err = register_cache(sb, sb_page, bdev, ca); 1837 register_cache(sb, sb_page, bdev, ca);
1855 } 1838 }
1856 1839out:
1857 if (err) { 1840 if (sb_page)
1858 /* register_(bdev|cache) will only return an error if they
1859 * didn't get far enough to create the kobject - if they did,
1860 * the kobject destructor will do this cleanup.
1861 */
1862 put_page(sb_page); 1841 put_page(sb_page);
1863err_close:
1864 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
1865err:
1866 if (attr != &ksysfs_register_quiet)
1867 pr_info("error opening %s: %s", path, err);
1868 ret = -EINVAL;
1869 }
1870
1871 kfree(sb); 1842 kfree(sb);
1872 kfree(path); 1843 kfree(path);
1873 mutex_unlock(&bch_register_lock); 1844 mutex_unlock(&bch_register_lock);
1874 module_put(THIS_MODULE); 1845 module_put(THIS_MODULE);
1875 return ret; 1846 return ret;
1847
1848err_close:
1849 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
1850err:
1851 if (attr != &ksysfs_register_quiet)
1852 pr_info("error opening %s: %s", path, err);
1853 ret = -EINVAL;
1854 goto out;
1876} 1855}
1877 1856
1878static int bcache_reboot(struct notifier_block *n, unsigned long code, void *x) 1857static int bcache_reboot(struct notifier_block *n, unsigned long code, void *x)
diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c
index 93e7e31a4bd3..2714ed3991d1 100644
--- a/drivers/md/bcache/writeback.c
+++ b/drivers/md/bcache/writeback.c
@@ -375,7 +375,7 @@ err:
375 refill_dirty(cl); 375 refill_dirty(cl);
376} 376}
377 377
378void bch_writeback_init_cached_dev(struct cached_dev *dc) 378void bch_cached_dev_writeback_init(struct cached_dev *dc)
379{ 379{
380 closure_init_unlocked(&dc->writeback); 380 closure_init_unlocked(&dc->writeback);
381 init_rwsem(&dc->writeback_lock); 381 init_rwsem(&dc->writeback_lock);
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 9359828ffe26..753f318c8984 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -664,6 +664,7 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
664 if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags)) 664 if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
665 bi->bi_rw |= REQ_FLUSH; 665 bi->bi_rw |= REQ_FLUSH;
666 666
667 bi->bi_vcnt = 1;
667 bi->bi_io_vec[0].bv_len = STRIPE_SIZE; 668 bi->bi_io_vec[0].bv_len = STRIPE_SIZE;
668 bi->bi_io_vec[0].bv_offset = 0; 669 bi->bi_io_vec[0].bv_offset = 0;
669 bi->bi_size = STRIPE_SIZE; 670 bi->bi_size = STRIPE_SIZE;
@@ -701,6 +702,7 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
701 else 702 else
702 rbi->bi_sector = (sh->sector 703 rbi->bi_sector = (sh->sector
703 + rrdev->data_offset); 704 + rrdev->data_offset);
705 rbi->bi_vcnt = 1;
704 rbi->bi_io_vec[0].bv_len = STRIPE_SIZE; 706 rbi->bi_io_vec[0].bv_len = STRIPE_SIZE;
705 rbi->bi_io_vec[0].bv_offset = 0; 707 rbi->bi_io_vec[0].bv_offset = 0;
706 rbi->bi_size = STRIPE_SIZE; 708 rbi->bi_size = STRIPE_SIZE;
diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
index 5951e3f38878..26806775b11b 100644
--- a/include/linux/scatterlist.h
+++ b/include/linux/scatterlist.h
@@ -111,6 +111,9 @@ static inline struct page *sg_page(struct scatterlist *sg)
111static inline void sg_set_buf(struct scatterlist *sg, const void *buf, 111static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
112 unsigned int buflen) 112 unsigned int buflen)
113{ 113{
114#ifdef CONFIG_DEBUG_SG
115 BUG_ON(!virt_addr_valid(buf));
116#endif
114 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf)); 117 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
115} 118}
116 119