In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "introduction of Device Mapper mechanism in Linux system". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Device mapper is relatively simple in user space, including device mapper libraries and dmsetup tools. Device mapper library is the encapsulation of ioctl and user space for creating necessary operations to delete device mapper logic devices. Dmsetup is a command line tool for creating and deleting device mapper devices that is directly available to users.
Because their functions and processes are relatively simple, we will not cover their details in this article. User space is mainly responsible for the following tasks:
Discover the target device associated with each mapped device
Create a mapping table based on configuration information
Pass the mapping table built in user space into the kernel and let the kernel build the dm_table structure corresponding to the mapped device
Save the current mapping information for future reconstruction.
Below we mainly illustrate the use of dmsetup through examples, and further illustrate the mapping mechanism of device mapper. The main task in user space is to build and save mapping tables. Here are some examples of mapping tables:
Example 1:
0 1024 linear / dev/sda 2041024 linear / dev/sdb 7661536 1024 linear / dev/sdc 02) 0 2048 striped 2 64 / dev/sda 1024 / dev/sdb 03) 0 4711 mirror core 2 64 nosync 2 / dev/sda 2048 / dev/sdb 1024
In example 1, the address ranges of the logical device 0sectors 1023, 1024 1535, and 1536 1663 are linearly mapped to sectors 204 of / dev/sda devices, 766 sectors of / dev/sdb devices, and areas beginning with sector 0 of / dev/sdc devices, respectively.
In example 2, the 2048 sector length segment of the logical device starting from sector 0 is striped to the area starting with sector 1024 of the / dev/sda device and sector 0 of the / dev/sdb device. At the same time, it tells the kernel that there are 2 stripe devices mapped to logical devices in this stripe type target driver, and the stripe size is 64 sectors, so that the driver can split IO requests across devices by this value.
In example 3, the 4711 sector length segment of the logical device starting from sector 0 is mirrored to the 2048th sector of the / dev/sda device and the area starting with sector 1024 of the / dev/sdb device.
After the mapping table is determined, the operation of creating and deleting logical devices is relatively simple, and the corresponding operation can be completed by using the following command dmsetup.
Dmsetup create device name mapping table file / * create a logical device based on the specified mapping table * /
Dmsetup reload device name mapping table file / * read the mapping file from disk for the specified device and rebuild the mapping relationship * /
Dmsetup remove device name / * Delete the specified logical device * /
When the user space issues the command to create the logical device according to the mapping table, device mapper establishes the mapping relationship between the logical address and the physical address in the kernel according to the incoming parameters and mapping relationship. The device established according to the mapping relationship in example 1 of the mapping table is shown in figure 4, and the lower part of the figure abstractly depicts the mapping from logical address to physical address established in the kernel according to the mapping table.
The user space part of Device mapper is optional for developers to implement their own storage management tools. in fact, many of our common logical volume managers, such as LVM2 and dmraid, make use of the device mapper user space library provided by device mapper to build an independent set of management tools according to their own management needs, without using the dmsetup tool provided by it, or even IBM's open source project enterprise logical volume management system-EVMS. The user space library of device mapper is not used in the implementation, and a set of function libraries is implemented completely according to the definition of ioctl in the kernel.
Target Driver
Device mapper provides a unified architecture that allows users to specify their own IO processing rules according to their actual needs through the way of target driver plug-ins, so target driver fully reflects the flexibility of device mapper. In the above, we have mentioned target driver more than once, and we have also described the functions of target driver. Here we introduce the implementation of target driver in detail with the simplest linear target driver.
Target driver mainly defines the rules for handling IO requests. A unified interface has been defined for target driver operations in device mapper. In implementation, this interface is defined in the target_type structure we mentioned above, which defines the following target driver methods:
The method of constructing target device
The method of deleting target device
The method of mapping IO requests of Target
The method of ending IO request by Target
The method of pausing target device read and write
Restore access to target device read and write
Get access to the current target device status
The method of handling user messages in Target
Users can selectively implement the above methods according to their specific needs, but generally at least the first three methods should be implemented, otherwise they will not work properly under device mapper. Linear target driver only implements the first three methods and method 7, which completes the linear mapping of logical address space to physical address space, and can form a logical device by linearly connecting multiple physical devices. As described in figure 4, the three contiguous spaces of / dev/sda, / dev/sdb, / dev/sdc are formed into a large logical block device through linear target driver. The implementation of Linear target is very simple, and its creation and deletion methods mainly complete the application and release of memory resources that describe the structure used by linear target device. The implementation of IO mapping processing method is even simpler, as shown in the following code:
Static int linear_map (struct dm_target * ti, struct bio * bio, union map_info * map_context) {struct linear_c * lc = (struct linear_c *) ti- > private; bio- > bi_bdev = lc- > dev- > bdev; bio- > bi_sector = lc- > start + (bio- > bi_sector-ti- > begin); return 1;}
The mapping method is to redirect the bio request sent to the logical device mapped device to the corresponding location of the physical device represented by the linear target device in a linear manner according to the mapping relationship. As shown in the code, the specific implementation method is to modify the bi_bdev device pointer of bio to the device pointer corresponding to target device, and to change the sector number bi_sector at the beginning of the IO request according to the starting address of the target device and the offset value of the bio request on the mapped device device. To complete the redirection of the IO request. Other target driver implementations are more or less the same, according to the interface specifications defined by device mapper, combined with their own functions can be implemented, here one by one will not be introduced, interested readers can see the specific target driver code in the kernel.
This is the end of the introduction of Device Mapper Mechanism in Linux system. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.