# dm-era

_Peios Kernel / Administration / System administration / Device mapper_

> 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…

<a id="rst-dm-era"></a>

<a id="rst-introduction"></a>

## 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.

<a id="rst-constructor"></a>

## Constructor

era &lt;metadata dev&gt; &lt;origin dev&gt; &lt;block size&gt;

>
> <table>
> <tbody>
> <tr>
> <td>
>
>
> metadata dev
>
> </td>
> <td>
>
>
> fast device holding the persistent metadata
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> origin dev
>
> </td>
> <td>
>
>
> device holding data blocks that may change
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> block size
>
> </td>
> <td>
>
>
> block size of origin data device, granularity that is tracked by the target
>
> </td>
> </tr>
> </tbody>
> </table>

<a id="rst-messages"></a>

## Messages

None of the dm messages take any arguments.

<a id="rst-checkpoint"></a>

### 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.

<a id="rst-take-metadata-snap"></a>

### take_metadata_snap

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

<a id="rst-drop-metadata-snap"></a>

### drop_metadata_snap

Drop the metadata snapshot.

<a id="rst-status"></a>

## Status

&lt;metadata block size&gt; &lt;\#used metadata blocks&gt;/&lt;\#total metadata blocks&gt; &lt;current era&gt; &lt;held metadata root \| '-'&gt;


<table>
<tbody>
<tr>
<td>


metadata block size

</td>
<td>


Fixed block size for each metadata block in sectors

</td>
</tr>
<tr>
<td>


\#used metadata blocks

</td>
<td>


Number of metadata blocks used

</td>
</tr>
<tr>
<td>


\#total metadata blocks

</td>
<td>


Total number of metadata blocks

</td>
</tr>
<tr>
<td>


current era

</td>
<td>


The current era

</td>
</tr>
<tr>
<td>


held metadata root

</td>
<td>


The location, in blocks, of the metadata root that has been 'held' for userspace read access. '-' indicates there is no held root

</td>
</tr>
</tbody>
</table>

<a id="rst-detailed-use-case"></a>

## Detailed use case

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

<a id="rst-taking-a-vendor-snapshot"></a>

### 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).

<a id="rst-rolling-back-to-an-vendor-snapshot"></a>

### 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

<a id="rst-memory-usage"></a>

## 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:



```text
(4 * nr_blocks) bytes + buffers
```

<a id="rst-resilience"></a>

## 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.

<a id="rst-userland-tools"></a>

## Userland tools

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

> [https://github.com/jthornber/thin-provisioning-tools](<https://github.com/jthornber/thin-provisioning-tools>)
