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@redhat.com>
This commit is contained in:
Chris Lalancette 2008-06-17 12:45:24 +00:00
parent a48f26c718
commit a75a612ad5
4 changed files with 45 additions and 19 deletions

View File

@ -352,7 +352,8 @@ virStorageBackendRunProgRegex(virConnectPtr conn,
const char **regex, const char **regex,
int *nvars, int *nvars,
virStorageBackendListVolRegexFunc func, virStorageBackendListVolRegexFunc func,
void *data) void *data,
int *outexit)
{ {
int child = 0, fd = -1, exitstatus, err, failed = 1; int child = 0, fd = -1, exitstatus, err, failed = 1;
FILE *list = NULL; FILE *list = NULL;
@ -487,12 +488,8 @@ virStorageBackendRunProgRegex(virConnectPtr conn,
return -1; return -1;
} else { } else {
if (WIFEXITED(exitstatus)) { if (WIFEXITED(exitstatus)) {
if (WEXITSTATUS(exitstatus) != 0) { if (outexit != NULL)
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, *outexit = WEXITSTATUS(exitstatus);
_("non-zero exit status from command %d"),
WEXITSTATUS(exitstatus));
return -1;
}
} else { } else {
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("command did not exit cleanly")); "%s", _("command did not exit cleanly"));

View File

@ -133,7 +133,8 @@ int virStorageBackendRunProgRegex(virConnectPtr conn,
const char **regex, const char **regex,
int *nvars, int *nvars,
virStorageBackendListVolRegexFunc func, virStorageBackendListVolRegexFunc func,
void *data); void *data,
int *exitstatus);
int virStorageBackendRunProgNul(virConnectPtr conn, int virStorageBackendRunProgNul(virConnectPtr conn,
virStoragePoolObjPtr pool, virStoragePoolObjPtr pool,

View File

@ -124,13 +124,18 @@ virStorageBackendISCSISession(virConnectPtr conn,
}; };
char *session = NULL; char *session = NULL;
/* Note that we ignore the exitstatus. Older versions of iscsiadm tools
* returned an exit status of > 0, even if they succeeded. We will just
* rely on whether session got filled in properly.
*/
if (virStorageBackendRunProgRegex(conn, pool, if (virStorageBackendRunProgRegex(conn, pool,
prog, prog,
1, 1,
regexes, regexes,
vars, vars,
virStorageBackendISCSIExtractSession, virStorageBackendISCSIExtractSession,
&session) < 0) &session,
NULL) < 0)
return NULL; return NULL;
if (session == NULL) { if (session == NULL) {
@ -373,7 +378,7 @@ virStorageBackendISCSIFindLUNs(virConnectPtr conn,
regexes, regexes,
vars, vars,
virStorageBackendISCSIMakeLUN, virStorageBackendISCSIMakeLUN,
(void *)session); (void *)session, NULL);
} }

View File

@ -214,14 +214,30 @@ virStorageBackendLogicalFindLVs(virConnectPtr conn,
pool->def->name, NULL pool->def->name, NULL
}; };
return virStorageBackendRunProgRegex(conn, int exitstatus;
pool,
prog, if (virStorageBackendRunProgRegex(conn,
1, pool,
regexes, prog,
vars, 1,
virStorageBackendLogicalMakeVol, regexes,
vol); 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 static int
@ -347,6 +363,7 @@ virStorageBackendLogicalRefreshPool(virConnectPtr conn,
"--nosuffix", "--options", "vg_size,vg_free", "--nosuffix", "--options", "vg_size,vg_free",
pool->def->name, NULL pool->def->name, NULL
}; };
int exitstatus;
/* Get list of all logical volumes */ /* Get list of all logical volumes */
if (virStorageBackendLogicalFindLVs(conn, pool, NULL) < 0) { if (virStorageBackendLogicalFindLVs(conn, pool, NULL) < 0) {
@ -362,7 +379,13 @@ virStorageBackendLogicalRefreshPool(virConnectPtr conn,
regexes, regexes,
vars, vars,
virStorageBackendLogicalRefreshPoolFunc, virStorageBackendLogicalRefreshPoolFunc,
NULL) < 0) { NULL,
&exitstatus) < 0) {
virStoragePoolObjClearVols(pool);
return -1;
}
if (exitstatus != 0) {
virStoragePoolObjClearVols(pool); virStoragePoolObjClearVols(pool);
return -1; return -1;
} }