Skip to contentSkip to conversation

bcache: md conversion

RFC PATCH In review Dan Williams 6 participants 13 messages May 11, 2012 – May 19, 2012 1 message not in the archive

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover bcache: md conversion

The consensus from LSF was that bcache need not invent a new interface when md and dm can both do the job. As mentioned in patch 7 this series aims to be a minimal conversion. Other refactoring items like deprecating register_lock for mddev->reconfig_mutex are deferred.

This supports assembly of an already established cache array:

mdadm -A /dev/md/bcache /dev/sd[ab]

...will create the /dev/md/bcache container and a subarray representing the cache volume. "Flash-only", or backing-device only volumes were not tested. "Create" support and hot-add/hot-remove come later.

Note:
* When attempting to test with small loopback devices (100MB), assembly soft locks in bcache_journal_read(). That hang went away with larger devices, so there seems to be minimum component device size that needs to be considered in the tooling.

---

Dan Williams (7):
bcache: compile fix
bcache: disable lockdep, enable CONFIG_BCACHE=m
bcache: drop select COMPACTION
bcache: fix symlink removal
bcache: move to drivers/md/
bcache: uplevel allocation of 'cached_dev' and 'cache'
md: add bcache personality

 drivers/block/Kconfig            |    2 
 drivers/block/Makefile           |    1 
 drivers/md/Kconfig               |   14 +
 drivers/md/Makefile              |    1 
 drivers/md/bcache/Kconfig        |    3 
 drivers/md/bcache/Makefile       |    2 
 drivers/md/bcache/alloc.c        |    0 
 drivers/md/bcache/bcache.h       |   39 ++++
 drivers/md/bcache/bset.c         |    0 
 drivers/md/bcache/bset.h         |    0 
 drivers/md/bcache/btree.c        |   18 --
 drivers/md/bcache/btree.h        |    0 
 drivers/md/bcache/debug.c        |    0 
 drivers/md/bcache/debug.h        |    0 
 drivers/md/bcache/io.c           |    0 
 drivers/md/bcache/journal.c      |    0 
 drivers/md/bcache/journal.h      |    0 
 drivers/md/bcache/md.c           |  374 ++++++++++++++++++++++++++++++++++++
 drivers/md/bcache/request.c      |   24 +-
 drivers/md/bcache/request.h      |    0 
 drivers/md/bcache/stats.c        |    0 
 drivers/md/bcache/stats.h        |    0 
 drivers/md/bcache/super.c        |  394 +++++++++-----------------------------
 drivers/md/bcache/sysfs.c        |   49 -----
 drivers/md/bcache/sysfs.h        |    0 
 drivers/md/bcache/trace.c        |    0 
 drivers/md/bcache/util.c         |    2 
 drivers/md/bcache/util.h         |    3 
 drivers/md/bcache/writeback.c    |    0 
 kernel/lockdep.c                 |    1 
 30 files changed, 539 insertions(+), 388 deletions(-)
 rename drivers/{block/bcache/Kconfig => md/bcache/Kconfig} (95%)
 rename drivers/{block/bcache/Makefile => md/bcache/Makefile} (77%)
 rename drivers/{block/bcache/alloc.c => md/bcache/alloc.c} (100%)
 rename drivers/{block/bcache/bcache.h => md/bcache/bcache.h} (94%)
 rename drivers/{block/bcache/bset.c => md/bcache/bset.c} (100%)
 rename drivers/{block/bcache/bset.h => md/bcache/bset.h} (100%)
 rename drivers/{block/bcache/btree.c => md/bcache/btree.c} (99%)
 rename drivers/{block/bcache/btree.h => md/bcache/btree.h} (100%)
 rename drivers/{block/bcache/debug.c => md/bcache/debug.c} (100%)
 rename drivers/{block/bcache/debug.h => md/bcache/debug.h} (100%)
 rename drivers/{block/bcache/io.c => md/bcache/io.c} (100%)
 rename drivers/{block/bcache/journal.c => md/bcache/journal.c} (100%)
 rename drivers/{block/bcache/journal.h => md/bcache/journal.h} (100%)
 create mode 100644 drivers/md/bcache/md.c
 rename drivers/{block/bcache/request.c => md/bcache/request.c} (98%)
 rename drivers/{block/bcache/request.h => md/bcache/request.h} (100%)
 rename drivers/{block/bcache/stats.c => md/bcache/stats.c} (100%)
 rename drivers/{block/bcache/stats.h => md/bcache/stats.h} (100%)
 rename drivers/{block/bcache/super.c => md/bcache/super.c} (83%)
 rename drivers/{block/bcache/sysfs.c => md/bcache/sysfs.c} (95%)
 rename drivers/{block/bcache/sysfs.h => md/bcache/sysfs.h} (100%)
 rename drivers/{block/bcache/trace.c => md/bcache/trace.c} (100%)
 rename drivers/{block/bcache/util.c => md/bcache/util.c} (99%)
 rename drivers/{block/bcache/util.h => md/bcache/util.h} (99%)
 rename drivers/{block/bcache/writeback.c => md/bcache/writeback.c} (100%)
#2 lore raw

RFC PATCH 1/7 bcache: compile fix

In reply to a message not in the archive

dynamic_fault bits have been removed.

---
 drivers/block/bcache/util.c |    2 --
 drivers/block/bcache/util.h |    3 ---
 2 files changed, 5 deletions(-)
drivers/block/bcache/util.c +0 -2
index 200c523..6da7058 100644
@@ -6,8 +6,6 @@
 #include <linux/seq_file.h>
 #include <linux/types.h>
 
-#include <linux/dynamic_fault.h>
-
 #include "util.h"
 
 #define simple_strtoint(c, end, base)	simple_strtol(c, end, base)
