dm cache: revert writethrough support for now

(need to sort out DM core conflicts and then come back to this)
dm: revert to v3.7-rc1

this introduces Mikulas' commit dba141601d1 and reverts Joe's
conflicting get_num_duplicates changes for now
dm: reverts mikulas' "dm: store dm_target_io in bio front_pad"

Going to apply all v3.7 changes with proper commits
dm mpath: fix check for null mpio in end_io fn

The mpio dereference should be moved below the BUG_ON NULL test
in multipath_end_io().

spatch with a semantic match was used to found this.
(http://coccinelle.lip6.fr/)

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
dm: use ACCESS_ONCE for sysfs values

Use the ACCESS_ONCE macro in dm-bufio and dm-verity where a variable
can be modified asynchronously (through sysfs) and we want to prevent
compiler optimizations that assume that the variable hasn't changed.
(See Documentation/atomic_ops.txt.)

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
dm: store dm_target_io in bio front_pad

Use the recently-added bio front_pad field to allocate struct dm_target_io.

Prior to this patch, dm_target_io was allocated from a mempool. For each
dm_target_io, there is exactly one bio allocated from a bioset.

This patch merges these two allocations into one allocation: we create a
bioset with front_pad equal to the size of dm_target_io so that every
bio allocated from the bioset has sizeof(struct dm_target_io) bytes
before it. We allocate a bio and use the bytes before the bio as
dm_target_io.

_tio_cache is removed and the tio_pool mempool is now only used for
request-based devices.

This idea was introduced by Kent Overstreet.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Cc: Kent Overstreet <koverstreet@google.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: tj@kernel.org
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Bill Pemberton <wfp5p@viridian.itc.virginia.edu>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
dm raid1: remove impossible mempool_alloc error test

mempool_alloc can't fail if __GFP_WAIT is specified, so the condition
that tests if read_record is non-NULL is always true.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
dm raid: use DM_ENDIO_INCOMPLETE

Use a defined macro DM_ENDIO_INCOMPLETE instead of a numeric constant.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
dm snap: optimize track_chunk

track_chunk is always called with interrupts enabled. Consequently, we
do not need to save and restore interrupt state in "flags" variable.
This patch changes spin_lock_irqsave to spin_lock_irq and
spin_unlock_irqrestore to spin_unlock_irq.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
dm: introduce per request data

Introduce a field per_request_data in struct dm_target.

Targets can set this field in the constructor. If a target sets this
field to non-zero value, "per_request_data" bytes of auxliliary data is
allocated for each bio submitted to the target. These data can be used
for any purpose by the target.

Per-request data is accessed with dm_bio_get_per_request_data. The
argument data_size must be the same as the value per_request_data in
dm_target.

If the target has a pointer to per request data, it can get a pointer to
the bio with dm_per_request_data_get_bio function (data_size must be the
same ast the value passed to dm_bio_get_per_request_data).

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
dm-raid1: use per request data

Remove read_record_pool and use per_request_data instead.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
dm-verity: use per request data

Remove io_mempool and use per_request_data instead.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
dm-snap: use per request data

Remove tracked_chunk_pool and use per_request_data instead.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
dm: move target_request_nr from map_info to dm_target_io

This patch moves target_request_nr from map_info to dm_target_io and
makes it accessible with dm_bio_get_target_request_nr.

This patch is a preparation for the next patch that removes map_info.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
dm-raid1: rename read_record to bio_record

In the following patch, the structure will be used for both read and
write bios, so rename it.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
dm-flakey: don't use map_info

Don't use map_info and use a per-bio structure "struct per_bio_data" instead.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
dm-raid1: don't use map_info

Don't use map_info.

map_info was used for writes to hold the region number (for this purpose
we add a new field dm_bio_details to dm_raid1_bio_record).

map_info was used for reads to hold a pointer to dm_raid1_bio_record (if
the pointer was non-NULL, bio details were saved; if the pointer was
NULL, bio details were not saved). We use
dm_raid1_bio_record.details->bi_bdev for this purpose. If bi_bdev is
NULL, details were not saved, if bi_bdev is non-NULL, details were
saved.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
dm-thin: remove map_info

This patch removes endio_hook_pool from dm-thin uses per-bio data instead.

This patch removes any use of map_info and in preparation for the next patch
that removes map_info from bio-based device mapper.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
dm-snap: don't use map_info

map_info->ptr was used in dm-snap to indicate if the bio was tracked.
If map_info->ptr was non-NULL, the bio was linked in tracked_chunk_hash.

This patch removes the use of map_info->ptr. We determine if the bio was
tracked based on hlist_unhashed(&c->node) --- if hlist_unhashed is true,
the bio is not tracked, if it is false, the bio is tracked.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
dm: remove map_info

This patch removes map_info from bio-based device mapper targets.
map_info is still used for request-based targets.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>