Fold into 3
[agk]
---
 Documentation/device-mapper/thin-provisioning.txt |    7 -
 drivers/md/dm-thin-metadata.c                     |    2 
 drivers/md/dm-thin.c                              |   92 +++++++++++-----------
 3 files changed, 51 insertions(+), 50 deletions(-)

Index: linux-3.0-rc7/Documentation/device-mapper/thin-provisioning.txt
===================================================================
--- linux-3.0-rc7.orig/Documentation/device-mapper/thin-provisioning.txt
+++ linux-3.0-rc7/Documentation/device-mapper/thin-provisioning.txt
@@ -168,12 +168,13 @@ i) Constructor
 
  thin-pool <metadata dev>
            <data dev>
-           <data block size in sectors>
+           <data block size (sectors)>
            <low water mark (sectors)>
+AGK FIXME Define this
 	   [number of feature args> [<arg>]*]
 
- optional feature args:
-   - 'skip_block_zeroing': skips the zeroing of newly provisioned blocks
+ Optional feature arguments:
+   - 'skip_block_zeroing': skips the zeroing of newly-provisioned blocks.
 
 ii) Status
 
Index: linux-3.0-rc7/drivers/md/dm-thin-metadata.c
===================================================================
--- linux-3.0-rc7.orig/drivers/md/dm-thin-metadata.c
+++ linux-3.0-rc7/drivers/md/dm-thin-metadata.c
@@ -14,7 +14,7 @@
 
 /*----------------------------------------------------------------*/
 
-#define DM_MSG_PREFIX   "thin-metadata"
+#define DM_MSG_PREFIX   "thin metadata"
 
 #define THIN_SUPERBLOCK_MAGIC 27022010
 #define THIN_SUPERBLOCK_LOCATION 0
