[libvirt-users] Lifecycle of a connection to libvirtd

Vincent Bernat bernat at luffy.cx
Sun Jul 24 21:13:08 UTC 2016


Hey!

I am trying to figure out how to reliably maintain a connection to
libvirtd. From the documentation, I would expect something like that:

 - virConnectOpen()
 - virConnectRegisterCloseCallback()
 - virConnectSetKeepAlive()
 - Application logic

And in the registered callback, I would:

 - virConnectUnregisterCloseCallback()
 - virConnectClose()
 - virConnectOpen()
 - virConnectRegisterCloseCallback()
 - virConnectSetKeepAlive()

However, looking at the source code of virsh, I see that it additional
stuff, notably:

 - virConnectIsAlive()
 - checking error codes of all calls to check if they are the result of
   a disconnect

Are those steps needed? Randomly checking virConnectIsAlive() doesn't
seem reliable. Checking individual error codes either (maybe I will miss
one of them or misinterpret another one).

virsh code uses those error codes to check if there is a disconnection:

             (((last_error->code == VIR_ERR_SYSTEM_ERROR) &&
               (last_error->domain == VIR_FROM_REMOTE)) ||
              (last_error->code == VIR_ERR_RPC) ||
              (last_error->code == VIR_ERR_NO_CONNECT) ||
              (last_error->code == VIR_ERR_INVALID_CONN))))

Any hint?
-- 
Program defensively.
            - The Elements of Programming Style (Kernighan & Plauger)




More information about the libvirt-users mailing list