drivers/block/bcache/util.h +0 -3
index 0c14cd7..6bd5327 100644
@@ -597,9 +597,6 @@ unsigned __bio_max_sectors(struct bio *bio, struct block_device *bdev,
 
 int bio_alloc_pages(struct bio *bio, gfp_t gfp);
 
-#define bio_alloc_pages(...)						\
-	(dynamic_fault() ? -ENOMEM	: bio_alloc_pages(__VA_ARGS__))
-
 static inline unsigned bio_max_sectors(struct bio *bio)
 {
 	return __bio_max_sectors(bio, bio->bi_bdev, bio->bi_sector);
#3 lore raw

RFC PATCH 2/7 bcache: disable lockdep, enable CONFIG_BCACHE=m

In reply to a message not in the archive

Of course checkpatch rightly complains:

ERROR: lockdep_no_validate class is reserved for device->mutex.

...so this is only hack for debugging.

Without this compiling as a module is not possible because the calls to __up_write() cause:

ERROR: "call_rwsem_wake" [drivers/block/bcache/bcache.ko] undefined!

...because __up_write is an internal rwsem detail.

lockdep_no_validate at least makes it explicit that lockdep support is a work-in-progress.

Not-signed-off-by... need a better workaround

---
 drivers/block/bcache/btree.c |   18 ++++--------------
 kernel/lockdep.c             |    1 +
 2 files changed, 5 insertions(+), 14 deletions(-)
drivers/block/bcache/btree.c +4 -14
index 7e9975f..e2fc357 100644
@@ -538,6 +538,7 @@ static struct btree *mca_bucket_alloc(struct cache_set *c,
 		return NULL;
 
 	init_rwsem(&b->lock);
+	lockdep_set_novalidate_class(&b->lock);
 	INIT_LIST_HEAD(&b->list);
 	INIT_DELAYED_WORK(&b->work, btree_write_work);
 	b->c = c;
@@ -1116,9 +1117,7 @@ static struct btree *btree_gc_alloc(struct btree *b, struct bkey *k,
 		b->prio_blocked++;
 
 		btree_free(n, op);
-		__up_write(&n->lock);
-
-		rwsem_release(&b->lock.dep_map, 1, _THIS_IP_);
+		up_write(&n->lock);
 	}
 
 	return b;
@@ -1218,7 +1217,7 @@ static void btree_gc_coalesce(struct btree *b, struct btree_op *op,
 	}
 
 	btree_free(r->b, op);
-	__up_write(&r->b->lock);
+	up_write(&r->b->lock);
 
 	pr_debug("coalesced %u nodes", nodes);
 
@@ -1244,7 +1243,7 @@ static int btree_gc_recurse(struct btree *b, struct btree_op *op,
 			btree_write(r, true, NULL);
 		}
 
-		__up_write(&r->lock);
+		up_write(&r->lock);
 	}
 
 	int ret = 0, stale;
@@ -1260,15 +1259,6 @@ static int btree_gc_recurse(struct btree *b, struct btree_op *op,
 			break;
 		}
 
-		/*
-		 * Fake out lockdep, because I'm a terrible person: it's just
-		 * not possible to express our lock ordering to lockdep, because
-		 * lockdep works at most in terms of a small fixed number of
-		 * subclasses, and we're just iterating through all of them in a
-		 * fixed order.
-		 */
-		rwsem_release(&r->b->lock.dep_map, 1, _THIS_IP_);
-
 		r->keys	= 0;
 		stale = btree_gc_mark(r->b, &r->keys, gc);
 
kernel/lockdep.c +1 -0
index 8889f7d..d203b16 100644
@@ -2997,6 +2997,7 @@ void lockdep_init_map(struct lockdep_map *lock, const char *name,
 EXPORT_SYMBOL_GPL(lockdep_init_map);
 
 struct lock_class_key __lockdep_no_validate__;
+EXPORT_SYMBOL_GPL(__lockdep_no_validate__);
 
 /*
  * This gets called for every mutex_lock*()/spin_lock*() operation.
#4 lore raw

RFC PATCH 3/7 bcache: drop select COMPACTION

In reply to a message not in the archive

It's not a build dependency, although it may be strongly recommended.

---
 drivers/block/bcache/Kconfig |    1 -
 1 file changed, 1 deletion(-)
drivers/block/bcache/Kconfig +0 -1
index 019f133..9acd870 100644
@@ -1,7 +1,6 @@
 
 config BCACHE
 	tristate "Block device as cache"
-	select COMPACTION
 	select CLOSURES
 	---help---
 	Allows a block device to be used as cache for other devices; uses
#5 lore raw

RFC PATCH 4/7 bcache: fix symlink removal

In reply to a message not in the archive

symlinks need to be removed prior to the kobject being deleted, otherwise we get:

 WARNING: at fs/sysfs/inode.c:323 sysfs_hash_and_remove+0xa9/0xb0()
 Hardware name: Bochs
 sysfs: can not remove 'cache', no directory
---
 drivers/block/bcache/super.c |   15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/block/bcache/super.c +9 -6
index 70d7bcd..3289db9 100644
@@ -747,9 +747,6 @@ static void bcache_device_detach(struct bcache_device *d)
 		atomic_set(&d->detaching, 0);
 	}
 
-	sysfs_remove_link(&d->c->kobj, d->name);
-	sysfs_remove_link(&d->kobj, "cache");
-
 	d->c->devices[d->id] = NULL;
 	closure_put(&d->c->caching);
 	d->c = NULL;
@@ -1049,10 +1046,13 @@ static void cached_dev_free(struct closure *cl)
 
 static void cached_dev_flush(struct closure *cl)
 {
-	struct cached_dev *d = container_of(cl, struct cached_dev, disk.cl);
+	struct cached_dev *cd = container_of(cl, struct cached_dev, disk.cl);
+	struct bcache_device *d = &cd->disk;
 
-	destroy_cache_accounting(&d->accounting);
-	kobject_del(&d->disk.kobj);
+	destroy_cache_accounting(&cd->accounting);
+	sysfs_remove_link(&d->kobj, d->name);
+	sysfs_remove_link(&d->kobj, "cache");
+	kobject_del(&d->kobj);
 
 	continue_at(cl, cached_dev_free, system_wq);
 }
@@ -1175,6 +1175,9 @@ static void flash_dev_free(struct closure *cl)
 static void flash_dev_flush(struct closure *cl)
 {
 	struct bcache_device *d = container_of(cl, struct bcache_device, cl);
+
+	sysfs_remove_link(&d->c->kobj, d->name);
+	sysfs_remove_link(&d->kobj, "cache");
 	kobject_del(&d->kobj);
 	continue_at(cl, flash_dev_free, system_wq);
 }
#6 lore raw

RFC PATCH 5/7 bcache: move to drivers/md/

In reply to a message not in the archive

This is in preparation for being exposed as a md or dm device. The rationale is that userspace tooling already knows how to generically manipulate these composite block devices, so there is not much motivation to add new bcache-specific tooling.

As seen with raid there is precedent for md and dm to share a common personality backend and separate the frontend virtual block device presentation.

---
 drivers/block/Kconfig            |    2 --
 drivers/block/Makefile           |    1 -
 drivers/md/Kconfig               |    2 ++
 drivers/md/Makefile              |    1 +
 drivers/md/bcache/Kconfig        |    0 
 drivers/md/bcache/Makefile       |    0 
 drivers/md/bcache/alloc.c        |    0 
 drivers/md/bcache/bcache.h       |    0 
 drivers/md/bcache/bset.c         |    0 
 drivers/md/bcache/bset.h         |    0 
 drivers/md/bcache/btree.c        |    0 
 drivers/md/bcache/btree.h        |    0 
 drivers/md/bcache/debug.c        |    0 
 drivers/md/bcache/debug.h        |    0 
 drivers/md/bcache/io.c           |    0 
 drivers/md/bcache/journal.c      |    0 
 drivers/md/bcache/journal.h      |    0 
 drivers/md/bcache/request.c      |    0 
 drivers/md/bcache/request.h      |    0 
 drivers/md/bcache/stats.c        |    0 
 drivers/md/bcache/stats.h        |    0 
 drivers/md/bcache/super.c        |    0 
 drivers/md/bcache/sysfs.c        |    0 
 drivers/md/bcache/sysfs.h        |    0 
 drivers/md/bcache/trace.c        |    0 
 drivers/md/bcache/util.c         |    0 
 drivers/md/bcache/util.h         |    0 
 drivers/md/bcache/writeback.c    |    0 
 28 files changed, 3 insertions(+), 3 deletions(-)
 rename drivers/{block/bcache/Kconfig => md/bcache/Kconfig} (100%)
 rename drivers/{block/bcache/Makefile => md/bcache/Makefile} (100%)
 rename drivers/{block/bcache/alloc.c => md/bcache/alloc.c} (100%)
 rename drivers/{block/bcache/bcache.h => md/bcache/bcache.h} (100%)
 rename drivers/{block/bcache/bset.c => md/bcache/bset.c} (100%)
 rename drivers/{block/bcache/bset.h => md/bcache/bset.h} (100%)
 rename drivers/{block/bcache/btree.c => md/bcache/btree.c} (100%)
 rename drivers/{block/bcache/btree.h => md/bcache/btree.h} (100%)
 rename drivers/{block/bcache/debug.c => md/bcache/debug.c} (100%)
 rename drivers/{block/bcache/debug.h => md/bcache/debug.h} (100%)
 rename drivers/{block/bcache/io.c => md/bcache/io.c} (100%)
 rename drivers/{block/bcache/journal.c => md/bcache/journal.c} (100%)
 rename drivers/{block/bcache/journal.h => md/bcache/journal.h} (100%)
 rename drivers/{block/bcache/request.c => md/bcache/request.c} (100%)
 rename drivers/{block/bcache/request.h => md/bcache/request.h} (100%)
 rename drivers/{block/bcache/stats.c => md/bcache/stats.c} (100%)
 rename drivers/{block/bcache/stats.h => md/bcache/stats.h} (100%)
 rename drivers/{block/bcache/super.c => md/bcache/super.c} (100%)
 rename drivers/{block/bcache/sysfs.c => md/bcache/sysfs.c} (100%)
 rename drivers/{block/bcache/sysfs.h => md/bcache/sysfs.h} (100%)
 rename drivers/{block/bcache/trace.c => md/bcache/trace.c} (100%)
 rename drivers/{block/bcache/util.c => md/bcache/util.c} (100%)
 rename drivers/{block/bcache/util.h => md/bcache/util.h} (100%)
 rename drivers/{block/bcache/writeback.c => md/bcache/writeback.c} (100%)
drivers/block/Kconfig +0 -2
index d872600..4e4c8a4 100644
@@ -526,8 +526,6 @@ config VIRTIO_BLK
 	  This is the virtual block driver for virtio.  It can be used with
           lguest or QEMU based VMMs (like KVM or Xen).  Say Y or M.
 
-source "drivers/block/bcache/Kconfig"
-
 config BLK_DEV_HD
 	bool "Very old hard disk (MFM/RLL/IDE) driver"
 	depends on HAVE_IDE
drivers/block/Makefile +0 -1
index 19520e1..5b79505 100644
@@ -41,6 +41,5 @@ obj-$(CONFIG_XEN_BLKDEV_BACKEND)	+= xen-blkback/
 obj-$(CONFIG_BLK_DEV_DRBD)     += drbd/
 obj-$(CONFIG_BLK_DEV_RBD)     += rbd.o
 obj-$(CONFIG_BLK_DEV_PCIESSD_MTIP32XX)	+= mtip32xx/
-obj-$(CONFIG_BCACHE)           += bcache/
 
 swim_mod-y	:= swim.o swim_asm.o
drivers/md/Kconfig +2 -0
index faa4741..110c1b7 100644
@@ -185,6 +185,8 @@ config MD_FAULTY
 
 	  In unsure, say N.
 
+source "drivers/md/bcache/Kconfig"
+
 config BLK_DEV_DM
 	tristate "Device mapper support"
 	---help---
drivers/md/Makefile +1 -0
index 046860c..b717f51 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_MD_RAID10)		+= raid10.o
 obj-$(CONFIG_MD_RAID456)	+= raid456.o
 obj-$(CONFIG_MD_MULTIPATH)	+= multipath.o
 obj-$(CONFIG_MD_FAULTY)		+= faulty.o
+obj-$(CONFIG_BCACHE)		+= bcache/
 obj-$(CONFIG_BLK_DEV_MD)	+= md-mod.o
 obj-$(CONFIG_BLK_DEV_DM)	+= dm-mod.o
 obj-$(CONFIG_DM_BUFIO)		+= dm-bufio.o
drivers/md/bcache/Kconfig renamed from drivers/block/bcache/Kconfig +0 -0
similarity index 100%
rename from drivers/block/bcache/Kconfig
rename to drivers/md/bcache/Kconfig
drivers/md/bcache/Makefile renamed from drivers/block/bcache/Makefile +0 -0
similarity index 100%
rename from drivers/block/bcache/Makefile
rename to drivers/md/bcache/Makefile
drivers/md/bcache/alloc.c renamed from drivers/block/bcache/alloc.c +0 -0
similarity index 100%
rename from drivers/block/bcache/alloc.c
rename to drivers/md/bcache/alloc.c
drivers/md/bcache/bcache.h renamed from drivers/block/bcache/bcache.h +0 -0
similarity index 100%
rename from drivers/block/bcache/bcache.h
rename to drivers/md/bcache/bcache.h
drivers/md/bcache/bset.c renamed from drivers/block/bcache/bset.c +0 -0
similarity index 100%
rename from drivers/block/bcache/bset.c
rename to drivers/md/bcache/bset.c
drivers/md/bcache/bset.h renamed from drivers/block/bcache/bset.h +0 -0
similarity index 100%
rename from drivers/block/bcache/bset.h
rename to drivers/md/bcache/bset.h
drivers/md/bcache/btree.c renamed from drivers/block/bcache/btree.c +0 -0
similarity index 100%
rename from drivers/block/bcache/btree.c
rename to drivers/md/bcache/btree.c
drivers/md/bcache/btree.h renamed from drivers/block/bcache/btree.h +0 -0
similarity index 100%
rename from drivers/block/bcache/btree.h
rename to drivers/md/bcache/btree.h
drivers/md/bcache/debug.c renamed from drivers/block/bcache/debug.c +0 -0
similarity index 100%
rename from drivers/block/bcache/debug.c
rename to drivers/md/bcache/debug.c
drivers/md/bcache/debug.h renamed from drivers/block/bcache/debug.h +0 -0
similarity index 100%
rename from drivers/block/bcache/debug.h
rename to drivers/md/bcache/debug.h
drivers/md/bcache/io.c renamed from drivers/block/bcache/io.c +0 -0
similarity index 100%
rename from drivers/block/bcache/io.c
rename to drivers/md/bcache/io.c
drivers/md/bcache/journal.c renamed from drivers/block/bcache/journal.c +0 -0
similarity index 100%
rename from drivers/block/bcache/journal.c
rename to drivers/md/bcache/journal.c
drivers/md/bcache/journal.h renamed from drivers/block/bcache/journal.h +0 -0
similarity index 100%
rename from drivers/block/bcache/journal.h
rename to drivers/md/bcache/journal.h
drivers/md/bcache/request.c renamed from drivers/block/bcache/request.c +0 -0
similarity index 100%
rename from drivers/block/bcache/request.c
rename to drivers/md/bcache/request.c
drivers/md/bcache/request.h renamed from drivers/block/bcache/request.h +0 -0
similarity index 100%
rename from drivers/block/bcache/request.h
rename to drivers/md/bcache/request.h
drivers/md/bcache/stats.c renamed from drivers/block/bcache/stats.c +0 -0
similarity index 100%
rename from drivers/block/bcache/stats.c
rename to drivers/md/bcache/stats.c
drivers/md/bcache/stats.h renamed from drivers/block/bcache/stats.h +0 -0
similarity index 100%
rename from drivers/block/bcache/stats.h
rename to drivers/md/bcache/stats.h
drivers/md/bcache/super.c renamed from drivers/block/bcache/super.c +0 -0
similarity index 100%
rename from drivers/block/bcache/super.c
rename to drivers/md/bcache/super.c
drivers/md/bcache/sysfs.c renamed from drivers/block/bcache/sysfs.c +0 -0
similarity index 100%
rename from drivers/block/bcache/sysfs.c
rename to drivers/md/bcache/sysfs.c
drivers/md/bcache/sysfs.h renamed from drivers/block/bcache/sysfs.h +0 -0
similarity index 100%
rename from drivers/block/bcache/sysfs.h
rename to drivers/md/bcache/sysfs.h
drivers/md/bcache/trace.c renamed from drivers/block/bcache/trace.c +0 -0
similarity index 100%
rename from drivers/block/bcache/trace.c
rename to drivers/md/bcache/trace.c
drivers/md/bcache/util.c renamed from drivers/block/bcache/util.c +0 -0
similarity index 100%
rename from drivers/block/bcache/util.c
rename to drivers/md/bcache/util.c
drivers/md/bcache/util.h renamed from drivers/block/bcache/util.h +0 -0
similarity index 100%
rename from drivers/block/bcache/util.h
rename to drivers/md/bcache/util.h
drivers/md/bcache/writeback.c renamed from drivers/block/bcache/writeback.c +0 -0
similarity index 100%
rename from drivers/block/bcache/writeback.c
rename to drivers/md/bcache/writeback.c
#7 lore raw

RFC PATCH 6/7 bcache: uplevel allocation of 'cached_dev' and 'cache'

In reply to a message not in the archive

This is prepartion to enable a container_of() relationship between these and a 'rdev' for the md conversion (or a dm_dev for an eventual dm skin).

---
 drivers/md/bcache/super.c |   46 +++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 22 deletions(-)
drivers/md/bcache/super.c +24 -22
index 3289db9..c1fe44d 100644
@@ -1057,11 +1057,9 @@ static void cached_dev_flush(struct closure *cl)
 	continue_at(cl, cached_dev_free, system_wq);
 }
 
-static struct cached_dev *cached_dev_alloc(unsigned block_size)
+static int cached_dev_init(struct cached_dev *d, unsigned block_size)
 {
-	struct cached_dev *d = kzalloc(sizeof(struct cached_dev), GFP_KERNEL);
-	if (!d)
-		return NULL;
+	int err;
 
 	closure_init(&d->disk.cl, NULL);
 	set_closure_fn(&d->disk.cl, cached_dev_flush, system_wq);
@@ -1093,29 +1091,28 @@ static struct cached_dev *cached_dev_alloc(unsigned block_size)
 
 	bcache_writeback_init_cached_dev(d);
 
+	err = -ENOMEM;
 	d->bio_passthrough = mempool_create_slab_pool(32, passthrough_cache);
 	if (!d->bio_passthrough)
 		goto err;
 
-	return d;
+	return 0;
 err:
 	bcache_device_stop(&d->disk);
-	return NULL;
+	return err;
 }
 
 /* Cached device - bcache superblock */
 
 static const char *register_bdev(struct cache_sb *sb, struct page *sb_page,
-				 struct block_device *bdev)
+				 struct block_device *bdev, struct cached_dev *d)
 {
 	char name[BDEVNAME_SIZE];
 	const char *err = "cannot allocate memory";
 	struct gendisk *g;
 	struct cache_set *c;
 
-	struct cached_dev *d = cached_dev_alloc(sb->block_size << 9);
-
-	if (!d)
+	if (!d || cached_dev_init(d, sb->block_size << 9) != 0)
 		return err;
 
 	memcpy(&d->sb, sb, sizeof(struct cache_sb));
@@ -1729,13 +1726,13 @@ static void cache_free(struct kobject *kobj)
 	module_put(THIS_MODULE);
 }
 
-static struct cache *cache_alloc(struct cache_sb *sb)
+static int cache_alloc(struct cache_sb *sb, struct cache *c)
 {
 	size_t free;
 	struct bucket *b;
-	struct cache *c = kzalloc(sizeof(struct cache), GFP_KERNEL);
+
 	if (!c)
-		return NULL;
+		return -ENOMEM;
 
 	__module_get(THIS_MODULE);
 	cache_kobject_init(c);
@@ -1779,19 +1776,19 @@ static struct cache *cache_alloc(struct cache_sb *sb)
 	if (alloc_discards(c))
 		goto err;
 
-	return c;
+	return 0;
 err:
 	kobject_put(&c->kobj);
-	return NULL;
+	return -ENOMEM;
 }
 
 static const char *register_cache(struct cache_sb *sb, struct page *sb_page,
-				  struct block_device *bdev)
+				  struct block_device *bdev, struct cache *c)
 {
 	char name[BDEVNAME_SIZE];
 	const char *err = "cannot allocate memory";
-	struct cache *c = cache_alloc(sb);
-	if (!c)
+
+	if (cache_alloc(sb, c) != 0)
 		return err;
 
 	c->sb_bio.bi_io_vec[0].bv_page = sb_page;
@@ -1867,10 +1864,15 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
 	if (err)
 		goto err_close;
 
-	if (sb->version == CACHE_BACKING_DEV)
-		err = register_bdev(sb, sb_page, bdev);
-	else
-		err = register_cache(sb, sb_page, bdev);
+	if (sb->version == CACHE_BACKING_DEV) {
+		struct cached_dev *d = kzalloc(sizeof(*d), GFP_KERNEL);
+
+		err = register_bdev(sb, sb_page, bdev, d);
+	} else {
+		struct cache *c = kzalloc(sizeof(*c), GFP_KERNEL);
+
+		err = register_cache(sb, sb_page, bdev, c);
+	}
 
 	if (err) {
 		/* register_(bdev|cache) will only return an error if they
#8 lore raw

RFC PATCH 7/7 md: add bcache personality

In reply to a message not in the archive

Expose bcache as a md personality. Since bcache already depends on userpsace assembly, allow it to borrow all the discovery and assembly mechanisms that have grown up around mdadm. Userpace requests raid-level "bcache", or "11" (0xb), when starting an array. "Backing device" vs "cache device" is determined by slot number whereby the backing device slot is the highest number index.

This attempts to be a minimal conversion, but reconciling the gendisk and kobject relationships with md contributed to the bulk of the thrash. The removal of the balance of the duplicated functionality comes later. Also note that functionality like flash-only volume creation and flash-only resize are temporarily removed until they can be re-implemented via the upper layer (md or dm). Another todo item is detaching devices from cache sets via md hot disk add/remove.

The sysfs topology is easier to navigate now. The bcache attributes no longer pop up up under individual block devices. Instead bcache membership of an individual block device can be determined the same as raid membership, i.e. by following:

/sys/block/<blockdev>/holders/<mddev>

From there the layout is:

/sys/block/<mddev>/md/bcache : cache set attributes /sys/block/<mddev>/md/rd[0..N-1]/bcache : cache device device attributes /sys/block/<mddev>/md/rdN/bcache : backing device attributes

Global listing of all bcache volumes available via /proc/mdstat or /sys/block/*/md/bcache (rather than /sys/fs/bcache).

---
 drivers/md/Kconfig          |   12 +
 drivers/md/bcache/Kconfig   |    2 
 drivers/md/bcache/Makefile  |    2 
 drivers/md/bcache/bcache.h  |   39 ++++
 drivers/md/bcache/md.c      |  374 +++++++++++++++++++++++++++++++++++++++++++
 drivers/md/bcache/request.c |   24 +--
 drivers/md/bcache/super.c   |  359 +++++++++--------------------------------
 drivers/md/bcache/sysfs.c   |   49 ------
 8 files changed, 511 insertions(+), 350 deletions(-)
 create mode 100644 drivers/md/bcache/md.c
drivers/md/Kconfig +12 -0
index 110c1b7..e1ad581 100644
@@ -185,6 +185,18 @@ config MD_FAULTY
 
 	  In unsure, say N.
 
+config MD_BCACHE
+	tristate "Caching mode for MD"
+	depends on BLK_DEV_MD
+	select BCACHE
+	help
+	  The "md_bcache" module allows for an md device that
+	  establishes a cache hierarchy of high iops and/or bandwidth
+	  block device(s) to a slower block device.  Assembly of arrays
+	  of this personality require userspace assistance, i.e. arrays
+	  with this format are treated as "external" metadata, see
+	  MDADM(8)
+
 source "drivers/md/bcache/Kconfig"
 
 config BLK_DEV_DM
drivers/md/bcache/Kconfig +1 -1
index 9acd870..c4f404c 100644
@@ -1,6 +1,6 @@
 
 config BCACHE
-	tristate "Block device as cache"
+	tristate
 	select CLOSURES
 	---help---
 	Allows a block device to be used as cache for other devices; uses
drivers/md/bcache/Makefile +2 -0
index 84302f9..5a0c445 100644
@@ -1,8 +1,10 @@
 
 ccflags-y		+= -std=gnu99
 obj-$(CONFIG_BCACHE)	+= bcache.o
+obj-$(CONFIG_MD_BCACHE) += md_bcache.o
 
 bcache-y		:= alloc.o btree.o bset.o io.o journal.o\
 	writeback.o request.o super.o debug.o util.o trace.o stats.o
+md_bcache-y		:= md.o
 
 CFLAGS_request.o	+= -Iblock
drivers/md/bcache/bcache.h +39 -0
index aad9c48..1bdae7b 100644
@@ -1,5 +1,7 @@
 
+#ifndef pr_fmt
 #define pr_fmt(fmt) "bcache: %s() " fmt "\n", __func__
+#endif
 
 #include <linux/bio.h>
 #include <linux/blktrace_api.h>
@@ -297,6 +299,7 @@ struct cached_dev {
 	unsigned		writeback_rate_d_term;
 	unsigned		writeback_rate_p_term_inverse;
 	unsigned		writeback_rate_d_smooth;
+	void			(*release)(struct cached_dev *);
 };
 
 struct cache {
@@ -375,6 +378,7 @@ struct cache {
 	atomic_long_t		meta_sectors_written;
 	atomic_long_t		btree_sectors_written;
 	atomic_long_t		sectors_written;
+	void			(*release)(struct cache *);
 };
 
 struct gc_stat {
@@ -387,6 +391,26 @@ struct gc_stat {
 	unsigned		in_use; /* percent */
 };
 
+struct uuid_entry {
+	union {
+		struct {
+			uint8_t		uuid[16];
+			uint8_t		label[32];
+			uint32_t	first_reg;
+			uint32_t	last_reg;
+			uint32_t	invalidated;
+
+			uint32_t	flags;
+			/* Size of flash only volumes */
+			uint64_t	sectors;
+		};
+
+		uint8_t	pad[128];
+	};
+};
+
+BITMASK(UUID_FLASH_ONLY,	struct uuid_entry, flags, 0, 1);
+
 struct cache_set {
 	struct closure		cl;
 
@@ -837,3 +861,18 @@ void bcache_request_exit(void);
 int bcache_request_init(void);
 void bcache_btree_exit(void);
 int bcache_btree_init(void);
+
+int bcache_flash_dev_run(struct cache_set *, struct uuid_entry *, struct bcache_device *);
+const char *bcache_register_cache(struct cache_sb *, struct page *, struct block_device *,
+				  struct kobject *, struct cache *, struct kobject *);
+const char *bcache_register_bdev(struct cache_sb *, struct page *, struct block_device *,
+				 struct kobject *, struct cached_dev *);
+const char *bcache_read_super(struct cache_sb *, struct block_device *, struct page **);
+void bcache_cached_dev_make_request(struct bcache_device *d, struct bio *bio);
+void bcache_flash_dev_make_request(struct bcache_device *d, struct bio *bio);
+int bcache_cached_dev_attach(struct cached_dev *d, struct cache_set *c);
+int bcache_cached_dev_congested(void *data, int bits);
+int bcache_flash_dev_congested(void *data, int bits);
+void bcache_cached_dev_run(struct cached_dev *);
+void bcache_device_stop(struct bcache_device *);
+void bcache_cache_set_stop(struct cache_set *);
drivers/md/bcache/md.c new file +374 -0

374 lines not on this page · raw message

drivers/md/bcache/request.c +9 -15
index 691fe8d..2d0d7ee 100644
@@ -1228,11 +1228,10 @@ skip:
 	s->skip = true;
 }
 
-static void cached_dev_make_request(struct request_queue *q, struct bio *bio)
+void bcache_cached_dev_make_request(struct bcache_device *d, struct bio *bio)
 {
-	struct search *s;
-	struct bcache_device *d = bio->bi_bdev->bd_disk->private_data;
 	struct cached_dev *dc = container_of(d, struct cached_dev, disk);
+	struct search *s;
 
 	bio->bi_bdev = dc->bdev;
 	bio->bi_sector += 16;
@@ -1247,6 +1246,7 @@ static void cached_dev_make_request(struct request_queue *q, struct bio *bio)
 	} else
 		bio_passthrough(dc, bio);
 }
+EXPORT_SYMBOL_GPL(bcache_cached_dev_make_request);
 
 static int cached_dev_ioctl(struct bcache_device *d, fmode_t mode,
 			    unsigned int cmd, unsigned long arg)
@@ -1255,7 +1255,7 @@ static int cached_dev_ioctl(struct bcache_device *d, fmode_t mode,
 	return __blkdev_driver_ioctl(dc->bdev, mode, cmd, arg);
 }
 
-static int cached_dev_congested(void *data, int bits)
+int bcache_cached_dev_congested(void *data, int bits)
 {
 	struct bcache_device *d = data;
 	struct cached_dev *dc = container_of(d, struct cached_dev, disk);
@@ -1278,13 +1278,10 @@ static int cached_dev_congested(void *data, int bits)
 
 	return ret;
 }
+EXPORT_SYMBOL_GPL(bcache_cached_dev_congested);
 
 void cached_dev_request_init(struct cached_dev *d)
 {
-	struct gendisk *g = d->disk.disk;
-
-	g->queue->make_request_fn		= cached_dev_make_request;
-	g->queue->backing_dev_info.congested_fn = cached_dev_congested;
 	d->disk.cache_miss			= cached_dev_cache_miss;
 	d->disk.ioctl				= cached_dev_ioctl;
 }
@@ -1398,10 +1395,9 @@ static void flash_dev_req_nodata(struct search *s)
 	continue_at(&s->cl, flash_dev_bio_complete, NULL);
 }
 
-static void flash_dev_make_request(struct request_queue *q, struct bio *bio)
+void bcache_flash_dev_make_request(struct bcache_device *d, struct bio *bio)
 {
 	struct search *s;
-	struct bcache_device *d = bio->bi_bdev->bd_disk->private_data;
 
 	s = do_bio_hook(bio, d);
 	trace_bcache_request_start(&s->op, bio);
@@ -1410,6 +1406,7 @@ static void flash_dev_make_request(struct request_queue *q, struct bio *bio)
 	 bio->bi_rw & REQ_WRITE ? flash_dev_write :
 				  flash_dev_read)(s);
 }
+EXPORT_SYMBOL_GPL(bcache_flash_dev_make_request);
 
 static int flash_dev_ioctl(struct bcache_device *d, fmode_t mode,
 			   unsigned int cmd, unsigned long arg)
@@ -1417,7 +1414,7 @@ static int flash_dev_ioctl(struct bcache_device *d, fmode_t mode,
 	return -ENOTTY;
 }
 
-static int flash_dev_congested(void *data, int bits)
+int bcache_flash_dev_congested(void *data, int bits)
 {
 	struct bcache_device *d = data;
 	struct request_queue *q;
@@ -1431,13 +1428,10 @@ static int flash_dev_congested(void *data, int bits)
 
 	return ret;
 }
+EXPORT_SYMBOL_GPL(bcache_flash_dev_congested);
 
 void flash_dev_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->cache_miss				= flash_dev_cache_miss;
 	d->ioctl				= flash_dev_ioctl;
 }
drivers/md/bcache/super.c +74 -285

652 lines not on this page · raw message

drivers/md/bcache/sysfs.c +0 -49

118 lines not on this page · raw message

#11 lore raw
In reply to a message not in the archive
Quoted 83 lines · Dan Williams

The consensus from LSF was that bcache need not invent a new interface when md and dm can both do the job.  As mentioned in patch 7 this series aims to be a minimal conversion.  Other refactoring items like deprecating register_lock for mddev->reconfig_mutex are deferred.

This supports assembly of an already established cache array:

       mdadm -A /dev/md/bcache /dev/sd[ab]

...will create the /dev/md/bcache container and a subarray representing the cache volume.  "Flash-only", or backing-device only volumes were not tested.  "Create" support and hot-add/hot-remove come later.

Note:
* When attempting to test with small loopback devices (100MB), assembly soft locks in bcache_journal_read().  That hang went away with larger devices, so there seems to be minimum component device size that needs to be considered in the tooling.

---

Dan Williams (7):
     bcache: compile fix
     bcache: disable lockdep, enable CONFIG_BCACHE=m
     bcache: drop select COMPACTION
     bcache: fix symlink removal
     bcache: move to drivers/md/
     bcache: uplevel allocation of 'cached_dev' and 'cache'
     md: add bcache personality

 drivers/block/Kconfig            |    2
 drivers/block/Makefile           |    1
 drivers/md/Kconfig               |   14 +
 drivers/md/Makefile              |    1
 drivers/md/bcache/Kconfig        |    3
 drivers/md/bcache/Makefile       |    2
 drivers/md/bcache/alloc.c        |    0
 drivers/md/bcache/bcache.h       |   39 ++++

 drivers/md/bcache/bset.c         |    0
 drivers/md/bcache/bset.h         |    0
 drivers/md/bcache/btree.c        |   18 --
 drivers/md/bcache/btree.h        |    0
 drivers/md/bcache/debug.c        |    0
 drivers/md/bcache/debug.h        |    0

 drivers/md/bcache/io.c           |    0 drivers/md/bcache/journal.c      |    0 drivers/md/bcache/journal.h      |    0
 drivers/md/bcache/md.c           |  374 ++++++++++++++++++++++++++++++++++++ drivers/md/bcache/request.c      |   24 +- drivers/md/bcache/request.h      |    0

 drivers/md/bcache/stats.c        |    0
 drivers/md/bcache/stats.h        |    0
 drivers/md/bcache/super.c        |  394 +++++++++-----------------------------
 drivers/md/bcache/sysfs.c        |   49 -----
 drivers/md/bcache/sysfs.h        |    0
 drivers/md/bcache/trace.c        |    0
 drivers/md/bcache/util.c         |    2
 drivers/md/bcache/util.h         |    3
 drivers/md/bcache/writeback.c    |    0
 kernel/lockdep.c                 |    1
 30 files changed, 539 insertions(+), 388 deletions(-)

 rename drivers/{block/bcache/Kconfig => md/bcache/Kconfig} (95%) rename drivers/{block/bcache/Makefile => md/bcache/Makefile} (77%) rename drivers/{block/bcache/alloc.c => md/bcache/alloc.c} (100%) rename drivers/{block/bcache/bcache.h => md/bcache/bcache.h} (94%) rename drivers/{block/bcache/bset.c => md/bcache/bset.c} (100%) rename drivers/{block/bcache/bset.h => md/bcache/bset.h} (100%) rename drivers/{block/bcache/btree.c => md/bcache/btree.c} (99%) rename drivers/{block/bcache/btree.h => md/bcache/btree.h} (100%) rename drivers/{block/bcache/debug.c => md/bcache/debug.c} (100%) rename drivers/{block/bcache/debug.h => md/bcache/debug.h} (100%) rename drivers/{block/bcache/io.c => md/bcache/io.c} (100%) rename drivers/{block/bcache/journal.c => md/bcache/journal.c} (100%) rename drivers/{block/bcache/journal.h => md/bcache/journal.h} (100%) create mode 100644 drivers/md/bcache/md.c
 rename drivers/{block/bcache/request.c => md/bcache/request.c} (98%) rename drivers/{block/bcache/request.h => md/bcache/request.h} (100%) rename drivers/{block/bcache/stats.c => md/bcache/stats.c} (100%) rename drivers/{block/bcache/stats.h => md/bcache/stats.h} (100%) rename drivers/{block/bcache/super.c => md/bcache/super.c} (83%) rename drivers/{block/bcache/sysfs.c => md/bcache/sysfs.c} (95%) rename drivers/{block/bcache/sysfs.h => md/bcache/sysfs.h} (100%)

Quoted 8 lines

 rename drivers/{block/bcache/trace.c => md/bcache/trace.c} (100%) rename drivers/{block/bcache/util.c => md/bcache/util.c} (99%) rename drivers/{block/bcache/util.h => md/bcache/util.h} (99%) rename drivers/{block/bcache/writeback.c => md/bcache/writeback.c} (100%) --
To unsubscribe from this list: send the line "unsubscribe linux-bcache" in the body of a message to [email protected] More majordomo info at  http://vger.kernel.org/majordomo-info.html

This is very interesting,

I will play around with these this weekend. :)

