Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 04535d27 authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull device mapper changes from Mike Snitzer:

 - Fix dm-cache corruption caused by discard_block_size > cache_block_size

 - Fix a lock-inversion detected by LOCKDEP in dm-cache

 - Fix a dangling bio bug in the dm-thinp target's process_deferred_bios
   error path

 - Fix corruption due to non-atomic transaction commit which allowed a
   metadata superblock to be written before all other metadata was
   successfully written -- this is common to all targets that use the
   persistent-data library's transaction manager (dm-thinp, dm-cache and
   dm-era).

 - Various small cleanups in the DM core

 - Add the dm-era target which is useful for keeping track of which
   blocks were written within a user defined period of time called an
   'era'.  Use cases include tracking changed blocks for backup
   software, and partially invalidating the contents of a cache to
   restore cache coherency after rolling back a vendor snapshot.

 - Improve the on-disk layout of multithreaded writes to the
   dm-thin-pool by splitting the pool's deferred bio list to be a
   per-thin device list and then sorting that list using an rb_tree.
   The subsequent read throughput of the data written via multiple
   threads improved by ~70%.

 - Simplify the multipath target's handling of queuing IO by pushing
   requests back to the request queue rather than queueing the IO
   internally.

* tag 'dm-3.15-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: (24 commits)
  dm cache: fix a lock-inversion
  dm thin: sort the per thin deferred bios using an rb_tree
  dm thin: use per thin device deferred bio lists
  dm thin: simplify pool_is_congested
  dm thin: fix dangling bio in process_deferred_bios error path
  dm mpath: print more useful warnings in multipath_message()
  dm-mpath: do not activate failed paths
  dm mpath: remove extra nesting in map function
  dm mpath: remove map_io()
  dm mpath: reduce memory pressure when requeuing
  dm mpath: remove process_queued_ios()
  dm mpath: push back requests instead of queueing
  dm table: add dm_table_run_md_queue_async
  dm mpath: do not call pg_init when it is already running
  dm: use RCU_INIT_POINTER instead of rcu_assign_pointer in __unbind
  dm: stop using bi_private
  dm: remove dm_get_mapinfo
  dm: make dm_table_alloc_md_mempools static
  dm: take care to copy the space map roots before locking the superblock
  dm transaction manager: fix corruption due to non-atomic transaction commit
  ...
parents 3f583bc2 0596661f
Loading
Loading
Loading
Loading
+108 −0
Original line number Diff line number Diff line
Introduction
============

dm-era is a target that behaves similar to the linear target.  In
addition it keeps track of which blocks were written within a user
defined period of time called an 'era'.  Each era target instance
maintains the current era as a monotonically increasing 32-bit
counter.

Use cases include tracking changed blocks for backup software, and
partially invalidating the contents of a cache to restore cache
coherency after rolling back a vendor snapshot.

Constructor
===========

 era <metadata dev> <origin dev> <block size>

 metadata dev    : fast device holding the persistent metadata
 origin dev	 : device holding data blocks that may change
 block size      : block size of origin data device, granularity that is
		     tracked by the target

Messages
========

None of the dm messages take any arguments.

checkpoint
----------

Possibly move to a new era.  You shouldn't assume the era has
incremented.  After sending this message, you should check the
current era via the status line.

take_metadata_snap
------------------

Create a clone of the metadata, to allow a userland process to read it.

drop_metadata_snap
------------------

Drop the metadata snapshot.

Status
======

<metadata block size> <#used metadata blocks>/<#total metadata blocks>
<current era> <held metadata root | '-'>

metadata block size	 : Fixed block size for each metadata block in
			     sectors
#used metadata blocks	 : Number of metadata blocks used
#total metadata blocks	 : Total number of metadata blocks
current era		 : The current era
held metadata root	 : The location, in blocks, of the metadata root
			     that has been 'held' for userspace read
			     access. '-' indicates there is no held root

Detailed use case
=================

The scenario of invalidating a cache when rolling back a vendor
snapshot was the primary use case when developing this target:

Taking a vendor snapshot
------------------------

