Provide function in libiscsi to return the compile-time limit on number of

targets. Use this function in the initiator, to ensure that the same limit
is used throughout (i.e. stop you attempting to compile the initiator with a
different limit to the library - the initiator uses the library for most of
its functionality).

If truncating the number of targets in the initiator, truncate it to the
correct amount, not half of what it should be.

Obey RFC3720 when determining targets. SendTargets=All MUST be supported
on a discovery session, and MUST NOT be supported on an operational session.
Previously, SendTargets=All was used both in the initial discovery session
and the later session. (from Daisuke Aoyama - author of istgt).
This commit is contained in:
sborrill 2011-10-06 13:05:28 +00:00
parent 5dbc169dd3
commit c8be037fd1
3 changed files with 45 additions and 9 deletions

View File

@ -45,7 +45,9 @@
#include "parameters.h"
#include "defs.h"
#ifndef CONFIG_INITIATOR_NUM_TARGETS
#define CONFIG_INITIATOR_NUM_TARGETS 16
#endif
/***********
* Private *
@ -113,6 +115,8 @@ typedef struct initiator_cmd_t {
char targetname[TARGET_HOSTNAME_SIZE];
} initiator_cmd_t;
DEFINE_ARRAY(strv_t, char *);
typedef struct initiator_target_t {
char name[TARGET_HOSTNAME_SIZE];
char ip[TARGET_IP_SIZE];
@ -121,10 +125,9 @@ typedef struct initiator_target_t {
initiator_session_t *sess;
int has_session;
char iqnwanted[TARGET_NAME_SIZE];
strv_t all_targets;
} initiator_target_t;
DEFINE_ARRAY(strv_t, char *);
/**********
* Public *
@ -140,5 +143,6 @@ int ii_initiator_init(const char *, int, int, const char *, char *, int, int, i
int iscsi_initiator_get_targets(int, strv_t *);
int initiator_set_target_name(int, char *);
int iscsi_initiator_get_max_targets(void);
#endif /* _INITIATOR_H_ */

View File

@ -548,6 +548,7 @@ main(int argc, char **argv)
int discover;
int cc;
int i;
uint32_t max_targets;
(void) memset(&tinfo, 0x0, sizeof(tinfo));
iscsi_initiator_set_defaults(&ini);
@ -557,6 +558,8 @@ main(int argc, char **argv)
(void) stat("/etc/hosts", &sti.st);
devtype = 'f';
iscsi_initiator_setvar(&ini, "address family", "4");
max_targets = iscsi_initiator_get_max_targets();
while ((i = getopt(argc, argv, "46a:bcd:Dfh:p:t:u:v:V")) != -1) {
switch(i) {
case '4':
@ -663,16 +666,19 @@ main(int argc, char **argv)
exit(EXIT_SUCCESS);
}
if (all_targets.c/2 > CONFIG_INITIATOR_NUM_TARGETS) {
if (all_targets.c/2 > max_targets) {
(void) fprintf(stderr,
"CONFIG_INITIATOR_NUM_TARGETS in initiator.h "
"is too small. %d targets available, "
"only %d configurable.\n",
all_targets.c/2, CONFIG_INITIATOR_NUM_TARGETS);
all_targets.c/2, max_targets);
(void) fprintf(stderr,
"To increase this value, libiscsi will have be "
"recompiled.\n");
(void) fprintf(stderr,
"Truncating number of targets to %d.\n",
CONFIG_INITIATOR_NUM_TARGETS);
all_targets.c = CONFIG_INITIATOR_NUM_TARGETS;
max_targets);
all_targets.c = 2 * max_targets;
}
sti.st.st_ino = 0x15c51;

View File

@ -155,7 +155,6 @@ static int session_destroy_i(initiator_session_t *);
static int wait_callback_i(void *);
static int discovery_phase(int, strv_t *);
/*
* Private Functions
*/
@ -622,6 +621,13 @@ initiator_set_target_name(int target, char *target_name)
}
int
iscsi_initiator_get_max_targets(void)
{
return CONFIG_INITIATOR_NUM_TARGETS;
}
#if 0
int
iscsi_initiator_get_targets(int target, strv_t *svp)
{
@ -675,6 +681,27 @@ iscsi_initiator_get_targets(int target, strv_t *svp)
return 1;
}
#else
/* SendTargets=All must be sent in discovery session. */
int
iscsi_initiator_get_targets(int target, strv_t *svp)
{
initiator_session_t *sess = g_target[target].sess;
strv_t *tp = &g_target[target].all_targets;
uint32_t i;
if (sess == NULL)
return -1;
for (i = 0; i < tp->c; i++) {
ALLOC(char *, svp->v, svp->size, svp->c, 10,
10, "igt", return -1);
svp->v[svp->c++] = strdup(tp->v[i]);
}
return 1;
}
#endif
static int
discovery_phase(int target, strv_t *svp)
@ -1209,7 +1236,6 @@ enqueue_worker_proc(void *arg)
iscsi_worker_t *me = (iscsi_worker_t *) arg;
uint64_t target;
uint32_t tag;
strv_t sv;
int rc;
@ -1273,7 +1299,7 @@ initialize:
if (strlen(g_target[(int)target].TargetName) == 0) {
iscsi_trace(TRACE_ISCSI_DEBUG, "enqueue_worker: entering Discovery phase with target %llu\n", target);
rc = discovery_phase((int)target, &sv);
rc = discovery_phase((int)target, &g_target[(int)target].all_targets);
iscsi_trace(TRACE_ISCSI_DEBUG, "enqueue_worker: Discovery phase complete\n");
/* Destroy session */