test: move UA drain helper function into iscsi-support

test_iscsi_tur_until_good() dispatches TUR requests until the target has
cleared all UAs for the given sd, or the maximum number of retries is
reached.
This helper function is useful for any test that needs to deal with UAs
(e.g. PRs), so should be moved out into common code.

Signed-off-by: David Disseldorp <ddiss@suse.de>
This commit is contained in:
David Disseldorp
2015-09-28 14:33:14 +02:00
parent 760ae95d9c
commit a1d11eb0f9
3 changed files with 36 additions and 30 deletions

View File

@@ -33,6 +33,7 @@
#include <string.h>
#include <poll.h>
#include <fnmatch.h>
#include <errno.h>
#ifdef HAVE_SG_IO
#include <fcntl.h>
@@ -2943,3 +2944,37 @@ int receive_copy_results(struct scsi_device *sdev, enum scsi_copy_results_sa sa,
return ret;
}
#define TEST_ISCSI_TUR_MAX_RETRIES 5
int
test_iscsi_tur_until_good(struct scsi_device *iscsi_sd, int *num_uas)
{
int num_turs;
if (iscsi_sd->iscsi_ctx == NULL) {
logging(LOG_NORMAL, "invalid sd for tur_until_good");
return -EINVAL;
}
*num_uas = 0;
for (num_turs = 0; num_turs < TEST_ISCSI_TUR_MAX_RETRIES; num_turs++) {
struct scsi_task *tsk;
tsk = iscsi_testunitready_sync(iscsi_sd->iscsi_ctx,
iscsi_sd->iscsi_lun);
if (tsk->status == SCSI_STATUS_GOOD) {
logging(LOG_VERBOSE, "TUR good after %d retries",
num_turs);
return 0;
} else if ((tsk->status == SCSI_STATUS_CHECK_CONDITION)
&& (tsk->sense.key == SCSI_SENSE_UNIT_ATTENTION)) {
logging(LOG_VERBOSE, "Got UA for TUR");
(*num_uas)++;
} else {
logging(LOG_NORMAL, "unexpected non-UA failure: %d,%d",
tsk->status, tsk->sense.key);
}
}
return -ETIMEDOUT;
}