Joseph.

Signature · 3 lines
Founder | Director | VP Research
Orion Virtualisation Solutions | www.orionvm.com.au | Phone: 1300 56
99 52 | Mobile: 0428 754 846
#12 lore raw
In reply to a message not in the archive
Quoted 4 lines · Dan Williams

The consensus from LSF was that bcache need not invent a new interface when md and dm can both do the job. As mentioned in patch 7 this series aims to be a minimal conversion. Other refactoring items like deprecating register_lock for mddev->reconfig_mutex are deferred.

Awesome! I just applied the first 6 - the lockdep fix especially was exactly what I'd been looking for. I need to dig in to the patch that does the actual md conversion more and play with it... also need to look at how refcounting works.

Quoted 8 lines

This supports assembly of an already established cache array:

mdadm -A /dev/md/bcache /dev/sd[ab]

...will create the /dev/md/bcache container and a subarray representing the cache volume. "Flash-only", or backing-device only volumes were not tested. "Create" support and hot-add/hot-remove come later.

Quoted 5 lines

Note:
* When attempting to test with small loopback devices (100MB), assembly soft locks in bcache_journal_read(). That hang went away with larger devices, so there seems to be minimum component device size that needs to be considered in the tooling.

Curious. I normally use a 256 mb cache for vm testing and I haven't seen anything like that in ages, wonder what you found. Will investigate.

