<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=ISO-8859-1"/><linkrel="stylesheet"type="text/css"href="../libvirt.css"/><linkrel="SHORTCUT ICON"href="/32favicon.png"/><title>Module libvirt from libvirt</title></head><body><divid="container"><divid="intro"><divid="adjustments"></div><divid="pageHeader"></div><divid="content2"><h1class="style1">Module libvirt from libvirt</h1><tableclass="navigation"width="100%"summary="Navigation header"cellpadding="2"cellspacing="2"><trvalign="middle"><td><aaccesskey="u"href="index.html"><imgsrc="up.png"width="24"height="24"border="0"alt="Up"/></a></td><thalign="left"><ahref="index.html">API documentation</a></th><td><aaccesskey="h"href="../index.html"><imgsrc="home.png"width="24"height="24"border="0"alt="Home"/></a></td><thalign="center"><ahref="../index.html">The virtualization API</a></th></tr></table><p>Provides the interfaces of the libvirt library to handle Xen domains from a process running in domain 0 </p><h2>Table of Contents</h2><preclass="programlisting">#define <ahref="#LIBVIR_VERSION_NUMBER">LIBVIR_VERSION_NUMBER</a></pre><preclass="programlisting">Structure <ahref="#virConnect">virConnect</a><br/>struct _virConnect
The content of this structure is not made public by the API.
<preclass="programlisting">unsigned int <ahref="#virDomainGetID">virDomainGetID</a> (<ahref="libvirt-libvirt.html#virDomainPtr">virDomainPtr</a> domain)</pre>
<preclass="programlisting">unsigned long <ahref="#virDomainGetMaxMemory">virDomainGetMaxMemory</a> (<ahref="libvirt-libvirt.html#virDomainPtr">virDomainPtr</a> domain)</pre>
<preclass="programlisting">int <ahref="#virGetVersion">virGetVersion</a> (unsigned long * libVer, <br/> const char * type, <br/> unsigned long * typeVer)</pre>
<h2>Description</h2>
<h3><aname="LIBVIR_VERSION_NUMBER"id="LIBVIR_VERSION_NUMBER"></a>Macro: LIBVIR_VERSION_NUMBER</h3><pre>#define LIBVIR_VERSION_NUMBER</pre><p>Macro providing the version of the library as version * 1,000,000 + minor * 1000 + micro</p>
</pre><p>This function closes the connection to the Hypervisor. This should not be called if further interaction with the Hypervisor are needed especially if there is running domain which need further monitoring by the application.</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>conn</tt></i>:</span></td><td>pointer to the hypervisor connection</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>0 in case of success or -1 in case of error.</td></tr></tbody></table></div><h3><aname="virConnectGetType"id="virConnectGetType"></a>Function: virConnectGetType</h3><preclass="programlisting">const char * virConnectGetType (<ahref="libvirt-libvirt.html#virConnectPtr">virConnectPtr</a> conn)<br/>
</pre><p>Get the name of the Hypervisor software used.</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>conn</tt></i>:</span></td><td>pointer to the hypervisor connection</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>NULL in case of error, a static zero terminated string otherwise.</td></tr></tbody></table></div><h3><aname="virConnectGetVersion"id="virConnectGetVersion"></a>Function: virConnectGetVersion</h3><preclass="programlisting">int virConnectGetVersion (<ahref="libvirt-libvirt.html#virConnectPtr">virConnectPtr</a> conn, <br/> unsigned long * hvVer)<br/>
</pre><p>Get the version level of the Hypervisor running. This may work only with hypervisor call, i.e. with priviledged access to the hypervisor, not with a Read-Only connection.</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>conn</tt></i>:</span></td><td>pointer to the hypervisor connection</td></tr><tr><td><spanclass="term"><i><tt>hvVer</tt></i>:</span></td><td>return value for the version of the running hypervisor (OUT)</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>-1 in case of error, 0 otherwise. if the version can't be extracted by lack of capacities returns 0 and @hvVer is 0, otherwise @hvVer value is major * 1,000,000 + minor * 1,000 + release</td></tr></tbody></table></div><h3><aname="virConnectListDomains"id="virConnectListDomains"></a>Function: virConnectListDomains</h3><preclass="programlisting">int virConnectListDomains (<ahref="libvirt-libvirt.html#virConnectPtr">virConnectPtr</a> conn, <br/> int * ids, <br/> int maxids)<br/>
</pre><p>Collect the list of active domains, and store their ID in @maxids</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>conn</tt></i>:</span></td><td>pointer to the hypervisor connection</td></tr><tr><td><spanclass="term"><i><tt>ids</tt></i>:</span></td><td>array to collect the list of IDs of active domains</td></tr><tr><td><spanclass="term"><i><tt>maxids</tt></i>:</span></td><td>size of @ids</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>the number of domain found or -1 in case of error</td></tr></tbody></table></div><h3><aname="virConnectNumOfDomains"id="virConnectNumOfDomains"></a>Function: virConnectNumOfDomains</h3><preclass="programlisting">int virConnectNumOfDomains (<ahref="libvirt-libvirt.html#virConnectPtr">virConnectPtr</a> conn)<br/>
</pre><p>Provides the number of active domains.</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>conn</tt></i>:</span></td><td>pointer to the hypervisor connection</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>the number of domain found or -1 in case of error</td></tr></tbody></table></div><h3><aname="virConnectOpen"id="virConnectOpen"></a>Function: virConnectOpen</h3><preclass="programlisting"><ahref="libvirt-libvirt.html#virConnectPtr">virConnectPtr</a> virConnectOpen (const char * name)<br/>
</pre><p>This function should be called first to get a connection to the Hypervisor and xen store</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>name</tt></i>:</span></td><td>optional argument currently unused, pass NULL</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>a pointer to the hypervisor connection or NULL in case of error</td></tr></tbody></table></div><h3><aname="virConnectOpenReadOnly"id="virConnectOpenReadOnly"></a>Function: virConnectOpenReadOnly</h3><preclass="programlisting"><ahref="libvirt-libvirt.html#virConnectPtr">virConnectPtr</a> virConnectOpenReadOnly (const char * name)<br/>
</pre><p>This function should be called first to get a restricted connection to the libbrary functionalities. The set of APIs usable are then restricted on the available methods to control the domains.</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>name</tt></i>:</span></td><td>optional argument currently unused, pass NULL</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>a pointer to the hypervisor connection or NULL in case of error</td></tr></tbody></table></div><h3><aname="virDomainCreateLinux"id="virDomainCreateLinux"></a>Function: virDomainCreateLinux</h3><preclass="programlisting"><ahref="libvirt-libvirt.html#virDomainPtr">virDomainPtr</a> virDomainCreateLinux (<ahref="libvirt-libvirt.html#virConnectPtr">virConnectPtr</a> conn, <br/> const char * xmlDesc, <br/> unsigned int flags)<br/>
</pre><p>Launch a new Linux guest domain, based on an XML description similar to the one returned by virDomainGetXMLDesc() This function may requires priviledged access to the hypervisor.</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>conn</tt></i>:</span></td><td>pointer to the hypervisor connection</td></tr><tr><td><spanclass="term"><i><tt>xmlDesc</tt></i>:</span></td><td>an XML description of the domain</td></tr><tr><td><spanclass="term"><i><tt>flags</tt></i>:</span></td><td>an optional set of virDomainFlags</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>a new domain object or NULL in case of failure</td></tr></tbody></table></div><h3><aname="virDomainDestroy"id="virDomainDestroy"></a>Function: virDomainDestroy</h3><preclass="programlisting">int virDomainDestroy (<ahref="libvirt-libvirt.html#virDomainPtr">virDomainPtr</a> domain)<br/>
</pre><p>Destroy the domain object. The running instance is shutdown if not down already and all resources used by it are given back to the hypervisor. The data structure is freed and should not be used thereafter if the call does not return an error. This function may requires priviledged access</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>domain</tt></i>:</span></td><td>a domain object</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>0 in case of success and -1 in case of failure.</td></tr></tbody></table></div><h3><aname="virDomainFree"id="virDomainFree"></a>Function: virDomainFree</h3><preclass="programlisting">int virDomainFree (<ahref="libvirt-libvirt.html#virDomainPtr">virDomainPtr</a> domain)<br/>
</pre><p>Free the domain object. The running instance is kept alive. The data structure is freed and should not be used thereafter.</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>domain</tt></i>:</span></td><td>a domain object</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>0 in case of success and -1 in case of failure.</td></tr></tbody></table></div><h3><aname="virDomainGetID"id="virDomainGetID"></a>Function: virDomainGetID</h3><preclass="programlisting">unsigned int virDomainGetID (<ahref="libvirt-libvirt.html#virDomainPtr">virDomainPtr</a> domain)<br/>
</pre><p>Get the hypervisor ID number for the domain</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>domain</tt></i>:</span></td><td>a domain object</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>the domain ID number or (unsigned int) -1 in case of error</td></tr></tbody></table></div><h3><aname="virDomainGetInfo"id="virDomainGetInfo"></a>Function: virDomainGetInfo</h3><preclass="programlisting">int virDomainGetInfo (<ahref="libvirt-libvirt.html#virDomainPtr">virDomainPtr</a> domain, <br/><ahref="libvirt-libvirt.html#virDomainInfoPtr">virDomainInfoPtr</a> info)<br/>
</pre><p>Extract information about a domain. Note that if the connection used to get the domain is limited only a partial set of the informations can be extracted.</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>domain</tt></i>:</span></td><td>a domain object</td></tr><tr><td><spanclass="term"><i><tt>info</tt></i>:</span></td><td>pointer to a <ahref="libvirt-libvirt.html#virDomainInfo">virDomainInfo</a> structure allocated by the user</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>0 in case of success and -1 in case of failure.</td></tr></tbody></table></div><h3><aname="virDomainGetMaxMemory"id="virDomainGetMaxMemory"></a>Function: virDomainGetMaxMemory</h3><preclass="programlisting">unsigned long virDomainGetMaxMemory (<ahref="libvirt-libvirt.html#virDomainPtr">virDomainPtr</a> domain)<br/>
</pre><p>Retrieve the maximum amount of physical memory allocated to a domain. If domain is NULL, then this get the amount of memory reserved to Domain0 i.e. the domain where the application runs.</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>domain</tt></i>:</span></td><td>a domain object or NULL</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>the memory size in kilobytes or 0 in case of error.</td></tr></tbody></table></div><h3><aname="virDomainGetName"id="virDomainGetName"></a>Function: virDomainGetName</h3><preclass="programlisting">const char * virDomainGetName (<ahref="libvirt-libvirt.html#virDomainPtr">virDomainPtr</a> domain)<br/>
</pre><p>Get the public name for that domain</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>domain</tt></i>:</span></td><td>a domain object</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>a pointer to the name or NULL, the string need not be deallocated its lifetime will be the same as the domain object.</td></tr></tbody></table></div><h3><aname="virDomainGetOSType"id="virDomainGetOSType"></a>Function: virDomainGetOSType</h3><preclass="programlisting">char * virDomainGetOSType (<ahref="libvirt-libvirt.html#virDomainPtr">virDomainPtr</a> domain)<br/>
</pre><p>Get the type of domain operation system.</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>domain</tt></i>:</span></td><td>a domain object</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>the new string or NULL in case of error</td></tr></tbody></table></div><h3><aname="virDomainGetXMLDesc"id="virDomainGetXMLDesc"></a>Function: virDomainGetXMLDesc</h3><preclass="programlisting">char * virDomainGetXMLDesc (<ahref="libvirt-libvirt.html#virDomainPtr">virDomainPtr</a> domain, <br/> int flags)<br/>
</pre><p>Provide an XML description of the domain. The description may be reused later to relaunch the domain with virDomainCreateLinux().</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>domain</tt></i>:</span></td><td>a domain object</td></tr><tr><td><spanclass="term"><i><tt>flags</tt></i>:</span></td><td>and OR'ed set of extraction flags, not used yet</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>a 0 terminated UTF-8 encoded XML instance, or NULL in case of error. the caller must free() the returned value.</td></tr></tbody></table></div><h3><aname="virDomainLookupByID"id="virDomainLookupByID"></a>Function: virDomainLookupByID</h3><preclass="programlisting"><ahref="libvirt-libvirt.html#virDomainPtr">virDomainPtr</a> virDomainLookupByID (<ahref="libvirt-libvirt.html#virConnectPtr">virConnectPtr</a> conn, <br/> int id)<br/>
</pre><p>Try to find a domain based on the hypervisor ID number</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>conn</tt></i>:</span></td><td>pointer to the hypervisor connection</td></tr><tr><td><spanclass="term"><i><tt>id</tt></i>:</span></td><td>the domain ID number</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>a new domain object or NULL in case of failure</td></tr></tbody></table></div><h3><aname="virDomainLookupByName"id="virDomainLookupByName"></a>Function: virDomainLookupByName</h3><preclass="programlisting"><ahref="libvirt-libvirt.html#virDomainPtr">virDomainPtr</a> virDomainLookupByName (<ahref="libvirt-libvirt.html#virConnectPtr">virConnectPtr</a> conn, <br/> const char * name)<br/>
</pre><p>Try to lookup a domain on the given hypervisor based on its name.</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>conn</tt></i>:</span></td><td>pointer to the hypervisor connection</td></tr><tr><td><spanclass="term"><i><tt>name</tt></i>:</span></td><td>name for the domain</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>a new domain object or NULL in case of failure</td></tr></tbody></table></div><h3><aname="virDomainRestore"id="virDomainRestore"></a>Function: virDomainRestore</h3><preclass="programlisting">int virDomainRestore (<ahref="libvirt-libvirt.html#virConnectPtr">virConnectPtr</a> conn, <br/> const char * from)<br/>
</pre><p>This method will restore a domain saved to disk by virDomainSave().</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>conn</tt></i>:</span></td><td>pointer to the hypervisor connection</td></tr><tr><td><spanclass="term"><i><tt>from</tt></i>:</span></td><td>path to the</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>0 in case of success and -1 in case of failure.</td></tr></tbody></table></div><h3><aname="virDomainResume"id="virDomainResume"></a>Function: virDomainResume</h3><preclass="programlisting">int virDomainResume (<ahref="libvirt-libvirt.html#virDomainPtr">virDomainPtr</a> domain)<br/>
</pre><p>Resume an suspended domain, the process is restarted from the state where it was frozen by calling virSuspendDomain(). This function may requires priviledged access</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>domain</tt></i>:</span></td><td>a domain object</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>0 in case of success and -1 in case of failure.</td></tr></tbody></table></div><h3><aname="virDomainSave"id="virDomainSave"></a>Function: virDomainSave</h3><preclass="programlisting">int virDomainSave (<ahref="libvirt-libvirt.html#virDomainPtr">virDomainPtr</a> domain, <br/> const char * to)<br/>
</pre><p>This method will suspend a domain and save its memory contents to a file on disk. After the call, if successful, the domain is not listed as running anymore (this may be a problem). Use virDomainRestore() to restore a domain after saving.</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>domain</tt></i>:</span></td><td>a domain object</td></tr><tr><td><spanclass="term"><i><tt>to</tt></i>:</span></td><td>path for the output file</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>0 in case of success and -1 in case of failure.</td></tr></tbody></table></div><h3><aname="virDomainSetMaxMemory"id="virDomainSetMaxMemory"></a>Function: virDomainSetMaxMemory</h3><preclass="programlisting">int virDomainSetMaxMemory (<ahref="libvirt-libvirt.html#virDomainPtr">virDomainPtr</a> domain, <br/> unsigned long memory)<br/>
</pre><p>Dynamically change the maximum amount of physical memory allocated to a domain. If domain is NULL, then this change the amount of memory reserved to Domain0 i.e. the domain where the application runs. This function requires priviledged access to the hypervisor.</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>domain</tt></i>:</span></td><td>a domain object or NULL</td></tr><tr><td><spanclass="term"><i><tt>memory</tt></i>:</span></td><td>the memory size in kilobytes</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>0 in case of success and -1 in case of failure.</td></tr></tbody></table></div><h3><aname="virDomainShutdown"id="virDomainShutdown"></a>Function: virDomainShutdown</h3><preclass="programlisting">int virDomainShutdown (<ahref="libvirt-libvirt.html#virDomainPtr">virDomainPtr</a> domain)<br/>
</pre><p>Shutdown a domain, the domain object is still usable there after but the domain OS is being stopped. Note that the guest OS may ignore the request. TODO: should we add an option for reboot, knowing it may not be doable in the general case ?</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>domain</tt></i>:</span></td><td>a domain object</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>0 in case of success and -1 in case of failure.</td></tr></tbody></table></div><h3><aname="virDomainSuspend"id="virDomainSuspend"></a>Function: virDomainSuspend</h3><preclass="programlisting">int virDomainSuspend (<ahref="libvirt-libvirt.html#virDomainPtr">virDomainPtr</a> domain)<br/>
</pre><p>Suspends an active domain, the process is frozen without further access to CPU resources and I/O but the memory used by the domain at the hypervisor level will stay allocated. Use virDomainResume() to reactivate the domain. This function may requires priviledged access.</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>domain</tt></i>:</span></td><td>a domain object</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>0 in case of success and -1 in case of failure.</td></tr></tbody></table></div><h3><aname="virGetVersion"id="virGetVersion"></a>Function: virGetVersion</h3><preclass="programlisting">int virGetVersion (unsigned long * libVer, <br/> const char * type, <br/> unsigned long * typeVer)<br/>
</pre><p>Provides two information back, @libVer is the version of the library while @typeVer will be the version of the hypervisor type @type against which the library was compiled. If @type is NULL, "Xen" is assumed, if @type is unknown or not availble, an error code will be returned and @typeVer will be 0.</p>
<divclass="variablelist"><tableborder="0"><colalign="left"/><tbody><tr><td><spanclass="term"><i><tt>libVer</tt></i>:</span></td><td>return value for the library version (OUT)</td></tr><tr><td><spanclass="term"><i><tt>type</tt></i>:</span></td><td>hypervisor type</td></tr><tr><td><spanclass="term"><i><tt>typeVer</tt></i>:</span></td><td>return value for the version of the hypervisor (OUT)</td></tr><tr><td><spanclass="term"><i><tt>Returns</tt></i>:</span></td><td>-1 in case of failure, 0 otherwise, and values for @libVer and @typeVer have the format major * 1,000,000 + minor * 1,000 + release.</td></tr></tbody></table></div></div></div><divclass="linkList2"><divclass="llinks2"><h3class="links2"><span>main menu</span></h3><ul><li><ahref="../index.html">Home</a></li><li><ahref="../html/index.html">API Menu</a></li><li><ahref="../examples/index.html">C code examples</a></li><li><ahref="../ChangeLog.html">Recent Changes</a></li></ul></div><divclass="llinks2"><h3class="links2"><span>related links</span></h3><ul><li><ahref="https://www.redhat.com/archives/libvir-list/">Mail archive</a></li><li><ahref="http://www.cl.cam.ac.uk/Research/SRG/netos/xen/index.html">Xen project</a></li><li><formaction="search.php"enctype="application/x-www-form-urlencoded"method="get"><inputname="query"type="text"size="12"value="Search..."/><inputname="submit"type="submit"value="Go"/></form></li><li><ahref="http://xmlsoft.org/"><imgsrc="../Libxml2-Logo-90x34.gif"alt="Made with Libxml2 Logo"/></a></li></ul><pclass="credits">Graphics and design by <ahref="mail:dfong@redhat.com">Diana Fong</a></p></div></div><divid="bottom"><pclass="p1"></p></div></div></body></html>