Concept Of Device Mapper Target



Device mapper layer - explored



Every storage system requires viewing the real disks in their own way. For example, if there are four disk and the system wants to create mirroring over them or concatenate them viewing them as a single big device or if there is one disk, then a particular system may want to encrypt all the data that is going to be stored on that disk i.e. all such systems want a logical layer of block devices on the top of existing underlying block devices and map the requests on this logical layer to underlying layer after doing particular processing at this layer. This facility is provided by device mapper.Device mapper can be defined as a generic way to add required functionality in the storage stack by creating virtual layer of block devices and mapping them to existing block devices. It create virtual layers of block devices that can do different things on top of existing underlying block devices like striping, concatenation, mirroring, snapshot, etc.The Device Mapper is a modular kernel driver that provides a generic framework for volume management. It has been introduced in the kernel version 2.6. The device-mapper is used by the LVM2 and EVMS 2.x tools.LVM is a tool which allows creating and managing partitions. The first version of LVM is in kernel 2.4 where there is no concept of device mapper. So, all the management of logical layer was the responsibility of LVM. But, due to the concept of device mapper in kernel 2.6, the logical layer management is done by device mapper and the code of LVM2 has been simplified to a great extent. This also brings modularity and reusability in the kernel.

The concept of device mapper target:


As stated above, we can create various logical layers through device mapper to carry out the required functionality. Each such layer is created by defining “a device mapper target” for that layer.There is one to one correspondence between a virtual layer at device mapper layer and the dm target for that layer. The particular dm target contains the code which does the task of  implementing functionality which the virtual layer intends to do. For example, a device mapper target can be written to implement mirroring over existing block devices. This dm target shows a virtual layer to upper layers which does the task of mirroring.Currently seven such features have been added to device mapper through seven device mapper targets. The device mapper targets are as follows:

 Linear
This dm target allows us to concatenate number of disks to view them as a single big device or to view a part of disk as an individual logical disk. Thus, it creates a linear logical device on the top of existing block devices.

 RAID-0 / Striped
The striped dm target is designed to handle striping across physical volumes i.e. to carry out well known RAID-0 functionality.

 RAID-1 / Mirrored RAID
The mirrored dm target is designed to handle mirroring across number of disks. It carries out one of most famous RAID level functionality by creating and maintaining number of mirrors of data which all contain same data to improve reliability and speed of operations through load balancing.

 Snapshot
This dm target carries out the functionality of snapshot and allows accessing the older versions of all files along with the latest one.

 DM-Crypt
The dm-crypt device mapper target does the task of providing security through encrypting and decrypting of all the data that gets stored on the disk.

 Multipath  
In order to provide higher reliability for accessing the disks, this dm target provides a functionality of multipath so that in case of failure of path to disk, data on the disk can be accessed through alternative path.

 Zero
The zero dm target returns all the data as zero for all the operations on the disk. Generally it is used for testing and to fill the gaps in new logical device.

 Error
The error dm target causes any I/O to the mapped disk to fail.  This also is useful for defining gaps in the new logical device.

Such device mapper target can be inserted into the kernel as a module and removed as per wish of the user. Or it can also be inserted into the kernel by creating its patch.Device mapper creates a logical layer of block devices and maps all the I/O requests on this logical layer to underlying existing block devices. For such mapping, device mapper uses a data structure called device mapper table. This table tells us how each and every sector (of size512 bytes) of a logical layer is mapped to a sector on underlying disk. Thus, each target carries out its functionality by doing I/O mapping using its corresponding device mapper table.

So last but not least, Device mapper target represents a type of block device.
Now the " ability to define the type of  block device is provided by device mapper"  so that is why it is generic layer.
So when we want to provide a new type of block device with some advance functionality like snapshots, deduplication. we create new device mapper target, we write logic of the new functionality into that device mapper target.And we can create block devices of that device mapper target. (i.e new type of device ).

No comments: