[Libvir] What is the Difference Between virConnCopyLastError and virCopyLastError?

Hi, I am little confused about these api's such as virConnCopyLastError and virCopyLastError. Please correct my understanding. 1. virConnCopyLastError expects 2 parameter connection and virErrorPtr, This is used only after getting successful connection, If i call this without connection say it is NULL, I hope it will return -1 if no what will it return? 2. virCopyLastError expects on 1 parameter virErrorPtr, this can be used any time, even before getting connection, If it is No. Then when will i use virCopyLastError api? 3. If virConnectOpen/virConnectOpenReadOnly fails which api should be called to know the error code? Thanks & Regards --Ajish

On Thu, Apr 10, 2008 at 02:56:36PM +0530, ajishrao wrote:
Hi, I am little confused about these api's such as virConnCopyLastError and virCopyLastError. Please correct my understanding.
1. virConnCopyLastError expects 2 parameter connection and virErrorPtr, This is used only after getting successful connection, If i call this without connection say it is NULL, I hope it will return -1 if no what will it return?
yes, see the code ... virConnCopyLastError(virConnectPtr conn, virErrorPtr to) { if (conn == NULL) return (-1); ...
2. virCopyLastError expects on 1 parameter virErrorPtr, this can be used any time, even before getting connection, If it is No. Then when will i use virCopyLastError api?
Also some errors may happen at a place where we don't have a connection pointer handy to report them, in that case the data is still saved but in a global variable. It's not just if a connection was successful or not.
3. If virConnectOpen/virConnectOpenReadOnly fails which api should be called to know the error code?
virCopyLastError Note that you don't have to do things asynchronously like this, see http://libvirt.org/html/libvirt-virterror.html#virSetErrorFunc allowing to provide a callback called on error if no connection is available and http://libvirt.org/html/libvirt-virterror.html#virConnSetErrorFunc to set such callback in a context with a connection i have tried to detail all this in the documentation at http://libvirt.org/errors.html Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ veillard@redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/

On Thu, Apr 10, 2008 at 02:56:36PM +0530, ajishrao wrote:
3. If virConnectOpen/virConnectOpenReadOnly fails which api should be called to know the error code?
You might find some example code useful. Look at the definition of CHECK_ERROR macro, used here: http://hg.et.redhat.com/applications/virt/applications/virt-top--devel?f=8c1... (eg line 63) and defined here: http://hg.et.redhat.com/applications/virt/applications/virt-top--devel?f=a5b... (line 45) and the _raise_virterror function which gets the virterror defined here: http://hg.et.redhat.com/applications/virt/applications/virt-top--devel?f=6fe... (line 66) errp = conn ? virConnGetLastError (conn) : virGetLastError (); Note that actually copying the virterror may not be such a good idea. The lifetime of that structure and the strings / pointers contained within it is a little bit undefined, and the virCopy* functions don't do a deep copy IIRC. So you should take copies of anything you need yourself, and make sure you don't refer to the conn/dom/net structure fields if you can possibly avoid it. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
participants (3)
-
ajishrao
-
Daniel Veillard
-
Richard W.M. Jones