[Libvir] Need Help on Error handling.

Hi, I am using libvirt to manage, The Hypervisor, Can Any one Help me about handling error? My main questions are. --- What is Library level Error Handling? --- Any Example to use void virSetErrorFunc (void * userData,virErrorFunc <http://libvirt.org/html/libvirt-virterror.html#virErrorFunc> handler) --- What is the difference between these two funtions? int virConnCopyLastError (virConnectPtr <http://libvirt.org/html/libvirt-libvirt.html#virConnectPtr> conn,virErrorPtr <http://libvirt.org/html/libvirt-virterror.html#virErrorPtr> to) virErrorPtr <http://libvirt.org/html/libvirt-virterror.html#virErrorPtr> virConnGetLastError (virConnectPtr <http://libvirt.org/html/libvirt-libvirt.html#virConnectPtr> conn) -- Thanks&Regards Ajeesh

On Sun, Mar 09, 2008 at 10:52:33PM +0530, Ajishrao.r wrote:
Hi, I am using libvirt to manage, The Hypervisor, Can Any one Help me about handling error? My main questions are.
--- What is Library level Error Handling? --- Any Example to use
void virSetErrorFunc (void * userData,virErrorFunc <http://libvirt.org/html/libvirt-virterror.html#virErrorFunc> handler)
I'm not aware of any example code which uses this. The intention is that it allows a user function to be called when an error occurs. The normal way to do this is to check for an error return code from a function and call virConnGetLastError to retrieve the error.
--- What is the difference between these two funtions?
int virConnCopyLastError (virConnectPtr <http://libvirt.org/html/libvirt-libvirt.html#virConnectPtr> conn,virErrorPtr <http://libvirt.org/html/libvirt-virterror.html#virErrorPtr> to) virErrorPtr <http://libvirt.org/html/libvirt-virterror.html#virErrorPtr> virConnGetLastError (virConnectPtr <http://libvirt.org/html/libvirt-libvirt.html#virConnectPtr> conn)
Not a lot of difference. virGetLastError returns a pointer to the global last error structure used by the library. This structure may be updated on subsequent calls. virCopyLastError copies this structure so your copy won't be mutated on subsequent calls. The global last error structure _isn't_ used much. There is also a per-connection error structure. Which one is used is an interesting subject. There are loads of other problems with keeping the error structure or a copy of it around for a long time (eg. connections and domains may be freed) so it's better to avoid this. The best documentation for virterror is the source (src/virterror.c) Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v

Richard W.M. Jones wrote:
On Sun, Mar 09, 2008 at 10:52:33PM +0530, Ajishrao.r wrote:
Hi, I am using libvirt to manage, The Hypervisor, Can Any one Help me about handling error? My main questions are.
--- What is Library level Error Handling? --- Any Example to use
void virSetErrorFunc (void * userData,virErrorFunc <http://libvirt.org/html/libvirt-virterror.html#virErrorFunc> handler)
I'm not aware of any example code which uses this.
Actually, there is example code right in the libvirt source tree. In src/virsh.c, virSetErrorFunc() is used to set up the virshErrorHandler callback. I've used that as an example before for my own code :). Chris Lalancette

Thanks for the reply, I will see it and then will let you know. On Mon, Mar 10, 2008 at 6:23 PM, Chris Lalancette <clalance@redhat.com> wrote:
Richard W.M. Jones wrote:
On Sun, Mar 09, 2008 at 10:52:33PM +0530, Ajishrao.r wrote:
Hi, I am using libvirt to manage, The Hypervisor, Can Any one Help me about handling error? My main questions are.
--- What is Library level Error Handling? --- Any Example to use
void virSetErrorFunc (void * userData,virErrorFunc <http://libvirt.org/html/libvirt-virterror.html#virErrorFunc> handler)
I'm not aware of any example code which uses this.
Actually, there is example code right in the libvirt source tree. In src/virsh.c, virSetErrorFunc() is used to set up the virshErrorHandler callback. I've used that as an example before for my own code :).
Chris Lalancette
-- Thanks&Regards Ajeesh
participants (3)
-
Ajishrao.r
-
Chris Lalancette
-
Richard W.M. Jones