]> xenbits.xensource.com Git - libvirt.git/commitdiff
iscsi: Add exit status checking for virISCSIGetSession
authorJohn Ferlan <jferlan@redhat.com>
Fri, 13 May 2016 17:25:30 +0000 (13:25 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 18 May 2016 12:29:24 +0000 (08:29 -0400)
Utilize the exit status parameter for virCommandRunRegex in order to
check the return error from the 'iscsiadm --mode session' command.
Without this enabled, if there are no sessions running then virCommandRun
would have displayed an error such as:

    2016-05-13 15:17:15.165+0000: 10920: error : virCommandWait:2553 :
               internal error: Child process (iscsiadm --mode session)
               unexpected exit status 21: iscsiadm: No active sessions.

It is possible that for certain paths (when probe is true) we only care
whether it's running or not to make certain decisions.  Spitting out
the error for those paths is unnecessary.

If we do have a situation where probe = false and there's an error,
then display the error from iscsiadm if it's there.

src/util/viriscsi.c

index 846ea686a18a7bda72f41d3543fb012535a00905..65a8677b65980b7b0936962d5474e8a51c23c046 100644 (file)
@@ -79,24 +79,28 @@ virISCSIGetSession(const char *devpath,
         .session = NULL,
         .devpath = devpath,
     };
+    char *error = NULL;
+    int exitstatus = 0;
 
-    virCommandPtr cmd = virCommandNewArgList(ISCSIADM, "--mode", "session", NULL);
+    virCommandPtr cmd = virCommandNewArgList(ISCSIADM, "--mode",
+                                             "session", NULL);
+    virCommandSetErrorBuffer(cmd, &error);
 
     if (virCommandRunRegex(cmd,
                            1,
                            regexes,
                            vars,
                            virISCSIExtractSession,
-                           &cbdata, NULL, NULL) < 0)
+                           &cbdata, NULL, &exitstatus) < 0)
         goto cleanup;
 
-    if (cbdata.session == NULL && !probe) {
+    if (cbdata.session == NULL && !probe)
         virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("cannot find session"));
-        goto cleanup;
-    }
+                       _("cannot find iscsiadm session: %s"),
+                       NULLSTR(error));
 
  cleanup:
+    VIR_FREE(error);
     virCommandFree(cmd);
     return cbdata.session;
 }