[libvirt] [RFC 1/5]: Return exitstatus from virStorageBackendRunProgRegex

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch changes things around so that virStorageBackendRunProgRegex() does
*not* virStorageReportError() if the fork()/exec() process it spawned returned a
!= 0 exit code.  Rather, it returns the exitcode in this case, and it is up to
the higher level to determine whether this is a fatal error or not.  The use
case for this change is in the iSCSI stuff; older versions of iscsiadm tools
would return a failure when getting the session number, despite the command
succeeding.

Signed-off-by: Chris Lalancette <clalance@xxxxxxxxxx>

Index: src/storage_backend.c
===================================================================
RCS file: /data/cvs/libvirt/src/storage_backend.c,v
retrieving revision 1.14
diff -u -r1.14 storage_backend.c
--- a/src/storage_backend.c	6 Jun 2008 11:09:57 -0000	1.14
+++ b/src/storage_backend.c	12 Jun 2008 13:19:39 -0000
@@ -352,7 +352,8 @@
                               const char **regex,
                               int *nvars,
                               virStorageBackendListVolRegexFunc func,
-                              void *data)
+                              void *data,
+			      int *outexit)
 {
     int child = 0, fd = -1, exitstatus, err, failed = 1;
     FILE *list = NULL;
@@ -487,12 +488,8 @@
         return -1;
     } else {
         if (WIFEXITED(exitstatus)) {
-            if (WEXITSTATUS(exitstatus) != 0) {
-                virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
-                                      _("non-zero exit status from command %d"),
-                                      WEXITSTATUS(exitstatus));
-                return -1;
-            }
+			if (outexit != NULL)
+				*outexit = WEXITSTATUS(exitstatus);
         } else {
             virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
                                   "%s", _("command did not exit cleanly"));
Index: src/storage_backend.h
===================================================================
RCS file: /data/cvs/libvirt/src/storage_backend.h,v
retrieving revision 1.3
diff -u -r1.3 storage_backend.h
--- a/src/storage_backend.h	10 Apr 2008 16:53:29 -0000	1.3
+++ b/src/storage_backend.h	12 Jun 2008 13:19:39 -0000
@@ -133,7 +133,8 @@
                                   const char **regex,
                                   int *nvars,
                                   virStorageBackendListVolRegexFunc func,
-                                  void *data);
+                                  void *data,
+				  int *exitstatus);
 
 int virStorageBackendRunProgNul(virConnectPtr conn,
                                 virStoragePoolObjPtr pool,
Index: src/storage_backend_iscsi.c
===================================================================
RCS file: /data/cvs/libvirt/src/storage_backend_iscsi.c,v
retrieving revision 1.7
diff -u -r1.7 storage_backend_iscsi.c
--- a/src/storage_backend_iscsi.c	6 Jun 2008 11:09:57 -0000	1.7
+++ b/src/storage_backend_iscsi.c	12 Jun 2008 13:19:39 -0000
@@ -124,13 +124,18 @@
     };
     char *session = NULL;
 
+    /* Note that we ignore the exitstatus.  Older versions of iscsiadm tools
+     * returned and exit status of > 0, even if they succeeded.  We will just
+     * rely on whether session got filled in properlly.
+     */
     if (virStorageBackendRunProgRegex(conn, pool,
                                       prog,
                                       1,
                                       regexes,
                                       vars,
                                       virStorageBackendISCSIExtractSession,
-                                      &session) < 0)
+                                      &session,
+				      NULL) < 0)
         return NULL;
 
     if (session == NULL) {
@@ -373,7 +378,7 @@
                                          regexes,
                                          vars,
                                          virStorageBackendISCSIMakeLUN,
-                                         (void *)session);
+                                         (void *)session, NULL);
 }
 
 
Index: src/storage_backend_logical.c
===================================================================
RCS file: /data/cvs/libvirt/src/storage_backend_logical.c,v
retrieving revision 1.6
diff -u -r1.6 storage_backend_logical.c
--- a/src/storage_backend_logical.c	6 Jun 2008 11:09:57 -0000	1.6
+++ b/src/storage_backend_logical.c	12 Jun 2008 13:19:39 -0000
@@ -213,15 +213,30 @@
         "lv_name,uuid,devices,seg_size,vg_extent_size",
         pool->def->name, NULL
     };
+	int exitstatus;
 
-    return virStorageBackendRunProgRegex(conn,
-                                         pool,
-                                         prog,
-                                         1,
-                                         regexes,
-                                         vars,
-                                         virStorageBackendLogicalMakeVol,
-                                         vol);
+    if (virStorageBackendRunProgRegex(conn,
+									  pool,
+									  prog,
+									  1,
+									  regexes,
+									  vars,
+									  virStorageBackendLogicalMakeVol,
+									  vol,
+									  &exitstatus) < 0) {
+		virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
+							  _("lvs command failed"));
+		return -1;
+	}
+
+	if (exitstatus != 0) {
+		virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
+							  _("lvs command failed with exitstatus %d"),
+							  exitstatus);
+		return -1;
+	}
+
+	return 0;
 }
 
 static int
@@ -347,6 +362,7 @@
         "--nosuffix", "--options", "vg_size,vg_free",
         pool->def->name, NULL
     };
+	int exitstatus;
 
     /* Get list of all logical volumes */
     if (virStorageBackendLogicalFindLVs(conn, pool, NULL) < 0) {
@@ -362,11 +378,22 @@
                                       regexes,
                                       vars,
                                       virStorageBackendLogicalRefreshPoolFunc,
-                                      NULL) < 0) {
+                                      NULL,
+									  &exitstatus) < 0) {
+		virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
+							  _("vgs command failed"));
         virStoragePoolObjClearVols(pool);
         return -1;
     }
 
+	if (exitstatus != 0) {
+		virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
+							  _("vgs command failed with exitstatus %d"),
+							  exitstatus);
+		virStoragePoolObjClearVols(pool);
+		return -1;
+	}
+
     return 0;
 }
 

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]