#9 lore raw

Re: [RFC PATCH 7/7] md: add bcache personality

In reply to Dan Williams
Quoted 3 lines · Dan Williams

"Backing
device" vs "cache device" is determined by slot number whereby the backing device slot is the highest number index.

That needs fixing. We used to do things by slot number long ago, and it turned out to create lots of races on reconfiguring slot indexes and moving devices around on rebuilds and stuff like that. I would have to see us undo that fix when it comes to bcache.

Signature · 6 lines
Doug Ledford <[email protected]>
              GPG KeyID: 0E572FDD
	      http://people.redhat.com/dledford

Infiniband specific RPMs available at
	      http://people.redhat.com/dledford/Infiniband
#10 lore raw

Re: [RFC PATCH 7/7] md: add bcache personality

Quoted 9 lines · Doug Ledford
Quoted 3 lines · Dan Williams

"Backing
device" vs "cache device" is determined by slot number whereby the backing device slot is the highest number index.

That needs fixing.  We used to do things by slot number long ago, and it turned out to create lots of races on reconfiguring slot indexes and moving devices around on rebuilds and stuff like that.  I would have to see us undo that fix when it comes to bcache.

Yeah, that hack should be easy to remove and userspace can look at the sysfs attributes to determine the device's role.

--
Dan
--
To unsubscribe from this list: send the line "unsubscribe linux-raid" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#13 lore raw
In reply to Dan Williams
Quoted 13 lines · Dan Williams

