Re: [libvirt] Writing a new driver for libvirt

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

 



On Wed, Aug 27, 2008 at 09:47:40AM -0700, Orr, David-P64407 wrote:
> Hey all,
> 
> I am new to libvirt and have been asked to look at the possibility of
> writing a libvirt driver for a hypervisor we are using.  I am wondering
> if someone can give me the basics on what is involved in accomplishing
> this task, what are the basics of writing a new driver?  I have looked
> at the documentation posted and been poking around the code and just
> wanted to ask someone to point me in the right direction.

There are essentially two types of libvirt driver styles. First one I
call 'stateless', where libvirt doesn't maintain any persistent info
itself, and just talks to the hypervisor / external tools to implement
every API. The second style is 'stateful', where libvirt directly manages 
everything, including persistence of the domain configuration info.

Examples of stateless drivers are  Xen, and OpenVZ.

Examples of stateful drivers are QEMU, LXC

As for choosing which style to use, it depends on the hypervisor in question.
If your hypervisor has ability to storage persistent configuration data, and
make that available to libvirt, then stateless is the best approac because
it provides interoperability with existing tools for that hypervisor.

As for actually implementing things, you can take an incremental approach,
adding impls for individual methods as you go. The 'struct _virDriver'
in src/driver.h file lists all the  APIs you need for a complete impl
of libvirt on a hypervisor, but you certainly don't need to have all of 
them to get something useful working.

I'd recommend starting with Probe, Open, Close, NumOfDomains, ListDomains
and DomainGetInfo. That should be enough to get 'virsh list' working.

Then, add  NumOfDefinedDomains and ListDefinedDomain. That will get the
virsh list --inactive  command working

Then add  NodeGetInfo and GetCapabilities, which lets 'virsh nodeinfo'
and 'virsh capabilities' to work.

Then add  DomainDumpXML  to allow a domain config to be queried via
virsh dumpxml

And then add  DomainCreateLinux/DomainCreate/DomainDefine/DomainUndefine
to allow new domains to be created, started, and deleted.

At this point you'll have a pretty good impl working. Anything else beyond
this point is just a nice bonus.

For parsing XML file, the 'src/domain_conf.h' file APIs should be used. 
There are other useful APIs for internal use in util.h, capabilities.h,
buf.h, and memory.h.

Also look at the HACKING file for general guidelines.

Finally, ask questions on this list for anything you don't understand.
The task of writing new hypervisor drivers is not at all documented
but there are lots of people who can advise you.... 


Out of interest..... what hypervisor are you using ?

Regards,
Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]