dm: sync cache and thin changes that agk staged in linux-next for v3.9
dm cache: fix leak of ctr_args
dm: sync with nearly all v3.9-rc1 DM changes

Only things held back were the hlist_for_each_entry and idr changes.
dm cache: fix writethrough implementation

When the cache is in writethrough mode it needs to send WRITE bios to
both the origin and cache devices.

Previously we've been implementing this by having dm core query the
cache target on every write to find out how many copies of the bio it
wants.  The cache will ask for two bios if the block is in the cache,
and one otherwise.

Then main problem with this is it's racey.  At the time this check is
made the bio hasn't yet been submitted and so isn't being taken into
account when quiescing a block for migration (promotion or demotion).
This means a single bio may be submitted when two were needed because
the block has since been promoted to the cache (catastrophic), or two
bios where only one is needed (harmless).

I really don't want to start entering bios into the quiescing system
(deferred_set) in the get_num_write_bios callback.  Instead this patch
simplifies things; only one bio is submitted by the core, this is
first written to the origin and then the cache device in series.
Obviously this will have a latency impact.

deferred_writethrough_bios is introduced to record bios that must be
later issued to the cache device from the worker thread.  This deferred
submission, after the origin bio completes, is required given that we're
in interrupt context (writethrough_endio).

Signed-off-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
dm cache: avoid double destory of policy in error path

If the cache policy's config values are not able to be set we must avoid
attempting to destroy the policy twice by resetting it to NULL once it
is destroyed in the create_cache_policy error path.

Signed-off-by: Heinz Mauelshagen <heinzm@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
dm cache metadata: set dirty bits to clean on clean shutdown

When writing the dirty bitset to the metadata device on clean shutdown,
dirty bits were never being set to clean.  Harmless bug but this led to
confusion about whether there really was dirty data in the cache or not.

Reported-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
dm cache: fix missing cache_create return check

Missing return check made cache_ctr continue even after an error in
cache_create(); resulting in the cache object being destroyed.  So a
simple failure like an odd number of cache policy config value arguments
would result in an oops.

Signed-off-by: Heinz Mauelshagen <heinzm@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Merge branch 'thin-dev-next' of https://github.com/snitm/linux into mike

Conflicts:
	drivers/md/dm-cache-target.c