Libvirt Architecture and source code analysis

Source: Internet
Author: User
Tags snmp

Http://blog.chinaunix.net/uid-20940095-id-3813601.html

Libvirt is a collection of software used to manage virtual machines or virtualization features, including: Libvirt API,LIBVIRTD process and Virsh toolset.     The initial goal was to provide a unified management interface for different hypervisor. The goal of Libvirt:to provide a common and stable layer sufficient to securely manage domains on a node, possibly remote 。
1. Libvirt API
Different versions of the API see: http://libvirt.org/hvsupport.html, mainly for different virtualization technology solutions to provide a unified interface, the design idea is:
(1) Isolation from HV API changes-isolate the impact of the underlying hardware virtualization interface on the upper layer
(2) portable across HV-supports multiple OS, such as Linux,windows,solairs, etc.
(3) Rapid application development-provides encapsulated API to accelerate software development process
(4) TLS, SASL, SSH, PolicyKit-provides a variety of cryptographic protocols to ensure secure access to the underlying resources for upper-level applications
Through the encapsulation of the most primitive C library, the implementation of the interface of a variety of programming languages: Perl, Python, OCaml, Java, ruby,c#, PHP, and the current application layer programming commonly used protocols to encapsulate, the formation of different protocol library, easy to call in the application layer programming, currently mainly support:
(1) Mapping to Cim/dmtf:libvirt-cim
CIM, a public information model, is a conceptual model that is independent of implementation and is used to describe management information.
(2) Mapping to AMQP/QMF:LIBVIRT-QMF
AMQP is an application-layer standard protocol that provides unified messaging services and is a binary protocol that provides asynchronous, secure, and efficient interaction between client applications and messaging middleware.
The client and message middleware based on this protocol can deliver the message, and it is not restricted by the different products of client/middleware, different development language and other conditions.
(3) Mapping to Snmp:libvirt-snmp
The library makes the Libvirt a feature of SNMP that enables developers to monitor and set up different domain information on each node via SNMP
(4) Mapping to Gobject:libvirt-glib

2. Daemon process (LIBVIRTD)
The background process mainly implements the following functions:
(1) Remote agent
All commands sent by the remote client are monitored by the process execution
(2) Local environment initialization
Libvirt Service Start-Stop, user connection response, etc.
(3) Registration of various driver according to the environment (QEMU, Xen, storage ...) ) Implementation of
Different virtualization technology in the form of driver, because Libvirt provides a unified interface, so each driver is to implement these interfaces, will be driver registered to Libvirt

3. Virsh Tool Set
The API package will be libvirt to command line interface to provide an external interface.

4. Libvirt Hierarchy Architecture
For ease of understanding, the Libvirt is divided into three hierarchies, see figure below.
Refer to the above image to see the code execution path for creating a virtual machine instance from the Virsh command or interface:
(1) Virsh command or API interface C create virtual machine-Interface layer
Virsh Create Vm.xml or virdomainptr virdomain create XML (Virconnectptr conn, const char * xmldesc, unsigned int Flags
(2) Invoking the unified interface provided by Libvirt--the abstract driver layer
Conn->driver->domaincreatexml (conn, xmldesc, flags); The domaincreatexml here is the abstract unified interface, and there is no need to care whether the underlying driver is KVM or Xen
(3) Call the interface of the underlying virtualization technology--specific drive layer
Domaincreatexml = Qemudomaincreatexml; If Driver=qemu, then the called QEMU here is registered to the function on the abstract drive layer Qemudomaincreatexml
(4) Assemble the shell command and execute
In Qemu, for example, Qemudomaincreatexml first assembled a command to create a virtual machine, such as Qemu-hda disk.img, and then create a new thread to execute
Thinking back, libvirt through 4 steps, the bottom of the shell directly into the command to complete the operation of the abstract encapsulation, to the application developers to provide a unified, easy-to-use interface.

5. Abstract Drive Layer
Currently, there are several types of abstract drivers libvirt, each of which represents an abstract encapsulation of a function module:
(1) Virtualization Driver (VIRDRIVERPTR)
(2) Virtual network driver (virnetworkdriverptr)
(3) Physical NIC Drive (VIRINTERFACEDRIVERPTR)
(4) Storage driver (virstoragedriverptr)
(5) Monitoring driver (virdevicemonitorptr)
(6) Safety Drive (VIRSECRETDRIVERPTR)
(7) Filter Drive (VIRNWFILTERDRIVERPTR)
(8) State-driven (VIRSTATEDRIVERPTR)

In the next article, we will start with how to set up the Libvirt debugging environment and analyze the code of Libvirt each module in depth.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.