On 06/29/2012 12:25 AM, Dennis Chen wrote:
>>
>> 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?
>
http://libvirt.org/git/?p=libvirt.git;a=blob;f=src/qemu/qemu_driver.c;h=2...
>
Yes, I noticed the code above in libvirt, but it's not related
with my
question in the first message...
Actually, yes it is. That's the code that libvirtd runs in reaction to
your client code making an RPC code via libvirt.so.
I guess the qemuProcessStart() is used to spawn a QEMU process, but
seems that lot's of tricks in its implementation, essentially, does this
function spawn the qemu process looks like, eg:
StartProcess("/usr/bin/qemu-system-x86_64", ...);
Not StartProcess, so much as execve(), as wrapped in our virCommand API
(src/util/command.c). If you want to see the exact command line that we
constructed, look at /var/log/libvirt/qemu/$dom.log for the domain name
that you are starting. It is a rather hairy command line; this is an
example from one of my VMs:
LC_ALL=C PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
QEMU_AUDIO_DRV=none /usr/bin/qemu-kvm -S -M pc-0.14 -cpu qemu32
-enable-kvm -m 768 -smp 1,sockets=1,cores=1,threads=1 -name fedora-local
-uuid 24ab99db-bf50-085d-d3e5-7528243ae9b1 -nodefconfig -nodefaults
-chardev
socket,id=charmonitor,path=/var/lib/libvirt/qemu/fedora-local.monitor,server,nowait
-mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc
-no-shutdown -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive
file=/var/lib/libvirt/images/fedora-local.img,if=none,id=drive-virtio-disk0,format=raw
-device
virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1
-drive
file=/var/lib/libvirt/images/top.img,if=none,id=drive-virtio-disk1,format=qcow2
-device
virtio-blk-pci,scsi=off,bus=pci.0,addr=0x3,drive=drive-virtio-disk1,id=virtio-disk1
-drive if=none,id=drive-ide0-1-0,readonly=on,format=raw -device
ide-cd,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0,bootindex=2
-netdev tap,fd=22,id=hostnet0,vhost=on,vhostfd=23 -device
virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:65:82:9e,bus=pci.0,addr=0x5
-chardev pty,id=charserial0 -device
isa-serial,chardev=charserial0,id=serial0 -device usb-tablet,id=input0
-vnc 127.0.0.1:1 -k en-us -vga cirrus -device
ES1370,id=sound0,bus=pci.0,addr=0x6 -device
virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x7
In turn, it is that hairy command line that starts the qemu process, and
qemu then takes over the actual communication with the kernel via
/dev/kvm to use KVM virtualization.
--
Eric Blake eblake(a)redhat.com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org