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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -336,4 +336,5 @@ int populate_seg_desc_hdr(unsigned char *hdr, enum ec_descr_type_code desc_type,
|
||||
int populate_seg_desc_b2b(unsigned char *desc, int dc, int cat, int src_index, int dst_index, int num_blks, uint64_t src_lba, uint64_t dst_lba);
|
||||
void populate_param_header(unsigned char *buf, int list_id, int str, int list_id_usage, int prio, int tgt_desc_len, int seg_desc_len, int inline_data_len);
|
||||
int receive_copy_results(struct scsi_device *sdev, enum scsi_copy_results_sa sa, int list_id, void **datap, int status, enum scsi_sense_key key, int *ascq, int num_ascq);
|
||||
int test_iscsi_tur_until_good(struct scsi_device *iscsi_sd, int *num_uas);
|
||||
#endif /* _ISCSI_SUPPORT_H_ */
|
||||
|
||||
@@ -27,36 +27,6 @@
|
||||
#include "iscsi-test-cu.h"
|
||||
#include "iscsi-multipath.h"
|
||||
|
||||
#define MPATH_MAX_TUR_RETRIES 5
|
||||
|
||||
static int
|
||||
test_iscsi_tur_until_good(struct scsi_device *iscsi_sd,
|
||||
int *num_uas)
|
||||
{
|
||||
int num_turs;
|
||||
|
||||
*num_uas = 0;
|
||||
for (num_turs = 0; num_turs < MPATH_MAX_TUR_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;
|
||||
}
|
||||
|
||||
void
|
||||
test_multipathio_reset(void)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user