2022-04-07 12:08:41 +00:00
|
|
|
=========================
|
|
|
|
libvirt API call overview
|
|
|
|
=========================
|
2022-04-04 14:14:32 +00:00
|
|
|
|
|
|
|
The following diagram depicts code flow from a client application, in this case
|
|
|
|
the libvirt provided ``virsh`` command through the various layers to elicit a
|
|
|
|
response from some chosen hypervisor.
|
|
|
|
|
2022-04-07 12:08:41 +00:00
|
|
|
**Note:** Some aspects of this document may be outdated.
|
|
|
|
|
2022-04-04 14:14:32 +00:00
|
|
|
.. image:: ../../images/libvirt-virConnect-example.png
|
|
|
|
:alt: virConnectOpen calling sequence
|
|
|
|
|
2022-04-07 12:08:41 +00:00
|
|
|
- ``virsh -c qemu:///system list --all``
|
2022-04-04 14:14:32 +00:00
|
|
|
|
|
|
|
After the virsh code processes the input arguments, it eventually will make a
|
|
|
|
call to open the connection using a default set of authentication credentials
|
2022-04-07 12:08:41 +00:00
|
|
|
(``virConnectAuthDefault``).
|
2022-04-04 14:14:32 +00:00
|
|
|
|
2022-04-07 12:08:41 +00:00
|
|
|
- ``virConnectOpenAuth()``
|
2022-04-04 14:14:32 +00:00
|
|
|
|
2022-04-07 12:08:41 +00:00
|
|
|
Each of the ``virConnectOpen`` APIs will first call ``virInitialize()`` and
|
|
|
|
then revector through the local "``do_open()``" call.
|
2022-04-04 14:14:32 +00:00
|
|
|
|
2022-04-07 12:08:41 +00:00
|
|
|
- ``virInitialize()``
|
2022-04-04 14:14:32 +00:00
|
|
|
|
|
|
|
Calls the registration API for each of the drivers with client-side only
|
2022-04-07 12:08:41 +00:00
|
|
|
capabilities and then call the ``remoteRegister()`` API last. This
|
|
|
|
ensures the ``virDriverTab[]`` tries local drivers first before using the
|
|
|
|
remote driver.
|
2022-04-04 14:14:32 +00:00
|
|
|
|
2022-04-07 12:08:41 +00:00
|
|
|
- Loop through ``virDriverTab[]`` entries trying to call their respective
|
|
|
|
"open" entry point (in our case ``remoteOpen()``)
|
2022-04-04 14:14:32 +00:00
|
|
|
|
2022-04-07 12:08:41 +00:00
|
|
|
- After successful return from the ``virDriverTab[]`` ``open()`` API,
|
|
|
|
attempt to find and open other drivers (network, interface, storage, etc.)
|
2022-04-04 14:14:32 +00:00
|
|
|
|
2022-04-07 12:08:41 +00:00
|
|
|
- ``remoteOpen()``
|
2022-04-04 14:14:32 +00:00
|
|
|
|
2022-04-07 12:08:41 +00:00
|
|
|
After a couple of URI checks, a call to ``doRemoteOpen()`` is made
|
2022-04-04 14:14:32 +00:00
|
|
|
|
|
|
|
- Determine network transport and host/port to use from URI
|
|
|
|
|
2022-04-07 12:08:41 +00:00
|
|
|
The transport will be either ``tls``, ``unix``, ``ssh``, ``libssh2``,
|
|
|
|
``ext``, or ``tcp`` with the default of ``tls``. Decode the host/port if
|
|
|
|
provided or default to ``localhost``.
|
2022-04-04 14:14:32 +00:00
|
|
|
|
2022-04-07 12:08:41 +00:00
|
|
|
- ``virNetClientRegisterAsyncIO()``
|
2022-04-04 14:14:32 +00:00
|
|
|
|
|
|
|
Register an I/O callback mechanism to get returned data via
|
2022-04-07 12:08:41 +00:00
|
|
|
``virNetClientIncomingEvent()``
|
2022-04-04 14:14:32 +00:00
|
|
|
|
2022-04-07 12:08:41 +00:00
|
|
|
- ``call(...REMOTE_PROC_OPEN...)``
|
2022-04-04 14:14:32 +00:00
|
|
|
|
2022-04-07 12:08:41 +00:00
|
|
|
Eventually routes into ``virNetClientProgramCall()`` which will call
|
|
|
|
``virNetClientSendWithReply()`` and eventually uses ``virNetClientIO()``
|
|
|
|
to send the message to libvirtd and then waits for a response using
|
|
|
|
``virNetClientIOEventLoop()``
|
2022-04-04 14:14:32 +00:00
|
|
|
|
2022-04-07 12:08:41 +00:00
|
|
|
- ``virNetClientIncomingEvent()``
|
2022-04-04 14:14:32 +00:00
|
|
|
|
|
|
|
Receives the returned packet and processes through
|
2022-04-07 12:08:41 +00:00
|
|
|
``virNetClientIOUpdateCallback()``
|
2022-04-04 14:14:32 +00:00
|
|
|
|
|
|
|
- libvirtd Daemon
|
|
|
|
|
|
|
|
- Daemon Startup
|
|
|
|
|
|
|
|
The daemon initialization processing will declare itself as a daemon via a
|
2022-04-07 12:08:41 +00:00
|
|
|
``virNetDaemonNew()`` call, then creates new server using
|
|
|
|
``virNetServerNew()`` and adds that server to the main daemon struct with
|
|
|
|
``virNetDaemonAddServer()`` call. It will then use
|
|
|
|
``virDriverLoadModule()`` to find/load all known drivers, set up an RPC
|
|
|
|
server program using the ``remoteProcs[]`` table via a
|
|
|
|
``virNetServerProgramNew()`` call. The table is the corollary to the
|
|
|
|
``remote_procedure`` enum list in the client. It lists all the functions
|
|
|
|
to be called in the same order. Once RPC is set up, networking server
|
|
|
|
sockets are opened, the various driver state initialization routines are
|
|
|
|
run from the ``virStateDriverTab[]``, the network links are enabled, and
|
|
|
|
the daemon waits for work.
|
2022-04-04 14:14:32 +00:00
|
|
|
|
|
|
|
- RPC
|
|
|
|
|
|
|
|
When a message is received, the ``remoteProcs[]`` table is referenced for
|
2022-04-07 12:08:41 +00:00
|
|
|
the ``REMOTE_PROC_OPEN`` call entry. This results in
|
|
|
|
``remoteDispatchOpen()`` being called via the
|
|
|
|
``virNetServerProgramDispatchCall()``.
|
2022-04-04 14:14:32 +00:00
|
|
|
|
2022-04-07 12:08:41 +00:00
|
|
|
- ``remoteDispatchOpen()``
|
2022-04-04 14:14:32 +00:00
|
|
|
|
|
|
|
The API will read the argument passed picking out the ``name`` of the
|
2022-04-07 12:08:41 +00:00
|
|
|
driver to be opened. The code will then call ``virConnectOpen()`` or
|
|
|
|
``virConnectOpenReadOnly()`` depending on the argument ``flags``.
|
2022-04-04 14:14:32 +00:00
|
|
|
|
2022-04-07 12:08:41 +00:00
|
|
|
- ``virConnectOpen()`` or ``virConnectOpenReadOnly()``
|
2022-04-04 14:14:32 +00:00
|
|
|
|
|
|
|
Just like the client except that upon entry the URI is what was passed
|
|
|
|
from the client and will be found and opened to process the data.
|
|
|
|
|
2022-04-07 12:08:41 +00:00
|
|
|
The returned structure data is returned via the ``virNetServer``
|
|
|
|
interfaces to the remote driver which then returns it to the client
|
|
|
|
application.
|