- Send a checkpoint message to the era target
- Make a note of the current era in its status line
- Take vendor snapshot (the era and snapshot should be forever
  associated now).

Rolling back to an vendor snapshot
----------------------------------

- Cache enters passthrough mode (see: dm-cache's docs in cache.txt)
- Rollback vendor storage
- Take metadata snapshot
- Ascertain which blocks have been written since the snapshot was taken
  by checking each block's era
- Invalidate those blocks in the caching software
- Cache returns to writeback/writethrough mode

Memory usage
============

The target uses a bitset to record writes in the current era.  It also
has a spare bitset ready for switching over to a new era.  Other than
that it uses a few 4k blocks for updating metadata.

   (4 * nr_blocks) bytes + buffers

Resilience
==========

Metadata is updated on disk before a write to a previously unwritten
block is performed.  As such dm-era should not be effected by a hard
crash such as power failure.

Userland tools
==============

Userland tools are found in the increasingly poorly named
thin-provisioning-tools project:

    https://github.com/jthornber/thin-provisioning-tools
+11 −0
Original line number Diff line number Diff line
@@ -285,6 +285,17 @@ config DM_CACHE_CLEANER
         A simple cache policy that writes back all data to the
         origin.  Used when decommissioning a dm-cache.

config DM_ERA
       tristate "Era target (EXPERIMENTAL)"
       depends on BLK_DEV_DM
       default n
       select DM_PERSISTENT_DATA
       select DM_BIO_PRISON
       ---help---
         dm-era tracks which parts of a block device are written to
         over time.  Useful for maintaining cache coherency when using
         vendor snapshots.

config DM_MIRROR
       tristate "Mirror target"
       depends on BLK_DEV_DM
+2 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ dm-thin-pool-y += dm-thin.o dm-thin-metadata.o
dm-cache-y	+= dm-cache-target.o dm-cache-metadata.o dm-cache-policy.o
dm-cache-mq-y   += dm-cache-policy-mq.o
dm-cache-cleaner-y += dm-cache-policy-cleaner.o
dm-era-y	+= dm-era-target.o
md-mod-y	+= md.o bitmap.o
raid456-y	+= raid5.o

@@ -53,6 +54,7 @@ obj-$(CONFIG_DM_VERITY) += dm-verity.o
obj-$(CONFIG_DM_CACHE)		+= dm-cache.o
obj-$(CONFIG_DM_CACHE_MQ)	+= dm-cache-mq.o
obj-$(CONFIG_DM_CACHE_CLEANER)	+= dm-cache-cleaner.o
obj-$(CONFIG_DM_ERA)		+= dm-era.o

ifeq ($(CONFIG_DM_UEVENT),y)
dm-mod-objs			+= dm-uevent.o
+0 −11
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@

typedef dm_block_t __bitwise__ dm_oblock_t;
typedef uint32_t __bitwise__ dm_cblock_t;
typedef dm_block_t __bitwise__ dm_dblock_t;

static inline dm_oblock_t to_oblock(dm_block_t b)
{
@@ -41,14 +40,4 @@ static inline uint32_t from_cblock(dm_cblock_t b)
	return (__force uint32_t) b;
}

static inline dm_dblock_t to_dblock(dm_block_t b)
{
	return (__force dm_dblock_t) b;
}

static inline dm_block_t from_dblock(dm_dblock_t b)
{
	return (__force dm_block_t) b;
}

#endif /* DM_CACHE_BLOCK_TYPES_H */
+74 −58
Original line number Diff line number Diff line
@@ -109,7 +109,7 @@ struct dm_cache_metadata {
	dm_block_t discard_root;

	sector_t discard_block_size;
	dm_dblock_t discard_nr_blocks;
	dm_oblock_t discard_nr_blocks;

	sector_t data_block_size;
	dm_cblock_t cache_blocks;
@@ -120,6 +120,12 @@ struct dm_cache_metadata {
	unsigned policy_version[CACHE_POLICY_VERSION_SIZE];
	size_t policy_hint_size;
	struct dm_cache_statistics stats;

	/*
	 * Reading the space map root can fail, so we read it into this
	 * buffer before the superblock is locked and updated.
	 */
	__u8 metadata_space_map_root[SPACE_MAP_ROOT_SIZE];
};

/*-------------------------------------------------------------------
@@ -260,11 +266,31 @@ static void __setup_mapping_info(struct dm_cache_metadata *cmd)
	}
}

static int __save_sm_root(struct dm_cache_metadata *cmd)
{
	int r;
	size_t metadata_len;

	r = dm_sm_root_size(cmd->metadata_sm, &metadata_len);
	if (r < 0)
		return r;

	return dm_sm_copy_root(cmd->metadata_sm, &cmd->metadata_space_map_root,
			       metadata_len);
}

static void __copy_sm_root(struct dm_cache_metadata *cmd,
			   struct cache_disk_superblock *disk_super)
{
	memcpy(&disk_super->metadata_space_map_root,
	       &cmd->metadata_space_map_root,
	       sizeof(cmd->metadata_space_map_root));
}

static int __write_initial_superblock(struct dm_cache_metadata *cmd)
{
	int r;
	struct dm_block *sblock;
	size_t metadata_len;
	struct cache_disk_superblock *disk_super;
	sector_t bdev_size = i_size_read(cmd->bdev->bd_inode) >> SECTOR_SHIFT;

@@ -272,12 +298,16 @@ static int __write_initial_superblock(struct dm_cache_metadata *cmd)
	if (bdev_size > DM_CACHE_METADATA_MAX_SECTORS)
		bdev_size = DM_CACHE_METADATA_MAX_SECTORS;

	r = dm_sm_root_size(cmd->metadata_sm, &metadata_len);
	r = dm_tm_pre_commit(cmd->tm);
	if (r < 0)
		return r;

	r = dm_tm_pre_commit(cmd->tm);
	if (r < 0)
	/*
	 * dm_sm_copy_root() can fail.  So we need to do it before we start
	 * updating the superblock.
	 */
	r = __save_sm_root(cmd);
	if (r)
		return r;

	r = superblock_lock_zero(cmd, &sblock);
@@ -293,16 +323,13 @@ static int __write_initial_superblock(struct dm_cache_metadata *cmd)
	memset(disk_super->policy_version, 0, sizeof(disk_super->policy_version));
	disk_super->policy_hint_size = 0;

	r = dm_sm_copy_root(cmd->metadata_sm, &disk_super->metadata_space_map_root,
			    metadata_len);
	if (r < 0)
		goto bad_locked;
	__copy_sm_root(cmd, disk_super);

	disk_super->mapping_root = cpu_to_le64(cmd->root);
	disk_super->hint_root = cpu_to_le64(cmd->hint_root);
	disk_super->discard_root = cpu_to_le64(cmd->discard_root);
	disk_super->discard_block_size = cpu_to_le64(cmd->discard_block_size);
	disk_super->discard_nr_blocks = cpu_to_le64(from_dblock(cmd->discard_nr_blocks));
	disk_super->discard_nr_blocks = cpu_to_le64(from_oblock(cmd->discard_nr_blocks));
	disk_super->metadata_block_size = cpu_to_le32(DM_CACHE_METADATA_BLOCK_SIZE >> SECTOR_SHIFT);
	disk_super->data_block_size = cpu_to_le32(cmd->data_block_size);
	disk_super->cache_blocks = cpu_to_le32(0);
@@ -313,10 +340,6 @@ static int __write_initial_superblock(struct dm_cache_metadata *cmd)
	disk_super->write_misses = cpu_to_le32(0);

	return dm_tm_commit(cmd->tm, sblock);

bad_locked:
	dm_bm_unlock(sblock);
	return r;
}

static int __format_metadata(struct dm_cache_metadata *cmd)
@@ -496,7 +519,7 @@ static void read_superblock_fields(struct dm_cache_metadata *cmd,
	cmd->hint_root = le64_to_cpu(disk_super->hint_root);
	cmd->discard_root = le64_to_cpu(disk_super->discard_root);
	cmd->discard_block_size = le64_to_cpu(disk_super->discard_block_size);
	cmd->discard_nr_blocks = to_dblock(le64_to_cpu(disk_super->discard_nr_blocks));
	cmd->discard_nr_blocks = to_oblock(le64_to_cpu(disk_super->discard_nr_blocks));
	cmd->data_block_size = le32_to_cpu(disk_super->data_block_size);
	cmd->cache_blocks = to_cblock(le32_to_cpu(disk_super->cache_blocks));
	strncpy(cmd->policy_name, disk_super->policy_name, sizeof(cmd->policy_name));
@@ -530,8 +553,9 @@ static int __begin_transaction_flags(struct dm_cache_metadata *cmd,
	disk_super = dm_block_data(sblock);
	update_flags(disk_super, mutator);
	read_superblock_fields(cmd, disk_super);
	dm_bm_unlock(sblock);

	return dm_bm_flush_and_unlock(cmd->bm, sblock);
	return dm_bm_flush(cmd->bm);
}

static int __begin_transaction(struct dm_cache_metadata *cmd)
@@ -559,7 +583,6 @@ static int __commit_transaction(struct dm_cache_metadata *cmd,
				flags_mutator mutator)
{
	int r;
	size_t metadata_len;
	struct cache_disk_superblock *disk_super;
	struct dm_block *sblock;

@@ -577,8 +600,8 @@ static int __commit_transaction(struct dm_cache_metadata *cmd,
	if (r < 0)
		return r;

	r = dm_sm_root_size(cmd->metadata_sm, &metadata_len);
	if (r < 0)
	r = __save_sm_root(cmd);
	if (r)
		return r;

	r = superblock_lock(cmd, &sblock);
@@ -594,7 +617,7 @@ static int __commit_transaction(struct dm_cache_metadata *cmd,
	disk_super->hint_root = cpu_to_le64(cmd->hint_root);
	disk_super->discard_root = cpu_to_le64(cmd->discard_root);
	disk_super->discard_block_size = cpu_to_le64(cmd->discard_block_size);
	disk_super->discard_nr_blocks = cpu_to_le64(from_dblock(cmd->discard_nr_blocks));
	disk_super->discard_nr_blocks = cpu_to_le64(from_oblock(cmd->discard_nr_blocks));
	disk_super->cache_blocks = cpu_to_le32(from_cblock(cmd->cache_blocks));
	strncpy(disk_super->policy_name, cmd->policy_name, sizeof(disk_super->policy_name));
	disk_super->policy_version[0] = cpu_to_le32(cmd->policy_version[0]);
@@ -605,13 +628,7 @@ static int __commit_transaction(struct dm_cache_metadata *cmd,
	disk_super->read_misses = cpu_to_le32(cmd->stats.read_misses);
	disk_super->write_hits = cpu_to_le32(cmd->stats.write_hits);
	disk_super->write_misses = cpu_to_le32(cmd->stats.write_misses);

	r = dm_sm_copy_root(cmd->metadata_sm, &disk_super->metadata_space_map_root,
			    metadata_len);
	if (r < 0) {
		dm_bm_unlock(sblock);
		return r;
	}
	__copy_sm_root(cmd, disk_super);

	return dm_tm_commit(cmd->tm, sblock);
}
@@ -771,15 +788,15 @@ int dm_cache_resize(struct dm_cache_metadata *cmd, dm_cblock_t new_cache_size)

int dm_cache_discard_bitset_resize(struct dm_cache_metadata *cmd,
				   sector_t discard_block_size,
				   dm_dblock_t new_nr_entries)
				   dm_oblock_t new_nr_entries)
{
	int r;

	down_write(&cmd->root_lock);
	r = dm_bitset_resize(&cmd->discard_info,
			     cmd->discard_root,
			     from_dblock(cmd->discard_nr_blocks),
			     from_dblock(new_nr_entries),
			     from_oblock(cmd->discard_nr_blocks),
			     from_oblock(new_nr_entries),
			     false, &cmd->discard_root);
	if (!r) {
		cmd->discard_block_size = discard_block_size;
@@ -792,28 +809,28 @@ int dm_cache_discard_bitset_resize(struct dm_cache_metadata *cmd,
	return r;
}

static int __set_discard(struct dm_cache_metadata *cmd, dm_dblock_t b)
static int __set_discard(struct dm_cache_metadata *cmd, dm_oblock_t b)
{
	return dm_bitset_set_bit(&cmd->discard_info, cmd->discard_root,
				 from_dblock(b), &cmd->discard_root);
				 from_oblock(b), &cmd->discard_root);
}

static int __clear_discard(struct dm_cache_metadata *cmd, dm_dblock_t b)
static int __clear_discard(struct dm_cache_metadata *cmd, dm_oblock_t b)
{
	return dm_bitset_clear_bit(&cmd->discard_info, cmd->discard_root,
				   from_dblock(b), &cmd->discard_root);
				   from_oblock(b), &cmd->discard_root);
}

static int __is_discarded(struct dm_cache_metadata *cmd, dm_dblock_t b,
static int __is_discarded(struct dm_cache_metadata *cmd, dm_oblock_t b,
			  bool *is_discarded)
{
	return dm_bitset_test_bit(&cmd->discard_info, cmd->discard_root,
				  from_dblock(b), &cmd->discard_root,
				  from_oblock(b), &cmd->discard_root,
				  is_discarded);
}

static int __discard(struct dm_cache_metadata *cmd,
		     dm_dblock_t dblock, bool discard)
		     dm_oblock_t dblock, bool discard)
{
	int r;

@@ -826,7 +843,7 @@ static int __discard(struct dm_cache_metadata *cmd,
}

int dm_cache_set_discard(struct dm_cache_metadata *cmd,
			 dm_dblock_t dblock, bool discard)
			 dm_oblock_t dblock, bool discard)
{
	int r;

@@ -844,8 +861,8 @@ static int __load_discards(struct dm_cache_metadata *cmd,
	dm_block_t b;
	bool discard;

	for (b = 0; b < from_dblock(cmd->discard_nr_blocks); b++) {
		dm_dblock_t dblock = to_dblock(b);
	for (b = 0; b < from_oblock(cmd->discard_nr_blocks); b++) {
		dm_oblock_t dblock = to_oblock(b);

		if (cmd->clean_when_opened) {
			r = __is_discarded(cmd, dblock, &discard);
@@ -1228,22 +1245,12 @@ static int begin_hints(struct dm_cache_metadata *cmd, struct dm_cache_policy *po
	return 0;
}

int dm_cache_begin_hints(struct dm_cache_metadata *cmd, struct dm_cache_policy *policy)
static int save_hint(void *context, dm_cblock_t cblock, dm_oblock_t oblock, uint32_t hint)
{
	struct dm_cache_metadata *cmd = context;
	__le32 value = cpu_to_le32(hint);
	int r;

	down_write(&cmd->root_lock);
	r = begin_hints(cmd, policy);
	up_write(&cmd->root_lock);

	return r;
}

static int save_hint(struct dm_cache_metadata *cmd, dm_cblock_t cblock,
		     uint32_t hint)
{
	int r;
	__le32 value = cpu_to_le32(hint);
	__dm_bless_for_disk(&value);

	r = dm_array_set_value(&cmd->hint_info, cmd->hint_root,
@@ -1253,16 +1260,25 @@ static int save_hint(struct dm_cache_metadata *cmd, dm_cblock_t cblock,
	return r;
}

int dm_cache_save_hint(struct dm_cache_metadata *cmd, dm_cblock_t cblock,
		       uint32_t hint)
static int write_hints(struct dm_cache_metadata *cmd, struct dm_cache_policy *policy)
{
	int r;

	if (!hints_array_initialized(cmd))
		return 0;
	r = begin_hints(cmd, policy);
	if (r) {
		DMERR("begin_hints failed");
		return r;
	}

	return policy_walk_mappings(policy, save_hint, cmd);
}

int dm_cache_write_hints(struct dm_cache_metadata *cmd, struct dm_cache_policy *policy)
{
	int r;

	down_write(&cmd->root_lock);
	r = save_hint(cmd, cblock, hint);
	r = write_hints(cmd, policy);
	up_write(&cmd->root_lock);

	return r;
Loading