]> xenbits.xensource.com Git - libvirt.git/commitdiff
xenapi: Improve error message on session failure
authorMatthew Booth <mbooth@redhat.com>
Fri, 10 Jun 2011 09:18:01 +0000 (17:18 +0800)
committerDaniel Veillard <veillard@redhat.com>
Fri, 10 Jun 2011 09:18:01 +0000 (17:18 +0800)
XenAPI session login can fail for a number of reasons, but currently no
specific
reason is displayed to the user, e.g.:

virsh -c XenAPI://citrix-xen.example.com/
Enter username for citrix-xen.example.com: root
Enter root's password for citrix-xen.example.com:
error: authentication failed: (null)
error: failed to connect to the hypervisor

This patch displays the session error description on failure.

src/xenapi/xenapi_driver.c

index 6f642084233febbcc1a7d91bdc83de87ae880f79..3fc35c649965daca7e3beea888d5d79dc83db5a2 100644 (file)
@@ -166,7 +166,22 @@ xenapiOpen (virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUS
     privP->session = xen_session_login_with_password(call_func, privP, username,
                                                      password, xen_api_latest_version);
 
-    if (privP->session != NULL && privP->session->ok) {
+    if (privP->session == NULL) {
+        /* From inspection of xen_session_login_with_password in
+         * libxenserver(Version 5.6.100-1), this appears not to be currently
+         * possible. The only way for this to be NULL would be on malloc
+         * failure, except that the code doesn't check for this and would
+         * segfault before returning.
+         *
+         * We don't assume the reason here for a failure in an external library.
+         */
+        xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR,
+                                  _("Failed to allocate xen session"));
+
+        goto error;
+    }
+
+    if (privP->session->ok) {
         conn->privateData = privP;
 
         VIR_FREE(username);
@@ -175,7 +190,8 @@ xenapiOpen (virConnectPtr conn, virConnectAuthPtr auth, int flags ATTRIBUTE_UNUS
         return VIR_DRV_OPEN_SUCCESS;
     }
 
-    xenapiSessionErrorHandler(conn, VIR_ERR_AUTH_FAILED, NULL);
+    xenapiSessionErrorHandler(conn, VIR_ERR_AUTH_FAILED,
+                              *privP->session->error_description);
 
   error:
     VIR_FREE(username);