[libvirt] possible bug in virConnectGetLibVersion()

I need to get libvirt version. Using function virConnecGetLibVersion(), I've return message like errore: unknown error My system settings are: Kernel: 2.6.33 Hypervisor: QEMU 0.12.3 Libvirt: 0.7.6 (cloned from git) The code that fails is in src/libvirt.c:1656 ========================================================= if (conn->driver->libvirtVersion) { ret = conn->driver->libvirtVersion(conn, libVer); if (ret < 0) goto error; return ret; } *libVer = LIBVIR_VERSION_NUMBER; ret = 0; error: virDispatchError(conn); return ret; } ========================================================= I noticed that conn->driver->libvirtVersion is NULL for all the hypervisors except the remote one (src/remote/remote_driver.c), hence it always dispatch an unknown error. I checked the current libvirt code (always cloned from git), and the bug is also present. Is this a bug, or this is a well known behavior? If this is a bug, a possible solution could be to add the code line return ret; before "error:" label. This is my debugged code ========================================================= if (conn->driver->libvirtVersion) { ret = conn->driver->libvirtVersion(conn, libVer); if (ret < 0) goto error; return ret; } *libVer = LIBVIR_VERSION_NUMBER; ret = 0; return ret; /* POSSIBLE BUG SOLUTION */ error: virDispatchError(conn); return ret; } ========================================================= Have a good day! -- PAOLO SMIRAGLIA Via Avigliana 13/5 10138 Torino (TO) Tel: 0039 333 52 73 593 E-Mail: paolo.smiraglia@gmail.com - - - - - MSN: mastronano@hotmail.com Jabber: mastronano@jabber.linux.it Skype: paolo.smiraglia

From: Paolo Smiraglia <paolo.smiraglia@gmail.com> * src/libvirt.c (virConnectGetLibVersion): Don't emit error on success. --- Paolo, thanks for the report; I've rewritten it in patch form, with a slight modification. I think it is correct, but would like to hear feedback from someone more experienced with the design to say whether it was intentional before we push this. src/libvirt.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libvirt.c b/src/libvirt.c index cc5b4c5..c04489d 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -1660,8 +1660,8 @@ virConnectGetLibVersion(virConnectPtr conn, unsigned long *libVer) return ret; } - *libVer = LIBVIR_VERSION_NUMBER; - ret = 0; + *libVer = LIBVIR_VERSION_NUMBER; + return 0; error: virDispatchError(conn); return ret; -- 1.6.6.1

Eric Blake wrote:
From: Paolo Smiraglia <paolo.smiraglia@gmail.com>
* src/libvirt.c (virConnectGetLibVersion): Don't emit error on success. ---
Paolo, thanks for the report; I've rewritten it in patch form, with a slight modification. I think it is correct, but would like to hear feedback from someone more experienced with the design to say whether it was intentional before we push this.
src/libvirt.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/libvirt.c b/src/libvirt.c index cc5b4c5..c04489d 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -1660,8 +1660,8 @@ virConnectGetLibVersion(virConnectPtr conn, unsigned long *libVer) return ret; }
- *libVer = LIBVIR_VERSION_NUMBER; - ret = 0; + *libVer = LIBVIR_VERSION_NUMBER; + return 0; error: virDispatchError(conn); return ret;
This change is fine. It would be wrong to report an error there. I'd insert a blank line after the "return 0;" Thanks!

* AUTHORS: Add recent contributors. ---
- *libVer = LIBVIR_VERSION_NUMBER; - ret = 0; + *libVer = LIBVIR_VERSION_NUMBER; + return 0; error: virDispatchError(conn); return ret;
This change is fine. It would be wrong to report an error there. I'd insert a blank line after the "return 0;"
Done, and pushed. I'm also pushing this followup as trivial. And in doing so, I noticed that we incorrectly attributed one patch to Philip Hahn instead of Philipp Hahn. AUTHORS | 3 ++++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/AUTHORS b/AUTHORS index 1fa97b6..d6f025e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -95,6 +95,9 @@ Patches have also been contributed by: Rolf Eike Beer <eike@sf-mail.de> Wolfgang Mauerer <wolfgang.mauerer@siemens.com> Philipp Hahn <hahn@univention.de> + Ed Swierk <eswierk@aristanetworks.com> + Paolo Smiraglia <paolo.smiraglia@gmail.com> + Sharadha Prabhakar <sharadha.prabhakar@citrix.com> [....send patches to get your name here....] -- 1.6.6.1
participants (3)
-
Eric Blake
-
Jim Meyering
-
Paolo Smiraglia