Re: How does libvirt interaction with KVM to create a VM?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 06/28/2012 06:26 PM, Daniel P. Berrange wrote:
On Thu, Jun 28, 2012 at 05:21:57PM +0800, Dennis Chen wrote:
All,

These days I am trying to understand the interaction relationship
between the libvirt and KVM kernel module, eg. kvm_intel.ko.

We know that KVM kernel module expose an entry in form of device
file "/dev/kvm" which can be accessed by user space application to
control, for example, create a VM using KVM_CREATE_VM with help of
ioctl.

Now let's say the tool virsh based upon libvirt, we can create a
guest domain with the command looks like:
#virsh create guest.xml
Obviously, the above command will create a VM. But when I try to
investigate the libvirt code, I can't find any code play with the
"/dev/kvm" to send KVM_CREATE_VM ioctl code to KVM kernel module.
But  I do found that the reference count of the kvm_intel.ko changed
before the virsh create command launched and after.

So my question is: how does the libvirt interaction with KVM to
create a VM? Anybody can give me some tips about that, eg, the
corresponding codes in libvirt?
The '/dev/kvm' device is the low level kernel interface for creating
virtual domains. This is not actually used by libvirt at all. The
QEMU binary has code that talks to /dev/kvm, so all libvirt does is
to spawn a QEMU process which in turns creates the virtual machine

All the libvirt code for this part is under $GIT/src/qemu/  in particular
the qemu_command.c and qemu_process.c files

Daniel
Thanks Daniel, now I understand that the libvirt code will play with QEMU binary, for example, qemu-system-x86_64, the latter will talk with KVM module . But now the question is, I guess qemuProcessStart() function was used to spawn a QEMU process, so I built a virsh from the source package with "-g -O0" flag, I want to gdb the virsh, but when I want to set a break point on qemuProcessStart(), I encounter issue:

#gdb virsh
(gdb) b main
Breakpoint 1 at 0x807d480: file virsh.c, line 20270.
(gdb) r
Starting program: /usr/bin/virsh
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".

Breakpoint 1, main (argc=1, argv=0xbffff294) at virsh.c:20270
20270    {
(gdb) b qemuProcessStart
Function "qemuProcessStart" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 2 (qemuProcessStart) pending.

(gdb)c

virsh # create guest.xml
Domain vdo created from vdo.xml

virsh #

continue instruction above doesn't hit the pending Breakpoint 2...

So my question is, which kind of object file will be created from $GIT/src/qemu folder during the build process, is it a .so file and virsh will load it?

BRs
Dennis


_______________________________________________
libvirt-users mailing list
libvirt-users@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvirt-users


[Index of Archives]     [Virt Tools]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]

  Powered by Linux