Dennis Chen
2012-Jun-28 09:21 UTC
[libvirt-users] How does libvirt interaction with KVM to create a VM?
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? BRs. Dennis
Daniel P. Berrange
2012-Jun-28 10:26 UTC
[libvirt-users] How does libvirt interaction with KVM to create a VM?
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 -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Alex Jia
2012-Jun-28 11:03 UTC
[libvirt-users] How does libvirt interaction with KVM to create a VM?
On 06/28/2012 05:21 PM, 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?http://libvirt.org/git/?p=libvirt.git;a=blob;f=src/qemu/qemu_driver.c;h=2f934040ea7d996574ac447498a195d440ec0783;hb=HEAD 114 /* device for kvm ioctls */ 115 #define KVM_DEVICE "/dev/kvm" 1022 static int kvmGetMaxVCPUs(void) { 1023 int maxvcpus = 1; 1024 1025 int r, fd; 1026 1027 fd = open(KVM_DEVICE, O_RDONLY); 1028 if (fd < 0) { 1029 virReportSystemError(errno, _("Unable to open %s"), KVM_DEVICE); 1030 return -1; 1031 } 1032 1033 r = ioctl(fd, KVM_CHECK_EXTENSION, KVM_CAP_NR_VCPUS); 1034 if (r > 0) 1035 maxvcpus = r; 1036 1037 VIR_FORCE_CLOSE(fd); 1038 return maxvcpus; 1039 } http://libvirt.org/git/?p=libvirt.git;a=blob;f=src/qemu/qemu_process.c;h=c5140c3c92a9ceec8cb7778c79c8542f60eca486;hb=HEAD Please see qemuProcessStart() implemetation: 3288 int qemuProcessStart(virConnectPtr conn, 3289 struct qemud_driver *driver, 3290 virDomainObjPtr vm, 3291 const char *migrateFrom, 3292 int stdin_fd, 3293 const char *stdin_path, 3294 virDomainSnapshotObjPtr snapshot, 3295 enum virNetDevVPortProfileOp vmop, 3296 unsigned int flags) ......> > BRs. > Dennis > > _______________________________________________ > libvirt-users mailing list > libvirt-users at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-users
Possibly Parallel Threads
- Re: libvirtd segfault when using oVirt 4.1 with graphic console - CentOS7.3
- [RFC/PATCH 12/15] kvm-s390: API documentation
- [RFC/PATCH 12/15] kvm-s390: API documentation
- [BUG] Not exiting media forced a promptly close of libvirt 3.10
- libguest-test-tool error report