In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you how to carry out virtio analysis, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.
Virtio
Virtio is a general io virtualization framework through which hypervisor simulates a series of virtualized devices and makes them available through api calls within the virtual machine. It provides clients with an efficient way to access block devices. It consists of four parts: front-end driver, back-end driver, vring and unified interface between communications. Compared with other analog io methods, virtio reduces the exit of virtual machines and data copy, and can greatly improve the performance of IO. There are different bus standards in computers, and virtio uses the pci bus (of course, it can also be implemented with other buses). Every virtio device is a pci device.
Back-end initialization of virtio-blk
The virtio-blk code package is saved in hw/virtio-pci.c and hw/virtio-blk.c, and virtio_blk is initialized with the following functions. The main initialization function is virtio_blk_init_pci. The information for the device is defined here.
Static void virtio_blk_class_init (ObjectClass * klass, void * data) {DeviceClass * dc = DEVICE_CLASS (klass); PCIDeviceClass * k = PCI_DEVICE_CLASS (klass); k-> init = virtio_blk_init_pci; / / virtio-blk initialization function k-> exit = virtio_blk_exit_pci; k-> vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET / / equipment factory firm, all virtio devices are 0x1af4 k-> device_id = PCI_DEVICE_ID_VIRTIO_BLOCK; / / device number k-> revision = VIRTIO_PCI_ABI_VERSION; / / virtio ABI version number k-> class_id = PCI_CLASS_STORAGE_SCSI; dc- > reset = virtio_pci_reset; dc- > props = virtio_blk_properties / / characteristics supported by virtio-blk devices} static TypeInfo virtio_blk_info = {.name = "virtio-blk-pci", .parent = TYPE_PCI_DEVICE, .instance _ size = sizeof (VirtIOPCIProxy), .class _ init = virtio_blk_class_init, / / virtio-blk device type initialization function}
The virtio_blk backend data structure is as follows
Virtio-blk is first of all a pci device, initialization is mainly divided into two phases: pci device initialization and device initialization
Here are several stages of its initialization:
PCI device detection and initialization
When the virtual machine starts, the bios and the system scan the pci bus to see if there are any pci devices mounted on it. If so, a pci_dev structure is created. A pci device is represented by a pci_dev data structure, and after creation, the pci_dev is populated with the pci device configuration space information, and then device_register is called to register it with the pci bus. The match and probe functions of the PCI bus match the device with the driver registered on the PCI bus according to the Vendor ID and Device ID in the pci_dev data structure, and then match the PCI driver virtio_pci_driver shared by all virtio devices.
Static struct pci_device_id virtio_pci_id_table [] = {{0x1af4, PCI_ANY_ID, 0,0,0}, {0},} / / PCI_ANY_ID means to match any device IDstatic struct pci_driver virtio_pci_driver = {.name = "virtio-pci", / / driver name .id _ table = virtio_pci_id_table, / / device ID information supported by the driver .probe = virtio_pci_probe / / probe function (responsible for PCI device initialization and further virtio device detection). Remove = virtio_pci_remove,// device removal handling function # ifdef CONFIG_PM. Driver. Pm = & virtio_pci_pm_ops, / / Power Management function # endif}
Detection and initialization of virtio equipment
Virtio_pci_driver is the key function of this phase, and the specific process is as follows
The frontend driver reads the io request and puts it into the vring
The front end notifies the back-end driver to process io through the notify notification mechanism.
The notify operation exits the vcpu execution thread to the qemu application layer, which obtains the client io request information from vring, puts the request thread into the aio thread pool, and then returns the processing flow of the vcpu thread to the client
After the aio thread processing is complete, notify the main thread and inject an interrupt to the client indicating that it has completed the io operation
The client interrupts accordingly, obtains the io request result and processing information, and then continues to return the result up the layer.
Client io request flow
1. Read and write operations enter the kernel layer of the operating system through system calls, and first reach the VFS layer
2. The VFS layer continues to pass the request to the lower layer. If the page cache hits and the file is not read or written directly, the IO request is processed in the page cache.
3. If there is no page cache or page cache MISS, enter the Mapping Layer (mapping layer), which mainly solves the mapping between the file offset and the logical block number in the block device based on the file system information, and sends the request to the Generic Block Layer (common block layer) according to the mapping.
4. At the general block layer, IO read and write requests are represented by struct bio, and the general block layer continues to send requests to IO Scheduler Layer (IO scheduling layer)
5. In the IO scheduling layer, the bio passed from the upper layer will be scheduled according to the type, whether the logical block is close or not, and finally form a req (struct request type), and the req will be linked to the request_queue of the device.
6. The IO scheduling layer continues to send the request, and the request reaches the block device driver, and the block device driver takes each request from the request_queue to process.
The above content is how to analyze virtio. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.