Home > php教程 > PHP开发 > body text

Device Mapper mechanism in the Linux system kernel (1) (4)

黄舟
Release: 2016-12-23 14:10:03
Original
1303 people have browsed it

User space part

Device mapper is relatively simple in user space, mainly including the device mapper library and dmsetup tool. The Device mapper library is an encapsulation of the necessary operations required for ioctl and user space to create and delete device mapper logical devices. dmsetup is a command line tool that provides users with a directly available command line tool for creating and deleting device mapper devices. Because their functions and processes are relatively simple, their details will not be introduced in this article. The user space is mainly responsible for the following work:

1. Discover the target device related to each mapped device;

2. Create based on configuration information Mapping table;

3. Pass the mapping table constructed by user space to the kernel, and let the kernel build the dm_table structure corresponding to the mapped device;

4. Save the current mapping information for future reconstruction.

Below we mainly illustrate the use of dmsetup through examples, and further explain the mapping mechanism of device mapper. The most important work in user space is to build and save the mapping table. Here are some examples of mapping tables:

1)
0 1024 linear /dev/sda 204
1024 512 linear /dev/sdb 766

1536 128 linear /dev/sdc 0 
2) 0 2048 striped 2 64 /dev/sda 1024 /dev/sdb 0

3) 0 4711 mirror core 2 64 nosync 2 /dev/sda 2048 /dev/sdb 1024
Copy after login

In Example 1, the three addresses of logical devices are sectors 0~1023, sectors 1024~1535, and 1536~1663. The range is mapped to the area starting from sector No. 204 of the /dev/sda device, sector No. 766 of the /dev/sdb device, and sector No. 0 of the /dev/sdc device in a linear mapping manner.

In Example 2, the 2048-sector segment of the logical device starting from sector 0 is mapped to the 1024th sector of the /dev/sda device and the /dev/sdb device in a striped manner. The area starting from sector 0. At the same time, it tells the kernel that the target driver of this stripe type has two stripe devices mapped to logical devices, and the size of the stripe is 64 sectors, so that the driver can use this value to split IO requests across devices.

In Example 3, the 4711-sector segment of the logical device starting from sector 0 is mapped to the 2048th sector of the /dev/sda device and the 1024th sector of the /dev/sdb device in a mirroring manner. The area where sector number starts.

After the mapping table is determined, the operations of creating and deleting logical devices are relatively simple. The corresponding operations can be completed through the following dmsetup commands.

dmsetup create 设备名 映射表文件 /* 根据指定的映射表创建一个逻辑设备 */

dmsetup reload 设备名 映射表文件 /* 为指定设备从磁盘中读取映射文件,重新构建映射关系 */

dmsetup remove 设备名 /* 删除指定的逻辑设备 */
Copy after login

Device Mapper mechanism in the Linux system kernel (1) (4)

Figure 4 The logical device created in the kernel based on the mapping table in Example 1

When the user space issues a command to create a logical device based on the mapping table, the device mapper in the kernel uses the incoming parameters and mapping relationship Establish a mapping relationship from logical addresses to physical addresses. The device established based on the mapping relationship in mapping table example 1 is shown in Figure 4. The lower part of the figure abstractly depicts the mapping relationship between logical addresses and physical addresses established in the kernel according to the mapping table.

The above is the content of the Device Mapper mechanism (1) (4) in the Linux system kernel. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!