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

Device Mapper mechanism in Linux system kernel (1) (5)

黄舟
Release: 2016-12-23 14:11:24
Original
1188 people have browsed it

The user space part of the 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, dmraid and other tools, use the device provided by the device mapper The mapper user space library establishes an independent set of management tools based on its own management needs, but does not use the dmsetup tool it provides. Even IBM's open source project enterprise-level logical volume management system-EVMS does not use device in its implementation. The user space library of mapper implements its own function library completely based on the ioctl definition in the kernel.

Target Driver

Device mapper provides a unified architecture that allows users to specify their own IO processing rules according to actual needs through the target driver plug-in. Therefore, the target driver fully embodies the flexibility of the device mapper. In the above, we have mentioned the target driver more than once and described the functions of the target driver. Here we will introduce the implementation of the target driver in detail with the simplest linear target driver.

Target driver mainly defines the processing rules for IO requests. In the device mapper, a unified interface has been defined for the operation of the target driver. In the implementation, the interface is defined by the target_type structure we mentioned above, which defines The following target driver methods:

1. Method of building target device;

2. Method of deleting target device;

3. Target’s method of mapping IO requests;

4. Target’s method of ending IO requests;

5. Method to pause target device reading and writing;

6. Restore target device reading and writing access;

7. Access to obtain current target device status;

8. Target's method to process user messages;

Users can The above methods can be selectively implemented according to specific needs, but generally at least the first three methods must be implemented, otherwise it will not work properly under the device mapper. The linear target driver only implements the first three methods and method 7. It completes the linear mapping from the logical address space to the physical address space, and can form a logical device by linearly connecting multiple physical devices, as described in Figure 4. As in, the three continuous spaces of /dev/sda, /dev/sdb, and /dev/sdc are formed into a large logical block device through the linear target driver. The implementation of Linear target is very simple. Its creation and deletion methods mainly complete the application and release of memory resources describing 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;

}
Copy after login

The mapping method is The bio request sent to the logical device mapped device is redirected in a linear manner to the corresponding location of the physical device represented by the linear target device 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 correspond to the target device. The device pointer, and changes the sector number bi_sector where the IO request starts based on the starting address of the target device and the offset value of the bio request on the mapped device device, thereby completing the redirection of the IO request. The implementation of other target drivers is also similar. You can implement it according to the interface specifications defined by the device mapper and combine the functions you need. I will not introduce them one by one here. Interested readers can see the specific target driver code in the kernel.

(T114)

The above is the content of Device Mapper mechanism (1) (5) in the Linux system kernel. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


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!