All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Thornber <thornber@redhat.com>
To: device-mapper development <dm-devel@redhat.com>,
	Alasdair G Kergon <agk@redhat.com>, Joe Thornber <ejt@redhat.com>
Subject: Re: [PATCH] dm thin: fix pool target flags that control discard
Date: Mon, 26 Mar 2012 16:34:39 +0100	[thread overview]
Message-ID: <20120326153438.GA26558@ubuntu> (raw)
In-Reply-To: <20120326141520.GA24249@ubuntu>

On Mon, Mar 26, 2012 at 03:15:21PM +0100, Joe Thornber wrote:
> > o disallow disabling discards if a pool was already configured with
> >   discards enabled (the default)
> >   - justification is inlined in the code
> >   - required pool_ctr knowing whether pool was created or not; so added
> >     'created' flag to __pool_find()
> 
> ack, this needs fixing.

The following patch prevents people changing the top-level discard
flag when reloading a pool target.

I'll push this test in a bit (dm-cache changes holding things up).

  # we don't allow people to change their minds about top level                                                                                                    
  # discard support.                                                                                                                                               
  def test_change_discard_with_reload_fails
    with_standard_pool(@size, :discard => true) do |pool|
      assert_raise(ExitError) do
        table = Table.new(ThinPool.new(@size, @metadata_dev, @data_dev,
                                       @data_block_size, @low_water_mark, false, false, false))
        pool.load(table)
      end
    end

    with_standard_pool(@size, :discard => false) do |pool|
      assert_raise(ExitError) do
        table = Table.new(ThinPool.new(@size, @metadata_dev, @data_dev,
                                       @data_block_size, @low_water_mark, false, true, false))
        pool.load(table)
      end
    end
  end


- Joe


commit 9f075e7f5330039addba213a0f512ab7c0ea3ecf
Author: Joe Thornber <ejt@redhat.com>
Date:   Mon Mar 26 16:26:33 2012 +0100

    dm-thin: don't allow the top level discard flag to be changed on reload.

diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c
index e8fe5db..e5a6ed4 100644
--- a/drivers/md/dm-thin.c
+++ b/drivers/md/dm-thin.c
@@ -1445,10 +1445,12 @@ static void __pool_dec(struct pool *pool)
 
 static struct pool *__pool_find(struct mapped_device *pool_md,
 				struct block_device *metadata_dev,
-				unsigned long block_size, char **error)
+				unsigned long block_size, char **error,
+				int *created)
 {
 	struct pool *pool = __pool_table_lookup_metadata_dev(metadata_dev);
 
+	*created = 0;
 	if (pool) {
 		if (pool->pool_md != pool_md)
 			return ERR_PTR(-EBUSY);
@@ -1461,8 +1463,10 @@ static struct pool *__pool_find(struct mapped_device *pool_md,
 				return ERR_PTR(-EINVAL);
 			__pool_inc(pool);
 
-		} else
+		} else {
 			pool = pool_create(pool_md, metadata_dev, block_size, error);
+			*created = 1;
+		}
 	}
 
 	return pool;
@@ -1542,7 +1546,7 @@ static int parse_pool_features(struct dm_arg_set *as, struct pool_features *pf,
  */
 static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv)
 {
-	int r;
+	int r, pool_created;
 	struct pool_c *pt;
 	struct pool *pool;
 	struct pool_features pf;
@@ -1617,12 +1621,24 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv)
 	}
 
 	pool = __pool_find(dm_table_get_md(ti->table), metadata_dev->bdev,
-			   block_size, &ti->error);
+			   block_size, &ti->error, &pool_created);
 	if (IS_ERR(pool)) {
 		r = PTR_ERR(pool);
 		goto out_free_pt;
 	}
 
+	/*
+	 * 'pool_created' reflects whether this is the first table load.
+	 * Top level discard support is not allowed to be changed after
+	 * initial load.  This would require a pool reload to trigger thin
+	 * device changes.
+	 */
+	if (!pool_created && pf.discard_enabled != pool->pf.discard_enabled) {
+		ti->error = "Discard support cannot be changed once enabled";
+		r = -EINVAL;
+		goto out_flags_changed;
+	}
+
 	pt->pool = pool;
 	pt->ti = ti;
 	pt->metadata_dev = metadata_dev;
@@ -1643,6 +1659,8 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv)
 
 	return 0;
 
+out_flags_changed:
+	__pool_dec(pool);
 out_free_pt:
 	kfree(pt);
 out:

  parent reply	other threads:[~2012-03-26 15:34 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-16 15:21 dm-thin patches for 3.4 Joe Thornber
2012-03-16 15:22 ` [PATCH 01/14] dm-thin: don't use the bi_next field for the holder of a cell Joe Thornber
2012-03-16 15:22   ` [PATCH 02/14] dm-thin: remove some documentation for the unimplemented 'trim' target message Joe Thornber
2012-03-16 15:22   ` [PATCH 03/14] dm_thin: dm_sm_root_size() was being called for the wrong space-map Joe Thornber
2012-03-16 15:22   ` [PATCH 04/14] dm_thin: tweak a comment Joe Thornber
2012-03-16 15:22   ` [PATCH 05/14] dm_btree: remove redundant arg from value_ptr() Joe Thornber
2012-03-16 15:22   ` [PATCH 06/14] dm_btree: fix rebalancing of 3 nodes after remove Joe Thornber
2012-03-16 15:22   ` [PATCH 07/14] dm_space_map: remove entries from the ref_count tree if they're no longer needed Joe Thornber
2012-03-16 15:22   ` [PATCH 08/14] dm_thin: add support for read-only external snapshot origins Joe Thornber
2012-03-16 15:22   ` [PATCH 09/14] dm_thin: foundation for discard support Joe Thornber
2012-03-16 15:22   ` [PATCH 10/14] dm_thin: add support for REQ_DISCARD Joe Thornber
2012-03-23 12:45     ` Alasdair G Kergon
2012-03-16 15:22   ` [PATCH 11/14] dm_thin: add pool target flags to control discard Joe Thornber
2012-03-23 12:37     ` Alasdair G Kergon
2012-03-23 21:55       ` [PATCH] dm thin: fix pool target flags that " Mike Snitzer
2012-03-26 14:15         ` Joe Thornber
2012-03-26 15:33           ` Mike Snitzer
2012-03-26 19:56             ` Mike Snitzer
2012-03-26 15:34           ` Joe Thornber [this message]
2012-03-26 15:46           ` [PATCH] " Joe Thornber
2012-03-16 15:22   ` [PATCH 12/14] dm_thin: commit metadata every second Joe Thornber
2012-03-16 15:22   ` [PATCH 13/14] dm_thin: commit just before processing a pool target info request Joe Thornber
2012-03-19 14:00     ` Alasdair G Kergon
2012-03-20 10:12       ` Joe Thornber
2012-03-16 15:22   ` [PATCH 14/14] dm_thin: bump the target versions Joe Thornber
2012-03-20 18:24   ` [PATCH 01/14] dm-thin: don't use the bi_next field for the holder of a cell Alasdair G Kergon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120326153438.GA26558@ubuntu \
    --to=thornber@redhat.com \
    --cc=agk@redhat.com \
    --cc=dm-devel@redhat.com \
    --cc=ejt@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.