Index: linux-3.0-rc7/drivers/md/dm-thin.c
===================================================================
--- linux-3.0-rc7.orig/drivers/md/dm-thin.c
+++ linux-3.0-rc7/drivers/md/dm-thin.c
@@ -537,17 +537,19 @@ struct endio_hook {
 #define TABLE_SIZE 32
 #define TABLE_PRIME 27 /* Largest prime smaller than table size. */
 #define	TABLE_SHIFT 5  /* Shift fitting prime. */
-struct bdev_table {
+
+static struct dm_thin_bdev_table {
 	spinlock_t lock;
 	struct hlist_head buckets[TABLE_SIZE];
-};
+} dm_thin_bdev_table;
 
-static void bdev_table_init(struct bdev_table *t)
+static void bdev_table_init(void)
 {
 	unsigned i;
-	spin_lock_init(&t->lock);
+
+	spin_lock_init(&dm_thin_bdev_table.lock);
 	for (i = 0; i < TABLE_SIZE; i++)
-		INIT_HLIST_HEAD(t->buckets + i);
+		INIT_HLIST_HEAD(dm_thin_bdev_table.buckets + i);
 }
 
 static unsigned hash_bdev(struct block_device *bdev)
@@ -558,37 +560,35 @@ static unsigned hash_bdev(struct block_d
 	return ((p * TABLE_PRIME) >> TABLE_SHIFT) & (TABLE_SIZE - 1);
 }
 
-static void bdev_table_insert(struct bdev_table *t, struct pool *pool)
+static void bdev_table_insert(struct pool *pool)
 {
 	unsigned bucket = hash_bdev(pool->pool_dev);
-	spin_lock(&t->lock);
-	hlist_add_head(&pool->hlist, t->buckets + bucket);
-	spin_unlock(&t->lock);
+
+	spin_lock(&dm_thin_bdev_table.lock);
+	hlist_add_head(&pool->hlist, dm_thin_bdev_table.buckets + bucket);
+	spin_unlock(&dm_thin_bdev_table.lock);
 }
 
-static void bdev_table_remove(struct bdev_table *t, struct pool *pool)
+static void bdev_table_remove(struct pool *pool)
 {
-	spin_lock(&t->lock);
+	spin_lock(&dm_thin_bdev_table.lock);
 	hlist_del(&pool->hlist);
-	spin_unlock(&t->lock);
+	spin_unlock(&dm_thin_bdev_table.lock);
 }
 
-static struct pool *bdev_table_lookup(struct bdev_table *t,
-				      struct block_device *bdev)
+static struct pool *bdev_table_lookup(struct block_device *bdev)
 {
 	unsigned bucket = hash_bdev(bdev);
 	struct hlist_node *n;
 	struct pool *pool;
 
-	hlist_for_each_entry(pool, n, t->buckets + bucket, hlist)
+	hlist_for_each_entry(pool, n, dm_thin_bdev_table.buckets + bucket, hlist)
 		if (pool->pool_dev == bdev)
 			return pool;
 
 	return NULL;
 }
 
-static struct bdev_table bdev_table_;
-
 /*----------------------------------------------------------------*/
 
 /*
@@ -1293,20 +1293,20 @@ static void pool_destroy(struct pool *po
  * dm_get_device() except it doesn't associate the device with the target,
  * which would prevent the target to be destroyed.
  */
-static struct block_device *thin_get_device(const char *path, fmode_t mode)
+static struct block_device *thin_get_device(const char *metadata_path, fmode_t mode)
 {
 	dev_t uninitialized_var(dev);
 	unsigned int major, minor;
 	struct block_device *bdev;
 
-	if (sscanf(path, "%u:%u", &major, &minor) == 2) {
+	if (sscanf(metadata_path, "%u:%u", &major, &minor) == 2) {
 		/* Extract the major/minor numbers */
 		dev = MKDEV(major, minor);
 		if (MAJOR(dev) != major || MINOR(dev) != minor)
 			return ERR_PTR(-EOVERFLOW);
 		bdev = blkdev_get_by_dev(dev, mode, &thin_get_device);
 	} else
-		bdev = blkdev_get_by_path(path, mode, &thin_get_device);
+		bdev = blkdev_get_by_path(metadata_path, mode, &thin_get_device);
 
 	if (!bdev)
 		return ERR_PTR(-EINVAL);
@@ -1453,8 +1453,9 @@ static struct pool *pool_find(struct blo
 {
 	struct pool *pool;
 
-	pool = bdev_table_lookup(&bdev_table_, pool_bdev);
+	pool = bdev_table_lookup(pool_bdev);
 	if (pool)
+// AGK FIXME metadata_path not validated here
 		pool_inc(pool);
 	else
 		pool = pool_create(metadata_path, block_size, error);
@@ -1487,22 +1488,17 @@ static int parse_pool_features(struct dm
 	const char *arg_name;
 
 	static struct dm_arg _args[] = {
-		{0, 1, "invalid number of pool feature args"},
+		{0, 1, "Invalid number of pool feature arguments"},
 	};
 
 	/* No feature arguments supplied. */
 	if (!as->argc)
 		return 0;
 
-	r = dm_read_arg(_args, as, &argc, &ti->error);
+	r = dm_read_arg_group(_args, as, &argc, &ti->error);
 	if (r)
 		return -EINVAL;
 
-	if (argc > as->argc) {
-		ti->error = "not enough arguments for pool features";
-		return -EINVAL;
-	}
-
 	while (argc && !r) {
 		arg_name = dm_shift_arg(as);
 		argc--;
@@ -1512,7 +1508,7 @@ static int parse_pool_features(struct dm
 			continue;
 		}
 
-		ti->error = "Unrecognised pool feature request";
+		ti->error = "Unrecognised pool feature requested";
 		r = -EINVAL;
 	}
 
@@ -1520,11 +1516,13 @@ static int parse_pool_features(struct dm
 }
 
 /*
- * thin-pool <metadata dev>
- *           <data dev>
- *           <data block size in sectors>
- *           <low water mark (sectors)>
- *           [<#feature args> [<arg>]*]
+ * thin-pool <metadata dev> <data dev>
+ *	     <data block size (sectors)>
+ *	     <low water mark (sectors)>
+ *	     [<#feature args> [<arg>]*]
+ *
+ * Optional feature arguments are:
+ *	     skip_block_zeroing: skips the zeroing of newly-provisioned blocks
  */
 static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv)
 {
@@ -1536,7 +1534,7 @@ static int pool_ctr(struct dm_target *ti
 	struct dm_dev *data_dev;
 	unsigned long block_size;
 	dm_block_t low_water;
-	const char *metadata_devname;
+	const char *metadata_path;
 	char *end;
 
 	if (argc < 4) {
@@ -1546,7 +1544,7 @@ static int pool_ctr(struct dm_target *ti
 	as.argc = argc;
 	as.argv = argv;
 
-	metadata_devname = argv[0];
+	metadata_path = argv[0];
 
 	r = dm_get_device(ti, argv[1], FMODE_READ | FMODE_WRITE, &data_dev);
 	if (r) {
@@ -1568,7 +1566,9 @@ static int pool_ctr(struct dm_target *ti
 		goto out;
 	}
 
-	/* set pool feature defaults */
+	/*
+	 * Set default pool features.
+	 */
 	memset(&pf, 0, sizeof(pf));
 	pf.zero_new_blocks = 1;
 
@@ -1577,7 +1577,7 @@ static int pool_ctr(struct dm_target *ti
 	if (r)
 		goto out;
 
-	pool = pool_find(get_target_bdev(ti), metadata_devname,
+	pool = pool_find(get_target_bdev(ti), metadata_path,
 			 block_size, &ti->error);
 	if (IS_ERR(pool)) {
 		r = PTR_ERR(pool);
@@ -1684,7 +1684,7 @@ static int pool_preresume(struct dm_targ
 
 	/* The pool object is only present if the pool is active */
 	pool->pool_dev = get_target_bdev(ti);
-	bdev_table_insert(&bdev_table_, pool);
+	bdev_table_insert(pool);
 
 	return 0;
 }
@@ -1708,7 +1708,7 @@ static void pool_postsuspend(struct dm_t
 	struct pool_c *pt = ti->private;
 	struct pool *pool = pt->pool;
 
-	bdev_table_remove(&bdev_table_, pool);
+	bdev_table_remove(pool);
 	pool->pool_dev = NULL;
 }
 
@@ -1978,9 +1978,9 @@ static void thin_dtr(struct dm_target *t
 }
 
 /*
- * Construct a thin device:
+ * Thin target parameters:
  *
- * <start> <length> thin <pool dev> <dev id>
+ * <pool dev> <dev id>
  *
  * pool dev: the path to the pool (eg, /dev/mapper/my_pool)
  * dev id: the internal device identifier
@@ -2017,7 +2017,7 @@ static int thin_ctr(struct dm_target *ti
 		goto bad_dev_id;
 	}
 
-	mc->pool = bdev_table_lookup(&bdev_table_, mc->pool_dev->bdev);
+	mc->pool = bdev_table_lookup(mc->pool_dev->bdev);
 	if (!mc->pool) {
 		ti->error = "Couldn't find pool object";
 		r = -EINVAL;
@@ -2121,7 +2121,7 @@ static int thin_iterate_devices(struct d
 	struct thin_c *mc = ti->private;
 	struct pool *pool;
 
-	pool = bdev_table_lookup(&bdev_table_, mc->pool_dev->bdev);
+	pool = bdev_table_lookup(mc->pool_dev->bdev);
 	if (!pool) {
 		DMERR("%s: Couldn't find pool object", __func__);
 		return -EINVAL;
@@ -2135,7 +2135,7 @@ static void thin_io_hints(struct dm_targ
 	struct thin_c *mc = ti->private;
 	struct pool *pool;
 
-	pool = bdev_table_lookup(&bdev_table_, mc->pool_dev->bdev);
+	pool = bdev_table_lookup(mc->pool_dev->bdev);
 	if (!pool) {
 		DMERR("%s: Couldn't find pool object", __func__);
 		return;
@@ -2177,7 +2177,7 @@ static int __init dm_thin_init(void)
 	if (r)
 		dm_unregister_target(&thin_target);
 
-	bdev_table_init(&bdev_table_);
+	bdev_table_init();
 	return r;
 }
 