The consensus from LSF was that bcache need not invent a new interface when md and dm can both do the job. As mentioned in patch 7 this series aims to be a minimal conversion. Other refactoring items like deprecating register_lock for mddev->reconfig_mutex are deferred.

This supports assembly of an already established cache array:

mdadm -A /dev/md/bcache /dev/sd[ab]

...will create the /dev/md/bcache container and a subarray representing the cache volume. "Flash-only", or backing-device only volumes were not tested. "Create" support and hot-add/hot-remove come later.

Quoted 5 lines

Note:
* When attempting to test with small loopback devices (100MB), assembly soft locks in bcache_journal_read(). That hang went away with larger devices, so there seems to be minimum component device size that needs to be considered in the tooling.

Is there any plan to separate the on-disk layout (per-device headers, etc) from the logic for the purpose of reuse? I can think of at least one case where this would be extremely useful: integration in BtrFS.

BtrFS already has its own methods for making sure a group of devices are all present when the filesystem is mounted, so it doesn't really need the formatting of the backing device bcache does to prevent it from being mounted solo. Putting bcache under BtrFS would be silly in the same way as putting it under a raid array, but bcache can't be put on top of BtrFS.

Logically, in looking at BtrFS' architecture, a cache would likely fit best at the 'block group' level, which IIUC would be roughly equivalent to the recommended 'over raid, under lvm' method of using bcache.