test/multipath: add helper to obtain secondary sessions
A number of existing tests create a secondary iSCSI session by logging into the target specified in the base sd during the test. With multipath sessions now connected during iscsi-test-cu startup (when launched with multiple URIs), secondary sessions can be provided via multipath when available, rather than reconnecting. This change adds a helper that conditionally returns the secondary multipath device if available, or falls back to creating a new session via the base sd target details. Signed-off-by: David Disseldorp <ddiss@suse.de>
This commit is contained in:
@@ -32,6 +32,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <fnmatch.h>
|
#include <fnmatch.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#ifdef HAVE_SG_IO
|
#ifdef HAVE_SG_IO
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@@ -385,3 +386,59 @@ mpath_count_iscsi(int num_sds,
|
|||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* use an existing multi-path connection, or clone iscsi sd1.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
mpath_sd2_get_or_clone(struct scsi_device *sd1, struct scsi_device **_sd2)
|
||||||
|
{
|
||||||
|
struct scsi_device *sd2;
|
||||||
|
|
||||||
|
if (mp_num_sds > 1) {
|
||||||
|
logging(LOG_VERBOSE, "using multipath dev for second session");
|
||||||
|
*_sd2 = mp_sds[1];
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sd1->iscsi_ctx == NULL) {
|
||||||
|
logging(LOG_NORMAL, "can't clone non-iscsi device");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
logging(LOG_VERBOSE, "cloning sd1 for second session");
|
||||||
|
sd2 = malloc(sizeof(*sd2));
|
||||||
|
if (sd2 == NULL) {
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(sd2, 0, sizeof(*sd2));
|
||||||
|
sd2->iscsi_url = sd1->iscsi_url;
|
||||||
|
sd2->iscsi_lun = sd1->iscsi_lun;
|
||||||
|
sd2->iscsi_ctx = iscsi_context_login(initiatorname2, sd2->iscsi_url,
|
||||||
|
&sd2->iscsi_lun);
|
||||||
|
if (sd2->iscsi_ctx == NULL) {
|
||||||
|
logging(LOG_VERBOSE, "Failed to login to target");
|
||||||
|
free(sd2);
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
*_sd2 = sd2;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mpath_sd2_put(struct scsi_device *sd2)
|
||||||
|
{
|
||||||
|
if (mp_num_sds > 1) {
|
||||||
|
if (sd2 != mp_sds[1]) {
|
||||||
|
logging(LOG_NORMAL, "Invalid sd2!");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* sd2 was allocated by mp_get - cleanup */
|
||||||
|
iscsi_logout_sync(sd2->iscsi_ctx);
|
||||||
|
iscsi_destroy_context(sd2->iscsi_ctx);
|
||||||
|
free(sd2);
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ mpath_check_matching_ids(int num_sds,
|
|||||||
int
|
int
|
||||||
mpath_count_iscsi(int num_sds,
|
mpath_count_iscsi(int num_sds,
|
||||||
struct scsi_device **sds);
|
struct scsi_device **sds);
|
||||||
|
int
|
||||||
|
mpath_sd2_get_or_clone(struct scsi_device *sd1, struct scsi_device **_sd2);
|
||||||
|
void
|
||||||
|
mpath_sd2_put(struct scsi_device *sd2);
|
||||||
|
|
||||||
#define MPATH_SKIP_IF_UNAVAILABLE(_sds, _num_sds) \
|
#define MPATH_SKIP_IF_UNAVAILABLE(_sds, _num_sds) \
|
||||||
do { \
|
do { \
|
||||||
|
|||||||
Reference in New Issue
Block a user