diff options
-rw-r--r-- | drivers/md/bcache/bkey.h | 9 | ||||
-rw-r--r-- | drivers/md/bcache/blockdev.c | 88 | ||||
-rw-r--r-- | drivers/md/bcache/blockdev.h | 21 | ||||
-rw-r--r-- | drivers/md/bcache/inode.c | 6 | ||||
-rw-r--r-- | drivers/md/bcache/inode.h | 4 | ||||
-rw-r--r-- | drivers/md/bcache/request.c | 24 | ||||
-rw-r--r-- | drivers/md/bcache/request.h | 2 | ||||
-rw-r--r-- | drivers/md/bcache/super.c | 34 | ||||
-rw-r--r-- | drivers/md/bcache/sysfs.c | 22 | ||||
-rw-r--r-- | drivers/md/bcache/writeback.c | 2 | ||||
-rw-r--r-- | include/uapi/linux/bcache.h | 4 |
11 files changed, 118 insertions, 98 deletions
diff --git a/drivers/md/bcache/bkey.h b/drivers/md/bcache/bkey.h index cc662084d3e8..408f98abd294 100644 --- a/drivers/md/bcache/bkey.h +++ b/drivers/md/bcache/bkey.h @@ -494,7 +494,14 @@ static inline void __bch_extent_assert(u8 type, u8 nr) __BKEY_VAL_ACCESSORS(extent, BCH_EXTENT, __bch_extent_assert); BKEY_VAL_ACCESSORS(inode, BCH_INODE_FS); -BKEY_VAL_ACCESSORS(inode_blockdev, BCH_INODE_BLOCKDEV); + +static inline void __bch_inode_blockdev_assert(u8 type, u8 nr) +{ + EBUG_ON(type != BCH_INODE_BLOCKDEV && type != BCH_INODE_CACHED_DEV); +} + +__BKEY_VAL_ACCESSORS(inode_blockdev, BCH_INODE_BLOCKDEV, + __bch_inode_blockdev_assert); BKEY_VAL_ACCESSORS(dirent, BCH_DIRENT); diff --git a/drivers/md/bcache/blockdev.c b/drivers/md/bcache/blockdev.c index 4faecf99805a..0723e509a65e 100644 --- a/drivers/md/bcache/blockdev.c +++ b/drivers/md/bcache/blockdev.c @@ -13,7 +13,7 @@ static int bch_blockdev_major; static DEFINE_IDA(bch_blockdev_minor); -LIST_HEAD(uncached_devices); +static LIST_HEAD(uncached_devices); struct kmem_cache *bch_search_cache; static void write_bdev_super_endio(struct bio *bio) @@ -49,7 +49,7 @@ void bch_write_bdev_super(struct cached_dev *dc, struct closure *parent) closure_return_with_destructor(cl, bch_write_bdev_super_unlock); } -bool bch_is_open_backing(struct block_device *bdev) +bool bch_is_open_backing_dev(struct block_device *bdev) { struct cache_set *c, *tc; struct cached_dev *dc, *t; @@ -97,7 +97,7 @@ static const struct block_device_operations bcache_ops = { .owner = THIS_MODULE, }; -void bcache_device_stop(struct bcache_device *d) +void bch_blockdev_stop(struct bcache_device *d) { if (!test_and_set_bit(BCACHE_DEV_CLOSING, &d->flags)) closure_queue(&d->cl); @@ -389,7 +389,7 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c) return -EINVAL; } - found = !bch_blockdev_inode_find_by_uuid(c, &dc->sb.disk_uuid, + found = !bch_cached_dev_inode_find_by_uuid(c, &dc->sb.disk_uuid, &dc->disk.inode); if (!found && BDEV_STATE(&dc->sb) == BDEV_STATE_DIRTY) { @@ -410,6 +410,7 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c) if (!found) { bkey_inode_blockdev_init(&dc->disk.inode.k_i); + dc->disk.inode.k.type = BCH_INODE_CACHED_DEV; dc->disk.inode.v.i_uuid = dc->sb.disk_uuid; memcpy(dc->disk.inode.v.i_label, dc->sb.label, SB_LABEL_SIZE); dc->disk.inode.v.i_inode.i_ctime = rtime; @@ -471,6 +472,16 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c) return 0; } +void bch_attach_backing_devs(struct cache_set *c) +{ + struct cached_dev *dc, *t; + + lockdep_assert_held(&bch_register_lock); + + list_for_each_entry_safe(dc, t, &uncached_devices, list) + bch_cached_dev_attach(dc, c); +} + void bch_cached_dev_release(struct kobject *kobj) { struct cached_dev *dc = container_of(kobj, struct cached_dev, @@ -554,7 +565,7 @@ static int cached_dev_init(struct cached_dev *dc, unsigned block_size) /* Cached device - bcache superblock */ -const char *bch_register_bdev(struct bcache_superblock *sb) +const char *bch_backing_dev_register(struct bcache_superblock *sb) { char name[BDEVNAME_SIZE]; const char *err; @@ -613,20 +624,20 @@ const char *bch_register_bdev(struct bcache_superblock *sb) mutex_unlock(&bch_register_lock); return NULL; err: - bcache_device_stop(&dc->disk); + bch_blockdev_stop(&dc->disk); return err; } /* Flash only volumes */ -void bch_flash_dev_release(struct kobject *kobj) +void bch_blockdev_volume_release(struct kobject *kobj) { struct bcache_device *d = container_of(kobj, struct bcache_device, kobj); kfree(d); } -static void flash_dev_free(struct closure *cl) +static void blockdev_volume_free(struct closure *cl) { struct bcache_device *d = container_of(cl, struct bcache_device, cl); @@ -636,7 +647,7 @@ static void flash_dev_free(struct closure *cl) kobject_put(&d->kobj); } -static void flash_dev_flush(struct closure *cl) +static void blockdev_volume_flush(struct closure *cl) { struct bcache_device *d = container_of(cl, struct bcache_device, cl); @@ -644,11 +655,11 @@ static void flash_dev_flush(struct closure *cl) bcache_device_unlink(d); mutex_unlock(&bch_register_lock); kobject_del(&d->kobj); - continue_at(cl, flash_dev_free, system_wq); + continue_at(cl, blockdev_volume_free, system_wq); } -static int flash_dev_run(struct cache_set *c, - struct bkey_s_c_inode_blockdev inode) +static int blockdev_volume_run(struct cache_set *c, + struct bkey_s_c_inode_blockdev inode) { struct bcache_device *d = kzalloc(sizeof(struct bcache_device), GFP_KERNEL); @@ -660,9 +671,9 @@ static int flash_dev_run(struct cache_set *c, bkey_reassemble(&d->inode.k_i, inode.s_c); closure_init(&d->cl, NULL); - set_closure_fn(&d->cl, flash_dev_flush, system_wq); + set_closure_fn(&d->cl, blockdev_volume_flush, system_wq); - kobject_init(&d->kobj, &bch_flash_dev_ktype); + kobject_init(&d->kobj, &bch_blockdev_volume_ktype); ret = bcache_device_init(d, block_bytes(c), inode.v->i_inode.i_size >> 9); @@ -673,7 +684,7 @@ static int flash_dev_run(struct cache_set *c, if (ret) goto err; - bch_flash_dev_request_init(d); + bch_blockdev_volume_request_init(d); add_disk(d->disk); if (kobject_add(&d->kobj, &disk_to_dev(d->disk)->kobj, "bcache")) @@ -687,7 +698,7 @@ err: return ret; } -int flash_devs_run(struct cache_set *c) +int bch_blockdev_volumes_start(struct cache_set *c) { struct btree_iter iter; struct bkey_s_c k; @@ -706,14 +717,12 @@ int flash_devs_run(struct cache_set *c) inode = bkey_s_c_to_inode_blockdev(k); - if (INODE_FLASH_ONLY(inode.v)) { - ret = flash_dev_run(c, inode); - if (ret) { - bch_cache_set_error(c, - "can't bring up flash volumes: %i", - ret); - break; - } + ret = blockdev_volume_run(c, inode); + if (ret) { + bch_cache_set_error(c, + "can't bring up blockdev volumes: %i", + ret); + break; } } bch_btree_iter_unlock(&iter); @@ -721,7 +730,7 @@ int flash_devs_run(struct cache_set *c) return ret; } -int bch_flash_dev_create(struct cache_set *c, u64 size) +int bch_blockdev_volume_create(struct cache_set *c, u64 size) { struct timespec ts = CURRENT_TIME; s64 rtime = timespec_to_ns(&ts); @@ -733,7 +742,6 @@ int bch_flash_dev_create(struct cache_set *c, u64 size) inode.v.i_inode.i_ctime = rtime; inode.v.i_inode.i_mtime = rtime; inode.v.i_inode.i_size = size; - SET_INODE_FLASH_ONLY(&inode.v, 1); ret = bch_inode_create(c, &inode.k_i, 0, BLOCKDEV_INODE_MAX, &c->unused_inode_hint); @@ -742,7 +750,33 @@ int bch_flash_dev_create(struct cache_set *c, u64 size) return ret; } - return flash_dev_run(c, inode_blockdev_i_to_s_c(&inode)); + return blockdev_volume_run(c, inode_blockdev_i_to_s_c(&inode)); +} + +void bch_blockdevs_stop(struct cache_set *c) +{ + struct cached_dev *dc; + struct bcache_device *d; + struct radix_tree_iter iter; + void **slot; + + mutex_lock(&bch_register_lock); + rcu_read_lock(); + + radix_tree_for_each_slot(slot, &c->devices, &iter, 0) { + d = radix_tree_deref_slot(slot); + + if (d->inode.k.type == BCH_INODE_CACHED_DEV && + test_bit(CACHE_SET_UNREGISTERING, &c->flags)) { + dc = container_of(d, struct cached_dev, disk); + bch_cached_dev_detach(dc); + } else { + bch_blockdev_stop(d); + } + } + + rcu_read_unlock(); + mutex_unlock(&bch_register_lock); } void bch_blockdev_exit(void) diff --git a/drivers/md/bcache/blockdev.h b/drivers/md/bcache/blockdev.h index a4be96bd0eb6..5b0c3aa950f6 100644 --- a/drivers/md/bcache/blockdev.h +++ b/drivers/md/bcache/blockdev.h @@ -8,23 +8,26 @@ void bch_write_bdev_super(struct cached_dev *, struct closure *); void bch_cached_dev_release(struct kobject *); -void bch_flash_dev_release(struct kobject *); +void bch_blockdev_volume_release(struct kobject *); int bch_cached_dev_attach(struct cached_dev *, struct cache_set *); +void bch_attach_backing_devs(struct cache_set *); + void bch_cached_dev_detach(struct cached_dev *); void bch_cached_dev_run(struct cached_dev *); -void bcache_device_stop(struct bcache_device *); +void bch_blockdev_stop(struct bcache_device *); + +bool bch_is_open_backing_dev(struct block_device *); +const char *bch_backing_dev_register(struct bcache_superblock *); -bool bch_is_open_backing(struct block_device *); -const char *bch_register_bdev(struct bcache_superblock *); -int flash_devs_run(struct cache_set *); -int bch_flash_dev_create(struct cache_set *, u64); +int bch_blockdev_volume_create(struct cache_set *, u64); +int bch_blockdev_volumes_start(struct cache_set *); + +void bch_blockdevs_stop(struct cache_set *); void bch_blockdev_exit(void); int bch_blockdev_init(void); -extern struct list_head uncached_devices; - static inline void cached_dev_put(struct cached_dev *dc) { if (atomic_dec_and_test(&dc->count)) @@ -89,6 +92,6 @@ struct search { extern struct kmem_cache *bch_search_cache; extern struct kobj_type bch_cached_dev_ktype; -extern struct kobj_type bch_flash_dev_ktype; +extern struct kobj_type bch_blockdev_volume_ktype; #endif /* _BCACHE_BLOCKDEV_H */ diff --git a/drivers/md/bcache/inode.c b/drivers/md/bcache/inode.c index ba6863ec5d01..fa6064cb96d7 100644 --- a/drivers/md/bcache/inode.c +++ b/drivers/md/bcache/inode.c @@ -225,8 +225,8 @@ int bch_inode_find_by_inum(struct cache_set *c, u64 inode_nr, return ret; } -int bch_blockdev_inode_find_by_uuid(struct cache_set *c, uuid_le *uuid, - struct bkey_i_inode_blockdev *ret) +int bch_cached_dev_inode_find_by_uuid(struct cache_set *c, uuid_le *uuid, + struct bkey_i_inode_blockdev *ret) { struct btree_iter iter; struct bkey_s_c k; @@ -235,7 +235,7 @@ int bch_blockdev_inode_find_by_uuid(struct cache_set *c, uuid_le *uuid, if (k.k->p.inode >= BLOCKDEV_INODE_MAX) break; - if (k.k->type == BCH_INODE_BLOCKDEV) { + if (k.k->type == BCH_INODE_CACHED_DEV) { struct bkey_s_c_inode_blockdev inode = bkey_s_c_to_inode_blockdev(k); diff --git a/drivers/md/bcache/inode.h b/drivers/md/bcache/inode.h index dc1c26f8240f..e2ca50afff2f 100644 --- a/drivers/md/bcache/inode.h +++ b/drivers/md/bcache/inode.h @@ -18,7 +18,7 @@ static inline int bch_inode_update(struct cache_set *c, struct bkey_i *inode, } int bch_inode_find_by_inum(struct cache_set *, u64, struct bkey_i_inode *); -int bch_blockdev_inode_find_by_uuid(struct cache_set *, uuid_le *, - struct bkey_i_inode_blockdev *); +int bch_cached_dev_inode_find_by_uuid(struct cache_set *, uuid_le *, + struct bkey_i_inode_blockdev *); #endif diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c index 167c2f185f0e..6538df0ea499 100644 --- a/drivers/md/bcache/request.c +++ b/drivers/md/bcache/request.c @@ -655,9 +655,10 @@ void bch_cached_dev_request_init(struct cached_dev *dc) dc->disk.ioctl = cached_dev_ioctl; } -/* Flash backed devices */ +/* Blockdev volumes */ -static void __flash_dev_make_request(struct request_queue *q, struct bio *bio) +static void __blockdev_volume_make_request(struct request_queue *q, + struct bio *bio) { struct search *s; struct bcache_device *d = bio->bi_bdev->bd_disk->private_data; @@ -700,19 +701,20 @@ static void __flash_dev_make_request(struct request_queue *q, struct bio *bio) } } -static blk_qc_t flash_dev_make_request(struct request_queue *q, struct bio *bio) +static blk_qc_t blockdev_volume_make_request(struct request_queue *q, + struct bio *bio) { - __flash_dev_make_request(q, bio); + __blockdev_volume_make_request(q, bio); return BLK_QC_T_NONE; } -static int flash_dev_ioctl(struct bcache_device *d, fmode_t mode, - unsigned int cmd, unsigned long arg) +static int blockdev_volume_ioctl(struct bcache_device *d, fmode_t mode, + unsigned int cmd, unsigned long arg) { return -ENOTTY; } -static int flash_dev_congested(void *data, int bits) +static int blockdev_volume_congested(void *data, int bits) { struct bcache_device *d = data; struct request_queue *q; @@ -728,11 +730,11 @@ static int flash_dev_congested(void *data, int bits) return ret; } -void bch_flash_dev_request_init(struct bcache_device *d) +void bch_blockdev_volume_request_init(struct bcache_device *d) { struct gendisk *g = d->disk; - g->queue->make_request_fn = flash_dev_make_request; - g->queue->backing_dev_info.congested_fn = flash_dev_congested; - d->ioctl = flash_dev_ioctl; + g->queue->make_request_fn = blockdev_volume_make_request; + g->queue->backing_dev_info.congested_fn = blockdev_volume_congested; + d->ioctl = blockdev_volume_ioctl; } diff --git a/drivers/md/bcache/request.h b/drivers/md/bcache/request.h index dc52abf47d52..cd3fe1225045 100644 --- a/drivers/md/bcache/request.h +++ b/drivers/md/bcache/request.h @@ -11,6 +11,6 @@ struct kmem_cache; unsigned bch_get_congested(struct cache_set *); void bch_cached_dev_request_init(struct cached_dev *dc); -void bch_flash_dev_request_init(struct bcache_device *d); +void bch_blockdev_volume_request_init(struct bcache_device *d); #endif /* _BCACHE_REQUEST_H_ */ diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index 4b0e4167e3c8..c274503df127 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -110,7 +110,7 @@ static bool bch_is_open(struct block_device *bdev) bool ret; mutex_lock(&bch_register_lock); - ret = bch_is_open_cache(bdev) || bch_is_open_backing(bdev); + ret = bch_is_open_cache(bdev) || bch_is_open_backing_dev(bdev); mutex_unlock(&bch_register_lock); return ret; @@ -907,30 +907,8 @@ static void cache_set_flush(struct closure *cl) static void __cache_set_unregister(struct closure *cl) { struct cache_set *c = container_of(cl, struct cache_set, caching); - struct cached_dev *dc; - struct bcache_device *d; - struct radix_tree_iter iter; - void **slot; - mutex_lock(&bch_register_lock); - - rcu_read_lock(); - - radix_tree_for_each_slot(slot, &c->devices, &iter, 0) { - d = radix_tree_deref_slot(slot); - - if (!INODE_FLASH_ONLY(&d->inode.v) && - test_bit(CACHE_SET_UNREGISTERING, &c->flags)) { - dc = container_of(d, struct cached_dev, disk); - bch_cached_dev_detach(dc); - } else { - bcache_device_stop(d); - } - } - - rcu_read_unlock(); - - mutex_unlock(&bch_register_lock); + bch_blockdevs_stop(c); continue_at(cl, cache_set_flush, system_wq); } @@ -1158,7 +1136,6 @@ static const char *run_cache_set(struct cache_set *c) { const char *err = "cannot allocate memory"; struct cache_member_rcu *mi; - struct cached_dev *dc, *t; struct cache *ca; struct closure cl; unsigned i, id; @@ -1342,7 +1319,7 @@ static const char *run_cache_set(struct cache_set *c) bcache_write_super(c); - flash_devs_run(c); + bch_blockdev_volumes_start(c); bch_debug_init_cache_set(c); @@ -1351,8 +1328,7 @@ static const char *run_cache_set(struct cache_set *c) goto err; set_bit(CACHE_SET_RUNNING, &c->flags); - list_for_each_entry_safe(dc, t, &uncached_devices, list) - bch_cached_dev_attach(dc, c); + bch_attach_backing_devs(c); closure_put(&c->caching); @@ -2245,7 +2221,7 @@ const char *bch_register_one(const char *path) if (__SB_IS_BDEV(le64_to_cpu(sb.sb->version))) { mutex_lock(&bch_register_lock); - err = bch_register_bdev(&sb); + err = bch_backing_dev_register(&sb); mutex_unlock(&bch_register_lock); } else { err = register_cache(&sb, cache_set_opts_empty()); diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c index 059e76268fd5..02a31295220b 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -68,7 +68,7 @@ write_attribute(stop); write_attribute(clear_stats); write_attribute(trigger_gc); write_attribute(prune_cache); -write_attribute(flash_vol_create); +write_attribute(blockdev_volume_create); write_attribute(add_device); read_attribute(uuid); @@ -339,7 +339,7 @@ STORE(__cached_dev) bch_cached_dev_detach(dc); if (attr == &sysfs_stop) - bcache_device_stop(&dc->disk); + bch_blockdev_stop(&dc->disk); return size; } @@ -393,7 +393,7 @@ static struct attribute *bch_cached_dev_files[] = { }; KTYPE(bch_cached_dev); -SHOW(bch_flash_dev) +SHOW(bch_blockdev_volume) { struct bcache_device *d = container_of(kobj, struct bcache_device, kobj); @@ -411,7 +411,7 @@ SHOW(bch_flash_dev) return 0; } -STORE(__bch_flash_dev) +STORE(__bch_blockdev_volume) { struct bcache_device *d = container_of(kobj, struct bcache_device, kobj); @@ -450,14 +450,14 @@ STORE(__bch_flash_dev) if (attr == &sysfs_unregister) { set_bit(BCACHE_DEV_DETACHING, &d->flags); - bcache_device_stop(d); + bch_blockdev_stop(d); } return size; } -STORE_LOCKED(bch_flash_dev) +STORE_LOCKED(bch_blockdev_volume) -static struct attribute *bch_flash_dev_files[] = { +static struct attribute *bch_blockdev_volume_files[] = { &sysfs_unregister, #if 0 &sysfs_data_csum, @@ -466,7 +466,7 @@ static struct attribute *bch_flash_dev_files[] = { &sysfs_size, NULL }; -KTYPE(bch_flash_dev); +KTYPE(bch_blockdev_volume); static int bch_bset_print_stats(struct cache_set *c, char *buf) { @@ -853,9 +853,9 @@ STORE(__bch_cache_set) return size; } - if (attr == &sysfs_flash_vol_create) { + if (attr == &sysfs_blockdev_volume_create) { u64 v = strtoi_h_or_return(buf); - int r = bch_flash_dev_create(c, v); + int r = bch_blockdev_volume_create(c, v); if (r) return r; @@ -916,7 +916,7 @@ static struct attribute *bch_cache_set_files[] = { &sysfs_unregister, &sysfs_stop, &sysfs_journal_delay_ms, - &sysfs_flash_vol_create, + &sysfs_blockdev_volume_create, &sysfs_add_device, &sysfs_block_size, diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c index 7c7e2ac27c08..6c1ef352e188 100644 --- a/drivers/md/bcache/writeback.c +++ b/drivers/md/bcache/writeback.c @@ -512,7 +512,7 @@ void bch_writeback_recalc_oldest_gens(struct cache_set *c) d = radix_tree_deref_slot(slot); - if (INODE_FLASH_ONLY(&d->inode.v)) + if (d->inode.k.type != BCH_INODE_CACHED_DEV) continue; dc = container_of(d, struct cached_dev, disk); diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h index b1ac5b9aa794..1fd882cf99ef 100644 --- a/include/uapi/linux/bcache.h +++ b/include/uapi/linux/bcache.h @@ -419,6 +419,7 @@ BKEY_VAL_TYPE(extent, BCH_EXTENT); enum bch_inode_types { BCH_INODE_FS = 128, BCH_INODE_BLOCKDEV = 129, + BCH_INODE_CACHED_DEV = 130, }; enum { @@ -461,9 +462,6 @@ struct bch_inode_blockdev { } __attribute__((packed)); BKEY_VAL_TYPE(inode_blockdev, BCH_INODE_BLOCKDEV); -BITMASK(INODE_FLASH_ONLY, struct bch_inode_blockdev, - i_inode.i_flags, 0, 1); - /* Dirents */ /* |